From: Philippe Guibert Date: Thu, 7 Dec 2017 14:58:48 +0000 (+0100) Subject: zebra: enhance show vrf for netns and fixing X-Git-Tag: frr-5.0-dev~209^2~29 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=81c9005ff6edd2294ec945b93d49f03470b3b827;p=mirror%2Ffrr.git zebra: enhance show vrf for netns and fixing 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 --- diff --git a/lib/ns.c b/lib/ns.c index 5e6bddf0d8..5af896632c 100644 --- 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) { diff --git a/lib/ns.h b/lib/ns.h index 6aebc44259..fca5becd7a 100644 --- 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*/ diff --git a/zebra/zebra_vrf.h b/zebra/zebra_vrf.h index 3b9e930969..ae5a174116 100644 --- a/zebra/zebra_vrf.h +++ b/zebra/zebra_vrf.h @@ -22,6 +22,7 @@ #if !defined(__ZEBRA_RIB_H__) #define __ZEBRA_RIB_H__ +#include #include #include #include @@ -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); diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index ccc7cb30c3..4824c09f3d 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -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);