Skip to content

Commit

Permalink
Merge pull request #3 from yukinakanaka/refactor
Browse files Browse the repository at this point in the history
Delete unused map/struct and Enable tests
  • Loading branch information
yukinakanaka authored Feb 19, 2025
2 parents 1dc4114 + 0bb2f9d commit ad6fafe
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 43 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/rust_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ env:
jobs:
test:
runs-on: ubuntu-24.04
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -32,8 +35,28 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Codegen
run: cargo xtask codegen
- name: Check codegen works fine
run: |
if [ -e /sys/kernel/btf/vmlinux ]; then
ls -l /sys/kernel/btf/vmlinux
else
echo "Warning: /sys/kernel/btf/vmlinux not found"
exit 1
fi
if ! command -v bindgen > /dev/null 2>&1; then
echo "bindgen not found, running cargo install bindgen..."
cargo install bindgen-cli
fi
cargo xtask codegen
git diff tetragon-common/src/vmlinux.rs
# The following can be enabled after supporting multiple kernel versions and platforms.
# if git diff --name-only | grep -q "tetragon-common/src/vmlinux.rs"; then
# echo "tetragon-common/src/vmlinux.rs hasn't been update. Update it by cargo task codegen."
# exit 1
# fi
- name: Check formatting
run: cargo fmt --all --check
# - name: Build test
Expand Down
48 changes: 22 additions & 26 deletions tetragon-common/src/vmlinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7605,6 +7605,7 @@ pub struct inode {
pub i_mode: umode_t,
pub i_opflags: ::aya_ebpf::cty::c_ushort,
pub i_uid: kuid_t,
pub i_lru: list_head,
pub i_gid: kgid_t,
pub i_flags: ::aya_ebpf::cty::c_uint,
pub i_acl: *mut posix_acl,
Expand Down Expand Up @@ -7635,7 +7636,6 @@ pub struct inode {
pub i_wb_frn_winner: ::aya_ebpf::cty::c_int,
pub i_wb_frn_avg_time: u16_,
pub i_wb_frn_history: u16_,
pub i_lru: list_head,
pub i_sb_list: list_head,
pub i_wb_list: list_head,
pub __bindgen_anon_2: inode__bindgen_ty_2,
Expand Down Expand Up @@ -16637,7 +16637,7 @@ pub struct cdrom_device_ops {
pub select_speed: ::core::option::Option<
unsafe extern "C" fn(
arg1: *mut cdrom_device_info,
arg2: ::aya_ebpf::cty::c_int,
arg2: ::aya_ebpf::cty::c_ulong,
) -> ::aya_ebpf::cty::c_int,
>,
pub get_last_session: ::core::option::Option<
Expand Down Expand Up @@ -18866,12 +18866,7 @@ pub struct ctl_table_root {
unsafe extern "C" fn(arg1: *mut ctl_table_root) -> *mut ctl_table_set,
>,
pub set_ownership: ::core::option::Option<
unsafe extern "C" fn(
arg1: *mut ctl_table_header,
arg2: *mut ctl_table,
arg3: *mut kuid_t,
arg4: *mut kgid_t,
),
unsafe extern "C" fn(arg1: *mut ctl_table_header, arg2: *mut kuid_t, arg3: *mut kgid_t),
>,
pub permissions: ::core::option::Option<
unsafe extern "C" fn(
Expand Down Expand Up @@ -34584,6 +34579,7 @@ pub struct led_trigger {
unsafe extern "C" fn(arg1: *mut led_classdev) -> ::aya_ebpf::cty::c_int,
>,
pub deactivate: ::core::option::Option<unsafe extern "C" fn(arg1: *mut led_classdev)>,
pub brightness: led_brightness::Type,
pub trigger_type: *mut led_hw_trigger_type,
pub leddev_list_lock: spinlock_t,
pub led_cdevs: list_head,
Expand Down Expand Up @@ -37237,7 +37233,7 @@ pub struct mountpoint {
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct mptcp_mib {
pub mibs: [::aya_ebpf::cty::c_ulong; 59usize],
pub mibs: [::aya_ebpf::cty::c_ulong; 61usize],
}
#[repr(C)]
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -42672,16 +42668,7 @@ pub struct per_cpu_pages {
pub alloc_factor: u8_,
pub expire: u8_,
pub free_count: ::aya_ebpf::cty::c_short,
pub lists: [list_head; 13usize],
pub _bitfield_align_1: [u8; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>,
}
impl per_cpu_pages {
#[inline]
pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 16usize]> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default();
__bindgen_bitfield_unit
}
pub lists: [list_head; 14usize],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -43319,6 +43306,7 @@ pub struct perf_buffer {
pub mmap_count: atomic_t,
pub mmap_locked: ::aya_ebpf::cty::c_ulong,
pub mmap_user: *mut user_struct,
pub aux_mutex: mutex,
pub aux_head: ::aya_ebpf::cty::c_long,
pub aux_nest: ::aya_ebpf::cty::c_uint,
pub aux_wakeup: ::aya_ebpf::cty::c_long,
Expand Down Expand Up @@ -45045,6 +45033,7 @@ pub struct perf_event {
pub pending_irq: irq_work,
pub pending_task: callback_head,
pub pending_work: ::aya_ebpf::cty::c_uint,
pub pending_work_wait: rcuwait,
pub event_limit: atomic_t,
pub addr_filters: perf_addr_filters_head,
pub addr_filter_ranges: *mut perf_addr_filter_range,
Expand Down Expand Up @@ -50352,14 +50341,16 @@ pub struct sb_writers {
pub rw_sem: [percpu_rw_semaphore; 3usize],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Copy, Clone)]
pub struct sbitmap_word {
pub word: ::aya_ebpf::cty::c_ulong,
pub _bitfield_align_1: [u8; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 56usize]>,
pub cleared: ::aya_ebpf::cty::c_ulong,
pub swap_lock: spinlock_t,
pub _bitfield_align_2: [u8; 0],
pub _bitfield_2: __BindgenBitfieldUnit<[u8; 56usize]>,
pub _bitfield_2: __BindgenBitfieldUnit<[u8; 48usize]>,
pub __bindgen_padding_0: u32,
}
#[repr(C)]
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -54927,7 +54918,6 @@ pub struct svc_program {
pub pg_vers: *mut *const svc_version,
pub pg_name: *mut ::aya_ebpf::cty::c_char,
pub pg_class: *mut ::aya_ebpf::cty::c_char,
pub pg_stats: *mut svc_stat,
pub pg_authenticate:
::core::option::Option<unsafe extern "C" fn(arg1: *mut svc_rqst) -> svc_auth_status::Type>,
pub pg_init_request: ::core::option::Option<
Expand Down Expand Up @@ -59145,7 +59135,7 @@ pub struct worker {
pub last_active: ::aya_ebpf::cty::c_ulong,
pub flags: ::aya_ebpf::cty::c_uint,
pub id: ::aya_ebpf::cty::c_int,
pub desc: [::aya_ebpf::cty::c_char; 24usize],
pub desc: [::aya_ebpf::cty::c_char; 32usize],
pub rescue_wq: *mut workqueue_struct,
}
#[repr(C)]
Expand Down Expand Up @@ -60138,7 +60128,7 @@ pub struct xfrm_stats {
pub struct xfrm_state {
pub xs_net: possible_net_t,
pub __bindgen_anon_1: xfrm_state__bindgen_ty_1,
pub bysrc: hlist_node,
pub __bindgen_anon_2: xfrm_state__bindgen_ty_2,
pub byspi: hlist_node,
pub byseq: hlist_node,
pub refcnt: refcount_t,
Expand All @@ -60150,7 +60140,7 @@ pub struct xfrm_state {
pub tfcpad: u32_,
pub genid: u32_,
pub km: xfrm_state_walk,
pub props: xfrm_state__bindgen_ty_2,
pub props: xfrm_state__bindgen_ty_3,
pub lft: xfrm_lifetime_cfg,
pub aalg: *mut xfrm_algo_auth,
pub ealg: *mut xfrm_algo,
Expand Down Expand Up @@ -60197,7 +60187,13 @@ pub union xfrm_state__bindgen_ty_1 {
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct xfrm_state__bindgen_ty_2 {
pub union xfrm_state__bindgen_ty_2 {
pub dev_gclist: hlist_node,
pub bysrc: hlist_node,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct xfrm_state__bindgen_ty_3 {
pub reqid: u32_,
pub mode: u8_,
pub replay_window: u8_,
Expand Down
2 changes: 2 additions & 0 deletions tetragon-ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition = "2021"

[dependencies]
aya-ebpf = "0.1.1"
aya-ebpf-bindings = "0.1.1"
aya-ebpf-cty = "0.2.2"
aya-log-ebpf = "0.1.1"
tetragon-common = { version = "0.1.0", path = "../tetragon-common" }

Expand Down
2 changes: 1 addition & 1 deletion tetragon-ebpf/src/lib_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub unsafe fn execve_map_get(pid: &__u32) -> Option<*mut ExecveMapValue> {
}
};

match maps::EXECVE_MAP.insert(pid, &buf.value, 0) {
match maps::EXECVE_MAP.insert(pid, &buf, 0) {
Ok(_) => {
// TODO update stats
}
Expand Down
15 changes: 1 addition & 14 deletions tetragon-ebpf/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,14 @@ use crate::lib_data_msg::MsgData;
use tetragon_common::process::{EventBytes, ExecveInfo, ExecveMapValue, ProcessEvent};
use tetragon_common::vmlinux::{__u32, __u64};

#[repr(C)]
pub struct ProcessEventBuf {
pub p: ProcessEvent,
}

#[map(name = "DATA_HEAP_CUSTOM")]
pub static mut DATA_HEAP_CUSTOM: PerCpuArray<ProcessEventBuf> = PerCpuArray::with_max_entries(1, 0);

#[map(name = "PROCESS_EVENTS")]
pub static PROCESS_EVENTS: PerfEventArray<ProcessEvent> = PerfEventArray::new(0);

#[map(name = "EXECVE_MAP")]
pub static EXECVE_MAP: HashMap<__u32, ExecveMapValue> = HashMap::with_max_entries(32768, 0);

#[repr(C)]
pub struct ExecveMapValueBuf {
pub value: ExecveMapValue,
}

#[map(name = "EXECVE_VAL")]
pub static mut EXECVE_VAL: PerCpuArray<ExecveMapValueBuf> = PerCpuArray::with_max_entries(1, 0);
pub static mut EXECVE_VAL: PerCpuArray<ExecveMapValue> = PerCpuArray::with_max_entries(1, 0);

#[map(name = "TCPMON_MAP")]
pub static TCPMON_MAP: PerfEventArray<EventBytes> = PerfEventArray::new(0);
Expand Down

0 comments on commit ad6fafe

Please sign in to comment.