#include <sched.h>
#endif
+/* for basename */
+#include <libgen.h>
+
#include "if.h"
#include "ns.h"
#include "log.h"
{
static char pathname[PATH_MAX];
char *result;
+ char *check_base;
if (name[0] == '/') /* absolute pathname */
result = realpath(name, pathname);
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;
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",
}
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",
#include <zebra.h>
+/* for basename */
+#include <libgen.h>
+
#include "if.h"
#include "vrf.h"
#include "vrf_int.h"
if (vrf == NULL) {
vrf = XCALLOC(MTYPE_VRF, sizeof(struct vrf));
vrf->vrf_id = VRF_UNKNOWN;
- RB_INIT(if_name_head, &vrf->ifaces_by_name);
- RB_INIT(if_index_head, &vrf->ifaces_by_index);
QOBJ_REG(vrf, vrf);
new = 1;
strlcpy(vrf->name, name, sizeof(vrf->name));
RB_INSERT(vrf_name_head, &vrfs_by_name, vrf);
}
-
if (new &&vrf_master.vrf_new_hook)
(*vrf_master.vrf_new_hook)(vrf);
#endif
#define VRF_NAMSIZ 36
+#define NS_NAMSIZ 16
#define VRF_DEFAULT_NAME "Default-IP-Routing-Table"
union {
struct {
uint32_t table_id;
+ char netns_name[NS_NAMSIZ];
} l;
};
};
/* Lookup/create vrf by vrf_id. */
vrf = vrf_get(vrf_id, vrfname_tmp);
- vrf->data = data;
-
+ vrf->data.l.table_id = data.l.table_id;
+ memcpy(vrf->data.l.netns_name, data.l.netns_name, NS_NAMSIZ);
vrf_enable(vrf);
}
struct vrf *vrf;
RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
- if (vrf->vrf_id)
+ if (vrf->vrf_id != VRF_UNKNOWN)
zsend_vrf_add(client, vrf_info_lookup(vrf->vrf_id));
}
}
#include <zebra.h>
#include <sys/un.h>
+/* for basename */
+#include <libgen.h>
#include "prefix.h"
#include "command.h"
static void zserv_encode_vrf(struct stream *s, struct zebra_vrf *zvrf)
{
struct vrf_data data;
+ const char *netns_name = zvrf_ns_name(zvrf);
data.l.table_id = zvrf->table_id;
- /* Pass the tableid */
+
+ if (netns_name)
+ strlcpy(data.l.netns_name,
+ basename((char *)netns_name), NS_NAMSIZ);
+ else
+ memset(data.l.netns_name, 0, NS_NAMSIZ);
+ /* Pass the tableid and the netns NAME */
stream_put(s, &data, sizeof(struct vrf_data));
/* Interface information. */
stream_put(s, zvrf_name(zvrf), VRF_NAMSIZ);
-
/* Write packet size. */
stream_putw_at(s, 0, stream_get_endp(s));
}