@@ -18,21 +18,40 @@ public bool Equals(NetworkService? service1, NetworkService? service2)
1818 return false ;
1919 }
2020
21+ if ( CompareProtTypes ( service1 , service2 ) )
22+ {
23+ return true ;
24+ }
25+
2126 int destPortEnd1 = service1 . DestinationPortEnd ?? service1 . DestinationPort ?? 0 ;
2227 int destPortEnd2 = service2 . DestinationPortEnd ?? service2 . DestinationPort ?? 0 ;
2328
24- return ( ! option . SvcRegardPortAndProt || service1 . ProtoId == service2 . ProtoId
25- && service1 . DestinationPort == service2 . DestinationPort
26- && destPortEnd1 == destPortEnd2 )
29+ return ( ! option . SvcRegardPortAndProt || ( service1 . ProtoId == service2 . ProtoId &&
30+ service1 . DestinationPort == service2 . DestinationPort && destPortEnd1 == destPortEnd2 ) )
2731 && ( ! option . SvcRegardName || service1 . Name == service2 . Name ) ;
2832 }
2933
3034 public int GetHashCode ( NetworkService service )
3135 {
36+ if ( IsProtType ( service . ProtoId ) )
37+ {
38+ return ( option . SvcRegardPortAndProt ? HashCode . Combine ( service . ProtoId ) : 0 )
39+ ^ ( option . SvcRegardName ? HashCode . Combine ( service . Name ) : 0 ) ;
40+ }
3241 int destPortEnd = service . DestinationPortEnd ?? service . DestinationPort ?? 0 ;
3342 return ( option . SvcRegardPortAndProt ? HashCode . Combine ( service . ProtoId , service . DestinationPort , destPortEnd ) : 0 )
3443 ^ ( option . SvcRegardName ? HashCode . Combine ( service . Name ) : 0 ) ;
3544 }
45+
46+ private static bool IsProtType ( int ? protoId )
47+ {
48+ return protoId != null && protoId != 1 && protoId != 6 && protoId != 17 ;
49+ }
50+
51+ private static bool CompareProtTypes ( NetworkService service1 , NetworkService service2 )
52+ {
53+ return IsProtType ( service1 . ProtoId ) && IsProtType ( service2 . ProtoId ) && service1 . ProtoId == service2 . ProtoId ;
54+ }
3655 }
3756
3857 public class NetworkServiceGroupComparer ( RuleRecognitionOption option ) : IEqualityComparer < NetworkService ? >
@@ -57,18 +76,18 @@ public bool Equals(NetworkService? service1, NetworkService? service2)
5776 return false ;
5877 }
5978
60- return service1 . ServiceGroupFlats . ToList ( ) . ConvertAll ( g => g . Object ) . ToList ( )
79+ return service1 . ServiceGroupFlats . ToList ( ) . ConvertAll ( g => g . Object )
6180 . Except ( [ .. service2 . ServiceGroupFlats . ToList ( ) . ConvertAll ( g => g . Object ) ] , networkServiceComparer ) . ToList ( ) . Count == 0
62- && service2 . ServiceGroupFlats . ToList ( ) . ConvertAll ( g => g . Object ) . ToList ( )
81+ && service2 . ServiceGroupFlats . ToList ( ) . ConvertAll ( g => g . Object )
6382 . Except ( [ .. service1 . ServiceGroupFlats . ToList ( ) . ConvertAll ( g => g . Object ) ] , networkServiceComparer ) . ToList ( ) . Count == 0 ;
6483 }
6584
6685 public int GetHashCode ( NetworkService serviceGrp )
6786 {
6887 int hashCode = 0 ;
69- foreach ( var svc in serviceGrp . ServiceGroupFlats . Where ( s => s . Object ? . Type . Name != ServiceType . Group ) . ToList ( ) )
88+ foreach ( var svc in serviceGrp . ServiceGroupFlats . Select ( sg => sg . Object ) . Where ( s => s ? . Type . Name != ServiceType . Group ) . ToList ( ) )
7089 {
71- hashCode ^= ( svc . Object != null ? networkServiceComparer . GetHashCode ( svc . Object ) : 0 ) ;
90+ hashCode ^= svc != null ? networkServiceComparer . GetHashCode ( svc ) : 0 ;
7291 }
7392 return hashCode ^ ( option . SvcRegardGroupName ? HashCode . Combine ( serviceGrp . Name ) : 0 ) ;
7493 }
0 commit comments