]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: support PROXY v2 TLV emission without stream
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 16 May 2024 15:46:36 +0000 (17:46 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 22 May 2024 08:01:57 +0000 (10:01 +0200)
Update API for PROXY protocol header encoding. Previously, it requires
stream parameter to be set. Change make_proxy_line() and associated
functions to add an extra session parameter. This is useful in context
where no stream is instantiated. For example, this is the case for rhttp
preconnect.

This change allows to extend PROXY v2 TLV encoding. Replace
build_logline() which requires a stream instance and call directly
sess_build_logline().

Note that stream parameter is kept as it is necessary for unique ID
encoding.

This change has no functional change for standard connections. However,
it is necessary to support TLV encoding on rhttp preconnect.

include/haproxy/connection.h
src/backend.c
src/connection.c

index 6ca737c0dee41d677aaf74f66d85dfc8f5d302b6..91ddcd6a53c2aaa9316976ee09d8577bd33742ae 100644 (file)
@@ -53,7 +53,7 @@ extern struct mux_stopping_data mux_stopping_data[MAX_THREADS];
 /* receive a PROXY protocol header over a connection */
 int conn_recv_proxy(struct connection *conn, int flag);
 int conn_send_proxy(struct connection *conn, unsigned int flag);
-int make_proxy_line(char *buf, int buf_len, struct server *srv, struct connection *remote, struct stream *strm);
+int make_proxy_line(char *buf, int buf_len, struct server *srv, struct connection *remote, struct stream *strm, struct session *sess);
 struct conn_tlv_list *conn_get_tlv(struct connection *conn, int type);
 
 int conn_append_debug_info(struct buffer *buf, const struct connection *conn, const char *pfx);
index bd6f80e39636e93c0f1c0c1ccd14c32147652a1f..e5444988c2344a0ce5079f591ba6489cec328e5b 100644 (file)
@@ -1424,7 +1424,7 @@ int connect_server(struct stream *s)
 
        /* 5. proxy protocol */
        if (srv && srv->pp_opts) {
-               proxy_line_ret = make_proxy_line(trash.area, trash.size, srv, cli_conn, s);
+               proxy_line_ret = make_proxy_line(trash.area, trash.size, srv, cli_conn, s, strm_sess(s));
                if (proxy_line_ret) {
                        hash_params.proxy_prehash =
                          conn_hash_prehash(trash.area, proxy_line_ret);
index 05704741751c4e4bb5f449d555ace7e217a7330e..97af8f65e50c6d637fa3bd005f0601b48b17b82a 100644 (file)
@@ -1321,10 +1321,11 @@ int conn_send_proxy(struct connection *conn, unsigned int flag)
                 */
 
                if (sc && sc_strm(sc)) {
+                       struct stream *strm = __sc_strm(sc);
                        ret = make_proxy_line(trash.area, trash.size,
                                              objt_server(conn->target),
                                              sc_conn(sc_opposite(sc)),
-                                             __sc_strm(sc));
+                                             strm, strm_sess(strm));
                }
                else {
                        /* The target server expects a LOCAL line to be sent first. Retrieving
@@ -1335,7 +1336,7 @@ int conn_send_proxy(struct connection *conn, unsigned int flag)
 
                        ret = make_proxy_line(trash.area, trash.size,
                                              objt_server(conn->target), conn,
-                                             NULL);
+                                             NULL, conn->owner);
                }
 
                if (!ret)
@@ -1941,7 +1942,7 @@ static int make_tlv(char *dest, int dest_len, char type, uint16_t length, const
 }
 
 /* Note: <remote> is explicitly allowed to be NULL */
-static int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct connection *remote, struct stream *strm)
+static int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct connection *remote, struct stream *strm, struct session *sess)
 {
        const char pp2_signature[] = PP2_SIGNATURE;
        void *tlv_crc32c_p = NULL;
@@ -2022,7 +2023,7 @@ static int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct
                }
        }
 
-       if (strm) {
+       if (sess) {
                struct buffer *replace = NULL;
 
                list_for_each_entry(srv_tlv, &srv->pp_tlvs, list) {
@@ -2036,7 +2037,7 @@ static int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct
                                if (unlikely(!replace))
                                        return 0;
 
-                               replace->data = build_logline(strm, replace->area, replace->size, &srv_tlv->fmt);
+                               replace->data = sess_build_logline(sess, strm, replace->area, replace->size, &srv_tlv->fmt);
 
                                if (unlikely((buf_len - ret) < sizeof(struct tlv))) {
                                        free_trash_chunk(replace);
@@ -2179,12 +2180,12 @@ static int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct
 }
 
 /* Note: <remote> is explicitly allowed to be NULL */
-int make_proxy_line(char *buf, int buf_len, struct server *srv, struct connection *remote, struct stream *strm)
+int make_proxy_line(char *buf, int buf_len, struct server *srv, struct connection *remote, struct stream *strm, struct session *sess)
 {
        int ret = 0;
 
        if (srv && (srv->pp_opts & SRV_PP_V2)) {
-               ret = make_proxy_line_v2(buf, buf_len, srv, remote, strm);
+               ret = make_proxy_line_v2(buf, buf_len, srv, remote, strm, sess);
        }
        else {
                const struct sockaddr_storage *src = NULL;