TUN-6308: Add debug logs to see if packets are sent/received from edge
This commit is contained in:
parent
08a8101308
commit
baed5f4eea
|
@ -58,7 +58,7 @@ func NewQUICConnection(
|
||||||
return nil, fmt.Errorf("failed to dial to edge: %w", err)
|
return nil, fmt.Errorf("failed to dial to edge: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
datagramMuxer, err := quicpogs.NewDatagramMuxer(session)
|
datagramMuxer, err := quicpogs.NewDatagramMuxer(session, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ func (q *QUICConnection) RegisterUdpSession(ctx context.Context, sessionID uuid.
|
||||||
|
|
||||||
go q.serveUDPSession(session, closeAfterIdleHint)
|
go q.serveUDPSession(session, closeAfterIdleHint)
|
||||||
|
|
||||||
q.logger.Debug().Msgf("Registered session %v, %v, %v", sessionID, dstIP, dstPort)
|
q.logger.Debug().Str("sessionID", sessionID.String()).Str("src", originProxy.LocalAddr().String()).Str("dst", fmt.Sprintf("%s:%d", dstIP, dstPort)).Msgf("Registered session")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,16 @@ import (
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UDPProxy struct {
|
type UDPProxy interface {
|
||||||
io.ReadWriteCloser
|
io.ReadWriteCloser
|
||||||
|
LocalAddr() net.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func DialUDP(dstIP net.IP, dstPort uint16) (*UDPProxy, error) {
|
type udpProxy struct {
|
||||||
|
*net.UDPConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func DialUDP(dstIP net.IP, dstPort uint16) (UDPProxy, error) {
|
||||||
dstAddr := &net.UDPAddr{
|
dstAddr := &net.UDPAddr{
|
||||||
IP: dstIP,
|
IP: dstIP,
|
||||||
Port: int(dstPort),
|
Port: int(dstPort),
|
||||||
|
@ -23,5 +28,5 @@ func DialUDP(dstIP net.IP, dstPort uint16) (*UDPProxy, error) {
|
||||||
return nil, fmt.Errorf("unable to create UDP proxy to origin (%v:%v): %w", dstIP, dstPort, err)
|
return nil, fmt.Errorf("unable to create UDP proxy to origin (%v:%v): %w", dstIP, dstPort, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &UDPProxy{udpConn}, nil
|
return &udpProxy{udpConn}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -13,18 +14,14 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type DatagramMuxer struct {
|
type DatagramMuxer struct {
|
||||||
ID uuid.UUID
|
|
||||||
session quic.Session
|
session quic.Session
|
||||||
|
logger *zerolog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDatagramMuxer(quicSession quic.Session) (*DatagramMuxer, error) {
|
func NewDatagramMuxer(quicSession quic.Session, logger *zerolog.Logger) (*DatagramMuxer, error) {
|
||||||
muxerID, err := uuid.NewRandom()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &DatagramMuxer{
|
return &DatagramMuxer{
|
||||||
ID: muxerID,
|
|
||||||
session: quicSession,
|
session: quicSession,
|
||||||
|
logger: logger,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +39,7 @@ func (dm *DatagramMuxer) SendTo(sessionID uuid.UUID, payload []byte) error {
|
||||||
if err := dm.session.SendMessage(msgWithID); err != nil {
|
if err := dm.session.SendMessage(msgWithID); err != nil {
|
||||||
return errors.Wrap(err, "Failed to send datagram back to edge")
|
return errors.Wrap(err, "Failed to send datagram back to edge")
|
||||||
}
|
}
|
||||||
|
dm.logger.Debug().Str("sessionID", sessionID.String()).Int("bytes", len(payload)).Msg("Send datagram back to edge")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +51,12 @@ func (dm *DatagramMuxer) ReceiveFrom() (uuid.UUID, []byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return uuid.Nil, nil, err
|
return uuid.Nil, nil, err
|
||||||
}
|
}
|
||||||
return extractSessionID(msg)
|
sessionID, payload, err := extractSessionID(msg)
|
||||||
|
if err != nil {
|
||||||
|
return uuid.Nil, nil, err
|
||||||
|
}
|
||||||
|
dm.logger.Debug().Str("sessionID", sessionID.String()).Int("bytes", len(payload)).Msg("Received datagram from edge")
|
||||||
|
return sessionID, payload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maximum application payload to send to / receive from QUIC datagram frame
|
// Maximum application payload to send to / receive from QUIC datagram frame
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
@ -71,7 +72,8 @@ func TestMaxDatagramPayload(t *testing.T) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
muxer, err := NewDatagramMuxer(quicSession)
|
logger := zerolog.Nop()
|
||||||
|
muxer, err := NewDatagramMuxer(quicSession, &logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -96,7 +98,8 @@ func TestMaxDatagramPayload(t *testing.T) {
|
||||||
quicSession, err := quic.DialAddrEarly(quicListener.Addr().String(), tlsClientConfig, quicConfig)
|
quicSession, err := quic.DialAddrEarly(quicListener.Addr().String(), tlsClientConfig, quicConfig)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
muxer, err := NewDatagramMuxer(quicSession)
|
logger := zerolog.Nop()
|
||||||
|
muxer, err := NewDatagramMuxer(quicSession, &logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue