* [PATCH net] rtnetlink: always put ILFA_LINK for links with a link-netnsid
@ 2019-05-13 13:01 Sabrina Dubroca
2019-05-13 13:17 ` Nicolas Dichtel
0 siblings, 1 reply; 3+ messages in thread
From: Sabrina Dubroca @ 2019-05-13 13:01 UTC (permalink / raw)
To: netdev; +Cc: Sabrina Dubroca, Nicolas Dichtel, Dan Winship
Currently, nla_put_iflink() doesn't put the IFLA_LINK attribute when
iflink == ifindex.
In some cases, a device can be created in a different netns with the
same ifindex as its parent. That device will not dump its IFLA_LINK
attribute, which can confuse some userspace software that expects it.
For example, if the last ifindex created in init_net and foo are both
8, these commands will trigger the issue:
ip link add parent type dummy # ifindex 9
ip link add link parent netns foo type macvlan # ifindex 9 in ns foo
So, in case a device puts the IFLA_LINK_NETNSID attribute in a dump,
always put the IFLA_LINK attribute as well.
Thanks to Dan Winship for analyzing the original OpenShift bug down to
the missing netlink attribute.
Analyzed-by: Dan Winship <danw@redhat.com>
Fixes: a54acb3a6f85 ("dev: introduce dev_get_iflink()")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
net/core/rtnetlink.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 2bd12afb9297..adcc045952c2 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1496,14 +1496,15 @@ 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)
+static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev,
+ bool force)
{
int ifindex = dev_get_iflink(dev);
- if (dev->ifindex == ifindex)
- return 0;
+ if (force || dev->ifindex != ifindex)
+ 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,
@@ -1520,6 +1521,8 @@ static int rtnl_fill_link_netnsid(struct sk_buff *skb,
const struct net_device *dev,
struct net *src_net)
{
+ 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);
@@ -1528,10 +1531,12 @@ 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 0;
+ return nla_put_iflink(skb, dev, put_iflink);
}
static int rtnl_fill_link_af(struct sk_buff *skb,
@@ -1617,7 +1622,6 @@ 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 &&
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] rtnetlink: always put ILFA_LINK for links with a link-netnsid
2019-05-13 13:01 [PATCH net] rtnetlink: always put ILFA_LINK for links with a link-netnsid Sabrina Dubroca
@ 2019-05-13 13:17 ` Nicolas Dichtel
2019-05-13 13:42 ` Sabrina Dubroca
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Dichtel @ 2019-05-13 13:17 UTC (permalink / raw)
To: Sabrina Dubroca, netdev; +Cc: Dan Winship
Le 13/05/2019 à 15:01, Sabrina Dubroca a écrit :
> Currently, nla_put_iflink() doesn't put the IFLA_LINK attribute when
> iflink == ifindex.
>
> In some cases, a device can be created in a different netns with the
> same ifindex as its parent. That device will not dump its IFLA_LINK
> attribute, which can confuse some userspace software that expects it.
> For example, if the last ifindex created in init_net and foo are both
> 8, these commands will trigger the issue:
>
> ip link add parent type dummy # ifindex 9
> ip link add link parent netns foo type macvlan # ifindex 9 in ns foo
>
> So, in case a device puts the IFLA_LINK_NETNSID attribute in a dump,
> always put the IFLA_LINK attribute as well.
>
> Thanks to Dan Winship for analyzing the original OpenShift bug down to
> the missing netlink attribute.
Good catch.
>
> Analyzed-by: Dan Winship <danw@redhat.com>
> Fixes: a54acb3a6f85 ("dev: introduce dev_get_iflink()")
I don't agree with the Fixes tag. The test 'iflink != ifindex' is here at least
since the beginning of the git history.
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] rtnetlink: always put ILFA_LINK for links with a link-netnsid
2019-05-13 13:17 ` Nicolas Dichtel
@ 2019-05-13 13:42 ` Sabrina Dubroca
0 siblings, 0 replies; 3+ messages in thread
From: Sabrina Dubroca @ 2019-05-13 13:42 UTC (permalink / raw)
To: Nicolas Dichtel; +Cc: netdev, Dan Winship
2019-05-13, 15:17:33 +0200, Nicolas Dichtel wrote:
> Le 13/05/2019 à 15:01, Sabrina Dubroca a écrit :
> > Currently, nla_put_iflink() doesn't put the IFLA_LINK attribute when
> > iflink == ifindex.
> >
> > In some cases, a device can be created in a different netns with the
> > same ifindex as its parent. That device will not dump its IFLA_LINK
> > attribute, which can confuse some userspace software that expects it.
> > For example, if the last ifindex created in init_net and foo are both
> > 8, these commands will trigger the issue:
> >
> > ip link add parent type dummy # ifindex 9
> > ip link add link parent netns foo type macvlan # ifindex 9 in ns foo
> >
> > So, in case a device puts the IFLA_LINK_NETNSID attribute in a dump,
> > always put the IFLA_LINK attribute as well.
> >
> > Thanks to Dan Winship for analyzing the original OpenShift bug down to
> > the missing netlink attribute.
> Good catch.
>
> >
> > Analyzed-by: Dan Winship <danw@redhat.com>
> > Fixes: a54acb3a6f85 ("dev: introduce dev_get_iflink()")
> I don't agree with the Fixes tag. The test 'iflink != ifindex' is here at least
> since the beginning of the git history.
Hmpf, right, now that I re-blamed, I see. I don't know why I stopped
on your patch, sorry.
> > Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
> Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Thanks!
I'll repost with a correct Fixes tag and your Ack.
--
Sabrina
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-13 13:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-13 13:01 [PATCH net] rtnetlink: always put ILFA_LINK for links with a link-netnsid Sabrina Dubroca
2019-05-13 13:17 ` Nicolas Dichtel
2019-05-13 13:42 ` Sabrina Dubroca
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).