Fix prefix class logic
authorSteven Barth <steven@midlink.org>
Tue, 3 Dec 2013 21:00:33 +0000 (22:00 +0100)
committerSteven Barth <steven@midlink.org>
Tue, 3 Dec 2013 21:00:33 +0000 (22:00 +0100)
CMakeLists.txt
src/dhcpv6-ia.c
src/odhcpd.c
src/odhcpd.h
src/ubus.c

index 891dc41ad4e3fc78ff5e1d71c827dedb945e7374..09173e40f1c35d7063d677421baae7f1c2c2abba 100644 (file)
@@ -10,6 +10,11 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -std=c99")
 
 add_definitions(-D_GNU_SOURCE -Wall -Werror -Wextra -DWITH_UBUS)
 
+if(${EXT_PREFIX_CLASS})
+       add_definitions(-DEXT_PREFIX_CLASS=${EXT_PREFIX_CLASS})
+endif(${EXT_PREFIX_CLASS})
+
+
 add_executable(odhcpd src/odhcpd.c src/config.c src/router.c src/dhcpv6.c src/ndp.c src/md5.c src/dhcpv6-ia.c src/dhcpv4.c src/ubus.c)
 target_link_libraries(odhcpd resolv ubus ubox uci)
 
index 3d9fe831908ac58b0178b71a8d080438b2200fe1..b0a31a2d40445107f16d3f99d48b485e3439290e 100644 (file)
@@ -900,8 +900,10 @@ size_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface,
                                a->assigned = reqhint;
                                a->all_class = class_oro;
                                a->classes_cnt = classes_cnt;
-                               a->classes = malloc(classes_cnt * sizeof(uint16_t));
-                               memcpy(a->classes, classes, classes_cnt * sizeof(uint16_t));
+                               if (classes_cnt) {
+                                       a->classes = malloc(classes_cnt * sizeof(uint16_t));
+                                       memcpy(a->classes, classes, classes_cnt * sizeof(uint16_t));
+                               }
 
                                if (first)
                                        memcpy(a->key, first->key, sizeof(a->key));
index 5a800b702127ab7e6a5da5eea00e1f9b4bdaa5cd..d6ca2988526656f3b589b2618eed161a1a908793 100644 (file)
@@ -244,10 +244,9 @@ ssize_t odhcpd_get_interface_addresses(int ifindex,
                addrs[ret].class = 0;
 #ifdef WITH_UBUS
                struct interface *iface = odhcpd_get_interface_by_index(ifindex);
-               if (iface) {
-                       addrs[ret].has_class = true;
-                       addrs[ret].class = ubus_get_class(iface->ifname, &addrs[ret].addr);
-               }
+               if (iface)
+                       addrs[ret].has_class = ubus_get_class(iface->ifname,
+                                       &addrs[ret].addr, &addrs[ret].class);
 #endif
                ++ret;
        }
index 510dd6ab7817b19ccd668509534aee5e44ca1148..727c638f1680807c70a2928514473e97afa83f84 100644 (file)
@@ -195,7 +195,7 @@ int init_ubus(void);
 const char* ubus_get_ifname(const char *name);
 void ubus_apply_network(void);
 bool ubus_has_prefix(const char *name, const char *ifname);
-uint16_t ubus_get_class(const char *ifname, const struct in6_addr *addr);
+bool ubus_get_class(const char *ifname, const struct in6_addr *addr, uint16_t *pclass);
 #endif
 
 
index 317a9c1919edc5a2ed56565931d2be69758313d0..dbb43a69f6f1cfd73ec807fd71707537f2658deb 100644 (file)
@@ -364,13 +364,13 @@ static const struct blobmsg_policy addr_attrs[ADDR_ATTR_MAX] = {
        [ADDR_ATTR_CLASS] = { .name = "class", .type = BLOBMSG_TYPE_STRING },
 };
 
-uint16_t ubus_get_class(const char *ifname, const struct in6_addr *addr)
+bool ubus_get_class(const char *ifname, const struct in6_addr *addr, uint16_t *pclass)
 {
        struct blob_attr *c, *cur;
        unsigned rem;
 
        if (!dump)
-               return 0;
+               return false;
 
        blobmsg_for_each_attr(c, dump, rem) {
                struct blob_attr *tb[IFACE_ATTR_MAX];
@@ -401,15 +401,17 @@ uint16_t ubus_get_class(const char *ifname, const struct in6_addr *addr)
                                struct in6_addr ip6addr;
                                inet_pton(AF_INET6, addrs, &ip6addr);
 
-                               if (IN6_ARE_ADDR_EQUAL(&ip6addr, addr))
-                                       return atoi(class);
+                               if (IN6_ARE_ADDR_EQUAL(&ip6addr, addr)) {
+                                       *pclass = atoi(class);
+                                       return true;
+                               }
                        }
                }
 
-               return 0;
+               return false;
        }
 
-       return 0;
+       return false;
 }