MEDIUM: acl/pattern: use the same direction scheme
Patterns were using a bitmask to indicate if request or response was desired
in fetch functions and keywords. ACLs were using a bitmask in fetch keywords
and a single bit in fetch functions. ACLs were also using an ACL_PARTIAL bit
in fetch functions indicating that a non-final fetch was performed, which was
an abuse of the existing direction flag.
The change now consists in using :
- a capabilities field for fetch keywords => SMP_CAP_REQ/RES to indicate
if a keyword supports requests, responses, both, etc...
- an option field for fetch functions to indicate what the caller expects
(request/response, final/non-final)
The ACL_PARTIAL bit was reversed to get SMP_OPT_FINAL as it's more explicit
to know we're working on a final buffer than on a non-final one.
ACL_DIR_* were removed, as well as PATTERN_FETCH_*. L4 fetches were improved
to support being called on responses too since they're still available.
The <dir> field of all fetch functions was changed to <opt> which is now
unsigned.
The patch is large but mostly made of cosmetic changes to accomodate this, as
almost no logic change happened.
diff --git a/src/session.c b/src/session.c
index f381f9e..9d1c935 100644
--- a/src/session.c
+++ b/src/session.c
@@ -982,7 +982,7 @@
list_for_each_entry(rule, &s->fe->switching_rules, list) {
int ret;
- ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, ACL_DIR_REQ);
+ ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (rule->cond->pol == ACL_COND_UNLESS)
ret = !ret;
@@ -1017,7 +1017,7 @@
int ret = 1;
if (prst_rule->cond) {
- ret = acl_exec_cond(prst_rule->cond, s->be, s, &s->txn, ACL_DIR_REQ);
+ ret = acl_exec_cond(prst_rule->cond, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (prst_rule->cond->pol == ACL_COND_UNLESS)
ret = !ret;
@@ -1074,7 +1074,7 @@
list_for_each_entry(rule, &px->server_rules, list) {
int ret;
- ret = acl_exec_cond(rule->cond, s->be, s, &s->txn, ACL_DIR_REQ);
+ ret = acl_exec_cond(rule->cond, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (rule->cond->pol == ACL_COND_UNLESS)
ret = !ret;
@@ -1132,7 +1132,7 @@
continue;
if (rule->cond) {
- ret = acl_exec_cond(rule->cond, px, s, &s->txn, ACL_DIR_REQ);
+ ret = acl_exec_cond(rule->cond, px, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (rule->cond->pol == ACL_COND_UNLESS)
ret = !ret;
@@ -1141,7 +1141,7 @@
if (ret) {
struct stktable_key *key;
- key = stktable_fetch_key(rule->table.t, px, s, &s->txn, PATTERN_FETCH_REQ, rule->expr);
+ key = stktable_fetch_key(rule->table.t, px, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->expr);
if (!key)
continue;
@@ -1225,7 +1225,7 @@
continue;
if (rule->cond) {
- ret = acl_exec_cond(rule->cond, px, s, &s->txn, ACL_DIR_RTR);
+ ret = acl_exec_cond(rule->cond, px, s, &s->txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (rule->cond->pol == ACL_COND_UNLESS)
ret = !ret;
@@ -1234,7 +1234,7 @@
if (ret) {
struct stktable_key *key;
- key = stktable_fetch_key(rule->table.t, px, s, &s->txn, PATTERN_FETCH_RTR, rule->expr);
+ key = stktable_fetch_key(rule->table.t, px, s, &s->txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->expr);
if (!key)
continue;
@@ -2326,7 +2326,7 @@
* frontend counters.
*/
static int
-acl_fetch_sc1_get_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2338,7 +2338,7 @@
* backend counters.
*/
static int
-acl_fetch_sc2_get_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2351,7 +2351,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_get_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2386,7 +2386,7 @@
* frontend counters and return it into temp integer.
*/
static int
-acl_fetch_sc1_inc_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2398,7 +2398,7 @@
* backend counters and return it into temp integer.
*/
static int
-acl_fetch_sc2_inc_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2411,7 +2411,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_inc_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2447,7 +2447,7 @@
* frontend counters and return its previous value into temp integer.
*/
static int
-acl_fetch_sc1_clr_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_clr_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2459,7 +2459,7 @@
* backend counters and return its previous value into temp integer.
*/
static int
-acl_fetch_sc2_clr_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_clr_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2472,7 +2472,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_clr_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_clr_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2503,7 +2503,7 @@
/* set temp integer to the cumulated number of connections from the session's tracked FE counters */
static int
-acl_fetch_sc1_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2514,7 +2514,7 @@
/* set temp integer to the cumulated number of connections from the session's tracked BE counters */
static int
-acl_fetch_sc2_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2528,7 +2528,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2562,7 +2562,7 @@
* the configured period.
*/
static int
-acl_fetch_sc1_conn_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_conn_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2575,7 +2575,7 @@
* the configured period.
*/
static int
-acl_fetch_sc2_conn_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_conn_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2589,7 +2589,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_conn_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_conn_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2607,7 +2607,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stksess *ts;
@@ -2653,7 +2653,7 @@
/* set temp integer to the number of concurrent connections from the session's tracked FE counters */
static int
-acl_fetch_sc1_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_conn_cur(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2664,7 +2664,7 @@
/* set temp integer to the number of concurrent connections from the session's tracked BE counters */
static int
-acl_fetch_sc2_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_conn_cur(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2678,7 +2678,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2709,7 +2709,7 @@
/* set temp integer to the cumulated number of sessions from the session's tracked FE counters */
static int
-acl_fetch_sc1_sess_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_sess_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2720,7 +2720,7 @@
/* set temp integer to the cumulated number of sessions from the session's tracked BE counters */
static int
-acl_fetch_sc2_sess_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_sess_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2734,7 +2734,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_sess_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_sess_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2768,7 +2768,7 @@
* the configured period.
*/
static int
-acl_fetch_sc1_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2781,7 +2781,7 @@
* the configured period.
*/
static int
-acl_fetch_sc2_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2795,7 +2795,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2826,7 +2826,7 @@
/* set temp integer to the cumulated number of sessions from the session's tracked FE counters */
static int
-acl_fetch_sc1_http_req_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_http_req_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2837,7 +2837,7 @@
/* set temp integer to the cumulated number of sessions from the session's tracked BE counters */
static int
-acl_fetch_sc2_http_req_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_http_req_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2851,7 +2851,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_http_req_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_http_req_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2885,7 +2885,7 @@
* the configured period.
*/
static int
-acl_fetch_sc1_http_req_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_http_req_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2898,7 +2898,7 @@
* the configured period.
*/
static int
-acl_fetch_sc2_http_req_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_http_req_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2912,7 +2912,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_http_req_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_http_req_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -2943,7 +2943,7 @@
/* set temp integer to the cumulated number of sessions from the session's tracked FE counters */
static int
-acl_fetch_sc1_http_err_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -2954,7 +2954,7 @@
/* set temp integer to the cumulated number of sessions from the session's tracked BE counters */
static int
-acl_fetch_sc2_http_err_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -2968,7 +2968,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_http_err_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -3002,7 +3002,7 @@
* the configured period.
*/
static int
-acl_fetch_sc1_http_err_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_http_err_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -3015,7 +3015,7 @@
* the configured period.
*/
static int
-acl_fetch_sc2_http_err_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_http_err_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -3029,7 +3029,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_http_err_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_http_err_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -3063,7 +3063,7 @@
* session's tracked FE counters.
*/
static int
-acl_fetch_sc1_kbytes_in(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -3076,7 +3076,7 @@
* session's tracked BE counters.
*/
static int
-acl_fetch_sc2_kbytes_in(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -3090,7 +3090,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_kbytes_in(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -3126,7 +3126,7 @@
* counters over the configured period.
*/
static int
-acl_fetch_sc1_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -3139,7 +3139,7 @@
* counters over the configured period.
*/
static int
-acl_fetch_sc2_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -3153,7 +3153,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -3187,7 +3187,7 @@
* tracked FE counters.
*/
static int
-acl_fetch_sc1_kbytes_out(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_kbytes_out(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -3200,7 +3200,7 @@
* tracked BE counters.
*/
static int
-acl_fetch_sc2_kbytes_out(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_kbytes_out(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -3214,7 +3214,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_kbytes_out(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_kbytes_out(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -3250,7 +3250,7 @@
* over the configured period.
*/
static int
-acl_fetch_sc1_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc1_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr1_entry)
@@ -3263,7 +3263,7 @@
* over the configured period.
*/
static int
-acl_fetch_sc2_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_sc2_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
if (!l4->stkctr2_entry)
@@ -3277,7 +3277,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_src_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_src_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
struct stktable_key *key;
@@ -3294,7 +3294,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_table_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_table_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
smp->flags = SMP_F_VOL_TEST;
@@ -3307,7 +3307,7 @@
* Accepts exactly 1 argument of type table.
*/
static int
-acl_fetch_table_avl(struct proxy *px, struct session *l4, void *l7, int dir,
+acl_fetch_table_avl(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp)
{
px = args->data.prx;