From 77a8f28edc09725665b970ebc36863a46795c60c Mon Sep 17 00:00:00 2001 From: Christian Groschupp Date: Mon, 15 Apr 2024 21:43:09 +0200 Subject: [PATCH] feat: add whitelist support --- bypass/bypass.go | 8 +++++++- bypass/plugin/grpc.go | 4 ++++ bypass/plugin/http.go | 4 ++++ registry/bypass.go | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bypass/bypass.go b/bypass/bypass.go index ea4f131..3da5cb7 100644 --- a/bypass/bypass.go +++ b/bypass/bypass.go @@ -235,11 +235,17 @@ func (bp *localBypass) Contains(ctx context.Context, network, addr string, opts b := !bp.options.whitelist && matched || bp.options.whitelist && !matched 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 } +func (p *localBypass) IsWhitelist() bool { + return p.options.whitelist +} + func (bp *localBypass) parseLine(s string) string { if n := strings.IndexByte(s, '#'); n >= 0 { s = s[:n] diff --git a/bypass/plugin/grpc.go b/bypass/plugin/grpc.go index 37ad21f..d4d7250 100644 --- a/bypass/plugin/grpc.go +++ b/bypass/plugin/grpc.go @@ -75,3 +75,7 @@ func (p *grpcPlugin) Close() error { } return nil } + +func (p *grpcPlugin) IsWhitelist() bool { + return false +} diff --git a/bypass/plugin/http.go b/bypass/plugin/http.go index 2035251..17792fe 100644 --- a/bypass/plugin/http.go +++ b/bypass/plugin/http.go @@ -96,3 +96,7 @@ func (p *httpPlugin) Contains(ctx context.Context, network, addr string, opts .. } return res.OK } + +func (p *httpPlugin) IsWhitelist() bool { + return false +} diff --git a/registry/bypass.go b/registry/bypass.go index 3ad7b1e..59b167e 100644 --- a/registry/bypass.go +++ b/registry/bypass.go @@ -37,3 +37,11 @@ func (w *bypassWrapper) Contains(ctx context.Context, network, addr string, 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() +}