]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: tcp: stop exporting smp_fetch_src()
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Aug 2020 09:31:31 +0000 (11:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Aug 2020 16:51:36 +0000 (18:51 +0200)
This is totally ugly, smp_fetch_src() is exported only so that stick_table.c
can (ab)use it in the {sc,src}_* sample fetch functions. It could be argued
that the sample could have been reconstructed there in place, but we don't
even need to duplicate the code. We'd rather simply retrieve the "src"
fetch's function from where it's used at init time and be done with it.

include/haproxy/proto_tcp.h
src/proto_tcp.c
src/stick_table.c

index e3eeca91c4daf15870f7b9acc8c90ecd23ca1d82..38c02c73df00e5e09c4ac813d03fa61e4289df81 100644 (file)
@@ -35,9 +35,6 @@ int tcp_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir);
 int tcp_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
 int tcp_is_foreign(int fd, sa_family_t family);
 
-/* Export some samples. */
-int smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *private);
-
 #endif /* _HAPROXY_PROTO_TCP_H */
 
 /*
index b2733d650231ec6bf30db29c8ef1b805752c97b5..b4e13fab0f615ce769c8a0a81460f2c7ac48aeb6 100644 (file)
@@ -1211,7 +1211,8 @@ int tcp_pause_listener(struct listener *l)
 /************************************************************************/
 
 /* fetch the connection's source IPv4/IPv6 address */
-int smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
+static int
+smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
        struct connection *cli_conn = objt_conn(smp->sess->origin);
 
index 121ad07c2260c55d52e538f2a95e905871739c67..69bd7adc5e97d66fb2aef20fe6c59f910e52429e 100644 (file)
@@ -45,6 +45,7 @@
 
 /* structure used to return a table key built from a sample */
 static THREAD_LOCAL struct stktable_key static_table_key;
+static int (*smp_fetch_src)(const struct arg *, struct sample *, const char *, void *);
 
 struct stktable *stktables_list;
 struct eb_root stktable_by_name = EB_ROOT;
@@ -2211,7 +2212,7 @@ smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg
                smp.px = NULL;
                smp.sess = sess;
                smp.strm = strm;
-               if (!smp_fetch_src(NULL, &smp, NULL, NULL))
+               if (!smp_fetch_src || !smp_fetch_src(NULL, &smp, NULL, NULL))
                        return NULL;
 
                /* Converts into key. */
@@ -2276,7 +2277,7 @@ smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct ar
        smp.px = NULL;
        smp.sess = sess;
        smp.strm = strm;
-       if (!smp_fetch_src(NULL, &smp, NULL, NULL))
+       if (!smp_fetch_src || !smp_fetch_src(NULL, &smp, NULL, NULL))
                return NULL;
 
        /* Converts into key. */
@@ -2808,7 +2809,7 @@ smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const ch
                return 0;
 
        /* Fetch source address in a sample. */
-       if (!smp_fetch_src(NULL, smp, NULL, NULL))
+       if (!smp_fetch_src || !smp_fetch_src(NULL, smp, NULL, NULL))
                return 0;
 
        /* Converts into key. */
@@ -3856,6 +3857,17 @@ static void cli_release_show_table(struct appctx *appctx)
        }
 }
 
+static void stkt_late_init(void)
+{
+       struct sample_fetch *f;
+
+       f = find_sample_fetch("src", strlen("src"));
+       if (f)
+               smp_fetch_src = f->process;
+}
+
+INITCALL0(STG_INIT, stkt_late_init);
+
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
        { { "clear", "table", NULL }, "clear table    : remove an entry from a table", cli_parse_table_req, cli_io_handler_table, cli_release_show_table, (void *)STK_CLI_ACT_CLR },