src/backend.c
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)
		src = &srv->conn_src;
	else if (s->be->conn_src.opts & CO_SRC_BIND)
		src = &s->be->conn_src;
	else
		return;

	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;

			/* 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));
			}
			b_adv(s->req->buf, rewind);
		}
		break;
	default:
		memset(&s->req->cons->conn->addr.from, 0, sizeof(s->req->cons->conn->addr.from));
	}
#endif
}
/* If an explicit source binding is specified on the server and/or backend, and
 * this source makes use of the transparent proxy, then it is extracted now and
 * assigned to the session's req->cons->addr.from entry.
 */
If an explicit source binding is specified on the server and/or backend, and
this source makes use of the transparent proxy, then it is extracted now and
assigned to the session's req->cons->addr.from entry.
If an explicit source binding is specified on the server and / or backend and this source makes use of the transparent proxy then it is extracted now and assigned to the session ' s req - > cons - > addr . from entry .
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)
		src = &srv->conn_src;
	else if (s->be->conn_src.opts & CO_SRC_BIND)
		src = &s->be->conn_src;
	else
		return;
	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:
		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;
			((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));
			}
			b_adv(s->req->buf, rewind);
		}
		break;
	default:
		memset(&s->req->cons->conn->addr.from, 0, sizeof(s->req->cons->conn->addr.from));
	}
#endif
}
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 ) src = & srv -> conn_src ; else if ( s -> be -> conn_src . opts & CO_SRC_BIND ) src = & s -> be -> conn_src ; else return ; 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 : 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 ; ( ( 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 ) ) ; } b_adv ( s -> req -> buf , rewind ) ; } break ; default : memset ( & s -> req -> cons -> conn -> addr . from , 0 , sizeof ( s -> req -> cons -> conn -> addr . from ) ) ; } #endif }
If an explicit source binding is specified on the server and/or backend, and
 this source makes use of the transparent proxy, then it is extracted now and
 assigned to the session's req->cons->addr.from entry.
If an explicit source binding is specified on the server and / or backend and this source makes use of the transparent proxy then it is extracted now and assigned to the session ' s req - > cons - > addr . from entry .
/* FIXME: what can we do if the client connects in IPv6 or unix socket ? */ /* bind to the IP in a header */