From cd4b15a523b74882a3c4c783ba16c06561614941 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Wed, 4 Apr 2018 14:20:25 -0400 Subject: [PATCH] zebra: display holdem statics correctly Holdem statics display the dest (and mask, if present) string that the user entered instead of converting to CIDR notation and applying the mask. They need to do the latter. Signed-off-by: Quentin Young --- zebra/zebra_vty.c | 51 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index ea35c782fd..b8370c0aca 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -91,6 +91,9 @@ struct static_hold_route { char *tag_str; char *distance_str; char *label_str; + + /* processed & masked destination, used for config display */ + struct prefix dest; }; static struct list *static_list; @@ -160,11 +163,7 @@ static int static_list_compare(void *arg1, void *arg2) if (ret) return ret; - ret = static_list_compare_helper(shr1->dest_str, shr2->dest_str); - if (ret) - return ret; - - ret = static_list_compare_helper(shr1->mask_str, shr2->mask_str); + ret = prefix_cmp(&shr1->dest, &shr2->dest); if (ret) return ret; @@ -198,15 +197,12 @@ static int static_list_compare(void *arg1, void *arg2) /* General function for static route. */ -static int zebra_static_route_holdem(struct zebra_vrf *zvrf, - struct zebra_vrf *nh_zvrf, - afi_t afi, safi_t safi, - const char *negate, const char *dest_str, - const char *mask_str, const char *src_str, - const char *gate_str, const char *ifname, - const char *flag_str, const char *tag_str, - const char *distance_str, - const char *label_str) +static int zebra_static_route_holdem( + struct zebra_vrf *zvrf, struct zebra_vrf *nh_zvrf, afi_t afi, + safi_t safi, const char *negate, struct prefix *dest, + const char *dest_str, const char *mask_str, const char *src_str, + const char *gate_str, const char *ifname, const char *flag_str, + const char *tag_str, const char *distance_str, const char *label_str) { struct static_hold_route *shr, *lookup; struct listnode *node; @@ -216,6 +212,8 @@ static int zebra_static_route_holdem(struct zebra_vrf *zvrf, shr->nhvrf_name = XSTRDUP(MTYPE_STATIC_ROUTE, nh_zvrf->vrf->name); shr->afi = afi; shr->safi = safi; + if (dest) + prefix_copy(&shr->dest, dest); if (dest_str) shr->dest_str = XSTRDUP(MTYPE_STATIC_ROUTE, dest_str); if (mask_str) @@ -294,14 +292,6 @@ static int zebra_static_route_leak( return CMD_WARNING_CONFIG_FAILED; } - if (zvrf->vrf->vrf_id == VRF_UNKNOWN - || nh_zvrf->vrf->vrf_id == VRF_UNKNOWN) { - vrf_set_user_cfged(zvrf->vrf); - return zebra_static_route_holdem( - zvrf, nh_zvrf, afi, safi, negate, dest_str, mask_str, - src_str, gate_str, ifname, flag_str, tag_str, - distance_str, label_str); - } switch (afi) { case AFI_IP: /* Cisco like mask notation. */ @@ -343,6 +333,15 @@ static int zebra_static_route_leak( /* Apply mask for given prefix. */ apply_mask(&p); + if (zvrf->vrf->vrf_id == VRF_UNKNOWN + || nh_zvrf->vrf->vrf_id == VRF_UNKNOWN) { + vrf_set_user_cfged(zvrf->vrf); + return zebra_static_route_holdem( + zvrf, nh_zvrf, afi, safi, negate, &p, dest_str, + mask_str, src_str, gate_str, ifname, flag_str, tag_str, + distance_str, label_str); + } + /* Administrative distance. */ if (distance_str) distance = atoi(distance_str); @@ -2221,11 +2220,13 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi, if (strcmp(zvrf->vrf->name, shr->vrf_name) != 0) continue; + char dest_str[PREFIX_STRLEN]; + + prefix2str(&shr->dest, dest_str, sizeof(dest_str)); + vty_out(vty, "%s ", spacing); if (shr->dest_str) - vty_out(vty, "%s ", shr->dest_str); - if (shr->mask_str) - vty_out(vty, "%s ", shr->mask_str); + vty_out(vty, "%s ", dest_str); if (shr->src_str) vty_out(vty, "from %s ", shr->src_str); if (shr->gate_str) -- 2.39.5