Skip to content

Commit

Permalink
add fake_ip item in DefaultRule to match FakeIP origin destination
Browse files Browse the repository at this point in the history
  • Loading branch information
PuerNya committed Jul 1, 2024
1 parent fa1fd7a commit 5362057
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/configuration/route/rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"geosite-cn"
],
"rule_set_ipcidr_match_source": false,
"fake_ip": false,
"invert": false,
"skip_resolve": false,
"outbound": "direct"
Expand Down Expand Up @@ -312,6 +313,10 @@ Match [Rule Set](/configuration/route/#rule_set).

Make `ipcidr` in rule sets match the source IP.

#### fake_ip

Match FakeIP origin destination.

#### invert

Invert match result.
Expand Down
5 changes: 5 additions & 0 deletions docs/configuration/route/rule.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"geosite-cn"
],
"rule_set_ipcidr_match_source": false,
"fake_ip": false,
"invert": false,
"skip_resolve": false,
"outbound": "direct"
Expand Down Expand Up @@ -310,6 +311,10 @@

使规则集中的 `ipcidr` 规则匹配源 IP。

#### fake_ip

匹配入站为 FakeIP 的情况

#### invert

反选匹配结果。
Expand Down
1 change: 1 addition & 0 deletions option/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type DefaultRule struct {
WIFIBSSID Listable[string] `json:"wifi_bssid,omitempty"`
RuleSet Listable[string] `json:"rule_set,omitempty"`
RuleSetIPCIDRMatchSource bool `json:"rule_set_ipcidr_match_source,omitempty"`
FakeIP bool `json:"fake_ip,omitempty"`
Invert bool `json:"invert,omitempty"`
SkipResolve bool `json:"skip_resolve,omitempty"`
Outbound string `json:"outbound,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions route/rule_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ func NewDefaultRule(router adapter.Router, logger log.ContextLogger, options opt
rule.ruleSetItems = append(rule.ruleSetItems, item)
rule.allItems = append(rule.allItems, item)
}
if options.FakeIP {
item := NewFakeIPItem()
rule.items = append(rule.items, item)
rule.allItems = append(rule.allItems, item)
}
return rule, nil
}

Expand Down
22 changes: 22 additions & 0 deletions route/rule_item_fake_ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package route

import (
"github.com/sagernet/sing-box/adapter"
C "github.com/sagernet/sing-box/constant"
)

var _ RuleItem = (*FakeIPItem)(nil)

type FakeIPItem struct{}

func NewFakeIPItem() *FakeIPItem {
return &FakeIPItem{}
}

func (r *FakeIPItem) Match(metadata *adapter.InboundContext) bool {
return metadata.DNSMode == C.DNSModeFakeIP
}

func (r *FakeIPItem) String() string {
return "fake_ip=true"
}

0 comments on commit 5362057

Please sign in to comment.