From a3310f1a3b5b80acf8e988e449dc45f593ee3edb Mon Sep 17 00:00:00 2001 From: Kent Dong Date: Fri, 15 Aug 2025 13:39:26 +0800 Subject: [PATCH] fix: Allow duplicated items in the IP list of ip-restriction config (#2755) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 澄潭 --- plugins/wasm-go/extensions/ip-restriction/utils.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/wasm-go/extensions/ip-restriction/utils.go b/plugins/wasm-go/extensions/ip-restriction/utils.go index 7706faa3d..abc464ba5 100644 --- a/plugins/wasm-go/extensions/ip-restriction/utils.go +++ b/plugins/wasm-go/extensions/ip-restriction/utils.go @@ -1,11 +1,15 @@ package main import ( + "errors" "fmt" "strings" + "github.com/asergeyev/nradix" "github.com/tidwall/gjson" "github.com/zmap/go-iptree/iptree" + + "github.com/higress-group/wasm-go/pkg/log" ) // parseIPNets 解析Ip段配置 @@ -17,7 +21,12 @@ func parseIPNets(array []gjson.Result) (*iptree.IPTree, error) { for _, result := range array { err := tree.AddByString(result.String(), 0) if err != nil { - return nil, fmt.Errorf("invalid IP[%s]", result.String()) + if errors.Is(err, nradix.ErrNodeBusy) { + // ErrNodeBusy means the IP already exists in the tree + log.Warnf("ignore duplicate IP [%s]", result.String()) + } else { + return nil, fmt.Errorf("add IP [%s] into tree failed: %v", result.String(), err) + } } } return tree, nil