summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--talpid-core/src/split_tunnel/macos/bindings.rs306
-rw-r--r--talpid-core/src/split_tunnel/macos/bpf.rs8
-rwxr-xr-xtalpid-core/src/split_tunnel/macos/generate-bindings.sh4
3 files changed, 53 insertions, 265 deletions
diff --git a/talpid-core/src/split_tunnel/macos/bindings.rs b/talpid-core/src/split_tunnel/macos/bindings.rs
index 7430029c14..425527d5c0 100644
--- a/talpid-core/src/split_tunnel/macos/bindings.rs
+++ b/talpid-core/src/split_tunnel/macos/bindings.rs
@@ -1,4 +1,4 @@
-// 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 type __int32_t = ::std::os::raw::c_int;
@@ -11,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)]
@@ -71,220 +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)
- )
- );
-}
-
-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];
+};
diff --git a/talpid-core/src/split_tunnel/macos/bpf.rs b/talpid-core/src/split_tunnel/macos/bpf.rs
index ec3f8fc62d..566cc1f56b 100644
--- a/talpid-core/src/split_tunnel/macos/bpf.rs
+++ b/talpid-core/src/split_tunnel/macos/bpf.rs
@@ -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
@@ -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 {
diff --git a/talpid-core/src/split_tunnel/macos/generate-bindings.sh b/talpid-core/src/split_tunnel/macos/generate-bindings.sh
index 9cfa5c1b62..a52c09fd86 100755
--- a/talpid-core/src/split_tunnel/macos/generate-bindings.sh
+++ b/talpid-core/src/split_tunnel/macos/generate-bindings.sh
@@ -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"