]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: action: Use a generic function to check validity of an action rule list
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 25 Mar 2021 16:19:04 +0000 (17:19 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 1 Apr 2021 13:34:22 +0000 (15:34 +0200)
The check_action_rules() function is now used to check the validity of an
action rule list. It is used from check_config_validity() function to check
L5/6/7 rulesets.

include/haproxy/action.h
src/action.c
src/cfgparse.c

index 845c0fd8b9cd00719a7a0dd87cbc9802d4ce6591..62fba7ed3daf8ec8febceb76b6307be0701da6eb 100644 (file)
@@ -76,6 +76,11 @@ static inline void action_build_list(struct list *keywords,
                *p = '\0';
 }
 
+/* Check an action ruleset validity. It returns the number of error encountered
+ * andd err_code is updated if a warning is emitted.
+ */
+int check_action_rules(struct list *rules, struct proxy *px, int *err_code);
+
 /* Find and check the target table used by an action track-sc*. This
  * function should be called during the configuration validity check.
  *
index 29eae81138d13b37b72ce47c3719e521a0fe9511..7b017f618580537f1f312951da761781b3af5e98 100644 (file)
 #include <haproxy/tools.h>
 
 
+/* Check an action ruleset validity. It returns the number of error encountered
+ * andd err_code is updated if a warning is emitted.
+ */
+int check_action_rules(struct list *rules, struct proxy *px, int *err_code)
+{
+       struct act_rule *rule;
+       char *errmsg = NULL;
+       int err = 0;
+
+       list_for_each_entry(rule, rules, list) {
+               if (rule->check_ptr && !rule->check_ptr(rule, px, &errmsg)) {
+                       ha_alert("Proxy '%s': %s.\n", px->id, errmsg);
+                       err++;
+               }
+
+               free(errmsg);
+               errmsg = NULL;
+       }
+
+       return err;
+}
+
 /* Find and check the target table used by an action track-sc*. This
  * function should be called during the configuration validity check.
  *
index 6f8522e41e5f0ef9145ff821b59dc146f3d142e5..5562185eb40ea209ddb9fd520add61a556e4d936 100644 (file)
@@ -34,7 +34,7 @@
 #include <unistd.h>
 
 #include <haproxy/acl.h>
-#include <haproxy/action-t.h>
+#include <haproxy/action.h>
 #include <haproxy/api.h>
 #include <haproxy/auth.h>
 #include <haproxy/backend.h>
@@ -2007,7 +2007,6 @@ int check_config_validity()
                struct switching_rule *rule;
                struct server_rule *srule;
                struct sticking_rule *mrule;
-               struct act_rule *arule;
                struct logsrv *tmplogsrv;
                unsigned int next_id;
                int nbproc;
@@ -2494,65 +2493,14 @@ int check_config_validity()
                        }
                }
 
-               /* check validity for 'tcp-request' layer 4 rules */
-               list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) {
-                       err = NULL;
-                       if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
-                               ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
-                               free(err);
-                               cfgerr++;
-                       }
-               }
-
-               /* check validity for 'tcp-request' layer 5 rules */
-               list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) {
-                       err = NULL;
-                       if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
-                               ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
-                               free(err);
-                               cfgerr++;
-                       }
-               }
-
-               /* check validity for 'tcp-request' layer 6 rules */
-               list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) {
-                       err = NULL;
-                       if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
-                               ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
-                               free(err);
-                               cfgerr++;
-                       }
-               }
-
-               /* check validity for 'http-request' layer 7 rules */
-               list_for_each_entry(arule, &curproxy->http_req_rules, list) {
-                       err = NULL;
-                       if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
-                               ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
-                               free(err);
-                               cfgerr++;
-                       }
-               }
-
-               /* check validity for 'http-response' layer 7 rules */
-               list_for_each_entry(arule, &curproxy->http_res_rules, list) {
-                       err = NULL;
-                       if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
-                               ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
-                               free(err);
-                               cfgerr++;
-                       }
-               }
-
-               /* check validity for 'http-after-response' layer 7 rules */
-               list_for_each_entry(arule, &curproxy->http_after_res_rules, list) {
-                       err = NULL;
-                       if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) {
-                               ha_alert("Proxy '%s': %s.\n", curproxy->id, err);
-                               free(err);
-                               cfgerr++;
-                       }
-               }
+               /* check validity for 'tcp-request' layer 4/5/6/7 rules */
+               cfgerr += check_action_rules(&curproxy->tcp_req.l4_rules, curproxy, &err_code);
+               cfgerr += check_action_rules(&curproxy->tcp_req.l5_rules, curproxy, &err_code);
+               cfgerr += check_action_rules(&curproxy->tcp_req.inspect_rules, curproxy, &err_code);
+               cfgerr += check_action_rules(&curproxy->tcp_rep.inspect_rules, curproxy, &err_code);
+               cfgerr += check_action_rules(&curproxy->http_req_rules, curproxy, &err_code);
+               cfgerr += check_action_rules(&curproxy->http_res_rules, curproxy, &err_code);
+               cfgerr += check_action_rules(&curproxy->http_after_res_rules, curproxy, &err_code);
 
                /* Warn is a switch-mode http is used on a TCP listener with servers but no backend */
                if (!curproxy->defbe.name && LIST_ISEMPTY(&curproxy->switching_rules) && curproxy->srv) {