@@ -47,6 +47,7 @@ type Common struct {
4747 minPoolCapacity int // 最小池容量
4848 maxPoolCapacity int // 最大池容量
4949 proxyProtocol string // 代理协议
50+ disableUDP string // 禁用UDP
5051 rateLimit int // 速率限制
5152 rateLimiter * conn.RateLimiter // 全局限速器
5253 readTimeout time.Duration // 读取超时
@@ -98,6 +99,7 @@ const (
9899 defaultRateLimit = 0 // 默认速率限制
99100 defaultSlotLimit = 65536 // 默认槽位限制
100101 defaultProxyProtocol = "0" // 默认代理协议
102+ defaultUDPStrategy = "0" // 默认UDP策略
101103)
102104
103105// getTCPBuffer 获取TCP缓冲区
@@ -402,6 +404,15 @@ func (c *Common) getProxyProtocol(parsedURL *url.URL) {
402404 }
403405}
404406
407+ // getUDPStrategy 获取UDP策略
408+ func (c * Common ) getUDPStrategy (parsedURL * url.URL ) {
409+ if udpStrategy := parsedURL .Query ().Get ("noudp" ); udpStrategy != "" {
410+ c .disableUDP = udpStrategy
411+ } else {
412+ c .disableUDP = defaultUDPStrategy
413+ }
414+ }
415+
405416// initConfig 初始化配置
406417func (c * Common ) initConfig (parsedURL * url.URL ) error {
407418 if err := c .getAddress (parsedURL ); err != nil {
@@ -415,6 +426,7 @@ func (c *Common) initConfig(parsedURL *url.URL) error {
415426 c .getRateLimit (parsedURL )
416427 c .getSlotLimit (parsedURL )
417428 c .getProxyProtocol (parsedURL )
429+ c .getUDPStrategy (parsedURL )
418430
419431 return nil
420432}
@@ -487,7 +499,7 @@ func (c *Common) initTunnelListener() error {
487499 }
488500
489501 // 初始化隧道UDP监听器
490- if c .tunnelUDPAddr != nil {
502+ if c .tunnelUDPAddr != nil && c . disableUDP != "1" {
491503 tunnelUDPConn , err := net .ListenUDP ("udp" , c .tunnelUDPAddr )
492504 if err != nil {
493505 return fmt .Errorf ("initTunnelListener: listenUDP failed: %w" , err )
@@ -514,7 +526,7 @@ func (c *Common) initTargetListener() error {
514526 }
515527
516528 // 初始化目标UDP监听器
517- if len (c .targetUDPAddrs ) > 0 {
529+ if len (c .targetUDPAddrs ) > 0 && c . disableUDP != "1" {
518530 targetUDPConn , err := net .ListenUDP ("udp" , c .targetUDPAddrs [0 ])
519531 if err != nil {
520532 return fmt .Errorf ("initTargetListener: listenUDP failed: %w" , err )
@@ -743,8 +755,12 @@ func (c *Common) commonLoop() {
743755 for c .ctx .Err () == nil {
744756 // 等待连接池准备就绪
745757 if c .tunnelPool .Ready () {
746- go c .commonTCPLoop ()
747- go c .commonUDPLoop ()
758+ if c .targetListener != nil {
759+ go c .commonTCPLoop ()
760+ }
761+ if c .targetUDPConn != nil {
762+ go c .commonUDPLoop ()
763+ }
748764 return
749765 }
750766
@@ -1014,9 +1030,13 @@ func (c *Common) commonOnce() error {
10141030 // 处理信号
10151031 switch signalURL .Fragment {
10161032 case "1" : // TCP
1017- go c .commonTCPOnce (signalURL )
1033+ if len (c .targetTCPAddrs ) > 0 {
1034+ go c .commonTCPOnce (signalURL )
1035+ }
10181036 case "2" : // UDP
1019- go c .commonUDPOnce (signalURL )
1037+ if c .disableUDP != "1" {
1038+ go c .commonUDPOnce (signalURL )
1039+ }
10201040 case "c" : // 连接池清理
10211041 go func () {
10221042 c .tunnelPool .Clean ()
0 commit comments