]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: peers: rely on srv->addr and remove peer->addr
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 30 Nov 2023 16:41:58 +0000 (17:41 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 21 Dec 2023 13:22:27 +0000 (14:22 +0100)
Similarly to the previous commit, we get rid of unused peer member.

peer->addr was only used to save a copy of the sever's addr at parsing
time. But instead of relying on an intermediate variable, we can actually
use server's address directly when initiating the peer session.

As with other streams created from server's settings (tcp/http, log, ring),
we should rely on srv->svc_port for the port part of the address. This
shouldn't change anything for peers since the address is fully resolved
at parsing time and runtime changes are not supported, but this should
help to make the code future-proof.

include/haproxy/peers-t.h
src/cfgparse.c
src/peers.c

index ed95b076093bb23c742a454ae0ba72f59af540bf..1b557f0266e221ffd52f8c31713a2e0a5a6e9e1e 100644 (file)
@@ -59,7 +59,6 @@ struct peer {
                int line;                 /* line where the section appears */
        } conf;                       /* config information */
        time_t last_change;
-       struct sockaddr_storage addr; /* peer address */
        unsigned int flags;           /* peer session flags */
        unsigned int statuscode;      /* current/last session status code */
        unsigned int reconnect;       /* next connect timer */
index 01a959514769c3812f3c9f11750924457326880c..fc1ab8a306cd82f2e22cc9916a93917b35f4523c 100644 (file)
@@ -745,7 +745,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                                        goto out;
                                }
                        }
-                       newpeer->addr = l->rx.addr;
                        cur_arg++;
                }
 
@@ -899,12 +898,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_WARN;
                }
 
-               /* If the peer address has just been parsed, let's copy it to <newpeer>
-                */
-               if (peer || !local_peer) {
-                       newpeer->addr = curpeers->peers_fe->srv->addr;
-               }
-
                HA_SPIN_INIT(&newpeer->lock);
 
                newpeer->srv = curpeers->peers_fe->srv;
index 5eefd1830e8f17606d004c6509e3cf07749b1149..5ed0e3f68e78b6eb895d1f4e783954feeba76cc4 100644 (file)
@@ -1083,8 +1083,9 @@ static int peer_session_init(struct appctx *appctx)
        struct stream *s;
        struct sockaddr_storage *addr = NULL;
 
-       if (!sockaddr_alloc(&addr, &peer->addr, sizeof(peer->addr)))
+       if (!sockaddr_alloc(&addr, &peer->srv->addr, sizeof(peer->srv->addr)))
                goto out_error;
+       set_host_port(addr, peer->srv->svc_port);
 
        if (appctx_finalize_startup(appctx, peer->peers->peers_fe, &BUF_NULL) == -1)
                goto out_free_addr;
@@ -3966,12 +3967,12 @@ static int peers_dump_peer(struct buffer *msg, struct appctx *appctx, struct pee
        struct stream *peer_s;
        struct shared_table *st;
 
-       addr_to_str(&peer->addr, pn, sizeof pn);
+       addr_to_str(&peer->srv->addr, pn, sizeof pn);
        chunk_appendf(msg, "  %p: id=%s(%s,%s) addr=%s:%d last_status=%s",
                      peer, peer->id,
                      peer->local ? "local" : "remote",
                      peer->appctx ? "active" : "inactive",
-                     pn, get_host_port(&peer->addr),
+                     pn, get_host_port(&peer->srv->addr),
                      statuscode_str(peer->statuscode));
 
        chunk_appendf(msg, " last_hdshk=%s\n",