feat: separate zstd and faketcp into features (#1861)

* feat: separate faketcp into a feature
* fix: no need to initialize out_len
* feat: separate zstd into a feature
* clippy: remove unnecessary cast, because for unix size_t always equals usize
This commit is contained in:
Chenx Dust
2026-02-03 11:12:33 +08:00
committed by GitHub
parent 7750e81168
commit e1cbd07d1f
8 changed files with 79 additions and 23 deletions
@@ -716,7 +716,7 @@ fn open_bpf_device() -> io::Result<OwnedFd> {
fn set_ifreq_name(ifr: &mut libc::ifreq, interface_name: &str) -> io::Result<()> {
let bytes = interface_name.as_bytes();
let ifnamsiz = libc::IFNAMSIZ as usize;
let ifnamsiz = libc::IFNAMSIZ;
if bytes.len() >= ifnamsiz {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
@@ -932,7 +932,7 @@ impl MacosBpfTun {
let pkt_start = off + pkt_range.start;
let pkt_end = off + pkt_range.end;
let shift = (pkt_range.start as usize).saturating_sub(hdr_len as usize);
let shift = pkt_range.start.saturating_sub(hdr_len as usize);
if shift != 0 && shifted_record_logs_left > 0 {
shifted_record_logs_left -= 1;
warn!(
@@ -1039,7 +1039,7 @@ impl stack::Tun for MacosBpfTun {
Ok(())
};
let mut out_len = 0usize;
let mut out_len: usize;
let res = match self.link_type {
LinkType::En10Mb => {
out_len = packet.len();
+3 -1
View File
@@ -15,7 +15,6 @@ use self::packet_def::ZCPacket;
pub mod buf;
pub mod common;
pub mod fake_tcp;
pub mod filter;
pub mod mpsc;
pub mod packet_def;
@@ -33,6 +32,9 @@ pub const PROTO_PORT_OFFSET: &[(&str, u16)] = &[
("faketcp", 3),
];
#[cfg(feature = "faketcp")]
pub mod fake_tcp;
#[cfg(feature = "wireguard")]
pub mod wireguard;
+2
View File
@@ -288,6 +288,7 @@ pub const AES_GCM_ENCRYPTION_RESERVED: usize = std::mem::size_of::<AesGcmTail>()
#[repr(u8)]
pub enum CompressorAlgo {
None = 0,
#[cfg(feature = "zstd")]
ZstdDefault = 1,
}
@@ -301,6 +302,7 @@ pub const COMPRESSOR_TAIL_SIZE: usize = std::mem::size_of::<CompressorTail>();
impl CompressorTail {
pub fn get_algo(&self) -> Option<CompressorAlgo> {
match self.algo {
#[cfg(feature = "zstd")]
1 => Some(CompressorAlgo::ZstdDefault),
_ => None,
}