Skip to content

Commit 937922c

Browse files
authored
Merge branch 'MetaCubeX:Alpha' into Alpha
2 parents 536a120 + c2e2956 commit 937922c

File tree

7 files changed

+77
-20
lines changed

7 files changed

+77
-20
lines changed

component/dialer/dialer.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"strings"
1111
"sync"
12+
"syscall"
1213
"time"
1314

1415
"github.com/metacubex/mihomo/component/keepalive"
@@ -177,6 +178,34 @@ func dialContext(ctx context.Context, network string, destination netip.Addr, po
177178
return dialer.DialContext(ctx, network, address)
178179
}
179180

181+
func ICMPControl(destination netip.Addr) func(network, address string, conn syscall.RawConn) error {
182+
return func(network, address string, conn syscall.RawConn) error {
183+
if DefaultSocketHook != nil {
184+
return DefaultSocketHook(network, address, conn)
185+
}
186+
dialer := &net.Dialer{}
187+
interfaceName := DefaultInterface.Load()
188+
if interfaceName == "" {
189+
if finder := DefaultInterfaceFinder.Load(); finder != nil {
190+
interfaceName = finder.FindInterfaceName(destination)
191+
}
192+
}
193+
if interfaceName != "" {
194+
if err := bindIfaceToDialer(interfaceName, dialer, network, destination); err != nil {
195+
return err
196+
}
197+
}
198+
routingMark := int(DefaultRoutingMark.Load())
199+
if routingMark != 0 {
200+
bindMarkToDialer(routingMark, dialer, network, destination)
201+
}
202+
if dialer.ControlContext != nil {
203+
return dialer.ControlContext(context.TODO(), network, address, conn)
204+
}
205+
return nil
206+
}
207+
}
208+
180209
func serialSingleStackDialContext(ctx context.Context, network string, ips []netip.Addr, port string, opt option) (net.Conn, error) {
181210
return serialDialContext(ctx, network, ips, port, opt)
182211
}

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ require (
2424
github.com/metacubex/quic-go v0.54.1-0.20250730114134-a1ae705fe295
2525
github.com/metacubex/randv2 v0.2.0
2626
github.com/metacubex/restls-client-go v0.1.7
27-
github.com/metacubex/sing v0.5.5
27+
github.com/metacubex/sing v0.5.6-0.20250823162028-e4ed887cf06e
2828
github.com/metacubex/sing-mux v0.3.3-0.20250813083925-d7c9aeaeeaac
2929
github.com/metacubex/sing-quic v0.0.0-20250718154553-1b193bec4cbb
3030
github.com/metacubex/sing-shadowsocks v0.2.12
3131
github.com/metacubex/sing-shadowsocks2 v0.2.6
3232
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2
33-
github.com/metacubex/sing-tun v0.4.7
33+
github.com/metacubex/sing-tun v0.4.8-0.20250823163003-53dbe7b5dfd8
3434
github.com/metacubex/sing-vmess v0.2.4-0.20250822020810-4856053566f0
3535
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f
3636
github.com/metacubex/smux v0.0.0-20250503055512-501391591dee
3737
github.com/metacubex/tfo-go v0.0.0-20250516165257-e29c16ae41d4
38-
github.com/metacubex/utls v1.8.1-0.20250811145843-49b4f106169a
38+
github.com/metacubex/utls v1.8.1-0.20250823120917-12f5ba126142
3939
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f
4040
github.com/miekg/dns v1.1.63 // lastest version compatible with golang1.20
4141
github.com/mroth/weightedrand/v2 v2.1.0
@@ -86,7 +86,7 @@ require (
8686
github.com/mailru/easyjson v0.7.7 // indirect
8787
github.com/mdlayher/socket v0.4.1 // indirect
8888
github.com/metacubex/ascon v0.1.0 // indirect
89-
github.com/metacubex/gvisor v0.0.0-20250324165734-5857f47bd43b // indirect
89+
github.com/metacubex/gvisor v0.0.0-20250823135502-e52fca163229 // indirect
9090
github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793 // indirect
9191
github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 // indirect
9292
github.com/onsi/ginkgo/v2 v2.9.5 // indirect

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ github.com/metacubex/fswatch v0.1.1 h1:jqU7C/v+g0qc2RUFgmAOPoVvfl2BXXUXEumn6oQux
100100
github.com/metacubex/fswatch v0.1.1/go.mod h1:czrTT7Zlbz7vWft8RQu9Qqh+JoX+Nnb+UabuyN1YsgI=
101101
github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759 h1:cjd4biTvOzK9ubNCCkQ+ldc4YSH/rILn53l/xGBFHHI=
102102
github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759/go.mod h1:UHOv2xu+RIgLwpXca7TLrXleEd4oR3sPatW6IF8wU88=
103-
github.com/metacubex/gvisor v0.0.0-20250324165734-5857f47bd43b h1:RUh4OdVPz/jDrM9MQ2ySuqu2aeBqcA8rtfWUYLZ8RtI=
104-
github.com/metacubex/gvisor v0.0.0-20250324165734-5857f47bd43b/go.mod h1:8LpS0IJW1VmWzUm3ylb0e2SK5QDm5lO/2qwWLZgRpBU=
103+
github.com/metacubex/gvisor v0.0.0-20250823135502-e52fca163229 h1:sXVGoj8TdkMYp/ZiZgZJ5lgNww2DJdA/Lywu63+Z2/w=
104+
github.com/metacubex/gvisor v0.0.0-20250823135502-e52fca163229/go.mod h1:8LpS0IJW1VmWzUm3ylb0e2SK5QDm5lO/2qwWLZgRpBU=
105105
github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793 h1:1Qpuy+sU3DmyX9HwI+CrBT/oLNJngvBorR2RbajJcqo=
106106
github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793/go.mod h1:RjRNb4G52yAgfR+Oe/kp9G4PJJ97Fnj89eY1BFO3YyA=
107107
github.com/metacubex/quic-go v0.54.1-0.20250730114134-a1ae705fe295 h1:8JVlYuE8uSJAvmyCd4TjvDxs57xjb0WxEoaWafK5+qs=
@@ -111,8 +111,8 @@ github.com/metacubex/randv2 v0.2.0/go.mod h1:kFi2SzrQ5WuneuoLLCMkABtiBu6VRrMrWFq
111111
github.com/metacubex/restls-client-go v0.1.7 h1:eCwiXCTQb5WJu9IlgYvDBA1OgrINv58dEe7hcN5H15k=
112112
github.com/metacubex/restls-client-go v0.1.7/go.mod h1:BN/U52vPw7j8VTSh2vleD/MnmVKCov84mS5VcjVHH4g=
113113
github.com/metacubex/sing v0.5.2/go.mod h1:ypf0mjwlZm0sKdQSY+yQvmsbWa0hNPtkeqyRMGgoN+w=
114-
github.com/metacubex/sing v0.5.5 h1:m5U8iHvRAUxlme3FZlE/LPIGHjU8oMCUzXWGbQQAC1E=
115-
github.com/metacubex/sing v0.5.5/go.mod h1:ypf0mjwlZm0sKdQSY+yQvmsbWa0hNPtkeqyRMGgoN+w=
114+
github.com/metacubex/sing v0.5.6-0.20250823162028-e4ed887cf06e h1:gJATpvB5faqzNc6sLKaGhbsXDdvdnMIMBa2pBBS3INA=
115+
github.com/metacubex/sing v0.5.6-0.20250823162028-e4ed887cf06e/go.mod h1:ypf0mjwlZm0sKdQSY+yQvmsbWa0hNPtkeqyRMGgoN+w=
116116
github.com/metacubex/sing-mux v0.3.3-0.20250813083925-d7c9aeaeeaac h1:wDH/Jh/yqWbzPktqJP+Y1cUG8hchcrzKzUxJiSpnaQs=
117117
github.com/metacubex/sing-mux v0.3.3-0.20250813083925-d7c9aeaeeaac/go.mod h1:3rt1soewn0O6j89GCLmwAQFsq257u0jf2zQSPhTL3Bw=
118118
github.com/metacubex/sing-quic v0.0.0-20250718154553-1b193bec4cbb h1:U/m3h8lp/j7i8zFgfvScLdZa1/Y8dd74oO7iZaQq80s=
@@ -123,8 +123,8 @@ github.com/metacubex/sing-shadowsocks2 v0.2.6 h1:ZR1kYT0f0Vi64iQSS09OdhFfppiNkh7
123123
github.com/metacubex/sing-shadowsocks2 v0.2.6/go.mod h1:vOEbfKC60txi0ca+yUlqEwOGc3Obl6cnSgx9Gf45KjE=
124124
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2 h1:gXU+MYPm7Wme3/OAY2FFzVq9d9GxPHOqu5AQfg/ddhI=
125125
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2/go.mod h1:mbfboaXauKJNIHJYxQRa+NJs4JU9NZfkA+I33dS2+9E=
126-
github.com/metacubex/sing-tun v0.4.7 h1:ZDY/W+1c7PeWWKeKRyUo18fySF/TWjB0i5ui81Ar778=
127-
github.com/metacubex/sing-tun v0.4.7/go.mod h1:xHecZRwBnKWe6zG9amAK9cXf91lF6blgjBqm+VvOrmU=
126+
github.com/metacubex/sing-tun v0.4.8-0.20250823163003-53dbe7b5dfd8 h1:FPgUwy8Myr3mRi3yp3+Iv+sz5yxvN9FjuZUYM3p+GqA=
127+
github.com/metacubex/sing-tun v0.4.8-0.20250823163003-53dbe7b5dfd8/go.mod h1:/i53ifwthzZaUrhyxgrR/ihQDjoEgfJf+TJ0FivBtdI=
128128
github.com/metacubex/sing-vmess v0.2.4-0.20250822020810-4856053566f0 h1:WZepq4TOZa6WewB8tGAZrrL+bL2R2ivoBzuEgAeolWc=
129129
github.com/metacubex/sing-vmess v0.2.4-0.20250822020810-4856053566f0/go.mod h1:21R5R1u90uUvBQF0owoooEu96/SAYYD56nDrwm6nFaM=
130130
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f h1:Sr/DYKYofKHKc4GF3qkRGNuj6XA6c0eqPgEDN+VAsYU=
@@ -133,8 +133,8 @@ github.com/metacubex/smux v0.0.0-20250503055512-501391591dee h1:lp6hJ+4wCLZu113a
133133
github.com/metacubex/smux v0.0.0-20250503055512-501391591dee/go.mod h1:4bPD8HWx9jPJ9aE4uadgyN7D1/Wz3KmPy+vale8sKLE=
134134
github.com/metacubex/tfo-go v0.0.0-20250516165257-e29c16ae41d4 h1:j1VRTiC9JLR4nUbSikx9OGdu/3AgFDqgcLj4GoqyQkc=
135135
github.com/metacubex/tfo-go v0.0.0-20250516165257-e29c16ae41d4/go.mod h1:l9oLnLoEXyGZ5RVLsh7QCC5XsouTUyKk4F2nLm2DHLw=
136-
github.com/metacubex/utls v1.8.1-0.20250811145843-49b4f106169a h1:IIzlVmDoB4+7b0BUcLZaY5+AirhhLFep3PhwkAFMRnQ=
137-
github.com/metacubex/utls v1.8.1-0.20250811145843-49b4f106169a/go.mod h1:FdjYzVfCtgtna19hX0ER1Xsa5uJInwdQ4IcaaI98lEQ=
136+
github.com/metacubex/utls v1.8.1-0.20250823120917-12f5ba126142 h1:csEbKOzRAxJXffOeZnnS3/kA/F55JiTbKv5jcYqCXms=
137+
github.com/metacubex/utls v1.8.1-0.20250823120917-12f5ba126142/go.mod h1:67I3skhEY4Sya8f1YxELwWPoeQdXqZCrWNYLvq8gn2U=
138138
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f h1:FGBPRb1zUabhPhDrlKEjQ9lgIwQ6cHL4x8M9lrERhbk=
139139
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f/go.mod h1:oPGcV994OGJedmmxrcK9+ni7jUEMGhR+uVQAdaduIP4=
140140
github.com/miekg/dns v1.1.63 h1:8M5aAw6OMZfFXTT7K5V0Eu5YiiL8l7nUAkyN6C9YwaY=

listener/sing_tun/prepare.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package sing_tun
2+
3+
import (
4+
"context"
5+
6+
"github.com/metacubex/mihomo/component/dialer"
7+
"github.com/metacubex/mihomo/log"
8+
9+
tun "github.com/metacubex/sing-tun"
10+
"github.com/metacubex/sing-tun/ping"
11+
M "github.com/metacubex/sing/common/metadata"
12+
N "github.com/metacubex/sing/common/network"
13+
)
14+
15+
func (h *ListenerHandler) PrepareConnection(network string, source M.Socksaddr, destination M.Socksaddr, routeContext tun.DirectRouteContext) (tun.DirectRouteDestination, error) {
16+
switch network {
17+
case N.NetworkICMPv4, N.NetworkICMPv6: // our fork only send those type to PrepareConnection now
18+
log.Infoln("[ICMP] %s %s --> %s using DIRECT", network, source, destination)
19+
directRouteDestination, err := ping.ConnectDestination(context.TODO(), log.SingLogger, dialer.ICMPControl(destination.Addr), destination.Addr, routeContext)
20+
if err != nil {
21+
log.Warnln("[ICMP] failed to connect to %s", destination)
22+
return nil, err
23+
}
24+
log.Debugln("[ICMP] success connect to %s", destination)
25+
return directRouteDestination, nil
26+
}
27+
return nil, nil
28+
}

listener/sing_tun/server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strconv"
1212
"strings"
1313
"sync"
14+
"time"
1415

1516
"github.com/metacubex/mihomo/adapter/inbound"
1617
"github.com/metacubex/mihomo/component/dialer"
@@ -174,11 +175,11 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
174175
if tunMTU == 0 {
175176
tunMTU = 9000
176177
}
177-
var udpTimeout int64
178+
var udpTimeout time.Duration
178179
if options.UDPTimeout != 0 {
179-
udpTimeout = options.UDPTimeout
180+
udpTimeout = time.Second * time.Duration(options.UDPTimeout)
180181
} else {
181-
udpTimeout = int64(sing.UDPTimeout.Seconds())
182+
udpTimeout = sing.UDPTimeout
182183
}
183184
tableIndex := options.IPRoute2TableIndex
184185
if tableIndex == 0 {

transport/vless/encryption/common.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"math/big"
1111
"net"
1212

13+
"github.com/metacubex/utls/hkdf"
1314
"golang.org/x/crypto/chacha20poly1305"
14-
"golang.org/x/crypto/hkdf"
1515
"golang.org/x/crypto/sha3"
1616
)
1717

@@ -81,8 +81,7 @@ func ReadAndDiscardPaddings(conn net.Conn, aead cipher.AEAD, nonce []byte) (h []
8181
}
8282

8383
func NewAEAD(c byte, secret, salt, info []byte) (aead cipher.AEAD) {
84-
key := make([]byte, 32)
85-
hkdf.New(sha3.New256, secret, salt, info).Read(key)
84+
key, _ := hkdf.Key(sha3.New256, secret, salt, string(info), 32)
8685
if c&1 == 1 {
8786
block, _ := aes.NewCipher(key)
8887
aead, _ = cipher.NewGCM(block)

transport/vless/encryption/xor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"io"
1010
"net"
1111

12-
"golang.org/x/crypto/hkdf"
12+
"github.com/metacubex/utls/hkdf"
1313
"golang.org/x/crypto/sha3"
1414
)
1515

@@ -38,7 +38,7 @@ func NewCTR(key, iv []byte, isServer bool) cipher.Stream {
3838
if isServer {
3939
info = "SERVER" // avoids attackers sending traffic back to the client, though the encryption layer has its own protection
4040
}
41-
hkdf.New(sha3.New256, key, iv, []byte(info)).Read(key) // avoids using pKey directly if attackers sent the basepoint, or whaterver they like
41+
key, _ = hkdf.Key(sha3.New256, key, iv, info, 32) // avoids using pKey directly if attackers sent the basepoint, or whaterver they like
4242
block, _ := aes.NewCipher(key)
4343
return cipher.NewCTR(block, iv)
4444
}

0 commit comments

Comments
 (0)