diff options
-rw-r--r-- | networking/udhcp/clientpacket.c | 4 | ||||
-rw-r--r-- | networking/udhcp/common.h | 4 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 44 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.h | 3 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 21 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.h | 6 | ||||
-rw-r--r-- | networking/udhcp/dhcprelay.c | 2 | ||||
-rw-r--r-- | networking/udhcp/packet.c | 2 | ||||
-rw-r--r-- | networking/udhcp/serverpacket.c | 13 |
9 files changed, 50 insertions, 49 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index f826c1b94..c562c1200 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c | |||
@@ -175,7 +175,7 @@ int send_release(uint32_t server, uint32_t ciaddr) | |||
175 | 175 | ||
176 | 176 | ||
177 | /* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */ | 177 | /* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */ |
178 | int get_raw_packet(struct dhcpMessage *payload, int fd) | 178 | int udhcp_recv_raw_packet(struct dhcpMessage *payload, int fd) |
179 | { | 179 | { |
180 | int bytes; | 180 | int bytes; |
181 | struct udp_dhcp_packet packet; | 181 | struct udp_dhcp_packet packet; |
@@ -185,7 +185,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
185 | bytes = safe_read(fd, &packet, sizeof(packet)); | 185 | bytes = safe_read(fd, &packet, sizeof(packet)); |
186 | if (bytes < 0) { | 186 | if (bytes < 0) { |
187 | DEBUG("Cannot read on raw listening socket - ignoring"); | 187 | DEBUG("Cannot read on raw listening socket - ignoring"); |
188 | sleep(1); /* possible down interface, looping condition */ | 188 | /* NB: possible down interface, etc. Caller should pause. */ |
189 | return bytes; /* returns -1 */ | 189 | return bytes; /* returns -1 */ |
190 | } | 190 | } |
191 | 191 | ||
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 1131baee2..bf0ecc7b1 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -61,7 +61,9 @@ uint16_t udhcp_checksum(void *addr, int count); | |||
61 | 61 | ||
62 | void udhcp_init_header(struct dhcpMessage *packet, char type); | 62 | void udhcp_init_header(struct dhcpMessage *packet, char type); |
63 | 63 | ||
64 | int udhcp_recv_packet(struct dhcpMessage *packet, int fd); | 64 | /*int udhcp_recv_raw_packet(struct dhcpMessage *payload, int fd); - in dhcpc.h */ |
65 | int udhcp_recv_kernel_packet(struct dhcpMessage *packet, int fd); | ||
66 | |||
65 | int udhcp_send_raw_packet(struct dhcpMessage *payload, | 67 | int udhcp_send_raw_packet(struct dhcpMessage *payload, |
66 | uint32_t source_ip, int source_port, | 68 | uint32_t source_ip, int source_port, |
67 | uint32_t dest_ip, int dest_port, | 69 | uint32_t dest_ip, int dest_port, |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 7138389b8..fef8632f6 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -147,9 +147,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
147 | unsigned opt; | 147 | unsigned opt; |
148 | int max_fd; | 148 | int max_fd; |
149 | int retval; | 149 | int retval; |
150 | int len; | ||
151 | struct timeval tv; | 150 | struct timeval tv; |
152 | struct in_addr temp_addr; | ||
153 | struct dhcpMessage packet; | 151 | struct dhcpMessage packet; |
154 | fd_set rfds; | 152 | fd_set rfds; |
155 | 153 | ||
@@ -380,7 +378,6 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
380 | if (packet_num == 0) | 378 | if (packet_num == 0) |
381 | xid = random_xid(); | 379 | xid = random_xid(); |
382 | 380 | ||
383 | /* send discover packet */ | ||
384 | send_discover(xid, requested_ip); /* broadcast */ | 381 | send_discover(xid, requested_ip); /* broadcast */ |
385 | 382 | ||
386 | timeout = discover_timeout; | 383 | timeout = discover_timeout; |
@@ -396,7 +393,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
396 | retval = 1; | 393 | retval = 1; |
397 | goto ret; | 394 | goto ret; |
398 | } | 395 | } |
399 | /* wait to try again */ | 396 | /* wait before trying again */ |
400 | timeout = tryagain_timeout; | 397 | timeout = tryagain_timeout; |
401 | packet_num = 0; | 398 | packet_num = 0; |
402 | continue; | 399 | continue; |
@@ -404,11 +401,12 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
404 | case REQUESTING: | 401 | case REQUESTING: |
405 | if (packet_num < discover_retries) { | 402 | if (packet_num < discover_retries) { |
406 | /* send request packet */ | 403 | /* send request packet */ |
407 | if (state == RENEW_REQUESTED) | 404 | if (state == RENEW_REQUESTED) /* unicast */ |
408 | send_renew(xid, server_addr, requested_ip); /* unicast */ | 405 | send_renew(xid, server_addr, requested_ip); |
409 | else send_selecting(xid, server_addr, requested_ip); /* broadcast */ | 406 | else /* broadcast */ |
407 | send_selecting(xid, server_addr, requested_ip); | ||
410 | 408 | ||
411 | timeout = ((packet_num == 2) ? 10 : 2); | 409 | timeout = discover_timeout; |
412 | packet_num++; | 410 | packet_num++; |
413 | continue; | 411 | continue; |
414 | } | 412 | } |
@@ -436,7 +434,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
436 | /* Timed out, enter rebinding state */ | 434 | /* Timed out, enter rebinding state */ |
437 | DEBUG("Entering rebinding state"); | 435 | DEBUG("Entering rebinding state"); |
438 | state = REBINDING; | 436 | state = REBINDING; |
439 | continue; | 437 | /* fall right through */ |
440 | case REBINDING: | 438 | case REBINDING: |
441 | /* Lease is *really* about to run out, | 439 | /* Lease is *really* about to run out, |
442 | * try to find DHCP server using broadcast */ | 440 | * try to find DHCP server using broadcast */ |
@@ -464,23 +462,24 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
464 | /* select() didn't timeout, something did happen. */ | 462 | /* select() didn't timeout, something did happen. */ |
465 | /* Is is a packet? */ | 463 | /* Is is a packet? */ |
466 | if (listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { | 464 | if (listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { |
465 | int len; | ||
467 | /* A packet is ready, read it */ | 466 | /* A packet is ready, read it */ |
468 | 467 | ||
469 | if (listen_mode == LISTEN_KERNEL) | 468 | if (listen_mode == LISTEN_KERNEL) |
470 | len = udhcp_recv_packet(&packet, sockfd); | 469 | len = udhcp_recv_kernel_packet(&packet, sockfd); |
471 | else | 470 | else |
472 | len = get_raw_packet(&packet, sockfd); | 471 | len = udhcp_recv_raw_packet(&packet, sockfd); |
473 | |||
474 | /* If this packet will turn out to be unrelated/bogus, | ||
475 | * we will go back and wait for next one. | ||
476 | * Be sure timeout is properly decreased. */ | ||
477 | already_waited_sec += (unsigned)monotonic_sec() - timestamp_before_wait; | ||
478 | |||
479 | if (len == -1) { /* error is severe, reopen socket */ | 472 | if (len == -1) { /* error is severe, reopen socket */ |
480 | DEBUG("error on read, %s, reopening socket", strerror(errno)); | 473 | DEBUG("error on read, %s, reopening socket", strerror(errno)); |
474 | sleep(discover_timeout); /* 3 seconds by default */ | ||
481 | change_listen_mode(listen_mode); /* just close and reopen */ | 475 | change_listen_mode(listen_mode); /* just close and reopen */ |
482 | } | 476 | } |
483 | if (len < 0) continue; | 477 | /* If this packet will turn out to be unrelated/bogus, |
478 | * we will go back and wait for next one. | ||
479 | * Be sure timeout is properly decreased. */ | ||
480 | already_waited_sec += (unsigned)monotonic_sec() - timestamp_before_wait; | ||
481 | if (len < 0) | ||
482 | continue; | ||
484 | 483 | ||
485 | if (packet.xid != xid) { | 484 | if (packet.xid != xid) { |
486 | DEBUG("Ignoring XID %x (our xid is %x)", | 485 | DEBUG("Ignoring XID %x (our xid is %x)", |
@@ -563,9 +562,12 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
563 | #endif | 562 | #endif |
564 | /* enter bound state */ | 563 | /* enter bound state */ |
565 | timeout = lease_seconds / 2; | 564 | timeout = lease_seconds / 2; |
566 | temp_addr.s_addr = packet.yiaddr; | 565 | { |
567 | bb_info_msg("Lease of %s obtained, lease time %u", | 566 | struct in_addr temp_addr; |
568 | inet_ntoa(temp_addr), (unsigned)lease_seconds); | 567 | temp_addr.s_addr = packet.yiaddr; |
568 | bb_info_msg("Lease of %s obtained, lease time %u", | ||
569 | inet_ntoa(temp_addr), (unsigned)lease_seconds); | ||
570 | } | ||
569 | requested_ip = packet.yiaddr; | 571 | requested_ip = packet.yiaddr; |
570 | udhcp_run_script(&packet, | 572 | udhcp_run_script(&packet, |
571 | ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); | 573 | ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); |
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 452afcf45..9331466e1 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h | |||
@@ -62,7 +62,8 @@ int send_decline(uint32_t xid, uint32_t server, uint32_t requested); | |||
62 | int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); | 62 | int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); |
63 | int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); | 63 | int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); |
64 | int send_release(uint32_t server, uint32_t ciaddr); | 64 | int send_release(uint32_t server, uint32_t ciaddr); |
65 | int get_raw_packet(struct dhcpMessage *payload, int fd); | 65 | |
66 | int udhcp_recv_raw_packet(struct dhcpMessage *payload, int fd); | ||
66 | 67 | ||
67 | #if __GNUC_PREREQ(4,1) | 68 | #if __GNUC_PREREQ(4,1) |
68 | # pragma GCC visibility pop | 69 | # pragma GCC visibility pop |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 263719657..a6264ad2f 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -145,7 +145,7 @@ int udhcpd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
145 | default: continue; /* signal or error (probably EINTR) */ | 145 | default: continue; /* signal or error (probably EINTR) */ |
146 | } | 146 | } |
147 | 147 | ||
148 | bytes = udhcp_recv_packet(&packet, server_socket); /* this waits for a packet - idle */ | 148 | bytes = udhcp_recv_kernel_packet(&packet, server_socket); /* this waits for a packet - idle */ |
149 | if (bytes < 0) { | 149 | if (bytes < 0) { |
150 | if (bytes == -1 && errno != EINTR) { | 150 | if (bytes == -1 && errno != EINTR) { |
151 | DEBUG("error on read, %s, reopening socket", strerror(errno)); | 151 | DEBUG("error on read, %s, reopening socket", strerror(errno)); |
@@ -180,7 +180,7 @@ int udhcpd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
180 | case DHCPDISCOVER: | 180 | case DHCPDISCOVER: |
181 | DEBUG("Received DISCOVER"); | 181 | DEBUG("Received DISCOVER"); |
182 | 182 | ||
183 | if (sendOffer(&packet) < 0) { | 183 | if (send_offer(&packet) < 0) { |
184 | bb_error_msg("send OFFER failed"); | 184 | bb_error_msg("send OFFER failed"); |
185 | } | 185 | } |
186 | break; | 186 | break; |
@@ -200,20 +200,19 @@ int udhcpd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
200 | if (server_id_align == server_config.server && requested | 200 | if (server_id_align == server_config.server && requested |
201 | && requested_align == lease->yiaddr | 201 | && requested_align == lease->yiaddr |
202 | ) { | 202 | ) { |
203 | sendACK(&packet, lease->yiaddr); | 203 | send_ACK(&packet, lease->yiaddr); |
204 | } | 204 | } |
205 | } else if (requested) { | 205 | } else if (requested) { |
206 | /* INIT-REBOOT State */ | 206 | /* INIT-REBOOT State */ |
207 | if (lease->yiaddr == requested_align) | 207 | if (lease->yiaddr == requested_align) |
208 | sendACK(&packet, lease->yiaddr); | 208 | send_ACK(&packet, lease->yiaddr); |
209 | else | 209 | else |
210 | sendNAK(&packet); | 210 | send_NAK(&packet); |
211 | } else if (lease->yiaddr == packet.ciaddr) { | 211 | } else if (lease->yiaddr == packet.ciaddr) { |
212 | /* RENEWING or REBINDING State */ | 212 | /* RENEWING or REBINDING State */ |
213 | sendACK(&packet, lease->yiaddr); | 213 | send_ACK(&packet, lease->yiaddr); |
214 | } else { | 214 | } else { /* don't know what to do!!!! */ |
215 | /* don't know what to do!!!! */ | 215 | send_NAK(&packet); |
216 | sendNAK(&packet); | ||
217 | } | 216 | } |
218 | 217 | ||
219 | /* what to do if we have no record of the client */ | 218 | /* what to do if we have no record of the client */ |
@@ -229,13 +228,13 @@ int udhcpd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
229 | memset(lease->chaddr, 0, 16); | 228 | memset(lease->chaddr, 0, 16); |
230 | /* make some contention for this address */ | 229 | /* make some contention for this address */ |
231 | } else | 230 | } else |
232 | sendNAK(&packet); | 231 | send_NAK(&packet); |
233 | } else { | 232 | } else { |
234 | uint32_t r = ntohl(requested_align); | 233 | uint32_t r = ntohl(requested_align); |
235 | if (r < server_config.start_ip | 234 | if (r < server_config.start_ip |
236 | || r > server_config.end_ip | 235 | || r > server_config.end_ip |
237 | ) { | 236 | ) { |
238 | sendNAK(&packet); | 237 | send_NAK(&packet); |
239 | } | 238 | } |
240 | /* else remain silent */ | 239 | /* else remain silent */ |
241 | } | 240 | } |
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 8a206ea49..87e1afc1f 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
@@ -104,9 +104,9 @@ void printStaticLeases(struct static_lease **lease_struct); | |||
104 | 104 | ||
105 | /*** serverpacket.h ***/ | 105 | /*** serverpacket.h ***/ |
106 | 106 | ||
107 | int sendOffer(struct dhcpMessage *oldpacket); | 107 | int send_offer(struct dhcpMessage *oldpacket); |
108 | int sendNAK(struct dhcpMessage *oldpacket); | 108 | int send_NAK(struct dhcpMessage *oldpacket); |
109 | int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr); | 109 | int send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr); |
110 | int send_inform(struct dhcpMessage *oldpacket); | 110 | int send_inform(struct dhcpMessage *oldpacket); |
111 | 111 | ||
112 | 112 | ||
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index def1bc297..08fb733d7 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c | |||
@@ -257,7 +257,7 @@ static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **cli | |||
257 | if (select(max_socket + 1, &rfds, NULL, NULL, &tv) > 0) { | 257 | if (select(max_socket + 1, &rfds, NULL, NULL, &tv) > 0) { |
258 | /* server */ | 258 | /* server */ |
259 | if (FD_ISSET(fds[0], &rfds)) { | 259 | if (FD_ISSET(fds[0], &rfds)) { |
260 | packlen = udhcp_recv_packet(&dhcp_msg, fds[0]); | 260 | packlen = udhcp_recv_kernel_packet(&dhcp_msg, fds[0]); |
261 | if (packlen > 0) { | 261 | if (packlen > 0) { |
262 | pass_back(&dhcp_msg, packlen, fds); | 262 | pass_back(&dhcp_msg, packlen, fds); |
263 | } | 263 | } |
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index fb6ef7175..923add628 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c | |||
@@ -34,7 +34,7 @@ void udhcp_init_header(struct dhcpMessage *packet, char type) | |||
34 | 34 | ||
35 | 35 | ||
36 | /* read a packet from socket fd, return -1 on read error, -2 on packet error */ | 36 | /* read a packet from socket fd, return -1 on read error, -2 on packet error */ |
37 | int udhcp_recv_packet(struct dhcpMessage *packet, int fd) | 37 | int udhcp_recv_kernel_packet(struct dhcpMessage *packet, int fd) |
38 | { | 38 | { |
39 | int bytes; | 39 | int bytes; |
40 | unsigned char *vendor; | 40 | unsigned char *vendor; |
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index 1dc7233f2..fc6249725 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c | |||
@@ -67,12 +67,9 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas | |||
67 | /* send a dhcp packet, if force broadcast is set, the packet will be broadcast to the client */ | 67 | /* send a dhcp packet, if force broadcast is set, the packet will be broadcast to the client */ |
68 | static int send_packet(struct dhcpMessage *payload, int force_broadcast) | 68 | static int send_packet(struct dhcpMessage *payload, int force_broadcast) |
69 | { | 69 | { |
70 | int ret; | ||
71 | |||
72 | if (payload->giaddr) | 70 | if (payload->giaddr) |
73 | ret = send_packet_to_relay(payload); | 71 | return send_packet_to_relay(payload); |
74 | else ret = send_packet_to_client(payload, force_broadcast); | 72 | return send_packet_to_client(payload, force_broadcast); |
75 | return ret; | ||
76 | } | 73 | } |
77 | 74 | ||
78 | 75 | ||
@@ -100,7 +97,7 @@ static void add_bootp_options(struct dhcpMessage *packet) | |||
100 | 97 | ||
101 | 98 | ||
102 | /* send a DHCP OFFER to a DHCP DISCOVER */ | 99 | /* send a DHCP OFFER to a DHCP DISCOVER */ |
103 | int sendOffer(struct dhcpMessage *oldpacket) | 100 | int send_offer(struct dhcpMessage *oldpacket) |
104 | { | 101 | { |
105 | struct dhcpMessage packet; | 102 | struct dhcpMessage packet; |
106 | struct dhcpOfferedAddr *lease = NULL; | 103 | struct dhcpOfferedAddr *lease = NULL; |
@@ -188,7 +185,7 @@ int sendOffer(struct dhcpMessage *oldpacket) | |||
188 | } | 185 | } |
189 | 186 | ||
190 | 187 | ||
191 | int sendNAK(struct dhcpMessage *oldpacket) | 188 | int send_NAK(struct dhcpMessage *oldpacket) |
192 | { | 189 | { |
193 | struct dhcpMessage packet; | 190 | struct dhcpMessage packet; |
194 | 191 | ||
@@ -199,7 +196,7 @@ int sendNAK(struct dhcpMessage *oldpacket) | |||
199 | } | 196 | } |
200 | 197 | ||
201 | 198 | ||
202 | int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) | 199 | int send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) |
203 | { | 200 | { |
204 | struct dhcpMessage packet; | 201 | struct dhcpMessage packet; |
205 | struct option_set *curr; | 202 | struct option_set *curr; |