diff mbox

[OpenWrt-Devel,1/2,package] netifd: multicast flag control

Message ID B4EFE0128BCDD542A8E7DC55F7D7FCF61CFBFBAE@bb-corp-mbx02.corp.cubic.cub
State Superseded
Headers show

Commit Message

Podolak, Nicholas Sept. 2, 2015, 8:30 p.m. UTC
From: Nick Podolak <nicholas.podolak@dtechlabs.com >

This patch set allows for interfaces defined in UCI to enable and disable multicast support on their underlying device.  This has particular use on GRE tunnels which previously did NOT enable multicast by default.  Since GRE is commonly used to create router to router links that support multicast for use by routing protocols (e.g. OSPF, EIGRP, etc), or specifically for multicast applications, this modification seemed necessary.

This first patch adds the multicast capability to all interfaces/devices.

Signed-off-by: Nick Podolak <nicholas.podolak@dtechlabs.com>

 	uint8_t macaddr[6];
 	bool ipv6;
 	bool promisc;
+	bool multicast;
 	unsigned int rpfilter;
 	bool acceptlocal;
 	unsigned int igmpversion;
diff mbox

Patch

Index: netifd-2015-06-08/device.c
===================================================================
--- netifd-2015-06-08.orig/device.c
+++ netifd-2015-06-08/device.c
@@ -39,6 +39,7 @@  static const struct blobmsg_policy dev_a
 	[DEV_ATTR_ENABLED] = { .name = "enabled", .type = BLOBMSG_TYPE_BOOL },
 	[DEV_ATTR_IPV6] = { .name = "ipv6", .type = BLOBMSG_TYPE_BOOL },
 	[DEV_ATTR_PROMISC] = { .name = "promisc", .type = BLOBMSG_TYPE_BOOL },
+	[DEV_ATTR_MULTICAST] = { .name = "multicast", .type = 
+BLOBMSG_TYPE_BOOL },
 	[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 }, @@ -161,6 +162,7 @@ device_merge_settings(struct device *dev
 		sizeof(n->macaddr));
 	n->ipv6 = s->flags & DEV_OPT_IPV6 ? s->ipv6 : os->ipv6;
 	n->promisc = s->flags & DEV_OPT_PROMISC ? s->promisc : os->promisc;
+	n->multicast = s->flags & DEV_OPT_MULTICAST ? s->multicast : 
+os->multicast;
 	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; @@ -212,6 +214,11 @@ device_init_settings(struct device *dev,
 		s->flags |= DEV_OPT_PROMISC;
 	}
 
+	if ((cur = tb[DEV_ATTR_MULTICAST])) {
+		s->multicast = blobmsg_get_bool(cur);
+		s->flags |= DEV_OPT_MULTICAST;
+	}
+
 	if ((cur = tb[DEV_ATTR_RPFILTER])) {
 		if (system_resolve_rpfilter(blobmsg_data(cur), &s->rpfilter))
 			s->flags |= DEV_OPT_RPFILTER;
@@ -851,6 +858,8 @@  device_dump_status(struct blob_buf *b, s
 			blobmsg_add_u8(b, "ipv6", st.ipv6);
 		if (st.flags & DEV_OPT_PROMISC)
 			blobmsg_add_u8(b, "promisc", st.promisc);
+		if (st.flags & DEV_OPT_MULTICAST)
+			blobmsg_add_u8(b, "multicast", st.multicast);
 		if (st.flags & DEV_OPT_RPFILTER)
 			blobmsg_add_u32(b, "rpfilter", st.rpfilter);
 		if (st.flags & DEV_OPT_ACCEPTLOCAL)
Index: netifd-2015-06-08/system-linux.c
===================================================================
--- netifd-2015-06-08.orig/system-linux.c
+++ netifd-2015-06-08/system-linux.c
@@ -1039,6 +1039,11 @@  system_if_get_settings(struct device *de
 		s->flags |= DEV_OPT_PROMISC;
 	}
 
+	if (ioctl(sock_ioctl, SIOCGIFFLAGS, &ifr) == 0) {
+		s->multicast = ifr.ifr_flags & IFF_MULTICAST;
+		s->flags |= DEV_OPT_MULTICAST;
+	}
+
 	if (!system_get_rpfilter(dev, buf, sizeof(buf))) {
 		s->rpfilter = strtoul(buf, NULL, 0);
 		s->flags |= DEV_OPT_RPFILTER;
@@ -1132,6 +1137,11 @@  system_if_apply_settings(struct device *
 				    !s->promisc ? IFF_PROMISC : 0) < 0)
 			s->flags &= ~DEV_OPT_PROMISC;
 	}
+	if (s->flags & DEV_OPT_MULTICAST & apply_mask) {
+		if (system_if_flags(dev->ifname, s->multicast ? IFF_MULTICAST : 0,
+				    !s->multicast ? IFF_MULTICAST : 0) < 0)
+			s->flags &= ~DEV_OPT_MULTICAST;
+	}
 	if (s->flags & DEV_OPT_RPFILTER & apply_mask) {
 		char buf[2];
 
Index: netifd-2015-06-08/device.h
===================================================================
--- netifd-2015-06-08.orig/device.h
+++ netifd-2015-06-08/device.h
@@ -33,6 +33,7 @@  enum {
 	DEV_ATTR_ENABLED,
 	DEV_ATTR_IPV6,
 	DEV_ATTR_PROMISC,
+	DEV_ATTR_MULTICAST,
 	DEV_ATTR_RPFILTER,
 	DEV_ATTR_ACCEPTLOCAL,
 	DEV_ATTR_IGMPVERSION,
@@ -80,6 +81,7 @@  enum {
 	DEV_OPT_NEIGHREACHABLETIME	= (1 << 9),
 	DEV_OPT_RPS			= (1 << 10),
 	DEV_OPT_XPS			= (1 << 11),
+	DEV_OPT_MULTICAST		= (1 << 12),
 };
 
 /* events broadcasted to all users of a device */ @@ -127,6 +129,7 @@ struct device_settings {