All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: netdev@vger.kernel.org
Cc: Sabrina Dubroca <sd@queasysnail.net>,
	Roopa Prabhu <roopa@nvidia.com>,
	Nikolay Aleksandrov <nikolay@nvidia.com>
Subject: [PATCH net 06/12] bridge: advertise IFLA_LINK_NETNSID when dumping bridge ports
Date: Thu,  1 Oct 2020 09:59:30 +0200	[thread overview]
Message-ID: <616f74e09c5dca0735e25573ad6a8a10411f51df.1600770261.git.sd@queasysnail.net> (raw)
In-Reply-To: <cover.1600770261.git.sd@queasysnail.net>

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: <BROADCAST,MULTICAST> mtu 1500 ...
    10: veth0@if10: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master bridge0 ...
    11: veth1@if9: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master bridge0 ...

we'll get:
    10: veth0: <BROADCAST,MULTICAST> mtu 1500 master bridge0 ...
    11: veth1@bridge0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 master ...

instead of:
    10: veth0@if10: <BROADCAST,MULTICAST> mtu 1500 master bridge0 ...
    11: veth1@if9: <BROADCAST,MULTICAST> 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 <sd@queasysnail.net>
---
 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;
-- 
2.28.0


  parent reply	other threads:[~2020-10-01  8:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01  7:59 [PATCH net 00/12] net: iflink and link-netnsid fixes Sabrina Dubroca
2020-10-01  7:59 ` [PATCH net 01/12] ipvlan: add get_link_net Sabrina Dubroca
2020-10-01  8:19   ` Eric Dumazet
2020-10-01  7:59 ` [PATCH net 02/12] geneve: " Sabrina Dubroca
2020-10-01  7:59 ` [PATCH net 03/12] Revert "rtnetlink: always put IFLA_LINK for links with a link-netnsid" Sabrina Dubroca
2020-10-01  7:59 ` [PATCH net 04/12] rtnetlink: always put IFLA_LINK for links with ndo_get_iflink Sabrina Dubroca
2020-10-01  7:59 ` [PATCH net 05/12] bridge: always put IFLA_LINK for ports " Sabrina Dubroca
2020-10-01  7:59 ` Sabrina Dubroca [this message]
2020-10-01  7:59 ` [PATCH net 07/12] ipv6: always put IFLA_LINK for devices " Sabrina Dubroca
2020-10-01  7:59 ` [PATCH net 08/12] ipv6: advertise IFLA_LINK_NETNSID when dumping ipv6 addresses Sabrina Dubroca
2020-10-01 15:58   ` Nicolas Dichtel
2020-10-02  9:03     ` Sabrina Dubroca
2020-10-05 15:16       ` Nicolas Dichtel
2020-10-01  7:59 ` [PATCH net 09/12] net: link_watch: fix operstate when the link has the same index as the device Sabrina Dubroca
2020-10-01 11:00   ` Taehee Yoo
2020-10-01  7:59 ` [PATCH net 10/12] net: link_watch: fix detection of urgent events Sabrina Dubroca
2020-10-01  7:59 ` [PATCH net 11/12] batman-adv: fix iflink detection in batadv_is_on_batman_iface Sabrina Dubroca
2022-05-14 10:21   ` Sven Eckelmann
2022-05-14 10:21     ` Sven Eckelmann
2020-10-01  7:59 ` [PATCH net 12/12] batman-adv: fix detection of lower link in batadv_get_real_netdevice Sabrina Dubroca
2020-10-01 21:25 ` [PATCH net 00/12] net: iflink and link-netnsid fixes Stephen Hemminger
2020-10-02  9:07   ` Sabrina Dubroca

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=616f74e09c5dca0735e25573ad6a8a10411f51df.1600770261.git.sd@queasysnail.net \
    --to=sd@queasysnail.net \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@nvidia.com \
    --cc=roopa@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.