mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 17:51:53 +00:00
Make BGP protocol instance search a separate function
Thanks to Alexander V. Chernikov for the patch.
This commit is contained in:
parent
6264aad16f
commit
374917adcc
@ -712,6 +712,28 @@ bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing c
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bgp_incoming_connection - handle an incoming connection
|
* bgp_incoming_connection - handle an incoming connection
|
||||||
* @sk: TCP socket
|
* @sk: TCP socket
|
||||||
@ -727,18 +749,21 @@ bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing c
|
|||||||
static int
|
static int
|
||||||
bgp_incoming_connection(sock *sk, int dummy UNUSED)
|
bgp_incoming_connection(sock *sk, int dummy UNUSED)
|
||||||
{
|
{
|
||||||
struct proto_config *pc;
|
struct bgp_proto *p;
|
||||||
|
int acc, hops;
|
||||||
|
|
||||||
DBG("BGP: Incoming connection from %I port %d\n", sk->daddr, sk->dport);
|
DBG("BGP: Incoming connection from %I port %d\n", sk->daddr, sk->dport);
|
||||||
WALK_LIST(pc, config->protos)
|
p = bgp_find_proto(sk);
|
||||||
if (pc->protocol == &proto_bgp && pc->proto)
|
if (!p)
|
||||||
{
|
|
||||||
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)))
|
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/* We are in proper state and there is no other incoming connection */
|
/* We are in proper state and there is no other incoming connection */
|
||||||
int acc = (p->p.proto_state == PS_START || p->p.proto_state == PS_UP) &&
|
acc = (p->p.proto_state == PS_START || p->p.proto_state == PS_UP) &&
|
||||||
(p->start_state >= BSS_CONNECT) && (!p->incoming_conn.sk);
|
(p->start_state >= BSS_CONNECT) && (!p->incoming_conn.sk);
|
||||||
|
|
||||||
if (p->conn && (p->conn->state == BS_ESTABLISHED) && p->gr_ready)
|
if (p->conn && (p->conn->state == BS_ESTABLISHED) && p->gr_ready)
|
||||||
@ -754,9 +779,12 @@ bgp_incoming_connection(sock *sk, int dummy UNUSED)
|
|||||||
sk->dport, acc ? "accepted" : "rejected");
|
sk->dport, acc ? "accepted" : "rejected");
|
||||||
|
|
||||||
if (!acc)
|
if (!acc)
|
||||||
goto reject;
|
{
|
||||||
|
rfree(sk);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int hops = p->cf->multihop ? : 1;
|
hops = p->cf->multihop ? : 1;
|
||||||
|
|
||||||
if (sk_set_ttl(sk, p->cf->ttl_security ? 255 : hops) < 0)
|
if (sk_set_ttl(sk, p->cf->ttl_security ? 255 : hops) < 0)
|
||||||
goto err;
|
goto err;
|
||||||
@ -776,14 +804,6 @@ bgp_incoming_connection(sock *sk, int dummy UNUSED)
|
|||||||
rfree(sk);
|
rfree(sk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
reject:
|
|
||||||
rfree(sk);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bgp_listen_sock_err(sock *sk UNUSED, int err)
|
bgp_listen_sock_err(sock *sk UNUSED, int err)
|
||||||
|
Loading…
Reference in New Issue
Block a user