]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[BUG] backend: risk of picking a wrong port when mapping is used with crossed families
authorWilly Tarreau <w@1wt.eu>
Sat, 27 Aug 2011 10:07:49 +0000 (12:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 27 Aug 2011 10:07:49 +0000 (12:07 +0200)
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.

src/backend.c

index 31e29d3d2ce11f1f2ef7a30477ace6cb4ca36809..d850ebf403492aec1998b0cdc5d0cd7e627128f3 100644 (file)
@@ -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) {