[PATCH v2 6/6] udhcpc6: Set -x options in request
Samuel Mendoza-Jonas
sam at mendozajonas.com
Mon May 14 04:29:16 UTC 2018
Signed-off-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
---
networking/udhcp/common.c | 19 +++++++++++++++----
networking/udhcp/common.h | 4 ++++
networking/udhcp/d6_dhcpc.c | 10 +++++++++-
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index bc4606293..7e4b71390 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -411,10 +411,21 @@ static NOINLINE void attach_option(
/* make a new option */
log2("attaching option %02x to list", optflag->code);
new = xmalloc(sizeof(*new));
- new->data = xmalloc(length + OPT_DATA);
- new->data[OPT_CODE] = optflag->code;
- new->data[OPT_LEN] = length;
- memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer), length);
+ if (addr_type == CLIENT_CONFIG_DHCPV6) {
+ 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, (allocated ? allocated : buffer),
+ length);
+ } else {
+ new->data = xmalloc(length + OPT_DATA);
+ new->data[OPT_CODE] = optflag->code;
+ new->data[OPT_LEN] = length;
+ memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer),
+ length);
+ }
curr = opt_list;
while (*curr && (*curr)->data[OPT_CODE] < optflag->code)
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index e8c3dc2af..15499197c 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -164,6 +164,10 @@ enum {
#define OPT_CODE 0
#define OPT_LEN 1
#define OPT_DATA 2
+/* Offsets in option byte sequence for DHCPv6 */
+#define D6_OPT_CODE 0
+#define D6_OPT_LEN 2
+#define D6_OPT_DATA 4
/* Bits in "overload" option */
#define OPTION_FIELD 0
#define FILE_FIELD 1
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 26ce147c4..8bdff6e10 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -486,8 +486,11 @@ static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid
static uint8_t *add_d6_client_options(uint8_t *ptr)
{
+ struct option_set *curr;
uint8_t *start = ptr;
unsigned option;
+ uint16_t len;
+
ptr += 4;
for (option = 1; option < 256; option++) {
@@ -510,7 +513,12 @@ static uint8_t *add_d6_client_options(uint8_t *ptr)
ptr = mempcpy(ptr, &opt_fqdn_req, sizeof(opt_fqdn_req));
#endif
/* Add -x options if any */
- //...
+ curr = client_config.options;
+ while (curr) {
+ len = curr->data[D6_OPT_LEN] << 8 | (curr->data[D6_OPT_LEN + 1] & 0xff);
+ ptr = mempcpy(ptr, curr->data, D6_OPT_DATA + len);
+ curr = curr->next;
+ }
return ptr;
}
--
2.17.0
More information about the busybox
mailing list