diff --git a/zebra/zebra_errors.c b/zebra/zebra_errors.c index 5a0905d59115..ef792d14c285 100644 --- a/zebra/zebra_errors.c +++ b/zebra/zebra_errors.c @@ -316,6 +316,12 @@ static struct log_ref ferr_zebra_err[] = { .description = "Zebra attempted to look up a interface for a particular vrf_id and interface index, but didn't find anything.", .suggestion = "If you entered a command to trigger this error, make sure you entered the arguments correctly. Check your config file for any potential errors. If these look correct, seek help.", }, + { + .code = EC_ZEBRA_NS_NO_DEFAULT, + .title = "Zebra NameSpace failed to find Default", + .description = "Zebra NameSpace subsystem failed to find a Default namespace during initialization.", + .suggestion = "Open an Issue with all relevant log files and restart FRR", + }, /* Warnings */ { .code = EC_ZEBRAING_LM_PROTO_MISMATCH, diff --git a/zebra/zebra_errors.h b/zebra/zebra_errors.h index f9ccc2db282d..4625a03ae644 100644 --- a/zebra/zebra_errors.h +++ b/zebra/zebra_errors.h @@ -76,6 +76,7 @@ enum zebra_log_refs { EC_ZEBRA_NHG_SYNC, EC_ZEBRA_NHG_FIB_UPDATE, EC_ZEBRA_IF_LOOKUP_FAILED, + EC_ZEBRA_NS_NO_DEFAULT, /* warnings */ EC_ZEBRA_NS_NOTIFY_READ, EC_ZEBRAING_LM_PROTO_MISMATCH, diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 37f53bf91187..4d971cc24f10 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -37,6 +37,7 @@ #include "zebra_pbr.h" #include "rib.h" #include "table_manager.h" +#include "zebra_errors.h" extern struct zebra_privs_t zserv_privs; @@ -64,6 +65,9 @@ static int zebra_ns_new(struct ns *ns) { struct zebra_ns *zns; + if (!ns) + return -1; + if (IS_ZEBRA_DEBUG_EVENT) zlog_info("ZNS %s with id %u (created)", ns->name, ns->ns_id); @@ -175,19 +179,26 @@ int zebra_ns_final_shutdown(struct ns *ns) int zebra_ns_init(const char *optional_default_name) { + struct ns *default_ns; ns_id_t ns_id; ns_id_t ns_id_external; - dzns = zebra_ns_alloc(); - frr_with_privs(&zserv_privs) { ns_id = zebra_ns_id_get_default(); } ns_id_external = ns_map_nsid_with_external(ns_id, true); ns_init_management(ns_id_external, ns_id); + default_ns = ns_lookup(ns_get_default_id()); + if (!default_ns) { + flog_err(EC_ZEBRA_NS_NO_DEFAULT, + "%s: failed to find default ns", __func__); + exit(EXIT_FAILURE); /* This is non-recoverable */ + } + /* Do any needed per-NS data structure allocation. */ - dzns->if_table = route_table_init(); + zebra_ns_new(default_ns); + dzns = default_ns->info; /* Register zebra VRF callbacks, create and activate default VRF. */ zebra_vrf_init();