]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
routing/linux: check IPv6 forwarding status when enabling Router capa
authorAntonio Quartulli <a@unstable.cc>
Sat, 9 Jan 2021 14:45:50 +0000 (15:45 +0100)
committerVincent Bernat <vincent@bernat.ch>
Sat, 9 Jan 2021 18:07:38 +0000 (19:07 +0100)
Consider also IPv6 when deciding whether to enable the Router capability.
This way, if a host is a router for IPv6 only, it will still be
advertised as Router to its neighbours.

Signed-off-by: Antonio Quartulli <a@unstable.cc>
src/daemon/forward-linux.c
src/daemon/lldpd.h
src/daemon/priv-linux.c

index c7d9f735665243b422b2f21f80242a83df63dcf2..db563bdc8435ec942018918712793581238319e7 100644 (file)
 
 #include <unistd.h>
 
+int
+ip_forwarding_enabled(int af)
+{
+       int fd, rc = -1;
+       char *fname;
+       char status;
+
+       if (af == LLDPD_AF_IPV4)
+               fname = PROCFS_SYS_NET "ipv4/ip_forward";
+       else if (af == LLDPD_AF_IPV6)
+               fname = PROCFS_SYS_NET "ipv6/conf/all/forwarding";
+       else
+               return -1;
+
+       if ((fd = priv_open(fname)) < 0)
+               return -1;
+
+       if (read(fd, &status, 1) == 1)
+               rc = (status == '1');
+
+       close(fd);
+       return rc;
+}
+
 int
 interfaces_routing_enabled(struct lldpd *cfg) {
        (void)cfg;
-       int f;
-       char status;
        int rc;
-       if ((f = priv_open("/proc/sys/net/ipv4/ip_forward")) >= 0) {
-               if (read(f, &status, 1) == 1) {
-                       rc = (status == '1');
-               } else rc = -1;
-               close(f);
+
+       rc = ip_forwarding_enabled(LLDPD_AF_IPV4);
+       /*
+        * Report being a router if IPv4 forwarding is enabled.
+        * In case of error also stop the execution right away.
+        * If IPv4 forwarding is disabled we'll check the IPv6 status.
+        */
+       if (rc != 0)
                return rc;
-       }
-       return -1;
+
+       return ip_forwarding_enabled(LLDPD_AF_IPV6);
 }
index 0d67d7c9fa7bbd58020371ef0a772306845c8900..32581e5985b7f5c0fd5e1a83573e59a2a6c0c1d3 100644 (file)
@@ -61,6 +61,7 @@
 struct event;
 struct event_base;
 
+#define PROCFS_SYS_NET "/proc/sys/net/"
 #define SYSFS_CLASS_NET "/sys/class/net/"
 #define SYSFS_CLASS_DMI "/sys/class/dmi/id/"
 #define LLDPD_TX_INTERVAL      30
index 6b7d9f4b16ce199db218645675f36d3eaf752e21..315faf3eef6bd287b14a46a4905f2d7c836e9b13 100644 (file)
@@ -58,7 +58,8 @@ void
 asroot_open()
 {
        const char* authorized[] = {
-               "/proc/sys/net/ipv4/ip_forward",
+               PROCFS_SYS_NET "ipv4/ip_forward",
+               PROCFS_SYS_NET "ipv6/conf/all/forwarding",
                "/proc/net/bonding/[^.][^/]*",
                "/proc/self/net/bonding/[^.][^/]*",
 #ifdef ENABLE_OLDIES