summaryrefslogtreecommitdiff
path: root/zebra/zebra_ns.c
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2017-12-07 18:27:31 +0100
committerPhilippe Guibert <philippe.guibert@6wind.com>2018-02-27 11:11:24 +0100
commit3347430b12ecccc4f03fb29111e9621a6e123b3c (patch)
treed3a7ce58f828c05cfb32d84f6342c59618932cf7 /zebra/zebra_ns.c
parent697d3ec73157fde8a008738907fef94fdcd569bb (diff)
zebra: add the registration mechanism for netns
If vrf backend is netns, then the zebra will create its own zebra_ns context for each new netns discovered. As consequence, a routing table, and other contexts will be created for each new namespace discovered. When it is enabled, a populate process will be done, consisting in learning new interfaces and routes, and addresses from other NETNS. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'zebra/zebra_ns.c')
-rw-r--r--zebra/zebra_ns.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c
index 80847518a7..6ce64b3a33 100644
--- a/zebra/zebra_ns.c
+++ b/zebra/zebra_ns.c
@@ -32,6 +32,7 @@
#include "zebra_memory.h"
#include "rt.h"
#include "zebra_vxlan.h"
+#include "debug.h"
DEFINE_MTYPE(ZEBRA, ZEBRA_NS, "Zebra Name Space")
@@ -59,6 +60,58 @@ struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id)
return dzns;
}
+static struct zebra_ns *zebra_ns_alloc(void)
+{
+ return XCALLOC(MTYPE_ZEBRA_NS, sizeof(struct zebra_ns));
+}
+
+static int zebra_ns_new(struct ns *ns)
+{
+ struct zebra_ns *zns;
+
+ if (IS_ZEBRA_DEBUG_EVENT)
+ zlog_info("ZNS %s with id %u (created)", ns->name, ns->ns_id);
+
+ zns = zebra_ns_alloc();
+ ns->info = zns;
+ zns->ns = ns;
+ return 0;
+}
+
+static int zebra_ns_delete(struct ns *ns)
+{
+ struct zebra_ns *zns = (struct zebra_ns *) ns->info;
+
+ if (IS_ZEBRA_DEBUG_EVENT)
+ zlog_info("ZNS %s with id %u (deleted)", ns->name, ns->ns_id);
+ if (!zns)
+ return 0;
+ XFREE(MTYPE_ZEBRA_NS, zns);
+ return 0;
+}
+
+static int zebra_ns_enabled(struct ns *ns)
+{
+ struct zebra_ns *zns = ns->info;
+
+ if (IS_ZEBRA_DEBUG_EVENT)
+ zlog_info("ZNS %s with id %u (enabled)", ns->name, ns->ns_id);
+ if (!zns)
+ return 0;
+ return zebra_ns_enable(ns->ns_id, (void **)&zns);
+}
+
+static int zebra_ns_disabled(struct ns *ns)
+{
+ struct zebra_ns *zns = ns->info;
+
+ if (IS_ZEBRA_DEBUG_EVENT)
+ zlog_info("ZNS %s with id %u (disabled)", ns->name, ns->ns_id);
+ if (!zns)
+ return 0;
+ return zebra_ns_disable(ns->ns_id, (void **)&zns);
+}
+
/* Do global enable actions - open sockets, read kernel config etc. */
int zebra_ns_enable(ns_id_t ns_id, void **info)
{
@@ -162,7 +215,9 @@ int zebra_ns_disable(ns_id_t ns_id, void **info)
int zebra_ns_init(void)
{
- dzns = XCALLOC(MTYPE_ZEBRA_NS, sizeof(struct zebra_ns));
+ dzns = zebra_ns_alloc();
+
+ ns_init_zebra();
ns_init();
@@ -176,6 +231,12 @@ int zebra_ns_init(void)
/* Default NS is activated */
zebra_ns_enable(NS_DEFAULT, (void **)&dzns);
+ if (vrf_is_backend_netns()) {
+ ns_add_hook(NS_NEW_HOOK, zebra_ns_new);
+ ns_add_hook(NS_ENABLE_HOOK, zebra_ns_enabled);
+ ns_add_hook(NS_DISABLE_HOOK, zebra_ns_disabled);
+ ns_add_hook(NS_DELETE_HOOK, zebra_ns_delete);
+ }
return 0;
}