Skip to content

Commit 649cee6

Browse files
committed
vey-daemon: simplify ebpf feature cfg guard
1 parent eb286ff commit 649cee6

3 files changed

Lines changed: 26 additions & 25 deletions

File tree

lib/vey-daemon/src/listen/quic.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use std::net::{SocketAddr, UdpSocket};
88
use std::sync::Arc;
99
use std::time::Duration;
1010

11-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
11+
#[cfg(feature = "ebpf")]
1212
use anyhow::anyhow;
1313
use async_trait::async_trait;
1414
use log::{info, warn};
1515
use quinn::{Connection, Endpoint, Incoming};
1616
use tokio::runtime::Handle;
1717
use tokio::sync::broadcast;
1818

19-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
19+
#[cfg(feature = "ebpf")]
2020
use vey_reuseport::quic::{QuicSocketSelectGuard, QuicSocketSelector};
2121
use vey_socket::RawSocket;
2222
use vey_std_ext::net::SocketAddrExt;
@@ -43,7 +43,7 @@ pub struct ListenQuicRuntime<S> {
4343
server: S,
4444
listen_config: UdpListenConfig,
4545
listen_stats: Arc<ListenStats>,
46-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
46+
#[cfg(feature = "ebpf")]
4747
socket_selector: Option<QuicSocketSelector>,
4848
}
4949

@@ -56,7 +56,7 @@ where
5656
server,
5757
listen_config,
5858
listen_stats,
59-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
59+
#[cfg(feature = "ebpf")]
6060
socket_selector: None,
6161
}
6262
}
@@ -77,7 +77,7 @@ where
7777
}
7878
}
7979

80-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
80+
#[cfg(feature = "ebpf")]
8181
if self
8282
.listen_config
8383
.use_ebpf(rustix::process::getuid().as_raw())
@@ -107,7 +107,7 @@ where
107107

108108
for i in 0..instance_count {
109109
let socket = vey_socket::udp::new_std_bind_listen(&self.listen_config)?;
110-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
110+
#[cfg(feature = "ebpf")]
111111
let guard = if let Some(selector) = &mut self.socket_selector {
112112
let guard = selector.add_socket(RawSocket::from(&socket))?;
113113
Some(guard)
@@ -128,7 +128,7 @@ where
128128
instance_id: i,
129129
ingress_net_filter: ingress_net_filter.cloned(),
130130
accept_timeout,
131-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
131+
#[cfg(feature = "ebpf")]
132132
_bpf_guard: guard,
133133
_alive_guard: None,
134134
};
@@ -139,7 +139,7 @@ where
139139
);
140140
}
141141

142-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
142+
#[cfg(feature = "ebpf")]
143143
if let Some(mut selector) = self.socket_selector.take() {
144144
if let Err(e) = selector.load_and_attach() {
145145
if self.listen_config.fail_on_ebpf_error() {
@@ -180,7 +180,7 @@ pub struct ListenQuicRuntimeInstance<S> {
180180
instance_id: usize,
181181
ingress_net_filter: Option<Arc<AclNetworkRule>>,
182182
accept_timeout: Duration,
183-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
183+
#[cfg(feature = "ebpf")]
184184
_bpf_guard: Option<QuicSocketSelectGuard>,
185185
_alive_guard: Option<ListenAliveGuard>,
186186
}

lib/vey-daemon/src/listen/tcp.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use std::net::SocketAddr;
88
use std::sync::Arc;
99

10-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
10+
#[cfg(feature = "ebpf")]
1111
use anyhow::anyhow;
1212
use async_trait::async_trait;
1313
use log::{info, warn};
@@ -17,7 +17,7 @@ use tokio::sync::broadcast;
1717

1818
use vey_compat::CpuAffinity;
1919
use vey_io_ext::LimitedTcpListener;
20-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
20+
#[cfg(feature = "ebpf")]
2121
use vey_reuseport::tcp::TcpSocketSelector;
2222
use vey_socket::RawSocket;
2323
use vey_std_ext::net::SocketAddrExt;
@@ -34,7 +34,7 @@ pub trait AcceptTcpServer: BaseServer {
3434
pub struct ListenTcpRuntime<S> {
3535
server: S,
3636
listen_stats: Arc<ListenStats>,
37-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
37+
#[cfg(feature = "ebpf")]
3838
socket_selector: Option<TcpSocketSelector>,
3939
}
4040

@@ -46,7 +46,7 @@ where
4646
ListenTcpRuntime {
4747
server,
4848
listen_stats,
49-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
49+
#[cfg(feature = "ebpf")]
5050
socket_selector: None,
5151
}
5252
}
@@ -82,7 +82,7 @@ where
8282
}
8383
}
8484

85-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
85+
#[cfg(feature = "ebpf")]
8686
if listen_config.use_ebpf(rustix::process::getuid().as_raw()) {
8787
match TcpSocketSelector::new(
8888
rustix::process::getpid().as_raw_pid(),
@@ -109,7 +109,7 @@ where
109109

110110
for i in 0..instance_count {
111111
let listener = vey_socket::tcp::new_std_listener(listen_config)?;
112-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
112+
#[cfg(feature = "ebpf")]
113113
if let Some(selector) = &mut self.socket_selector {
114114
selector.add_socket(RawSocket::from(&listener));
115115
}
@@ -122,7 +122,7 @@ where
122122
);
123123
}
124124

125-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
125+
#[cfg(feature = "ebpf")]
126126
if let Some(mut selector) = self.socket_selector.take() {
127127
if let Err(e) = selector.load_and_attach() {
128128
if listen_config.fail_on_ebpf_error() {

lib/vey-daemon/src/listen/udp/listen.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::sync::Arc;
2121
use std::sync::atomic::{AtomicUsize, Ordering};
2222
use std::task::{Context, Poll};
2323

24-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
24+
#[cfg(feature = "ebpf")]
2525
use anyhow::anyhow;
2626
use async_trait::async_trait;
2727
use bytes::Bytes;
@@ -32,11 +32,12 @@ use smallvec::SmallVec;
3232
use tokio::net::UdpSocket;
3333
use tokio::runtime::Handle;
3434
use tokio::sync::{broadcast, mpsc};
35+
#[cfg(feature = "ebpf")]
3536
use tokio::time::Instant;
3637

3738
use vey_io_ext::{UdpMoveRecv, UdpMoveSend, UdpSocketExt};
3839
use vey_io_sys::udp::{RecvMsgHdr, SendMsgHdr};
39-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
40+
#[cfg(feature = "ebpf")]
4041
use vey_reuseport::udp::{UdpSocketSelectGuard, UdpSocketSelector};
4142
use vey_socket::RawSocket;
4243
use vey_types::acl::{AclAction, AclNetworkRule};
@@ -434,7 +435,7 @@ pub struct ListenUdpRuntime<S> {
434435
conn_track: UdpConnectionTrackConfig,
435436
packet_max_size: u16,
436437
listen_stats: Arc<ListenStats>,
437-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
438+
#[cfg(feature = "ebpf")]
438439
socket_selector: Option<UdpSocketSelector>,
439440
}
440441

@@ -455,7 +456,7 @@ where
455456
conn_track,
456457
packet_max_size,
457458
listen_stats,
458-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
459+
#[cfg(feature = "ebpf")]
459460
socket_selector: None,
460461
}
461462
}
@@ -532,7 +533,7 @@ where
532533
listen_in_worker,
533534
instance_id: id,
534535
ingress_net_filter: None,
535-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
536+
#[cfg(feature = "ebpf")]
536537
_bpf_guard: None,
537538
_alive_guard: None,
538539

@@ -554,7 +555,7 @@ where
554555
}
555556
}
556557

557-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
558+
#[cfg(feature = "ebpf")]
558559
if self
559560
.listen_config
560561
.use_ebpf(rustix::process::getuid().as_raw())
@@ -589,15 +590,15 @@ where
589590

590591
let mut runtime = self.create_instance(i, listen_addr, listen_in_worker);
591592
runtime.ingress_net_filter = ingress_net_filter.cloned();
592-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
593+
#[cfg(feature = "ebpf")]
593594
if let Some(selector) = &mut self.socket_selector {
594595
let guard = selector.add_socket(RawSocket::from(&socket));
595596
runtime._bpf_guard = Some(guard);
596597
}
597598
runtime.into_running(socket, server_reload_sender.subscribe());
598599
}
599600

600-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
601+
#[cfg(feature = "ebpf")]
601602
if let Some(mut selector) = self.socket_selector.take() {
602603
if let Err(e) = selector.load_and_attach() {
603604
if self.listen_config.fail_on_ebpf_error() {
@@ -639,7 +640,7 @@ struct ListenUdpRuntimeInstance<S> {
639640
listen_in_worker: bool,
640641
instance_id: usize,
641642
ingress_net_filter: Option<Arc<AclNetworkRule>>,
642-
#[cfg(all(target_os = "linux", feature = "ebpf"))]
643+
#[cfg(feature = "ebpf")]
643644
_bpf_guard: Option<UdpSocketSelectGuard>,
644645
_alive_guard: Option<ListenAliveGuard>,
645646

0 commit comments

Comments
 (0)