-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
da41c76
commit 18126ef
Showing
13 changed files
with
1,175 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::tracing::constants::{MAX_EXTENSIONS_PER_PROBE, MAX_MPLS_MEMBERS_PER_STACK}; | ||
use crate::tracing::error::TracerError; | ||
use crate::tracing::packet::icmp_extension::extension_object::ClassNum; | ||
use crate::tracing::packet::icmp_extension::extension_structure::ExtensionStructure; | ||
use crate::tracing::packet::icmp_extension::mpls_label_stack::MplsLabelStack; | ||
use crate::tracing::packet::icmp_extension::mpls_label_stack_member::MplsLabelStackMember; | ||
use crate::tracing::probe::{ | ||
MplsExtensionData, MplsExtensionMember, ProbeResponseExtension, ProbeResponseExtensions, | ||
}; | ||
use crate::tracing::util::Required; | ||
|
||
impl TryFrom<&[u8]> for ProbeResponseExtensions { | ||
type Error = TracerError; | ||
|
||
fn try_from(value: &[u8]) -> Result<Self, Self::Error> { | ||
Self::try_from(ExtensionStructure::new_view(value).req()?) | ||
} | ||
} | ||
|
||
impl TryFrom<ExtensionStructure<'_>> for ProbeResponseExtensions { | ||
type Error = TracerError; | ||
|
||
fn try_from(value: ExtensionStructure<'_>) -> Result<Self, Self::Error> { | ||
let extensions = value | ||
.objects() | ||
.take(MAX_EXTENSIONS_PER_PROBE) | ||
.map(|obj| match obj.get_class_num() { | ||
ClassNum::MultiProtocolLabelSwitchingLabelStack => { | ||
MplsLabelStack::new_view(obj.payload()) | ||
.req() | ||
.map(|mpls| ProbeResponseExtension::Mpls(MplsExtensionData::from(mpls))) | ||
} | ||
_ => Ok(ProbeResponseExtension::Unknown), | ||
}) | ||
.collect::<Result<_, _>>()?; | ||
Ok(Self { extensions }) | ||
} | ||
} | ||
|
||
impl From<MplsLabelStack<'_>> for MplsExtensionData { | ||
fn from(value: MplsLabelStack<'_>) -> Self { | ||
Self { | ||
members: value | ||
.members() | ||
.take(MAX_MPLS_MEMBERS_PER_STACK) | ||
.map(MplsExtensionMember::from) | ||
.collect(), | ||
} | ||
} | ||
} | ||
|
||
impl From<MplsLabelStackMember<'_>> for MplsExtensionMember { | ||
fn from(value: MplsLabelStackMember<'_>) -> Self { | ||
Self { | ||
label: value.get_label(), | ||
exp: value.get_exp(), | ||
bos: value.get_bos(), | ||
ttl: value.get_ttl(), | ||
} | ||
} | ||
} |
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
Oops, something went wrong.