]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Fix `dampening dampened-paths json` crash
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 15 Jul 2021 12:55:46 +0000 (15:55 +0300)
committermergify-bot <noreply@mergify.io>
Fri, 23 Jul 2021 09:20:58 +0000 (09:20 +0000)
```
5  0x00007fccab6fac39 in json_object_boolean_true_add (obj=<optimized out>, key=<optimized out>) at lib/json.c:70
No locals.
6  0x000055c7b8c08ae5 in route_vty_short_status_out (vty=<optimized out>, path=0x55c7bb37dcf0, p=<optimized out>, json_path=0x55c7bb3735a0)
    at bgpd/bgp_route.c:8566
        rpki_state = RPKI_NOT_BEING_USED
7  0x000055c7b8c22d1b in flap_route_vty_out (afi=AFI_IP, json=0x55c7bb3735a0, use_json=true, safi=SAFI_UNICAST, display=0, path=0x55c7bb37dcf0,
    p=0x55c7bb37dea0, vty=0x55c7bb39e4c0) at bgpd/bgp_route.c:9600
        attr = <optimized out>
        bdi = 0x55c7bb377950
        timebuf = '\000' <repeats 24 times>
        len = <optimized out>
8  bgp_show_table (vty=0x55c7bb39e4c0, bgp=0x55c7bb316300, safi=safi@entry=SAFI_UNICAST, table=0x55c7bb314d90, type=bgp_show_type_flap_statistics,
    output_arg=0x0, rd=0x0, is_last=1, output_cum=0x0, total_cum=0x0, json_header_depth=0x7ffeefd649f8, show_flags=1, rpki_target_state=RPKI_NOT_BEING_USED)
    at bgpd/bgp_route.c:11110
```

With fix:

```
exit1-debian-9# sh ip bgp dampening dampened-paths
BGP table version is 16, local router ID is 10.10.10.200, 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 10.0.0.0/24      192.168.0.2      00:21:08 65000 ?
*d 10.10.10.100/32  192.168.0.2      00:21:08 65000 ?
*d 192.168.1.0/24   192.168.0.2      00:21:08 65000 ?

Displayed  3 routes and 10 total paths
exit1-debian-9# sh ip bgp dampening dampened-paths json
{
 "vrfId": 0,
 "vrfName": "default",
 "tableVersion": 16,
 "routerId": "10.10.10.200",
 "defaultLocPrf": 100,
 "localAS": 65001,
 "routes": { "10.0.0.0/24": [
  {
    "valid":true,
    "damped":true,
    "pathFrom":"external",
    "reuseTimerMsecs":1263000,
    "asPath":"65000",
    "origin":"?",
    "peerHost":"192.168.0.2"
  }
],"10.10.10.100/32": [
  {
    "valid":true,
    "damped":true,
    "pathFrom":"external",
    "reuseTimerMsecs":1263000,
    "asPath":"65000",
    "origin":"?",
    "peerHost":"192.168.0.2"
  }
],"192.168.1.0/24": [
  {
    "valid":true,
    "damped":true,
    "pathFrom":"external",
    "reuseTimerMsecs":1263000,
    "asPath":"65000",
    "origin":"?",
    "peerHost":"192.168.0.2"
  }
] }  }
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
(cherry picked from commit e5be8c1dac44958550dee57350b732920aa27d4e)

bgpd/bgp_route.c

index 366a53e26c780d19d587fc3a19df9eed6fc905f8..1d00c287605682acb82bdd7ef83a97ea042ab406 100644 (file)
@@ -9175,14 +9175,18 @@ void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
 static void damp_route_vty_out(struct vty *vty, const struct prefix *p,
                               struct bgp_path_info *path, int display,
                               afi_t afi, safi_t safi, bool use_json,
-                              json_object *json)
+                              json_object *json_paths)
 {
-       struct attr *attr;
+       struct attr *attr = path->attr;
        int len;
        char timebuf[BGP_UPTIME_LEN];
+       json_object *json_path = NULL;
+
+       if (use_json)
+               json_path = json_object_new_object();
 
        /* short status lead text */
-       route_vty_short_status_out(vty, path, p, json);
+       route_vty_short_status_out(vty, path, p, json_path);
 
        /* print prefix and mask */
        if (!use_json) {
@@ -9190,50 +9194,40 @@ static void damp_route_vty_out(struct vty *vty, const struct prefix *p,
                        route_vty_out_route(path->net, p, vty, NULL, false);
                else
                        vty_out(vty, "%*s", 17, " ");
-       }
 
-       len = vty_out(vty, "%s", path->peer->host);
-       len = 17 - len;
-       if (len < 1) {
-               if (!use_json)
+               len = vty_out(vty, "%s", path->peer->host);
+               len = 17 - len;
+
+               if (len < 1)
                        vty_out(vty, "\n%*s", 34, " ");
-       } else {
-               if (use_json)
-                       json_object_int_add(json, "peerHost", len);
                else
                        vty_out(vty, "%*s", len, " ");
-       }
 
-       if (use_json)
-               bgp_damp_reuse_time_vty(vty, path, timebuf, BGP_UPTIME_LEN, afi,
-                                       safi, use_json, json);
-       else
                vty_out(vty, "%s ",
                        bgp_damp_reuse_time_vty(vty, path, timebuf,
                                                BGP_UPTIME_LEN, afi, safi,
-                                               use_json, json));
-
-       /* Print attribute */
-       attr = path->attr;
+                                               use_json, NULL));
 
-       /* Print aspath */
-       if (attr->aspath) {
-               if (use_json)
-                       json_object_string_add(json, "asPath",
-                                              attr->aspath->str);
-               else
+               if (attr->aspath)
                        aspath_print_vty(vty, "%s", attr->aspath, " ");
-       }
 
-       /* Print origin */
-       if (use_json)
-               json_object_string_add(json, "origin",
-                                      bgp_origin_str[attr->origin]);
-       else
                vty_out(vty, "%s", bgp_origin_str[attr->origin]);
 
-       if (!use_json)
                vty_out(vty, "\n");
+       } else {
+               bgp_damp_reuse_time_vty(vty, path, timebuf, BGP_UPTIME_LEN, afi,
+                                       safi, use_json, json_path);
+
+               if (attr->aspath)
+                       json_object_string_add(json_path, "asPath",
+                                              attr->aspath->str);
+
+               json_object_string_add(json_path, "origin",
+                                      bgp_origin_str[attr->origin]);
+               json_object_string_add(json_path, "peerHost", path->peer->host);
+
+               json_object_array_add(json_paths, json_path);
+       }
 }
 
 /* flap route */