234 Commits

Author SHA1 Message Date
Arthur de Kerhor 3ae91215be graceful restart: send initial paths list to all neighbors
Before this PR, when graceful restart was configured for a neighbor
and when the restart flag was set by the restarting speaker, if
the neighbor was not advertising the GR capability, the initial
paths list was never sent by the restarting speaker to its neighbor

This is a problem when the server is configured with graceful
restart for all its peers without knowing if the peer supports it.
If some of the peers don't support it, they may never receive the
routes from the restarting speaker, leading to an inconsistent
routing state.
2024-04-30 16:05:51 +02:00
Tuetuopay 78516cf8af server: fix nil pointer exception in evpn mac mobility
With large EVPN fabrics, it can happen that some paths are nil in the
mac mobility codepath, causing crashes of the process.

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xb8e03a]
    goroutine 25 [running]:
    github.com/osrg/gobgp/v3/internal/pkg/table.(*Path).root(...)
        /home/tuetuopay/dev/gobgp/internal/pkg/table/path.go:341
    github.com/osrg/gobgp/v3/internal/pkg/table.(*Path).OriginInfo(...)
        /home/tuetuopay/dev/gobgp/internal/pkg/table/path.go:348
    github.com/osrg/gobgp/v3/internal/pkg/table.(*Path).GetNlri(...)
        /home/tuetuopay/dev/gobgp/internal/pkg/table/path.go:460
    github.com/osrg/gobgp/v3/pkg/server.getMacMobilityExtendedCommunity(0x0, {0xc002833520, 0x6, 0xc00033ec00?}, {0xc001a52008, 0xa72, 0xc000000000?})
        /home/tuetuopay/dev/gobgp/pkg/server/server.go:2044 +0x1da
    github.com/osrg/gobgp/v3/pkg/server.(*BgpServer).fixupApiPath(0xc000372008, {0x0, 0x0}, {0xc0008fbe48, 0x1, 0x0?})
        /home/tuetuopay/dev/gobgp/pkg/server/server.go:2120 +0x4bc
    github.com/osrg/gobgp/v3/pkg/server.(*BgpServer).addPathList(0xc000372008, {0x0?, 0x0?}, {0xc0008fbe48, 0x1, 0x1})
        /home/tuetuopay/dev/gobgp/pkg/server/server.go:2162 +0x2c
    github.com/osrg/gobgp/v3/pkg/server.(*BgpServer).AddPath.func1()
        /home/tuetuopay/dev/gobgp/pkg/server/server.go:2191 +0xa5
    github.com/osrg/gobgp/v3/pkg/server.(*BgpServer).handleMGMTOp(0xc0b4e0?, 0xc001243140)
        /home/tuetuopay/dev/gobgp/pkg/server/server.go:280 +0x82
    github.com/osrg/gobgp/v3/pkg/server.(*BgpServer).Serve(0xc000372008)
        /home/tuetuopay/dev/gobgp/pkg/server/server.go:490 +0x53a
    created by main.main in goroutine 1
        /home/tuetuopay/dev/gobgp/cmd/gobgpd/main.go:202 +0x13ea
2024-04-29 19:34:56 +09:00
Maxime Peim 9fbc03765a send-max: respect configuration 2024-04-29 17:29:42 +09:00
Tuetuopay bbde806641 evpn: fix quadratic mac-mobility handling for gRPC routes
The gRPC code paths uses different functions than the BGP code path.
Thus is did not receive the fix for the mac mobility handling.

Fixes: c393f43 ("evpn: fix quadratic evpn mac-mobility handling")
2024-04-29 17:25:29 +09:00
Arthur de Kerhor 7ec4af4818 fix data race when getting capabilities from neighbor config
Func capabilitiesFromConfig was always taken under the read lock.
However, when graceful restart is enabled for some families, this
function writes to the neighbor config which creates a data race.
2024-04-29 17:22:48 +09:00
Yutaro Hayakawa 0ccd87db55 Sending Cease/Hard Reset notification
Send Cease/Hard Reset notification for certain scenario when graceful
restart + notification support (RFC8538) are enabled. In this
implementation, we follow the suggestion of RFC8538 and map following
notification subcodes to Hard Reset subcode.

1. BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED

In this case, GoBGP is in the resource shortage and not working
properly. Thus, the peer should stop forwarding packet immediately.

2. BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN

This happens when the user uses DisablePeer API. This clearly indicates
user's intention of shutting down the session. Thus, we should send Hard
Reset.

3. BGP_ERROR_SUB_PEER_DECONFIGURED

This happens when the user uses DeletePeer API or StopBgp API or there's
an ASN mismatch found in the Open phase. The former two cases, the user
shows the intention to shutdown the session, so we should Hard Reset.
The latter case is not so obvious, but I think it's ok to do Hard Reset
because it is an unrecoverable error that cannot be solved without
user's involvement.

4. BGP_ERROR_SUB_HARD_RESET

This case currently doesn't exist, but obviously we should send Hard
Reset when someone explicitly specifies it.

The behavior for the remaining subcodes are unchanged. We may want to
expose a knob to adjust the behavior of BGP_ERROR_SUB_ADMINISTRATIVE_RESET
as suggested by RFC8538, but for this initial implementation, we kept it
as is.

Signed-off-by: Yutaro Hayakawa <yutaro.hayakawa@isovalent.com>
2024-04-27 23:51:11 +09:00
wenovus 7ef2f0bb82 Add CommunityCount BGP Policy Condition
This is intended to have the same behaviour as [these OpenConfig paths](https://openconfig.net/projects/models/schemadocs/yangdoc/openconfig-routing-policy.html#routing-policy-policy-definitions-policy-definition-statements-statement-conditions-bgp-conditions-community-count):
* /routing-policy/policy-definitions/policy-definition/statements/statement/conditions/bgp-conditions/community-count/config/operator
* /routing-policy/policy-definitions/policy-definition/statements/statement/conditions/bgp-conditions/community-count/config/value
2024-04-11 07:48:16 +09:00
Rinat Baygildin 5d5a6b9afe Do not check enabling when EOR received
Signed-off-by: Rinat Baygildin <bayrinat@yandex-team.ru>
2024-03-20 08:45:34 +00:00
Rinat Baygildin ed87360952 Add EOR type to Table's filter on Watch method
Signed-off-by: Rinat Baygildin <bayrinat@yandex-team.ru>
2024-03-20 08:45:34 +00:00
wenovus 829bbcf0a2 Fix ListPath for ADJ_IN and EnableFiltered=true and add tests.
Currently, even though `ApplyPolicy` is called for determining the
accepted routes after apply policy, the new route with attribute
modifications is not returned. This is problematic for gRPC API users.

Tests are added for all four cases that were described in
https://github.com/osrg/gobgp/issues/2765. This PR makes the behaviour
correct for "Case/Attempt 2" described in the issue.
2024-03-15 16:11:55 -07:00
FUJITA Tomonori 9d05544d1e Revert "Add EOR type to Table's filter on Watch method"
This reverts commit aff055b44d.

This breaks WatchEvent API:
https://github.com/osrg/gobgp/issues/2777
2024-03-05 07:42:25 +00:00
FUJITA Tomonori 84a264e618 Revert "Do not check enabling when EOR received"
This reverts commit fbeaa1c668.

This breaks WatchEvent API:
https://github.com/osrg/gobgp/issues/2777
2024-03-05 07:41:28 +00:00
Rinat Baygildin fbeaa1c668 Do not check enabling when EOR received
Signed-off-by: Rinat Baygildin <bayrinat@yandex-team.ru>
2024-03-02 08:35:54 +00:00
Rinat Baygildin aff055b44d Add EOR type to Table's filter on Watch method
Signed-off-by: Rinat Baygildin <bayrinat@yandex-team.ru>
2024-03-02 08:35:54 +00:00
Britton Payne 3448996706 Use net.IP.Equal in peer.filterPathFromSourcePeer
- Compares IPs using net.IP.Equal instead of using a string comparison
  in order to avoid unnecessary allocations.

- Adds peer.routerID to access IP, called by peer.RouterID.
2024-03-02 07:45:40 +00:00
Dawn Minion 003745affe logs: Guard frequently called logs behind if check
Moves a number of heavily called debug lines behind if checks to avoid
needless allocations of Fields objects and stringification of fields.
For cases where the server is not set to "debug" log level, these fields
were allocated on the heap and then immediately discarded - as well a
number of these were stringifying state / NLRIs regardless of log level.

In servers with significant amounts of routes and BGP peers, this lead
to a large amount of wasted allocations - in our case looking at Go's
memory profiler, 25% of all allocations were from these lines alone.
2024-03-02 06:12:45 +00:00
Dawn Minion 87e5b819e4 server: Fix deadlock if StopBgp is called when conn queue is full
Fixes a deadlock condition that can happen if StopBgp is called when the
pending connection queue is full. During teardown, StopBgp calls a
mgmtOp on the server goroutine which attempts to stop the goroutine
accepting inbound connections, and waits for it to finish before
continuing.

This connection goroutine can block if the connection queue is full,
which is read by the same goroutine that processes all mgmtOps. This
means that if the queue is full and the goroutine is currently blocked,
then calling StopBgp will lead to a complete deadlock, as the connection
goroutine will never close as it is trying to send to the queue, but the
queue will not be read as the server goroutine is currently waiting for
the connection goroutine to exit.

To correct this, a context has been added that gets passed to the
connection goroutine. This is then checked in a new select statement on
the connection queue which gets cancelled by tcpListener.Close() ensuring
the goroutine exits correctly even if the queue is full.
2024-02-27 12:24:45 -08:00
Christian Persson ce7e5d3296 server: only log warning if grpcServer.Serve() returned an error.
Additionally change the `Key` to be the listener address, which is hopefully
more useful than a difficult-to-decipher dump of the listener struct.

The previous behavior would result in log lines like the following, even if
nothing went wrong:
```
time="2024-01-31T17:30:25Z" level=warning msg="accept failed" Error="<nil>" Key="&{0x140002e4000 {<nil> 0 0}}" Topic=grpc
```
With this change, the message is only logged if there was an error, and it will look like this:
```
time="2024-01-31T17:40:25Z" level=warning msg="accept failed" Error="lolol just testing" Key="127.0.0.1:59289" Topic=grpc
```
2024-01-31 17:42:41 +00:00
Yutaro Hayakawa 815683fa5e Only wait for GR End of RIB for the received address family
Currently, graceful restart waits for the EoR message for all address
families "enabled" for the peer, but it should only wait for "received"
address families (the address families the peer is capable of handling).

Fixes: #2524

Signed-off-by: Yutaro Hayakawa <yutaro.hayakawa@isovalent.com>
2024-01-29 11:15:08 +09:00
Arthur de Kerhor 08529d6cc4 Make sure the TCP connection is closed when a peer is deleted
It could be that a peer gets deleted and added back during the
transition from active state to open confirm. In that case, the TCP
connection from the old version of the peer could still be up. This
is a problem if the server is a listener only as the remote peer
would consider the old TCP connection as being valid and it won't
be able to connect until the TCP connection is eventually cleaned
by the Golang GC.
2023-12-04 13:32:37 +01:00
Jeremiah Millay 0d57904082 add test case for AddDefinedSet with replace 2023-11-10 13:59:11 -05:00
Jeremiah Millay 16412bfc03 Add replace option to AddDefinedSet rpc 2023-11-10 13:35:24 -05:00
Joshua DeWald 02fa6129af Implementation of Dynamic Neighbor MD5 (Issue #2589)
Adds usage of the "prefix-based" TCP MD5 for dynamic
neighbors. Non-dynamic neighbors will continue to use
non-prefix based, which makes it more compatible with
running on older kernels, as only 4.14+ includes the
necessary support.

This change also includes tests of dynamic peers in general.
2023-11-07 11:28:12 -08:00
wenovus 340030dc28 Fix imports 2023-10-31 22:42:13 +09:00
Dawn Minion 1b975be057 Fix data race in newWatchEventPeer
This method was attempting to read from peer.fsm before acquiring a read
lock, leading to a data race as this struct is written by a different
goroutine in parallel. Commit moves the call to RLock before the first
read from the struct.
2023-10-24 22:26:02 +09:00
wenovus 419c50dfac Check Address and LocalAddress instead of RouterId 2023-10-15 21:33:50 +09:00
wenovus 16a9c95393 Allow testing multiple GoBGP instances on localhost.
Currently GoBGP does not accept UPDATE messages with nexthops pointing
to a loopback address. This disallows multiple GoBGP instances from
running at the same time on 127.0.0.0/8.

This PR proposes removing this constraint when the RouterID of the
current GoBGP instance itself resides within the testing subnet of
127.0.0.0/8.
2023-10-15 21:32:04 +09:00
Vladislav Grishenko 146b2b8f59 server: improve ListPath's memory consumption with batched send
With a lot of paths (hundreds of thousands) gobgp may oom or
stuck in swapping.
Allow to specify max batch size via grpc and keep unlimited batch
size by default since 21093fbc87
without preallocation on the first run, so it still should not
affect perfomance/allocations with small ammount of paths.

Signed-off-by: Vladislav Grishenko <themiron@yandex-team.ru>
2023-10-02 14:42:52 +09:00
wenovus aa0cf39f37 Export Generated BGP Configuration Code
Move internal/pkg/config -> pkg/config/oc

Background: #2593
2023-09-30 09:53:37 +09:00
Kirill Pletnev 35bfc9605c CLI VPNv4/VPNv6 filtering
gobgp CLI can filter VPNv4/VPNv6 prefixes with or without rd.
2023-09-06 11:14:47 +03:00
Rinat Baygildin b8e17e06cd Use filter for watch pre/post-update watch events
Filtering by peer address worked only for initial state.
Using watch event's filter allows to use it for each event and could be extended by other conditions, e.g. peer group.

peer_address and peer_group were added to API (backward compatible).

Signed-off-by: Rinat Baygildin <bayrinat@yandex-team.ru>
2023-09-06 15:35:55 +09:00
Rinat Baygildin eb58efd79c Fix test TestAddBogusPath
Stop the server in the test.

Signed-off-by: Rinat Baygildin <bayrinat@yandex-team.ru>
2023-09-06 15:35:55 +09:00
Maxime Peim e7534de3d2 use TCP MSS configuration 2023-07-25 12:46:48 +09:00
Jeremiah Millay 79d301f75b Fix UpdatePathAggregator4ByteAs() ignores 32bit value
Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
2023-06-12 17:19:09 -04:00
Rastislav Szabo 03982e597e Fix setting of TTL on a nil connection in updateNeighbor
Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
2023-06-05 09:42:48 +02:00
Rastislav Szabo 987c1794d5 Allow non-disruptive changes of TTL in UpdatePeer
Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
2023-05-26 09:59:47 +02:00
Rastislav Szabo f8c6d24e32 Fix defaulting for UpdatePeer + make IdleHoldTimeAfterReset actually configurable
Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
2023-05-22 13:36:45 +02:00
Tobias Klauser 88da915c97 Use standard library context package
Use Go's standard library context package instead of the
golang.org/x/net/context package. Package context has been available in
the standard library since Go 1.7 and x/net/context.Context is merely an
alias for the standard library type.
2023-04-18 13:56:58 +02:00
Vladimir Kikhtenko 16ced2072c use public api for metric collection 2023-04-01 21:55:38 +09:00
Vladimir Kikhtenko 024d88c9b7 fix data race & add test 2023-04-01 21:55:38 +09:00
Vladimir Kikhtenko 41566d1b38 basic prometheus metrics 2023-04-01 21:55:34 +09:00
Tobias Klauser 4f52a30b97 server: use SetsockoptTCPMD5Sig from golang.org/x/sys/unix
Use the TCPMD5Sig type and the corresponding SetsockoptTCPMD5Sig func
added upstream in golang.org/x/sys v0.6.0

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2023-03-07 12:05:41 +01:00
Donatas Abraitis c556ca4f8d Add SoftwareVersion capability
https://datatracker.ietf.org/doc/html/draft-abraitis-bgp-version-capability

Working example with FRR
```
% ./gobgp neighbor 192.168.10.124
BGP neighbor is 192.168.10.124, remote AS 65001
  BGP version 4, remote router ID 200.200.200.202
  BGP state = ESTABLISHED, up for 00:01:14
  BGP OutQ = 0, Flops = 0
  Hold time is 3, keepalive interval is 1 seconds
  Configured hold time is 90, keepalive interval is 30 seconds

  Neighbor capabilities:
    multiprotocol:
        ipv6-unicast:	advertised
        ipv4-unicast:	advertised and received
    route-refresh:	advertised and received
    extended-nexthop:	advertised
        Local:  nlri: ipv4-unicast, nexthop: ipv6
    UnknownCapability(6):	received
    UnknownCapability(9):	received
    graceful-restart:	advertised and received
        Local: restart time 10 sec
	    ipv6-unicast
	    ipv4-unicast
        Remote: restart time 120 sec, notification flag set
	    ipv4-unicast, forward flag set
    4-octet-as:	advertised and received
    add-path:	received
      Remote:
         ipv4-unicast:	receive
    enhanced-route-refresh:	received
    long-lived-graceful-restart:	advertised and received
        Local:
	    ipv6-unicast, restart time 10 sec
	    ipv4-unicast, restart time 20 sec
        Remote:
	    ipv4-unicast, restart time 0 sec, forward flag set
    fqdn:	advertised and received
      Local:
         name: donatas-pc, domain:
      Remote:
         name: spine1-debian-11, domain:
    software-version:	advertised and received
      Local:
         GoBGP/3.10.0
      Remote:
         FRRouting/8.5-dev-MyOwnFRRVersion-gdc92f44a4
    cisco-route-refresh:	received
  Message statistics:
```

FRR side:

```
root@spine1-debian-11:~# vtysh -c 'show bgp neighbor 192.168.10.17 json' | \
> jq '."192.168.10.17".neighborCapabilities.softwareVersion.receivedSoftwareVersion'
"GoBGP/3.10.0"
root@spine1-debian-11:~#
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-01-31 23:09:24 +09:00
Shengjing Zhu 1474c4bbcc Fix TCPM5Sig tests on big-endian host
Closes: #2545

Signed-off-by: Shengjing Zhu <zhsj@debian.org>
2022-12-29 21:43:42 +08:00
Ben Renninson 9f94c96cf4 Get building on Windows
Both `gobgpd` and `gobgpd` now build for and run on Windows. This is based on https://github.com/osrg/gobgp/pull/2250/ with less required changes. Tested and confirmed it can peer successfully and receive routes. It still builds on Linux (doesn't change syscalls for non-windows files).
2022-12-29 01:09:32 +00:00
Rinat Baygildin a3f1d8c19a Add enable_only_binary flag to grpc ListPath method
Adding enable_only_binary allows using only binary representation of nlri and attributes on the ListPath call.
For clients who uses only binary representation it helps to significantly reduce
resource consumption by refusing unnecessary conversion.

It is vital while processing a large number of paths, e.g. full-view.

This change doesn't break backward compatibility.
2022-11-18 16:04:41 +04:00
Tuetuopay 162eae62bd grpc: fix goroutine leak in WatchEvent
The context used there was a background context, which was not inherited
from the stream. Thus when the client ends the stream (e.g. ^C
`gobgp monitor global rib`), the context never completed, preventing the
stop of most goroutines responsible for forwarding events. The only case
where it completes is when an event gets generated, the transmit channel
was closed, ending the chain of goroutines.

Fix by inheriting the context from the stream, which completes when the
stream ends, properly cleaning up all resources.
2022-10-26 17:09:07 +02:00
FUJITA Tomonori 42a5f1d771 server: handle uuid error in AddPath API
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
2022-08-05 21:22:00 +09:00
toby fc6fa7c64e Listener Queue: reduce length 2022-05-13 08:15:18 +09:00
Hitoshi Irino 157a7689e1 Support FRRouting 8.2 and introduce zebra.Software structure. 2022-05-04 07:32:58 +00:00