summaryrefslogtreecommitdiff
path: root/lib/vrf.c
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2017-12-20 12:29:21 +0100
committerPhilippe Guibert <philippe.guibert@6wind.com>2018-02-27 11:11:24 +0100
commitce1be3692f809cfa4d533d484a75653f91c24c4e (patch)
treed6a151cb9d906b8e1f517b641fabd39b741ef3a0 /lib/vrf.c
parent4691b65ae4c3e50c295dce4fc007738080826b49 (diff)
lib: provide an API to switch from one netns to an other
Two apis are provided so that the switch from one netns to an other one is taken care. Also an other API to know if the VRF has a NETNS backend or a VRF Lite backend. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'lib/vrf.c')
-rw-r--r--lib/vrf.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/vrf.c b/lib/vrf.c
index 5b85effabd..7871052352 100644
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -86,6 +86,32 @@ static int vrf_name_compare(const struct vrf *a, const struct vrf *b)
return strcmp(a->name, b->name);
}
+int vrf_switch_to_netns(vrf_id_t vrf_id)
+{
+ char *name;
+ struct vrf *vrf = vrf_lookup_by_id(vrf_id);
+
+ /* VRF has no NETNS backend. silently ignore */
+ if (!vrf || vrf->data.l.netns_name[0] == '\0')
+ return 0;
+ /* VRF is default VRF. silently ignore */
+ if (vrf->vrf_id == VRF_DEFAULT)
+ return 0;
+ name = ns_netns_pathname(NULL, vrf->data.l.netns_name);
+ if (debug_vrf)
+ zlog_debug("VRF_SWITCH: %s(%u)", name, vrf->vrf_id);
+ return ns_switch_to_netns(name);
+}
+
+int vrf_switchback_to_initial(void)
+{
+ int ret = ns_switchback_to_initial();
+
+ if (ret == 0 && debug_vrf)
+ zlog_debug("VRF_SWITCHBACK");
+ return ret;
+}
+
/* return 1 if vrf can be enabled */
int vrf_update_vrf_id(vrf_id_t vrf_id, struct vrf *vrf)
{
@@ -509,6 +535,17 @@ int vrf_handler_create(struct vty *vty, const char *vrfname, struct vrf **vrf)
return CMD_SUCCESS;
}
+int vrf_is_mapped_on_netns(vrf_id_t vrf_id)
+{
+ struct vrf *vrf = vrf_lookup_by_id(vrf_id);
+
+ if (!vrf || vrf->data.l.netns_name[0] == '\0')
+ return 0;
+ if (vrf->vrf_id == VRF_DEFAULT)
+ return 0;
+ return 1;
+}
+
/* vrf CLI commands */
DEFUN_NOSH (vrf,
vrf_cmd,