mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 20:50:00 +00:00
TUN-6592: Decrement TTL and return ICMP time exceed if it's 0
This commit is contained in:
@@ -51,7 +51,7 @@ type QUICConnection struct {
|
||||
sessionManager datagramsession.Manager
|
||||
// datagramMuxer mux/demux datagrams from quic connection
|
||||
datagramMuxer quicpogs.BaseDatagramMuxer
|
||||
packetRouter *packetRouter
|
||||
packetRouter *packet.Router
|
||||
controlStreamHandler ControlStreamHandler
|
||||
connOptions *tunnelpogs.ConnectionOptions
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func NewQUICConnection(
|
||||
connOptions *tunnelpogs.ConnectionOptions,
|
||||
controlStreamHandler ControlStreamHandler,
|
||||
logger *zerolog.Logger,
|
||||
icmpProxy ingress.ICMPProxy,
|
||||
icmpRouter packet.ICMPRouter,
|
||||
) (*QUICConnection, error) {
|
||||
session, err := quic.DialAddr(edgeAddr.String(), tlsConfig, quicConfig)
|
||||
if err != nil {
|
||||
@@ -75,15 +75,12 @@ func NewQUICConnection(
|
||||
sessionDemuxChan := make(chan *packet.Session, demuxChanCapacity)
|
||||
var (
|
||||
datagramMuxer quicpogs.BaseDatagramMuxer
|
||||
pr *packetRouter
|
||||
pr *packet.Router
|
||||
)
|
||||
if icmpProxy != nil {
|
||||
pr = &packetRouter{
|
||||
muxer: quicpogs.NewDatagramMuxerV2(session, logger, sessionDemuxChan),
|
||||
icmpProxy: icmpProxy,
|
||||
logger: logger,
|
||||
}
|
||||
datagramMuxer = pr.muxer
|
||||
if icmpRouter != nil {
|
||||
datagramMuxerV2 := quicpogs.NewDatagramMuxerV2(session, logger, sessionDemuxChan)
|
||||
pr = packet.NewRouter(datagramMuxerV2, &returnPipe{muxer: datagramMuxerV2}, icmpRouter, logger)
|
||||
datagramMuxer = datagramMuxerV2
|
||||
} else {
|
||||
datagramMuxer = quicpogs.NewDatagramMuxer(session, logger, sessionDemuxChan)
|
||||
}
|
||||
@@ -139,7 +136,7 @@ func (q *QUICConnection) Serve(ctx context.Context) error {
|
||||
if q.packetRouter != nil {
|
||||
errGroup.Go(func() error {
|
||||
defer cancel()
|
||||
return q.packetRouter.serve(ctx)
|
||||
return q.packetRouter.Serve(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -348,50 +345,6 @@ func (q *QUICConnection) UpdateConfiguration(ctx context.Context, version int32,
|
||||
return q.orchestrator.UpdateConfig(version, config)
|
||||
}
|
||||
|
||||
type packetRouter struct {
|
||||
muxer *quicpogs.DatagramMuxerV2
|
||||
icmpProxy ingress.ICMPProxy
|
||||
logger *zerolog.Logger
|
||||
}
|
||||
|
||||
func (pr *packetRouter) serve(ctx context.Context) error {
|
||||
icmpDecoder := packet.NewICMPDecoder()
|
||||
for {
|
||||
pk, err := pr.muxer.ReceivePacket(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
icmpPacket, err := icmpDecoder.Decode(pk)
|
||||
if err != nil {
|
||||
pr.logger.Err(err).Msg("Failed to decode ICMP packet from quic datagram")
|
||||
continue
|
||||
}
|
||||
|
||||
flowPipe := muxerResponder{muxer: pr.muxer}
|
||||
if err := pr.icmpProxy.Request(icmpPacket, &flowPipe); err != nil {
|
||||
pr.logger.Err(err).
|
||||
Str("src", icmpPacket.Src.String()).
|
||||
Str("dst", icmpPacket.Dst.String()).
|
||||
Interface("type", icmpPacket.Type).
|
||||
Msg("Failed to send ICMP packet")
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// muxerResponder wraps DatagramMuxerV2 to satisfy the packet.FunnelUniPipe interface
|
||||
type muxerResponder struct {
|
||||
muxer *quicpogs.DatagramMuxerV2
|
||||
}
|
||||
|
||||
func (mr *muxerResponder) SendPacket(dst netip.Addr, pk packet.RawPacket) error {
|
||||
return mr.muxer.SendPacket(pk)
|
||||
}
|
||||
|
||||
func (mr *muxerResponder) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// streamReadWriteAcker is a light wrapper over QUIC streams with a callback to send response back to
|
||||
// the client.
|
||||
type streamReadWriteAcker struct {
|
||||
@@ -538,3 +491,16 @@ func (np *nopCloserReadWriter) Close() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// returnPipe wraps DatagramMuxerV2 to satisfy the packet.FunnelUniPipe interface
|
||||
type returnPipe struct {
|
||||
muxer *quicpogs.DatagramMuxerV2
|
||||
}
|
||||
|
||||
func (rp *returnPipe) SendPacket(dst netip.Addr, pk packet.RawPacket) error {
|
||||
return rp.muxer.SendPacket(pk)
|
||||
}
|
||||
|
||||
func (rp *returnPipe) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user