Don't enable relay master if no slaves are present
authorSteven Barth <steven@midlink.org>
Fri, 17 Jan 2014 19:06:46 +0000 (20:06 +0100)
committerSteven Barth <steven@midlink.org>
Fri, 17 Jan 2014 19:06:46 +0000 (20:06 +0100)
src/config.c
src/ndp.c
src/odhcpd.c

index 195a9a420c20156c34070054a0b060faed72ec20..05eb8248c99cafc2db1b84b04e286ca04c8303e6 100644 (file)
@@ -555,6 +555,23 @@ void odhcpd_reload(void)
        ubus_apply_network();
 #endif
 
+       bool any_dhcpv6_slave = false, any_ra_slave = false, any_ndp_slave = false;
+
+       // Test for
+       list_for_each_entry(i, &interfaces, head) {
+               if (i->master)
+                       continue;
+
+               if (i->dhcpv6 == RELAYD_HYBRID || i->dhcpv6 == RELAYD_RELAY)
+                       any_dhcpv6_slave = true;
+
+               if (i->ra == RELAYD_HYBRID || i->ra == RELAYD_RELAY)
+                       any_ra_slave = true;
+
+               if (i->ndp == RELAYD_HYBRID || i->ndp == RELAYD_RELAY)
+                       any_ndp_slave = true;
+       }
+
        // Evaluate hybrid mode for master
        list_for_each_entry(i, &interfaces, head) {
                if (!i->master)
@@ -569,12 +586,21 @@ void odhcpd_reload(void)
                if (i->dhcpv6 == RELAYD_HYBRID)
                        i->dhcpv6 = hybrid_mode;
 
+               if (i->dhcpv6 == RELAYD_RELAY && !any_dhcpv6_slave)
+                       i->dhcpv6 = RELAYD_DISABLED;
+
                if (i->ra == RELAYD_HYBRID)
                        i->ra = hybrid_mode;
 
+               if (i->ra == RELAYD_RELAY && !any_ra_slave)
+                       i->ra = RELAYD_DISABLED;
+
                if (i->ndp == RELAYD_HYBRID)
                        i->ndp = hybrid_mode;
 
+               if (i->ndp == RELAYD_RELAY && !any_ndp_slave)
+                       i->ndp = RELAYD_DISABLED;
+
                if (i->dhcpv6 == RELAYD_RELAY || i->ra == RELAYD_RELAY || i->ndp == RELAYD_RELAY)
                        master = i;
        }
@@ -593,7 +619,7 @@ void odhcpd_reload(void)
 
                        if (i->ndp == RELAYD_HYBRID)
                                i->ndp = (master && master->ndp == RELAYD_RELAY) ?
-                                               RELAYD_RELAY : RELAYD_SERVER;
+                                               RELAYD_RELAY : RELAYD_DISABLED;
 
                        setup_router_interface(i, true);
                        setup_dhcpv6_interface(i, true);
index 150d3600920f9faf9cfb03c3684b0003c0dcfadf..02c2dbd89164b96c2c352df3d3300bf1bffc9695 100644 (file)
--- a/src/ndp.c
+++ b/src/ndp.c
@@ -234,7 +234,7 @@ static void handle_solicit(void *addr, void *data, size_t len,
 
        char ipbuf[INET6_ADDRSTRLEN];
        inet_ntop(AF_INET6, &req->nd_ns_target, ipbuf, sizeof(ipbuf));
-       syslog(LOG_NOTICE, "Got a NS for %s", ipbuf);
+       syslog(LOG_DEBUG, "Got a NS for %s", ipbuf);
 
        uint8_t mac[6];
        odhcpd_get_mac(iface, mac);
@@ -246,7 +246,7 @@ static void handle_solicit(void *addr, void *data, size_t len,
 
        struct ndp_neighbor *n = find_neighbor(&req->nd_ns_target, false);
        if (n && (n->iface || abs(n->timeout - now) < 5)) {
-               syslog(LOG_NOTICE, "%s is on %s", ipbuf,
+               syslog(LOG_DEBUG, "%s is on %s", ipbuf,
                                (n->iface) ? n->iface->ifname : "<pending>");
                if (!n->iface || n->iface == iface)
                        return;
index 6512e618443739033a0100c60dc2fa89169acdac..f40cea0447e721c9737e678fb5f2cb0959216ac2 100644 (file)
@@ -52,7 +52,7 @@ static int urandom_fd = -1;
 int main()
 {
        openlog("odhcpd", LOG_PERROR | LOG_PID, LOG_DAEMON);
-       setlogmask(LOG_UPTO(LOG_INFO));
+       setlogmask(LOG_UPTO(LOG_WARNING));
        uloop_init();
 
        if (getuid() != 0) {