]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
BGP: Storing the protocol accept-matching data in the request
authorKaterina Kubecova <katerina.kubecova@nic.cz>
Thu, 4 Sep 2025 13:31:38 +0000 (15:31 +0200)
committerMaria Matejka <mq@ucw.cz>
Thu, 13 Nov 2025 11:25:03 +0000 (12:25 +0100)
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.

proto/bgp/bgp.c
proto/bgp/bgp.h

index 7bd7f37431cf109302a9b5663212090efdcb3fc4..96957db2834379261bbfc90e49e9def47392e55f 100644 (file)
@@ -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))
index dfc80e6c678457d9097a8f1c7cc7be25d0e403c2..f1328eed25e9f73c7aa179e2bc5b2497ae42479b 100644 (file)
@@ -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 {