summaryrefslogtreecommitdiff
path: root/lib/ns.c
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2017-12-22 16:02:51 +0100
committerPhilippe Guibert <philippe.guibert@6wind.com>2018-02-27 11:11:24 +0100
commit4691b65ae4c3e50c295dce4fc007738080826b49 (patch)
tree80ed778117ec0305a8fb67cd4b0eeb3b09b197b8 /lib/ns.c
parent81c9005ff6edd2294ec945b93d49f03470b3b827 (diff)
lib: add namespace name structure in zebra message
The addition of the name of the netns in the vrf message introduces also a limitation when the size of the netns is bigger than 15 bytes. Then the netns are ignored by the library. In addition to this, some sanity checks have been introduced. some functions to create the netns from a call not coming from the vty is being added with traces. Also, the ns vty function is reentrant, if the context is already created. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com> Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/ns.c')
-rw-r--r--lib/ns.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/ns.c b/lib/ns.c
index 5af896632c..e2c042d16c 100644
--- a/lib/ns.c
+++ b/lib/ns.c
@@ -28,6 +28,9 @@
#include <sched.h>
#endif
+/* for basename */
+#include <libgen.h>
+
#include "if.h"
#include "ns.h"
#include "log.h"
@@ -353,6 +356,7 @@ char *ns_netns_pathname(struct vty *vty, const char *name)
{
static char pathname[PATH_MAX];
char *result;
+ char *check_base;
if (name[0] == '/') /* absolute pathname */
result = realpath(name, pathname);
@@ -367,6 +371,21 @@ char *ns_netns_pathname(struct vty *vty, const char *name)
if (vty)
vty_out(vty, "Invalid pathname: %s\n",
safe_strerror(errno));
+ else
+ 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 needed)\n",
+ check_base, NS_NAMSIZ-1);
+ else
+ zlog_warn("NS name (%s) invalid:"
+ " too long ( %d needed)",
+ check_base, NS_NAMSIZ-1);
return NULL;
}
return pathname;
@@ -489,6 +508,8 @@ int ns_handler_create(struct vty *vty, struct vrf *vrf,
if (ns && ns->vrf_ctxt) {
struct vrf *vrf2 = (struct vrf *)ns->vrf_ctxt;
+ if (vrf2 == vrf)
+ return CMD_SUCCESS;
if (vty)
vty_out(vty, "NS %s is already configured"
" with VRF %u(%s)\n",
@@ -507,6 +528,10 @@ int ns_handler_create(struct vty *vty, struct vrf *vrf,
}
ns->vrf_ctxt = (void *)vrf;
vrf->ns_ctxt = (void *)ns;
+ /* update VRF netns NAME */
+ if (vrf)
+ strlcpy(vrf->data.l.netns_name, basename(pathname), NS_NAMSIZ);
+
if (!ns_enable(ns)) {
if (vty)
vty_out(vty, "Can not associate NS %u with NETNS %s\n",