Skip to content

Commit f4ed512

Browse files
committed
fix
1 parent 5aa9535 commit f4ed512

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

oryx-ebpf/src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ static BLOCKLIST_IPV4: HashMap<u32, [u16; MAX_RULES_PORT]> =
4848
#[no_mangle]
4949
static TRAFFIC_DIRECTION: i32 = 0;
5050

51+
#[no_mangle]
52+
static PID_HELPER_AVAILABILITY: u8 = 0;
53+
5154
#[classifier]
5255
pub fn oryx(ctx: TcContext) -> i32 {
5356
match process(ctx) {
@@ -157,7 +160,13 @@ fn process(ctx: TcContext) -> Result<i32, ()> {
157160
let pid = if is_ingress() {
158161
None
159162
} else {
160-
Some((bpf_get_current_pid_tgid() >> 32) as u32)
163+
let pid_helper_available = unsafe { core::ptr::read_volatile(&PID_HELPER_AVAILABILITY) };
164+
165+
if pid_helper_available == 1 {
166+
Some((bpf_get_current_pid_tgid() >> 32) as u32)
167+
} else {
168+
None
169+
}
161170
};
162171

163172
match unsafe { (*eth_header).ether_type } {

oryx-tui/src/ebpf/egress.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use aya::{
1010
include_bytes_aligned,
1111
maps::{Array, HashMap},
1212
programs::{tc, SchedClassifier, TcAttachType},
13+
util::KernelVersion,
1314
EbpfLoader,
1415
};
1516
use log::error;
@@ -29,6 +30,14 @@ use super::{
2930
EbpfTrafficDirection, RingBuffer,
3031
};
3132

33+
fn is_pid_helper_available() -> bool {
34+
if let Ok(current_version) = KernelVersion::current() {
35+
current_version >= KernelVersion::new(6, 10, 0)
36+
} else {
37+
false
38+
}
39+
}
40+
3241
pub fn load_egress(
3342
iface: String,
3443
notification_sender: kanal::Sender<Event>,
@@ -51,9 +60,12 @@ pub fn load_egress(
5160

5261
let traffic_direction = EbpfTrafficDirection::Egress as i32;
5362

63+
let pid_helper_available = is_pid_helper_available() as u8;
64+
5465
#[cfg(debug_assertions)]
5566
let mut bpf = match EbpfLoader::new()
5667
.set_global("TRAFFIC_DIRECTION", &traffic_direction, true)
68+
.set_global("PID_HELPER_AVAILABILITY", &pid_helper_available, false)
5769
.load(include_bytes_aligned!(env!("ORYX_BIN_PATH")))
5870
{
5971
Ok(v) => v,

0 commit comments

Comments
 (0)