Make it easier to change capture size at compile time, set to 128 bytes.

This commit is contained in:
Herbert Wolverson
2023-03-15 20:32:31 +00:00
parent 17100415dd
commit 951ee4cbe5
4 changed files with 19 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
use std::time::Duration; use std::time::Duration;
use zerocopy::AsBytes; use zerocopy::AsBytes;
use crate::perf_interface::HeimdallEvent; use crate::perf_interface::{HeimdallEvent, PACKET_OCTET_SIZE};
#[derive(AsBytes)] #[derive(AsBytes)]
#[repr(C)] #[repr(C)]
@@ -22,7 +22,7 @@ impl PcapFileHeader {
version_minor: 4, version_minor: 4,
thiszone: 0, thiszone: 0,
sigfigs: 0, sigfigs: 0,
snaplen: 64, snaplen: PACKET_OCTET_SIZE as u32,
link_type: 1, link_type: 1,
} }
} }
@@ -43,7 +43,7 @@ impl PcapPacketHeader {
Self { Self {
ts_sec: timestamp_nanos.as_secs() as u32, ts_sec: timestamp_nanos.as_secs() as u32,
ts_usec: timestamp_nanos.subsec_micros(), ts_usec: timestamp_nanos.subsec_micros(),
inc_len: u32::min(64, event.size), inc_len: u32::min(PACKET_OCTET_SIZE as u32, event.size),
orig_len: event.size orig_len: event.size
} }
} }

View File

@@ -1,9 +1,11 @@
use std::{ffi::c_void, slice}; use std::{ffi::c_void, slice};
use lqos_utils::XdpIpAddress; use lqos_utils::XdpIpAddress;
use zerocopy::FromBytes; use zerocopy::FromBytes;
use crate::{flows::record_flow, timeline::store_on_timeline}; use crate::{flows::record_flow, timeline::store_on_timeline};
/// This constant MUST exactly match PACKET_OCTET_STATE in heimdall.h
pub(crate) const PACKET_OCTET_SIZE: usize = 128;
#[derive(FromBytes, Debug, Clone, PartialEq, Eq, Hash)] #[derive(FromBytes, Debug, Clone, PartialEq, Eq, Hash)]
#[repr(C)] #[repr(C)]
pub struct HeimdallEvent { pub struct HeimdallEvent {
@@ -19,7 +21,7 @@ pub struct HeimdallEvent {
pub tcp_window: u16, pub tcp_window: u16,
pub tcp_tsval: u32, pub tcp_tsval: u32,
pub tcp_tsecr: u32, pub tcp_tsecr: u32,
pub packet_data: [u8; 64], pub packet_data: [u8; PACKET_OCTET_SIZE],
} }
/* /*

View File

@@ -4,7 +4,7 @@ use lqos_bus::{PacketHeader, tos_parser};
use lqos_utils::{unix_time::time_since_boot, XdpIpAddress}; use lqos_utils::{unix_time::time_since_boot, XdpIpAddress};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use zerocopy::AsBytes; use zerocopy::AsBytes;
use crate::{perf_interface::HeimdallEvent, pcap::{PcapFileHeader, PcapPacketHeader}}; use crate::{perf_interface::{HeimdallEvent, PACKET_OCTET_SIZE}, pcap::{PcapFileHeader, PcapPacketHeader}};
impl HeimdallEvent { impl HeimdallEvent {
fn as_header(&self) -> PacketHeader { fn as_header(&self) -> PacketHeader {
@@ -69,7 +69,11 @@ pub fn ten_second_pcap() -> Vec<u8> {
packets.iter().for_each(|p| { packets.iter().for_each(|p| {
let packet_header = PcapPacketHeader::from_heimdall(p); let packet_header = PcapPacketHeader::from_heimdall(p);
bytes.extend(packet_header.as_bytes()); bytes.extend(packet_header.as_bytes());
bytes.extend(p.packet_data); if p.size < PACKET_OCTET_SIZE as u32 {
bytes.extend(&p.packet_data[0 .. p.size as usize]);
} else {
bytes.extend(p.packet_data);
}
}); });
bytes bytes
} }

View File

@@ -7,6 +7,8 @@
#include "debug.h" #include "debug.h"
#include "dissector.h" #include "dissector.h"
#define PACKET_OCTET_SIZE 128
// Array containing one element, the Heimdall configuration // Array containing one element, the Heimdall configuration
struct heimdall_config_t struct heimdall_config_t
{ {
@@ -54,7 +56,7 @@ struct heimdall_event {
__u16 tcp_window; __u16 tcp_window;
__u32 tsval; __u32 tsval;
__u32 tsecr; __u32 tsecr;
__u8 dump[64]; __u8 dump[PACKET_OCTET_SIZE];
}; };
static __always_inline __u8 get_heimdall_mode() static __always_inline __u8 get_heimdall_mode()
@@ -100,8 +102,9 @@ static __always_inline void update_heimdall(struct dissector_t *dissector, __u32
event.tcp_window = dissector->window; event.tcp_window = dissector->window;
event.tsval = dissector->tsval; event.tsval = dissector->tsval;
event.tsecr = dissector->tsecr; event.tsecr = dissector->tsecr;
if (size > 64 && ((char *)dissector->start + 64 < dissector->end)) { if (size > PACKET_OCTET_SIZE) size = PACKET_OCTET_SIZE;
__builtin_memcpy(&event.dump, dissector->start, 64); if ((char *)dissector->start + size < dissector->end) {
bpf_probe_read_kernel(&event.dump, size, dissector->start);
} }
long err = bpf_ringbuf_output(&heimdall_events, &event, sizeof(event), 0); long err = bpf_ringbuf_output(&heimdall_events, &event, sizeof(event), 0);
if (err != 0) { if (err != 0) {