summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2014-12-23 14:12:32 +0100
committerSteven Barth <steven@midlink.org>2014-12-23 14:12:32 +0100
commit6b4570a107447034b5ae3861a7ca388d3052460a (patch)
tree5f65dc9775616c84d1e52c1d7c870244750addff
parent02713a50084b26a927d5d1f95455829d320aa4e1 (diff)
downloadnetifd-6b4570a107447034b5ae3861a7ca388d3052460a.tar.gz
netifd: Add mldversion config support
Config support to set the MLD host version on device level; possible values are : 1 : MLDv1 2 : MLDv2 Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> Cleaned up and simplified. Signed-off-by: Steven Barth <steven@midlink.org>
-rw-r--r--device.c15
-rw-r--r--device.h3
-rw-r--r--system-dummy.c6
-rw-r--r--system-linux.c34
-rw-r--r--system.h1
5 files changed, 39 insertions, 20 deletions
diff --git a/device.c b/device.c
index 6cdfb49..6eb1486 100644
--- a/device.c
+++ b/device.c
@@ -42,6 +42,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
[DEV_ATTR_RPFILTER] = { .name = "rpfilter", .type = BLOBMSG_TYPE_STRING },
[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 },
};
const struct uci_blob_param_list device_attr_list = {
@@ -160,6 +161,7 @@ device_merge_settings(struct device *dev, struct device_settings *n)
n->rpfilter = s->flags & DEV_OPT_RPFILTER ? s->rpfilter : os->rpfilter;
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->flags = s->flags | os->flags;
}
@@ -216,12 +218,21 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
}
if ((cur = tb[DEV_ATTR_IGMPVERSION])) {
- if (system_resolve_igmpversion(blobmsg_get_u32(cur), &s->igmpversion))
+ s->igmpversion = blobmsg_get_u32(cur);
+ if (s->igmpversion >= 1 && s->igmpversion <= 3)
s->flags |= DEV_OPT_IGMPVERSION;
else
DPRINTF("Failed to resolve igmpversion: %d\n", blobmsg_get_u32(cur));
}
+ if ((cur = tb[DEV_ATTR_MLDVERSION])) {
+ s->mldversion = blobmsg_get_u32(cur);
+ if (s->mldversion >= 1 && s->mldversion <= 2)
+ s->flags |= DEV_OPT_MLDVERSION;
+ else
+ DPRINTF("Failed to resolve mldversion: %d\n", blobmsg_get_u32(cur));
+ }
+
device_set_disabled(dev, disabled);
}
@@ -765,6 +776,8 @@ device_dump_status(struct blob_buf *b, struct device *dev)
blobmsg_add_u8(b, "acceptlocal", st.acceptlocal);
if (st.flags & DEV_OPT_IGMPVERSION)
blobmsg_add_u32(b, "igmpversion", st.igmpversion);
+ if (st.flags & DEV_OPT_MLDVERSION)
+ blobmsg_add_u32(b, "mldversion", st.mldversion);
}
s = blobmsg_open_table(b, "statistics");
diff --git a/device.h b/device.h
index a83cac8..0772f5f 100644
--- a/device.h
+++ b/device.h
@@ -36,6 +36,7 @@ enum {
DEV_ATTR_RPFILTER,
DEV_ATTR_ACCEPTLOCAL,
DEV_ATTR_IGMPVERSION,
+ DEV_ATTR_MLDVERSION,
__DEV_ATTR_MAX,
};
@@ -72,6 +73,7 @@ enum {
DEV_OPT_RPFILTER = (1 << 5),
DEV_OPT_ACCEPTLOCAL = (1 << 6),
DEV_OPT_IGMPVERSION = (1 << 7),
+ DEV_OPT_MLDVERSION = (1 << 8),
};
/* events broadcasted to all users of a device */
@@ -122,6 +124,7 @@ struct device_settings {
unsigned int rpfilter;
bool acceptlocal;
unsigned int igmpversion;
+ unsigned int mldversion;
};
/*
diff --git a/system-dummy.c b/system-dummy.c
index 9542d3c..76c6ffa 100644
--- a/system-dummy.c
+++ b/system-dummy.c
@@ -215,12 +215,6 @@ bool system_resolve_rpfilter(const char *filter, unsigned int *id)
return true;
}
-bool system_resolve_igmpversion(const unsigned int version, unsigned int *id)
-{
- *id = 0;
- return true;
-}
-
int system_add_iprule(struct iprule *rule)
{
return 0;
diff --git a/system-linux.c b/system-linux.c
index 7beae09..4737fa6 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -280,6 +280,11 @@ static void system_set_igmpversion(struct device *dev, const char *val)
system_set_dev_sysctl("/proc/sys/net/ipv4/conf/%s/force_igmp_version", dev->ifname, val);
}
+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 int system_get_sysctl(const char *path, char *buf, const size_t buf_sz)
{
int fd = -1, ret = -1;
@@ -332,6 +337,12 @@ static int system_get_igmpversion(struct device *dev, char *buf, const size_t bu
dev->ifname, buf, buf_sz);
}
+static int system_get_mldversion(struct device *dev, char *buf, const size_t buf_sz)
+{
+ return system_get_dev_sysctl("/proc/sys/net/ipv6/conf/%s/force_mld_version",
+ dev->ifname, buf, buf_sz);
+}
+
// Evaluate netlink messages
static int cb_rtnl_event(struct nl_msg *msg, void *arg)
{
@@ -1001,6 +1012,11 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
s->igmpversion = strtoul(buf, NULL, 0);
s->flags |= DEV_OPT_IGMPVERSION;
}
+
+ if (!system_get_mldversion(dev, buf, sizeof(buf))) {
+ s->mldversion = strtoul(buf, NULL, 0);
+ s->flags |= DEV_OPT_MLDVERSION;
+ }
}
void
@@ -1050,6 +1066,12 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned
snprintf(buf, sizeof(buf), "%d", s->igmpversion);
system_set_igmpversion(dev, buf);
}
+ if (s->flags & DEV_OPT_MLDVERSION & apply_mask) {
+ char buf[2];
+
+ snprintf(buf, sizeof(buf), "%d", s->mldversion);
+ system_set_mldversion(dev, buf);
+ }
}
int system_if_up(struct device *dev)
@@ -1597,18 +1619,6 @@ bool system_resolve_rpfilter(const char *filter, unsigned int *id)
return true;
}
-bool system_resolve_igmpversion(const unsigned int version, unsigned int *id)
-{
- if (!version || version > 3)
- return false;
-
- *id = version;
- if (*id == 3)
- *id = 0;
-
- return true;
-}
-
static int system_iprule(struct iprule *rule, int cmd)
{
int alen = ((rule->flags & IPRULE_FAMILY) == IPRULE_INET4) ? 4 : 16;
diff --git a/system.h b/system.h
index 8c9e994..9a2326b 100644
--- a/system.h
+++ b/system.h
@@ -136,7 +136,6 @@ bool system_resolve_rt_type(const char *type, unsigned int *id);
bool system_resolve_rt_table(const char *name, unsigned int *id);
bool system_is_default_rt_table(unsigned int id);
bool system_resolve_rpfilter(const char *filter, unsigned int *id);
-bool system_resolve_igmpversion(const unsigned int version, unsigned int *id);
int system_del_ip_tunnel(const char *name, struct blob_attr *attr);
int system_add_ip_tunnel(const char *name, struct blob_attr *attr);