From: Aurelien DARRAGON Date: Thu, 30 Nov 2023 16:41:58 +0000 (+0100) Subject: MINOR: peers: rely on srv->addr and remove peer->addr X-Git-Tag: v3.0-dev1~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6ae25858;p=thirdparty%2Fhaproxy.git MINOR: peers: rely on srv->addr and remove peer->addr 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. --- diff --git a/include/haproxy/peers-t.h b/include/haproxy/peers-t.h index ed95b07609..1b557f0266 100644 --- a/include/haproxy/peers-t.h +++ b/include/haproxy/peers-t.h @@ -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 */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 01a9595147..fc1ab8a306 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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 - */ - if (peer || !local_peer) { - newpeer->addr = curpeers->peers_fe->srv->addr; - } - HA_SPIN_INIT(&newpeer->lock); newpeer->srv = curpeers->peers_fe->srv; diff --git a/src/peers.c b/src/peers.c index 5eefd1830e..5ed0e3f68e 100644 --- a/src/peers.c +++ b/src/peers.c @@ -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",