Allow openvswitch to query ports in another netns.
Subsystems (3)
cover Allow openvswitch to query ports in another netns.
Today Open vSwitch users are moving internal ports to other namespaces and although packets are flowing OK, the userspace daemon can't find out basic information like if the port is UP or DOWN, for instance.
This patchset extends openvswitch API to retrieve the current netnsid of a port. It will be used by the userspace daemon to find out in which netns the port is located.
This patchset also extends the rtnetlink getlink call to accept and operate on a given netnsid. More details are available in each patch.
Jiri Benc (3):
net: export peernet2id_alloc
openvswitch: reliable interface indentification in port dumps
rtnetlink: use netnsid to query interface
include/uapi/linux/if_link.h | 1 + include/uapi/linux/openvswitch.h | 2 + net/core/net_namespace.c | 1 + net/core/rtnetlink.c | 103 ++++++++++++++++++++++++++++++++------- net/openvswitch/datapath.c | 47 +++++++++++++----- net/openvswitch/datapath.h | 4 +- net/openvswitch/dp_notify.c | 4 +- 7 files changed, 127 insertions(+), 35 deletions(-)
Signature · 1 line
2.13.6
PATCH 1/3 net: export peernet2id_alloc
From: Jiri Benc <[email protected]>
It will be used by openvswitch.
--- net/core/net_namespace.c | 1 + 1 file changed, 1 insertion(+)
net/core/net_namespace.c +1 -0
@@ -234,6 +234,7 @@ int peernet2id_alloc(struct net *net, struct net *peer)rtnl_net_notifyid (net,RTM_NEWNSID , id);return id; } +EXPORT_SYMBOL_GPL (peernet2id_alloc);/* This function returns, if assigned, the id of a peer netns. */ int peernet2id (struct net *net,struct net *peer)
Signature · 1 line
2.13.6
PATCH 2/3 openvswitch: reliable interface indentification in port dumps
In reply to Flavio LeitnerFrom: Jiri Benc <[email protected]>
This patch allows reliable identification of netdevice interfaces connected to openvswitch bridges. In particular, user space queries the netdev interfaces belonging to the ports for statistics, up/down state, etc. Datapath dump needs to provide enough information for the user space to be able to do that.
Currently, only interface names are returned. This is not sufficient, as openvswitch allows its ports to be in different name spaces and the interface name is valid only in its name space. What is needed and generally used in other netlink APIs, is the pair ifindex+netnsid.
The solution is addition of the ifindex+netnsid pair (or only ifindex if in the same name space) to vport get/dump operation.
On request side, ideally the ifindex+netnsid pair could be used to get/set/del the corresponding vport. This is not implemented by this patch and can be added later if needed.
--- include/uapi/linux/openvswitch.h | 2 ++ net/openvswitch/datapath.c | 47 +++++++++++++++++++++++++++++----------- net/openvswitch/datapath.h | 4 ++-- net/openvswitch/dp_notify.c | 4 ++-- 4 files changed, 40 insertions(+), 17 deletions(-)
include/uapi/linux/openvswitch.h +2 -0
@@ -257,6 +257,8 @@ enum ovs_vport_attr {/* receiving upcalls */ OVS_VPORT_ATTR_STATS ,/* struct ovs_vport_stats */ OVS_VPORT_ATTR_PAD , +OVS_VPORT_ATTR_IFINDEX , +OVS_VPORT_ATTR_NETNSID , __OVS_VPORT_ATTR_MAX };
net/openvswitch/datapath.c +34 -13
127 lines not on this page · raw message
net/openvswitch/datapath.h +2 -2
@@ -200,8 +200,8 @@ int ovs_dp_upcall(struct datapath *, struct sk_buff *, uint32_t cutlen);const char *ovs_dp_name (const struct datapath *dp); -struct sk_buff *ovs_vport_cmd_build_info (struct vport *,u32 pid,u32 seq, -u8 cmd); +struct sk_buff *ovs_vport_cmd_build_info (struct vport *vport,struct net *net, +u32 portid,u32 seq,u8 cmd);int ovs_execute_actions (struct datapath *dp,struct sk_buff *skb,const struct sw_flow_actions *,struct sw_flow_key *);
net/openvswitch/dp_notify.c +2 -2
@@ -30,8 +30,8 @@ static void dp_detach_port_notify(struct vport *vport)struct datapath *dp; dp = vport->dp; - notify =ovs_vport_cmd_build_info (vport,0 ,0 , -OVS_VPORT_CMD_DEL ); + notify =ovs_vport_cmd_build_info (vport,ovs_dp_get_net (dp), +0 ,0 ,OVS_VPORT_CMD_DEL );ovs_dp_detach_port (vport);if (IS_ERR (notify)) { genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
Signature · 1 line
2.13.6
PATCH 3/3 rtnetlink: use netnsid to query interface
In reply to Flavio LeitnerFrom: Jiri Benc <[email protected]>
Currently, when an application gets netnsid from the kernel (for example as the result of RTM_GETLINK call on one end of the veth pair), it's not much useful. There's no reliable way to get to the netns fd from the netnsid, nor does any kernel API accept netnsid.
Extend the RTM_GETLINK call to also accept netnsid. It will operate on the netns with the given netnsid in such case. Of course, the calling process needs to have enough capabilities in the target name space; for now, require CAP_NET_ADMIN. This can be relaxed in the future.
To signal to the calling process that the kernel understood the new IFLA_IF_NETNSID attribute in the query, it will include it in the response. This is needed to detect older kernels, as they will just ignore IFLA_IF_NETNSID and query in the current name space.
This patch implemetns IFLA_IF_NETNSID only for get and dump. For set operations, this can be extended later.
--- include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 103 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 86 insertions(+), 18 deletions(-)
include/uapi/linux/if_link.h +1 -0
@@ -159,6 +159,7 @@ enum {IFLA_XDP ,IFLA_EVENT ,IFLA_NEW_NETNSID , +IFLA_IF_NETNSID , __IFLA_MAX };
net/core/rtnetlink.c +85 -18
250 lines not on this page · raw message
Signature · 1 line
2.13.6
David Miller
maintainerFrom: Flavio Leitner <[email protected]>
Date: Thu, 2 Nov 2017 17:04:35 -0200
Quoted 10 lines
Today Open vSwitch users are moving internal ports to other namespaces and although packets are flowing OK, the userspace daemon can't find out basic information like if the port is UP or DOWN, for instance.
This patchset extends openvswitch API to retrieve the current netnsid of a port. It will be used by the userspace daemon to find out in which netns the port is located.
This patchset also extends the rtnetlink getlink call to accept and operate on a given netnsid. More details are available in each patch.
Series applied, thanks Flavio.