mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-31 07:37:54 +00:00
CLEANUP: backend: use the same tproxy address selection code for servers and backends
This is just like previous commit, but for the backend this time. All this code did not need to remain duplicated. These are 500 more bytes shaved off.
This commit is contained in:
parent
a4380b4f15
commit
9cd7d6ccfe
@ -884,74 +884,46 @@ static void assign_tproxy_address(struct session *s)
|
||||
{
|
||||
#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY)
|
||||
struct server *srv = objt_server(s->target);
|
||||
struct conn_src *src;
|
||||
|
||||
if (srv && srv->conn_src.opts & CO_SRC_BIND) {
|
||||
switch (srv->conn_src.opts & CO_SRC_TPROXY_MASK) {
|
||||
case CO_SRC_TPROXY_ADDR:
|
||||
s->req->cons->conn->addr.from = srv->conn_src.tproxy_addr;
|
||||
break;
|
||||
case CO_SRC_TPROXY_CLI:
|
||||
case CO_SRC_TPROXY_CIP:
|
||||
/* FIXME: what can we do if the client connects in IPv6 or unix socket ? */
|
||||
s->req->cons->conn->addr.from = s->req->prod->conn->addr.from;
|
||||
break;
|
||||
case CO_SRC_TPROXY_DYN:
|
||||
if (srv->conn_src.bind_hdr_occ) {
|
||||
char *vptr;
|
||||
int vlen;
|
||||
int rewind;
|
||||
if (srv && srv->conn_src.opts & CO_SRC_BIND)
|
||||
src = &srv->conn_src;
|
||||
else if (s->be->conn_src.opts & CO_SRC_BIND)
|
||||
src = &s->be->conn_src;
|
||||
else
|
||||
return;
|
||||
|
||||
/* bind to the IP in a header */
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_port = 0;
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_addr.s_addr = 0;
|
||||
switch (src->opts & CO_SRC_TPROXY_MASK) {
|
||||
case CO_SRC_TPROXY_ADDR:
|
||||
s->req->cons->conn->addr.from = src->tproxy_addr;
|
||||
break;
|
||||
case CO_SRC_TPROXY_CLI:
|
||||
case CO_SRC_TPROXY_CIP:
|
||||
/* FIXME: what can we do if the client connects in IPv6 or unix socket ? */
|
||||
s->req->cons->conn->addr.from = s->req->prod->conn->addr.from;
|
||||
break;
|
||||
case CO_SRC_TPROXY_DYN:
|
||||
if (src->bind_hdr_occ) {
|
||||
char *vptr;
|
||||
int vlen;
|
||||
int rewind;
|
||||
|
||||
b_rew(s->req->buf, rewind = s->req->buf->o);
|
||||
if (http_get_hdr(&s->txn.req, srv->conn_src.bind_hdr_name, srv->conn_src.bind_hdr_len,
|
||||
&s->txn.hdr_idx, srv->conn_src.bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_addr.s_addr =
|
||||
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
||||
}
|
||||
b_adv(s->req->buf, rewind);
|
||||
/* bind to the IP in a header */
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_port = 0;
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_addr.s_addr = 0;
|
||||
|
||||
b_rew(s->req->buf, rewind = s->req->buf->o);
|
||||
if (http_get_hdr(&s->txn.req, src->bind_hdr_name, src->bind_hdr_len,
|
||||
&s->txn.hdr_idx, src->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_addr.s_addr =
|
||||
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
memset(&s->req->cons->conn->addr.from, 0, sizeof(s->req->cons->conn->addr.from));
|
||||
}
|
||||
}
|
||||
else if (s->be->conn_src.opts & CO_SRC_BIND) {
|
||||
switch (s->be->conn_src.opts & CO_SRC_TPROXY_MASK) {
|
||||
case CO_SRC_TPROXY_ADDR:
|
||||
s->req->cons->conn->addr.from = s->be->conn_src.tproxy_addr;
|
||||
break;
|
||||
case CO_SRC_TPROXY_CLI:
|
||||
case CO_SRC_TPROXY_CIP:
|
||||
/* FIXME: what can we do if the client connects in IPv6 or socket unix? */
|
||||
s->req->cons->conn->addr.from = s->req->prod->conn->addr.from;
|
||||
break;
|
||||
case CO_SRC_TPROXY_DYN:
|
||||
if (s->be->conn_src.bind_hdr_occ) {
|
||||
char *vptr;
|
||||
int vlen;
|
||||
int rewind;
|
||||
|
||||
/* bind to the IP in a header */
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_port = 0;
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_addr.s_addr = 0;
|
||||
|
||||
b_rew(s->req->buf, rewind = s->req->buf->o);
|
||||
if (http_get_hdr(&s->txn.req, s->be->conn_src.bind_hdr_name, s->be->conn_src.bind_hdr_len,
|
||||
&s->txn.hdr_idx, s->be->conn_src.bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||
((struct sockaddr_in *)&s->req->cons->conn->addr.from)->sin_addr.s_addr =
|
||||
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
||||
}
|
||||
b_adv(s->req->buf, rewind);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
memset(&s->req->cons->conn->addr.from, 0, sizeof(s->req->cons->conn->addr.from));
|
||||
b_adv(s->req->buf, rewind);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
memset(&s->req->cons->conn->addr.from, 0, sizeof(s->req->cons->conn->addr.from));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user