interface: proto_ip: order by address index first
authorYousong Zhou <yszhou4tech@gmail.com>
Tue, 20 Oct 2020 02:49:18 +0000 (10:49 +0800)
committerYousong Zhou <yszhou4tech@gmail.com>
Thu, 22 Oct 2020 02:22:23 +0000 (10:22 +0800)
At the moment, dnsmasq initscript generates dhcp-range for an interface
by inspecting first address of that interface from netifd ubus output.

Order by address index as specified in the uci config makes netifd ubus
output consistent with linux network interfaces' primary/secondary
address settings.  More importantly, the ubus output and dnsmasq config
generation will be more predictable.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
interface-ip.c
proto.c

index f1ed8d39cad1b3a2b2a90b47326fd50e608fb85c..6efc3c503aac85e1005bc4394f83c4c86cb1d1e6 100644 (file)
@@ -516,8 +516,14 @@ error:
 static int
 addr_cmp(const void *k1, const void *k2, void *ptr)
 {
-       return memcmp(k1, k2, sizeof(struct device_addr) -
-                     offsetof(struct device_addr, flags));
+       const struct device_addr *a1 = k1;
+       const struct device_addr *a2 = k2;
+       const int cmp_offset = offsetof(struct device_addr, flags);
+       const int cmp_size = sizeof(struct device_addr) - cmp_offset;
+
+       if (a1->index != a2->index)
+               return a1->index - a2->index;
+       return memcmp(k1+cmp_offset, k2+cmp_offset, cmp_size);
 }
 
 static int
diff --git a/proto.c b/proto.c
index f7d27aad68dc009d44a6be41490c963267c2fdc3..01473f2494fc0d586011a6a27fdbf58baa20a04f 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -174,7 +174,7 @@ parse_static_address_option(struct interface *iface, struct blob_attr *attr,
                }
                addr->index = n_addr;
                n_addr++;
-               vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags);
+               vlist_add(&iface->proto_ip.addr, &addr->node, addr);
        }
 
        return n_addr;
@@ -275,7 +275,7 @@ parse_address_list(struct interface *iface, struct blob_attr *attr, bool v6,
 
                addr->index = n_addr;
                n_addr++;
-               vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags);
+               vlist_add(&iface->proto_ip.addr, &addr->node, addr);
        }
 
        return n_addr;