Commit graph

347 commits

Author SHA1 Message Date
Mark Stapp 660cbf5651 bgpd: clean up variable-shadowing compiler warnings
Clean up -Wshadow warnings in bgp.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-04-08 14:41:27 -04:00
Mark Stapp 2496bfecfe bgpd: fix handling of configured RTs for l2vni, l3vni
Test for existing explicit config as part of validation of
route-target configuration: allow explicit config of generic/
default AS+VNI, for example, instead of rejecting it.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-03-24 16:53:32 -04:00
Mark Stapp 9943a08720 bgpd: fix vty output of evpn route-target AS4
evpn route-targets are decoded in  ... multiple places; at least
two have a bug where the AS4 form doesn't have its AS decoded.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-02-11 14:35:28 -05:00
Donatas Abraitis 1d6925e02f bgpd: Show internal data for BGP routes
Sometimes it's very useful to compare pointers from the gdb (and/or from the
logs) or just do some quick adhoc analysis.

```
donatas# sh ip bgp 1.1.1.0/24 internal
BGP routing table entry for 1.1.1.0/24, version 0
Paths: (1 available, no best path)
  Not advertised to any peer
  65002
    127.0.0.1 (inaccessible, import-check enabled) from 127.0.0.1 (127.0.0.2)
      Origin IGP, invalid, external
      Last update: Thu Jan 16 16:49:53 2025
      net: 0x63f3e6fc2ea0, path: 0x63f3e6fc2f50, pathext: 0x63f3e6faed00, attr: 0x63f3e6e8c550
      flags net: 0x0, path: 0x1024, attr: 0x7
donatas#
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2025-01-17 22:24:35 +02:00
Russ White c9c9608c70
Merge pull request #17431 from krishna-samy/bgpd_json_commits
bgpd: show json output changes to optimize various show commands
2025-01-07 08:43:55 -05:00
Donatas Abraitis 708f08cb18 bgpd: Show applied route-map attributes for neighbor X advertised-routes detail
If we have a route-map that sets some attributes e.g. community or large-community,
and the route-map is applied for outgoing direction, everything is fine, but
we missed the point that `advertised-routes detail` was not using the applied
attributes to display and instead it uses what is received from the peer (original).

Let's fix this, and use what's already applied (advertise attributes), and
we can now see:

```
route-map r3 permit 10
 match ip address prefix-list p1
 set community 65001:65002
 set extcommunity bandwidth 100
 set large-community 65001:65002:65003
exit
!
...
 address-family ipv4 unicast
  neighbor 192.168.2.3 route-map r3 out
 exit-address-family
...
```

The output:

```
r2# show bgp ipv4 neighbors 192.168.2.3 advertised-routes detail
BGP table version is 1, local router ID is 192.168.2.2, vrf id 0
Default local pref 100, local AS 65002
BGP routing table entry for 10.10.10.1/32, version 1
Paths: (1 available, best #1, table default)
  Advertised to non peer-group peers:
  192.168.1.1 192.168.2.3
  65001
    0.0.0.0 from 192.168.1.1 (192.168.1.1)
      Origin IGP, valid, external, best (First path received)
      Community: 65001:65002
      Extended Community: LB:65002:12500000 (100.000 Mbps)
      Large Community: 65001:65002:65003
      Last update: Thu Dec 19 17:00:40 2024
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-12-19 17:10:06 +02:00
vivek f8c464688d bgpd: Check L3VNI status before announcing default
Check that the L3VNI is "up" before taking action to announce or
withdraw the EVPN type-5 default based on configuration. Otherwise,
there can be timing conditions where a EVPN type-5 default route
gets announced without a VNI and with invalid route targets.

Signed-off-by: Vivek Venkatraman <vivek@nvidia.com>

Ticket: #2684144
Reviewed By: Chirag Shah
Testing Done:
1. Rerun failed test multiple times successfully
2. Some manual testing
3. precommit and partial evpn-smoke
2024-12-09 12:31:29 -05:00
Ashwini Reddy 9c5530144a bgpd: show bgp l2vpn evpn route detail json stringify changes
Json object could lead to out-of-memory in scaled bgp l2vpn evpn route setup.

Changes:

- not use pretty print and stringify smaller json objects to reduce memory
usage
- free memory after ouput of json_rd
- minor formatting of json output

Commands supported with this Json stringify:

show bgp l2vpn evpn route detail json
show bgp l2vpn evpn route detail type 2 json
show bgp l2vpn evpn route detail type 2 self-originate json
show bgp l2vpn evpn route detail self-originate json
show bgp l2vpn evpn route json
show bgp l2vpn evpn route type 2 json
show bgp l2vpn evpn route type 2 self-originate json
show bgp l2vpn evpn route self-originate json

Ticket:#3513249

Issue:3513249

Signed-off-by: Ashwini Reddy <ashred@nvidia.com>
Signed-off-by: Sindhu Parvathi Gopinathan's <sgopinathan@nvidia.com>
2024-11-15 22:49:01 -08:00
Sindhu Parvathi Gopinathan ff008cee6b bgpd: EVPN fix per rd specific type-2 json output
Current Issue:

paths key is not there for
'show bgp l2vpn evpn route rd <rd-id> mac <mac> json' uses
evpn prefix as key for each path.
Replace the evpn prefix with "paths".
This aligned with overall EVPN RIB json output like
'show bgp l2vpn evpn route json'
'show bgp l2vpn evpn route rd <> type 2 json'

Fix:

paths key is added instead of prefix info.

Ticket:#4087461

Issue:4087461

Testing:

Before fix:

leaf22# show bgp l2vpn evpn route rd 6.0.0.17:2 mac 00:02:00:00:00:12 json
{
  "prefix":"[2]:[0]:[48]:[00:02:00:00:00:12]",
  "prefixLen":352,
  "rd":"6.0.0.17:2",
  "routeType":2,
  "ethTag":0,
  "macLen":48,
  "mac":"00:02:00:00:00:12",
  "advertisedTo":{
    "220.20.0.33":{
      "hostname":"spine21"
    },
    "220.21.0.33":{
      "hostname":"spine22"
    }
  },
  "[2]:[0]:[48]:[00:02:00:00:00:12]":[ <=====  Prefix info instead of "paths" key
    [
      {
        "vni":"101101",
        "aspath":{
          "string":"65202 65024",
          "segments":[
            {
              "type":"as-sequence",
              "list":[
                65202,
                65024
              ]
            }
          ],
          "length":2
        },
        "esi":"03:00:00:00:77:02:04:00:00:18",
        "es_info":{
          "localEs":true
        },
        "origin":"IGP",
        "valid":true,
        "version":5,
        "bestpath":{
          "bestpathFromAs":65202,
          "overall":true,
          "selectionReason":"Older Path"
        },
        "extendedCommunity":{
          "string":"RT:65024:101101 ET:8"
        },
        "lastUpdate":{
          "epoch":1726803218,
          "string":"Fri Sep 20 03:33:38 2024\n"
        },
        "nexthops":[
          {
            "ip":"6.0.0.17",
            "hostname":"spine21",
            "afi":"ipv4",
            "metric":0,
            "accessible":true,
            "used":true
          }
        ],
        "peer":{
          "peerId":"220.20.0.33",
          "routerId":"6.0.0.20",
          "hostname":"spine21",
          "type":"external"
        }
      }
    ],
    [
      {
        "vni":"101101",
        "aspath":{
          "string":"65202 65024",
          "segments":[
            {
              "type":"as-sequence",
              "list":[
                65202,
                65024
              ]
            }
          ],
          "length":2
        },
        "esi":"03:00:00:00:77:02:04:00:00:18",
        "es_info":{
          "localEs":true
        },
        "origin":"IGP",
        "valid":true,
        "version":5,
        "extendedCommunity":{
          "string":"RT:65024:101101 ET:8"
        },
        "lastUpdate":{
          "epoch":1726803218,
          "string":"Fri Sep 20 03:33:38 2024\n"
        },
        "nexthops":[
          {
            "ip":"6.0.0.17",
            "hostname":"spine22",
            "afi":"ipv4",
            "metric":0,
            "accessible":true,
            "used":true
          }
        ],
        "peer":{
          "peerId":"220.21.0.33",
          "routerId":"6.0.0.21",
          "hostname":"spine22",
          "type":"external"
        }
      }
    ]
  ],
  "numPaths":2
}

After fix:

eaf22# show bgp l2vpn evpn route rd 6.0.0.17:2 mac 00:02:00:00:00:12 json
{
  "prefix":"[2]:[0]:[48]:[00:02:00:00:00:12]",
  "prefixLen":352,
  "rd":"6.0.0.17:2",
  "routeType":2,
  "ethTag":0,
  "macLen":48,
  "mac":"00:02:00:00:00:12",
  "advertisedTo":{
    "220.20.0.33":{
      "hostname":"spine21"
    },
    "220.21.0.33":{
      "hostname":"spine22"
    }
  },
  "paths":[
    [
      {
        "vni":"101101",
        "aspath":{
          "string":"65202 65024",
          "segments":[
            {
              "type":"as-sequence",
              "list":[
                65202,
                65024
              ]
            }
          ],
          "length":2
        },
        "esi":"03:00:00:00:77:02:04:00:00:18",
        "es_info":{
          "localEs":true
        },
        "origin":"IGP",
        "valid":true,
        "version":3,
        "bestpath":{
          "bestpathFromAs":65202,
          "overall":true,
          "selectionReason":"Router ID"
        },
        "extendedCommunity":{
          "string":"RT:65024:101101 ET:8"
        },
        "lastUpdate":{
          "epoch":1727175046,
          "string":"Tue Sep 24 10:50:46 2024\n"
        },
        "nexthops":[
          {
            "ip":"6.0.0.17",
            "hostname":"spine21",
            "afi":"ipv4",
            "metric":0,
            "accessible":true,
            "used":true
          }
        ],
        "peer":{
          "peerId":"220.20.0.33",
          "routerId":"6.0.0.20",
          "hostname":"spine21",
          "type":"external"
        }
      }
    ],
    [
      {
        "vni":"101101",
        "aspath":{
          "string":"65202 65024",
          "segments":[
            {
              "type":"as-sequence",
              "list":[
                65202,
                65024
              ]
            }
          ],
          "length":2
        },
        "esi":"03:00:00:00:77:02:04:00:00:18",
        "es_info":{
          "localEs":true
        },
        "origin":"IGP",
        "valid":true,
        "version":3,
        "extendedCommunity":{
          "string":"RT:65024:101101 ET:8"
        },
        "lastUpdate":{
          "epoch":1727175046,
          "string":"Tue Sep 24 10:50:46 2024\n"
        },
        "nexthops":[
          {
            "ip":"6.0.0.17",
            "hostname":"spine22",
            "afi":"ipv4",
            "metric":0,
            "accessible":true,
            "used":true
          }
        ],
        "peer":{
          "peerId":"220.21.0.33",
          "routerId":"6.0.0.21",
          "hostname":"spine22",
          "type":"external"
        }
      }
    ]
  ],
  "numPaths":2
}

Signed-off-by: Sindhu Parvathi Gopinathan's <sgopinathan@nvidia.com>
2024-09-24 20:10:59 -07:00
Donald Sharp 4dd9d1176f bgpd: Ensure evpn local table display shows route send status
evpn has a concept of `local` tables where the evpn routes
are actually converted into underlying routes/neighbor
table entries( or vice versa ).  Then this local route
is propagated to the global evpn l2vpn table and sent
to the peers.  Certain show commands in evpn look
operate on the local table but make the output look
like the data has not been sent to the peer.  This
is confusing for the operator.  Modify the code
such that local tables get a `Local BGP table not advertised`
in the place where the code talks about whom has received
the data or not.

Example:
torm11# show bgp l2vpn evpn route vni 1000 mac 8a:a1:cc:73:a3:ac ip 45.0.0.5
BGP routing table entry for [2]:[0]:[48]:[8a:a1:cc:73:a3:ac]:[32]:[45.0.0.5]
Paths: (2 available, best #2)
  Local BGP table not advertised
  Route [2]:[0]:[48]:[8a:a1:cc:73:a3:ac]:[32]:[45.0.0.5] VNI 1000
  Imported from 192.168.100.18:2:[2]:[0]:[48]:[8a:a1:cc:73:a3:ac]:[32]:[45.0.0.5], VNI 1000
  65101 65005
    192.168.100.18(leaf2) from leaf2(192.168.5.1) (192.168.100.14)
      Origin IGP, valid, external
      Extended Community: RT:65005:1000 ET:8
      Last update: Thu Mar 21 14:29:04 2024
  Route [2]:[0]:[48]:[8a:a1:cc:73:a3:ac]:[32]:[45.0.0.5] VNI 1000
  Imported from 192.168.100.18:2:[2]:[0]:[48]:[8a:a1:cc:73:a3:ac]:[32]:[45.0.0.5], VNI 1000
  65101 65005
    192.168.100.18(leaf1) from leaf1(192.168.1.1) (192.168.100.13)
      Origin IGP, valid, external, bestpath-from-AS 65101, best (Router ID)
      Extended Community: RT:65005:1000 ET:8
      Last update: Thu Mar 21 14:29:04 2024

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-08-30 16:23:20 -04:00
Donatas Abraitis 0ed36e44f8 bgpd: Convert int to enum peer_asn_type
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-07-04 23:07:01 +03:00
Donald Sharp 0b81a7524d bgpd: MTYPE_BGP was being overused split up
The MTYPE_BGP memory type was being over used as
both the handler for the bgp instance itself as
well as memory associated with name strings.
Let's separate out the two.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-21 12:41:18 -05:00
Donatas Abraitis 02d8b80ce4 *: Do not cast to the same type as the destination is
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-09-29 10:24:16 +03:00
Yuqing Zhao 6e7f305e54 bgpd: Convert from struct bgp_node to struct bgp_dest
This is based on @donaldsharp's work

The current code base is the struct bgp_node data structure.
The problem with this is that it creates a bunch of
extra data per route_node.
The table structure generates ‘holder’ nodes
that are never going to receive bgp routes,
and now the memory of those nodes is allocated
as if they are a full bgp_node.

After splitting up the bgp_node into bgp_dest and route_node,
the memory of ‘holder’ node which does not have any bgp data
will be allocated as the route_node, not the bgp_node,
and the memory usage is reduced.
The memory usage of BGP node will be reduced from 200B to 96B.
The total memory usage optimization of this part is ~16.00%.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Signed-off-by: Yuqing Zhao <xiaopanghu99@163.com>
2023-08-22 09:35:46 +08:00
Donatas Abraitis ad151f66aa bgpd: Refactor bgp_static_set/bgp_static_set_safi
Those two functions are very similar, let's get a single one.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-14 17:10:07 +03:00
Donald Sharp ad5329c7b0 bgpd: bgp_vrf is already deref'ed in all paths
The usage of bgp_vrf does not need to be tested
at this point since it's already been derefed in all
paths to this point.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-08-07 15:11:05 -04:00
Abhinay Ramesh 56b895c172 bgpd: fix bgp evpn cli memory leaks.
problem:
In CLI config codeflow there are memory leaks in failure scenario

Fix:
Code changes are done to free ecommunity

Signed-off-by: Abhinay Ramesh <rabhinay@vmware.com>
2023-07-18 10:15:19 +00:00
Keelan10 9d659b167d bgpd: Fix memory leak
The `bgp_vrf->vrf_prd_pretty` string was not properly freed, leading to a memory leak.
This commit resolves the memory leak by freeing the memory allocated for `bgp_vrf->vrf_prd_pretty` before returning from the function.

The ASan leak log for reference:
```
***********************************************************************************
Address Sanitizer Error detected in evpn_type5_test_topo1.test_evpn_type5_topo1/e1.asan.bgpd.17689

=================================================================
==17689==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 15 byte(s) in 1 object(s) allocated from:
    #0 0x7fdd94fc0538 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x77538)
    #1 0x55e28d9c4c6c in qstrdup lib/memory.c:117
    #2 0x55e28d6c0d27 in evpn_configure_vrf_rd bgpd/bgp_evpn_vty.c:2297
    #3 0x55e28d6c0d27 in bgp_evpn_vrf_rd bgpd/bgp_evpn_vty.c:6271
    #4 0x55e28d94c155 in cmd_execute_command_real lib/command.c:994
    #5 0x55e28d94c622 in cmd_execute_command lib/command.c:1053
    #6 0x55e28d94ca99 in cmd_execute lib/command.c:1221
    #7 0x55e28da6d7d4 in vty_command lib/vty.c:591
    #8 0x55e28da6dc6e in vty_execute lib/vty.c:1354
    #9 0x55e28da7644d in vtysh_read lib/vty.c:2362
    #10 0x55e28da616e2 in event_call lib/event.c:1995
    #11 0x55e28d9a7a65 in frr_run lib/libfrr.c:1213
    #12 0x55e28d63ef00 in main bgpd/bgp_main.c:505
    #13 0x7fdd93883c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 15 byte(s) leaked in 1 allocation(s).
***********************************************************************************
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
2023-07-05 22:17:48 +04:00
Donald Sharp cc64917540 bgpd: All paths bgp_vrf have already been derefed
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-03 13:00:07 -04:00
Trey Aspelund 08a3439d51 bgpd: fix static analyzer complaint for evpn_info
In CI, CLANG static analyzer started complaining about possible null
dereferences of pre-existing fields. Let's make it happy and do a null
check.

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2023-05-30 15:25:45 +00:00
Trey Aspelund 6cabac8505 bgpd: fix rc for invalid mac-vrf soo
Change CMD_WARNING -> CMD_WARNING_CONFIG_FAILED so that the rc is
non-zero and the caller can detect a failure.

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2023-05-30 15:20:35 +00:00
Trey Aspelund c4b59c9ab1 bgpd: add mac-vrf soo to show bgp l2vpn evpn vni
Adds the current MAC-VRF SoO value to the output of "show bgp l2vpn evpn
vni [vni]". Also fixes a missing space in front of the Tenant VRF string.

New output:
```
ub20-2(config-router-af)# do show bgp l2vpn evpn vni
Advertise Gateway Macip: Disabled
Advertise SVI Macip: Disabled
Advertise All VNI flag: Enabled
BUM flooding: Head-end replication
VXLAN flooding: Enabled
Number of L2 VNIs: 2
Number of L3 VNIs: 1
Flags: * - Kernel
  VNI        Type RD                    Import RT                 Export RT                 MAC-VRF Site-of-Origin    Tenant VRF
* 20         L2   100.64.0.33:3         1:20                      1:20                      3.3.3.3:20                stuff
* 30         L2   100.64.0.33:4         1:30                      1:30                      3.3.3.3:20                stuff
* 10         L3   30.0.0.3:2            1:10                      1:10                      3.3.3.3:20                stuff

ub20-2(config-router-af)# do show bgp l2vpn evpn vni 10
VNI: 10 (known to the kernel)
  Type: L3
  Tenant VRF: stuff
  RD: 30.0.0.3:2
  Originator IP: 3.3.3.3
  MAC-VRF Site-of-Origin: 3.3.3.3:20     <<<<<
  Advertise-gw-macip : n/a
  Advertise-svi-macip : n/a
  Advertise-pip: Yes
  System-IP: 100.64.0.33
  System-MAC: aa:bb:cc:00:33:33
  Router-MAC: aa:bb:cc:00:33:33
  Import Route Target:
    1:10
  Export Route Target:
    1:10

ub20-2(config-router-af)# do show bgp l2vpn evpn vni 20
VNI: 20 (known to the kernel)
  Type: L2
  Tenant-Vrf: stuff
  RD: 100.64.0.33:3
  Originator IP: 3.3.3.3
  MAC-VRF Site-of-Origin: 3.3.3.3:20     <<<<<
  Mcast group: 0.0.0.0
  Advertise-gw-macip : Disabled
  Advertise-svi-macip : Disabled
  SVI interface : br20
  Import Route Target:
    1:20
  Export Route Target:
    1:20
```

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2023-05-30 15:20:35 +00:00
Trey Aspelund 65cdb9ce9b bgpd: Add MAC-VRF Site-of-Origin support
Initial support for configuring an SoO for all MAC-VRFs (EVIs/L2VNIs).
This provides a topology-independent method of preventing EVPN routes
from one MAC-VRF "site" (an L2 domain) from being imported by other PEs
in the same MAC-VRF "site", similar to how SoO is traditionally used in
L3VPN to identify and break loops for an L3/IP-VRF "site".
One example of where a MAC-VRF SoO can be used to avoid an L2 control
plane loop is with Active/Active MLAG VTEPs. For a given L2 site only
one control plane should be active. SoO can be used to ID/ignore entries
originated from the local MAC-VRF site so that EVPN will not attempt to
manage entries that are already handled by MLAG.

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2023-05-30 15:20:35 +00:00
Rajasekar Raja 82465ca7f9 bgpd: Using no pretty json output for l2vpn-Evpn routes
The output of show bgp all json is inconsistent across Address-families
i.e. ipv4/ipv6 is a no pretty format while l2vpn-evpn is in a pretty
format. For huge scale (lots of routes with lots of paths), it is better
to use no_pretty format.

Before fix:
torm-11# sh bgp all json
{
"ipv4Unicast":{
 "vrfId": 0,
 "vrfName": "default",
 "tableVersion": 1,
 "routerId": "27.0.0.15",
 "defaultLocPrf": 100,
 "localAS": 65000,
 "routes": { } }
,
"l2VpnEvpn":{
"routes":{
  "27.0.0.15:2":{
    "rd":"27.0.0.15:2",
    "[1]:[0]:[03:44:38:39:ff:ff:01:00:00:01]:[128]:[::]:[0]":{
      "prefix":"[1]:[0]:[03:44:38:39:ff:ff:01:00:00:01]:[128]:[::]:[0]",
      "prefixLen":352,
      "paths":[
<SNIP>.............

After fix:
torm-11# sh bgp all json
{
"ipv4Unicast":{
 "vrfId": 0,
 "vrfName": "default",
 "tableVersion": 1,
 "routerId": "27.0.0.15",
 "defaultLocPrf": 100,
 "localAS": 65000,
 "routes": { } }
,
"l2VpnEvpn":{
"routes":{"27.0.0.15:2":{"rd":"27.0.0.15:2","[1]:[0]:[03:44:38:39:ff:ff:01:00:00:01]:[128]:[::]:[0]":{"prefix":"[1]:[0]:[03:44:38:39:ff:ff:01:00:00:01]:[128]:[::]:[0]","prefixLen":352,"paths":[[{"valid":true,"bestpath":true,"selectionReason":"First path received","pathFrom":"external","routeType":1,"weight":32768,"peerId":"(unspec)","path":"","origin":"IGP","extendedCommunity"
<SNIP>.............

Issue: 3472865

Ticket:#3472865

Signed-off-by: Rajasekar Raja <rajasekarr@nvidia.com>
2023-05-22 14:14:30 -07:00
Donald Sharp 332133d19b bgpd: Ensure bgp_vrf is non-null
If we attempt to get the bgp_vrf and it fails then
ensure that we don't just de-ref and crash.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-04-21 08:04:06 -04:00
Donatas Abraitis 59d6b4d6ab bgpd: Rename bgp_afi_node_lookup() to bgp_safi_node_lookup()
afi not used in this function, reduce a bit.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-03-14 12:01:56 +02:00
Russ White eb9f54b872
Merge pull request #12805 from karlquan/kquan_self_orig
bgpd: BGP troubleshooting - Add a keyword self-originate to display o…
2023-02-21 08:38:07 -05:00
Russ White ba755d35e5
Merge pull request #12248 from pguibert6WIND/bgpasdot
lib, bgp: add initial support for asdot format
2023-02-21 08:01:03 -05:00
Donatas Abraitis 5ef2911d23
Merge pull request #12791 from taspelund/loc_rib_json_fix
bgpd: fix 'json detail' output structure
2023-02-17 20:24:33 +02:00
Trey Aspelund f9f2d188e3 bgpd: fix 'json detail' output structure
"show bgp <afi> <safi> json detail" was incorrectly displaying header
information from route_vty_out_detail_header() as an element of the
"paths" array. This corrects the behavior for 'json detail' so that a
route holds a dictionary with keys for "paths" and header info, which
aligns with how we structure the output for a specific prefix, e.g.
"show bgp <afi> <safi> <prefix> json".

Before:
```
ub20# show ip bgp json detail
{
 "vrfId": 0,
 "vrfName": "default",
 "tableVersion": 3,
 "routerId": "100.64.0.222",
 "defaultLocPrf": 100,
 "localAS": 1,
 "routes": { "2.2.2.2/32": [
  {                           <<<<<<<<<  should be outside the array
    "prefix":"2.2.2.2/32",
    "version":1,
    "advertisedTo":{
      "192.168.122.12":{
        "hostname":"ub20-2"
      }
    }
  },
  {
    "aspath":{
      "string":"Local",
      "segments":[
      ],
      "length":0
    },
<snip>
```

After:
```
ub20# show ip bgp json detail
{
 "vrfId": 0,
 "vrfName": "default",
 "tableVersion": 3,
 "routerId": "100.64.0.222",
 "defaultLocPrf": 100,
 "localAS": 1,
 "routes": { "2.2.2.2/32": {
"prefix": "2.2.2.2/32",
"version": "1",
"advertisedTo": {
  "192.168.122.12":{
    "hostname":"ub20-2"
  }
}
,"paths": [
  {
    "aspath":{
      "string":"Local",
      "segments":[
      ],
      "length":0
    },
```

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2023-02-16 16:05:16 +00:00
Karl Quan 83856649b3 bgpd: BGP troubleshooting - Add a keyword self-originate to display only self-originated prefixes when looking at the BGP table for a given address-family
Add a keyword self-originate" to extend current CLI commands to filter out self-originated routes only

a\) CLI to show ipv4/ipv6 self-originated routes
	"show [ip] bgp [afi] [safi] [all] self-originate [wide|json]"

b\) CLI to show evpn self-originated routes
    "show bgp l2vpn evpn route [detail] [type <ead|macip|multicast|es|prefix|1|2|3|4|5>] self-originate [json]"

Signed-off-by: Karl Quan <kquan@nvidia.com>
2023-02-15 14:14:28 -08:00
Philippe Guibert fa566a94af bgpd: store the route-distinguisher from config as a string
The route-distinguisher string can be expressed in different
ways when the AS number is part of the RD. And the configured
string value has to be kept intact.
The following vty commands store the string value internally:
- router bgp / address-family ipv4 unicast / rd vpn export <>
- router bgp / address-family l2vpn evpn / rd <>
- router bgp / address-family l2vpn evpn / vni <> / rd <>

The vty commands where RD is configured in the below places is
not considered:
- router bgp / rfapi related commands
- router bgp / address-family xxx xxx / network .. rd <>

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10 10:27:23 +01:00
Philippe Guibert 4a8cd6ad7f bgpd: support for as notation format for route distinguisher
RD may be built based on an AS number. Like for the AS, the RD
may use the AS notation. The two below examples can illustrate:

RD 1.1:20 stands for an AS4B:NN RD with AS4B=65536 in dot format.
RD 0.1:20 stands for an AS2B:NNNN RD with AS2B=0.1 in dot+ format.

This commit adds the asnotation mode to prefix_rd2str() API so as
to pick up the relevant display.

Two new printfrr extensions are available to display the RD with
the two above display methods.
- The pRDD extension stands for dot asnotation format
- The pRDE extension stands for dot+ asnotation format.
- The pRD extension has been renamed to pRDP extension

The code is changed each time '%pRD' printf extension is called.
Possibly, the asnotation may change the output, then a macro defines
the asnotation mode to use. A side effect of forging the mode to
use is that the string could not be concatenated with other strings
in vty_out and snprintfrr. Those functions have been called multiple
times. When zlog_debug needs to display the RD with some other string,
the prefix_rd2str() old API is used instead of the printf extension.

Some code has been kept untouched:
- code related to running-config. Actually, wherever an RD is displayed,
its configured name should be dumped.
- bgp rfapi code
- bgp evpn multihoming code (partially done), since the logic is
missing to get the asnotation of 'struct bgp_evpn_es'.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10 10:27:23 +01:00
Philippe Guibert e84c7c12f2 bgpd: modify bgp as number output
A json AS number API is created in order to output a
given AS number. In order to keep backward compatibility,
if the as-notation uses a number, then the json is encoded
as an integer, otherwise the encoding will be a string.

For what is not relevant to running-configuration, the
as-notation mode is the one used for the BGP instance.

Also, the vty completion gets the configured 'as_pretty'
string value, when an user wants to get the available
BGP instances.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10 10:27:23 +01:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
anlan_cs 432ff4b036 bgpd: fix use-after-free crash for evpn
```
anlan(config-router-af)# vni 33
anlan(config-router-af-vni)# route-target both 44:55
anlan(config-router-af-vni)# no route-target both 44:55
vtysh: error reading from bgpd: Resource temporarily unavailable (11)Warning: closing connection to bgpd because of an I/O error!
```

When `bgp_evpn_vni_rt_cmd` deals with "both" type, it wrongly created
only one node ( should be two nodes ) for lists of both `vpn->import_rtl` and
`vpn->export_rtl`.  At this time, the two lists are already wrong.

In `no route-target both RT`, it will free the single node from lists of both
`vpn->import_rtl` and `vpn->export_rtl`.  After freed from `vpn->import_rtl`,
it is "use-after-free" at the time of freeing it from `vpn->export_rtl`.
It causes crash sometimes, or other unexpected behaviours.

This issue is introduced by commit `3b7e8d`, which have adjusted both
`bgp_evpn_vni_rt_cmd` and `bgp_evpn_vrf_rt_cmd`.

Since `bgp_evpn_vrf_rt_cmd/no_bgp_evpn_vrf_rt_cmd` works well again
unintentionally with commit `7022da`, only `bgp_evpn_vni_rt_cmd` needs to
modify - add two nodes for "both" type and some explicit comments for this
special case of "both" type.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-02-06 21:39:22 +08:00
Donald Sharp 2d4460de6f bgpd: Convert evpn output to not pretty print json
Commit: 3cdb03fba7
changed the vty_json output to not be pretty printing.
The previous commit in the tree added vty_json_no_pretty
let's use that instead

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-02-02 10:42:21 -05:00
Chirag Shah 3cdb03fba7 bgpd: evpn route detail json display non prett
For BGP evpn route table detail json to use
non pretty form of display.

Problem:
In scaled evpn route table detail json dump
occupies high resources (CPU + memory) of the system.
In high scale evpn route dump using pretty form
hogs CPU for a while which can trigger watchfrr
to kill bgpd.

Solution:
Avoid pretty JSON print for detail version dump

Signed-off-by: Chirag Shah <chirag@nvidia.com>
2023-01-23 22:25:12 -08:00
Louis Scalbert 0adc5bbb21 bgpd: fix show bgp all with evpn
Fix crash on "show bgp all" when BGP EVPN is set.

> #0  raise (sig=11) at ../sysdeps/unix/sysv/linux/raise.c:50
> #1  0x00007fdfe03cf53c in core_handler (signo=11, siginfo=0x7ffdebbffe30, context=0x7ffdebbffd00) at lib/sigevent.c:261
> #2  <signal handler called>
> #3  0x00000000004d4fec in bgp_attr_get_community (attr=0x41) at bgpd/bgp_attr.h:553
> #4  0x00000000004eee84 in bgp_show_table (vty=0x1a790d0, bgp=0x19d0a00, safi=SAFI_EVPN, table=0x19f6010, type=bgp_show_type_normal, output_arg=0x0, rd=0x0, is_last=1, output_cum=0x0,
>     total_cum=0x0, json_header_depth=0x7ffdebc00bf8, show_flags=4, rpki_target_state=RPKI_NOT_BEING_USED) at bgpd/bgp_route.c:11329
> #5  0x00000000004f7765 in bgp_show (vty=0x1a790d0, bgp=0x19d0a00, afi=AFI_L2VPN, safi=SAFI_EVPN, type=bgp_show_type_normal, output_arg=0x0, show_flags=4,
>     rpki_target_state=RPKI_NOT_BEING_USED) at bgpd/bgp_route.c:11814
> #6  0x00000000004fb53b in show_ip_bgp_magic (self=0x6752b0 <show_ip_bgp_cmd>, vty=0x1a790d0, argc=3, argv=0x19cb050, viewvrfname=0x0, all=0x1395390 "all", aa_nn=0x0, community_list=0,
>     community_list_str=0x0, community_list_name=0x0, as_path_filter_name=0x0, prefix_list=0x0, accesslist_name=0x0, rmap_name=0x0, version=0, version_str=0x0, alias_name=0x0,
>     orr_group_name=0x0, detail_routes=0x0, uj=0x0, detail_json=0x0, wide=0x0) at bgpd/bgp_route.c:13040
> #7  0x00000000004fa322 in show_ip_bgp (self=0x6752b0 <show_ip_bgp_cmd>, vty=0x1a790d0, argc=3, argv=0x19cb050) at ./bgpd/bgp_route_clippy.c:519
> #8  0x00007fdfe033ccc8 in cmd_execute_command_real (vline=0x19c9300, filter=FILTER_RELAXED, vty=0x1a790d0, cmd=0x0, up_level=0) at lib/command.c:996
> #9  0x00007fdfe033c739 in cmd_execute_command (vline=0x19c9300, vty=0x1a790d0, cmd=0x0, vtysh=0) at lib/command.c:1056
> #10 0x00007fdfe033cdf5 in cmd_execute (vty=0x1a790d0, cmd=0x19c9eb0 "show bgp all", matched=0x0, vtysh=0) at lib/command.c:1223
> #11 0x00007fdfe03f65c6 in vty_command (vty=0x1a790d0, buf=0x19c9eb0 "show bgp all") at lib/vty.c:486
> #12 0x00007fdfe03f603b in vty_execute (vty=0x1a790d0) at lib/vty.c:1249
> #13 0x00007fdfe03f533b in vtysh_read (thread=0x7ffdebc03838) at lib/vty.c:2148
> #14 0x00007fdfe03e815d in thread_call (thread=0x7ffdebc03838) at lib/thread.c:2006
> #15 0x00007fdfe0379b54 in frr_run (master=0x1246880) at lib/libfrr.c:1198
> #16 0x000000000042b2a8 in main (argc=7, argv=0x7ffdebc03af8) at bgpd/bgp_main.c:520

Link: https://github.com/FRRouting/frr/issues/12576
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-29 17:05:01 +01:00
Donald Sharp 0fce20b808
Merge pull request #12339 from anlancs/fix/bgpd-null-show
bgpd: fix null pointer dereference
2022-12-06 14:11:47 -05:00
Donatas Abraitis 073801481b bgpd: inet_ntop() adjustments
Use %pI4/%pI6 where possible, otherwise at least atjust stack buffer sizes
for inet_ntop() calls.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-29 17:36:13 +02:00
anlan_cs f3a88e7272 bgpd: fix null pointer dereference
It is possible there is no ip address in type2 prefix, that leads to crash in
`build_evpn_type2_prefix()`.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-11-18 22:06:37 +08:00
Donatas Abraitis f8d69be43f
Merge pull request #12081 from sworleys/EMM-upstream
Rework of Various Handling in EVPN for Extended Mac Mobility
2022-11-17 16:46:58 +02:00
Donald Sharp 3e85fb3373
Merge pull request #12244 from anlancs/fix/bgpd-evpn-leak-l3rt
bgpd: avoid possible memleak
2022-11-04 11:59:32 -04:00
anlan_cs ed8862ad30 bgpd: avoid possible memleak
In the case of without ':' in `ecom_str`, memleak on this `ecom_str` will
occur. Just free `ecom_str` for this case.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-11-03 21:21:14 +08:00
Donald Sharp d7cde18c63
Merge pull request #12196 from opensourcerouting/xref-vtysh
*: rewrite `extract.pl` using `xref` infra
2022-11-03 08:54:09 -04:00
Stephen Worley d950d2246d bgpd: use vty_json() in show bpg vni json output
Use vty_json() in show bgp vni json output.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
2022-11-01 14:54:11 -04:00
Stephen Worley 339af96e38 bgpd: vni_t is uint32_t so print it as such in vty
vni_t is a uint32_t so print is as such in vty output.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
2022-11-01 14:33:36 -04:00
David Lamparter 89cb86aeb0 build, vtysh: extract vtysh commands from .xref
Rather than running selected source files through the preprocessor and a
bunch of perl regex'ing to get the list of all DEFUNs, use the data
collected in frr.xref.

This not only eliminates issues we've been having with preprocessor
failures due to nonexistent header files, but is also much faster.
Where extract.pl would take 5s, this now finishes in 0.2s.  And since
this is a non-parallelizable build step towards the end of the build
(dependent on a lot of other things being done already), the speedup is
actually noticeable.

Also files containing CLI no longer need to be listed in `vtysh_scan`
since the .xref data covers everything.  `#ifndef VTYSH_EXTRACT_PL`
checks are equally obsolete.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-10-26 17:12:34 +01:00
Russ White 5f37d597e8
Merge pull request #12166 from anlancs/fix/bgpd-wildcard
bgpd: return failure for wildcard ERT
2022-10-25 11:34:38 -04:00