@@ -12,14 +12,13 @@ use crate::networking::types::data_info_host::DataInfoHost;
1212use crate :: networking:: types:: info_address_port_pair:: InfoAddressPortPair ;
1313use crate :: networking:: types:: info_traffic:: InfoTraffic ;
1414use crate :: networking:: types:: ip_blacklist:: IpBlacklist ;
15+ use crate :: networking:: types:: message_type:: MessageType ;
1516use crate :: networking:: types:: program:: Program ;
1617use crate :: networking:: types:: service:: Service ;
1718use crate :: networking:: types:: service_query:: ServiceQuery ;
1819use crate :: networking:: types:: traffic_direction:: TrafficDirection ;
1920use crate :: networking:: types:: traffic_type:: TrafficType ;
2021use crate :: utils:: types:: timestamp:: Timestamp ;
21- use sniffnet_packet_parser:: IcmpType ;
22- use sniffnet_packet_parser:: { ArpType , IgmpType } ;
2322use std:: time:: Instant ;
2423
2524include ! ( concat!( env!( "OUT_DIR" ) , "/services.rs" ) ) ;
@@ -76,15 +75,13 @@ pub fn get_service(
7675}
7776
7877/// Function to insert the source and destination of a packet into the map containing the analyzed traffic
79- #[ allow( clippy:: too_many_arguments, clippy :: similar_names ) ]
78+ #[ allow( clippy:: too_many_arguments) ]
8079pub fn modify_or_insert_in_map (
8180 info_traffic_msg : & mut InfoTraffic ,
8281 key : & AddressPortPair ,
8382 my_interface_addresses : & [ Address ] ,
8483 mac_addresses : ( Option < [ u8 ; 6 ] > , Option < [ u8 ; 6 ] > ) ,
85- icmp_type : Option < IcmpType > ,
86- arp_type : Option < ArpType > ,
87- igmp_type : Option < IgmpType > ,
84+ message_type : Option < MessageType > ,
8885 packets : u128 ,
8986 bytes : u128 ,
9087 ip_blacklist : & IpBlacklist ,
@@ -132,27 +129,9 @@ pub fn modify_or_insert_in_map(
132129 info. final_timestamp = final_ts;
133130 }
134131 info. final_instant = Instant :: now ( ) ;
135- if key. protocol . is_icmp ( )
136- && let Some ( icmp_type) = icmp_type
137- {
138- info. icmp_types
139- . entry ( icmp_type)
140- . and_modify ( |n| * n += 1 )
141- . or_insert ( 1 ) ;
142- }
143- if key. protocol . eq ( & Protocol :: Arp )
144- && let Some ( arp_type) = arp_type
145- {
146- info. arp_types
147- . entry ( arp_type)
148- . and_modify ( |n| * n += 1 )
149- . or_insert ( 1 ) ;
150- }
151- if key. protocol . eq ( & Protocol :: Igmp )
152- && let Some ( igmp_type) = igmp_type
153- {
154- info. igmp_types
155- . entry ( igmp_type)
132+ if let Some ( message_type) = message_type {
133+ info. message_types
134+ . entry ( message_type)
156135 . and_modify ( |n| * n += 1 )
157136 . or_insert ( 1 ) ;
158137 }
@@ -167,24 +146,8 @@ pub fn modify_or_insert_in_map(
167146 final_instant : Instant :: now ( ) ,
168147 service,
169148 traffic_direction,
170- icmp_types : if key. protocol . is_icmp ( )
171- && let Some ( icmp_type) = icmp_type
172- {
173- HashMap :: from ( [ ( icmp_type, 1 ) ] )
174- } else {
175- HashMap :: new ( )
176- } ,
177- arp_types : if key. protocol . eq ( & Protocol :: Arp )
178- && let Some ( arp_type) = arp_type
179- {
180- HashMap :: from ( [ ( arp_type, 1 ) ] )
181- } else {
182- HashMap :: new ( )
183- } ,
184- igmp_types : if key. protocol . eq ( & Protocol :: Igmp )
185- && let Some ( igmp_type) = igmp_type
186- {
187- HashMap :: from ( [ ( igmp_type, 1 ) ] )
149+ message_types : if let Some ( message_type) = message_type {
150+ HashMap :: from ( [ ( message_type, 1 ) ] )
188151 } else {
189152 HashMap :: new ( )
190153 } ,
0 commit comments