aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/d6_dhcpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/d6_dhcpc.c')
-rw-r--r--networking/udhcp/d6_dhcpc.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 7f288f891..8d11a7539 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -479,15 +479,15 @@ static ALWAYS_INLINE uint32_t random_xid(void)
479} 479}
480 480
481/* Initialize the packet with the proper defaults */ 481/* Initialize the packet with the proper defaults */
482static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid) 482static uint8_t *init_d6_packet(struct d6_packet *packet, char type)
483{ 483{
484 uint8_t *ptr; 484 uint8_t *ptr;
485 unsigned secs; 485 unsigned secs;
486 486
487 memset(packet, 0, sizeof(*packet)); 487 memset(packet, 0, sizeof(*packet));
488 488
489 packet->d6_xid32 = xid; 489 packet->d6_xid32 = client_data.xid;
490 packet->d6_msg_type = type; 490 packet->d6_msg_type = type; /* union, overwrites lowest byte of d6_xid32 */
491 491
492 /* ELAPSED_TIME option is required to be present by the RFC, 492 /* ELAPSED_TIME option is required to be present by the RFC,
493 * and some servers do check for its presense. [which?] 493 * and some servers do check for its presense. [which?]
@@ -585,13 +585,13 @@ static int d6_mcast_from_client_data_ifindex(struct d6_packet *packet, uint8_t *
585 * about parameter values the client would like to have returned. 585 * about parameter values the client would like to have returned.
586 */ 586 */
587/* NOINLINE: limit stack usage in caller */ 587/* NOINLINE: limit stack usage in caller */
588static NOINLINE int send_d6_info_request(uint32_t xid) 588static NOINLINE int send_d6_info_request(void)
589{ 589{
590 struct d6_packet packet; 590 struct d6_packet packet;
591 uint8_t *opt_ptr; 591 uint8_t *opt_ptr;
592 592
593 /* Fill in: msg type */ 593 /* Fill in: msg type, xid, ELAPSED_TIME */
594 opt_ptr = init_d6_packet(&packet, D6_MSG_INFORMATION_REQUEST, xid); 594 opt_ptr = init_d6_packet(&packet, D6_MSG_INFORMATION_REQUEST);
595 595
596 /* Add options: client-id, 596 /* Add options: client-id,
597 * "param req" option according to -O, options specified with -x 597 * "param req" option according to -O, options specified with -x
@@ -684,14 +684,14 @@ static NOINLINE int send_d6_info_request(uint32_t xid)
684 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 684 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
685 */ 685 */
686/* NOINLINE: limit stack usage in caller */ 686/* NOINLINE: limit stack usage in caller */
687static NOINLINE int send_d6_discover(uint32_t xid, struct in6_addr *requested_ipv6) 687static NOINLINE int send_d6_discover(struct in6_addr *requested_ipv6)
688{ 688{
689 struct d6_packet packet; 689 struct d6_packet packet;
690 uint8_t *opt_ptr; 690 uint8_t *opt_ptr;
691 unsigned len; 691 unsigned len;
692 692
693 /* Fill in: msg type */ 693 /* Fill in: msg type, xid, ELAPSED_TIME */
694 opt_ptr = init_d6_packet(&packet, D6_MSG_SOLICIT, xid); 694 opt_ptr = init_d6_packet(&packet, D6_MSG_SOLICIT);
695 695
696 /* Create new IA_NA, optionally with included IAADDR with requested IP */ 696 /* Create new IA_NA, optionally with included IAADDR with requested IP */
697 free(client6_data.ia_na); 697 free(client6_data.ia_na);
@@ -763,13 +763,13 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct in6_addr *requested_ip
763 * messages from the server. 763 * messages from the server.
764 */ 764 */
765/* NOINLINE: limit stack usage in caller */ 765/* NOINLINE: limit stack usage in caller */
766static NOINLINE int send_d6_select(uint32_t xid) 766static NOINLINE int send_d6_select(void)
767{ 767{
768 struct d6_packet packet; 768 struct d6_packet packet;
769 uint8_t *opt_ptr; 769 uint8_t *opt_ptr;
770 770
771 /* Fill in: msg type */ 771 /* Fill in: msg type, xid, ELAPSED_TIME */
772 opt_ptr = init_d6_packet(&packet, D6_MSG_REQUEST, xid); 772 opt_ptr = init_d6_packet(&packet, D6_MSG_REQUEST);
773 773
774 /* server id */ 774 /* server id */
775 opt_ptr = mempcpy(opt_ptr, client6_data.server_id, client6_data.server_id->len + 2+2); 775 opt_ptr = mempcpy(opt_ptr, client6_data.server_id, client6_data.server_id->len + 2+2);
@@ -836,13 +836,13 @@ static NOINLINE int send_d6_select(uint32_t xid)
836 * about parameter values the client would like to have returned. 836 * about parameter values the client would like to have returned.
837 */ 837 */
838/* NOINLINE: limit stack usage in caller */ 838/* NOINLINE: limit stack usage in caller */
839static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) 839static NOINLINE int send_d6_renew(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6)
840{ 840{
841 struct d6_packet packet; 841 struct d6_packet packet;
842 uint8_t *opt_ptr; 842 uint8_t *opt_ptr;
843 843
844 /* Fill in: msg type */ 844 /* Fill in: msg type, xid, ELAPSED_TIME */
845 opt_ptr = init_d6_packet(&packet, DHCPREQUEST, xid); 845 opt_ptr = init_d6_packet(&packet, DHCPREQUEST);
846 846
847 /* server id */ 847 /* server id */
848 opt_ptr = mempcpy(opt_ptr, client6_data.server_id, client6_data.server_id->len + 2+2); 848 opt_ptr = mempcpy(opt_ptr, client6_data.server_id, client6_data.server_id->len + 2+2);
@@ -877,8 +877,8 @@ int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6)
877 uint8_t *opt_ptr; 877 uint8_t *opt_ptr;
878 struct option_set *ci; 878 struct option_set *ci;
879 879
880 /* Fill in: msg type, client id */ 880 /* Fill in: msg type, xid, ELAPSED_TIME */
881 opt_ptr = init_d6_packet(&packet, D6_MSG_RELEASE, random_xid()); 881 opt_ptr = init_d6_packet(&packet, D6_MSG_RELEASE);
882 /* server id */ 882 /* server id */
883 opt_ptr = mempcpy(opt_ptr, client6_data.server_id, client6_data.server_id->len + 2+2); 883 opt_ptr = mempcpy(opt_ptr, client6_data.server_id, client6_data.server_id->len + 2+2);
884 /* IA NA (contains our current IP) */ 884 /* IA NA (contains our current IP) */
@@ -1097,6 +1097,7 @@ static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *ou
1097 || client_data.state == RENEW_REQUESTED 1097 || client_data.state == RENEW_REQUESTED
1098 ) { 1098 ) {
1099 bb_simple_info_msg("unicasting a release"); 1099 bb_simple_info_msg("unicasting a release");
1100 client_data.xid = random_xid(); //TODO: can omit?
1100 send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */ 1101 send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */
1101 } 1102 }
1102 bb_simple_info_msg("entering released state"); 1103 bb_simple_info_msg("entering released state");
@@ -1126,23 +1127,23 @@ static void client_background(void)
1126//usage:# define IF_UDHCP_VERBOSE(...) 1127//usage:# define IF_UDHCP_VERBOSE(...)
1127//usage:#endif 1128//usage:#endif
1128//usage:#define udhcpc6_trivial_usage 1129//usage:#define udhcpc6_trivial_usage
1129//usage: "[-fbnq"IF_UDHCP_VERBOSE("v")"odR] [-i IFACE] [-r IPv6] [-s PROG] [-p PIDFILE]\n" 1130//usage: "[-fbq"IF_UDHCP_VERBOSE("v")"R] [-t N] [-T SEC] [-A SEC|-n] [-i IFACE] [-s PROG]\n"
1130//usage: " [-x OPT:VAL]... [-O OPT]..." IF_FEATURE_UDHCP_PORT(" [-P PORT]") 1131//usage: " [-p PIDFILE]"IF_FEATURE_UDHCP_PORT(" [-P PORT]")" [-ldo] [-r IPv6] [-x OPT:VAL]... [-O OPT]..."
1131//usage:#define udhcpc6_full_usage "\n" 1132//usage:#define udhcpc6_full_usage "\n"
1132//usage: "\n -i IFACE Interface to use (default "CONFIG_UDHCPC_DEFAULT_INTERFACE")" 1133//usage: "\n -i IFACE Interface to use (default "CONFIG_UDHCPC_DEFAULT_INTERFACE")"
1133//usage: "\n -p FILE Create pidfile" 1134//usage: "\n -p FILE Create pidfile"
1134//usage: "\n -s PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" 1135//usage: "\n -s PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")"
1135//usage: "\n -B Request broadcast replies" 1136//usage: "\n -B Request broadcast replies"
1136//usage: "\n -t N Send up to N discover packets" 1137//usage: "\n -t N Send up to N discover packets"
1137//usage: "\n -T N Pause between packets (default 3 seconds)" 1138//usage: "\n -T SEC Pause between packets (default 3)"
1138//usage: "\n -A N Wait N seconds (default 20) after failure" 1139//usage: "\n -A SEC Wait if lease is not obtained (default 20)"
1139//usage: "\n -f Run in foreground"
1140//usage: USE_FOR_MMU( 1140//usage: USE_FOR_MMU(
1141//usage: "\n -b Background if lease is not obtained" 1141//usage: "\n -b Background if lease is not obtained"
1142//usage: ) 1142//usage: )
1143//usage: "\n -n Exit if lease is not obtained" 1143//usage: "\n -n Exit if lease is not obtained"
1144//usage: "\n -q Exit after obtaining lease" 1144//usage: "\n -q Exit after obtaining lease"
1145//usage: "\n -R Release IP on exit" 1145//usage: "\n -R Release IP on exit"
1146//usage: "\n -f Run in foreground"
1146//usage: "\n -S Log to syslog too" 1147//usage: "\n -S Log to syslog too"
1147//usage: IF_FEATURE_UDHCP_PORT( 1148//usage: IF_FEATURE_UDHCP_PORT(
1148//usage: "\n -P PORT Use PORT (default 546)" 1149//usage: "\n -P PORT Use PORT (default 546)"
@@ -1150,12 +1151,12 @@ static void client_background(void)
1150////usage: IF_FEATURE_UDHCPC_ARPING( 1151////usage: IF_FEATURE_UDHCPC_ARPING(
1151////usage: "\n -a Use arping to validate offered address" 1152////usage: "\n -a Use arping to validate offered address"
1152////usage: ) 1153////usage: )
1153//usage: "\n -O OPT Request option OPT from server (cumulative)"
1154//usage: "\n -o Don't request any options (unless -O is given)"
1155//usage: "\n -r IPv6 Request this address ('no' to not request any IP)"
1156//usage: "\n -d Request prefix"
1157//usage: "\n -l Send 'information request' instead of 'solicit'" 1154//usage: "\n -l Send 'information request' instead of 'solicit'"
1158//usage: "\n (used for servers which do not assign IPv6 addresses)" 1155//usage: "\n (used for servers which do not assign IPv6 addresses)"
1156//usage: "\n -r IPv6 Request this address ('no' to not request any IP)"
1157//usage: "\n -d Request prefix"
1158//usage: "\n -o Don't request any options (unless -O is given)"
1159//usage: "\n -O OPT Request option OPT from server (cumulative)"
1159//usage: "\n -x OPT:VAL Include option OPT in sent packets (cumulative)" 1160//usage: "\n -x OPT:VAL Include option OPT in sent packets (cumulative)"
1160//usage: "\n Examples of string, numeric, and hex byte opts:" 1161//usage: "\n Examples of string, numeric, and hex byte opts:"
1161//usage: "\n -x hostname:bbox - option 12" 1162//usage: "\n -x hostname:bbox - option 12"
@@ -1183,7 +1184,6 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1183 struct in6_addr srv6_buf; 1184 struct in6_addr srv6_buf;
1184 struct in6_addr ipv6_buf; 1185 struct in6_addr ipv6_buf;
1185 struct in6_addr *requested_ipv6; 1186 struct in6_addr *requested_ipv6;
1186 uint32_t xid = 0;
1187 int packet_num; 1187 int packet_num;
1188 int timeout; /* must be signed */ 1188 int timeout; /* must be signed */
1189 int lease_remaining; /* must be signed */ 1189 int lease_remaining; /* must be signed */
@@ -1387,13 +1387,13 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1387 if (!discover_retries || packet_num < discover_retries) { 1387 if (!discover_retries || packet_num < discover_retries) {
1388 if (packet_num == 0) { 1388 if (packet_num == 0) {
1389 change_listen_mode(LISTEN_RAW); 1389 change_listen_mode(LISTEN_RAW);
1390 xid = random_xid(); 1390 client_data.xid = random_xid();
1391 } 1391 }
1392 /* multicast */ 1392 /* multicast */
1393 if (opt & OPT_l) 1393 if (opt & OPT_l)
1394 send_d6_info_request(xid); 1394 send_d6_info_request();
1395 else 1395 else
1396 send_d6_discover(xid, requested_ipv6); 1396 send_d6_discover(requested_ipv6);
1397 timeout = discover_timeout; 1397 timeout = discover_timeout;
1398 packet_num++; 1398 packet_num++;
1399 continue; 1399 continue;
@@ -1427,7 +1427,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1427 case REQUESTING: 1427 case REQUESTING:
1428 if (!discover_retries || packet_num < discover_retries) { 1428 if (!discover_retries || packet_num < discover_retries) {
1429 /* send multicast select packet */ 1429 /* send multicast select packet */
1430 send_d6_select(xid); 1430 send_d6_select();
1431 timeout = discover_timeout; 1431 timeout = discover_timeout;
1432 packet_num++; 1432 packet_num++;
1433 continue; 1433 continue;
@@ -1459,9 +1459,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1459 * into INIT_SELECTING state. 1459 * into INIT_SELECTING state.
1460 */ 1460 */
1461 if (opt & OPT_l) 1461 if (opt & OPT_l)
1462 send_d6_info_request(xid); 1462 send_d6_info_request();
1463 else 1463 else
1464 send_d6_renew(xid, &srv6_buf, requested_ipv6); 1464 send_d6_renew(&srv6_buf, requested_ipv6);
1465 timeout = discover_timeout; 1465 timeout = discover_timeout;
1466 packet_num++; 1466 packet_num++;
1467 continue; 1467 continue;
@@ -1484,9 +1484,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1484 * try to find DHCP server using broadcast */ 1484 * try to find DHCP server using broadcast */
1485 if (lease_remaining > 0 && packet_num < 3) { 1485 if (lease_remaining > 0 && packet_num < 3) {
1486 if (opt & OPT_l) 1486 if (opt & OPT_l)
1487 send_d6_info_request(xid); 1487 send_d6_info_request();
1488 else /* send a broadcast renew request */ 1488 else /* send a broadcast renew request */
1489 send_d6_renew(xid, /*server_ipv6:*/ NULL, requested_ipv6); 1489 send_d6_renew(/*server_ipv6:*/ NULL, requested_ipv6);
1490 timeout = discover_timeout; 1490 timeout = discover_timeout;
1491 packet_num++; 1491 packet_num++;
1492 continue; 1492 continue;
@@ -1581,9 +1581,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1581 packet_end = (uint8_t*)&packet + len; 1581 packet_end = (uint8_t*)&packet + len;
1582 } 1582 }
1583 1583
1584 if ((packet.d6_xid32 & htonl(0x00ffffff)) != xid) { 1584 if ((packet.d6_xid32 & htonl(0x00ffffff)) != client_data.xid) {
1585 log1("xid %x (our is %x)%s", 1585 log1("xid %x (our is %x)%s",
1586 (unsigned)(packet.d6_xid32 & htonl(0x00ffffff)), (unsigned)xid, 1586 (unsigned)(packet.d6_xid32 & htonl(0x00ffffff)), (unsigned)client_data.xid,
1587 ", ignoring packet" 1587 ", ignoring packet"
1588 ); 1588 );
1589 continue; 1589 continue;