net: bridge: notify on vlan tunnel changes done via the old api

If someone uses the old vlan API to configure tunnel mappings we'll only
generate the old-style full port notification. That would be a problem
if we are monitoring the new vlan notifications for changes. The patch
resolves the issue by adding vlan notifications to the old tunnel netlink
code. As usual we try to compress the notifications for as many vlans
in a range as possible, thus a vlan tunnel change is considered able
to enter the "current" vlan notification range if:
 1. vlan exists
 2. it has actually changed (curr_change == true)
 3. it passes all standard vlan notification range checks done by
    br_vlan_can_enter_range() such as option equality, id continuity etc

Note that vlan tunnel changes (add/del) are considered a part of vlan
options so only RTM_NEWVLAN notification is generated with the relevant
information inside.

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Nikolay Aleksandrov 2020-07-11 18:05:04 +03:00 committed by David S. Miller
parent 71930d6102
commit 9433944368

View File

@ -250,6 +250,36 @@ int br_parse_vlan_tunnel_info(struct nlattr *attr,
return 0;
}
/* send a notification if v_curr can't enter the range and start a new one */
static void __vlan_tunnel_handle_range(const struct net_bridge_port *p,
struct net_bridge_vlan **v_start,
struct net_bridge_vlan **v_end,
int v_curr, bool curr_change)
{
struct net_bridge_vlan_group *vg;
struct net_bridge_vlan *v;
vg = nbp_vlan_group(p);
if (!vg)
return;
v = br_vlan_find(vg, v_curr);
if (!*v_start)
goto out_init;
if (v && curr_change && br_vlan_can_enter_range(v, *v_end)) {
*v_end = v;
return;
}
br_vlan_notify(p->br, p, (*v_start)->vid, (*v_end)->vid, RTM_NEWVLAN);
out_init:
/* we start a range only if there are any changes to notify about */
*v_start = curr_change ? v : NULL;
*v_end = *v_start;
}
int br_process_vlan_tunnel_info(const struct net_bridge *br,
const struct net_bridge_port *p, int cmd,
struct vtunnel_info *tinfo_curr,
@ -263,6 +293,7 @@ int br_process_vlan_tunnel_info(const struct net_bridge *br,
return -EINVAL;
memcpy(tinfo_last, tinfo_curr, sizeof(struct vtunnel_info));
} else if (tinfo_curr->flags & BRIDGE_VLAN_INFO_RANGE_END) {
struct net_bridge_vlan *v_start = NULL, *v_end = NULL;
int t, v;
if (!(tinfo_last->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN))
@ -272,11 +303,24 @@ int br_process_vlan_tunnel_info(const struct net_bridge *br,
return -EINVAL;
t = tinfo_last->tunid;
for (v = tinfo_last->vid; v <= tinfo_curr->vid; v++) {
err = br_vlan_tunnel_info(p, cmd, v, t, changed);
bool curr_change = false;
err = br_vlan_tunnel_info(p, cmd, v, t, &curr_change);
if (err)
return err;
break;
t++;
if (curr_change)
*changed = curr_change;
__vlan_tunnel_handle_range(p, &v_start, &v_end, v,
curr_change);
}
if (v_start && v_end)
br_vlan_notify(br, p, v_start->vid, v_end->vid,
RTM_NEWVLAN);
if (err)
return err;
memset(tinfo_last, 0, sizeof(struct vtunnel_info));
memset(tinfo_curr, 0, sizeof(struct vtunnel_info));
} else {
@ -286,6 +330,7 @@ int br_process_vlan_tunnel_info(const struct net_bridge *br,
tinfo_curr->tunid, changed);
if (err)
return err;
br_vlan_notify(br, p, tinfo_curr->vid, 0, RTM_NEWVLAN);
memset(tinfo_last, 0, sizeof(struct vtunnel_info));
memset(tinfo_curr, 0, sizeof(struct vtunnel_info));
}