Skip to content

Commit a5d29ae

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
net: bridge: vlan: add basic option setting support
This patch adds support for option modification of single vlans and ranges. It allows to only modify options, i.e. skip create/delete by using the BRIDGE_VLAN_INFO_ONLY_OPTS flag. When working with a range option changes we try to pack the notifications as much as possible. v2: do full port (all vlans) notification only when creating/deleting vlans for compatibility, rework the range detection when changing options, add more verbose extack errors and check if a vlan should be used (br_vlan_should_use checks) Signed-off-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7a53e71 commit a5d29ae

File tree

4 files changed

+130
-7
lines changed

4 files changed

+130
-7
lines changed

include/uapi/linux/if_bridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ enum {
130130
#define BRIDGE_VLAN_INFO_RANGE_BEGIN (1<<3) /* VLAN is start of vlan range */
131131
#define BRIDGE_VLAN_INFO_RANGE_END (1<<4) /* VLAN is end of vlan range */
132132
#define BRIDGE_VLAN_INFO_BRENTRY (1<<5) /* Global bridge VLAN entry */
133+
#define BRIDGE_VLAN_INFO_ONLY_OPTS (1<<6) /* Skip create/delete/flags */
133134

134135
struct bridge_vlan_info {
135136
__u16 flags;

net/bridge/br_private.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ void br_vlan_notify(const struct net_bridge *br,
976976
const struct net_bridge_port *p,
977977
u16 vid, u16 vid_range,
978978
int cmd);
979+
bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
980+
const struct net_bridge_vlan *range_end);
979981

980982
static inline struct net_bridge_vlan_group *br_vlan_group(
981983
const struct net_bridge *br)
@@ -1197,6 +1199,12 @@ bool br_vlan_opts_eq(const struct net_bridge_vlan *v1,
11971199
const struct net_bridge_vlan *v2);
11981200
bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v);
11991201
size_t br_vlan_opts_nl_size(void);
1202+
int br_vlan_process_options(const struct net_bridge *br,
1203+
const struct net_bridge_port *p,
1204+
struct net_bridge_vlan *range_start,
1205+
struct net_bridge_vlan *range_end,
1206+
struct nlattr **tb,
1207+
struct netlink_ext_ack *extack);
12001208
#endif
12011209

12021210
struct nf_br_ops {

net/bridge/br_vlan.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,8 +1667,8 @@ void br_vlan_notify(const struct net_bridge *br,
16671667
}
16681668

16691669
/* check if v_curr can enter a range ending in range_end */
1670-
static bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1671-
const struct net_bridge_vlan *range_end)
1670+
bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1671+
const struct net_bridge_vlan *range_end)
16721672
{
16731673
return v_curr->vid - range_end->vid == 1 &&
16741674
range_end->flags == v_curr->flags &&
@@ -1824,11 +1824,11 @@ static int br_vlan_rtm_process_one(struct net_device *dev,
18241824
{
18251825
struct bridge_vlan_info *vinfo, vrange_end, *vinfo_last = NULL;
18261826
struct nlattr *tb[BRIDGE_VLANDB_ENTRY_MAX + 1];
1827+
bool changed = false, skip_processing = false;
18271828
struct net_bridge_vlan_group *vg;
18281829
struct net_bridge_port *p = NULL;
18291830
int err = 0, cmdmap = 0;
18301831
struct net_bridge *br;
1831-
bool changed = false;
18321832

18331833
if (netif_is_bridge_master(dev)) {
18341834
br = netdev_priv(dev);
@@ -1882,16 +1882,43 @@ static int br_vlan_rtm_process_one(struct net_device *dev,
18821882
switch (cmd) {
18831883
case RTM_NEWVLAN:
18841884
cmdmap = RTM_SETLINK;
1885+
skip_processing = !!(vinfo->flags & BRIDGE_VLAN_INFO_ONLY_OPTS);
18851886
break;
18861887
case RTM_DELVLAN:
18871888
cmdmap = RTM_DELLINK;
18881889
break;
18891890
}
18901891

1891-
err = br_process_vlan_info(br, p, cmdmap, vinfo, &vinfo_last, &changed,
1892-
extack);
1893-
if (changed)
1894-
br_ifinfo_notify(cmdmap, br, p);
1892+
if (!skip_processing) {
1893+
struct bridge_vlan_info *tmp_last = vinfo_last;
1894+
1895+
/* br_process_vlan_info may overwrite vinfo_last */
1896+
err = br_process_vlan_info(br, p, cmdmap, vinfo, &tmp_last,
1897+
&changed, extack);
1898+
1899+
/* notify first if anything changed */
1900+
if (changed)
1901+
br_ifinfo_notify(cmdmap, br, p);
1902+
1903+
if (err)
1904+
return err;
1905+
}
1906+
1907+
/* deal with options */
1908+
if (cmd == RTM_NEWVLAN) {
1909+
struct net_bridge_vlan *range_start, *range_end;
1910+
1911+
if (vinfo_last) {
1912+
range_start = br_vlan_find(vg, vinfo_last->vid);
1913+
range_end = br_vlan_find(vg, vinfo->vid);
1914+
} else {
1915+
range_start = br_vlan_find(vg, vinfo->vid);
1916+
range_end = range_start;
1917+
}
1918+
1919+
err = br_vlan_process_options(br, p, range_start, range_end,
1920+
tb, extack);
1921+
}
18951922

18961923
return err;
18971924
}

net/bridge/br_vlan_options.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,90 @@ size_t br_vlan_opts_nl_size(void)
2323
{
2424
return 0;
2525
}
26+
27+
static int br_vlan_process_one_opts(const struct net_bridge *br,
28+
const struct net_bridge_port *p,
29+
struct net_bridge_vlan_group *vg,
30+
struct net_bridge_vlan *v,
31+
struct nlattr **tb,
32+
bool *changed,
33+
struct netlink_ext_ack *extack)
34+
{
35+
*changed = false;
36+
return 0;
37+
}
38+
39+
int br_vlan_process_options(const struct net_bridge *br,
40+
const struct net_bridge_port *p,
41+
struct net_bridge_vlan *range_start,
42+
struct net_bridge_vlan *range_end,
43+
struct nlattr **tb,
44+
struct netlink_ext_ack *extack)
45+
{
46+
struct net_bridge_vlan *v, *curr_start = NULL, *curr_end = NULL;
47+
struct net_bridge_vlan_group *vg;
48+
int vid, err = 0;
49+
u16 pvid;
50+
51+
if (p)
52+
vg = nbp_vlan_group(p);
53+
else
54+
vg = br_vlan_group(br);
55+
56+
if (!range_start || !br_vlan_should_use(range_start)) {
57+
NL_SET_ERR_MSG_MOD(extack, "Vlan range start doesn't exist, can't process options");
58+
return -ENOENT;
59+
}
60+
if (!range_end || !br_vlan_should_use(range_end)) {
61+
NL_SET_ERR_MSG_MOD(extack, "Vlan range end doesn't exist, can't process options");
62+
return -ENOENT;
63+
}
64+
65+
pvid = br_get_pvid(vg);
66+
for (vid = range_start->vid; vid <= range_end->vid; vid++) {
67+
bool changed = false;
68+
69+
v = br_vlan_find(vg, vid);
70+
if (!v || !br_vlan_should_use(v)) {
71+
NL_SET_ERR_MSG_MOD(extack, "Vlan in range doesn't exist, can't process options");
72+
err = -ENOENT;
73+
break;
74+
}
75+
76+
err = br_vlan_process_one_opts(br, p, vg, v, tb, &changed,
77+
extack);
78+
if (err)
79+
break;
80+
81+
if (changed) {
82+
/* vlan options changed, check for range */
83+
if (!curr_start) {
84+
curr_start = v;
85+
curr_end = v;
86+
continue;
87+
}
88+
89+
if (v->vid == pvid ||
90+
!br_vlan_can_enter_range(v, curr_end)) {
91+
br_vlan_notify(br, p, curr_start->vid,
92+
curr_end->vid, RTM_NEWVLAN);
93+
curr_start = v;
94+
}
95+
curr_end = v;
96+
} else {
97+
/* nothing changed and nothing to notify yet */
98+
if (!curr_start)
99+
continue;
100+
101+
br_vlan_notify(br, p, curr_start->vid, curr_end->vid,
102+
RTM_NEWVLAN);
103+
curr_start = NULL;
104+
curr_end = NULL;
105+
}
106+
}
107+
if (curr_start)
108+
br_vlan_notify(br, p, curr_start->vid, curr_end->vid,
109+
RTM_NEWVLAN);
110+
111+
return err;
112+
}

0 commit comments

Comments
 (0)