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_*".
This commit is contained in:
Willy Tarreau 2013-01-07 22:54:17 +01:00
parent d6896bc72a
commit 0ccb744ffb
2 changed files with 28 additions and 8 deletions

View 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, On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent,
according to RFC 4291. 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 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 side, which is the port the client connected to. This might be
used when running in transparent mode or when assigning dynamic 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" 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. 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. It is of type IPv4 and works on both IPv4 and IPv6 tables.
On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent, On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent,

View File

@ -1,7 +1,7 @@
/* /*
* Listener management functions. * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -28,6 +28,7 @@
#include <proto/fd.h> #include <proto/fd.h>
#include <proto/freq_ctr.h> #include <proto/freq_ctr.h>
#include <proto/log.h> #include <proto/log.h>
#include <proto/sample.h>
#include <proto/task.h> #include <proto/task.h>
/* List head of all known bind keywords */ /* 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 */ /* set temp integer to the number of connexions to the same listening socket */
static int 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) const struct arg *args, struct sample *smp)
{ {
smp->type = SMP_T_UINT; 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) */ /* set temp integer to the id of the socket (listener) */
static int 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) const struct arg *args, struct sample *smp)
{ {
smp->type = SMP_T_UINT; 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. /* Note: must not be declared <const> as its list will be overwritten.
* Please take care of keeping this list alphabetically sorted. * Please take care of keeping this list alphabetically sorted.
*/ */
static struct acl_kw_list acl_kws = {{ },{ static struct acl_kw_list acl_kws = {{ },{
{ "dst_conn", acl_parse_int, acl_fetch_dconn, acl_match_int, ACL_USE_NOTHING, 0 }, { "dst_conn", acl_parse_int, smp_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 }, { "so_id", acl_parse_int, smp_fetch_so_id, acl_match_int, ACL_USE_NOTHING, 0 },
{ NULL, NULL, NULL, NULL }, { /* END */ },
}}; }};
/* Note: must not be declared <const> as its list will be overwritten. /* 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 */ { "maxconn", bind_parse_maxconn, 1 }, /* set maxconn of listening socket */
{ "name", bind_parse_name, 1 }, /* set name of listening socket */ { "name", bind_parse_name, 1 }, /* set name of listening socket */
{ "nice", bind_parse_nice, 1 }, /* set nice of listening socket */ { "nice", bind_parse_nice, 1 }, /* set nice of listening socket */
{ NULL, NULL, 0 }, { /* END */ },
}}; }};
__attribute__((constructor)) __attribute__((constructor))
static void __listener_init(void) static void __listener_init(void)
{ {
sample_register_fetches(&smp_kws);
acl_register_keywords(&acl_kws); acl_register_keywords(&acl_kws);
bind_register_keywords(&bind_kws); bind_register_keywords(&bind_kws);
} }