]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: checks: Add a reverse non-comment rule iterator to get last rule
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 15 Apr 2020 09:34:04 +0000 (11:34 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Apr 2020 07:39:38 +0000 (09:39 +0200)
the get_last_tcpcheck_rule() function iters on a rule list in the reverse order
and returns the first non comment and non action-kw rule. If no such rule is
found, NULL is returned.

src/checks.c

index e43e73224ad1a62805a648158cb8a3988fbc5838..8ff6bc83cbba4503bc748f21628c2377f469d0c2 100644 (file)
@@ -1125,6 +1125,20 @@ static struct tcpcheck_rule *get_first_tcpcheck_rule(struct tcpcheck_rules *rule
        return NULL;
 }
 
+/* returns the last NON-COMMENT tcp-check rule from list <list> or NULL if none
+ * was found.
+ */
+static struct tcpcheck_rule *get_last_tcpcheck_rule(struct tcpcheck_rules *rules)
+{
+       struct tcpcheck_rule *r;
+
+       list_for_each_entry_rev(r, rules->list, list) {
+               if (r->action != TCPCHK_ACT_COMMENT && r->action != TCPCHK_ACT_ACTION_KW)
+                       return r;
+       }
+       return NULL;
+}
+
 /* returns the NON-COMMENT tcp-check rule from list <list> following <start> or
  * NULL if non was found. If <start> is NULL, it relies on
  * get_first_tcpcheck_rule().