Commit 70e4272b authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

net: bridge: add no_linklocal_learn bool option

Use the new boolopt API to add an option which disables learning from
link-local packets. The default is kept as before and learning is
enabled. This is a simple map from a boolopt bit to a bridge private
flag that is tested before learning.

v2: pass NULL for extack via sysfs
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a428afe8
...@@ -294,10 +294,13 @@ struct br_mcast_stats { ...@@ -294,10 +294,13 @@ struct br_mcast_stats {
}; };
/* bridge boolean options /* bridge boolean options
* BR_BOOLOPT_NO_LL_LEARN - disable learning from link-local packets
*
* IMPORTANT: if adding a new option do not forget to handle * IMPORTANT: if adding a new option do not forget to handle
* it in br_boolopt_toggle/get and bridge sysfs * it in br_boolopt_toggle/get and bridge sysfs
*/ */
enum br_boolopt_id { enum br_boolopt_id {
BR_BOOLOPT_NO_LL_LEARN,
BR_BOOLOPT_MAX BR_BOOLOPT_MAX
}; };
......
...@@ -189,6 +189,9 @@ int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on, ...@@ -189,6 +189,9 @@ int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
switch (opt) { switch (opt) {
case BR_BOOLOPT_NO_LL_LEARN:
br_opt_toggle(br, BROPT_NO_LL_LEARN, on);
break;
default: default:
/* shouldn't be called with unsupported options */ /* shouldn't be called with unsupported options */
WARN_ON(1); WARN_ON(1);
...@@ -201,6 +204,8 @@ int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on, ...@@ -201,6 +204,8 @@ int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt) int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt)
{ {
switch (opt) { switch (opt) {
case BR_BOOLOPT_NO_LL_LEARN:
return br_opt_get(br, BROPT_NO_LL_LEARN);
default: default:
/* shouldn't be called with unsupported options */ /* shouldn't be called with unsupported options */
WARN_ON(1); WARN_ON(1);
......
...@@ -188,7 +188,9 @@ static void __br_handle_local_finish(struct sk_buff *skb) ...@@ -188,7 +188,9 @@ static void __br_handle_local_finish(struct sk_buff *skb)
u16 vid = 0; u16 vid = 0;
/* check if vlan is allowed, to avoid spoofing */ /* check if vlan is allowed, to avoid spoofing */
if (p->flags & BR_LEARNING && br_should_learn(p, skb, &vid)) if ((p->flags & BR_LEARNING) &&
!br_opt_get(p->br, BROPT_NO_LL_LEARN) &&
br_should_learn(p, skb, &vid))
br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid, false); br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid, false);
} }
......
...@@ -328,6 +328,7 @@ enum net_bridge_opts { ...@@ -328,6 +328,7 @@ enum net_bridge_opts {
BROPT_NEIGH_SUPPRESS_ENABLED, BROPT_NEIGH_SUPPRESS_ENABLED,
BROPT_MTU_SET_BY_USER, BROPT_MTU_SET_BY_USER,
BROPT_VLAN_STATS_PER_PORT, BROPT_VLAN_STATS_PER_PORT,
BROPT_NO_LL_LEARN,
}; };
struct net_bridge { struct net_bridge {
......
...@@ -328,6 +328,27 @@ static ssize_t flush_store(struct device *d, ...@@ -328,6 +328,27 @@ static ssize_t flush_store(struct device *d,
} }
static DEVICE_ATTR_WO(flush); static DEVICE_ATTR_WO(flush);
static ssize_t no_linklocal_learn_show(struct device *d,
struct device_attribute *attr,
char *buf)
{
struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%d\n", br_boolopt_get(br, BR_BOOLOPT_NO_LL_LEARN));
}
static int set_no_linklocal_learn(struct net_bridge *br, unsigned long val)
{
return br_boolopt_toggle(br, BR_BOOLOPT_NO_LL_LEARN, !!val, NULL);
}
static ssize_t no_linklocal_learn_store(struct device *d,
struct device_attribute *attr,
const char *buf, size_t len)
{
return store_bridge_parm(d, buf, len, set_no_linklocal_learn);
}
static DEVICE_ATTR_RW(no_linklocal_learn);
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
static ssize_t multicast_router_show(struct device *d, static ssize_t multicast_router_show(struct device *d,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
...@@ -841,6 +862,7 @@ static struct attribute *bridge_attrs[] = { ...@@ -841,6 +862,7 @@ static struct attribute *bridge_attrs[] = {
&dev_attr_gc_timer.attr, &dev_attr_gc_timer.attr,
&dev_attr_group_addr.attr, &dev_attr_group_addr.attr,
&dev_attr_flush.attr, &dev_attr_flush.attr,
&dev_attr_no_linklocal_learn.attr,
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
&dev_attr_multicast_router.attr, &dev_attr_multicast_router.attr,
&dev_attr_multicast_snooping.attr, &dev_attr_multicast_snooping.attr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment