diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-17 13:24:03 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-17 13:24:03 +0200 |
commit | 6947d2c7e194e3be31eed1c75260e15fca1a2568 (patch) | |
tree | ff4d67b49e0e7e02e29ecc090db619a39b24498d /networking/udhcp/dhcpd.c | |
parent | 2b0e95780863da44f6a9244699ece8620a599e19 (diff) | |
download | busybox-w32-6947d2c7e194e3be31eed1c75260e15fca1a2568.tar.gz busybox-w32-6947d2c7e194e3be31eed1c75260e15fca1a2568.tar.bz2 busybox-w32-6947d2c7e194e3be31eed1c75260e15fca1a2568.zip |
udhcp: logging improvements, field and variable renames
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpd.c')
-rw-r--r-- | networking/udhcp/dhcpd.c | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 348246341..23292a55d 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | 19 | ||
20 | /* globals */ | 20 | /* globals */ |
21 | struct dyn_lease *leases; | 21 | struct dyn_lease *g_leases; |
22 | /* struct server_config_t server_config is in bb_common_bufsiz1 */ | 22 | /* struct server_config_t server_config is in bb_common_bufsiz1 */ |
23 | 23 | ||
24 | 24 | ||
@@ -28,15 +28,13 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
28 | fd_set rfds; | 28 | fd_set rfds; |
29 | int server_socket = -1, retval, max_sock; | 29 | int server_socket = -1, retval, max_sock; |
30 | struct dhcp_packet packet; | 30 | struct dhcp_packet packet; |
31 | uint8_t *state, *server_id, *requested; | 31 | uint8_t *state; |
32 | uint32_t server_id_aligned = server_id_aligned; /* for compiler */ | ||
33 | uint32_t requested_aligned = requested_aligned; | ||
34 | uint32_t static_lease_ip; | 32 | uint32_t static_lease_ip; |
35 | unsigned timeout_end; | 33 | unsigned timeout_end; |
36 | unsigned num_ips; | 34 | unsigned num_ips; |
37 | unsigned opt; | 35 | unsigned opt; |
38 | struct option_set *option; | 36 | struct option_set *option; |
39 | struct dyn_lease *lease, static_lease; | 37 | struct dyn_lease *lease, fake_lease; |
40 | IF_FEATURE_UDHCP_PORT(char *str_P;) | 38 | IF_FEATURE_UDHCP_PORT(char *str_P;) |
41 | 39 | ||
42 | #if ENABLE_FEATURE_UDHCP_PORT | 40 | #if ENABLE_FEATURE_UDHCP_PORT |
@@ -84,10 +82,10 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
84 | bb_info_msg("%s (v"BB_VER") started", applet_name); | 82 | bb_info_msg("%s (v"BB_VER") started", applet_name); |
85 | 83 | ||
86 | option = find_option(server_config.options, DHCP_LEASE_TIME); | 84 | option = find_option(server_config.options, DHCP_LEASE_TIME); |
87 | server_config.lease = LEASE_TIME; | 85 | server_config.max_lease_sec = LEASE_TIME; |
88 | if (option) { | 86 | if (option) { |
89 | move_from_unaligned32(server_config.lease, option->data + 2); | 87 | move_from_unaligned32(server_config.max_lease_sec, option->data + OPT_DATA); |
90 | server_config.lease = ntohl(server_config.lease); | 88 | server_config.max_lease_sec = ntohl(server_config.max_lease_sec); |
91 | } | 89 | } |
92 | 90 | ||
93 | /* Sanity check */ | 91 | /* Sanity check */ |
@@ -98,7 +96,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
98 | server_config.max_leases = num_ips; | 96 | server_config.max_leases = num_ips; |
99 | } | 97 | } |
100 | 98 | ||
101 | leases = xzalloc(server_config.max_leases * sizeof(*leases)); | 99 | g_leases = xzalloc(server_config.max_leases * sizeof(g_leases[0])); |
102 | read_leases(server_config.lease_file); | 100 | read_leases(server_config.lease_file); |
103 | 101 | ||
104 | if (udhcp_read_interface(server_config.interface, | 102 | if (udhcp_read_interface(server_config.interface, |
@@ -186,13 +184,13 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
186 | if (static_lease_ip) { | 184 | if (static_lease_ip) { |
187 | bb_info_msg("Found static lease: %x", static_lease_ip); | 185 | bb_info_msg("Found static lease: %x", static_lease_ip); |
188 | 186 | ||
189 | memcpy(&static_lease.lease_mac, &packet.chaddr, 6); | 187 | memcpy(&fake_lease.lease_mac, &packet.chaddr, 6); |
190 | static_lease.lease_nip = static_lease_ip; | 188 | fake_lease.lease_nip = static_lease_ip; |
191 | static_lease.expires = 0; | 189 | fake_lease.expires = 0; |
192 | 190 | ||
193 | lease = &static_lease; | 191 | lease = &fake_lease; |
194 | } else { | 192 | } else { |
195 | lease = find_lease_by_chaddr(packet.chaddr); | 193 | lease = find_lease_by_mac(packet.chaddr); |
196 | } | 194 | } |
197 | 195 | ||
198 | switch (state[0]) { | 196 | switch (state[0]) { |
@@ -203,29 +201,32 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
203 | bb_error_msg("send OFFER failed"); | 201 | bb_error_msg("send OFFER failed"); |
204 | } | 202 | } |
205 | break; | 203 | break; |
206 | case DHCPREQUEST: | 204 | case DHCPREQUEST: { |
207 | log1("Received REQUEST"); | 205 | uint8_t *server_id_opt, *requested_opt; |
206 | uint32_t server_id_net = server_id_net; /* for compiler */ | ||
207 | uint32_t requested_nip = requested_nip; /* for compiler */ | ||
208 | 208 | ||
209 | requested = get_option(&packet, DHCP_REQUESTED_IP); | 209 | log1("Received REQUEST"); |
210 | server_id = get_option(&packet, DHCP_SERVER_ID); | ||
211 | 210 | ||
212 | if (requested) | 211 | requested_opt = get_option(&packet, DHCP_REQUESTED_IP); |
213 | move_from_unaligned32(requested_aligned, requested); | 212 | server_id_opt = get_option(&packet, DHCP_SERVER_ID); |
214 | if (server_id) | 213 | if (requested_opt) |
215 | move_from_unaligned32(server_id_aligned, server_id); | 214 | move_from_unaligned32(requested_nip, requested_opt); |
215 | if (server_id_opt) | ||
216 | move_from_unaligned32(server_id_net, server_id_opt); | ||
216 | 217 | ||
217 | if (lease) { | 218 | if (lease) { |
218 | if (server_id) { | 219 | if (server_id_opt) { |
219 | /* SELECTING State */ | 220 | /* SELECTING State */ |
220 | if (server_id_aligned == server_config.server_nip | 221 | if (server_id_net == server_config.server_nip |
221 | && requested | 222 | && requested_opt |
222 | && requested_aligned == lease->lease_nip | 223 | && requested_nip == lease->lease_nip |
223 | ) { | 224 | ) { |
224 | send_ACK(&packet, lease->lease_nip); | 225 | send_ACK(&packet, lease->lease_nip); |
225 | } | 226 | } |
226 | } else if (requested) { | 227 | } else if (requested_opt) { |
227 | /* INIT-REBOOT State */ | 228 | /* INIT-REBOOT State */ |
228 | if (lease->lease_nip == requested_aligned) | 229 | if (lease->lease_nip == requested_nip) |
229 | send_ACK(&packet, lease->lease_nip); | 230 | send_ACK(&packet, lease->lease_nip); |
230 | else | 231 | else |
231 | send_NAK(&packet); | 232 | send_NAK(&packet); |
@@ -237,14 +238,14 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
237 | } | 238 | } |
238 | 239 | ||
239 | /* what to do if we have no record of the client */ | 240 | /* what to do if we have no record of the client */ |
240 | } else if (server_id) { | 241 | } else if (server_id_opt) { |
241 | /* SELECTING State */ | 242 | /* SELECTING State */ |
242 | 243 | ||
243 | } else if (requested) { | 244 | } else if (requested_opt) { |
244 | /* INIT-REBOOT State */ | 245 | /* INIT-REBOOT State */ |
245 | lease = find_lease_by_yiaddr(requested_aligned); | 246 | lease = find_lease_by_nip(requested_nip); |
246 | if (lease) { | 247 | if (lease) { |
247 | if (lease_expired(lease)) { | 248 | if (is_expired_lease(lease)) { |
248 | /* probably best if we drop this lease */ | 249 | /* probably best if we drop this lease */ |
249 | memset(lease->lease_mac, 0, sizeof(lease->lease_mac)); | 250 | memset(lease->lease_mac, 0, sizeof(lease->lease_mac)); |
250 | } else { | 251 | } else { |
@@ -252,7 +253,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
252 | send_NAK(&packet); | 253 | send_NAK(&packet); |
253 | } | 254 | } |
254 | } else { | 255 | } else { |
255 | uint32_t r = ntohl(requested_aligned); | 256 | uint32_t r = ntohl(requested_nip); |
256 | if (r < server_config.start_ip | 257 | if (r < server_config.start_ip |
257 | || r > server_config.end_ip | 258 | || r > server_config.end_ip |
258 | ) { | 259 | ) { |
@@ -265,6 +266,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
265 | /* RENEWING or REBINDING State */ | 266 | /* RENEWING or REBINDING State */ |
266 | } | 267 | } |
267 | break; | 268 | break; |
269 | } | ||
268 | case DHCPDECLINE: | 270 | case DHCPDECLINE: |
269 | log1("Received DECLINE"); | 271 | log1("Received DECLINE"); |
270 | if (lease) { | 272 | if (lease) { |