-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76962a4
commit 73b5380
Showing
11 changed files
with
112 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,6 +232,4 @@ impl From<Type> for u8 { | |
} | ||
} | ||
|
||
pub type TypeMask = u8; | ||
pub type Code = u8; | ||
pub type CodeMask = u8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// General purpose networking abstractions. | ||
#![forbid(unsafe_code)] | ||
#![deny( | ||
clippy::all, | ||
clippy::pedantic, | ||
clippy::unwrap_used, | ||
clippy::expect_used, | ||
clippy::panic | ||
)] | ||
|
||
pub mod arp; | ||
pub mod ethernet; | ||
pub mod icmpv4; | ||
pub mod icmpv6; | ||
pub mod mpls; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::convert::TryFrom; | ||
use anyhow::Error; | ||
|
||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Ord, PartialOrd, Hash)] | ||
#[repr(transparent)] | ||
pub struct Label(u32); | ||
|
||
/// Should we add handling for reserved labels as per [RFC 3032][1] (see page | ||
/// 4)? | ||
/// | ||
/// [1]: https://www.iana.org/assignments/mpls-label-values/mpls-label-values.xhtml | ||
impl Label { | ||
pub fn try_new(label: u32) -> Result<Self, Error> { | ||
if label > 0xFFFFF { | ||
Err(Error::msg("MPLS label must be less than 0xFFFFF"))?; | ||
} | ||
Ok(Self(label)) | ||
} | ||
} | ||
|
||
impl TryFrom<u32> for Label { | ||
type Error = Error; | ||
|
||
fn try_from(label: u32) -> Result<Self, Self::Error> { | ||
Self::try_new(label) | ||
} | ||
} | ||
|
||
impl From<Label> for u32 { | ||
fn from(label: Label) -> u32 { | ||
label.0 | ||
} | ||
} | ||
|
||
/// Bottom of stack flag. | ||
/// | ||
/// The "bottom of stack" flag is only a single bit wide. | ||
/// For this reason, we can get away without marking this as non-exhaustive. | ||
/// It is represented as `u8` in the netlink message. | ||
/// I take this to mean that it functions like a c boolean and that any non-zero | ||
/// value is `Set`. | ||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Ord, PartialOrd, Hash)] | ||
#[repr(u8)] | ||
pub enum BottomOfStack { | ||
Unset = 0, | ||
Set = 1, | ||
} | ||
|
||
impl From<u8> for BottomOfStack { | ||
fn from(bos: u8) -> Self { | ||
match bos { | ||
0 => BottomOfStack::Unset, | ||
1 => BottomOfStack::Set, | ||
_ => { | ||
log::warn!( | ||
"Invalid BottomOfStack value: {}, interpreting as Set", | ||
bos | ||
); | ||
BottomOfStack::Set | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<BottomOfStack> for u8 { | ||
fn from(value: BottomOfStack) -> Self { | ||
value as u8 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters