Skip to content

Commit bccc30f

Browse files
committed
feat: support icmp close type
1 parent 51488c1 commit bccc30f

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

agent/src/collector/quadruple_generator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ impl QuadrupleGenerator {
986986
| CloseType::TcpFin
987987
| CloseType::Unknown
988988
| CloseType::TcpFinClientRst
989+
| CloseType::IcmpUnknown
989990
| CloseType::Max => (),
990991
}
991992
}

agent/src/common/flow.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ pub enum CloseType {
7777
ClientEstablishReset = 18, // 18: 建连-客户端其他重置
7878
ServerEstablishReset = 19, // 19: 建连-服务端其他重置
7979
TcpFinClientRst = 20, // 20: 正常结束-客户端重置
80-
Max = 21,
80+
IcmpUnknown = 21, // 21: TODO
81+
Max = 22,
8182
}
8283

8384
impl CloseType {
@@ -87,6 +88,7 @@ impl CloseType {
8788
|| self == CloseType::ClientHalfClose
8889
|| self == CloseType::ClientSourcePortReuse
8990
|| self == CloseType::ClientEstablishReset
91+
|| self == CloseType::IcmpUnknown
9092
}
9193

9294
pub fn is_server_error(self) -> bool {
@@ -1070,7 +1072,21 @@ impl Flow {
10701072
FlowState::Exception => CloseType::Unknown,
10711073
FlowState::Opening1 => CloseType::ClientSynRepeat,
10721074
FlowState::Opening2 => CloseType::ServerSynAckRepeat,
1073-
FlowState::Established => CloseType::Timeout,
1075+
FlowState::Established => {
1076+
if self.flow_key.proto == IpProtocol::ICMPV4
1077+
|| self.flow_key.proto == IpProtocol::ICMPV6
1078+
{
1079+
if self.flow_metrics_peers[0].total_packet_count
1080+
!= self.flow_metrics_peers[1].total_packet_count
1081+
{
1082+
CloseType::IcmpUnknown
1083+
} else {
1084+
CloseType::Timeout
1085+
}
1086+
} else {
1087+
CloseType::Timeout
1088+
}
1089+
}
10741090
FlowState::ClosingTx1 => CloseType::ServerHalfClose,
10751091
FlowState::ClosingRx1 => CloseType::ClientHalfClose,
10761092
FlowState::ClosingTx2 | FlowState::ClosingRx2 | FlowState::Closed => CloseType::TcpFin,

agent/src/flow_generator/flow_config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub const TIMEOUT_OTHERS: Timestamp = Timestamp::from_secs(5);
2626
pub const TIMEOUT_ESTABLISHED: Timestamp = Timestamp::from_secs(300);
2727
pub const TIMEOUT_CLOSING: Timestamp = Timestamp::from_secs(35);
2828
pub const TIMEOUT_OPENING_RST: Timestamp = Timestamp::from_secs(1);
29+
pub const TIMEOUT_ICMP: Timestamp = Timestamp::from_secs(5);
2930

3031
pub struct TcpTimeout {
3132
pub established: Timestamp,
@@ -55,6 +56,7 @@ pub struct FlowTimeout {
5556
pub closed_fin: Timestamp,
5657
pub single_direction: Timestamp,
5758
pub opening_rst: Timestamp,
59+
pub icmp_timeout: Timestamp,
5860

5961
pub min: Timestamp,
6062
pub max: Timestamp, // time window
@@ -71,6 +73,8 @@ impl From<TcpTimeout> for FlowTimeout {
7173
closed_fin: Timestamp::from_secs(2),
7274
single_direction: t.others,
7375
opening_rst: t.opening_rst,
76+
icmp_timeout: TIMEOUT_ICMP,
77+
7478
min: Timestamp::from_secs(0),
7579
max: Timestamp::from_secs(0),
7680
};

agent/src/flow_generator/flow_map.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,11 @@ impl FlowMap {
915915
) -> bool {
916916
self.update_flow(config, node, meta_packet);
917917
let peers = &node.tagged_flow.flow.flow_metrics_peers;
918-
if peers[FLOW_METRICS_PEER_SRC].packet_count > 0
918+
if node.tagged_flow.flow.flow_key.proto == IpProtocol::ICMPV4
919+
|| node.tagged_flow.flow.flow_key.proto == IpProtocol::ICMPV6
920+
{
921+
node.timeout = config.flow.flow_timeout.icmp_timeout;
922+
} else if peers[FLOW_METRICS_PEER_SRC].packet_count > 0
919923
&& peers[FLOW_METRICS_PEER_DST].packet_count > 0
920924
{
921925
node.timeout = config.flow.flow_timeout.established_rst;

server/libs/datatype/flow.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ const (
6969
CloseTypeClientEstablishReset // 18: 建连-客户端其他重置
7070
CloseTypeServerEstablishReset // 19: 建连-服务端其他重置
7171
CloseTypeTCPFinClientRst // 20: 正常结束-客户端重置
72+
CloseTypeIcmpUnknown // 21: TODO
7273
MaxCloseType
7374
)
7475

7576
func (t CloseType) IsClientError() bool {
7677
return t == CloseTypeClientSYNRepeat || t == CloseTypeTCPClientRst ||
7778
t == CloseTypeClientHalfClose || t == CloseTypeClientSourcePortReuse ||
78-
t == CloseTypeClientEstablishReset
79+
t == CloseTypeClientEstablishReset || t == CloseTypeIcmpUnknown
7980
}
8081

8182
func (t CloseType) IsServerError() bool {

0 commit comments

Comments
 (0)