From a72ad61f508852140c5e7fff5e20e3bb2ee96037 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 19 Mar 2022 22:27:22 +0800 Subject: [PATCH] =?UTF-8?q?[skip=20ci][=E5=86=85=E5=AE=B9]=201.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=83=A8=E5=88=86=E7=A9=BA=E6=8C=87=E9=92=88=E9=97=AE?= =?UTF-8?q?=E9=A2=98=202.=E4=BF=AE=E6=94=B9go.mod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 6 ++---- rule/common/network_type.go | 14 ++++++++------ rule/logic/and.go | 4 ++-- rule/logic/common.go | 14 +++++++++++++- rule/logic/not.go | 4 ++-- rule/logic/or.go | 4 ++-- rule/provider/rule_set.go | 3 ++- 8 files changed, 32 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index b4928679..31f2ddaf 100644 --- a/go.mod +++ b/go.mod @@ -57,4 +57,4 @@ require ( ) -replace golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 => ./listener/tun/device/tun/wintun +replace golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 => github.com/MetaCubeX/wintun-go v0.0.0-20220319102620-bbc5e6b2015e diff --git a/go.sum b/go.sum index 324a6cdb..08b6d877 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Dreamacro/go-shadowsocks2 v0.1.7 h1:8CtbE1HoPPMfrQZGXmlluq6dO2lL31W6WRRE8fabc4Q= github.com/Dreamacro/go-shadowsocks2 v0.1.7/go.mod h1:8p5G4cAj5ZlXwUR+Ww63gfSikr8kvw8uw3TDwLAJpUc= +github.com/MetaCubeX/wintun-go v0.0.0-20220319102620-bbc5e6b2015e h1:GRfT5Lf8HP7RNczKIwTYLoCh1PPuIs/sY9hj+W+3deg= +github.com/MetaCubeX/wintun-go v0.0.0-20220319102620-bbc5e6b2015e/go.mod h1:ARUuShAtcziEJ/vnZ2hgoP+zc0J7Ukcca2S/NPDoQCc= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= @@ -305,8 +307,6 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf h1:Fm4IcnUL803i92qDlmB0obyHmosDrxZWxJL3gIeNqOw= -golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 h1:saXMvIOKvRFwbOMicHXr0B1uwoxq9dGmLe5ExMES6c4= golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -339,8 +339,6 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.zx2c4.com/wireguard v0.0.0-20220310012736-ae6bc4dd64e1 h1:iuQdvJn3LrXxz3Iony1qBGVS7kEy2uHYnnjHsVbzq/s= -golang.zx2c4.com/wireguard v0.0.0-20220310012736-ae6bc4dd64e1/go.mod h1:TjUWrnD5ATh7bFvmm/ALEJZQ4ivKbETb6pmyj1vUoNI= golang.zx2c4.com/wireguard v0.0.0-20220318042302-193cf8d6a5d6 h1:kgBK1EGuTIYbwoKROmsoV0FQp08gnCcVa110A4Unqhk= golang.zx2c4.com/wireguard v0.0.0-20220318042302-193cf8d6a5d6/go.mod h1:bVQfyl2sCM/QIIGHpWbFGfHPuDvqnCNkT6MQLTCjO/U= golang.zx2c4.com/wireguard/windows v0.5.3 h1:On6j2Rpn3OEMXqBq00QEDC7bWSZrPIHKIus8eIuExIE= diff --git a/rule/common/network_type.go b/rule/common/network_type.go index f10d9a37..93abeade 100644 --- a/rule/common/network_type.go +++ b/rule/common/network_type.go @@ -13,20 +13,22 @@ type NetworkType struct { } func NewNetworkType(network, adapter string) (*NetworkType, error) { - ntType := new(NetworkType) - ntType.adapter = adapter + var netType C.NetWork switch strings.ToUpper(network) { case "TCP": - ntType.network = C.TCP + netType = C.TCP break case "UDP": - ntType.network = C.UDP + netType = C.UDP break default: return nil, fmt.Errorf("unsupported network type, only TCP/UDP") } - - return ntType, nil + return &NetworkType{ + Base: &Base{}, + network: netType, + adapter: adapter, + }, nil } func (n *NetworkType) RuleType() C.RuleType { diff --git a/rule/logic/and.go b/rule/logic/and.go index 91197b8a..1d4c99f7 100644 --- a/rule/logic/and.go +++ b/rule/logic/and.go @@ -6,7 +6,7 @@ import ( ) type AND struct { - common.Base + *common.Base rules []C.Rule payload string adapter string @@ -18,7 +18,7 @@ func (A *AND) ShouldFindProcess() bool { } func NewAND(payload string, adapter string) (*AND, error) { - and := &AND{payload: payload, adapter: adapter} + and := &AND{Base: &common.Base{}, payload: payload, adapter: adapter} rules, err := parseRuleByPayload(payload) if err != nil { return nil, err diff --git a/rule/logic/common.go b/rule/logic/common.go index d28cbc26..657add05 100644 --- a/rule/logic/common.go +++ b/rule/logic/common.go @@ -111,7 +111,19 @@ func parseRule(tp, payload string, params []string) (C.Rule, error) { parseErr = fmt.Errorf("unsupported rule type %s", tp) } - return parsed, parseErr + if parseErr != nil { + return nil, parseErr + } + + ruleExtra := &C.RuleExtra{ + Network: RC.FindNetwork(params), + SourceIPs: RC.FindSourceIPs(params), + ProcessNames: RC.FindProcessName(params), + } + + parsed.SetRuleExtra(ruleExtra) + + return parsed, nil } type Range struct { diff --git a/rule/logic/not.go b/rule/logic/not.go index 0c85d2dd..81e357a5 100644 --- a/rule/logic/not.go +++ b/rule/logic/not.go @@ -7,7 +7,7 @@ import ( ) type NOT struct { - common.Base + *common.Base rule C.Rule payload string adapter string @@ -18,7 +18,7 @@ func (not *NOT) ShouldFindProcess() bool { } func NewNOT(payload string, adapter string) (*NOT, error) { - not := &NOT{payload: payload, adapter: adapter} + not := &NOT{Base: &common.Base{}, payload: payload, adapter: adapter} rule, err := parseRuleByPayload(payload) if err != nil { return nil, err diff --git a/rule/logic/or.go b/rule/logic/or.go index 7aeb27b3..05ad6f91 100644 --- a/rule/logic/or.go +++ b/rule/logic/or.go @@ -6,7 +6,7 @@ import ( ) type OR struct { - common.Base + *common.Base rules []C.Rule payload string adapter string @@ -44,7 +44,7 @@ func (or *OR) ShouldResolveIP() bool { } func NewOR(payload string, adapter string) (*OR, error) { - or := &OR{payload: payload, adapter: adapter} + or := &OR{Base: &common.Base{}, payload: payload, adapter: adapter} rules, err := parseRuleByPayload(payload) if err != nil { return nil, err diff --git a/rule/provider/rule_set.go b/rule/provider/rule_set.go index 386e838e..d5f0a7c9 100644 --- a/rule/provider/rule_set.go +++ b/rule/provider/rule_set.go @@ -8,7 +8,7 @@ import ( ) type RuleSet struct { - common.Base + *common.Base ruleProviderName string adapter string ruleProvider P.RuleProvider @@ -52,6 +52,7 @@ func NewRuleSet(ruleProviderName string, adapter string) (*RuleSet, error) { return nil, fmt.Errorf("rule set %s not found", ruleProviderName) } return &RuleSet{ + Base: &common.Base{}, ruleProviderName: ruleProviderName, adapter: adapter, ruleProvider: rp,