[OpenWrt-Devel] [PATCH] netifd: Add option to configure gc_stale_time for each device
Alin Nastac
alin.nastac at gmail.com
Tue May 24 11:02:20 EDT 2016
The UCI parameter neighgcstaletime allows to control how much time will
STALE entries be kept in the neighbour table for both IPv4 and IPv6.
Signed-off-by: Alin Nastac <alin.nastac at gmail.com>
---
device.c | 14 ++++++++++++++
device.h | 4 ++++
system-linux.c | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+)
diff --git a/device.c b/device.c
index 7004bfd..3e182f3 100644
--- a/device.c
+++ b/device.c
@@ -45,6 +45,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
[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 },
+ [DEV_ATTR_NEIGHGCSTALETIME] = { .name = "neighgcstaletime", .type = BLOBMSG_TYPE_INT32 },
[DEV_ATTR_RPS] = { .name = "rps", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_XPS] = { .name = "xps", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_DADTRANSMITS] = { .name = "dadtransmits", .type = BLOBMSG_TYPE_INT32 },
@@ -171,6 +172,10 @@ device_merge_settings(struct device *dev, struct device_settings *n)
s->neigh4reachabletime : os->neigh4reachabletime;
n->neigh6reachabletime = s->flags & DEV_OPT_NEIGHREACHABLETIME ?
s->neigh6reachabletime : os->neigh6reachabletime;
+ n->neigh4gcstaletime = s->flags & DEV_OPT_NEIGHGCSTALETIME ?
+ s->neigh4gcstaletime : os->neigh4gcstaletime;
+ n->neigh6gcstaletime = s->flags & DEV_OPT_NEIGHGCSTALETIME ?
+ s->neigh6gcstaletime : os->neigh6gcstaletime;
n->dadtransmits = s->flags & DEV_OPT_DADTRANSMITS ?
s->dadtransmits : os->dadtransmits;
n->multicast = s->flags & DEV_OPT_MULTICAST ?
@@ -258,6 +263,11 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
s->flags |= DEV_OPT_NEIGHREACHABLETIME;
}
+ if ((cur = tb[DEV_ATTR_NEIGHGCSTALETIME])) {
+ s->neigh6gcstaletime = s->neigh4gcstaletime = blobmsg_get_u32(cur);
+ s->flags |= DEV_OPT_NEIGHGCSTALETIME;
+ }
+
if ((cur = tb[DEV_ATTR_RPS])) {
s->rps = blobmsg_get_bool(cur);
s->flags |= DEV_OPT_RPS;
@@ -960,6 +970,10 @@ device_dump_status(struct blob_buf *b, struct device *dev)
blobmsg_add_u32(b, "neigh4reachabletime", st.neigh4reachabletime);
blobmsg_add_u32(b, "neigh6reachabletime", st.neigh6reachabletime);
}
+ if (st.flags & DEV_OPT_NEIGHGCSTALETIME) {
+ blobmsg_add_u32(b, "neigh4gcstaletime", st.neigh4gcstaletime);
+ blobmsg_add_u32(b, "neigh6gcstaletime", st.neigh6gcstaletime);
+ }
if (st.flags & DEV_OPT_DADTRANSMITS)
blobmsg_add_u32(b, "dadtransmits", st.dadtransmits);
if (st.flags & DEV_OPT_MULTICAST_TO_UNICAST)
diff --git a/device.h b/device.h
index 9c4b822..0b8cd6a 100644
--- a/device.h
+++ b/device.h
@@ -45,6 +45,7 @@ enum {
DEV_ATTR_MULTICAST_TO_UNICAST,
DEV_ATTR_MULTICAST_ROUTER,
DEV_ATTR_MULTICAST,
+ DEV_ATTR_NEIGHGCSTALETIME,
__DEV_ATTR_MAX,
};
@@ -88,6 +89,7 @@ enum {
DEV_OPT_MULTICAST_TO_UNICAST = (1 << 14),
DEV_OPT_MULTICAST_ROUTER = (1 << 15),
DEV_OPT_MULTICAST = (1 << 16),
+ DEV_OPT_NEIGHGCSTALETIME = (1 << 17),
};
/* events broadcasted to all users of a device */
@@ -143,6 +145,8 @@ struct device_settings {
unsigned int mldversion;
unsigned int neigh4reachabletime;
unsigned int neigh6reachabletime;
+ unsigned int neigh4gcstaletime;
+ unsigned int neigh6gcstaletime;
bool rps;
bool xps;
unsigned int dadtransmits;
diff --git a/system-linux.c b/system-linux.c
index f79625a..62c51b5 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -310,6 +310,16 @@ 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 void system_set_neigh4gcstaletime(struct device *dev, const char *val)
+{
+ system_set_dev_sysctl("/proc/sys/net/ipv4/neigh/%s/gc_stale_time", dev->ifname, val);
+}
+
+static void system_set_neigh6gcstaletime(struct device *dev, const char *val)
+{
+ system_set_dev_sysctl("/proc/sys/net/ipv6/neigh/%s/gc_stale_time", dev->ifname, val);
+}
+
static void system_set_dadtransmits(struct device *dev, const char *val)
{
system_set_dev_sysctl("/proc/sys/net/ipv6/conf/%s/dad_transmits", dev->ifname, val);
@@ -446,6 +456,18 @@ static int system_get_neigh6reachabletime(struct device *dev, char *buf, const s
dev->ifname, buf, buf_sz);
}
+static int system_get_neigh4gcstaletime(struct device *dev, char *buf, const size_t buf_sz)
+{
+ return system_get_dev_sysctl("/proc/sys/net/ipv4/neigh/%s/gc_stale_time",
+ dev->ifname, buf, buf_sz);
+}
+
+static int system_get_neigh6gcstaletime(struct device *dev, char *buf, const size_t buf_sz)
+{
+ return system_get_dev_sysctl("/proc/sys/net/ipv6/neigh/%s/gc_stale_time",
+ dev->ifname, buf, buf_sz);
+}
+
static int system_get_dadtransmits(struct device *dev, char *buf, const size_t buf_sz)
{
return system_get_dev_sysctl("/proc/sys/net/ipv6/conf/%s/dad_transmits",
@@ -1230,6 +1252,16 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
s->flags |= DEV_OPT_NEIGHREACHABLETIME;
}
+ if (!system_get_neigh4gcstaletime(dev, buf, sizeof(buf))) {
+ s->neigh4gcstaletime = strtoul(buf, NULL, 0);
+ s->flags |= DEV_OPT_NEIGHGCSTALETIME;
+ }
+
+ if (!system_get_neigh6gcstaletime(dev, buf, sizeof(buf))) {
+ s->neigh6gcstaletime = strtoul(buf, NULL, 0);
+ s->flags |= DEV_OPT_NEIGHGCSTALETIME;
+ }
+
if (!system_get_dadtransmits(dev, buf, sizeof(buf))) {
s->dadtransmits = strtoul(buf, NULL, 0);
s->flags |= DEV_OPT_DADTRANSMITS;
@@ -1324,6 +1356,12 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned
snprintf(buf, sizeof(buf), "%d", s->neigh6reachabletime);
system_set_neigh6reachabletime(dev, buf);
}
+ if (s->flags & DEV_OPT_NEIGHGCSTALETIME & apply_mask) {
+ snprintf(buf, sizeof(buf), "%d", s->neigh4gcstaletime);
+ system_set_neigh4gcstaletime(dev, buf);
+ snprintf(buf, sizeof(buf), "%d", s->neigh6gcstaletime);
+ system_set_neigh6gcstaletime(dev, buf);
+ }
if (s->flags & DEV_OPT_DADTRANSMITS & apply_mask) {
snprintf(buf, sizeof(buf), "%d", s->dadtransmits);
system_set_dadtransmits(dev, buf);
--
1.7.12.4
_______________________________________________
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