This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.2.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit a79adda1a7ca2f980725a250b840df8cb50fa0c3 Author: Robert Clendenin <[email protected]> AuthorDate: Thu Apr 16 15:07:59 2026 -0500 Allow full CIDR range (1-128) for IPv6 literals in HRW4U grammar (#13077) * Allow full CIDR range (1-128) for IPv6 literals in HRW4U grammar * Added AST test file (cherry picked from commit afdf454a8d564fd2f0dfde4e8ca1ac00c324879c) --- tools/hrw4u/grammar/hrw4u.g4 | 4 ++-- tools/hrw4u/tests/data/conds/ipv6-cidr.ast.txt | 1 + tools/hrw4u/tests/data/conds/ipv6-cidr.input.txt | 13 +++++++++++++ tools/hrw4u/tests/data/conds/ipv6-cidr.output.txt | 11 +++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/hrw4u/grammar/hrw4u.g4 b/tools/hrw4u/grammar/hrw4u.g4 index 1527778716..335a3817b3 100644 --- a/tools/hrw4u/grammar/hrw4u.g4 +++ b/tools/hrw4u/grammar/hrw4u.g4 @@ -59,8 +59,8 @@ fragment IPV4_CIDR : [1-9] | '3'[0-2] ; -fragment IPV6_CIDR : '3'[3-9] - | [4-9][0-9] +fragment IPV6_CIDR : [1-9] + | [1-9][0-9] | '1'[0-1][0-9] | '12'[0-8] ; diff --git a/tools/hrw4u/tests/data/conds/ipv6-cidr.ast.txt b/tools/hrw4u/tests/data/conds/ipv6-cidr.ast.txt new file mode 100644 index 0000000000..4371c9ccc1 --- /dev/null +++ b/tools/hrw4u/tests/data/conds/ipv6-cidr.ast.txt @@ -0,0 +1 @@ +(program (programItem (section REMAP { (sectionBody (conditional (ifStatement if (condition (expression (term (factor (comparison (comparable inbound.ip) in (iprange { (ip (ipv4 128.0.0.0/1)) , (ip (ipv4 10.0.0.0/8)) , (ip (ipv4 172.16.0.0/16)) , (ip (ipv4 192.168.1.0/24)) , (ip (ipv4 10.0.0.0/31)) , (ip (ipv4 10.0.0.1/32)) })))))) (block { (blockItem (statement inbound.req.X-V4 = (value "matched") ;)) })))) (sectionBody (conditional (ifStatement if (condition (expression (term (factor ( [...] diff --git a/tools/hrw4u/tests/data/conds/ipv6-cidr.input.txt b/tools/hrw4u/tests/data/conds/ipv6-cidr.input.txt new file mode 100644 index 0000000000..0c22f6373c --- /dev/null +++ b/tools/hrw4u/tests/data/conds/ipv6-cidr.input.txt @@ -0,0 +1,13 @@ +REMAP { + if inbound.ip in {128.0.0.0/1, 10.0.0.0/8, 172.16.0.0/16, 192.168.1.0/24, 10.0.0.0/31, 10.0.0.1/32} { + inbound.req.X-V4 = "matched"; + } + + if inbound.ip in {8000::/1, 2001:db8::/8, fe80::/16, 2620:149::/31, 2620:149::/32, 2620:149:a00::/33, 2001:db8:abcd::/64, ::1/128} { + inbound.req.X-V6 = "matched"; + } + + if inbound.ip !in {10.0.0.0/8, 2620:149::/32} { + inbound.status = 403; + } +} diff --git a/tools/hrw4u/tests/data/conds/ipv6-cidr.output.txt b/tools/hrw4u/tests/data/conds/ipv6-cidr.output.txt new file mode 100644 index 0000000000..061d6f47ec --- /dev/null +++ b/tools/hrw4u/tests/data/conds/ipv6-cidr.output.txt @@ -0,0 +1,11 @@ +cond %{REMAP_PSEUDO_HOOK} [AND] +cond %{IP:CLIENT} {128.0.0.0/1,10.0.0.0/8,172.16.0.0/16,192.168.1.0/24,10.0.0.0/31,10.0.0.1/32} + set-header X-V4 "matched" + +cond %{REMAP_PSEUDO_HOOK} [AND] +cond %{IP:CLIENT} {8000::/1,2001:db8::/8,fe80::/16,2620:149::/31,2620:149::/32,2620:149:a00::/33,2001:db8:abcd::/64,::1/128} + set-header X-V6 "matched" + +cond %{REMAP_PSEUDO_HOOK} [AND] +cond %{IP:CLIENT} {10.0.0.0/8,2620:149::/32} [NOT] + set-status 403
