Commit 93d6bf38 authored by Martin Mareš's avatar Martin Mareš
Browse files

The bgp_list is gone. Incomming connections are now handled in a much

more straightforward manner by scanning the active configuration for
matching protocols.
parent 5d86aefb
......@@ -22,7 +22,6 @@
struct linpool *bgp_linpool; /* Global temporary pool */
static sock *bgp_listen_sk; /* Global listening socket */
static int bgp_counter; /* Number of protocol instances using the listening socket */
static list bgp_list; /* List of active BGP instances */
static char *bgp_state_names[] = { "Idle", "Connect", "Active", "OpenSent", "OpenConfirm", "Established" };
static void bgp_connect(struct bgp_proto *p);
......@@ -32,7 +31,6 @@ static void bgp_setup_listen_sk(void);
void
bgp_close(struct bgp_proto *p)
{
rem_node(&p->bgp_node);
ASSERT(bgp_counter);
bgp_counter--;
if (!bgp_counter)
......@@ -284,28 +282,35 @@ bgp_initiate(struct bgp_proto *p)
static int
bgp_incoming_connection(sock *sk, int dummy)
{
struct proto_config *pc;
node *n;
int match = 0;
DBG("BGP: Incoming connection from %I port %d\n", sk->daddr, sk->dport);
WALK_LIST(n, bgp_list)
{
struct bgp_proto *p = SKIP_BACK(struct bgp_proto, bgp_node, n);
if (ipa_equal(p->cf->remote_ip, sk->daddr) &&
(p->p.proto_state == PS_START || p->p.proto_state == PS_UP))
{
BGP_TRACE(D_EVENTS, "Incoming connection from %I port %d", sk->daddr, sk->dport);
if (p->incoming_conn.sk)
{
DBG("BGP: But one incoming connection already exists, how is that possible?\n");
break;
}
bgp_setup_conn(p, &p->incoming_conn);
bgp_setup_sk(p, &p->incoming_conn, sk);
bgp_send_open(&p->incoming_conn);
return 0;
}
}
log(L_AUTH "BGP: Unauthorized connect from %I port %d", sk->daddr, sk->dport);
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))
{
match = 1;
if (p->p.proto_state == PS_START || p->p.proto_state == PS_UP)
{
BGP_TRACE(D_EVENTS, "Incoming connection from %I port %d", sk->daddr, sk->dport);
if (p->incoming_conn.sk)
{
DBG("BGP: But one incoming connection already exists, how is that possible?\n");
break;
}
bgp_setup_conn(p, &p->incoming_conn);
bgp_setup_sk(p, &p->incoming_conn, sk);
bgp_send_open(&p->incoming_conn);
return 0;
}
}
}
if (!match)
log(L_AUTH "BGP: Unauthorized connect from %I port %d", sk->daddr, sk->dport);
rfree(sk);
return 0;
}
......@@ -395,12 +400,10 @@ bgp_start(struct proto *P)
p->incoming_conn.state = BS_IDLE;
p->startup_delay = 0;
if (!bgp_counter++)
init_list(&bgp_list);
bgp_counter++;
bgp_setup_listen_sk();
if (!bgp_linpool)
bgp_linpool = lp_new(&root_pool, 4080);
add_tail(&bgp_list, &p->bgp_node);
/*
* Before attempting to create the connection, we need to lock the
......
......@@ -53,7 +53,6 @@ struct bgp_conn {
struct bgp_proto {
struct proto p;
struct bgp_config *cf; /* Shortcut to BGP configuration */
node bgp_node; /* Node in global BGP protocol list */
unsigned local_as, remote_as;
int is_internal; /* Internal BGP connection (local_as == remote_as) */
u32 local_id; /* BGP identifier of this router */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment