summaryrefslogtreecommitdiff
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
parent7e02a263a3108a768ae7fb25238e5a71a3aefd7a (diff)
Feat: support to specify `onlyIPType` option in private input format
-rw-r--r--configuration.md22
-rw-r--r--plugin/special/private.go24
2 files changed, 44 insertions, 2 deletions
diff --git a/configuration.md b/configuration.md
index fb1f4f3e..a6044823 100644
--- a/configuration.md
+++ b/configuration.md
@@ -415,6 +415,8 @@
- **type**:(必须)输入格式的名称
- **action**:(必须)操作类型,值为 `add`(添加 IP 地址)或 `remove`(移除 IP 地址)
+- **args**:(可选)
+ - **onlyIPType**:(可选)只处理的 IP 地址类型,值为 `ipv4` 或 `ipv6`
> `private` 默认添加或移除的 CIDR 地址,见 [private.go](https://github.com/Loyalsoldier/geoip/blob/HEAD/plugin/special/private.go#L16-L36)
@@ -432,6 +434,26 @@
}
```
+```jsonc
+{
+ "type": "private",
+ "action": "add", // 添加 IP 地址
+ "args": {
+ "onlyIPType": "ipv4" // 只添加 IPv4 地址
+ }
+}
+```
+
+```jsonc
+{
+ "type": "private",
+ "action": "remove", // 移除 IP 地址
+ "args": {
+ "onlyIPType": "ipv6" // 只移除 IPv6 地址
+ }
+}
+```
+
### **singboxSRS**
- **type**:(必须)输入格式的名称
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: