mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-04-13 20:28:32 +10:00
Return v3 registration protocol errors
This commit is contained in:
@@ -120,7 +120,7 @@ func (m *DatagramV3Muxer) handleRegistration(ctx context.Context, data []byte) {
|
||||
|
||||
if flags&v3FlagIPv6 != 0 {
|
||||
if len(data) < offset+v3IPv6AddrLen {
|
||||
m.logger.Debug("V3 registration too short for IPv6")
|
||||
m.sendRegistrationResponse(requestID, v3ResponseErrorWithMsg, "registration too short for IPv6")
|
||||
return
|
||||
}
|
||||
var addr [16]byte
|
||||
@@ -129,7 +129,7 @@ func (m *DatagramV3Muxer) handleRegistration(ctx context.Context, data []byte) {
|
||||
offset += v3IPv6AddrLen
|
||||
} else {
|
||||
if len(data) < offset+v3IPv4AddrLen {
|
||||
m.logger.Debug("V3 registration too short for IPv4")
|
||||
m.sendRegistrationResponse(requestID, v3ResponseErrorWithMsg, "registration too short for IPv4")
|
||||
return
|
||||
}
|
||||
var addr [4]byte
|
||||
|
||||
@@ -36,3 +36,29 @@ func TestDatagramV3RegistrationDestinationUnreachable(t *testing.T) {
|
||||
t.Fatalf("unexpected datagram response: %v", sender.sent[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDatagramV3RegistrationErrorWithMessage(t *testing.T) {
|
||||
sender := &captureDatagramSender{}
|
||||
inboundInstance := &Inbound{
|
||||
Adapter: inbound.NewAdapter(C.TypeCloudflareTunnel, "test"),
|
||||
flowLimiter: &FlowLimiter{},
|
||||
}
|
||||
muxer := NewDatagramV3Muxer(inboundInstance, sender, nil)
|
||||
|
||||
requestID := RequestID{}
|
||||
requestID[15] = 2
|
||||
payload := make([]byte, 1+2+2+16+1)
|
||||
payload[0] = 1
|
||||
binary.BigEndian.PutUint16(payload[1:3], 53)
|
||||
binary.BigEndian.PutUint16(payload[3:5], 30)
|
||||
copy(payload[5:21], requestID[:])
|
||||
payload[21] = 0xaa
|
||||
|
||||
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] != v3ResponseErrorWithMsg {
|
||||
t.Fatalf("unexpected datagram response: %v", sender.sent[0])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user