From: Katerina Kubecova Date: Thu, 4 Sep 2025 13:31:38 +0000 (+0200) Subject: BGP: Storing the protocol accept-matching data in the request X-Git-Tag: v3.2.0~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f38b6e62c099c41f0410d45a6b561d8a77437cc;p=thirdparty%2Fbird.git BGP: Storing the protocol accept-matching data in the request The common TCP accept routine should not touch the protocol structure from outside, and it should get all the relevant information directly in the listen request. --- diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 7bd7f3743..96957db28 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -699,6 +699,12 @@ bgp_open(struct bgp_proto *p) (p->ipv4 ? IPA_NONE4 : IPA_NONE6); req->params.port = p->cf->local_port; req->params.flags = p->cf->free_bind ? SKF_FREEBIND : 0; + req->proto = p->p.proto; + req->local_ip = p->cf->local_ip; + req->iface = p->cf->iface; + req->remote_ip = p->remote_ip; + req->remote_range = p->cf->remote_range; + req->p = p; BGP_TRACE(D_EVENTS, "Requesting listen socket at %I%J port %u", req->params.addr, req->params.iface, req->params.port); @@ -1874,18 +1880,17 @@ bgp_find_proto(sock *sk) WALK_LIST(req, bs->requests) { - SKIP_BACK_DECLARE(struct bgp_proto, p, listen, req); - if ((p->p.proto == &proto_bgp) && - (ipa_equal(p->remote_ip, sk->daddr) || bgp_is_dynamic(p)) && - (!p->cf->remote_range || ipa_in_netX(sk->daddr, p->cf->remote_range)) && - (p->p.vrf == sk->vrf) && + if ((req->proto == &proto_bgp) && + (ipa_equal(req->remote_ip, sk->daddr) || ipa_zero(req->remote_ip)) && + (!req->remote_range || ipa_in_netX(sk->daddr, req->remote_range)) && + (req->params.vrf == sk->vrf) && (req->params.port == sk->sport) && - (!link || (p->cf->iface == sk->iface)) && - (ipa_zero(p->cf->local_ip) || ipa_equal(p->cf->local_ip, sk->saddr))) + (!link || (req->iface == sk->iface)) && + (ipa_zero(req->local_ip) || ipa_equal(req->local_ip, sk->saddr))) { - best = p; + best = req->p; - if (!bgp_is_dynamic(p)) + if (! ipa_zero(req->remote_ip)) break; } } @@ -3177,6 +3182,9 @@ bgp_reconfigure(struct proto *P, struct proto_config *CF) p->cf = new; p->hostname = proto_get_hostname(CF); + /* Fixup the listen request; all other changes cause a restart. */ + p->listen.remote_range = new->remote_range; + /* Check whether existing connections are compatible with required capabilities */ struct bgp_conn *ci = &p->incoming_conn; if (((ci->state == BS_OPENCONFIRM) || (ci->state == BS_ESTABLISHED)) && !bgp_check_capabilities(ci)) diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index dfc80e6c6..f1328eed2 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -377,7 +377,14 @@ struct bgp_session_close_ad { struct bgp_listen_request { node n; /* Node in bgp_socket / pending list */ struct bgp_socket *sock; /* Assigned socket */ - struct bgp_socket_params params; + struct bgp_socket_params params; /* Listening socket parameters */ + struct protocol *proto; /* Requesting protocol */ + ip_addr local_ip; /* Local IP address to match */ + struct iface *iface; /* Local interface to match */ + ip_addr remote_ip; /* Remote IP address to match */ + const net_addr *remote_range; /* Remote IP range to match */ + struct bgp_proto *p; + }; struct bgp_proto {