[asterisk-commits] kpfleming: branch 1.2 r44955 - in /branches/1.2: ./ channels/ include/asterisk/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Oct 12 11:31:27 MST 2006


Author: kpfleming
Date: Thu Oct 12 13:31:26 2006
New Revision: 44955

URL: http://svn.digium.com/view/asterisk?rev=44955&view=rev
Log:
ensure that IAX2 and SIP sockets allow UDP fragmentation when running on Linux (thanks to Brian Candler on the asterisk-dev list for the tip)

Modified:
    branches/1.2/channels/chan_sip.c
    branches/1.2/include/asterisk/utils.h
    branches/1.2/netsock.c
    branches/1.2/utils.c

Modified: branches/1.2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_sip.c?rev=44955&r1=44954&r2=44955&view=diff
==============================================================================
--- branches/1.2/channels/chan_sip.c (original)
+++ branches/1.2/channels/chan_sip.c Thu Oct 12 13:31:26 2006
@@ -12856,9 +12856,12 @@
 		} else {
 			/* Allow SIP clients on the same host to access us: */
 			const int reuseFlag = 1;
+
 			setsockopt(sipsock, SOL_SOCKET, SO_REUSEADDR,
 				   (const char*)&reuseFlag,
 				   sizeof reuseFlag);
+
+			ast_enable_packet_fragmentation(sipsock);
 
 			if (bind(sipsock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) {
 				ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n",

Modified: branches/1.2/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/branches/1.2/include/asterisk/utils.h?rev=44955&r1=44954&r2=44955&view=diff
==============================================================================
--- branches/1.2/include/asterisk/utils.h (original)
+++ branches/1.2/include/asterisk/utils.h Thu Oct 12 13:31:26 2006
@@ -235,4 +235,19 @@
 int getloadavg(double *list, int nelem);
 #endif
 
+/*!
+  \brief Disable PMTU discovery on a socket
+  \param sock The socket to manipulate
+  \return Nothing
+
+  On Linux, UDP sockets default to sending packets with the Dont Fragment (DF)
+  bit set. This is supposedly done to allow the application to do PMTU
+  discovery, but Asterisk does not do this.
+
+  Because of this, UDP packets sent by Asterisk that are larger than the MTU
+  of any hop in the path will be lost. This function can be called on a socket
+  to ensure that the DF bit will not be set.
+ */
+void ast_enable_packet_fragmentation(int sock);
+
 #endif /* _ASTERISK_UTILS_H */

Modified: branches/1.2/netsock.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/netsock.c?rev=44955&r1=44954&r2=44955&view=diff
==============================================================================
--- branches/1.2/netsock.c (original)
+++ branches/1.2/netsock.c Thu Oct 12 13:31:26 2006
@@ -146,6 +146,8 @@
 
 	if (setsockopt(netsocket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) 
 		ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
+
+	ast_enable_packet_fragmentation(netsocket);
 
 	ns = malloc(sizeof(struct ast_netsock));
 	if (ns) {

Modified: branches/1.2/utils.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/utils.c?rev=44955&r1=44954&r2=44955&view=diff
==============================================================================
--- branches/1.2/utils.c (original)
+++ branches/1.2/utils.c Thu Oct 12 13:31:26 2006
@@ -895,3 +895,14 @@
 		*dataPut = 0;
 	return dataPut;
 }
+
+void ast_enable_packet_fragmentation(int sock)
+{
+#ifdef __linux__
+	int val = IP_PMTUDISC_DONT;
+	
+	if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val)))
+		ast_log(LOG_WARNING, "Unable to disable PMTU discovery. Large UDP packets may fail to be delivered when sent from this socket.\n");
+#endif
+}
+



More information about the asterisk-commits mailing list