Contents of /trunk/mkinitrd-magellan/busybox/networking/udhcp/dhcpd.h
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 5867 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 5867 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* vi: set sw=4 ts=4: */ |
2 | /* dhcpd.h */ |
3 | #ifndef _DHCPD_H |
4 | #define _DHCPD_H |
5 | |
6 | /************************************/ |
7 | /* Defaults _you_ may want to tweak */ |
8 | /************************************/ |
9 | |
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" |
13 | |
14 | /* where to find the DHCP server configuration file */ |
15 | #define DHCPD_CONF_FILE "/etc/udhcpd.conf" |
16 | |
17 | /*****************************************************************/ |
18 | /* Do not modify below here unless you know what you are doing!! */ |
19 | /*****************************************************************/ |
20 | |
21 | /* DHCP protocol -- see RFC 2131 */ |
22 | #define SERVER_PORT 67 |
23 | #define CLIENT_PORT 68 |
24 | |
25 | #define DHCP_MAGIC 0x63825363 |
26 | |
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 |
44 | #define DHCP_MTU 0x1a |
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 |
56 | #define DHCP_T1 0x3a |
57 | #define DHCP_T2 0x3b |
58 | #define DHCP_VENDOR 0x3c |
59 | #define DHCP_CLIENT_ID 0x3d |
60 | #define DHCP_FQDN 0x51 |
61 | |
62 | #define DHCP_END 0xFF |
63 | |
64 | |
65 | #define BOOTREQUEST 1 |
66 | #define BOOTREPLY 2 |
67 | |
68 | #define ETH_10MB 1 |
69 | #define ETH_10MB_LEN 6 |
70 | |
71 | #define DHCPDISCOVER 1 |
72 | #define DHCPOFFER 2 |
73 | #define DHCPREQUEST 3 |
74 | #define DHCPDECLINE 4 |
75 | #define DHCPACK 5 |
76 | #define DHCPNAK 6 |
77 | #define DHCPRELEASE 7 |
78 | #define DHCPINFORM 8 |
79 | |
80 | #define BROADCAST_FLAG 0x8000 |
81 | |
82 | #define OPTION_FIELD 0 |
83 | #define FILE_FIELD 1 |
84 | #define SNAME_FIELD 2 |
85 | |
86 | /* miscellaneous defines */ |
87 | #define MAC_BCAST_ADDR (uint8_t *) "\xff\xff\xff\xff\xff\xff" |
88 | #define OPT_CODE 0 |
89 | #define OPT_LEN 1 |
90 | #define OPT_DATA 2 |
91 | |
92 | struct option_set { |
93 | uint8_t *data; |
94 | struct option_set *next; |
95 | }; |
96 | |
97 | struct static_lease { |
98 | uint8_t *mac; |
99 | uint32_t *ip; |
100 | struct static_lease *next; |
101 | }; |
102 | |
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 |
118 | * decline message */ |
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*/ |
122 | char *lease_file; |
123 | char *pidfile; |
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 */ |
129 | }; |
130 | |
131 | extern struct server_config_t server_config; |
132 | extern struct dhcpOfferedAddr *leases; |
133 | |
134 | |
135 | /*** leases.h ***/ |
136 | |
137 | struct dhcpOfferedAddr { |
138 | uint8_t chaddr[16]; |
139 | uint32_t yiaddr; /* network order */ |
140 | uint32_t expires; /* host order */ |
141 | }; |
142 | |
143 | extern uint8_t blank_chaddr[]; |
144 | |
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); |
152 | |
153 | |
154 | /*** static_leases.h ***/ |
155 | |
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); |
165 | |
166 | |
167 | /*** serverpacket.h ***/ |
168 | |
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); |
173 | |
174 | |
175 | /*** files.h ***/ |
176 | |
177 | struct config_keyword { |
178 | const char *keyword; |
179 | int (* const handler)(const char *line, void *var); |
180 | void *var; |
181 | const char *def; |
182 | }; |
183 | |
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); |
188 | |
189 | |
190 | #endif |