From aebfb0a389df502c09d3e548501f112bc1feb031 Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Fri, 14 May 2021 12:20:59 +0800 Subject: [PATCH] fix: a problem that intranet sharing not work #181 #183 --- service/core/ipforward/ipforward.go | 1 - service/db/configure/configure.go | 4 +--- service/pre.go | 8 -------- service/server/service/connect.go | 5 +++++ service/server/service/setting.go | 10 ++++------ 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/service/core/ipforward/ipforward.go b/service/core/ipforward/ipforward.go index 408f1d76..ada70234 100644 --- a/service/core/ipforward/ipforward.go +++ b/service/core/ipforward/ipforward.go @@ -10,7 +10,6 @@ func IsIpForwardOn() bool { return err == nil && strings.TrimSpace(string(out)) == "1" } -//返回ipv4.ip_forward的开启状态。该命令写的ip_forward状态重启将失效。 func WriteIpForward(on bool) (err error) { val := "0" if on { diff --git a/service/db/configure/configure.go b/service/db/configure/configure.go index 56ea9da4..d1311e6d 100644 --- a/service/db/configure/configure.go +++ b/service/db/configure/configure.go @@ -5,12 +5,11 @@ import ( "encoding/hex" jsoniter "github.com/json-iterator/go" "github.com/tidwall/gjson" - "github.com/v2rayA/v2rayA/core/ipforward" + "github.com/v2rayA/v2rayA/common/errors" "github.com/v2rayA/v2rayA/db" "github.com/xujiajun/nutsdb" "log" "strings" - "github.com/v2rayA/v2rayA/common/errors" ) type Configure struct { @@ -203,7 +202,6 @@ func GetSettingNotNil() *Setting { r = NewSetting() _ = db.Set("system", "setting", r) } - r.IntranetSharing = ipforward.IsIpForwardOn() //永远用真实值 if r.AntiPollution == "" { r.AntiPollution = AntipollutionNone } diff --git a/service/pre.go b/service/pre.go index 349d0a19..24cac925 100644 --- a/service/pre.go +++ b/service/pre.go @@ -8,7 +8,6 @@ import ( jsonIteratorExtra "github.com/json-iterator/go/extra" "github.com/tidwall/gjson" "github.com/v2rayA/v2rayA/common/netTools/ports" - "github.com/v2rayA/v2rayA/core/ipforward" "github.com/v2rayA/v2rayA/core/iptables" "github.com/v2rayA/v2rayA/core/v2ray" "github.com/v2rayA/v2rayA/core/v2ray/asset" @@ -155,13 +154,6 @@ func initConfigure() { initDBValue() } } - //配置ip转发 - setting := configure.GetSettingNotNil() - if setting.Transparent != configure.TransparentClose { - if setting.IntranetSharing != ipforward.IsIpForwardOn() { - _ = ipforward.WriteIpForward(setting.IntranetSharing) - } - } //检查config.json是否存在 if _, err := os.Stat(asset.GetV2rayConfigPath()); err != nil { //不存在就建一个。多数情况发生于docker模式挂载volume时覆盖了/etc/v2ray diff --git a/service/server/service/connect.go b/service/server/service/connect.go index 66f202f8..a17cc573 100644 --- a/service/server/service/connect.go +++ b/service/server/service/connect.go @@ -1,6 +1,7 @@ package service import ( + "github.com/v2rayA/v2rayA/core/ipforward" "github.com/v2rayA/v2rayA/core/v2ray" "github.com/v2rayA/v2rayA/core/v2ray/asset/gfwlist" "github.com/v2rayA/v2rayA/db/configure" @@ -73,6 +74,10 @@ func Connect(which *configure.Which) (err error) { return newError("which can not be nil") } checkResolvConf() + //配置ip转发 + if setting.IntranetSharing != ipforward.IsIpForwardOn() { + _ = ipforward.WriteIpForward(setting.IntranetSharing) + } //定位Server tsr, err := which.LocateServer() if err != nil { diff --git a/service/server/service/setting.go b/service/server/service/setting.go index 006b2a45..f5ca447e 100644 --- a/service/server/service/setting.go +++ b/service/server/service/setting.go @@ -22,12 +22,10 @@ func UpdateSetting(setting *configure.Setting) (err error) { if (setting.Transparent == configure.TransparentGfwlist || setting.PacMode == configure.GfwlistMode) && !asset.IsGFWListExists() { return newError("cannot find GFWList files. update GFWList and try again") } - if setting.Transparent != configure.TransparentClose { - if setting.IntranetSharing != ipforward.IsIpForwardOn() { - err = ipforward.WriteIpForward(setting.IntranetSharing) - if err != nil { - return - } + if setting.IntranetSharing != ipforward.IsIpForwardOn() { + err = ipforward.WriteIpForward(setting.IntranetSharing) + if err != nil { + return } } err = configure.SetSetting(setting)