MINOR: frontend: 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 :

      fe_conn, fe_id, fe_sess_rate

The fetch functions have been renamed "smp_fetch_*".
This commit is contained in:
Willy Tarreau 2013-01-07 22:48:29 +01:00
parent 1a7eca19b8
commit d6896bc72a
2 changed files with 46 additions and 8 deletions

View File

@ -9636,6 +9636,27 @@ The list of currently supported pattern fetch functions is the following :
ports to some clients for a whole application session. It is of
type integer and only works with such tables.
fe_conn([<frontend>])
Returns the number of currently established connections on the
the frontend, possibly including the connection being evaluated.
If no frontend name is specified, the current one is used. But
it is also possible to check another frontend. It can be used to
return a sorry page before hard-blocking, or to use a specific
backend to drain new requests when the farm is considered full.
This is mostly used with ACLs but can also be used to pass some
statistics to servers in HTTP headers. See also the "dst_conn",
"be_conn", "fe_sess_rate" criteria.
fe_id Returns an integer containing the current frontend's id.
fe_sess_rate([<frontend>])
Returns an integer value corresponding to the sessions creation
rate on the frontend, in number of new sessions per second. This
is used with ACLs to limit the incoming session rate to an
acceptable range in order to prevent abuse of service at the
earliest moment. It can also be useful to add this element to
logs using a log-format directive.
hdr(<name>[,<occ>])
This extracts the last occurrence of header <name> in an HTTP
request. Optionally, a specific occurrence might be specified as

View File

@ -1,7 +1,7 @@
/*
* Frontend variables and functions.
*
* Copyright 2000-2011 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
@ -41,6 +41,7 @@
#include <proto/proto_tcp.h>
#include <proto/proto_http.h>
#include <proto/proxy.h>
#include <proto/sample.h>
#include <proto/session.h>
#include <proto/stream_interface.h>
#include <proto/task.h>
@ -208,9 +209,13 @@ int frontend_accept(struct session *s)
return -1;
}
/************************************************************************/
/* All supported sample and ACL keywords must be declared here. */
/************************************************************************/
/* set temp integer to the id of the frontend */
static int
acl_fetch_fe_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
smp_fetch_fe_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
smp->flags = SMP_F_VOL_SESS;
@ -224,7 +229,7 @@ acl_fetch_fe_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt
* an undefined behaviour.
*/
static int
acl_fetch_fe_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
smp_fetch_fe_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
smp->flags = SMP_F_VOL_TEST;
@ -238,7 +243,7 @@ acl_fetch_fe_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned
* an undefined behaviour.
*/
static int
acl_fetch_fe_conn(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
smp_fetch_fe_conn(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
smp->flags = SMP_F_VOL_TEST;
@ -248,20 +253,32 @@ acl_fetch_fe_conn(struct proxy *px, struct session *l4, void *l7, unsigned int o
}
/* 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 = {{ },{
{ "fe_conn", smp_fetch_fe_conn, ARG1(1,FE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "fe_id", smp_fetch_fe_id, 0, NULL, SMP_T_UINT, SMP_USE_FTEND, },
{ "fe_sess_rate", smp_fetch_fe_sess_rate, ARG1(1,FE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ /* 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 = {{ },{
{ "fe_conn", acl_parse_int, acl_fetch_fe_conn, acl_match_int, ACL_USE_NOTHING, ARG1(1,FE) },
{ "fe_id", acl_parse_int, acl_fetch_fe_id, acl_match_int, ACL_USE_NOTHING, 0 },
{ "fe_sess_rate", acl_parse_int, acl_fetch_fe_sess_rate, acl_match_int, ACL_USE_NOTHING, ARG1(1,FE) },
{ NULL, NULL, NULL, NULL },
{ "fe_conn", acl_parse_int, smp_fetch_fe_conn, acl_match_int, ACL_USE_NOTHING, ARG1(1,FE) },
{ "fe_id", acl_parse_int, smp_fetch_fe_id, acl_match_int, ACL_USE_NOTHING, 0 },
{ "fe_sess_rate", acl_parse_int, smp_fetch_fe_sess_rate, acl_match_int, ACL_USE_NOTHING, ARG1(1,FE) },
{ /* END */ },
}};
__attribute__((constructor))
static void __frontend_init(void)
{
sample_register_fetches(&smp_kws);
acl_register_keywords(&acl_kws);
}