rework IPv6 address dump logic
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 27 Mar 2017 20:01:13 +0000 (22:01 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Wed, 29 Mar 2017 09:35:14 +0000 (11:35 +0200)
Make the code more logical by moving the IPv6 address dump logic into the
different protocol interface enable handlers so it's clear which protocols
require interface IPv6 address tracking.
At the same time restructure the IPv6 address dump logic so less IPv6 address
netlink dumps are created.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/config.c
src/dhcpv6.c
src/ndp.c
src/odhcpd.h
src/router.c

index 689d4ce3cf593ccf2e4a069a33b4e86cc89042f3..943f2430326cb40e251f1dc67e7b0caca2dc333a 100644 (file)
@@ -760,11 +760,11 @@ void odhcpd_reload(void)
                        setup_dhcpv6_interface(i, !i->ignore || i->dhcpv6 != RELAYD_DISABLED);
                        setup_ndp_interface(i, !i->ignore || i->ndp != RELAYD_DISABLED);
                        setup_dhcpv4_interface(i, !i->ignore || i->dhcpv4 != RELAYD_DISABLED);
-               } else {
+               } else
                        close_interface(i);
-               }
        }
 
+       ndp_handle_addr6_dump();
        uci_unload(uci, dhcp);
        uci_free_context(uci);
 }
index 81eae06059481a6b046eca711ab68f8552071fbe..4cd9e0293e0cb1390ebb6647c218cc51d02ebf8c 100644 (file)
@@ -90,6 +90,9 @@ int setup_dhcpv6_interface(struct interface *iface, bool enable)
                if (iface->dhcpv6 == RELAYD_SERVER)
                        setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &server, sizeof(server));
 
+               if (iface->dhcpv6 != RELAYD_RELAY || !iface->master)
+                       ndp_rqs_addr6_dump();
+
                iface->dhcpv6_event.uloop.fd = sock;
                iface->dhcpv6_event.handle_dgram = handle_dhcpv6;
                odhcpd_register(&iface->dhcpv6_event);
index 93b70fc2e0af91ac6b98d7b62f45d6a437953860..e201ac99f44826ff889d7c5bfe575d093376322d 100644 (file)
--- a/src/ndp.c
+++ b/src/ndp.c
@@ -49,6 +49,7 @@ static void handle_rtnl_event(struct odhcpd_event *ev);
 static int cb_rtnl_valid(struct nl_msg *msg, void *arg);
 static void catch_rtnl_err(struct odhcpd_event *e, int error);
 
+static int addr6_dump_rqs = 0;
 static int ping_socket = -1;
 static struct event_socket rtnl_event = {
        .ev = {
@@ -150,7 +151,7 @@ static void dump_neigh_table(const bool proxy)
        nlmsg_free(msg);
 }
 
-static void dump_addr_table(void)
+static void dump_addr6_table(void)
 {
        struct nl_msg *msg;
        struct ifaddrmsg ifa = {
@@ -168,6 +169,20 @@ static void dump_addr_table(void)
        nlmsg_free(msg);
 }
 
+void ndp_handle_addr6_dump(void)
+{
+       if (!addr6_dump_rqs)
+               return;
+
+       dump_addr6_table();
+       addr6_dump_rqs = 0;
+}
+
+inline void ndp_rqs_addr6_dump(void)
+{
+       addr6_dump_rqs++;
+}
+
 int setup_ndp_interface(struct interface *iface, bool enable)
 {
        int ret = 0, procfd;
@@ -193,10 +208,6 @@ int setup_ndp_interface(struct interface *iface, bool enable)
                dump_neigh = true;
        }
 
-       if (enable && (iface->ra == RELAYD_SERVER ||
-                       iface->dhcpv6 == RELAYD_SERVER || iface->ndp == RELAYD_RELAY))
-               dump_addr_table();
-
        if (enable && iface->ndp == RELAYD_RELAY) {
                if (write(procfd, "1\n", 2) < 0) {}
 
@@ -243,6 +254,8 @@ int setup_ndp_interface(struct interface *iface, bool enable)
                        dump_neigh_table(false);
                else
                        dump_neigh = false;
+
+               ndp_rqs_addr6_dump();
        }
 
        if (dump_neigh)
@@ -570,7 +583,7 @@ static void catch_rtnl_err(struct odhcpd_event *e, int error)
        if (nl_socket_set_buffer_size(ev_sock->sock, ev_sock->sock_bufsize, 0))
                goto err;
 
-       dump_addr_table();
+       dump_addr6_table();
        return;
 
 err:
index 538a7e5213a899e8b44cb9dab46403e738ad4cdc..973309090f6ca01aafaee39a93a2c4669c9e82ee 100644 (file)
@@ -226,6 +226,9 @@ void odhcpd_bmemcpy(void *av, const void *bv, size_t bits);
 
 int config_parse_interface(void *data, size_t len, const char *iname, bool overwrite);
 
+void ndp_handle_addr6_dump(void);
+void ndp_rqs_addr6_dump(void);
+
 #ifdef WITH_UBUS
 int init_ubus(void);
 const char* ubus_get_ifname(const char *name);
index e8a9aa97760c0a048c08958792bb1a6d0c9b8c6d..6e5111a0b5f5cb94a77af94e086c5d01b03cdbdc 100644 (file)
@@ -120,6 +120,7 @@ int setup_router_interface(struct interface *iface, bool enable)
                } else if (iface->ra == RELAYD_SERVER && !iface->master) {
                        iface->timer_rs.cb = trigger_router_advert;
                        uloop_timeout_set(&iface->timer_rs, 1000);
+                       ndp_rqs_addr6_dump();
                }
 
                if (iface->ra == RELAYD_RELAY || (iface->ra == RELAYD_SERVER && !iface->master))