From c1aa9e7f905e2ee033e972cda60e5497f3062884 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Fri, 25 Nov 2022 12:24:15 +0100 Subject: [PATCH] bgpd: handle network rd parameter in network configuration The bgp network command creates static routes with an optional route-distinguisher parameter for VPN and EVPN address families. Store the rd parameter in those static routes. This will be used by the 'show running-config' later. Signed-off-by: Philippe Guibert --- bgpd/bgp_route.c | 19 +++++++++---------- bgpd/bgp_route.h | 1 + 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 8f16f6cae8..5686f21f87 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -6081,6 +6081,8 @@ static void bgp_static_free(struct bgp_static *bgp_static) XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); route_map_counter_decrement(bgp_static->rmap.map); + if (bgp_static->prd_pretty) + XFREE(MTYPE_BGP, bgp_static->prd_pretty); XFREE(MTYPE_ATTR, bgp_static->eth_s_id); XFREE(MTYPE_BGP_STATIC, bgp_static); } @@ -6984,6 +6986,8 @@ int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty, bgp_static->label = label; bgp_static->prd = prd; + if (rd_str) + bgp_static->prd_pretty = XSTRDUP(MTYPE_BGP, rd_str); if (rmap_str) { XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); route_map_counter_decrement(bgp_static->rmap.map); @@ -15606,7 +15610,6 @@ static void bgp_config_write_network_vpn(struct vty *vty, struct bgp *bgp, struct bgp_dest *dest; struct bgp_table *table; const struct prefix *p; - const struct prefix_rd *prd; struct bgp_static *bgp_static; mpls_label_t label; @@ -15624,14 +15627,12 @@ static void bgp_config_write_network_vpn(struct vty *vty, struct bgp *bgp, continue; p = bgp_dest_get_prefix(dest); - prd = (const struct prefix_rd *)bgp_dest_get_prefix( - pdest); /* "network" configuration display. */ label = decode_label(&bgp_static->label); - /* TODO: save RD format */ - vty_out(vty, " network %pFX rd %pRDP", p, prd); + vty_out(vty, " network %pFX rd %s", p, + bgp_static->prd_pretty); if (safi == SAFI_MPLS_VPN) vty_out(vty, " label %u", label); @@ -15654,7 +15655,6 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp, struct bgp_dest *dest; struct bgp_table *table; const struct prefix *p; - const struct prefix_rd *prd; struct bgp_static *bgp_static; char buf[PREFIX_STRLEN * 2]; char buf2[SU_ADDRSTRLEN]; @@ -15682,7 +15682,6 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp, esi_to_str(bgp_static->eth_s_id, esi_buf, sizeof(esi_buf)); p = bgp_dest_get_prefix(dest); - prd = (struct prefix_rd *)bgp_dest_get_prefix(pdest); /* "network" configuration display. */ if (p->u.prefix_evpn.route_type == 5) { @@ -15708,10 +15707,10 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp, inet_ntop(bgp_static->gatewayIp.family, &bgp_static->gatewayIp.u.prefix, buf2, sizeof(buf2)); - /* TODO: save RD format */ vty_out(vty, - " network %s rd %pRDP ethtag %u label %u esi %s gwip %s routermac %s\n", - buf, prd, p->u.prefix_evpn.prefix_addr.eth_tag, + " network %s rd %s ethtag %u label %u esi %s gwip %s routermac %s\n", + buf, bgp_static->prd_pretty, + p->u.prefix_evpn.prefix_addr.eth_tag, decode_label(&bgp_static->label), esi_buf, buf2, macrouter); diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 452282926f..441f84e115 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -370,6 +370,7 @@ struct bgp_static { /* Route Distinguisher */ struct prefix_rd prd; + char *prd_pretty; /* MPLS label. */ mpls_label_t label;