summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2013-12-03 22:00:33 +0100
committerSteven Barth <steven@midlink.org>2013-12-03 22:00:33 +0100
commit1565d76bd6ff2d1064c3d30e947dc70613417853 (patch)
treec0dca5b2447e09124a0b93cfa5e472f74f9b94ba
parentd02dc222e61e2464bf850a629030c8a8b9b57ee8 (diff)
Fix prefix class logic
-rw-r--r--CMakeLists.txt5
-rw-r--r--src/dhcpv6-ia.c6
-rw-r--r--src/odhcpd.c7
-rw-r--r--src/odhcpd.h2
-rw-r--r--src/ubus.c14
5 files changed, 21 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 891dc41..09173e4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
index 3d9fe83..b0a31a2 100644
--- a/src/dhcpv6-ia.c
+++ b/src/dhcpv6-ia.c
@@ -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));
diff --git a/src/odhcpd.c b/src/odhcpd.c
index 5a800b7..d6ca298 100644
--- a/src/odhcpd.c
+++ b/src/odhcpd.c
@@ -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;
}
diff --git a/src/odhcpd.h b/src/odhcpd.h
index 510dd6a..727c638 100644
--- a/src/odhcpd.h
+++ b/src/odhcpd.h
@@ -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
diff --git a/src/ubus.c b/src/ubus.c
index 317a9c1..dbb43a6 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -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;
}