-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ovs: extract ufid and generate the related event.
While at it, n_{mask,cache}_hit have been included. Ideally, this should be done with fexit indexing by sw_flow_key, but given that is missing, it reuses the existing inflight_exec map. Signed-off-by: Paolo Valerio <[email protected]>
- Loading branch information
Showing
13 changed files
with
253 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* automatically generated by rust-bindgen 0.70.1 */ | ||
|
||
pub type __u32 = ::std::os::raw::c_uint; | ||
pub type u32_ = __u32; | ||
#[repr(C)] | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct flow_lookup_ret_event { | ||
pub ufid: [u32_; 4usize], | ||
pub n_mask_hit: u32_, | ||
pub n_cache_hit: u32_, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <common.h> | ||
#include <ovs_common.h> | ||
|
||
/* Hook for kprobe:ovs_flow_tbl_lookup_stats */ | ||
DEFINE_HOOK_RAW( | ||
u64 tid = bpf_get_current_pid_tgid(); | ||
struct execute_actions_ctx *ectx; | ||
|
||
ectx = bpf_map_lookup_elem(&inflight_exec, &tid); | ||
if (!ectx) { | ||
return 0; | ||
} | ||
|
||
ectx->n_mask_hit = (u32 *)ctx->regs.reg[3]; | ||
ectx->n_cache_hit = (u32 *)ctx->regs.reg[4]; | ||
|
||
return 0; | ||
) | ||
|
||
char __license[] SEC("license") = "GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <common.h> | ||
#include <ovs_common.h> | ||
|
||
#define MAX_UFID_LENGTH 16 | ||
|
||
struct flow_lookup_ret_event { | ||
u32 ufid[MAX_UFID_LENGTH / 4]; | ||
u32 n_mask_hit; | ||
u32 n_cache_hit; | ||
} __binding; | ||
|
||
/* Hook for kretprobe:ovs_flow_tbl_lookup_stats */ | ||
DEFINE_HOOK_RAW( | ||
u64 tid = bpf_get_current_pid_tgid(); | ||
struct flow_lookup_ret_event *ret; | ||
struct execute_actions_ctx *ectx; | ||
struct sw_flow *flow; | ||
u32 ufid_len = 0; | ||
|
||
ectx = bpf_map_lookup_elem(&inflight_exec, &tid); | ||
if (!ectx) { | ||
return 0; | ||
} | ||
|
||
flow = (struct sw_flow *)ctx->regs.ret; | ||
if (!flow) { | ||
/* No flows. This is most likely an upcall. | ||
* There's no much we can do other than clean-up | ||
* the map and return. | ||
*/ | ||
bpf_map_delete_elem(&inflight_exec, &tid); | ||
return 0; | ||
} | ||
|
||
ufid_len = BPF_CORE_READ(flow, id.ufid_len); | ||
if (!ufid_len) { | ||
log_error("Expected ufid representation expected, found key"); | ||
return 0; | ||
} | ||
|
||
ret = get_event_section(event, COLLECTOR_OVS, | ||
OVS_FLOW_TBL_LOOKUP_RETURN, | ||
sizeof(*ret)); | ||
if (!ret) | ||
return 0; | ||
|
||
if (BPF_CORE_READ_INTO(&ret->ufid, flow, id.ufid)) | ||
log_error("Failed to read the ufid"); | ||
|
||
/* Only log in case of failure while retrieving ancillary | ||
* informations. | ||
*/ | ||
if (bpf_probe_read_kernel(&ret->n_mask_hit, sizeof(ret->n_mask_hit), | ||
ectx->n_mask_hit) < 0) { | ||
log_error("Failed to retrieve n_mask_hit"); | ||
} | ||
|
||
if (bpf_probe_read_kernel(&ret->n_cache_hit, sizeof(ret->n_cache_hit), | ||
ectx->n_cache_hit) < 0) { | ||
log_error("Failed to retrieve n_cache_hit"); | ||
} | ||
|
||
return 0; | ||
) | ||
|
||
char __license[] SEC("license") = "GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <common.h> | ||
#include <ovs_common.h> | ||
|
||
/* Hook for kprobe:ovs_dp_process_packet. */ | ||
DEFINE_HOOK(F_AND, RETIS_ALL_FILTERS, | ||
u64 tid = bpf_get_current_pid_tgid(); | ||
struct execute_actions_ctx ectx = {}; | ||
|
||
ectx.skb = retis_get_sk_buff(ctx); | ||
if (!ectx.skb) { | ||
log_error("Invalid skb while ovs is processing the packet"); | ||
return 0; | ||
} | ||
|
||
if (!bpf_map_update_elem(&inflight_exec, &tid, &ectx, BPF_ANY)) | ||
return 0; | ||
|
||
return 0; | ||
) | ||
|
||
char __license[] SEC("license") = "GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.