]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[REORG] tcp: make tcpv4_connect_server() take the target address from the SI
authorWilly Tarreau <w@1wt.eu>
Thu, 3 Mar 2011 17:27:32 +0000 (18:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Mar 2011 22:32:15 +0000 (23:32 +0100)
The address is now available in the stream interface, no need to pass it by
argument.

include/proto/proto_tcp.h
include/types/stream_interface.h
src/backend.c
src/proto_tcp.c

index 89705614f2cbf68424d37c6fa48d0e49182a6d2a..3baed1fdda0be79e156e47b1dc9934e0c6d25dff 100644 (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 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);
index 7bafce34d4af0ef4dada6f1141dea110676dc113..ea7b266a3fbc266efdf068e69b5d729091622c71 100644 (file)
@@ -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 */
index 870947a342dbb66531c20f5592a6e44fab649256..0e1f9255a78bb6a6856f580576f363febefaa15e 100644 (file)
@@ -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;
index 2a74c29bb16312a111f9185ae129c68c348e0804..174d661db8f5c08c6e00eb38bc90b6705e617e44 100644 (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
- * (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);