add port filter for matcher

This commit is contained in:
ginuerzh
2023-11-09 10:59:32 +08:00
parent a697bf2e35
commit 3eca21104a
3 changed files with 152 additions and 30 deletions

View File

@ -113,8 +113,13 @@ func (p *localAdmission) Admit(ctx context.Context, addr string, opts ...admissi
matched := p.matched(addr)
return !p.options.whitelist && !matched ||
b := !p.options.whitelist && !matched ||
p.options.whitelist && matched
if !b {
p.options.logger.Debugf("%s is denied", addr)
}
return b
}
func (p *localAdmission) periodReload(ctx context.Context) error {
@ -156,6 +161,10 @@ func (p *localAdmission) reload(ctx context.Context) error {
inets = append(inets, inet)
continue
}
if ipAddr, _ := net.ResolveIPAddr("ip", pattern); ipAddr != nil {
p.options.logger.Debugf("resolve IP: %s -> %s", pattern, ipAddr)
ips = append(ips, ipAddr.IP)
}
}
p.mu.Lock()