Skip to main content

scion_stack/scionstack/
scmp_handler.rs

1// Copyright 2026 Anapaya Systems
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//   http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//! SCION stack SCMP handlers.
15
16#[cfg(test)]
17use mockall::automock;
18use scion_proto::{packet::ScionPacketRaw, path::Path, scmp::ScmpErrorMessage};
19
20pub mod echo;
21pub mod error;
22
23pub use echo::DefaultEchoHandler;
24pub use error::ScmpErrorHandler;
25
26/// Trait for SCMP handlers that can process incoming raw SCION packets and optionally return a
27/// reply packet.
28/// Sending of the reply is best effort (try_send).
29pub trait ScmpHandler: Send + Sync {
30    /// Handles an incoming SCMP packet and returns a reply packet if applicable.
31    fn handle(&self, pkt: ScionPacketRaw) -> Option<ScionPacketRaw>;
32}
33
34/// Trait for reporting path issues.
35#[cfg_attr(test, automock)]
36pub trait ScmpErrorReceiver: Send + Sync {
37    /// Reports a SCMP error. This function must return immediately and not block.
38    ///
39    /// # Arguments
40    ///
41    /// * `scmp_error` - The SCMP error to report.
42    /// * `path` - The path that the SCMP error was received on (not reversed).
43    fn report_scmp_error(&self, scmp_error: ScmpErrorMessage, path: &Path);
44}
45
46// Note: `mockall` will generate `MockScmpErrorReceiver` for tests in this module.