From 1565d76bd6ff2d1064c3d30e947dc70613417853 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Tue, 3 Dec 2013 22:00:33 +0100 Subject: Fix prefix class logic --- CMakeLists.txt | 5 +++++ src/dhcpv6-ia.c | 6 ++++-- src/odhcpd.c | 7 +++---- src/odhcpd.h | 2 +- src/ubus.c | 14 ++++++++------ 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; } -- cgit v1.2.3