mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2024-11-22 08:16:25 -06:00
Make it easier to change capture size at compile time, set to 128 bytes.
This commit is contained in:
parent
17100415dd
commit
951ee4cbe5
@ -1,6 +1,6 @@
|
||||
use std::time::Duration;
|
||||
use zerocopy::AsBytes;
|
||||
use crate::perf_interface::HeimdallEvent;
|
||||
use crate::perf_interface::{HeimdallEvent, PACKET_OCTET_SIZE};
|
||||
|
||||
#[derive(AsBytes)]
|
||||
#[repr(C)]
|
||||
@ -22,7 +22,7 @@ impl PcapFileHeader {
|
||||
version_minor: 4,
|
||||
thiszone: 0,
|
||||
sigfigs: 0,
|
||||
snaplen: 64,
|
||||
snaplen: PACKET_OCTET_SIZE as u32,
|
||||
link_type: 1,
|
||||
}
|
||||
}
|
||||
@ -43,7 +43,7 @@ impl PcapPacketHeader {
|
||||
Self {
|
||||
ts_sec: timestamp_nanos.as_secs() as u32,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
use std::{ffi::c_void, slice};
|
||||
use lqos_utils::XdpIpAddress;
|
||||
use zerocopy::FromBytes;
|
||||
|
||||
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)]
|
||||
#[repr(C)]
|
||||
pub struct HeimdallEvent {
|
||||
@ -19,7 +21,7 @@ pub struct HeimdallEvent {
|
||||
pub tcp_window: u16,
|
||||
pub tcp_tsval: u32,
|
||||
pub tcp_tsecr: u32,
|
||||
pub packet_data: [u8; 64],
|
||||
pub packet_data: [u8; PACKET_OCTET_SIZE],
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -4,7 +4,7 @@ use lqos_bus::{PacketHeader, tos_parser};
|
||||
use lqos_utils::{unix_time::time_since_boot, XdpIpAddress};
|
||||
use once_cell::sync::Lazy;
|
||||
use zerocopy::AsBytes;
|
||||
use crate::{perf_interface::HeimdallEvent, pcap::{PcapFileHeader, PcapPacketHeader}};
|
||||
use crate::{perf_interface::{HeimdallEvent, PACKET_OCTET_SIZE}, pcap::{PcapFileHeader, PcapPacketHeader}};
|
||||
|
||||
impl HeimdallEvent {
|
||||
fn as_header(&self) -> PacketHeader {
|
||||
@ -69,7 +69,11 @@ pub fn ten_second_pcap() -> Vec<u8> {
|
||||
packets.iter().for_each(|p| {
|
||||
let packet_header = PcapPacketHeader::from_heimdall(p);
|
||||
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
|
||||
}
|
@ -7,6 +7,8 @@
|
||||
#include "debug.h"
|
||||
#include "dissector.h"
|
||||
|
||||
#define PACKET_OCTET_SIZE 128
|
||||
|
||||
// Array containing one element, the Heimdall configuration
|
||||
struct heimdall_config_t
|
||||
{
|
||||
@ -54,7 +56,7 @@ struct heimdall_event {
|
||||
__u16 tcp_window;
|
||||
__u32 tsval;
|
||||
__u32 tsecr;
|
||||
__u8 dump[64];
|
||||
__u8 dump[PACKET_OCTET_SIZE];
|
||||
};
|
||||
|
||||
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.tsval = dissector->tsval;
|
||||
event.tsecr = dissector->tsecr;
|
||||
if (size > 64 && ((char *)dissector->start + 64 < dissector->end)) {
|
||||
__builtin_memcpy(&event.dump, dissector->start, 64);
|
||||
if (size > PACKET_OCTET_SIZE) size = PACKET_OCTET_SIZE;
|
||||
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);
|
||||
if (err != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user