Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump pcap to address TODO comment in split tunnel implementation #6685

Merged
merged 3 commits into from
Aug 28, 2024
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion talpid-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ system-configuration = "0.5.1"
hickory-proto = "0.24.1"
hickory-server = { version = "0.24.1", features = ["resolver"] }
talpid-platform-metadata = { path = "../talpid-platform-metadata" }
pcap = { version = "2.0", features = ["capture-stream"] }
pcap = { version = "2.1", features = ["capture-stream"] }
pnet_packet = "0.34"
tun = { version = "0.5.5", features = ["async"] }
nix = { version = "0.28", features = ["socket"] }
Expand Down
324 changes: 53 additions & 271 deletions talpid-core/src/split_tunnel/macos/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// automatically generated by rust-bindgen 0.69.2
/* automatically generated by rust-bindgen 0.70.1 */

pub const PTH_FLAG_DIR_OUT: u32 = 2;
pub const PCAP_ERRBUF_SIZE: u32 = 256;
pub type __int32_t = ::std::os::raw::c_int;
pub type __darwin_pid_t = __int32_t;
pub type __darwin_uuid_t = [::std::os::raw::c_uchar; 16usize];
Expand All @@ -12,41 +11,13 @@ pub struct timeval32 {
pub tv_sec: __int32_t,
pub tv_usec: __int32_t,
}
#[test]
fn bindgen_test_layout_timeval32() {
const UNINIT: ::std::mem::MaybeUninit<timeval32> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<timeval32>(),
8usize,
concat!("Size of: ", stringify!(timeval32))
);
assert_eq!(
::std::mem::align_of::<timeval32>(),
4usize,
concat!("Alignment of ", stringify!(timeval32))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(timeval32),
"::",
stringify!(tv_sec)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).tv_usec) as usize - ptr as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(timeval32),
"::",
stringify!(tv_usec)
)
);
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of timeval32"][::std::mem::size_of::<timeval32>() - 8usize];
["Alignment of timeval32"][::std::mem::align_of::<timeval32>() - 4usize];
["Offset of field: timeval32::tv_sec"][::std::mem::offset_of!(timeval32, tv_sec) - 0usize];
["Offset of field: timeval32::tv_usec"][::std::mem::offset_of!(timeval32, tv_usec) - 4usize];
};
pub type uuid_t = __darwin_uuid_t;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand All @@ -72,237 +43,48 @@ pub struct pktap_header {
pub pth_uuid: uuid_t,
pub pth_euuid: uuid_t,
}
#[test]
fn bindgen_test_layout_pktap_header() {
const UNINIT: ::std::mem::MaybeUninit<pktap_header> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<pktap_header>(),
156usize,
concat!("Size of: ", stringify!(pktap_header))
);
assert_eq!(
::std::mem::align_of::<pktap_header>(),
4usize,
concat!("Alignment of ", stringify!(pktap_header))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_length) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_length)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_type_next) as usize - ptr as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_type_next)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_dlt) as usize - ptr as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_dlt)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_ifname) as usize - ptr as usize },
12usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_ifname)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_flags) as usize - ptr as usize },
36usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_flags)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_protocol_family) as usize - ptr as usize },
40usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_protocol_family)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_frame_pre_length) as usize - ptr as usize },
44usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_frame_pre_length)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_frame_post_length) as usize - ptr as usize },
48usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_frame_post_length)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_pid) as usize - ptr as usize },
52usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_pid)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_comm) as usize - ptr as usize },
56usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_comm)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_svc) as usize - ptr as usize },
76usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_svc)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_iftype) as usize - ptr as usize },
80usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_iftype)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_ifunit) as usize - ptr as usize },
82usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_ifunit)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_epid) as usize - ptr as usize },
84usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_epid)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_ecomm) as usize - ptr as usize },
88usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_ecomm)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_flowid) as usize - ptr as usize },
108usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_flowid)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_ipproto) as usize - ptr as usize },
112usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_ipproto)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_tstamp) as usize - ptr as usize },
116usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_tstamp)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_uuid) as usize - ptr as usize },
124usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_uuid)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).pth_euuid) as usize - ptr as usize },
140usize,
concat!(
"Offset of field: ",
stringify!(pktap_header),
"::",
stringify!(pth_euuid)
)
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct pcap {
_unused: [u8; 0],
}
pub type pcap_t = pcap;
extern "C" {
pub fn pcap_create(
arg1: *const ::std::os::raw::c_char,
arg2: *mut ::std::os::raw::c_char,
) -> *mut pcap_t;
}
extern "C" {
pub fn pcap_set_want_pktap(
arg1: *mut pcap_t,
arg2: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
}
pub const BIOCSWANTPKTAP: u64 = 3221504639;
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of pktap_header"][::std::mem::size_of::<pktap_header>() - 156usize];
["Alignment of pktap_header"][::std::mem::align_of::<pktap_header>() - 4usize];
["Offset of field: pktap_header::pth_length"]
[::std::mem::offset_of!(pktap_header, pth_length) - 0usize];
["Offset of field: pktap_header::pth_type_next"]
[::std::mem::offset_of!(pktap_header, pth_type_next) - 4usize];
["Offset of field: pktap_header::pth_dlt"]
[::std::mem::offset_of!(pktap_header, pth_dlt) - 8usize];
["Offset of field: pktap_header::pth_ifname"]
[::std::mem::offset_of!(pktap_header, pth_ifname) - 12usize];
["Offset of field: pktap_header::pth_flags"]
[::std::mem::offset_of!(pktap_header, pth_flags) - 36usize];
["Offset of field: pktap_header::pth_protocol_family"]
[::std::mem::offset_of!(pktap_header, pth_protocol_family) - 40usize];
["Offset of field: pktap_header::pth_frame_pre_length"]
[::std::mem::offset_of!(pktap_header, pth_frame_pre_length) - 44usize];
["Offset of field: pktap_header::pth_frame_post_length"]
[::std::mem::offset_of!(pktap_header, pth_frame_post_length) - 48usize];
["Offset of field: pktap_header::pth_pid"]
[::std::mem::offset_of!(pktap_header, pth_pid) - 52usize];
["Offset of field: pktap_header::pth_comm"]
[::std::mem::offset_of!(pktap_header, pth_comm) - 56usize];
["Offset of field: pktap_header::pth_svc"]
[::std::mem::offset_of!(pktap_header, pth_svc) - 76usize];
["Offset of field: pktap_header::pth_iftype"]
[::std::mem::offset_of!(pktap_header, pth_iftype) - 80usize];
["Offset of field: pktap_header::pth_ifunit"]
[::std::mem::offset_of!(pktap_header, pth_ifunit) - 82usize];
["Offset of field: pktap_header::pth_epid"]
[::std::mem::offset_of!(pktap_header, pth_epid) - 84usize];
["Offset of field: pktap_header::pth_ecomm"]
[::std::mem::offset_of!(pktap_header, pth_ecomm) - 88usize];
["Offset of field: pktap_header::pth_flowid"]
[::std::mem::offset_of!(pktap_header, pth_flowid) - 108usize];
["Offset of field: pktap_header::pth_ipproto"]
[::std::mem::offset_of!(pktap_header, pth_ipproto) - 112usize];
["Offset of field: pktap_header::pth_tstamp"]
[::std::mem::offset_of!(pktap_header, pth_tstamp) - 116usize];
["Offset of field: pktap_header::pth_uuid"]
[::std::mem::offset_of!(pktap_header, pth_uuid) - 124usize];
["Offset of field: pktap_header::pth_euuid"]
[::std::mem::offset_of!(pktap_header, pth_euuid) - 140usize];
};
8 changes: 0 additions & 8 deletions talpid-core/src/split_tunnel/macos/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use std::{
};
use tokio::io::{unix::AsyncFd, AsyncRead, Interest, ReadBuf};

use super::bindings::BIOCSWANTPKTAP;

#[derive(thiserror::Error, Debug)]
pub enum Error {
/// Failed to open BPF device
Expand Down Expand Up @@ -167,12 +165,6 @@ impl Bpf {
unsafe { ioctl!(self.file.as_raw_fd(), BIOCSHDRCMPLT, &enable) }
}

pub fn set_want_pktap(&self, enable: bool) -> Result<(), Error> {
let enable: c_int = if enable { 1 } else { 0 };
// SAFETY: The fd is valid for the lifetime of `self`
unsafe { ioctl!(self.file.as_raw_fd(), BIOCSWANTPKTAP, &enable) }
}

pub fn set_buffer_size(&self, mut buffer_size: c_uint) -> Result<usize, Error> {
// SAFETY: The fd is valid for the lifetime of `self`
unsafe {
Expand Down
4 changes: 0 additions & 4 deletions talpid-core/src/split_tunnel/macos/generate-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ curl https://opensource.apple.com/source/libpcap/libpcap-67/libpcap/pcap/pcap.h
curl https://opensource.apple.com/source/xnu/xnu-3789.41.3/bsd/net/bpf.h -o include/bpf.h

bindgen "include/bindings.h" -o ./bindings.rs \
--allowlist-item "^pcap_create" \
--allowlist-item "^pcap_set_want_pktap" \
--allowlist-item "^pktap_header" \
--allowlist-item "PCAP_ERRBUF_SIZE" \
--allowlist-item "^BIOCSWANTPKTAP" \
--allowlist-item "^PTH_FLAG_DIR_OUT"
Loading
Loading