Add support for raw DHCPv6 attributes
authorSteven Barth <steven@midlink.org>
Sun, 25 May 2014 12:14:52 +0000 (14:14 +0200)
committerSteven Barth <steven@midlink.org>
Sun, 25 May 2014 12:14:52 +0000 (14:14 +0200)
src/config.c
src/dhcpv6.c
src/odhcpd.h

index 4cde4312c926742b796002aa08dcd03d43b52277..6dd52bba70b6bdb7ade2fadb59c465f5cf6e14d8 100644 (file)
@@ -32,6 +32,7 @@ enum {
        IFACE_ATTR_NDP,
        IFACE_ATTR_DNS,
        IFACE_ATTR_DOMAIN,
+       IFACE_ATTR_DHCPV6_RAW,
        IFACE_ATTR_RA_DEFAULT,
        IFACE_ATTR_RA_MANAGEMENT,
        IFACE_ATTR_RA_OFFLINK,
@@ -61,6 +62,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_NDP] = { .name = "ndp", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
        [IFACE_ATTR_DOMAIN] = { .name = "domain", .type = BLOBMSG_TYPE_ARRAY },
+       [IFACE_ATTR_DHCPV6_RAW] = { .name = "dhcpv6_raw", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_PD_MANAGER] = { .name = "pd_manager", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_PD_CER] = { .name = "pd_cer", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_RA_DEFAULT] = { .name = "ra_default", .type = BLOBMSG_TYPE_INT32 },
@@ -149,6 +151,7 @@ static void clean_interface(struct interface *iface)
        free(iface->upstream);
        free(iface->static_ndp);
        free(iface->dhcpv4_dns);
+       free(iface->dhcpv6_raw);
        memset(&iface->ra, 0, sizeof(*iface) - offsetof(struct interface, ra));
 }
 
@@ -454,6 +457,12 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                }
        }
 
+       if ((c = tb[IFACE_ATTR_DHCPV6_RAW])) {
+               iface->dhcpv6_raw_len = blobmsg_data_len(c) / 2;
+               iface->dhcpv6_raw = realloc(iface->dhcpv6_raw, iface->dhcpv6_raw_len);
+               odhcpd_unhexlify(iface->dhcpv6_raw, iface->dhcpv6_raw_len, blobmsg_get_string(c));
+       }
+
        if ((c = tb[IFACE_ATTR_RA_DEFAULT]))
                iface->default_router = blobmsg_get_u32(c);
 
index 55b9ea9208f8aee993bdde236a8c34b440cd3583..37dc3f5057a1b5f9d3d8ae3a3c61ae58a8c08328 100644 (file)
@@ -124,8 +124,8 @@ static void handle_nested_message(uint8_t *data, size_t len,
        uint8_t *odata;
        dhcpv6_for_each_option(hdr->options, data + len, otype, olen, odata) {
                if (otype == DHCPV6_OPT_RELAY_MSG) {
-                       iov[8].iov_base = odata + olen;
-                       iov[8].iov_len = (((uint8_t*)iov[0].iov_base) + iov[0].iov_len)
+                       iov[9].iov_base = odata + olen;
+                       iov[9].iov_len = (((uint8_t*)iov[0].iov_base) + iov[0].iov_len)
                                        - (odata + olen);
                        handle_nested_message(odata, olen, opts, end, iov);
                        return;
@@ -262,6 +262,7 @@ static void handle_client_request(void *addr, void *data, size_t len,
                        {search_domain, search_len},
                        {pdbuf, 0},
                        {&cerid, 0},
+                       {iface->dhcpv6_raw, iface->dhcpv6_raw_len},
                        {NULL, 0}};
 
        uint8_t *opts = (uint8_t*)&hdr[1], *opts_end = (uint8_t*)data + len;
index cf349388a36194852e0c7bf0c5fe49909a80014b..6b90831c8410075756b07f30c6f1fd0f7005405e 100644 (file)
@@ -123,6 +123,8 @@ struct interface {
        // Managed PD
        char dhcpv6_pd_manager[128];
        struct in6_addr dhcpv6_pd_cer;
+       void *dhcpv6_raw;
+       size_t dhcpv6_raw_len;
 
        // Services
        enum odhcpd_mode ra;