From patchwork Thu Oct 1 07:59:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374920 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25NF5jJ2z9sSC for ; Thu, 1 Oct 2020 18:08:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731632AbgJAIIJ convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:08:09 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:39884 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725921AbgJAIII (ORCPT ); Thu, 1 Oct 2020 04:08:08 -0400 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-276-qL86IzwWOeWS1scDCNaT0g-1; Thu, 01 Oct 2020 04:00:34 -0400 X-MC-Unique: qL86IzwWOeWS1scDCNaT0g-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 38413801AB3; Thu, 1 Oct 2020 08:00:33 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F0CF5C1CF; Thu, 1 Oct 2020 08:00:32 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca Subject: [PATCH net 01/12] ipvlan: add get_link_net Date: Thu, 1 Oct 2020 09:59:25 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: queasysnail.net Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, ipvlan devices don't advertise a link-netnsid. We can get it from the lower device, like macvlan does. Signed-off-by: Sabrina Dubroca --- drivers/net/ipvlan/ipvlan_main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 5bca94c99006..a81bb68a5713 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -678,6 +678,14 @@ void ipvlan_link_setup(struct net_device *dev) } EXPORT_SYMBOL_GPL(ipvlan_link_setup); +static struct net *ipvlan_get_link_net(const struct net_device *dev) +{ + struct ipvl_dev *ipvlan = netdev_priv(dev); + struct net_device *phy_dev = ipvlan->phy_dev; + + return dev_net(phy_dev); +} + static const struct nla_policy ipvlan_nl_policy[IFLA_IPVLAN_MAX + 1] = { [IFLA_IPVLAN_MODE] = { .type = NLA_U16 }, @@ -691,6 +699,7 @@ static struct rtnl_link_ops ipvlan_link_ops = { .setup = ipvlan_link_setup, .newlink = ipvlan_link_new, .dellink = ipvlan_link_delete, + .get_link_net = ipvlan_get_link_net, }; int ipvlan_link_register(struct rtnl_link_ops *ops) From patchwork Thu Oct 1 07:59:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374915 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25MG47Ccz9sSC for ; Thu, 1 Oct 2020 18:07:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731621AbgJAIHF convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:38546 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725975AbgJAIHE (ORCPT ); Thu, 1 Oct 2020 04:07:04 -0400 X-Greylist: delayed 387 seconds by postgrey-1.27 at vger.kernel.org; Thu, 01 Oct 2020 04:07:04 EDT 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-193-c0rJb9JYMwi4j-kEEH-aOA-1; Thu, 01 Oct 2020 04:00:35 -0400 X-MC-Unique: c0rJb9JYMwi4j-kEEH-aOA-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 5A64C10BBEE2; Thu, 1 Oct 2020 08:00:34 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 918485C1CF; Thu, 1 Oct 2020 08:00:33 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca Subject: [PATCH net 02/12] geneve: add get_link_net Date: Thu, 1 Oct 2020 09:59:26 +0200 Message-Id: <84bc21ebf2a9f5898cd81d68e00b72fd6f43ba6b.1600770261.git.sd@queasysnail.net> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: queasysnail.net Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, geneve devices don't advertise a link netns. Similarly to VXLAN, we can get it from geneve_dev->net. Fixes: 2d07dc79fe04 ("geneve: add initial netdev driver for GENEVE tunnels") Signed-off-by: Sabrina Dubroca --- drivers/net/geneve.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index 974a244f45ba..cd47940bfcbe 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -1791,6 +1791,13 @@ static int geneve_fill_info(struct sk_buff *skb, const struct net_device *dev) return -EMSGSIZE; } +static struct net *geneve_get_link_net(const struct net_device *dev) +{ + struct geneve_dev *geneve = netdev_priv(dev); + + return geneve->net; +} + static struct rtnl_link_ops geneve_link_ops __read_mostly = { .kind = "geneve", .maxtype = IFLA_GENEVE_MAX, @@ -1803,6 +1810,7 @@ static struct rtnl_link_ops geneve_link_ops __read_mostly = { .dellink = geneve_dellink, .get_size = geneve_get_size, .fill_info = geneve_fill_info, + .get_link_net = geneve_get_link_net, }; struct net_device *geneve_dev_create_fb(struct net *net, const char *name, From patchwork Thu Oct 1 07:59:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374916 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25MK269rz9sVH for ; Thu, 1 Oct 2020 18:07:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731679AbgJAIHX convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:23 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:32162 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731599AbgJAIHF (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 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-534-69hJf2bWPKeeqIMgWn5mVw-1; Thu, 01 Oct 2020 04:00:36 -0400 X-MC-Unique: 69hJf2bWPKeeqIMgWn5mVw-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 8027E9CC01; Thu, 1 Oct 2020 08:00:35 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id B42D65E1DD; Thu, 1 Oct 2020 08:00:34 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca Subject: [PATCH net 03/12] Revert "rtnetlink: always put IFLA_LINK for links with a link-netnsid" Date: Thu, 1 Oct 2020 09:59:27 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: queasysnail.net Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This reverts commit feadc4b6cf42a53a8a93c918a569a0b7e62bd350. It fixed the particular issue that was seen in the OpenShift setup, but ignored the case of tunnels like VXLAN, which export a IFLA_LINK_NETNSID attribute but don't have an IFLA_LINK. In case a vxlan device is created in one netns, then moved to another, we end up seeing: # ip -net foo link 15: vxlan1@if15: mtu 1450 qdisc noop state DOWN mode DEFAULT group default qlen 1000 ^ The next patch will fix the original problem properly. Fixes: feadc4b6cf42 ("rtnetlink: always put IFLA_LINK for links with a link-netnsid") Signed-off-by: Sabrina Dubroca --- net/core/rtnetlink.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 68e0682450c6..c35b3f02b4f9 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1547,15 +1547,14 @@ static int put_master_ifindex(struct sk_buff *skb, struct net_device *dev) return ret; } -static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev, - bool force) +static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev) { int ifindex = dev_get_iflink(dev); - if (force || dev->ifindex != ifindex) - return nla_put_u32(skb, IFLA_LINK, ifindex); + if (dev->ifindex == ifindex) + return 0; - return 0; + return nla_put_u32(skb, IFLA_LINK, ifindex); } static noinline_for_stack int nla_put_ifalias(struct sk_buff *skb, @@ -1572,8 +1571,6 @@ static int rtnl_fill_link_netnsid(struct sk_buff *skb, const struct net_device *dev, struct net *src_net, gfp_t gfp) { - bool put_iflink = false; - if (dev->rtnl_link_ops && dev->rtnl_link_ops->get_link_net) { struct net *link_net = dev->rtnl_link_ops->get_link_net(dev); @@ -1582,12 +1579,10 @@ static int rtnl_fill_link_netnsid(struct sk_buff *skb, if (nla_put_s32(skb, IFLA_LINK_NETNSID, id)) return -EMSGSIZE; - - put_iflink = true; } } - return nla_put_iflink(skb, dev, put_iflink); + return 0; } static int rtnl_fill_link_af(struct sk_buff *skb, @@ -1738,6 +1733,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, #ifdef CONFIG_RPS nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) || #endif + nla_put_iflink(skb, dev) || put_master_ifindex(skb, dev) || nla_put_u8(skb, IFLA_CARRIER, netif_carrier_ok(dev)) || (dev->qdisc && From patchwork Thu Oct 1 07:59:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374914 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25MD3b2bz9sSC for ; Thu, 1 Oct 2020 18:07:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731678AbgJAIHT convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:19 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:25668 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731602AbgJAIHF (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 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-270-cvmLx2hHODuBMJbnzzTZLA-1; Thu, 01 Oct 2020 04:00:37 -0400 X-MC-Unique: cvmLx2hHODuBMJbnzzTZLA-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 A257318BE170; Thu, 1 Oct 2020 08:00:36 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7B635C1CF; Thu, 1 Oct 2020 08:00:35 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca Subject: [PATCH net 04/12] rtnetlink: always put IFLA_LINK for links with ndo_get_iflink Date: Thu, 1 Oct 2020 09:59:28 +0200 Message-Id: <34fa2e8db1eed23297405cd9144afd6c10ccc392.1600770261.git.sd@queasysnail.net> 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The test that nla_put_iflink() uses to detect whether a device has a lower link doesn't work with network namespaces, as a device can have the same ifindex as its parent: ip netns add main ip netns add peer ip -net main link add dummy0 type dummy ip -net main link add link dummy0 macvlan0 netns peer type macvlan ip -net main link show type dummy # 9: dummy0: mtu 1500 qdisc noop ... ip -net peer link show type macvlan # 9: macvlan0@if9: mtu 1500 qdisc noop ... Instead of calling dev_get_iflink(), we can use the existence of the ndo_get_iflink operation (which dev_get_iflink would call) to check if a device has a lower link. I previously tried to fix this with commit feadc4b6cf42 ("rtnetlink: always put IFLA_LINK for links with a link-netnsid") but didn't get to the root of the problem. Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.") Signed-off-by: Sabrina Dubroca --- net/core/rtnetlink.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index c35b3f02b4f9..a8459fb59ccd 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1549,12 +1549,13 @@ static int put_master_ifindex(struct sk_buff *skb, struct net_device *dev) static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev) { - int ifindex = dev_get_iflink(dev); + if (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink) { + int ifindex = dev->netdev_ops->ndo_get_iflink(dev); - if (dev->ifindex == ifindex) - return 0; + return nla_put_u32(skb, IFLA_LINK, ifindex); + } - return nla_put_u32(skb, IFLA_LINK, ifindex); + return 0; } static noinline_for_stack int nla_put_ifalias(struct sk_buff *skb, From patchwork Thu Oct 1 07:59:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374912 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25M813vqz9sSC for ; Thu, 1 Oct 2020 18:07:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731527AbgJAIHO convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:14 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:23098 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731604AbgJAIHF (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 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-358-NyFMpeS1MquNUIqzQwKA3A-1; Thu, 01 Oct 2020 04:00:39 -0400 X-MC-Unique: NyFMpeS1MquNUIqzQwKA3A-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 2EC8B10BBEDC; Thu, 1 Oct 2020 08:00:38 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 077055C1CF; Thu, 1 Oct 2020 08:00:36 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca , Roopa Prabhu , Nikolay Aleksandrov Subject: [PATCH net 05/12] bridge: always put IFLA_LINK for ports with ndo_get_iflink Date: Thu, 1 Oct 2020 09:59:29 +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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Bridge devices try to detect if devices have a lower link when dumping information about their ports, but that detection doesn't work when the device and its link have the same ifindex: For a bridge with the following ports: 20: veth1@if20: mtu 1500 qdisc noop master bridge0 ... 22: veth2@if21: mtu 1500 qdisc noop master bridge0 ... We get this output with the "bridge link" command: 20: veth1: mtu 1500 master bridge0 ... 22: veth2@if21: mtu 1500 master bridge0 ... veth1 should also have "@if20" in bridge link. Instead of calling dev_get_iflink(), we can use the existence of the ndo_get_iflink operation (which dev_get_iflink would call) to check if a device has a lower link. Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.") Signed-off-by: Sabrina Dubroca --- net/bridge/br_netlink.c | 2 +- net/core/rtnetlink.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 147d52596e17..6af5d62ddf7b 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -410,7 +410,7 @@ static int br_fill_ifinfo(struct sk_buff *skb, nla_put_u8(skb, IFLA_OPERSTATE, operstate) || (dev->addr_len && nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || - (dev->ifindex != dev_get_iflink(dev) && + (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink && nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev)))) goto nla_put_failure; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index a8459fb59ccd..3d8051158890 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4625,7 +4625,7 @@ int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, nla_put_u32(skb, IFLA_MASTER, br_dev->ifindex)) || (dev->addr_len && nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || - (dev->ifindex != dev_get_iflink(dev) && + (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink && nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev)))) goto nla_put_failure; From patchwork Thu Oct 1 07:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374909 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25M126gJz9sSC for ; Thu, 1 Oct 2020 18:07:09 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731674AbgJAIHI convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:08 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:36667 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731383AbgJAIHG (ORCPT ); Thu, 1 Oct 2020 04:07:06 -0400 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-100-PlP_Dy8BNCOL9PTgHCWvXw-1; Thu, 01 Oct 2020 04:00:40 -0400 X-MC-Unique: PlP_Dy8BNCOL9PTgHCWvXw-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 AF2E018BE198; Thu, 1 Oct 2020 08:00:39 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 884FA5C1CF; Thu, 1 Oct 2020 08:00:38 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca , Roopa Prabhu , Nikolay Aleksandrov Subject: [PATCH net 06/12] bridge: advertise IFLA_LINK_NETNSID when dumping bridge ports Date: Thu, 1 Oct 2020 09:59:30 +0200 Message-Id: <616f74e09c5dca0735e25573ad6a8a10411f51df.1600770261.git.sd@queasysnail.net> 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, we're not advertising link-netnsid for bridge ports, so the "bridge link" command will not correctly interpret the value of the IFLA_LINK attribute. With this setup (ip link output): 9: bridge0: mtu 1500 ... 10: veth0@if10: mtu 1500 qdisc noop master bridge0 ... 11: veth1@if9: mtu 1500 qdisc noop master bridge0 ... we'll get: 10: veth0: mtu 1500 master bridge0 ... 11: veth1@bridge0: mtu 1500 master ... instead of: 10: veth0@if10: mtu 1500 master bridge0 ... 11: veth1@if9: mtu 1500 master bridge0 ... br_fill_ifinfo can be called without RTNL (from br_forward_delay_timer_expired), so we need to change get_link_net callbacks to use rcu_dereference_rtnl instead of rtnl_dereference. Signed-off-by: Sabrina Dubroca --- drivers/net/can/vxcan.c | 2 +- drivers/net/veth.c | 2 +- include/net/rtnetlink.h | 4 ++++ net/bridge/br_netlink.c | 2 ++ net/core/rtnetlink.c | 8 +++++--- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c index d6ba9426be4d..870109d38b28 100644 --- a/drivers/net/can/vxcan.c +++ b/drivers/net/can/vxcan.c @@ -276,7 +276,7 @@ static const struct nla_policy vxcan_policy[VXCAN_INFO_MAX + 1] = { static struct net *vxcan_get_link_net(const struct net_device *dev) { struct vxcan_priv *priv = netdev_priv(dev); - struct net_device *peer = rtnl_dereference(priv->peer); + struct net_device *peer = rcu_dereference_rtnl(priv->peer); return peer ? dev_net(peer) : dev_net(dev); } diff --git a/drivers/net/veth.c b/drivers/net/veth.c index a475f48d43c4..5f814620d97e 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1433,7 +1433,7 @@ static const struct nla_policy veth_policy[VETH_INFO_MAX + 1] = { static struct net *veth_get_link_net(const struct net_device *dev) { struct veth_priv *priv = netdev_priv(dev); - struct net_device *peer = rtnl_dereference(priv->peer); + struct net_device *peer = rcu_dereference_rtnl(priv->peer); return peer ? dev_net(peer) : dev_net(dev); } diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index e2091bb2b3a8..c37cb3d98c7c 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -168,6 +168,10 @@ int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len, struct netlink_ext_ack *exterr); struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid); +int rtnl_fill_link_netnsid(struct sk_buff *skb, + const struct net_device *dev, + struct net *src_net, gfp_t gfp); + #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind) #endif diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 6af5d62ddf7b..81ea4e89edba 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -164,6 +164,7 @@ static inline size_t br_nlmsg_size(struct net_device *dev, u32 filter_mask) + nla_total_size(4) /* IFLA_MASTER */ + nla_total_size(4) /* IFLA_MTU */ + nla_total_size(4) /* IFLA_LINK */ + + nla_total_size(4) /* IFLA_LINK_NETNSID */ + nla_total_size(1) /* IFLA_OPERSTATE */ + nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */ + nla_total_size(br_get_link_af_size_filtered(dev, @@ -410,6 +411,7 @@ static int br_fill_ifinfo(struct sk_buff *skb, nla_put_u8(skb, IFLA_OPERSTATE, operstate) || (dev->addr_len && nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || + rtnl_fill_link_netnsid(skb, dev, dev_net(br->dev), GFP_ATOMIC) || (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink && nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev)))) goto nla_put_failure; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 3d8051158890..26ce9fafc379 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1568,9 +1568,9 @@ static noinline_for_stack int nla_put_ifalias(struct sk_buff *skb, return ret > 0 ? nla_put_string(skb, IFLA_IFALIAS, buf) : 0; } -static int rtnl_fill_link_netnsid(struct sk_buff *skb, - const struct net_device *dev, - struct net *src_net, gfp_t gfp) +int rtnl_fill_link_netnsid(struct sk_buff *skb, + const struct net_device *dev, + struct net *src_net, gfp_t gfp) { if (dev->rtnl_link_ops && dev->rtnl_link_ops->get_link_net) { struct net *link_net = dev->rtnl_link_ops->get_link_net(dev); @@ -1585,6 +1585,7 @@ static int rtnl_fill_link_netnsid(struct sk_buff *skb, return 0; } +EXPORT_SYMBOL_GPL(rtnl_fill_link_netnsid); static int rtnl_fill_link_af(struct sk_buff *skb, const struct net_device *dev, @@ -4625,6 +4626,7 @@ int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, nla_put_u32(skb, IFLA_MASTER, br_dev->ifindex)) || (dev->addr_len && nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || + rtnl_fill_link_netnsid(skb, dev, dev_net(br_dev), GFP_ATOMIC) || (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink && nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev)))) goto nla_put_failure; From patchwork Thu Oct 1 07:59:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374913 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25MB0j26z9sSC for ; Thu, 1 Oct 2020 18:07:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731632AbgJAIHF convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:40344 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730534AbgJAIHE (ORCPT ); Thu, 1 Oct 2020 04:07:04 -0400 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-559-17nANtxkPeWVclLZgalo2g-1; Thu, 01 Oct 2020 04:00:41 -0400 X-MC-Unique: 17nANtxkPeWVclLZgalo2g-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 D15A58070FD; Thu, 1 Oct 2020 08:00:40 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1359D5C1CF; Thu, 1 Oct 2020 08:00:39 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca Subject: [PATCH net 07/12] ipv6: always put IFLA_LINK for devices with ndo_get_iflink Date: Thu, 1 Oct 2020 09:59:31 +0200 Message-Id: <9ccee167b001a643109fcb61130e32ccf96080ee.1600770261.git.sd@queasysnail.net> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: queasysnail.net Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org IPv6 tries to detect if devices have a lower link when dumping addresses, but that detection doesn't work when the device and its link have the same ifindex. In this setup: ip netns add main ip netns add peer ip -net main link add dummy0 type dummy # ifidx 9 ip -net main link add link dummy0 macvlan0 up netns peer type macvlan # ifidx 9 We'll get: ip -net peer -6 a 9: macvlan0: Instead of: ip -net peer -6 a 9: macvlan0@if9: Instead of calling dev_get_iflink(), we can use the existence of the ndo_get_iflink operation (which dev_get_iflink would call) to check if a device has a lower link. Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.") Signed-off-by: Sabrina Dubroca --- net/ipv6/addrconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 01146b66d666..688e441a8699 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -5835,7 +5835,7 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, (dev->addr_len && nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || nla_put_u32(skb, IFLA_MTU, dev->mtu) || - (dev->ifindex != dev_get_iflink(dev) && + (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink && nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))) || nla_put_u8(skb, IFLA_OPERSTATE, netif_running(dev) ? dev->operstate : IF_OPER_DOWN)) From patchwork Thu Oct 1 07:59:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374910 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25M43ql9z9sSC for ; Thu, 1 Oct 2020 18:07:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731647AbgJAIHF convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:48057 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731459AbgJAIHE (ORCPT ); Thu, 1 Oct 2020 04:07:04 -0400 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-527-To-CSBxWNle7O1IMxEJkdQ-1; Thu, 01 Oct 2020 04:00:43 -0400 X-MC-Unique: To-CSBxWNle7O1IMxEJkdQ-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 F235D106C10B; Thu, 1 Oct 2020 08:00:41 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35C945C1CF; Thu, 1 Oct 2020 08:00:41 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca Subject: [PATCH net 08/12] ipv6: advertise IFLA_LINK_NETNSID when dumping ipv6 addresses Date: Thu, 1 Oct 2020 09:59:32 +0200 Message-Id: <00ecfc1804b58d8dbb23b8a6e7e5c0646f0100e1.1600770261.git.sd@queasysnail.net> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: queasysnail.net Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, we're not advertising link-netnsid when dumping IPv6 addresses, so the "ip -6 addr" command will not correctly interpret the value of the IFLA_LINK attribute. For example, we'll get: 9: macvlan0@macvlan0: mtu 1500 state UP qlen 1000 Instead of: 9: macvlan0@if9: mtu 1500 state UP qlen 1000 link-netns main ndisc_ifinfo_sysctl_change calls inet6_fill_ifinfo without rcu or rtnl, so I'm adding rcu_read_lock around rtnl_fill_link_netnsid. Signed-off-by: Sabrina Dubroca --- net/ipv6/addrconf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 688e441a8699..fb95c0227dfe 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -5533,6 +5533,7 @@ static inline size_t inet6_if_nlmsg_size(void) + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ + nla_total_size(4) /* IFLA_MTU */ + nla_total_size(4) /* IFLA_LINK */ + + nla_total_size(4) /* IFLA_LINK_NETNSID */ + nla_total_size(1) /* IFLA_OPERSTATE */ + nla_total_size(inet6_ifla6_size()); /* IFLA_PROTINFO */ } @@ -5840,6 +5841,14 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, nla_put_u8(skb, IFLA_OPERSTATE, netif_running(dev) ? dev->operstate : IF_OPER_DOWN)) goto nla_put_failure; + + rcu_read_lock(); + if (rtnl_fill_link_netnsid(skb, dev, dev_net(dev), GFP_ATOMIC)) { + rcu_read_unlock(); + goto nla_put_failure; + } + rcu_read_unlock(); + protoinfo = nla_nest_start_noflag(skb, IFLA_PROTINFO); if (!protoinfo) goto nla_put_failure; From patchwork Thu Oct 1 07:59:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374918 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25NB16m7z9sSC for ; Thu, 1 Oct 2020 18:08:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731670AbgJAIIJ convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:08:09 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:54308 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731067AbgJAIII (ORCPT ); Thu, 1 Oct 2020 04:08:08 -0400 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-474-s2QRyDWfMUOkq9IBwFci3A-1; Thu, 01 Oct 2020 04:00:44 -0400 X-MC-Unique: s2QRyDWfMUOkq9IBwFci3A-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 20731ADF0D; Thu, 1 Oct 2020 08:00:43 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 570395C1CF; Thu, 1 Oct 2020 08:00:42 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca Subject: [PATCH net 09/12] net: link_watch: fix operstate when the link has the same index as the device Date: Thu, 1 Oct 2020 09:59:33 +0200 Message-Id: <879af1e3232451feee4a306c1e757bef188b0ee4.1600770261.git.sd@queasysnail.net> 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When we create a macvlan device on top of a bond, the macvlan device should always start with IF_OPER_LOWERLAYERDOWN if the bond is down. Currently, this doesn't happen if the macvlan device gets the same ifindex as the bond, which can happen because different namespaces assign the ifindex independently: ip netns add main ip netns add peer ip -net main link add type bond # idx 9 ip -net main link add link bond0 netns peer type macvlan # idx 10 ip -net main link add link bond0 type macvlan # idx 9 ip -net main link show type macvlan # M-DOWN since bond0 is DOWN 10: macvlan0@bond0: ... ip -net peer link show type macvlan # should also be M-DOWN 9: macvlan0@if9: ... Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.") Signed-off-by: Sabrina Dubroca Reported-by: syzbot+95eec132c4bd9b1d8430@syzkaller.appspotmail.com Reported-by: syzbot+d702fd2351989927037c@syzkaller.appspotmail.com --- net/core/link_watch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/link_watch.c b/net/core/link_watch.c index 75431ca9300f..6932ad51aa4a 100644 --- a/net/core/link_watch.c +++ b/net/core/link_watch.c @@ -38,7 +38,7 @@ static unsigned char default_operstate(const struct net_device *dev) return IF_OPER_TESTING; if (!netif_carrier_ok(dev)) - return (dev->ifindex != dev_get_iflink(dev) ? + return (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink ? IF_OPER_LOWERLAYERDOWN : IF_OPER_DOWN); if (netif_dormant(dev)) From patchwork Thu Oct 1 07:59:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374911 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25M61fTqz9sSC for ; Thu, 1 Oct 2020 18:07:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731639AbgJAIHF convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:47606 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731584AbgJAIHE (ORCPT ); Thu, 1 Oct 2020 04:07:04 -0400 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-212-OKq6BDwgObuMt32IHqf7oA-1; Thu, 01 Oct 2020 04:00:45 -0400 X-MC-Unique: OKq6BDwgObuMt32IHqf7oA-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 458C318C89FD; Thu, 1 Oct 2020 08:00:44 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id 791D65C1D7; Thu, 1 Oct 2020 08:00:43 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca Subject: [PATCH net 10/12] net: link_watch: fix detection of urgent events Date: Thu, 1 Oct 2020 09:59:34 +0200 Message-Id: <5a58a1a6425c565bb0ba7f46461fdd23cedb6b72.1600770261.git.sd@queasysnail.net> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: queasysnail.net Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org linkwatch_urgent_event can miss urgent events when the device and its link have the same ifindex, which can happen when those devices are in different network namespaces. With this setup, the vlan0 device can remain in LOWERLAYERDOWN state for a full second (the linkwatch delay for non-urgent events), while the vlan1 device will come up immediately: ip netns add a ip netns add b ip -net a link add dummy0 type dummy ip -net a link add link dummy0 vlan0 netns b type vlan id 1 ip -net a link add link dummy0 vlan1 netns b type vlan id 2 ip -net a link set dummy0 up ip -net b link set vlan1 down ; ip -net b link set vlan0 down sleep 2 ip -net b link set vlan1 up ; ip -net b link set vlan0 up Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.") Signed-off-by: Sabrina Dubroca --- net/core/link_watch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/link_watch.c b/net/core/link_watch.c index 6932ad51aa4a..8a5d0ab820f9 100644 --- a/net/core/link_watch.c +++ b/net/core/link_watch.c @@ -92,7 +92,7 @@ static bool linkwatch_urgent_event(struct net_device *dev) if (!netif_running(dev)) return false; - if (dev->ifindex != dev_get_iflink(dev)) + if (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink) return true; if (netif_is_lag_port(dev) || netif_is_lag_master(dev)) 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: 1374905 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25Ly3tzBz9sVH for ; Thu, 1 Oct 2020 18:07:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731662AbgJAIHG convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:06 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:54589 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731592AbgJAIHF (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 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 Cc: Sabrina Dubroca , Marek Lindner , Simon Wunderlich , Antonio Quartulli , Sven Eckelmann , b.a.t.m.a.n@lists.open-mesh.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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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); From patchwork Thu Oct 1 07:59:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 1374908 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=queasysnail.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C25Lz4nrZz9sSC for ; Thu, 1 Oct 2020 18:07:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731670AbgJAIHG convert rfc822-to-8bit (ORCPT ); Thu, 1 Oct 2020 04:07:06 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:52078 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731596AbgJAIHF (ORCPT ); Thu, 1 Oct 2020 04:07:05 -0400 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-402-6b_LtMKCMyORfAEColTw4A-1; Thu, 01 Oct 2020 04:00:50 -0400 X-MC-Unique: 6b_LtMKCMyORfAEColTw4A-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 9FA913EB9; Thu, 1 Oct 2020 08:00:48 +0000 (UTC) Received: from hog.localdomain, (unknown [10.40.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id E20CB5C1CF; Thu, 1 Oct 2020 08:00:46 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca , Marek Lindner , Simon Wunderlich , Antonio Quartulli , Sven Eckelmann , b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH net 12/12] batman-adv: fix detection of lower link in batadv_get_real_netdevice Date: Thu, 1 Oct 2020 09:59:36 +0200 Message-Id: <9599bc5738a16580aa5b87a6586110953918d622.1600770261.git.sd@queasysnail.net> 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, batadv_get_real_netdevice can return different results in this situation: ip netns add main ip netns add peer ip -net main link add dummy1 type dummy ip -net main link add link dummy1 netns peer type macsec # same ifindex as dummy1 ip -net main link add link dummy1 netns peer type macsec port 2 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: 5ed4a460a1d3 ("batman-adv: additional checks for virtual interfaces on top of WiFi") 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 0d87c5d56844..8f7d2dd37321 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -223,7 +223,7 @@ static struct net_device *batadv_get_real_netdevice(struct net_device *netdev) if (!netdev) return NULL; - if (netdev->ifindex == dev_get_iflink(netdev)) { + if (!(netdev->netdev_ops && netdev->netdev_ops->ndo_get_iflink)) { dev_hold(netdev); return netdev; }