diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-09-07 18:38:19 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-09-07 18:38:19 +0200 |
commit | 7b61ee4c2db87e195f5291fb1a3927648d38a2a4 (patch) | |
tree | 410c0609c3f4d1afbd0d87791b9156a538f59398 /src/router/ip.rs | |
parent | Added outbound benchmark (diff) | |
download | wireguard-rs-7b61ee4c2db87e195f5291fb1a3927648d38a2a4.tar.xz wireguard-rs-7b61ee4c2db87e195f5291fb1a3927648d38a2a4.zip |
Write inbound packets to TUN device
Diffstat (limited to 'src/router/ip.rs')
-rw-r--r-- | src/router/ip.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/router/ip.rs b/src/router/ip.rs new file mode 100644 index 0000000..6eb303c --- /dev/null +++ b/src/router/ip.rs @@ -0,0 +1,37 @@ +use byteorder::BigEndian; +use zerocopy::byteorder::U16; +use zerocopy::{AsBytes, ByteSlice, FromBytes, LayoutVerified}; + +pub const SIZE_IP4_HEADER: usize = 16; +pub const SIZE_IP6_HEADER: usize = 36; + +pub const VERSION_IP4: u8 = 4; +pub const VERSION_IP6: u8 = 6; + +pub const OFFSET_IP4_SRC: usize = 12; +pub const OFFSET_IP6_SRC: usize = 8; + +pub const OFFSET_IP4_DST: usize = 16; +pub const OFFSET_IP6_DST: usize = 24; + +pub const TYPE_TRANSPORT: u8 = 4; + +#[repr(packed)] +#[derive(Copy, Clone, FromBytes, AsBytes)] +pub struct IPv4Header { + _f_space1: [u8; 2], + pub f_total_len: U16<BigEndian>, + _f_space2: [u8; 8], + pub f_source: [u8; 4], + pub f_destination: [u8; 4], +} + +#[repr(packed)] +#[derive(Copy, Clone, FromBytes, AsBytes)] +pub struct IPv6Header { + _f_pre: [u8; 4], + pub f_len: U16<BigEndian>, + _f_space2: [u8; 2], + pub f_source: [u8; 16], + pub f_destination: [u8; 16], +} |