From edbc33221c34c2ef2fb942ea8202a85a0c148bf7 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Fri, 21 Dec 2018 16:25:20 +0100 Subject: [PATCH] zebra: start the netns notification mechanism after ns initialisation when zebra is run, by using vrf netns backend mode, then the parser detector of netns is run before forcing the default vrf to a possible value. In that case, there is a possibility that the forced '-o' option will create a second vrf with same name, whereas this option should be there to uniquely have a default vrf with a value. To make things consistent, the forced value will be priorised. Then, the notifier will attempt to create vrf contexts. The expectation is that the creation will fail, due to an already present vrf with same name. Signed-off-by: Philippe Guibert --- zebra/main.c | 5 +---- zebra/zebra_ns.c | 6 +++++- zebra/zebra_ns.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/zebra/main.c b/zebra/main.c index 90d3dbc18..b54c36c10 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -407,10 +407,7 @@ int main(int argc, char **argv) /* * Initialize NS( and implicitly the VRF module), and make kernel * routing socket. */ - zebra_ns_init(); - if (vrf_default_name_configured) - vrf_set_default_name(vrf_default_name_configured, - true); + zebra_ns_init((const char *)vrf_default_name_configured); zebra_vty_init(); access_list_init(); prefix_list_init(); diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 03987fcb5..0c743d867 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -183,7 +183,7 @@ int zebra_ns_final_shutdown(struct ns *ns) return 0; } -int zebra_ns_init(void) +int zebra_ns_init(const char *optional_default_name) { ns_id_t ns_id; ns_id_t ns_id_external; @@ -207,6 +207,10 @@ int zebra_ns_init(void) /* Default NS is activated */ zebra_ns_enable(ns_id_external, (void **)&dzns); + if (optional_default_name) + vrf_set_default_name(optional_default_name, + true); + if (vrf_is_backend_netns()) { ns_add_hook(NS_NEW_HOOK, zebra_ns_new); ns_add_hook(NS_ENABLE_HOOK, zebra_ns_enabled); diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index d3592f8f3..01af64c17 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -60,7 +60,7 @@ struct zebra_ns { struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id); -int zebra_ns_init(void); +int zebra_ns_init(const char *optional_default_name); int zebra_ns_enable(ns_id_t ns_id, void **info); int zebra_ns_disabled(struct ns *ns); int zebra_ns_early_shutdown(struct ns *ns); -- 2.39.2