]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
parse error response for code to only change roles on 487
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 27 Jun 2013 18:00:20 +0000 (13:00 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 27 Jun 2013 18:00:20 +0000 (13:00 -0500)
src/include/switch_stun.h
src/switch_rtp.c
src/switch_stun.c

index fdf1fbd74dba345ba6e4de8db20668d4a8870d17..b6de510159697ab1a640c72f9be4cf6c7d029eab 100644 (file)
@@ -142,6 +142,27 @@ typedef struct {
 } switch_stun_ip_t;
 
 
+#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
+
+typedef struct {
+       unsigned padding:21;
+       unsigned code:3;
+       unsigned number:8;
+       char reason[764];
+} switch_stun_error_code_t;
+
+#else
+
+typedef struct {
+       unsigned number:8;
+       unsigned code:3;
+       unsigned padding:21;
+       char reason[764];
+} switch_stun_error_code_t;
+
+#endif
+
+
 /*!
   \brief Writes random characters into a buffer
   \param buf the buffer
index cc735639680e63ffd1414ab634c8c3dd01d0e351..821c3753843b82137d01037d141b6579dcda9789 100644 (file)
@@ -227,7 +227,6 @@ typedef struct {
        uint8_t ready;
        uint8_t rready;
        int missed_count;
-       int flips;
        char last_sent_id[12];
 } switch_rtp_ice_t;
 
@@ -784,27 +783,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
 
        }
 
-
-       if (packet->header.type == SWITCH_STUN_BINDING_ERROR_RESPONSE) {
-               if ((ice->type & ICE_VANILLA)) {
-                       if (ice->flips < 4) {
-                               if ((ice->type & ICE_CONTROLLED)) {
-                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "Changing role to CONTROLLING\n");
-                                       ice->type &= ~ICE_CONTROLLED;
-                                       ice->flips++;
-                               } else {
-                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "Changing role to CONTROLLED\n");
-                                       ice->type |= ICE_CONTROLLED;
-                                       ice->flips++;
-                               }
-                               packet->header.type = SWITCH_STUN_BINDING_RESPONSE;
-                       }
-               }
-
-       } else {
-               ice->flips = 0;
-       }
-
        end_buf = buf + ((sizeof(buf) > packet->header.length) ? packet->header.length : sizeof(buf));
 
        rtp_session->last_stun = switch_micro_time_now();
@@ -813,6 +791,30 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
 
        do {
                switch (attr->type) {
+               case SWITCH_STUN_ATTR_ERROR_CODE:
+                       {
+                               switch_stun_error_code_t *err = (switch_stun_error_code_t *) attr->value;
+                               uint32_t code = (err->code * 100) + err->number;
+
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "%s got stun binding response %u %s\n",
+                                                                 switch_core_session_get_name(rtp_session->session),
+                                                                 code,
+                                                                 err->reason
+                                                                 );
+
+                               if ((ice->type & ICE_VANILLA) && code == 487) {
+                                       if ((ice->type & ICE_CONTROLLED)) {
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "Changing role to CONTROLLING\n");
+                                               ice->type &= ~ICE_CONTROLLED;
+                                       } else {
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "Changing role to CONTROLLED\n");
+                                               ice->type |= ICE_CONTROLLED;
+                                       }
+                                       packet->header.type = SWITCH_STUN_BINDING_RESPONSE;
+                               }
+
+                       }
+                       break;
                case SWITCH_STUN_ATTR_MAPPED_ADDRESS:
                        if (attr->type) {
                                char ip[16];
index f2af463f150294277c5be142e82ba3da9d224229..8be191e782915d95579973609dab329222d68227 100644 (file)
@@ -257,11 +257,16 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
                                *val = ntohl(*val);     /* should we do this here? */
                        }
                        break;
+               case SWITCH_STUN_ATTR_ERROR_CODE:       /* ErrorCode */
+                       {
+                               uint32_t *u = (uint32_t *) attr->value;
+                               *u = htonl(*u);
+                       }
+                       break;
 
                case SWITCH_STUN_ATTR_USERNAME: /* ByteString, multiple of 4 bytes */
                case SWITCH_STUN_ATTR_PASSWORD: /* ByteString, multiple of 4 bytes */
                case SWITCH_STUN_ATTR_DATA:     /* ByteString */
-               case SWITCH_STUN_ATTR_ERROR_CODE:       /* ErrorCode */
                case SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES:    /* TransportPrefs */
                        /*
                         * No length checking here, since we already checked against the padded length