@@ -8,11 +8,13 @@ import (
8
8
"strconv"
9
9
"sync"
10
10
11
+ CN "github.com/metacubex/mihomo/common/net"
11
12
"github.com/metacubex/mihomo/component/dialer"
12
13
"github.com/metacubex/mihomo/component/proxydialer"
13
14
C "github.com/metacubex/mihomo/constant"
14
15
15
16
mieruclient "github.com/enfein/mieru/v3/apis/client"
17
+ mierucommon "github.com/enfein/mieru/v3/apis/common"
16
18
mierumodel "github.com/enfein/mieru/v3/apis/model"
17
19
mierupb "github.com/enfein/mieru/v3/pkg/appctl/appctlpb"
18
20
"google.golang.org/protobuf/proto"
@@ -32,6 +34,7 @@ type MieruOption struct {
32
34
Port int `proxy:"port,omitempty"`
33
35
PortRange string `proxy:"port-range,omitempty"`
34
36
Transport string `proxy:"transport"`
37
+ UDP bool `proxy:"udp,omitempty"`
35
38
UserName string `proxy:"username"`
36
39
Password string `proxy:"password"`
37
40
Multiplexing string `proxy:"multiplexing,omitempty"`
@@ -50,6 +53,23 @@ func (m *Mieru) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d
50
53
return NewConn (c , m ), nil
51
54
}
52
55
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
+
53
73
// ProxyInfo implements C.ProxyAdapter
54
74
func (m * Mieru ) ProxyInfo () C.ProxyInfo {
55
75
info := m .Base .ProxyInfo ()
@@ -113,7 +133,7 @@ func NewMieru(option MieruOption) (*Mieru, error) {
113
133
addr : addr ,
114
134
iface : option .Interface ,
115
135
tp : C .Mieru ,
116
- udp : false ,
136
+ udp : option . UDP ,
117
137
xudp : false ,
118
138
rmark : option .RoutingMark ,
119
139
prefer : C .NewDNSPrefer (option .IPVersion ),
0 commit comments