Skip to content

Commit 3f1e5be

Browse files
fix(filter): normalize matching
1 parent 3056520 commit 3f1e5be

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

docs/filtering.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ filter:
6161
* **`prefix`** (Single String): CIDR subnet. The address must be contained within this subnet.
6262
* Example: `2001:db8::/32`
6363
* **`suffix`** (Single String): The host part (suffix) of the address.
64-
* Example: `::1` (Matches `2001:db8::1`, `fe80::1`, etc.)
64+
* Case-insensitive. The filter matches against the lowercase, RFC 5952 canonical representation of the address.
65+
* Example: `::1` (Matches `2001:db8::1`, `fe80::1`, etc.) or `dead:beef` (Matches `...:DEAD:BEEF`)
6566
* **`type`** (List of Strings): Match semantic IP types. All types must match.
6667
* Values:
6768
* `global`: Global Unicast Address (Publicly routable).

pkg/filter/filter.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,18 @@ func isEUI64(addr *ipv6disc.Addr) bool {
170170
return bytes.Equal(iid, eui64)
171171
}
172172

173-
func CheckPrefix(ip netip.Addr, subnet netip.Prefix) bool {
174-
if !subnet.IsValid() {
173+
func CheckPrefix(ip netip.Addr, prefix netip.Prefix) bool {
174+
if !prefix.IsValid() {
175175
return true
176176
}
177-
return subnet.Contains(ip)
177+
return prefix.Contains(ip.WithZone(""))
178178
}
179179

180180
func CheckSuffix(ip netip.Addr, suffix string) bool {
181181
if suffix == "" {
182182
return true
183183
}
184-
return strings.HasSuffix(ip.String(), suffix)
184+
return strings.HasSuffix(ip.WithZone("").String(), strings.ToLower(suffix))
185185
}
186186

187187
func CheckMask(ip netip.Addr, filters []string) bool {

0 commit comments

Comments
 (0)