Disable BGP protocol when cannot open listening socket.

This commit is contained in:
Ondrej Zajicek 2010-05-31 11:35:29 +02:00
parent 9b061f7ea5
commit a34b09349e
2 changed files with 14 additions and 4 deletions

View file

@ -97,6 +97,15 @@ bgp_open(struct bgp_proto *p)
if (!bgp_listen_sk) if (!bgp_listen_sk)
bgp_listen_sk = bgp_setup_listen_sk(cfg->listen_bgp_addr, cfg->listen_bgp_port, cfg->listen_bgp_flags); bgp_listen_sk = bgp_setup_listen_sk(cfg->listen_bgp_addr, cfg->listen_bgp_port, cfg->listen_bgp_flags);
if (!bgp_listen_sk)
{
bgp_counter--;
p->p.disabled = 1;
bgp_store_error(p, NULL, BE_MISC, BEM_NO_SOCKET);
proto_notify_state(&p->p, PS_DOWN);
return -1;
}
if (!bgp_linpool) if (!bgp_linpool)
bgp_linpool = lp_new(&root_pool, 4080); bgp_linpool = lp_new(&root_pool, 4080);
@ -630,14 +639,14 @@ bgp_listen_sock_err(sock *sk UNUSED, int err)
if (err == ECONNABORTED) if (err == ECONNABORTED)
log(L_WARN "BGP: Incoming connection aborted"); log(L_WARN "BGP: Incoming connection aborted");
else else
log(L_ERR "BGP: Error on incoming socket: %M", err); log(L_ERR "BGP: Error on listening socket: %M", err);
} }
static sock * static sock *
bgp_setup_listen_sk(ip_addr addr, unsigned port, u32 flags) bgp_setup_listen_sk(ip_addr addr, unsigned port, u32 flags)
{ {
sock *s = sk_new(&root_pool); sock *s = sk_new(&root_pool);
DBG("BGP: Creating incoming socket\n"); DBG("BGP: Creating listening socket\n");
s->type = SK_TCP_PASSIVE; s->type = SK_TCP_PASSIVE;
s->saddr = addr; s->saddr = addr;
s->sport = port ? port : BGP_PORT; s->sport = port ? port : BGP_PORT;
@ -649,7 +658,7 @@ bgp_setup_listen_sk(ip_addr addr, unsigned port, u32 flags)
s->err_hook = bgp_listen_sock_err; s->err_hook = bgp_listen_sock_err;
if (sk_open(s)) if (sk_open(s))
{ {
log(L_ERR "BGP: Unable to open incoming socket"); log(L_ERR "BGP: Unable to open listening socket");
rfree(s); rfree(s);
return NULL; return NULL;
} }
@ -937,7 +946,7 @@ bgp_check(struct bgp_config *c)
static char *bgp_state_names[] = { "Idle", "Connect", "Active", "OpenSent", "OpenConfirm", "Established", "Close" }; static char *bgp_state_names[] = { "Idle", "Connect", "Active", "OpenSent", "OpenConfirm", "Established", "Close" };
static char *bgp_err_classes[] = { "", "Error: ", "Socket: ", "Received: ", "BGP Error: ", "Automatic shutdown: ", ""}; static char *bgp_err_classes[] = { "", "Error: ", "Socket: ", "Received: ", "BGP Error: ", "Automatic shutdown: ", ""};
static char *bgp_misc_errors[] = { "", "Neighbor lost", "Invalid next hop", "Kernel MD5 auth failed" }; static char *bgp_misc_errors[] = { "", "Neighbor lost", "Invalid next hop", "Kernel MD5 auth failed", "No listening socket" };
static char *bgp_auto_errors[] = { "", "Route limit exceeded"}; static char *bgp_auto_errors[] = { "", "Route limit exceeded"};
static const char * static const char *

View file

@ -275,6 +275,7 @@ void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsi
#define BEM_NEIGHBOR_LOST 1 #define BEM_NEIGHBOR_LOST 1
#define BEM_INVALID_NEXT_HOP 2 #define BEM_INVALID_NEXT_HOP 2
#define BEM_INVALID_MD5 3 /* MD5 authentication kernel request failed (possibly not supported) */ #define BEM_INVALID_MD5 3 /* MD5 authentication kernel request failed (possibly not supported) */
#define BEM_NO_SOCKET 4
/* Automatic shutdown error codes */ /* Automatic shutdown error codes */