mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: backend: switch to conn_get_{src,dst}() for port and address mapping
The backend connect code uses conn_get_{from,to}_addr to forward addresses in transparent mode and to map server ports, without really checking if the operation succeeds. In preparation of future changes, let's switch to conn_get_{src,dst}() and integrate status check for possible failures.
This commit is contained in:
parent
a0a4b09d08
commit
3cc01d84b3
@ -526,7 +526,7 @@ static inline int si_connect(struct stream_interface *si, struct connection *con
|
|||||||
|
|
||||||
/* needs src ip/port for logging */
|
/* needs src ip/port for logging */
|
||||||
if (si->flags & SI_FL_SRC_ADDR)
|
if (si->flags & SI_FL_SRC_ADDR)
|
||||||
conn_get_from_addr(conn);
|
conn_get_src(conn);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -678,12 +678,12 @@ int assign_server(struct stream *s)
|
|||||||
switch (s->be->lbprm.algo & BE_LB_PARM) {
|
switch (s->be->lbprm.algo & BE_LB_PARM) {
|
||||||
case BE_LB_HASH_SRC:
|
case BE_LB_HASH_SRC:
|
||||||
conn = objt_conn(strm_orig(s));
|
conn = objt_conn(strm_orig(s));
|
||||||
if (conn && conn->addr.from.ss_family == AF_INET) {
|
if (conn && conn_get_src(conn) && conn->addr.from.ss_family == AF_INET) {
|
||||||
srv = get_server_sh(s->be,
|
srv = get_server_sh(s->be,
|
||||||
(void *)&((struct sockaddr_in *)&conn->addr.from)->sin_addr,
|
(void *)&((struct sockaddr_in *)&conn->addr.from)->sin_addr,
|
||||||
4, prev_srv);
|
4, prev_srv);
|
||||||
}
|
}
|
||||||
else if (conn && conn->addr.from.ss_family == AF_INET6) {
|
else if (conn && conn_get_src(conn) && conn->addr.from.ss_family == AF_INET6) {
|
||||||
srv = get_server_sh(s->be,
|
srv = get_server_sh(s->be,
|
||||||
(void *)&((struct sockaddr_in6 *)&conn->addr.from)->sin6_addr,
|
(void *)&((struct sockaddr_in6 *)&conn->addr.from)->sin6_addr,
|
||||||
16, prev_srv);
|
16, prev_srv);
|
||||||
@ -840,9 +840,9 @@ int assign_server_address(struct stream *s, struct connection *srv_conn)
|
|||||||
* locally on multiple addresses at once. Nothing is done
|
* locally on multiple addresses at once. Nothing is done
|
||||||
* for AF_UNIX addresses.
|
* for AF_UNIX addresses.
|
||||||
*/
|
*/
|
||||||
conn_get_to_addr(cli_conn);
|
if (!conn_get_dst(cli_conn)) {
|
||||||
|
/* do nothing if we can't retrieve the address */
|
||||||
if (cli_conn->addr.to.ss_family == AF_INET) {
|
} else if (cli_conn->addr.to.ss_family == AF_INET) {
|
||||||
((struct sockaddr_in *)&srv_conn->addr.to)->sin_addr = ((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr;
|
((struct sockaddr_in *)&srv_conn->addr.to)->sin_addr = ((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr;
|
||||||
} else if (cli_conn->addr.to.ss_family == AF_INET6) {
|
} else if (cli_conn->addr.to.ss_family == AF_INET6) {
|
||||||
((struct sockaddr_in6 *)&srv_conn->addr.to)->sin6_addr = ((struct sockaddr_in6 *)&cli_conn->addr.to)->sin6_addr;
|
((struct sockaddr_in6 *)&srv_conn->addr.to)->sin6_addr = ((struct sockaddr_in6 *)&cli_conn->addr.to)->sin6_addr;
|
||||||
@ -854,14 +854,14 @@ int assign_server_address(struct stream *s, struct connection *srv_conn)
|
|||||||
if ((__objt_server(s->target)->flags & SRV_F_MAPPORTS) && cli_conn) {
|
if ((__objt_server(s->target)->flags & SRV_F_MAPPORTS) && cli_conn) {
|
||||||
int base_port;
|
int base_port;
|
||||||
|
|
||||||
conn_get_to_addr(cli_conn);
|
if (conn_get_dst(cli_conn)) {
|
||||||
|
/* First, retrieve the port from the incoming connection */
|
||||||
|
base_port = get_host_port(&cli_conn->addr.to);
|
||||||
|
|
||||||
/* First, retrieve the port from the incoming connection */
|
/* Second, assign the outgoing connection's port */
|
||||||
base_port = get_host_port(&cli_conn->addr.to);
|
base_port += get_host_port(&srv_conn->addr.to);
|
||||||
|
set_host_port(&srv_conn->addr.to, base_port);
|
||||||
/* Second, assign the outgoing connection's port */
|
}
|
||||||
base_port += get_host_port(&srv_conn->addr.to);
|
|
||||||
set_host_port(&srv_conn->addr.to, base_port);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (s->be->options & PR_O_DISPATCH) {
|
else if (s->be->options & PR_O_DISPATCH) {
|
||||||
@ -870,9 +870,8 @@ int assign_server_address(struct stream *s, struct connection *srv_conn)
|
|||||||
}
|
}
|
||||||
else if ((s->be->options & PR_O_TRANSP) && cli_conn) {
|
else if ((s->be->options & PR_O_TRANSP) && cli_conn) {
|
||||||
/* in transparent mode, use the original dest addr if no dispatch specified */
|
/* in transparent mode, use the original dest addr if no dispatch specified */
|
||||||
conn_get_to_addr(cli_conn);
|
if (conn_get_dst(cli_conn) &&
|
||||||
|
(cli_conn->addr.to.ss_family == AF_INET || cli_conn->addr.to.ss_family == AF_INET6))
|
||||||
if (cli_conn->addr.to.ss_family == AF_INET || cli_conn->addr.to.ss_family == AF_INET6)
|
|
||||||
srv_conn->addr.to = cli_conn->addr.to;
|
srv_conn->addr.to = cli_conn->addr.to;
|
||||||
}
|
}
|
||||||
else if (s->be->options & PR_O_HTTP_PROXY) {
|
else if (s->be->options & PR_O_HTTP_PROXY) {
|
||||||
@ -1046,7 +1045,7 @@ static void assign_tproxy_address(struct stream *s)
|
|||||||
case CO_SRC_TPROXY_CIP:
|
case CO_SRC_TPROXY_CIP:
|
||||||
/* FIXME: what can we do if the client connects in IPv6 or unix socket ? */
|
/* FIXME: what can we do if the client connects in IPv6 or unix socket ? */
|
||||||
cli_conn = objt_conn(strm_orig(s));
|
cli_conn = objt_conn(strm_orig(s));
|
||||||
if (cli_conn)
|
if (cli_conn && conn_get_src(cli_conn))
|
||||||
srv_conn->addr.from = cli_conn->addr.from;
|
srv_conn->addr.from = cli_conn->addr.from;
|
||||||
else
|
else
|
||||||
memset(&srv_conn->addr.from, 0, sizeof(srv_conn->addr.from));
|
memset(&srv_conn->addr.from, 0, sizeof(srv_conn->addr.from));
|
||||||
@ -1474,7 +1473,7 @@ int connect_server(struct stream *s)
|
|||||||
srv_conn->flags |= CO_FL_SEND_PROXY;
|
srv_conn->flags |= CO_FL_SEND_PROXY;
|
||||||
srv_conn->send_proxy_ofs = 1; /* must compute size */
|
srv_conn->send_proxy_ofs = 1; /* must compute size */
|
||||||
if (cli_conn)
|
if (cli_conn)
|
||||||
conn_get_to_addr(cli_conn);
|
conn_get_dst(cli_conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
assign_tproxy_address(s);
|
assign_tproxy_address(s);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user