From 5ae81fc05c635865b6cae88987f13debd4c28767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=9D=92?= <295421489@qq.com> Date: Tue, 11 Jan 2022 13:20:11 +0800 Subject: [PATCH 1/2] mod_tcp_keepalive: fix compile error in windows os (#944) Signed-off-by: liuximu <295421489@qq.com> --- .gitignore | 2 + .../mod_tcp_keepalive/keepalive_darwin.go | 4 ++ .../mod_tcp_keepalive/keepalive_linux.go | 4 ++ .../mod_tcp_keepalive/keepalive_windows.go | 51 +++++++++++++++++++ .../mod_tcp_keepalive/mod_tcp_keepalive.go | 5 -- conf/bfe.conf | 1 + conf/mod_tcp_keepalive/mod_tcp_keepalive.conf | 2 +- conf/mod_tcp_keepalive/tcp_keepalive.data | 14 +++++ 8 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 bfe_modules/mod_tcp_keepalive/keepalive_windows.go create mode 100644 conf/mod_tcp_keepalive/tcp_keepalive.data diff --git a/.gitignore b/.gitignore index 899664793..5415d97da 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ coverage.txt .vscode/* bfe dist/* + +.DS_Store diff --git a/bfe_modules/mod_tcp_keepalive/keepalive_darwin.go b/bfe_modules/mod_tcp_keepalive/keepalive_darwin.go index ac03edfac..c8393ac9d 100644 --- a/bfe_modules/mod_tcp_keepalive/keepalive_darwin.go +++ b/bfe_modules/mod_tcp_keepalive/keepalive_darwin.go @@ -36,3 +36,7 @@ func setCount(fd int, n int) error { func setInterval(fd int, secs int) error { return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, _TCP_KEEPINTVL, secs)) } + +func setNonblock(fd int) error { + return os.NewSyscallError("setsockopt", syscall.SetNonblock(fd, true)) +} diff --git a/bfe_modules/mod_tcp_keepalive/keepalive_linux.go b/bfe_modules/mod_tcp_keepalive/keepalive_linux.go index 150078d91..6196c03d7 100644 --- a/bfe_modules/mod_tcp_keepalive/keepalive_linux.go +++ b/bfe_modules/mod_tcp_keepalive/keepalive_linux.go @@ -30,3 +30,7 @@ func setCount(fd int, n int) error { func setInterval(fd int, secs int) error { return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs)) } + +func setNonblock(fd int) error { + return os.NewSyscallError("setsockopt", syscall.SetNonblock(fd, true)) +} diff --git a/bfe_modules/mod_tcp_keepalive/keepalive_windows.go b/bfe_modules/mod_tcp_keepalive/keepalive_windows.go new file mode 100644 index 000000000..f38cf4c0b --- /dev/null +++ b/bfe_modules/mod_tcp_keepalive/keepalive_windows.go @@ -0,0 +1,51 @@ +// Copyright (c) 2021 The BFE Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package mod_tcp_keepalive + +import ( + "github.com/baidu/go-lib/log" +) + +func setIdle(fd int, secs int) error { + if openDebug { + log.Logger.Debug("mod[mod_tcp_keepalive] setIdle not implemented") + } + + return nil +} + +func setCount(fd int, n int) error { + if openDebug { + log.Logger.Debug("mod[mod_tcp_keepalive] setCount not implemented") + } + + return nil +} + +func setInterval(fd int, secs int) error { + if openDebug { + log.Logger.Debug("mod[mod_tcp_keepalive] setInterval not implemented") + } + + return nil +} + +func setNonblock(fd int) error { + if openDebug { + log.Logger.Debug("mod[mod_tcp_keepalive] setNonblock not implemented") + } + + return nil +} diff --git a/bfe_modules/mod_tcp_keepalive/mod_tcp_keepalive.go b/bfe_modules/mod_tcp_keepalive/mod_tcp_keepalive.go index 36334d4c3..cddb13274 100644 --- a/bfe_modules/mod_tcp_keepalive/mod_tcp_keepalive.go +++ b/bfe_modules/mod_tcp_keepalive/mod_tcp_keepalive.go @@ -20,7 +20,6 @@ import ( "net/url" "os" "reflect" - "syscall" "github.com/baidu/go-lib/log" "github.com/baidu/go-lib/web-monitor/metrics" @@ -142,10 +141,6 @@ func (m *ModuleTcpKeepAlive) disableKeepAlive(tcpConn *net.TCPConn) error { return nil } -func setNonblock(fd int) error { - return os.NewSyscallError("setsockopt", syscall.SetNonblock(fd, true)) -} - func (m *ModuleTcpKeepAlive) setKeepAliveParam(conn *net.TCPConn, p KeepAliveParam) error { var err error var f *os.File diff --git a/conf/bfe.conf b/conf/bfe.conf index c399ea295..f32ab5f13 100644 --- a/conf/bfe.conf +++ b/conf/bfe.conf @@ -45,6 +45,7 @@ ClusterTableConf = cluster_conf/cluster_table.data GslbConf = cluster_conf/gslb.data Modules = mod_trust_clientip +# Modules = mod_tcp_keepalive Modules = mod_block Modules = mod_header Modules = mod_rewrite diff --git a/conf/mod_tcp_keepalive/mod_tcp_keepalive.conf b/conf/mod_tcp_keepalive/mod_tcp_keepalive.conf index a68c030f6..e51d7d08f 100644 --- a/conf/mod_tcp_keepalive/mod_tcp_keepalive.conf +++ b/conf/mod_tcp_keepalive/mod_tcp_keepalive.conf @@ -1,5 +1,5 @@ [basic] -DataPath = ../data/mod_tcp_keepalive/tcp_keepalive.data +DataPath = mod_tcp_keepalive/tcp_keepalive.data [log] OpenDebug = false diff --git a/conf/mod_tcp_keepalive/tcp_keepalive.data b/conf/mod_tcp_keepalive/tcp_keepalive.data new file mode 100644 index 000000000..d56982a32 --- /dev/null +++ b/conf/mod_tcp_keepalive/tcp_keepalive.data @@ -0,0 +1,14 @@ +{ + "Config": { + "product1": [ + { + "VipConf": ["180.97.93.196"], + "KeepAliveParam": { + "KeepIdle": 270, + "KeepIntvl": 9 + } + } + ] + }, + "Version": "2021-06-25 14:31:05" +} \ No newline at end of file From a970f7fb68ace4067d573f1e23d31f0356b52793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=9D=92?= <295421489@qq.com> Date: Tue, 11 Jan 2022 14:18:31 +0800 Subject: [PATCH 2/2] update go.mod --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index fcae9fbdf..5a5c886a6 100644 --- a/go.mod +++ b/go.mod @@ -58,6 +58,7 @@ require ( go.elastic.co/apm/module/apmhttp v1.7.2 // indirect go.elastic.co/fastjson v1.1.0 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect + golang.org/x/text v0.3.7 // indirect google.golang.org/grpc v1.22.1 // indirect gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect