@@ -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);
}
@@ -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);
}
@@ -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
@@ -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;
@@ -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;
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(-)