no bart for cidr

This commit is contained in:
JackDoan committed 2026-09-30 12:24:01 -05:00
1 parent f3b76703ae
commit 9aab46c1ad
4 files changed
+65 -27

No files matched your search

+12 -6
View File
@@ -46,7 +46,9 @@ type remoteRules struct {
Any *localRules
Hosts map[string]*localRules
Groups []*groupsRule
CIDR *bart.Table[*localRules]
// CIDR is checked with Prefix.Contains, so 0.0.0.0/0 allows any IPv4 address and ::/0 any IPv6 address,
// neither allows the other family
CIDR []cidrRule
}
type groupsRule struct {
@@ -54,6 +56,12 @@ type groupsRule struct {
LocalCIDR *localRules
}
type cidrRule struct {
// Prefix is masked, so a cidr written two ways is one cidrRule
Prefix netip.Prefix
LocalCIDR *localRules
}
type localRules struct {
Any bool
// LocalCIDR is always set when Any isn't. It's shared with other localRules, so it's never changed.
@@ -164,11 +172,9 @@ func (rr *remoteRules) match(p *Packet, c *cert.CachedCertificate) bool {
}
}
if rr.CIDR != nil {
for _, v := range rr.CIDR.Supernets(netip.PrefixFrom(p.RemoteAddr, p.RemoteAddr.BitLen())) {
if v.match(p, c) {
return true
}
for i := range rr.CIDR {
if rr.CIDR[i].Prefix.Contains(p.RemoteAddr) && rr.CIDR[i].LocalCIDR.match(p, c) {
return true
}
}