Skip to content

Commit

Permalink
ovs: export flow and sw_acts
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Valerio <[email protected]>
  • Loading branch information
vlrpl committed Nov 12, 2024
1 parent 726a609 commit 5603ee3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
8 changes: 6 additions & 2 deletions retis-events/src/ovs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ impl fmt::Display for Ufid {
#[event_type]
#[derive(Copy, Default, PartialEq)]
pub struct LookupEvent {
/// flow pointer
pub flow: u64,
/// actions pointer
pub sf_acts: u64,
/// Flow UFID.
pub ufid: Ufid,
/// n_mask_hit.
Expand All @@ -165,8 +169,8 @@ impl EventFmt for LookupEvent {
fn event_fmt(&self, f: &mut Formatter, _: &DisplayFormat) -> fmt::Result {
write!(
f,
"ufid {} hit {} (mask) {} (cache)",
self.ufid, self.n_mask_hit, self.n_cache_hit,
"ufid {} hit (mask/cache) {}/{} flow {:x} sf_acts {:x}",
self.ufid, self.n_mask_hit, self.n_cache_hit, self.flow, self.sf_acts,
)
}
}
Expand Down
13 changes: 12 additions & 1 deletion retis/src/bindings/kernel_flow_tbl_lookup_ret_uapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
pub type __u32 = ::std::os::raw::c_uint;
pub type u32_ = __u32;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
#[derive(Debug, Copy, Clone)]
pub struct flow_lookup_ret_event {
pub flow: *mut ::std::os::raw::c_void,
pub sf_acts: *mut ::std::os::raw::c_void,
pub ufid: [u32_; 4usize],
pub n_mask_hit: u32_,
pub n_cache_hit: u32_,
}
impl Default for flow_lookup_ret_event {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
2 changes: 2 additions & 0 deletions retis/src/module/ovs/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub(super) fn unmarshall_flow_lookup(raw_section: &BpfRawSection) -> Result<OvsE
let raw = parse_raw_section::<flow_lookup_ret_event>(raw_section)?;
Ok(OvsEvent {
event: OvsEventType::DpLookup(LookupEvent {
flow: raw.flow as usize as u64,
sf_acts: raw.sf_acts as usize as u64,
ufid: raw.ufid.into(),
n_mask_hit: raw.n_mask_hit,
n_cache_hit: raw.n_cache_hit,
Expand Down
7 changes: 7 additions & 0 deletions retis/src/module/ovs/bpf/kernel_flow_tbl_lookup_ret.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#define MAX_UFID_LENGTH 16

struct flow_lookup_ret_event {
BINDING_PTR(struct sw_flow *, flow);
BINDING_PTR(struct sw_flow_actions *, sf_acts);
u32 ufid[MAX_UFID_LENGTH / 4];
u32 n_mask_hit;
u32 n_cache_hit;
Expand Down Expand Up @@ -44,6 +46,11 @@ DEFINE_HOOK_RAW(
if (BPF_CORE_READ_INTO(&ret->ufid, flow, id.ufid))
log_error("Failed to read the ufid");

ret->flow = flow;

if (bpf_core_read(&ret->sf_acts, sizeof(ret->sf_acts), &flow->sf_acts))
log_error("Failed to read sf_acts");

/* Only log in case of failure while retrieving ancillary
* informations.
*/
Expand Down

0 comments on commit 5603ee3

Please sign in to comment.