Skip to content

Commit

Permalink
introduce propagation stopper
Browse files Browse the repository at this point in the history
  • Loading branch information
oncilla committed Sep 6, 2023
1 parent 3867f0d commit 409e795
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 25 deletions.
50 changes: 29 additions & 21 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,21 @@ func (g *Gateway) Run(ctx context.Context) error {
return serrors.WrapStr("unable to generate TLS config", err)
}

// scionNetwork is the network for all SCION connections, with the exception of the QUIC server
// connection.
scionNetwork := &snet.SCIONNetwork{
// scionNetworkNoSCMP is the network for the QUIC server connection. Because SCMP errors
// will cause the server's accepts to fail, we ignore SCMP.
scionNetworkNoSCMP := &snet.SCIONNetwork{
LocalIA: localIA,
Dispatcher: &snet.DefaultPacketDispatcherService{
// Enable transparent reconnections to the dispatcher
Dispatcher: reconnectingDispatcher,
// Forward revocations to Daemon
SCMPHandler: snet.DefaultSCMPHandler{
RevocationHandler: revocationHandler,
SCMPErrors: g.Metrics.SCMPErrors,
// Discard all SCMP propagation, to avoid accept/read errors on the
// QUIC server/client.
SCMPHandler: snet.SCMPPropagationStopper{
Handler: snet.DefaultSCMPHandler{
RevocationHandler: revocationHandler,
SCMPErrors: g.Metrics.SCMPErrors,
},
Log: log.FromCtx(ctx).Debug,
},
SCIONPacketConnMetrics: g.Metrics.SCIONPacketConnMetrics,
},
Expand All @@ -467,7 +471,7 @@ func (g *Gateway) Run(ctx context.Context) error {

// Initialize the UDP/SCION QUIC conn for outgoing Gateway Discovery RPCs and outgoing Prefix
// Fetching. Open up a random high port for this.
clientConn, err := scionNetwork.Listen(
clientConn, err := scionNetworkNoSCMP.Listen(
context.TODO(),
"udp",
&net.UDPAddr{IP: g.ControlClientIP},
Expand Down Expand Up @@ -511,6 +515,23 @@ func (g *Gateway) Run(ctx context.Context) error {
"remote_isd_as", ia.String())
}
}

// scionNetwork is the network for all SCION connections, with the exception of the QUIC server
// and client connection.
scionNetwork := &snet.SCIONNetwork{
LocalIA: localIA,
Dispatcher: &snet.DefaultPacketDispatcherService{
// Enable transparent reconnections to the dispatcher
Dispatcher: reconnectingDispatcher,
// Forward revocations to Daemon
SCMPHandler: snet.DefaultSCMPHandler{
RevocationHandler: revocationHandler,
SCMPErrors: g.Metrics.SCMPErrors,
},
SCIONPacketConnMetrics: g.Metrics.SCIONPacketConnMetrics,
},
Metrics: g.Metrics.SCIONNetworkMetrics,
}
remoteMonitor := &control.RemoteMonitor{
IAs: remoteIAsChannel,
RemotesMonitored: rmMetric,
Expand Down Expand Up @@ -550,19 +571,6 @@ func (g *Gateway) Run(ctx context.Context) error {
}()
logger.Debug("Remote monitor started.")

// scionNetworkNoSCMP is the network for the QUIC server connection. Because SCMP errors
// will cause the server's accepts to fail, we ignore SCMP.
scionNetworkNoSCMP := &snet.SCIONNetwork{
LocalIA: localIA,
Dispatcher: &snet.DefaultPacketDispatcherService{
// Enable transparent reconnections to the dispatcher
Dispatcher: reconnectingDispatcher,
// Discard all SCMP, to avoid accept errors on the QUIC server.
SCMPHandler: ignoreSCMP{},
SCIONPacketConnMetrics: g.Metrics.SCIONPacketConnMetrics,
},
Metrics: g.Metrics.SCIONNetworkMetrics,
}
serverConn, err := scionNetworkNoSCMP.Listen(
context.TODO(),
"udp",
Expand Down
21 changes: 21 additions & 0 deletions pkg/snet/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,24 @@ func (h *DefaultSCMPHandler) handleSCMPRev(typeCode slayers.SCMPTypeCode,
}
return &OpError{typeCode: typeCode, revInfo: revInfo}
}

// SCMPPropagationStopper wraps an SCMP handler and stops propagation of the
// SCMP errors up the stack. This can be necessary if the client code aborts on
// unexpected errors. This is a temporary solution until we address
// https://github.com/scionproto/scion/issues/4389.
//
// EXPERIMENTAL: This handler is experimental and may be removed in the future.
type SCMPPropagationStopper struct {
// Handler is the wrapped handler.
Handler SCMPHandler
// Log is an optional function that is called when the wrapped handler
// returns an error and propagation is stopped.
Log func(msg string, ctx ...any)
}

func (h SCMPPropagationStopper) Handle(pkt *Packet) error {
if err := h.Handler.Handle(pkt); err != nil && h.Log != nil {
h.Log("Stopped SCMP error propagation", "err", err)
}
return nil
}
6 changes: 6 additions & 0 deletions pkg/snet/squic/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ type ConnDialer struct {
// Conn is the transport to initiate QUIC Sessions on. It can be shared
// between clients and servers, because QUIC connection IDs are used to
// demux the packets.
//
// Note: When creating the transport, ensure that the SCMP errors are not
// propagated. You can for example use
// [github.com/scionproto/scion/pkg/snet.SCMPPropagationStopper]. Otherwise,
// the QUIC transport will close the listening side on SCMP errors and enter
// a broken state.
Transport *quic.Transport
// TLSConfig is the client's TLS configuration for starting QUIC connections.
TLSConfig *tls.Config
Expand Down
9 changes: 7 additions & 2 deletions private/app/appnet/infraenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,13 @@ func (nc *NetworkConfig) initQUICSockets() (net.PacketConn, net.PacketConn, erro
clientNet := &snet.SCIONNetwork{
LocalIA: nc.IA,
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: dispatcherService,
SCMPHandler: nc.SCMPHandler,
Dispatcher: dispatcherService,
// Discard all SCMP propagation, to avoid read errors on the QUIC
// client.
SCMPHandler: snet.SCMPPropagationStopper{
Handler: nc.SCMPHandler,
Log: log.Debug,
},
SCIONPacketConnMetrics: nc.SCIONPacketConnMetrics,
},
Metrics: nc.SCIONNetworkMetrics,
Expand Down
7 changes: 5 additions & 2 deletions scion-pki/certs/renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,11 @@ func (r *renewer) requestRemote(
LocalIA: local.IA,
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: reliable.NewDispatcher(r.Disatcher),
SCMPHandler: snet.DefaultSCMPHandler{
RevocationHandler: daemon.RevHandler{Connector: r.Daemon},
SCMPHandler: snet.SCMPPropagationStopper{
Handler: snet.DefaultSCMPHandler{
RevocationHandler: daemon.RevHandler{Connector: r.Daemon},
},
Log: log.FromCtx(ctx).Debug,
},
},
}
Expand Down

0 comments on commit 409e795

Please sign in to comment.