From b7b816df6bd8b110aedb0f047fa8e3105ce86d1d Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Fri, 16 Feb 2018 18:22:34 +0100 Subject: [PATCH] zebra: prevent from discovering a NS with same NSID as previous one This limitation ignores the creation of a new NS context, when an already present NS is available with the same NSID. This limitation removes confusion, so that only the first NS will be used for configuration. Signed-off-by: Philippe Guibert --- zebra/zebra_netns_notify.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index b28998acf8..b98d6ed703 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -75,15 +75,22 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name) if (netnspath == NULL) return; - if (vrf_handler_create(NULL, name, &vrf) != CMD_SUCCESS) { - zlog_warn("NS notify : failed to create VRF %s", name); - return; - } if (zserv_privs.change(ZPRIVS_RAISE)) zlog_err("Can't raise privileges"); ns_id = zebra_ns_id_get(netnspath); if (zserv_privs.change(ZPRIVS_LOWER)) zlog_err("Can't lower privileges"); + /* if VRF with NS ID already present */ + vrf = vrf_lookup_by_id((vrf_id_t)ns_id); + if (vrf) { + zlog_warn("NS notify : same NSID used by VRF %s. Ignore NS %s creation", + vrf->name, netnspath); + return; + } + if (vrf_handler_create(NULL, name, &vrf) != CMD_SUCCESS) { + zlog_warn("NS notify : failed to create VRF %s", name); + return; + } ret = vrf_netns_handler_create(NULL, vrf, netnspath, ns_id); if (ret != CMD_SUCCESS) { zlog_warn("NS notify : failed to create NS %s", netnspath); -- 2.39.5