netifd: Add option to configure base_reachable_time_ms for each device
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 2 Feb 2015 15:11:24 +0000 (16:11 +0100)
committerSteven Barth <steven@midlink.org>
Mon, 9 Feb 2015 08:26:25 +0000 (09:26 +0100)
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@gmail.com>
Signed-off-by: Jean-Francois Remy <jeff@melix.org>
device.c
device.h
system-linux.c

index 54638e7c25fb7e1bb85886ebbb8ff4886c0bb368..556d9fc89d695ffc6c340a6ea88249e4a7577c67 100644 (file)
--- 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");
index ca4cc1184e7144874fd088a06f9003b775df3cdf..6418f169a9baf57dbc2c3aaf872e1013d541b508 100644 (file)
--- 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;
 };
 
 /*
index 4737fa6e2c7083185af760c0e5142afb0175ece1..fb2ee29d2d8e216adf76163318e6da0fcc7590dc 100644 (file)
@@ -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)