summaryrefslogtreecommitdiff
path: root/lib/vrf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vrf.c')
-rw-r--r--lib/vrf.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/vrf.c b/lib/vrf.c
index c4e527db5b..d5cff4e2e5 100644
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -35,11 +35,11 @@ DEFINE_MTYPE_STATIC(LIB, VRF_BITMAP, "VRF bit-map")
DEFINE_QOBJ_TYPE(vrf)
-static __inline int vrf_id_compare (struct vrf *, struct vrf *);
-static __inline int vrf_name_compare (struct vrf *, struct vrf *);
+static __inline int vrf_id_compare (const struct vrf *, const struct vrf *);
+static __inline int vrf_name_compare (const struct vrf *, const struct vrf *);
-RB_GENERATE (vrf_id_head, vrf, id_entry, vrf_id_compare)
-RB_GENERATE (vrf_name_head, vrf, name_entry, vrf_name_compare)
+RB_GENERATE (vrf_id_head, vrf, id_entry, vrf_id_compare);
+RB_GENERATE (vrf_name_head, vrf, name_entry, vrf_name_compare);
struct vrf_id_head vrfs_by_id = RB_INITIALIZER (&vrfs_by_id);
struct vrf_name_head vrfs_by_name = RB_INITIALIZER (&vrfs_by_name);
@@ -72,13 +72,13 @@ vrf_lookup_by_name (const char *name)
}
static __inline int
-vrf_id_compare (struct vrf *a, struct vrf *b)
+vrf_id_compare (const struct vrf *a, const struct vrf *b)
{
return (a->vrf_id - b->vrf_id);
}
static int
-vrf_name_compare (struct vrf *a, struct vrf *b)
+vrf_name_compare (const struct vrf *a, const struct vrf *b)
{
return strcmp (a->name, b->name);
}
@@ -377,6 +377,28 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id)
VRF_BITMAP_FLAG (offset)) ? 1 : 0;
}
+static void
+vrf_autocomplete (vector comps, struct cmd_token *token)
+{
+ struct vrf *vrf = NULL;
+
+ RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
+ {
+ if (vrf->vrf_id != 0)
+ vector_set (comps, XSTRDUP (MTYPE_COMPLETION, vrf->name));
+ }
+}
+
+static const struct cmd_variable_handler vrf_var_handlers[] = {
+ {
+ .varname = "vrf",
+ .completions = vrf_autocomplete,
+ },
+ {
+ .completions = NULL
+ },
+};
+
/* Initialize VRF module. */
void
vrf_init (int (*create)(struct vrf *),
@@ -408,6 +430,8 @@ vrf_init (int (*create)(struct vrf *),
zlog_err ("vrf_init: failed to enable the default VRF!");
exit (1);
}
+
+ cmd_variable_handler_register (vrf_var_handlers);
}
/* Terminate VRF module. */
@@ -419,9 +443,9 @@ vrf_terminate (void)
if (debug_vrf)
zlog_debug ("%s: Shutting down vrf subsystem", __PRETTY_FUNCTION__);
- while ((vrf = RB_ROOT (&vrfs_by_id)) != NULL)
+ while ((vrf = RB_ROOT (vrf_id_head, &vrfs_by_id)) != NULL)
vrf_delete (vrf);
- while ((vrf = RB_ROOT (&vrfs_by_name)) != NULL)
+ while ((vrf = RB_ROOT (vrf_name_head, &vrfs_by_name)) != NULL)
vrf_delete (vrf);
}