Commit 0241b836 authored by Roopa Prabhu's avatar Roopa Prabhu Committed by David S. Miller

vxlan: fix default fdb entry netlink notify ordering during netdev create

Problem:
In vxlan_newlink, a default fdb entry is added before register_netdev.
The default fdb creation function also notifies user-space of the
fdb entry on the vxlan device which user-space does not know about yet.
(RTM_NEWNEIGH goes before RTM_NEWLINK for the same ifindex).

This patch fixes the user-space netlink notification ordering issue
with the following changes:
- decouple fdb notify from fdb create.
- Move fdb notify after register_netdev.
- Call rtnl_configure_link in vxlan newlink handler to notify
userspace about the newlink before fdb notify and
hence avoiding the user-space race.

Fixes: afbd8bae ("vxlan: add implicit fdb entry for default destination")
Signed-off-by: default avatarRoopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4c2438ba
...@@ -3197,6 +3197,7 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, ...@@ -3197,6 +3197,7 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
{ {
struct vxlan_net *vn = net_generic(net, vxlan_net_id); struct vxlan_net *vn = net_generic(net, vxlan_net_id);
struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_dev *vxlan = netdev_priv(dev);
struct vxlan_fdb *f = NULL;
int err; int err;
err = vxlan_dev_configure(net, dev, conf, false, extack); err = vxlan_dev_configure(net, dev, conf, false, extack);
...@@ -3207,27 +3208,38 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, ...@@ -3207,27 +3208,38 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
/* create an fdb entry for a valid default destination */ /* create an fdb entry for a valid default destination */
if (!vxlan_addr_any(&vxlan->default_dst.remote_ip)) { if (!vxlan_addr_any(&vxlan->default_dst.remote_ip)) {
err = vxlan_fdb_update(vxlan, all_zeros_mac, err = vxlan_fdb_create(vxlan, all_zeros_mac,
&vxlan->default_dst.remote_ip, &vxlan->default_dst.remote_ip,
NUD_REACHABLE | NUD_PERMANENT, NUD_REACHABLE | NUD_PERMANENT,
NLM_F_EXCL | NLM_F_CREATE,
vxlan->cfg.dst_port, vxlan->cfg.dst_port,
vxlan->default_dst.remote_vni, vxlan->default_dst.remote_vni,
vxlan->default_dst.remote_vni, vxlan->default_dst.remote_vni,
vxlan->default_dst.remote_ifindex, vxlan->default_dst.remote_ifindex,
NTF_SELF); NTF_SELF, &f);
if (err) if (err)
return err; return err;
} }
err = register_netdevice(dev); err = register_netdevice(dev);
if (err)
goto errout;
err = rtnl_configure_link(dev, NULL);
if (err) { if (err) {
vxlan_fdb_delete_default(vxlan, vxlan->default_dst.remote_vni); unregister_netdevice(dev);
return err; goto errout;
} }
/* notify default fdb entry */
if (f)
vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH);
list_add(&vxlan->next, &vn->vxlan_list); list_add(&vxlan->next, &vn->vxlan_list);
return 0; return 0;
errout:
if (f)
vxlan_fdb_destroy(vxlan, f, false);
return err;
} }
static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[], static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[],
...@@ -3462,6 +3474,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], ...@@ -3462,6 +3474,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
struct vxlan_rdst *dst = &vxlan->default_dst; struct vxlan_rdst *dst = &vxlan->default_dst;
struct vxlan_rdst old_dst; struct vxlan_rdst old_dst;
struct vxlan_config conf; struct vxlan_config conf;
struct vxlan_fdb *f = NULL;
int err; int err;
err = vxlan_nl2conf(tb, data, err = vxlan_nl2conf(tb, data,
...@@ -3487,19 +3500,19 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], ...@@ -3487,19 +3500,19 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
old_dst.remote_ifindex, 0); old_dst.remote_ifindex, 0);
if (!vxlan_addr_any(&dst->remote_ip)) { if (!vxlan_addr_any(&dst->remote_ip)) {
err = vxlan_fdb_update(vxlan, all_zeros_mac, err = vxlan_fdb_create(vxlan, all_zeros_mac,
&dst->remote_ip, &dst->remote_ip,
NUD_REACHABLE | NUD_PERMANENT, NUD_REACHABLE | NUD_PERMANENT,
NLM_F_CREATE | NLM_F_APPEND,
vxlan->cfg.dst_port, vxlan->cfg.dst_port,
dst->remote_vni, dst->remote_vni,
dst->remote_vni, dst->remote_vni,
dst->remote_ifindex, dst->remote_ifindex,
NTF_SELF); NTF_SELF, &f);
if (err) { if (err) {
spin_unlock_bh(&vxlan->hash_lock); spin_unlock_bh(&vxlan->hash_lock);
return err; return err;
} }
vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH);
} }
spin_unlock_bh(&vxlan->hash_lock); spin_unlock_bh(&vxlan->hash_lock);
} }
......
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