BUG/MINOR: tcp-act: Don't forget to set the original port for IPv4 set-dst rule

If an IPv4 is set via a TCP/HTTP set-dst rule, the original port must be
preserved or set to 0 if the previous family was neither AF_INET nor
AF_INET6. The first case is not an issue because the port remains the
same. But if the previous family was, for instance, AF_UNIX, the port is not
set to 0 and have an undefined value.

This patch must be backported as far as 1.7.
This commit is contained in:
Christopher Faulet 2021-03-01 11:21:14 +01:00
parent 0de36adb5c
commit e01ca0fbc9

View File

@ -91,6 +91,7 @@ static enum act_return tcp_action_req_set_dst(struct act_rule *rule, struct prox
if (smp->data.type == SMP_T_IPV4) { if (smp->data.type == SMP_T_IPV4) {
((struct sockaddr_in *)cli_conn->dst)->sin_family = AF_INET; ((struct sockaddr_in *)cli_conn->dst)->sin_family = AF_INET;
((struct sockaddr_in *)cli_conn->dst)->sin_addr.s_addr = smp->data.u.ipv4.s_addr; ((struct sockaddr_in *)cli_conn->dst)->sin_addr.s_addr = smp->data.u.ipv4.s_addr;
((struct sockaddr_in *)cli_conn->dst)->sin_port = port;
} else if (smp->data.type == SMP_T_IPV6) { } else if (smp->data.type == SMP_T_IPV6) {
((struct sockaddr_in6 *)cli_conn->dst)->sin6_family = AF_INET6; ((struct sockaddr_in6 *)cli_conn->dst)->sin6_family = AF_INET6;
memcpy(&((struct sockaddr_in6 *)cli_conn->dst)->sin6_addr, &smp->data.u.ipv6, sizeof(struct in6_addr)); memcpy(&((struct sockaddr_in6 *)cli_conn->dst)->sin6_addr, &smp->data.u.ipv6, sizeof(struct in6_addr));