[OpenWrt-Devel] [PATCH 3/3] netifd: Add option to configure base_reachable_time_ms for each device

Hans Dedecker dedeckeh at gmail.com
Mon Feb 2 10:11:24 EST 2015


The UCI parameter neighreachabletime allows to control the hardware address
to IP mapping lifetime in the neighbour table for both IPv4 and IPv6

Signed-off-by: Hans Dedecker <dedeckeh at gmail.com>
Signed-off-by: Jean-Francois Remy <jeff at melix.org>
---
 device.c       | 14 ++++++++++++++
 device.h       | 22 +++++++++++++---------
 system-linux.c | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/device.c b/device.c
index 54638e7..556d9fc 100644
--- a/device.c
+++ b/device.c
@@ -43,6 +43,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
 	[DEV_ATTR_ACCEPTLOCAL] = { .name = "acceptlocal", .type = BLOBMSG_TYPE_BOOL },
 	[DEV_ATTR_IGMPVERSION] = { .name = "igmpversion", .type = BLOBMSG_TYPE_INT32 },
 	[DEV_ATTR_MLDVERSION] = { .name = "mldversion", .type = BLOBMSG_TYPE_INT32 },
+	[DEV_ATTR_NEIGHREACHABLETIME] = { .name = "neighreachabletime", .type = BLOBMSG_TYPE_INT32 },
 };
 
 const struct uci_blob_param_list device_attr_list = {
@@ -162,6 +163,10 @@ device_merge_settings(struct device *dev, struct device_settings *n)
 	n->acceptlocal = s->flags & DEV_OPT_ACCEPTLOCAL ? s->acceptlocal : os->acceptlocal;
 	n->igmpversion = s->flags & DEV_OPT_IGMPVERSION ? s->igmpversion : os->igmpversion;
 	n->mldversion = s->flags & DEV_OPT_MLDVERSION ? s->mldversion : os->mldversion;
+	n->neigh4reachabletime = s->flags & DEV_OPT_NEIGHREACHABLETIME ?
+		s->neigh4reachabletime : os->neigh4reachabletime;
+	n->neigh6reachabletime = s->flags & DEV_OPT_NEIGHREACHABLETIME ?
+			s->neigh6reachabletime : os->neigh6reachabletime;
 	n->flags = s->flags | os->flags;
 }
 
@@ -233,6 +238,11 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
 			DPRINTF("Failed to resolve mldversion: %d\n", blobmsg_get_u32(cur));
 	}
 
+	if ((cur = tb[DEV_ATTR_NEIGHREACHABLETIME])) {
+		s->neigh6reachabletime = s->neigh4reachabletime = blobmsg_get_u32(cur);
+		s->flags |= DEV_OPT_NEIGHREACHABLETIME;
+	}
+
 	device_set_disabled(dev, disabled);
 }
 
@@ -794,6 +804,10 @@ device_dump_status(struct blob_buf *b, struct device *dev)
 			blobmsg_add_u32(b, "igmpversion", st.igmpversion);
 		if (st.flags & DEV_OPT_MLDVERSION)
 			blobmsg_add_u32(b, "mldversion", st.mldversion);
+		if (st.flags & DEV_OPT_NEIGHREACHABLETIME) {
+			blobmsg_add_u32(b, "neigh4reachabletime", st.neigh4reachabletime);
+			blobmsg_add_u32(b, "neigh6reachabletime", st.neigh6reachabletime);
+		}
 	}
 
 	s = blobmsg_open_table(b, "statistics");
diff --git a/device.h b/device.h
index ca4cc11..6418f16 100644
--- a/device.h
+++ b/device.h
@@ -37,6 +37,7 @@ enum {
 	DEV_ATTR_ACCEPTLOCAL,
 	DEV_ATTR_IGMPVERSION,
 	DEV_ATTR_MLDVERSION,
+	DEV_ATTR_NEIGHREACHABLETIME,
 	__DEV_ATTR_MAX,
 };
 
@@ -65,15 +66,16 @@ struct device_type {
 };
 
 enum {
-	DEV_OPT_MTU		= (1 << 0),
-	DEV_OPT_MACADDR		= (1 << 1),
-	DEV_OPT_TXQUEUELEN	= (1 << 2),
-	DEV_OPT_IPV6		= (1 << 3),
-	DEV_OPT_PROMISC		= (1 << 4),
-	DEV_OPT_RPFILTER	= (1 << 5),
-	DEV_OPT_ACCEPTLOCAL	= (1 << 6),
-	DEV_OPT_IGMPVERSION	= (1 << 7),
-	DEV_OPT_MLDVERSION	= (1 << 8),
+	DEV_OPT_MTU			= (1 << 0),
+	DEV_OPT_MACADDR			= (1 << 1),
+	DEV_OPT_TXQUEUELEN		= (1 << 2),
+	DEV_OPT_IPV6			= (1 << 3),
+	DEV_OPT_PROMISC			= (1 << 4),
+	DEV_OPT_RPFILTER		= (1 << 5),
+	DEV_OPT_ACCEPTLOCAL		= (1 << 6),
+	DEV_OPT_IGMPVERSION		= (1 << 7),
+	DEV_OPT_MLDVERSION		= (1 << 8),
+	DEV_OPT_NEIGHREACHABLETIME	= (1 << 9),
 };
 
 /* events broadcasted to all users of a device */
@@ -125,6 +127,8 @@ struct device_settings {
 	bool acceptlocal;
 	unsigned int igmpversion;
 	unsigned int mldversion;
+	unsigned int neigh4reachabletime;
+	unsigned int neigh6reachabletime;
 };
 
 /*
diff --git a/system-linux.c b/system-linux.c
index 4737fa6..fb2ee29 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -285,6 +285,16 @@ static void system_set_mldversion(struct device *dev, const char *val)
 	system_set_dev_sysctl("/proc/sys/net/ipv6/conf/%s/force_mld_version", dev->ifname, val);
 }
 
+static void system_set_neigh4reachabletime(struct device *dev, const char *val)
+{
+	system_set_dev_sysctl("/proc/sys/net/ipv4/neigh/%s/base_reachable_time_ms", dev->ifname, val);
+}
+
+static void system_set_neigh6reachabletime(struct device *dev, const char *val)
+{
+	system_set_dev_sysctl("/proc/sys/net/ipv6/neigh/%s/base_reachable_time_ms", dev->ifname, val);
+}
+
 static int system_get_sysctl(const char *path, char *buf, const size_t buf_sz)
 {
 	int fd = -1, ret = -1;
@@ -343,6 +353,18 @@ static int system_get_mldversion(struct device *dev, char *buf, const size_t buf
 			dev->ifname, buf, buf_sz);
 }
 
+static int system_get_neigh4reachabletime(struct device *dev, char *buf, const size_t buf_sz)
+{
+	return system_get_dev_sysctl("/proc/sys/net/ipv4/neigh/%s/base_reachable_time_ms",
+			dev->ifname, buf, buf_sz);
+}
+
+static int system_get_neigh6reachabletime(struct device *dev, char *buf, const size_t buf_sz)
+{
+	return system_get_dev_sysctl("/proc/sys/net/ipv6/neigh/%s/base_reachable_time_ms",
+			dev->ifname, buf, buf_sz);
+}
+
 // Evaluate netlink messages
 static int cb_rtnl_event(struct nl_msg *msg, void *arg)
 {
@@ -1017,6 +1039,16 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
 		s->mldversion = strtoul(buf, NULL, 0);
 		s->flags |= DEV_OPT_MLDVERSION;
 	}
+
+	if (!system_get_neigh4reachabletime(dev, buf, sizeof(buf))) {
+		s->neigh4reachabletime = strtoul(buf, NULL, 0);
+		s->flags |= DEV_OPT_NEIGHREACHABLETIME;
+	}
+
+	if (!system_get_neigh6reachabletime(dev, buf, sizeof(buf))) {
+		s->neigh6reachabletime = strtoul(buf, NULL, 0);
+		s->flags |= DEV_OPT_NEIGHREACHABLETIME;
+	}
 }
 
 void
@@ -1072,6 +1104,14 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned
 		snprintf(buf, sizeof(buf), "%d", s->mldversion);
 		system_set_mldversion(dev, buf);
 	}
+	if (s->flags & DEV_OPT_NEIGHREACHABLETIME & apply_mask) {
+		char buf[12];
+
+		snprintf(buf, sizeof(buf), "%d", s->neigh4reachabletime);
+		system_set_neigh4reachabletime(dev, buf);
+		snprintf(buf, sizeof(buf), "%d", s->neigh6reachabletime);
+		system_set_neigh6reachabletime(dev, buf);
+	}
 }
 
 int system_if_up(struct device *dev)
-- 
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list