aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/common.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-02 13:50:26 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-02 14:07:26 +0200
commit265fcddd08f22c99a2a419a1537c18f4d6d43e9f (patch)
treee1cfb7a18bb0887b95700a7417f88ff90883bfa3 /networking/udhcp/common.c
parent9659a8db1dd28bdf8659fdae5d097b6f48bd2736 (diff)
downloadbusybox-w32-265fcddd08f22c99a2a419a1537c18f4d6d43e9f.tar.gz
busybox-w32-265fcddd08f22c99a2a419a1537c18f4d6d43e9f.tar.bz2
busybox-w32-265fcddd08f22c99a2a419a1537c18f4d6d43e9f.zip
udhcpc: include client-id option in DECLINEs, even if it's a custom -x 61:HEX option
client_data.vendorclass, .hostname and .fqdn probably need the same treatment: just insert them into the list of -x opts, get rid of if (client_data.vendorclass) udhcp_add_binary_option(packet, client_data.vendorclass); if (client_data.hostname) udhcp_add_binary_option(packet, client_data.hostname); if (client_data.fqdn) udhcp_add_binary_option(packet, client_data.fqdn); function old new delta udhcp_insert_new_option - 166 +166 perform_release 171 207 +36 perform_d6_release 227 259 +32 udhcpc6_main 2558 2580 +22 init_d6_packet 103 84 -19 udhcpc_main 2585 2564 -21 attach_option 397 253 -144 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/3 up/down: 256/-184) Total: 72 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r--networking/udhcp/common.c63
1 files changed, 38 insertions, 25 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index f2d6907ad..684d76b2b 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -420,6 +420,43 @@ int FAST_FUNC udhcp_str2nip(const char *str, void *arg)
420 return 1; 420 return 1;
421} 421}
422 422
423void* FAST_FUNC udhcp_insert_new_option(
424 struct option_set **opt_list,
425 unsigned code,
426 const void *buffer,
427 unsigned length,
428 bool dhcpv6)
429{
430 IF_NOT_UDHCPC6(bool dhcpv6 = 0;)
431 struct option_set *new, **curr;
432
433 log2("attaching option %02x to list", code);
434 new = xmalloc(sizeof(*new));
435 if (!dhcpv6) {
436 new->data = xmalloc(length + OPT_DATA);
437 new->data[OPT_CODE] = code;
438 new->data[OPT_LEN] = length;
439 memcpy(new->data + OPT_DATA, buffer, length);
440 } else {
441 new->data = xmalloc(length + D6_OPT_DATA);
442 new->data[D6_OPT_CODE] = code >> 8;
443 new->data[D6_OPT_CODE + 1] = code & 0xff;
444 new->data[D6_OPT_LEN] = length >> 8;
445 new->data[D6_OPT_LEN + 1] = length & 0xff;
446 memcpy(new->data + D6_OPT_DATA, buffer, length);
447 }
448
449 curr = opt_list;
450//FIXME: DHCP6 codes > 255!!
451 while (*curr && (*curr)->data[OPT_CODE] < code)
452 curr = &(*curr)->next;
453
454 new->next = *curr;
455 *curr = new;
456
457 return new->data;
458}
459
423/* udhcp_str2optset: 460/* udhcp_str2optset:
424 * Parse string option representation to binary form and add it to opt_list. 461 * Parse string option representation to binary form and add it to opt_list.
425 * Called to parse "udhcpc -x OPTNAME:OPTVAL" 462 * Called to parse "udhcpc -x OPTNAME:OPTVAL"
@@ -459,32 +496,8 @@ static NOINLINE void attach_option(
459 496
460 existing = udhcp_find_option(*opt_list, optflag->code); 497 existing = udhcp_find_option(*opt_list, optflag->code);
461 if (!existing) { 498 if (!existing) {
462 struct option_set *new, **curr;
463
464 /* make a new option */ 499 /* make a new option */
465 log2("attaching option %02x to list", optflag->code); 500 udhcp_insert_new_option(opt_list, optflag->code, buffer, length, dhcpv6);
466 new = xmalloc(sizeof(*new));
467 if (!dhcpv6) {
468 new->data = xmalloc(length + OPT_DATA);
469 new->data[OPT_CODE] = optflag->code;
470 new->data[OPT_LEN] = length;
471 memcpy(new->data + OPT_DATA, buffer, length);
472 } else {
473 new->data = xmalloc(length + D6_OPT_DATA);
474 new->data[D6_OPT_CODE] = optflag->code >> 8;
475 new->data[D6_OPT_CODE + 1] = optflag->code & 0xff;
476 new->data[D6_OPT_LEN] = length >> 8;
477 new->data[D6_OPT_LEN + 1] = length & 0xff;
478 memcpy(new->data + D6_OPT_DATA, buffer,
479 length);
480 }
481
482 curr = opt_list;
483 while (*curr && (*curr)->data[OPT_CODE] < optflag->code)
484 curr = &(*curr)->next;
485
486 new->next = *curr;
487 *curr = new;
488 goto ret; 501 goto ret;
489 } 502 }
490 503