]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: rename sample fetch functions and declare the sample keywords
authorWilly Tarreau <w@1wt.eu>
Mon, 7 Jan 2013 21:54:17 +0000 (22:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 3 Apr 2013 00:12:57 +0000 (02:12 +0200)
The following sample fetch functions were only usable by ACLs but are now
usable by sample fetches too :

          dst_conn, so_id,

The fetch functions have been renamed "smp_fetch_*".

doc/configuration.txt
src/listener.c

index 63557530174c125ea4fba5e71cd02126f12a1a19..aef2a2c846b83d4370b085d6070fa2cc6ee2d34b 100644 (file)
@@ -9630,6 +9630,13 @@ The list of currently supported pattern fetch functions is the following :
                On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent,
                according to RFC 4291.
 
+  dst_conn
+               Returns an integer value corresponding to the number of
+               currently established connections on the same socket including
+               the one being evaluated. It is normally used with ACLs but can
+               as well be used to pass the information to servers in an HTTP
+               header or in logs. See also "fe_conn" and "dst_conn".
+
   dst_port     This is the destination TCP port of the session on the client
                side, which is the port the client connected to. This might be
                used when running in transparent mode or when assigning dynamic
@@ -9787,6 +9794,8 @@ The list of currently supported pattern fetch functions is the following :
 
                See also : "appsession"
 
+  so_id        Returns an integer containing the listening socket's id.
+
   src          This is the source IPv4 address of the client of the session.
                It is of type IPv4 and works on both IPv4 and IPv6 tables.
                On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent,
index 22e386e3ae7de844c97642a627ac2531c6bef393..e9ce07e128ed615a264b199edddf7fef6cb91c2c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Listener management functions.
  *
- * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
+ * Copyright 2000-2013 Willy Tarreau <w@1wt.eu>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -28,6 +28,7 @@
 #include <proto/fd.h>
 #include <proto/freq_ctr.h>
 #include <proto/log.h>
+#include <proto/sample.h>
 #include <proto/task.h>
 
 /* List head of all known bind keywords */
@@ -481,12 +482,12 @@ void bind_dump_kws(char **out)
 }
 
 /************************************************************************/
-/*           All supported ACL keywords must be declared here.          */
+/*      All supported sample and ACL keywords must be declared here.    */
 /************************************************************************/
 
 /* set temp integer to the number of connexions to the same listening socket */
 static int
-acl_fetch_dconn(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+smp_fetch_dconn(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
                 const struct arg *args, struct sample *smp)
 {
        smp->type = SMP_T_UINT;
@@ -496,7 +497,7 @@ acl_fetch_dconn(struct proxy *px, struct session *l4, void *l7, unsigned int opt
 
 /* set temp integer to the id of the socket (listener) */
 static int
-acl_fetch_so_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+smp_fetch_so_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
                 const struct arg *args, struct sample *smp)
 {
        smp->type = SMP_T_UINT;
@@ -639,13 +640,22 @@ static int bind_parse_nice(char **args, int cur_arg, struct proxy *px, struct bi
 }
 
 
+/* Note: must not be declared <const> as its list will be overwritten.
+ * Please take care of keeping this list alphabetically sorted.
+ */
+static struct sample_fetch_kw_list smp_kws = {{ },{
+       { "dst_conn", smp_fetch_dconn, 0, NULL, SMP_T_UINT, SMP_USE_FTEND, },
+       { "so_id",    smp_fetch_so_id, 0, NULL, SMP_T_UINT, SMP_USE_FTEND, },
+       { /* END */ },
+}};
+
 /* Note: must not be declared <const> as its list will be overwritten.
  * Please take care of keeping this list alphabetically sorted.
  */
 static struct acl_kw_list acl_kws = {{ },{
-       { "dst_conn",   acl_parse_int,   acl_fetch_dconn,    acl_match_int, ACL_USE_NOTHING, 0 },
-       { "so_id",      acl_parse_int,   acl_fetch_so_id,    acl_match_int, ACL_USE_NOTHING, 0 },
-       { NULL, NULL, NULL, NULL },
+       { "dst_conn",   acl_parse_int,   smp_fetch_dconn,    acl_match_int, ACL_USE_NOTHING, 0 },
+       { "so_id",      acl_parse_int,   smp_fetch_so_id,    acl_match_int, ACL_USE_NOTHING, 0 },
+       { /* END */ },
 }};
 
 /* Note: must not be declared <const> as its list will be overwritten.
@@ -662,12 +672,13 @@ static struct bind_kw_list bind_kws = { "ALL", { }, {
        { "maxconn",      bind_parse_maxconn,      1 }, /* set maxconn of listening socket */
        { "name",         bind_parse_name,         1 }, /* set name of listening socket */
        { "nice",         bind_parse_nice,         1 }, /* set nice of listening socket */
-       { NULL, NULL, 0 },
+       { /* END */ },
 }};
 
 __attribute__((constructor))
 static void __listener_init(void)
 {
+       sample_register_fetches(&smp_kws);
        acl_register_keywords(&acl_kws);
        bind_register_keywords(&bind_kws);
 }