Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@ jobs:
use-cross: true
command: test
args: --target ${{ matrix.target }} --no-default-features

- name: cargo build serde
if: matrix.target == ''
uses: actions-rs/cargo@v1
with:
command: build
args: --features serde

- name: cross build serde
if: matrix.target != ''
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --target ${{ matrix.target }} --features serde

- name: cargo test serde
if: matrix.target == ''
uses: actions-rs/cargo@v1
with:
command: test
args: --features serde

- name: cross test serde
if: matrix.target != ''
uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --target ${{ matrix.target }} --features serde

no_std_build:
name: no_std build
Expand All @@ -129,4 +159,4 @@ jobs:
toolchain: stable
target: x86_64-unknown-none
override: true
- run: cargo build --target x86_64-unknown-none
- run: cargo build --target x86_64-unknown-none
7 changes: 5 additions & 2 deletions etherparse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ exclude = [
]

[features]
default = ["std"]
std = ["arrayvec/std"]
default = ["std", "serde"]
std = []
serde = ["dep:serde", "dep:serde_arrays"]

[dependencies]
arrayvec = { version = "0.7.2", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_arrays = { version = "0.1", optional = true }

[dev-dependencies]
proptest = "1.4.0"
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/len_source.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Sources of length limiting values (e.g. "ipv6 payload length field").
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum LenSource {
/// Limiting length was the slice length (we don't know what determined
/// that one originally).
Expand Down
10 changes: 10 additions & 0 deletions etherparse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,19 @@ pub use crate::packet_builder::*;
mod packet_headers;
pub use crate::packet_headers::*;

#[cfg(feature = "std")]
mod packet;
#[cfg(feature = "std")]
pub use crate::packet::*;

mod payload_slice;
pub use crate::payload_slice::*;

#[cfg(feature = "std")]
mod payload;
#[cfg(feature = "std")]
pub use crate::payload::*;

mod sliced_packet;
pub use crate::sliced_packet::*;

Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/arp_hardware_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
///

#[derive(Clone, Copy, Eq, PartialEq, Default, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ArpHardwareId(pub u16);

impl ArpHardwareId {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/double_vlan_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// IEEE 802.1Q double VLAN Tagging Header
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DoubleVlanHeader {
/// The outer vlan tagging header
pub outer: SingleVlanHeader,
Expand Down
22 changes: 22 additions & 0 deletions etherparse/src/link/ether_payload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::vec::Vec;

use crate::{EtherPayloadSlice, EtherType};

/// Payload of an IP packet. Owned version of [`EtherPayloadSlice`].
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EtherPayload {
/// Identifying content of the payload.
pub ether_type: EtherType,
/// Payload
pub payload: Vec<u8>,
}

impl<'a> From<EtherPayloadSlice<'a>> for EtherPayload {
fn from(slice: EtherPayloadSlice<'a>) -> Self {
Self {
ether_type: slice.ether_type,
payload: slice.payload.to_vec(),
}
}
}
1 change: 1 addition & 0 deletions etherparse/src/link/ether_payload_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// Payload of an IP packet.
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EtherPayloadSlice<'a> {
/// Identifying content of the payload.
pub ether_type: EtherType,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/ether_type_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
/// ```
///
#[derive(Default, PartialEq, Eq, Clone, Copy, Hash, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EtherType(pub u16);

impl EtherType {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/ethernet2_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{err::Layer, err::SliceWriteSpaceError, *};

/// Ethernet II header.
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ethernet2Header {
/// Source MAC Address
pub source: [u8; 6],
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/link_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{Ethernet2Header, LinuxSllHeader};

/// The possible headers on the link layer
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum LinkHeader {
LinuxSll(LinuxSllHeader),
Ethernet2(Ethernet2Header),
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/linux_nonstandard_ether_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/// assert_eq!(0x0001, num);
/// ```
#[derive(Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LinuxNonstandardEtherType(pub(crate) u16);

impl LinuxNonstandardEtherType {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/linux_sll_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{err, ArpHardwareId, LinuxSllHeaderSlice, LinuxSllPacketType, LinuxSl

/// Linux Cooked Capture v1 (SLL) Header
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LinuxSllHeader {
/// Type of the captured packet
pub packet_type: LinuxSllPacketType,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/linux_sll_packet_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::err::{self};
/// assert_eq!(1, num);
/// ```
#[derive(Clone, Copy, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LinuxSllPacketType(u16);

impl LinuxSllPacketType {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/linux_sll_protocol_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{err, ArpHardwareId, EtherType, LinuxNonstandardEtherType};
/// assert_eq!(0x0001, num);
/// ```
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum LinuxSllProtocolType {
/// The protocol type should be ignored
Ignored(u16),
Expand Down
3 changes: 3 additions & 0 deletions etherparse/src/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ pub mod vlan_header;
pub mod vlan_id;
pub mod vlan_pcp;
pub mod vlan_slice;

#[cfg(feature = "std")]
pub mod ether_payload;
1 change: 1 addition & 0 deletions etherparse/src/link/single_vlan_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// IEEE 802.1Q VLAN Tagging Header
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SingleVlanHeader {
/// A 3 bit number which refers to the IEEE 802.1p class of service and maps to the frame priority level.
pub pcp: VlanPcp,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/vlan_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// IEEE 802.1Q VLAN Tagging Header (can be single or double tagged).
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum VlanHeader {
/// IEEE 802.1Q VLAN Tagging Header
Single(SingleVlanHeader),
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/vlan_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::err::ValueTooBigError;
/// 12 bit unsigned integer containing the "VLAN identifier" (present
/// in the [`crate::SingleVlanHeader`]).
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct VlanId(u16);

impl VlanId {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/vlan_pcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::err::ValueTooBigError;
/// Refers to the IEEE 802.1p class of service and maps to the
/// frame priority level.
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct VlanPcp(u8);

impl VlanPcp {
Expand Down
2 changes: 2 additions & 0 deletions etherparse/src/net/ip_auth_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub type IpAuthenticationHeader = IpAuthHeader;

/// IP Authentication Header (rfc4302)
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IpAuthHeader {
/// IP protocol number specifying the next header or transport layer protocol.
///
Expand All @@ -28,6 +29,7 @@ pub struct IpAuthHeader {
raw_icv_len: u8,
/// Buffer containing the "Encoded Integrity Check Value-ICV" (variable).
/// The length of the used data can be set via the `variable` (must be a multiple of 4 bytes).
#[cfg_attr(feature = "serde", serde(with = "serde_arrays"))]
raw_icv_buffer: [u8; 0xfe * 4],
}

Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ip_frag_offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use crate::err::ValueTooBigError;
/// }
/// ```
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IpFragOffset(u16);

impl IpFragOffset {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ip_number_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub type IpTrafficClass = IpNumber;
/// The list original values were copied from
/// <https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml>
#[derive(PartialEq, Eq, Clone, Copy, Hash, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IpNumber(pub u8);

impl IpNumber {
Expand Down
36 changes: 36 additions & 0 deletions etherparse/src/net/ip_payload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::vec::Vec;

use crate::{IpNumber, IpPayloadSlice, LenSource};

/// Payload of an IP packet. Owned version of [`IpPayloadSlice`].
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IpPayload {
/// Identifying content of the payload.
pub ip_number: IpNumber,

/// True if the payload is not complete and has been fragmented.
///
/// This can occur if the IPv4 incdicates that the payload
/// has been fragmented or if there is an IPv6 fragmentation
/// header indicating that the payload has been fragmented.
pub fragmented: bool,

/// Length field that was used to determine the length
/// of the payload (e.g. IPv6 "payload_length" field).
pub len_source: LenSource,

/// Payload
pub payload: Vec<u8>,
}

impl<'a> From<IpPayloadSlice<'a>> for IpPayload {
fn from(slice: IpPayloadSlice<'a>) -> Self {
Self {
ip_number: slice.ip_number,
fragmented: slice.fragmented,
len_source: slice.len_source,
payload: slice.payload.to_vec(),
}
}
}
1 change: 1 addition & 0 deletions etherparse/src/net/ip_payload_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// Payload of an IP packet.
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IpPayloadSlice<'a> {
/// Identifying content of the payload.
pub ip_number: IpNumber,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ipv4_dscp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::err::ValueTooBigError;
/// 6 bit unsigned integer containing the "Differentiated Services
/// Code Point" (present in the [`crate::Ipv4Header`]).
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv4Dscp(u8);

impl Ipv4Dscp {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ipv4_ecn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::err::ValueTooBigError;
/// 2 bit unsigned integer containing the "Explicit Congestion
/// Notification" (present in the [`crate::Ipv4Header`]).
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv4Ecn(u8);

impl Ipv4Ecn {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ipv4_exts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{err::ipv4_exts::ExtsWalkError, *};
/// Currently not supported:
/// - Encapsulating Security Payload Header (ESP)
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv4Extensions {
pub auth: Option<IpAuthHeader>,
}
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ipv4_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use arrayvec::ArrayVec;
/// assert_eq!(slice_rest, &[]);
/// ```
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv4Header {
/// Differentiated Services Code Point
pub dscp: Ipv4Dscp,
Expand Down
2 changes: 2 additions & 0 deletions etherparse/src/net/ipv4_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ use core::borrow::{Borrow, BorrowMut};
/// }
/// ```
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv4Options {
pub(crate) len: u8,
#[cfg_attr(feature = "serde", serde(with = "serde_arrays"))]
pub(crate) buf: [u8; 40],
}

Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ipv6_exts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
/// * IP Mobility
/// * Site Multihoming by IPv6 Intermediation (SHIM6)
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6Extensions {
pub hop_by_hop_options: Option<Ipv6RawExtHeader>,
pub destination_options: Option<Ipv6RawExtHeader>,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ipv6_flow_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use crate::err::ValueTooBigError;
/// }
/// ```
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6FlowLabel(u32);

impl Ipv6FlowLabel {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ipv6_fragment_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::super::*;

/// IPv6 fragment header.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6FragmentHeader {
/// IP protocol number specifying the next header or transport layer protocol.
///
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/net/ipv6_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{err::ValueTooBigError, *};

/// IPv6 header according to rfc8200.
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6Header {
pub traffic_class: u8,
/// If non 0 serves as a hint to router and switches with multiple outbound paths that these packets should stay on the same path, so that they will not be reordered.
Expand Down
2 changes: 2 additions & 0 deletions etherparse/src/net/ipv6_raw_ext_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub type Ipv6RawExtensionHeader = Ipv6RawExtHeader;
/// * Host Identity Protocol
/// * Shim6 Protocol
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6RawExtHeader {
/// IP protocol number specifying the next header or transport layer protocol.
///
Expand All @@ -33,6 +34,7 @@ pub struct Ipv6RawExtHeader {
/// Length of the extension header in 8 octets (minus the first 8 octets).
header_length: u8,
//// The data contained in the extension header (excluding next_header & hdr length).
#[cfg_attr(feature = "serde", serde(with = "serde_arrays"))]
payload_buffer: [u8; 0xff * 8 + 6],
}

Expand Down
Loading