Some relatively simple performance enhancements that reduce the burden of Heimdall when he's not looking.

This commit is contained in:
Herbert Wolverson
2023-03-16 13:00:20 +00:00
parent 810823c8bb
commit 5ff671567a
2 changed files with 25 additions and 22 deletions

View File

@@ -73,16 +73,18 @@ static __always_inline __u8 get_heimdall_mode()
}
}
static __always_inline bool is_heimdall_watching(struct dissector_t *dissector)
static __always_inline bool is_heimdall_watching(struct dissector_t *dissector, int effective_direction)
{
__u32 *watching = (__u32 *)bpf_map_lookup_elem(&heimdall_watching, &dissector->src_ip);
if (watching) {
return true;
}
watching = (__u32 *)bpf_map_lookup_elem(&heimdall_watching, &dissector->dst_ip);
if (watching) {
return true;
if (effective_direction == 2) {
__u32 *watching = (__u32 *)bpf_map_lookup_elem(&heimdall_watching, &dissector->src_ip);
if (watching) {
return true;
}
} else {
__u32 *watching = (__u32 *)bpf_map_lookup_elem(&heimdall_watching, &dissector->dst_ip);
if (watching) {
return true;
}
}
return false;
}
@@ -100,14 +102,16 @@ static __always_inline void update_heimdall(struct dissector_t *dissector, __u32
event.size = size;
event.tcp_flags = dissector->tcp_flags;
event.tcp_window = dissector->window;
event.tsval = dissector->tsval;
event.tsecr = dissector->tsecr;
//event.tsval = dissector->tsval;
//event.tsecr = dissector->tsecr;
if (size > PACKET_OCTET_SIZE) size = PACKET_OCTET_SIZE;
if ((char *)dissector->start + size < dissector->end) {
bpf_probe_read_kernel(&event.dump, PACKET_OCTET_SIZE, dissector->start);
}
long err = bpf_ringbuf_output(&heimdall_events, &event, sizeof(event), 0);
if (err != 0) {
bpf_debug("Failed to send perf event %d", err);
}
//if ((char *)dissector->start + size < dissector->end) {
bpf_probe_read_kernel(&event.dump, size, dissector->start);
//}
bpf_ringbuf_output(&heimdall_events, &event, sizeof(event), 0);
// Commented out because we don't really care - some will be missed
// during very heavy load.
//if (err != 0) {
// bpf_debug("Failed to send perf event %d", err);
//}
}

View File

@@ -66,8 +66,6 @@ int xdp_prog(struct xdp_md *ctx)
return XDP_PASS;
}
__u8 heimdall_mode = get_heimdall_mode();
// Do we need to perform a VLAN redirect?
bool vlan_redirect = false;
{ // Note: scope for removing temporaries from the stack
@@ -77,7 +75,7 @@ int xdp_prog(struct xdp_md *ctx)
&bifrost_interface_map,
&my_interface
);
if (redirect_info && redirect_info->scan_vlans) {
if (redirect_info) {
// If we have a redirect, mark it - the dissector will
// apply it
vlan_redirect = true;
@@ -137,7 +135,8 @@ int xdp_prog(struct xdp_md *ctx)
// Send on its way
if (tc_handle != 0) {
// Send data to Heimdall
if (heimdall_mode == 2 || (heimdall_mode==1 && is_heimdall_watching(&dissector))) {
__u8 heimdall_mode = get_heimdall_mode();
if (heimdall_mode == 2 || (heimdall_mode==1 && is_heimdall_watching(&dissector, effective_direction))) {
#ifdef VERBOSE
bpf_debug("(XDP) Storing Heimdall Data");
#endif