]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: enhance show vrf for netns and fixing
authorPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 7 Dec 2017 14:58:48 +0000 (15:58 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 27 Feb 2018 10:11:24 +0000 (11:11 +0100)
Show vrf command displays information on the vrf, if it is related to
vrf kernel or if it is related to netns.
When a vrf from kernel is detected, before creating a new vrf, a check
is done against an already present vrf, and if that vrf is not a vrf
mapped with a netns. If that is that case, then the creation is
rejected.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
lib/ns.c
lib/ns.h
zebra/zebra_vrf.h
zebra/zebra_vty.c

index 5e6bddf0d8d71ec18cda559a61342441cc23459f..5af896632c3a632a8650a0aeece6a9f1506b8925 100644 (file)
--- a/lib/ns.c
+++ b/lib/ns.c
@@ -218,6 +218,13 @@ void ns_walk_func(int (*func)(struct ns *))
                func(ns);
 }
 
+const char *ns_get_name(struct ns *ns)
+{
+       if (!ns)
+               return NULL;
+       return ns->name;
+}
+
 /* Look up a NS by name */
 static struct ns *ns_lookup_name(const char *name)
 {
index 6aebc442595ba71bdcb165b48ed9bb63cede20d9..fca5becd7a8ab35d306dab4dcafdde4496893289 100644 (file)
--- a/lib/ns.h
+++ b/lib/ns.h
@@ -99,5 +99,6 @@ extern int ns_handler_create(struct vty *vty, struct vrf *vrf,
 extern char *ns_netns_pathname(struct vty *vty, const char *name);
 extern void *ns_info_lookup(ns_id_t ns_id);
 extern void ns_walk_func(int (*func)(struct ns *));
+extern const char *ns_get_name(struct ns *ns);
 
 #endif /*_ZEBRA_NS_H*/
index 3b9e9309696187e884062a6b5dcce969747bbcd3..ae5a174116df41198fb94d2d194604c634ae26a1 100644 (file)
@@ -22,6 +22,7 @@
 #if !defined(__ZEBRA_RIB_H__)
 #define __ZEBRA_RIB_H__
 
+#include <lib/ns.h>
 #include <zebra/zebra_ns.h>
 #include <zebra/zebra_pw.h>
 #include <lib/vxlan.h>
@@ -133,11 +134,23 @@ static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf)
        return zvrf->vrf->vrf_id;
 }
 
+static inline const char *zvrf_ns_name(struct zebra_vrf *zvrf)
+{
+       if (!zvrf->vrf || !zvrf->vrf->ns_ctxt)
+               return NULL;
+       return ns_get_name((struct ns *)zvrf->vrf->ns_ctxt);
+}
+
 static inline const char *zvrf_name(struct zebra_vrf *zvrf)
 {
        return zvrf->vrf->name;
 }
 
+static inline bool zvrf_is_active(struct zebra_vrf *zvrf)
+{
+       return zvrf->vrf->status & VRF_ACTIVE;
+}
+
 struct route_table *zebra_vrf_table_with_table_id(afi_t afi, safi_t safi,
                                                  vrf_id_t vrf_id,
                                                  u_int32_t table_id);
index ccc7cb30c312d6f213251c047994ebcc28ca7171..4824c09f3db89a74581338da5bceac1e342fee24 100644 (file)
@@ -2374,8 +2374,12 @@ DEFUN (show_vrf,
                        continue;
 
                vty_out(vty, "vrf %s ", zvrf_name(zvrf));
-               if (zvrf_id(zvrf) == VRF_UNKNOWN)
+               if (zvrf_id(zvrf) == VRF_UNKNOWN
+                   || !zvrf_is_active(zvrf))
                        vty_out(vty, "inactive");
+               else if (zvrf_ns_name(zvrf))
+                       vty_out(vty, "id %u netns %s",
+                               zvrf_id(zvrf), zvrf_ns_name(zvrf));
                else
                        vty_out(vty, "id %u table %u", zvrf_id(zvrf),
                                zvrf->table_id);