• Jakub Kicinski's avatar
    net: fix ifname in netlink ntf during netns move · 311cca40
    Jakub Kicinski authored
    dev_get_valid_name() overwrites the netdev's name on success.
    This makes it hard to use in prepare-commit-like fashion,
    where we do validation first, and "commit" to the change
    later.
    
    Factor out a helper which lets us save the new name to a buffer.
    Use it to fix the problem of notification on netns move having
    incorrect name:
    
     5: eth0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
         link/ether be:4d:58:f9:d5:40 brd ff:ff:ff:ff:ff:ff
     6: eth1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
         link/ether 1e:4a:34:36:e3:cd brd ff:ff:ff:ff:ff:ff
    
     [ ~]# ip link set dev eth0 netns 1 name eth1
    
    ip monitor inside netns:
     Deleted inet eth0
     Deleted inet6 eth0
     Deleted 5: eth1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
         link/ether be:4d:58:f9:d5:40 brd ff:ff:ff:ff:ff:ff new-netnsid 0 new-ifindex 7
    
    Name is reported as eth1 in old netns for ifindex 5, already renamed.
    
    Fixes: d9031024
    
     ("net: device name allocation cleanups")
    Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
    Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
    311cca40
dev.c 291 KB