]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stream-int/conn-stream: Move src/dst addresses in the conn-stream
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 29 Mar 2022 15:53:09 +0000 (17:53 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Apr 2022 13:10:14 +0000 (15:10 +0200)
The source and destination addresses at the applicative layer are moved from
the stream-interface to the conn-stream. This simplifies a bit the code and
it is a logicial step to remove the stream-interface.

24 files changed:
dev/flags/flags.c
include/haproxy/conn_stream-t.h
include/haproxy/cs_utils.h
include/haproxy/stream.h
include/haproxy/stream_interface-t.h
include/haproxy/stream_interface.h
src/backend.c
src/cli.c
src/conn_stream.c
src/connection.c
src/dns.c
src/frontend.c
src/hlua.c
src/http_ana.c
src/http_client.c
src/http_fetch.c
src/log.c
src/mux_fcgi.c
src/peers.c
src/queue.c
src/sink.c
src/stream_interface.c
src/tcp_act.c
src/tcp_sample.c

index 02064b39eaf6bdd8092255c047d12e4744ab2edc..266df9d24277ec16f79d648653ec09e5dd433ac5 100644 (file)
@@ -219,6 +219,8 @@ void show_cs_flags(unsigned int f)
                printf("0\n");
                return;
        }
+       SHOW_FLAG(f, CS_FL_ADDR_FROM_SET);
+       SHOW_FLAG(f, CS_FL_ADDR_TO_SET);
        SHOW_FLAG(f, CS_FL_ISBACK);
 
        if (f) {
@@ -279,8 +281,6 @@ void show_si_flags(unsigned int f)
        SHOW_FLAG(f, SI_FL_RXBLK_SHUT);
        SHOW_FLAG(f, SI_FL_RXBLK_CONN);
        SHOW_FLAG(f, SI_FL_RX_WAIT_EP);
-       SHOW_FLAG(f, SI_FL_ADDR_FROM_SET);
-       SHOW_FLAG(f, SI_FL_ADDR_TO_SET);
 
        if (f) {
                printf("EXTRA(0x%08x)", f);
index 226d451fec5a64424f797caad44e66c2f558a142..fdaa6c3b25195fb1c30add980642d2f7e8495d4d 100644 (file)
@@ -79,6 +79,9 @@ struct stream_interface;
 enum {
        CS_FL_NONE          = 0x00000000,  /* Just for initialization purposes */
        CS_FL_ISBACK        = 0x00000001,  /* Set for CS on back-side */
+
+       CS_FL_ADDR_FROM_SET = 0x00000002, /* source address is set */
+       CS_FL_ADDR_TO_SET   = 0x00000004, /* destination address is set */
 };
 
 /* cs_shutr() modes */
@@ -125,6 +128,8 @@ struct conn_stream {
        enum obj_type *app;                  /* points to the applicative point (stream or check) */
        struct stream_interface *si;
        const struct data_cb *data_cb;       /* data layer callbacks. Must be set before xprt->init() */
+       struct sockaddr_storage *src;        /* source address (pool), when known, otherwise NULL */
+       struct sockaddr_storage *dst;        /* destination address (pool), when known, otherwise NULL */
 };
 
 
index 58334b8cea443240dd531b90a49262cdf354df08..7381499dc125b327e05931d3202fedcd62630294 100644 (file)
 #include <haproxy/channel-t.h>
 #include <haproxy/stream-t.h>
 #include <haproxy/task-t.h>
+#include <haproxy/connection.h>
 #include <haproxy/conn_stream.h>
+#include <haproxy/session.h>
+#include <haproxy/stream.h>
 
 /* returns the channel which receives data from this conn-stream (input channel) */
 static inline struct channel *cs_ic(struct conn_stream *cs)
@@ -73,4 +76,105 @@ static inline struct conn_stream *cs_opposite(struct conn_stream *cs)
 }
 
 
+/* Returns the source address of the conn-stream and, if not set, fallbacks on
+ * the session for frontend CS and the server connection for the backend CS. It
+ * returns a const address on success or NULL on failure.
+ */
+static inline const struct sockaddr_storage *cs_src(struct conn_stream *cs)
+{
+       if (cs->flags & CS_FL_ADDR_FROM_SET)
+               return cs->src;
+       if (!(cs->flags & CS_FL_ISBACK))
+               return sess_src(strm_sess(__cs_strm(cs)));
+       else {
+               struct connection *conn = cs_conn(cs);
+
+               if (conn)
+                       return conn_src(conn);
+       }
+       return NULL;
+}
+
+
+/* Returns the destination address of the conn-stream and, if not set, fallbacks
+ * on the session for frontend CS and the server connection for the backend
+ * CS. It returns a const address on success or NULL on failure.
+ */
+static inline const struct sockaddr_storage *cs_dst(struct conn_stream *cs)
+{
+       if (cs->flags & CS_FL_ADDR_TO_SET)
+               return cs->dst;
+       if (!(cs->flags & CS_FL_ISBACK))
+               return sess_dst(strm_sess(__cs_strm(cs)));
+       else {
+               struct connection *conn = cs_conn(cs);
+
+               if (conn)
+                       return conn_dst(conn);
+       }
+       return NULL;
+}
+
+/* Retrieves the source address of the conn-stream. Returns non-zero on success
+ * or zero on failure. The operation is only performed once and the address is
+ * stored in the conn-stream for future use. On the first call, the conn-stream
+ * source address is copied from the session one for frontend CS and the server
+ * connection for the backend CS.
+ */
+static inline int cs_get_src(struct conn_stream *cs)
+{
+       const struct sockaddr_storage *src = NULL;
+
+       if (cs->flags & CS_FL_ADDR_FROM_SET)
+               return 1;
+
+       if (!(cs->flags & CS_FL_ISBACK))
+               src = sess_src(strm_sess(__cs_strm(cs)));
+       else {
+               struct connection *conn = cs_conn(cs);
+
+               if (conn)
+                       src = conn_src(conn);
+       }
+       if (!src)
+               return 0;
+
+       if (!sockaddr_alloc(&cs->src, src, sizeof(*src)))
+               return 0;
+
+       cs->flags |= CS_FL_ADDR_FROM_SET;
+       return 1;
+}
+
+/* Retrieves the destination address of the conn-stream. Returns non-zero on
+ * success or zero on failure. The operation is only performed once and the
+ * address is stored in the conn-stream for future use. On the first call, the
+ * conn-stream destination address is copied from the session one for frontend
+ * CS and the server connection for the backend CS.
+ */
+static inline int cs_get_dst(struct conn_stream *cs)
+{
+       const struct sockaddr_storage *dst = NULL;
+
+       if (cs->flags & CS_FL_ADDR_TO_SET)
+               return 1;
+
+       if (!(cs->flags & CS_FL_ISBACK))
+               dst = sess_dst(strm_sess(__cs_strm(cs)));
+       else {
+               struct connection *conn = cs_conn(cs);
+
+               if (conn)
+                       dst = conn_dst(conn);
+       }
+       if (!dst)
+               return 0;
+
+       if (!sockaddr_alloc(&cs->dst, dst, sizeof(*dst)))
+               return 0;
+
+       cs->flags |= CS_FL_ADDR_TO_SET;
+       return 1;
+}
+
 #endif /* _HAPROXY_CS_UTILS_H */
index 19832301466dcc939d1249e3032179cc5bba3857..db1a2d6b68831ad3a1b6f1578ecb60c90e46a492 100644 (file)
@@ -340,7 +340,7 @@ static inline void stream_choose_redispatch(struct stream *s)
                if (may_dequeue_tasks(objt_server(s->target), s->be))
                        process_srv_queue(objt_server(s->target));
 
-               sockaddr_free(&cs_si(s->csb)->dst);
+               sockaddr_free(&s->csb->dst);
                s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
                si->state = SI_ST_REQ;
        } else {
index 8ed3d4ed0b1b66eb21d586d52b4065f4d27a588e..d9f1242c0ffecbca2cd86002153952738003e725 100644 (file)
@@ -104,10 +104,6 @@ enum {
        SI_FL_RXBLK_CONN = 0x00100000,  /* other side is not connected */
        SI_FL_RXBLK_ANY  = 0x001F0000,  /* any of the RXBLK flags above */
        SI_FL_RX_WAIT_EP = 0x00200000,  /* stream-int waits for more data from the end point */
-       /* unused: 0x01000000, 0x02000000 */
-
-       SI_FL_ADDR_FROM_SET = 0x04000000, /* source address is set */
-       SI_FL_ADDR_TO_SET   = 0x08000000  /* destination address is set */
 };
 
 /* A stream interface has 3 parts :
@@ -129,8 +125,6 @@ struct stream_interface {
        unsigned int flags;     /* SI_FL_* */
        struct conn_stream *cs; /* points to the conn-streams that owns the endpoint (connection or applet) */
        struct si_ops *ops;     /* general operations at the stream interface layer */
-       struct sockaddr_storage *src; /* source address (pool), when known, otherwise NULL */
-       struct sockaddr_storage *dst; /* destination address (pool), when known, otherwise NULL */
        unsigned int exp;       /* wake up time for connect, queue, turn-around, ... */
 
        /* struct members below are the "remote" part, as seen from the buffer side */
index 33d5e19f5daee2c98c9595fe0bae316c8e6442bb..56f772b7288399ffcae89121b3210aa69abaa669 100644 (file)
@@ -107,8 +107,6 @@ static inline struct stream_interface *si_opposite(struct stream_interface *si)
  */
 static inline int si_init(struct stream_interface *si)
 {
-       si->src            = NULL;
-       si->dst            = NULL;
        si->err_type       = SI_ET_NONE;
        si->exp            = TICK_ETERNITY;
        si->flags         &= SI_FL_ISBACK;
@@ -429,108 +427,6 @@ static inline const char *si_state_str(int state)
        }
 }
 
-
-/* Returns the source address of the stream-int and, if not set, fallbacks on
- * the session for frontend SI and the server connection for the backend SI. It
- * returns a const address on success or NULL on failure.
- */
-static inline const struct sockaddr_storage *si_src(struct stream_interface *si)
-{
-       if (si->flags & SI_FL_ADDR_FROM_SET)
-               return si->src;
-       if (!(si->flags & SI_FL_ISBACK))
-               return sess_src(strm_sess(si_strm(si)));
-       else {
-               struct connection *conn = cs_conn(si->cs);
-
-               if (conn)
-                       return conn_src(conn);
-       }
-       return NULL;
-}
-
-
-/* Returns the destination address of the stream-int and, if not set, fallbacks
- * on the session for frontend SI and the server connection for the backend
- * SI. It returns a const address on success or NULL on failure.
- */
-static inline const struct sockaddr_storage *si_dst(struct stream_interface *si)
-{
-       if (si->flags & SI_FL_ADDR_TO_SET)
-               return si->dst;
-       if (!(si->flags & SI_FL_ISBACK))
-               return sess_dst(strm_sess(si_strm(si)));
-       else {
-               struct connection *conn = cs_conn(si->cs);
-
-               if (conn)
-                       return conn_dst(conn);
-       }
-       return NULL;
-}
-
-/* Retrieves the source address of the stream-int. Returns non-zero on success
- * or zero on failure. The operation is only performed once and the address is
- * stored in the stream-int for future use. On the first call, the stream-int
- * source address is copied from the session one for frontend SI and the server
- * connection for the backend SI.
- */
-static inline int si_get_src(struct stream_interface *si)
-{
-       const struct sockaddr_storage *src = NULL;
-
-       if (si->flags & SI_FL_ADDR_FROM_SET)
-               return 1;
-
-       if (!(si->flags & SI_FL_ISBACK))
-               src = sess_src(strm_sess(si_strm(si)));
-       else {
-               struct connection *conn = cs_conn(si->cs);
-
-               if (conn)
-                       src = conn_src(conn);
-       }
-       if (!src)
-               return 0;
-
-       if (!sockaddr_alloc(&si->src, src, sizeof(*src)))
-               return 0;
-
-       si->flags |= SI_FL_ADDR_FROM_SET;
-       return 1;
-}
-
-/* Retrieves the destination address of the stream-int. Returns non-zero on
- * success or zero on failure. The operation is only performed once and the
- * address is stored in the stream-int for future use. On the first call, the
- * stream-int destination address is copied from the session one for frontend SI
- * and the server connection for the backend SI.
- */
-static inline int si_get_dst(struct stream_interface *si)
-{
-       const struct sockaddr_storage *dst = NULL;
-
-       if (si->flags & SI_FL_ADDR_TO_SET)
-               return 1;
-
-       if (!(si->flags & SI_FL_ISBACK))
-               dst = sess_dst(strm_sess(si_strm(si)));
-       else {
-               struct connection *conn = cs_conn(si->cs);
-
-               if (conn)
-                       dst = conn_dst(conn);
-       }
-       if (!dst)
-               return 0;
-
-       if (!sockaddr_alloc(&si->dst, dst, sizeof(*dst)))
-               return 0;
-
-       si->flags |= SI_FL_ADDR_TO_SET;
-       return 1;
-}
-
 #endif /* _HAPROXY_STREAM_INTERFACE_H */
 
 /*
index c73b23e7858de9566c4c127feaf45769b4b8d9f1..941d755c16d6c1e61b0ccc808b7e4fce3a665894 100644 (file)
@@ -701,7 +701,7 @@ int assign_server(struct stream *s)
                                const struct sockaddr_storage *src;
 
                        case BE_LB_HASH_SRC:
-                               src = si_src(cs_si(s->csf));
+                               src = cs_src(s->csf);
                                if (src && src->ss_family == AF_INET) {
                                        srv = get_server_sh(s->be,
                                                            (void *)&((struct sockaddr_in *)src)->sin_addr,
@@ -854,7 +854,7 @@ static int alloc_dst_address(struct sockaddr_storage **ss,
                         * locally on multiple addresses at once. Nothing is done
                         * for AF_UNIX addresses.
                         */
-                       dst = si_dst(cs_si(s->csf));
+                       dst = cs_dst(s->csf);
                        if (dst && dst->ss_family == AF_INET) {
                                ((struct sockaddr_in *)*ss)->sin_family = AF_INET;
                                ((struct sockaddr_in *)*ss)->sin_addr =
@@ -871,7 +871,7 @@ static int alloc_dst_address(struct sockaddr_storage **ss,
                if ((srv->flags & SRV_F_MAPPORTS)) {
                        int base_port;
 
-                       dst = si_dst(cs_si(s->csf));
+                       dst = cs_dst(s->csf);
                        if (dst) {
                                /* First, retrieve the port from the incoming connection */
                                base_port = get_host_port(dst);
@@ -894,7 +894,7 @@ static int alloc_dst_address(struct sockaddr_storage **ss,
                        return SRV_STATUS_INTERNAL;
 
                /* in transparent mode, use the original dest addr if no dispatch specified */
-               dst = si_dst(cs_si(s->csf));
+               dst = cs_dst(s->csf);
                if (dst && (dst->ss_family == AF_INET || dst->ss_family == AF_INET6))
                        **ss = *dst;
        }
@@ -1069,7 +1069,7 @@ static int alloc_bind_address(struct sockaddr_storage **ss,
        case CO_SRC_TPROXY_CLI:
        case CO_SRC_TPROXY_CIP:
                /* FIXME: what can we do if the client connects in IPv6 or unix socket ? */
-               addr = si_src(cs_si(s->csf));
+               addr = cs_src(s->csf);
                if (!addr)
                        return SRV_STATUS_INTERNAL;
 
@@ -1271,7 +1271,7 @@ static int connect_server(struct stream *s)
        srv = objt_server(s->target);
 
        if (!(s->flags & SF_ADDR_SET)) {
-               err = alloc_dst_address(&(cs_si(s->csb)->dst), srv, s);
+               err = alloc_dst_address(&s->csb->dst, srv, s);
                if (err != SRV_STATUS_OK)
                        return SF_ERR_INTERNAL;
 
@@ -1326,7 +1326,7 @@ static int connect_server(struct stream *s)
 
        /* 3. destination address */
        if (srv && (!is_addr(&srv->addr) || srv->flags & SRV_F_MAPPORTS))
-               hash_params.dst_addr = cs_si(s->csb)->dst;
+               hash_params.dst_addr = s->csb->dst;
 
        /* 4. source address */
        hash_params.src_addr = bind_addr;
@@ -1546,7 +1546,7 @@ skip_reuse:
                return SF_ERR_RESOURCE;
 
        /* copy the target address into the connection */
-       *srv_conn->dst = *(cs_si(s->csb))->dst;
+       *srv_conn->dst = *s->csb->dst;
 
        /* Copy network namespace from client connection */
        srv_conn->proxy_netns = cli_conn ? cli_conn->proxy_netns : NULL;
@@ -1820,7 +1820,7 @@ int srv_redispatch_connect(struct stream *s)
                if (((s->flags & (SF_DIRECT|SF_FORCE_PRST)) == SF_DIRECT) &&
                    (s->be->options & PR_O_REDISP)) {
                        s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
-                       sockaddr_free(&(cs_si(s->csb)->dst));
+                       sockaddr_free(&s->csb->dst);
                        goto redispatch;
                }
 
index f3d05d80079b669b59cccca88fb7f9c3c7be64e6..9b5337060e73a92be4a03774a51cd53c56c66389 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2764,7 +2764,7 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                        }
                }
 
-               sockaddr_free(&(cs_si(s->csb)->dst));
+               sockaddr_free(&s->csb->dst);
 
                cs_si(s->csb)->state = cs_si(s->csb)->prev_state = SI_ST_INI;
                cs_si(s->csb)->err_type = SI_ET_NONE;
index 45c82efba3513b4c9810bb77c03f5c2785244372..55dd86cd9d917d9811807a4d91cb4814a5599b0e 100644 (file)
@@ -60,7 +60,8 @@ struct conn_stream *cs_new(struct cs_endpoint *endp)
        cs->app = NULL;
        cs->si = NULL;
        cs->data_cb = NULL;
-
+       cs->src = NULL;
+       cs->dst = NULL;
        if (!endp) {
                endp = cs_endpoint_new();
                if (unlikely(!endp))
@@ -147,6 +148,8 @@ struct conn_stream *cs_new_from_check(struct check *check, unsigned int flags)
 void cs_free(struct conn_stream *cs)
 {
        si_free(cs->si);
+       sockaddr_free(&cs->src);
+       sockaddr_free(&cs->dst);
        if (cs->endp) {
                BUG_ON(!(cs->endp->flags & CS_EP_DETACHED));
                cs_endpoint_free(cs->endp);
@@ -282,7 +285,8 @@ void cs_detach_app(struct conn_stream *cs)
        cs->app = NULL;
        cs->si  = NULL;
        cs->data_cb = NULL;
-
+       sockaddr_free(&cs->src);
+       sockaddr_free(&cs->dst);
        if (!cs->endp || (cs->endp->flags & CS_EP_DETACHED))
                cs_free(cs);
 }
index a14dfe79219a5b1abd48063bbfa75d3b3af916d2..227e9d9a81a4e1e6d733fa2ab770be2733f6646a 100644 (file)
@@ -18,6 +18,7 @@
 #include <haproxy/cfgparse.h>
 #include <haproxy/connection.h>
 #include <haproxy/conn_stream.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/fd.h>
 #include <haproxy/frontend.h>
 #include <haproxy/hash.h>
@@ -1746,8 +1747,8 @@ static int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct
        memcpy(hdr->sig, pp2_signature, PP2_SIGNATURE_LEN);
 
        if (strm) {
-               src = si_src(strm->csf->si);
-               dst = si_dst(strm->csf->si);
+               src = cs_src(strm->csf);
+               dst = cs_dst(strm->csf);
        }
        else if (remote && conn_get_src(remote) && conn_get_dst(remote)) {
                src = conn_src(remote);
@@ -1945,8 +1946,8 @@ int make_proxy_line(char *buf, int buf_len, struct server *srv, struct connectio
                const struct sockaddr_storage *dst = NULL;
 
                if (strm) {
-                       src = si_src(strm->csf->si);
-                       dst = si_dst(strm->csf->si);
+                       src = cs_src(strm->csf);
+                       dst = cs_dst(strm->csf);
                }
                else if (remote && conn_get_src(remote) && conn_get_dst(remote)) {
                        src = conn_src(remote);
index 755053ad58c531f60906062d86a06234ba67a3f3..92f37b4f7ccdc78e97c101f7c33ec7db0c5d37aa 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -915,7 +915,7 @@ static struct appctx *dns_session_create(struct dns_session *ds)
        }
 
        s = DISGUISE(cs_strm(cs));
-       cs_si(s->csb)->dst = addr;
+       s->csb->dst = addr;
        cs_si(s->csb)->flags |= SI_FL_NOLINGER;
        s->target = &ds->dss->srv->obj_type;
        s->flags = SF_ASSIGNED|SF_ADDR_SET;
index c8fb3d2ba237e7cfe2277b9aab8296f3b370d8eb..3ae24f263e078107579e3cc566ab8e3074d0750a 100644 (file)
@@ -26,6 +26,8 @@
 #include <haproxy/api.h>
 #include <haproxy/arg.h>
 #include <haproxy/chunk.h>
+#include <haproxy/connection.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/fd.h>
 #include <haproxy/frontend.h>
 #include <haproxy/global.h>
@@ -62,7 +64,7 @@ int frontend_accept(struct stream *s)
                                        s->do_log(s);
                }
                else if (conn) {
-                       src = si_src(cs_si(s->csf));
+                       src = cs_src(s->csf);
                        if (!src)
                                send_log(fe, LOG_INFO, "Connect from unknown source to listener %d (%s/%s)\n",
                                         l->luid, fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
@@ -73,7 +75,7 @@ int frontend_accept(struct stream *s)
                                switch (addr_to_str(src, pn, sizeof(pn))) {
                                case AF_INET:
                                case AF_INET6:
-                                       dst = si_dst(cs_si(s->csf));
+                                       dst = cs_dst(s->csf);
                                        if (dst) {
                                                addr_to_str(dst, sn, sizeof(sn));
                                                port = get_host_port(dst);
@@ -113,7 +115,7 @@ int frontend_accept(struct stream *s)
                        }
                }
 
-               src = si_src(cs_si(s->csf));
+               src = cs_src(s->csf);
                if (!src) {
                        chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n",
                                     s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
index 380e61bfc10b64337a9db33274e6da89b2d59390..60b9923d8c18260236b47dd834125d113cc04fec 100644 (file)
@@ -2576,7 +2576,7 @@ __LJMP static int hlua_socket_getpeername(struct lua_State *L)
        }
        appctx = container_of(peer, struct appctx, ctx.hlua_cosocket.xref);
        cs = appctx->owner;
-       dst = si_dst(cs_opposite(cs)->si);
+       dst = cs_dst(cs_opposite(cs));
        if (!dst) {
                xref_unlock(&socket->xref, peer);
                lua_pushnil(L);
@@ -2778,7 +2778,7 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
        cs = appctx->owner;
        s = __cs_strm(cs);
 
-       if (!sockaddr_alloc(&cs_opposite(cs)->si->dst, addr, sizeof(*addr))) {
+       if (!sockaddr_alloc(&cs_opposite(cs)->dst, addr, sizeof(*addr))) {
                xref_unlock(&socket->xref, peer);
                WILL_LJMP(luaL_error(L, "connect: internal error"));
        }
index 2c93edbd205a324652f6e878d2a9b75f3290d00e..f17e2e2a5a1f632683187733e9300bb19fde5796 100644 (file)
@@ -20,6 +20,8 @@
 #include <haproxy/channel.h>
 #include <haproxy/check.h>
 #include <haproxy/connection.h>
+#include <haproxy/conn_stream.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/errors.h>
 #include <haproxy/filters.h>
 #include <haproxy/http.h>
@@ -653,7 +655,7 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit)
         * asks for it.
         */
        if ((sess->fe->options | s->be->options) & PR_O_FWDFOR) {
-               const struct sockaddr_storage *src = si_src(cs_si(s->csf));
+               const struct sockaddr_storage *src = cs_src(s->csf);
                struct http_hdr_ctx ctx = { .blk = NULL };
                struct ist hdr = isttest(s->be->fwdfor_hdr_name) ? s->be->fwdfor_hdr_name : sess->fe->fwdfor_hdr_name;
 
@@ -710,7 +712,7 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit)
         * asks for it.
         */
        if ((sess->fe->options | s->be->options) & PR_O_ORGTO) {
-               const struct sockaddr_storage *dst = si_dst(cs_si(s->csf));
+               const struct sockaddr_storage *dst = cs_dst(s->csf);
                struct ist hdr = isttest(s->be->orgto_hdr_name) ? s->be->orgto_hdr_name : sess->fe->orgto_hdr_name;
 
                if (dst && dst->ss_family == AF_INET) {
index 965dc9d02541efe74658526d6f6878e6a209e5e6..83faffed25aa1bab07576d2409aa812147c56ddb 100644 (file)
@@ -525,7 +525,7 @@ struct appctx *httpclient_start(struct httpclient *hc)
                        break;
        }
 
-       cs_si(s->csb)->dst = addr;
+       s->csb->dst = addr;
        cs_si(s->csb)->flags |= SI_FL_NOLINGER;
        s->flags |= SF_ASSIGNED|SF_ADDR_SET;
        s->res.flags |= CF_READ_DONTWAIT;
index 2ee507b65f1cb63c342b72274402eb6aecabf167..5b83c1906173b0b9d9f0369150298964fbed6456 100644 (file)
@@ -23,6 +23,7 @@
 #include <haproxy/channel.h>
 #include <haproxy/chunk.h>
 #include <haproxy/connection.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/global.h>
 #include <haproxy/h1.h>
 #include <haproxy/h1_htx.h>
@@ -1186,7 +1187,7 @@ static int smp_fetch_base32(const struct arg *args, struct sample *smp, const ch
  */
 static int smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       const struct sockaddr_storage *src = (smp->strm ? si_src(smp->strm->csf->si) : NULL);
+       const struct sockaddr_storage *src = (smp->strm ? cs_src(smp->strm->csf) : NULL);
        struct buffer *temp;
 
        if (!src)
@@ -2053,7 +2054,7 @@ static int smp_fetch_url32(const struct arg *args, struct sample *smp, const cha
  */
 static int smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       const struct sockaddr_storage *src = (smp->strm ? si_src(smp->strm->csf->si) : NULL);
+       const struct sockaddr_storage *src = (smp->strm ? cs_src(smp->strm->csf) : NULL);
        struct buffer *temp;
 
        if (!src)
index edffcbdb75dbe01e1586e37ca514facd07bf8894..c0c3e29084b0f138f33725336a67db288c1a230a 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2116,7 +2116,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                                break;
 
                        case LOG_FMT_CLIENTIP:  // %ci
-                               addr = (s ? si_src(cs_si(s->csf)) : sess_src(sess));
+                               addr = (s ? cs_src(s->csf) : sess_src(sess));
                                if (addr)
                                        ret = lf_ip(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
                                else
@@ -2129,7 +2129,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                                break;
 
                        case LOG_FMT_CLIENTPORT:  // %cp
-                               addr = (s ? si_src(cs_si(s->csf)) : sess_src(sess));
+                               addr = (s ? cs_src(s->csf) : sess_src(sess));
                                if (addr) {
                                        /* sess->listener is always defined when the session's owner is an inbound connections */
                                        if (addr->ss_family == AF_UNIX)
@@ -2147,7 +2147,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                                break;
 
                        case LOG_FMT_FRONTENDIP: // %fi
-                               addr = (s ? si_dst(cs_si(s->csf)) : sess_dst(sess));
+                               addr = (s ? cs_dst(s->csf) : sess_dst(sess));
                                if (addr)
                                        ret = lf_ip(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
                                else
@@ -2160,7 +2160,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                                break;
 
                        case  LOG_FMT_FRONTENDPORT: // %fp
-                               addr = (s ? si_dst(cs_si(s->csf)) : sess_dst(sess));
+                               addr = (s ? cs_dst(s->csf) : sess_dst(sess));
                                if (addr) {
                                        /* sess->listener is always defined when the session's owner is an inbound connections */
                                        if (addr->ss_family == AF_UNIX)
index 50f271f22a333bf39c6dfb06445457198a5c70b6..6e993933ca5e41ef4d63c3fd7f0ee0b35da0e813 100644 (file)
@@ -1235,8 +1235,8 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst
                                  struct fcgi_strm_params *params)
 {
        struct connection *cli_conn = objt_conn(fstrm->sess->origin);
-       const struct sockaddr_storage *src = (cs_check(fstrm->cs) ? conn_src(fconn->conn) : si_src(cs_opposite(fstrm->cs)->si));
-       const struct sockaddr_storage *dst = (cs_check(fstrm->cs) ? conn_dst(fconn->conn) : si_dst(cs_opposite(fstrm->cs)->si));
+       const struct sockaddr_storage *src = (cs_check(fstrm->cs) ? conn_src(fconn->conn) : cs_src(cs_opposite(fstrm->cs)));
+       const struct sockaddr_storage *dst = (cs_check(fstrm->cs) ? conn_dst(fconn->conn) : cs_dst(cs_opposite(fstrm->cs)));
        struct ist p;
 
        if (!sl)
index 9846612464703c4d113a0b41a69b6779ef476d37..4d86126f216e9cdb78a08119aade788bf8a3b526 100644 (file)
@@ -3209,7 +3209,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
        appctx_wakeup(appctx);
 
        /* initiate an outgoing connection */
-       cs_si(s->csb)->dst = addr;
+       s->csb->dst = addr;
        cs_si(s->csb)->flags |= SI_FL_NOLINGER;
        s->flags = SF_ASSIGNED|SF_ADDR_SET;
        s->target = peer_session_target(peer, s);
index 002b94b85df1bebbf332da10470bb68579d66ffe..97862f08ab401dd76f30df37287b022f39785e5f 100644 (file)
@@ -601,7 +601,7 @@ int pendconn_dequeue(struct stream *strm)
 
        /* the entry might have been redistributed to another server */
        if (!(strm->flags & SF_ADDR_SET))
-               sockaddr_free(&cs_si(strm->csb)->dst);
+               sockaddr_free(&strm->csb->dst);
 
        if (p->target) {
                /* a server picked this pendconn, it must skip LB */
index 91ee67f025998fc15cdc00f0b1cad42277140db7..e7ad4bd0356f45fbd4e6e909db95becf1ad00192 100644 (file)
@@ -656,7 +656,7 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink
        }
        s = DISGUISE(cs_strm(cs));
 
-       cs_si(s->csb)->dst = addr;
+       s->csb->dst = addr;
        cs_si(s->csb)->flags |= SI_FL_NOLINGER;
 
        s->target = &sft->srv->obj_type;
index 1e28a8fc04f4c43e43ed825232abaafbd53b45f1..b4d7cab75421c3b0afe682e7013ab2512a3a8c8b 100644 (file)
@@ -125,8 +125,6 @@ void si_free(struct stream_interface *si)
                return;
 
        tasklet_free(si->wait_event.tasklet);
-       sockaddr_free(&si->src);
-       sockaddr_free(&si->dst);
        pool_free(pool_head_streaminterface, si);
 }
 
index 04400d2107654d38c3472c57f4483d8fe9662eba..00505150909e6563685a64fdb663046de164a246 100644 (file)
@@ -30,6 +30,7 @@
 #include <haproxy/arg.h>
 #include <haproxy/channel.h>
 #include <haproxy/connection.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/global.h>
 #include <haproxy/http_rules.h>
 #include <haproxy/proto_tcp.h>
@@ -68,9 +69,9 @@ static enum act_return tcp_action_req_set_src(struct act_rule *rule, struct prox
 
        case ACT_F_TCP_REQ_CNT:
        case ACT_F_HTTP_REQ:
-               if (!si_get_src(cs_si(s->csf)))
+               if (!cs_get_src(s->csf))
                        goto end;
-               src = cs_si(s->csf)->src;
+               src = s->csf->src;
                break;
 
        default:
@@ -124,9 +125,9 @@ static enum act_return tcp_action_req_set_dst(struct act_rule *rule, struct prox
 
        case ACT_F_TCP_REQ_CNT:
        case ACT_F_HTTP_REQ:
-               if (!si_get_dst(cs_si(s->csf)))
+               if (!cs_get_dst(s->csf))
                        goto end;
-               dst = cs_si(s->csf)->dst;
+               dst = s->csf->dst;
                break;
 
        default:
@@ -181,9 +182,9 @@ static enum act_return tcp_action_req_set_src_port(struct act_rule *rule, struct
 
        case ACT_F_TCP_REQ_CNT:
        case ACT_F_HTTP_REQ:
-               if (!si_get_src(cs_si(s->csf)))
+               if (!cs_get_src(s->csf))
                        goto end;
-               src = cs_si(s->csf)->src;
+               src = s->csf->src;
                break;
 
        default:
@@ -236,9 +237,9 @@ static enum act_return tcp_action_req_set_dst_port(struct act_rule *rule, struct
 
        case ACT_F_TCP_REQ_CNT:
        case ACT_F_HTTP_REQ:
-               if (!si_get_dst(cs_si(s->csf)))
+               if (!cs_get_dst(s->csf))
                        goto end;
-               dst = cs_si(s->csf)->dst;
+               dst = s->csf->dst;
                break;
 
        default:
index 53e3d1e01f28a4f8055638450a3d130121b01d9a..fe10fc2cf78deb8c6c7b31f126851323579a128e 100644 (file)
@@ -33,6 +33,7 @@
 #include <haproxy/api.h>
 #include <haproxy/arg.h>
 #include <haproxy/connection.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/errors.h>
 #include <haproxy/global.h>
 #include <haproxy/listener-t.h>
@@ -65,7 +66,7 @@ smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *
                        src = conn_src(conn);
        }
         else /* src */
-               src = (smp->strm ? si_src(smp->strm->csf->si) : sess_src(smp->sess));
+               src = (smp->strm ? cs_src(smp->strm->csf) : sess_src(smp->sess));
 
        if (!src)
                return 0;
@@ -109,7 +110,7 @@ smp_fetch_sport(const struct arg *args, struct sample *smp, const char *kw, void
                        src = conn_src(conn);
        }
         else /* src_port */
-               src = (smp->strm ? si_src(smp->strm->csf->si) : sess_src(smp->sess));
+               src = (smp->strm ? cs_src(smp->strm->csf) : sess_src(smp->sess));
 
        if (!src)
                return 0;
@@ -144,7 +145,7 @@ smp_fetch_dst(const struct arg *args, struct sample *smp, const char *kw, void *
                        dst = conn_dst(conn);
        }
         else /* dst */
-               dst = (smp->strm ? si_dst(smp->strm->csf->si) : sess_dst(smp->sess));
+               dst = (smp->strm ? cs_dst(smp->strm->csf) : sess_dst(smp->sess));
 
        if (!dst)
                return 0;
@@ -181,7 +182,7 @@ int smp_fetch_dst_is_local(const struct arg *args, struct sample *smp, const cha
                        dst = conn_dst(conn);
        }
        else /* dst_is_local */
-               dst = (smp->strm ? si_dst(smp->strm->csf->si) : sess_dst(smp->sess));
+               dst = (smp->strm ? cs_dst(smp->strm->csf) : sess_dst(smp->sess));
 
        if (!dst)
                return 0;
@@ -207,7 +208,7 @@ int smp_fetch_src_is_local(const struct arg *args, struct sample *smp, const cha
                        src = conn_src(conn);
        }
        else /* src_is_local */
-               src = (smp->strm ? si_src(smp->strm->csf->si) : sess_src(smp->sess));
+               src = (smp->strm ? cs_src(smp->strm->csf) : sess_src(smp->sess));
 
        if (!src)
                return 0;
@@ -240,7 +241,7 @@ smp_fetch_dport(const struct arg *args, struct sample *smp, const char *kw, void
                        dst = conn_dst(conn);
        }
         else /* dst_port */
-               dst = (smp->strm ? si_dst(smp->strm->csf->si) : sess_dst(smp->sess));
+               dst = (smp->strm ? cs_dst(smp->strm->csf) : sess_dst(smp->sess));
 
        if (!dst)
                return 0;