From patchwork Thu Aug 9 07:53:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Emelyanov X-Patchwork-Id: 176015 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 727F12C00DE for ; Thu, 9 Aug 2012 17:53:16 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756050Ab2HIHxO (ORCPT ); Thu, 9 Aug 2012 03:53:14 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:18604 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754371Ab2HIHxM (ORCPT ); Thu, 9 Aug 2012 03:53:12 -0400 Received: from [10.30.16.117] ([10.30.16.117]) (authenticated bits=0) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id q797r4K5015152 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 9 Aug 2012 11:53:04 +0400 (MSK) Message-ID: <50236C5F.1010609@parallels.com> Date: Thu, 09 Aug 2012 11:53:03 +0400 From: Pavel Emelyanov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120209 Thunderbird/10.0.1 MIME-Version: 1.0 To: David Miller , Eric Dumazet , "Eric W. Biederman" , Linux Netdev List , Ben Hutchings Subject: [PATCH 3/5] veth: Allow to create peer link with given ifindex References: <50236C20.4050108@parallels.com> In-Reply-To: <50236C20.4050108@parallels.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- drivers/net/veth.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 5852361..e522ff7 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -348,6 +348,9 @@ static int veth_newlink(struct net *src_net, struct net_device *dev, if (tbp[IFLA_ADDRESS] == NULL) eth_hw_addr_random(peer); + if (ifmp && (dev->ifindex != 0)) + peer->ifindex = ifmp->ifi_index; + err = register_netdevice(peer); put_net(net); net = NULL;