Commit Graph

1420 Commits

Author SHA1 Message Date
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