[PATCH 2/6] add device setting for disabeling arp

Joerg Vehlow lkml at jv-coder.de
Thu Nov 3 23:20:49 PDT 2022


From: Joerg Vehlow <joerg.vehlow at aox.de>

---
 device.c       | 7 +++++++
 device.h       | 3 +++
 system-linux.c | 7 +++++++
 3 files changed, 17 insertions(+)

diff --git a/device.c b/device.c
index 4f55906..9ed50ef 100644
--- a/device.c
+++ b/device.c
@@ -65,6 +65,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
 	[DEV_ATTR_DUPLEX] = { .name = "duplex", .type = BLOBMSG_TYPE_BOOL },
 	[DEV_ATTR_IP_FORWARDING] = { .name = "ip_forwarding", .type = BLOBMSG_TYPE_BOOL},
 	[DEV_ATTR_IP6_FORWARDING] = { .name = "ip6_forwarding", .type = BLOBMSG_TYPE_BOOL},
+	[DEV_ATTR_ARP] = { .name = "arp", .type = BLOBMSG_TYPE_BOOL},
 };
 
 const struct uci_blob_param_list device_attr_list = {
@@ -284,6 +285,7 @@ device_merge_settings(struct device *dev, struct device_settings *n)
 	n->duplex = s->flags & DEV_OPT_DUPLEX ? s->duplex : os->duplex;
 	n->ip_forwarding = s->flags & DEV_OPT_IP_FORWARDING ? s->ip_forwarding : os->ip_forwarding;
 	n->ip6_forwarding = s->flags & DEV_OPT_IP6_FORWARDING ? s->ip6_forwarding : os->ip6_forwarding;
+	n->arp = s->flags & DEV_OPT_ARP ? s->arp : os->arp;
 	n->flags = s->flags | os->flags | os->valid_flags;
 }
 
@@ -478,6 +480,11 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
 		s->flags |= DEV_OPT_IP6_FORWARDING;
 	}
 
+	if ((cur = tb[DEV_ATTR_ARP])) {
+		s->arp = blobmsg_get_bool(cur);
+		s->flags |= DEV_OPT_ARP;
+	}
+
 	device_set_disabled(dev, disabled);
 }
 
diff --git a/device.h b/device.h
index 066f537..f78bbcb 100644
--- a/device.h
+++ b/device.h
@@ -64,6 +64,7 @@ enum {
 	DEV_ATTR_DUPLEX,
 	DEV_ATTR_IP_FORWARDING,
 	DEV_ATTR_IP6_FORWARDING,
+	DEV_ATTR_ARP,
 	__DEV_ATTR_MAX,
 };
 
@@ -130,6 +131,7 @@ enum {
 	DEV_OPT_DUPLEX			= (1ULL << 31),
 	DEV_OPT_IP_FORWARDING   = (1ULL << 32),
 	DEV_OPT_IP6_FORWARDING  = (1ULL << 33),
+	DEV_OPT_ARP             = (1ULL << 34),
 };
 
 /* events broadcasted to all users of a device */
@@ -209,6 +211,7 @@ struct device_settings {
 	bool duplex;
 	bool ip_forwarding;
 	bool ip6_forwarding;
+	bool arp;
 };
 
 /*
diff --git a/system-linux.c b/system-linux.c
index 6232a26..7b82e17 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -1736,6 +1736,9 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
 
 		s->multicast = ifr.ifr_flags & IFF_MULTICAST;
 		s->flags |= DEV_OPT_MULTICAST;
+
+		s->arp = !(ifr.ifr_flags & IFF_NOARP);
+		s->arp |= DEV_OPT_ARP;
 	}
 
 	if (!system_get_rpfilter(dev, buf, sizeof(buf))) {
@@ -1929,6 +1932,10 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, uint64_t
 		system_set_ip_forwarding(dev, s->ip_forwarding ? "1" : "0");
 	if (apply_mask & DEV_OPT_IP6_FORWARDING)
 		system_set_ip6_forwarding(dev, s->ip6_forwarding ? "1" : "0");
+	if (apply_mask & DEV_OPT_ARP) {
+		if (system_if_flags(dev->ifname, !s->arp ? IFF_NOARP : 0, s->arp ? IFF_NOARP : 0) < 0)
+			s->flags &= ~DEV_OPT_ARP;
+	}
 
 	system_set_ethtool_settings(dev, s);
 }
-- 
2.25.1




More information about the openwrt-devel mailing list