[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:
parent
957c0a5845
commit
f153686a71
|
@ -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 tcpv6_add_listener(struct listener *listener);
|
||||
int tcpv4_connect_server(struct stream_interface *si,
|
||||
struct proxy *be, struct server *srv,
|
||||
struct sockaddr *srv_addr, struct sockaddr *from_addr);
|
||||
struct proxy *be, struct server *srv);
|
||||
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_persist_rdp_cookie(struct session *s, struct buffer *req, int an_bit);
|
||||
|
|
|
@ -108,8 +108,7 @@ struct stream_interface {
|
|||
void (*shutw)(struct stream_interface *); /* shutw function */
|
||||
void (*chk_rcv)(struct stream_interface *);/* chk_rcv function */
|
||||
void (*chk_snd)(struct stream_interface *);/* chk_snd function */
|
||||
int (*connect)(struct stream_interface *, struct proxy *, struct server *,
|
||||
struct sockaddr *, struct sockaddr *); /* connect function if any */
|
||||
int (*connect)(struct stream_interface *, struct proxy *, struct server *); /* connect function if any */
|
||||
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 */
|
||||
|
|
|
@ -939,9 +939,7 @@ int connect_server(struct session *s)
|
|||
|
||||
assign_tproxy_address(s);
|
||||
|
||||
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);
|
||||
err = s->req->cons->connect(s->req->cons, s->be, s->srv);
|
||||
|
||||
if (err != SN_ERR_NONE)
|
||||
return err;
|
||||
|
|
|
@ -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
|
||||
* (s->srv, s->srv_addr). It will assign a server if none is assigned yet. A
|
||||
* source address may be pointed to by <from_addr>. Note that this is only used
|
||||
* in case of transparent proxying. Normal source bind addresses are still
|
||||
* determined locally (due to the possible need of a source port).
|
||||
* (s->srv, si->addr.s.to). A source address may be pointed to by si->addr.s.from.
|
||||
* Note that this is only used in case of transparent proxying. Normal source bind
|
||||
* addresses are still determined locally (due to the possible need of a source port).
|
||||
*
|
||||
* It can return one of :
|
||||
* - 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
|
||||
* 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,
|
||||
struct sockaddr *srv_addr, struct sockaddr *from_addr)
|
||||
|
||||
int tcpv4_connect_server(struct stream_interface *si, struct proxy *be, struct server *srv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
|
@ -292,11 +290,11 @@ int tcpv4_connect_server(struct stream_interface *si,
|
|||
fdinfo[fd].port_range = srv->sport_range;
|
||||
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 */
|
||||
}
|
||||
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) {
|
||||
|
@ -339,7 +337,7 @@ int tcpv4_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 = 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) {
|
||||
close(fd);
|
||||
if (ret == 1) {
|
||||
|
@ -374,7 +372,7 @@ int tcpv4_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 *)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)) {
|
||||
|
||||
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].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);
|
||||
|
||||
fd_insert(fd);
|
||||
|
|
Loading…
Reference in New Issue