2000-03-20 06:09:07 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- The Border Gateway Protocol
|
|
|
|
*
|
|
|
|
* (c) 2000 Martin Mares <mj@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-05 01:06:18 +08:00
|
|
|
/**
|
|
|
|
* DOC: Border Gateway Protocol
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* both incoming and outgoing BGP packets and |attrs.c| containing functions for
|
|
|
|
* manipulation with BGP attribute lists.
|
|
|
|
*
|
|
|
|
* 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-07 21:25:53 +08:00
|
|
|
* Each instance of BGP (corresponding to a single BGP peer) is described by a &bgp_proto
|
2000-06-05 01:06:18 +08:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
2000-06-07 21:25:53 +08:00
|
|
|
* tracking code wanting to send a Open, Keepalive or Notification message), we call
|
2000-06-05 01:06:18 +08:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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 08:35:33 +08: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.
|
2000-06-05 01:06:18 +08:00
|
|
|
*/
|
|
|
|
|
2009-03-19 03:30:21 +08:00
|
|
|
#undef LOCAL_DEBUG
|
2000-03-20 06:09:07 +08:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/route.h"
|
2010-04-07 06:19:23 +08:00
|
|
|
#include "nest/cli.h"
|
2013-11-20 05:33:48 +08:00
|
|
|
#include "nest/locks.h"
|
2000-03-20 06:09:07 +08:00
|
|
|
#include "conf/conf.h"
|
2000-03-21 05:50:17 +08:00
|
|
|
#include "lib/socket.h"
|
2000-03-31 02:44:23 +08:00
|
|
|
#include "lib/resource.h"
|
2002-11-13 16:47:06 +08:00
|
|
|
#include "lib/string.h"
|
2000-03-20 06:09:07 +08:00
|
|
|
|
|
|
|
#include "bgp.h"
|
|
|
|
|
2013-11-27 05:37:24 +08:00
|
|
|
|
2000-03-31 02:44:23 +08:00
|
|
|
struct linpool *bgp_linpool; /* Global temporary pool */
|
2000-03-21 05:50:17 +08:00
|
|
|
static sock *bgp_listen_sk; /* Global listening socket */
|
|
|
|
static int bgp_counter; /* Number of protocol instances using the listening socket */
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
static void bgp_close(struct bgp_proto *p, int apply_md5);
|
2000-03-21 05:50:17 +08:00
|
|
|
static void bgp_connect(struct bgp_proto *p);
|
2009-06-07 00:16:22 +08:00
|
|
|
static void bgp_active(struct bgp_proto *p);
|
2009-06-19 01:20:07 +08:00
|
|
|
static sock *bgp_setup_listen_sk(ip_addr addr, unsigned port, u32 flags);
|
2013-11-20 05:33:48 +08:00
|
|
|
static void bgp_update_bfd(struct bgp_proto *p, int use_bfd);
|
2000-03-20 06:09:07 +08:00
|
|
|
|
2008-10-27 05:36:08 +08:00
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
/**
|
|
|
|
* bgp_open - open a BGP instance
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
|
|
|
* This function allocates and configures shared BGP resources.
|
|
|
|
* Should be called as the last step during initialization
|
|
|
|
* (when lock is acquired and neighbor is ready).
|
|
|
|
* When error, state changed to PS_DOWN, -1 is returned and caller
|
|
|
|
* should return immediately.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
bgp_open(struct bgp_proto *p)
|
|
|
|
{
|
2009-06-19 01:20:07 +08:00
|
|
|
struct config *cfg = p->cf->c.global;
|
2011-08-17 05:05:35 +08:00
|
|
|
int errcode;
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
if (!bgp_listen_sk)
|
2009-06-23 17:08:30 +08:00
|
|
|
bgp_listen_sk = bgp_setup_listen_sk(cfg->listen_bgp_addr, cfg->listen_bgp_port, cfg->listen_bgp_flags);
|
2008-12-19 08:34:39 +08:00
|
|
|
|
2010-05-31 17:35:29 +08:00
|
|
|
if (!bgp_listen_sk)
|
|
|
|
{
|
2011-08-17 05:05:35 +08:00
|
|
|
errcode = BEM_NO_SOCKET;
|
|
|
|
goto err;
|
2010-05-31 17:35:29 +08:00
|
|
|
}
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
if (!bgp_linpool)
|
|
|
|
bgp_linpool = lp_new(&root_pool, 4080);
|
|
|
|
|
2014-05-18 17:42:26 +08:00
|
|
|
bgp_counter++;
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
if (p->cf->password)
|
2014-05-18 17:42:26 +08:00
|
|
|
if (sk_set_md5_auth(bgp_listen_sk, p->cf->remote_ip, p->cf->iface, p->cf->password) < 0)
|
|
|
|
{
|
|
|
|
sk_log_error(bgp_listen_sk, p->p.name);
|
|
|
|
bgp_close(p, 0);
|
|
|
|
errcode = BEM_INVALID_MD5;
|
|
|
|
goto err;
|
|
|
|
}
|
2008-12-19 08:34:39 +08:00
|
|
|
|
|
|
|
return 0;
|
2011-08-17 05:05:35 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
p->p.disabled = 1;
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, errcode);
|
|
|
|
proto_notify_state(&p->p, PS_DOWN);
|
|
|
|
return -1;
|
2008-12-19 08:34:39 +08:00
|
|
|
}
|
|
|
|
|
2009-06-07 00:16:22 +08:00
|
|
|
static void
|
|
|
|
bgp_startup(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "Started");
|
|
|
|
p->start_state = p->cf->capabilities ? BSS_CONNECT : BSS_CONNECT_NOCAP;
|
2009-09-25 04:12:11 +08:00
|
|
|
|
|
|
|
if (!p->cf->passive)
|
|
|
|
bgp_active(p);
|
2009-06-07 00:16:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_startup_timeout(timer *t)
|
|
|
|
{
|
|
|
|
bgp_startup(t->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_initiate(struct bgp_proto *p)
|
|
|
|
{
|
2010-07-12 23:39:39 +08:00
|
|
|
int rv = bgp_open(p);
|
|
|
|
if (rv < 0)
|
|
|
|
return;
|
|
|
|
|
2013-11-20 05:33:48 +08:00
|
|
|
if (p->cf->bfd)
|
|
|
|
bgp_update_bfd(p, p->cf->bfd);
|
|
|
|
|
2009-06-07 00:16:22 +08:00
|
|
|
if (p->startup_delay)
|
|
|
|
{
|
2013-11-20 05:33:48 +08:00
|
|
|
p->start_state = BSS_DELAY;
|
2015-02-22 23:08:28 +08:00
|
|
|
BGP_TRACE(D_EVENTS, "Startup delayed by %d seconds due to errors", p->startup_delay);
|
2009-06-07 00:16:22 +08:00
|
|
|
bgp_start_timer(p->startup_timer, p->startup_delay);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bgp_startup(p);
|
|
|
|
}
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
/**
|
|
|
|
* bgp_close - close a BGP instance
|
|
|
|
* @p: BGP instance
|
|
|
|
* @apply_md5: 0 to disable unsetting MD5 auth
|
|
|
|
*
|
|
|
|
* This function frees and deconfigures shared BGP resources.
|
|
|
|
* @apply_md5 is set to 0 when bgp_close is called as a cleanup
|
|
|
|
* from failed bgp_open().
|
|
|
|
*/
|
2004-06-05 17:58:23 +08:00
|
|
|
static void
|
2008-12-19 08:34:39 +08:00
|
|
|
bgp_close(struct bgp_proto *p, int apply_md5)
|
2000-03-21 05:50:17 +08:00
|
|
|
{
|
|
|
|
ASSERT(bgp_counter);
|
|
|
|
bgp_counter--;
|
2008-10-27 05:42:39 +08:00
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
if (p->cf->password && apply_md5)
|
2014-05-18 17:42:26 +08:00
|
|
|
if (sk_set_md5_auth(bgp_listen_sk, p->cf->remote_ip, p->cf->iface, NULL) < 0)
|
|
|
|
sk_log_error(bgp_listen_sk, p->p.name);
|
2008-10-27 05:42:39 +08:00
|
|
|
|
2000-03-21 05:50:17 +08:00
|
|
|
if (!bgp_counter)
|
|
|
|
{
|
|
|
|
rfree(bgp_listen_sk);
|
|
|
|
bgp_listen_sk = NULL;
|
2000-03-31 02:44:23 +08:00
|
|
|
rfree(bgp_linpool);
|
|
|
|
bgp_linpool = NULL;
|
2000-03-21 05:50:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-05 01:06:18 +08:00
|
|
|
/**
|
|
|
|
* bgp_start_timer - start a BGP timer
|
|
|
|
* @t: timer
|
|
|
|
* @value: time to fire (0 to disable the timer)
|
|
|
|
*
|
|
|
|
* 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-03-30 18:44:20 +08:00
|
|
|
void
|
2000-03-21 05:50:17 +08:00
|
|
|
bgp_start_timer(timer *t, int value)
|
|
|
|
{
|
2000-03-30 18:44:20 +08:00
|
|
|
if (value)
|
2000-04-26 06:01:19 +08:00
|
|
|
{
|
|
|
|
/* The randomization procedure is specified in RFC 1771: 9.2.3.3 */
|
|
|
|
t->randomize = value / 4;
|
|
|
|
tm_start(t, value - t->randomize);
|
|
|
|
}
|
2000-03-31 01:39:48 +08:00
|
|
|
else
|
|
|
|
tm_stop(t);
|
|
|
|
}
|
|
|
|
|
2000-06-05 01:06:18 +08:00
|
|
|
/**
|
|
|
|
* bgp_close_conn - close a BGP connection
|
|
|
|
* @conn: connection to close
|
|
|
|
*
|
|
|
|
* This function takes a connection described by the &bgp_conn structure,
|
|
|
|
* closes its socket and frees all resources associated with it.
|
|
|
|
*/
|
2000-03-31 01:39:48 +08:00
|
|
|
void
|
|
|
|
bgp_close_conn(struct bgp_conn *conn)
|
|
|
|
{
|
2010-02-21 21:34:53 +08:00
|
|
|
// struct bgp_proto *p = conn->bgp;
|
2000-03-31 01:39:48 +08:00
|
|
|
|
|
|
|
DBG("BGP: Closing connection\n");
|
|
|
|
conn->packets_to_send = 0;
|
|
|
|
rfree(conn->connect_retry_timer);
|
|
|
|
conn->connect_retry_timer = NULL;
|
|
|
|
rfree(conn->keepalive_timer);
|
|
|
|
conn->keepalive_timer = NULL;
|
|
|
|
rfree(conn->hold_timer);
|
|
|
|
conn->hold_timer = NULL;
|
2004-06-01 05:48:19 +08:00
|
|
|
rfree(conn->sk);
|
2000-03-31 01:39:48 +08:00
|
|
|
conn->sk = NULL;
|
2008-12-19 08:34:39 +08:00
|
|
|
rfree(conn->tx_ev);
|
|
|
|
conn->tx_ev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bgp_update_startup_delay - update a startup delay
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* It should be called when BGP protocol error happened.
|
|
|
|
*/
|
|
|
|
void
|
2009-06-07 06:38:38 +08:00
|
|
|
bgp_update_startup_delay(struct bgp_proto *p)
|
2008-12-19 08:34:39 +08:00
|
|
|
{
|
|
|
|
struct bgp_config *cf = p->cf;
|
|
|
|
|
2009-06-07 06:38:38 +08:00
|
|
|
DBG("BGP: Updating startup delay\n");
|
2008-12-19 08:34:39 +08:00
|
|
|
|
2010-02-21 21:34:53 +08:00
|
|
|
if (p->last_proto_error && ((now - p->last_proto_error) >= (int) cf->error_amnesia_time))
|
2009-06-07 00:56:33 +08:00
|
|
|
p->startup_delay = 0;
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
p->last_proto_error = now;
|
|
|
|
|
|
|
|
if (cf->disable_after_error)
|
|
|
|
{
|
|
|
|
p->startup_delay = 0;
|
|
|
|
p->p.disabled = 1;
|
|
|
|
return;
|
2000-04-26 07:08:31 +08:00
|
|
|
}
|
2008-12-19 08:34:39 +08:00
|
|
|
|
|
|
|
if (!p->startup_delay)
|
|
|
|
p->startup_delay = cf->error_delay_time_min;
|
|
|
|
else
|
2009-06-07 06:38:38 +08:00
|
|
|
p->startup_delay = MIN(2 * p->startup_delay, cf->error_delay_time_max);
|
2000-03-21 05:50:17 +08:00
|
|
|
}
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
static void
|
2009-06-07 06:38:38 +08:00
|
|
|
bgp_graceful_close_conn(struct bgp_conn *conn, unsigned subcode)
|
2000-04-10 19:21:40 +08:00
|
|
|
{
|
2008-12-19 08:34:39 +08:00
|
|
|
switch (conn->state)
|
2000-04-10 19:21:40 +08:00
|
|
|
{
|
|
|
|
case BS_IDLE:
|
2008-12-19 08:34:39 +08:00
|
|
|
case BS_CLOSE:
|
|
|
|
return;
|
2000-04-10 19:21:40 +08:00
|
|
|
case BS_CONNECT:
|
|
|
|
case BS_ACTIVE:
|
2008-12-19 08:34:39 +08:00
|
|
|
bgp_conn_enter_idle_state(conn);
|
|
|
|
return;
|
2000-04-10 19:21:40 +08:00
|
|
|
case BS_OPENSENT:
|
|
|
|
case BS_OPENCONFIRM:
|
|
|
|
case BS_ESTABLISHED:
|
2009-06-07 06:38:38 +08:00
|
|
|
bgp_error(conn, 6, subcode, NULL, 0);
|
2008-12-19 08:34:39 +08:00
|
|
|
return;
|
2000-04-10 19:21:40 +08:00
|
|
|
default:
|
2008-12-19 08:34:39 +08:00
|
|
|
bug("bgp_graceful_close_conn: Unknown state %d", conn->state);
|
2000-04-10 19:21:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
static void
|
|
|
|
bgp_down(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
if (p->start_state > BSS_PREPARE)
|
|
|
|
bgp_close(p, 1);
|
|
|
|
|
2009-06-07 06:38:38 +08:00
|
|
|
BGP_TRACE(D_EVENTS, "Down");
|
2008-12-19 08:34:39 +08:00
|
|
|
proto_notify_state(&p->p, PS_DOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_decision(void *vp)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = vp;
|
|
|
|
|
|
|
|
DBG("BGP: Decision start\n");
|
|
|
|
if ((p->p.proto_state == PS_START)
|
2009-09-25 04:12:11 +08:00
|
|
|
&& (p->outgoing_conn.state == BS_IDLE)
|
2014-03-20 21:07:12 +08:00
|
|
|
&& (p->incoming_conn.state != BS_OPENCONFIRM)
|
2009-09-25 04:12:11 +08:00
|
|
|
&& (!p->cf->passive))
|
2009-06-07 00:16:22 +08:00
|
|
|
bgp_active(p);
|
2008-12-19 08:34:39 +08:00
|
|
|
|
|
|
|
if ((p->p.proto_state == PS_STOP)
|
|
|
|
&& (p->outgoing_conn.state == BS_IDLE)
|
|
|
|
&& (p->incoming_conn.state == BS_IDLE))
|
|
|
|
bgp_down(p);
|
|
|
|
}
|
|
|
|
|
2009-06-07 06:38:38 +08:00
|
|
|
void
|
|
|
|
bgp_stop(struct bgp_proto *p, unsigned subcode)
|
2008-12-19 08:34:39 +08:00
|
|
|
{
|
|
|
|
proto_notify_state(&p->p, PS_STOP);
|
2009-06-07 06:38:38 +08:00
|
|
|
bgp_graceful_close_conn(&p->outgoing_conn, subcode);
|
|
|
|
bgp_graceful_close_conn(&p->incoming_conn, subcode);
|
2008-12-19 08:34:39 +08:00
|
|
|
ev_schedule(p->event);
|
|
|
|
}
|
|
|
|
|
2010-01-03 19:17:52 +08:00
|
|
|
static inline void
|
|
|
|
bgp_conn_set_state(struct bgp_conn *conn, unsigned new_state)
|
|
|
|
{
|
|
|
|
if (conn->bgp->p.mrtdump & MD_STATES)
|
|
|
|
mrt_dump_bgp_state_change(conn, conn->state, new_state);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
void
|
|
|
|
bgp_conn_enter_established_state(struct bgp_conn *conn)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = conn->bgp;
|
2015-02-21 18:46:14 +08:00
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
BGP_TRACE(D_EVENTS, "BGP session established");
|
|
|
|
DBG("BGP: UP!!!\n");
|
|
|
|
|
2010-07-12 23:39:39 +08:00
|
|
|
/* For multi-hop BGP sessions */
|
|
|
|
if (ipa_zero(p->source_addr))
|
2014-03-20 21:07:12 +08:00
|
|
|
p->source_addr = conn->sk->saddr;
|
2010-07-12 23:39:39 +08:00
|
|
|
|
2016-04-06 17:49:34 +08:00
|
|
|
conn->sk->fast_rx = 0;
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
p->conn = conn;
|
|
|
|
p->last_error_class = 0;
|
|
|
|
p->last_error_code = 0;
|
2015-03-30 00:27:13 +08:00
|
|
|
p->feed_state = BFS_NONE;
|
|
|
|
p->load_state = BFS_NONE;
|
2012-08-14 22:25:22 +08:00
|
|
|
bgp_init_bucket_table(p);
|
|
|
|
bgp_init_prefix_table(p, 8);
|
|
|
|
|
2014-03-20 21:07:12 +08:00
|
|
|
int peer_gr_ready = conn->peer_gr_aware && !(conn->peer_gr_flags & BGP_GRF_RESTART);
|
|
|
|
|
|
|
|
if (p->p.gr_recovery && !peer_gr_ready)
|
|
|
|
proto_graceful_restart_unlock(&p->p);
|
|
|
|
|
|
|
|
if (p->p.gr_recovery && (p->cf->gr_mode == BGP_GR_ABLE) && peer_gr_ready)
|
|
|
|
p->p.gr_wait = 1;
|
|
|
|
|
|
|
|
if (p->gr_active)
|
|
|
|
tm_stop(p->gr_timer);
|
|
|
|
|
|
|
|
if (p->gr_active && (!conn->peer_gr_able || !(conn->peer_gr_aflags & BGP_GRF_FORWARDING)))
|
|
|
|
bgp_graceful_restart_done(p);
|
|
|
|
|
2015-03-30 00:27:13 +08:00
|
|
|
/* GR capability implies that neighbor will send End-of-RIB */
|
|
|
|
if (conn->peer_gr_aware)
|
|
|
|
p->load_state = BFS_LOADING;
|
|
|
|
|
|
|
|
/* proto_notify_state() will likely call bgp_feed_begin(), setting p->feed_state */
|
|
|
|
|
2010-01-03 19:17:52 +08:00
|
|
|
bgp_conn_set_state(conn, BS_ESTABLISHED);
|
2008-12-19 08:34:39 +08: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");
|
|
|
|
p->conn = NULL;
|
|
|
|
|
|
|
|
if (p->p.proto_state == PS_UP)
|
2009-06-07 06:38:38 +08:00
|
|
|
bgp_stop(p, 0);
|
2008-12-19 08:34:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bgp_conn_enter_close_state(struct bgp_conn *conn)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = conn->bgp;
|
|
|
|
int os = conn->state;
|
|
|
|
|
2010-01-03 19:17:52 +08:00
|
|
|
bgp_conn_set_state(conn, BS_CLOSE);
|
2008-12-19 08:34:39 +08:00
|
|
|
tm_stop(conn->keepalive_timer);
|
|
|
|
conn->sk->rx_hook = NULL;
|
|
|
|
|
2013-07-13 07:39:41 +08: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 08:34:39 +08: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 19:17:52 +08:00
|
|
|
bgp_conn_set_state(conn, BS_IDLE);
|
2008-12-19 08:34:39 +08:00
|
|
|
ev_schedule(p->event);
|
|
|
|
|
|
|
|
if (os == BS_ESTABLISHED)
|
|
|
|
bgp_conn_leave_established_state(p);
|
|
|
|
}
|
|
|
|
|
2014-03-23 08:35:33 +08: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 21:07:12 +08: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",
|
|
|
|
p->gr_active ? " - already pending" : "");
|
|
|
|
proto_notify_state(&p->p, PS_START);
|
|
|
|
|
|
|
|
if (p->gr_active)
|
|
|
|
rt_refresh_end(p->p.main_ahook->table, p->p.main_ahook);
|
|
|
|
|
|
|
|
p->gr_active = 1;
|
|
|
|
bgp_start_timer(p->gr_timer, p->conn->peer_gr_time);
|
|
|
|
rt_refresh_begin(p->p.main_ahook->table, p->p.main_ahook);
|
|
|
|
}
|
|
|
|
|
2014-03-23 08:35:33 +08:00
|
|
|
/**
|
|
|
|
* bgp_graceful_restart_done - finish active BGP graceful restart
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
|
|
|
* This function is called when the active BGP graceful restart of the neighbor
|
|
|
|
* should be finished - either successfully (the neighbor sends all paths and
|
|
|
|
* reports end-of-RIB on the new session) or unsuccessfully (the neighbor does
|
|
|
|
* not support BGP graceful restart on the new session). The function ends
|
|
|
|
* routing table refresh cycle and stops BGP restart timer.
|
|
|
|
*/
|
2014-03-20 21:07:12 +08:00
|
|
|
void
|
|
|
|
bgp_graceful_restart_done(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor graceful restart done");
|
|
|
|
p->gr_active = 0;
|
|
|
|
tm_stop(p->gr_timer);
|
|
|
|
rt_refresh_end(p->p.main_ahook->table, p->p.main_ahook);
|
|
|
|
}
|
|
|
|
|
2014-03-23 08:35:33 +08: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 21:07:12 +08:00
|
|
|
static void
|
|
|
|
bgp_graceful_restart_timeout(timer *t)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = t->data;
|
|
|
|
|
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor graceful restart timeout");
|
|
|
|
bgp_stop(p, 0);
|
|
|
|
}
|
|
|
|
|
2015-03-30 00:27:13 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* bgp_refresh_begin - start incoming enhanced route refresh sequence
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
bgp_refresh_begin(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
if (p->load_state == BFS_LOADING)
|
|
|
|
{ log(L_WARN "%s: BEGIN-OF-RR received before END-OF-RIB, ignoring", p->p.name); return; }
|
|
|
|
|
|
|
|
p->load_state = BFS_REFRESHING;
|
|
|
|
rt_refresh_begin(p->p.main_ahook->table, p->p.main_ahook);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bgp_refresh_end - finish incoming enhanced route refresh sequence
|
|
|
|
* @p: BGP instance
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
bgp_refresh_end(struct bgp_proto *p)
|
|
|
|
{
|
|
|
|
if (p->load_state != BFS_REFRESHING)
|
|
|
|
{ log(L_WARN "%s: END-OF-RR received without prior BEGIN-OF-RR, ignoring", p->p.name); return; }
|
|
|
|
|
|
|
|
p->load_state = BFS_NONE;
|
|
|
|
rt_refresh_end(p->p.main_ahook->table, p->p.main_ahook);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-21 05:50:17 +08:00
|
|
|
static void
|
|
|
|
bgp_send_open(struct bgp_conn *conn)
|
|
|
|
{
|
2008-12-25 00:24:41 +08:00
|
|
|
conn->start_state = conn->bgp->start_state;
|
2012-08-14 22:25:22 +08:00
|
|
|
|
|
|
|
// Default values, possibly changed by receiving capabilities.
|
2014-03-20 21:07:12 +08:00
|
|
|
conn->advertised_as = 0;
|
2012-08-14 22:25:22 +08:00
|
|
|
conn->peer_refresh_support = 0;
|
|
|
|
conn->peer_as4_support = 0;
|
|
|
|
conn->peer_add_path = 0;
|
2015-03-30 00:27:13 +08:00
|
|
|
conn->peer_enhanced_refresh_support = 0;
|
2014-03-20 21:07:12 +08:00
|
|
|
conn->peer_gr_aware = 0;
|
|
|
|
conn->peer_gr_able = 0;
|
|
|
|
conn->peer_gr_time = 0;
|
|
|
|
conn->peer_gr_flags = 0;
|
|
|
|
conn->peer_gr_aflags = 0;
|
2015-07-18 19:38:21 +08:00
|
|
|
conn->peer_ext_messages_support = 0;
|
2008-12-25 00:24:41 +08:00
|
|
|
|
2000-03-21 05:50:17 +08:00
|
|
|
DBG("BGP: Sending open\n");
|
|
|
|
conn->sk->rx_hook = bgp_rx;
|
2000-03-31 01:39:48 +08:00
|
|
|
conn->sk->tx_hook = bgp_tx;
|
2000-03-21 05:50:17 +08:00
|
|
|
tm_stop(conn->connect_retry_timer);
|
2000-03-21 23:53:50 +08:00
|
|
|
bgp_schedule_packet(conn, PKT_OPEN);
|
2010-01-03 19:17:52 +08:00
|
|
|
bgp_conn_set_state(conn, BS_OPENSENT);
|
2000-03-30 18:44:20 +08:00
|
|
|
bgp_start_timer(conn->hold_timer, conn->bgp->cf->initial_hold_time);
|
2000-03-21 05:50:17 +08:00
|
|
|
}
|
|
|
|
|
2000-03-30 18:44:20 +08:00
|
|
|
static void
|
|
|
|
bgp_connected(sock *sk)
|
2000-03-21 05:50:17 +08:00
|
|
|
{
|
|
|
|
struct bgp_conn *conn = sk->data;
|
2000-05-03 00:07:41 +08:00
|
|
|
struct bgp_proto *p = conn->bgp;
|
2000-03-21 05:50:17 +08:00
|
|
|
|
2000-05-03 00:07:41 +08:00
|
|
|
BGP_TRACE(D_EVENTS, "Connected");
|
2000-03-21 05:50:17 +08:00
|
|
|
bgp_send_open(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_connect_timeout(timer *t)
|
|
|
|
{
|
2000-03-30 18:44:20 +08:00
|
|
|
struct bgp_conn *conn = t->data;
|
2000-05-03 00:07:41 +08:00
|
|
|
struct bgp_proto *p = conn->bgp;
|
2000-03-21 05:50:17 +08:00
|
|
|
|
2000-05-03 00:07:41 +08:00
|
|
|
DBG("BGP: connect_timeout\n");
|
2008-12-19 08:34:39 +08:00
|
|
|
if (p->p.proto_state == PS_START)
|
|
|
|
{
|
|
|
|
bgp_close_conn(conn);
|
|
|
|
bgp_connect(p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bgp_conn_enter_idle_state(conn);
|
2000-03-21 05:50:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-03-30 18:44:20 +08:00
|
|
|
bgp_sock_err(sock *sk, int err)
|
2000-03-21 05:50:17 +08:00
|
|
|
{
|
|
|
|
struct bgp_conn *conn = sk->data;
|
2000-05-03 00:07:41 +08:00
|
|
|
struct bgp_proto *p = conn->bgp;
|
2000-03-21 05:50:17 +08:00
|
|
|
|
2010-05-14 22:54:39 +08: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 08:34:39 +08:00
|
|
|
bgp_store_error(p, conn, BE_SOCKET, err);
|
|
|
|
|
2000-05-03 00:10:04 +08:00
|
|
|
if (err)
|
|
|
|
BGP_TRACE(D_EVENTS, "Connection lost (%M)", err);
|
|
|
|
else
|
|
|
|
BGP_TRACE(D_EVENTS, "Connection closed");
|
2008-12-19 08:34:39 +08:00
|
|
|
|
2014-03-20 21:07:12 +08:00
|
|
|
if ((conn->state == BS_ESTABLISHED) && p->gr_ready)
|
|
|
|
bgp_handle_graceful_restart(p);
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
bgp_conn_enter_idle_state(conn);
|
2000-03-21 05:50:17 +08:00
|
|
|
}
|
|
|
|
|
2000-03-30 18:44:20 +08:00
|
|
|
static void
|
|
|
|
bgp_hold_timeout(timer *t)
|
|
|
|
{
|
|
|
|
struct bgp_conn *conn = t->data;
|
2013-07-13 07:39:41 +08:00
|
|
|
struct bgp_proto *p = conn->bgp;
|
2000-03-30 18:44:20 +08:00
|
|
|
|
2009-10-12 00:56:16 +08:00
|
|
|
DBG("BGP: Hold timeout\n");
|
|
|
|
|
2013-07-13 07:39:41 +08: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-12 00:56:16 +08: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);
|
|
|
|
else
|
|
|
|
bgp_error(conn, 4, 0, NULL, 0);
|
2000-03-30 18:44:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_keepalive_timeout(timer *t)
|
|
|
|
{
|
|
|
|
struct bgp_conn *conn = t->data;
|
|
|
|
|
|
|
|
DBG("BGP: Keepalive timer\n");
|
|
|
|
bgp_schedule_packet(conn, PKT_KEEPALIVE);
|
2016-04-06 17:57:28 +08:00
|
|
|
|
|
|
|
/* Kick TX a bit faster */
|
|
|
|
if (ev_active(conn->tx_ev))
|
|
|
|
ev_run(conn->tx_ev);
|
2000-03-30 18:44:20 +08:00
|
|
|
}
|
|
|
|
|
2000-03-21 05:50:17 +08:00
|
|
|
static void
|
2000-04-26 07:08:31 +08:00
|
|
|
bgp_setup_conn(struct bgp_proto *p, struct bgp_conn *conn)
|
2000-03-21 05:50:17 +08:00
|
|
|
{
|
|
|
|
timer *t;
|
|
|
|
|
2000-04-26 07:08:31 +08:00
|
|
|
conn->sk = NULL;
|
2000-03-21 05:50:17 +08:00
|
|
|
conn->bgp = p;
|
2000-03-21 23:53:50 +08:00
|
|
|
conn->packets_to_send = 0;
|
2000-03-21 05:50:17 +08:00
|
|
|
|
|
|
|
t = conn->connect_retry_timer = tm_new(p->p.pool);
|
|
|
|
t->hook = bgp_connect_timeout;
|
2000-03-30 18:44:20 +08:00
|
|
|
t->data = conn;
|
|
|
|
t = conn->hold_timer = tm_new(p->p.pool);
|
2000-03-21 05:50:17 +08:00
|
|
|
t->hook = bgp_hold_timeout;
|
2000-03-30 18:44:20 +08:00
|
|
|
t->data = conn;
|
|
|
|
t = conn->keepalive_timer = tm_new(p->p.pool);
|
2000-03-21 05:50:17 +08:00
|
|
|
t->hook = bgp_keepalive_timeout;
|
2000-03-30 18:44:20 +08:00
|
|
|
t->data = conn;
|
2008-12-19 08:34:39 +08:00
|
|
|
conn->tx_ev = ev_new(p->p.pool);
|
|
|
|
conn->tx_ev->hook = bgp_kick_tx;
|
|
|
|
conn->tx_ev->data = conn;
|
2000-03-21 05:50:17 +08:00
|
|
|
}
|
|
|
|
|
2000-04-26 07:08:31 +08:00
|
|
|
static void
|
2010-02-21 21:34:53 +08:00
|
|
|
bgp_setup_sk(struct bgp_conn *conn, sock *s)
|
2000-04-26 07:08:31 +08:00
|
|
|
{
|
|
|
|
s->data = conn;
|
|
|
|
s->err_hook = bgp_sock_err;
|
2016-04-06 17:49:34 +08:00
|
|
|
s->fast_rx = 1;
|
2000-04-26 07:08:31 +08:00
|
|
|
conn->sk = s;
|
|
|
|
}
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
static void
|
2009-06-07 00:16:22 +08:00
|
|
|
bgp_active(struct bgp_proto *p)
|
2008-12-19 08:34:39 +08:00
|
|
|
{
|
2015-02-22 23:08:28 +08:00
|
|
|
int delay = MAX(1, p->cf->connect_delay_time);
|
2008-12-19 08:34:39 +08: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 19:17:52 +08:00
|
|
|
bgp_conn_set_state(conn, BS_ACTIVE);
|
2008-12-19 08:34:39 +08:00
|
|
|
bgp_start_timer(conn->connect_retry_timer, delay);
|
|
|
|
}
|
|
|
|
|
2000-06-05 01:06:18 +08: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-21 05:50:17 +08:00
|
|
|
static void
|
|
|
|
bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing connection */
|
|
|
|
{
|
|
|
|
sock *s;
|
2000-03-31 01:39:48 +08:00
|
|
|
struct bgp_conn *conn = &p->outgoing_conn;
|
2011-08-17 05:05:35 +08:00
|
|
|
int hops = p->cf->multihop ? : 1;
|
2000-03-21 05:50:17 +08:00
|
|
|
|
|
|
|
DBG("BGP: Connecting\n");
|
|
|
|
s = sk_new(p->p.pool);
|
|
|
|
s->type = SK_TCP_ACTIVE;
|
2009-04-29 00:11:56 +08:00
|
|
|
s->saddr = p->source_addr;
|
2000-03-21 05:50:17 +08:00
|
|
|
s->daddr = p->cf->remote_ip;
|
2014-10-02 17:33:55 +08:00
|
|
|
s->dport = p->cf->remote_port;
|
2012-01-08 22:28:27 +08:00
|
|
|
s->iface = p->neigh ? p->neigh->iface : NULL;
|
2011-08-17 05:05:35 +08:00
|
|
|
s->ttl = p->cf->ttl_security ? 255 : hops;
|
2015-07-18 19:38:21 +08: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 23:58:40 +08:00
|
|
|
s->tos = IP_PREC_INTERNET_CONTROL;
|
|
|
|
s->password = p->cf->password;
|
|
|
|
s->tx_hook = bgp_connected;
|
2012-01-08 22:28:27 +08:00
|
|
|
BGP_TRACE(D_EVENTS, "Connecting to %I%J from local address %I%J", s->daddr, p->cf->iface,
|
2014-10-24 17:11:43 +08:00
|
|
|
s->saddr, ipa_is_link_local(s->saddr) ? s->iface : NULL);
|
2000-04-26 07:08:31 +08:00
|
|
|
bgp_setup_conn(p, conn);
|
2010-02-21 21:34:53 +08:00
|
|
|
bgp_setup_sk(conn, s);
|
2010-01-03 19:17:52 +08:00
|
|
|
bgp_conn_set_state(conn, BS_CONNECT);
|
2011-08-17 05:05:35 +08:00
|
|
|
|
|
|
|
if (sk_open(s) < 0)
|
2014-05-18 17:42:26 +08:00
|
|
|
goto err;
|
2011-08-17 05:05:35 +08:00
|
|
|
|
|
|
|
/* Set minimal receive TTL if needed */
|
|
|
|
if (p->cf->ttl_security)
|
|
|
|
if (sk_set_min_ttl(s, 256 - hops) < 0)
|
2014-05-18 17:42:26 +08:00
|
|
|
goto err;
|
2011-08-17 05:05:35 +08:00
|
|
|
|
2000-03-21 05:50:17 +08:00
|
|
|
DBG("BGP: Waiting for connect success\n");
|
|
|
|
bgp_start_timer(conn->connect_retry_timer, p->cf->connect_retry_time);
|
2014-05-18 17:42:26 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
sk_log_error(s, p->p.name);
|
|
|
|
bgp_sock_err(s, 0);
|
|
|
|
return;
|
2000-03-21 05:50:17 +08:00
|
|
|
}
|
|
|
|
|
2015-02-22 03:39:59 +08:00
|
|
|
/**
|
|
|
|
* bgp_find_proto - find existing proto for incoming connection
|
|
|
|
* @sk: TCP socket
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static struct bgp_proto *
|
|
|
|
bgp_find_proto(sock *sk)
|
|
|
|
{
|
|
|
|
struct proto_config *pc;
|
|
|
|
|
|
|
|
WALK_LIST(pc, config->protos)
|
|
|
|
if ((pc->protocol == &proto_bgp) && pc->proto)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) pc->proto;
|
|
|
|
if (ipa_equal(p->cf->remote_ip, sk->daddr) &&
|
|
|
|
(!ipa_is_link_local(sk->daddr) || (p->cf->iface == sk->iface)))
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-06-05 01:06:18 +08: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 19:21:40 +08:00
|
|
|
static int
|
2004-06-05 17:27:17 +08:00
|
|
|
bgp_incoming_connection(sock *sk, int dummy UNUSED)
|
2000-03-21 05:50:17 +08:00
|
|
|
{
|
2015-02-22 03:39:59 +08:00
|
|
|
struct bgp_proto *p;
|
|
|
|
int acc, hops;
|
2000-03-21 05:50:17 +08:00
|
|
|
|
2000-04-10 19:21:40 +08:00
|
|
|
DBG("BGP: Incoming connection from %I port %d\n", sk->daddr, sk->dport);
|
2015-02-22 03:39:59 +08:00
|
|
|
p = bgp_find_proto(sk);
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-11 23:38:28 +08: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-22 03:39:59 +08: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-07 00:16:22 +08:00
|
|
|
|
2015-02-22 03:39:59 +08:00
|
|
|
if (p->conn && (p->conn->state == BS_ESTABLISHED) && p->gr_ready)
|
|
|
|
{
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_GRACEFUL_RESTART);
|
|
|
|
bgp_handle_graceful_restart(p);
|
|
|
|
bgp_conn_enter_idle_state(p->conn);
|
|
|
|
acc = 1;
|
2016-02-11 23:38:28 +08:00
|
|
|
|
|
|
|
/* There might be separate incoming connection in OpenSent state */
|
|
|
|
if (p->incoming_conn.state > BS_ACTIVE)
|
|
|
|
bgp_close_conn(&p->incoming_conn);
|
2015-02-22 03:39:59 +08: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)
|
|
|
|
{
|
|
|
|
rfree(sk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 19:38:21 +08:00
|
|
|
if (p->cf->enable_extended_messages)
|
|
|
|
{
|
|
|
|
sk->rbsize = BGP_RX_BUFFER_EXT_SIZE;
|
|
|
|
sk->tbsize = BGP_TX_BUFFER_EXT_SIZE;
|
|
|
|
sk_reallocate(sk);
|
|
|
|
}
|
|
|
|
|
2015-02-22 03:39:59 +08: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 19:21:40 +08:00
|
|
|
rfree(sk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-11 18:12:58 +08:00
|
|
|
static void
|
2010-02-21 21:34:53 +08:00
|
|
|
bgp_listen_sock_err(sock *sk UNUSED, int err)
|
2010-02-11 18:12:58 +08:00
|
|
|
{
|
|
|
|
if (err == ECONNABORTED)
|
|
|
|
log(L_WARN "BGP: Incoming connection aborted");
|
|
|
|
else
|
2010-05-31 17:35:29 +08:00
|
|
|
log(L_ERR "BGP: Error on listening socket: %M", err);
|
2010-02-11 18:12:58 +08:00
|
|
|
}
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
static sock *
|
2009-06-19 01:20:07 +08:00
|
|
|
bgp_setup_listen_sk(ip_addr addr, unsigned port, u32 flags)
|
2000-04-10 19:21:40 +08:00
|
|
|
{
|
2008-12-19 08:34:39 +08:00
|
|
|
sock *s = sk_new(&root_pool);
|
2010-05-31 17:35:29 +08:00
|
|
|
DBG("BGP: Creating listening socket\n");
|
2008-12-19 08:34:39 +08:00
|
|
|
s->type = SK_TCP_PASSIVE;
|
2011-08-17 05:05:35 +08:00
|
|
|
s->ttl = 255;
|
2009-06-19 01:20:07 +08:00
|
|
|
s->saddr = addr;
|
|
|
|
s->sport = port ? port : BGP_PORT;
|
2010-11-03 17:02:24 +08:00
|
|
|
s->flags = flags ? 0 : SKF_V6ONLY;
|
2008-12-19 08:34:39 +08:00
|
|
|
s->tos = IP_PREC_INTERNET_CONTROL;
|
|
|
|
s->rbsize = BGP_RX_BUFFER_SIZE;
|
|
|
|
s->tbsize = BGP_TX_BUFFER_SIZE;
|
|
|
|
s->rx_hook = bgp_incoming_connection;
|
2010-02-11 18:12:58 +08:00
|
|
|
s->err_hook = bgp_listen_sock_err;
|
2011-08-17 05:05:35 +08:00
|
|
|
|
|
|
|
if (sk_open(s) < 0)
|
2014-05-18 17:42:26 +08:00
|
|
|
goto err;
|
2011-08-17 05:05:35 +08:00
|
|
|
|
|
|
|
return s;
|
2014-05-18 17:42:26 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
sk_log_error(s, "BGP");
|
|
|
|
log(L_ERR "BGP: Cannot open listening socket");
|
|
|
|
rfree(s);
|
|
|
|
return NULL;
|
2000-05-07 18:41:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_start_neighbor(struct bgp_proto *p)
|
|
|
|
{
|
2010-07-12 23:39:39 +08:00
|
|
|
/* Called only for single-hop BGP sessions */
|
|
|
|
|
|
|
|
if (ipa_zero(p->source_addr))
|
2015-02-21 18:46:14 +08:00
|
|
|
p->source_addr = p->neigh->ifa->ip;
|
2009-04-29 00:11:56 +08:00
|
|
|
|
2003-02-23 06:47:45 +08:00
|
|
|
#ifdef IPV6
|
|
|
|
{
|
|
|
|
struct ifa *a;
|
2009-04-30 00:58:24 +08:00
|
|
|
p->local_link = IPA_NONE;
|
2003-02-23 06:47:45 +08:00
|
|
|
WALK_LIST(a, p->neigh->iface->addrs)
|
|
|
|
if (a->scope == SCOPE_LINK)
|
|
|
|
{
|
|
|
|
p->local_link = a->ip;
|
|
|
|
break;
|
|
|
|
}
|
2009-04-30 00:58:24 +08:00
|
|
|
|
|
|
|
if (! ipa_nonzero(p->local_link))
|
|
|
|
log(L_WARN "%s: Missing link local address on interface %s", p->p.name, p->neigh->iface->name);
|
|
|
|
|
2003-02-23 06:47:45 +08:00
|
|
|
DBG("BGP: Selected link-level address %I\n", p->local_link);
|
|
|
|
}
|
|
|
|
#endif
|
2008-12-19 08:34:39 +08:00
|
|
|
|
2000-04-26 07:08:31 +08:00
|
|
|
bgp_initiate(p);
|
2000-04-10 19:21:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_neigh_notify(neighbor *n)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) n->proto;
|
2015-02-21 18:46:14 +08:00
|
|
|
int ps = p->p.proto_state;
|
|
|
|
|
|
|
|
if (n != p->neigh)
|
|
|
|
return;
|
2000-04-10 19:21:40 +08:00
|
|
|
|
2015-02-21 18:46:14 +08:00
|
|
|
if ((ps == PS_DOWN) || (ps == PS_STOP))
|
2013-08-14 02:42:43 +08:00
|
|
|
return;
|
|
|
|
|
2015-02-21 18:46:14 +08:00
|
|
|
int prepare = (ps == PS_START) && (p->start_state == BSS_PREPARE);
|
|
|
|
|
|
|
|
if (n->scope <= 0)
|
2000-04-10 19:21:40 +08:00
|
|
|
{
|
2015-02-21 18:46:14 +08:00
|
|
|
if (!prepare)
|
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor lost");
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_NEIGHBOR_LOST);
|
|
|
|
/* Perhaps also run bgp_update_startup_delay(p)? */
|
|
|
|
bgp_stop(p, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (p->cf->check_link && !(n->iface->flags & IF_LINK_UP))
|
|
|
|
{
|
|
|
|
if (!prepare)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
bgp_stop(p, 0);
|
2008-12-19 08:34:39 +08:00
|
|
|
}
|
2000-04-10 19:21:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-21 18:46:14 +08:00
|
|
|
if (prepare)
|
2008-12-19 08:34:39 +08:00
|
|
|
{
|
2015-02-21 18:46:14 +08:00
|
|
|
BGP_TRACE(D_EVENTS, "Neighbor ready");
|
|
|
|
bgp_start_neighbor(p);
|
2008-12-19 08:34:39 +08:00
|
|
|
}
|
2000-04-10 19:21:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 05:33:48 +08: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)))
|
|
|
|
{
|
|
|
|
BGP_TRACE(D_EVENTS, "BFD session down");
|
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_BFD_DOWN);
|
|
|
|
if (ps == PS_UP)
|
|
|
|
bgp_update_startup_delay(p);
|
|
|
|
bgp_stop(p, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_update_bfd(struct bgp_proto *p, int use_bfd)
|
|
|
|
{
|
|
|
|
if (use_bfd && !p->bfd_req)
|
|
|
|
p->bfd_req = bfd_request_session(p->p.pool, p->cf->remote_ip, p->source_addr,
|
|
|
|
p->cf->multihop ? NULL : p->neigh->iface,
|
|
|
|
bgp_bfd_notify, p);
|
|
|
|
|
|
|
|
if (!use_bfd && p->bfd_req)
|
|
|
|
{
|
|
|
|
rfree(p->bfd_req);
|
|
|
|
p->bfd_req = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-27 03:47:59 +08:00
|
|
|
static int
|
|
|
|
bgp_reload_routes(struct proto *P)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
if (!p->conn || !p->conn->peer_refresh_support)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bgp_schedule_packet(p->conn, PKT_ROUTE_REFRESH);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-20 21:07:12 +08:00
|
|
|
static void
|
2015-03-30 00:27:13 +08:00
|
|
|
bgp_feed_begin(struct proto *P, int initial)
|
2014-03-20 21:07:12 +08:00
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
2015-03-30 00:27:13 +08:00
|
|
|
|
|
|
|
/* This should not happen */
|
|
|
|
if (!p->conn)
|
2014-03-20 21:07:12 +08:00
|
|
|
return;
|
|
|
|
|
2015-03-30 00:27:13 +08:00
|
|
|
if (initial && p->cf->gr_mode)
|
|
|
|
p->feed_state = BFS_LOADING;
|
|
|
|
|
|
|
|
/* It is refeed and both sides support enhanced route refresh */
|
|
|
|
if (!initial && p->cf->enable_refresh &&
|
|
|
|
p->conn->peer_enhanced_refresh_support)
|
|
|
|
{
|
|
|
|
/* BoRR must not be sent before End-of-RIB */
|
|
|
|
if (p->feed_state == BFS_LOADING || p->feed_state == BFS_LOADED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->feed_state = BFS_REFRESHING;
|
|
|
|
bgp_schedule_packet(p->conn, PKT_BEGIN_REFRESH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_feed_end(struct proto *P)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
|
|
|
|
/* This should not happen */
|
|
|
|
if (!p->conn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Non-demarcated feed ended, nothing to do */
|
|
|
|
if (p->feed_state == BFS_NONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Schedule End-of-RIB packet */
|
|
|
|
if (p->feed_state == BFS_LOADING)
|
|
|
|
p->feed_state = BFS_LOADED;
|
|
|
|
|
|
|
|
/* Schedule EoRR packet */
|
|
|
|
if (p->feed_state == BFS_REFRESHING)
|
|
|
|
p->feed_state = BFS_REFRESHED;
|
|
|
|
|
|
|
|
/* Kick TX hook */
|
2014-03-20 21:07:12 +08:00
|
|
|
bgp_schedule_packet(p->conn, PKT_UPDATE);
|
|
|
|
}
|
|
|
|
|
2015-03-30 00:27:13 +08:00
|
|
|
|
2000-04-10 19:21:40 +08:00
|
|
|
static void
|
|
|
|
bgp_start_locked(struct object_lock *lock)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = lock->data;
|
|
|
|
struct bgp_config *cf = p->cf;
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
if (p->p.proto_state != PS_START)
|
|
|
|
{
|
|
|
|
DBG("BGP: Got lock in different state %d\n", p->p.proto_state);
|
2010-07-12 23:39:39 +08:00
|
|
|
return;
|
2008-12-19 08:34:39 +08:00
|
|
|
}
|
|
|
|
|
2000-04-10 19:21:40 +08:00
|
|
|
DBG("BGP: Got lock\n");
|
2008-10-27 05:45:09 +08:00
|
|
|
|
2010-07-12 23:39:39 +08:00
|
|
|
if (cf->multihop)
|
2008-10-27 05:45:09 +08:00
|
|
|
{
|
2010-07-12 23:39:39 +08:00
|
|
|
/* Multi-hop sessions do not use neighbor entries */
|
|
|
|
bgp_initiate(p);
|
|
|
|
return;
|
2008-10-27 05:45:09 +08:00
|
|
|
}
|
|
|
|
|
2015-02-21 18:46:14 +08:00
|
|
|
neighbor *n = neigh_find2(&p->p, &cf->remote_ip, cf->iface, NEF_STICKY);
|
|
|
|
if (!n)
|
2000-04-10 19:21:40 +08:00
|
|
|
{
|
2012-01-08 22:28:27 +08:00
|
|
|
log(L_ERR "%s: Invalid remote address %I%J", p->p.name, cf->remote_ip, cf->iface);
|
2008-12-19 08:34:39 +08:00
|
|
|
/* As we do not start yet, we can just disable protocol */
|
2000-04-10 19:21:40 +08:00
|
|
|
p->p.disabled = 1;
|
2008-12-19 08:34:39 +08:00
|
|
|
bgp_store_error(p, NULL, BE_MISC, BEM_INVALID_NEXT_HOP);
|
2000-04-10 19:21:40 +08:00
|
|
|
proto_notify_state(&p->p, PS_DOWN);
|
2008-12-19 08:34:39 +08:00
|
|
|
return;
|
2000-04-10 19:21:40 +08:00
|
|
|
}
|
2015-02-21 18:46:14 +08:00
|
|
|
|
|
|
|
p->neigh = n;
|
|
|
|
|
|
|
|
if (n->scope <= 0)
|
2012-01-08 22:28:27 +08:00
|
|
|
BGP_TRACE(D_EVENTS, "Waiting for %I%J to become my neighbor", cf->remote_ip, cf->iface);
|
2015-02-21 18:46:14 +08: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-21 05:50:17 +08:00
|
|
|
}
|
|
|
|
|
2000-03-20 06:09:07 +08:00
|
|
|
static int
|
|
|
|
bgp_start(struct proto *P)
|
|
|
|
{
|
2000-03-21 05:50:17 +08:00
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
struct object_lock *lock;
|
|
|
|
|
2000-03-31 01:39:48 +08:00
|
|
|
DBG("BGP: Startup.\n");
|
2008-12-19 08:34:39 +08:00
|
|
|
p->start_state = BSS_PREPARE;
|
2000-03-31 01:39:48 +08:00
|
|
|
p->outgoing_conn.state = BS_IDLE;
|
|
|
|
p->incoming_conn.state = BS_IDLE;
|
2000-06-20 15:49:08 +08:00
|
|
|
p->neigh = NULL;
|
2013-11-20 05:33:48 +08:00
|
|
|
p->bfd_req = NULL;
|
2014-03-20 21:07:12 +08:00
|
|
|
p->gr_ready = 0;
|
|
|
|
p->gr_active = 0;
|
2000-03-31 01:39:48 +08:00
|
|
|
|
2010-07-05 23:50:19 +08:00
|
|
|
rt_lock_table(p->igp_table);
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
p->event = ev_new(p->p.pool);
|
|
|
|
p->event->hook = bgp_decision;
|
|
|
|
p->event->data = p;
|
2000-05-08 19:04:22 +08:00
|
|
|
|
2009-06-07 00:16:22 +08:00
|
|
|
p->startup_timer = tm_new(p->p.pool);
|
|
|
|
p->startup_timer->hook = bgp_startup_timeout;
|
|
|
|
p->startup_timer->data = p;
|
|
|
|
|
2014-03-20 21:07:12 +08:00
|
|
|
p->gr_timer = tm_new(p->p.pool);
|
|
|
|
p->gr_timer->hook = bgp_graceful_restart_timeout;
|
|
|
|
p->gr_timer->data = p;
|
|
|
|
|
2011-04-01 19:54:39 +08: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 23:39:39 +08:00
|
|
|
p->remote_id = 0;
|
|
|
|
p->source_addr = p->cf->source_addr;
|
|
|
|
|
2014-03-23 08:35:33 +08:00
|
|
|
if (p->p.gr_recovery && p->cf->gr_mode)
|
2014-03-20 21:07:12 +08:00
|
|
|
proto_graceful_restart_lock(P);
|
|
|
|
|
2000-03-21 05:50:17 +08:00
|
|
|
/*
|
|
|
|
* Before attempting to create the connection, we need to lock the
|
|
|
|
* port, so that are sure we're the only instance attempting to talk
|
|
|
|
* with that neighbor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
lock = p->lock = olock_new(P->pool);
|
|
|
|
lock->addr = p->cf->remote_ip;
|
2014-10-02 17:33:55 +08:00
|
|
|
lock->port = p->cf->remote_port;
|
2012-01-08 22:28:27 +08:00
|
|
|
lock->iface = p->cf->iface;
|
2000-03-21 05:50:17 +08:00
|
|
|
lock->type = OBJLOCK_TCP;
|
|
|
|
lock->hook = bgp_start_locked;
|
|
|
|
lock->data = p;
|
|
|
|
olock_acquire(lock);
|
2008-10-27 05:42:39 +08:00
|
|
|
|
2000-03-21 05:50:17 +08:00
|
|
|
return PS_START;
|
2000-03-20 06:09:07 +08:00
|
|
|
}
|
|
|
|
|
2012-04-25 05:39:57 +08:00
|
|
|
extern int proto_restart;
|
|
|
|
|
2000-03-20 06:09:07 +08:00
|
|
|
static int
|
|
|
|
bgp_shutdown(struct proto *P)
|
|
|
|
{
|
2000-03-21 05:50:17 +08:00
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
2012-04-15 21:28:29 +08:00
|
|
|
unsigned subcode = 0;
|
2000-03-21 05:50:17 +08:00
|
|
|
|
2000-05-03 00:07:41 +08:00
|
|
|
BGP_TRACE(D_EVENTS, "Shutdown requested");
|
2009-06-07 06:38:38 +08:00
|
|
|
|
2012-04-15 21:28:29 +08:00
|
|
|
switch (P->down_code)
|
2009-06-07 06:38:38 +08:00
|
|
|
{
|
2012-04-15 21:28:29 +08: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:
|
2012-08-06 08:42:24 +08:00
|
|
|
case PDC_CMD_SHUTDOWN:
|
2012-04-15 21:28:29 +08:00
|
|
|
subcode = 2; // Errcode 6, 2 - administrative shutdown
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PDC_CMD_RESTART:
|
|
|
|
subcode = 4; // Errcode 6, 4 - administrative reset
|
|
|
|
break;
|
|
|
|
|
2013-01-10 20:07:33 +08:00
|
|
|
case PDC_RX_LIMIT_HIT:
|
2012-04-15 21:28:29 +08:00
|
|
|
case PDC_IN_LIMIT_HIT:
|
|
|
|
subcode = 1; // Errcode 6, 1 - max number of prefixes reached
|
2012-04-25 05:39:57 +08:00
|
|
|
/* log message for compatibility */
|
2012-04-15 21:28:29 +08:00
|
|
|
log(L_WARN "%s: Route limit exceeded, shutting down", p->p.name);
|
2012-04-25 05:39:57 +08:00
|
|
|
goto limit;
|
|
|
|
|
|
|
|
case PDC_OUT_LIMIT_HIT:
|
|
|
|
subcode = proto_restart ? 4 : 2; // Administrative reset or shutdown
|
2012-04-15 21:28:29 +08:00
|
|
|
|
2012-04-25 05:39:57 +08:00
|
|
|
limit:
|
2012-04-15 21:28:29 +08:00
|
|
|
bgp_store_error(p, NULL, BE_AUTO_DOWN, BEA_ROUTE_LIMIT_EXCEEDED);
|
2012-04-25 05:39:57 +08:00
|
|
|
if (proto_restart)
|
2012-04-15 21:28:29 +08:00
|
|
|
bgp_update_startup_delay(p);
|
2009-06-07 06:38:38 +08:00
|
|
|
else
|
2012-04-15 21:28:29 +08:00
|
|
|
p->startup_delay = 0;
|
|
|
|
goto done;
|
2009-06-07 06:38:38 +08:00
|
|
|
}
|
|
|
|
|
2012-04-15 21:28:29 +08:00
|
|
|
bgp_store_error(p, NULL, BE_MAN_DOWN, 0);
|
2008-12-19 08:34:39 +08:00
|
|
|
p->startup_delay = 0;
|
2000-03-21 05:50:17 +08:00
|
|
|
|
2012-04-15 21:28:29 +08:00
|
|
|
done:
|
|
|
|
bgp_stop(p, subcode);
|
2008-12-19 08:34:39 +08:00
|
|
|
return p->p.proto_state;
|
2000-03-20 06:09:07 +08:00
|
|
|
}
|
|
|
|
|
2010-07-05 23:50:19 +08:00
|
|
|
static void
|
|
|
|
bgp_cleanup(struct proto *P)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
rt_unlock_table(p->igp_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
static rtable *
|
|
|
|
get_igp_table(struct bgp_config *cf)
|
|
|
|
{
|
|
|
|
return cf->igp_table ? cf->igp_table->table : cf->c.table->table;
|
|
|
|
}
|
|
|
|
|
2000-04-10 19:21:40 +08:00
|
|
|
static struct proto *
|
|
|
|
bgp_init(struct proto_config *C)
|
|
|
|
{
|
|
|
|
struct proto *P = proto_new(C, sizeof(struct bgp_proto));
|
2012-08-14 22:25:22 +08:00
|
|
|
struct bgp_config *c = (struct bgp_config *) C;
|
2000-04-10 19:21:40 +08:00
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
|
2012-04-15 21:07:58 +08:00
|
|
|
P->accept_ra_types = c->secondary ? RA_ACCEPTED : RA_OPTIMAL;
|
2000-04-10 19:21:40 +08:00
|
|
|
P->rt_notify = bgp_rt_notify;
|
|
|
|
P->import_control = bgp_import_control;
|
|
|
|
P->neigh_notify = bgp_neigh_notify;
|
2009-11-27 03:47:59 +08:00
|
|
|
P->reload_routes = bgp_reload_routes;
|
2015-03-30 00:27:13 +08:00
|
|
|
P->feed_begin = bgp_feed_begin;
|
|
|
|
P->feed_end = bgp_feed_end;
|
2012-08-14 22:25:22 +08:00
|
|
|
P->rte_better = bgp_rte_better;
|
2015-06-08 08:20:43 +08:00
|
|
|
P->rte_mergable = bgp_rte_mergable;
|
2012-08-14 22:25:22 +08:00
|
|
|
P->rte_recalculate = c->deterministic_med ? bgp_rte_recalculate : NULL;
|
2011-12-22 20:20:29 +08:00
|
|
|
|
2000-04-10 19:21:40 +08:00
|
|
|
p->cf = c;
|
|
|
|
p->local_as = c->local_as;
|
|
|
|
p->remote_as = c->remote_as;
|
|
|
|
p->is_internal = (c->local_as == c->remote_as);
|
2010-07-12 23:39:39 +08:00
|
|
|
p->rs_client = c->rs_client;
|
|
|
|
p->rr_client = c->rr_client;
|
2010-07-05 23:50:19 +08:00
|
|
|
p->igp_table = get_igp_table(c);
|
2010-07-12 23:39:39 +08:00
|
|
|
|
2000-04-10 19:21:40 +08:00
|
|
|
return P;
|
|
|
|
}
|
|
|
|
|
2011-11-07 07:31:23 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
bgp_check_config(struct bgp_config *c)
|
|
|
|
{
|
|
|
|
int internal = (c->local_as == c->remote_as);
|
|
|
|
|
|
|
|
/* Do not check templates at all */
|
|
|
|
if (c->c.class == SYM_TEMPLATE)
|
|
|
|
return;
|
|
|
|
|
2013-11-24 19:37:24 +08:00
|
|
|
|
|
|
|
/* EBGP direct by default, IBGP multihop by default */
|
|
|
|
if (c->multihop < 0)
|
|
|
|
c->multihop = internal ? 64 : 0;
|
|
|
|
|
|
|
|
/* Different default for gw_mode */
|
|
|
|
if (!c->gw_mode)
|
|
|
|
c->gw_mode = c->multihop ? GW_RECURSIVE : GW_DIRECT;
|
|
|
|
|
|
|
|
/* Different default based on rs_client */
|
|
|
|
if (!c->missing_lladdr)
|
|
|
|
c->missing_lladdr = c->rs_client ? MLL_IGNORE : MLL_SELF;
|
|
|
|
|
|
|
|
/* Disable after error incompatible with restart limit action */
|
|
|
|
if (c->c.in_limit && (c->c.in_limit->action == PLA_RESTART) && c->disable_after_error)
|
|
|
|
c->c.in_limit->action = PLA_DISABLE;
|
|
|
|
|
|
|
|
|
2011-11-07 07:31:23 +08:00
|
|
|
if (!c->local_as)
|
|
|
|
cf_error("Local AS number must be set");
|
|
|
|
|
2015-02-22 20:50:58 +08:00
|
|
|
if (ipa_zero(c->remote_ip))
|
2011-11-07 07:31:23 +08:00
|
|
|
cf_error("Neighbor must be configured");
|
|
|
|
|
2015-02-22 20:50:58 +08:00
|
|
|
if (!c->remote_as)
|
|
|
|
cf_error("Remote AS number must be set");
|
|
|
|
|
|
|
|
// if (ipa_is_link_local(c->remote_ip) && !c->iface)
|
|
|
|
// cf_error("Link-local neighbor address requires specified interface");
|
|
|
|
|
|
|
|
if (!ipa_is_link_local(c->remote_ip) != !c->iface)
|
|
|
|
cf_error("Link-local address and interface scope must be used together");
|
|
|
|
|
2011-11-07 07:31:23 +08:00
|
|
|
if (!(c->capabilities && c->enable_as4) && (c->remote_as > 0xFFFF))
|
|
|
|
cf_error("Neighbor AS number out of range (AS4 not available)");
|
|
|
|
|
|
|
|
if (!internal && c->rr_client)
|
|
|
|
cf_error("Only internal neighbor can be RR client");
|
|
|
|
|
|
|
|
if (internal && c->rs_client)
|
|
|
|
cf_error("Only external neighbor can be RS client");
|
|
|
|
|
|
|
|
if (c->multihop && (c->gw_mode == GW_DIRECT))
|
|
|
|
cf_error("Multihop BGP cannot use direct gateway mode");
|
|
|
|
|
2014-10-24 17:11:43 +08:00
|
|
|
if (c->multihop && (ipa_is_link_local(c->remote_ip) ||
|
|
|
|
ipa_is_link_local(c->source_addr)))
|
2012-01-08 22:28:27 +08:00
|
|
|
cf_error("Multihop BGP cannot be used with link-local addresses");
|
|
|
|
|
2015-02-21 18:46:14 +08:00
|
|
|
if (c->multihop && c->check_link)
|
|
|
|
cf_error("Multihop BGP cannot depend on link state");
|
|
|
|
|
2013-11-20 05:33:48 +08:00
|
|
|
if (c->multihop && c->bfd && ipa_zero(c->source_addr))
|
|
|
|
cf_error("Multihop BGP with BFD requires specified source address");
|
|
|
|
|
2012-07-05 03:31:03 +08:00
|
|
|
if ((c->gw_mode == GW_RECURSIVE) && c->c.table->sorted)
|
|
|
|
cf_error("BGP in recursive mode prohibits sorted table");
|
|
|
|
|
|
|
|
if (c->deterministic_med && c->c.table->sorted)
|
|
|
|
cf_error("BGP with deterministic MED prohibits sorted table");
|
|
|
|
|
|
|
|
if (c->secondary && !c->c.table->sorted)
|
|
|
|
cf_error("BGP with secondary option requires sorted table");
|
2011-11-07 07:31:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bgp_reconfigure(struct proto *P, struct proto_config *C)
|
|
|
|
{
|
|
|
|
struct bgp_config *new = (struct bgp_config *) C;
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
struct bgp_config *old = p->cf;
|
|
|
|
|
2012-12-27 19:56:23 +08:00
|
|
|
if (proto_get_router_id(C) != p->local_id)
|
|
|
|
return 0;
|
|
|
|
|
2011-11-07 07:31:23 +08: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))
|
|
|
|
&& ((!old->password && !new->password)
|
|
|
|
|| (old->password && new->password && !strcmp(old->password, new->password)))
|
|
|
|
&& (get_igp_table(old) == get_igp_table(new));
|
|
|
|
|
2013-11-20 05:33:48 +08:00
|
|
|
if (same && (p->start_state > BSS_PREPARE))
|
|
|
|
bgp_update_bfd(p, new->bfd);
|
|
|
|
|
2011-11-07 07:31:23 +08:00
|
|
|
/* We should update our copy of configuration ptr as old configuration will be freed */
|
|
|
|
if (same)
|
|
|
|
p->cf = new;
|
|
|
|
|
|
|
|
return same;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_copy_config(struct proto_config *dest, struct proto_config *src)
|
|
|
|
{
|
|
|
|
/* Just a shallow copy */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-05 01:06:18 +08:00
|
|
|
/**
|
|
|
|
* bgp_error - report a protocol error
|
|
|
|
* @c: connection
|
|
|
|
* @code: error code (according to the RFC)
|
2000-06-07 20:29:08 +08:00
|
|
|
* @subcode: error sub-code
|
2000-06-05 01:06:18 +08: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 20:29:08 +08:00
|
|
|
* error has occurred (including the data considered erroneous if possible) and
|
2000-06-05 01:06:18 +08:00
|
|
|
* closes the connection.
|
|
|
|
*/
|
2000-03-30 18:44:20 +08:00
|
|
|
void
|
2000-04-26 05:13:25 +08:00
|
|
|
bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int len)
|
2000-03-30 18:44:20 +08:00
|
|
|
{
|
2009-06-07 06:38:38 +08:00
|
|
|
struct bgp_proto *p = c->bgp;
|
|
|
|
|
2008-12-19 08:34:39 +08:00
|
|
|
if (c->state == BS_CLOSE)
|
2000-03-30 18:44:20 +08:00
|
|
|
return;
|
2008-12-19 08:34:39 +08:00
|
|
|
|
2009-06-07 06:38:38 +08:00
|
|
|
bgp_log_error(p, BE_BGP_TX, "Error", code, subcode, data, (len > 0) ? len : -len);
|
|
|
|
bgp_store_error(p, c, BE_BGP_TX, (code << 16) | subcode);
|
2008-12-19 08:34:39 +08:00
|
|
|
bgp_conn_enter_close_state(c);
|
|
|
|
|
2000-03-30 18:44:20 +08:00
|
|
|
c->notify_code = code;
|
|
|
|
c->notify_subcode = subcode;
|
2000-04-26 05:13:25 +08:00
|
|
|
c->notify_data = data;
|
|
|
|
c->notify_size = (len > 0) ? len : 0;
|
2000-03-30 18:44:20 +08:00
|
|
|
bgp_schedule_packet(c, PKT_NOTIFICATION);
|
2009-06-07 06:38:38 +08:00
|
|
|
|
|
|
|
if (code != 6)
|
|
|
|
{
|
|
|
|
bgp_update_startup_delay(p);
|
|
|
|
bgp_stop(p, 0);
|
|
|
|
}
|
2000-03-30 18:44:20 +08:00
|
|
|
}
|
|
|
|
|
2008-12-19 08:34:39 +08: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 19:31:09 +08:00
|
|
|
static char *bgp_err_classes[] = { "", "Error: ", "Socket: ", "Received: ", "BGP Error: ", "Automatic shutdown: ", ""};
|
2015-02-21 18:46:14 +08: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 19:31:09 +08:00
|
|
|
static char *bgp_auto_errors[] = { "", "Route limit exceeded"};
|
2008-12-19 08:34:39 +08:00
|
|
|
|
2010-04-07 06:19:23 +08:00
|
|
|
static const char *
|
|
|
|
bgp_last_errmsg(struct bgp_proto *p)
|
2000-03-31 02:44:23 +08:00
|
|
|
{
|
2008-12-19 08:34:39 +08:00
|
|
|
switch (p->last_error_class)
|
|
|
|
{
|
|
|
|
case BE_MISC:
|
2010-04-07 06:19:23 +08:00
|
|
|
return bgp_misc_errors[p->last_error_code];
|
2008-12-19 08:34:39 +08:00
|
|
|
case BE_SOCKET:
|
2010-04-07 06:19:23 +08:00
|
|
|
return (p->last_error_code == 0) ? "Connection closed" : strerror(p->last_error_code);
|
2008-12-19 08:34:39 +08:00
|
|
|
case BE_BGP_RX:
|
|
|
|
case BE_BGP_TX:
|
2010-04-07 06:19:23 +08:00
|
|
|
return bgp_error_dsc(p->last_error_code >> 16, p->last_error_code & 0xFF);
|
2009-06-04 19:31:09 +08:00
|
|
|
case BE_AUTO_DOWN:
|
2010-04-07 06:19:23 +08:00
|
|
|
return bgp_auto_errors[p->last_error_code];
|
|
|
|
default:
|
|
|
|
return "";
|
2008-12-19 08:34:39 +08:00
|
|
|
}
|
2010-04-07 06:19:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
bgp_state_dsc(struct bgp_proto *p)
|
|
|
|
{
|
2011-09-04 06:56:02 +08:00
|
|
|
if (p->p.proto_state == PS_DOWN)
|
|
|
|
return "Down";
|
2010-04-07 06:19:23 +08:00
|
|
|
|
|
|
|
int state = MAX(p->incoming_conn.state, p->outgoing_conn.state);
|
|
|
|
if ((state == BS_IDLE) && (p->start_state >= BSS_CONNECT) && p->cf->passive)
|
|
|
|
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 08:34:39 +08:00
|
|
|
|
2000-05-15 20:19:28 +08:00
|
|
|
if (P->proto_state == PS_DOWN)
|
2008-12-19 08:34:39 +08:00
|
|
|
bsprintf(buf, "%s%s", err1, err2);
|
2000-05-15 20:19:28 +08:00
|
|
|
else
|
2010-04-07 06:19:23 +08:00
|
|
|
bsprintf(buf, "%-14s%s%s", bgp_state_dsc(p), err1, err2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_show_proto_info(struct proto *P)
|
|
|
|
{
|
|
|
|
struct bgp_proto *p = (struct bgp_proto *) P;
|
|
|
|
struct bgp_conn *c = p->conn;
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
proto_show_basic_info(P);
|
|
|
|
|
2010-04-07 06:19:23 +08:00
|
|
|
cli_msg(-1006, " BGP state: %s", bgp_state_dsc(p));
|
2012-01-08 22:28:27 +08:00
|
|
|
cli_msg(-1006, " Neighbor address: %I%J", p->cf->remote_ip, p->cf->iface);
|
2011-09-04 06:56:02 +08:00
|
|
|
cli_msg(-1006, " Neighbor AS: %u", p->remote_as);
|
2010-04-07 06:19:23 +08:00
|
|
|
|
2014-03-20 21:07:12 +08:00
|
|
|
if (p->gr_active)
|
|
|
|
cli_msg(-1006, " Neighbor graceful restart active");
|
|
|
|
|
2010-04-07 06:19:23 +08:00
|
|
|
if (P->proto_state == PS_START)
|
|
|
|
{
|
|
|
|
struct bgp_conn *oc = &p->outgoing_conn;
|
|
|
|
|
|
|
|
if ((p->start_state < BSS_CONNECT) &&
|
|
|
|
(p->startup_timer->expires))
|
2014-03-20 21:07:12 +08:00
|
|
|
cli_msg(-1006, " Error wait: %d/%d",
|
2010-04-07 06:19:23 +08:00
|
|
|
p->startup_timer->expires - now, p->startup_delay);
|
|
|
|
|
|
|
|
if ((oc->state == BS_ACTIVE) &&
|
|
|
|
(oc->connect_retry_timer->expires))
|
2015-02-22 23:08:28 +08:00
|
|
|
cli_msg(-1006, " Connect delay: %d/%d",
|
|
|
|
oc->connect_retry_timer->expires - now, p->cf->connect_delay_time);
|
2014-03-20 21:07:12 +08:00
|
|
|
|
|
|
|
if (p->gr_active && p->gr_timer->expires)
|
|
|
|
cli_msg(-1006, " Restart timer: %d/-", p->gr_timer->expires - now);
|
2010-04-07 06:19:23 +08:00
|
|
|
}
|
|
|
|
else if (P->proto_state == PS_UP)
|
|
|
|
{
|
2011-09-04 06:56:02 +08:00
|
|
|
cli_msg(-1006, " Neighbor ID: %R", p->remote_id);
|
2015-07-18 19:38:21 +08:00
|
|
|
cli_msg(-1006, " Neighbor caps: %s%s%s%s%s%s%s",
|
2011-09-04 06:56:02 +08:00
|
|
|
c->peer_refresh_support ? " refresh" : "",
|
2015-03-30 00:27:13 +08:00
|
|
|
c->peer_enhanced_refresh_support ? " enhanced-refresh" : "",
|
2014-03-20 21:07:12 +08:00
|
|
|
c->peer_gr_able ? " restart-able" : (c->peer_gr_aware ? " restart-aware" : ""),
|
2012-08-14 22:25:22 +08:00
|
|
|
c->peer_as4_support ? " AS4" : "",
|
|
|
|
(c->peer_add_path & ADD_PATH_RX) ? " add-path-rx" : "",
|
2015-07-18 19:38:21 +08:00
|
|
|
(c->peer_add_path & ADD_PATH_TX) ? " add-path-tx" : "",
|
|
|
|
c->peer_ext_messages_support ? " ext-messages" : "");
|
|
|
|
cli_msg(-1006, " Session: %s%s%s%s%s%s%s%s",
|
2010-04-07 06:19:23 +08:00
|
|
|
p->is_internal ? "internal" : "external",
|
2011-09-04 06:56:02 +08:00
|
|
|
p->cf->multihop ? " multihop" : "",
|
2010-04-07 06:19:23 +08:00
|
|
|
p->rr_client ? " route-reflector" : "",
|
|
|
|
p->rs_client ? " route-server" : "",
|
2012-08-14 22:25:22 +08:00
|
|
|
p->as4_session ? " AS4" : "",
|
|
|
|
p->add_path_rx ? " add-path-rx" : "",
|
2015-07-18 19:38:21 +08:00
|
|
|
p->add_path_tx ? " add-path-tx" : "",
|
|
|
|
p->ext_messages ? " ext-messages" : "");
|
2010-04-07 06:19:23 +08:00
|
|
|
cli_msg(-1006, " Source address: %I", p->source_addr);
|
2012-04-22 03:05:36 +08:00
|
|
|
if (P->cf->in_limit)
|
2010-04-07 06:19:23 +08:00
|
|
|
cli_msg(-1006, " Route limit: %d/%d",
|
2012-11-15 08:29:01 +08:00
|
|
|
p->p.stats.imp_routes + p->p.stats.filt_routes, P->cf->in_limit->limit);
|
2011-06-25 20:51:16 +08:00
|
|
|
cli_msg(-1006, " Hold timer: %d/%d",
|
|
|
|
tm_remains(c->hold_timer), c->hold_time);
|
|
|
|
cli_msg(-1006, " Keepalive timer: %d/%d",
|
|
|
|
tm_remains(c->keepalive_timer), c->keepalive_time);
|
2010-04-07 06:19:23 +08:00
|
|
|
}
|
|
|
|
|
2015-02-21 18:46:14 +08:00
|
|
|
if ((p->last_error_class != BE_NONE) &&
|
2010-04-07 06:19:23 +08:00
|
|
|
(p->last_error_class != BE_MAN_DOWN))
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2000-03-31 02:44:23 +08:00
|
|
|
}
|
|
|
|
|
2000-03-20 06:09:07 +08:00
|
|
|
struct protocol proto_bgp = {
|
2014-12-03 17:10:34 +08:00
|
|
|
.name = "BGP",
|
|
|
|
.template = "bgp%d",
|
|
|
|
.attr_class = EAP_BGP,
|
|
|
|
.preference = DEF_PREF_BGP,
|
2015-02-22 04:08:23 +08:00
|
|
|
.config_size = sizeof(struct bgp_config),
|
2014-12-03 17:10:34 +08:00
|
|
|
.init = bgp_init,
|
|
|
|
.start = bgp_start,
|
|
|
|
.shutdown = bgp_shutdown,
|
|
|
|
.cleanup = bgp_cleanup,
|
|
|
|
.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-20 06:09:07 +08:00
|
|
|
};
|