Skip to main content

scion_stack/stack/
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;
18
19pub mod echo;
20pub mod error;
21
22pub use echo::DefaultEchoHandler;
23pub(crate) use error::ScmpErrorHandler;
24use sciparse::{
25    dataplane_path::view::ScionDpPathViewRef,
26    packet::{model::ScionRawPacket, view::ScionRawPacketView},
27    payload::scmp::model::ScmpErrorMessage,
28};
29
30/// Trait for SCMP handlers that can process incoming raw SCION packets and optionally return a
31/// reply packet.
32/// Sending of the reply is best effort (`try_send`).
33pub trait ScmpHandler: Send + Sync {
34    /// Handles an incoming SCMP packet and returns a reply packet if applicable.
35    fn handle(&self, pkt: &ScionRawPacketView) -> Option<ScionRawPacket>;
36}
37
38/// Trait for reporting path issues.
39#[cfg_attr(test, automock)]
40pub trait ScmpErrorReceiver: Send + Sync {
41    /// Reports a SCMP error. This function must return immediately and not block.
42    ///
43    /// # Arguments
44    ///
45    /// * `scmp_error` - The SCMP error to report.
46    /// * `path` - The path that the SCMP error was received on (not reversed).
47    // The explicit lifetime is required by `mockall`'s `automock` code generation.
48    #[allow(clippy::needless_lifetimes, clippy::elidable_lifetime_names)]
49    fn report_scmp_error<'a>(&self, scmp_error: ScmpErrorMessage, path: ScionDpPathViewRef<'a>);
50}
51
52// Note: `mockall` will generate `MockScmpErrorReceiver` for tests in this module.