#include <netinet/in.h>
#include <arpa/inet.h>
+#include <libubox/utils.h>
+
#include "odhcpd.h"
#include "dhcpv6.h"
#include "dhcpv4.h"
blob_buf_init(&b, 0);
a = blobmsg_open_table(&b, "device");
- list_for_each_entry(iface, &interfaces, head) {
+ avl_for_each_element(&interfaces, iface, avl) {
if (iface->dhcpv4 != MODE_SERVER || iface->dhcpv4_assignments.next == NULL)
continue;
void *i = blobmsg_open_table(&b, iface->ifname);
void *j = blobmsg_open_array(&b, "leases");
- struct dhcpv4_assignment *c;
+ struct dhcp_assignment *c;
list_for_each_entry(c, &iface->dhcpv4_assignments, head) {
if (!INFINITE_VALID(c->valid_until) && c->valid_until < now)
continue;
blob_buf_init(&b, 0);
a = blobmsg_open_table(&b, "device");
- list_for_each_entry(iface, &interfaces, head) {
+ avl_for_each_element(&interfaces, iface, avl) {
if (iface->dhcpv6 != MODE_SERVER || iface->ia_assignments.next == NULL)
continue;
void *i = blobmsg_open_table(&b, iface->ifname);
void *j = blobmsg_open_array(&b, "leases");
- struct dhcpv6_assignment *a, *border = list_last_entry(
- &iface->ia_assignments, struct dhcpv6_assignment, head);
+ struct dhcp_assignment *a, *border = list_last_entry(
+ &iface->ia_assignments, struct dhcp_assignment, head);
list_for_each_entry(a, &iface->ia_assignments, head) {
if (a == border || (!INFINITE_VALID(a->valid_until) &&
blobmsg_close_array(&b, m);
m = blobmsg_open_array(&b, a->length == 128 ? "ipv6-addr": "ipv6-prefix");
- dhcpv6_enum_ia_addrs(iface, a, now, dhcpv6_blobmsg_ia_addr, NULL);
+ dhcpv6_ia_enum_addrs(iface, a, now, dhcpv6_blobmsg_ia_addr, NULL);
blobmsg_close_table(&b, m);
blobmsg_add_u32(&b, "valid", INFINITE_VALID(a->valid_until) ?
struct blob_attr *msg)
{
struct blob_attr *tb[IFACE_ATTR_MAX];
- blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb, blob_data(msg), blob_len(msg));
+ struct interface *c;
+ bool update = true;
+ blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb, blob_data(msg), blob_len(msg));
const char *interface = (tb[IFACE_ATTR_INTERFACE]) ?
blobmsg_get_string(tb[IFACE_ATTR_INTERFACE]) : "";
- const char *ifname = (tb[IFACE_ATTR_IFNAME]) ?
- blobmsg_get_string(tb[IFACE_ATTR_IFNAME]) : "";
- struct interface *c, *iface = NULL;
- list_for_each_entry(c, &interfaces, head)
- if (!strcmp(interface, c->name) || !strcmp(ifname, c->ifname))
- iface = c;
+ avl_for_each_element(&interfaces, c, avl) {
+ if (!strcmp(interface, c->name) && c->ignore) {
+ update = false;
+ break;
+ }
+ }
- if (iface && iface->ignore)
- return 0;
+ if (update)
+ update_netifd(false);
- update_netifd(false);
return 0;
}
const char *interface = (tb[IFACE_ATTR_INTERFACE]) ?
blobmsg_get_string(tb[IFACE_ATTR_INTERFACE]) : "";
- const char *ifname = (tb[IFACE_ATTR_IFNAME]) ?
- blobmsg_get_string(tb[IFACE_ATTR_IFNAME]) : "";
bool matched = false;
- struct interface *c, *n;
- list_for_each_entry_safe(c, n, &interfaces, head) {
+ struct interface *c, *tmp;
+ avl_for_each_element_safe(&interfaces, c, avl, tmp) {
char *f = memmem(c->upstream, c->upstream_len,
interface, strlen(interface) + 1);
- bool cmatched = !strcmp(interface, c->name) || !strcmp(ifname, c->ifname);
+ bool cmatched = !strcmp(interface, c->name);
matched |= cmatched;
if (!cmatched && (!c->upstream_len || !f || (f != c->upstream && f[-1] != 0)))