diff options
| author | luwenpeng <[email protected]> | 2023-09-27 17:54:40 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2023-09-27 17:54:50 +0800 |
| commit | e0c7dfa5bd9d424249b87ec07d377e94d49d139a (patch) | |
| tree | 1d9bab0ed3b366ce3ff9ef0d9190162546521e7f /src/session/session.rs | |
| parent | 521fbe5464652d509e3290fd336c87ba28fa24c0 (diff) | |
[optimize] Packet Decode
1. Add a macro to obtain Packet’s encapsulation information (the returned data is an immutable reference to Packet)
* get_innermost_special_encapsulation!()
* get_outermost_special_encapsulation!()
Example: let icmp_encapsulation : Option<&Encapsulation> = get_innermost_special_encapsulation!(&Packet, ICMP);
Example: let l4_encapsulation : Option<&Encapsulation> = get_innermost_special_encapsulation!(&Packet, TCP | UDP);
2. Clean up the Clone/Copy Trait of PacketDecode to avoid memory copies caused by improper use by users.
Diffstat (limited to 'src/session/session.rs')
| -rw-r--r-- | src/session/session.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/session/session.rs b/src/session/session.rs index e8b2be4..1db4bfd 100644 --- a/src/session/session.rs +++ b/src/session/session.rs @@ -7,19 +7,19 @@ use std::collections::HashMap; const MAX_SESSION_EXPIRE_TIME: i64 = 60; -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum SessionDirection { C2S, S2C, } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum SessionProto { TCP, UDP, } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum SessionState { New, Active, @@ -27,7 +27,7 @@ pub enum SessionState { Expired, } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Debug)] pub struct SessionMetrics { pub send_pkts: u64, pub send_bytes: u64, @@ -35,7 +35,7 @@ pub struct SessionMetrics { pub recv_bytes: u64, } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Debug)] struct SessionTimeStamp { ts_start: i64, ts_end: i64, @@ -49,7 +49,7 @@ struct SessionTimeStamp { * - if current packet is iterm of session, require packet lifetime > session lifetime ******************************************************************************/ -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Debug)] pub struct Session { session_id: String, session_proto: SessionProto, @@ -132,8 +132,8 @@ impl Session { self.session_metrics_c2s.recv_bytes += recv_bytes; } - pub fn get_session_c2s_metrics(&self) -> SessionMetrics { - self.session_metrics_c2s + pub fn get_session_c2s_metrics(&self) -> &SessionMetrics { + &self.session_metrics_c2s } pub fn inc_session_s2c_metrics( @@ -149,8 +149,8 @@ impl Session { self.session_metrics_s2c.recv_bytes += recv_bytes; } - pub fn get_session_s2c_metrics(&self) -> SessionMetrics { - self.session_metrics_s2c + pub fn get_session_s2c_metrics(&self) -> &SessionMetrics { + &self.session_metrics_s2c } pub fn update_session_expire_ts(&mut self) { |
