]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: peers: add peers keyword registration
authorPatrick Hemmer <phemmer@haproxy.com>
Mon, 26 Jun 2023 18:43:48 +0000 (14:43 -0400)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 20 Jul 2023 16:12:44 +0000 (18:12 +0200)
This adds support for registering keywords in the 'peers' section.

include/haproxy/peers-t.h
include/haproxy/peers.h
src/cfgparse.c
src/peers.c

index 9535518a7853721ccb41d8c6aaa13ecf235debb9..363030ebf20bda50772d81450e62857196b798ec 100644 (file)
@@ -139,5 +139,21 @@ struct dcache {
        size_t max_entries;
 };
 
+struct peers_keyword {
+       const char *kw;
+       int (*parse)(
+               char **args,
+               struct peers *curpeer,
+               const char *file,
+               int line,
+               char **err);
+       int flags;
+};
+
+struct peers_kw_list {
+       struct list list;
+       struct peers_keyword kw[VAR_ARRAY];
+};
+
 #endif /* _HAPROXY_PEERS_T_H */
 
index c5918690d62c032ac6fa5751ab7fe980f3743f1a..e3c5fd34a0971ca52414f6ca445d7584745b873e 100644 (file)
 #include <haproxy/stream-t.h>
 
 
+extern struct peers_kw_list peers_keywords;
 extern struct peers *cfg_peers;
 
 int peers_init_sync(struct peers *peers);
 int peers_alloc_dcache(struct peers *peers);
 int peers_register_table(struct peers *, struct stktable *table);
 void peers_setup_frontend(struct proxy *fe);
+void peers_register_keywords(struct peers_kw_list *pkwl);
 
 #if defined(USE_OPENSSL)
 static inline enum obj_type *peer_session_target(struct peer *p, struct stream *s)
index 661f5d98082bda3fca1233bcca3d957e640fdf6c..d5422f2c5e72a3c6fb13074b4c75ea2758352c49 100644 (file)
@@ -1076,6 +1076,29 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                curpeers->disabled = 0;
        }
        else if (*args[0] != 0) {
+               struct peers_kw_list *pkwl;
+               int index;
+               int rc = -1;
+
+               list_for_each_entry(pkwl, &peers_keywords.list, list) {
+                       for (index = 0; pkwl->kw[index].kw != NULL; index++) {
+                               if (strcmp(pkwl->kw[index].kw, args[0]) == 0) {
+                                       rc = pkwl->kw[index].parse(args, curpeers, file, linenum, &errmsg);
+                                       if (rc < 0) {
+                                               ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
+                                               err_code |= ERR_ALERT | ERR_FATAL;
+                                               goto out;
+                                       }
+                                       else if (rc > 0) {
+                                               ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
+                                               err_code |= ERR_WARN;
+                                               goto out;
+                                       }
+                                       goto out;
+                               }
+                       }
+               }
+
                ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
                err_code |= ERR_ALERT | ERR_FATAL;
                goto out;
@@ -4810,6 +4833,23 @@ void cfg_dump_registered_keywords()
                        dump_act_rules(&http_res_keywords.list,       "\thttp-response ");
                        dump_act_rules(&http_after_res_keywords.list, "\thttp-after-response ");
                }
+               if (section == CFG_PEERS) {
+                       struct peers_kw_list *pkwl;
+                       const struct peers_keyword *pkwp, *pkwn;
+                       for (pkwn = pkwp = NULL;; pkwp = pkwn) {
+                               list_for_each_entry(pkwl, &peers_keywords.list, list) {
+                                       for (index = 0; pkwl->kw[index].kw != NULL; index++) {
+                                               if (strordered(pkwp ? pkwp->kw : NULL,
+                                                              pkwl->kw[index].kw,
+                                                              pkwn != pkwp ? pkwn->kw : NULL))
+                                                       pkwn = &pkwl->kw[index];
+                                       }
+                               }
+                               if (pkwn == pkwp)
+                                       break;
+                               printf("\t%s\n", pkwn->kw);
+                       }
+               }
                if (section == CFG_CRTLIST) {
                        /* displays the keyword available for the crt-lists */
                        extern struct ssl_crtlist_kw ssl_crtlist_kws[] __maybe_unused;
index 1bbc1ca056525306f982bb5dae6b3d4b14a71aea..5bf85406b6b0461fb75137f5cf680ac674f932f6 100644 (file)
@@ -4070,6 +4070,16 @@ static int cli_io_handler_show_peers(struct appctx *appctx)
        return ret;
 }
 
+
+struct peers_kw_list peers_keywords = {
+       .list = LIST_HEAD_INIT(peers_keywords.list)
+};
+
+void peers_register_keywords(struct peers_kw_list *pkwl)
+{
+       LIST_APPEND(&peers_keywords.list, &pkwl->list);
+}
+
 /* config parser for global "tune.peers.max-updates-at-once" */
 static int cfg_parse_max_updt_at_once(char **args, int section_type, struct proxy *curpx,
                                       const struct proxy *defpx, const char *file, int line,