diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 42a762f14..fde9b34e9 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -4214,9 +4214,9 @@ dependencies = [ [[package]] name = "network-types" -version = "0.0.7" +version = "0.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82e9f64c09f56aa7c80c3fa087997bd99a913f91d9c74d36cf5fd75dd5773e6" +checksum = "f2df15b1cb023b9d205ae287d5dbe74510ae4d62b5131ceec516f4913ed05230" [[package]] name = "new_debug_unreachable" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index f0bfff99c..bdebdb9c2 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -102,7 +102,7 @@ lru = "0.12.5" mio = "1.0.3" moka = "0.12.10" native-dialog = "0.7.0" -network-types = "0.0.7" +network-types = "0.0.8" nix = "0.29.0" nu-ansi-term = "0.50" num_cpus = "1.16.0" diff --git a/rust/relay/ebpf-turn-router/src/channel_data.rs b/rust/relay/ebpf-turn-router/src/channel_data.rs index 3c7d61e99..71979167e 100644 --- a/rust/relay/ebpf-turn-router/src/channel_data.rs +++ b/rust/relay/ebpf-turn-router/src/channel_data.rs @@ -1,6 +1,6 @@ -use crate::{Error, ref_mut_at::ref_mut_at, udp::UdpHdr}; +use crate::{Error, ref_mut_at::ref_mut_at}; use aya_ebpf::programs::XdpContext; -use network_types::eth::EthHdr; +use network_types::{eth::EthHdr, udp::UdpHdr}; /// Represents a channel-data header within our packet. pub struct ChannelData<'a> { diff --git a/rust/relay/ebpf-turn-router/src/ip4.rs b/rust/relay/ebpf-turn-router/src/ip4.rs index e846a9288..c1e7eaf5f 100644 --- a/rust/relay/ebpf-turn-router/src/ip4.rs +++ b/rust/relay/ebpf-turn-router/src/ip4.rs @@ -3,7 +3,10 @@ use core::net::Ipv4Addr; use crate::{Error, checksum::ChecksumUpdate, ref_mut_at::ref_mut_at}; use aya_ebpf::programs::XdpContext; use aya_log_ebpf::debug; -use network_types::{eth::EthHdr, ip::IpProto}; +use network_types::{ + eth::EthHdr, + ip::{IpProto, Ipv4Hdr}, +}; /// Represents an IPv4 header within our packet. pub struct Ip4<'a> { @@ -81,51 +84,3 @@ impl<'a> Ip4<'a> { ip_pseudo_header } } - -// Copied from `network-types` but uses byte-arrays instead of `u32` and `u16` -// See . -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Ipv4Hdr { - pub version_ihl: u8, - pub tos: u8, - pub tot_len: [u8; 2], - pub id: [u8; 2], - pub frag_off: [u8; 2], - pub ttl: u8, - pub proto: IpProto, - pub check: [u8; 2], - pub src_addr: [u8; 4], - pub dst_addr: [u8; 4], -} - -impl Ipv4Hdr { - pub const LEN: usize = core::mem::size_of::(); - - pub fn ihl(&self) -> u8 { - self.version_ihl & 0b00001111 - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn ihl() { - let ipv4_hdr = Ipv4Hdr { - version_ihl: 0b0100_0101, - tos: Default::default(), - tot_len: Default::default(), - id: Default::default(), - frag_off: Default::default(), - ttl: Default::default(), - proto: IpProto::Udp, - check: Default::default(), - src_addr: Default::default(), - dst_addr: Default::default(), - }; - - assert_eq!(ipv4_hdr.ihl(), 0b0101); // The lower 4 bits of `version_ihl` are the IHL, - } -} diff --git a/rust/relay/ebpf-turn-router/src/ip6.rs b/rust/relay/ebpf-turn-router/src/ip6.rs index c65d2a7f0..80e19f6d1 100644 --- a/rust/relay/ebpf-turn-router/src/ip6.rs +++ b/rust/relay/ebpf-turn-router/src/ip6.rs @@ -3,7 +3,10 @@ use core::net::Ipv6Addr; use crate::{Error, checksum::ChecksumUpdate, ref_mut_at::ref_mut_at}; use aya_ebpf::programs::XdpContext; use aya_log_ebpf::debug; -use network_types::{eth::EthHdr, ip::IpProto}; +use network_types::{ + eth::EthHdr, + ip::{IpProto, Ipv6Hdr}, +}; /// Represents an IPv6 header within our packet. pub struct Ip6<'a> { @@ -63,16 +66,3 @@ impl<'a> Ip6<'a> { ip_pseudo_header } } - -// Copied from `network-types` but uses byte-arrays instead of `u32` and `u16` -// See . -#[repr(C)] -#[derive(Copy, Clone)] -pub struct Ipv6Hdr { - pub version_traffic_class_flow_label: [u8; 4], - pub payload_len: [u8; 2], - pub next_hdr: IpProto, - pub hop_limit: u8, - pub src_addr: [u8; 16], - pub dst_addr: [u8; 16], -} diff --git a/rust/relay/ebpf-turn-router/src/main.rs b/rust/relay/ebpf-turn-router/src/main.rs index 9b47e0790..46035d25b 100644 --- a/rust/relay/ebpf-turn-router/src/main.rs +++ b/rust/relay/ebpf-turn-router/src/main.rs @@ -13,7 +13,7 @@ use channel_data::{CdHdr, ChannelData}; use ebpf_shared::{ClientAndChannelV4, ClientAndChannelV6, PortAndPeerV4, PortAndPeerV6}; use error::{SupportedChannel, UnsupportedChannel}; use eth::Eth; -use ip4::{Ip4, Ipv4Hdr}; +use ip4::Ip4; use ip6::Ip6; use move_headers::{ add_channel_data_header_ipv4, add_channel_data_header_ipv6, remove_channel_data_header_ipv4, @@ -21,9 +21,10 @@ use move_headers::{ }; use network_types::{ eth::EtherType, - ip::{IpProto, Ipv6Hdr}, + ip::{IpProto, Ipv4Hdr, Ipv6Hdr}, + udp::UdpHdr, }; -use udp::{Udp, UdpHdr}; +use udp::Udp; mod channel_data; mod checksum; diff --git a/rust/relay/ebpf-turn-router/src/udp.rs b/rust/relay/ebpf-turn-router/src/udp.rs index 7349186d8..712058757 100644 --- a/rust/relay/ebpf-turn-router/src/udp.rs +++ b/rust/relay/ebpf-turn-router/src/udp.rs @@ -1,7 +1,7 @@ use crate::{Error, checksum::ChecksumUpdate, ref_mut_at::ref_mut_at}; use aya_ebpf::programs::XdpContext; use aya_log_ebpf::debug; -use network_types::eth::EthHdr; +use network_types::{eth::EthHdr, udp::UdpHdr}; /// Represents a UDP header within our packet. pub struct Udp<'a> { @@ -93,18 +93,3 @@ impl<'a> Udp<'a> { ); } } - -// Copied from `network-types` but uses byte-arrays instead of `u32` and `u16` -// See . -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct UdpHdr { - pub source: [u8; 2], - pub dest: [u8; 2], - pub len: [u8; 2], - pub check: [u8; 2], -} - -impl UdpHdr { - pub const LEN: usize = core::mem::size_of::(); -}