]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: action: Add function to check rules using an action ACT_ACTION_TRK_*
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 18 Sep 2017 12:43:55 +0000 (14:43 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 10:36:12 +0000 (11:36 +0100)
The function "check_trk_action" has been added to find and check the target
table for rules using an action ACT_ACTION_TRK_*.

Makefile
include/proto/action.h
src/action.c [new file with mode: 0644]
src/proto_http.c
src/tcp_rules.c

index 0ab30675b6865eda52d9311715092a754ea5202c..c79e4ae251c5059400284e841b009f6406485b5c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -843,7 +843,7 @@ OBJS = src/cfgparse.o src/proto_http.o src/stats.o src/server.o src/stream.o \
        src/regex.o src/queue.o src/frontend.o src/arg.o src/proto_uxst.o \
        src/raw_sock.o src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o \
        src/lb_fas.o src/applet.o src/hdr_idx.o src/ev_select.o src/hash.o \
-       src/lb_map.o src/base64.o src/sha1.o src/protocol.o src/h1.o
+       src/lb_map.o src/base64.o src/sha1.o src/protocol.o src/h1.o src/action.o
 
 EBTREE_OBJS = $(EBTREE_DIR)/ebtree.o \
               $(EBTREE_DIR)/eb32tree.o $(EBTREE_DIR)/eb64tree.o \
index ce94aa04962aa7da78fbf486f6de2602c03dcf05..e3015ec11558a27722923df7f10bdd86d5374a5a 100644 (file)
@@ -76,4 +76,12 @@ static inline int trk_idx(int trk_action)
        return trk_action - ACT_ACTION_TRK_SC0;
 }
 
+/* Find and check the target table used by an action ACT_ACTION_TRK_*. This
+ * function should be called during the configuration validity check.
+ *
+ * The function returns 1 in success case, otherwise, it returns 0 and err is
+ * filled.
+ */
+int check_trk_action(struct act_rule *rule, struct proxy *px, char **err);
+
 #endif /* _PROTO_ACTION_H */
diff --git a/src/action.c b/src/action.c
new file mode 100644 (file)
index 0000000..54d27a0
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Action management functions.
+ *
+ * Copyright 2017 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <common/config.h>
+#include <common/memory.h>
+#include <common/mini-clist.h>
+#include <common/standard.h>
+
+#include <proto/action.h>
+#include <proto/proxy.h>
+#include <proto/stick_table.h>
+
+
+/* Find and check the target table used by an action ACT_ACTION_TRK_*. This
+ * function should be called during the configuration validity check.
+ *
+ * The function returns 1 in success case, otherwise, it returns 0 and err is
+ * filled.
+ */
+int check_trk_action(struct act_rule *rule, struct proxy *px, char **err)
+{
+       struct proxy *target;
+
+       if (rule->arg.trk_ctr.table.n)
+               target = proxy_tbl_by_name(rule->arg.trk_ctr.table.n);
+       else
+               target = px;
+
+       if (!target) {
+               memprintf(err, "unable to find table '%s' referenced by track-sc%d",
+                         rule->arg.trk_ctr.table.n, trk_idx(rule->action));
+               return 0;
+       }
+       else if (target->table.size == 0) {
+               memprintf(err, "table '%s' used but not configured",
+                         rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id);
+               return 0;
+       }
+       else if (!stktable_compatible_sample(rule->arg.trk_ctr.expr,  target->table.type)) {
+               memprintf(err, "stick-table '%s' uses a type incompatible with the 'track-sc%d' rule",
+                         rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id,
+                         trk_idx(rule->action));
+               return 0;
+       }
+       else {
+               free(rule->arg.trk_ctr.table.n);
+               rule->arg.trk_ctr.table.t = &target->table;
+               /* Note: if we decide to enhance the track-sc syntax, we may be
+                * able to pass a list of counters to track and allocate them
+                * right here using stktable_alloc_data_type().
+                */
+       }
+       return 1;
+}
+
index 23f683c60e6828662ae6329493e34202384f4a5b..3c37ade2725a3a4014f98746a1646957cc12f8c2 100644 (file)
@@ -8404,6 +8404,7 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li
                }
                rule->arg.trk_ctr.expr = expr;
                rule->action = ACT_ACTION_TRK_SC0 + args[0][8] - '0';
+               rule->check_ptr = check_trk_action;
        } else if (strcmp(args[0], "redirect") == 0) {
                struct redirect_rule *redir;
                char *errmsg = NULL;
@@ -9008,6 +9009,7 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li
                }
                rule->arg.trk_ctr.expr = expr;
                rule->action = ACT_ACTION_TRK_SC0 + args[0][8] - '0';
+               rule->check_ptr = check_trk_action;
        } else if (((custom = action_http_res_custom(args[0])) != NULL)) {
                char *errmsg = NULL;
                cur_arg = 1;
index d15b153a8d5e21d5a73ae2c6373d0b115b09feaa..f259d515cb41a3274749f0cf26df1f93981ad095 100644 (file)
@@ -773,6 +773,7 @@ static int tcp_parse_request_rule(char **args, int arg, int section_type,
                }
                rule->arg.trk_ctr.expr = expr;
                rule->action = ACT_ACTION_TRK_SC0 + args[kw][8] - '0';
+               rule->check_ptr = check_trk_action;
        }
        else if (strcmp(args[arg], "expect-proxy") == 0) {
                if (strcmp(args[arg+1], "layer4") != 0) {