From 5eea262a68603baa9f6dbdb56db6100dd80cdf5d Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 2 Oct 2019 13:34:40 +0200 Subject: [PATCH] zebra, lib: store relative default ns id in each namespace to be able to retrieve the network namespace identifier for each namespace, the ns id is stored in each ns context. For default namespace, the netns id is the same as that value. Signed-off-by: Philippe Guibert --- lib/ns.h | 5 +++++ lib/vrf.c | 8 ++++++-- lib/vrf.h | 2 +- zebra/zebra_netns_notify.c | 4 +++- zebra/zebra_ns.c | 4 ++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/ns.h b/lib/ns.h index c594cbfac9..188161e11a 100644 --- a/lib/ns.h +++ b/lib/ns.h @@ -53,6 +53,11 @@ struct ns { /* Identifier, mapped on the NSID value */ ns_id_t internal_ns_id; + /* Identifier, value of NSID of default netns, + * relative value in that local netns + */ + ns_id_t relative_default_ns; + /* Name */ char *name; diff --git a/lib/vrf.c b/lib/vrf.c index 2a3ce2a315..20e08b03d8 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -653,7 +653,8 @@ int vrf_handler_create(struct vty *vty, const char *vrfname, } int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname, - ns_id_t ns_id, ns_id_t internal_ns_id) + ns_id_t ns_id, ns_id_t internal_ns_id, + ns_id_t rel_def_ns_id) { struct ns *ns = NULL; @@ -700,6 +701,7 @@ int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname, } ns = ns_get_created(ns, pathname, ns_id); ns->internal_ns_id = internal_ns_id; + ns->relative_default_ns = rel_def_ns_id; ns->vrf_ctxt = (void *)vrf; vrf->ns_ctxt = (void *)ns; /* update VRF netns NAME */ @@ -795,7 +797,9 @@ DEFUN_NOSH (vrf_netns, frr_with_privs(vrf_daemon_privs) { ret = vrf_netns_handler_create(vty, vrf, pathname, - NS_UNKNOWN, NS_UNKNOWN); + NS_UNKNOWN, + NS_UNKNOWN, + NS_UNKNOWN); } return ret; } diff --git a/lib/vrf.h b/lib/vrf.h index 83ed16b48e..a8514d74ed 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -315,7 +315,7 @@ extern int vrf_handler_create(struct vty *vty, const char *name, */ extern int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname, ns_id_t ext_ns_id, - ns_id_t ns_id); + ns_id_t ns_id, ns_id_t rel_def_ns_id); /* used internally to enable or disable VRF. * Notify a change in the VRF ID of the VRF diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index db620cf220..521053484c 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -109,7 +109,9 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name) } frr_with_privs(&zserv_privs) { ret = vrf_netns_handler_create(NULL, vrf, netnspath, - ns_id_external, ns_id); + ns_id_external, + ns_id, + ns_id_relative); } if (ret != CMD_SUCCESS) { flog_warn(EC_ZEBRA_NS_VRF_CREATION_FAILED, diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 4e23ca2f03..13864cd429 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -183,12 +183,16 @@ int zebra_ns_init(const char *optional_default_name) struct ns *default_ns; ns_id_t ns_id; ns_id_t ns_id_external; + struct ns *ns; frr_with_privs(&zserv_privs) { ns_id = zebra_ns_id_get_default(); } ns_id_external = ns_map_nsid_with_external(ns_id, true); ns_init_management(ns_id_external, ns_id); + ns = ns_get_default(); + if (ns) + ns->relative_default_ns = ns_id; default_ns = ns_lookup(ns_get_default_id()); if (!default_ns) { -- 2.39.5