[OpenWrt-Devel] [PATCH netifd 15/16] device: Support multicast config option

Hans Dedecker dedeckeh at gmail.com
Mon Feb 1 04:56:29 EST 2016


Make multicast device flag configurable by extending device attributes
with the multicast attribute

Signed-off-by: Hans Dedecker <dedeckeh at gmail.com>
Signed-off-by: Nick Podolak <nicholas.podolak at dtechlabs.com>
---
Based on a patch by Nick Podolak (https://lists.openwrt.org/pipermail/openwrt-devel/2015-October/036654.html)
with some minor tweaks.
Original patch did not get applied due to line wrapping issue
(https://lists.openwrt.org/pipermail/openwrt-devel/2015-November/037336.html)

 device.c       | 10 ++++++++++
 device.h       |  3 +++
 system-linux.c |  8 ++++++++
 3 files changed, 21 insertions(+)

diff --git a/device.c b/device.c
index 65183f3..3404fee 100644
--- a/device.c
+++ b/device.c
@@ -50,6 +50,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
 	[DEV_ATTR_DADTRANSMITS] = { .name = "dadtransmits", .type = BLOBMSG_TYPE_INT32 },
 	[DEV_ATTR_MULTICAST_TO_UNICAST] = { .name = "multicast_to_unicast", .type = BLOBMSG_TYPE_BOOL },
 	[DEV_ATTR_MULTICAST_ROUTER] = { .name = "multicast_router", .type = BLOBMSG_TYPE_INT32 },
+	[DEV_ATTR_MULTICAST] = { .name ="multicast", .type = BLOBMSG_TYPE_BOOL },
 };
 
 const struct uci_blob_param_list device_attr_list = {
@@ -172,6 +173,8 @@ device_merge_settings(struct device *dev, struct device_settings *n)
 		s->neigh6reachabletime : os->neigh6reachabletime;
 	n->dadtransmits = s->flags & DEV_OPT_DADTRANSMITS ?
 		s->dadtransmits : os->dadtransmits;
+	n->multicast = s->flags & DEV_OPT_MULTICAST ?
+		s->multicast : os->multicast;
 	n->multicast_to_unicast = s->multicast_to_unicast;
 	n->multicast_router = s->multicast_router;
 	n->flags = s->flags | os->flags | os->valid_flags;
@@ -287,6 +290,11 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
 			DPRINTF("Invalid value: %d - (Use 0: never, 1: learn, 2: always)\n", blobmsg_get_u32(cur));
 	}
 
+	if ((cur = tb[DEV_ATTR_MULTICAST])) {
+		s->multicast = blobmsg_get_bool(cur);
+		s->flags |= DEV_OPT_MULTICAST;
+	}
+
 	device_set_disabled(dev, disabled);
 }
 
@@ -922,6 +930,8 @@ device_dump_status(struct blob_buf *b, struct device *dev)
 			blobmsg_add_u8(b, "multicast_to_unicast", st.multicast_to_unicast);
 		if (st.flags & DEV_OPT_MULTICAST_ROUTER)
 			blobmsg_add_u32(b, "multicast_router", st.multicast_router);
+		if (st.flags & DEV_OPT_MULTICAST)
+			blobmsg_add_u8(b, "multicast", st.multicast);
 	}
 
 	s = blobmsg_open_table(b, "statistics");
diff --git a/device.h b/device.h
index a6c131a..ac77cfb 100644
--- a/device.h
+++ b/device.h
@@ -44,6 +44,7 @@ enum {
 	DEV_ATTR_DADTRANSMITS,
 	DEV_ATTR_MULTICAST_TO_UNICAST,
 	DEV_ATTR_MULTICAST_ROUTER,
+	DEV_ATTR_MULTICAST,
 	__DEV_ATTR_MAX,
 };
 
@@ -86,6 +87,7 @@ enum {
 	DEV_OPT_DADTRANSMITS		= (1 << 13),
 	DEV_OPT_MULTICAST_TO_UNICAST	= (1 << 14),
 	DEV_OPT_MULTICAST_ROUTER	= (1 << 15),
+	DEV_OPT_MULTICAST		= (1 << 16),
 };
 
 /* events broadcasted to all users of a device */
@@ -146,6 +148,7 @@ struct device_settings {
 	unsigned int dadtransmits;
 	bool multicast_to_unicast;
 	unsigned int multicast_router;
+	bool multicast;
 };
 
 /*
diff --git a/system-linux.c b/system-linux.c
index 9978ade..86e373c 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -1089,6 +1089,9 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
 	if (ioctl(sock_ioctl, SIOCGIFFLAGS, &ifr) == 0) {
 		s->promisc = ifr.ifr_flags & IFF_PROMISC;
 		s->flags |= DEV_OPT_PROMISC;
+
+		s->multicast = ifr.ifr_flags & IFF_MULTICAST;
+		s->flags |= DEV_OPT_MULTICAST;
 	}
 
 	if (!system_get_rpfilter(dev, buf, sizeof(buf))) {
@@ -1219,6 +1222,11 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned
 		snprintf(buf, sizeof(buf), "%d", s->dadtransmits);
 		system_set_dadtransmits(dev, buf);
 	}
+	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;
+	}
 
 	system_if_apply_rps_xps(dev, s);
 }
-- 
1.9.1
_______________________________________________
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