diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-25 20:32:38 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-25 20:32:38 +0100 |
commit | 7e6add1dfca95183bf409820066fab975979bf06 (patch) | |
tree | 0da56954d93e9b10e956235a32f0d0644a60063b /networking/udhcp/dhcpc.c | |
parent | 0454d9d6c314f381eee8022ad4e7447d2fa1dcf1 (diff) | |
download | busybox-w32-7e6add1dfca95183bf409820066fab975979bf06.tar.gz busybox-w32-7e6add1dfca95183bf409820066fab975979bf06.tar.bz2 busybox-w32-7e6add1dfca95183bf409820066fab975979bf06.zip |
udhcpc: add -x OPT:VAL option
function old new delta
udhcp_str2optset - 443 +443
add_client_options - 160 +160
udhcpc_main 2753 2857 +104
packed_usage 26670 26689 +19
attach_option 380 385 +5
udhcpd_main 1964 1965 +1
udhcp_add_option_string 94 86 -8
add_param_req_option 128 - -128
read_opt 443 - -443
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 4/1 up/down: 732/-579) Total: 153 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 758750907..4565d7fd2 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -331,11 +331,11 @@ static void init_packet(struct dhcp_packet *packet, char type) | |||
331 | } | 331 | } |
332 | } | 332 | } |
333 | 333 | ||
334 | /* Add a parameter request list for stubborn DHCP servers. Pull the data | 334 | static void add_client_options(struct dhcp_packet *packet) |
335 | * from the struct in options.c. Don't do bounds checking here because it | ||
336 | * goes towards the head of the packet. */ | ||
337 | static void add_param_req_option(struct dhcp_packet *packet) | ||
338 | { | 335 | { |
336 | /* Add am "param req" option with the list of options we'd like to have | ||
337 | * from stubborn DHCP servers. Pull the data from the struct in options.c. | ||
338 | * No bounds checking because it goes towards the head of the packet. */ | ||
339 | uint8_t c; | 339 | uint8_t c; |
340 | int end = udhcp_end_option(packet->options); | 340 | int end = udhcp_end_option(packet->options); |
341 | int i, len = 0; | 341 | int i, len = 0; |
@@ -355,6 +355,19 @@ static void add_param_req_option(struct dhcp_packet *packet) | |||
355 | packet->options[end + OPT_LEN] = len; | 355 | packet->options[end + OPT_LEN] = len; |
356 | packet->options[end + OPT_DATA + len] = DHCP_END; | 356 | packet->options[end + OPT_DATA + len] = DHCP_END; |
357 | } | 357 | } |
358 | |||
359 | /* Add -x options if any */ | ||
360 | { | ||
361 | struct option_set *curr = client_config.options; | ||
362 | while (curr) { | ||
363 | udhcp_add_option_string(packet->options, curr->data); | ||
364 | curr = curr->next; | ||
365 | } | ||
366 | // if (client_config.sname) | ||
367 | // strncpy((char*)packet->sname, client_config.sname, sizeof(packet->sname) - 1); | ||
368 | // if (client_config.boot_file) | ||
369 | // strncpy((char*)packet->file, client_config.boot_file, sizeof(packet->file) - 1); | ||
370 | } | ||
358 | } | 371 | } |
359 | 372 | ||
360 | /* RFC 2131 | 373 | /* RFC 2131 |
@@ -395,7 +408,7 @@ static int send_discover(uint32_t xid, uint32_t requested) | |||
395 | /* Explicitly saying that we want RFC-compliant packets helps | 408 | /* Explicitly saying that we want RFC-compliant packets helps |
396 | * some buggy DHCP servers to NOT send bigger packets */ | 409 | * some buggy DHCP servers to NOT send bigger packets */ |
397 | udhcp_add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576)); | 410 | udhcp_add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576)); |
398 | add_param_req_option(&packet); | 411 | add_client_options(&packet); |
399 | 412 | ||
400 | bb_info_msg("Sending discover..."); | 413 | bb_info_msg("Sending discover..."); |
401 | return raw_bcast_from_client_config_ifindex(&packet); | 414 | return raw_bcast_from_client_config_ifindex(&packet); |
@@ -414,7 +427,7 @@ static int send_select(uint32_t xid, uint32_t server, uint32_t requested) | |||
414 | packet.xid = xid; | 427 | packet.xid = xid; |
415 | udhcp_add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); | 428 | udhcp_add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); |
416 | udhcp_add_simple_option(packet.options, DHCP_SERVER_ID, server); | 429 | udhcp_add_simple_option(packet.options, DHCP_SERVER_ID, server); |
417 | add_param_req_option(&packet); | 430 | add_client_options(&packet); |
418 | 431 | ||
419 | addr.s_addr = requested; | 432 | addr.s_addr = requested; |
420 | bb_info_msg("Sending select for %s...", inet_ntoa(addr)); | 433 | bb_info_msg("Sending select for %s...", inet_ntoa(addr)); |
@@ -429,7 +442,7 @@ static int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) | |||
429 | init_packet(&packet, DHCPREQUEST); | 442 | init_packet(&packet, DHCPREQUEST); |
430 | packet.xid = xid; | 443 | packet.xid = xid; |
431 | packet.ciaddr = ciaddr; | 444 | packet.ciaddr = ciaddr; |
432 | add_param_req_option(&packet); | 445 | add_client_options(&packet); |
433 | 446 | ||
434 | bb_info_msg("Sending renew..."); | 447 | bb_info_msg("Sending renew..."); |
435 | if (server) | 448 | if (server) |
@@ -728,6 +741,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
728 | const char *str_c, *str_V, *str_h, *str_F, *str_r; | 741 | const char *str_c, *str_V, *str_h, *str_F, *str_r; |
729 | IF_FEATURE_UDHCP_PORT(char *str_P;) | 742 | IF_FEATURE_UDHCP_PORT(char *str_P;) |
730 | llist_t *list_O = NULL; | 743 | llist_t *list_O = NULL; |
744 | llist_t *list_x = NULL; | ||
731 | int tryagain_timeout = 20; | 745 | int tryagain_timeout = 20; |
732 | int discover_timeout = 3; | 746 | int discover_timeout = 3; |
733 | int discover_retries = 3; | 747 | int discover_retries = 3; |
@@ -792,9 +806,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
792 | OPT_A = 1 << 16, | 806 | OPT_A = 1 << 16, |
793 | OPT_O = 1 << 17, | 807 | OPT_O = 1 << 17, |
794 | OPT_o = 1 << 18, | 808 | OPT_o = 1 << 18, |
795 | OPT_f = 1 << 19, | 809 | OPT_x = 1 << 19, |
810 | OPT_f = 1 << 20, | ||
796 | /* The rest has variable bit positions, need to be clever */ | 811 | /* The rest has variable bit positions, need to be clever */ |
797 | OPTBIT_f = 19, | 812 | OPTBIT_f = 20, |
798 | USE_FOR_MMU( OPTBIT_b,) | 813 | USE_FOR_MMU( OPTBIT_b,) |
799 | IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) | 814 | IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) |
800 | IF_FEATURE_UDHCP_PORT( OPTBIT_P,) | 815 | IF_FEATURE_UDHCP_PORT( OPTBIT_P,) |
@@ -811,14 +826,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
811 | str_V = "udhcp "BB_VER; | 826 | str_V = "udhcp "BB_VER; |
812 | 827 | ||
813 | /* Parse command line */ | 828 | /* Parse command line */ |
814 | /* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */ | 829 | /* Cc: mutually exclusive; O,x: list; -T,-t,-A take numeric param */ |
815 | opt_complementary = "c--C:C--c:O::T+:t+:A+" | 830 | opt_complementary = "c--C:C--c:O::x::T+:t+:A+" |
816 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 | 831 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 |
817 | ":vv" | 832 | ":vv" |
818 | #endif | 833 | #endif |
819 | ; | 834 | ; |
820 | IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) | 835 | IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) |
821 | opt = getopt32(argv, "c:CV:H:h:F:i:np:qRr:s:T:t:SA:O:of" | 836 | opt = getopt32(argv, "c:CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:f" |
822 | USE_FOR_MMU("b") | 837 | USE_FOR_MMU("b") |
823 | IF_FEATURE_UDHCPC_ARPING("a") | 838 | IF_FEATURE_UDHCPC_ARPING("a") |
824 | IF_FEATURE_UDHCP_PORT("P:") | 839 | IF_FEATURE_UDHCP_PORT("P:") |
@@ -828,6 +843,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
828 | , &client_config.script /* s */ | 843 | , &client_config.script /* s */ |
829 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ | 844 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ |
830 | , &list_O | 845 | , &list_O |
846 | , &list_x | ||
831 | IF_FEATURE_UDHCP_PORT(, &str_P) | 847 | IF_FEATURE_UDHCP_PORT(, &str_P) |
832 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 | 848 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 |
833 | , &dhcp_verbose | 849 | , &dhcp_verbose |
@@ -868,6 +884,19 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
868 | n = dhcp_options[n].code; | 884 | n = dhcp_options[n].code; |
869 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 885 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); |
870 | } | 886 | } |
887 | while (list_x) { | ||
888 | int n; | ||
889 | char *optstr = llist_pop(&list_x); | ||
890 | char *colon = strchr(optstr, ':'); | ||
891 | if (colon) | ||
892 | *colon = '\0'; | ||
893 | n = index_in_strings(dhcp_option_strings, optstr); | ||
894 | if (n < 0) | ||
895 | bb_error_msg_and_die("unknown option '%s'", optstr); | ||
896 | if (colon) | ||
897 | *colon = ' '; | ||
898 | udhcp_str2optset(optstr, &client_config.options); | ||
899 | } | ||
871 | 900 | ||
872 | if (udhcp_read_interface(client_config.interface, | 901 | if (udhcp_read_interface(client_config.interface, |
873 | &client_config.ifindex, | 902 | &client_config.ifindex, |