From: Patrick Hemmer Date: Mon, 26 Jun 2023 18:43:48 +0000 (-0400) Subject: MINOR: peers: add peers keyword registration X-Git-Tag: v2.9-dev2~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57926fe8a30a32d573450201ea031a520820ff0e;p=thirdparty%2Fhaproxy.git MINOR: peers: add peers keyword registration This adds support for registering keywords in the 'peers' section. --- diff --git a/include/haproxy/peers-t.h b/include/haproxy/peers-t.h index 9535518a78..363030ebf2 100644 --- a/include/haproxy/peers-t.h +++ b/include/haproxy/peers-t.h @@ -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 */ diff --git a/include/haproxy/peers.h b/include/haproxy/peers.h index c5918690d6..e3c5fd34a0 100644 --- a/include/haproxy/peers.h +++ b/include/haproxy/peers.h @@ -31,12 +31,14 @@ #include +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) diff --git a/src/cfgparse.c b/src/cfgparse.c index 661f5d9808..d5422f2c5e 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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; diff --git a/src/peers.c b/src/peers.c index 1bbc1ca056..5bf85406b6 100644 --- a/src/peers.c +++ b/src/peers.c @@ -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,