[OpenWrt-Devel] [PATCH][netifd] device: add proxy_arp config support
Hrvoje Varga
hrvoje.varga at sartura.hr
Tue Oct 25 06:54:30 EDT 2016
Add interface config support to enable or disable ARP proxy in the
kernel per device.
Signed-off-by: Hrvoje Varga <hrvoje.varga at sartura.hr>
---
bridge.c | 5 +++++
device.c | 9 +++++++++
device.h | 3 +++
system-linux.c | 18 ++++++++++++++++++
system.h | 1 +
5 files changed, 36 insertions(+)
diff --git a/bridge.c b/bridge.c
index 8e6c9a6..8f2bd30 100644
--- a/bridge.c
+++ b/bridge.c
@@ -176,6 +176,11 @@ bridge_enable_interface(struct bridge_state *bst)
return ret;
bst->active = true;
+
+ if (bst->dev.settings.flags & DEV_OPT_PROXY_ARP) {
+ system_set_proxy_arp(&bst->dev, bst->dev.settings.proxy_arp ? "1" : "0");
+ }
+
return 0;
}
diff --git a/device.c b/device.c
index 82596e4..aa06d37 100644
--- a/device.c
+++ b/device.c
@@ -58,6 +58,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
[DEV_ATTR_MULTICAST] = { .name ="multicast", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_LEARNING] = { .name ="learning", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_UNICAST_FLOOD] = { .name ="unicast_flood", .type = BLOBMSG_TYPE_BOOL },
+ [DEV_ATTR_PROXY_ARP] = { .name ="proxy_arp", .type = BLOBMSG_TYPE_BOOL },
};
const struct uci_blob_param_list device_attr_list = {
@@ -225,6 +226,7 @@ device_merge_settings(struct device *dev, struct device_settings *n)
n->multicast_fast_leave = s->multicast_fast_leave;
n->learning = s->learning;
n->unicast_flood = s->unicast_flood;
+ n->proxy_arp = s->flags & DEV_OPT_PROXY_ARP ? s->proxy_arp : os->proxy_arp;
n->flags = s->flags | os->flags | os->valid_flags;
}
@@ -363,6 +365,11 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
s->flags |= DEV_OPT_UNICAST_FLOOD;
}
+ if ((cur = tb[DEV_ATTR_PROXY_ARP])) {
+ s->proxy_arp = blobmsg_get_bool(cur);
+ s->flags |= DEV_OPT_PROXY_ARP;
+ }
+
device_set_disabled(dev, disabled);
}
@@ -1050,6 +1057,8 @@ device_dump_status(struct blob_buf *b, struct device *dev)
blobmsg_add_u8(b, "learning", st.learning);
if (st.flags & DEV_OPT_UNICAST_FLOOD)
blobmsg_add_u8(b, "unicast_flood", st.unicast_flood);
+ if (st.flags & DEV_OPT_PROXY_ARP)
+ blobmsg_add_u8(b, "proxy_arp", st.proxy_arp);
}
s = blobmsg_open_table(b, "statistics");
diff --git a/device.h b/device.h
index 2af93bb..699c7cc 100644
--- a/device.h
+++ b/device.h
@@ -50,6 +50,7 @@ enum {
DEV_ATTR_LEARNING,
DEV_ATTR_UNICAST_FLOOD,
DEV_ATTR_NEIGHGCSTALETIME,
+ DEV_ATTR_PROXY_ARP,
__DEV_ATTR_MAX,
};
@@ -101,6 +102,7 @@ enum {
DEV_OPT_UNICAST_FLOOD = (1 << 18),
DEV_OPT_NEIGHGCSTALETIME = (1 << 19),
DEV_OPT_MULTICAST_FAST_LEAVE = (1 << 20),
+ DEV_OPT_PROXY_ARP = (1 << 21),
};
/* events broadcasted to all users of a device */
@@ -167,6 +169,7 @@ struct device_settings {
bool multicast;
bool learning;
bool unicast_flood;
+ bool proxy_arp;
};
/*
diff --git a/system-linux.c b/system-linux.c
index 6e4a194..d0c8655 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -271,6 +271,11 @@ static void system_set_dev_sysctl(const char *path, const char *device, const ch
system_set_sysctl(dev_buf, val);
}
+void system_set_proxy_arp(struct device *dev, const char *val)
+{
+ system_set_dev_sysctl("/proc/sys/net/ipv4/conf/%s/proxy_arp", dev->ifname, val);
+}
+
static void system_set_disable_ipv6(struct device *dev, const char *val)
{
system_set_dev_sysctl("/proc/sys/net/ipv6/conf/%s/disable_ipv6", dev->ifname, val);
@@ -485,6 +490,12 @@ static int system_get_dadtransmits(struct device *dev, char *buf, const size_t b
dev->ifname, buf, buf_sz);
}
+static int system_get_proxy_arp(struct device *dev, char *buf, const size_t buf_sz)
+{
+ return system_get_dev_sysctl("/proc/sys/net/ipv4/conf/%s/proxy_arp",
+ dev->ifname, buf, buf_sz);
+}
+
// Evaluate netlink messages
static int cb_rtnl_event(struct nl_msg *msg, void *arg)
{
@@ -1288,6 +1299,11 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
s->dadtransmits = strtoul(buf, NULL, 0);
s->flags |= DEV_OPT_DADTRANSMITS;
}
+
+ if (!system_get_proxy_arp(dev, buf, sizeof(buf))) {
+ s->proxy_arp = strtoul(buf, NULL, 0);
+ s->flags |= DEV_OPT_PROXY_ARP;
+ }
}
static void
@@ -1393,6 +1409,8 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned
!s->multicast ? IFF_MULTICAST : 0) < 0)
s->flags &= ~DEV_OPT_MULTICAST;
}
+ if (s->flags & DEV_OPT_PROXY_ARP & apply_mask)
+ system_set_proxy_arp(dev, s->proxy_arp ? "1" : "0");
system_if_apply_rps_xps(dev, s);
}
diff --git a/system.h b/system.h
index d5cb4e3..a41a1b2 100644
--- a/system.h
+++ b/system.h
@@ -165,4 +165,5 @@ void system_fd_set_cloexec(int fd);
int system_update_ipv6_mtu(struct device *device, int mtu);
+void system_set_proxy_arp(struct device *dev, const char *val);
#endif
--
2.10.0
_______________________________________________
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