netifd: Add option to configure gc_stale_time for each device
authorAlin Năstac <alin.nastac@gmail.com>
Tue, 24 May 2016 15:02:20 +0000 (17:02 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 1 Jun 2016 13:47:36 +0000 (15:47 +0200)
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@gmail.com>
device.c
device.h
system-linux.c

index 0e07615b1301e2813b112e2a6fff818d21de6628..06c48205991867f014edeeb4f6503c36b59a8663 100644 (file)
--- 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 },
@@ -173,6 +174,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 ?
@@ -262,6 +267,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;
@@ -945,6 +955,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)
index 4a88c0521c734bf4b90c58ce229b603bbdf0478f..77a2fefc09cee84b5225dc7b06936f4bf7a87b82 100644 (file)
--- a/device.h
+++ b/device.h
@@ -47,6 +47,7 @@ enum {
        DEV_ATTR_MULTICAST,
        DEV_ATTR_LEARNING,
        DEV_ATTR_UNICAST_FLOOD,
+       DEV_ATTR_NEIGHGCSTALETIME,
        __DEV_ATTR_MAX,
 };
 
@@ -92,6 +93,7 @@ enum {
        DEV_OPT_MULTICAST               = (1 << 16),
        DEV_OPT_LEARNING                = (1 << 17),
        DEV_OPT_UNICAST_FLOOD           = (1 << 18),
+       DEV_OPT_NEIGHGCSTALETIME        = (1 << 19),
 };
 
 /* events broadcasted to all users of a device */
@@ -147,6 +149,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;
index 621f99b3fd6984412aeac47ef26a53370b7b321a..90b0775d57bd26b6ff29f9040f17bf53031469ad 100644 (file)
@@ -306,6 +306,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);
@@ -452,6 +462,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",
@@ -1243,6 +1265,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;
@@ -1337,6 +1369,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);