From 6471afb43d46fdb31da5344209381fa4713966b8 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 23 Sep 2011 10:54:59 +0200 Subject: MINOR: remove the client/server side distinction in SI addresses Stream interfaces used to distinguish between client and server addresses because they were previously of different types (sockaddr_storage for the client, sockaddr_in for the server). This is not the case anymore, and this distinction is confusing at best and has caused a number of regressions to be introduced in the process of converting everything to full-ipv6. We can now remove this and have a much cleaner code. --- include/proto/proto_tcp.h | 6 ++-- include/types/stream_interface.h | 14 +++------- src/backend.c | 56 +++++++++++++++++++------------------- src/dumpstats.c | 8 +++--- src/frontend.c | 42 ++++++++++++++-------------- src/log.c | 6 ++-- src/peers.c | 2 +- src/proto_http.c | 54 ++++++++++++++++++------------------ src/proto_tcp.c | 50 +++++++++++++++++----------------- src/session.c | 6 ++-- src/stream_sock.c | 2 +- 11 files changed, 120 insertions(+), 126 deletions(-) diff --git a/include/proto/proto_tcp.h b/include/proto/proto_tcp.h index ae23c72..1665f15 100644 --- a/include/proto/proto_tcp.h +++ b/include/proto/proto_tcp.h @@ -43,12 +43,12 @@ int tcp_exec_req_rules(struct session *s); */ static inline struct stktable_key *tcp_src_to_stktable_key(struct session *s) { - switch (s->si[0].addr.c.from.ss_family) { + switch (s->si[0].addr.from.ss_family) { case AF_INET: - static_table_key.key = (void *)&((struct sockaddr_in *)&s->si[0].addr.c.from)->sin_addr; + static_table_key.key = (void *)&((struct sockaddr_in *)&s->si[0].addr.from)->sin_addr; break; case AF_INET6: - static_table_key.key = (void *)&((struct sockaddr_in6 *)&s->si[0].addr.c.from)->sin6_addr; + static_table_key.key = (void *)&((struct sockaddr_in6 *)&s->si[0].addr.from)->sin6_addr; break; } return &static_table_key; diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h index 27a2f97..4f0bfa2 100644 --- a/include/types/stream_interface.h +++ b/include/types/stream_interface.h @@ -178,16 +178,10 @@ struct stream_interface { } cli; } ctx; /* used by stats I/O handlers to dump the stats */ } applet; - union { - struct { - struct sockaddr_storage from; /* the client address */ - struct sockaddr_storage to; /* the address reached by the client if SN_FRT_ADDR_SET is set */ - } c; /* client side */ - struct { - struct sockaddr_storage from; /* the address to spoof when connecting to the server (transparent mode) */ - struct sockaddr_storage to; /* the address to connect to */ - } s; /* server side */ - } addr; /* addresses of the remote side */ + struct { + struct sockaddr_storage from; /* client address, or address to spoof when connecting to the server */ + struct sockaddr_storage to; /* address reached by the client if SN_FRT_ADDR_SET is set, or address to connect to */ + } addr; /* addresses of the remote side, client for producer and server for consumer */ }; /* An applet designed to run in a stream interface */ diff --git a/src/backend.c b/src/backend.c index 0fa28f0..248bf1e 100644 --- a/src/backend.c +++ b/src/backend.c @@ -532,9 +532,9 @@ int assign_server(struct session *s) switch (s->be->lbprm.algo & BE_LB_PARM) { case BE_LB_HASH_SRC: - if (s->req->prod->addr.c.from.ss_family == AF_INET) + if (s->req->prod->addr.from.ss_family == AF_INET) len = 4; - else if (s->req->prod->addr.c.from.ss_family == AF_INET6) + else if (s->req->prod->addr.from.ss_family == AF_INET6) len = 16; else { /* unknown IP family */ @@ -543,7 +543,7 @@ int assign_server(struct session *s) } srv = get_server_sh(s->be, - (void *)&((struct sockaddr_in *)&s->req->prod->addr.c.from)->sin_addr, + (void *)&((struct sockaddr_in *)&s->req->prod->addr.from)->sin_addr, len); break; @@ -620,7 +620,7 @@ int assign_server(struct session *s) set_target_proxy(&s->target, s->be); } else if ((s->be->options & PR_O_HTTP_PROXY) && - is_addr(&s->req->cons->addr.s.to)) { + is_addr(&s->req->cons->addr.to)) { /* in proxy mode, we need a valid destination address */ set_target_proxy(&s->target, s->be); } @@ -674,9 +674,9 @@ int assign_server_address(struct session *s) if (!(s->flags & SN_ASSIGNED)) return SRV_STATUS_INTERNAL; - s->req->cons->addr.s.to = target_srv(&s->target)->addr; + s->req->cons->addr.to = target_srv(&s->target)->addr; - if (!is_addr(&s->req->cons->addr.s.to)) { + if (!is_addr(&s->req->cons->addr.to)) { /* if the server has no address, we use the same address * the client asked, which is handy for remapping ports * locally on multiple addresses at once. @@ -684,10 +684,10 @@ int assign_server_address(struct session *s) if (!(s->be->options & PR_O_TRANSP) && !(s->flags & SN_FRT_ADDR_SET)) get_frt_addr(s); - if (s->req->prod->addr.c.to.ss_family == AF_INET) { - ((struct sockaddr_in *)&s->req->cons->addr.s.to)->sin_addr = ((struct sockaddr_in *)&s->req->prod->addr.c.to)->sin_addr; - } else if (s->req->prod->addr.c.to.ss_family == AF_INET6) { - ((struct sockaddr_in6 *)&s->req->cons->addr.s.to)->sin6_addr = ((struct sockaddr_in6 *)&s->req->prod->addr.c.to)->sin6_addr; + if (s->req->prod->addr.to.ss_family == AF_INET) { + ((struct sockaddr_in *)&s->req->cons->addr.to)->sin_addr = ((struct sockaddr_in *)&s->req->prod->addr.to)->sin_addr; + } else if (s->req->prod->addr.to.ss_family == AF_INET6) { + ((struct sockaddr_in6 *)&s->req->cons->addr.to)->sin6_addr = ((struct sockaddr_in6 *)&s->req->prod->addr.to)->sin6_addr; } } @@ -700,24 +700,24 @@ int assign_server_address(struct session *s) get_frt_addr(s); /* First, retrieve the port from the incoming connection */ - base_port = get_host_port(&s->req->prod->addr.c.to); + base_port = get_host_port(&s->req->prod->addr.to); /* Second, assign the outgoing connection's port */ - base_port += get_host_port(&s->req->cons->addr.s.to); - set_host_port(&s->req->cons->addr.s.to, base_port); + base_port += get_host_port(&s->req->cons->addr.to); + set_host_port(&s->req->cons->addr.to, base_port); } } else if (s->be->options & PR_O_DISPATCH) { /* connect to the defined dispatch addr */ - s->req->cons->addr.s.to = s->be->dispatch_addr; + s->req->cons->addr.to = s->be->dispatch_addr; } else if (s->be->options & PR_O_TRANSP) { /* in transparent mode, use the original dest addr if no dispatch specified */ if (!(s->flags & SN_FRT_ADDR_SET)) get_frt_addr(s); - if (s->req->prod->addr.c.to.ss_family == AF_INET || s->req->prod->addr.c.to.ss_family == AF_INET6) { - memcpy(&s->req->cons->addr.s.to, &s->req->prod->addr.c.to, MIN(sizeof(s->req->cons->addr.s.to), sizeof(s->req->prod->addr.c.to))); + if (s->req->prod->addr.to.ss_family == AF_INET || s->req->prod->addr.to.ss_family == AF_INET6) { + memcpy(&s->req->cons->addr.to, &s->req->prod->addr.to, MIN(sizeof(s->req->cons->addr.to), sizeof(s->req->prod->addr.to))); } /* when we support IPv6 on the backend, we may add other tests */ //qfprintf(stderr, "Cannot get original server address.\n"); @@ -861,7 +861,7 @@ int assign_server_and_queue(struct session *s) /* 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.s.from entry. + * assigned to the session's req->cons->addr.from entry. */ static void assign_tproxy_address(struct session *s) { @@ -871,18 +871,18 @@ static void assign_tproxy_address(struct session *s) if (srv && srv->state & SRV_BIND_SRC) { switch (srv->state & SRV_TPROXY_MASK) { case SRV_TPROXY_ADDR: - s->req->cons->addr.s.from = srv->tproxy_addr; + s->req->cons->addr.from = srv->tproxy_addr; break; case SRV_TPROXY_CLI: case SRV_TPROXY_CIP: /* FIXME: what can we do if the client connects in IPv6 or unix socket ? */ - s->req->cons->addr.s.from = s->req->prod->addr.c.from; + s->req->cons->addr.from = s->req->prod->addr.from; break; case SRV_TPROXY_DYN: if (srv->bind_hdr_occ) { /* bind to the IP in a header */ - ((struct sockaddr_in *)&s->req->cons->addr.s.from)->sin_port = 0; - ((struct sockaddr_in *)&s->req->cons->addr.s.from)->sin_addr.s_addr = + ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0; + ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = htonl(get_ip_from_hdr2(&s->txn.req, srv->bind_hdr_name, srv->bind_hdr_len, @@ -891,24 +891,24 @@ static void assign_tproxy_address(struct session *s) } break; default: - memset(&s->req->cons->addr.s.from, 0, sizeof(s->req->cons->addr.s.from)); + memset(&s->req->cons->addr.from, 0, sizeof(s->req->cons->addr.from)); } } else if (s->be->options & PR_O_BIND_SRC) { switch (s->be->options & PR_O_TPXY_MASK) { case PR_O_TPXY_ADDR: - s->req->cons->addr.s.from = s->be->tproxy_addr; + s->req->cons->addr.from = s->be->tproxy_addr; break; case PR_O_TPXY_CLI: case PR_O_TPXY_CIP: /* FIXME: what can we do if the client connects in IPv6 or socket unix? */ - s->req->cons->addr.s.from = s->req->prod->addr.c.from; + s->req->cons->addr.from = s->req->prod->addr.from; break; case PR_O_TPXY_DYN: if (s->be->bind_hdr_occ) { /* bind to the IP in a header */ - ((struct sockaddr_in *)&s->req->cons->addr.s.from)->sin_port = 0; - ((struct sockaddr_in *)&s->req->cons->addr.s.from)->sin_addr.s_addr = + ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0; + ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = htonl(get_ip_from_hdr2(&s->txn.req, s->be->bind_hdr_name, s->be->bind_hdr_len, @@ -917,7 +917,7 @@ static void assign_tproxy_address(struct session *s) } break; default: - memset(&s->req->cons->addr.s.from, 0, sizeof(s->req->cons->addr.s.from)); + memset(&s->req->cons->addr.from, 0, sizeof(s->req->cons->addr.from)); } } #endif @@ -926,7 +926,7 @@ static void assign_tproxy_address(struct session *s) /* * This function initiates a connection to the server assigned to this session - * (s->target, s->req->cons->addr.s.to). It will assign a server if none + * (s->target, s->req->cons->addr.to). It will assign a server if none * is assigned yet. * It can return one of : * - SN_ERR_NONE if everything's OK diff --git a/src/dumpstats.c b/src/dumpstats.c index d976e07..a15b15b 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -3204,11 +3204,11 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si) sess->uniq_id, sess->listener->proto->name); - switch (addr_to_str(&sess->si[0].addr.c.from, pn, sizeof(pn))) { + switch (addr_to_str(&sess->si[0].addr.from, pn, sizeof(pn))) { case AF_INET: case AF_INET6: chunk_printf(&msg, " source=%s:%d\n", - pn, get_host_port(&sess->si[0].addr.c.from)); + pn, get_host_port(&sess->si[0].addr.from)); break; case AF_UNIX: chunk_printf(&msg, " source=unix:%d\n", sess->listener->luid); @@ -3432,13 +3432,13 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si) curr_sess->listener->proto->name); - switch (addr_to_str(&curr_sess->si[0].addr.c.from, pn, sizeof(pn))) { + switch (addr_to_str(&curr_sess->si[0].addr.from, pn, sizeof(pn))) { case AF_INET: case AF_INET6: chunk_printf(&msg, " src=%s:%d fe=%s be=%s srv=%s", pn, - get_host_port(&curr_sess->si[0].addr.c.from), + get_host_port(&curr_sess->si[0].addr.from), curr_sess->fe->id, (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "", target_srv(&curr_sess->target) ? target_srv(&curr_sess->target)->id : "" diff --git a/src/frontend.c b/src/frontend.c index 4ed4862..548cd02 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -50,10 +50,10 @@ */ void get_frt_addr(struct session *s) { - socklen_t namelen = sizeof(s->si[0].addr.c.to); + socklen_t namelen = sizeof(s->si[0].addr.to); - if (get_original_dst(s->si[0].fd, (struct sockaddr_in *)&s->si[0].addr.c.to, &namelen) == -1) - getsockname(s->si[0].fd, (struct sockaddr *)&s->si[0].addr.c.to, &namelen); + if (get_original_dst(s->si[0].fd, (struct sockaddr_in *)&s->si[0].addr.to, &namelen) == -1) + getsockname(s->si[0].fd, (struct sockaddr *)&s->si[0].addr.to, &namelen); s->flags |= SN_FRT_ADDR_SET; } @@ -157,13 +157,13 @@ int frontend_accept(struct session *s) if (!(s->flags & SN_FRT_ADDR_SET)) get_frt_addr(s); - switch (addr_to_str(&s->req->prod->addr.c.from, pn, sizeof(pn))) { + switch (addr_to_str(&s->req->prod->addr.from, pn, sizeof(pn))) { case AF_INET: case AF_INET6: - addr_to_str(&s->req->prod->addr.c.to, sn, sizeof(sn)); + addr_to_str(&s->req->prod->addr.to, sn, sizeof(sn)); send_log(s->fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n", - pn, get_host_port(&s->req->prod->addr.c.from), - sn, get_host_port(&s->req->prod->addr.c.to), + pn, get_host_port(&s->req->prod->addr.from), + sn, get_host_port(&s->req->prod->addr.to), s->fe->id, (s->fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP"); break; case AF_UNIX: @@ -183,12 +183,12 @@ int frontend_accept(struct session *s) if (!(s->flags & SN_FRT_ADDR_SET)) get_frt_addr(s); - switch (addr_to_str(&s->req->prod->addr.c.from, pn, sizeof(pn))) { + switch (addr_to_str(&s->req->prod->addr.from, pn, sizeof(pn))) { case AF_INET: case AF_INET6: len = sprintf(trash, "%08x:%s.accept(%04x)=%04x from [%s:%d]\n", s->uniq_id, s->fe->id, (unsigned short)s->listener->fd, (unsigned short)cfd, - pn, get_host_port(&s->req->prod->addr.c.from)); + pn, get_host_port(&s->req->prod->addr.from)); break; case AF_UNIX: /* UNIX socket, only the destination is known */ @@ -329,13 +329,13 @@ int frontend_decode_proxy_request(struct session *s, struct buffer *req, int an_ goto fail; /* update the session's addresses and mark them set */ - ((struct sockaddr_in *)&s->si[0].addr.c.from)->sin_family = AF_INET; - ((struct sockaddr_in *)&s->si[0].addr.c.from)->sin_addr.s_addr = htonl(src3); - ((struct sockaddr_in *)&s->si[0].addr.c.from)->sin_port = htons(sport); + ((struct sockaddr_in *)&s->si[0].addr.from)->sin_family = AF_INET; + ((struct sockaddr_in *)&s->si[0].addr.from)->sin_addr.s_addr = htonl(src3); + ((struct sockaddr_in *)&s->si[0].addr.from)->sin_port = htons(sport); - ((struct sockaddr_in *)&s->si[0].addr.c.to)->sin_family = AF_INET; - ((struct sockaddr_in *)&s->si[0].addr.c.to)->sin_addr.s_addr = htonl(dst3); - ((struct sockaddr_in *)&s->si[0].addr.c.to)->sin_port = htons(dport); + ((struct sockaddr_in *)&s->si[0].addr.to)->sin_family = AF_INET; + ((struct sockaddr_in *)&s->si[0].addr.to)->sin_addr.s_addr = htonl(dst3); + ((struct sockaddr_in *)&s->si[0].addr.to)->sin_port = htons(dport); s->flags |= SN_FRT_ADDR_SET; } @@ -391,13 +391,13 @@ int frontend_decode_proxy_request(struct session *s, struct buffer *req, int an_ goto fail; /* update the session's addresses and mark them set */ - ((struct sockaddr_in6 *)&s->si[0].addr.c.from)->sin6_family = AF_INET6; - memcpy(&((struct sockaddr_in6 *)&s->si[0].addr.c.from)->sin6_addr, &src3, sizeof(struct in6_addr)); - ((struct sockaddr_in6 *)&s->si[0].addr.c.from)->sin6_port = htons(sport); + ((struct sockaddr_in6 *)&s->si[0].addr.from)->sin6_family = AF_INET6; + memcpy(&((struct sockaddr_in6 *)&s->si[0].addr.from)->sin6_addr, &src3, sizeof(struct in6_addr)); + ((struct sockaddr_in6 *)&s->si[0].addr.from)->sin6_port = htons(sport); - ((struct sockaddr_in6 *)&s->si[0].addr.c.to)->sin6_family = AF_INET6; - memcpy(&((struct sockaddr_in6 *)&s->si[0].addr.c.to)->sin6_addr, &dst3, sizeof(struct in6_addr)); - ((struct sockaddr_in6 *)&s->si[0].addr.c.to)->sin6_port = htons(dport); + ((struct sockaddr_in6 *)&s->si[0].addr.to)->sin6_family = AF_INET6; + memcpy(&((struct sockaddr_in6 *)&s->si[0].addr.to)->sin6_addr, &dst3, sizeof(struct in6_addr)); + ((struct sockaddr_in6 *)&s->si[0].addr.to)->sin6_port = htons(dport); s->flags |= SN_FRT_ADDR_SET; } else { diff --git a/src/log.c b/src/log.c index b62eeda..162ff48 100644 --- a/src/log.c +++ b/src/log.c @@ -317,7 +317,7 @@ void tcp_sess_log(struct session *s) if (!err && (fe->options2 & PR_O2_NOLOGNORM)) return; - addr_to_str(&s->si[0].addr.c.from, pn, sizeof(pn)); + addr_to_str(&s->si[0].addr.from, pn, sizeof(pn)); get_localtime(s->logs.tv_accept.tv_sec, &tm); if (fe->logfac1 < 0 && fe->logfac2 < 0) @@ -347,8 +347,8 @@ void tcp_sess_log(struct session *s) send_log(prx_log, level, "%s:%d [%02d/%s/%04d:%02d:%02d:%02d.%03d]" " %s %s/%s %ld/%ld/%s%ld %s%lld" " %c%c %d/%d/%d/%d/%s%u %ld/%ld\n", - s->si[0].addr.c.from.ss_family == AF_UNIX ? "unix" : pn, - s->si[0].addr.c.from.ss_family == AF_UNIX ? s->listener->luid : get_host_port(&s->si[0].addr.c.from), + s->si[0].addr.from.ss_family == AF_UNIX ? "unix" : pn, + s->si[0].addr.from.ss_family == AF_UNIX ? s->listener->luid : get_host_port(&s->si[0].addr.from), tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)s->logs.tv_accept.tv_usec/1000, fe->id, be->id, svid, diff --git a/src/peers.c b/src/peers.c index bbe99d4..ac24e12 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1138,7 +1138,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio t->context = s; t->nice = l->nice; - memcpy(&s->si[1].addr.s.to, &peer->addr, sizeof(s->si[1].addr.s.to)); + memcpy(&s->si[1].addr.to, &peer->addr, sizeof(s->si[1].addr.to)); s->task = t; s->listener = l; diff --git a/src/proto_http.c b/src/proto_http.c index c39fb94..3ae46bc 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -870,7 +870,7 @@ void http_sess_clflog(struct session *s) (s->req->cons->conn_retries != be->conn_retries) || txn->status >= 500; - if (addr_to_str(&s->req->prod->addr.c.from, pn, sizeof(pn)) == AF_UNIX) + if (addr_to_str(&s->req->prod->addr.from, pn, sizeof(pn)) == AF_UNIX) snprintf(pn, sizeof(pn), "unix:%d", s->listener->luid); get_gmtime(s->logs.accept_date.tv_sec, &tm); @@ -911,8 +911,8 @@ void http_sess_clflog(struct session *s) w = snprintf(h, sizeof(tmpline) - (h - tmpline), " %d %03d", - s->req->prod->addr.c.from.ss_family == AF_UNIX ? s->listener->luid : - get_host_port(&s->req->prod->addr.c.from), + s->req->prod->addr.from.ss_family == AF_UNIX ? s->listener->luid : + get_host_port(&s->req->prod->addr.from), (int)s->logs.accept_date.tv_usec/1000); if (w < 0 || w >= sizeof(tmpline) - (h - tmpline)) goto trunc; @@ -1104,7 +1104,7 @@ void http_sess_log(struct session *s) if (prx_log->options2 & PR_O2_CLFLOG) return http_sess_clflog(s); - if (addr_to_str(&s->req->prod->addr.c.from, pn, sizeof(pn)) == AF_UNIX) + if (addr_to_str(&s->req->prod->addr.from, pn, sizeof(pn)) == AF_UNIX) snprintf(pn, sizeof(pn), "unix:%d", s->listener->luid); get_localtime(s->logs.accept_date.tv_sec, &tm); @@ -1179,9 +1179,9 @@ void http_sess_log(struct session *s) "%s:%d [%02d/%s/%04d:%02d:%02d:%02d.%03d]" " %s %s/%s %d/%ld/%ld/%ld/%s%ld %d %s%lld" " %s %s %c%c%c%c %d/%d/%d/%d/%s%u %ld/%ld%s\n", - (s->req->prod->addr.c.from.ss_family == AF_UNIX) ? "unix" : pn, - (s->req->prod->addr.c.from.ss_family == AF_UNIX) ? s->listener->luid : - get_host_port(&s->req->prod->addr.c.from), + (s->req->prod->addr.from.ss_family == AF_UNIX) ? "unix" : pn, + (s->req->prod->addr.from.ss_family == AF_UNIX) ? s->listener->luid : + get_host_port(&s->req->prod->addr.from), tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)s->logs.accept_date.tv_usec/1000, fe->id, be->id, svid, @@ -3513,7 +3513,7 @@ int http_process_request(struct session *s, struct buffer *req, int an_bit) * parsing incoming request. */ if ((s->be->options & PR_O_HTTP_PROXY) && !(s->flags & SN_ADDR_SET)) { - url2sa(msg->sol + msg->sl.rq.u, msg->sl.rq.u_l, &s->req->cons->addr.s.to); + url2sa(msg->sol + msg->sl.rq.u, msg->sl.rq.u_l, &s->req->cons->addr.to); } /* @@ -3549,19 +3549,19 @@ int http_process_request(struct session *s, struct buffer *req, int an_bit) * and we found it, so don't do anything. */ } - else if (s->req->prod->addr.c.from.ss_family == AF_INET) { + else if (s->req->prod->addr.from.ss_family == AF_INET) { /* Add an X-Forwarded-For header unless the source IP is * in the 'except' network range. */ if ((!s->fe->except_mask.s_addr || - (((struct sockaddr_in *)&s->req->prod->addr.c.from)->sin_addr.s_addr & s->fe->except_mask.s_addr) + (((struct sockaddr_in *)&s->req->prod->addr.from)->sin_addr.s_addr & s->fe->except_mask.s_addr) != s->fe->except_net.s_addr) && (!s->be->except_mask.s_addr || - (((struct sockaddr_in *)&s->req->prod->addr.c.from)->sin_addr.s_addr & s->be->except_mask.s_addr) + (((struct sockaddr_in *)&s->req->prod->addr.from)->sin_addr.s_addr & s->be->except_mask.s_addr) != s->be->except_net.s_addr)) { int len; unsigned char *pn; - pn = (unsigned char *)&((struct sockaddr_in *)&s->req->prod->addr.c.from)->sin_addr; + pn = (unsigned char *)&((struct sockaddr_in *)&s->req->prod->addr.from)->sin_addr; /* Note: we rely on the backend to get the header name to be used for * x-forwarded-for, because the header is really meant for the backends. @@ -3582,14 +3582,14 @@ int http_process_request(struct session *s, struct buffer *req, int an_bit) goto return_bad_req; } } - else if (s->req->prod->addr.c.from.ss_family == AF_INET6) { + else if (s->req->prod->addr.from.ss_family == AF_INET6) { /* FIXME: for the sake of completeness, we should also support * 'except' here, although it is mostly useless in this case. */ int len; char pn[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, - (const void *)&((struct sockaddr_in6 *)(&s->req->prod->addr.c.from))->sin6_addr, + (const void *)&((struct sockaddr_in6 *)(&s->req->prod->addr.from))->sin6_addr, pn, sizeof(pn)); /* Note: we rely on the backend to get the header name to be used for @@ -3619,23 +3619,23 @@ int http_process_request(struct session *s, struct buffer *req, int an_bit) if ((s->fe->options | s->be->options) & PR_O_ORGTO) { /* FIXME: don't know if IPv6 can handle that case too. */ - if (s->req->prod->addr.c.from.ss_family == AF_INET) { + if (s->req->prod->addr.from.ss_family == AF_INET) { /* Add an X-Original-To header unless the destination IP is * in the 'except' network range. */ if (!(s->flags & SN_FRT_ADDR_SET)) get_frt_addr(s); - if (s->req->prod->addr.c.to.ss_family == AF_INET && + if (s->req->prod->addr.to.ss_family == AF_INET && ((!s->fe->except_mask_to.s_addr || - (((struct sockaddr_in *)&s->req->prod->addr.c.to)->sin_addr.s_addr & s->fe->except_mask_to.s_addr) + (((struct sockaddr_in *)&s->req->prod->addr.to)->sin_addr.s_addr & s->fe->except_mask_to.s_addr) != s->fe->except_to.s_addr) && (!s->be->except_mask_to.s_addr || - (((struct sockaddr_in *)&s->req->prod->addr.c.to)->sin_addr.s_addr & s->be->except_mask_to.s_addr) + (((struct sockaddr_in *)&s->req->prod->addr.to)->sin_addr.s_addr & s->be->except_mask_to.s_addr) != s->be->except_to.s_addr))) { int len; unsigned char *pn; - pn = (unsigned char *)&((struct sockaddr_in *)&s->req->prod->addr.c.to)->sin_addr; + pn = (unsigned char *)&((struct sockaddr_in *)&s->req->prod->addr.to)->sin_addr; /* Note: we rely on the backend to get the header name to be used for * x-original-to, because the header is really meant for the backends. @@ -7454,7 +7454,7 @@ void http_capture_bad_message(struct error_snapshot *es, struct session *s, es->sid = s->uniq_id; es->srv = target_srv(&s->target); es->oe = other_end; - es->src = s->req->prod->addr.c.from; + es->src = s->req->prod->addr.from; es->state = state; es->flags = buf->flags; es->ev_id = error_snapshot_id++; @@ -7927,8 +7927,8 @@ acl_fetch_url_ip(struct proxy *px, struct session *l4, void *l7, int dir, return 0; /* Parse HTTP request */ - url2sa(txn->req.sol + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &l4->req->cons->addr.s.to); - test->ptr = (void *)&((struct sockaddr_in *)&l4->req->cons->addr.s.to)->sin_addr; + url2sa(txn->req.sol + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &l4->req->cons->addr.to); + test->ptr = (void *)&((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_addr; test->i = AF_INET; /* @@ -7959,8 +7959,8 @@ acl_fetch_url_port(struct proxy *px, struct session *l4, void *l7, int dir, return 0; /* Same optimization as url_ip */ - url2sa(txn->req.sol + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &l4->req->cons->addr.s.to); - test->i = ntohs(((struct sockaddr_in *)&l4->req->cons->addr.s.to)->sin_port); + url2sa(txn->req.sol + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &l4->req->cons->addr.to); + test->i = ntohs(((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_port); if (px->options & PR_O_HTTP_PROXY) l4->flags |= SN_ADDR_SET; @@ -8180,9 +8180,9 @@ acl_fetch_hdr_ip(struct proxy *px, struct session *l4, void *l7, char *sol, test->flags |= ACL_TEST_F_FETCH_MORE; test->flags |= ACL_TEST_F_VOL_HDR; /* Same optimization as url_ip */ - memset(&((struct sockaddr_in *)&l4->req->cons->addr.s.to)->sin_addr, 0, sizeof(((struct sockaddr_in *)&l4->req->cons->addr.s.to)->sin_addr)); - url2ipv4((char *)ctx->line + ctx->val, &((struct sockaddr_in *)&l4->req->cons->addr.s.to)->sin_addr); - test->ptr = (void *)&((struct sockaddr_in *)&l4->req->cons->addr.s.to)->sin_addr; + memset(&((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_addr, 0, sizeof(((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_addr)); + url2ipv4((char *)ctx->line + ctx->val, &((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_addr); + test->ptr = (void *)&((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_addr; test->i = AF_INET; return 1; } diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 913e04e..e5496dc 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -193,7 +193,7 @@ int tcp_bind_socket(int fd, int flags, struct sockaddr_storage *local, struct so /* * This function initiates a connection to the target assigned to this session - * (si->{target,addr.s.to}). A source address may be pointed to by si->addr.s.from + * (si->{target,addr.to}). A source address may be pointed to by si->addr.from * in case of transparent proxying. Normal source bind addresses are still * determined locally (due to the possible need of a source port). * si->target may point either to a valid server or to a backend, depending @@ -228,7 +228,7 @@ int tcp_connect_server(struct stream_interface *si) return SN_ERR_INTERNAL; } - if ((fd = si->fd = socket(si->addr.s.to.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) { + if ((fd = si->fd = socket(si->addr.to.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) { qfprintf(stderr, "Cannot get a server socket.\n"); if (errno == ENFILE) @@ -318,11 +318,11 @@ int tcp_connect_server(struct stream_interface *si) fdinfo[fd].port_range = srv->sport_range; set_host_port(&src, fdinfo[fd].local_port); - ret = tcp_bind_socket(fd, flags, &src, &si->addr.s.from); + ret = tcp_bind_socket(fd, flags, &src, &si->addr.from); } while (ret != 0); /* binding NOK */ } else { - ret = tcp_bind_socket(fd, flags, &srv->source_addr, &si->addr.s.from); + ret = tcp_bind_socket(fd, flags, &srv->source_addr, &si->addr.from); } if (ret) { @@ -365,7 +365,7 @@ int tcp_connect_server(struct stream_interface *si) if (be->iface_name) setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, be->iface_name, be->iface_len + 1); #endif - ret = tcp_bind_socket(fd, flags, &be->source_addr, &si->addr.s.from); + ret = tcp_bind_socket(fd, flags, &be->source_addr, &si->addr.from); if (ret) { close(fd); if (ret == 1) { @@ -400,7 +400,7 @@ int tcp_connect_server(struct stream_interface *si) if (global.tune.server_rcvbuf) setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &global.tune.server_rcvbuf, sizeof(global.tune.server_rcvbuf)); - if ((connect(fd, (struct sockaddr *)&si->addr.s.to, get_addr_len(&si->addr.s.to)) == -1) && + if ((connect(fd, (struct sockaddr *)&si->addr.to, get_addr_len(&si->addr.to)) == -1) && (errno != EINPROGRESS) && (errno != EALREADY) && (errno != EISCONN)) { if (errno == EAGAIN || errno == EADDRINUSE) { @@ -442,8 +442,8 @@ int tcp_connect_server(struct stream_interface *si) fdtab[fd].cb[DIR_WR].f = &stream_sock_write; fdtab[fd].cb[DIR_WR].b = si->ob; - fdinfo[fd].peeraddr = (struct sockaddr *)&si->addr.s.to; - fdinfo[fd].peerlen = get_addr_len(&si->addr.s.to); + fdinfo[fd].peeraddr = (struct sockaddr *)&si->addr.to; + fdinfo[fd].peerlen = get_addr_len(&si->addr.to); fd_insert(fd); EV_FD_SET(fd, DIR_WR); /* for connect status */ @@ -1247,11 +1247,11 @@ static int acl_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { - test->i = l4->si[0].addr.c.from.ss_family; + test->i = l4->si[0].addr.from.ss_family; if (test->i == AF_INET) - test->ptr = (char *)&((struct sockaddr_in *)&l4->si[0].addr.c.from)->sin_addr; + test->ptr = (char *)&((struct sockaddr_in *)&l4->si[0].addr.from)->sin_addr; else if (test->i == AF_INET6) - test->ptr = (char *)&((struct sockaddr_in6 *)(&l4->si[0].addr.c.from))->sin6_addr; + test->ptr = (char *)&((struct sockaddr_in6 *)(&l4->si[0].addr.from))->sin6_addr; else return 0; @@ -1264,10 +1264,10 @@ static int pattern_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir, const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) { - if (l4->si[0].addr.c.from.ss_family != AF_INET ) + if (l4->si[0].addr.from.ss_family != AF_INET ) return 0; - data->ip.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.c.from)->sin_addr.s_addr; + data->ip.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.from)->sin_addr.s_addr; return 1; } @@ -1276,10 +1276,10 @@ static int pattern_fetch_src6(struct proxy *px, struct session *l4, void *l7, int dir, const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) { - if (l4->si[0].addr.c.from.ss_family != AF_INET6) + if (l4->si[0].addr.from.ss_family != AF_INET6) return 0; - memcpy(data->ipv6.s6_addr, ((struct sockaddr_in6 *)&l4->si[0].addr.c.from)->sin6_addr.s6_addr, sizeof(data->ipv6.s6_addr)); + memcpy(data->ipv6.s6_addr, ((struct sockaddr_in6 *)&l4->si[0].addr.from)->sin6_addr.s6_addr, sizeof(data->ipv6.s6_addr)); return 1; } @@ -1288,7 +1288,7 @@ static int acl_fetch_sport(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { - if (!(test->i = get_host_port(&l4->si[0].addr.c.from))) + if (!(test->i = get_host_port(&l4->si[0].addr.from))) return 0; test->flags = 0; @@ -1304,11 +1304,11 @@ acl_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir, if (!(l4->flags & SN_FRT_ADDR_SET)) get_frt_addr(l4); - test->i = l4->si[0].addr.c.to.ss_family; + test->i = l4->si[0].addr.to.ss_family; if (test->i == AF_INET) - test->ptr = (char *)&((struct sockaddr_in *)&l4->si[0].addr.c.to)->sin_addr; + test->ptr = (char *)&((struct sockaddr_in *)&l4->si[0].addr.to)->sin_addr; else if (test->i == AF_INET6) - test->ptr = (char *)&((struct sockaddr_in6 *)(&l4->si[0].addr.c.to))->sin6_addr; + test->ptr = (char *)&((struct sockaddr_in6 *)(&l4->si[0].addr.to))->sin6_addr; else return 0; @@ -1325,10 +1325,10 @@ pattern_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir, if (!(l4->flags & SN_FRT_ADDR_SET)) get_frt_addr(l4); - if (l4->si[0].addr.c.to.ss_family != AF_INET) + if (l4->si[0].addr.to.ss_family != AF_INET) return 0; - data->ip.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.c.to)->sin_addr.s_addr; + data->ip.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.to)->sin_addr.s_addr; return 1; } @@ -1340,10 +1340,10 @@ pattern_fetch_dst6(struct proxy *px, struct session *l4, void *l7, int dir, if (!(l4->flags & SN_FRT_ADDR_SET)) get_frt_addr(l4); - if (l4->si[0].addr.c.to.ss_family != AF_INET6) + if (l4->si[0].addr.to.ss_family != AF_INET6) return 0; - memcpy(data->ipv6.s6_addr, ((struct sockaddr_in6 *)&l4->si[0].addr.c.to)->sin6_addr.s6_addr, sizeof(data->ipv6.s6_addr)); + memcpy(data->ipv6.s6_addr, ((struct sockaddr_in6 *)&l4->si[0].addr.to)->sin6_addr.s6_addr, sizeof(data->ipv6.s6_addr)); return 1; } @@ -1355,7 +1355,7 @@ acl_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir, if (!(l4->flags & SN_FRT_ADDR_SET)) get_frt_addr(l4); - if (!(test->i = get_host_port(&l4->si[0].addr.c.to))) + if (!(test->i = get_host_port(&l4->si[0].addr.to))) return 0; test->flags = 0; @@ -1369,7 +1369,7 @@ pattern_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir, if (!(l4->flags & SN_FRT_ADDR_SET)) get_frt_addr(l4); - if (!(data->integer = get_host_port(&l4->si[0].addr.c.to))) + if (!(data->integer = get_host_port(&l4->si[0].addr.to))) return 0; return 1; diff --git a/src/session.c b/src/session.c index d39da99..9c66906 100644 --- a/src/session.c +++ b/src/session.c @@ -96,7 +96,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) LIST_INIT(&s->back_refs); s->term_trace = 0; - s->si[0].addr.c.from = *addr; + s->si[0].addr.from = *addr; s->logs.accept_date = date; /* user-visible date for logging */ s->logs.tv_accept = now; /* corrected date for internal use */ s->uniq_id = totalconn; @@ -278,8 +278,8 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) fdtab[cfd].cb[DIR_RD].b = s->req; fdtab[cfd].cb[DIR_WR].f = l->proto->write; fdtab[cfd].cb[DIR_WR].b = s->rep; - fdinfo[cfd].peeraddr = (struct sockaddr *)&s->si[0].addr.c.from; - fdinfo[cfd].peerlen = sizeof(s->si[0].addr.c.from); + fdinfo[cfd].peeraddr = (struct sockaddr *)&s->si[0].addr.from; + fdinfo[cfd].peerlen = sizeof(s->si[0].addr.from); EV_FD_SET(cfd, DIR_RD); if (p->accept && (ret = p->accept(s)) <= 0) { diff --git a/src/stream_sock.c b/src/stream_sock.c index d673aba..d6fd54e 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -517,7 +517,7 @@ static int stream_sock_write_loop(struct stream_interface *si, struct buffer *b) * it is positive, it means we have to send from the start. */ ret = make_proxy_line(trash, sizeof(trash), - &b->prod->addr.c.from, &b->prod->addr.c.to); + &b->prod->addr.from, &b->prod->addr.to); if (!ret) return -1; -- 1.7.2.3