fix: Allow duplicated items in the IP list of ip-restriction config (#2755)

Co-authored-by: 澄潭 <zty98751@alibaba-inc.com>
This commit is contained in:
Kent Dong
2025-08-15 13:39:26 +08:00
committed by GitHub
parent 0bb934073a
commit a3310f1a3b

View File

@@ -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