Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

param: Enable absolute bits parameters #4016

Merged
merged 8 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/varnishd/mgt/mgt_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ mcf_wash_param(struct cli *cli, struct parspec *pp, enum mcf_which_e which,
static struct cli_proto cli_params[] = {
{ CLICMD_PARAM_SHOW, "", mcf_param_show, mcf_param_show_json },
{ CLICMD_PARAM_SET, "", mcf_param_set, mcf_param_set_json },
{ CLICMD_PARAM_RESET, "", mcf_param_reset },
{ CLICMD_PARAM_RESET, "", mcf_param_reset, mcf_param_set_json },
{ NULL }
};

Expand Down
51 changes: 28 additions & 23 deletions bin/varnishd/mgt/mgt_param_tweak.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ bit(uint8_t *p, unsigned no, enum bit_do act)
return (*p & b);
}

static inline void
bit_clear(uint8_t *p, unsigned l)
{

memset(p, 0, (l + 7) >> 3);
}

/*--------------------------------------------------------------------
*/

Expand All @@ -627,6 +634,14 @@ bit_tweak(struct vsb *vsb, uint8_t *p, unsigned l, const char *arg,
}
for (i = 1; av[i] != NULL; i++) {
s = av[i];
if (sign == '+' && !strcmp(s, "none")) {
bit_clear(p, l);
continue;
}
if (sign == '-' && !strcmp(s, "all")) {
bit_clear(p, l);
continue;
}
if (*s != '-' && *s != '+') {
VSB_printf(vsb, "Missing '+' or '-' (%s)\n", s);
VAV_Free(av);
Expand Down Expand Up @@ -660,36 +675,26 @@ tweak_generic_bits(struct vsb *vsb, const struct parspec *par, const char *arg,
uint8_t *p, unsigned l, const char * const *tags, const char *desc,
char sign)
{
const char *s;
unsigned j;

if (arg != NULL && !strcmp(arg, "default") &&
strcmp(par->def, "none")) {
memset(p, 0, l >> 3);
if (arg != NULL && !strcmp(arg, "default")) {
/* XXX: deprecated in favor of param.reset */
return (tweak_generic_bits(vsb, par, par->def, p, l, tags,
desc, sign));
}

if (arg != NULL && arg != JSON_FMT) {
if (sign == '+' && !strcmp(arg, "none"))
memset(p, 0, l >> 3);
else
return (bit_tweak(vsb, p, l, arg, tags, desc, sign));
} else {
if (arg == JSON_FMT)
VSB_putc(vsb, '"');
s = "";
for (j = 0; j < l; j++) {
if (bit(p, j, BTST)) {
VSB_printf(vsb, "%s%c%s", s, sign, tags[j]);
s = ",";
}
}
if (*s == '\0')
VSB_cat(vsb, sign == '+' ? "none" : "(all enabled)");
if (arg == JSON_FMT)
VSB_putc(vsb, '"');
if (arg != NULL && arg != JSON_FMT)
return (bit_tweak(vsb, p, l, arg, tags, desc, sign));

if (arg == JSON_FMT)
VSB_putc(vsb, '"');
VSB_cat(vsb, sign == '+' ? "none" : "all");
for (j = 0; j < l; j++) {
if (bit(p, j, BTST))
VSB_printf(vsb, ",%c%s", sign, tags[j]);
}
if (arg == JSON_FMT)
VSB_putc(vsb, '"');
return (0);
}

Expand Down
19 changes: 5 additions & 14 deletions bin/varnishtest/tests/c00054.vtc
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
varnishtest "bitmap params masking"


server s1 {
rxreq
txresp
} -start

varnish v1 -vcl+backend {} -start

varnish v1 -cliok "param.show vsl_mask"
varnish v1 -cliok "param.set vsl_mask -VCL_trace"
varnish v1 -cliok "param.show vsl_mask"
varnish v1 -cliok "param.set vsl_mask -WorkThread,-TTL"
varnish v1 -cliok "param.show vsl_mask"
varnish v1 -cliok "param.set vsl_mask +WorkThread,+TTL,+Hash"
varnish v1 -cliok "param.show vsl_mask"

varnish v1 -cliexpect {"value": "none"} "param.set -j feature none"
varnish v1 -cliexpect {"value": "all"} "param.set -j vsl_mask all"
varnish v1 -cliexpect {"value": "all(,-\w+)+"} "param.reset -j vsl_mask"

varnish v1 -clierr 106 "param.set vsl_mask FooBar"
varnish v1 -clierr 106 "param.set vsl_mask -FooBar"
varnish v1 -clierr 106 {param.set vsl_mask \"}
Expand All @@ -24,9 +21,3 @@ varnish v1 -cliok "param.show debug"
varnish v1 -cliok "param.show feature"
varnish v1 -cliok "param.set feature +short_panic"
varnish v1 -cliok "param.show feature"


client c1 {
txreq
rxresp
} -run
6 changes: 4 additions & 2 deletions include/tbl/cli_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ CLI_CMD(VCL_LABEL,

CLI_CMD(PARAM_RESET,
"param.reset",
"param.reset <param>",
"param.reset [-j] <param>",
"Reset parameter to default value.",
"",
" The JSON output is the same as ``param.show -j <param>`` and"
" contains the updated value as it would be represented by a"
" subsequent execution of ``param.show``.\n\n",
1,1
)

Expand Down
10 changes: 7 additions & 3 deletions include/tbl/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -1829,11 +1829,12 @@ PARAM_BITS(
/* name */ feature,
/* fld */ feature_bits,
/* def */
"none,"
"+validate_headers,"
"+vcl_req_reset",
/* descr */
"Enable/Disable various minor features.\n"
"\tdefault\tSet default value\n"
"\tdefault\tSet default value (deprecated: use param.reset)\n"
"\tnone\tDisable all features.\n\n"
"Use +/- prefix to enable/disable individual feature:")
#ifdef PARAM_ALL
Expand All @@ -1847,11 +1848,12 @@ PARAM_BITS(
/* name */ vcc_feature,
/* fld */ vcc_feature_bits,
/* def */
"none,"
"+err_unref,"
"+unsafe_path",
/* descr */
"Enable/Disable various VCC behaviors.\n"
"\tdefault\tSet default value\n"
"\tdefault\tSet default value (deprecated: use param.reset)\n"
"\tnone\tDisable all behaviors.\n\n"
"Use +/- prefix to enable/disable individual behavior:")
#ifdef PARAM_ALL
Expand All @@ -1865,6 +1867,7 @@ PARAM_BITS(
/* name */ vsl_mask,
/* fld */ vsl_mask,
/* def */
"all,"
"-Debug,"
"-ExpKill,"
"-H2RxBody,"
Expand All @@ -1881,7 +1884,8 @@ PARAM_BITS(
"-WorkThread",
/* descr */
"Mask individual VSL messages from being logged.\n"
"\tdefault\tSet default value\n"
"\tall\tEnable all tags\n"
"\tdefault\tSet default value (deprecated: use param.reset)\n"
"\nUse +/- prefix in front of VSL tag name to unmask/mask "
"individual VSL messages.")
PARAM_POST
Expand Down