From: Philippe Guibert Date: Fri, 8 Dec 2017 13:32:38 +0000 (+0100) Subject: zebra: handle the zns init/destroy X-Git-Tag: frr-5.0-dev~209^2~30 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=ff705b15dd5e191e727662412a8433d718887a08;p=matthieu%2Ffrr.git zebra: handle the zns init/destroy 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 --- diff --git a/lib/ns.c b/lib/ns.c index 1929104eeb..5e6bddf0d8 100644 --- 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) { diff --git a/lib/ns.h b/lib/ns.h index 590e1f2c20..6aebc44259 100644 --- 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*/ diff --git a/zebra/main.c b/zebra/main.c index a881fcb9c6..73e5f1290d 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -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(); diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 6ce64b3a33..02fc2b1844 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -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; } diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index aaf5abaa26..3a998a49ff 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -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,