Skip to content

Commit 7a53e71

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
net: bridge: vlan: add basic option dumping support
We'll be dumping the options for the whole range if they're equal. The first range vlan will be used to extract the options. The commit doesn't change anything yet it just adds the skeleton for the support. The dump will happen when the first option is added. Signed-off-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ac0e932 commit 7a53e71

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

net/bridge/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ obj-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o
2020

2121
bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o
2222

23-
bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o br_vlan_tunnel.o
23+
bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o br_vlan_tunnel.o br_vlan_options.o
2424

2525
bridge-$(CONFIG_NET_SWITCHDEV) += br_switchdev.o
2626

net/bridge/br_private.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,14 @@ static inline void br_vlan_notify(const struct net_bridge *br,
11911191
}
11921192
#endif
11931193

1194+
/* br_vlan_options.c */
1195+
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
1196+
bool br_vlan_opts_eq(const struct net_bridge_vlan *v1,
1197+
const struct net_bridge_vlan *v2);
1198+
bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v);
1199+
size_t br_vlan_opts_nl_size(void);
1200+
#endif
1201+
11941202
struct nf_br_ops {
11951203
int (*br_dev_xmit_hook)(struct sk_buff *skb);
11961204
};

net/bridge/br_vlan.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,9 @@ void br_vlan_port_event(struct net_bridge_port *p, unsigned long event)
15471547
}
15481548
}
15491549

1550+
/* v_opts is used to dump the options which must be equal in the whole range */
15501551
static bool br_vlan_fill_vids(struct sk_buff *skb, u16 vid, u16 vid_range,
1552+
const struct net_bridge_vlan *v_opts,
15511553
u16 flags)
15521554
{
15531555
struct bridge_vlan_info info;
@@ -1572,6 +1574,9 @@ static bool br_vlan_fill_vids(struct sk_buff *skb, u16 vid, u16 vid_range,
15721574
nla_put_u16(skb, BRIDGE_VLANDB_ENTRY_RANGE, vid_range))
15731575
goto out_err;
15741576

1577+
if (v_opts && !br_vlan_opts_fill(skb, v_opts))
1578+
goto out_err;
1579+
15751580
nla_nest_end(skb, nest);
15761581

15771582
return true;
@@ -1586,7 +1591,8 @@ static size_t rtnl_vlan_nlmsg_size(void)
15861591
return NLMSG_ALIGN(sizeof(struct br_vlan_msg))
15871592
+ nla_total_size(0) /* BRIDGE_VLANDB_ENTRY */
15881593
+ nla_total_size(sizeof(u16)) /* BRIDGE_VLANDB_ENTRY_RANGE */
1589-
+ nla_total_size(sizeof(struct bridge_vlan_info)); /* BRIDGE_VLANDB_ENTRY_INFO */
1594+
+ nla_total_size(sizeof(struct bridge_vlan_info)) /* BRIDGE_VLANDB_ENTRY_INFO */
1595+
+ br_vlan_opts_nl_size(); /* bridge vlan options */
15901596
}
15911597

15921598
void br_vlan_notify(const struct net_bridge *br,
@@ -1595,7 +1601,7 @@ void br_vlan_notify(const struct net_bridge *br,
15951601
int cmd)
15961602
{
15971603
struct net_bridge_vlan_group *vg;
1598-
struct net_bridge_vlan *v;
1604+
struct net_bridge_vlan *v = NULL;
15991605
struct br_vlan_msg *bvm;
16001606
struct nlmsghdr *nlh;
16011607
struct sk_buff *skb;
@@ -1647,7 +1653,7 @@ void br_vlan_notify(const struct net_bridge *br,
16471653
goto out_kfree;
16481654
}
16491655

1650-
if (!br_vlan_fill_vids(skb, vid, vid_range, flags))
1656+
if (!br_vlan_fill_vids(skb, vid, vid_range, v, flags))
16511657
goto out_err;
16521658

16531659
nlmsg_end(skb, nlh);
@@ -1665,7 +1671,8 @@ static bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
16651671
const struct net_bridge_vlan *range_end)
16661672
{
16671673
return v_curr->vid - range_end->vid == 1 &&
1668-
range_end->flags == v_curr->flags;
1674+
range_end->flags == v_curr->flags &&
1675+
br_vlan_opts_eq(v_curr, range_end);
16691676
}
16701677

16711678
static int br_vlan_dump_dev(const struct net_device *dev,
@@ -1729,7 +1736,8 @@ static int br_vlan_dump_dev(const struct net_device *dev,
17291736
u16 flags = br_vlan_flags(range_start, pvid);
17301737

17311738
if (!br_vlan_fill_vids(skb, range_start->vid,
1732-
range_end->vid, flags)) {
1739+
range_end->vid, range_start,
1740+
flags)) {
17331741
err = -EMSGSIZE;
17341742
break;
17351743
}
@@ -1748,7 +1756,7 @@ static int br_vlan_dump_dev(const struct net_device *dev,
17481756
*/
17491757
if (!err && range_start &&
17501758
!br_vlan_fill_vids(skb, range_start->vid, range_end->vid,
1751-
br_vlan_flags(range_start, pvid)))
1759+
range_start, br_vlan_flags(range_start, pvid)))
17521760
err = -EMSGSIZE;
17531761

17541762
cb->args[1] = err ? idx : 0;

net/bridge/br_vlan_options.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
// Copyright (c) 2020, Nikolay Aleksandrov <[email protected]>
3+
#include <linux/kernel.h>
4+
#include <linux/netdevice.h>
5+
#include <linux/rtnetlink.h>
6+
#include <linux/slab.h>
7+
8+
#include "br_private.h"
9+
10+
/* check if the options between two vlans are equal */
11+
bool br_vlan_opts_eq(const struct net_bridge_vlan *v1,
12+
const struct net_bridge_vlan *v2)
13+
{
14+
return true;
15+
}
16+
17+
bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v)
18+
{
19+
return true;
20+
}
21+
22+
size_t br_vlan_opts_nl_size(void)
23+
{
24+
return 0;
25+
}

0 commit comments

Comments
 (0)