mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
[BUG] backend: risk of picking a wrong port when mapping is used with crossed families
A similar issue as the previous one causes port mapping to fail in some combinations of client and server address families. Using the macros fixes the issue.
This commit is contained in:
parent
48da04a6af
commit
542a31d6c3
@ -700,22 +700,11 @@ int assign_server_address(struct session *s)
|
||||
get_frt_addr(s);
|
||||
|
||||
/* First, retrieve the port from the incoming connection */
|
||||
if (s->req->prod->addr.c.to.ss_family == AF_INET)
|
||||
base_port = ntohs(((struct sockaddr_in *)&s->req->prod->addr.c.to)->sin_port);
|
||||
else if (s->req->prod->addr.c.to.ss_family == AF_INET6)
|
||||
base_port = ntohs(((struct sockaddr_in6 *)&s->req->prod->addr.c.to)->sin6_port);
|
||||
else
|
||||
base_port = 0;
|
||||
base_port = get_host_port(&s->req->prod->addr.c.to);
|
||||
|
||||
/* Second, assign the outgoing connection's port */
|
||||
if (s->req->cons->addr.c.to.ss_family == AF_INET) {
|
||||
((struct sockaddr_in *)&s->req->cons->addr.s.to)->sin_port =
|
||||
htons(base_port + ntohs(((struct sockaddr_in *)&s->req->cons->addr.s.to)->sin_port));
|
||||
}
|
||||
else if (s->req->prod->addr.c.to.ss_family == AF_INET6) {
|
||||
((struct sockaddr_in6 *)&s->req->cons->addr.s.to)->sin6_port =
|
||||
htons(base_port + ntohs(((struct sockaddr_in6 *)&s->req->cons->addr.s.to)->sin6_port));
|
||||
}
|
||||
base_port += get_host_port(&s->req->prod->addr.s.to);
|
||||
set_host_port(&s->req->cons->addr.s.to, base_port);
|
||||
}
|
||||
}
|
||||
else if (s->be->options & PR_O_DISPATCH) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user