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

net: bridge: vlan options: move the tunnel command to the nested attribute

Now that we have a nested tunnel info attribute we can add a separate
one for the tunnel command and require it explicitly from user-space. It
must be one of RTM_SETLINK/DELLINK. Only RTM_SETLINK requires a valid
tunnel id, DELLINK just removes it if it was set before. This allows us
to have all tunnel attributes and control in one place, thus removing
the need for an outside vlan info flag.
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fa388f29
...@@ -131,7 +131,6 @@ enum { ...@@ -131,7 +131,6 @@ enum {
#define BRIDGE_VLAN_INFO_RANGE_END (1<<4) /* VLAN is end of vlan range */ #define BRIDGE_VLAN_INFO_RANGE_END (1<<4) /* VLAN is end of vlan range */
#define BRIDGE_VLAN_INFO_BRENTRY (1<<5) /* Global bridge VLAN entry */ #define BRIDGE_VLAN_INFO_BRENTRY (1<<5) /* Global bridge VLAN entry */
#define BRIDGE_VLAN_INFO_ONLY_OPTS (1<<6) /* Skip create/delete/flags */ #define BRIDGE_VLAN_INFO_ONLY_OPTS (1<<6) /* Skip create/delete/flags */
#define BRIDGE_VLAN_INFO_REMOVE_TUN (1<<7) /* Remove tunnel mapping */
struct bridge_vlan_info { struct bridge_vlan_info {
__u16 flags; __u16 flags;
...@@ -219,6 +218,7 @@ enum { ...@@ -219,6 +218,7 @@ enum {
enum { enum {
BRIDGE_VLANDB_TINFO_UNSPEC, BRIDGE_VLANDB_TINFO_UNSPEC,
BRIDGE_VLANDB_TINFO_ID, BRIDGE_VLANDB_TINFO_ID,
BRIDGE_VLANDB_TINFO_CMD,
__BRIDGE_VLANDB_TINFO_MAX, __BRIDGE_VLANDB_TINFO_MAX,
}; };
#define BRIDGE_VLANDB_TINFO_MAX (__BRIDGE_VLANDB_TINFO_MAX - 1) #define BRIDGE_VLANDB_TINFO_MAX (__BRIDGE_VLANDB_TINFO_MAX - 1)
......
...@@ -97,6 +97,7 @@ static int br_vlan_modify_state(struct net_bridge_vlan_group *vg, ...@@ -97,6 +97,7 @@ static int br_vlan_modify_state(struct net_bridge_vlan_group *vg,
static const struct nla_policy br_vlandb_tinfo_pol[BRIDGE_VLANDB_TINFO_MAX + 1] = { static const struct nla_policy br_vlandb_tinfo_pol[BRIDGE_VLANDB_TINFO_MAX + 1] = {
[BRIDGE_VLANDB_TINFO_ID] = { .type = NLA_U32 }, [BRIDGE_VLANDB_TINFO_ID] = { .type = NLA_U32 },
[BRIDGE_VLANDB_TINFO_CMD] = { .type = NLA_U32 },
}; };
static int br_vlan_modify_tunnel(const struct net_bridge_port *p, static int br_vlan_modify_tunnel(const struct net_bridge_port *p,
...@@ -107,8 +108,8 @@ static int br_vlan_modify_tunnel(const struct net_bridge_port *p, ...@@ -107,8 +108,8 @@ static int br_vlan_modify_tunnel(const struct net_bridge_port *p,
{ {
struct nlattr *tun_tb[BRIDGE_VLANDB_TINFO_MAX + 1], *attr; struct nlattr *tun_tb[BRIDGE_VLANDB_TINFO_MAX + 1], *attr;
struct bridge_vlan_info *vinfo; struct bridge_vlan_info *vinfo;
int cmdmap, err; u32 tun_id = 0;
u32 tun_id; int cmd, err;
if (!p) { if (!p) {
NL_SET_ERR_MSG_MOD(extack, "Can't modify tunnel mapping of non-port vlans"); NL_SET_ERR_MSG_MOD(extack, "Can't modify tunnel mapping of non-port vlans");
...@@ -125,23 +126,35 @@ static int br_vlan_modify_tunnel(const struct net_bridge_port *p, ...@@ -125,23 +126,35 @@ static int br_vlan_modify_tunnel(const struct net_bridge_port *p,
if (err) if (err)
return err; return err;
if (!tun_tb[BRIDGE_VLANDB_TINFO_ID]) { if (!tun_tb[BRIDGE_VLANDB_TINFO_CMD]) {
NL_SET_ERR_MSG_MOD(extack, "Missing tunnel id attribute"); NL_SET_ERR_MSG_MOD(extack, "Missing tunnel command attribute");
return -ENOENT; return -ENOENT;
} }
/* vlan info attribute is guaranteed by br_vlan_rtm_process_one */ cmd = nla_get_u32(tun_tb[BRIDGE_VLANDB_TINFO_CMD]);
vinfo = nla_data(tb[BRIDGE_VLANDB_ENTRY_INFO]); switch (cmd) {
cmdmap = vinfo->flags & BRIDGE_VLAN_INFO_REMOVE_TUN ? RTM_DELLINK : case RTM_SETLINK:
RTM_SETLINK; if (!tun_tb[BRIDGE_VLANDB_TINFO_ID]) {
/* when working on vlan ranges this represents the starting tunnel id */ NL_SET_ERR_MSG_MOD(extack, "Missing tunnel id attribute");
tun_id = nla_get_u32(tun_tb[BRIDGE_VLANDB_TINFO_ID]); return -ENOENT;
/* tunnel ids are mapped to each vlan in increasing order, }
* the starting vlan is in BRIDGE_VLANDB_ENTRY_INFO and v is the /* when working on vlan ranges this is the starting tunnel id */
* current vlan, so we compute: tun_id + v - vinfo->vid tun_id = nla_get_u32(tun_tb[BRIDGE_VLANDB_TINFO_ID]);
*/ /* vlan info attr is guaranteed by br_vlan_rtm_process_one */
tun_id += v->vid - vinfo->vid; vinfo = nla_data(tb[BRIDGE_VLANDB_ENTRY_INFO]);
/* tunnel ids are mapped to each vlan in increasing order,
return br_vlan_tunnel_info(p, cmdmap, v->vid, tun_id, changed); * the starting vlan is in BRIDGE_VLANDB_ENTRY_INFO and v is the
* current vlan, so we compute: tun_id + v - vinfo->vid
*/
tun_id += v->vid - vinfo->vid;
break;
case RTM_DELLINK:
break;
default:
NL_SET_ERR_MSG_MOD(extack, "Unsupported tunnel command");
return -EINVAL;
}
return br_vlan_tunnel_info(p, cmd, v->vid, tun_id, changed);
} }
static int br_vlan_process_one_opts(const struct net_bridge *br, static int br_vlan_process_one_opts(const struct net_bridge *br,
......
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