Skip to content

Commit f6e94ff

Browse files
committed
Merge branch 'net-bridge-vlan-options-nest-the-tunnel-options'
Nikolay Aleksandrov says: ==================== net: bridge: vlan options: nest the tunnel options After a discussion with Roopa about the new tunnel vlan option, she suggested that we'll be adding more tunnel options and attributes, so it'd be better to have them all grouped together under one main vlan entry tunnel attribute instead of making them all main attributes. Since the tunnel code was added in this net-next cycle and still hasn't been released we can easily nest the BRIDGE_VLANDB_ENTRY_TUNNEL_ID attribute in BRIDGE_VLANDB_ENTRY_TUNNEL_INFO and allow for any new tunnel attributes to be added there. In addition one positive side-effect is that we can remove the outside vlan info flag which controlled the operation (setlink/dellink) and move it under a new nested attribute so user-space can specify it explicitly. Thus the vlan tunnel format becomes: [BRIDGE_VLANDB_ENTRY] [BRIDGE_VLANDB_ENTRY_TUNNEL_INFO] [BRIDGE_VLANDB_TINFO_ID] [BRIDGE_VLANDB_TINFO_CMD] ... ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents ee9d0cb + c443758 commit f6e94ff

3 files changed

Lines changed: 74 additions & 22 deletions

File tree

‎include/uapi/linux/if_bridge.h‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ enum {
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 */
133133
#define BRIDGE_VLAN_INFO_ONLY_OPTS (1<<6) /* Skip create/delete/flags */
134-
#define BRIDGE_VLAN_INFO_REMOVE_TUN (1<<7) /* Remove tunnel mapping */
135134

136135
struct bridge_vlan_info {
137136
__u16 flags;
@@ -203,12 +202,27 @@ enum {
203202
BRIDGE_VLANDB_ENTRY_INFO,
204203
BRIDGE_VLANDB_ENTRY_RANGE,
205204
BRIDGE_VLANDB_ENTRY_STATE,
206-
BRIDGE_VLANDB_ENTRY_TUNNEL_ID,
205+
BRIDGE_VLANDB_ENTRY_TUNNEL_INFO,
207206
BRIDGE_VLANDB_ENTRY_STATS,
208207
__BRIDGE_VLANDB_ENTRY_MAX,
209208
};
210209
#define BRIDGE_VLANDB_ENTRY_MAX (__BRIDGE_VLANDB_ENTRY_MAX - 1)
211210

211+
/* [BRIDGE_VLANDB_ENTRY] = {
212+
* [BRIDGE_VLANDB_ENTRY_TUNNEL_INFO] = {
213+
* [BRIDGE_VLANDB_TINFO_ID]
214+
* ...
215+
* }
216+
* }
217+
*/
218+
enum {
219+
BRIDGE_VLANDB_TINFO_UNSPEC,
220+
BRIDGE_VLANDB_TINFO_ID,
221+
BRIDGE_VLANDB_TINFO_CMD,
222+
__BRIDGE_VLANDB_TINFO_MAX,
223+
};
224+
#define BRIDGE_VLANDB_TINFO_MAX (__BRIDGE_VLANDB_TINFO_MAX - 1)
225+
212226
/* [BRIDGE_VLANDB_ENTRY] = {
213227
* [BRIDGE_VLANDB_ENTRY_STATS] = {
214228
* [BRIDGE_VLANDB_STATS_RX_BYTES]

‎net/bridge/br_vlan.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ static const struct nla_policy br_vlan_db_policy[BRIDGE_VLANDB_ENTRY_MAX + 1] =
18881888
.len = sizeof(struct bridge_vlan_info) },
18891889
[BRIDGE_VLANDB_ENTRY_RANGE] = { .type = NLA_U16 },
18901890
[BRIDGE_VLANDB_ENTRY_STATE] = { .type = NLA_U8 },
1891-
[BRIDGE_VLANDB_ENTRY_TUNNEL_ID] = { .type = NLA_U32 },
1891+
[BRIDGE_VLANDB_ENTRY_TUNNEL_INFO] = { .type = NLA_NESTED },
18921892
};
18931893

18941894
static int br_vlan_rtm_process_one(struct net_device *dev,

‎net/bridge/br_vlan_options.c‎

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@
1212
static bool __vlan_tun_put(struct sk_buff *skb, const struct net_bridge_vlan *v)
1313
{
1414
__be32 tid = tunnel_id_to_key32(v->tinfo.tunnel_id);
15+
struct nlattr *nest;
1516

1617
if (!v->tinfo.tunnel_dst)
1718
return true;
1819

19-
return !nla_put_u32(skb, BRIDGE_VLANDB_ENTRY_TUNNEL_ID,
20-
be32_to_cpu(tid));
20+
nest = nla_nest_start(skb, BRIDGE_VLANDB_ENTRY_TUNNEL_INFO);
21+
if (!nest)
22+
return false;
23+
if (nla_put_u32(skb, BRIDGE_VLANDB_TINFO_ID, be32_to_cpu(tid))) {
24+
nla_nest_cancel(skb, nest);
25+
return false;
26+
}
27+
nla_nest_end(skb, nest);
28+
29+
return true;
2130
}
2231

2332
static bool __vlan_tun_can_enter_range(const struct net_bridge_vlan *v_curr,
@@ -45,7 +54,8 @@ bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v)
4554
size_t br_vlan_opts_nl_size(void)
4655
{
4756
return nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_ENTRY_STATE */
48-
+ nla_total_size(sizeof(u32)); /* BRIDGE_VLANDB_ENTRY_TUNNEL_ID */
57+
+ nla_total_size(0) /* BRIDGE_VLANDB_ENTRY_TUNNEL_INFO */
58+
+ nla_total_size(sizeof(u32)); /* BRIDGE_VLANDB_TINFO_ID */
4959
}
5060

5161
static int br_vlan_modify_state(struct net_bridge_vlan_group *vg,
@@ -85,15 +95,21 @@ static int br_vlan_modify_state(struct net_bridge_vlan_group *vg,
8595
return 0;
8696
}
8797

98+
static const struct nla_policy br_vlandb_tinfo_pol[BRIDGE_VLANDB_TINFO_MAX + 1] = {
99+
[BRIDGE_VLANDB_TINFO_ID] = { .type = NLA_U32 },
100+
[BRIDGE_VLANDB_TINFO_CMD] = { .type = NLA_U32 },
101+
};
102+
88103
static int br_vlan_modify_tunnel(const struct net_bridge_port *p,
89104
struct net_bridge_vlan *v,
90105
struct nlattr **tb,
91106
bool *changed,
92107
struct netlink_ext_ack *extack)
93108
{
109+
struct nlattr *tun_tb[BRIDGE_VLANDB_TINFO_MAX + 1], *attr;
94110
struct bridge_vlan_info *vinfo;
95-
int cmdmap;
96-
u32 tun_id;
111+
u32 tun_id = 0;
112+
int cmd, err;
97113

98114
if (!p) {
99115
NL_SET_ERR_MSG_MOD(extack, "Can't modify tunnel mapping of non-port vlans");
@@ -104,19 +120,41 @@ static int br_vlan_modify_tunnel(const struct net_bridge_port *p,
104120
return -EINVAL;
105121
}
106122

107-
/* vlan info attribute is guaranteed by br_vlan_rtm_process_one */
108-
vinfo = nla_data(tb[BRIDGE_VLANDB_ENTRY_INFO]);
109-
cmdmap = vinfo->flags & BRIDGE_VLAN_INFO_REMOVE_TUN ? RTM_DELLINK :
110-
RTM_SETLINK;
111-
/* when working on vlan ranges this represents the starting tunnel id */
112-
tun_id = nla_get_u32(tb[BRIDGE_VLANDB_ENTRY_TUNNEL_ID]);
113-
/* tunnel ids are mapped to each vlan in increasing order,
114-
* the starting vlan is in BRIDGE_VLANDB_ENTRY_INFO and v is the
115-
* current vlan, so we compute: tun_id + v - vinfo->vid
116-
*/
117-
tun_id += v->vid - vinfo->vid;
118-
119-
return br_vlan_tunnel_info(p, cmdmap, v->vid, tun_id, changed);
123+
attr = tb[BRIDGE_VLANDB_ENTRY_TUNNEL_INFO];
124+
err = nla_parse_nested(tun_tb, BRIDGE_VLANDB_TINFO_MAX, attr,
125+
br_vlandb_tinfo_pol, extack);
126+
if (err)
127+
return err;
128+
129+
if (!tun_tb[BRIDGE_VLANDB_TINFO_CMD]) {
130+
NL_SET_ERR_MSG_MOD(extack, "Missing tunnel command attribute");
131+
return -ENOENT;
132+
}
133+
cmd = nla_get_u32(tun_tb[BRIDGE_VLANDB_TINFO_CMD]);
134+
switch (cmd) {
135+
case RTM_SETLINK:
136+
if (!tun_tb[BRIDGE_VLANDB_TINFO_ID]) {
137+
NL_SET_ERR_MSG_MOD(extack, "Missing tunnel id attribute");
138+
return -ENOENT;
139+
}
140+
/* when working on vlan ranges this is the starting tunnel id */
141+
tun_id = nla_get_u32(tun_tb[BRIDGE_VLANDB_TINFO_ID]);
142+
/* vlan info attr is guaranteed by br_vlan_rtm_process_one */
143+
vinfo = nla_data(tb[BRIDGE_VLANDB_ENTRY_INFO]);
144+
/* tunnel ids are mapped to each vlan in increasing order,
145+
* the starting vlan is in BRIDGE_VLANDB_ENTRY_INFO and v is the
146+
* current vlan, so we compute: tun_id + v - vinfo->vid
147+
*/
148+
tun_id += v->vid - vinfo->vid;
149+
break;
150+
case RTM_DELLINK:
151+
break;
152+
default:
153+
NL_SET_ERR_MSG_MOD(extack, "Unsupported tunnel command");
154+
return -EINVAL;
155+
}
156+
157+
return br_vlan_tunnel_info(p, cmd, v->vid, tun_id, changed);
120158
}
121159

122160
static int br_vlan_process_one_opts(const struct net_bridge *br,
@@ -137,7 +175,7 @@ static int br_vlan_process_one_opts(const struct net_bridge *br,
137175
if (err)
138176
return err;
139177
}
140-
if (tb[BRIDGE_VLANDB_ENTRY_TUNNEL_ID]) {
178+
if (tb[BRIDGE_VLANDB_ENTRY_TUNNEL_INFO]) {
141179
err = br_vlan_modify_tunnel(p, v, tb, changed, extack);
142180
if (err)
143181
return err;

0 commit comments

Comments
 (0)