DEFINE_MTYPE_STATIC(LIB, NS, "NetNS Context")
DEFINE_MTYPE_STATIC(LIB, NS_NAME, "NetNS Name")
+/* default NS ID value used when VRF backend is not NETNS */
+#define NS_DEFAULT_INTERNAL 0
+
static inline int ns_compare(const struct ns *ns, const struct ns *ns2);
static struct ns *ns_lookup_name_internal(const char *name);
zlog_info("NS %s is created.", ns->name);
}
if (ns_master.ns_new_hook)
- (*ns_master.ns_new_hook) (ns);
+ (*ns_master.ns_new_hook)(ns);
return ns;
}
{
if (ns_is_enabled(ns)) {
if (ns_debug)
- zlog_info("NS %u is to be disabled.",
- ns->ns_id);
+ zlog_info("NS %u is to be disabled.", ns->ns_id);
if (ns_master.ns_disable_hook)
(*ns_master.ns_disable_hook)(ns);
}
/* Look up the data pointer of the specified VRF. */
-void *
-ns_info_lookup(ns_id_t ns_id)
+void *ns_info_lookup(ns_id_t ns_id)
{
struct ns *ns = ns_lookup_internal(ns_id);
vty_out(vty, "Invalid pathname: %s\n",
safe_strerror(errno));
else
- zlog_warn("Invalid pathname: %s",
- safe_strerror(errno));
+ zlog_warn("Invalid pathname: %s", safe_strerror(errno));
return NULL;
}
check_base = basename(pathname);
if (check_base != NULL && strlen(check_base) + 1 > NS_NAMSIZ) {
if (vty)
vty_out(vty, "NS name (%s) invalid: too long (>%d)\n",
- check_base, NS_NAMSIZ-1);
+ check_base, NS_NAMSIZ - 1);
else
zlog_warn("NS name (%s) invalid: too long (>%d)",
- check_base, NS_NAMSIZ-1);
+ check_base, NS_NAMSIZ - 1);
return NULL;
}
return pathname;
return;
errno = 0;
#ifdef HAVE_NETNS
- if (have_netns_enabled < 0)
+ if (have_netns_enabled < 0) {
ns_default_ns_fd = open(NS_DEFAULT_NAME, O_RDONLY);
- else
+ if (ns_default_ns_fd == -1)
+ zlog_err("NS initialization failure %d(%s)",
+ errno, safe_strerror(errno));
+ } else {
ns_default_ns_fd = -1;
+ default_ns = NULL;
+ }
#else
ns_default_ns_fd = -1;
default_ns = NULL;
#endif /* HAVE_NETNS */
- if (ns_default_ns_fd == -1)
- zlog_err("NS initialisation failure (%s)",
- safe_strerror(errno));
ns_current_ns_fd = -1;
ns_initialised = 1;
}
ns_init();
default_ns = ns_get_created_internal(NULL, NULL, default_ns_id);
if (!default_ns) {
- zlog_err("%s: failed to create the default NS!",
- __func__);
+ zlog_err("%s: failed to create the default NS!", __func__);
exit(1);
}
if (have_netns()) {
/* Set the default NS name. */
default_ns->name = XSTRDUP(MTYPE_NS_NAME, NS_DEFAULT_NAME);
if (ns_debug)
- zlog_info("%s: default NSID is %u",
- __func__, default_ns->ns_id);
+ zlog_info("%s: default NSID is %u", __func__,
+ default_ns->ns_id);
/* Enable the default NS. */
if (!ns_enable(default_ns, NULL)) {
- zlog_err("%s: failed to enable the default NS!",
- __func__);
+ zlog_err("%s: failed to enable the default NS!", __func__);
exit(1);
}
}
{
if (default_ns)
return default_ns->ns_id;
- return NS_UNKNOWN;
+ return NS_DEFAULT_INTERNAL;
}
-