Skip to content

Commit 39eea6e

Browse files
committed
vcc_acl: Add +fold,noreport modifier to omit fold warnings
With a lot of folding going on, the warnings can easily bury more relevant CLI output.
1 parent 4fffeeb commit 39eea6e

File tree

3 files changed

+80
-14
lines changed

3 files changed

+80
-14
lines changed

bin/varnishtest/tests/c00005.vtc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,39 @@ client c1 {
375375
} -run
376376

377377
logexpect l1 -wait
378+
379+
# test +fold,noreport
380+
varnish v1 -cliexpect "^$" {vcl.inline silent << EOF
381+
vcl 4.1;
382+
383+
backend dummy None;
384+
385+
acl acl1 +log +pedantic +fold,noreport {
386+
"1.2.0.0"/23;
387+
"1.2.2.0"/24;
388+
"1.2.3.0"/24;
389+
}
390+
391+
sub vcl_recv {
392+
if (client.ip ~ acl1) {
393+
return (synth(403));
394+
}
395+
}
396+
EOF
397+
}
398+
399+
varnish v1 -errvcl "Unknown modifier" {
400+
backend dummy None;
401+
402+
acl acl1 +log +pedantic +fold,foo {
403+
"1.2.0.0"/23;
404+
}
405+
}
406+
407+
varnish v1 -errvcl "-fold,noreport is invalid" {
408+
backend dummy None;
409+
410+
acl acl1 +log +pedantic -fold,noreport {
411+
"1.2.0.0"/23;
412+
}
413+
}

doc/sphinx/reference/vcl.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ individually:
354354

355355
Skip and fold operations on VCL entries are output as warnings
356356
during VCL compilation as entries from the VCL are processed in
357-
order.
357+
order unless the `noreport` modifier is added (see below).
358358

359359
Logging under the ``VCL_acl`` tag can change with this parameter
360360
enabled: Matches on skipped subnet entries are now logged as matches
@@ -365,6 +365,13 @@ individually:
365365

366366
Negated ACL entries are never folded.
367367

368+
* `+fold,noreport` - Fold without reporting
369+
370+
Enable folding, but do not output folding-related warnings during VCL
371+
compilation
372+
373+
The ``noreport`` modifier is only valid with ``+fold``.
374+
368375
VCL objects
369376
-----------
370377

lib/libvcc/vcc_acl.c

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct acl {
5454

5555
int flag_log;
5656
int flag_fold;
57+
int flag_fold_report;
5758
int flag_pedantic;
5859
int flag_table;
5960

@@ -263,26 +264,30 @@ vcl_acl_fold(struct vcc *tl, struct acl_e **l, struct acl_e **r)
263264
do {
264265
switch (cmp) {
265266
case ACL_CONTAINED:
266-
VSB_cat(tl->sb, "ACL entry:\n");
267-
vcc_ErrWhere(tl, (*r)->t_addr);
268-
VSB_cat(tl->sb, "supersedes / removes:\n");
269-
vcc_ErrWhere(tl, (*l)->t_addr);
270-
vcc_Warn(tl);
267+
if (tl->acl->flag_fold_report) {
268+
VSB_cat(tl->sb, "ACL entry:\n");
269+
vcc_ErrWhere(tl, (*r)->t_addr);
270+
VSB_cat(tl->sb, "supersedes / removes:\n");
271+
vcc_ErrWhere(tl, (*l)->t_addr);
272+
vcc_Warn(tl);
273+
}
271274
VRBT_REMOVE(acl_tree, &tl->acl->acl_tree, *l);
272275
FREE_OBJ(*l);
273276
*l = VRBT_PREV(acl_tree, &tl->acl->acl_tree, *r);
274277
break;
275278
case ACL_LEFT:
276279
(*l)->mask--;
277280
(*l)->fixed = "folded";
278-
VSB_cat(tl->sb, "ACL entry:\n");
279-
vcc_ErrWhere(tl, (*l)->t_addr);
280-
VSB_cat(tl->sb, "left of:\n");
281-
vcc_ErrWhere(tl, (*r)->t_addr);
282-
VSB_printf(tl->sb, "removing the latter and expanding "
283-
"mask of the former by one to /%u\n",
284-
(*l)->mask - 8);
285-
vcc_Warn(tl);
281+
if (tl->acl->flag_fold_report) {
282+
VSB_cat(tl->sb, "ACL entry:\n");
283+
vcc_ErrWhere(tl, (*l)->t_addr);
284+
VSB_cat(tl->sb, "left of:\n");
285+
vcc_ErrWhere(tl, (*r)->t_addr);
286+
VSB_printf(tl->sb, "removing the latter and "
287+
"expanding mask of the former by one to "
288+
"/%u\n", (*l)->mask - 8);
289+
vcc_Warn(tl);
290+
}
286291
VRBT_REMOVE(acl_tree, &tl->acl->acl_tree, *r);
287292
FREE_OBJ(*r);
288293
VRBT_REMOVE(acl_tree, &tl->acl->acl_tree, *l);
@@ -807,13 +812,30 @@ static void
807812
vcc_parseAclFold(struct vcc *tl, int sign)
808813
{
809814
struct acl *acl;
815+
struct token *t;
810816

811817
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
812818
assert(vcc_IdIs(tl->t, "fold"));
813819
acl = tl->acl;
814820
CHECK_OBJ_NOTNULL(acl, VCC_ACL_MAGIC);
815821

822+
t = tl->t;
816823
acl->flag_fold = sign;
824+
acl->flag_fold_report = 1;
825+
vcc_NextToken(tl);
826+
if (tl->t->tok != ',')
827+
return;
828+
829+
vcc_NextToken(tl);
830+
if (! vcc_IdIs(tl->t, "noreport")) {
831+
VSB_cat(tl->sb, "Unknown modifier:\n");
832+
vcc_ErrWhere(tl, tl->t);
833+
} else if (! sign) {
834+
VSB_cat(tl->sb, "-fold,noreport is invalid, use -fold:\n");
835+
vcc_ErrWhere(tl, t);
836+
} else {
837+
acl->flag_fold_report = 0;
838+
}
817839
vcc_NextToken(tl);
818840
}
819841

@@ -828,6 +850,7 @@ vcc_ParseAcl(struct vcc *tl)
828850
tl->acl = acl;
829851
acl->flag_pedantic = 1;
830852
acl->flag_fold = 1;
853+
acl->flag_fold_report = 1;
831854
vcc_NextToken(tl);
832855
VRBT_INIT(&acl->acl_tree);
833856

0 commit comments

Comments
 (0)