diff --git a/doc/configuration.txt b/doc/configuration.txt index d01622b3e..635575301 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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([]) + 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([]) + 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([,]) This extracts the last occurrence of header in an HTTP request. Optionally, a specific occurrence might be specified as diff --git a/src/frontend.c b/src/frontend.c index e7779e485..d7b093991 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -1,7 +1,7 @@ /* * Frontend variables and functions. * - * Copyright 2000-2011 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 @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -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 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 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); }