1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! Raw packet-level datatypes.

use super::FromMbuf;
use retina_core::{conntrack::pdu::L4Context, Mbuf};

/// Subscribable alias for [`retina_core::Mbuf`]
pub type ZcFrame = Mbuf;

impl FromMbuf for ZcFrame {
    fn from_mbuf(mbuf: &Mbuf) -> Option<&Self> {
        Some(mbuf)
    }
}

/// Payload after TCP/UDP headers
pub type Payload = [u8];

impl FromMbuf for Payload {
    fn from_mbuf(mbuf: &Mbuf) -> Option<&Self> {
        if let Ok(ctxt) = L4Context::new(mbuf) {
            let offset = ctxt.offset;
            let payload_len = ctxt.length;
            if let Ok(data) = mbuf.get_data_slice(offset, payload_len) {
                return Some(data);
            }
        }
        None
    }
}