From 265fcddd08f22c99a2a419a1537c18f4d6d43e9f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 2 Jun 2021 13:50:26 +0200 Subject: 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 --- networking/udhcp/common.c | 63 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 25 deletions(-) (limited to 'networking/udhcp/common.c') diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index f2d6907..684d76b 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) return 1; } +void* FAST_FUNC udhcp_insert_new_option( + struct option_set **opt_list, + unsigned code, + const void *buffer, + unsigned length, + bool dhcpv6) +{ + IF_NOT_UDHCPC6(bool dhcpv6 = 0;) + struct option_set *new, **curr; + + log2("attaching option %02x to list", code); + new = xmalloc(sizeof(*new)); + if (!dhcpv6) { + new->data = xmalloc(length + OPT_DATA); + new->data[OPT_CODE] = code; + new->data[OPT_LEN] = length; + memcpy(new->data + OPT_DATA, buffer, length); + } else { + new->data = xmalloc(length + D6_OPT_DATA); + new->data[D6_OPT_CODE] = code >> 8; + new->data[D6_OPT_CODE + 1] = code & 0xff; + new->data[D6_OPT_LEN] = length >> 8; + new->data[D6_OPT_LEN + 1] = length & 0xff; + memcpy(new->data + D6_OPT_DATA, buffer, length); + } + + curr = opt_list; +//FIXME: DHCP6 codes > 255!! + while (*curr && (*curr)->data[OPT_CODE] < code) + curr = &(*curr)->next; + + new->next = *curr; + *curr = new; + + return new->data; +} + /* udhcp_str2optset: * Parse string option representation to binary form and add it to opt_list. * Called to parse "udhcpc -x OPTNAME:OPTVAL" @@ -459,32 +496,8 @@ static NOINLINE void attach_option( existing = udhcp_find_option(*opt_list, optflag->code); if (!existing) { - struct option_set *new, **curr; - /* make a new option */ - log2("attaching option %02x to list", optflag->code); - new = xmalloc(sizeof(*new)); - if (!dhcpv6) { - new->data = xmalloc(length + OPT_DATA); - new->data[OPT_CODE] = optflag->code; - new->data[OPT_LEN] = length; - memcpy(new->data + OPT_DATA, buffer, length); - } else { - new->data = xmalloc(length + D6_OPT_DATA); - new->data[D6_OPT_CODE] = optflag->code >> 8; - new->data[D6_OPT_CODE + 1] = optflag->code & 0xff; - new->data[D6_OPT_LEN] = length >> 8; - new->data[D6_OPT_LEN + 1] = length & 0xff; - memcpy(new->data + D6_OPT_DATA, buffer, - length); - } - - curr = opt_list; - while (*curr && (*curr)->data[OPT_CODE] < optflag->code) - curr = &(*curr)->next; - - new->next = *curr; - *curr = new; + udhcp_insert_new_option(opt_list, optflag->code, buffer, length, dhcpv6); goto ret; } -- cgit v1.1