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