From: Aurelien DARRAGON Date: Wed, 20 Nov 2024 15:22:22 +0000 (+0100) Subject: MINOR: pattern: split pat_ref_set() X-Git-Tag: v3.2-dev1~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d250b3be862746279e66d2acb50449bb9ef261b;p=thirdparty%2Fhaproxy.git MINOR: pattern: split pat_ref_set() split pat_ref_set() function in 2 distinct functions. Indeed, since 0844bed7d3 ("MEDIUM: map/acl: Improve pat_ref_set() efficiency (for "set-map", "add-acl" action perfs)"), pat_ref_set() prototype was updated to include an extra argument. But the logic behind is not explicit because the function will not only try to set , but also its duplicate (unlike pat_ref_set_elt() which only tries to update ). Thus, to make it clearer and better distinguish between the key-based lookup version and the elt-based one, restotre pat_ref_set() previous prototype and add a dedicated pat_ref_set_elt_duplicate() that takes as argument and tries to update and all duplicates. --- diff --git a/include/haproxy/pattern.h b/include/haproxy/pattern.h index 49e5ad2c20..db0a8a32f3 100644 --- a/include/haproxy/pattern.h +++ b/include/haproxy/pattern.h @@ -188,7 +188,8 @@ struct pat_ref_elt *pat_ref_append(struct pat_ref *ref, const char *pattern, con struct pat_ref_elt *pat_ref_load(struct pat_ref *ref, unsigned int gen, const char *pattern, const char *sample, int line, char **err); int pat_ref_push(struct pat_ref_elt *elt, struct pattern_expr *expr, int patflags, char **err); int pat_ref_add(struct pat_ref *ref, const char *pattern, const char *sample, char **err); -int pat_ref_set(struct pat_ref *ref, const char *pattern, const char *sample, char **err, struct pat_ref_elt *elt); +int pat_ref_set(struct pat_ref *ref, const char *pattern, const char *sample, char **err); +int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value, char **err); int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const char *value, char **err); int pat_ref_delete(struct pat_ref *ref, const char *key); void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt); diff --git a/src/hlua.c b/src/hlua.c index 10f702798b..49c7942ac9 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -2294,7 +2294,7 @@ static int hlua_set_map(lua_State *L) HA_RWLOCK_WRLOCK(PATREF_LOCK, &ref->lock); elt = pat_ref_find_elt(ref, key); if (elt) - pat_ref_set(ref, key, value, NULL, elt); + pat_ref_set_elt_duplicate(ref, elt, value, NULL); else pat_ref_add(ref, key, value, NULL); HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ref->lock); diff --git a/src/http_act.c b/src/http_act.c index b7cc5f209e..a24f5fe30b 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -1848,7 +1848,7 @@ static enum act_return http_action_set_map(struct act_rule *rule, struct proxy * elt = pat_ref_find_elt(ref, key->area); if (elt) { /* update entry if it exists */ - pat_ref_set(ref, key->area, value->area, NULL, elt); + pat_ref_set_elt_duplicate(ref, elt, value->area, NULL); } else { /* insert a new entry */ diff --git a/src/map.c b/src/map.c index b285a1f51a..9fce3ddd04 100644 --- a/src/map.c +++ b/src/map.c @@ -808,7 +808,7 @@ static int cli_parse_set_map(char **args, char *payload, struct appctx *appctx, */ err = NULL; HA_RWLOCK_WRLOCK(PATREF_LOCK, &ctx->ref->lock); - if (!pat_ref_set(ctx->ref, args[3], args[4], &err, NULL)) { + if (!pat_ref_set(ctx->ref, args[3], args[4], &err)) { HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ctx->ref->lock); if (err) return cli_dynerr(appctx, memprintf(&err, "%s.\n", err)); diff --git a/src/pattern.c b/src/pattern.c index 98b2b3d1d7..e8e995deba 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -1754,21 +1754,10 @@ int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const cha return 0; } -/* This function modifies to the sample of all patterns matching - * under . - */ -int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **err, struct pat_ref_elt *elt) +static int pat_ref_set_from_node(struct pat_ref *ref, struct ebmb_node *node, const char *value, char **err) { + struct pat_ref_elt *elt; int found = 0; - struct ebmb_node *node; - - if (elt) { - node = &elt->node; - } - else { - /* Look for pattern in the reference. */ - node = ebst_lookup(&ref->ebmb_root, key); - } while (node) { char *tmp_err = NULL; @@ -1792,6 +1781,25 @@ int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char ** return 1; } +/* modifies to the sample for and all its duplicates */ +int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value, + char **err) +{ + return pat_ref_set_from_node(ref, &elt->node, value, err); +} + +/* This function modifies to the sample of all patterns matching + * under . + */ +int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **err) +{ + struct ebmb_node *node; + + /* Look for pattern in the reference. */ + node = ebst_lookup(&ref->ebmb_root, key); + return pat_ref_set_from_node(ref, node, value, err); +} + /* helper function to create and initialize a generic pat_ref struct * * Returns the new struct on success and NULL on failure (memory allocation