]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra, lib: store relative default ns id in each namespace
authorPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 2 Oct 2019 11:34:40 +0000 (13:34 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 21 Sep 2020 07:17:10 +0000 (09:17 +0200)
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 <philippe.guibert@6wind.com>
lib/ns.h
lib/vrf.c
lib/vrf.h
zebra/zebra_netns_notify.c
zebra/zebra_ns.c

index c594cbfac924ddf08d0faf6eb55408120d0b9398..188161e11a2b0862a30a79d8e6aa07809c4e6199 100644 (file)
--- 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;
 
index 2a3ce2a31515c802822228dbc6be8294988eadf4..20e08b03d848f32a796fd15cc821fc9db0b65700 100644 (file)
--- 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;
 }
index 83ed16b48e4e19678050236d555a45fec801e878..a8514d74ed9374f38589238cd3ce32d47d4b0bd4 100644 (file)
--- 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
index db620cf220e318cb3df2aaf879a712a1886b8588..521053484c7053cf60170d2704dd94c99ff5e31c 100644 (file)
@@ -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,
index 4e23ca2f03f0130232d4ad2b5e9b381e51c6c426..13864cd4296db00e022abd22cf89b909778c45ad 100644 (file)
@@ -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) {