2000-03-19 22:09:07 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- The Border Gateway Protocol
|
|
|
|
*
|
|
|
|
* (c) 2000 Martin Mares <mj@ucw.cz>
|
2016-12-07 13:11:28 +00:00
|
|
|
* (c) 2008--2016 Ondrej Zajicek <santiago@crfreenet.org>
|
|
|
|
* (c) 2008--2016 CZ.NIC z.s.p.o.
|
2000-03-19 22:09:07 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-04 17:06:18 +00:00
|
|
|
/**
|
|
|
|
* DOC: Border Gateway Protocol
|
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* The BGP protocol is implemented in three parts: |bgp.c| which takes care of
|
|
|
|
* the connection and most of the interface with BIRD core, |packets.c| handling
|
2000-06-04 17:06:18 +00:00
|
|
|
* both incoming and outgoing BGP packets and |attrs.c| containing functions for
|
|
|
|
* manipulation with BGP attribute lists.
|
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* As opposed to the other existing routing daemons, BIRD has a sophisticated
|
|
|
|
* core architecture which is able to keep all the information needed by BGP in
|
|
|
|
* the primary routing table, therefore no complex data structures like a
|
|
|
|
* central BGP table are needed. This increases memory footprint of a BGP router
|
|
|
|
* with many connections, but not too much and, which is more important, it
|
|
|
|
* makes BGP much easier to implement.
|
2000-06-04 17:06:18 +00:00
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* Each instance of BGP (corresponding to a single BGP peer) is described by a
|
|
|
|
* &bgp_proto structure to which are attached individual connections represented
|
|
|
|
* by &bgp_connection (usually, there exists only one connection, but during BGP
|
|
|
|
* session setup, there can be more of them). The connections are handled
|
|
|
|
* according to the BGP state machine defined in the RFC with all the timers and
|
|
|
|
* all the parameters configurable.
|
2000-06-04 17:06:18 +00:00
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* In incoming direction, we listen on the connection's socket and each time we
|
|
|
|
* receive some input, we pass it to bgp_rx(). It decodes packet headers and the
|
|
|
|
* markers and passes complete packets to bgp_rx_packet() which distributes the
|
|
|
|
* packet according to its type.
|
2000-06-04 17:06:18 +00:00
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* In outgoing direction, we gather all the routing updates and sort them to
|
|
|
|
* buckets (&bgp_bucket) according to their attributes (we keep a hash table for
|
|
|
|
* fast comparison of &rta's and a &fib which helps us to find if we already
|
|
|
|
* have another route for the same destination queued for sending, so that we
|
|
|
|
* can replace it with the new one immediately instead of sending both
|
|
|
|
* updates). There also exists a special bucket holding all the route
|
|
|
|
* withdrawals which cannot be queued anywhere else as they don't have any
|
|
|
|
* attributes. If we have any packet to send (due to either new routes or the
|
|
|
|
* connection tracking code wanting to send a Open, Keepalive or Notification
|
|
|
|
* message), we call bgp_schedule_packet() which sets the corresponding bit in a
|
|
|
|
* @packet_to_send bit field in &bgp_conn and as soon as the transmit socket
|
|
|
|
* buffer becomes empty, we call bgp_fire_tx(). It inspects state of all the
|
|
|
|
* packet type bits and calls the corresponding bgp_create_xx() functions,
|
|
|
|
* eventually rescheduling the same packet type if we have more data of the same
|
|
|
|
* type to send.
|
2000-06-04 17:06:18 +00:00
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* The processing of attributes consists of two functions: bgp_decode_attrs()
|
|
|
|
* for checking of the attribute blocks and translating them to the language of
|
|
|
|
* BIRD's extended attributes and bgp_encode_attrs() which does the
|
|
|
|
* converse. Both functions are built around a @bgp_attr_table array describing
|
|
|
|
* all important characteristics of all known attributes. Unknown transitive
|
|
|
|
* attributes are attached to the route as %EAF_TYPE_OPAQUE byte streams.
|
2014-03-23 00:35:33 +00:00
|
|
|
*
|
|
|
|
* BGP protocol implements graceful restart in both restarting (local restart)
|
|
|
|
* and receiving (neighbor restart) roles. The first is handled mostly by the
|
|
|
|
* graceful restart code in the nest, BGP protocol just handles capabilities,
|
|
|
|
* sets @gr_wait and locks graceful restart until end-of-RIB mark is received.
|
|
|
|
* The second is implemented by internal restart of the BGP state to %BS_IDLE
|
|
|
|
* and protocol state to %PS_START, but keeping the protocol up from the core
|
|
|
|
* point of view and therefore maintaining received routes. Routing table
|
|
|
|
* refresh cycle (rt_refresh_begin(), rt_refresh_end()) is used for removing
|
|
|
|
* stale routes after reestablishment of BGP session during graceful restart.
|
2017-03-29 11:48:23 +00:00
|
|
|
*
|
|
|
|
* Supported standards:
|
2018-12-12 15:38:30 +00:00
|
|
|
* RFC 4271 - Border Gateway Protocol 4 (BGP)
|
|
|
|
* RFC 1997 - BGP Communities Attribute
|
|
|
|
* RFC 2385 - Protection of BGP Sessions via TCP MD5 Signature
|
|
|
|
* RFC 2545 - Use of BGP Multiprotocol Extensions for IPv6
|
|
|
|
* RFC 2918 - Route Refresh Capability
|
|
|
|
* RFC 3107 - Carrying Label Information in BGP
|
|
|
|
* RFC 4360 - BGP Extended Communities Attribute
|
|
|
|
* RFC 4364 - BGP/MPLS IPv4 Virtual Private Networks
|
|
|
|
* RFC 4456 - BGP Route Reflection
|
|
|
|
* RFC 4486 - Subcodes for BGP Cease Notification Message
|
|
|
|
* RFC 4659 - BGP/MPLS IPv6 Virtual Private Networks
|
|
|
|
* RFC 4724 - Graceful Restart Mechanism for BGP
|
|
|
|
* RFC 4760 - Multiprotocol extensions for BGP
|
|
|
|
* RFC 4798 - Connecting IPv6 Islands over IPv4 MPLS
|
|
|
|
* RFC 5065 - AS confederations for BGP
|
|
|
|
* RFC 5082 - Generalized TTL Security Mechanism
|
|
|
|
* RFC 5492 - Capabilities Advertisement with BGP
|
|
|
|
* RFC 5549 - Advertising IPv4 NLRI with an IPv6 Next Hop
|
|
|
|
* RFC 5575 - Dissemination of Flow Specification Rules
|
|
|
|
* RFC 5668 - 4-Octet AS Specific BGP Extended Community
|
|
|
|
* RFC 6286 - AS-Wide Unique BGP Identifier
|
|
|
|
* RFC 6608 - Subcodes for BGP Finite State Machine Error
|
|
|
|
* RFC 6793 - BGP Support for 4-Octet AS Numbers
|
2019-09-28 12:17:20 +00:00
|
|
|
* RFC 7311 - Accumulated IGP Metric Attribute for BGP
|
2018-12-12 15:38:30 +00:00
|
|
|
* RFC 7313 - Enhanced Route Refresh Capability for BGP
|
|
|
|
* RFC 7606 - Revised Error Handling for BGP UPDATE Messages
|
|
|
|
* RFC 7911 - Advertisement of Multiple Paths in BGP
|
|
|
|
* RFC 7947 - Internet Exchange BGP Route Server
|
|
|
|
* RFC 8092 - BGP Large Communities Attribute
|
|
|
|
* RFC 8203 - BGP Administrative Shutdown Communication
|
|
|
|
* RFC 8212 - Default EBGP Route Propagation Behavior without Policies
|
2019-10-25 23:28:38 +00:00
|
|
|
* RFC 8654 - Extended Message Support for BGP
|
2023-02-19 14:35:07 +00:00
|
|
|
* RFC 9072 - Extended Optional Parameters Length for BGP OPEN Message
|
2021-12-20 19:25:35 +00:00
|
|
|
* RFC 9117 - Revised Validation Procedure for BGP Flow Specifications
|
2022-07-11 15:19:34 +00:00
|
|
|
* RFC 9234 - Route Leak Prevention and Detection Using Roles
|
2018-12-12 15:38:30 +00:00
|
|
|
* draft-uttaro-idr-bgp-persistence-04
|
2021-02-10 15:53:57 +00:00
|
|
|
* draft-walton-bgp-hostname-capability-02
|
2018-12-12 15:38:30 +00:00
|
|
|
*/
|
2000-06-04 17:06:18 +00:00
|
|
|
|
2009-03-18 19:30:21 +00:00
|
|
|
#undef LOCAL_DEBUG
|
2000-03-19 22:09:07 +00:00
|
|
|
|
2017-06-01 10:33:20 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-03-19 22:09:07 +00:00
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/route.h"
|
2010-04-06 22:19:23 +00:00
|
|
|
#include "nest/cli.h"
|
2013-11-19 21:33:48 +00:00
|
|
|
#include "nest/locks.h"
|
2000-03-19 22:09:07 +00:00
|
|
|
#include "conf/conf.h"
|
2018-01-16 03:14:49 +00:00
|
|
|
#include "filter/filter.h"
|
2000-03-20 21:50:17 +00:00
|
|
|
#include "lib/socket.h"
|
2000-03-30 18:44:23 +00:00
|
|
|
#include "lib/resource.h"
|
2002-11-13 08:47:06 +00:00
|
|
|
#include "lib/string.h"
|
2000-03-19 22:09:07 +00:00
|
|
|
|
|
|
|
#include "bgp.h"
|
2021-03-29 20:45:21 +00:00
|
|
|
#include "proto/bmp/bmp.h"
|
2000-03-19 22:09:07 +00:00
|
|
|
|
2013-11-26 21:37:24 +00:00
|
|
|
|
2022-03-02 10:22:32 +00:00
|
|
|
static list STATIC_LIST_INIT(bgp_sockets); /* Global list of listening sockets */
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2000-03-20 21:50:17 +00:00
|
|
|
|
|
|
|
static void bgp_connect(struct bgp_proto *p);
|
2009-06-06 16:16:22 +00:00
|
|
|
static void bgp_active(struct bgp_proto *p);
|
2019-04-08 15:05:07 +00:00
|
|
|
static void bgp_setup_conn(struct bgp_proto *p, struct bgp_conn *conn);
|
|
|
|
static void bgp_setup_sk(struct bgp_conn *conn, sock *s);
|
|
|
|
static void bgp_send_open(struct bgp_conn *conn);
|
2020-11-08 14:33:22 +00:00
|
|
|
static void bgp_update_bfd(struct bgp_proto *p, const struct bfd_options *bfd);
|
2000-03-19 22:09:07 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
static int bgp_incoming_connection(sock *sk, uint dummy UNUSED);
|
|
|
|
static void bgp_listen_sock_err(sock *sk UNUSED, int err);
|
2008-10-26 21:36:08 +00:00
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
/**
|
|
|
|
* bgp_open - open a BGP instance
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* This function allocates and configures shared BGP resources, mainly listening
|
|
|
|
* sockets. Should be called as the last step during initialization (when lock
|
|
|
|
* is acquired and neighbor is ready). When error, caller should change state to
|
|
|
|
* PS_DOWN and return immediately.
|
2008-12-19 00:34:39 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
bgp_open(struct bgp_proto *p)
|
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_socket *bs = NULL;
|
|
|
|
struct iface *ifa = p->cf->strict_bind ? p->cf->iface : NULL;
|
|
|
|
ip_addr addr = p->cf->strict_bind ? p->cf->local_ip :
|
2019-04-08 15:05:07 +00:00
|
|
|
(p->ipv4 ? IPA_NONE4 : IPA_NONE6);
|
2016-12-07 13:11:28 +00:00
|
|
|
uint port = p->cf->local_port;
|
2022-01-09 01:40:58 +00:00
|
|
|
uint flags = p->cf->free_bind ? SKF_FREEBIND : 0;
|
|
|
|
uint flag_mask = SKF_FREEBIND;
|
2016-12-07 13:11:28 +00:00
|
|
|
|
|
|
|
/* We assume that cf->iface is defined iff cf->local_ip is link-local */
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
WALK_LIST(bs, bgp_sockets)
|
2022-01-09 01:40:58 +00:00
|
|
|
if (ipa_equal(bs->sk->saddr, addr) &&
|
|
|
|
(bs->sk->sport == port) &&
|
|
|
|
(bs->sk->iface == ifa) &&
|
|
|
|
(bs->sk->vrf == p->p.vrf) &&
|
|
|
|
((bs->sk->flags & flag_mask) == flags))
|
2010-05-31 09:35:29 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
bs->uc++;
|
|
|
|
p->sock = bs;
|
|
|
|
return 0;
|
2010-05-31 09:35:29 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
sock *sk = sk_new(proto_pool);
|
|
|
|
sk->type = SK_TCP_PASSIVE;
|
|
|
|
sk->ttl = 255;
|
|
|
|
sk->saddr = addr;
|
|
|
|
sk->sport = port;
|
2018-10-26 17:11:33 +00:00
|
|
|
sk->iface = ifa;
|
|
|
|
sk->vrf = p->p.vrf;
|
2022-01-09 01:40:58 +00:00
|
|
|
sk->flags = flags;
|
2016-12-07 13:11:28 +00:00
|
|
|
sk->tos = IP_PREC_INTERNET_CONTROL;
|
|
|
|
sk->rbsize = BGP_RX_BUFFER_SIZE;
|
|
|
|
sk->tbsize = BGP_TX_BUFFER_SIZE;
|
|
|
|
sk->rx_hook = bgp_incoming_connection;
|
|
|
|
sk->err_hook = bgp_listen_sock_err;
|
|
|
|
|
|
|
|
if (sk_open(sk) < 0)
|
|
|
|
goto err;
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
bs = mb_allocz(proto_pool, sizeof(struct bgp_socket));
|
|
|
|
bs->sk = sk;
|
|
|
|
bs->uc = 1;
|
|
|
|
p->sock = bs;
|
2019-01-02 15:01:21 +00:00
|
|
|
sk->data = bs;
|
2014-05-18 09:42:26 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
add_tail(&bgp_sockets, &bs->n);
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
return 0;
|
2011-08-16 21:05:35 +00:00
|
|
|
|
|
|
|
err:
|
2016-12-07 13:11:28 +00:00
|
|
|
sk_log_error(sk, p->p.name);
|
|
|
|
log(L_ERR "%s: Cannot open listening socket", p->p.name);
|
|
|
|
rfree(sk);
|
2011-08-16 21:05:35 +00:00
|
|
|
return -1;
|
2008-12-19 00:34:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/**
|
|
|
|
* bgp_close - close a BGP instance
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
|
|
|
* This function frees and deconfigures shared BGP resources.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
bgp_close(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
struct bgp_socket *bs = p->sock;
|
|
|
|
|
|
|
|
ASSERT(bs && bs->uc);
|
|
|
|
|
|
|
|
if (--bs->uc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rfree(bs->sk);
|
|
|
|
rem_node(&bs->n);
|
|
|
|
mb_free(bs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
bgp_setup_auth(struct bgp_proto *p, int enable)
|
|
|
|
{
|
|
|
|
if (p->cf->password)
|
|
|
|
{
|
2020-02-27 15:16:48 +00:00
|
|
|
ip_addr prefix = p->cf->remote_ip;
|
|
|
|
int pxlen = -1;
|
|
|
|
|
|
|
|
if (p->cf->remote_range)
|
|
|
|
{
|
|
|
|
prefix = net_prefix(p->cf->remote_range);
|
|
|
|
pxlen = net_pxlen(p->cf->remote_range);
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
int rv = sk_set_md5_auth(p->sock->sk,
|
2020-02-27 15:16:48 +00:00
|
|
|
p->cf->local_ip, prefix, pxlen, p->cf->iface,
|
2016-12-07 13:11:28 +00:00
|
|
|
enable ? p->cf->password : NULL, p->cf->setkey);
|
|
|
|
|
|
|
|
if (rv < 0)
|
|
|
|
sk_log_error(p->sock->sk, p->p.name);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct bgp_channel *
|
|
|
|
bgp_find_channel(struct bgp_proto *p, u32 afi)
|
|
|
|
{
|
|
|
|
struct bgp_channel *c;
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_WALK_CHANNELS(p, c)
|
2016-12-07 13:11:28 +00:00
|
|
|
if (c->afi == afi)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-06 16:16:22 +00:00
|
|
|
static void
|
|
|
|
bgp_startup(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "Started");
|
2016-12-07 13:11:28 +00:00
|
|
|
p->start_state = BSS_CONNECT;
|
2009-09-24 20:12:11 +00:00
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
if (!p->passive)
|
2009-09-24 20:12:11 +00:00
|
|
|
bgp_active(p);
|
2019-04-08 15:05:07 +00:00
|
|
|
|
|
|
|
if (p->postponed_sk)
|
|
|
|
{
|
|
|
|
/* Apply postponed incoming connection */
|
|
|
|
bgp_setup_conn(p, &p->incoming_conn);
|
|
|
|
bgp_setup_sk(&p->incoming_conn, p->postponed_sk);
|
|
|
|
bgp_send_open(&p->incoming_conn);
|
|
|
|
p->postponed_sk = NULL;
|
|
|
|
}
|
2009-06-06 16:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_startup_timeout(timer *t)
|
|
|
|
{
|
|
|
|
bgp_startup(t->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_initiate(struct bgp_proto *p)
|
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
int err_val;
|
|
|
|
|
|
|
|
if (bgp_open(p) < 0)
|
|
|
|
{ err_val = BEM_NO_SOCKET; goto err1; }
|
|
|
|
|
|
|
|
if (bgp_setup_auth(p, 1) < 0)
|
|
|
|
{ err_val = BEM_INVALID_MD5; goto err2; }
|
2010-07-12 15:39:39 +00:00
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
if (p->cf->bfd)
|
|
|
|
bgp_update_bfd(p, p->cf->bfd);
|
|
|
|
|
2009-06-06 16:16:22 +00:00
|
|
|
if (p->startup_delay)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
p->start_state = BSS_DELAY;
|
|
|
|
BGP_TRACE(D_EVENTS, "Startup delayed by %d seconds due to errors", p->startup_delay);
|
|
|
|
bgp_start_timer(p->startup_timer, p->startup_delay);
|
|
|
|
}
|
2009-06-06 16:16:22 +00:00
|
|
|
else
|
|
|
|
bgp_startup(p);
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
return;
|
2008-10-26 21:42:39 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
err2:
|
|
|
|
bgp_close(p);
|
|
|
|
err1:
|
|
|
|
p->p.disabled = 1;
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, err_val);
|
2021-05-31 23:59:20 +00:00
|
|
|
|
|
|
|
p->neigh = NULL;
|
2016-12-07 13:11:28 +00:00
|
|
|
proto_notify_state(&p->p, PS_DOWN);
|
2008-10-26 21:42:39 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
return;
|
2000-03-20 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2000-06-04 17:06:18 +00:00
|
|
|
/**
|
|
|
|
* bgp_start_timer - start a BGP timer
|
|
|
|
* @t: timer
|
2017-06-21 12:14:51 +00:00
|
|
|
* @value: time (in seconds) to fire (0 to disable the timer)
|
2000-06-04 17:06:18 +00:00
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* This functions calls tm_start() on @t with time @value and the amount of
|
|
|
|
* randomization suggested by the BGP standard. Please use it for all BGP
|
|
|
|
* timers.
|
2000-06-04 17:06:18 +00:00
|
|
|
*/
|
2000-03-30 10:44:20 +00:00
|
|
|
void
|
2017-06-21 12:14:51 +00:00
|
|
|
bgp_start_timer(timer *t, uint value)
|
2000-03-20 21:50:17 +00:00
|
|
|
{
|
2000-03-30 10:44:20 +00:00
|
|
|
if (value)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
2017-06-21 12:14:51 +00:00
|
|
|
/* The randomization procedure is specified in RFC 4271 section 10 */
|
|
|
|
btime time = value S;
|
|
|
|
btime randomize = random() % ((time / 4) + 1);
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_start(t, time - randomize);
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2000-03-30 17:39:48 +00:00
|
|
|
else
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_stop(t);
|
2000-03-30 17:39:48 +00:00
|
|
|
}
|
|
|
|
|
2000-06-04 17:06:18 +00:00
|
|
|
/**
|
|
|
|
* bgp_close_conn - close a BGP connection
|
|
|
|
* @conn: connection to close
|
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* This function takes a connection described by the &bgp_conn structure, closes
|
|
|
|
* its socket and frees all resources associated with it.
|
2000-06-04 17:06:18 +00:00
|
|
|
*/
|
2000-03-30 17:39:48 +00:00
|
|
|
void
|
|
|
|
bgp_close_conn(struct bgp_conn *conn)
|
|
|
|
{
|
2010-02-21 13:34:53 +00:00
|
|
|
// struct bgp_proto *p = conn->bgp;
|
2000-03-30 17:39:48 +00:00
|
|
|
|
|
|
|
DBG("BGP: Closing connection\n");
|
|
|
|
conn->packets_to_send = 0;
|
2016-12-07 13:11:28 +00:00
|
|
|
conn->channels_to_send = 0;
|
|
|
|
rfree(conn->connect_timer);
|
|
|
|
conn->connect_timer = NULL;
|
2000-03-30 17:39:48 +00:00
|
|
|
rfree(conn->keepalive_timer);
|
|
|
|
conn->keepalive_timer = NULL;
|
|
|
|
rfree(conn->hold_timer);
|
|
|
|
conn->hold_timer = NULL;
|
2008-12-19 00:34:39 +00:00
|
|
|
rfree(conn->tx_ev);
|
|
|
|
conn->tx_ev = NULL;
|
2016-12-07 13:11:28 +00:00
|
|
|
rfree(conn->sk);
|
|
|
|
conn->sk = NULL;
|
|
|
|
|
|
|
|
mb_free(conn->local_caps);
|
|
|
|
conn->local_caps = NULL;
|
|
|
|
mb_free(conn->remote_caps);
|
|
|
|
conn->remote_caps = NULL;
|
2008-12-19 00:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bgp_update_startup_delay - update a startup delay
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
2016-12-07 13:11:28 +00:00
|
|
|
* This function updates a startup delay that is used to postpone next BGP
|
|
|
|
* connect. It also handles disable_after_error and might stop BGP instance
|
|
|
|
* when error happened and disable_after_error is on.
|
2008-12-19 00:34:39 +00:00
|
|
|
*
|
|
|
|
* It should be called when BGP protocol error happened.
|
|
|
|
*/
|
|
|
|
void
|
2009-06-06 22:38:38 +00:00
|
|
|
bgp_update_startup_delay(struct bgp_proto *p)
|
2008-12-19 00:34:39 +00:00
|
|
|
{
|
2019-04-02 15:22:31 +00:00
|
|
|
const struct bgp_config *cf = p->cf;
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2009-06-06 22:38:38 +00:00
|
|
|
DBG("BGP: Updating startup delay\n");
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2017-06-21 12:14:51 +00:00
|
|
|
if (p->last_proto_error && ((current_time() - p->last_proto_error) >= cf->error_amnesia_time S))
|
2009-06-06 16:56:33 +00:00
|
|
|
p->startup_delay = 0;
|
|
|
|
|
2017-06-21 12:14:51 +00:00
|
|
|
p->last_proto_error = current_time();
|
2008-12-19 00:34:39 +00:00
|
|
|
|
|
|
|
if (cf->disable_after_error)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
p->startup_delay = 0;
|
|
|
|
p->p.disabled = 1;
|
|
|
|
return;
|
|
|
|
}
|
2008-12-19 00:34:39 +00:00
|
|
|
|
|
|
|
if (!p->startup_delay)
|
|
|
|
p->startup_delay = cf->error_delay_time_min;
|
|
|
|
else
|
2009-06-06 22:38:38 +00:00
|
|
|
p->startup_delay = MIN(2 * p->startup_delay, cf->error_delay_time_max);
|
2000-03-20 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
static void
|
2019-06-18 14:27:21 +00:00
|
|
|
bgp_graceful_close_conn(struct bgp_conn *conn, int subcode, byte *data, uint len)
|
2000-04-10 11:21:40 +00:00
|
|
|
{
|
2008-12-19 00:34:39 +00:00
|
|
|
switch (conn->state)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
case BS_IDLE:
|
|
|
|
case BS_CLOSE:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case BS_CONNECT:
|
|
|
|
case BS_ACTIVE:
|
|
|
|
bgp_conn_enter_idle_state(conn);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case BS_OPENSENT:
|
|
|
|
case BS_OPENCONFIRM:
|
|
|
|
case BS_ESTABLISHED:
|
2019-06-18 14:27:21 +00:00
|
|
|
if (subcode < 0)
|
|
|
|
{
|
|
|
|
bgp_conn_enter_close_state(conn);
|
|
|
|
bgp_schedule_packet(conn, NULL, PKT_SCHEDULE_CLOSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bgp_error(conn, 6, subcode, data, len);
|
2016-12-07 13:11:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
bug("bgp_graceful_close_conn: Unknown state %d", conn->state);
|
|
|
|
}
|
2000-04-10 11:21:40 +00:00
|
|
|
}
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
static void
|
|
|
|
bgp_down(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
if (p->start_state > BSS_PREPARE)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
bgp_setup_auth(p, 0);
|
|
|
|
bgp_close(p);
|
|
|
|
}
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2021-05-31 23:59:20 +00:00
|
|
|
p->neigh = NULL;
|
|
|
|
|
2009-06-06 22:38:38 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Down");
|
2008-12-19 00:34:39 +00:00
|
|
|
proto_notify_state(&p->p, PS_DOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_decision(void *vp)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = vp;
|
|
|
|
|
|
|
|
DBG("BGP: Decision start\n");
|
2016-12-07 13:11:28 +00:00
|
|
|
if ((p->p.proto_state == PS_START) &&
|
|
|
|
(p->outgoing_conn.state == BS_IDLE) &&
|
|
|
|
(p->incoming_conn.state != BS_OPENCONFIRM) &&
|
2019-04-08 15:05:07 +00:00
|
|
|
!p->passive)
|
2009-06-06 16:16:22 +00:00
|
|
|
bgp_active(p);
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if ((p->p.proto_state == PS_STOP) &&
|
|
|
|
(p->outgoing_conn.state == BS_IDLE) &&
|
|
|
|
(p->incoming_conn.state == BS_IDLE))
|
2008-12-19 00:34:39 +00:00
|
|
|
bgp_down(p);
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
static struct bgp_proto *
|
|
|
|
bgp_spawn(struct bgp_proto *pp, ip_addr remote_ip)
|
|
|
|
{
|
|
|
|
struct symbol *sym;
|
|
|
|
char fmt[SYM_MAX_LEN];
|
|
|
|
|
|
|
|
bsprintf(fmt, "%s%%0%dd", pp->cf->dynamic_name, pp->cf->dynamic_name_digits);
|
|
|
|
|
|
|
|
/* This is hack, we would like to share config, but we need to copy it now */
|
|
|
|
new_config = config;
|
|
|
|
cfg_mem = config->mem;
|
|
|
|
conf_this_scope = config->root_scope;
|
|
|
|
sym = cf_default_name(fmt, &(pp->dynamic_name_counter));
|
|
|
|
proto_clone_config(sym, pp->p.cf);
|
|
|
|
new_config = NULL;
|
|
|
|
cfg_mem = NULL;
|
|
|
|
|
|
|
|
/* Just pass remote_ip to bgp_init() */
|
2019-07-03 09:09:52 +00:00
|
|
|
((struct bgp_config *) sym->proto)->remote_ip = remote_ip;
|
2019-04-08 15:05:07 +00:00
|
|
|
|
2019-07-03 09:09:52 +00:00
|
|
|
return (void *) proto_spawn(sym->proto, 0);
|
2019-04-08 15:05:07 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 22:38:38 +00:00
|
|
|
void
|
2019-06-18 14:27:21 +00:00
|
|
|
bgp_stop(struct bgp_proto *p, int subcode, byte *data, uint len)
|
2008-12-19 00:34:39 +00:00
|
|
|
{
|
|
|
|
proto_notify_state(&p->p, PS_STOP);
|
2017-09-19 17:55:37 +00:00
|
|
|
bgp_graceful_close_conn(&p->outgoing_conn, subcode, data, len);
|
|
|
|
bgp_graceful_close_conn(&p->incoming_conn, subcode, data, len);
|
2008-12-19 00:34:39 +00:00
|
|
|
ev_schedule(p->event);
|
|
|
|
}
|
|
|
|
|
2010-01-03 11:17:52 +00:00
|
|
|
static inline void
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_conn_set_state(struct bgp_conn *conn, uint new_state)
|
2010-01-03 11:17:52 +00:00
|
|
|
{
|
|
|
|
if (conn->bgp->p.mrtdump & MD_STATES)
|
2018-11-20 16:38:19 +00:00
|
|
|
bgp_dump_state_change(conn, conn->state, new_state);
|
2010-01-03 11:17:52 +00:00
|
|
|
|
|
|
|
conn->state = new_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bgp_conn_enter_openconfirm_state(struct bgp_conn *conn)
|
|
|
|
{
|
|
|
|
/* Really, most of the work is done in bgp_rx_open(). */
|
|
|
|
bgp_conn_set_state(conn, BS_OPENCONFIRM);
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
static const struct bgp_af_caps dummy_af_caps = { };
|
2019-03-15 19:54:01 +00:00
|
|
|
static const struct bgp_af_caps basic_af_caps = { .ready = 1 };
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
void
|
|
|
|
bgp_conn_enter_established_state(struct bgp_conn *conn)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = conn->bgp;
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_caps *local = conn->local_caps;
|
|
|
|
struct bgp_caps *peer = conn->remote_caps;
|
|
|
|
struct bgp_channel *c;
|
2015-02-21 10:46:14 +00:00
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "BGP session established");
|
2019-12-03 17:05:41 +00:00
|
|
|
p->last_established = current_time();
|
|
|
|
p->stats.fsm_established_transitions++;
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2010-07-12 15:39:39 +00:00
|
|
|
/* For multi-hop BGP sessions */
|
2019-04-02 15:22:31 +00:00
|
|
|
if (ipa_zero(p->local_ip))
|
|
|
|
p->local_ip = conn->sk->saddr;
|
2010-07-12 15:39:39 +00:00
|
|
|
|
2019-04-03 13:54:50 +00:00
|
|
|
/* For promiscuous sessions */
|
|
|
|
if (!p->remote_as)
|
|
|
|
p->remote_as = conn->received_as;
|
|
|
|
|
2019-01-02 14:57:14 +00:00
|
|
|
/* In case of LLv6 is not valid during BGP start */
|
|
|
|
if (ipa_zero(p->link_addr) && p->neigh && p->neigh->iface && p->neigh->iface->llv6)
|
|
|
|
p->link_addr = p->neigh->iface->llv6->ip;
|
|
|
|
|
2016-04-06 09:49:34 +00:00
|
|
|
conn->sk->fast_rx = 0;
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
p->conn = conn;
|
|
|
|
p->last_error_class = 0;
|
|
|
|
p->last_error_code = 0;
|
2012-08-14 14:25:22 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
p->as4_session = conn->as4_session;
|
|
|
|
|
|
|
|
p->route_refresh = peer->route_refresh;
|
|
|
|
p->enhanced_refresh = local->enhanced_refresh && peer->enhanced_refresh;
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
/* Whether we may handle possible GR/LLGR of peer (it has some AF GR-able) */
|
|
|
|
p->gr_ready = p->llgr_ready = 0; /* Updated later */
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Whether peer is ready to handle our GR recovery */
|
|
|
|
int peer_gr_ready = peer->gr_aware && !(peer->gr_flags & BGP_GRF_RESTART);
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (p->gr_active_num)
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_stop(p->gr_timer);
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Number of active channels */
|
|
|
|
int num = 0;
|
|
|
|
|
2018-11-20 16:38:19 +00:00
|
|
|
/* Summary state of ADD_PATH RX for active channels */
|
|
|
|
uint summary_add_path_rx = 0;
|
|
|
|
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_WALK_CHANNELS(p, c)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
const struct bgp_af_caps *loc = bgp_find_af_caps(local, c->afi);
|
|
|
|
const struct bgp_af_caps *rem = bgp_find_af_caps(peer, c->afi);
|
|
|
|
|
2019-03-15 19:54:01 +00:00
|
|
|
/* Use default if capabilities were not announced */
|
|
|
|
if (!local->length && (c->afi == BGP_AF_IPV4))
|
|
|
|
loc = &basic_af_caps;
|
|
|
|
|
|
|
|
if (!peer->length && (c->afi == BGP_AF_IPV4))
|
|
|
|
rem = &basic_af_caps;
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Ignore AFIs that were not announced in multiprotocol capability */
|
|
|
|
if (!loc || !loc->ready)
|
|
|
|
loc = &dummy_af_caps;
|
|
|
|
|
|
|
|
if (!rem || !rem->ready)
|
|
|
|
rem = &dummy_af_caps;
|
|
|
|
|
|
|
|
int active = loc->ready && rem->ready;
|
|
|
|
c->c.disabled = !active;
|
2018-09-27 20:57:55 +00:00
|
|
|
c->c.reloadable = p->route_refresh || c->cf->import_table;
|
2016-12-07 13:11:28 +00:00
|
|
|
|
|
|
|
c->index = active ? num++ : 0;
|
|
|
|
|
|
|
|
c->feed_state = BFS_NONE;
|
|
|
|
c->load_state = BFS_NONE;
|
|
|
|
|
|
|
|
/* Channels where peer may do GR */
|
2018-07-31 16:40:38 +00:00
|
|
|
uint gr_ready = active && local->gr_aware && rem->gr_able;
|
|
|
|
uint llgr_ready = active && local->llgr_aware && rem->llgr_able;
|
|
|
|
|
|
|
|
c->gr_ready = gr_ready || llgr_ready;
|
2016-12-07 13:11:28 +00:00
|
|
|
p->gr_ready = p->gr_ready || c->gr_ready;
|
2018-07-31 16:40:38 +00:00
|
|
|
p->llgr_ready = p->llgr_ready || llgr_ready;
|
|
|
|
|
|
|
|
/* Remember last LLGR stale time */
|
|
|
|
c->stale_time = local->llgr_aware ? rem->llgr_time : 0;
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Channels not able to recover gracefully */
|
|
|
|
if (p->p.gr_recovery && (!active || !peer_gr_ready))
|
|
|
|
channel_graceful_restart_unlock(&c->c);
|
2015-03-29 16:27:13 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Channels waiting for local convergence */
|
|
|
|
if (p->p.gr_recovery && loc->gr_able && peer_gr_ready)
|
|
|
|
c->c.gr_wait = 1;
|
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
/* Channels where regular graceful restart failed */
|
|
|
|
if ((c->gr_active == BGP_GRS_ACTIVE) &&
|
|
|
|
!(active && rem->gr_able && (rem->gr_af_flags & BGP_GRF_FORWARDING)))
|
|
|
|
bgp_graceful_restart_done(c);
|
|
|
|
|
|
|
|
/* Channels where regular long-lived restart failed */
|
|
|
|
if ((c->gr_active == BGP_GRS_LLGR) &&
|
|
|
|
!(active && rem->llgr_able && (rem->gr_af_flags & BGP_LLGRF_FORWARDING)))
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_graceful_restart_done(c);
|
|
|
|
|
|
|
|
/* GR capability implies that neighbor will send End-of-RIB */
|
|
|
|
if (peer->gr_aware)
|
|
|
|
c->load_state = BFS_LOADING;
|
|
|
|
|
2017-01-24 01:00:35 +00:00
|
|
|
c->ext_next_hop = c->cf->ext_next_hop && (bgp_channel_is_ipv6(c) || rem->ext_next_hop);
|
2016-12-07 13:11:28 +00:00
|
|
|
c->add_path_rx = (loc->add_path & BGP_ADD_PATH_RX) && (rem->add_path & BGP_ADD_PATH_TX);
|
|
|
|
c->add_path_tx = (loc->add_path & BGP_ADD_PATH_TX) && (rem->add_path & BGP_ADD_PATH_RX);
|
|
|
|
|
2018-11-20 16:38:19 +00:00
|
|
|
if (active)
|
|
|
|
summary_add_path_rx |= !c->add_path_rx ? 1 : 2;
|
|
|
|
|
2016-12-23 22:03:26 +00:00
|
|
|
/* Update RA mode */
|
2016-12-07 13:11:28 +00:00
|
|
|
if (c->add_path_tx)
|
|
|
|
c->c.ra_mode = RA_ANY;
|
2016-12-23 22:03:26 +00:00
|
|
|
else if (c->cf->secondary)
|
|
|
|
c->c.ra_mode = RA_ACCEPTED;
|
|
|
|
else
|
|
|
|
c->c.ra_mode = RA_OPTIMAL;
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p->afi_map = mb_alloc(p->p.pool, num * sizeof(u32));
|
|
|
|
p->channel_map = mb_alloc(p->p.pool, num * sizeof(void *));
|
|
|
|
p->channel_count = num;
|
2018-11-20 16:38:19 +00:00
|
|
|
p->summary_add_path_rx = summary_add_path_rx;
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_WALK_CHANNELS(p, c)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
if (c->c.disabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p->afi_map[c->index] = c->afi;
|
|
|
|
p->channel_map[c->index] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* proto_notify_state() will likely call bgp_feed_begin(), setting c->feed_state */
|
2015-03-29 16:27:13 +00:00
|
|
|
|
2010-01-03 11:17:52 +00:00
|
|
|
bgp_conn_set_state(conn, BS_ESTABLISHED);
|
2008-12-19 00:34:39 +00:00
|
|
|
proto_notify_state(&p->p, PS_UP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_conn_leave_established_state(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "BGP session closed");
|
2019-12-03 17:05:41 +00:00
|
|
|
p->last_established = current_time();
|
2008-12-19 00:34:39 +00:00
|
|
|
p->conn = NULL;
|
|
|
|
|
|
|
|
if (p->p.proto_state == PS_UP)
|
2017-09-19 17:55:37 +00:00
|
|
|
bgp_stop(p, 0, NULL, 0);
|
2008-12-19 00:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bgp_conn_enter_close_state(struct bgp_conn *conn)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = conn->bgp;
|
|
|
|
int os = conn->state;
|
|
|
|
|
2010-01-03 11:17:52 +00:00
|
|
|
bgp_conn_set_state(conn, BS_CLOSE);
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_stop(conn->keepalive_timer);
|
2008-12-19 00:34:39 +00:00
|
|
|
conn->sk->rx_hook = NULL;
|
|
|
|
|
2013-07-12 23:39:41 +00:00
|
|
|
/* Timeout for CLOSE state, if we cannot send notification soon then we just hangup */
|
|
|
|
bgp_start_timer(conn->hold_timer, 10);
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
if (os == BS_ESTABLISHED)
|
|
|
|
bgp_conn_leave_established_state(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bgp_conn_enter_idle_state(struct bgp_conn *conn)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = conn->bgp;
|
|
|
|
int os = conn->state;
|
|
|
|
|
|
|
|
bgp_close_conn(conn);
|
2010-01-03 11:17:52 +00:00
|
|
|
bgp_conn_set_state(conn, BS_IDLE);
|
2008-12-19 00:34:39 +00:00
|
|
|
ev_schedule(p->event);
|
|
|
|
|
|
|
|
if (os == BS_ESTABLISHED)
|
|
|
|
bgp_conn_leave_established_state(p);
|
|
|
|
}
|
|
|
|
|
2014-03-23 00:35:33 +00:00
|
|
|
/**
|
|
|
|
* bgp_handle_graceful_restart - handle detected BGP graceful restart
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
|
|
|
* This function is called when a BGP graceful restart of the neighbor is
|
|
|
|
* detected (when the TCP connection fails or when a new TCP connection
|
|
|
|
* appears). The function activates processing of the restart - starts routing
|
|
|
|
* table refresh cycle and activates BGP restart timer. The protocol state goes
|
|
|
|
* back to %PS_START, but changing BGP state back to %BS_IDLE is left for the
|
|
|
|
* caller.
|
|
|
|
*/
|
2014-03-20 13:07:12 +00:00
|
|
|
void
|
|
|
|
bgp_handle_graceful_restart(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
ASSERT(p->conn && (p->conn->state == BS_ESTABLISHED) && p->gr_ready);
|
|
|
|
|
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor graceful restart detected%s",
|
2016-12-07 13:11:28 +00:00
|
|
|
p->gr_active_num ? " - already pending" : "");
|
|
|
|
|
|
|
|
p->gr_active_num = 0;
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_channel *c;
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_WALK_CHANNELS(p, c)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
2017-12-09 23:55:34 +00:00
|
|
|
/* FIXME: perhaps check for channel state instead of disabled flag? */
|
|
|
|
if (c->c.disabled)
|
|
|
|
continue;
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (c->gr_ready)
|
|
|
|
{
|
2018-07-31 16:40:38 +00:00
|
|
|
p->gr_active_num++;
|
|
|
|
|
|
|
|
switch (c->gr_active)
|
|
|
|
{
|
|
|
|
case BGP_GRS_NONE:
|
|
|
|
c->gr_active = BGP_GRS_ACTIVE;
|
|
|
|
rt_refresh_begin(c->c.table, &c->c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BGP_GRS_ACTIVE:
|
2016-12-07 13:11:28 +00:00
|
|
|
rt_refresh_end(c->c.table, &c->c);
|
2018-07-31 16:40:38 +00:00
|
|
|
rt_refresh_begin(c->c.table, &c->c);
|
|
|
|
break;
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
case BGP_GRS_LLGR:
|
|
|
|
rt_refresh_begin(c->c.table, &c->c);
|
|
|
|
rt_modify_stale(c->c.table, &c->c);
|
|
|
|
break;
|
|
|
|
}
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Just flush the routes */
|
|
|
|
rt_refresh_begin(c->c.table, &c->c);
|
|
|
|
rt_refresh_end(c->c.table, &c->c);
|
|
|
|
}
|
2017-12-09 23:55:34 +00:00
|
|
|
|
|
|
|
/* Reset bucket and prefix tables */
|
|
|
|
bgp_free_bucket_table(c);
|
|
|
|
bgp_free_prefix_table(c);
|
|
|
|
bgp_init_bucket_table(c);
|
|
|
|
bgp_init_prefix_table(c);
|
|
|
|
c->packets_to_send = 0;
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-02 13:30:08 +00:00
|
|
|
/* p->gr_ready -> at least one active channel is c->gr_ready */
|
|
|
|
ASSERT(p->gr_active_num > 0);
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
proto_notify_state(&p->p, PS_START);
|
2018-07-31 16:40:38 +00:00
|
|
|
tm_start(p->gr_timer, p->conn->remote_caps->gr_time S);
|
2014-03-20 13:07:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 00:35:33 +00:00
|
|
|
/**
|
|
|
|
* bgp_graceful_restart_done - finish active BGP graceful restart
|
2016-12-07 13:11:28 +00:00
|
|
|
* @c: BGP channel
|
2014-03-23 00:35:33 +00:00
|
|
|
*
|
|
|
|
* This function is called when the active BGP graceful restart of the neighbor
|
2016-12-07 13:11:28 +00:00
|
|
|
* should be finished for channel @c - either successfully (the neighbor sends
|
|
|
|
* all paths and reports end-of-RIB for given AFI/SAFI on the new session) or
|
|
|
|
* unsuccessfully (the neighbor does not support BGP graceful restart on the new
|
|
|
|
* session). The function ends the routing table refresh cycle.
|
2014-03-23 00:35:33 +00:00
|
|
|
*/
|
2014-03-20 13:07:12 +00:00
|
|
|
void
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_graceful_restart_done(struct bgp_channel *c)
|
2014-03-20 13:07:12 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_proto *p = (void *) c->c.proto;
|
|
|
|
|
|
|
|
ASSERT(c->gr_active);
|
|
|
|
c->gr_active = 0;
|
|
|
|
p->gr_active_num--;
|
|
|
|
|
|
|
|
if (!p->gr_active_num)
|
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor graceful restart done");
|
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
tm_stop(c->stale_timer);
|
2016-12-07 13:11:28 +00:00
|
|
|
rt_refresh_end(c->c.table, &c->c);
|
2014-03-20 13:07:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 00:35:33 +00:00
|
|
|
/**
|
|
|
|
* bgp_graceful_restart_timeout - timeout of graceful restart 'restart timer'
|
|
|
|
* @t: timer
|
|
|
|
*
|
|
|
|
* This function is a timeout hook for @gr_timer, implementing BGP restart time
|
|
|
|
* limit for reestablisment of the BGP session after the graceful restart. When
|
|
|
|
* fired, we just proceed with the usual protocol restart.
|
|
|
|
*/
|
|
|
|
|
2014-03-20 13:07:12 +00:00
|
|
|
static void
|
|
|
|
bgp_graceful_restart_timeout(timer *t)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = t->data;
|
|
|
|
|
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor graceful restart timeout");
|
2018-07-31 16:40:38 +00:00
|
|
|
|
|
|
|
if (p->llgr_ready)
|
|
|
|
{
|
|
|
|
struct bgp_channel *c;
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_WALK_CHANNELS(p, c)
|
2018-07-31 16:40:38 +00:00
|
|
|
{
|
|
|
|
/* Channel is not in GR and is already flushed */
|
|
|
|
if (!c->gr_active)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Channel is already in LLGR from past restart */
|
|
|
|
if (c->gr_active == BGP_GRS_LLGR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Channel is in GR, but does not support LLGR -> stop GR */
|
|
|
|
if (!c->stale_time)
|
|
|
|
{
|
|
|
|
bgp_graceful_restart_done(c);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Channel is in GR, and supports LLGR -> start LLGR */
|
|
|
|
c->gr_active = BGP_GRS_LLGR;
|
|
|
|
tm_start(c->stale_timer, c->stale_time S);
|
|
|
|
rt_modify_stale(c->c.table, &c->c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2021-03-29 20:45:21 +00:00
|
|
|
{
|
2018-07-31 16:40:38 +00:00
|
|
|
bgp_stop(p, 0, NULL, 0);
|
2021-03-28 13:36:59 +00:00
|
|
|
bmp_peer_down(p, BE_NONE, NULL, 0);
|
2021-03-29 20:45:21 +00:00
|
|
|
}
|
2018-07-31 16:40:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_long_lived_stale_timeout(timer *t)
|
|
|
|
{
|
|
|
|
struct bgp_channel *c = t->data;
|
|
|
|
struct bgp_proto *p = (void *) c->c.proto;
|
|
|
|
|
|
|
|
BGP_TRACE(D_EVENTS, "Long-lived stale timeout");
|
|
|
|
|
|
|
|
bgp_graceful_restart_done(c);
|
2014-03-20 13:07:12 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 16:27:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* bgp_refresh_begin - start incoming enhanced route refresh sequence
|
2016-12-07 13:11:28 +00:00
|
|
|
* @c: BGP channel
|
2015-03-29 16:27:13 +00:00
|
|
|
*
|
|
|
|
* This function is called when an incoming enhanced route refresh sequence is
|
|
|
|
* started by the neighbor, demarcated by the BoRR packet. The function updates
|
|
|
|
* the load state and starts the routing table refresh cycle. Note that graceful
|
|
|
|
* restart also uses routing table refresh cycle, but RFC 7313 and load states
|
|
|
|
* ensure that these two sequences do not overlap.
|
|
|
|
*/
|
|
|
|
void
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_refresh_begin(struct bgp_channel *c)
|
2015-03-29 16:27:13 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_proto *p = (void *) c->c.proto;
|
|
|
|
|
|
|
|
if (c->load_state == BFS_LOADING)
|
|
|
|
{ log(L_WARN "%s: BEGIN-OF-RR received before END-OF-RIB, ignoring", p->p.name); return; }
|
2015-03-29 16:27:13 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
c->load_state = BFS_REFRESHING;
|
|
|
|
rt_refresh_begin(c->c.table, &c->c);
|
2018-09-27 20:57:55 +00:00
|
|
|
|
|
|
|
if (c->c.in_table)
|
|
|
|
rt_refresh_begin(c->c.in_table, &c->c);
|
2015-03-29 16:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bgp_refresh_end - finish incoming enhanced route refresh sequence
|
2016-12-07 13:11:28 +00:00
|
|
|
* @c: BGP channel
|
2015-03-29 16:27:13 +00:00
|
|
|
*
|
|
|
|
* This function is called when an incoming enhanced route refresh sequence is
|
|
|
|
* finished by the neighbor, demarcated by the EoRR packet. The function updates
|
|
|
|
* the load state and ends the routing table refresh cycle. Routes not received
|
|
|
|
* during the sequence are removed by the nest.
|
|
|
|
*/
|
|
|
|
void
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_refresh_end(struct bgp_channel *c)
|
2015-03-29 16:27:13 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_proto *p = (void *) c->c.proto;
|
2015-03-29 16:27:13 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (c->load_state != BFS_REFRESHING)
|
|
|
|
{ log(L_WARN "%s: END-OF-RR received without prior BEGIN-OF-RR, ignoring", p->p.name); return; }
|
|
|
|
|
|
|
|
c->load_state = BFS_NONE;
|
|
|
|
rt_refresh_end(c->c.table, &c->c);
|
2018-09-27 20:57:55 +00:00
|
|
|
|
|
|
|
if (c->c.in_table)
|
|
|
|
rt_prune_sync(c->c.in_table, 0);
|
2015-03-29 16:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-20 21:50:17 +00:00
|
|
|
static void
|
|
|
|
bgp_send_open(struct bgp_conn *conn)
|
|
|
|
{
|
|
|
|
DBG("BGP: Sending open\n");
|
|
|
|
conn->sk->rx_hook = bgp_rx;
|
2000-03-30 17:39:48 +00:00
|
|
|
conn->sk->tx_hook = bgp_tx;
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_stop(conn->connect_timer);
|
2019-04-08 14:39:22 +00:00
|
|
|
bgp_prepare_capabilities(conn);
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_schedule_packet(conn, NULL, PKT_OPEN);
|
2010-01-03 11:17:52 +00:00
|
|
|
bgp_conn_set_state(conn, BS_OPENSENT);
|
2000-03-30 10:44:20 +00:00
|
|
|
bgp_start_timer(conn->hold_timer, conn->bgp->cf->initial_hold_time);
|
2000-03-20 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2000-03-30 10:44:20 +00:00
|
|
|
static void
|
|
|
|
bgp_connected(sock *sk)
|
2000-03-20 21:50:17 +00:00
|
|
|
{
|
|
|
|
struct bgp_conn *conn = sk->data;
|
2000-05-02 16:07:41 +00:00
|
|
|
struct bgp_proto *p = conn->bgp;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2000-05-02 16:07:41 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Connected");
|
2000-03-20 21:50:17 +00:00
|
|
|
bgp_send_open(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_connect_timeout(timer *t)
|
|
|
|
{
|
2000-03-30 10:44:20 +00:00
|
|
|
struct bgp_conn *conn = t->data;
|
2000-05-02 16:07:41 +00:00
|
|
|
struct bgp_proto *p = conn->bgp;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2000-05-02 16:07:41 +00:00
|
|
|
DBG("BGP: connect_timeout\n");
|
2008-12-19 00:34:39 +00:00
|
|
|
if (p->p.proto_state == PS_START)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
bgp_close_conn(conn);
|
|
|
|
bgp_connect(p);
|
|
|
|
}
|
2008-12-19 00:34:39 +00:00
|
|
|
else
|
|
|
|
bgp_conn_enter_idle_state(conn);
|
2000-03-20 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-03-30 10:44:20 +00:00
|
|
|
bgp_sock_err(sock *sk, int err)
|
2000-03-20 21:50:17 +00:00
|
|
|
{
|
|
|
|
struct bgp_conn *conn = sk->data;
|
2000-05-02 16:07:41 +00:00
|
|
|
struct bgp_proto *p = conn->bgp;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2010-05-14 14:54:39 +00:00
|
|
|
/*
|
|
|
|
* This error hook may be called either asynchronously from main
|
|
|
|
* loop, or synchronously from sk_send(). But sk_send() is called
|
|
|
|
* only from bgp_tx() and bgp_kick_tx(), which are both called
|
|
|
|
* asynchronously from main loop. Moreover, they end if err hook is
|
|
|
|
* called. Therefore, we could suppose that it is always called
|
|
|
|
* asynchronously.
|
|
|
|
*/
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
bgp_store_error(p, conn, BE_SOCKET, err);
|
|
|
|
|
2000-05-02 16:10:04 +00:00
|
|
|
if (err)
|
|
|
|
BGP_TRACE(D_EVENTS, "Connection lost (%M)", err);
|
|
|
|
else
|
2021-03-29 20:45:21 +00:00
|
|
|
{
|
2000-05-02 16:10:04 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Connection closed");
|
2021-03-28 13:36:59 +00:00
|
|
|
bmp_peer_down(p, BE_SOCKET, NULL, 0);
|
2021-03-29 20:45:21 +00:00
|
|
|
}
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2014-03-20 13:07:12 +00:00
|
|
|
if ((conn->state == BS_ESTABLISHED) && p->gr_ready)
|
|
|
|
bgp_handle_graceful_restart(p);
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
bgp_conn_enter_idle_state(conn);
|
2000-03-20 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2000-03-30 10:44:20 +00:00
|
|
|
static void
|
|
|
|
bgp_hold_timeout(timer *t)
|
|
|
|
{
|
|
|
|
struct bgp_conn *conn = t->data;
|
2013-07-12 23:39:41 +00:00
|
|
|
struct bgp_proto *p = conn->bgp;
|
2000-03-30 10:44:20 +00:00
|
|
|
|
2009-10-11 16:56:16 +00:00
|
|
|
DBG("BGP: Hold timeout\n");
|
|
|
|
|
2013-07-12 23:39:41 +00:00
|
|
|
/* We are already closing the connection - just do hangup */
|
|
|
|
if (conn->state == BS_CLOSE)
|
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "Connection stalled");
|
|
|
|
bgp_conn_enter_idle_state(conn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-11 16:56:16 +00:00
|
|
|
/* If there is something in input queue, we are probably congested
|
|
|
|
and perhaps just not processed BGP packets in time. */
|
|
|
|
|
|
|
|
if (sk_rx_ready(conn->sk) > 0)
|
|
|
|
bgp_start_timer(conn->hold_timer, 10);
|
2018-07-31 16:40:38 +00:00
|
|
|
else if ((conn->state == BS_ESTABLISHED) && p->llgr_ready)
|
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "Hold timer expired");
|
|
|
|
bgp_handle_graceful_restart(p);
|
|
|
|
bgp_conn_enter_idle_state(conn);
|
|
|
|
}
|
2009-10-11 16:56:16 +00:00
|
|
|
else
|
|
|
|
bgp_error(conn, 4, 0, NULL, 0);
|
2000-03-30 10:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_keepalive_timeout(timer *t)
|
|
|
|
{
|
|
|
|
struct bgp_conn *conn = t->data;
|
|
|
|
|
|
|
|
DBG("BGP: Keepalive timer\n");
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_schedule_packet(conn, NULL, PKT_KEEPALIVE);
|
2016-04-06 09:57:28 +00:00
|
|
|
|
|
|
|
/* Kick TX a bit faster */
|
|
|
|
if (ev_active(conn->tx_ev))
|
|
|
|
ev_run(conn->tx_ev);
|
2000-03-30 10:44:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-20 21:50:17 +00:00
|
|
|
static void
|
2000-04-25 23:08:31 +00:00
|
|
|
bgp_setup_conn(struct bgp_proto *p, struct bgp_conn *conn)
|
2000-03-20 21:50:17 +00:00
|
|
|
{
|
2000-04-25 23:08:31 +00:00
|
|
|
conn->sk = NULL;
|
2000-03-20 21:50:17 +00:00
|
|
|
conn->bgp = p;
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2000-03-21 15:53:50 +00:00
|
|
|
conn->packets_to_send = 0;
|
2016-12-07 13:11:28 +00:00
|
|
|
conn->channels_to_send = 0;
|
|
|
|
conn->last_channel = 0;
|
|
|
|
conn->last_channel_count = 0;
|
|
|
|
|
2017-11-28 16:43:20 +00:00
|
|
|
conn->connect_timer = tm_new_init(p->p.pool, bgp_connect_timeout, conn, 0, 0);
|
|
|
|
conn->hold_timer = tm_new_init(p->p.pool, bgp_hold_timeout, conn, 0, 0);
|
|
|
|
conn->keepalive_timer = tm_new_init(p->p.pool, bgp_keepalive_timeout, conn, 0, 0);
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2018-10-01 13:55:23 +00:00
|
|
|
conn->tx_ev = ev_new_init(p->p.pool, bgp_kick_tx, conn);
|
2000-03-20 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2000-04-25 23:08:31 +00:00
|
|
|
static void
|
2010-02-21 13:34:53 +00:00
|
|
|
bgp_setup_sk(struct bgp_conn *conn, sock *s)
|
2000-04-25 23:08:31 +00:00
|
|
|
{
|
|
|
|
s->data = conn;
|
|
|
|
s->err_hook = bgp_sock_err;
|
2016-04-06 09:49:34 +00:00
|
|
|
s->fast_rx = 1;
|
2000-04-25 23:08:31 +00:00
|
|
|
conn->sk = s;
|
|
|
|
}
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
static void
|
2009-06-06 16:16:22 +00:00
|
|
|
bgp_active(struct bgp_proto *p)
|
2008-12-19 00:34:39 +00:00
|
|
|
{
|
2015-02-22 15:08:28 +00:00
|
|
|
int delay = MAX(1, p->cf->connect_delay_time);
|
2008-12-19 00:34:39 +00:00
|
|
|
struct bgp_conn *conn = &p->outgoing_conn;
|
|
|
|
|
|
|
|
BGP_TRACE(D_EVENTS, "Connect delayed by %d seconds", delay);
|
|
|
|
bgp_setup_conn(p, conn);
|
2010-01-03 11:17:52 +00:00
|
|
|
bgp_conn_set_state(conn, BS_ACTIVE);
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_start_timer(conn->connect_timer, delay);
|
2008-12-19 00:34:39 +00:00
|
|
|
}
|
|
|
|
|
2000-06-04 17:06:18 +00:00
|
|
|
/**
|
|
|
|
* bgp_connect - initiate an outgoing connection
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
|
|
|
* The bgp_connect() function creates a new &bgp_conn and initiates
|
|
|
|
* a TCP connection to the peer. The rest of connection setup is governed
|
|
|
|
* by the BGP state machine as described in the standard.
|
|
|
|
*/
|
2000-03-20 21:50:17 +00:00
|
|
|
static void
|
|
|
|
bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing connection */
|
|
|
|
{
|
2000-03-30 17:39:48 +00:00
|
|
|
struct bgp_conn *conn = &p->outgoing_conn;
|
2011-08-16 21:05:35 +00:00
|
|
|
int hops = p->cf->multihop ? : 1;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
|
|
|
DBG("BGP: Connecting\n");
|
2016-12-07 13:11:28 +00:00
|
|
|
sock *s = sk_new(p->p.pool);
|
2000-03-20 21:50:17 +00:00
|
|
|
s->type = SK_TCP_ACTIVE;
|
2019-04-02 15:22:31 +00:00
|
|
|
s->saddr = p->local_ip;
|
|
|
|
s->daddr = p->remote_ip;
|
2014-10-02 09:33:55 +00:00
|
|
|
s->dport = p->cf->remote_port;
|
2012-01-08 14:28:27 +00:00
|
|
|
s->iface = p->neigh ? p->neigh->iface : NULL;
|
2017-09-06 15:38:48 +00:00
|
|
|
s->vrf = p->p.vrf;
|
2011-08-16 21:05:35 +00:00
|
|
|
s->ttl = p->cf->ttl_security ? 255 : hops;
|
2015-07-18 11:38:21 +00:00
|
|
|
s->rbsize = p->cf->enable_extended_messages ? BGP_RX_BUFFER_EXT_SIZE : BGP_RX_BUFFER_SIZE;
|
|
|
|
s->tbsize = p->cf->enable_extended_messages ? BGP_TX_BUFFER_EXT_SIZE : BGP_TX_BUFFER_SIZE;
|
2008-11-01 15:58:40 +00:00
|
|
|
s->tos = IP_PREC_INTERNET_CONTROL;
|
|
|
|
s->password = p->cf->password;
|
|
|
|
s->tx_hook = bgp_connected;
|
2023-03-16 18:23:19 +00:00
|
|
|
s->flags = p->cf->free_bind ? SKF_FREEBIND : 0;
|
2019-01-02 15:01:21 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Connecting to %I%J from local address %I%J",
|
|
|
|
s->daddr, ipa_is_link_local(s->daddr) ? p->cf->iface : NULL,
|
2014-10-24 09:11:43 +00:00
|
|
|
s->saddr, ipa_is_link_local(s->saddr) ? s->iface : NULL);
|
2000-04-25 23:08:31 +00:00
|
|
|
bgp_setup_conn(p, conn);
|
2010-02-21 13:34:53 +00:00
|
|
|
bgp_setup_sk(conn, s);
|
2010-01-03 11:17:52 +00:00
|
|
|
bgp_conn_set_state(conn, BS_CONNECT);
|
2011-08-16 21:05:35 +00:00
|
|
|
|
|
|
|
if (sk_open(s) < 0)
|
2014-05-18 09:42:26 +00:00
|
|
|
goto err;
|
2011-08-16 21:05:35 +00:00
|
|
|
|
|
|
|
/* Set minimal receive TTL if needed */
|
|
|
|
if (p->cf->ttl_security)
|
|
|
|
if (sk_set_min_ttl(s, 256 - hops) < 0)
|
2014-05-18 09:42:26 +00:00
|
|
|
goto err;
|
2011-08-16 21:05:35 +00:00
|
|
|
|
2000-03-20 21:50:17 +00:00
|
|
|
DBG("BGP: Waiting for connect success\n");
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_start_timer(conn->connect_timer, p->cf->connect_retry_time);
|
2014-05-18 09:42:26 +00:00
|
|
|
return;
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
err:
|
2014-05-18 09:42:26 +00:00
|
|
|
sk_log_error(s, p->p.name);
|
|
|
|
bgp_sock_err(s, 0);
|
|
|
|
return;
|
2000-03-20 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
static inline int bgp_is_dynamic(struct bgp_proto *p)
|
|
|
|
{ return ipa_zero(p->remote_ip); }
|
|
|
|
|
2015-02-21 19:39:59 +00:00
|
|
|
/**
|
|
|
|
* bgp_find_proto - find existing proto for incoming connection
|
|
|
|
* @sk: TCP socket
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static struct bgp_proto *
|
|
|
|
bgp_find_proto(sock *sk)
|
|
|
|
{
|
2019-04-08 15:05:07 +00:00
|
|
|
struct bgp_proto *best = NULL;
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_proto *p;
|
2015-02-21 19:39:59 +00:00
|
|
|
|
2019-01-02 15:01:21 +00:00
|
|
|
/* sk->iface is valid only if src or dst address is link-local */
|
|
|
|
int link = ipa_is_link_local(sk->saddr) || ipa_is_link_local(sk->daddr);
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
WALK_LIST(p, proto_list)
|
|
|
|
if ((p->p.proto == &proto_bgp) &&
|
2019-04-08 15:05:07 +00:00
|
|
|
(ipa_equal(p->remote_ip, sk->daddr) || bgp_is_dynamic(p)) &&
|
|
|
|
(!p->cf->remote_range || ipa_in_netX(sk->daddr, p->cf->remote_range)) &&
|
|
|
|
(p->p.vrf == sk->vrf) &&
|
|
|
|
(p->cf->local_port == sk->sport) &&
|
2019-01-02 15:01:21 +00:00
|
|
|
(!link || (p->cf->iface == sk->iface)) &&
|
|
|
|
(ipa_zero(p->cf->local_ip) || ipa_equal(p->cf->local_ip, sk->saddr)))
|
2019-04-08 15:05:07 +00:00
|
|
|
{
|
|
|
|
best = p;
|
2015-02-21 19:39:59 +00:00
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
if (!bgp_is_dynamic(p))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
2015-02-21 19:39:59 +00:00
|
|
|
}
|
|
|
|
|
2000-06-04 17:06:18 +00:00
|
|
|
/**
|
|
|
|
* bgp_incoming_connection - handle an incoming connection
|
|
|
|
* @sk: TCP socket
|
|
|
|
* @dummy: unused
|
|
|
|
*
|
|
|
|
* This function serves as a socket hook for accepting of new BGP
|
|
|
|
* connections. It searches a BGP instance corresponding to the peer
|
|
|
|
* which has connected and if such an instance exists, it creates a
|
|
|
|
* &bgp_conn structure, attaches it to the instance and either sends
|
|
|
|
* an Open message or (if there already is an active connection) it
|
|
|
|
* closes the new connection by sending a Notification message.
|
|
|
|
*/
|
2000-04-10 11:21:40 +00:00
|
|
|
static int
|
2016-10-14 13:37:04 +00:00
|
|
|
bgp_incoming_connection(sock *sk, uint dummy UNUSED)
|
2000-03-20 21:50:17 +00:00
|
|
|
{
|
2015-02-21 19:39:59 +00:00
|
|
|
struct bgp_proto *p;
|
|
|
|
int acc, hops;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2000-04-10 11:21:40 +00:00
|
|
|
DBG("BGP: Incoming connection from %I port %d\n", sk->daddr, sk->dport);
|
2015-02-21 19:39:59 +00:00
|
|
|
p = bgp_find_proto(sk);
|
|
|
|
if (!p)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
log(L_WARN "BGP: Unexpected connect from unknown address %I%J (port %d)",
|
|
|
|
sk->daddr, ipa_is_link_local(sk->daddr) ? sk->iface : NULL, sk->dport);
|
|
|
|
rfree(sk);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-02-21 19:39:59 +00:00
|
|
|
|
2016-02-11 15:38:28 +00:00
|
|
|
/*
|
|
|
|
* BIRD should keep multiple incoming connections in OpenSent state (for
|
|
|
|
* details RFC 4271 8.2.1 par 3), but it keeps just one. Duplicate incoming
|
|
|
|
* connections are rejected istead. The exception is the case where an
|
|
|
|
* incoming connection triggers a graceful restart.
|
|
|
|
*/
|
|
|
|
|
2015-02-21 19:39:59 +00:00
|
|
|
acc = (p->p.proto_state == PS_START || p->p.proto_state == PS_UP) &&
|
|
|
|
(p->start_state >= BSS_CONNECT) && (!p->incoming_conn.sk);
|
2009-06-06 16:16:22 +00:00
|
|
|
|
2015-02-21 19:39:59 +00:00
|
|
|
if (p->conn && (p->conn->state == BS_ESTABLISHED) && p->gr_ready)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_GRACEFUL_RESTART);
|
|
|
|
bgp_handle_graceful_restart(p);
|
|
|
|
bgp_conn_enter_idle_state(p->conn);
|
|
|
|
acc = 1;
|
|
|
|
|
|
|
|
/* There might be separate incoming connection in OpenSent state */
|
|
|
|
if (p->incoming_conn.state > BS_ACTIVE)
|
|
|
|
bgp_close_conn(&p->incoming_conn);
|
|
|
|
}
|
2015-02-21 19:39:59 +00:00
|
|
|
|
|
|
|
BGP_TRACE(D_EVENTS, "Incoming connection from %I%J (port %d) %s",
|
|
|
|
sk->daddr, ipa_is_link_local(sk->daddr) ? sk->iface : NULL,
|
|
|
|
sk->dport, acc ? "accepted" : "rejected");
|
|
|
|
|
|
|
|
if (!acc)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
rfree(sk);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-02-21 19:39:59 +00:00
|
|
|
|
|
|
|
hops = p->cf->multihop ? : 1;
|
|
|
|
|
|
|
|
if (sk_set_ttl(sk, p->cf->ttl_security ? 255 : hops) < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (p->cf->ttl_security)
|
|
|
|
if (sk_set_min_ttl(sk, 256 - hops) < 0)
|
|
|
|
goto err;
|
|
|
|
|
2015-07-18 11:38:21 +00:00
|
|
|
if (p->cf->enable_extended_messages)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
sk->rbsize = BGP_RX_BUFFER_EXT_SIZE;
|
|
|
|
sk->tbsize = BGP_TX_BUFFER_EXT_SIZE;
|
|
|
|
sk_reallocate(sk);
|
|
|
|
}
|
2015-07-18 11:38:21 +00:00
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
/* For dynamic BGP, spawn new instance and postpone the socket */
|
|
|
|
if (bgp_is_dynamic(p))
|
|
|
|
{
|
|
|
|
p = bgp_spawn(p, sk->daddr);
|
|
|
|
p->postponed_sk = sk;
|
|
|
|
rmove(sk, p->p.pool);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rmove(sk, p->p.pool);
|
2015-02-21 19:39:59 +00:00
|
|
|
bgp_setup_conn(p, &p->incoming_conn);
|
|
|
|
bgp_setup_sk(&p->incoming_conn, sk);
|
|
|
|
bgp_send_open(&p->incoming_conn);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
sk_log_error(sk, p->p.name);
|
|
|
|
log(L_ERR "%s: Incoming connection aborted", p->p.name);
|
2000-04-10 11:21:40 +00:00
|
|
|
rfree(sk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-11 10:12:58 +00:00
|
|
|
static void
|
2010-02-21 13:34:53 +00:00
|
|
|
bgp_listen_sock_err(sock *sk UNUSED, int err)
|
2010-02-11 10:12:58 +00:00
|
|
|
{
|
|
|
|
if (err == ECONNABORTED)
|
|
|
|
log(L_WARN "BGP: Incoming connection aborted");
|
|
|
|
else
|
2010-05-31 09:35:29 +00:00
|
|
|
log(L_ERR "BGP: Error on listening socket: %M", err);
|
2010-02-11 10:12:58 +00:00
|
|
|
}
|
|
|
|
|
2000-05-07 10:41:45 +00:00
|
|
|
static void
|
|
|
|
bgp_start_neighbor(struct bgp_proto *p)
|
|
|
|
{
|
2010-07-12 15:39:39 +00:00
|
|
|
/* Called only for single-hop BGP sessions */
|
|
|
|
|
2019-04-02 15:22:31 +00:00
|
|
|
if (ipa_zero(p->local_ip))
|
|
|
|
p->local_ip = p->neigh->ifa->ip;
|
2009-04-28 16:11:56 +00:00
|
|
|
|
2019-04-02 15:22:31 +00:00
|
|
|
if (ipa_is_link_local(p->local_ip))
|
|
|
|
p->link_addr = p->local_ip;
|
2017-12-07 12:06:01 +00:00
|
|
|
else if (p->neigh->iface->llv6)
|
|
|
|
p->link_addr = p->neigh->iface->llv6->ip;
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2000-04-25 23:08:31 +00:00
|
|
|
bgp_initiate(p);
|
2000-04-10 11:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_neigh_notify(neighbor *n)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) n->proto;
|
2015-02-21 10:46:14 +00:00
|
|
|
int ps = p->p.proto_state;
|
|
|
|
|
|
|
|
if (n != p->neigh)
|
|
|
|
return;
|
2000-04-10 11:21:40 +00:00
|
|
|
|
2015-02-21 10:46:14 +00:00
|
|
|
if ((ps == PS_DOWN) || (ps == PS_STOP))
|
2013-08-13 18:42:43 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-21 10:46:14 +00:00
|
|
|
int prepare = (ps == PS_START) && (p->start_state == BSS_PREPARE);
|
|
|
|
|
|
|
|
if (n->scope <= 0)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
if (!prepare)
|
2000-04-10 11:21:40 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor lost");
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_NEIGHBOR_LOST);
|
|
|
|
/* Perhaps also run bgp_update_startup_delay(p)? */
|
2017-12-07 20:54:47 +00:00
|
|
|
bgp_stop(p, 0, NULL, 0);
|
2021-03-28 13:36:59 +00:00
|
|
|
bmp_peer_down(p, BE_MISC, NULL, 0);
|
2015-02-21 10:46:14 +00:00
|
|
|
}
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2015-02-21 10:46:14 +00:00
|
|
|
else if (p->cf->check_link && !(n->iface->flags & IF_LINK_UP))
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
if (!prepare)
|
2015-02-21 10:46:14 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Link down");
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_LINK_DOWN);
|
|
|
|
if (ps == PS_UP)
|
|
|
|
bgp_update_startup_delay(p);
|
2017-12-07 20:54:47 +00:00
|
|
|
bgp_stop(p, 0, NULL, 0);
|
2021-03-28 13:36:59 +00:00
|
|
|
bmp_peer_down(p, BE_MISC, NULL, 0);
|
2000-04-10 11:21:40 +00:00
|
|
|
}
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2000-04-10 11:21:40 +00:00
|
|
|
else
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
if (prepare)
|
2000-04-10 11:21:40 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor ready");
|
|
|
|
bgp_start_neighbor(p);
|
2000-04-10 11:21:40 +00:00
|
|
|
}
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2000-04-10 11:21:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
static void
|
|
|
|
bgp_bfd_notify(struct bfd_request *req)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = req->data;
|
|
|
|
int ps = p->p.proto_state;
|
|
|
|
|
|
|
|
if (req->down && ((ps == PS_START) || (ps == PS_UP)))
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "BFD session down");
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_BFD_DOWN);
|
2018-07-31 16:40:38 +00:00
|
|
|
|
2020-11-08 14:33:22 +00:00
|
|
|
if (req->opts.mode == BGP_BFD_GRACEFUL)
|
2018-07-31 16:40:38 +00:00
|
|
|
{
|
|
|
|
/* Trigger graceful restart */
|
|
|
|
if (p->conn && (p->conn->state == BS_ESTABLISHED) && p->gr_ready)
|
|
|
|
bgp_handle_graceful_restart(p);
|
|
|
|
|
|
|
|
if (p->incoming_conn.state > BS_IDLE)
|
|
|
|
bgp_conn_enter_idle_state(&p->incoming_conn);
|
|
|
|
|
|
|
|
if (p->outgoing_conn.state > BS_IDLE)
|
|
|
|
bgp_conn_enter_idle_state(&p->outgoing_conn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Trigger session down */
|
|
|
|
if (ps == PS_UP)
|
|
|
|
bgp_update_startup_delay(p);
|
|
|
|
bgp_stop(p, 0, NULL, 0);
|
2021-03-28 13:36:59 +00:00
|
|
|
bmp_peer_down(p, BE_MISC, NULL, 0);
|
2018-07-31 16:40:38 +00:00
|
|
|
}
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2013-11-19 21:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-11-08 14:33:22 +00:00
|
|
|
bgp_update_bfd(struct bgp_proto *p, const struct bfd_options *bfd)
|
2013-11-19 21:33:48 +00:00
|
|
|
{
|
2020-11-08 14:33:22 +00:00
|
|
|
if (bfd && p->bfd_req)
|
|
|
|
bfd_update_request(p->bfd_req, bfd);
|
|
|
|
|
|
|
|
if (bfd && !p->bfd_req && !bgp_is_dynamic(p))
|
2019-04-02 15:22:31 +00:00
|
|
|
p->bfd_req = bfd_request_session(p->p.pool, p->remote_ip, p->local_ip,
|
2013-11-19 21:33:48 +00:00
|
|
|
p->cf->multihop ? NULL : p->neigh->iface,
|
2020-11-08 14:33:22 +00:00
|
|
|
p->p.vrf, bgp_bfd_notify, p, bfd);
|
2013-11-19 21:33:48 +00:00
|
|
|
|
2020-11-08 14:33:22 +00:00
|
|
|
if (!bfd && p->bfd_req)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
rfree(p->bfd_req);
|
|
|
|
p->bfd_req = NULL;
|
|
|
|
}
|
2013-11-19 21:33:48 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
static void
|
|
|
|
bgp_reload_routes(struct channel *C)
|
2009-11-26 19:47:59 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_proto *p = (void *) C->proto;
|
|
|
|
struct bgp_channel *c = (void *) C;
|
2009-11-26 19:47:59 +00:00
|
|
|
|
2022-09-08 17:41:02 +00:00
|
|
|
/* Ignore non-BGP channels */
|
|
|
|
if (C->channel != &channel_bgp)
|
|
|
|
return;
|
|
|
|
|
2018-09-27 20:57:55 +00:00
|
|
|
ASSERT(p->conn && (p->route_refresh || c->c.in_table));
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2018-09-27 20:57:55 +00:00
|
|
|
if (c->c.in_table)
|
|
|
|
channel_schedule_reload(C);
|
|
|
|
else
|
|
|
|
bgp_schedule_packet(p->conn, c, PKT_ROUTE_REFRESH);
|
2009-11-26 19:47:59 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 13:07:12 +00:00
|
|
|
static void
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_feed_begin(struct channel *C, int initial)
|
2014-03-20 13:07:12 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_proto *p = (void *) C->proto;
|
|
|
|
struct bgp_channel *c = (void *) C;
|
2015-03-29 16:27:13 +00:00
|
|
|
|
2022-09-08 17:41:02 +00:00
|
|
|
/* Ignore non-BGP channels */
|
|
|
|
if (C->channel != &channel_bgp)
|
|
|
|
return;
|
|
|
|
|
2015-03-29 16:27:13 +00:00
|
|
|
/* This should not happen */
|
|
|
|
if (!p->conn)
|
2014-03-20 13:07:12 +00:00
|
|
|
return;
|
|
|
|
|
2015-03-29 16:27:13 +00:00
|
|
|
if (initial && p->cf->gr_mode)
|
2016-12-07 13:11:28 +00:00
|
|
|
c->feed_state = BFS_LOADING;
|
2015-03-29 16:27:13 +00:00
|
|
|
|
|
|
|
/* It is refeed and both sides support enhanced route refresh */
|
2016-12-07 13:11:28 +00:00
|
|
|
if (!initial && p->enhanced_refresh)
|
|
|
|
{
|
|
|
|
/* BoRR must not be sent before End-of-RIB */
|
|
|
|
if (c->feed_state == BFS_LOADING || c->feed_state == BFS_LOADED)
|
|
|
|
return;
|
2015-03-29 16:27:13 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
c->feed_state = BFS_REFRESHING;
|
|
|
|
bgp_schedule_packet(p->conn, c, PKT_BEGIN_REFRESH);
|
|
|
|
}
|
2015-03-29 16:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_feed_end(struct channel *C)
|
2015-03-29 16:27:13 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_proto *p = (void *) C->proto;
|
|
|
|
struct bgp_channel *c = (void *) C;
|
2015-03-29 16:27:13 +00:00
|
|
|
|
2022-09-08 17:41:02 +00:00
|
|
|
/* Ignore non-BGP channels */
|
|
|
|
if (C->channel != &channel_bgp)
|
|
|
|
return;
|
|
|
|
|
2015-03-29 16:27:13 +00:00
|
|
|
/* This should not happen */
|
|
|
|
if (!p->conn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Non-demarcated feed ended, nothing to do */
|
2016-12-07 13:11:28 +00:00
|
|
|
if (c->feed_state == BFS_NONE)
|
2015-03-29 16:27:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Schedule End-of-RIB packet */
|
2016-12-07 13:11:28 +00:00
|
|
|
if (c->feed_state == BFS_LOADING)
|
|
|
|
c->feed_state = BFS_LOADED;
|
2015-03-29 16:27:13 +00:00
|
|
|
|
|
|
|
/* Schedule EoRR packet */
|
2016-12-07 13:11:28 +00:00
|
|
|
if (c->feed_state == BFS_REFRESHING)
|
|
|
|
c->feed_state = BFS_REFRESHED;
|
2015-03-29 16:27:13 +00:00
|
|
|
|
|
|
|
/* Kick TX hook */
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_schedule_packet(p->conn, c, PKT_UPDATE);
|
2014-03-20 13:07:12 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 16:27:13 +00:00
|
|
|
|
2000-04-10 11:21:40 +00:00
|
|
|
static void
|
|
|
|
bgp_start_locked(struct object_lock *lock)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = lock->data;
|
2019-04-02 15:22:31 +00:00
|
|
|
const struct bgp_config *cf = p->cf;
|
2000-04-10 11:21:40 +00:00
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
if (p->p.proto_state != PS_START)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
DBG("BGP: Got lock in different state %d\n", p->p.proto_state);
|
|
|
|
return;
|
|
|
|
}
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2000-04-10 11:21:40 +00:00
|
|
|
DBG("BGP: Got lock\n");
|
2008-10-26 21:45:09 +00:00
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
if (cf->multihop || bgp_is_dynamic(p))
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
/* Multi-hop sessions do not use neighbor entries */
|
|
|
|
bgp_initiate(p);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-26 21:45:09 +00:00
|
|
|
|
2019-04-02 15:22:31 +00:00
|
|
|
neighbor *n = neigh_find(&p->p, p->remote_ip, cf->iface, NEF_STICKY);
|
2015-02-21 10:46:14 +00:00
|
|
|
if (!n)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
2019-04-02 15:22:31 +00:00
|
|
|
log(L_ERR "%s: Invalid remote address %I%J", p->p.name, p->remote_ip, cf->iface);
|
2016-12-07 13:11:28 +00:00
|
|
|
/* As we do not start yet, we can just disable protocol */
|
|
|
|
p->p.disabled = 1;
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_INVALID_NEXT_HOP);
|
|
|
|
proto_notify_state(&p->p, PS_DOWN);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-21 10:46:14 +00:00
|
|
|
|
|
|
|
p->neigh = n;
|
|
|
|
|
|
|
|
if (n->scope <= 0)
|
2019-04-02 15:22:31 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Waiting for %I%J to become my neighbor", p->remote_ip, cf->iface);
|
2015-02-21 10:46:14 +00:00
|
|
|
else if (p->cf->check_link && !(n->iface->flags & IF_LINK_UP))
|
|
|
|
BGP_TRACE(D_EVENTS, "Waiting for link on %s", n->iface->name);
|
|
|
|
else
|
|
|
|
bgp_start_neighbor(p);
|
2000-03-20 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 22:09:07 +00:00
|
|
|
static int
|
|
|
|
bgp_start(struct proto *P)
|
|
|
|
{
|
2000-03-20 21:50:17 +00:00
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
2019-04-02 15:22:31 +00:00
|
|
|
const struct bgp_config *cf = p->cf;
|
|
|
|
|
|
|
|
p->local_ip = cf->local_ip;
|
|
|
|
p->local_as = cf->local_as;
|
|
|
|
p->remote_as = cf->remote_as;
|
|
|
|
p->public_as = cf->local_as;
|
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
/* For dynamic BGP childs, remote_ip is already set */
|
|
|
|
if (ipa_nonzero(cf->remote_ip))
|
|
|
|
p->remote_ip = cf->remote_ip;
|
|
|
|
|
2019-04-02 15:22:31 +00:00
|
|
|
/* Confederation ID is used for truly external peers */
|
|
|
|
if (p->cf->confederation && !p->is_interior)
|
|
|
|
p->public_as = cf->confederation;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
p->passive = cf->passive || bgp_is_dynamic(p);
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
p->start_state = BSS_PREPARE;
|
2000-03-30 17:39:48 +00:00
|
|
|
p->outgoing_conn.state = BS_IDLE;
|
|
|
|
p->incoming_conn.state = BS_IDLE;
|
2000-06-20 07:49:08 +00:00
|
|
|
p->neigh = NULL;
|
2013-11-19 21:33:48 +00:00
|
|
|
p->bfd_req = NULL;
|
2019-04-08 15:05:07 +00:00
|
|
|
p->postponed_sk = NULL;
|
2014-03-20 13:07:12 +00:00
|
|
|
p->gr_ready = 0;
|
2016-12-07 13:11:28 +00:00
|
|
|
p->gr_active_num = 0;
|
2010-07-05 15:50:19 +00:00
|
|
|
|
2019-12-03 17:05:41 +00:00
|
|
|
/* Reset some stats */
|
|
|
|
p->stats.rx_messages = p->stats.tx_messages = 0;
|
|
|
|
p->stats.rx_updates = p->stats.tx_updates = 0;
|
|
|
|
p->stats.rx_bytes = p->stats.tx_bytes = 0;
|
|
|
|
p->last_rx_update = 0;
|
|
|
|
|
2018-10-01 13:55:23 +00:00
|
|
|
p->event = ev_new_init(p->p.pool, bgp_decision, p);
|
2017-11-28 16:43:20 +00:00
|
|
|
p->startup_timer = tm_new_init(p->p.pool, bgp_startup_timeout, p, 0, 0);
|
|
|
|
p->gr_timer = tm_new_init(p->p.pool, bgp_graceful_restart_timeout, p, 0, 0);
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2011-04-01 11:54:39 +00:00
|
|
|
p->local_id = proto_get_router_id(P->cf);
|
|
|
|
if (p->rr_client)
|
|
|
|
p->rr_cluster_id = p->cf->rr_cluster_id ? p->cf->rr_cluster_id : p->local_id;
|
|
|
|
|
2010-07-12 15:39:39 +00:00
|
|
|
p->remote_id = 0;
|
2017-03-26 17:20:15 +00:00
|
|
|
p->link_addr = IPA_NONE;
|
2010-07-12 15:39:39 +00:00
|
|
|
|
2017-12-09 23:55:34 +00:00
|
|
|
/* Lock all channels when in GR recovery mode */
|
2014-03-23 00:35:33 +00:00
|
|
|
if (p->p.gr_recovery && p->cf->gr_mode)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
struct bgp_channel *c;
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_WALK_CHANNELS(p, c)
|
2016-12-07 13:11:28 +00:00
|
|
|
channel_graceful_restart_lock(&c->c);
|
|
|
|
}
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2000-03-20 21:50:17 +00:00
|
|
|
/*
|
2016-12-07 13:11:28 +00:00
|
|
|
* Before attempting to create the connection, we need to lock the port,
|
|
|
|
* so that we are the only instance attempting to talk with that neighbor.
|
2000-03-20 21:50:17 +00:00
|
|
|
*/
|
2019-04-02 15:22:31 +00:00
|
|
|
struct object_lock *lock;
|
2000-03-20 21:50:17 +00:00
|
|
|
lock = p->lock = olock_new(P->pool);
|
2019-04-02 15:22:31 +00:00
|
|
|
lock->addr = p->remote_ip;
|
2014-10-02 09:33:55 +00:00
|
|
|
lock->port = p->cf->remote_port;
|
2012-01-08 14:28:27 +00:00
|
|
|
lock->iface = p->cf->iface;
|
2017-09-12 13:49:36 +00:00
|
|
|
lock->vrf = p->cf->iface ? NULL : p->p.vrf;
|
2000-03-20 21:50:17 +00:00
|
|
|
lock->type = OBJLOCK_TCP;
|
|
|
|
lock->hook = bgp_start_locked;
|
|
|
|
lock->data = p;
|
2019-09-17 12:45:14 +00:00
|
|
|
|
|
|
|
/* For dynamic BGP, we use inst 1 to avoid collisions with regular BGP */
|
|
|
|
if (bgp_is_dynamic(p))
|
|
|
|
{
|
|
|
|
lock->addr = net_prefix(p->cf->remote_range);
|
|
|
|
lock->inst = 1;
|
|
|
|
}
|
|
|
|
|
2000-03-20 21:50:17 +00:00
|
|
|
olock_acquire(lock);
|
2008-10-26 21:42:39 +00:00
|
|
|
|
2000-03-20 21:50:17 +00:00
|
|
|
return PS_START;
|
2000-03-19 22:09:07 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 21:39:57 +00:00
|
|
|
extern int proto_restart;
|
|
|
|
|
2000-03-19 22:09:07 +00:00
|
|
|
static int
|
|
|
|
bgp_shutdown(struct proto *P)
|
|
|
|
{
|
2000-03-20 21:50:17 +00:00
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
2019-06-18 14:27:21 +00:00
|
|
|
int subcode = 0;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2017-09-19 17:55:37 +00:00
|
|
|
char *message = NULL;
|
|
|
|
byte *data = NULL;
|
|
|
|
uint len = 0;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2000-05-02 16:07:41 +00:00
|
|
|
BGP_TRACE(D_EVENTS, "Shutdown requested");
|
2009-06-06 22:38:38 +00:00
|
|
|
|
2012-04-15 13:28:29 +00:00
|
|
|
switch (P->down_code)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
case PDC_CF_REMOVE:
|
|
|
|
case PDC_CF_DISABLE:
|
|
|
|
subcode = 3; // Errcode 6, 3 - peer de-configured
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PDC_CF_RESTART:
|
|
|
|
subcode = 6; // Errcode 6, 6 - other configuration change
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PDC_CMD_DISABLE:
|
|
|
|
case PDC_CMD_SHUTDOWN:
|
2019-06-18 14:27:21 +00:00
|
|
|
shutdown:
|
2016-12-07 13:11:28 +00:00
|
|
|
subcode = 2; // Errcode 6, 2 - administrative shutdown
|
2017-12-07 20:54:47 +00:00
|
|
|
message = P->message;
|
2016-12-07 13:11:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PDC_CMD_RESTART:
|
|
|
|
subcode = 4; // Errcode 6, 4 - administrative reset
|
2017-12-07 20:54:47 +00:00
|
|
|
message = P->message;
|
2016-12-07 13:11:28 +00:00
|
|
|
break;
|
|
|
|
|
2019-06-18 14:27:21 +00:00
|
|
|
case PDC_CMD_GR_DOWN:
|
|
|
|
if ((p->cf->gr_mode != BGP_GR_ABLE) &&
|
|
|
|
(p->cf->llgr_mode != BGP_LLGR_ABLE))
|
|
|
|
goto shutdown;
|
|
|
|
|
|
|
|
subcode = -1; // Do not send NOTIFICATION, just close the connection
|
|
|
|
break;
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
case PDC_RX_LIMIT_HIT:
|
|
|
|
case PDC_IN_LIMIT_HIT:
|
|
|
|
subcode = 1; // Errcode 6, 1 - max number of prefixes reached
|
|
|
|
/* log message for compatibility */
|
|
|
|
log(L_WARN "%s: Route limit exceeded, shutting down", p->p.name);
|
|
|
|
goto limit;
|
|
|
|
|
|
|
|
case PDC_OUT_LIMIT_HIT:
|
|
|
|
subcode = proto_restart ? 4 : 2; // Administrative reset or shutdown
|
|
|
|
|
|
|
|
limit:
|
|
|
|
bgp_store_error(p, NULL, BE_AUTO_DOWN, BEA_ROUTE_LIMIT_EXCEEDED);
|
|
|
|
if (proto_restart)
|
|
|
|
bgp_update_startup_delay(p);
|
|
|
|
else
|
|
|
|
p->startup_delay = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
2009-06-06 22:38:38 +00:00
|
|
|
|
2012-04-15 13:28:29 +00:00
|
|
|
bgp_store_error(p, NULL, BE_MAN_DOWN, 0);
|
2008-12-19 00:34:39 +00:00
|
|
|
p->startup_delay = 0;
|
2000-03-20 21:50:17 +00:00
|
|
|
|
2017-09-19 17:55:37 +00:00
|
|
|
/* RFC 8203 - shutdown communication */
|
|
|
|
if (message)
|
|
|
|
{
|
|
|
|
uint msg_len = strlen(message);
|
2019-04-30 11:55:43 +00:00
|
|
|
msg_len = MIN(msg_len, 255);
|
2017-09-19 17:55:37 +00:00
|
|
|
|
|
|
|
/* Buffer will be freed automatically by protocol shutdown */
|
|
|
|
data = mb_alloc(p->p.pool, msg_len + 1);
|
|
|
|
len = msg_len + 1;
|
|
|
|
|
|
|
|
data[0] = msg_len;
|
|
|
|
memcpy(data+1, message, msg_len);
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
done:
|
2017-09-19 17:55:37 +00:00
|
|
|
bgp_stop(p, subcode, data, len);
|
2008-12-19 00:34:39 +00:00
|
|
|
return p->p.proto_state;
|
2000-03-19 22:09:07 +00:00
|
|
|
}
|
|
|
|
|
2000-04-10 11:21:40 +00:00
|
|
|
static struct proto *
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_init(struct proto_config *CF)
|
2000-04-10 11:21:40 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct proto *P = proto_new(CF);
|
2000-04-10 11:21:40 +00:00
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_config *cf = (struct bgp_config *) CF;
|
2000-04-10 11:21:40 +00:00
|
|
|
|
|
|
|
P->rt_notify = bgp_rt_notify;
|
2021-03-29 20:45:21 +00:00
|
|
|
P->rte_update_in_notify = bgp_rte_update_in_notify;
|
Terminology cleanup: The import_control hook is now called preexport.
Once upon a time, far far away, there were the old Bird developers
discussing what direction of route flow shall be called import and
export. They decided to say "import to protocol" and "export to table"
when speaking about a protocol. When speaking about a table, they
spoke about "importing to table" and "exporting to protocol".
The latter terminology was adopted in configuration, then also the
bird CLI in commit ea2ae6dd0 started to use it (in year 2009). Now
it's 2018 and the terminology is the latter. Import is from protocol to
table, export is from table to protocol. Anyway, there was still an
import_control hook which executed right before route export.
One thing is funny. There are two commits in April 1999 with just two
minutes between them. The older announces the final settlement
on config terminology, the newer uses the other definition. Let's see
their commit messages as the git-log tool shows them (the newer first):
commit 9e0e485e50ea74c4f1c5cb65bdfe6ce819c2cee2
Author: Martin Mares <mj@ucw.cz>
Date: Mon Apr 5 20:17:59 1999 +0000
Added some new protocol hooks (look at the comments for better explanation):
make_tmp_attrs Convert inline attributes to ea_list
store_tmp_attrs Convert ea_list to inline attributes
import_control Pre-import decisions
commit 5056c559c4eb253a4eee10cf35b694faec5265eb
Author: Martin Mares <mj@ucw.cz>
Date: Mon Apr 5 20:15:31 1999 +0000
Changed syntax of attaching filters to protocols to hopefully the final
version:
EXPORT <filter-spec> for outbound routes (i.e., those announced
by BIRD to the rest of the world).
IMPORT <filter-spec> for inbound routes (i.e., those imported
by BIRD from the rest of the world).
where <filter-spec> is one of:
ALL pass all routes
NONE drop all routes
FILTER <name> use named filter
FILTER { <filter> } use explicitly defined filter
For all protocols, the default is IMPORT ALL, EXPORT NONE. This includes
the kernel protocol, so that you need to add EXPORT ALL to get the previous
configuration of kernel syncer (as usually, see doc/bird.conf.example for
a bird.conf example :)).
Let's say RIP to this almost 19-years-old inconsistency. For now, if you
import a route, it is always from protocol to table. If you export a
route, it is always from table to protocol.
And they lived happily ever after.
2018-02-14 12:42:53 +00:00
|
|
|
P->preexport = bgp_preexport;
|
2000-04-10 11:21:40 +00:00
|
|
|
P->neigh_notify = bgp_neigh_notify;
|
2009-11-26 19:47:59 +00:00
|
|
|
P->reload_routes = bgp_reload_routes;
|
2015-03-29 16:27:13 +00:00
|
|
|
P->feed_begin = bgp_feed_begin;
|
|
|
|
P->feed_end = bgp_feed_end;
|
2012-08-14 14:25:22 +00:00
|
|
|
P->rte_better = bgp_rte_better;
|
2015-06-08 00:20:43 +00:00
|
|
|
P->rte_mergable = bgp_rte_mergable;
|
2016-12-07 13:11:28 +00:00
|
|
|
P->rte_recalculate = cf->deterministic_med ? bgp_rte_recalculate : NULL;
|
2018-07-31 16:40:38 +00:00
|
|
|
P->rte_modify = bgp_rte_modify_stale;
|
2021-03-20 22:18:34 +00:00
|
|
|
P->rte_igp_metric = bgp_rte_igp_metric;
|
2016-12-07 13:11:28 +00:00
|
|
|
|
|
|
|
p->cf = cf;
|
|
|
|
p->is_internal = (cf->local_as == cf->remote_as);
|
|
|
|
p->is_interior = p->is_internal || cf->confederation_member;
|
|
|
|
p->rs_client = cf->rs_client;
|
|
|
|
p->rr_client = cf->rr_client;
|
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
p->ipv4 = ipa_nonzero(cf->remote_ip) ?
|
|
|
|
ipa_is_ip4(cf->remote_ip) :
|
|
|
|
(cf->remote_range && (cf->remote_range->type == NET_IP4));
|
|
|
|
|
|
|
|
p->remote_ip = cf->remote_ip;
|
|
|
|
p->remote_as = cf->remote_as;
|
|
|
|
|
|
|
|
/* Hack: We use cf->remote_ip just to pass remote_ip from bgp_spawn() */
|
|
|
|
if (cf->c.parent)
|
|
|
|
cf->remote_ip = IPA_NONE;
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Add all channels */
|
|
|
|
struct bgp_channel_config *cc;
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_CF_WALK_CHANNELS(cf, cc)
|
2016-12-07 13:11:28 +00:00
|
|
|
proto_add_channel(P, &cc->c);
|
2010-07-12 15:39:39 +00:00
|
|
|
|
2000-04-10 11:21:40 +00:00
|
|
|
return P;
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
static void
|
|
|
|
bgp_channel_init(struct channel *C, struct channel_config *CF)
|
|
|
|
{
|
|
|
|
struct bgp_channel *c = (void *) C;
|
|
|
|
struct bgp_channel_config *cf = (void *) CF;
|
|
|
|
|
|
|
|
c->cf = cf;
|
|
|
|
c->afi = cf->afi;
|
2017-03-26 17:20:15 +00:00
|
|
|
c->desc = cf->desc;
|
|
|
|
|
|
|
|
if (cf->igp_table_ip4)
|
|
|
|
c->igp_table_ip4 = cf->igp_table_ip4->table;
|
|
|
|
|
|
|
|
if (cf->igp_table_ip6)
|
|
|
|
c->igp_table_ip6 = cf->igp_table_ip6->table;
|
2021-12-20 19:25:35 +00:00
|
|
|
|
|
|
|
if (cf->base_table)
|
|
|
|
c->base_table = cf->base_table->table;
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bgp_channel_start(struct channel *C)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (void *) C->proto;
|
|
|
|
struct bgp_channel *c = (void *) C;
|
2019-04-02 15:22:31 +00:00
|
|
|
ip_addr src = p->local_ip;
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2017-03-26 17:20:15 +00:00
|
|
|
if (c->igp_table_ip4)
|
|
|
|
rt_lock_table(c->igp_table_ip4);
|
|
|
|
|
|
|
|
if (c->igp_table_ip6)
|
|
|
|
rt_lock_table(c->igp_table_ip6);
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2021-12-20 19:25:35 +00:00
|
|
|
if (c->base_table)
|
|
|
|
{
|
|
|
|
rt_lock_table(c->base_table);
|
|
|
|
rt_flowspec_link(c->base_table, c->c.table);
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
c->pool = p->p.pool; // XXXX
|
|
|
|
bgp_init_bucket_table(c);
|
|
|
|
bgp_init_prefix_table(c);
|
|
|
|
|
2018-09-27 20:57:55 +00:00
|
|
|
if (c->cf->import_table)
|
|
|
|
channel_setup_in_table(C);
|
|
|
|
|
2019-08-13 16:22:07 +00:00
|
|
|
if (c->cf->export_table)
|
|
|
|
channel_setup_out_table(C);
|
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
c->stale_timer = tm_new_init(c->pool, bgp_long_lived_stale_timeout, c, 0, 0);
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
c->next_hop_addr = c->cf->next_hop_addr;
|
|
|
|
c->link_addr = IPA_NONE;
|
|
|
|
c->packets_to_send = 0;
|
|
|
|
|
|
|
|
/* Try to use source address as next hop address */
|
|
|
|
if (ipa_zero(c->next_hop_addr))
|
|
|
|
{
|
2017-03-26 17:20:15 +00:00
|
|
|
if (bgp_channel_is_ipv4(c) && (ipa_is_ip4(src) || c->ext_next_hop))
|
2016-12-07 13:11:28 +00:00
|
|
|
c->next_hop_addr = src;
|
|
|
|
|
2017-03-26 17:20:15 +00:00
|
|
|
if (bgp_channel_is_ipv6(c) && (ipa_is_ip6(src) || c->ext_next_hop))
|
2016-12-07 13:11:28 +00:00
|
|
|
c->next_hop_addr = src;
|
|
|
|
}
|
|
|
|
|
2017-12-08 01:26:17 +00:00
|
|
|
/* Use preferred addresses associated with interface / source address */
|
|
|
|
if (ipa_zero(c->next_hop_addr))
|
|
|
|
{
|
|
|
|
/* We know the iface for single-hop, we make lookup for multihop */
|
2018-06-27 14:51:53 +00:00
|
|
|
struct neighbor *nbr = p->neigh ?: neigh_find(&p->p, src, NULL, 0);
|
2017-12-08 01:26:17 +00:00
|
|
|
struct iface *iface = nbr ? nbr->iface : NULL;
|
|
|
|
|
|
|
|
if (bgp_channel_is_ipv4(c) && iface && iface->addr4)
|
|
|
|
c->next_hop_addr = iface->addr4->ip;
|
|
|
|
|
|
|
|
if (bgp_channel_is_ipv6(c) && iface && iface->addr6)
|
|
|
|
c->next_hop_addr = iface->addr6->ip;
|
|
|
|
}
|
|
|
|
|
2017-03-26 17:20:15 +00:00
|
|
|
/* Exit if no feasible next hop address is found */
|
|
|
|
if (ipa_zero(c->next_hop_addr))
|
|
|
|
{
|
|
|
|
log(L_WARN "%s: Missing next hop address", p->p.name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Set link-local address for IPv6 single-hop BGP */
|
2017-03-26 17:20:15 +00:00
|
|
|
if (ipa_is_ip6(c->next_hop_addr) && p->neigh)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
c->link_addr = p->link_addr;
|
|
|
|
|
|
|
|
if (ipa_zero(c->link_addr))
|
|
|
|
log(L_WARN "%s: Missing link-local address", p->p.name);
|
|
|
|
}
|
|
|
|
|
2017-03-26 17:20:15 +00:00
|
|
|
/* Link local address is already in c->link_addr */
|
|
|
|
if (ipa_is_link_local(c->next_hop_addr))
|
|
|
|
c->next_hop_addr = IPA_NONE;
|
2016-12-07 13:11:28 +00:00
|
|
|
|
|
|
|
return 0; /* XXXX: Currently undefined */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_channel_shutdown(struct channel *C)
|
|
|
|
{
|
|
|
|
struct bgp_channel *c = (void *) C;
|
|
|
|
|
|
|
|
c->next_hop_addr = IPA_NONE;
|
|
|
|
c->link_addr = IPA_NONE;
|
2017-12-09 23:55:34 +00:00
|
|
|
c->packets_to_send = 0;
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_channel_cleanup(struct channel *C)
|
|
|
|
{
|
|
|
|
struct bgp_channel *c = (void *) C;
|
|
|
|
|
2017-03-26 17:20:15 +00:00
|
|
|
if (c->igp_table_ip4)
|
|
|
|
rt_unlock_table(c->igp_table_ip4);
|
|
|
|
|
|
|
|
if (c->igp_table_ip6)
|
|
|
|
rt_unlock_table(c->igp_table_ip6);
|
2019-01-26 18:48:16 +00:00
|
|
|
|
2021-12-20 19:25:35 +00:00
|
|
|
if (c->base_table)
|
|
|
|
{
|
|
|
|
rt_flowspec_unlink(c->base_table, c->c.table);
|
|
|
|
rt_unlock_table(c->base_table);
|
|
|
|
}
|
|
|
|
|
2019-01-26 18:48:16 +00:00
|
|
|
c->index = 0;
|
|
|
|
|
|
|
|
/* Cleanup rest of bgp_channel starting at pool field */
|
|
|
|
memset(&(c->pool), 0, sizeof(struct bgp_channel) - OFFSETOF(struct bgp_channel, pool));
|
2017-03-26 17:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct bgp_channel_config *
|
|
|
|
bgp_find_channel_config(struct bgp_config *cf, u32 afi)
|
|
|
|
{
|
|
|
|
struct bgp_channel_config *cc;
|
|
|
|
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_CF_WALK_CHANNELS(cf, cc)
|
2017-03-26 17:20:15 +00:00
|
|
|
if (cc->afi == afi)
|
|
|
|
return cc;
|
|
|
|
|
|
|
|
return NULL;
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2011-11-06 23:31:23 +00:00
|
|
|
|
2017-03-26 17:20:15 +00:00
|
|
|
struct rtable_config *
|
|
|
|
bgp_default_igp_table(struct bgp_config *cf, struct bgp_channel_config *cc, u32 type)
|
|
|
|
{
|
|
|
|
struct bgp_channel_config *cc2;
|
|
|
|
struct rtable_config *tab;
|
|
|
|
|
|
|
|
/* First, try table connected by the channel */
|
|
|
|
if (cc->c.table->addr_type == type)
|
|
|
|
return cc->c.table;
|
|
|
|
|
|
|
|
/* Find paired channel with the same SAFI but the other AFI */
|
|
|
|
u32 afi2 = cc->afi ^ 0x30000;
|
|
|
|
cc2 = bgp_find_channel_config(cf, afi2);
|
|
|
|
|
|
|
|
/* Second, try IGP table configured in the paired channel */
|
|
|
|
if (cc2 && (tab = (type == NET_IP4) ? cc2->igp_table_ip4 : cc2->igp_table_ip6))
|
|
|
|
return tab;
|
|
|
|
|
|
|
|
/* Third, try table connected by the paired channel */
|
|
|
|
if (cc2 && (cc2->c.table->addr_type == type))
|
|
|
|
return cc2->c.table;
|
|
|
|
|
|
|
|
/* Last, try default table of given type */
|
|
|
|
if (tab = cf->c.global->def_tables[type])
|
|
|
|
return tab;
|
|
|
|
|
|
|
|
cf_error("Undefined IGP table");
|
|
|
|
}
|
|
|
|
|
2021-12-20 19:25:35 +00:00
|
|
|
static struct rtable_config *
|
|
|
|
bgp_default_base_table(struct bgp_config *cf, struct bgp_channel_config *cc)
|
|
|
|
{
|
|
|
|
/* Expected table type */
|
|
|
|
u32 type = (cc->afi == BGP_AF_FLOW4) ? NET_IP4 : NET_IP6;
|
|
|
|
|
|
|
|
/* First, try appropriate IP channel */
|
|
|
|
u32 afi2 = BGP_AF(BGP_AFI(cc->afi), BGP_SAFI_UNICAST);
|
|
|
|
struct bgp_channel_config *cc2 = bgp_find_channel_config(cf, afi2);
|
|
|
|
if (cc2 && (cc2->c.table->addr_type == type))
|
|
|
|
return cc2->c.table;
|
|
|
|
|
|
|
|
/* Last, try default table of given type */
|
|
|
|
struct rtable_config *tab = cf->c.global->def_tables[type];
|
|
|
|
if (tab)
|
|
|
|
return tab;
|
|
|
|
|
|
|
|
cf_error("Undefined base table");
|
|
|
|
}
|
2017-03-26 17:20:15 +00:00
|
|
|
|
2011-11-06 23:31:23 +00:00
|
|
|
void
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_postconfig(struct proto_config *CF)
|
2011-11-06 23:31:23 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_config *cf = (void *) CF;
|
2011-11-06 23:31:23 +00:00
|
|
|
|
|
|
|
/* Do not check templates at all */
|
2016-12-07 13:11:28 +00:00
|
|
|
if (cf->c.class == SYM_TEMPLATE)
|
2011-11-06 23:31:23 +00:00
|
|
|
return;
|
|
|
|
|
2013-11-24 11:37:24 +00:00
|
|
|
|
2019-04-03 13:54:50 +00:00
|
|
|
/* Handle undefined remote_as, zero should mean unspecified external */
|
|
|
|
if (!cf->remote_as && (cf->peer_type == BGP_PT_INTERNAL))
|
|
|
|
cf->remote_as = cf->local_as;
|
|
|
|
|
|
|
|
int internal = (cf->local_as == cf->remote_as);
|
|
|
|
int interior = internal || cf->confederation_member;
|
|
|
|
|
2013-11-24 11:37:24 +00:00
|
|
|
/* EBGP direct by default, IBGP multihop by default */
|
2016-12-07 13:11:28 +00:00
|
|
|
if (cf->multihop < 0)
|
|
|
|
cf->multihop = internal ? 64 : 0;
|
2013-11-24 11:37:24 +00:00
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
/* LLGR mode default based on GR mode */
|
|
|
|
if (cf->llgr_mode < 0)
|
|
|
|
cf->llgr_mode = cf->gr_mode ? BGP_LLGR_AWARE : 0;
|
|
|
|
|
2017-12-08 16:00:47 +00:00
|
|
|
/* Link check for single-hop BGP by default */
|
|
|
|
if (cf->check_link < 0)
|
|
|
|
cf->check_link = !cf->multihop;
|
|
|
|
|
2013-11-24 11:37:24 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (!cf->local_as)
|
2011-11-06 23:31:23 +00:00
|
|
|
cf_error("Local AS number must be set");
|
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
if (ipa_zero(cf->remote_ip) && !cf->remote_range)
|
2011-11-06 23:31:23 +00:00
|
|
|
cf_error("Neighbor must be configured");
|
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
if (ipa_zero(cf->local_ip) && cf->strict_bind)
|
|
|
|
cf_error("Local address must be configured for strict bind");
|
|
|
|
|
2019-04-03 13:54:50 +00:00
|
|
|
if (!cf->remote_as && !cf->peer_type)
|
|
|
|
cf_error("Remote AS number (or peer type) must be set");
|
|
|
|
|
|
|
|
if ((cf->peer_type == BGP_PT_INTERNAL) && !internal)
|
|
|
|
cf_error("IBGP cannot have different ASNs");
|
|
|
|
|
|
|
|
if ((cf->peer_type == BGP_PT_EXTERNAL) && internal)
|
|
|
|
cf_error("EBGP cannot have the same ASNs");
|
2015-02-22 12:50:58 +00:00
|
|
|
|
2019-01-02 15:01:21 +00:00
|
|
|
if (!cf->iface && (ipa_is_link_local(cf->local_ip) ||
|
|
|
|
ipa_is_link_local(cf->remote_ip)))
|
|
|
|
cf_error("Link-local addresses require defined interface");
|
2015-02-22 12:50:58 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (!(cf->capabilities && cf->enable_as4) && (cf->remote_as > 0xFFFF))
|
2011-11-06 23:31:23 +00:00
|
|
|
cf_error("Neighbor AS number out of range (AS4 not available)");
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (!internal && cf->rr_client)
|
2011-11-06 23:31:23 +00:00
|
|
|
cf_error("Only internal neighbor can be RR client");
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (internal && cf->rs_client)
|
2011-11-06 23:31:23 +00:00
|
|
|
cf_error("Only external neighbor can be RS client");
|
|
|
|
|
2022-07-11 15:19:34 +00:00
|
|
|
if (internal && (cf->local_role != BGP_ROLE_UNDEFINED))
|
|
|
|
cf_error("Local role cannot be set on IBGP sessions");
|
|
|
|
|
2022-07-12 13:03:17 +00:00
|
|
|
if (interior && (cf->local_role != BGP_ROLE_UNDEFINED))
|
|
|
|
log(L_WARN "BGP roles are not recommended to be used within AS confederations");
|
|
|
|
|
2022-07-11 15:19:34 +00:00
|
|
|
if (cf->require_roles && (cf->local_role == BGP_ROLE_UNDEFINED))
|
|
|
|
cf_error("Local role must be set if roles are required");
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (!cf->confederation && cf->confederation_member)
|
|
|
|
cf_error("Confederation ID must be set for member sessions");
|
2011-11-06 23:31:23 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (cf->multihop && (ipa_is_link_local(cf->local_ip) ||
|
|
|
|
ipa_is_link_local(cf->remote_ip)))
|
2012-01-08 14:28:27 +00:00
|
|
|
cf_error("Multihop BGP cannot be used with link-local addresses");
|
|
|
|
|
2017-04-28 09:19:12 +00:00
|
|
|
if (cf->multihop && cf->iface)
|
2017-03-14 11:56:47 +00:00
|
|
|
cf_error("Multihop BGP cannot be bound to interface");
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (cf->multihop && cf->check_link)
|
2015-02-21 10:46:14 +00:00
|
|
|
cf_error("Multihop BGP cannot depend on link state");
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (cf->multihop && cf->bfd && ipa_zero(cf->local_ip))
|
|
|
|
cf_error("Multihop BGP with BFD requires specified local address");
|
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
if (!cf->gr_mode && cf->llgr_mode)
|
|
|
|
cf_error("Long-lived graceful restart requires basic graceful restart");
|
|
|
|
|
2019-11-10 01:06:07 +00:00
|
|
|
if (internal && cf->enforce_first_as)
|
|
|
|
cf_error("Enforce first AS check is requires EBGP sessions");
|
|
|
|
|
2022-12-09 04:51:30 +00:00
|
|
|
if (cf->keepalive_time > cf->hold_time)
|
|
|
|
cf_error("Keepalive time must be at most hold time");
|
|
|
|
|
|
|
|
if (cf->keepalive_time > (cf->hold_time / 2))
|
|
|
|
log(L_WARN "Keepalive time should be at most 1/2 of hold time");
|
|
|
|
|
|
|
|
if (cf->min_hold_time > cf->hold_time)
|
|
|
|
cf_error("Min hold time (%u) exceeds hold time (%u)",
|
|
|
|
cf->min_hold_time, cf->hold_time);
|
|
|
|
|
|
|
|
uint keepalive_time = cf->keepalive_time ?: cf->hold_time / 3;
|
|
|
|
if (cf->min_keepalive_time > keepalive_time)
|
|
|
|
cf_error("Min keepalive time (%u) exceeds keepalive time (%u)",
|
|
|
|
cf->min_keepalive_time, keepalive_time);
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
|
|
|
|
struct bgp_channel_config *cc;
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_CF_WALK_CHANNELS(cf, cc)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
2018-01-16 03:14:49 +00:00
|
|
|
/* Handle undefined import filter */
|
|
|
|
if (cc->c.in_filter == FILTER_UNDEF)
|
|
|
|
if (interior)
|
|
|
|
cc->c.in_filter = FILTER_ACCEPT;
|
|
|
|
else
|
|
|
|
cf_error("EBGP requires explicit import policy");
|
|
|
|
|
|
|
|
/* Handle undefined export filter */
|
|
|
|
if (cc->c.out_filter == FILTER_UNDEF)
|
|
|
|
if (interior)
|
|
|
|
cc->c.out_filter = FILTER_REJECT;
|
|
|
|
else
|
|
|
|
cf_error("EBGP requires explicit export policy");
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Disable after error incompatible with restart limit action */
|
|
|
|
if ((cc->c.in_limit.action == PLA_RESTART) && cf->disable_after_error)
|
|
|
|
cc->c.in_limit.action = PLA_DISABLE;
|
|
|
|
|
2018-12-16 22:44:24 +00:00
|
|
|
/* Different default based on rr_client, rs_client */
|
|
|
|
if (cc->next_hop_keep == 0xff)
|
|
|
|
cc->next_hop_keep = cf->rr_client ? NH_IBGP : (cf->rs_client ? NH_ALL : NH_NO);
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
/* Different default for gw_mode */
|
|
|
|
if (!cc->gw_mode)
|
|
|
|
cc->gw_mode = cf->multihop ? GW_RECURSIVE : GW_DIRECT;
|
2013-11-19 21:33:48 +00:00
|
|
|
|
2022-10-10 03:06:19 +00:00
|
|
|
/* Different default for next_hop_prefer */
|
|
|
|
if (!cc->next_hop_prefer)
|
|
|
|
cc->next_hop_prefer = (cc->gw_mode == GW_DIRECT) ? NHP_GLOBAL : NHP_LOCAL;
|
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
/* Defaults based on proto config */
|
2016-12-07 13:11:28 +00:00
|
|
|
if (cc->gr_able == 0xff)
|
|
|
|
cc->gr_able = (cf->gr_mode == BGP_GR_ABLE);
|
2012-07-04 19:31:03 +00:00
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
if (cc->llgr_able == 0xff)
|
|
|
|
cc->llgr_able = (cf->llgr_mode == BGP_LLGR_ABLE);
|
|
|
|
|
|
|
|
if (cc->llgr_time == ~0U)
|
|
|
|
cc->llgr_time = cf->llgr_time;
|
|
|
|
|
2019-09-28 12:17:20 +00:00
|
|
|
/* AIGP enabled by default on interior sessions */
|
|
|
|
if (cc->aigp == 0xff)
|
|
|
|
cc->aigp = interior;
|
|
|
|
|
2017-03-29 13:31:04 +00:00
|
|
|
/* Default values of IGP tables */
|
2017-03-26 17:20:15 +00:00
|
|
|
if ((cc->gw_mode == GW_RECURSIVE) && !cc->desc->no_igp)
|
|
|
|
{
|
|
|
|
if (!cc->igp_table_ip4 && (bgp_cc_is_ipv4(cc) || cc->ext_next_hop))
|
|
|
|
cc->igp_table_ip4 = bgp_default_igp_table(cf, cc, NET_IP4);
|
|
|
|
|
|
|
|
if (!cc->igp_table_ip6 && (bgp_cc_is_ipv6(cc) || cc->ext_next_hop))
|
|
|
|
cc->igp_table_ip6 = bgp_default_igp_table(cf, cc, NET_IP6);
|
2017-03-29 13:31:04 +00:00
|
|
|
|
|
|
|
if (cc->igp_table_ip4 && bgp_cc_is_ipv6(cc) && !cc->ext_next_hop)
|
|
|
|
cf_error("Mismatched IGP table type");
|
|
|
|
|
|
|
|
if (cc->igp_table_ip6 && bgp_cc_is_ipv4(cc) && !cc->ext_next_hop)
|
|
|
|
cf_error("Mismatched IGP table type");
|
2017-03-26 17:20:15 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 19:25:35 +00:00
|
|
|
/* Default value of base table */
|
|
|
|
if ((BGP_SAFI(cc->afi) == BGP_SAFI_FLOW) && cc->validate && !cc->base_table)
|
|
|
|
cc->base_table = bgp_default_base_table(cf, cc);
|
|
|
|
|
|
|
|
if (cc->base_table && !cc->base_table->trie_used)
|
|
|
|
cf_error("Flowspec validation requires base table (%s) with trie",
|
|
|
|
cc->base_table->name);
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (cf->multihop && (cc->gw_mode == GW_DIRECT))
|
|
|
|
cf_error("Multihop BGP cannot use direct gateway mode");
|
2012-07-04 19:31:03 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if ((cc->gw_mode == GW_RECURSIVE) && cc->c.table->sorted)
|
|
|
|
cf_error("BGP in recursive mode prohibits sorted table");
|
|
|
|
|
|
|
|
if (cf->deterministic_med && cc->c.table->sorted)
|
|
|
|
cf_error("BGP with deterministic MED prohibits sorted table");
|
|
|
|
|
|
|
|
if (cc->secondary && !cc->c.table->sorted)
|
|
|
|
cf_error("BGP with secondary option requires sorted table");
|
|
|
|
}
|
2011-11-06 23:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_reconfigure(struct proto *P, struct proto_config *CF)
|
2011-11-06 23:31:23 +00:00
|
|
|
{
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_proto *p = (void *) P;
|
2019-04-02 15:22:31 +00:00
|
|
|
const struct bgp_config *new = (void *) CF;
|
|
|
|
const struct bgp_config *old = p->cf;
|
2011-11-06 23:31:23 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (proto_get_router_id(CF) != p->local_id)
|
2012-12-27 11:56:23 +00:00
|
|
|
return 0;
|
|
|
|
|
2011-11-06 23:31:23 +00:00
|
|
|
int same = !memcmp(((byte *) old) + sizeof(struct proto_config),
|
|
|
|
((byte *) new) + sizeof(struct proto_config),
|
|
|
|
// password item is last and must be checked separately
|
|
|
|
OFFSETOF(struct bgp_config, password) - sizeof(struct proto_config))
|
2019-07-22 23:52:18 +00:00
|
|
|
&& !bstrcmp(old->password, new->password)
|
2019-06-12 14:35:42 +00:00
|
|
|
&& ((!old->remote_range && !new->remote_range)
|
|
|
|
|| (old->remote_range && new->remote_range && net_equal(old->remote_range, new->remote_range)))
|
2019-07-22 23:52:18 +00:00
|
|
|
&& !bstrcmp(old->dynamic_name, new->dynamic_name)
|
2019-04-08 15:05:07 +00:00
|
|
|
&& (old->dynamic_name_digits == new->dynamic_name_digits);
|
2016-12-07 13:11:28 +00:00
|
|
|
|
|
|
|
/* FIXME: Move channel reconfiguration to generic protocol code ? */
|
|
|
|
struct channel *C, *C2;
|
|
|
|
struct bgp_channel_config *cc;
|
|
|
|
|
|
|
|
WALK_LIST(C, p->p.channels)
|
|
|
|
C->stale = 1;
|
|
|
|
|
2022-09-08 17:41:02 +00:00
|
|
|
BGP_CF_WALK_CHANNELS(new, cc)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
C = (struct channel *) bgp_find_channel(p, cc->afi);
|
|
|
|
same = proto_configure_channel(P, &C, &cc->c) && same;
|
|
|
|
}
|
|
|
|
|
|
|
|
WALK_LIST_DELSAFE(C, C2, p->p.channels)
|
|
|
|
if (C->stale)
|
|
|
|
same = proto_configure_channel(P, &C, NULL) && same;
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
if (same && (p->start_state > BSS_PREPARE))
|
|
|
|
bgp_update_bfd(p, new->bfd);
|
|
|
|
|
2011-11-06 23:31:23 +00:00
|
|
|
/* We should update our copy of configuration ptr as old configuration will be freed */
|
|
|
|
if (same)
|
|
|
|
p->cf = new;
|
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
/* Reset name counter */
|
|
|
|
p->dynamic_name_counter = 0;
|
|
|
|
|
2011-11-06 23:31:23 +00:00
|
|
|
return same;
|
|
|
|
}
|
|
|
|
|
2021-12-20 19:25:35 +00:00
|
|
|
#define TABLE(cf, NAME) ((cf)->NAME ? (cf)->NAME->table : NULL )
|
2017-03-30 11:29:34 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
static int
|
2019-08-06 13:29:06 +00:00
|
|
|
bgp_channel_reconfigure(struct channel *C, struct channel_config *CC, int *import_changed, int *export_changed)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
2019-10-10 21:33:40 +00:00
|
|
|
struct bgp_proto *p = (void *) C->proto;
|
2016-12-07 13:11:28 +00:00
|
|
|
struct bgp_channel *c = (void *) C;
|
|
|
|
struct bgp_channel_config *new = (void *) CC;
|
|
|
|
struct bgp_channel_config *old = c->cf;
|
|
|
|
|
2019-08-06 13:29:06 +00:00
|
|
|
if ((new->secondary != old->secondary) ||
|
2021-12-20 19:25:35 +00:00
|
|
|
(new->validate != old->validate) ||
|
2019-08-06 13:29:06 +00:00
|
|
|
(new->gr_able != old->gr_able) ||
|
|
|
|
(new->llgr_able != old->llgr_able) ||
|
|
|
|
(new->llgr_time != old->llgr_time) ||
|
|
|
|
(new->ext_next_hop != old->ext_next_hop) ||
|
|
|
|
(new->add_path != old->add_path) ||
|
|
|
|
(new->import_table != old->import_table) ||
|
2019-08-13 16:22:07 +00:00
|
|
|
(new->export_table != old->export_table) ||
|
2021-12-20 19:25:35 +00:00
|
|
|
(TABLE(new, igp_table_ip4) != TABLE(old, igp_table_ip4)) ||
|
|
|
|
(TABLE(new, igp_table_ip6) != TABLE(old, igp_table_ip6)) ||
|
|
|
|
(TABLE(new, base_table) != TABLE(old, base_table)))
|
2016-12-07 13:11:28 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-08-06 13:29:06 +00:00
|
|
|
if (new->mandatory && !old->mandatory && (C->channel_state != CS_UP))
|
2016-12-07 13:11:28 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-09-28 12:17:20 +00:00
|
|
|
if ((new->gw_mode != old->gw_mode) ||
|
2022-10-10 03:06:19 +00:00
|
|
|
(new->next_hop_prefer != old->next_hop_prefer) ||
|
2019-09-28 12:17:20 +00:00
|
|
|
(new->aigp != old->aigp) ||
|
|
|
|
(new->cost != old->cost))
|
2019-10-10 21:33:40 +00:00
|
|
|
{
|
|
|
|
/* import_changed itself does not force ROUTE_REFRESH when import_table is active */
|
|
|
|
if (c->c.in_table && (c->c.channel_state == CS_UP))
|
|
|
|
bgp_schedule_packet(p->conn, c, PKT_ROUTE_REFRESH);
|
|
|
|
|
2019-08-06 13:29:06 +00:00
|
|
|
*import_changed = 1;
|
2019-10-10 21:33:40 +00:00
|
|
|
}
|
2019-08-06 13:29:06 +00:00
|
|
|
|
|
|
|
if (!ipa_equal(new->next_hop_addr, old->next_hop_addr) ||
|
|
|
|
(new->next_hop_self != old->next_hop_self) ||
|
|
|
|
(new->next_hop_keep != old->next_hop_keep) ||
|
2019-09-28 12:17:20 +00:00
|
|
|
(new->aigp != old->aigp) ||
|
|
|
|
(new->aigp_originate != old->aigp_originate))
|
2019-08-06 13:29:06 +00:00
|
|
|
*export_changed = 1;
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
c->cf = new;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-11-06 23:31:23 +00:00
|
|
|
static void
|
2020-11-08 14:33:22 +00:00
|
|
|
bgp_copy_config(struct proto_config *dest, struct proto_config *src)
|
2011-11-06 23:31:23 +00:00
|
|
|
{
|
2020-11-08 14:33:22 +00:00
|
|
|
struct bgp_config *d = (void *) dest;
|
|
|
|
struct bgp_config *s = (void *) src;
|
|
|
|
|
|
|
|
/* Copy BFD options */
|
|
|
|
if (s->bfd)
|
|
|
|
{
|
|
|
|
struct bfd_options *opts = cfg_alloc(sizeof(struct bfd_options));
|
|
|
|
memcpy(opts, s->bfd, sizeof(struct bfd_options));
|
|
|
|
d->bfd = opts;
|
|
|
|
}
|
2011-11-06 23:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-04 17:06:18 +00:00
|
|
|
/**
|
|
|
|
* bgp_error - report a protocol error
|
|
|
|
* @c: connection
|
|
|
|
* @code: error code (according to the RFC)
|
2000-06-07 12:29:08 +00:00
|
|
|
* @subcode: error sub-code
|
2000-06-04 17:06:18 +00:00
|
|
|
* @data: data to be passed in the Notification message
|
|
|
|
* @len: length of the data
|
|
|
|
*
|
|
|
|
* bgp_error() sends a notification packet to tell the other side that a protocol
|
2000-06-07 12:29:08 +00:00
|
|
|
* error has occurred (including the data considered erroneous if possible) and
|
2000-06-04 17:06:18 +00:00
|
|
|
* closes the connection.
|
|
|
|
*/
|
2000-03-30 10:44:20 +00:00
|
|
|
void
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_error(struct bgp_conn *c, uint code, uint subcode, byte *data, int len)
|
2000-03-30 10:44:20 +00:00
|
|
|
{
|
2009-06-06 22:38:38 +00:00
|
|
|
struct bgp_proto *p = c->bgp;
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
if (c->state == BS_CLOSE)
|
2000-03-30 10:44:20 +00:00
|
|
|
return;
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_log_error(p, BE_BGP_TX, "Error", code, subcode, data, ABS(len));
|
2009-06-06 22:38:38 +00:00
|
|
|
bgp_store_error(p, c, BE_BGP_TX, (code << 16) | subcode);
|
2008-12-19 00:34:39 +00:00
|
|
|
bgp_conn_enter_close_state(c);
|
|
|
|
|
2000-03-30 10:44:20 +00:00
|
|
|
c->notify_code = code;
|
|
|
|
c->notify_subcode = subcode;
|
2000-04-25 21:13:25 +00:00
|
|
|
c->notify_data = data;
|
|
|
|
c->notify_size = (len > 0) ? len : 0;
|
2016-12-07 13:11:28 +00:00
|
|
|
bgp_schedule_packet(c, NULL, PKT_NOTIFICATION);
|
2009-06-06 22:38:38 +00:00
|
|
|
|
|
|
|
if (code != 6)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
bgp_update_startup_delay(p);
|
2017-12-07 20:54:47 +00:00
|
|
|
bgp_stop(p, 0, NULL, 0);
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2000-03-30 10:44:20 +00:00
|
|
|
}
|
|
|
|
|
2008-12-19 00:34:39 +00:00
|
|
|
/**
|
|
|
|
* bgp_store_error - store last error for status report
|
|
|
|
* @p: BGP instance
|
|
|
|
* @c: connection
|
|
|
|
* @class: error class (BE_xxx constants)
|
|
|
|
* @code: error code (class specific)
|
|
|
|
*
|
|
|
|
* bgp_store_error() decides whether given error is interesting enough
|
|
|
|
* and store that error to last_error variables of @p
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
bgp_store_error(struct bgp_proto *p, struct bgp_conn *c, u8 class, u32 code)
|
|
|
|
{
|
|
|
|
/* During PS_UP, we ignore errors on secondary connection */
|
|
|
|
if ((p->p.proto_state == PS_UP) && c && (c != p->conn))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* During PS_STOP, we ignore any errors, as we want to report
|
|
|
|
* the error that caused transition to PS_STOP
|
|
|
|
*/
|
|
|
|
if (p->p.proto_state == PS_STOP)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->last_error_class = class;
|
|
|
|
p->last_error_code = code;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *bgp_state_names[] = { "Idle", "Connect", "Active", "OpenSent", "OpenConfirm", "Established", "Close" };
|
2009-06-04 11:31:09 +00:00
|
|
|
static char *bgp_err_classes[] = { "", "Error: ", "Socket: ", "Received: ", "BGP Error: ", "Automatic shutdown: ", ""};
|
2015-02-21 10:46:14 +00:00
|
|
|
static char *bgp_misc_errors[] = { "", "Neighbor lost", "Invalid next hop", "Kernel MD5 auth failed", "No listening socket", "Link down", "BFD session down", "Graceful restart"};
|
2009-06-04 11:31:09 +00:00
|
|
|
static char *bgp_auto_errors[] = { "", "Route limit exceeded"};
|
2018-07-31 16:40:38 +00:00
|
|
|
static char *bgp_gr_states[] = { "None", "Regular", "Long-lived"};
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2010-04-06 22:19:23 +00:00
|
|
|
static const char *
|
|
|
|
bgp_last_errmsg(struct bgp_proto *p)
|
2000-03-30 18:44:23 +00:00
|
|
|
{
|
2008-12-19 00:34:39 +00:00
|
|
|
switch (p->last_error_class)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
case BE_MISC:
|
|
|
|
return bgp_misc_errors[p->last_error_code];
|
|
|
|
case BE_SOCKET:
|
|
|
|
return (p->last_error_code == 0) ? "Connection closed" : strerror(p->last_error_code);
|
|
|
|
case BE_BGP_RX:
|
|
|
|
case BE_BGP_TX:
|
|
|
|
return bgp_error_dsc(p->last_error_code >> 16, p->last_error_code & 0xFF);
|
|
|
|
case BE_AUTO_DOWN:
|
|
|
|
return bgp_auto_errors[p->last_error_code];
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
2010-04-06 22:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
bgp_state_dsc(struct bgp_proto *p)
|
|
|
|
{
|
2011-09-03 22:56:02 +00:00
|
|
|
if (p->p.proto_state == PS_DOWN)
|
|
|
|
return "Down";
|
2010-04-06 22:19:23 +00:00
|
|
|
|
|
|
|
int state = MAX(p->incoming_conn.state, p->outgoing_conn.state);
|
2019-04-08 15:05:07 +00:00
|
|
|
if ((state == BS_IDLE) && (p->start_state >= BSS_CONNECT) && p->passive)
|
2010-04-06 22:19:23 +00:00
|
|
|
return "Passive";
|
|
|
|
|
|
|
|
return bgp_state_names[state];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_get_status(struct proto *P, byte *buf)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
|
|
|
|
const char *err1 = bgp_err_classes[p->last_error_class];
|
|
|
|
const char *err2 = bgp_last_errmsg(p);
|
2008-12-19 00:34:39 +00:00
|
|
|
|
2000-05-15 12:19:28 +00:00
|
|
|
if (P->proto_state == PS_DOWN)
|
2008-12-19 00:34:39 +00:00
|
|
|
bsprintf(buf, "%s%s", err1, err2);
|
2000-05-15 12:19:28 +00:00
|
|
|
else
|
2010-04-06 22:19:23 +00:00
|
|
|
bsprintf(buf, "%-14s%s%s", bgp_state_dsc(p), err1, err2);
|
|
|
|
}
|
|
|
|
|
2016-12-20 16:39:59 +00:00
|
|
|
static void
|
|
|
|
bgp_show_afis(int code, char *s, u32 *afis, uint count)
|
|
|
|
{
|
|
|
|
buffer b;
|
|
|
|
LOG_BUFFER_INIT(b);
|
|
|
|
|
|
|
|
buffer_puts(&b, s);
|
|
|
|
|
|
|
|
for (u32 *af = afis; af < (afis + count); af++)
|
|
|
|
{
|
|
|
|
const struct bgp_af_desc *desc = bgp_get_af_desc(*af);
|
|
|
|
if (desc)
|
|
|
|
buffer_print(&b, " %s", desc->name);
|
|
|
|
else
|
|
|
|
buffer_print(&b, " <%u/%u>", BGP_AFI(*af), BGP_SAFI(*af));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b.pos == b.end)
|
|
|
|
strcpy(b.end - 32, " ... <too long>");
|
|
|
|
|
|
|
|
cli_msg(code, b.start);
|
|
|
|
}
|
|
|
|
|
2023-01-20 14:55:47 +00:00
|
|
|
const char *
|
2022-07-11 15:19:34 +00:00
|
|
|
bgp_format_role_name(u8 role)
|
|
|
|
{
|
|
|
|
static const char *bgp_role_names[] = { "provider", "rs_server", "rs_client", "customer", "peer" };
|
|
|
|
if (role == BGP_ROLE_UNDEFINED) return "undefined";
|
2022-07-12 13:03:17 +00:00
|
|
|
if (role < ARRAY_SIZE(bgp_role_names)) return bgp_role_names[role];
|
2022-07-11 15:19:34 +00:00
|
|
|
return "?";
|
|
|
|
}
|
|
|
|
|
2016-12-20 16:39:59 +00:00
|
|
|
static void
|
|
|
|
bgp_show_capabilities(struct bgp_proto *p UNUSED, struct bgp_caps *caps)
|
|
|
|
{
|
|
|
|
struct bgp_af_caps *ac;
|
|
|
|
uint any_mp_bgp = 0;
|
|
|
|
uint any_gr_able = 0;
|
|
|
|
uint any_add_path = 0;
|
2017-01-24 01:00:35 +00:00
|
|
|
uint any_ext_next_hop = 0;
|
2018-07-31 16:40:38 +00:00
|
|
|
uint any_llgr_able = 0;
|
2016-12-20 16:39:59 +00:00
|
|
|
u32 *afl1 = alloca(caps->af_count * sizeof(u32));
|
|
|
|
u32 *afl2 = alloca(caps->af_count * sizeof(u32));
|
|
|
|
uint afn1, afn2;
|
|
|
|
|
|
|
|
WALK_AF_CAPS(caps, ac)
|
|
|
|
{
|
|
|
|
any_mp_bgp |= ac->ready;
|
|
|
|
any_gr_able |= ac->gr_able;
|
|
|
|
any_add_path |= ac->add_path;
|
2017-01-24 01:00:35 +00:00
|
|
|
any_ext_next_hop |= ac->ext_next_hop;
|
2018-07-31 16:40:38 +00:00
|
|
|
any_llgr_able |= ac->llgr_able;
|
2016-12-20 16:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (any_mp_bgp)
|
|
|
|
{
|
|
|
|
cli_msg(-1006, " Multiprotocol");
|
|
|
|
|
|
|
|
afn1 = 0;
|
|
|
|
WALK_AF_CAPS(caps, ac)
|
|
|
|
if (ac->ready)
|
|
|
|
afl1[afn1++] = ac->afi;
|
|
|
|
|
|
|
|
bgp_show_afis(-1006, " AF announced:", afl1, afn1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caps->route_refresh)
|
|
|
|
cli_msg(-1006, " Route refresh");
|
|
|
|
|
2017-01-24 01:00:35 +00:00
|
|
|
if (any_ext_next_hop)
|
|
|
|
{
|
|
|
|
cli_msg(-1006, " Extended next hop");
|
|
|
|
|
|
|
|
afn1 = 0;
|
|
|
|
WALK_AF_CAPS(caps, ac)
|
|
|
|
if (ac->ext_next_hop)
|
|
|
|
afl1[afn1++] = ac->afi;
|
|
|
|
|
|
|
|
bgp_show_afis(-1006, " IPv6 nexthop:", afl1, afn1);
|
|
|
|
}
|
|
|
|
|
2016-12-20 16:39:59 +00:00
|
|
|
if (caps->ext_messages)
|
|
|
|
cli_msg(-1006, " Extended message");
|
|
|
|
|
|
|
|
if (caps->gr_aware)
|
|
|
|
cli_msg(-1006, " Graceful restart");
|
|
|
|
|
|
|
|
if (any_gr_able)
|
|
|
|
{
|
|
|
|
/* Continues from gr_aware */
|
|
|
|
cli_msg(-1006, " Restart time: %u", caps->gr_time);
|
|
|
|
if (caps->gr_flags & BGP_GRF_RESTART)
|
|
|
|
cli_msg(-1006, " Restart recovery");
|
|
|
|
|
|
|
|
afn1 = afn2 = 0;
|
|
|
|
WALK_AF_CAPS(caps, ac)
|
|
|
|
{
|
|
|
|
if (ac->gr_able)
|
|
|
|
afl1[afn1++] = ac->afi;
|
|
|
|
|
|
|
|
if (ac->gr_af_flags & BGP_GRF_FORWARDING)
|
|
|
|
afl2[afn2++] = ac->afi;
|
|
|
|
}
|
|
|
|
|
|
|
|
bgp_show_afis(-1006, " AF supported:", afl1, afn1);
|
|
|
|
bgp_show_afis(-1006, " AF preserved:", afl2, afn2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caps->as4_support)
|
|
|
|
cli_msg(-1006, " 4-octet AS numbers");
|
|
|
|
|
|
|
|
if (any_add_path)
|
|
|
|
{
|
|
|
|
cli_msg(-1006, " ADD-PATH");
|
|
|
|
|
|
|
|
afn1 = afn2 = 0;
|
|
|
|
WALK_AF_CAPS(caps, ac)
|
|
|
|
{
|
|
|
|
if (ac->add_path & BGP_ADD_PATH_RX)
|
|
|
|
afl1[afn1++] = ac->afi;
|
|
|
|
|
|
|
|
if (ac->add_path & BGP_ADD_PATH_TX)
|
|
|
|
afl2[afn2++] = ac->afi;
|
|
|
|
}
|
|
|
|
|
|
|
|
bgp_show_afis(-1006, " RX:", afl1, afn1);
|
|
|
|
bgp_show_afis(-1006, " TX:", afl2, afn2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caps->enhanced_refresh)
|
|
|
|
cli_msg(-1006, " Enhanced refresh");
|
2018-07-31 16:40:38 +00:00
|
|
|
|
|
|
|
if (caps->llgr_aware)
|
|
|
|
cli_msg(-1006, " Long-lived graceful restart");
|
|
|
|
|
|
|
|
if (any_llgr_able)
|
|
|
|
{
|
|
|
|
u32 stale_time = 0;
|
|
|
|
|
|
|
|
afn1 = afn2 = 0;
|
|
|
|
WALK_AF_CAPS(caps, ac)
|
|
|
|
{
|
|
|
|
stale_time = MAX(stale_time, ac->llgr_time);
|
|
|
|
|
|
|
|
if (ac->llgr_able && ac->llgr_time)
|
|
|
|
afl1[afn1++] = ac->afi;
|
|
|
|
|
|
|
|
if (ac->llgr_flags & BGP_GRF_FORWARDING)
|
|
|
|
afl2[afn2++] = ac->afi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Continues from llgr_aware */
|
|
|
|
cli_msg(-1006, " LL stale time: %u", stale_time);
|
|
|
|
|
|
|
|
bgp_show_afis(-1006, " AF supported:", afl1, afn1);
|
|
|
|
bgp_show_afis(-1006, " AF preserved:", afl2, afn2);
|
|
|
|
}
|
2021-02-10 15:53:57 +00:00
|
|
|
|
|
|
|
if (caps->hostname)
|
|
|
|
cli_msg(-1006, " Hostname: %s", caps->hostname);
|
2022-07-11 15:19:34 +00:00
|
|
|
|
|
|
|
if (caps->role != BGP_ROLE_UNDEFINED)
|
|
|
|
cli_msg(-1006, " Role: %s", bgp_format_role_name(caps->role));
|
2016-12-20 16:39:59 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 22:19:23 +00:00
|
|
|
static void
|
|
|
|
bgp_show_proto_info(struct proto *P)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
|
|
|
|
cli_msg(-1006, " BGP state: %s", bgp_state_dsc(p));
|
2019-04-08 15:05:07 +00:00
|
|
|
|
|
|
|
if (bgp_is_dynamic(p) && p->cf->remote_range)
|
|
|
|
cli_msg(-1006, " Neighbor range: %N", p->cf->remote_range);
|
|
|
|
else
|
|
|
|
cli_msg(-1006, " Neighbor address: %I%J", p->remote_ip, p->cf->iface);
|
|
|
|
|
2022-05-21 14:21:34 +00:00
|
|
|
if ((p->conn == &p->outgoing_conn) && (p->cf->remote_port != BGP_PORT))
|
|
|
|
cli_msg(-1006, " Neighbor port: %u", p->cf->remote_port);
|
|
|
|
|
2019-04-08 15:05:07 +00:00
|
|
|
cli_msg(-1006, " Neighbor AS: %u", p->remote_as);
|
2019-04-30 11:44:11 +00:00
|
|
|
cli_msg(-1006, " Local AS: %u", p->cf->local_as);
|
2010-04-06 22:19:23 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if (p->gr_active_num)
|
2014-03-20 13:07:12 +00:00
|
|
|
cli_msg(-1006, " Neighbor graceful restart active");
|
|
|
|
|
2010-04-06 22:19:23 +00:00
|
|
|
if (P->proto_state == PS_START)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
struct bgp_conn *oc = &p->outgoing_conn;
|
2010-04-06 22:19:23 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if ((p->start_state < BSS_CONNECT) &&
|
2017-11-28 16:43:20 +00:00
|
|
|
(tm_active(p->startup_timer)))
|
2017-06-13 14:52:21 +00:00
|
|
|
cli_msg(-1006, " Error wait: %t/%u",
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_remains(p->startup_timer), p->startup_delay);
|
2010-04-06 22:19:23 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
if ((oc->state == BS_ACTIVE) &&
|
2017-11-28 16:43:20 +00:00
|
|
|
(tm_active(oc->connect_timer)))
|
2017-06-13 14:52:21 +00:00
|
|
|
cli_msg(-1006, " Connect delay: %t/%u",
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_remains(oc->connect_timer), p->cf->connect_delay_time);
|
2014-03-20 13:07:12 +00:00
|
|
|
|
2017-11-28 16:43:20 +00:00
|
|
|
if (p->gr_active_num && tm_active(p->gr_timer))
|
2017-06-13 14:52:21 +00:00
|
|
|
cli_msg(-1006, " Restart timer: %t/-",
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_remains(p->gr_timer));
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2010-04-06 22:19:23 +00:00
|
|
|
else if (P->proto_state == PS_UP)
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
cli_msg(-1006, " Neighbor ID: %R", p->remote_id);
|
2016-12-20 16:39:59 +00:00
|
|
|
cli_msg(-1006, " Local capabilities");
|
|
|
|
bgp_show_capabilities(p, p->conn->local_caps);
|
|
|
|
cli_msg(-1006, " Neighbor capabilities");
|
|
|
|
bgp_show_capabilities(p, p->conn->remote_caps);
|
2017-12-09 23:55:34 +00:00
|
|
|
cli_msg(-1006, " Session: %s%s%s%s%s",
|
|
|
|
p->is_internal ? "internal" : "external",
|
|
|
|
p->cf->multihop ? " multihop" : "",
|
|
|
|
p->rr_client ? " route-reflector" : "",
|
|
|
|
p->rs_client ? " route-server" : "",
|
|
|
|
p->as4_session ? " AS4" : "");
|
2019-04-02 15:22:31 +00:00
|
|
|
cli_msg(-1006, " Source address: %I", p->local_ip);
|
2017-06-13 14:52:21 +00:00
|
|
|
cli_msg(-1006, " Hold timer: %t/%u",
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_remains(p->conn->hold_timer), p->conn->hold_time);
|
2017-06-13 14:52:21 +00:00
|
|
|
cli_msg(-1006, " Keepalive timer: %t/%u",
|
2017-11-28 16:43:20 +00:00
|
|
|
tm_remains(p->conn->keepalive_timer), p->conn->keepalive_time);
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2010-04-06 22:19:23 +00:00
|
|
|
|
2021-03-18 14:44:04 +00:00
|
|
|
#if 0
|
2019-12-03 17:05:41 +00:00
|
|
|
struct bgp_stats *s = &p->stats;
|
|
|
|
cli_msg(-1006, " FSM established transitions: %u",
|
|
|
|
s->fsm_established_transitions);
|
|
|
|
cli_msg(-1006, " Rcvd messages: %u total / %u updates / %lu bytes",
|
|
|
|
s->rx_messages, s->rx_updates, s->rx_bytes);
|
|
|
|
cli_msg(-1006, " Sent messages: %u total / %u updates / %lu bytes",
|
|
|
|
s->tx_messages, s->tx_updates, s->tx_bytes);
|
|
|
|
cli_msg(-1006, " Last rcvd update elapsed time: %t s",
|
|
|
|
p->last_rx_update ? (current_time() - p->last_rx_update) : 0);
|
2021-03-18 14:44:04 +00:00
|
|
|
#endif
|
2019-12-03 17:05:41 +00:00
|
|
|
|
2015-02-21 10:46:14 +00:00
|
|
|
if ((p->last_error_class != BE_NONE) &&
|
2010-04-06 22:19:23 +00:00
|
|
|
(p->last_error_class != BE_MAN_DOWN))
|
2016-12-07 13:11:28 +00:00
|
|
|
{
|
|
|
|
const char *err1 = bgp_err_classes[p->last_error_class];
|
|
|
|
const char *err2 = bgp_last_errmsg(p);
|
|
|
|
cli_msg(-1006, " Last error: %s%s", err1, err2);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-26 17:20:15 +00:00
|
|
|
struct bgp_channel *c;
|
2016-12-07 13:11:28 +00:00
|
|
|
WALK_LIST(c, p->p.channels)
|
2017-03-26 17:20:15 +00:00
|
|
|
{
|
|
|
|
channel_show_info(&c->c);
|
|
|
|
|
2022-09-08 17:41:02 +00:00
|
|
|
if (c->c.channel != &channel_bgp)
|
|
|
|
continue;
|
|
|
|
|
2018-07-31 16:40:38 +00:00
|
|
|
if (p->gr_active_num)
|
|
|
|
cli_msg(-1006, " Neighbor GR: %s", bgp_gr_states[c->gr_active]);
|
|
|
|
|
2018-10-01 13:35:43 +00:00
|
|
|
if (c->stale_timer && tm_active(c->stale_timer))
|
2018-07-31 16:40:38 +00:00
|
|
|
cli_msg(-1006, " LL stale timer: %t/-", tm_remains(c->stale_timer));
|
|
|
|
|
2017-12-09 23:55:34 +00:00
|
|
|
if (c->c.channel_state == CS_UP)
|
|
|
|
{
|
|
|
|
if (ipa_zero(c->link_addr))
|
|
|
|
cli_msg(-1006, " BGP Next hop: %I", c->next_hop_addr);
|
|
|
|
else
|
|
|
|
cli_msg(-1006, " BGP Next hop: %I %I", c->next_hop_addr, c->link_addr);
|
|
|
|
}
|
2017-12-08 01:26:17 +00:00
|
|
|
|
2017-03-26 17:20:15 +00:00
|
|
|
if (c->igp_table_ip4)
|
|
|
|
cli_msg(-1006, " IGP IPv4 table: %s", c->igp_table_ip4->name);
|
|
|
|
|
|
|
|
if (c->igp_table_ip6)
|
|
|
|
cli_msg(-1006, " IGP IPv6 table: %s", c->igp_table_ip6->name);
|
2021-12-20 19:25:35 +00:00
|
|
|
|
|
|
|
if (c->base_table)
|
|
|
|
cli_msg(-1006, " Base table: %s", c->base_table->name);
|
2017-03-26 17:20:15 +00:00
|
|
|
}
|
2016-12-07 13:11:28 +00:00
|
|
|
}
|
2000-03-30 18:44:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
struct channel_class channel_bgp = {
|
|
|
|
.channel_size = sizeof(struct bgp_channel),
|
|
|
|
.config_size = sizeof(struct bgp_channel_config),
|
|
|
|
.init = bgp_channel_init,
|
|
|
|
.start = bgp_channel_start,
|
|
|
|
.shutdown = bgp_channel_shutdown,
|
|
|
|
.cleanup = bgp_channel_cleanup,
|
|
|
|
.reconfigure = bgp_channel_reconfigure,
|
|
|
|
};
|
|
|
|
|
2000-03-19 22:09:07 +00:00
|
|
|
struct protocol proto_bgp = {
|
2014-12-03 09:10:34 +00:00
|
|
|
.name = "BGP",
|
|
|
|
.template = "bgp%d",
|
2018-05-07 12:47:00 +00:00
|
|
|
.class = PROTOCOL_BGP,
|
2014-12-03 09:10:34 +00:00
|
|
|
.preference = DEF_PREF_BGP,
|
2017-03-22 14:00:07 +00:00
|
|
|
.channel_mask = NB_IP | NB_VPN | NB_FLOW,
|
2016-12-07 13:11:28 +00:00
|
|
|
.proto_size = sizeof(struct bgp_proto),
|
2015-02-21 20:08:23 +00:00
|
|
|
.config_size = sizeof(struct bgp_config),
|
2016-12-07 13:11:28 +00:00
|
|
|
.postconfig = bgp_postconfig,
|
2014-12-03 09:10:34 +00:00
|
|
|
.init = bgp_init,
|
|
|
|
.start = bgp_start,
|
|
|
|
.shutdown = bgp_shutdown,
|
|
|
|
.reconfigure = bgp_reconfigure,
|
|
|
|
.copy_config = bgp_copy_config,
|
|
|
|
.get_status = bgp_get_status,
|
|
|
|
.get_attr = bgp_get_attr,
|
|
|
|
.get_route_info = bgp_get_route_info,
|
|
|
|
.show_proto_info = bgp_show_proto_info
|
2000-03-19 22:09:07 +00:00
|
|
|
};
|
2022-03-18 21:05:50 +00:00
|
|
|
|
|
|
|
void bgp_build(void)
|
|
|
|
{
|
|
|
|
proto_build(&proto_bgp);
|
|
|
|
}
|