diff options
author | Philippe Guibert <philippe.guibert@6wind.com> | 2017-12-08 14:32:38 +0100 |
---|---|---|
committer | Philippe Guibert <philippe.guibert@6wind.com> | 2018-02-27 11:11:24 +0100 |
commit | ff705b15dd5e191e727662412a8433d718887a08 (patch) | |
tree | c24cded67abdfb4af873cc13303c2274d13feb53 | |
parent | zebra: add the registration mechanism for netns (diff) | |
download | frr-ff705b15dd5e191e727662412a8433d718887a08.tar.xz frr-ff705b15dd5e191e727662412a8433d718887a08.zip |
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 <philippe.guibert@6wind.com>
-rw-r--r-- | lib/ns.c | 17 | ||||
-rw-r--r-- | lib/ns.h | 2 | ||||
-rw-r--r-- | zebra/main.c | 4 | ||||
-rw-r--r-- | zebra/zebra_ns.c | 17 | ||||
-rw-r--r-- | zebra/zebra_ns.h | 1 |
5 files changed, 36 insertions, 5 deletions
@@ -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) { @@ -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 a881fcb9c..73e5f1290 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 6ce64b3a3..02fc2b184 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 aaf5abaa2..3a998a49f 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, |