Commit ad7a393f authored by Ghislain MARY's avatar Ghislain MARY

Handle IPv6 in ICE and TURN.

parent b4d738ca
......@@ -146,6 +146,7 @@ typedef struct _IceStunServerRequest {
MSStunAddress peer_address;
uint16_t channel_number;
uint16_t stun_method;
uint8_t requested_address_family;
bool_t gathering;
bool_t responded;
bool_t to_remove;
......
......@@ -47,41 +47,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MS_TURN_METHOD_CHANNEL_BIND 0x009
#define MS_STUN_ATTR_MAPPED_ADDRESS 0x0001
#define MS_STUN_ATTR_RESPONSE_ADDRESS 0x0002 /* Deprecated, now reserved */
#define MS_STUN_ATTR_CHANGE_REQUEST 0x0003 /* Deprecated, now reserved */
#define MS_STUN_ATTR_SOURCE_ADDRESS 0x0004 /* Deprecated, now reserved */
#define MS_STUN_ATTR_CHANGED_ADDRESS 0x0005 /* Deprecated, now reserved */
#define MS_STUN_ATTR_USERNAME 0x0006
#define MS_STUN_ATTR_PASSWORD 0x0007 /* Deprecated, now reserved */
#define MS_STUN_ATTR_MESSAGE_INTEGRITY 0x0008
#define MS_STUN_ATTR_ERROR_CODE 0x0009
#define MS_STUN_ATTR_UNKNOWN_ATTRIBUTES 0x000A
#define MS_STUN_ATTR_REFLECTED_FROM 0x000B
#define MS_STUN_ATTR_REALM 0x0014
#define MS_STUN_ATTR_NONCE 0x0015
#define MS_STUN_ATTR_XOR_MAPPED_ADDRESS 0x0020
#define MS_STUN_ATTR_SOFTWARE 0x8022
#define MS_STUN_ATTR_ALTERNATE_SERVER 0x8023
#define MS_STUN_ATTR_FINGERPRINT 0x8028
#define MS_TURN_ATTR_CHANNEL_NUMBER 0x000C
#define MS_TURN_ATTR_LIFETIME 0x000D
#define MS_TURN_ATTR_BANDWIDTH 0x0010 /* Deprecated, now reserved */
#define MS_TURN_ATTR_XOR_PEER_ADDRESS 0x0012
#define MS_TURN_ATTR_DATA 0x0013
#define MS_TURN_ATTR_XOR_RELAYED_ADDRESS 0x0016
#define MS_TURN_ATTR_EVEN_PORT 0x0018
#define MS_TURN_ATTR_REQUESTED_TRANSPORT 0x0019
#define MS_TURN_ATTR_DONT_FRAGMENT 0x001A
#define MS_TURN_ATTR_TIMER_VAL 0x0021 /* Deprecated, now reserved */
#define MS_TURN_ATTR_RESERVATION_TOKEN 0x0022
#define MS_ICE_ATTR_PRIORITY 0x0024
#define MS_ICE_ATTR_USE_CANDIDATE 0x0025
#define MS_ICE_ATTR_ICE_CONTROLLED 0x8029
#define MS_ICE_ATTR_ICE_CONTROLLING 0x802A
#define MS_STUN_ATTR_MAPPED_ADDRESS 0x0001
#define MS_STUN_ATTR_RESPONSE_ADDRESS 0x0002 /* Deprecated, now reserved */
#define MS_STUN_ATTR_CHANGE_REQUEST 0x0003 /* Deprecated, now reserved */
#define MS_STUN_ATTR_SOURCE_ADDRESS 0x0004 /* Deprecated, now reserved */
#define MS_STUN_ATTR_CHANGED_ADDRESS 0x0005 /* Deprecated, now reserved */
#define MS_STUN_ATTR_USERNAME 0x0006
#define MS_STUN_ATTR_PASSWORD 0x0007 /* Deprecated, now reserved */
#define MS_STUN_ATTR_MESSAGE_INTEGRITY 0x0008
#define MS_STUN_ATTR_ERROR_CODE 0x0009
#define MS_STUN_ATTR_UNKNOWN_ATTRIBUTES 0x000A
#define MS_STUN_ATTR_REFLECTED_FROM 0x000B
#define MS_STUN_ATTR_REALM 0x0014
#define MS_STUN_ATTR_NONCE 0x0015
#define MS_STUN_ATTR_XOR_MAPPED_ADDRESS 0x0020
#define MS_STUN_ATTR_SOFTWARE 0x8022
#define MS_STUN_ATTR_ALTERNATE_SERVER 0x8023
#define MS_STUN_ATTR_FINGERPRINT 0x8028
#define MS_TURN_ATTR_CHANNEL_NUMBER 0x000C
#define MS_TURN_ATTR_LIFETIME 0x000D
#define MS_TURN_ATTR_BANDWIDTH 0x0010 /* Deprecated, now reserved */
#define MS_TURN_ATTR_XOR_PEER_ADDRESS 0x0012
#define MS_TURN_ATTR_DATA 0x0013
#define MS_TURN_ATTR_XOR_RELAYED_ADDRESS 0x0016
#define MS_TURN_ATTR_REQUESTED_ADDRESS_FAMILY 0x0017
#define MS_TURN_ATTR_EVEN_PORT 0x0018
#define MS_TURN_ATTR_REQUESTED_TRANSPORT 0x0019
#define MS_TURN_ATTR_DONT_FRAGMENT 0x001A
#define MS_TURN_ATTR_TIMER_VAL 0x0021 /* Deprecated, now reserved */
#define MS_TURN_ATTR_RESERVATION_TOKEN 0x0022
#define MS_ICE_ATTR_PRIORITY 0x0024
#define MS_ICE_ATTR_USE_CANDIDATE 0x0025
#define MS_ICE_ATTR_ICE_CONTROLLED 0x8029
#define MS_ICE_ATTR_ICE_CONTROLLING 0x802A
#define MS_STUN_ERROR_CODE_TRY_ALTERNATE 300
......@@ -151,6 +152,7 @@ typedef struct {
uint16_t channel_number;
uint16_t data_length;
uint8_t requested_transport;
uint8_t requested_address_family;
bool_t include_username_attribute;
bool_t has_error_code;
bool_t has_message_integrity;
......@@ -167,6 +169,7 @@ typedef struct {
bool_t has_lifetime;
bool_t has_channel_number;
bool_t has_requested_transport;
bool_t has_requested_address_family;
} MSStunMessage;
typedef enum {
......@@ -306,6 +309,9 @@ MS2_PUBLIC MSStunMessage * ms_turn_send_indication_create(MSStunAddress peer_add
MS2_PUBLIC MSStunMessage * ms_turn_channel_bind_request_create(MSStunAddress peer_address, uint16_t channel_number);
MS2_PUBLIC bool_t ms_stun_message_has_requested_transport(const MSStunMessage *msg);
MS2_PUBLIC uint8_t ms_stun_message_get_requested_transport(const MSStunMessage *msg);
MS2_PUBLIC bool_t ms_stun_message_has_requested_address_family(const MSStunMessage *msg);
MS2_PUBLIC uint8_t ms_stun_message_get_requested_address_family(const MSStunMessage *msg);
MS2_PUBLIC void ms_stun_message_set_requested_address_family(MSStunMessage *msg, uint8_t family);
MS2_PUBLIC bool_t ms_stun_message_has_lifetime(const MSStunMessage *msg);
MS2_PUBLIC uint32_t ms_stun_message_get_lifetime(const MSStunMessage *msg);
MS2_PUBLIC void ms_stun_message_set_lifetime(MSStunMessage *msg, uint32_t lifetime);
......
This diff is collapsed.
......@@ -282,6 +282,14 @@ static void encode_requested_transport(StunMessageEncoder *encoder, uint8_t requ
encode16(encoder, 0);
}
static void encode_requested_address_family(StunMessageEncoder *encoder, uint8_t family) {
encode16(encoder, MS_TURN_ATTR_REQUESTED_ADDRESS_FAMILY);
encode16(encoder, 4);
encode8(encoder, family);
encode8(encoder, 0);
encode16(encoder, 0);
}
static void encode_lifetime(StunMessageEncoder *encoder, uint32_t lifetime) {
encode16(encoder, MS_TURN_ATTR_LIFETIME);
encode16(encoder, 4);
......@@ -389,7 +397,7 @@ static MSStunAddress decode_addr(StunMessageDecoder *decoder, uint16_t length) {
MSStunAddress stun_addr;
memset(&stun_addr, 0, sizeof(stun_addr));
if (length != 8) {
if ((length != 8) && (length != 20)) {
ms_warning("STUN address attribute with wrong length");
decoder->error = TRUE;
goto error;
......@@ -595,6 +603,7 @@ MSStunAddress ms_ip_address_to_stun_address(int ai_family, int socktype, const c
void ms_stun_address_to_ip_address(const MSStunAddress *stun_address, char *ip, size_t ip_size, int *port) {
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(addr);
memset(&addr, 0, addrlen);
ms_stun_address_to_sockaddr(stun_address, (struct sockaddr *)&addr, &addrlen);
bctbx_sockaddr_to_ip_address((struct sockaddr *)&addr, addrlen, ip, ip_size, port);
}
......@@ -602,6 +611,7 @@ void ms_stun_address_to_ip_address(const MSStunAddress *stun_address, char *ip,
void ms_stun_address_to_printable_ip_address(const MSStunAddress *stun_address, char *printable_ip, size_t printable_ip_size) {
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(addr);
memset(&addr, 0, addrlen);
ms_stun_address_to_sockaddr(stun_address, (struct sockaddr *)&addr, &addrlen);
bctbx_sockaddr_to_printable_ip_address((struct sockaddr *)&addr, addrlen, printable_ip, printable_ip_size);
}
......@@ -943,6 +953,7 @@ size_t ms_stun_message_encode(const MSStunMessage *msg, char **buf) {
stun_addr = ms_stun_message_get_xor_relayed_address(msg);
if (stun_addr != NULL) encode_xor_addr(&encoder, MS_TURN_ATTR_XOR_RELAYED_ADDRESS, stun_addr, &msg->tr_id);
if (ms_stun_message_has_requested_transport(msg)) encode_requested_transport(&encoder, ms_stun_message_get_requested_transport(msg));
if (ms_stun_message_has_requested_address_family(msg)) encode_requested_address_family(&encoder, ms_stun_message_get_requested_address_family(msg));
if (ms_stun_message_has_lifetime(msg)) encode_lifetime(&encoder, ms_stun_message_get_lifetime(msg));
if (ms_stun_message_has_channel_number(msg)) encode_channel_number(&encoder, ms_stun_message_get_channel_number(msg));
if ((ms_stun_message_get_data(msg) != NULL) && (ms_stun_message_get_data_length(msg) > 0))
......@@ -1243,6 +1254,19 @@ uint8_t ms_stun_message_get_requested_transport(const MSStunMessage *msg) {
return msg->requested_transport;
}
bool_t ms_stun_message_has_requested_address_family(const MSStunMessage *msg) {
return msg->has_requested_address_family;
}
uint8_t ms_stun_message_get_requested_address_family(const MSStunMessage *msg) {
return msg->requested_address_family;
}
void ms_stun_message_set_requested_address_family(MSStunMessage *msg, uint8_t family) {
msg->requested_address_family = family;
msg->has_requested_address_family = TRUE;
}
bool_t ms_stun_message_has_lifetime(const MSStunMessage *msg) {
return msg->has_lifetime;
}
......@@ -1441,6 +1465,7 @@ static int ms_turn_rtp_endpoint_recvfrom(RtpTransport *rtptp, mblk_t *msg, int f
struct sockaddr_storage relay_ss;
struct sockaddr *relay_sa = (struct sockaddr *)&relay_ss;
socklen_t relay_sa_len = sizeof(relay_ss);
memset(relay_sa, 0, relay_sa_len);
/* Copy the data of the TURN data indication in the mblk_t so that it contains the unpacked data */
msgsize = ms_stun_message_get_data_length(stun_msg);
memcpy(msg->b_rptr, ms_stun_message_get_data(stun_msg), msgsize);
......@@ -1477,6 +1502,7 @@ static bool_t ms_turn_rtp_endpoint_send_via_turn_server(MSTurnContext *context,
struct sockaddr *relay_sa = (struct sockaddr *)&relay_ss;
socklen_t relay_sa_len = sizeof(relay_ss);
memset(relay_sa, 0, relay_sa_len);
ms_stun_address_to_sockaddr(&context->relay_addr, relay_sa, &relay_sa_len);
if (relay_sa->sa_family != from->sa_family) return FALSE;
if (relay_sa->sa_family == AF_INET) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment