return -1;
}
+ const char* saddr = ubus_get_address4(iface->name);
+ struct in_addr addr;
+ inet_pton(AF_INET,saddr, &addr);
+ int bits = ubus_get_mask4(iface->name);
+ struct in_addr mask;
+ if (bits < -32 || bits > 32)
+ bits = 0;
+
+ mask.s_addr = bits ? htonl(~((1 << (32 - abs(bits))) - 1)) : 0;
+ if (bits < 0)
+ mask.s_addr = ~mask.s_addr;
+
+
// Create a range if not specified
if (!(iface->dhcpv4_start.s_addr & htonl(0xffff0000)) &&
!(iface->dhcpv4_end.s_addr & htonl(0xffff0000))) {
- struct in_addr addr = ubus_get_address4(iface->ifname);
- struct in_addr mask = ubus_get_mask4(iface->ifname);
uint32_t start = ntohl(iface->dhcpv4_start.s_addr);
uint32_t end = ntohl(iface->dhcpv4_end.s_addr);
// Clean invalid assignments
struct dhcpv4_assignment *a, *n;
list_for_each_entry_safe(a, n, &iface->dhcpv4_assignments, head) {
- if ((htonl(a->addr) & smask->sin_addr.s_addr) !=
- (iface->dhcpv4_start.s_addr & smask->sin_addr.s_addr)) {
+ if ((htonl(a->addr) & mask.s_addr) !=
+ (iface->dhcpv4_start.s_addr & mask.s_addr)) {
list_del(&a->head);
free(a);
}