summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
4 files changed, 16 insertions, 13 deletions
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;
}