From patchwork Thu Oct 1 07:59:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 18197 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id EC19C80846; Thu, 1 Oct 2020 11:30:39 +0200 (CEST) Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by diktynna.open-mesh.org (Postfix) with ESMTPS id 951CB805F1 for ; Thu, 1 Oct 2020 10:00:55 +0200 (CEST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-xfHXktrMMp-DTQpSgZrIYQ-1; Thu, 01 Oct 2020 04:00:48 -0400 X-MC-Unique: xfHXktrMMp-DTQpSgZrIYQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 882F210BBED0; Thu, 1 Oct 2020 08:00:46 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E5705C1CF; Thu, 1 Oct 2020 08:00:44 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Subject: [PATCH net 11/12] batman-adv: fix iflink detection in batadv_is_on_batman_iface Date: Thu, 1 Oct 2020 09:59:35 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=sd@queasysnail.net X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: queasysnail.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1601539256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vKHr3Uh6hjZ4ArCpHl8IBK8GNSHgr0B2cFZxq8Ubec4=; b=RNtpCUZQWmgyk7ErUVmVrAtie4AXMpDqXeYRAycOBEMc++0QBQFTCyszTecgNFZbRSlJVY wMKevUeb4emZb6BUOV+JpmnecUK+duqP3gt48IUpz2kQjed1Dz16RgDrQ+CpHrVzKctGYv dxyyp9cr71rT+usWIYPUJfTiux41J4w= ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1601539256; a=rsa-sha256; cv=none; b=kx/ydnbrZ5C1BUG3oSe4+8zAxPNx/Co25ZzPHfNKdSSTFff7yLzC+AxKe+bk64KqSD35TM sVvwJ6watyyjFGsmPT5mSGZpqS5r/l8d8Bul834Jo0TahE6CQHny5lwDyGgJHwVFdJ1LyO Sc4xLgjsnE9SVxABRv3ElealDByKMg0= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none; spf=none (diktynna.open-mesh.org: domain of sd@queasysnail.net has no SPF policy when checking 207.211.30.44) smtp.mailfrom=sd@queasysnail.net X-MailFrom: sd@queasysnail.net X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1 Message-ID-Hash: 4A4F2JLOYPNIELC7KWHQ6GOEYXUUYV2D X-Message-ID-Hash: 4A4F2JLOYPNIELC7KWHQ6GOEYXUUYV2D X-Mailman-Approved-At: Thu, 01 Oct 2020 09:30:35 +0200 CC: Sabrina Dubroca , Marek Lindner , Antonio Quartulli , b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 3.2.1 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: BATMAN compares ifindex with dev_get_iflink to detect devices that don't have a parent, but that's wrong, since a device can have the same index as its parent if it's created in a different network namespace: ip netns add main ip netns add peer ip -net main link add dummy0 type dummy # keep ifindex in sync between the namespaces ip -net peer link add eatidx type dummy ip netns exec main batctl if add dummy0 # macsec0 and bat0 have the same ifindex ip -net main link add link bat0 netns peer type macsec ip netns exec peer batctl if add macsec0 That last command would fail if we didn't keep the ifindex in sync between the two namespaces, and should also fail when the macsec0 device has the same ifindex as its link. Let's use the presence of a ndo_get_iflink operation, rather than the value it returns, to detect a device without a link. Fixes: b7eddd0b3950 ("batman-adv: prevent using any virtual device created on batman-adv as hard-interface") Signed-off-by: Sabrina Dubroca --- net/batman-adv/hard-interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index fa06b51c0144..0d87c5d56844 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -159,7 +159,7 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) /* no more parents..stop recursion */ if (dev_get_iflink(net_dev) == 0 || - dev_get_iflink(net_dev) == net_dev->ifindex) + !(net_dev->netdev_ops && net_dev->netdev_ops->ndo_get_iflink)) return false; parent_net = batadv_getlink_net(net_dev, net);