diff options
author | Philippe Guibert <philippe.guibert@6wind.com> | 2018-01-16 13:59:58 +0100 |
---|---|---|
committer | Philippe Guibert <philippe.guibert@6wind.com> | 2018-02-27 11:11:24 +0100 |
commit | ec31f30d28b65a4820a44ac658e677840ed6f88b (patch) | |
tree | 12d7828e18031db13e71f2fa0d5f8070246fb966 /zebra/zebra_netns_id.c | |
parent | zebra: collect and get netnamespaces information (diff) | |
download | frr-ec31f30d28b65a4820a44ac658e677840ed6f88b.tar.xz frr-ec31f30d28b65a4820a44ac658e677840ed6f88b.zip |
zebra: upon startup, a NSID is assigned to default netns
when the netns backend is selected for VRF, the default VRF is being
assigned a NSID. This avoids the need to handle the case where if the
incoming NSID was 0 for a non default VRF, then a specific handling had
to be done to keep 0 value for default VRF.
In most cases, as the first NETNS to get a NSID will be the default VRF,
most probably the default VRF will be assigned to 0, while the other
ones will have their value incremented. On some cases, where the NSID is
already assigned for NETNS, including default VRF, then the default VRF
value will be the one derived from the NSID of default VRF, thus keeping
consistency between VRF IDs and NETNS IDs.
Default NS is attempted to be created. Actually, some VMs may have the
netns feature, but the NS initialisation fails because that folder is
not present.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'zebra/zebra_netns_id.c')
-rw-r--r-- | zebra/zebra_netns_id.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/zebra/zebra_netns_id.c b/zebra/zebra_netns_id.c index c5e792bd7..966d6ed0d 100644 --- a/zebra/zebra_netns_id.c +++ b/zebra/zebra_netns_id.c @@ -20,6 +20,7 @@ #include <zebra.h> #include "ns.h" +#include "vrf.h" #include "log.h" #if defined(HAVE_NETLINK) @@ -35,6 +36,9 @@ #include "zebra_netns_id.h" +/* default NS ID value used when VRF backend is not NETNS */ +#define NS_DEFAULT_INTERNAL 0 + /* in case NEWNSID not available, the NSID will be locally obtained */ #define NS_BASE_NSID 0 @@ -312,3 +316,40 @@ ns_id_t zebra_ns_id_get(const char *netnspath) return zebra_ns_id_get_fallback(netnspath); } #endif /* ! defined(HAVE_NETLINK) */ + +#ifdef HAVE_NETNS +static void zebra_ns_create_netns_directory(void) +{ + /* check that /var/run/netns is created */ + /* S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH */ + if (mkdir(NS_RUN_DIR, 0755)) { + if (errno != EEXIST) { + zlog_warn("NS check: failed to access %s", NS_RUN_DIR); + return; + } + } +} +#endif + +ns_id_t zebra_ns_id_get_default(void) +{ +#ifdef HAVE_NETNS + int fd; +#endif /* !HAVE_NETNS */ + +#ifdef HAVE_NETNS + if (vrf_is_backend_netns()) + zebra_ns_create_netns_directory(); + fd = open(NS_DEFAULT_NAME, O_RDONLY); + + if (fd == -1) + return NS_DEFAULT_INTERNAL; + if (!vrf_is_backend_netns()) + return NS_DEFAULT_INTERNAL; + close(fd); + return zebra_ns_id_get((char *)NS_DEFAULT_NAME); +#else /* HAVE_NETNS */ + return NS_DEFAULT_INTERNAL; +#endif /* !HAVE_NETNS */ +} + |