Skip to content

Commit e6f8f1a

Browse files
xemuldavem330
authored andcommitted
veth: Allow to create peer link with given ifindex
The ifinfomsg is in there (thanks kaber@ for foreseeing this long time ago), so take the given ifidex and register netdev with it. Ben noticed, that this code path previously ignored ifmp->ifi_index and userland could be passing in garbage. Thus it may now fail occasionally because the value clashes with an existing interface. To address this it's assumed that if the caller specifies the ifindex for the veth master device, then it's aware of this possibility and should explicitly specify (or set to 0 for auto-assignment) the peer's ifindex as well. With this the compatibility with old tools not setting ifindex is preserved. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9c7dafb commit e6f8f1a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/net/veth.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
348348
if (tbp[IFLA_ADDRESS] == NULL)
349349
eth_hw_addr_random(peer);
350350

351+
if (ifmp && (dev->ifindex != 0))
352+
peer->ifindex = ifmp->ifi_index;
353+
351354
err = register_netdevice(peer);
352355
put_net(net);
353356
net = NULL;

0 commit comments

Comments
 (0)