|
|
|
|
@ -39,6 +39,7 @@ |
|
|
|
|
#include "ns_ioalib_impl.h" |
|
|
|
|
|
|
|
|
|
#include "ns_turn_openssl.h" |
|
|
|
|
#include "prom_server.h" |
|
|
|
|
|
|
|
|
|
#include <pthread.h> |
|
|
|
|
|
|
|
|
|
@ -62,6 +63,8 @@ typedef uint16_t in_port_t; |
|
|
|
|
|
|
|
|
|
#define MAX_SINGLE_UDP_BATCH (16) |
|
|
|
|
|
|
|
|
|
static int packetcounter = 1; |
|
|
|
|
|
|
|
|
|
struct dtls_listener_relay_server_info { |
|
|
|
|
char ifname[1025]; |
|
|
|
|
ioa_addr addr; |
|
|
|
|
@ -130,6 +133,33 @@ int get_dtls_version(const unsigned char *buf, int len) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static size_t print_packet_txt2pcap(uint64_t now, uint8_t *payload, size_t payload_length, uint8_t *txt2pcap, |
|
|
|
|
size_t txt2pcap_length) { |
|
|
|
|
|
|
|
|
|
size_t index = 0; |
|
|
|
|
int64_t remaining = now % (24 * 60 * 60 * 1000); |
|
|
|
|
int hours = remaining / (60 * 60 * 1000); |
|
|
|
|
remaining = remaining % (60 * 60 * 1000); |
|
|
|
|
int minutes = remaining / (60 * 1000); |
|
|
|
|
remaining = remaining % (60 * 1000); |
|
|
|
|
int seconds = remaining / 1000; |
|
|
|
|
int ms = remaining % 1000; |
|
|
|
|
|
|
|
|
|
snprintf((char *)(txt2pcap + index), txt2pcap_length - index, "%02d:%02d:%02d.%03d", hours, minutes, seconds, ms); |
|
|
|
|
|
|
|
|
|
index += sizeof("00:00:00.000") - 1; |
|
|
|
|
snprintf((char *)(txt2pcap + index), txt2pcap_length - index, " 0000"); |
|
|
|
|
index += sizeof(" 0000") - 1; |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < payload_length; i++) { |
|
|
|
|
snprintf((char *)(txt2pcap + index), txt2pcap_length - index, " %02x", payload[i]); |
|
|
|
|
index += 3; |
|
|
|
|
} |
|
|
|
|
snprintf((char *)(txt2pcap + index), txt2pcap_length - index, " # STUN_PACKET "); |
|
|
|
|
index += sizeof(" # STUN_PACKET "); |
|
|
|
|
return index; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///////////// utils /////////////////////
|
|
|
|
|
|
|
|
|
|
#if DTLS_SUPPORTED |
|
|
|
|
@ -695,6 +725,7 @@ start_udp_cycle: |
|
|
|
|
} |
|
|
|
|
ioa_network_buffer_delete(server->e, server->sm.m.sm.nd.nbh); |
|
|
|
|
server->sm.m.sm.nd.nbh = NULL; |
|
|
|
|
prom_inc_packet_dropped(); |
|
|
|
|
FUNCEND; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
@ -704,21 +735,44 @@ start_udp_cycle: |
|
|
|
|
int rc = 0; |
|
|
|
|
ioa_network_buffer_set_size(elem, (size_t)bsize); |
|
|
|
|
|
|
|
|
|
if (server->connect_cb) { |
|
|
|
|
// Do minimal validation on the received UDP packet
|
|
|
|
|
// stun_is_channel_message_str and stun_is_command_message_str
|
|
|
|
|
size_t blen = bsize; |
|
|
|
|
uint16_t chnum = 0; |
|
|
|
|
uint8_t *data = ioa_network_buffer_data(elem); |
|
|
|
|
|
|
|
|
|
rc = create_new_connected_udp_socket(server, s); |
|
|
|
|
if (rc < 0) { |
|
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot handle UDP packet, size %d\n", (int)bsize); |
|
|
|
|
if ((turn_params.drop_invalid_packets && !stun_is_channel_message_str(data, &blen, &chnum, false) && |
|
|
|
|
!stun_is_command_message_str(data, blen)) |
|
|
|
|
#if DTLS_SUPPORTED |
|
|
|
|
|| (!turn_params.no_dtls && !is_dtls_message(data, blen)) |
|
|
|
|
#endif |
|
|
|
|
) { |
|
|
|
|
packetcounter++; |
|
|
|
|
if (packetcounter % 1000 == 0) { |
|
|
|
|
uint8_t txt2pcap[1000]; // 1000 is enough to print ~300B packet (3 chars per byte) with extras
|
|
|
|
|
print_packet_txt2pcap(packetcounter, data, blen, txt2pcap, sizeof(txt2pcap)); |
|
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_DEBUG, "TXT2PCAP: %s\n", txt2pcap); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
prom_inc_packet_dropped(); |
|
|
|
|
} else { |
|
|
|
|
server->sm.m.sm.s = s; |
|
|
|
|
rc = handle_udp_packet(server, &(server->sm), server->e, server->ts); |
|
|
|
|
} |
|
|
|
|
prom_inc_packet_processed(); |
|
|
|
|
|
|
|
|
|
if (rc < 0) { |
|
|
|
|
if (eve(server->e->verbose)) { |
|
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot handle UDP event\n"); |
|
|
|
|
if (server->connect_cb) { |
|
|
|
|
|
|
|
|
|
rc = create_new_connected_udp_socket(server, s); |
|
|
|
|
if (rc < 0) { |
|
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot handle UDP packet, size %d\n", (int)bsize); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
server->sm.m.sm.s = s; |
|
|
|
|
rc = handle_udp_packet(server, &(server->sm), server->e, server->ts); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (rc < 0) { |
|
|
|
|
if (eve(server->e->verbose)) { |
|
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot handle UDP event\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|