]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: handle the zns init/destroy
authorPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 8 Dec 2017 13:32:38 +0000 (14:32 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 27 Feb 2018 10:11:24 +0000 (11:11 +0100)
The zebra netnamespace contexts are initialised, based on the callback
coming from the NS. Reversely, the list of ns is parsed to disable the
ns contexts.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
lib/ns.c
lib/ns.h
zebra/main.c
zebra/zebra_ns.c
zebra/zebra_ns.h

index 1929104eebc05d5e6160ce048f818419b3f6bf44..5e6bddf0d8d71ec18cda559a61342441cc23459f 100644 (file)
--- a/lib/ns.c
+++ b/lib/ns.c
@@ -201,6 +201,23 @@ static struct ns *ns_lookup(ns_id_t ns_id)
        return (RB_FIND(ns_head, &ns_tree, &ns));
 }
 
+/* Look up the data pointer of the specified VRF. */
+void *
+ns_info_lookup(ns_id_t ns_id)
+{
+       struct ns *ns = ns_lookup(ns_id);
+
+       return ns ? ns->info : NULL;
+}
+
+void ns_walk_func(int (*func)(struct ns *))
+{
+       struct ns *ns = NULL;
+
+       RB_FOREACH(ns, ns_head, &ns_tree)
+               func(ns);
+}
+
 /* Look up a NS by name */
 static struct ns *ns_lookup_name(const char *name)
 {
index 590e1f2c20e026ecda779e249d7a1e55adc213b8..6aebc442595ba71bdcb165b48ed9bb63cede20d9 100644 (file)
--- a/lib/ns.h
+++ b/lib/ns.h
@@ -97,5 +97,7 @@ extern void ns_cmd_init(void);
 extern int ns_handler_create(struct vty *vty, struct vrf *vrf,
                             char *pathname, ns_id_t ns_id);
 extern char *ns_netns_pathname(struct vty *vty, const char *name);
+extern void *ns_info_lookup(ns_id_t ns_id);
+extern void ns_walk_func(int (*func)(struct ns *));
 
 #endif /*_ZEBRA_NS_H*/
index a881fcb9c6e50e8831f2f2a00082f7beb7346045..73e5f1290d9bfcc49415b778fc4d74e56ee08323 100644 (file)
@@ -123,7 +123,6 @@ static void sigint(void)
 {
        struct vrf *vrf;
        struct zebra_vrf *zvrf;
-       struct zebra_ns *zns;
 
        zlog_notice("Terminating on signal");
 
@@ -140,8 +139,7 @@ static void sigint(void)
                }
        vrf_terminate();
 
-       zns = zebra_ns_lookup(NS_DEFAULT);
-       zebra_ns_disable(0, (void **)&zns);
+       ns_walk_func(zebra_ns_disabled);
 
        access_list_reset();
        prefix_list_reset();
index 6ce64b3a33bf618183db130a5481765a89a8737c..02fc2b18443f39b3e4cbe5c9503c650ddf1042c8 100644 (file)
@@ -57,7 +57,11 @@ zebra_ns_table_entry_compare(const struct zebra_ns_table *e1,
 
 struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id)
 {
-       return dzns;
+       if (ns_id == NS_DEFAULT)
+               return dzns;
+       struct zebra_ns *info = (struct zebra_ns *)ns_info_lookup(ns_id);
+
+       return (info == NULL) ? dzns : info;
 }
 
 static struct zebra_ns *zebra_ns_alloc(void)
@@ -75,6 +79,11 @@ static int zebra_ns_new(struct ns *ns)
        zns = zebra_ns_alloc();
        ns->info = zns;
        zns->ns = ns;
+
+       /* Do any needed per-NS data structure allocation. */
+       zns->if_table = route_table_init();
+       zebra_vxlan_ns_init(zns);
+
        return 0;
 }
 
@@ -101,7 +110,7 @@ static int zebra_ns_enabled(struct ns *ns)
        return zebra_ns_enable(ns->ns_id, (void **)&zns);
 }
 
-static int zebra_ns_disabled(struct ns *ns)
+int zebra_ns_disabled(struct ns *ns)
 {
        struct zebra_ns *zns = ns->info;
 
@@ -117,6 +126,8 @@ int zebra_ns_enable(ns_id_t ns_id, void **info)
 {
        struct zebra_ns *zns = (struct zebra_ns *)(*info);
 
+       zns->ns_id = ns_id;
+
 #if defined(HAVE_RTADV)
        rtadv_init(zns);
 #endif
@@ -209,6 +220,8 @@ int zebra_ns_disable(ns_id_t ns_id, void **info)
 
        kernel_terminate(zns);
 
+       zns->ns_id = NS_DEFAULT;
+
        return 0;
 }
 
index aaf5abaa2642b5e8b2e086d6aef8e9b8edb99c09..3a998a49ff54b5a26e1d2670c6a8eb524944cde2 100644 (file)
@@ -78,6 +78,7 @@ struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id);
 
 int zebra_ns_init(void);
 int zebra_ns_enable(ns_id_t ns_id, void **info);
+int zebra_ns_disabled(struct ns *ns);
 int zebra_ns_disable(ns_id_t ns_id, void **info);
 
 extern struct route_table *zebra_ns_find_table(struct zebra_ns *zns,