diff options
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index b80ea2f40..1c3c478ac 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -605,7 +605,7 @@ static void init_packet(struct dhcp_packet *packet, char type) | |||
605 | /* Fill in: op, htype, hlen, cookie fields; message type option: */ | 605 | /* Fill in: op, htype, hlen, cookie fields; message type option: */ |
606 | udhcp_init_header(packet, type); | 606 | udhcp_init_header(packet, type); |
607 | 607 | ||
608 | packet->xid = random_xid(); | 608 | packet->xid = client_data.xid; |
609 | 609 | ||
610 | client_data.last_secs = monotonic_sec(); | 610 | client_data.last_secs = monotonic_sec(); |
611 | if (client_data.first_secs == 0) | 611 | if (client_data.first_secs == 0) |
@@ -719,17 +719,15 @@ static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t | |||
719 | 719 | ||
720 | /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ | 720 | /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ |
721 | /* NOINLINE: limit stack usage in caller */ | 721 | /* NOINLINE: limit stack usage in caller */ |
722 | static NOINLINE int send_discover(uint32_t xid, uint32_t requested) | 722 | static NOINLINE int send_discover(uint32_t requested) |
723 | { | 723 | { |
724 | struct dhcp_packet packet; | 724 | struct dhcp_packet packet; |
725 | 725 | ||
726 | /* Fill in: op, htype, hlen, cookie, chaddr fields, | 726 | /* Fill in: op, htype, hlen, cookie, chaddr fields, |
727 | * random xid field (we override it below), | 727 | * xid field, message type option: |
728 | * message type option: | ||
729 | */ | 728 | */ |
730 | init_packet(&packet, DHCPDISCOVER); | 729 | init_packet(&packet, DHCPDISCOVER); |
731 | 730 | ||
732 | packet.xid = xid; | ||
733 | if (requested) | 731 | if (requested) |
734 | udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); | 732 | udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); |
735 | 733 | ||
@@ -747,7 +745,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) | |||
747 | * "The client _broadcasts_ a DHCPREQUEST message..." | 745 | * "The client _broadcasts_ a DHCPREQUEST message..." |
748 | */ | 746 | */ |
749 | /* NOINLINE: limit stack usage in caller */ | 747 | /* NOINLINE: limit stack usage in caller */ |
750 | static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requested) | 748 | static NOINLINE int send_select(uint32_t server, uint32_t requested) |
751 | { | 749 | { |
752 | struct dhcp_packet packet; | 750 | struct dhcp_packet packet; |
753 | struct in_addr temp_addr; | 751 | struct in_addr temp_addr; |
@@ -766,12 +764,10 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste | |||
766 | * include that list in all subsequent messages. | 764 | * include that list in all subsequent messages. |
767 | */ | 765 | */ |
768 | /* Fill in: op, htype, hlen, cookie, chaddr fields, | 766 | /* Fill in: op, htype, hlen, cookie, chaddr fields, |
769 | * random xid field (we override it below), | 767 | * xid field, message type option: |
770 | * message type option: | ||
771 | */ | 768 | */ |
772 | init_packet(&packet, DHCPREQUEST); | 769 | init_packet(&packet, DHCPREQUEST); |
773 | 770 | ||
774 | packet.xid = xid; | ||
775 | udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); | 771 | udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); |
776 | 772 | ||
777 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); | 773 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); |
@@ -793,7 +789,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste | |||
793 | 789 | ||
794 | /* Unicast or broadcast a DHCP renew message */ | 790 | /* Unicast or broadcast a DHCP renew message */ |
795 | /* NOINLINE: limit stack usage in caller */ | 791 | /* NOINLINE: limit stack usage in caller */ |
796 | static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) | 792 | static NOINLINE int send_renew(uint32_t server, uint32_t ciaddr) |
797 | { | 793 | { |
798 | struct dhcp_packet packet; | 794 | struct dhcp_packet packet; |
799 | 795 | ||
@@ -812,12 +808,10 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) | |||
812 | * replying to the client. | 808 | * replying to the client. |
813 | */ | 809 | */ |
814 | /* Fill in: op, htype, hlen, cookie, chaddr fields, | 810 | /* Fill in: op, htype, hlen, cookie, chaddr fields, |
815 | * random xid field (we override it below), | 811 | * xid field, message type option: |
816 | * message type option: | ||
817 | */ | 812 | */ |
818 | init_packet(&packet, DHCPREQUEST); | 813 | init_packet(&packet, DHCPREQUEST); |
819 | 814 | ||
820 | packet.xid = xid; | ||
821 | packet.ciaddr = ciaddr; | 815 | packet.ciaddr = ciaddr; |
822 | 816 | ||
823 | /* Add options: maxsize, | 817 | /* Add options: maxsize, |
@@ -839,7 +833,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) | |||
839 | #if ENABLE_FEATURE_UDHCPC_ARPING | 833 | #if ENABLE_FEATURE_UDHCPC_ARPING |
840 | /* Broadcast a DHCP decline message */ | 834 | /* Broadcast a DHCP decline message */ |
841 | /* NOINLINE: limit stack usage in caller */ | 835 | /* NOINLINE: limit stack usage in caller */ |
842 | static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t requested) | 836 | static NOINLINE int send_decline(uint32_t server, uint32_t requested) |
843 | { | 837 | { |
844 | struct dhcp_packet packet; | 838 | struct dhcp_packet packet; |
845 | 839 | ||
@@ -848,14 +842,6 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req | |||
848 | */ | 842 | */ |
849 | init_packet(&packet, DHCPDECLINE); | 843 | init_packet(&packet, DHCPDECLINE); |
850 | 844 | ||
851 | #if 0 | ||
852 | /* RFC 2131 says DHCPDECLINE's xid is randomly selected by client, | ||
853 | * but in case the server is buggy and wants DHCPDECLINE's xid | ||
854 | * to match the xid which started entire handshake, | ||
855 | * we use the same xid we used in initial DHCPDISCOVER: | ||
856 | */ | ||
857 | packet.xid = xid; | ||
858 | #endif | ||
859 | /* DHCPDECLINE uses "requested ip", not ciaddr, to store offered IP */ | 845 | /* DHCPDECLINE uses "requested ip", not ciaddr, to store offered IP */ |
860 | udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); | 846 | udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); |
861 | 847 | ||
@@ -1145,6 +1131,7 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) | |||
1145 | temp_addr.s_addr = requested_ip; | 1131 | temp_addr.s_addr = requested_ip; |
1146 | bb_info_msg("unicasting a release of %s to %s", | 1132 | bb_info_msg("unicasting a release of %s to %s", |
1147 | inet_ntoa(temp_addr), buffer); | 1133 | inet_ntoa(temp_addr), buffer); |
1134 | client_data.xid = random_xid(); //TODO: can omit? | ||
1148 | send_release(server_addr, requested_ip); /* unicast */ | 1135 | send_release(server_addr, requested_ip); /* unicast */ |
1149 | } | 1136 | } |
1150 | bb_simple_info_msg("entering released state"); | 1137 | bb_simple_info_msg("entering released state"); |
@@ -1233,7 +1220,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1233 | int discover_retries = 3; | 1220 | int discover_retries = 3; |
1234 | uint32_t server_addr = server_addr; /* for compiler */ | 1221 | uint32_t server_addr = server_addr; /* for compiler */ |
1235 | uint32_t requested_ip = 0; | 1222 | uint32_t requested_ip = 0; |
1236 | uint32_t xid = xid; /* for compiler */ | ||
1237 | int packet_num; | 1223 | int packet_num; |
1238 | int timeout; /* must be signed */ | 1224 | int timeout; /* must be signed */ |
1239 | int lease_remaining; /* must be signed */ | 1225 | int lease_remaining; /* must be signed */ |
@@ -1458,10 +1444,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1458 | if (!discover_retries || packet_num < discover_retries) { | 1444 | if (!discover_retries || packet_num < discover_retries) { |
1459 | if (packet_num == 0) { | 1445 | if (packet_num == 0) { |
1460 | change_listen_mode(LISTEN_RAW); | 1446 | change_listen_mode(LISTEN_RAW); |
1461 | xid = random_xid(); | 1447 | client_data.xid = random_xid(); |
1462 | } | 1448 | } |
1463 | /* broadcast */ | 1449 | /* broadcast */ |
1464 | send_discover(xid, requested_ip); | 1450 | send_discover(requested_ip); |
1465 | timeout = discover_timeout; | 1451 | timeout = discover_timeout; |
1466 | packet_num++; | 1452 | packet_num++; |
1467 | continue; | 1453 | continue; |
@@ -1495,7 +1481,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1495 | case REQUESTING: | 1481 | case REQUESTING: |
1496 | if (packet_num < 3) { | 1482 | if (packet_num < 3) { |
1497 | /* send broadcast select packet */ | 1483 | /* send broadcast select packet */ |
1498 | send_select(xid, server_addr, requested_ip); | 1484 | send_select(server_addr, requested_ip); |
1499 | timeout = discover_timeout; | 1485 | timeout = discover_timeout; |
1500 | packet_num++; | 1486 | packet_num++; |
1501 | continue; | 1487 | continue; |
@@ -1526,7 +1512,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1526 | * Anyway, it does recover by eventually failing through | 1512 | * Anyway, it does recover by eventually failing through |
1527 | * into INIT_SELECTING state. | 1513 | * into INIT_SELECTING state. |
1528 | */ | 1514 | */ |
1529 | if (send_renew(xid, server_addr, requested_ip) >= 0) { | 1515 | if (send_renew(server_addr, requested_ip) >= 0) { |
1530 | timeout = discover_timeout; | 1516 | timeout = discover_timeout; |
1531 | packet_num++; | 1517 | packet_num++; |
1532 | continue; | 1518 | continue; |
@@ -1555,7 +1541,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1555 | * try to find DHCP server using broadcast */ | 1541 | * try to find DHCP server using broadcast */ |
1556 | if (lease_remaining > 0 && packet_num < 3) { | 1542 | if (lease_remaining > 0 && packet_num < 3) { |
1557 | /* send a broadcast renew request */ | 1543 | /* send a broadcast renew request */ |
1558 | send_renew(xid, 0 /*INADDR_ANY*/, requested_ip); | 1544 | send_renew(0 /*INADDR_ANY*/, requested_ip); |
1559 | timeout = discover_timeout; | 1545 | timeout = discover_timeout; |
1560 | packet_num++; | 1546 | packet_num++; |
1561 | continue; | 1547 | continue; |
@@ -1648,9 +1634,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1648 | continue; | 1634 | continue; |
1649 | } | 1635 | } |
1650 | 1636 | ||
1651 | if (packet.xid != xid) { | 1637 | if (packet.xid != client_data.xid) { |
1652 | log1("xid %x (our is %x)%s", | 1638 | log1("xid %x (our is %x)%s", |
1653 | (unsigned)packet.xid, (unsigned)xid, | 1639 | (unsigned)packet.xid, (unsigned)client_data.xid, |
1654 | ", ignoring packet" | 1640 | ", ignoring packet" |
1655 | ); | 1641 | ); |
1656 | continue; | 1642 | continue; |
@@ -1779,7 +1765,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1779 | ) { | 1765 | ) { |
1780 | bb_simple_info_msg("offered address is in use " | 1766 | bb_simple_info_msg("offered address is in use " |
1781 | "(got ARP reply), declining"); | 1767 | "(got ARP reply), declining"); |
1782 | send_decline(/*xid,*/ server_addr, packet.yiaddr); | 1768 | client_data.xid = random_xid(); //TODO: can omit? |
1769 | send_decline(server_addr, packet.yiaddr); | ||
1783 | 1770 | ||
1784 | if (client_data.state != REQUESTING) | 1771 | if (client_data.state != REQUESTING) |
1785 | d4_run_script_deconfig(); | 1772 | d4_run_script_deconfig(); |
@@ -1814,7 +1801,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1814 | timeout = (unsigned)lease_remaining / 2; | 1801 | timeout = (unsigned)lease_remaining / 2; |
1815 | client_data.state = BOUND; | 1802 | client_data.state = BOUND; |
1816 | /* make future renew packets use different xid */ | 1803 | /* make future renew packets use different xid */ |
1817 | /* xid = random_xid(); ...but why bother? */ | 1804 | /* client_data.xid = random_xid(); ...but why bother? */ |
1818 | packet_num = 0; | 1805 | packet_num = 0; |
1819 | continue; /* back to main loop */ | 1806 | continue; /* back to main loop */ |
1820 | } | 1807 | } |