Skip to content

Commit

Permalink
use the cmsg storage for socket v1
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Jun 14, 2023
1 parent d699033 commit 960cdbb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,7 @@ jobs:
! grep -q '[^[:space:]]' /tmp/typos.json
kani:
# Some of the kani proofs use quite a bit of memory so we need larger instances
# https://docs.github.com/en/actions/using-github-hosted-runners/using-larger-runners#machine-specs-for-larger-runners
runs-on: ubuntu-latest-8-cores
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion quic/s2n-quic-platform/src/message/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub type UdpGro = libc::c_int;
pub type IpTos = libc::c_int;

#[repr(align(8))] // the storage needs to be aligned to the same as `cmsghdr`
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct Storage([u8; MAX_LEN]);

impl Default for Storage {
Expand Down
11 changes: 4 additions & 7 deletions quic/s2n-quic-platform/src/message/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ pub struct Storage<Payloads> {

// this field holds references to allocated msg_names, but is never read directly
#[allow(dead_code)]
pub(crate) cmsgs: Pin<Box<[u8]>>,
pub(crate) cmsgs: Pin<Box<[cmsg::Storage]>>,

/// The maximum payload for any given message
mtu: usize,
Expand Down Expand Up @@ -434,19 +434,16 @@ impl<Payloads: crate::buffer::Buffer> Ring<Payloads> {
let mut payloads = Pin::new(payloads);
let mut iovecs = Pin::new(vec![unsafe { zeroed() }; capacity].into_boxed_slice());
let mut msg_names = Pin::new(vec![unsafe { zeroed() }; capacity].into_boxed_slice());
let mut cmsgs = Pin::new(vec![0u8; capacity * cmsg::MAX_LEN].into_boxed_slice());
let mut cmsgs = Pin::new(vec![cmsg::Storage::default(); capacity].into_boxed_slice());

// double message capacity to enable contiguous access
let mut messages = Vec::with_capacity(capacity * 2);

let mut payload_buf = &mut payloads.as_mut()[..];
let mut cmsg_buf = &mut cmsgs.as_mut()[..];

for index in 0..capacity {
let (payload, remaining) = payload_buf.split_at_mut(mtu * max_gso);
payload_buf = remaining;
let (cmsg, remaining) = cmsg_buf.split_at_mut(cmsg::MAX_LEN);
cmsg_buf = remaining;

let mut iovec = unsafe { zeroed::<iovec>() };
iovec.iov_base = payload.as_mut_ptr() as _;
Expand All @@ -457,8 +454,8 @@ impl<Payloads: crate::buffer::Buffer> Ring<Payloads> {
(&mut iovecs[index]) as *mut _,
(&mut msg_names[index]) as *mut _ as *mut _,
size_of::<sockaddr_in6>(),
cmsg as *mut _ as *mut _,
cmsg::MAX_LEN,
cmsgs[index].as_mut_ptr() as *mut _,
cmsgs[index].len(),
);

messages.push(msg);
Expand Down
2 changes: 2 additions & 0 deletions quic/s2n-quic-platform/src/socket/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ mod tests {
($name:ident, $msg:ty) => {
#[test]
#[cfg_attr(kani, kani::proof, kani::solver(cadical), kani::unwind(3))]
#[cfg(any(not(kani), kani_slow))] // this test takes too much memory for our CI
// environment
fn $name() {
check!().with_type::<Counts>().for_each(|counts| {
let entries = if cfg!(kani) { 2 } else { 16 };
Expand Down

0 comments on commit 960cdbb

Please sign in to comment.