Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/networking/udhcp/dhcpd.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/networking/udhcp/dhcpd.c
r2725 r3232 21 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 22 */ 23 24 //usage:#define udhcpd_trivial_usage 25 //usage: "[-fS]" IF_FEATURE_UDHCP_PORT(" [-P N]") " [CONFFILE]" 26 //usage:#define udhcpd_full_usage "\n\n" 27 //usage: "DHCP server\n" 28 //usage: "\n -f Run in foreground" 29 //usage: "\n -S Log to syslog too" 30 //usage: IF_FEATURE_UDHCP_PORT( 31 //usage: "\n -P N Use port N (default 67)" 32 //usage: ) 33 23 34 #include <syslog.h> 24 35 #include "common.h" … … 134 145 /* We got a DHCP DISCOVER. Send an OFFER. */ 135 146 /* NOINLINE: limit stack usage in caller */ 136 static NOINLINE void send_offer(struct dhcp_packet *oldpacket, uint32_t static_lease_nip, struct dyn_lease *lease) 147 static NOINLINE void send_offer(struct dhcp_packet *oldpacket, 148 uint32_t static_lease_nip, 149 struct dyn_lease *lease, 150 uint8_t *requested_ip_opt) 137 151 { 138 152 struct dhcp_packet packet; … … 148 162 /* We have no static lease for client's chaddr */ 149 163 uint32_t req_nip; 150 uint8_t *req_ip_opt;151 164 const char *p_host_name; 152 165 … … 159 172 } 160 173 /* Or: if client has requested an IP */ 161 else if ( (req_ip_opt = udhcp_get_option(oldpacket, DHCP_REQUESTED_IP))!= NULL174 else if (requested_ip_opt != NULL 162 175 /* (read IP) */ 163 && (move_from_unaligned32(req_nip, req _ip_opt), 1)176 && (move_from_unaligned32(req_nip, requested_ip_opt), 1) 164 177 /* and the IP is in the lease range */ 165 178 && ntohl(req_nip) >= server_config.start_ip … … 284 297 int udhcpd_main(int argc UNUSED_PARAM, char **argv) 285 298 { 286 fd_set rfds;287 299 int server_socket = -1, retval, max_sock; 288 struct dhcp_packet packet;289 300 uint8_t *state; 290 uint32_t static_lease_nip;291 301 unsigned timeout_end; 292 302 unsigned num_ips; 293 303 unsigned opt; 294 304 struct option_set *option; 295 struct dyn_lease *lease, fake_lease;296 305 IF_FEATURE_UDHCP_PORT(char *str_P;) 297 306 … … 306 315 opt = getopt32(argv, "fSv" 307 316 IF_FEATURE_UDHCP_PORT("P:", &str_P) 308 #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 309 , &dhcp_verbose 310 #endif 317 IF_UDHCP_VERBOSE(, &dhcp_verbose) 311 318 ); 312 319 if (!(opt & 1)) { /* no -f */ … … 371 378 udhcp_sp_setup(); 372 379 380 continue_with_autotime: 373 381 timeout_end = monotonic_sec() + server_config.auto_time; 374 382 while (1) { /* loop until universe collapses */ 383 fd_set rfds; 384 struct dhcp_packet packet; 375 385 int bytes; 376 386 struct timeval tv; 377 387 uint8_t *server_id_opt; 378 uint8_t *requested_ opt;388 uint8_t *requested_ip_opt; 379 389 uint32_t requested_nip = requested_nip; /* for compiler */ 390 uint32_t static_lease_nip; 391 struct dyn_lease *lease, fake_lease; 380 392 381 393 if (server_socket < 0) { … … 396 408 if (retval == 0) { 397 409 write_leases(); 398 timeout_end = monotonic_sec() + server_config.auto_time; 399 continue; 410 goto continue_with_autotime; 400 411 } 401 412 if (retval < 0 && errno != EINTR) { … … 409 420 write_leases(); 410 421 /* why not just reset the timeout, eh */ 411 timeout_end = monotonic_sec() + server_config.auto_time; 412 continue; 422 goto continue_with_autotime; 413 423 case SIGTERM: 414 424 bb_info_msg("Received SIGTERM"); 425 write_leases(); 415 426 goto ret0; 416 427 case 0: /* no signal: read a packet */ … … 442 453 bb_error_msg("no or bad message type option, ignoring packet"); 443 454 continue; 455 } 456 457 /* Get SERVER_ID if present */ 458 server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID); 459 if (server_id_opt) { 460 uint32_t server_id_network_order; 461 move_from_unaligned32(server_id_network_order, server_id_opt); 462 if (server_id_network_order != server_config.server_nip) { 463 /* client talks to somebody else */ 464 log1("server ID doesn't match, ignoring"); 465 continue; 466 } 444 467 } 445 468 … … 456 479 } 457 480 458 /* Get REQUESTED_IP and SERVER_ID if present */ 459 server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID); 460 if (server_id_opt) { 461 uint32_t server_id_net; 462 move_from_unaligned32(server_id_net, server_id_opt); 463 if (server_id_net != server_config.server_nip) { 464 /* client talks to somebody else */ 465 log1("server ID doesn't match, ignoring"); 466 continue; 467 } 468 } 469 requested_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP); 470 if (requested_opt) { 471 move_from_unaligned32(requested_nip, requested_opt); 481 /* Get REQUESTED_IP if present */ 482 requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP); 483 if (requested_ip_opt) { 484 move_from_unaligned32(requested_nip, requested_ip_opt); 472 485 } 473 486 … … 477 490 log1("Received DISCOVER"); 478 491 479 send_offer(&packet, static_lease_nip, lease );492 send_offer(&packet, static_lease_nip, lease, requested_ip_opt); 480 493 break; 481 494 … … 568 581 administrative authority to do so. 569 582 */ 570 if (!requested_ opt) {583 if (!requested_ip_opt) { 571 584 requested_nip = packet.ciaddr; 572 585 if (requested_nip == 0) { … … 581 594 break; 582 595 } 583 if (server_id_opt) { 584 /* client was talking specifically to us. 585 * "No, we don't have this IP for you". */ 596 /* No lease for this MAC, or lease IP != requested IP */ 597 598 if (server_id_opt /* client is in SELECTING state */ 599 || requested_ip_opt /* client is in INIT-REBOOT state */ 600 ) { 601 /* "No, we don't have this IP for you" */ 586 602 send_NAK(&packet); 587 } 603 } /* else: client is in RENEWING or REBINDING, do not answer */ 604 588 605 break; 589 606 … … 604 621 log1("Received DECLINE"); 605 622 if (server_id_opt 606 && requested_ opt623 && requested_ip_opt 607 624 && lease /* chaddr matches this lease */ 608 625 && requested_nip == lease->lease_nip
Note:
See TracChangeset
for help on using the changeset viewer.