From 1cf1a23f11668909b8d88561544ccf0f843127f6 Mon Sep 17 00:00:00 2001
From: Antonio Quartulli
Date: Sat, 9 Jan 2021 15:45:50 +0100
Subject: [PATCH] routing/linux: check IPv6 forwarding status when enabling
Router capa
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
---
src/daemon/forward-linux.c | 43 ++++++++++++++++++++++++++++++--------
src/daemon/lldpd.h | 1 +
src/daemon/priv-linux.c | 3 ++-
3 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/src/daemon/forward-linux.c b/src/daemon/forward-linux.c
index c7d9f735..db563bdc 100644
--- a/src/daemon/forward-linux.c
+++ b/src/daemon/forward-linux.c
@@ -19,18 +19,43 @@
#include
+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);
}
diff --git a/src/daemon/lldpd.h b/src/daemon/lldpd.h
index 0d67d7c9..32581e59 100644
--- a/src/daemon/lldpd.h
+++ b/src/daemon/lldpd.h
@@ -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
diff --git a/src/daemon/priv-linux.c b/src/daemon/priv-linux.c
index 6b7d9f4b..315faf3e 100644
--- a/src/daemon/priv-linux.c
+++ b/src/daemon/priv-linux.c
@@ -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
--
2.39.5