Skip to content

Commit 8f18d3f

Browse files
committed
chore: add recvmsgx and sendmsgx config to tun
Only for advanced users, enabling `recvmsgx` under darwin can improve performance, but enabling `sendmsgx` may cause unknown problems, please use with caution.
1 parent b9260e0 commit 8f18d3f

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ type RawTun struct {
296296
Inet6RouteAddress []netip.Prefix `yaml:"inet6-route-address" json:"inet6-route-address,omitempty"`
297297
Inet4RouteExcludeAddress []netip.Prefix `yaml:"inet4-route-exclude-address" json:"inet4-route-exclude-address,omitempty"`
298298
Inet6RouteExcludeAddress []netip.Prefix `yaml:"inet6-route-exclude-address" json:"inet6-route-exclude-address,omitempty"`
299+
300+
// darwin special config
301+
RecvMsgX bool `yaml:"recvmsgx" json:"recvmsgx,omitempty"`
302+
SendMsgX bool `yaml:"sendmsgx" json:"sendmsgx,omitempty"`
299303
}
300304

301305
type RawTuicServer struct {
@@ -513,6 +517,8 @@ func DefaultRawConfig() *RawConfig {
513517
AutoRoute: true,
514518
AutoDetectInterface: true,
515519
Inet6Address: []netip.Prefix{netip.MustParsePrefix("fdfe:dcba:9876::1/126")},
520+
RecvMsgX: true,
521+
SendMsgX: false, // In the current implementation, if enabled, the kernel may freeze during multi-thread downloads, so it is disabled by default.
516522
},
517523
TuicServer: RawTuicServer{
518524
Enable: false,
@@ -1554,6 +1560,9 @@ func parseTun(rawTun RawTun, general *General) error {
15541560
Inet6RouteAddress: rawTun.Inet6RouteAddress,
15551561
Inet4RouteExcludeAddress: rawTun.Inet4RouteExcludeAddress,
15561562
Inet6RouteExcludeAddress: rawTun.Inet6RouteExcludeAddress,
1563+
1564+
RecvMsgX: rawTun.RecvMsgX,
1565+
SendMsgX: rawTun.SendMsgX,
15571566
}
15581567

15591568
return nil

hub/route/configs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ type tunSchema struct {
100100
Inet6RouteAddress *[]netip.Prefix `yaml:"inet6-route-address" json:"inet6-route-address,omitempty"`
101101
Inet4RouteExcludeAddress *[]netip.Prefix `yaml:"inet4-route-exclude-address" json:"inet4-route-exclude-address,omitempty"`
102102
Inet6RouteExcludeAddress *[]netip.Prefix `yaml:"inet6-route-exclude-address" json:"inet6-route-exclude-address,omitempty"`
103+
104+
// darwin special config
105+
RecvMsgX *bool `yaml:"recvmsgx" json:"recvmsgx,omitempty"`
106+
SendMsgX *bool `yaml:"sendmsgx" json:"sendmsgx,omitempty"`
103107
}
104108

105109
type tuicServerSchema struct {
@@ -243,6 +247,12 @@ func pointerOrDefaultTun(p *tunSchema, def LC.Tun) LC.Tun {
243247
if p.FileDescriptor != nil {
244248
def.FileDescriptor = *p.FileDescriptor
245249
}
250+
if p.RecvMsgX != nil {
251+
def.RecvMsgX = *p.RecvMsgX
252+
}
253+
if p.SendMsgX != nil {
254+
def.SendMsgX = *p.SendMsgX
255+
}
246256
}
247257
return def
248258
}

listener/config/tun.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type Tun struct {
5454
Inet6RouteAddress []netip.Prefix `yaml:"inet6-route-address" json:"inet6-route-address,omitempty"`
5555
Inet4RouteExcludeAddress []netip.Prefix `yaml:"inet4-route-exclude-address" json:"inet4-route-exclude-address,omitempty"`
5656
Inet6RouteExcludeAddress []netip.Prefix `yaml:"inet6-route-exclude-address" json:"inet6-route-exclude-address,omitempty"`
57+
58+
// darwin special config
59+
RecvMsgX bool `yaml:"recvmsgx" json:"recvmsgx,omitempty"`
60+
SendMsgX bool `yaml:"sendmsgx" json:"sendmsgx,omitempty"`
5761
}
5862

5963
func (t *Tun) Sort() {
@@ -199,5 +203,12 @@ func (t *Tun) Equal(other Tun) bool {
199203
return false
200204
}
201205

206+
if t.RecvMsgX != other.RecvMsgX {
207+
return false
208+
}
209+
if t.SendMsgX != other.SendMsgX {
210+
return false
211+
}
212+
202213
return true
203214
}

listener/inbound/tun.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ type TunOption struct {
5555
Inet6RouteAddress []netip.Prefix `inbound:"inet6-route-address,omitempty"`
5656
Inet4RouteExcludeAddress []netip.Prefix `inbound:"inet4-route-exclude-address,omitempty"`
5757
Inet6RouteExcludeAddress []netip.Prefix `inbound:"inet6-route-exclude-address,omitempty"`
58+
59+
// darwin special config
60+
RecvMsgX bool `inbound:"recvmsgx,omitempty"`
61+
SendMsgX bool `inbound:"sendmsgx,omitempty"`
5862
}
5963

6064
var _ encoding.TextUnmarshaler = (*netip.Addr)(nil) // ensure netip.Addr can decode direct by structure package
@@ -124,6 +128,9 @@ func NewTun(options *TunOption) (*Tun, error) {
124128
Inet6RouteAddress: options.Inet6RouteAddress,
125129
Inet4RouteExcludeAddress: options.Inet4RouteExcludeAddress,
126130
Inet6RouteExcludeAddress: options.Inet6RouteExcludeAddress,
131+
132+
RecvMsgX: options.RecvMsgX,
133+
SendMsgX: options.SendMsgX,
127134
},
128135
}, nil
129136
}

listener/sing_tun/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
365365
ExcludePackage: options.ExcludePackage,
366366
FileDescriptor: options.FileDescriptor,
367367
InterfaceMonitor: defaultInterfaceMonitor,
368+
EXP_RecvMsgX: options.RecvMsgX,
369+
EXP_SendMsgX: options.SendMsgX,
368370
}
369371

370372
if options.AutoRedirect {

0 commit comments

Comments
 (0)