Skip to content

Commit

Permalink
feat: add types and de/encoding for SCMP messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mlegner committed Dec 20, 2023
1 parent 0d21eb2 commit 76d4587
Show file tree
Hide file tree
Showing 5 changed files with 878 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/scion-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod datagram;
pub mod packet;
pub mod path;
pub mod reliable;
pub mod scmp;
pub(crate) mod utils;
pub mod wire_encoding;

Expand Down
15 changes: 15 additions & 0 deletions crates/scion-proto/src/scmp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Types and conversion for the SCION Control Message Protocol.
//!
//! This implements the specification at the [SCION documentation page][scion-doc-scmp] but currently
//! does not cover DRKey-based authentication.
//!
//! [scion-doc-scmp]: https://docs.scion.org/en/latest/protocols/scmp.html

pub mod error;
pub use error::ScmpDecodeError;

pub mod messages;
pub use messages::{ScmpMessage, ScmpType};

pub mod raw;
pub use raw::ScmpMessageRaw;
24 changes: 24 additions & 0 deletions crates/scion-proto/src/scmp/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Errors encountered when handling SCMP messages.

/// Error encountered when attempting to decode an SCMP message.
#[derive(Debug, thiserror::Error)]
pub enum ScmpDecodeError {
/// The data is shorter than the minimum length of the corresponding SCMP message.
#[error("message is empty or was truncated")]
MessageEmptyOrTruncated,
/// When attempting to decode a specific message type and the data contains a different message
/// type.
#[error("the type of the message does not match the type being decoded")]
MessageTypeMismatch,
/// Informational messages of unknown types need to be dropped.
#[error("unknown info message type {0}")]
UnknownInfoMessage(u8),
/// Depending on the type of SCMP message, only specific values of the `code` field are allowed.
#[error("invalid code for this message type")]
InvalidCode,
/// When decoding a SCION packet presumably containing an SCMP message but the next-header value
/// of the SCION header doesn't match
/// [`ScmpMessageRaw::PROTOCOL_NUMBER`][super::ScmpMessageRaw::PROTOCOL_NUMBER].
#[error("next-header value of SCION header is not correct")]
WrongProtocolNumber(u8),
}
Loading

0 comments on commit 76d4587

Please sign in to comment.