Recent kernels provide the network namespace ID of a port, so use that to discover where the port currently is.
Signed-off-by: Flavio Leitner <f...@redhat.com> --- datapath/linux/compat/include/linux/openvswitch.h | 2 ++ lib/dpif-netlink.c | 6 ++++++ lib/dpif-netlink.h | 2 ++ lib/netdev-linux.c | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/datapath/linux/compat/include/linux/openvswitch.h b/datapath/linux/compat/include/linux/openvswitch.h index bc6c94b8d..d2712d05f 100644 --- a/datapath/linux/compat/include/linux/openvswitch.h +++ b/datapath/linux/compat/include/linux/openvswitch.h @@ -283,6 +283,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 }; diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index fd333094d..b85e74c50 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -3065,6 +3065,7 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, [OVS_VPORT_ATTR_STATS] = { NL_POLICY_FOR(struct ovs_vport_stats), .optional = true }, [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = true }, + [OVS_VPORT_ATTR_NETNSID] = { .type = NL_A_U32, .optional = true }, }; dpif_netlink_vport_init(vport); @@ -3100,6 +3101,11 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, vport->options = nl_attr_get(a[OVS_VPORT_ATTR_OPTIONS]); vport->options_len = nl_attr_get_size(a[OVS_VPORT_ATTR_OPTIONS]); } + if (a[OVS_VPORT_ATTR_NETNSID]) { + netns_set_id(&vport->netns, nl_attr_get_u32(a[OVS_VPORT_ATTR_NETNSID])); + } else { + netns_set_local(&vport->netns); + } return 0; } diff --git a/lib/dpif-netlink.h b/lib/dpif-netlink.h index 568b81441..680a74c2f 100644 --- a/lib/dpif-netlink.h +++ b/lib/dpif-netlink.h @@ -21,6 +21,7 @@ #include <stddef.h> #include <stdint.h> #include "odp-netlink.h" +#include "netns.h" #include "flow.h" @@ -32,6 +33,7 @@ struct dpif_netlink_vport { /* ovs_vport header. */ int dp_ifindex; + struct netns netns; odp_port_t port_no; /* ODPP_NONE if unknown. */ enum ovs_vport_type type; diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index c31334ce1..fd181272b 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -476,6 +476,7 @@ struct netdev_linux { long long int miimon_interval; /* Miimon Poll rate. Disabled if <= 0. */ struct timer miimon_timer; + struct netns netns; /* network namespace. */ /* The following are figured out "on demand" only. They are only valid * when the corresponding VALID_* bit in 'cache_valid' is set. */ int ifindex; @@ -571,6 +572,25 @@ netdev_rxq_linux_cast(const struct netdev_rxq *rx) return CONTAINER_OF(rx, struct netdev_rxq_linux, up); } +static int +netdev_linux_netns_update(struct netdev_linux *netdev) +{ + struct netns *dev_netns = &netdev->netns; + struct dpif_netlink_vport reply; + struct ofpbuf *buf; + int error; + + error = dpif_netlink_vport_get(netdev_get_name(&netdev->up), &reply, &buf); + if (error) { + netns_set_invalid(dev_netns); + return error; + } + + netns_copy(dev_netns, &reply.netns); + ofpbuf_delete(buf); + return 0; +} + static void netdev_linux_update(struct netdev_linux *netdev, const struct rtnetlink_change *) OVS_REQUIRES(netdev->mutex); -- 2.13.6 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev