pub struct NetflowParser {
pub v9_parser: V9Parser,
pub ipfix_parser: IPFixParser,
pub allowed_versions: HashSet<u16>,
pub max_error_sample_size: usize,
}Fields§
§v9_parser: V9Parser§ipfix_parser: IPFixParser§allowed_versions: HashSet<u16>§max_error_sample_size: usizeMaximum number of bytes to include in error samples to prevent memory exhaustion. Defaults to 256 bytes.
Implementations§
Source§impl NetflowParser
impl NetflowParser
Sourcepub fn parse_bytes(&mut self, packet: &[u8]) -> Vec<NetflowPacket>
pub fn parse_bytes(&mut self, packet: &[u8]) -> Vec<NetflowPacket>
Takes a Netflow packet slice and returns a vector of Parsed Netflows. If we reach some parse error we return what items be have.
§Examples
use serde_json::json;
use netflow_parser::NetflowParser;
let v5_packet = [0, 5, 2, 0, 3, 0, 4, 0, 5, 0, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7,];
println!("{}", json!(NetflowParser::default().parse_bytes(&v5_packet)).to_string());§Output:
[{"V5":{"header":{"count":1,"engine_id":7,"engine_type":6,"flow_sequence":33752069,"sampling_interval":2057,"sys_up_time":{"nanos":672000000,"secs":50332},"unix_nsecs":134807553,"unix_secs":83887623,"version":5},"sets":[{"d_octets":66051,"d_pkts":101124105,"dst_addr":"4.5.6.7","dst_as":515,"dst_mask":5,"dst_port":1029,"first":{"nanos":87000000,"secs":67438},"input":515,"last":{"nanos":553000000,"secs":134807},"next_hop":"8.9.0.1","output":1029,"pad1":6,"pad2":1543,"protocol_number":8,"protocol_type":"Egp","src_addr":"0.1.2.3","src_as":1,"src_mask":4,"src_port":515,"tcp_flags":7,"tos":9}]}}]Sourcepub fn iter_packets<'a>(
&'a mut self,
packet: &'a [u8],
) -> NetflowPacketIterator<'a> ⓘ
pub fn iter_packets<'a>( &'a mut self, packet: &'a [u8], ) -> NetflowPacketIterator<'a> ⓘ
Returns an iterator that yields NetflowPacket items without allocating a Vec. This is useful for processing large batches of packets without collecting all results in memory.
§Examples
use netflow_parser::{NetflowParser, NetflowPacket};
let v5_packet = [0, 5, 0, 1, 3, 0, 4, 0, 5, 0, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7,];
let mut parser = NetflowParser::default();
for packet in parser.iter_packets(&v5_packet) {
match packet {
NetflowPacket::V5(v5) => println!("V5 packet: {:?}", v5.header.version),
NetflowPacket::Error(e) => println!("Error: {:?}", e),
_ => (),
}
}