Implemented automatic restart after error with all the timers needed.
This commit is contained in:
parent
8573314326
commit
6fd766c17e
3 changed files with 74 additions and 16 deletions
|
@ -26,6 +26,7 @@ static list bgp_list; /* List of active BGP instances */
|
||||||
static char *bgp_state_names[] = { "Idle", "Connect", "Active", "OpenSent", "OpenConfirm", "Established" };
|
static char *bgp_state_names[] = { "Idle", "Connect", "Active", "OpenSent", "OpenConfirm", "Established" };
|
||||||
|
|
||||||
static void bgp_connect(struct bgp_proto *p);
|
static void bgp_connect(struct bgp_proto *p);
|
||||||
|
static void bgp_initiate(struct bgp_proto *p);
|
||||||
|
|
||||||
void
|
void
|
||||||
bgp_close(struct bgp_proto *p)
|
bgp_close(struct bgp_proto *p)
|
||||||
|
@ -40,7 +41,6 @@ bgp_close(struct bgp_proto *p)
|
||||||
rfree(bgp_linpool);
|
rfree(bgp_linpool);
|
||||||
bgp_linpool = NULL;
|
bgp_linpool = NULL;
|
||||||
}
|
}
|
||||||
/* FIXME: Automatic restart after errors? */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -60,6 +60,7 @@ void
|
||||||
bgp_close_conn(struct bgp_conn *conn)
|
bgp_close_conn(struct bgp_conn *conn)
|
||||||
{
|
{
|
||||||
struct bgp_proto *p = conn->bgp;
|
struct bgp_proto *p = conn->bgp;
|
||||||
|
struct bgp_config *cf = p->cf;
|
||||||
|
|
||||||
DBG("BGP: Closing connection\n");
|
DBG("BGP: Closing connection\n");
|
||||||
conn->packets_to_send = 0;
|
conn->packets_to_send = 0;
|
||||||
|
@ -72,14 +73,29 @@ bgp_close_conn(struct bgp_conn *conn)
|
||||||
sk_close(conn->sk);
|
sk_close(conn->sk);
|
||||||
conn->sk = NULL;
|
conn->sk = NULL;
|
||||||
conn->state = BS_IDLE;
|
conn->state = BS_IDLE;
|
||||||
|
if (conn->error_flag > 1)
|
||||||
|
{
|
||||||
|
if (cf->disable_after_error)
|
||||||
|
p->p.disabled = 1;
|
||||||
|
if (p->last_connect && (bird_clock_t)(p->last_connect + cf->error_amnesia_time) < now)
|
||||||
|
p->startup_delay = 0;
|
||||||
|
if (!p->startup_delay)
|
||||||
|
p->startup_delay = cf->error_delay_time_min;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p->startup_delay *= 2;
|
||||||
|
if (p->startup_delay > cf->error_delay_time_max)
|
||||||
|
p->startup_delay = cf->error_delay_time_max;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (conn->primary)
|
if (conn->primary)
|
||||||
{
|
{
|
||||||
bgp_close(p);
|
bgp_close(p);
|
||||||
p->conn = NULL;
|
p->conn = NULL;
|
||||||
if (conn->error_flag) /* FIXME: Enable automatically? */
|
|
||||||
p->p.disabled = 1;
|
|
||||||
proto_notify_state(&p->p, PS_DOWN);
|
proto_notify_state(&p->p, PS_DOWN);
|
||||||
}
|
}
|
||||||
|
else if (conn->error_flag > 1)
|
||||||
|
bgp_initiate(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -175,19 +191,12 @@ bgp_keepalive_timeout(timer *t)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bgp_setup_sk(struct bgp_proto *p, struct bgp_conn *conn, sock *s)
|
bgp_setup_conn(struct bgp_proto *p, struct bgp_conn *conn)
|
||||||
{
|
{
|
||||||
timer *t;
|
timer *t;
|
||||||
|
|
||||||
s->data = conn;
|
conn->sk = NULL;
|
||||||
s->ttl = p->cf->multihop ? : 1;
|
|
||||||
s->rbsize = BGP_RX_BUFFER_SIZE;
|
|
||||||
s->tbsize = BGP_TX_BUFFER_SIZE;
|
|
||||||
s->err_hook = bgp_sock_err;
|
|
||||||
s->tos = IP_PREC_INTERNET_CONTROL;
|
|
||||||
|
|
||||||
conn->bgp = p;
|
conn->bgp = p;
|
||||||
conn->sk = s;
|
|
||||||
conn->packets_to_send = 0;
|
conn->packets_to_send = 0;
|
||||||
conn->error_flag = 0;
|
conn->error_flag = 0;
|
||||||
conn->primary = 0;
|
conn->primary = 0;
|
||||||
|
@ -203,6 +212,18 @@ bgp_setup_sk(struct bgp_proto *p, struct bgp_conn *conn, sock *s)
|
||||||
t->data = conn;
|
t->data = conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bgp_setup_sk(struct bgp_proto *p, struct bgp_conn *conn, sock *s)
|
||||||
|
{
|
||||||
|
s->data = conn;
|
||||||
|
s->ttl = p->cf->multihop ? : 1;
|
||||||
|
s->rbsize = BGP_RX_BUFFER_SIZE;
|
||||||
|
s->tbsize = BGP_TX_BUFFER_SIZE;
|
||||||
|
s->err_hook = bgp_sock_err;
|
||||||
|
s->tos = IP_PREC_INTERNET_CONTROL;
|
||||||
|
conn->sk = s;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing connection */
|
bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing connection */
|
||||||
{
|
{
|
||||||
|
@ -210,6 +231,7 @@ bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing c
|
||||||
struct bgp_conn *conn = &p->outgoing_conn;
|
struct bgp_conn *conn = &p->outgoing_conn;
|
||||||
|
|
||||||
DBG("BGP: Connecting\n");
|
DBG("BGP: Connecting\n");
|
||||||
|
p->last_connect = now;
|
||||||
s = sk_new(p->p.pool);
|
s = sk_new(p->p.pool);
|
||||||
s->type = SK_TCP_ACTIVE;
|
s->type = SK_TCP_ACTIVE;
|
||||||
if (ipa_nonzero(p->cf->source_addr))
|
if (ipa_nonzero(p->cf->source_addr))
|
||||||
|
@ -218,6 +240,7 @@ bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing c
|
||||||
s->saddr = p->local_addr;
|
s->saddr = p->local_addr;
|
||||||
s->daddr = p->cf->remote_ip;
|
s->daddr = p->cf->remote_ip;
|
||||||
s->dport = BGP_PORT;
|
s->dport = BGP_PORT;
|
||||||
|
bgp_setup_conn(p, conn);
|
||||||
bgp_setup_sk(p, conn, s);
|
bgp_setup_sk(p, conn, s);
|
||||||
s->tx_hook = bgp_connected;
|
s->tx_hook = bgp_connected;
|
||||||
conn->state = BS_CONNECT;
|
conn->state = BS_CONNECT;
|
||||||
|
@ -230,6 +253,24 @@ bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing c
|
||||||
bgp_start_timer(conn->connect_retry_timer, p->cf->connect_retry_time);
|
bgp_start_timer(conn->connect_retry_timer, p->cf->connect_retry_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bgp_initiate(struct bgp_proto *p)
|
||||||
|
{
|
||||||
|
unsigned delay;
|
||||||
|
|
||||||
|
delay = p->cf->start_delay_time;
|
||||||
|
if (p->startup_delay > delay)
|
||||||
|
delay = p->startup_delay;
|
||||||
|
if (delay)
|
||||||
|
{
|
||||||
|
DBG("BGP: Connect delayed by %d seconds\n", delay);
|
||||||
|
bgp_setup_conn(p, &p->outgoing_conn);
|
||||||
|
bgp_start_timer(p->outgoing_conn.connect_retry_timer, delay);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
bgp_connect(p);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bgp_incoming_connection(sock *sk, int dummy)
|
bgp_incoming_connection(sock *sk, int dummy)
|
||||||
{
|
{
|
||||||
|
@ -247,6 +288,7 @@ bgp_incoming_connection(sock *sk, int dummy)
|
||||||
DBG("BGP: But one incoming connection already exists, how is that possible?\n");
|
DBG("BGP: But one incoming connection already exists, how is that possible?\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
bgp_setup_conn(p, &p->incoming_conn);
|
||||||
bgp_setup_sk(p, &p->incoming_conn, sk);
|
bgp_setup_sk(p, &p->incoming_conn, sk);
|
||||||
bgp_send_open(&p->incoming_conn);
|
bgp_send_open(&p->incoming_conn);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -285,7 +327,7 @@ bgp_start_neighbor(struct bgp_proto *p)
|
||||||
if (!bgp_linpool)
|
if (!bgp_linpool)
|
||||||
bgp_linpool = lp_new(&root_pool, 4080);
|
bgp_linpool = lp_new(&root_pool, 4080);
|
||||||
add_tail(&bgp_list, &p->bgp_node);
|
add_tail(&bgp_list, &p->bgp_node);
|
||||||
bgp_connect(p);
|
bgp_initiate(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -305,7 +347,6 @@ bgp_neigh_notify(neighbor *n)
|
||||||
bgp_graceful_close_conn(&p->outgoing_conn);
|
bgp_graceful_close_conn(&p->outgoing_conn);
|
||||||
bgp_graceful_close_conn(&p->incoming_conn);
|
bgp_graceful_close_conn(&p->incoming_conn);
|
||||||
proto_notify_state(&p->p, PS_DOWN);
|
proto_notify_state(&p->p, PS_DOWN);
|
||||||
/* FIXME: Remember to delay protocol startup here! */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,6 +381,7 @@ bgp_start(struct proto *P)
|
||||||
DBG("BGP: Startup.\n");
|
DBG("BGP: Startup.\n");
|
||||||
p->outgoing_conn.state = BS_IDLE;
|
p->outgoing_conn.state = BS_IDLE;
|
||||||
p->incoming_conn.state = BS_IDLE;
|
p->incoming_conn.state = BS_IDLE;
|
||||||
|
p->startup_delay = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Before attempting to create the connection, we need to lock the
|
* Before attempting to create the connection, we need to lock the
|
||||||
|
@ -415,7 +457,7 @@ bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int l
|
||||||
if (c->error_flag)
|
if (c->error_flag)
|
||||||
return;
|
return;
|
||||||
bgp_log_error(c->bgp, "Error", code, subcode, data, (len > 0) ? len : -len);
|
bgp_log_error(c->bgp, "Error", code, subcode, data, (len > 0) ? len : -len);
|
||||||
c->error_flag = 1;
|
c->error_flag = 1 + (code != 6);
|
||||||
c->notify_code = code;
|
c->notify_code = code;
|
||||||
c->notify_subcode = subcode;
|
c->notify_subcode = subcode;
|
||||||
c->notify_data = data;
|
c->notify_data = data;
|
||||||
|
|
|
@ -28,6 +28,11 @@ struct bgp_config {
|
||||||
unsigned connect_retry_time;
|
unsigned connect_retry_time;
|
||||||
unsigned hold_time, initial_hold_time;
|
unsigned hold_time, initial_hold_time;
|
||||||
unsigned keepalive_time;
|
unsigned keepalive_time;
|
||||||
|
unsigned start_delay_time; /* Minimum delay between connects */
|
||||||
|
unsigned error_amnesia_time; /* Errors are forgotten after */
|
||||||
|
unsigned error_delay_time_min; /* Time to wait after an error is detected */
|
||||||
|
unsigned error_delay_time_max;
|
||||||
|
unsigned disable_after_error; /* Disable the protocol when error is detected */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bgp_conn {
|
struct bgp_conn {
|
||||||
|
@ -65,6 +70,8 @@ struct bgp_proto {
|
||||||
struct fib prefix_fib; /* Prefixes to be sent */
|
struct fib prefix_fib; /* Prefixes to be sent */
|
||||||
list bucket_queue; /* Queue of buckets to send */
|
list bucket_queue; /* Queue of buckets to send */
|
||||||
struct bgp_bucket *withdraw_bucket; /* Withdrawn routes */
|
struct bgp_bucket *withdraw_bucket; /* Withdrawn routes */
|
||||||
|
unsigned startup_delay; /* Time to delay protocol startup by due to errors */
|
||||||
|
bird_clock_t last_connect; /* Time of last connect attempt */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bgp_prefix {
|
struct bgp_prefix {
|
||||||
|
|
|
@ -16,6 +16,7 @@ CF_DECLS
|
||||||
|
|
||||||
CF_KEYWORDS(BGP, LOCAL, NEIGHBOR, AS, HOLD, TIME, CONNECT, RETRY, KEEPALIVE,
|
CF_KEYWORDS(BGP, LOCAL, NEIGHBOR, AS, HOLD, TIME, CONNECT, RETRY, KEEPALIVE,
|
||||||
MULTIHOP, STARTUP, VIA, NEXT, HOP, SELF, DEFAULT, PATH, METRIC,
|
MULTIHOP, STARTUP, VIA, NEXT, HOP, SELF, DEFAULT, PATH, METRIC,
|
||||||
|
ERROR, START, DELAY, FORGET, WAIT, DISABLE, AFTER,
|
||||||
BGP_PATH, BGP_LOCAL_PREF, BGP_MED, BGP_ORIGIN, BGP_NEXT_HOP,
|
BGP_PATH, BGP_LOCAL_PREF, BGP_MED, BGP_ORIGIN, BGP_NEXT_HOP,
|
||||||
BGP_ATOMIC_AGGR, BGP_AGGREGATOR, BGP_COMMUNITY, SOURCE, ADDRESS)
|
BGP_ATOMIC_AGGR, BGP_AGGREGATOR, BGP_COMMUNITY, SOURCE, ADDRESS)
|
||||||
|
|
||||||
|
@ -31,6 +32,10 @@ bgp_proto_start: proto_start BGP {
|
||||||
BGP_CFG->initial_hold_time = 240;
|
BGP_CFG->initial_hold_time = 240;
|
||||||
BGP_CFG->default_med = ~0; /* RFC 1771 doesn't specify this, draft-09 says ~0 */
|
BGP_CFG->default_med = ~0; /* RFC 1771 doesn't specify this, draft-09 says ~0 */
|
||||||
BGP_CFG->compare_path_lengths = 1;
|
BGP_CFG->compare_path_lengths = 1;
|
||||||
|
BGP_CFG->start_delay_time = 5;
|
||||||
|
BGP_CFG->error_amnesia_time = 300;
|
||||||
|
BGP_CFG->error_delay_time_min = 60;
|
||||||
|
BGP_CFG->error_delay_time_max = 300;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -56,6 +61,10 @@ bgp_proto:
|
||||||
| bgp_proto DEFAULT BGP_MED NUM ';' { BGP_CFG->default_med = $4; }
|
| bgp_proto DEFAULT BGP_MED NUM ';' { BGP_CFG->default_med = $4; }
|
||||||
| bgp_proto DEFAULT BGP_LOCAL_PREF NUM ';' { BGP_CFG->default_local_pref = $4; }
|
| bgp_proto DEFAULT BGP_LOCAL_PREF NUM ';' { BGP_CFG->default_local_pref = $4; }
|
||||||
| bgp_proto SOURCE ADDRESS IPA ';' { BGP_CFG->source_addr = $4; }
|
| bgp_proto SOURCE ADDRESS IPA ';' { BGP_CFG->source_addr = $4; }
|
||||||
|
| bgp_proto START DELAY TIME NUM ';' { BGP_CFG->start_delay_time = $5; }
|
||||||
|
| bgp_proto ERROR FORGET TIME NUM ';' { BGP_CFG->error_amnesia_time = $5; }
|
||||||
|
| bgp_proto ERROR WAIT TIME NUM ',' NUM ';' { BGP_CFG->error_delay_time_min = $5; BGP_CFG->error_delay_time_max = $7; }
|
||||||
|
| bgp_proto DISABLE AFTER ERROR ';' { BGP_CFG->disable_after_error = 1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
CF_ADDTO(dynamic_attr, BGP_PATH
|
CF_ADDTO(dynamic_attr, BGP_PATH
|
||||||
|
|
Loading…
Reference in a new issue