vxlan: fix unexpected failure of vxlan_changelink()

After commit 0ce1822c2a ("vxlan: add adjacent link to limit depth
level"), vxlan_changelink() could fail because of
netdev_adjacent_change_prepare().
netdev_adjacent_change_prepare() returns -EEXIST when old lower device
and new lower device are same.
(old lower device is "dst->remote_dev" and new lower device is "lowerdev")
So, before calling it, lowerdev should be NULL if these devices are same.

Test command1:
    ip link add dummy0 type dummy
    ip link add vxlan0 type vxlan dev dummy0 dstport 4789 vni 1
    ip link set vxlan0 type vxlan ttl 5
    RTNETLINK answers: File exists

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 0ce1822c2a ("vxlan: add adjacent link to limit depth level")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Taehee Yoo 2019-10-30 08:15:12 +00:00 коммит произвёл David S. Miller
Родитель dc99da4f31
Коммит c6761cf521
1 изменённых файлов: 6 добавлений и 3 удалений

Просмотреть файл

@ -3967,6 +3967,9 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
if (err) if (err)
return err; return err;
if (dst->remote_dev == lowerdev)
lowerdev = NULL;
err = netdev_adjacent_change_prepare(dst->remote_dev, lowerdev, dev, err = netdev_adjacent_change_prepare(dst->remote_dev, lowerdev, dev,
extack); extack);
if (err) if (err)
@ -4008,10 +4011,10 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
mod_timer(&vxlan->age_timer, jiffies); mod_timer(&vxlan->age_timer, jiffies);
netdev_adjacent_change_commit(dst->remote_dev, lowerdev, dev); netdev_adjacent_change_commit(dst->remote_dev, lowerdev, dev);
if (lowerdev && lowerdev != dst->remote_dev) if (lowerdev && lowerdev != dst->remote_dev) {
dst->remote_dev = lowerdev; dst->remote_dev = lowerdev;
netdev_update_lockdep_key(lowerdev);
netdev_update_lockdep_key(lowerdev); }
vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true); vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true);
return 0; return 0;
} }