[REORG] tcp: make tcpv4_connect_server() take the target address from the SI

The address is now available in the stream interface, no need to pass it by
argument.
This commit is contained in:
Willy Tarreau 2011-03-03 18:27:32 +01:00
parent 957c0a5845
commit f153686a71
4 changed files with 13 additions and 19 deletions

View File

@ -31,8 +31,7 @@ int tcpv4_bind_socket(int fd, int flags, struct sockaddr_in *local, struct socka
void tcpv4_add_listener(struct listener *listener); void tcpv4_add_listener(struct listener *listener);
void tcpv6_add_listener(struct listener *listener); void tcpv6_add_listener(struct listener *listener);
int tcpv4_connect_server(struct stream_interface *si, int tcpv4_connect_server(struct stream_interface *si,
struct proxy *be, struct server *srv, struct proxy *be, struct server *srv);
struct sockaddr *srv_addr, struct sockaddr *from_addr);
int tcp_inspect_request(struct session *s, struct buffer *req, int an_bit); int tcp_inspect_request(struct session *s, struct buffer *req, int an_bit);
int tcp_inspect_response(struct session *s, struct buffer *rep, int an_bit); int tcp_inspect_response(struct session *s, struct buffer *rep, int an_bit);
int tcp_persist_rdp_cookie(struct session *s, struct buffer *req, int an_bit); int tcp_persist_rdp_cookie(struct session *s, struct buffer *req, int an_bit);

View File

@ -108,8 +108,7 @@ struct stream_interface {
void (*shutw)(struct stream_interface *); /* shutw function */ void (*shutw)(struct stream_interface *); /* shutw function */
void (*chk_rcv)(struct stream_interface *);/* chk_rcv function */ void (*chk_rcv)(struct stream_interface *);/* chk_rcv function */
void (*chk_snd)(struct stream_interface *);/* chk_snd function */ void (*chk_snd)(struct stream_interface *);/* chk_snd function */
int (*connect)(struct stream_interface *, struct proxy *, struct server *, int (*connect)(struct stream_interface *, struct proxy *, struct server *); /* connect function if any */
struct sockaddr *, struct sockaddr *); /* connect function if any */
void (*release)(struct stream_interface *); /* handler to call after the last close() */ void (*release)(struct stream_interface *); /* handler to call after the last close() */
/* struct members below are the "remote" part, as seen from the buffer side */ /* struct members below are the "remote" part, as seen from the buffer side */

View File

@ -939,9 +939,7 @@ int connect_server(struct session *s)
assign_tproxy_address(s); assign_tproxy_address(s);
err = s->req->cons->connect(s->req->cons, s->be, s->srv, err = s->req->cons->connect(s->req->cons, s->be, s->srv);
(struct sockaddr *)&s->req->cons->addr.s.to,
(struct sockaddr *)&s->req->cons->addr.s.from);
if (err != SN_ERR_NONE) if (err != SN_ERR_NONE)
return err; return err;

View File

@ -182,10 +182,9 @@ int tcpv4_bind_socket(int fd, int flags, struct sockaddr_in *local, struct socka
/* /*
* This function initiates a connection to the server assigned to this session * This function initiates a connection to the server assigned to this session
* (s->srv, s->srv_addr). It will assign a server if none is assigned yet. A * (s->srv, si->addr.s.to). A source address may be pointed to by si->addr.s.from.
* source address may be pointed to by <from_addr>. Note that this is only used * Note that this is only used in case of transparent proxying. Normal source bind
* in case of transparent proxying. Normal source bind addresses are still * addresses are still determined locally (due to the possible need of a source port).
* determined locally (due to the possible need of a source port).
* *
* It can return one of : * It can return one of :
* - SN_ERR_NONE if everything's OK * - SN_ERR_NONE if everything's OK
@ -196,9 +195,8 @@ int tcpv4_bind_socket(int fd, int flags, struct sockaddr_in *local, struct socka
* - SN_ERR_INTERNAL for any other purely internal errors * - SN_ERR_INTERNAL for any other purely internal errors
* Additionnally, in the case of SN_ERR_RESOURCE, an emergency log will be emitted. * Additionnally, in the case of SN_ERR_RESOURCE, an emergency log will be emitted.
*/ */
int tcpv4_connect_server(struct stream_interface *si,
struct proxy *be, struct server *srv, int tcpv4_connect_server(struct stream_interface *si, struct proxy *be, struct server *srv)
struct sockaddr *srv_addr, struct sockaddr *from_addr)
{ {
int fd; int fd;
@ -292,11 +290,11 @@ int tcpv4_connect_server(struct stream_interface *si,
fdinfo[fd].port_range = srv->sport_range; fdinfo[fd].port_range = srv->sport_range;
src.sin_port = htons(fdinfo[fd].local_port); src.sin_port = htons(fdinfo[fd].local_port);
ret = tcpv4_bind_socket(fd, flags, &src, (struct sockaddr_in *)from_addr); ret = tcpv4_bind_socket(fd, flags, &src, (struct sockaddr_in *)&si->addr.s.from);
} while (ret != 0); /* binding NOK */ } while (ret != 0); /* binding NOK */
} }
else { else {
ret = tcpv4_bind_socket(fd, flags, &srv->source_addr, (struct sockaddr_in *)from_addr); ret = tcpv4_bind_socket(fd, flags, &srv->source_addr, (struct sockaddr_in *)&si->addr.s.from);
} }
if (ret) { if (ret) {
@ -339,7 +337,7 @@ int tcpv4_connect_server(struct stream_interface *si,
if (be->iface_name) if (be->iface_name)
setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, be->iface_name, be->iface_len + 1); setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, be->iface_name, be->iface_len + 1);
#endif #endif
ret = tcpv4_bind_socket(fd, flags, &be->source_addr, (struct sockaddr_in *)from_addr); ret = tcpv4_bind_socket(fd, flags, &be->source_addr, (struct sockaddr_in *)&si->addr.s.from);
if (ret) { if (ret) {
close(fd); close(fd);
if (ret == 1) { if (ret == 1) {
@ -374,7 +372,7 @@ int tcpv4_connect_server(struct stream_interface *si,
if (global.tune.server_rcvbuf) if (global.tune.server_rcvbuf)
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &global.tune.server_rcvbuf, sizeof(global.tune.server_rcvbuf)); setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &global.tune.server_rcvbuf, sizeof(global.tune.server_rcvbuf));
if ((connect(fd, (struct sockaddr *)srv_addr, sizeof(struct sockaddr_in)) == -1) && if ((connect(fd, (struct sockaddr *)&si->addr.s.to, sizeof(struct sockaddr_in)) == -1) &&
(errno != EINPROGRESS) && (errno != EALREADY) && (errno != EISCONN)) { (errno != EINPROGRESS) && (errno != EALREADY) && (errno != EISCONN)) {
if (errno == EAGAIN || errno == EADDRINUSE) { if (errno == EAGAIN || errno == EADDRINUSE) {
@ -416,7 +414,7 @@ int tcpv4_connect_server(struct stream_interface *si,
fdtab[fd].cb[DIR_WR].f = &stream_sock_write; fdtab[fd].cb[DIR_WR].f = &stream_sock_write;
fdtab[fd].cb[DIR_WR].b = si->ob; fdtab[fd].cb[DIR_WR].b = si->ob;
fdinfo[fd].peeraddr = (struct sockaddr *)srv_addr; fdinfo[fd].peeraddr = (struct sockaddr *)&si->addr.s.to;
fdinfo[fd].peerlen = sizeof(struct sockaddr_in); fdinfo[fd].peerlen = sizeof(struct sockaddr_in);
fd_insert(fd); fd_insert(fd);