Commit Graph

1607 Commits

Author SHA1 Message Date
Donald Sharp
42778d2a3a
Merge pull request #12467 from opensourcerouting/fix/advertised_routes_json_naming
bgpd: Deprecate `bgpStatusCodes` and `bgpOriginCodes`
2022-12-09 11:54:13 -05:00
Donatas Abraitis
dd426a51e3 bgpd: Deprecate bgpStatusCodes and bgpOriginCodes
```
donatas-pc# sh ip bgp neighbors 192.168.10.124 advertised-routes json
{
  "bgpTableVersion":11,
  "bgpLocalRouterId":"192.168.10.17",
  "defaultLocPrf":100,
  "localAS":65002,
  "bgpStatusCodes":{
    "suppressed":"s",
    "damped":"d",
    "history":"h",
    "valid":"*",
    "best":">",
    "multipath":"=",
    "internal":"i",
    "ribFailure":"r",
    "stale":"S",
    "removed":"R"
  },
  "bgpOriginCodes":{
    "igp":"i",
    "egp":"e",
    "incomplete":"?"
  },
  "advertisedRoutes":{
    "200.200.200.200\/32":{
      "addrPrefix":"200.200.200.200",
      "prefixLen":32,
      "network":"200.200.200.200\/32",
      "nextHopGlobal":"2a02:4780:abc::2",
      "weight":0,
      "path":"65001",
      "bgpOriginCode":"?",
      "origin":"incomplete", <<<<<<<
      "valid":true, <<<<<<<<
      "best":true,  <<<<<<<<
      "appliedStatusSymbols":{
        "*":true,
        ">":true
      }
    }
  },
  "totalPrefixCounter":1,
  "filteredPrefixCounter":0
}
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-12-08 15:57:14 +02:00
Donatas Abraitis
65565c9a3f bgpd: totalPrefixCounter incorectly shows sent prefix count
Using: show bgp ipv4 unicast neighbors 192.168.12.2 advertised-routes json

Before:

```
  "bgpOriginatingDefaultNetwork":"0.0.0.0\/0",
  "advertisedRoutes":{
    "192.168.12.0\/24":{
      "addrPrefix":"192.168.12.0",
      "prefixLen":24,
      "network":"192.168.12.0\/24",
      "nextHop":"0.0.0.0",
      "metric":0,
      "weight":32768,
      "path":"",
      "bgpOriginCode":"?",
      "appliedStatusSymbols":{
        "*":true,
        ">":true
      }
    }
  },
  "totalPrefixCounter":1,
  "filteredPrefixCounter":0
```

After:

```
  "bgpOriginatingDefaultNetwork":"0.0.0.0\/0",
  "advertisedRoutes":{
    "192.168.12.0\/24":{
      "addrPrefix":"192.168.12.0",
      "prefixLen":24,
      "network":"192.168.12.0\/24",
      "nextHop":"0.0.0.0",
      "metric":0,
      "weight":32768,
      "path":"",
      "bgpOriginCode":"?",
      "appliedStatusSymbols":{
        "*":true,
        ">":true
      }
    }
  },
  "totalPrefixCounter":2,
  "filteredPrefixCounter":0
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-12-07 23:36:00 +02:00
Donald Sharp
1b97fa9976
Merge pull request #12456 from opensourcerouting/fix/bgpd_labeled_unicast_rr_addpath
bgpd: Labeled unicast fixes for addpath capability
2022-12-07 08:03:59 -05:00
Donatas Abraitis
8ccee4b8cc bgpd: Adopt addpath functionality for labeled-unicast
The same as for RIB, labeled-unicast allocations should live in
unicast space.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-12-06 21:39:15 +02:00
Donatas Abraitis
4d65410c54 bgpd: Show in JSON if the advertised path is multipath
```
  "advertisedRoutes":{
    "10.0.0.1\/32":{
      "addrPrefix":"10.0.0.1",
      "prefixLen":32,
      "network":"10.0.0.1\/32",
      "nextHop":"0.0.0.0",
      "weight":0,
      "path":"65001",
      "bgpOriginCode":"?",
      "appliedStatusSymbols":{
        "*":true,
        ">":true,
        "=":true
      }
    }
  },
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-12-06 21:39:14 +02:00
Russ White
17ccfbb6c2
Merge pull request #12322 from fdumontet6WIND/confed_num
bgp:  fix case where confederation id same as member-as
2022-12-06 08:59:44 -05:00
Donatas Abraitis
146c574ba6 bgpd: Fix unaligned output of advertised-routes, bestpath-routes, etc.
This commit eaeba5e868 changed a bit a formatting,
but this part was missed, let's fix it.

An example before the patch:

```
r3# sh ip bgp ipv4 labeled-unicast neighbors 192.168.34.4 advertised-routes
BGP table version is 3, local router ID is 192.168.34.3, vrf id 0
Default local pref 100, local AS 65003
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          Next Hop            Metric LocPrf Weight Path
*> 10.0.0.1/32      0.0.0.0                                0 65001 ?

Total number of prefixes 1
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-12-02 10:39:20 +02:00
Donald Sharp
0ec0fee279
Merge pull request #12418 from opensourcerouting/fix/tests_for_while_true
Fix old tests with `while true`
2022-12-01 11:00:23 -05:00
mobash-rasool
14a6791256
Merge pull request #12416 from opensourcerouting/fix/inet_ntop
bgpd: inet_ntop() adjustments
2022-11-30 23:57:11 +05:30
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
Donatas Abraitis
b381ed97a6 bgpd: Adjust received prefix count only when we validate the nexthop
bgp_pcount_adjust() is called only when calling bgp_path_info_set_flag().

Before this patch the pcount is not advanced before checking for overflow.

Additionally, print:

```
[RZMGQ-A03CG] 192.168.255.1(r1) rcvd UPDATE about 172.16.255.254/32 IPv4 unicast -- DENIED due to: maximum-prefix overflow
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-29 17:02:41 +02:00
Russ White
dd6e0bc0cc
Merge pull request #12329 from opensourcerouting/feature/graceful-shutdown_per_peer
bgpd: Implement graceful-shutdown command per neighbor
2022-11-29 08:47:20 -05:00
Francois Dumontet
b0a8f709a5 bgp: fix case where confederation id same as member-as
currently the following configuration

dut:

!
interface ntfp2
 ip router isis 1
!
router bgp 200
 no bgp ebgp-requires-policy
 bgp confederation identifier 300
 bgp confederation peers 300
 neighbor 192.168.1.1 remote-as 100
 neighbor 192.168.2.2 remote-as 300
 !
 address-family ipv4 unicast
  neighbor 192.168.2.2 default-originate
 exit-address-family
!
router isis 1
 is-type level-2-only
 net 49.0001.0002.0002.0002.00
 redistribute ipv4 connected level-2
!
end

router:

!
interface ntfp2
 ip router isis 1
 isis circuit-type level-2-only
!
router bgp 300
 no bgp ebgp-requires-policy
 bgp confederation identifier 300
 bgp confederation peers 200
 neighbor 192.168.2.1 remote-as 200
 neighbor 192.168.3.2 remote-as 400
 !
 address-family ipv4 unicast
  network 3.3.3.0/24
 exit-address-family
!
router isis 1
 is-type level-2-only
 net 49.0001.0003.0003.0003.00
 redistribute ipv4 connected level-2
!
end

on dut result of show bgp ipv4 unicast command is:
show bgp ipv4 unicast

  BGP table version is 1, local router ID is 192.168.2.1, vrf id 0
  Default local pref 100, local AS 200
  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          Next Hop            Metric LocPrf Weight Path
  *> 1.1.1.0/24       192.168.1.1              0             0 100 i

instead of

sho bgp ipv4 unicast
BGP table version is 3, local router ID is 192.168.2.1, vrf id 0
Default local pref 100, local AS 200
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          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.0/24       192.168.1.1              0             0 100 i
*> 3.3.3.0/24       192.168.2.2              0    100      0 (300) i
*> 4.4.4.0/24       192.168.3.2              0    100      0 (300) 400 i

Displayed  3 routes and 3 total paths

According to RFC 5065:the usage of one of the member AS number as the
confederation identifier is not forbidden.

fixes are the following

in bgp_route.c:
in bgp_update remove the test for presence of confederation id in
as_path since, this case is allowed;

in bgp_vty.c
bgp_confederation_peers, remove the test on peer as value

in bgpd.c
bgp_confederation_peers_add
remove the test on peer as value
invert the order of setting peer->sort value and peer->local_as,
since peer->sort is depending from current peer->local_as value

bgp_confederation_peers_remove
invert the order of setting peer->sort value and peer->local_as,
since peer->sort is depending from current peer->local_as value

Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
2022-11-25 15:28:32 +01:00
Stephen Worley
c8b92cd80a
Merge pull request #12340 from opensourcerouting/fix/rfc5549_vpn_set_ip_nexthop
bgpd: Allow overriding MPLS VPN next-hops via route-maps
2022-11-22 11:41:48 -05:00
vivek
9e8a096b73 bgpd: Remove unnecessary debug log
Signed-off-by: Vivek Venkatraman <vivek@nvidia.com>
2022-11-20 22:45:12 -05:00
Donatas Abraitis
0224b3296c bgpd: Print empty JSON {} if no entries under show bgp ipv4 vpn json
Before this, the application fails that is parsing JSON (expecting).

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-18 16:17:15 +02:00
Donatas Abraitis
6cf8a4bf42 bgpd: Print prefix in logs messages with BGP_PATH_ANNC_NH_SELF
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-18 16:17:15 +02: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
Donatas Abraitis
4f770cf1d2 bgpd: Implement graceful-shutdown command per neighbor
We already have a global knob for graceful-shutdown, but it's handy having
per neighbor knob as well.

Especially when a single neighbor needs to be restarted/shutdown gracefuly.

We can do this route-maps, but this is a faster/cleaner way doing the same
for an operator.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-16 21:42:21 +02:00
Philippe Guibert
f874552557 bgpd: authorise to select bgp self peer prefix on rr case
This commit addresses an issue that happens when using bgp
peering with a rr client, with a received prefix which is the
local ip address of the bgp session.

When using bgp ipv4 unicast session, the local prefix is
received by a peer, and finds out that the proposed prefix
and its next-hop are the same. To avoid a route loop locally,
no nexthop entry is referenced for that prefix, and the route
will not be selected.

When the received peer is a route reflector, the prefix has
to be selected, even if the route can not be installed locally.

Fixes: ("fb8ae704615c") bgpd: prevent routes loop through itself

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2022-11-15 09:49:38 +01:00
Donald Sharp
89c73443e8 bgpd: Make calling bgp_soft_reconfig_in consistent
Not all places were checking to see if soft reconfiguration
was turned on before calling into it to do all that work.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-11-08 08:11:52 -05: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
6012963ecd bgpd: use CHECK_FLAG for es_flags in route detail
Use CHECK_FLAG for es_flags in vtysh output for route
detail.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
2022-11-01 14:26:54 -04:00
Russ White
a5dac02901
Merge pull request #12114 from opensourcerouting/feature/bgp_aigp_attribute
bgpd: Implement AIGP
2022-10-31 11:24:43 -04:00
Trey Aspelund
8c4d4624d2 bgpd: Check for IP-format Site-of-Origin
When deciding whether to apply "neighbor soo" filtering towards a peer,
we were only looking for SoO ecoms that use either AS or AS4 encoding.
This makes sure we also check for IPv4 encoding, since we allow a user
to configure that encoding style against the peer.

Config:
```
router bgp 1
 address-family ipv4 unicast
  network 100.64.0.2/32 route-map soo-foo
  neighbor 192.168.122.12 soo 3.3.3.3:20
 exit-address-family
!
route-map soo-foo permit 10
 set extcommunity soo 3.3.3.3:20
exit
```

Before:
```
ub20# show ip bgp neighbors 192.168.122.12 advertised-routes
BGP table version is 5, local router ID is 100.64.0.222, vrf id 0
Default local pref 100, local AS 1
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          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.2/32       0.0.0.0                  0    100  32768 i
*> 100.64.0.2/32    0.0.0.0                  0    100  32768 i

Total number of prefixes 2
```

After:
```
ub20# show ip bgp neighbors 192.168.122.12 advertised-routes
BGP table version is 5, local router ID is 100.64.0.222, vrf id 0
Default local pref 100, local AS 1
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          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.2/32       0.0.0.0                  0    100  32768 i

Total number of prefixes 1
```

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2022-10-26 21:09:55 +00: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
659800f3c1
Merge pull request #12199 from tewok/frr-routes-table-columns
bgpd: fixed misaligned columns in BGP routes table
2022-10-26 09:48:41 -04:00
Donatas Abraitis
97a52c82a5 bgpd: Implement Accumulated IGP Metric Attribute for BGP
https://www.rfc-editor.org/rfc/rfc7311.html

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-10-26 11:26:57 +03:00
Wayne Morrison
eaeba5e868 bgpd: fixed misaligned columns in BGP routes table
Column headers in BGP routes table are not aligned with data when
RPKI status is available.  This was fixed to insert a space at the
beginning of the header and at the beginning of lines that do not
have RPKI status.

This fix requires that several testing templates be adjusted to
match the new output.

Signed-off-by: Wayne Morrison <wmorrison@netgate.com>
2022-10-25 10:45:35 -04:00
Mark Stapp
b2ac1d0d4f bgpd: fix config of allowas_in; add to show output
Ensure that un-configuring allowas-in for a peer or group
clears the related flags and integer value. Tighten the use
of the integer counter so that it's only used when the config
flag is set. Add show output if allowas-in is enabled.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2022-10-24 12:50:17 -04:00
Donatas Abraitis
46dbf9d0c0 bgpd: Implement ACCEPT_OWN extended community
TL;DR: rfc7611.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-10-12 17:48:43 +03:00
Madhuri Kuruganti
70cd87ca02 bgpd: optimal router reflection cli and fsm changes
Signed-off-by: Madhuri Kuruganti <maduri111@gmail.com>
2022-10-12 13:43:55 +05:30
Stephen Worley
100290e449 bgpd: fix vni table output broken by 8304dabfab
Fix vni table output broken by 8304dabfab

The "Imported from" output was not getting delimitted by a newline
after the mentioned commit. This fixes that and retains the output
wanted by the original change.

Before:

'''
  Route [2]:[0]:[48]:[b6:3a:cc:d5:a1:cd]:[128]:[fe80::b43a:ccff:fed5:a1cd] VNI 30/10  Imported from 2.2.2.2:4:[2]:[0]:[48]:[b6:3a:cc:d5:a1:cd]:[128]:[fe80::b43a:ccff:fed5:a1cd], VNI 30/10

  2
    2.2.2.2(alfred) from alfred(veth1) (2.2.2.2)
      Origin IGP, valid, external, bestpath-from-AS 2, best (First path received)
      Extended Community: RT:2:30 ET:8
      Last update: Fri Oct  7 16:04:59 2022
'''

After:

'''
  Route [2]:[0]:[48]:[b2:cf:96:70:4f:b6]:[128]:[fe80::b0cf:96ff:fe70:4fb6] VNI 30/10
  Imported from 2.2.2.2:4:[2]:[0]:[48]:[b2:cf:96:70:4f:b6]:[128]:[fe80::b0cf:96ff:fe70:4fb6], VNI 30/10
  2
    2.2.2.2(alfred) from alfred(veth1) (2.2.2.2)
      Origin IGP, valid, external, bestpath-from-AS 2, best (First path received)
      Extended Community: RT:2:30 ET:8
      Last update: Fri Oct  7 17:02:28 2022
'''

Signed-off-by: Stephen Worley <sworley@nvidia.com>
2022-10-11 16:18:21 -04:00
Stephen Worley
34c7f35f02 bgpd: rework VNI table for type2/macip routes
Use the IP addr of type2/macip routes only for the hash/key
of the VNI table and carry the MAC in a path_info_extra attribute.

There is exists situations that can be hit during extended MAC mobility events
where two MACs could be pointing to the same IP in our global table. It
is requires very specific timings.

When that happens, BPG would (because we key'd on both MAC and IP)
install both into it's VNI table as separate entries, but zebra only
knows/needs to know about a single IP -> MAC relationship for it's VNI
table's type2 routes. So it was compleletly undeterministic which one
zebra would end up with in these timing situations.

With these changes, we move BGP's VNI table to key'd the same as Zebra's
and now a single IP will have multiple path_info's with a path_info_extra
that is carrying the MAC info for each path.

BGP will then run best path to deterministically decide which one to send to
zebra during the occasions where there exist's two possible MACs.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
2022-10-11 15:18:39 -04:00
Your Name
1857760c1e bgpd: fix display bgp large-community exact-match
Before patch:
frr# show bgp large-community 1:1:1 exact-match
% Large-community malformed

After patch:
frr# show bgp large-community 1:1:1 exact-match

Signed-off-by: Dmitrii Turlupov <dturlupov@factor-ts.ru>
2022-10-10 13:51:27 +03:00
Donald Sharp
860ad3f91e bgpd: Remove unnecessary check for pi and setting type and sub-type
There is code that sets the pi based upon matching it against
the same peer.  In this code the type and sub-type are also
compared to the passed in type and sub-type.  Let's just use
type and sub-type as that if we have a pi we know type and sub-type
are already correct.  This should also make the first iteration
work correctly when the pi has not been created yet when we call
the martian_update function.bgpd: Remove unnecessary check for pi and setting type and sub-type

There is code that sets the pi based upon matching it against
the same peer.  In this code the type and sub-type are also
compared to the passed in type and sub-type.  Let's just use
type and sub-type as that if we have a pi we know type and sub-type
are already correct.  This should also make the first iteration
work correctly when the pi has not been created yet when we call
the martian_update function.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-10-06 20:17:26 -04:00
Donatas Abraitis
95ba22d531 bgpd: Show why the prefix is inaccessible in show commands
```
donatas-pc# show ip bgp 100.100.100.0/24 longer-prefixes
BGP table version is 13, local router ID is 10.10.10.10, vrf id 0
Default local pref 100, local AS 65000
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          Next Hop            Metric LocPrf Weight Path
   100.100.100.0/24 0.0.0.0                  0         32768 i

Displayed  1 routes and 15 total paths
donatas-pc# show ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 0
Paths: (1 available, no best path)
  Not advertised to any peer
  Local
    0.0.0.0 (inaccessible, import-check enabled) from 0.0.0.0 (10.10.10.10)
      Origin IGP, metric 0, weight 32768, invalid, sourced, local
      Last update: Tue Oct  4 11:31:44 2022
donatas-pc# show ip bgp 100.100.100.0/24 json
{
  "prefix":"100.100.100.0\/24",
  "version":0,
  "paths":[
    {
      "aspath":{
        "string":"Local",
        "segments":[
        ],
        "length":0
      },
      "origin":"IGP",
      "metric":0,
      "weight":32768,
      "valid":false,
      "version":0,
      "sourced":true,
      "local":true,
      "lastUpdate":{
        "epoch":1664872304,
        "string":"Tue Oct  4 11:31:44 2022\n"
      },
      "nexthops":[
        {
          "ip":"0.0.0.0",
          "hostname":"donatas-pc",
          "afi":"ipv4",
          "accessible":false,
          "importCheckEnabled":true,
          "used":true
        }
      ],
      "peer":{
        "peerId":"0.0.0.0",
        "routerId":"10.10.10.10"
      }
    }
  ]
}
donatas-pc#
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-10-04 11:32:39 +03:00
Donatas Abraitis
58e111f65c bgpd: Print hostname for peer as well when marking as stale for route-refresh
Before:

```
2022/09/26 10:13:35.261 BGP: [QCZ1W-VKS36] 192.168.0.1(r0) sending REFRESH_REQ for afi/safi: IPv4/unicast
2022/09/26 10:13:35.262 BGP: [VF3QY-FP1PP] 192.168.0.1: route-refresh for IPv4/unicast, marking prefix 172.16.1.1/32 as stale
2022/09/26 10:13:35.262 BGP: [VF3QY-FP1PP] 192.168.0.1: route-refresh for IPv4/unicast, marking prefix 192.168.0.0/24 as stale
2022/09/26 10:13:35.262 BGP: [SDZS7-XVC4W] 192.168.0.1(r0) rcvd route-refresh (BoRR) for IPv4/unicast, triggering timer for 360 seconds
2022/09/26 10:13:35.362 BGP: [Y6XKR-PF89P] 192.168.0.1(r0) rcvd route-refresh (EoRR) for IPv4/unicast, stopping BoRR timer
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-09-26 11:13:40 +03:00
Donatas Abraitis
c4f64ea94d bgpd: Use %pRD for prefix_rd2str()
Convert a bunch of prefix_rd2str() for json/vty stuff.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-09-22 13:12:11 +03:00
Donatas Abraitis
bbc5210686 bgpd: Don't forget bgp_dest_unlock_node before return
Before returning an error, unlock bgp dest which is locked by
bgp_node_lookup()/bgp_node_get().

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-09-16 16:16:01 +03:00
Russ White
7fa5e07b1c
Merge pull request #11899 from opensourcerouting/feature/route_validation_extended_community
bgpd: Implement Origin Validation State via extended communities
2022-09-13 11:30:54 -04:00
Donald Sharp
ed11f561bc
Merge pull request #11923 from opensourcerouting/fix/aggregate-address-matching-MED
bgpd: Fix aggregate-address summary-only matching-MED-only
2022-09-12 10:31:01 -04:00
Donatas Abraitis
bbe7bc46f1 bgpd: Fix memory leak for as-override
==536197== 400 (160 direct, 240 indirect) bytes in 4 blocks are definitely lost in loss record 19 of 21
==536197==    at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==536197==    by 0x491C753: qcalloc (memory.c:116)
==536197==    by 0x303FA9: aspath_dup (bgp_aspath.c:698)
==536197==    by 0x304B2A: aspath_replace_specific_asn (bgp_aspath.c:1219)
==536197==    by 0x256840: bgp_peer_as_override (bgp_route.c:1781)
==536197==    by 0x256840: subgroup_announce_check (bgp_route.c:2216)
==536197==    by 0x258345: subgroup_process_announce_selected (bgp_route.c:2804)
==536197==    by 0x27F2CA: group_announce_route_walkcb (bgp_updgrp_adv.c:199)
==536197==    by 0x4905A51: hash_walk (hash.c:285)
==536197==    by 0x27E8D1: update_group_af_walk (bgp_updgrp.c:1866)
==536197==    by 0x2809D3: group_announce_route (bgp_updgrp_adv.c:1022)
==536197==    by 0x257DC4: bgp_process_main_one (bgp_route.c:3189)
==536197==    by 0x257DC4: bgp_process_main_one (bgp_route.c:2975)
==536197==    by 0x2581F7: bgp_process_wq (bgp_route.c:3330)
==536197==    by 0x4961787: work_queue_run (workqueue.c:285)
==536197==    by 0x4957745: thread_call (thread.c:2008)
==536197==    by 0x4910B77: frr_run (libfrr.c:1198)
==536197==    by 0x1ED6AC: main (bgp_main.c:520)

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-09-10 06:56:01 +03:00
Donald Sharp
a50c13d4c0
Merge pull request #11909 from opensourcerouting/fix/a_couple_nits
bgpd: bgp_dest_unlock_node fixes
2022-09-09 07:55:13 -04:00
Donatas Abraitis
f66624f5c0 bgpd: Fix aggregate-address summary-only matching-MED-only
Before it worked only when configured initially via CLI. Later, when we
receive a new route, that should match a decent MED, we just skip it, because
MED mismatch is not recalculated.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-09-07 14:39:19 +03:00
Donatas Abraitis
8c0044f323 bgpd: Unlock bgp_dest for some more cases
bgp_static_set()
bgp_aggregate_install()

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-09-06 12:51:35 +03:00
Donatas Abraitis
636632c32f bgpd: Reuse prep_for_rmap_apply() when applying route-map for show cmd
Include extra path attributes.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-09-06 12:51:34 +03:00
Philippe Guibert
6fc4929e09 bgpd: associate appropriate family for redistributed connected addresses
When redistributing connected addresses, the address family has
to be figured out. The calculation was not done, the next-hop
address length was not set, and as consequence, the nexthop
is displayed like if it was an ipv6 address, which is wrong for
ipv4 addresses.

Calculate the family for connected addresses.
Change the topotests accordingly.

Fixes: ("7226bc40d606") bgpd: ignore NEXT_HOP for MP_REACH_NLRI

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2022-09-05 22:26:33 +02:00
Philippe Guibert
4cd690ae4d bgpd: add 'mpls bgp forwarding' to ease mpls vpn ebgp peering
RFC4364 describes peerings between multiple AS domains, to ease
the continuity of VPN services across multiple SPs. This commit
implements a sub-set of IETF option b) described in chapter 10 b.

The ASBR to ASBR approach is taken, with an EBGP peering between
the two routers. The EBGP peering must be directly connected to
the outgoing interface used. In those conditions, the next hop
is directly connected, and there is no need to have a transport
label to convey the VPN label. A new vty command is added on a
per interface basis:

This command if enabled, will permit to convey BGP VPN labels
without any transport labels (i.e. with implicit-null label).

restriction:
this command is used only for EBGP directly connected peerings.
Other use cases are not covered.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2022-09-05 22:26:33 +02:00
Donatas Abraitis
7b27cf7bbd bgpd: Add Origin Validation State extended community
```
spine1-debian-11# sh ip bgp 100.100.100.101/32
BGP routing table entry for 100.100.100.101/32, version 21
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Local
    fe80::ca5d:fd0d:cd8:1bb7 from eth3 (172.17.0.3)
    (fe80::ca5d:fd0d:cd8:1bb7) (used)
      Origin incomplete, metric 0, localpref 100, valid, internal, best (First path received)
      Extended Community: OVS:invalid
      Last update: Wed Aug 31 19:31:46 2022

spine1-debian-11# sh ip bgp 100.100.100.100/32
BGP routing table entry for 100.100.100.100/32, version 17
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Local
    fe80::ca5d:fd0d:cd8:1bb7 from eth3 (172.17.0.3)
    (fe80::ca5d:fd0d:cd8:1bb7) (used)
      Origin incomplete, metric 0, localpref 100, valid, internal, best (First path received)
      Extended Community: OVS:not-found
      Last update: Wed Aug 31 19:31:46 2022
spine1-debian-11#
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-09-04 21:23:59 +03:00
Russ White
d72c279d08
Merge pull request #11833 from opensourcerouting/feature/bgp_neighbor_soo
bgpd: Add `neighbor soo` command
2022-08-30 11:17:53 -04:00
Donatas Abraitis
511211bf56 bgpd: Convert prefix2str to %pFX
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-08-25 14:35:27 +03:00
Donatas Abraitis
2bf9780b26 bgpd: Do not print new line for EVPN CLI outputs if it's a JSON
Before:

```
$ vtysh -c 'show bgp l2vpn evpn route detail json'
<<<<<<<<<<<<<<<<<<<< empty line
<<<<<<<<<<<<<<<<<<<< empty line
<<<<<<<<<<<<<<<<<<<< empty line
<<<<<<<<<<<<<<<<<<<< empty line
{
	...
	"numPrefix":4,
	"numPaths":4 <<<<< four paths = four empty lines
}
```

Contain as much "empty lines" before the JSON string as the number
of paths displayed.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-08-25 13:15:27 +03:00
Donald Sharp
083ec940ab bgpd: Convert from bgp_clock() to monotime()
Let's convert to our actual library call instead
of using yet another abstraction that makes it fun
for people to switch daemons.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-08-24 08:23:40 -04:00
Donatas Abraitis
01da2d2691 bgpd: Add neighbor soo command
BGP SoO is a tag that is appended on BGP updates to allow a peer to mark
a particular peer as belonging to a particular site. In certain MPLS L3 VPN
configurations, the BGP AS-Path may not provide the granularity needed
prevent a loop in the control-plane. With this in mind, BGP SoO is designed
to fill this gap and prevent a routing loop that may occur.

If we configure for example, `neighbor soo 65000:1` at PEs, routes won't be
announced between CPEs if soo matches. This is especially needed when using
as-override or allowas-in.

Also, this is the automated way of the same behavior as configuring route-maps
for each peer like:

```
bgp extcommunity-list cpe permit soo 65000:1
!
route-map cpe permit 10
 set extcommunity soo 65000:1
...
route-map cpe deny 10
 match extcommunity cpe
route-map cpe permit 20
...
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-08-20 21:22:45 +03:00
Donatas Abraitis
a9f3f4f526 bgpd: Print peer's hostname for BGP (filtering) messages
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-08-19 12:55:37 +03:00
Donatas Abraitis
606d49a4ca bgpd: Change warning message when BGP community-list is not found
Before:

```
donatas-laptop# show bgp ipv4 unicast community-list testas
% testas is not a valid community-list name
donatas-laptop# con
donatas-laptop(config)# bgp community-list standard testas permit internet
donatas-laptop(config)# do show bgp ipv4 unicast community-list testas
donatas-laptop(config)#
```

`is not a valid community-list name` is a misleading warning message.

Doing the same for filter-list, access-list, prefix-list, route-map.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-08-16 09:32:36 +03:00
Quentin Young
0655090c6e bgpd: don't adv conditionally withdrawn routes
If we have conditional advertisement enabled, and conditionally withdrew
some prefixes, and then we do a 'clear bgp', those routes were getting
advertised again, and then withdrawn the next time the conditional
advertisement scanner executed.

When we go to advertise check the prefix against the conditional
advertisement status so we don't do that.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2022-08-11 10:58:17 -04:00
Trey Aspelund
7226bc40d6 bgpd: ignore NEXT_HOP for MP_REACH_NLRI
RFC 4760 states we SHOULD ignore the NEXT_HOP attribute for BGP Update
messages carrying only MP_REACH_NLRI attributes. Thus we should use the
Network Address of Next Hop field of the MP_REACH_NLRI as the nexthop.

Instead of always looking for BGP_ATTR_NEXT_HOP, this commit ensures:
1) we set mp_nexthop_len to BGP_ATTR_NHLEN_IPV4 for v4 bgp_static routes
2) we check mp_nexthop_len when choosing the nexthop to use for nht
3) we check mp_nexthop_len when choosing the nexthop to send to zebra
4) we check mp_nexthop_len when picking the nexthop to shown by vtysh

Reported-by: Binon Gorbutt <binon@aervivo.com>
Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2022-08-04 20:36:49 +00:00
Donatas Abraitis
42c9383767 bgpd: bgp_best_path_select_defer never returns negative
Just drop the test and convert to void.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-08-03 18:43:01 +03:00
Donatas Abraitis
ed12638288 bgpd: Add show bgp access-list command to filter routes by ACL
The same as with prefix-list/route-maps/etc.

```
donatas-pc# show ip access-list spine
ZEBRA:
Zebra IP access list spine
    seq 5 permit 200.200.200.200/32
BGP:
Zebra IP access list spine
    seq 5 permit 200.200.200.200/32
PIM:
Zebra IP access list spine
    seq 5 permit 200.200.200.200/32
BABELD:
Zebra IP access list spine
    seq 5 permit 200.200.200.200/32
donatas-pc# show bgp ipv4 unicast access-list
  ACCESSLIST_NAME  Access-list name
     spine
donatas-pc# show bgp ipv4 unicast access-list spine
BGP table version is 9, local router ID is 172.17.0.3, vrf id 0
Default local pref 100, local AS 1
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          Next Hop            Metric LocPrf Weight Path
*> 200.200.200.200/32
                    enp3s0                   0             0 65000 3456 ?

Displayed  1 routes and 10 total paths
donatas-pc#
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-08-03 12:58:14 +03:00
Donatas Abraitis
9bbdb4572d bgpd: Do not check if the whole as-path has target ASN when using as-override
as-override didn't work if the entire as-path is not a single ASN (as a target).

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-07-29 20:43:22 +03:00
Russ White
3bf3144517
Merge pull request #11523 from pguibert6WIND/bgp_no_retain
Bgp no retain
2022-07-26 08:50:59 -04:00
Donald Sharp
c3aaa89a44 bgpd: Convert thread_cancel to THREAD_OFF and use THREAD_ARG
Just convert all uses of thread_cancel to THREAD_OFF.  Additionally
use THREAD_ARG instead of t->arg to get the arguement.  Individual
files should never be accessing thread private data like this.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-21 08:30:49 -04:00
Donald Sharp
fa5806c318 bgpd: Remove various macros that overlap THREAD_OFF
Let's just use THREAD_OFF consistently in the code base
instead of each daemon having a special macro that needs to
be looked at and remembered what it does.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-21 08:27:36 -04:00
Donatas Abraitis
00e6edb97d bgpd: Add constants for some repetitive CLI strings
"Address Family\n"
"Address Family modifier\n"

Before:

```
donatas-laptop(config-router)# address-family ipv4
  <cr>
  flowspec         Address Family Modifier
  labeled-unicast  Address Family modifier
  multicast        Address Family modifier
  unicast          Address Family Modifier
  vpn              Address Family modifier
```

After:

```
donatas-laptop(config-router)# address-family
  ipv4   Address Family
  ipv6   Address Family
  l2vpn  Address Family
donatas-laptop(config-router)# address-family ipv4
  <cr>
  flowspec         Address Family modifier
  labeled-unicast  Address Family modifier
  multicast        Address Family modifier
  unicast          Address Family modifier
  vpn              Address Family modifier
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-07-18 10:12:57 +03:00
Philippe Guibert
a486300b26 bgpd: implement retain route-target all behaviour
A new command is available under SAFI_MPLS_VPN:

With this command, the BGP vpnvx prefixes received are
not kept, if there are no VRF interested in importing
those vpn entries.

A soft refresh is performed if there is a change of
configuration: retain cmd, vrf import settings, or
route-map change.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2022-07-18 08:57:19 +02:00
Donatas Abraitis
f646c17a43
Merge pull request #11426 from error2407/open_policy
bgpd: Add RFC9234 implementation
2022-06-27 09:57:29 +03:00
Eugene Bogomazov
5a78f2bcb0 bgpd: add AFI/SAFI check for RFC 9234
RFC 9234 mandates that role rules apply only to IPv4/IPv6 unicast bgp
sessions. If the OTC attribute appears in other sessions, it will remain
untouched.

Signed-off-by: Eugene Bogomazov <eb@qrator.net>
2022-06-22 13:34:51 +03:00
Donatas Abraitis
47e1288431 *: Replace sockunion2str => %pSU
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-21 13:34:56 +03:00
Donatas Abraitis
298ff7e357
Merge pull request #11284 from ordex/prefixlen_count
bgpd: Allow statistics gathering to give more data about prefix Lengths
2022-06-20 11:08:39 +03:00
Eugene Bogomazov
d864dd9eb1 bgpd: Add RFC9234 implementation
RFC9234 is a way to establish correct connection roles (Customer/
Provider, Peer or with RS) between bgp speakers. This patch:
- Add a new configuration/terminal option to set the appropriate local
role;
- Add a mechanism for checking used roles, implemented by exchanging
the corresponding capabilities in OPEN messages;
- Add strict mode to force other party to use this feature;
- Add basic support for a new transitive optional bgp attribute - OTC
(Only to Customer);
- Add logic for default setting OTC attribute and filtering routes with
this attribute by the edge speakers, if the appropriate conditions are
met;
- Add two test stands to check role negotiation and route filtering
during role usage.

Signed-off-by: Eugene Bogomazov <eb@qrator.net>
2022-06-17 13:14:46 +03:00
Donald Sharp
be9778a3c1
Merge pull request #11395 from opensourcerouting/fix/autocompete_for_rmap_bgp
*: Use autocomplete for route-maps under commands that require it
2022-06-14 10:48:36 -04:00
Russ White
b3a35b33c0
Merge pull request #11344 from opensourcerouting/feature/wrap_ipv4_unicast_valid
bgpd: Wrap IPV4_CLASS_DE into ipv4_unicast_valid() helper
2022-06-14 07:48:32 -04:00
Russ White
ab6fa0d2d2
Merge pull request #11343 from opensourcerouting/fix/local_preference_plus_minus_route_maps
bgpd: Initialize attr->local_pref to the configured default value
2022-06-14 06:53:08 -04:00
Donatas Abraitis
70dd370f5a *: Use autocomplete for route-maps under commands that require it
For example:

```
donatas-laptop# show bgp ipv4 unicast neighbors 127.0.0.2 advertised-routes route-map ?
  RMAP_NAME  Name of the route map
       testas2 testas

donatas-laptop(config)# router bgp
donatas-laptop(config-router)# address-family ipv4
donatas-laptop(config-router-af)# redistribute connected route-map ?
  RMAP_NAME  Pointer to route-map entries
       testas2 testas

donatas-laptop(config-router-af)# network 192.168.0.0/23 route-map ?
  RMAP_NAME  Name of the route map
       testas2 testas
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-13 21:00:51 +03:00
Donatas Abraitis
e24a6977ee bgpd: Wrap IPV4_CLASS_DE into ipv4_unicast_valid() helper
Linux kernel allows (FreeBSD/OpenBSD too) using reserved class E IP ranges.

This is a preparation commit that ease the global switch to allow/deny
class E IP ranges in FRR.

https://datatracker.ietf.org/doc/html/draft-chen-ati-adaptive-ipv4-address-space

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-13 20:44:52 +03:00
Donald Sharp
faa8c700e6
Merge pull request #11333 from opensourcerouting/fix/memory_leak_with_rmaps
bgpd: Fix memory leak when setting [l]community at egress
2022-06-13 08:27:24 -04:00
Jafar Al-Gharaibeh
d0911c6bdd
Merge pull request #11389 from ton31337/fix/some_codeql_fixes
bgpd: Minor warning fixes
2022-06-10 16:08:12 -05:00
Donatas Abraitis
0019e31c3b bgpd: Drop sockunion_vty_out() wrong definition
Probably leftover.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-10 12:53:10 +03:00
Antonio Quartulli
0747643e03
bgpd: Allow statistics gathering to give more data about prefix Lengths
When using json output for `show bgp statistics json` gather the
number of prefixes of each prefix Length.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
2022-06-09 21:02:11 +02:00
Donatas Abraitis
0f05ea43b0 bgpd: Initialize attr->local_pref to the configured default value
When we use network/redistribute local_preference is configured inproperly
when using route-maps something like:

```
network 100.100.100.100/32 route-map rm1
network 100.100.100.200/32 route-map rm2

route-map rm1 permit 10
 set local-preference +10
route-map rm2 permit 10
 set local-preference -10
```

Before:
```
root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.100/32 json' | jq '.paths[].locPrf'
10
root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.200/32 json' | jq '.paths[].locPrf'
0
```

After:
```
root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.100/32 json' | jq '.paths[].locPrf'
110
root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.200/32 json' | jq '.paths[].locPrf'
90
```

Set local-preference as the default value configured per BGP instance, but
do not set LOCAL_PREF flag by default.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-06 10:28:50 +03:00
Donatas Abraitis
a49e87d2d4 bgpd: Fix memory leak when setting [l]community at egress
```
==2209758== 7,791,480 (399,840 direct, 7,391,640 indirect) bytes in 9,996 blocks are definitely lost in loss record 102 of 103
==2209758==    at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2209758==    by 0x4EE264F: qcalloc (memory.c:116)
==2209758==    by 0x22E62A: lcommunity_new (bgp_lcommunity.c:42)
==2209758==    by 0x22E62A: lcommunity_dup (bgp_lcommunity.c:155)
==2209758==    by 0x26F28F: route_set_lcommunity (bgp_routemap.c:2382)
==2209758==    by 0x4EFF7EF: route_map_apply_ext (routemap.c:2663)
==2209758==    by 0x250B3D: subgroup_announce_check (bgp_route.c:2202)
==2209758==    by 0x27A195: subgroup_announce_table (bgp_updgrp_adv.c:690)
==2209758==    by 0x27A509: subgroup_coalesce_timer (bgp_updgrp_adv.c:332)
==2209758==    by 0x4F1C3FC: thread_call (thread.c:2002)
==2209758==    by 0x4ED6D67: frr_run (libfrr.c:1196)
==2209758==    by 0x1E921B: main (bgp_main.c:519)
```

To reproduce it's enough to have something like applied at egress:

```
route-map test permit 10
 on-match goto 15
 set large-community 20717:0:0 20717:1:1820 20717:1:3303 20717:1:4788 20717:1:5416 20717:1:5713 20717:1:6774 20717:1:8309 20717:1:8529 20717:1:8697 20717:1:8966 20717:1:9038 20717:1:9119 20717:1:9304 20717:1:9498 20717:1:12779 20717:1:12883 20717:1:13113 20717:1:14340 20717:1:14907 20717:1:15802 20717:1:16347 20717:1:16637 20717:1:18403 20717:1:20717 20717:1:20928 20717:1:21245 20717:1:25818 20717:1:28917 20717:1:30844 20717:1:30990 20717:1:31133 20717:1:35297 20717:1:35320 20717:1:35432 20717:1:35819 20717:1:35838 20717:1:36994 20717:1:37100 20717:1:37558 20717:1:37662 20717:1:39180 20717:1:39405 20717:1:41095 20717:1:43996 20717:1:45489 20717:1:45903 20717:1:47794 20717:1:51185 20717:1:51254 20717:1:58715 20717:1:59605 20717:1:60427 20717:1:62955 20717:1:63008 20717:1:63927 20717:1:64049 20717:1:132602 20717:1:198435 20717:1:205988 20717:1:208278 20717:1:327700
exit
!
route-map test deny 15
exit
!
```

On the other side doing:
```
spine1-debian-11# sharp install routes 100.100.100.1 nexthop 192.168.10.65 30
spine1-debian-11# sharp remove routes 100.100.100.1 30
spine1-debian-11# sharp install routes 100.100.100.1 nexthop 192.168.10.65 30
```

Before:

```
Large Community               :       66     40        2816       66      2816
Large Community value         :       66 variable     29728       66     29728
Large Community               :       96     40        4096       96      4096
Large Community value         :       96 variable     52048       96     52048
```

After:
```
Large Community               :       28     40        1152       29      1192
Large Community value         :       28 variable      1456       29      2200
Large Community               :       28     40        1152       29      1192
Large Community value         :       28 variable      1456       29      2200
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-02 13:36:13 +03:00
Donatas Abraitis
67f67ba481 bgpd: Drop label_ntop/label_pton functions
Start using mpls_lse_encode/mpls_lse_decode, that is endian-aware, because
we always use host-byte order, should use network-byte.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-01 16:45:22 +03:00
Donatas Abraitis
114fc22915 bgpd: Show a correct local AS for the advertised/bestpath routes
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-05-18 13:44:21 +03:00
Donald Sharp
e5b71bc69b bgpd: Fix coverity SA issue with copying over prefix data
in bgp_nlri_parse_ip there is a `sanity` check to ensure
that the prefix length as specified by the packet
will fit inside of a `struct prefix` correctly.  The problem
here of course is that this is only v4 / v6 unicast/multicast
parsing and the bytes will never be more than 16, but we are copying
into a part of the struct prefix that is only 16 bytes, but with
this check the length may be up to 47 bytes( but not really possible ).

Limit the size check to at most 16 bytes (since we are only handling
v4 or v6 addresses here )

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-05-17 09:17:37 -04:00
Donald Sharp
f205a2309c
Merge pull request #11177 from opensourcerouting/fix/memset_memcpy
*: memcpy/memset zeroing
2022-05-13 07:40:58 -04:00
Donald Sharp
aa53c036c0 bgpd: Change single value bitfield to a bool
The maxpaths same_clusterlen value was a uint16_t
with a single bit being used.  No other values are
being stored.  Let's remove the bitfield and simplify
to a bool.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-05-12 10:20:28 -04:00
Donatas Abraitis
6006b807b1 *: Properly use memset() when zeroing
Wrong: memset(&a, 0, sizeof(struct ...));
    Good:  memset(&a, 0, sizeof(a));

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-05-11 14:08:47 +03:00
Dmitrii Turlupov
5f933e1eca bgpd: fix size of esi_buf
Fixes: #11111
Signed-off-by: Dmitrii Turlupov <dturlupov@factor-ts.ru>
2022-04-29 14:56:25 +03:00
Donald Sharp
8f904fdb45
Merge pull request #11095 from ecbaldwin/unlock-node-always
bgpd: ensure that the node gets unlocked in all cases
2022-04-26 15:26:03 -04:00
Carl Baldwin
067ea16598 bgpd: ensure that the node gets unlocked in all cases
The logic to unlock dest if iteration completed without iterating the
entire node was flawed. Specifically, if iteration terminated due to
`gr_deferred == 0` then the node would not get unlocked.

This change takes into account the fact that dest will be NULL only in
the case when the entire table was iterated and all nodes were already
unlocked. In any other case, it needs to be unlocked.

Signed-off-by: Carl Baldwin <carl@ecbaldwin.net>
2022-04-26 09:38:37 -06:00
Donatas Abraitis
db66cf7c17 bgpd: Drop inet_ntop for route_vty_out_overlay()
Reuse %pI4/%pI6/%pIA

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-04-25 20:34:51 +03:00
Donald Sharp
544be97911 *: Fix spelling of strucutre
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-19 08:19:37 -04:00
Donald Sharp
ce5002c659 *: Fix spelling of comparision
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-19 08:18:43 -04:00
Russ White
6a1dbeba2f
Merge pull request #11010 from opensourcerouting/feature/reuse_bgp_attr_set_community_for_flags
bgpd: Reuse bgp_attr_set_[el]community() for setting attribute flags
2022-04-13 14:54:30 -04:00
Russ White
a39df8492d
Merge pull request #11009 from opensourcerouting/fix/med_for_aggregate-address
bgpd: aggregate-address fixes
2022-04-13 14:53:14 -04:00
Donatas Abraitis
3061acc235 bgpd: Convert bgp_peer_sort_t to enum
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-04-12 22:13:55 +03:00
Donatas Abraitis
9d34440bf8 bgpd: Reuse bgp_attr_set_[l]community() for setting attribute flags
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-04-12 22:09:28 +03:00
Donatas Abraitis
764402feba bgpd: Fix styling for aggregate_addressv4_cmd
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-04-11 17:53:42 +03:00
Donatas Abraitis
cacba915d0 bgpd: Add autocomplete for aggregate-address ... route-map X
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-04-11 17:47:52 +03:00
Donatas Abraitis
c0945b7828 bgpd: Allow setting BGP [large]community in route-maps
Before:
```
spine1-debian-11(config-route-map)# bgp community alias 65001:65001 test1
spine1-debian-11(config)# route-map rm permit 10
spine1-debian-11(config-route-map)# set community 65001:65001
% Malformed communities attribute
```

After:
```
spine1-debian-11(config)# bgp community alias 65001:65001 test1
spine1-debian-11(config)# route-map rm permit 10
spine1-debian-11(config-route-map)# set community 65001:65001
spine1-debian-11(config-route-map)#
```

Same for large-communities.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-04-09 17:34:06 +03:00
Xiao Liang
7e7639f548 bgpd: Fix memory leak in subgroup_announce_check
Flush dummy attr to release objects allocated by route-map.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
2022-04-02 17:02:35 +08:00
Donatas Abraitis
f70c91dcef bgpd: Add %pBP printfrr() extension to print IP(hostname) for BGP peer
Replace existing bgp_peer_hostname() function.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-03-31 21:20:11 +03:00
Russ White
8084c3325b
Merge pull request #10845 from opensourcerouting/feature/unify_bgp_logging
bgpd: Print hostname along with IP for most useful debug messages
2022-03-29 11:13:29 -04:00
Donald Sharp
a80d833f6b
Merge pull request #10878 from ton31337/fix/bgp_crash_vrf_all_all
bgpd: Fix crash for `show ip bgp vrf all all`
2022-03-28 08:27:19 -04:00
Donatas Abraitis
75ce3b14f3 bgpd: Fix crash for show ip bgp vrf all all neighbors 192.168.0.1 ...
When `all` is specified BGP pointer is always NULL, we need to iterate over
all instances separately.

```
Received signal 11 at 1648199394 (si_addr 0x30, PC 0x562e96597090); aborting...
 /usr/local/lib/libfrr.so.0(zlog_backtrace_sigsafe+0x5e) [0x7f378a57ff6e]
 /usr/local/lib/libfrr.so.0(zlog_signal+0xe6) [0x7f378a580146]
 /usr/local/lib/libfrr.so.0(+0xcd4c2) [0x7f378a5aa4c2]
 /lib/x86_64-linux-gnu/libpthread.so.0(+0x14140) [0x7f378a33e140]
 /usr/lib/frr/bgpd(bgp_afi_safi_peer_exists+0) [0x562e96597090]
 /usr/lib/frr/bgpd(+0x15c3b8) [0x562e9654a3b8]
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-03-25 11:53:47 +02:00
Donatas Abraitis
fa5ac37865 bgpd: Fix crash for show ip bgp vrf all all
When `all` is specified BGP pointer is always NULL, we need to iterate over
all instances separately.

```
BGP[170822]: Received signal 11 at 1648199394 (si_addr 0x30, PC 0x562e96597090); aborting...
BGP[170822]: /usr/local/lib/libfrr.so.0(zlog_backtrace_sigsafe+0x5e) [0x7f378a57ff6e]
BGP[170822]: /usr/local/lib/libfrr.so.0(zlog_signal+0xe6) [0x7f378a580146]
BGP[170822]: /usr/local/lib/libfrr.so.0(+0xcd4c2) [0x7f378a5aa4c2]
BGP[170822]: /lib/x86_64-linux-gnu/libpthread.so.0(+0x14140) [0x7f378a33e140]
BGP[170822]: /usr/lib/frr/bgpd(bgp_afi_safi_peer_exists+0) [0x562e96597090]
BGP[170822]: /usr/lib/frr/bgpd(+0x15c3b8) [0x562e9654a3b8]
BGP[170822]: /usr/local/lib/libfrr.so.0(+0x75a9e) [0x7f378a552a9e]
BGP[170822]: /usr/local/lib/libfrr.so.0(cmd_execute_command+0x5d) [0x7f378a552e2d]
BGP[170822]: /usr/local/lib/libfrr.so.0(cmd_execute+0xc0) [0x7f378a553070]
BGP[170822]: /usr/local/lib/libfrr.so.0(+0xe3697) [0x7f378a5c0697]
BGP[170822]: /usr/local/lib/libfrr.so.0(+0xe3db1) [0x7f378a5c0db1]
BGP[170822]: /usr/local/lib/libfrr.so.0(+0xe6c30) [0x7f378a5c3c30]
BGP[170822]: /usr/local/lib/libfrr.so.0(thread_call+0x73) [0x7f378a5bb743]
BGP[170822]: /usr/local/lib/libfrr.so.0(frr_run+0xd0) [0x7f378a578750]
BGP[170822]: /usr/lib/frr/bgpd(main+0x344) [0x562e964cf3f4]
BGP[170822]: /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea) [0x7f378a18bd0a]
BGP[170822]: /usr/lib/frr/bgpd(_start+0x2a) [0x562e964d10ea]
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-03-25 11:41:16 +02:00
Donatas Abraitis
a7d91a8c79 bgpd: Print hostname along with IP for most useful debug messages
Examples:

```
%ADJCHANGE: neighbor 192.168.0.1(exit1-debian-11) in vrf default Up
192.168.0.1(exit1-debian-11) graceful restart stalepath timer expired
192.168.0.1(exit1-debian-11) sending route-refresh (BoRR) for IPv4/unicast
192.168.0.1(exit1-debian-11) graceful restart timer started for 120 sec
192.168.0.1(exit1-debian-11) graceful restart stalepath timer started for 120 sec
192.168.0.1(exit1-debian-11) graceful restart timer stopped
%MAXPFXEXCEED: No. of IPv4 Unicast prefix received from 192.168.0.1(exit1-debian-11) 9 exceed, limit 1
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-03-22 21:59:58 +02:00
Donald Sharp
7baebfb715
Merge pull request #10447 from ton31337/fix/json_with_whitespaces
*: Fix JSON keys with whitespaces and PascalCase
2022-03-13 18:19:33 -04:00
Donald Sharp
e3015d915b bgpd: Fix continue/break change from old commit
Commit: ea47320b1d

Modified the bgp_clear_stale_route function to have
better indentation, but in the process changed some
`continue;` statements to `break;` which modified
the looping and caused stale paths to not always be
removed upon an update.

To reproduce:  A ---- B, setup with addpath and GR
One side has a prefix with nhop1 and nhop2, kill one
side and then resend the same prefix with nhop3,
paths nhop1 and 2 become stale and never removed.

Code inspection clearly shows that that `continue`
statements became `break` statements causing the
loop over all paths to stop prematurely.

The fix is to change the break back to continue
statements so the loop can continue instead of
stopping.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-03-07 11:28:28 -05:00
Rafael Zalamena
5be6fa9bf0 bgpd: fix 'show bgp detail json' output
Include the BGP_SHOW_OPT_DETAIL flag in the 'detail' version of the
command.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-03-03 18:26:03 -03:00
Russ White
d2dfd26697
Merge pull request #10636 from ton31337/fix/use_get_set_for_communities
bgpd: Reuse get/set helpers for attr->community
2022-02-28 09:52:50 -05:00
Ryoga Saito
ea7cd161b2 bgpd: change the treatment for SRv6 routes
This patch adds transpostion_offset and transposition_len to bgp_sid_info,
and transposes SID only at bgp_zebra_announce.

Signed-off-by: Ryoga Saito <ryoga.saito@linecorp.com>
2022-02-25 15:34:28 +00:00
Donatas Abraitis
9a706b42fb bgpd: Reuse get/set helpers for attr->community
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-25 10:02:30 +02:00
Donald Sharp
cc9f21da22 *: Change thread->func to return void instead of int
The int return value is never used.  Modify the code
base to just return a void instead.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-23 19:56:04 -05:00
Igor Ryzhov
474f8e031d
Merge pull request #10585 from ton31337/feature/advmap_set
bgpd: Allow setting attributes over route-maps for conditional advert…
2022-02-23 19:23:03 +03:00
Donatas Abraitis
51c3a7deed bgpd: Allow setting attributes over route-maps for conditional advertisements
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-18 11:46:05 +02:00
Donald Sharp
b17826b715 bgp: Add a 15 minute warning to missing policy
Add a 15 minute warning to the logging system when
bgp policy is not setup properly.  Operators keep asking
about the missing policy( on upgrade typically ).  Let's
try to give them a bit more of a hint when something is
going wrong as that they are clearly missing the other
various places FRR tells them about it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-15 12:40:38 -05:00
Donatas Abraitis
1bcf3a96de bgpd: Use get/set helpers for attr->lcommunity
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-10 11:04:03 +02:00
Donatas Abraitis
584fbadf83
Merge pull request #10550 from idryzhov/bgp-attr-undup
bgpd: remove bgp_attr_undup
2022-02-10 09:02:02 +02:00
Igor Ryzhov
d498917efd bgpd: remove bgp_attr_undup
bgp_attr_undup does the same thing as bgp_attr_flush – frees the
temporary data that might be allocated when applying a route-map. There
is no need to have two separate functions for that.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-02-10 01:43:37 +03:00
Igor Ryzhov
afb254d792 bgpd: fix aspath memory leak in aggr_suppress_map_test
aspth_empty a couple of lines earlier creates an aspath and it must be
freed.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-02-10 01:20:03 +03:00
Igor Ryzhov
4dbf2038ea bgpd: fix missing bgp_attr_flush on errors in bgp_update
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-02-10 01:15:57 +03:00
Donald Sharp
518223c161
Merge pull request #10496 from ton31337/fix/move_struct_ecommunity_to_extra
bgpd: Use bgp_attr_[sg]et_ecommunity for struct ecommunity
2022-02-08 14:12:15 -05:00
Donatas Abraitis
024945804a bgpd: Print route-map name for filtred outgoing prefixes
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-07 12:04:10 +02:00
Donatas Abraitis
686826e90e bgpd: Flush temporary attributes after route-map apply
Fixes crash:

```
Received signal 6 at 1644222173 (si_addr 0x6f000012d2, PC 0x7f79274cbfb7); aborting...
/usr/lib/x86_64-linux-gnu/frr/libfrr.so.0(zlog_backtrace_sigsafe+0x6d) [0x7f79282e079d]
/usr/lib/x86_64-linux-gnu/frr/libfrr.so.0(zlog_signal+0xf3) [0x7f79282e0993]
/usr/lib/x86_64-linux-gnu/frr/libfrr.so.0(+0xbd881) [0x7f792830b881]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12980) [0x7f7927890980]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7) [0x7f79274cbfb7]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141) [0x7f79274cd921]
/lib/x86_64-linux-gnu/libc.so.6(+0x89967) [0x7f7927516967]
/lib/x86_64-linux-gnu/libc.so.6(+0x909da) [0x7f792751d9da]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x620) [0x7f7927525050]
/usr/lib/frr/bgpd(+0x1e7c1c) [0x55b5c53b1c1c]
/usr/lib/frr/bgpd(aspath_free+0x28) [0x55b5c53b1c78]
/usr/lib/frr/bgpd(bgp_attr_flush+0x245) [0x55b5c52abc15]
/usr/lib/frr/bgpd(subgroup_announce_check+0x1137) [0x55b5c530c5d7]
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-07 10:50:33 +02:00
Donald Sharp
cd44428d62 bgpd: Prevent use after variable goes out of scope
`struct prefix p` was declared inside an if statement
where we assign the address of to a pointer that is
then passed to a sub function.  This will eventually
leave us in a bad state.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-04 10:29:38 -05:00
Donatas Abraitis
b53e67a389 bgpd: Use bgp_attr_[sg]et_ecommunity for struct ecommunity
This is an extra work before moving attr->ecommunity to attra_extra struct.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-04 15:56:20 +02:00
Donatas Abraitis
77a2f8e592 *: Add camelCase JSON keys in addition to PascalCase
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-03 10:48:06 +02:00
Igor Ryzhov
3b216639d7
Merge pull request #10430 from ton31337/fix/addpath_maximum-prefix-out
bgpd: Add bgp_check_selected() helper and just consistency changes
2022-02-01 18:38:57 +03:00
Donatas Abraitis
be92fc9f1a bgpd: Convert bgp_addpath_encode_[tr]x() to bool from int
Rename addpath_encode[d] to addpath_capable to be consistent.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-01 13:31:16 +02:00
Igor Ryzhov
515ae0c090
Merge pull request #10442 from ton31337/fix/reuse_bgp_path_info_extra_get
bgpd: Reuse bgp_path_info_extra_get() for allocating new bgp path info
2022-02-01 12:19:23 +03:00
Donatas Abraitis
3757f96485 bgpd,pimd,isisd,nhrpd: Convert to vty_json()
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-31 21:20:41 +02:00
Donatas Abraitis
53d3a0a80d bgpd: Reuse bgp_path_info_extra_get() for allocating new bgp path info
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-28 21:11:12 +02:00
Donatas Abraitis
9d56cc8750
Merge pull request #10159 from taspelund/retain-peer-asn
bgpd: retain peer asn even with remove-private-AS
2022-01-28 09:22:06 +02:00
Donatas Abraitis
6766acddbf
Merge pull request #9880 from louis-oui/maximum-prefix-out
bgpd: fixes maximum prefix out
2022-01-27 08:49:31 +02:00
Trey Aspelund
179d5a0e26 bgpd: retain peer asn even with remove-private-AS
In situations where remove-private-AS is configured for eBGP peers
residing in a private ASN, the peer's ASN was not being retained
in the AS-Path which can allow loops to occur. This was addressed
in a prior commit but it only addressed cases where the "replace-AS"
keyword was configured.
This commit ensures we retain the peer's ASN when using
"remove-private-AS" for eBGP peers in a private ASN regardless of other
keywords.

Setup:
=========
router bgp 4200000002
 neighbor enp1s0 interface v6only remote-as external
 neighbor enp6s0 interface v6only remote-as external
 !
 address-family ipv4 unicast
  neighbor enp6s0 remove-private-AS
 exit-address-family

ub18# show ip bgp sum | include 420000
BGP router identifier 100.64.0.111, local AS number 4200000002 vrf-id 0    <<<<< local asn 4200000002
ub20(enp1s0)    4 4200000001        22        22        0    0    0 00:00:57            1        1
ub20(enp6s0)    4 4200000001        21        22        0    0    0 00:00:57            0        1   <<<< peer asn 4200000001

ub18# show ip bgp | include 0.2
Default local pref 100, local AS 4200000002
*> 100.64.0.2/32    enp1s0                   0             0 4200000001 4200000004 4200000005 4200000001 i

Before ("remote-private-AS" only):
=========
ub18# show ip bgp neighbors enp6s0 advertised-routes | include 100.64.0.2
*> 100.64.0.2/32    ::                                     0 i     <<<<<  empty as-path, no way to prevent loop

After ("remote-private-AS" only):
=========
ub18# show ip bgp neighbors enp6s0 advertised-routes | include 100.64.0.2
*> 100.64.0.2/32    ::                                     0 4200000001 4200000001 i    <<<< retain peer's asn, breaks loop

Ticket: 2857047
Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2022-01-24 20:06:50 +00:00
Russ White
6ab0d40e87
Merge pull request #10380 from ton31337/feature/show_graceful_restart_timer_per_prefix
bgpd: Show Graceful Restart seconds remaining per prefix
2022-01-24 07:51:19 -05:00
Louis Scalbert
d0bf49ecd5 bgpd: apply maximum-prefix-out without clearing the neighbor
Abstract:
- The command "neighbor PEER maximum-prefix-out NUMBER" cannot be applied
  without clearing the BGP neighbor.
- Apply the maximum-prefix-out value as soon as it is modified without
  clearing the neighbor.

subgroup_update_packet() and subgroup_withdraw_packet() respectively
manages the announcement and withdrawal BGP message to the peer.
subgrp->scount counter counts the number of sent prefixes.

Before the patch, the maximum out prefix limitation was applied in
subgroup_update_packet() in order that subgrp->scount never exceeds the
limit. Setting a limit inferior to the effective number of sent prefix
did not result in sending any withdrawal message to reduce the number of
sent prefixes. Without clearing the BGP neighbor, the limitation only
applied to the announcement of new prefixes when the limitation was
over.

With the patch, the limitation is checked in subgroup_announce_check().
The function is intended to say whether a prefix has to be announced in
regards to the prefix-list, route-map... Now when a maximum-prefix-out
value is changed/removed, the neighbor AFI/SAFI table is re-parsed in
the same way as for the application of route-map, prefix-lists...

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-01-20 18:19:37 +01:00
Igor Ryzhov
860e740b36 bgpd: replace custom union gw_addr with struct ipaddr
BGP EVPN custom `union gw_addr` is basically the same thing as a common
`struct ipaddr` but it lacks the address family which is needed in some
cases.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-01-19 23:13:04 +03:00
Igor Ryzhov
b04c1e9997 bgpd: fix populating the attribute
This code is populating a temporary variable `add` instead of the attr.
Initially this variable was later copied to the attr but the copying was
erroneously deleted by 0a50c2481. Directly populate the attr to restore
the correct behavior.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-01-19 23:02:11 +03:00
Igor Ryzhov
8f2661b01d bgpd: remove wrong overlay index comparison
Here we try to compare the new attr with the existing one but this call
compares the existing index with zero instead. attrhash_cmp already
compares indexes using overlay_index_same so this call is both wrong and
useless.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-01-19 22:55:44 +03:00
Donatas Abraitis
d92646a4b7 bgpd: Add an empty line after new variable assignment
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-19 19:14:40 +02:00
Donatas Abraitis
848e8cf6c6 bgpd: Show Graceful Restart seconds remaining per prefix
```
exit1-debian-11# sh ip bgp 10.10.10.10/32
BGP routing table entry for 10.10.10.10/32, version 14
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  65000, (stale)
    192.168.0.2 from 192.168.0.2 (0.0.0.0)
      Origin incomplete, metric 0, valid, external, best (First path received)
      Last update: Wed Jan 19 17:13:51 2022
      Time until Graceful Restart stale route deleted: 117
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-19 19:14:19 +02:00
Trey Aspelund
c1984955b7 bgpd: fix advertisedRoutes json key
'show bgp ... neighbor [routes|received-routes]' both incorrectly
used a json key of 'advertisedRoutes'.
This corrects the key to be 'receivedRoutes' for commands where
the displayed routes were received, not advertised.

before:
unet> r3 show ip bgp neigh 10.2.30.2 received-routes json | include Routes
  "advertisedRoutes":{

after:
ub18# show ip bgp neighbors enp1s0 received-routes json | include Routes
  "receivedRoutes":{
ub18# show ip bgp neighbors enp1s0 advertised-routes json | include Routes
  "advertisedRoutes":{

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2022-01-14 22:03:11 +00:00
Donatas Abraitis
48ebba0476 bgpd: Show Long-lived Graceful Restart timer remaining per prefix
```
exit1-debian-11# sh ip bgp 100.100.100.100/32
BGP routing table entry for 100.100.100.100/32, version 7
Paths: (2 available, best #2, table default)
  Advertised to non peer-group peers:
  home-spine1.donatas.net(192.168.0.2)
  65002, (stale)
    192.168.10.17 from donatas-pc(192.168.10.17) (0.0.0.0)
      Origin incomplete, valid, external
      Community: llgr-stale
      Last update: Thu Jan 13 08:58:08 2022
      Time until Long-lived stale route deleted: 18
  65001
    192.168.0.2 from home-spine1.donatas.net(192.168.0.2) (2.2.2.2)
      Origin incomplete, metric 0, valid, external, best (First path received)
      Last update: Thu Jan 13 08:57:56 2022
```

```
~# vtysh -c 'show ip bgp 100.100.100.100/32 json' | jq '."paths"[] | ."llgrSecondsRemaining"'
17
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-13 12:19:32 +02:00
Donatas Abraitis
8ac66010c5 bgpd: Avoid additional check for json output under show ip bgp route
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-13 10:34:04 +02:00
Donatas Abraitis
83fc30745d
Merge pull request #10266 from opensourcerouting/bgp-aggr-rm
bgpd: fix aggregate route unsuppression bug
2022-01-12 23:18:58 +02:00
Donald Sharp
52979c3baa bgpd: Remove unneeded loop over all peers
The bgp_notify_conditional_adv_scanner function was/is looping
over all peers.  And only matching on the passed in peer,
based upon the subgroup.  As such we do not need to loop
over everything and just cut-to-the chase and just modify
the peer structure.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-12 09:53:15 -05:00
Rafael Zalamena
92b175bd40 bgpd: fix aggregate route unsuppression bug
Unsuppress route part of the aggregation when route-map configuration
is removed before the aggregation itself.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-01-11 13:44:54 -03:00
Kantesh Mundaragi
641065d4fc bgpd: VRF-Lite fix to clear stale leaked routes
Description:
Change is intended for fixing the issue related to
clearing of stale leaked routes:
- Whenever BGP goes down,
  after bringing down tcp connection and renegotiating capabilities,
  once we reestablish connection,
  we are not handling clear of VRF leaked route in the bgp_clear_stale_route.

- While bgp is clearing stale routes,
  we need to handle withdraw of routes for VRF route-leaking.

Co-authored-by: Kantesh Mundaragi <kmundaragi@vmware.com>
Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2022-01-08 10:21:10 -08:00
Donatas Abraitis
a30fec23f8 bgpd: Increase maximum supress threshold for dampening to 50,000
rfc7196 recommends:

In addition, BGP implementations have an internal constant, which we
   will call the 'maximum penalty', and the current computed penalty may
   not exceed it.

Router Maximum Penalty:  The internal constant for the maximum
      penalty value MUST be raised to at least 50,000.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-06 10:09:05 +02:00
Donatas Abraitis
1479ed2fb3 bgpd: Implement LLGR helper mode
Tested between GoBGP and FRR (this commit).

```
┌───────────┐             ┌────────────┐
│           │             │            │
│ GoBGPD    │             │ FRRouting  │
│ (restart) │             │            │
│           │             │            │
└──────┬────┘             └───────┬────┘
       │                          │
       │                          │
       │                          │
       │     ┌───────────┐        │
       │     │           │        │
       │     │           │        │
       └─────┤ FRRouting ├────────┘
             │ (helper)  │
             │           │
             └───────────┘

// GoBGPD
% cat /etc/gobgp/config.toml
[global.config]
    as = 65002
    router-id = "2.2.2.2"
    port = 179

[[neighbors]]
    [neighbors.config]
        peer-as = 65001
        neighbor-address = "2a02🔤:123"
    [neighbors.graceful-restart.config]
        enabled = true
        restart-time = 3
        long-lived-enabled = true
    [[neighbors.afi-safis]]
        [neighbors.afi-safis.config]
            afi-safi-name = "ipv6-unicast"
        [neighbors.afi-safis.mp-graceful-restart.config]
            enabled = true
        [neighbors.afi-safis.long-lived-graceful-restart.config]
            enabled = true
            restart-time = 10
    [[neighbors.afi-safis]]
        [neighbors.afi-safis.config]
            afi-safi-name = "ipv4-unicast"
        [neighbors.afi-safis.mp-graceful-restart.config]
            enabled = true
        [neighbors.afi-safis.long-lived-graceful-restart.config]
            enabled = true
            restart-time = 20

% ./gobgp global rib add -a ipv6 2001:db8:4::/64
% ./gobgp global rib add -a ipv6 2001:db8:5::/64 community 65535:7
% ./gobgp global rib add -a ipv4 100.100.100.100/32
% ./gobgp global rib add -a ipv4 100.100.100.200/32 community 65535:7
```

1. When killing GoBGPD, graceful restart timer starts in FRR helper router;
2. When GR timer expires in helper router:
   a) LLGR_STALE community is attached to routes to be retained;
   b) Clear stale routes that have NO_LLGR community attached;
   c) Start LLGR timer per AFI/SAFI;
   d) Recompute bestpath and reannounce routes to peers;
   d) When LLGR timer expires, clear all routes on particular AFI/SAFI.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-12-28 16:07:59 +02:00
Donatas Abraitis
f5827f3689 bgpd: Drop if 0 blocks
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-12-23 14:41:11 +02:00
Donald Sharp
be785e356a bgpd, tests: Add code to handle failed installations
Currently the Wait for Install code ( bgp_suppress_fib ) does
not properly handle two states from zebra:  ROUTE_INSTALL_FAILED
and BETTER_ADMIN_DISTANCE_WON.  Pre this change the WFI code
would just never notify our peers about a route install failure
but more is needed.  In the ROUTE_INSTALL_FAILED and the
BETTER_ADMIN_DISTANCE_WON we need to notify our peers with
a withdrawal about the route, else we will continue to
draw traffic to us when we cannot legally do so.

Why is this needed?  In either case imagine that we've already
received a bgp route, installed it and sent to our peers.
In the Better admin distance won case, say a static route is installed
at this point in time we must stop advertising the route through
us since we are not installed.  As such a withdrawal must be sent.

In the ROUTE_INSTALL_FAILED case, the code was not properly handling
the situation where we have Route A, it was successfully installed
and then we received a update to Route A that was attempted to be
installed but failed.  In this case we also need to send a withdrawal

Finally update the bgp_suppress_fib topotest to test both of these
situations.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-12-17 13:28:56 -05:00
Mark Stapp
907707db48 bgpd: clearer safi handling for BGP-LU route updates
Don't hide the LABELED_UNICAST safi when processing route
updates; map it where necessary (to use the UNICAST table
for instance).

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2021-12-01 07:56:38 -05:00
Russ White
f1f6716d4a
Merge pull request #9610 from iqras23/best_path
bgpd: VRF-Lite fix best path selection
2021-11-30 16:14:34 -05:00
Igor Ryzhov
cb3fa0a612
Merge pull request #10124 from ton31337/feature/vty_json 2021-11-29 02:11:29 +03:00
Russ White
d41e9fe0cb
Merge pull request #9203 from opensourcerouting/bgpd-show-json
bgpd: add "json" option to a few more show commands
2021-11-27 08:30:04 -05:00
Donatas Abraitis
75eeda9323 bgpd: Convert vty_out to vty_json for JSON
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:51:12 +02:00
Donatas Abraitis
746a6eda2f *: Remove unused variables
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:35:55 +02:00
Donatas Abraitis
67d7e256a3 bgpd: Replace prefix2str for JSON to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:34:17 +02:00
Renato Westphal
fe0f234d13 bgpd: add "json" option to "show ip bgp ... dampening parameters"
Also:
* rename show_ip_bgp_cmd to show_ip_bgp_dampening_params_cmd;
* rename show_ip_bgp_json_cmd to show_ip_bgp_cmd.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 15:14:08 -03:00
Renato Westphal
39c3c7364d bgpd: add "json" option to "show ip bgp ... longer-prefixes"
Move the "longer-prefixes" option from show_ip_bgp_cmd to
show_ip_bgp_json_cmd so that is has access to JSON output.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 15:14:08 -03:00
Renato Westphal
bf1a944ace bgpd: add "json" option to "show ip bgp ... route-map"
Move the "route-map" option from show_ip_bgp_cmd to
show_ip_bgp_json_cmd so that is has access to JSON output.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 15:14:08 -03:00
Renato Westphal
a71293475b bgpd: add "json" option to "show ip bgp ... filter-list"
Move the "filter-list" option from show_ip_bgp_cmd to
show_ip_bgp_json_cmd so that is has access to JSON output.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 15:14:08 -03:00
Renato Westphal
6deaf5794d bgpd: add "json" option to "show ip bgp ... prefix-list"
Move the "prefix-list" option from show_ip_bgp_cmd to
show_ip_bgp_json_cmd so that is has access to JSON output.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 15:14:08 -03:00
Renato Westphal
707999834a bgpd: add "json" option to "show ip bgp ... community-list"
Move the "community-list" option from show_ip_bgp_cmd to
show_ip_bgp_json_cmd so that is has access to JSON output.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 14:36:58 -03:00
Renato Westphal
2391833ecf bgpd: use void pointer to reduce code duplication
There's no need to have different calls to bgp_show() when the only
difference is one argument that corresponds to a "void *" parameter.

Code duplication should be reduced to a minimum to avoid bugs like
the one fixed in the previous commit.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 14:27:25 -03:00
Renato Westphal
db58b09fea bgpd: fix crash in "show ip bgp ... all alias ALIAS"
Like done in the other places (when "all" isn't used), pass the
actual alias name to bgp_show() instead of a null pointer.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 14:27:25 -03:00
Donald Sharp
d32c92a4c0
Merge pull request #10057 from ton31337/fix/we_shouldn_send_LLA_for_RS
bgpd: Do not send LLA for route-server-client peers
2021-11-22 12:06:36 -05:00
Kantesh Mundaragi
da0c0ef70c bgpd: VRF-Lite fix best path selection
Description:
Incorrect behavior during best path selection for the imported routes.
Imported routes are always treated as eBGP routes.

Change is intended for fixing the issues related to
bgp best path selection for leaked routes:
- FRR does ecmp for the imported routes,
  even without any ecmp related config.
  If the same prefix is imported from two different VRFs,
  then we configure the route with ecmp even without
  any ecmp related config.
- Locally imported routes are preferred over imported
  eBGP routes.
  If there is a local route and eBGP learned route
  for the same prefix, if we import both the routes,
  imported local route is selected as best path.
- Same route is imported from multiple tenant VRFs,
  both imported routes point to the same VRF in nexthop.
- When the same route with same nexthop in two different VRFs
  is imported from those two VRFs, route is not installed as ecmp,
  even though we had ecmp config.

- During best path selection, while comparing the paths for imported routes,
  we should correctly refer to the original route i.e. the ultimate path.
- When the same route is imported from multiple VRF,
  use the correct VRF while installing in the FIB.
- When same route is imported from two different tenant VRFs,
  while comparing bgp path info as part of bgp best path selection,
  we should ideally also compare corresponding VRFs.

See-also: https://github.com/FRRouting/frr/files/7169555/FRR.and.Cisco.VRF-Lite.Behaviour.pdf

Co-authored-by: Santosh P K <sapk@vmware.com>
Co-authored-by: Kantesh Mundaragi <kmundaragi@vmware.com>
Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2021-11-19 07:33:22 +05:30
Donatas Abraitis
4e9a98636f *: Remove unused variables
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-18 18:45:41 +02:00
Donatas Abraitis
c949c77101 bgpd: Replace inet_ntop to %pI4/6 for JSON outputs
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-18 11:35:29 +02:00
David Lamparter
de48804c01
Merge pull request #10046 from donaldsharp/bgp_instance_del 2021-11-15 10:49:31 +01:00
Donatas Abraitis
2d02e34eab bgpd: Do not send LLA for route-server-client peers
We should send only 16bytes next hop, no need for 32bytes, third party
next hops kinda for LLA does not work here.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-15 08:51:26 +02:00
Donald Sharp
4378495a27 bgpd: Add vrf information to best path debugging
When debugging issues for routes in multiple vrf's.  It would
be extremely useful if the debug output had which vrf we
are acting on.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-12 13:24:04 -05:00
Donald Sharp
e36f61b507 *: Rename quagga_timestamp with frr_timestamp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00
Donatas Abraitis
37b6787730
Merge pull request #9700 from mjstapp/add_json_det_attrs
bgpd: Add 'show bgp <afi> <safi> json detail' header data
2021-11-10 16:42:30 +02:00
Donatas Abraitis
458c1475ab bgpd: Set afi by default to AFI_IP6 for show bgp vrf/view detail
AFI/SAFI is handled in bgp_vty_find_and_parse_afi_safi_bgp() properly for
IPv4, but not for IPv6. Let's have it enabled for IPv6 by default.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-06 15:54:20 +02:00
Donatas Abraitis
54d05dea57 bgpd: Set afi by default to AFI_IP6 for show bgp vrf/view all
AFI/SAFI is handled in bgp_vty_find_and_parse_afi_safi_bgp() properly for
IPv4, but not for IPv6. Let's have it enabled for IPv6 by default.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-06 15:50:56 +02:00
Igor Ryzhov
12bc8a4068
Merge pull request #9791 from opensourcerouting/bgp-json-mem-fix
bgpd: Fix json object memory leaks and double-free
2021-10-26 18:06:47 +03:00
Donald Sharp
d9654571f9
Merge pull request #9316 from ton31337/fix/send_best_path_reason_for_zebra
bgpd: Send BGP best path reason to Zebra
2021-10-25 11:09:20 -04:00
Russ White
61a7ec774c
Merge pull request #9783 from mjstapp/fix_bgp_lu_lsp
bgpd, tests: BGP-labeled-unicast advertise implicit-null in more cases
2021-10-20 18:22:01 -04:00
Donatas Abraitis
de71d43e04 bgpd: Add autocomplete for filter-list
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-19 18:03:54 +03:00
Donatas Abraitis
1d7260a1b5 bgpd: Send BGP best path reason to Zebra
```
exit1-debian-9# show ip route 172.16.16.1/32
Routing entry for 172.16.16.1/32
  Known via "bgp", distance 20, metric 0, best
  Last update 00:00:28 ago
  * 192.168.0.2, via eth1, weight 1
    AS-Path          : 65003
    Communities      : first 65001:2 65001:3
    Large-Communities: 65001:1:1 65001:1:2 65001:1:3
    Selection reason : First path received
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-14 16:52:47 +03:00
Rafael Zalamena
21e33c958d bgpd: remove bogus check
`bgp` pointer always exists and is used before this function call.

Calling `free` in `json` in this context will also cause a
use-after-free crash.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-10-11 18:29:54 -03:00
Martin Winter
690c3134a4 bgpd: fix json object handling
Fix memory leaks when quitting early and double free when headers are
not set.

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
2021-10-11 18:28:09 -03:00
Donatas Abraitis
126f9ac563
Merge pull request #9693 from donaldsharp/bgp_address_removal
bgpd: When removing v6 address being used as a nexthop ensure peer is…
2021-10-08 17:41:59 +03:00
Mark Stapp
bb2ca6927f bgpd: BGP-LU use implicit-null in some cases
In some cases where bgp is at the mpls edge, where it has a BGP-LU
peer downstream but an IP peer upstream, it can advertise the
IMPLICIT_NULL label instead of a per-prefix label.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2021-10-08 09:11:51 -04:00
Igor Ryzhov
d3120452c4 bgpd: add missing vrf/view parameter to one command
"show bgp neighbors PEER received prefix-filter" misses the argument.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-07 18:29:22 +03:00
Donald Sharp
e1a32ec1c5 bgpd: bgp_announce_route should know if we should force the update or not
When calling bgp_announce_route allow it to properly set the flag
to force an update to go out or not.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-04 07:59:18 -04:00
Mark Stapp
2aad8c4289 bgpd: add 'header' info to show bgp afi safi json detail
The '... json detail' output is missing some data that's shown
via the 'route_vty_out_detail_header' function. Integrate the
json version of that function in the 'json detail' path.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2021-10-01 08:06:35 -04:00
Mark Stapp
edfee30d64 bgpd: add some const
Add const to a couple of arguments in bgp_label utilities,
and in a show function.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2021-10-01 07:48:45 -04:00
Philippe Guibert
700ddfed69 bgpd: add carriage return when dumping tags from all evpn rds
following command: show bgp l2vpn evpn rd all tags
does not append rd contexts one after the other

before:
dut-vm# show bgp l2vpn evpn rd all tags
   Network          Next Hop      In tag/Out tag
Route Distinguisher: 65000:999
*> [5]:[0]:[24]:[10.40.1.0]
                    10.209.36.1     Route Distinguisher: 65000:1000
*> [5]:[0]:[24]:[10.40.1.0]
                    10.209.36.1
Displayed 2 out of 2 total prefixes

after:
dut-vm# show bgp l2vpn evpn rd all tags
   Network          Next Hop      In tag/Out tag
Route Distinguisher: 65000:999
*> [5]:[0]:[24]:[10.40.1.0]
                    10.209.36.1
Route Distinguisher: 65000:1000
*> [5]:[0]:[24]:[10.40.1.0]
                    10.209.36.1

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-09-22 10:01:06 +02:00
Donatas Abraitis
d24f4b7d84
Merge pull request #9645 from mjstapp/fix_show_bgp_lu
bgpd: make show bgp labeled-unicast work
2021-09-22 09:52:09 +03:00
Russ White
2075387e77
Merge pull request #9546 from proelbtn/add-support-for-perfix-sid-type-5
Add support for Prefix-SID (Type 5)
2021-09-21 11:36:53 -04:00
Mark Stapp
cd8c2a27c1 bgpd: make show bgp labeled-unicast work
Yet-another path where the safi needs to be changed to locate
the unicast table where LU routes live.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2021-09-21 11:21:36 -04:00