#include "ns.h"
#include "log.h"
#include "memory.h"
-
#include "command.h"
#include "vty.h"
#include "vrf.h"
+#include "lib_errors.h"
DEFINE_MTYPE_STATIC(LIB, NS, "NetNS Context")
DEFINE_MTYPE_STATIC(LIB, NS_NAME, "NetNS Name")
}
if (!ns_is_enabled(ns)) {
- zlog_err("Can not enable NS %u: %s!", ns->ns_id,
- safe_strerror(errno));
+ flog_err_sys(EC_LIB_SYSTEM_CALL,
+ "Can not enable NS %u: %s!", ns->ns_id,
+ safe_strerror(errno));
return 0;
}
/* Non default NS. leave */
if (ns->ns_id == NS_UNKNOWN) {
- zlog_err("Can not enable NS %s %u: Invalid NSID",
+ flog_err(EC_LIB_NS,
+ "Can not enable NS %s %u: Invalid NSID",
ns->name, ns->ns_id);
return 0;
}
if (!result) {
if (vty)
- vty_out(vty, "Invalid pathname: %s\n",
+ vty_out(vty, "Invalid pathname for %s: %s\n",
+ pathname,
safe_strerror(errno));
else
- zlog_warn("Invalid pathname: %s", safe_strerror(errno));
+ flog_warn(EC_LIB_LINUX_NS,
+ "Invalid pathname for %s: %s", pathname,
+ safe_strerror(errno));
return NULL;
}
check_base = basename(pathname);
vty_out(vty, "NS name (%s) invalid: too long (>%d)\n",
check_base, NS_NAMSIZ - 1);
else
- zlog_warn("NS name (%s) invalid: too long (>%d)",
+ flog_warn(EC_LIB_LINUX_NS,
+ "NS name (%s) invalid: too long (>%d)",
check_base, NS_NAMSIZ - 1);
return NULL;
}
if (ns_initialised == 1)
return;
errno = 0;
-#ifdef HAVE_NETNS
- if (have_netns_enabled < 0) {
+ if (have_netns())
ns_default_ns_fd = open(NS_DEFAULT_NAME, O_RDONLY);
- if (ns_default_ns_fd == -1)
- zlog_err("NS initialization failure %d(%s)",
- errno, safe_strerror(errno));
- } else {
+ else {
ns_default_ns_fd = -1;
default_ns = NULL;
}
-#else
- ns_default_ns_fd = -1;
- default_ns = NULL;
-#endif /* HAVE_NETNS */
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__);
+ flog_err(EC_LIB_NS, "%s: failed to create the default NS!",
+ __func__);
exit(1);
}
if (have_netns()) {
/* Enable the default NS. */
if (!ns_enable(default_ns, NULL)) {
- zlog_err("%s: failed to enable the default NS!", __func__);
+ flog_err(EC_LIB_NS, "%s: failed to enable the default NS!",
+ __func__);
exit(1);
}
}