Merge pull request #27 from cgroschupp/feature/whitelist-change

feat: add whitelist support
This commit is contained in:
ginuerzh 2024-04-24 23:13:29 +08:00 committed by GitHub
commit 871afeeb6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 1 deletions

View File

@ -235,11 +235,17 @@ func (bp *localBypass) Contains(ctx context.Context, network, addr string, opts
b := !bp.options.whitelist && matched || b := !bp.options.whitelist && matched ||
bp.options.whitelist && !matched bp.options.whitelist && !matched
if b { if b {
bp.options.logger.Debugf("bypass: %s", addr) bp.options.logger.Debugf("bypass: %s, whitelist: %t", addr, bp.options.whitelist)
} else {
bp.options.logger.Debugf("pass: %s, whitelist: %t", addr, bp.options.whitelist)
} }
return b return b
} }
func (p *localBypass) IsWhitelist() bool {
return p.options.whitelist
}
func (bp *localBypass) parseLine(s string) string { func (bp *localBypass) parseLine(s string) string {
if n := strings.IndexByte(s, '#'); n >= 0 { if n := strings.IndexByte(s, '#'); n >= 0 {
s = s[:n] s = s[:n]

View File

@ -75,3 +75,7 @@ func (p *grpcPlugin) Close() error {
} }
return nil return nil
} }
func (p *grpcPlugin) IsWhitelist() bool {
return false
}

View File

@ -96,3 +96,7 @@ func (p *httpPlugin) Contains(ctx context.Context, network, addr string, opts ..
} }
return res.OK return res.OK
} }
func (p *httpPlugin) IsWhitelist() bool {
return false
}

View File

@ -37,3 +37,11 @@ func (w *bypassWrapper) Contains(ctx context.Context, network, addr string, opts
} }
return bp.Contains(ctx, network, addr, opts...) return bp.Contains(ctx, network, addr, opts...)
} }
func (p *bypassWrapper) IsWhitelist() bool {
bp := p.r.get(p.name)
if bp == nil {
return false
}
return bp.IsWhitelist()
}