Skip to content

Commit d37512a

Browse files
NicolasDichteldavem330
authored andcommitted
rtnl: add link netns id to interface messages
This patch adds a new attribute (IFLA_LINK_NETNSID) which contains the 'link' netns id when this netns is different from the netns where the interface stands (for example for x-net interfaces like ip tunnels). With this attribute, it's possible to interpret correctly all advertised information (like IFLA_LINK, etc.). Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0c7aecd commit d37512a

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

include/net/rtnetlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
4646
* to create when creating a new device.
4747
* @get_num_rx_queues: Function to determine number of receive queues
4848
* to create when creating a new device.
49+
* @get_link_net: Function to get the i/o netns of the device
4950
*/
5051
struct rtnl_link_ops {
5152
struct list_head list;
@@ -93,6 +94,7 @@ struct rtnl_link_ops {
9394
int (*fill_slave_info)(struct sk_buff *skb,
9495
const struct net_device *dev,
9596
const struct net_device *slave_dev);
97+
struct net *(*get_link_net)(const struct net_device *dev);
9698
};
9799

98100
int __rtnl_link_register(struct rtnl_link_ops *ops);

include/uapi/linux/if_link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ enum {
146146
IFLA_PHYS_PORT_ID,
147147
IFLA_CARRIER_CHANGES,
148148
IFLA_PHYS_SWITCH_ID,
149+
IFLA_LINK_NETNSID,
149150
__IFLA_MAX
150151
};
151152

net/core/rtnetlink.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
875875
+ nla_total_size(1) /* IFLA_OPERSTATE */
876876
+ nla_total_size(1) /* IFLA_LINKMODE */
877877
+ nla_total_size(4) /* IFLA_CARRIER_CHANGES */
878+
+ nla_total_size(4) /* IFLA_LINK_NETNSID */
878879
+ nla_total_size(ext_filter_mask
879880
& RTEXT_FILTER_VF ? 4 : 0) /* IFLA_NUM_VF */
880881
+ rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
@@ -1169,6 +1170,18 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
11691170
goto nla_put_failure;
11701171
}
11711172

1173+
if (dev->rtnl_link_ops &&
1174+
dev->rtnl_link_ops->get_link_net) {
1175+
struct net *link_net = dev->rtnl_link_ops->get_link_net(dev);
1176+
1177+
if (!net_eq(dev_net(dev), link_net)) {
1178+
int id = peernet2id(dev_net(dev), link_net);
1179+
1180+
if (nla_put_s32(skb, IFLA_LINK_NETNSID, id))
1181+
goto nla_put_failure;
1182+
}
1183+
}
1184+
11721185
if (!(af_spec = nla_nest_start(skb, IFLA_AF_SPEC)))
11731186
goto nla_put_failure;
11741187

0 commit comments

Comments
 (0)