]> git.decadent.org.uk Git - odhcp6c.git/commitdiff
Merge branch 'master' into hnet
authorMarkus Stenberg <markus.stenberg@iki.fi>
Mon, 24 Jun 2013 10:53:03 +0000 (13:53 +0300)
committerMarkus Stenberg <markus.stenberg@iki.fi>
Mon, 24 Jun 2013 10:53:38 +0000 (13:53 +0300)
Conflicts:
README
src/dhcpv6.c
src/odhcp6c.h

README
src/dhcpv6.c
src/odhcp6c.c
src/odhcp6c.h
src/ra.c
src/script.c

diff --git a/README b/README
index 16ac904734bdae6e9ce166023e2be65543beb529..3f2087fe65f45cdc3cceec939ebf5795cec037b3 100644 (file)
--- a/README
+++ b/README
@@ -68,7 +68,7 @@ Environment:
 * SIP_DOMAIN           A space-separated list of SIP domains
 * OPTION_<num>         Custom option received as base-16
 * PREFIXES             A space-separated list of prefixes currently assigned
-                               Format: <prefix>/<length>,preferred,valid[,excluded=<excluded-prefix>/<length>]
+                               Format: <prefix>/<length>,preferred,valid[,excluded=<excluded-prefix>/<length>][,class=<prefix class #>]
 * ADDRESSES            A space-separated list of addresses currently assigned
                                Format: <address>/<length>,preferred,valid
 * RA_ADDRESSES         A space-separated list of addresses from RA-prefixes
index ed6b8f868a67accdad22418e34cfc369204f5347..7f2aa1a70ab91c22c2b18d0700c9e0c07ee2a639 100644 (file)
@@ -142,8 +142,10 @@ int init_dhcpv6(const char *ifname, int request_pd)
                        htons(DHCPV6_OPT_DNS_SERVERS),
                        htons(DHCPV6_OPT_DNS_DOMAIN),
                        htons(DHCPV6_OPT_NTP_SERVER),
+                       htons(DHCPV6_OPT_SIP_SERVER_A),
                        htons(DHCPV6_OPT_AFTR_NAME),
                        htons(DHCPV6_OPT_PD_EXCLUDE),
+                       htons(DHCPV6_OPT_PREFIX_CLASS),
        };
        odhcp6c_add_state(STATE_ORO, oro, sizeof(oro));
 
@@ -800,11 +802,11 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end)
        uint16_t otype, olen;
        uint8_t *odata;
 
-       struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT,
-                       0, 0, IN6ADDR_ANY_INIT, 0, 0};
-
        // Update address IA
        dhcpv6_for_each_option(opt, end, otype, olen, odata) {
+          struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT,
+                                        0, 0, IN6ADDR_ANY_INIT, 0, 0, 0};
+
                if (otype == DHCPV6_OPT_IA_PREFIX) {
                        struct dhcpv6_ia_prefix *prefix = (void*)&odata[-4];
                        if (olen + 4U < sizeof(*prefix))
@@ -818,11 +820,17 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end)
 
                        entry.length = prefix->prefix;
                        entry.target = prefix->addr;
+                       uint16_t stype, slen;
+                       uint8_t *sdata;
+
+                        // Find prefix class, if any
+                       dhcpv6_for_each_option(&prefix[1], odata + olen,
+                                               stype, slen, sdata)
+                          if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2) 
+                            entry.prefix_class = ntohs(*((uint16_t*)sdata));
 
                        // Parse PD-exclude
                        bool ok = true;
-                       uint16_t stype, slen;
-                       uint8_t *sdata;
                        dhcpv6_for_each_option(odata + sizeof(*prefix) - 4U,
                                        odata + olen, stype, slen, sdata) {
                                if (stype != DHCPV6_OPT_PD_EXCLUDE || slen < 2)
index df89eb9baeb68c050b620e3541cfd27eccb6d719..6da604728c4f330d446e10c5c0e941c6ce529d65 100644 (file)
@@ -439,6 +439,7 @@ void odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *n
                if (x) {
                        x->valid = new->valid;
                        x->preferred = new->preferred;
+                        x->prefix_class = new->prefix_class;
                } else {
                        odhcp6c_add_state(state, new, sizeof(*new));
                }
index 2e7107c5d582eb63748bb3018cfb27987b9c4e25..d8a9bffdf80e0040285182cc5de6ab3f0b3d6618 100644 (file)
@@ -53,6 +53,8 @@ enum dhcvp6_opt {
        DHCPV6_OPT_SIP_SERVER_A = 22,
        DHCPV6_OPT_AFTR_NAME = 64,
        DHCPV6_OPT_PD_EXCLUDE = 67,
+        /* draft-bhandari-dhc-class-based-prefix */
+       DHCPV6_OPT_PREFIX_CLASS = 200, /* NOT STANDARDIZED! */
 };
 
 enum dhcpv6_opt_npt {
@@ -211,6 +213,7 @@ struct odhcp6c_entry {
        struct in6_addr target;
        uint32_t valid;
        uint32_t preferred;
+        uint32_t prefix_class;
 };
 
 
index 4690d419466975357a5a9bce667f469c633f87b2..9a579851524786704875d675100d8fded72ef6b7 100644 (file)
--- a/src/ra.c
+++ b/src/ra.c
@@ -142,7 +142,7 @@ static void update_proc(const char *sect, const char *opt, uint32_t value)
 
 static bool ra_deduplicate(const struct in6_addr *any, uint8_t length)
 {
-       struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, length, 0, *any, 0, 0};
+  struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, length, 0, *any, 0, 0, 0};
        struct odhcp6c_entry *x = odhcp6c_find_entry(STATE_RA_PREFIX, &entry);
        if (x && IN6_ARE_ADDR_EQUAL(&x->target, any)) {
                odhcp6c_random(&x->target.s6_addr32[2], 2 * sizeof(uint32_t));
@@ -202,7 +202,7 @@ bool ra_process(void)
        bool found = false;
        uint8_t buf[1500];
        struct nd_router_advert *adv = (struct nd_router_advert*)buf;
-       struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, 0, 0, IN6ADDR_ANY_INIT, 0, 0};
+       struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, 0, 0, IN6ADDR_ANY_INIT, 0, 0, 0};
        const struct in6_addr any = IN6ADDR_ANY_INIT;
 
        while (true) {
index bda9749ec27eb66ba336b16414378c8669af2576..3cc7e2b47c663afacb4575acf3baa8147af69c32 100644 (file)
@@ -187,6 +187,9 @@ static void entry_to_env(const char *name, const void *data, size_t len, enum en
                        } else {
                                buf_len += snprintf(&buf[buf_len], 24, ",%u,%u", e[i].preferred, e[i].valid);
                        }
+                        if (type == ENTRY_PREFIX && e[i].prefix_class) {
+                          buf_len += snprintf(&buf[buf_len], 12, ",class=%u", e[i].prefix_class);
+                        }
 
                        if (type == ENTRY_PREFIX && e[i].priority) {
                                // priority and router are abused for prefix exclusion