Message ID | 20201021030825.93626-5-yszhou4tech@gmail.com |
---|---|
State | Accepted |
Delegated to: | Yousong Zhou |
Headers | show |
Series | order by address index in ubus output | expand |
On Wed, Oct 21, 2020 at 5:08 AM Yousong Zhou <yszhou4tech@gmail.com> wrote: > > 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 make 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 | 11 +++++++++-- > proto.c | 4 ++-- > 2 files changed, 11 insertions(+), 4 deletions(-) > > diff --git a/interface-ip.c b/interface-ip.c > index f1ed8d3..35834a5 100644 > --- a/interface-ip.c > +++ b/interface-ip.c > @@ -516,8 +516,15 @@ 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; > + } small nitpick: remove the brackets to keep in line with existing coding style > + return memcmp(k1+cmp_offset, k2+cmp_offset, cmp_size); > } > > static int > diff --git a/proto.c b/proto.c > index f7d27aa..01473f2 100644 > --- 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;
diff --git a/interface-ip.c b/interface-ip.c index f1ed8d3..35834a5 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -516,8 +516,15 @@ 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 f7d27aa..01473f2 100644 --- 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;
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 make 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> --- interface-ip.c | 11 +++++++++-- proto.c | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-)