@@ -28,10 +28,8 @@ use aya_ebpf::{
2828use aya_log_ebpf:: info;
2929
3030use crate :: bindings:: { net, net_device, ns_common, possible_net_t} ;
31- use crate :: data_structures:: { ConnArray , NetnsLog , PacketLog , VethLog } ;
32- use crate :: data_structures:: {
33- ACTIVE_CONNECTIONS , CONNTRACKER , EVENTS , NET_EVENTS , VETH_EVENTS ,
34- } ;
31+ use crate :: data_structures:: { ConnArray , PacketLog , VethLog } ;
32+ use crate :: data_structures:: { ACTIVE_CONNECTIONS , CONNTRACKER , EVENTS , VETH_EVENTS } ;
3533/*
3634 * ETHERNET TYPE II FRAME:
3735 * Reference: https://it.wikipedia.org/wiki/Frame_Ethernet
@@ -151,6 +149,18 @@ fn read_linux_inner_value<T: Copy>(ptr: *const u8, offset: usize) -> Result<T, i
151149 Ok ( inner_value)
152150}
153151
152+ fn extract_netns_inum ( net_device_pointer : * const u8 ) -> Result < u32 , i64 > {
153+ let possible_net_t_offset = 280 ;
154+
155+ let net = read_linux_inner_struct :: < net > ( net_device_pointer, possible_net_t_offset) ?;
156+
157+ let ns_common_offset = 120 ;
158+
159+ let inum_offset = 16 ;
160+ let inum_ptr = read_linux_inner_value :: < u32 > ( net as * const u8 , ns_common_offset + inum_offset) ?;
161+ Ok ( inum_ptr)
162+ }
163+
154164//mode selection:
155165//1->veth_creation_tracer
156166//2->veth_deletion_tracer
@@ -180,6 +190,9 @@ pub fn try_veth_tracer(ctx: ProbeContext, mode: u8) -> Result<u32, i64> {
180190 let dev_addr_array: [ u32 ; 8 ] =
181191 read_linux_inner_value :: < [ u32 ; 8 ] > ( net_device_pointer as * const u8 , dev_addr_offset) ?;
182192
193+ let inum: u32 = extract_netns_inum ( net_device_pointer as * const u8 ) ?;
194+ let pid: u32 = ( bpf_get_current_pid_tgid ( ) << 32 ) as u32 ; //extracting lower 32 bit corresponding to the PID
195+
183196 //buffer copying for array types
184197 name_buf. copy_from_slice ( & name_array) ;
185198 dev_addr_buf. copy_from_slice ( & dev_addr_array) ;
@@ -190,7 +203,8 @@ pub fn try_veth_tracer(ctx: ProbeContext, mode: u8) -> Result<u32, i64> {
190203 state : state. into ( ) ,
191204 dev_addr : dev_addr_buf,
192205 event_type : mode,
193- //netns: inum,
206+ netns : inum,
207+ pid,
194208 } ;
195209
196210 //send the data to the userspace
0 commit comments