From: Willy Tarreau Date: Sat, 27 Aug 2011 10:07:49 +0000 (+0200) Subject: [BUG] backend: risk of picking a wrong port when mapping is used with crossed families X-Git-Tag: v1.5-dev8~142 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=542a31d6c3f092d5073c029b1e218f1ab9407b44;p=thirdparty%2Fhaproxy.git [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. --- diff --git a/src/backend.c b/src/backend.c index 31e29d3d2c..d850ebf403 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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) {