From 0ccb744ffb970e3d6e9179366c8c1b81189b36a3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 7 Jan 2013 22:54:17 +0100 Subject: [PATCH] MINOR: listener: rename sample fetch functions and declare the sample keywords 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 | 9 +++++++++ src/listener.c | 27 +++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 635575301..aef2a2c84 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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, diff --git a/src/listener.c b/src/listener.c index 22e386e3a..e9ce07e12 100644 --- a/src/listener.c +++ b/src/listener.c @@ -1,7 +1,7 @@ /* * Listener management functions. * - * Copyright 2000-2012 Willy Tarreau + * Copyright 2000-2013 Willy Tarreau * * 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 #include #include +#include #include /* 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 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 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 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); }