feat(tun): use time.Duration for timeout config

matches timeout config of other inbounds
This commit is contained in:
Haruue
2024-03-19 15:48:57 +08:00
parent 4aec8166b3
commit 0cde4f405f
2 changed files with 13 additions and 12 deletions

View File

@@ -150,11 +150,11 @@ type tcpRedirectConfig struct {
} }
type tunConfig struct { type tunConfig struct {
Name string `mapstructure:"name"` Name string `mapstructure:"name"`
MTU uint32 `mapstructure:"mtu"` MTU uint32 `mapstructure:"mtu"`
UDPTimeout int64 `mapstructure:"udpTimeout"` Timeout time.Duration `mapstructure:"timeout"`
Prefix4 string `mapstructure:"prefix4"` Prefix4 string `mapstructure:"prefix4"`
Prefix6 string `mapstructure:"prefix6"` Prefix6 string `mapstructure:"prefix6"`
} }
func (c *clientConfig) fillServerAddr(hyConfig *client.Config) error { func (c *clientConfig) fillServerAddr(hyConfig *client.Config) error {
@@ -680,8 +680,9 @@ func clientTUN(config tunConfig, c client.Client) error {
if config.MTU == 0 { if config.MTU == 0 {
config.MTU = 1500 config.MTU = 1500
} }
if config.UDPTimeout == 0 { timeout := int64(config.Timeout.Seconds())
config.UDPTimeout = 300 if timeout == 0 {
timeout = 300
} }
if config.Prefix4 == "" { if config.Prefix4 == "" {
config.Prefix4 = "100.100.100.101/30" config.Prefix4 = "100.100.100.101/30"
@@ -703,7 +704,7 @@ func clientTUN(config tunConfig, c client.Client) error {
Logger: logger, Logger: logger,
IfName: config.Name, IfName: config.Name,
MTU: config.MTU, MTU: config.MTU,
UDPTimeout: config.UDPTimeout, Timeout: timeout,
Inet4Address: []netip.Prefix{prefix4}, Inet4Address: []netip.Prefix{prefix4},
Inet6Address: []netip.Prefix{prefix6}, Inet6Address: []netip.Prefix{prefix6},
} }

View File

@@ -22,9 +22,9 @@ type Server struct {
// for debugging // for debugging
Logger *zap.Logger Logger *zap.Logger
IfName string IfName string
MTU uint32 MTU uint32
UDPTimeout int64 // in seconds Timeout int64 // in seconds, also applied to TCP in system stack
// required by system stack // required by system stack
Inet4Address []netip.Prefix Inet4Address []netip.Prefix
@@ -60,7 +60,7 @@ func (s *Server) Serve() error {
Context: context.Background(), Context: context.Background(),
Tun: tunIf, Tun: tunIf,
TunOptions: tunOpts, TunOptions: tunOpts,
UDPTimeout: s.UDPTimeout, UDPTimeout: s.Timeout,
Handler: &tunHandler{s}, Handler: &tunHandler{s},
Logger: &singLogger{ Logger: &singLogger{
tag: "tun-stack", tag: "tun-stack",