Skip to content

Commit 0f32c05

Browse files
authored
feat: support UDP over TCP in mieru (#1926)
1 parent 4f8b70c commit 0f32c05

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

adapter/outbound/mieru.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"strconv"
99
"sync"
1010

11+
CN "github.com/metacubex/mihomo/common/net"
1112
"github.com/metacubex/mihomo/component/dialer"
1213
"github.com/metacubex/mihomo/component/proxydialer"
1314
C "github.com/metacubex/mihomo/constant"
1415

1516
mieruclient "github.com/enfein/mieru/v3/apis/client"
17+
mierucommon "github.com/enfein/mieru/v3/apis/common"
1618
mierumodel "github.com/enfein/mieru/v3/apis/model"
1719
mierupb "github.com/enfein/mieru/v3/pkg/appctl/appctlpb"
1820
"google.golang.org/protobuf/proto"
@@ -32,6 +34,7 @@ type MieruOption struct {
3234
Port int `proxy:"port,omitempty"`
3335
PortRange string `proxy:"port-range,omitempty"`
3436
Transport string `proxy:"transport"`
37+
UDP bool `proxy:"udp,omitempty"`
3538
UserName string `proxy:"username"`
3639
Password string `proxy:"password"`
3740
Multiplexing string `proxy:"multiplexing,omitempty"`
@@ -50,6 +53,23 @@ func (m *Mieru) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d
5053
return NewConn(c, m), nil
5154
}
5255

56+
// ListenPacketContext implements C.ProxyAdapter
57+
func (m *Mieru) ListenPacketContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (_ C.PacketConn, err error) {
58+
if err := m.ensureClientIsRunning(opts...); err != nil {
59+
return nil, err
60+
}
61+
c, err := m.client.DialContext(ctx, metadata.UDPAddr())
62+
if err != nil {
63+
return nil, fmt.Errorf("dial to %s failed: %w", metadata.UDPAddr(), err)
64+
}
65+
return newPacketConn(CN.NewRefPacketConn(CN.NewThreadSafePacketConn(mierucommon.NewUDPAssociateWrapper(mierucommon.NewPacketOverStreamTunnel(c))), m), m), nil
66+
}
67+
68+
// SupportUOT implements C.ProxyAdapter
69+
func (m *Mieru) SupportUOT() bool {
70+
return true
71+
}
72+
5373
// ProxyInfo implements C.ProxyAdapter
5474
func (m *Mieru) ProxyInfo() C.ProxyInfo {
5575
info := m.Base.ProxyInfo()
@@ -113,7 +133,7 @@ func NewMieru(option MieruOption) (*Mieru, error) {
113133
addr: addr,
114134
iface: option.Interface,
115135
tp: C.Mieru,
116-
udp: false,
136+
udp: option.UDP,
117137
xudp: false,
118138
rmark: option.RoutingMark,
119139
prefer: C.NewDNSPrefer(option.IPVersion),

docs/config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ proxies: # socks5
879879
port: 2999
880880
# port-range: 2090-2099 #(不可同时填写 port 和 port-range)
881881
transport: TCP # 只支持 TCP
882+
udp: true # 支持 UDP over TCP
882883
username: user
883884
password: password
884885
# 可以使用的值包括 MULTIPLEXING_OFF, MULTIPLEXING_LOW, MULTIPLEXING_MIDDLE, MULTIPLEXING_HIGH。其中 MULTIPLEXING_OFF 会关闭多路复用功能。默认值为 MULTIPLEXING_LOW。

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/bahlo/generic-list-go v0.2.0
88
github.com/coreos/go-iptables v0.8.0
99
github.com/dlclark/regexp2 v1.11.5
10-
github.com/enfein/mieru/v3 v3.12.0
10+
github.com/enfein/mieru/v3 v3.13.0
1111
github.com/go-chi/chi/v5 v5.2.1
1212
github.com/go-chi/render v1.0.3
1313
github.com/gobwas/ws v1.4.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZ
2828
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
2929
github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I=
3030
github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
31-
github.com/enfein/mieru/v3 v3.12.0 h1:sV3moozWpRjjqwqFZJjGtMB0EacN8+D7BpjzsmacsXM=
32-
github.com/enfein/mieru/v3 v3.12.0/go.mod h1:zJBUCsi5rxyvHM8fjFf+GLaEl4OEjjBXr1s5F6Qd3hM=
31+
github.com/enfein/mieru/v3 v3.13.0 h1:eGyxLGkb+lut9ebmx+BGwLJ5UMbEc/wGIYO0AXEKy98=
32+
github.com/enfein/mieru/v3 v3.13.0/go.mod h1:zJBUCsi5rxyvHM8fjFf+GLaEl4OEjjBXr1s5F6Qd3hM=
3333
github.com/ericlagergren/aegis v0.0.0-20230312195928-b4ce538b56f9 h1:/5RkVc9Rc81XmMyVqawCiDyrBHZbLAZgTTCqou4mwj8=
3434
github.com/ericlagergren/aegis v0.0.0-20230312195928-b4ce538b56f9/go.mod h1:hkIFzoiIPZYxdFOOLyDho59b7SrDfo+w3h+yWdlg45I=
3535
github.com/ericlagergren/polyval v0.0.0-20220411101811-e25bc10ba391 h1:8j2RH289RJplhA6WfdaPqzg1MjH2K8wX5e0uhAxrw2g=

0 commit comments

Comments
 (0)