fix udp port forwarding

This commit is contained in:
ginuerzh
2024-10-22 22:50:40 +08:00
parent 3ca253537b
commit 3b4fd643de
2 changed files with 12 additions and 12 deletions
+6 -6
View File
@@ -105,6 +105,12 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
}) })
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr()) log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
network := "tcp"
if _, ok := conn.(net.PacketConn); ok {
network = "udp"
}
ro.Network = network
pStats := stats.Stats{} pStats := stats.Stats{}
conn = stats_wrapper.WrapConn(conn, &pStats) conn = stats_wrapper.WrapConn(conn, &pStats)
@@ -130,12 +136,6 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
return rate_limiter.ErrRateLimit return rate_limiter.ErrRateLimit
} }
network := "tcp"
if _, ok := conn.(net.PacketConn); ok {
network = "udp"
}
ro.Network = network
var proto string var proto string
if network == "tcp" && h.md.sniffing { if network == "tcp" && h.md.sniffing {
if h.md.sniffingTimeout > 0 { if h.md.sniffingTimeout > 0 {
+6 -6
View File
@@ -106,6 +106,12 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
}) })
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr()) log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
network := "tcp"
if _, ok := conn.(net.PacketConn); ok {
network = "udp"
}
ro.Network = network
pStats := stats.Stats{} pStats := stats.Stats{}
conn = stats_wrapper.WrapConn(conn, &pStats) conn = stats_wrapper.WrapConn(conn, &pStats)
@@ -131,12 +137,6 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
return rate_limiter.ErrRateLimit return rate_limiter.ErrRateLimit
} }
network := "tcp"
if _, ok := conn.(net.PacketConn); ok {
network = "udp"
}
ro.Network = network
var proto string var proto string
if network == "tcp" && h.md.sniffing { if network == "tcp" && h.md.sniffing {
if h.md.sniffingTimeout > 0 { if h.md.sniffingTimeout > 0 {