@@ -84,6 +84,8 @@ static int is_subclassification_real_by_proto(u_int16_t proto)
84
84
return 1 ;
85
85
}
86
86
87
+ /* ***************************************************** */
88
+
87
89
static int is_subclassification_real (struct ndpi_flow_struct * flow )
88
90
{
89
91
/* No previous subclassification */
@@ -92,6 +94,8 @@ static int is_subclassification_real(struct ndpi_flow_struct *flow)
92
94
return is_subclassification_real_by_proto (flow -> detected_protocol_stack [0 ]);
93
95
}
94
96
97
+ /* ***************************************************** */
98
+
95
99
static int is_new_subclassification_better (struct ndpi_detection_module_struct * ndpi_struct ,
96
100
struct ndpi_flow_struct * flow ,
97
101
u_int16_t new_app_proto )
@@ -121,6 +125,7 @@ static int is_new_subclassification_better(struct ndpi_detection_module_struct *
121
125
return 0 ;
122
126
}
123
127
128
+ /* ***************************************************** */
124
129
125
130
static u_int16_t search_into_cache (struct ndpi_detection_module_struct * ndpi_struct ,
126
131
struct ndpi_flow_struct * flow )
@@ -167,6 +172,8 @@ static u_int16_t search_into_cache(struct ndpi_detection_module_struct *ndpi_str
167
172
return NDPI_PROTOCOL_UNKNOWN ;
168
173
}
169
174
175
+ /* ***************************************************** */
176
+
170
177
static void add_to_cache (struct ndpi_detection_module_struct * ndpi_struct ,
171
178
struct ndpi_flow_struct * flow ,
172
179
u_int16_t app_proto )
@@ -187,6 +194,8 @@ static void add_to_cache(struct ndpi_detection_module_struct *ndpi_struct,
187
194
}
188
195
}
189
196
197
+ /* ***************************************************** */
198
+
190
199
static void parse_ip_port_attribute (const u_int8_t * payload , u_int16_t payload_length ,
191
200
int off , u_int16_t real_len , ndpi_address_port * ap ,
192
201
ndpi_address_port * ap_monit )
@@ -238,6 +247,8 @@ static void parse_ip_port_attribute(const u_int8_t *payload, u_int16_t payload_l
238
247
}
239
248
}
240
249
250
+ /* ***************************************************** */
251
+
241
252
static void parse_xor_ip_port_attribute (struct ndpi_detection_module_struct * ndpi_struct ,
242
253
struct ndpi_flow_struct * flow ,
243
254
const u_int8_t * payload , u_int16_t payload_length ,
@@ -354,7 +365,7 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
354
365
u_int32_t transaction_id [3 ];
355
366
356
367
if (payload_length < STUN_HDR_LEN )
357
- return (-1 );
368
+ return (-1 );
358
369
359
370
/* Some really old/legacy stuff */
360
371
if (strncmp ((const char * )payload , "RSP/" , 4 ) == 0 &&
@@ -400,7 +411,7 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
400
411
if (packet -> tcp ) {
401
412
if (msg_len + STUN_HDR_LEN > payload_length )
402
413
return 0 ;
403
-
414
+
404
415
payload_length = msg_len + STUN_HDR_LEN ;
405
416
}
406
417
@@ -531,7 +542,7 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
531
542
if (flow -> host_server_name [0 ] == '\0' ) {
532
543
int i ;
533
544
bool valid = true;
534
-
545
+
535
546
ndpi_hostname_sni_set (flow , payload + off + 4 , ndpi_min (len , payload_length - off - 4 ), NDPI_HOSTNAME_NORM_ALL );
536
547
NDPI_LOG_DBG (ndpi_struct , "Realm [%s]\n" , flow -> host_server_name );
537
548
@@ -604,6 +615,7 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
604
615
& flow -> stun .mapped_address ,
605
616
flow -> monit ? & flow -> monit -> protos .dtls_stun_rtp .mapped_address : NULL ,
606
617
transaction_id , magic_cookie , 0 );
618
+ flow -> stun .num_mapped_address ++ ;
607
619
}
608
620
break ;
609
621
@@ -614,6 +626,7 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
614
626
& flow -> stun .relayed_address ,
615
627
flow -> monit ? & flow -> monit -> protos .dtls_stun_rtp .relayed_address : NULL ,
616
628
transaction_id , magic_cookie , 0 );
629
+ flow -> stun .num_relayed_address ++ ;
617
630
}
618
631
break ;
619
632
@@ -634,18 +647,35 @@ static int keep_extra_dissection(struct ndpi_detection_module_struct *ndpi_struc
634
647
struct ndpi_flow_struct * flow )
635
648
{
636
649
/* We want extra dissection for:
637
- * sub-classification
638
- * metadata extraction (*-ADDRESS) or looking for RTP
639
- At the moment:
640
- * it seems ZOOM doens't have any meaningful attributes
641
- * we want (all) XOR-PEER-ADDRESS only for Telegram.
642
- * for the other protocols, we stop after we have all metadata (if enabled)
643
- * for some specific protocol, we might know that some attributes
644
- are never used
645
-
646
- **After** extra dissection is ended, we might move to monitoring. Note that:
647
- * classification doesn't change while in monitoring!
648
- */
650
+ * sub-classification
651
+ * metadata extraction (*-ADDRESS) or looking for RTP
652
+ At the moment:
653
+ * it seems ZOOM doens't have any meaningful attributes
654
+ * we want (all) XOR-PEER-ADDRESS only for Telegram.
655
+ * for the other protocols, we stop after we have all metadata (if enabled)
656
+ * for some specific protocol, we might know that some attributes
657
+ are never used
658
+
659
+ **After** extra dissection is ended, we might move to monitoring. Note that:
660
+ * classification doesn't change while in monitoring!
661
+ */
662
+
663
+ struct ndpi_packet_struct * packet = & ndpi_struct -> packet ;
664
+ bool is_stun_pkt = true;
665
+
666
+ if ((packet -> payload [0 ] != 0x0 ) && (packet -> payload [0 ] != 0x1 ))
667
+ flow -> stun .num_non_stun_pkts ++ , is_stun_pkt = false;
668
+
669
+ if (flow -> packet_counter > 1 ) {
670
+ if ((flow -> stun .last_first_byte != 0x0 ) && (flow -> stun .last_first_byte != 0x1 )) {
671
+ if (is_stun_pkt )
672
+ flow -> stun .num_stun_transitions ++ ;
673
+ } else {
674
+ if (!is_stun_pkt )
675
+ flow -> stun .num_stun_transitions ++ ;
676
+ }
677
+ }
678
+ flow -> stun .last_first_byte = packet -> payload [0 ];
649
679
650
680
if (flow -> monitoring )
651
681
return 1 ;
@@ -705,6 +735,8 @@ static int keep_extra_dissection(struct ndpi_detection_module_struct *ndpi_struc
705
735
return 1 ;
706
736
}
707
737
738
+ /* ***************************************************** */
739
+
708
740
static u_int32_t __get_master (struct ndpi_flow_struct * flow ) {
709
741
710
742
if (flow -> detected_protocol_stack [1 ] != NDPI_PROTOCOL_UNKNOWN )
@@ -714,6 +746,8 @@ static u_int32_t __get_master(struct ndpi_flow_struct *flow) {
714
746
return NDPI_PROTOCOL_STUN ;
715
747
}
716
748
749
+ /* ***************************************************** */
750
+
717
751
static int stun_search_again (struct ndpi_detection_module_struct * ndpi_struct ,
718
752
struct ndpi_flow_struct * flow )
719
753
{
@@ -1082,13 +1116,12 @@ void switch_extra_dissection_to_stun(struct ndpi_detection_module_struct *ndpi_s
1082
1116
1083
1117
/* ************************************************************ */
1084
1118
1085
-
1086
1119
static void ndpi_search_stun (struct ndpi_detection_module_struct * ndpi_struct , struct ndpi_flow_struct * flow )
1087
1120
{
1088
1121
struct ndpi_packet_struct * packet = & ndpi_struct -> packet ;
1089
1122
u_int16_t app_proto ;
1090
1123
int rc ;
1091
-
1124
+
1092
1125
NDPI_LOG_DBG (ndpi_struct , "search stun\n" );
1093
1126
1094
1127
app_proto = NDPI_PROTOCOL_UNKNOWN ;
@@ -1101,7 +1134,7 @@ static void ndpi_search_stun(struct ndpi_detection_module_struct *ndpi_struct, s
1101
1134
}
1102
1135
1103
1136
rc = is_stun (ndpi_struct , flow , & app_proto );
1104
-
1137
+
1105
1138
if (rc == 1 ) {
1106
1139
ndpi_int_stun_add_connection (ndpi_struct , flow , app_proto , __get_master (flow ));
1107
1140
return ;
@@ -1112,6 +1145,8 @@ static void ndpi_search_stun(struct ndpi_detection_module_struct *ndpi_struct, s
1112
1145
NDPI_EXCLUDE_PROTO (ndpi_struct , flow );
1113
1146
}
1114
1147
1148
+ /* ************************************************************ */
1149
+
1115
1150
void init_stun_dissector (struct ndpi_detection_module_struct * ndpi_struct , u_int32_t * id ) {
1116
1151
ndpi_set_bitmask_protocol_detection ("STUN" , ndpi_struct , * id ,
1117
1152
NDPI_PROTOCOL_STUN ,
0 commit comments