aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-05-14 11:06:35 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-05-14 11:11:08 +0200
commit6027597fd1a1a9293818db4729625fff375bf907 (patch)
treea8a38d8459b6a87f0c2132a5c05c779d8c1f4eca
parent30f4d52ed17112f4fa340afe3bcaf305eeed36d9 (diff)
downloadbusybox-w32-6027597fd1a1a9293818db4729625fff375bf907.tar.gz
busybox-w32-6027597fd1a1a9293818db4729625fff375bf907.tar.bz2
busybox-w32-6027597fd1a1a9293818db4729625fff375bf907.zip
udhcpc6: set -x options in request
Last foru commits: function old new delta option_to_env 621 791 +170 .rodata 168351 168505 +154 attach_option 431 506 +75 add_d6_client_options 112 167 +55 d6_option_strings 30 84 +54 udhcp_str2optset 644 660 +16 d6_optflags 12 20 +8 udhcpc6_main 2590 2596 +6 udhcpc_main 2648 2651 +3 read_optset 15 18 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 10/0 up/down: 544/0) Total: 544 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/udhcp/common.c33
-rw-r--r--networking/udhcp/common.h11
-rw-r--r--networking/udhcp/d6_dhcpc.c14
-rw-r--r--networking/udhcp/dhcpc.c5
-rw-r--r--networking/udhcp/dhcpd.c5
5 files changed, 56 insertions, 12 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index b7c04da73..52ef875f0 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -379,12 +379,18 @@ int FAST_FUNC udhcp_str2nip(const char *str, void *arg)
379 * and to parse udhcpd.conf's "opt OPTNAME OPTVAL" directives. 379 * and to parse udhcpd.conf's "opt OPTNAME OPTVAL" directives.
380 */ 380 */
381/* helper: add an option to the opt_list */ 381/* helper: add an option to the opt_list */
382#if !ENABLE_UDHCPC6
383#define attach_option(opt_list, optflag, buffer, length, dhcpv6) \
384 attach_option(opt_list, optflag, buffer, length)
385#endif
382static NOINLINE void attach_option( 386static NOINLINE void attach_option(
383 struct option_set **opt_list, 387 struct option_set **opt_list,
384 const struct dhcp_optflag *optflag, 388 const struct dhcp_optflag *optflag,
385 char *buffer, 389 char *buffer,
386 int length) 390 int length,
391 bool dhcpv6)
387{ 392{
393 IF_NOT_UDHCPC6(bool dhcpv6 = 0;)
388 struct option_set *existing; 394 struct option_set *existing;
389 char *allocated = NULL; 395 char *allocated = NULL;
390 396
@@ -410,10 +416,21 @@ static NOINLINE void attach_option(
410 /* make a new option */ 416 /* make a new option */
411 log2("attaching option %02x to list", optflag->code); 417 log2("attaching option %02x to list", optflag->code);
412 new = xmalloc(sizeof(*new)); 418 new = xmalloc(sizeof(*new));
413 new->data = xmalloc(length + OPT_DATA); 419 if (!dhcpv6) {
414 new->data[OPT_CODE] = optflag->code; 420 new->data = xmalloc(length + OPT_DATA);
415 new->data[OPT_LEN] = length; 421 new->data[OPT_CODE] = optflag->code;
416 memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer), length); 422 new->data[OPT_LEN] = length;
423 memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer),
424 length);
425 } else {
426 new->data = xmalloc(length + D6_OPT_DATA);
427 new->data[D6_OPT_CODE] = optflag->code >> 8;
428 new->data[D6_OPT_CODE + 1] = optflag->code & 0xff;
429 new->data[D6_OPT_LEN] = length >> 8;
430 new->data[D6_OPT_LEN + 1] = length & 0xff;
431 memcpy(new->data + D6_OPT_DATA, (allocated ? allocated : buffer),
432 length);
433 }
417 434
418 curr = opt_list; 435 curr = opt_list;
419 while (*curr && (*curr)->data[OPT_CODE] < optflag->code) 436 while (*curr && (*curr)->data[OPT_CODE] < optflag->code)
@@ -450,7 +467,9 @@ static NOINLINE void attach_option(
450 free(allocated); 467 free(allocated);
451} 468}
452 469
453int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, const struct dhcp_optflag *optflags, const char *option_strings) 470int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg,
471 const struct dhcp_optflag *optflags, const char *option_strings,
472 bool dhcpv6)
454{ 473{
455 struct option_set **opt_list = arg; 474 struct option_set **opt_list = arg;
456 char *opt; 475 char *opt;
@@ -602,7 +621,7 @@ case_OPTION_STRING:
602 } 621 }
603 622
604 if (retval) 623 if (retval)
605 attach_option(opt_list, optflag, opt, length); 624 attach_option(opt_list, optflag, opt, length, dhcpv6);
606 } while (retval && (optflag->flags & OPTION_LIST)); 625 } while (retval && (optflag->flags & OPTION_LIST));
607 626
608 return retval; 627 return retval;
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 13059f106..5f890459c 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -164,6 +164,10 @@ enum {
164#define OPT_CODE 0 164#define OPT_CODE 0
165#define OPT_LEN 1 165#define OPT_LEN 1
166#define OPT_DATA 2 166#define OPT_DATA 2
167/* Offsets in option byte sequence for DHCPv6 */
168#define D6_OPT_CODE 0
169#define D6_OPT_LEN 2
170#define D6_OPT_DATA 4
167/* Bits in "overload" option */ 171/* Bits in "overload" option */
168#define OPTION_FIELD 0 172#define OPTION_FIELD 0
169#define FILE_FIELD 1 173#define FILE_FIELD 1
@@ -290,10 +294,15 @@ void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
290/* 2nd param is "uint32_t*" */ 294/* 2nd param is "uint32_t*" */
291int FAST_FUNC udhcp_str2nip(const char *str, void *arg); 295int FAST_FUNC udhcp_str2nip(const char *str, void *arg);
292/* 2nd param is "struct option_set**" */ 296/* 2nd param is "struct option_set**" */
297#if !ENABLE_UDHCPC6
298#define udhcp_str2optset(str, arg, optflags, option_strings, dhcpv6) \
299 udhcp_str2optset(str, arg, optflags, option_strings)
300#endif
293int FAST_FUNC udhcp_str2optset(const char *str, 301int FAST_FUNC udhcp_str2optset(const char *str,
294 void *arg, 302 void *arg,
295 const struct dhcp_optflag *optflags, 303 const struct dhcp_optflag *optflags,
296 const char *option_strings); 304 const char *option_strings,
305 bool dhcpv6);
297 306
298#if ENABLE_UDHCPC || ENABLE_UDHCPD 307#if ENABLE_UDHCPC || ENABLE_UDHCPD
299void udhcp_init_header(struct dhcp_packet *packet, char type) FAST_FUNC; 308void udhcp_init_header(struct dhcp_packet *packet, char type) FAST_FUNC;
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 85068721a..9e3ce8b1c 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -484,8 +484,10 @@ static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid
484 484
485static uint8_t *add_d6_client_options(uint8_t *ptr) 485static uint8_t *add_d6_client_options(uint8_t *ptr)
486{ 486{
487 struct option_set *curr;
487 uint8_t *start = ptr; 488 uint8_t *start = ptr;
488 unsigned option; 489 unsigned option;
490 uint16_t len;
489 491
490 ptr += 4; 492 ptr += 4;
491 for (option = 1; option < 256; option++) { 493 for (option = 1; option < 256; option++) {
@@ -508,7 +510,12 @@ static uint8_t *add_d6_client_options(uint8_t *ptr)
508 ptr = mempcpy(ptr, &opt_fqdn_req, sizeof(opt_fqdn_req)); 510 ptr = mempcpy(ptr, &opt_fqdn_req, sizeof(opt_fqdn_req));
509#endif 511#endif
510 /* Add -x options if any */ 512 /* Add -x options if any */
511 //... 513 curr = client_config.options;
514 while (curr) {
515 len = (curr->data[D6_OPT_LEN] << 8) | curr->data[D6_OPT_LEN + 1];
516 ptr = mempcpy(ptr, curr->data, D6_OPT_DATA + len);
517 curr = curr->next;
518 }
512 519
513 return ptr; 520 return ptr;
514} 521}
@@ -1215,7 +1222,10 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1215 } 1222 }
1216 while (list_x) { 1223 while (list_x) {
1217 char *optstr = xstrdup(llist_pop(&list_x)); 1224 char *optstr = xstrdup(llist_pop(&list_x));
1218 udhcp_str2optset(optstr, &client_config.options, d6_optflags, d6_option_strings); 1225 udhcp_str2optset(optstr, &client_config.options,
1226 d6_optflags, d6_option_strings,
1227 /*dhcpv6:*/ 1
1228 );
1219 free(optstr); 1229 free(optstr);
1220 } 1230 }
1221 1231
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index bd9e8fdc2..c206a5825 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1337,7 +1337,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1337 } 1337 }
1338 while (list_x) { 1338 while (list_x) {
1339 char *optstr = xstrdup(llist_pop(&list_x)); 1339 char *optstr = xstrdup(llist_pop(&list_x));
1340 udhcp_str2optset(optstr, &client_config.options, dhcp_optflags, dhcp_option_strings); 1340 udhcp_str2optset(optstr, &client_config.options,
1341 dhcp_optflags, dhcp_option_strings,
1342 /*dhcpv6:*/ 0
1343 );
1341 free(optstr); 1344 free(optstr);
1342 } 1345 }
1343 1346
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 19f94a2d7..ef59dca5c 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -362,7 +362,10 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
362} 362}
363 363
364static int FAST_FUNC read_optset(const char *line, void *arg) { 364static int FAST_FUNC read_optset(const char *line, void *arg) {
365 return udhcp_str2optset(line, arg, dhcp_optflags, dhcp_option_strings); 365 return udhcp_str2optset(line, arg,
366 dhcp_optflags, dhcp_option_strings,
367 /*dhcpv6:*/ 0
368 );
366} 369}
367 370
368struct config_keyword { 371struct config_keyword {