diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-06-28 19:18:17 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-06-28 19:18:17 +0200 |
commit | ba4fbca8a81d765f81aefc74db7f73ec9ded3550 (patch) | |
tree | 3790acaa5ef3c682831aa15428beb313eea5dcb7 /networking/udhcp/common.c | |
parent | ae2b9f286c985394410aec19b12c1ebecfbe20f6 (diff) | |
download | busybox-w32-ba4fbca8a81d765f81aefc74db7f73ec9ded3550.tar.gz busybox-w32-ba4fbca8a81d765f81aefc74db7f73ec9ded3550.tar.bz2 busybox-w32-ba4fbca8a81d765f81aefc74db7f73ec9ded3550.zip |
udhcpc6: make -O OPT work
Patch is based on work by tiggerswelt.net.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r-- | networking/udhcp/common.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 420695a20..d3eea5def 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -14,6 +14,7 @@ const uint8_t MAC_BCAST_ADDR[6] ALIGN2 = { | |||
14 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | 14 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
15 | }; | 15 | }; |
16 | 16 | ||
17 | #if ENABLE_UDHCPC || ENABLE_UDHCPD | ||
17 | /* Supported options are easily added here. | 18 | /* Supported options are easily added here. |
18 | * See RFC2132 for more options. | 19 | * See RFC2132 for more options. |
19 | * OPTION_REQ: these options are requested by udhcpc (unless -o). | 20 | * OPTION_REQ: these options are requested by udhcpc (unless -o). |
@@ -136,6 +137,7 @@ const char dhcp_option_strings[] ALIGN1 = | |||
136 | "msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */ | 137 | "msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */ |
137 | "wpad" "\0" /* DHCP_WPAD */ | 138 | "wpad" "\0" /* DHCP_WPAD */ |
138 | ; | 139 | ; |
140 | #endif | ||
139 | 141 | ||
140 | /* Lengths of the option types in binary form. | 142 | /* Lengths of the option types in binary form. |
141 | * Used by: | 143 | * Used by: |
@@ -190,21 +192,26 @@ static void log_option(const char *pfx, const uint8_t *opt) | |||
190 | # define log_option(pfx, opt) ((void)0) | 192 | # define log_option(pfx, opt) ((void)0) |
191 | #endif | 193 | #endif |
192 | 194 | ||
193 | unsigned FAST_FUNC udhcp_option_idx(const char *name) | 195 | unsigned FAST_FUNC udhcp_option_idx(const char *name, const char *option_strings) |
194 | { | 196 | { |
195 | int n = index_in_strings(dhcp_option_strings, name); | 197 | int n = index_in_strings(option_strings, name); |
196 | if (n >= 0) | 198 | if (n >= 0) |
197 | return n; | 199 | return n; |
198 | 200 | ||
199 | { | 201 | { |
200 | char buf[sizeof(dhcp_option_strings)]; | 202 | char *buf, *d; |
201 | char *d = buf; | 203 | const char *s; |
202 | const char *s = dhcp_option_strings; | 204 | |
203 | while (s < dhcp_option_strings + sizeof(dhcp_option_strings) - 2) { | 205 | s = option_strings; |
206 | while (*s) | ||
207 | s += strlen(s) + 1; | ||
208 | |||
209 | d = buf = xzalloc(s - option_strings); | ||
210 | s = option_strings; | ||
211 | while (!(*s == '\0' && s[1] == '\0')) { | ||
204 | *d++ = (*s == '\0' ? ' ' : *s); | 212 | *d++ = (*s == '\0' ? ' ' : *s); |
205 | s++; | 213 | s++; |
206 | } | 214 | } |
207 | *d = '\0'; | ||
208 | bb_error_msg_and_die("unknown option '%s', known options: %s", name, buf); | 215 | bb_error_msg_and_die("unknown option '%s', known options: %s", name, buf); |
209 | } | 216 | } |
210 | } | 217 | } |
@@ -315,6 +322,7 @@ void FAST_FUNC udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addo | |||
315 | optionptr[end + len] = DHCP_END; | 322 | optionptr[end + len] = DHCP_END; |
316 | } | 323 | } |
317 | 324 | ||
325 | #if ENABLE_UDHCPC || ENABLE_UDHCPD | ||
318 | /* Add an one to four byte option to a packet */ | 326 | /* Add an one to four byte option to a packet */ |
319 | void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, uint32_t data) | 327 | void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, uint32_t data) |
320 | { | 328 | { |
@@ -338,6 +346,7 @@ void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, | |||
338 | 346 | ||
339 | bb_error_msg("can't add option 0x%02x", code); | 347 | bb_error_msg("can't add option 0x%02x", code); |
340 | } | 348 | } |
349 | #endif | ||
341 | 350 | ||
342 | /* Find option 'code' in opt_list */ | 351 | /* Find option 'code' in opt_list */ |
343 | struct option_set* FAST_FUNC udhcp_find_option(struct option_set *opt_list, uint8_t code) | 352 | struct option_set* FAST_FUNC udhcp_find_option(struct option_set *opt_list, uint8_t code) |
@@ -451,7 +460,7 @@ static NOINLINE void attach_option( | |||
451 | free(allocated); | 460 | free(allocated); |
452 | } | 461 | } |
453 | 462 | ||
454 | int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg) | 463 | int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, const struct dhcp_optflag *optflags, const char *option_strings) |
455 | { | 464 | { |
456 | struct option_set **opt_list = arg; | 465 | struct option_set **opt_list = arg; |
457 | char *opt, *val; | 466 | char *opt, *val; |
@@ -478,7 +487,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg) | |||
478 | bin_optflag.code = optcode; | 487 | bin_optflag.code = optcode; |
479 | optflag = &bin_optflag; | 488 | optflag = &bin_optflag; |
480 | } else { | 489 | } else { |
481 | optflag = &dhcp_optflags[udhcp_option_idx(opt)]; | 490 | optflag = &optflags[udhcp_option_idx(opt, option_strings)]; |
482 | } | 491 | } |
483 | 492 | ||
484 | retval = 0; | 493 | retval = 0; |