summaryrefslogtreecommitdiff
path: root/interface-ip.c
diff options
context:
space:
mode:
authorYousong Zhou <yszhou4tech@gmail.com>2020-10-20 10:49:18 +0800
committerYousong Zhou <yszhou4tech@gmail.com>2020-10-22 10:22:23 +0800
commit24ce1eab4910869576406bafd0489daf0d3e6e28 (patch)
tree83a94e89a0cee2fc44b798edeebf40e904348321 /interface-ip.c
parent3d7bf6043bc92212da7b98af265d1587ff4abe05 (diff)
downloadnetifd-24ce1eab4910869576406bafd0489daf0d3e6e28.tar.gz
interface: proto_ip: order by address index first
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>
Diffstat (limited to 'interface-ip.c')
-rw-r--r--interface-ip.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/interface-ip.c b/interface-ip.c
index f1ed8d3..6efc3c5 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -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