mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-04-13 20:28:32 +10:00
Report unreachable cloudflare v3 registrations
This commit is contained in:
@@ -142,6 +142,10 @@ func (m *DatagramV3Muxer) handleRegistration(ctx context.Context, data []byte) {
|
||||
if closeAfterIdle == 0 {
|
||||
closeAfterIdle = 210 * time.Second
|
||||
}
|
||||
if !destination.Addr().IsValid() || destination.Addr().IsUnspecified() || destination.Port() == 0 {
|
||||
m.sendRegistrationResponse(requestID, v3ResponseDestinationUnreachable, "")
|
||||
return
|
||||
}
|
||||
|
||||
m.sessionAccess.Lock()
|
||||
if existing, exists := m.sessions[requestID]; exists {
|
||||
|
||||
38
protocol/cloudflare/datagram_v3_test.go
Normal file
38
protocol/cloudflare/datagram_v3_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
//go:build with_cloudflare_tunnel
|
||||
|
||||
package cloudflare
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter/inbound"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
)
|
||||
|
||||
func TestDatagramV3RegistrationDestinationUnreachable(t *testing.T) {
|
||||
sender := &captureDatagramSender{}
|
||||
inboundInstance := &Inbound{
|
||||
Adapter: inbound.NewAdapter(C.TypeCloudflareTunnel, "test"),
|
||||
flowLimiter: &FlowLimiter{},
|
||||
}
|
||||
muxer := NewDatagramV3Muxer(inboundInstance, sender, nil)
|
||||
|
||||
requestID := RequestID{}
|
||||
requestID[15] = 1
|
||||
payload := make([]byte, 1+2+2+16+4)
|
||||
payload[0] = 0
|
||||
binary.BigEndian.PutUint16(payload[1:3], 0)
|
||||
binary.BigEndian.PutUint16(payload[3:5], 30)
|
||||
copy(payload[5:21], requestID[:])
|
||||
copy(payload[21:25], []byte{0, 0, 0, 0})
|
||||
|
||||
muxer.handleRegistration(context.Background(), payload)
|
||||
if len(sender.sent) != 1 {
|
||||
t.Fatalf("expected one registration response, got %d", len(sender.sent))
|
||||
}
|
||||
if sender.sent[0][0] != byte(DatagramV3TypeRegistrationResponse) || sender.sent[0][1] != v3ResponseDestinationUnreachable {
|
||||
t.Fatalf("unexpected datagram response: %v", sender.sent[0])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user