#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u16)]
pub enum IpProtocol
{
V4 = ::dpdk_sys::ETHER_TYPE_IPv4,
V6 = ::dpdk_sys::ETHER_TYPE_IPv6,
}
impl IpProtocol
{
#[inline(always)]
pub fn asEtherTypeBigEndian(self) -> u16
{
(self as u16).to_be()
}
#[inline(always)]
pub fn writeLayer3Header(self, buffer: *mut u8, differentiatedServiceCodePoint: DifferentiatedServiceCodePoint, hopLimits: u8, layer4Protocol: Layer4Protocol) -> (usize, usize)
{
match self
{
IpProtocol::V4 =>
{
const Version: u8 = 4 << 4;
let IpHeaderLengthIn32BitWordsAssumingNoOptions = (size_of::<ipv4_hdr>() as u8 / ::dpdk_sys::IPV4_IHL_MULTIPLIER) as u8;
let trafficClass = TrafficClass
{
differentiatedServiceCodePoint: differentiatedServiceCodePoint,
explicitCongestionNotification: ExplicitCongestionNotification::NotCapableTransport,
};
let mut header = unsafe { *(buffer as *mut ipv4_hdr) };
header.version_ihl = Version | IpHeaderLengthIn32BitWordsAssumingNoOptions;
header.type_of_service = trafficClass.as_u8();
header.fragment_offset = 0;
header.time_to_live = hopLimits;
header.next_proto_id = layer4Protocol.libcValue();
header.hdr_checksum = 0;
const TrailingAddressBytesLength: usize = SizeOfIpV4HostAddress * 2;
(size_of::<ipv4_hdr>(), TrailingAddressBytesLength)
},
IpProtocol::V6 =>
{
const Version: u32 = 6 << 24;
let trafficClass = TrafficClass
{
differentiatedServiceCodePoint: differentiatedServiceCodePoint,
explicitCongestionNotification: ExplicitCongestionNotification::NotCapableTransport,
};
const FlowLabel: u32 = 0;
let mut header = unsafe { *(buffer as *mut ipv6_hdr) };
header.vtc_flow = (Version | (trafficClass.as_u8() as u32) << 20 | FlowLabel).to_be();
header.proto = layer4Protocol.libcValue();
header.hop_limits = hopLimits;
const TrailingAddressBytesLength: usize = SizeOfIpV6HostAddress * 2;
(size_of::<ipv6_hdr>(), TrailingAddressBytesLength)
},
}
}
}