Skip to content

Commit 70e4272

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
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: Nikolay Aleksandrov <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a428afe commit 70e4272

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

include/uapi/linux/if_bridge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,13 @@ struct br_mcast_stats {
294294
};
295295

296296
/* bridge boolean options
297+
* BR_BOOLOPT_NO_LL_LEARN - disable learning from link-local packets
298+
*
297299
* IMPORTANT: if adding a new option do not forget to handle
298300
* it in br_boolopt_toggle/get and bridge sysfs
299301
*/
300302
enum br_boolopt_id {
303+
BR_BOOLOPT_NO_LL_LEARN,
301304
BR_BOOLOPT_MAX
302305
};
303306

net/bridge/br.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
189189
struct netlink_ext_ack *extack)
190190
{
191191
switch (opt) {
192+
case BR_BOOLOPT_NO_LL_LEARN:
193+
br_opt_toggle(br, BROPT_NO_LL_LEARN, on);
194+
break;
192195
default:
193196
/* shouldn't be called with unsupported options */
194197
WARN_ON(1);
@@ -201,6 +204,8 @@ int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
201204
int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt)
202205
{
203206
switch (opt) {
207+
case BR_BOOLOPT_NO_LL_LEARN:
208+
return br_opt_get(br, BROPT_NO_LL_LEARN);
204209
default:
205210
/* shouldn't be called with unsupported options */
206211
WARN_ON(1);

net/bridge/br_input.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ static void __br_handle_local_finish(struct sk_buff *skb)
188188
u16 vid = 0;
189189

190190
/* check if vlan is allowed, to avoid spoofing */
191-
if (p->flags & BR_LEARNING && br_should_learn(p, skb, &vid))
191+
if ((p->flags & BR_LEARNING) &&
192+
!br_opt_get(p->br, BROPT_NO_LL_LEARN) &&
193+
br_should_learn(p, skb, &vid))
192194
br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid, false);
193195
}
194196

net/bridge/br_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ enum net_bridge_opts {
328328
BROPT_NEIGH_SUPPRESS_ENABLED,
329329
BROPT_MTU_SET_BY_USER,
330330
BROPT_VLAN_STATS_PER_PORT,
331+
BROPT_NO_LL_LEARN,
331332
};
332333

333334
struct net_bridge {

net/bridge/br_sysfs_br.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,27 @@ static ssize_t flush_store(struct device *d,
328328
}
329329
static DEVICE_ATTR_WO(flush);
330330

331+
static ssize_t no_linklocal_learn_show(struct device *d,
332+
struct device_attribute *attr,
333+
char *buf)
334+
{
335+
struct net_bridge *br = to_bridge(d);
336+
return sprintf(buf, "%d\n", br_boolopt_get(br, BR_BOOLOPT_NO_LL_LEARN));
337+
}
338+
339+
static int set_no_linklocal_learn(struct net_bridge *br, unsigned long val)
340+
{
341+
return br_boolopt_toggle(br, BR_BOOLOPT_NO_LL_LEARN, !!val, NULL);
342+
}
343+
344+
static ssize_t no_linklocal_learn_store(struct device *d,
345+
struct device_attribute *attr,
346+
const char *buf, size_t len)
347+
{
348+
return store_bridge_parm(d, buf, len, set_no_linklocal_learn);
349+
}
350+
static DEVICE_ATTR_RW(no_linklocal_learn);
351+
331352
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
332353
static ssize_t multicast_router_show(struct device *d,
333354
struct device_attribute *attr, char *buf)
@@ -841,6 +862,7 @@ static struct attribute *bridge_attrs[] = {
841862
&dev_attr_gc_timer.attr,
842863
&dev_attr_group_addr.attr,
843864
&dev_attr_flush.attr,
865+
&dev_attr_no_linklocal_learn.attr,
844866
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
845867
&dev_attr_multicast_router.attr,
846868
&dev_attr_multicast_snooping.attr,

0 commit comments

Comments
 (0)