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.
This commit is contained in:
Aurelien DARRAGON 2023-11-30 17:41:58 +01:00 committed by Christopher Faulet
parent 372d3e2934
commit f6ae25858d
3 changed files with 4 additions and 11 deletions

View 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 */

View 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;

View 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",