1 /* vi: set sw=4 ts=4: */
6 /************************************/
7 /* Defaults _you_ may want to tweak */
8 /************************************/
10 /* the period of time the client is allowed to use that address */
11 #define LEASE_TIME (60*60*24*10) /* 10 days of seconds */
12 #define LEASES_FILE "/var/lib/misc/udhcpd.leases"
14 /* where to find the DHCP server configuration file */
15 #define DHCPD_CONF_FILE "/etc/udhcpd.conf"
17 /*****************************************************************/
18 /* Do not modify below here unless you know what you are doing!! */
19 /*****************************************************************/
21 /* DHCP protocol -- see RFC 2131 */
22 #define SERVER_PORT 67
23 #define CLIENT_PORT 68
25 #define DHCP_MAGIC 0x63825363
27 /* DHCP option codes (partial list) */
28 #define DHCP_PADDING 0x00
29 #define DHCP_SUBNET 0x01
30 #define DHCP_TIME_OFFSET 0x02
31 #define DHCP_ROUTER 0x03
32 #define DHCP_TIME_SERVER 0x04
33 #define DHCP_NAME_SERVER 0x05
34 #define DHCP_DNS_SERVER 0x06
35 #define DHCP_LOG_SERVER 0x07
36 #define DHCP_COOKIE_SERVER 0x08
37 #define DHCP_LPR_SERVER 0x09
38 #define DHCP_HOST_NAME 0x0c
39 #define DHCP_BOOT_SIZE 0x0d
40 #define DHCP_DOMAIN_NAME 0x0f
41 #define DHCP_SWAP_SERVER 0x10
42 #define DHCP_ROOT_PATH 0x11
43 #define DHCP_IP_TTL 0x17
45 #define DHCP_BROADCAST 0x1c
46 #define DHCP_NTP_SERVER 0x2a
47 #define DHCP_WINS_SERVER 0x2c
48 #define DHCP_REQUESTED_IP 0x32
49 #define DHCP_LEASE_TIME 0x33
50 #define DHCP_OPTION_OVER 0x34
51 #define DHCP_MESSAGE_TYPE 0x35
52 #define DHCP_SERVER_ID 0x36
53 #define DHCP_PARAM_REQ 0x37
54 #define DHCP_MESSAGE 0x38
55 #define DHCP_MAX_SIZE 0x39
58 #define DHCP_VENDOR 0x3c
59 #define DHCP_CLIENT_ID 0x3d
60 #define DHCP_FQDN 0x51
69 #define ETH_10MB_LEN 6
71 #define DHCPDISCOVER 1
80 #define BROADCAST_FLAG 0x8000
82 #define OPTION_FIELD 0
86 /* miscellaneous defines */
87 #define MAC_BCAST_ADDR (uint8_t *) "\xff\xff\xff\xff\xff\xff"
94 struct option_set *next;
100 struct static_lease *next;
103 struct server_config_t {
104 uint32_t server; /* Our IP, in network order */
105 uint32_t start; /* Start address of leases, network order */
106 uint32_t end; /* End of leases, network order */
107 struct option_set *options; /* List of DHCP options loaded from the config file */
108 char *interface; /* The name of the interface to use */
109 int ifindex; /* Index number of the interface to use */
110 uint8_t arp[6]; /* Our arp address */
111 unsigned long lease; /* lease time in seconds (host order) */
112 unsigned long max_leases; /* maximum number of leases (including reserved address) */
113 char remaining; /* should the lease file be interpreted as lease time remaining, or
114 * as the time the lease expires */
115 unsigned long auto_time; /* how long should udhcpd wait before writing a config file.
116 * if this is zero, it will only write one on SIGUSR1 */
117 unsigned long decline_time; /* how long an address is reserved if a client returns a
119 unsigned long conflict_time; /* how long an arp conflict offender is leased for */
120 unsigned long offer_time; /* how long an offered address is reserved */
121 unsigned long min_lease; /* minimum lease a client can request*/
124 char *notify_file; /* What to run whenever leases are written */
125 uint32_t siaddr; /* next server bootp option */
126 char *sname; /* bootp server name */
127 char *boot_file; /* bootp boot file option */
128 struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */
131 extern struct server_config_t server_config;
132 extern struct dhcpOfferedAddr *leases;
137 struct dhcpOfferedAddr {
139 uint32_t yiaddr; /* network order */
140 uint32_t expires; /* host order */
143 extern uint8_t blank_chaddr[];
145 void clear_lease(uint8_t *chaddr, uint32_t yiaddr);
146 struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease);
147 int lease_expired(struct dhcpOfferedAddr *lease);
148 struct dhcpOfferedAddr *oldest_expired_lease(void);
149 struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr);
150 struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr);
151 uint32_t find_address(int check_expired);
154 /*** static_leases.h ***/
156 /* Config file will pass static lease info to this function which will add it
157 * to a data structure that can be searched later */
158 int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip);
159 /* Check to see if a mac has an associated static lease */
160 uint32_t getIpByMac(struct static_lease *lease_struct, void *arg);
161 /* Check to see if an ip is reserved as a static ip */
162 uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip);
163 /* Print out static leases just to check what's going on (debug code) */
164 void printStaticLeases(struct static_lease **lease_struct);
167 /*** serverpacket.h ***/
169 int sendOffer(struct dhcpMessage *oldpacket);
170 int sendNAK(struct dhcpMessage *oldpacket);
171 int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr);
172 int send_inform(struct dhcpMessage *oldpacket);
177 struct config_keyword {
179 int (* const handler)(const char *line, void *var);
184 int read_config(const char *file);
185 void write_leases(void);
186 void read_leases(const char *file);
187 struct option_set *find_option(struct option_set *opt_list, char code);