Skip to content

Commit

Permalink
STUN counter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Nov 29, 2024
1 parent 74792e4 commit b1d1f8c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 27 deletions.
8 changes: 0 additions & 8 deletions example/reader_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1198,10 +1198,6 @@ static void process_ndpi_monitoring_info(struct ndpi_flow_info *flow) {
add_to_address_port_list(&flow->stun.peer_address, &flow->ndpi_flow->monit->protos.dtls_stun_rtp.peer_address);
add_to_address_port_list(&flow->stun.relayed_address, &flow->ndpi_flow->monit->protos.dtls_stun_rtp.relayed_address);
add_to_address_port_list(&flow->stun.response_origin, &flow->ndpi_flow->monit->protos.dtls_stun_rtp.response_origin);
flow->stun.num_mapped_address = flow->ndpi_flow->stun.num_mapped_address;
flow->stun.num_relayed_address = flow->ndpi_flow->stun.num_relayed_address;
flow->stun.num_non_stun_pkts = flow->ndpi_flow->stun.num_non_stun_pkts;
flow->stun.num_stun_transitions = flow->ndpi_flow->stun.num_stun_transitions;
flow->multimedia_flow_types |= flow->ndpi_flow->flow_multimedia_types;
}
}
Expand Down Expand Up @@ -1609,10 +1605,6 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
add_to_address_port_list(&flow->stun.relayed_address, &flow->ndpi_flow->stun.relayed_address);
add_to_address_port_list(&flow->stun.response_origin, &flow->ndpi_flow->stun.response_origin);
add_to_address_port_list(&flow->stun.other_address, &flow->ndpi_flow->stun.other_address);
flow->stun.num_mapped_address = flow->ndpi_flow->stun.num_mapped_address;
flow->stun.num_relayed_address = flow->ndpi_flow->stun.num_relayed_address;
flow->stun.num_non_stun_pkts = flow->ndpi_flow->stun.num_non_stun_pkts;
flow->stun.num_stun_transitions = flow->ndpi_flow->stun.num_stun_transitions;
}

flow->multimedia_flow_types |= flow->ndpi_flow->flow_multimedia_types;
Expand Down
1 change: 0 additions & 1 deletion example/reader_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ typedef struct ndpi_flow_info {
struct {
ndpi_address_port_list mapped_address, peer_address,
relayed_address, response_origin, other_address;
u_int8_t num_mapped_address, num_relayed_address, num_non_stun_pkts, num_stun_transitions;
} stun;

struct {
Expand Down
3 changes: 2 additions & 1 deletion src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,8 @@ struct ndpi_flow_struct {
struct {
u_int8_t maybe_dtls : 1, is_turn : 1, pad : 6;
ndpi_address_port mapped_address, peer_address, relayed_address, response_origin, other_address;
u_int8_t num_mapped_address, num_relayed_address, num_non_stun_pkts, last_first_byte, num_stun_transitions; /* SRTP */
u_int8_t num_xor_relayed_addresses, num_xor_mapped_addresses;
u_int8_t num_non_stun_pkt, non_stun_pkt_len[2];
} stun;

struct {
Expand Down
25 changes: 8 additions & 17 deletions src/lib/protocols/stun.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
&flow->stun.mapped_address,
flow->monit ? &flow->monit->protos.dtls_stun_rtp.mapped_address : NULL,
transaction_id, magic_cookie, 0);
flow->stun.num_mapped_address++;
flow->stun.num_xor_mapped_addresses++;
}
break;

Expand All @@ -628,7 +628,7 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
&flow->stun.relayed_address,
flow->monit ? &flow->monit->protos.dtls_stun_rtp.relayed_address : NULL,
transaction_id, magic_cookie, 0);
flow->stun.num_relayed_address++;
flow->stun.num_xor_relayed_addresses++;
}
break;

Expand Down Expand Up @@ -664,22 +664,13 @@ static int keep_extra_dissection(struct ndpi_detection_module_struct *ndpi_struc
* classification doesn't change while in monitoring!
*/

if(packet->payload_packet_len > 0) {
bool is_stun_pkt = true;
if((packet->payload[0] != 0x0) && (packet->payload[0] != 0x1)) {
if(flow->stun.num_non_stun_pkt < 2) {
flow->stun.non_stun_pkt_len[flow->stun.num_non_stun_pkt++] = packet->payload_packet_len;

if((packet->payload[0] != 0x0) && (packet->payload[0] != 0x1))
flow->stun.num_non_stun_pkts++, is_stun_pkt = false;

if(flow->packet_counter > 1) {
if((flow->stun.last_first_byte != 0x0) && (flow->stun.last_first_byte != 0x1)) {
if(is_stun_pkt)
flow->stun.num_stun_transitions++;
} else {
if(!is_stun_pkt)
flow->stun.num_stun_transitions++;
}
}
flow->stun.last_first_byte = packet->payload[0];
if(flow->stun.num_non_stun_pkt == 2)
printf("%d %d\n", flow->stun.non_stun_pkt_len[0], flow->stun.non_stun_pkt_len[1]);
}
}

if(flow->monitoring)
Expand Down

0 comments on commit b1d1f8c

Please sign in to comment.