]> git.decadent.org.uk Git - odhcp6c.git/commitdiff
Merge preliminary prefix class support
authorSteven Barth <steven@midlink.org>
Sat, 31 Aug 2013 08:48:56 +0000 (10:48 +0200)
committerSteven Barth <steven@midlink.org>
Sat, 31 Aug 2013 08:48:56 +0000 (10:48 +0200)
CMakeLists.txt
src/dhcpv6.c
src/odhcp6c.c
src/odhcp6c.h
src/script.c

index db7ef656259c75d14586b1aaa516c6bd6bce0d63..8112859a071941d9329b2d5504b7a322557ea8dd 100644 (file)
@@ -7,6 +7,10 @@ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -std=c99")
 add_definitions(-D_GNU_SOURCE -Wall -Werror -Wextra -pedantic)
 
+if(${EXT_PREFIX_CLASS})
+       add_definitions(-DEXT_PREFIX_CLASS=${EXT_PREFIX_CLASS})
+endif(${EXT_PREFIX_CLASS})
+
 add_executable(odhcp6c src/odhcp6c.c src/dhcpv6.c src/ra.c src/script.c src/md5.c)
 target_link_libraries(odhcp6c resolv)
 
index fe4cc0b48e8f5dd4ca56139ee1c7fdcc5e353f1f..785b57b03aedf1543dea2ff08a08594599873ceb 100644 (file)
@@ -145,7 +145,9 @@ int init_dhcpv6(const char *ifname, int request_pd)
                        htons(DHCPV6_OPT_SIP_SERVER_A),
                        htons(DHCPV6_OPT_AFTR_NAME),
                        htons(DHCPV6_OPT_PD_EXCLUDE),
+#ifdef EXT_PREFIX_CLASS
                        htons(DHCPV6_OPT_PREFIX_CLASS),
+#endif
        };
        odhcp6c_add_state(STATE_ORO, oro, sizeof(oro));
 
@@ -831,8 +833,8 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end)
 
        // 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};
+               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];
@@ -850,11 +852,13 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end)
                        uint16_t stype, slen;
                        uint8_t *sdata;
 
+#ifdef EXT_PREFIX_CLASS
                         // 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));
+                                       stype, slen, sdata)
+                               if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2)
+                                       entry.class = sdata[0] << 8 | sdata[1];
+#endif
 
                        // Parse PD-exclude
                        bool ok = true;
@@ -912,18 +916,18 @@ static uint32_t dhcpv6_parse_ia(void *opt, void *end)
                        entry.length = 128;
                        entry.target = addr->addr;
 
+#ifdef EXT_PREFIX_CLASS
                        uint16_t stype, slen;
                        uint8_t *sdata;
-                       
                        // Find prefix class, if any
                        dhcpv6_for_each_option(&addr[1], odata + olen,
-                                              stype, slen, sdata)
-                         if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2) 
-                            entry.prefix_class = ntohs(*((uint16_t*)sdata));
-                       
+                                       stype, slen, sdata)
+                               if (stype == DHCPV6_OPT_PREFIX_CLASS && slen == 2)
+                                       entry.class = sdata[0] << 8 | sdata[1];
+#endif
+
                        odhcp6c_update_entry(STATE_IA_NA, &entry);
                }
-
                if (entry.valid > 0 && timeout > entry.valid)
                        timeout = entry.valid;
        }
index b2c6b9815558f14c54aee130821f859e820588e9..d35da2e7a08be0ab66072e01190bb640c9d2a652 100644 (file)
@@ -459,7 +459,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;
+                       x->class = new->class;
                } else {
                        odhcp6c_add_state(state, new, sizeof(*new));
                }
index e0f6f62ce386515b73df1fea85f8e7582d7e677d..eb76b6b497ecd794d5c68eee1b45e4ab40393c76 100644 (file)
@@ -53,8 +53,10 @@ 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! */
+#ifdef EXT_PREFIX_CLASS
+        /* draft-bhandari-dhc-class-based-prefix, not yet standardized */
+       DHCPV6_OPT_PREFIX_CLASS = EXT_PREFIX_CLASS,
+#endif
 };
 
 enum dhcpv6_opt_npt {
@@ -217,7 +219,7 @@ struct odhcp6c_entry {
        struct in6_addr target;
        uint32_t valid;
        uint32_t preferred;
-        uint32_t prefix_class;
+       uint16_t class;
 };
 
 
index 74aea6411dbad82a14f0e05f52d2cbd1f4cc483e..e5b83415561729f77e72109b6986234d497ab38b 100644 (file)
@@ -187,9 +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 || type == ENTRY_ADDRESS) && e[i].prefix_class) {
-                          buf_len += snprintf(&buf[buf_len], 12, ",class=%u", e[i].prefix_class);
-                        }
+
+                       if ((type == ENTRY_PREFIX || type == ENTRY_ADDRESS) && e[i].class)
+                               buf_len += snprintf(&buf[buf_len], 12, ",class=%u", e[i].class);
 
                        if (type == ENTRY_PREFIX && e[i].priority) {
                                // priority and router are abused for prefix exclusion