Commit 191cdb38 authored by Serhey Popovych's avatar Serhey Popovych Committed by David S. Miller

veth: Be more robust on network device creation when no attributes

There are number of problems with configuration peer
network device in absence of IFLA_VETH_PEER attributes
where attributes for main network device shared with
peer.

First it is not feasible to configure both network
devices with same MAC address since this makes
communication in such configuration problematic.

This case can be reproduced with following sequence:

  # ip link add address 02:11:22:33:44:55 type veth
  # ip li sh
  ...
  26: veth0@veth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc \
  noop state DOWN mode DEFAULT qlen 1000
      link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
  27: veth1@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc \
  noop state DOWN mode DEFAULT qlen 1000
      link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff

Second it is not possible to register both main and
peer network devices with same name, that happens
when name for main interface is given with IFLA_IFNAME
and same attribute reused for peer.

This case can be reproduced with following sequence:

  # ip link add dev veth1a type veth
  RTNETLINK answers: File exists

To fix both of the cases check if corresponding netlink
attributes are taken from peer_tb when valid or
name based on rtnl ops kind and random address is used.
Signed-off-by: default avatarSerhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b88ff4f8
...@@ -383,7 +383,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev, ...@@ -383,7 +383,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
tbp = tb; tbp = tb;
} }
if (tbp[IFLA_IFNAME]) { if (ifmp && tbp[IFLA_IFNAME]) {
nla_strlcpy(ifname, tbp[IFLA_IFNAME], IFNAMSIZ); nla_strlcpy(ifname, tbp[IFLA_IFNAME], IFNAMSIZ);
name_assign_type = NET_NAME_USER; name_assign_type = NET_NAME_USER;
} else { } else {
...@@ -402,7 +402,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev, ...@@ -402,7 +402,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
return PTR_ERR(peer); return PTR_ERR(peer);
} }
if (tbp[IFLA_ADDRESS] == NULL) if (!ifmp || !tbp[IFLA_ADDRESS])
eth_hw_addr_random(peer); eth_hw_addr_random(peer);
if (ifmp && (dev->ifindex != 0)) if (ifmp && (dev->ifindex != 0))
......
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