[asterisk-commits] dvossel: branch dvossel/sip_via_tcp_rework r194525 - /team/dvossel/sip_via_tc...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 14 17:27:10 CDT 2009


Author: dvossel
Date: Thu May 14 17:27:03 2009
New Revision: 194525

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=194525
Log:
If a peer's default transport type changes during a register, when that register expires, the original transport is restored.

Modified:
    team/dvossel/sip_via_tcp_rework/channels/chan_sip.c

Modified: team/dvossel/sip_via_tcp_rework/channels/chan_sip.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/dvossel/sip_via_tcp_rework/channels/chan_sip.c?view=diff&rev=194525&r1=194524&r2=194525
==============================================================================
--- team/dvossel/sip_via_tcp_rework/channels/chan_sip.c (original)
+++ team/dvossel/sip_via_tcp_rework/channels/chan_sip.c Thu May 14 17:27:03 2009
@@ -1909,6 +1909,8 @@
 		AST_STRING_FIELD(engine);               /*!<  RTP Engine to use */
 		);
 	struct sip_socket socket;	/*!< Socket used for this peer */
+	enum sip_transport default_outbound_transport;    /*!< Peer Registration may change the default outbound transport.
+												If register expires, default should be reset. to this value */
 	unsigned int transports:3;      /*!< Transports (enum sip_transport) that are acceptable for this peer */
 	struct sip_auth *auth;		/*!< Realm authentication list */
 	int amaflags;			/*!< AMA Flags (for billing) */
@@ -1923,7 +1925,7 @@
 	int lastmsgssent;
 	unsigned int sipoptions;	/*!<  Supported SIP options */
 	struct ast_flags flags[2];	/*!<  SIP_ flags */
-	
+
 	/*! Mailboxes that this peer cares about */
 	AST_LIST_HEAD_NOLOCK(, sip_mailbox) mailboxes;
 
@@ -1945,7 +1947,7 @@
 	struct ast_dnsmgr_entry *dnsmgr;/*!<  DNS refresh manager for peer */
 	struct sockaddr_in addr;	/*!<  IP address of peer */
 	int maxcallbitrate;		/*!< Maximum Bitrate for a video call */
-	
+
 	/* Qualification */
 	struct sip_pvt *call;		/*!<  Call pointer */
 	int pokeexpire;			/*!<  When to expire poke (qualify= checking) */
@@ -11435,11 +11437,24 @@
 	}
 }
 
+static void set_peer_transport(struct sip_peer *peer, int transport)
+{
+	/* if the transport type changes, clear all socket data */
+	if (peer->socket.type != transport) {
+		peer->socket.type = transport;
+		peer->socket.fd = -1;
+		if (peer->socket.tcptls_session) {
+			ao2_ref(peer->socket.tcptls_session, -1);
+			peer->socket.tcptls_session = NULL;
+		}
+	}
+}
+
 /*! \brief Expire registration of SIP peer */
 static int expire_register(const void *data)
 {
 	struct sip_peer *peer = (struct sip_peer *)data;
-	
+
 	if (!peer)		/* Hmmm. We have no peer. Weird. */
 		return 0;
 
@@ -11447,7 +11462,8 @@
 	memset(&peer->addr, 0, sizeof(peer->addr));
 
 	destroy_association(peer);	/* remove registration data from storage */
-	
+	set_peer_transport(peer, peer->default_outbound_transport);
+
 	manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name);
 	register_peer_exten(peer, FALSE);	/* Remove regexten */
 	ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name);
@@ -11747,12 +11763,7 @@
 	 * transport type, change it.  If it got this far, it is a
 	 * supported type, but check just in case */
 	if ((peer->socket.type != transport_type) && (peer->transports & transport_type)) {
-		peer->socket.type = transport_type;
-		peer->socket.fd = -1;
-		if (peer->socket.tcptls_session) {
-			ao2_ref(peer->socket.tcptls_session, -1);
-			peer->socket.tcptls_session = NULL;
-		}
+		set_peer_transport(peer, transport_type);
 	}
 
 	oldsin = peer->addr;
@@ -23283,7 +23294,6 @@
 	int found = 0;
 	int firstpass = 1;
 	int format = 0;		/* Ama flags */
-	int original_transport = 0;
 	time_t regseconds = 0;
 	struct ast_flags peerflags[2] = {{(0)}};
 	struct ast_flags mask[2] = {{(0)}};
@@ -23346,8 +23356,7 @@
 	/* If we have realm authentication information, remove them (reload) */
 	clear_realm_authentication(peer->auth);
 	peer->auth = NULL;
-	original_transport = peer->socket.type;
-	peer->socket.type = 0;
+	peer->default_outbound_transport = 0;
 	peer->transports = 0;
 
 	for (; v || ((v = alt) && !(alt=NULL)); v = v->next) {
@@ -23360,7 +23369,7 @@
 			while ((trans = strsep(&val, ","))) {
 				trans = ast_skip_blanks(trans);
 
-				if (!strncasecmp(trans, "udp", 3)) 
+				if (!strncasecmp(trans, "udp", 3))
 					peer->transports |= SIP_TRANSPORT_UDP;
 				else if (!strncasecmp(trans, "tcp", 3))
 					peer->transports |= SIP_TRANSPORT_TCP;
@@ -23369,8 +23378,8 @@
 				else
 					ast_log(LOG_NOTICE, "'%s' is not a valid transport type. if no other is specified, udp will be used.\n", trans);
 
-				if (!peer->socket.type) { /*!< The first transport listed should be used for outgoing */
-					peer->socket.type = peer->transports;
+				if (!peer->default_outbound_transport) { /*!< The first transport listed should be default outbound */
+					peer->default_outbound_transport = peer->transports;
 				}
 			}
 		} else if (realtime && !strcasecmp(v->name, "regseconds")) {
@@ -23678,29 +23687,21 @@
 		}
 	}
 
-	if (!peer->socket.type) {
+	if (!peer->default_outbound_transport) {
 		/* Set default set of transports */
 		peer->transports = default_transports;
 		/* Set default primary transport */
-		peer->socket.type = default_primary_transport;
-	}
-
-	/* If the original peer socket type before rebuilding the peer is NOT equal to the new one,
-	 * override the new one with the original if a registration is present and the original type
-	 * is still supported by the peer.
-	 *
-	 * The original socket information is used to keep the socket type consistent with what was
-	 * specified during peer Registration.  The default set during build_peer should only be used when a
-	 * registration is not present. */
-	if ((original_transport != peer->socket.type) && ((peer->transports & original_transport)) && (peer->expire > -1)) {
-			peer->socket.type = original_transport;
-	} else if (original_transport != peer->socket.type) {
-		/* if the transport type changes, clear all socket data */
-		peer->socket.fd = -1;
-		if (peer->socket.tcptls_session) {
-			ao2_ref(peer->socket.tcptls_session, -1);
-			peer->socket.tcptls_session = NULL;
-		}
+		peer->default_outbound_transport = default_primary_transport;
+	}
+
+	/* The default transport type set during build_peer should only replace the socket.type when...
+	 * 1. Registration is not present and the socket.type and default transport types are different.
+	 * 2. The socket.type is not an acceptable transport type after rebuilding peer.
+	 * 3. The socket.type is not set yet. */
+	if (((peer->socket.type != peer->default_outbound_transport) && (peer->expire == -1)) ||
+		!(peer->socket.type & peer->transports) || !(peer->socket.type)) {
+
+		set_peer_transport(peer, peer->default_outbound_transport);
 	}
 
 	if (fullcontact->used > 0) {




More information about the asterisk-commits mailing list