summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-10-22 05:15:50 +0800
committerLoyalsoldier <[email protected]>2024-10-22 05:15:50 +0800
commit4cf50641990c7df79b1a03438dd9273532182e2f (patch)
treea91a07fdbce92c0f98c94237b9972ef46ec97c81 /plugin
parent7e02a263a3108a768ae7fb25238e5a71a3aefd7a (diff)
Feat: support to specify `onlyIPType` option in private input format
Diffstat (limited to 'plugin')
-rw-r--r--plugin/special/private.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/plugin/special/private.go b/plugin/special/private.go
index 4250c225..dc781c31 100644
--- a/plugin/special/private.go
+++ b/plugin/special/private.go
@@ -46,10 +46,21 @@ func init() {
}
func newPrivate(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+ var tmp struct {
+ OnlyIPType lib.IPType `json:"onlyIPType"`
+ }
+
+ if len(data) > 0 {
+ if err := json.Unmarshal(data, &tmp); err != nil {
+ return nil, err
+ }
+ }
+
return &private{
Type: typePrivate,
Action: action,
Description: descPrivate,
+ OnlyIPType: tmp.OnlyIPType,
}, nil
}
@@ -57,6 +68,7 @@ type private struct {
Type string
Action lib.Action
Description string
+ OnlyIPType lib.IPType
}
func (p *private) GetType() string {
@@ -83,13 +95,21 @@ func (p *private) Input(container lib.Container) (lib.Container, error) {
}
}
+ var ignoreIPType lib.IgnoreIPOption
+ switch p.OnlyIPType {
+ case lib.IPv4:
+ ignoreIPType = lib.IgnoreIPv6
+ case lib.IPv6:
+ ignoreIPType = lib.IgnoreIPv4
+ }
+
switch p.Action {
case lib.ActionAdd:
- if err := container.Add(entry); err != nil {
+ if err := container.Add(entry, ignoreIPType); err != nil {
return nil, err
}
case lib.ActionRemove:
- if err := container.Remove(entry, lib.CaseRemovePrefix); err != nil {
+ if err := container.Remove(entry, lib.CaseRemovePrefix, ignoreIPType); err != nil {
return nil, err
}
default: