From 14d8590688be9e9660c3549a1147a4e3537d0512 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 21 Sep 2023 15:37:17 +0300 Subject: [PATCH 1/3] bgpd: Make sure dampening is enabled for the specified AFI/SAFI ``` (gdb) bt 0 raise (sig=sig@entry=11) at ../sysdeps/unix/sysv/linux/raise.c:50 1 0x00007f55897c6ab0 in core_handler (signo=11, siginfo=0x7ffd19764bb0, context=) at lib/sigevent.c:246 2 3 0x00005624ccabdee9 in bgp_get_reuse_time (penalty=, buf=buf@entry=0x7ffd19765590 "", len=len@entry=25, afi=afi@entry=AFI_IP, safi=safi@entry=SAFI_UNICAST, use_json=, json=0x0) at bgpd/bgp_damp.c:498 4 0x00005624ccabf5e7 in bgp_damp_reuse_time_vty (vty=vty@entry=0x5624ce484e30, path=path@entry=0x5624cdd797a0, timebuf=timebuf@entry=0x7ffd19765590 "", len=len@entry=25, afi=afi@entry=AFI_IP, safi=safi@entry=SAFI_UNICAST, use_json=false, json=0x0) at bgpd/bgp_damp.c:635 5 0x00005624cca146a9 in damp_route_vty_out (afi=AFI_IP, json_paths=0x0, use_json=false, safi=SAFI_UNICAST, display=, path=0x5624cdd797a0, p=0x5624ce3f3160, vty=0x5624ce484e30) at bgpd/bgp_route.c:9852 6 bgp_show_table (vty=0x5624ce484e30, bgp=0x5624ce400950, safi=safi@entry=SAFI_UNICAST, table=0x5624ce409300, type=type@entry=bgp_show_type_dampend_paths, output_arg=0x0, rd=0x0, is_last=1, output_cum=0x0, total_cum=0x0, json_header_depth=0x7ffd19765830, show_flags=0, rpki_target_state=RPKI_NOT_BEING_USED) at bgpd/bgp_route.c:11448 7 0x00005624cca15f74 in bgp_show (vty=vty@entry=0x5624ce484e30, bgp=, afi=, safi=, type=type@entry=bgp_show_type_dampend_paths, output_arg=output_arg@entry=0x0, show_flags=0, rpki_target_state=RPKI_NOT_BEING_USED) at bgpd/bgp_route.c:11702 8 0x00005624cca17679 in show_ip_bgp_magic (self=, viewvrfname=, aa_nn=, community_list=, community_list_str=, community_list_name=, as_path_filter_name=, prefix_list=, accesslist_name=, rmap_name=, version=, version_str=, alias_name=, wide=, detail_json=, uj=, detail_routes=, all=, argv=0x5624ce3f32f0, argc=, vty=0x5624ce484e30) at bgpd/bgp_route.c:12863 9 show_ip_bgp (self=, vty=, argc=, argv=0x5624ce3f32f0) at ./bgpd/bgp_route_clippy.c:514 10 0x00007f55897618ee in cmd_execute_command_real (vline=vline@entry=0x5624ce427020, vty=vty@entry=0x5624ce484e30, cmd=cmd@entry=0x0, up_level=up_level@entry=0) at lib/command.c:993 11 0x00007f5589761a91 in cmd_execute_command (vline=vline@entry=0x5624ce427020, vty=vty@entry=0x5624ce484e30, cmd=0x0, vtysh=vtysh@entry=0) at lib/command.c:1051 12 0x00007f5589761c30 in cmd_execute (vty=vty@entry=0x5624ce484e30, cmd=cmd@entry=0x5624ce47b1b0 "show bgp dampening damp", matched=matched@entry=0x0, vtysh=vtysh@entry=0) at lib/command.c:1218 13 0x00007f55897de95e in vty_command (vty=vty@entry=0x5624ce484e30, buf=) at lib/vty.c:591 14 0x00007f55897deb9d in vty_execute (vty=0x5624ce484e30) at lib/vty.c:1354 15 0x00007f55897e23eb in vtysh_read (thread=) at lib/vty.c:2362 16 0x00007f55897d9426 in event_call (thread=thread@entry=0x7ffd19767e70) at lib/event.c:1971 17 0x00007f5589789df8 in frr_run (master=0x5624cdc42100) at lib/libfrr.c:1213 18 0x00005624cc985f65 in main (argc=, argv=0x7ffd197680d8) at bgpd/bgp_main.c:510 (gdb) frame 4 (gdb) p damp[1][1] $4 = {suppress_value = 0, reuse_limit = 0, max_suppress_time = 0, half_life = 0, tmax = 0, reuse_list_size = 0, reuse_index_size = 0, ceiling = 0, decay_rate_per_tick = 0, decay_array_size = 0, scale_factor = 0, reuse_scale_factor = 0, decay_array = 0x0, reuse_index = 0x0, reuse_list = 0x0, reuse_offset = 0, no_reuse_list = 0x0, t_reuse = 0x0, afi = AFI_UNSPEC, safi = SAFI_UNSPEC} (gdb) p damp[2][1] $5 = {suppress_value = 1, reuse_limit = 1, max_suppress_time = 1800, half_life = 60, tmax = 0, reuse_list_size = 181, reuse_index_size = 1024, ceiling = 1073741824, decay_rate_per_tick = 0, decay_array_size = 360, scale_factor = 9.5367431729442842e-07, reuse_scale_factor = 0, decay_array = 0x5624ce483780, reuse_index = 0x5624ce481320, reuse_list = 0x5624ce482c20, reuse_offset = 7, no_reuse_list = 0x0, t_reuse = 0x5624ce3ec840, afi = AFI_UNSPEC, safi = SAFI_UNSPEC} (gdb) ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_damp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index a6d0e74dc0..eaa2b85aba 100644 --- a/bgpd/bgp_damp.c +++ b/bgpd/bgp_damp.c @@ -570,7 +570,9 @@ void bgp_damp_info_vty(struct vty *vty, struct bgp_path_info *path, afi_t afi, /* If dampening is not enabled or there is no dampening information, return immediately. */ - if (!bdc || !bdi) + if (!CHECK_FLAG(path->peer->bgp->af_flags[afi][safi], + BGP_CONFIG_DAMPENING) || + !bdi) return; /* Calculate new penalty. */ @@ -624,7 +626,9 @@ const char *bgp_damp_reuse_time_vty(struct vty *vty, struct bgp_path_info *path, /* If dampening is not enabled or there is no dampening information, return immediately. */ - if (!bdc || !bdi) + if (!CHECK_FLAG(path->peer->bgp->af_flags[afi][safi], + BGP_CONFIG_DAMPENING) || + !bdi) return NULL; /* Calculate new penalty. */ From c39506d80f3e42059e00e562f0c5b376a5246ddd Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 21 Sep 2023 16:00:10 +0300 Subject: [PATCH 2/3] bgpd: Initialise timebuf arrays to zeros for dampening reuse timer Avoid having something like this in outputs: Before: ``` munet> r1 shi vtysh -c 'show bgp dampening damp' BGP table version is 10, local router ID is 10.10.10.1, vrf id 0 Default local pref 100, local AS 65001 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network From Reuse Path *d 2001:db8:1::1/128 2001:db8::2 (null) 65002 ? *d 2001:db8:2::1/128 2001:db8::2 (null) 65002 ? *d 2001:db8:3::1/128 2001:db8::2 (null) 65002 ? *d 2001:db8:4::1/128 2001:db8::2 (null) 65002 ? *d 2001:db8:5::1/128 2001:db8::2 (null) 65002 ? Displayed 5 routes and 5 total paths munet> r1 shi vtysh -c 'show bgp dampening flap' BGP table version is 10, local router ID is 10.10.10.1, vrf id 0 Default local pref 100, local AS 65001 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network From Flaps Duration Reuse Path *d 2001:db8:1::1/128 2001:db8::2 2 00:03:10 (null) 65002 ? *d 2001:db8:2::1/128 2001:db8::2 2 00:03:10 (null) 65002 ? *d 2001:db8:3::1/128 2001:db8::2 2 00:03:10 (null) 65002 ? *d 2001:db8:4::1/128 2001:db8::2 2 00:03:10 (null) 65002 ? *d 2001:db8:5::1/128 2001:db8::2 2 00:03:10 (null) 65002 ? Displayed 5 routes and 5 total paths ``` After: ``` munet> r1 shi vtysh -c 'show bgp dampening damp ' BGP table version is 10, local router ID is 10.10.10.1, vrf id 0 Default local pref 100, local AS 65001 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network From Reuse Path *d 2001:db8:1::1/128 2001:db8::2 00:00:00 65002 ? *d 2001:db8:2::1/128 2001:db8::2 00:00:00 65002 ? *d 2001:db8:3::1/128 2001:db8::2 00:00:00 65002 ? *d 2001:db8:4::1/128 2001:db8::2 00:00:00 65002 ? *d 2001:db8:5::1/128 2001:db8::2 00:00:00 65002 ? Displayed 5 routes and 5 total paths munet> r1 shi vtysh -c 'show bgp dampening flap' BGP table version is 10, local router ID is 10.10.10.1, vrf id 0 Default local pref 100, local AS 65001 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network From Flaps Duration Reuse Path *d 2001:db8:1::1/128 2001:db8::2 2 00:00:15 00:00:00 65002 ? *d 2001:db8:2::1/128 2001:db8::2 2 00:00:15 00:00:00 65002 ? *d 2001:db8:3::1/128 2001:db8::2 2 00:00:15 00:00:00 65002 ? *d 2001:db8:4::1/128 2001:db8::2 2 00:00:15 00:00:00 65002 ? *d 2001:db8:5::1/128 2001:db8::2 2 00:00:15 00:00:00 65002 ? Displayed 5 routes and 5 total paths ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_damp.c | 2 +- bgpd/bgp_route.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index eaa2b85aba..80425ebe7a 100644 --- a/bgpd/bgp_damp.c +++ b/bgpd/bgp_damp.c @@ -558,7 +558,7 @@ void bgp_damp_info_vty(struct vty *vty, struct bgp_path_info *path, afi_t afi, { struct bgp_damp_info *bdi; time_t t_now, t_diff; - char timebuf[BGP_UPTIME_LEN]; + char timebuf[BGP_UPTIME_LEN] = {}; int penalty; struct bgp_damp_config *bdc = &damp[afi][safi]; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index e73908b0af..95c493a8b2 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -9824,7 +9824,7 @@ static void damp_route_vty_out(struct vty *vty, const struct prefix *p, { struct attr *attr = path->attr; int len; - char timebuf[BGP_UPTIME_LEN]; + char timebuf[BGP_UPTIME_LEN] = {}; json_object *json_path = NULL; if (use_json) @@ -9883,7 +9883,7 @@ static void flap_route_vty_out(struct vty *vty, const struct prefix *p, { struct attr *attr = path->attr; struct bgp_damp_info *bdi; - char timebuf[BGP_UPTIME_LEN]; + char timebuf[BGP_UPTIME_LEN] = {}; int len; json_object *json_path = NULL; From e0a87954848311b61e69fb957dcf0382429f15f9 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 21 Sep 2023 16:08:50 +0300 Subject: [PATCH 3/3] bgpd: Use proper AFI when dumping information for dampening stuff Before we called IPv4 for IPv6 dampening info. Signed-off-by: Donatas Abraitis --- bgpd/bgp_mplsvpn.c | 2 +- bgpd/bgp_route.c | 16 ++++++++-------- bgpd/bgp_route.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 3a04514c09..138b182718 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -3142,7 +3142,7 @@ int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd, return CMD_WARNING; } table = bgp->rib[afi][SAFI_MPLS_VPN]; - return bgp_show_table_rd(vty, bgp, SAFI_MPLS_VPN, table, prd, type, + return bgp_show_table_rd(vty, bgp, afi, SAFI_MPLS_VPN, table, prd, type, output_arg, show_flags); } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 95c493a8b2..3a850a486d 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11085,7 +11085,7 @@ static int bgp_show_community(struct vty *vty, struct bgp *bgp, const char *comstr, int exact, afi_t afi, safi_t safi, uint16_t show_flags); -static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, +static int bgp_show_table(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_table *table, enum bgp_show_type type, void *output_arg, const char *rd, int is_last, unsigned long *output_cum, unsigned long *total_cum, @@ -11446,12 +11446,12 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, if (type == bgp_show_type_dampend_paths || type == bgp_show_type_damp_neighbor) damp_route_vty_out(vty, dest_p, pi, display, - AFI_IP, safi, use_json, + afi, safi, use_json, json_paths); else if (type == bgp_show_type_flap_statistics || type == bgp_show_type_flap_neighbor) flap_route_vty_out(vty, dest_p, pi, display, - AFI_IP, safi, use_json, + afi, safi, use_json, json_paths); else { if (detail_routes || detail_json) { @@ -11607,7 +11607,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, return CMD_SUCCESS; } -int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, +int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_table *table, struct prefix_rd *prd_match, enum bgp_show_type type, void *output_arg, uint16_t show_flags) @@ -11636,7 +11636,7 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, memcpy(&prd, dest_p, sizeof(struct prefix_rd)); prefix_rd2str(&prd, rd, sizeof(rd), bgp->asnotation); - bgp_show_table(vty, bgp, safi, itable, type, output_arg, + bgp_show_table(vty, bgp, afi, safi, itable, type, output_arg, rd, next == NULL, &output_cum, &total_cum, &json_header_depth, show_flags, RPKI_NOT_BEING_USED); @@ -11686,7 +11686,7 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, table = bgp->rib[afi][safi]; /* use MPLS and ENCAP specific shows until they are merged */ if (safi == SAFI_MPLS_VPN) { - return bgp_show_table_rd(vty, bgp, safi, table, NULL, type, + return bgp_show_table_rd(vty, bgp, afi, safi, table, NULL, type, output_arg, show_flags); } @@ -11699,7 +11699,7 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, if (safi == SAFI_EVPN) return bgp_evpn_show_all_routes(vty, bgp, type, use_json, 0); - return bgp_show_table(vty, bgp, safi, table, type, output_arg, NULL, 1, + return bgp_show_table(vty, bgp, afi, safi, table, type, output_arg, NULL, 1, NULL, NULL, &json_header_depth, show_flags, rpki_target_state); } @@ -12023,7 +12023,7 @@ static void bgp_show_path_info(const struct prefix_rd *pfx_rd, || CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)))) route_vty_out_detail(vty, bgp, bgp_node, bgp_dest_get_prefix(bgp_node), pi, - AFI_IP, safi, rpki_curr_state, + afi, safi, rpki_curr_state, json_paths); } diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 54fad03e6d..e9f48ea647 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -887,7 +887,7 @@ extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_path_info *path, afi_t afi, safi_t safi, enum rpki_states, json_object *json_paths); -extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, +extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_table *table, struct prefix_rd *prd, enum bgp_show_type type, void *output_arg, uint16_t show_flags);