[svn-commits] russell: trunk r62457 - in /trunk: channels/ configs/ doc/ include/asterisk/ ...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Apr 30 09:16:27 MST 2007


Author: russell
Date: Mon Apr 30 11:16:26 2007
New Revision: 62457

URL: http://svn.digium.com/view/asterisk?view=rev&rev=62457
Log:
Add support for setting the CoS for VLAN traffic (802.1p) in Linux.  The
file doc/qos.tex has been updated to document the new functionality.
(issue #9540, patch submitted by IgorG)

Modified:
    trunk/channels/chan_h323.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_mgcp.c
    trunk/channels/chan_sip.c
    trunk/channels/iax2-provision.c
    trunk/configs/h323.conf.sample
    trunk/configs/iax.conf.sample
    trunk/configs/iaxprov.conf.sample
    trunk/configs/mgcp.conf.sample
    trunk/configs/sip.conf.sample
    trunk/doc/asterisk.tex
    trunk/include/asterisk/acl.h
    trunk/include/asterisk/netsock.h
    trunk/include/asterisk/rtp.h
    trunk/include/asterisk/udptl.h
    trunk/main/acl.c
    trunk/main/netsock.c
    trunk/main/rtp.c
    trunk/main/udptl.c
    trunk/pbx/pbx_dundi.c

Modified: trunk/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_h323.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/channels/chan_h323.c (original)
+++ trunk/channels/chan_h323.c Mon Apr 30 11:16:26 2007
@@ -149,7 +149,8 @@
 /* Find user by alias (h.323 id) is default, alternative is the incomming call's source IP address*/
 static int userbyalias = 1;
 static int acceptAnonymous = 1;
-static int tos = 0;
+static unsigned int tos = 0;
+static unsigned int cos = 0;
 static char secret[50];
 static unsigned int unique = 0;
 
@@ -979,7 +980,7 @@
 	if (h323debug)
 		ast_log(LOG_DEBUG, "Created RTP channel\n");
 
-	ast_rtp_settos(pvt->rtp, tos);
+	ast_rtp_setqos(pvt->rtp, tos, cos);
 
 	if (h323debug)
 		ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", pvt->options.nat);
@@ -2812,7 +2813,6 @@
 
 static int reload_config(int is_reload)
 {
-	int format;
 	struct ast_config *cfg, *ucfg;
 	struct ast_variable *v;
 	struct oh323_peer *peer = NULL;
@@ -2858,6 +2858,7 @@
 	userbyalias = 1;
 	acceptAnonymous = 1;
 	tos = 0;
+	cos = 0;
 
 	/* Copy the default jb config over global_jbconf */
 	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
@@ -2900,20 +2901,12 @@
 				memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
 			}
 		} else if (!strcasecmp(v->name, "tos")) {
-			if (sscanf(v->value, "%d", &format)) {
-				tos = format & 0xff;
-			} else if (!strcasecmp(v->value, "lowdelay")) {
-				tos = IPTOS_LOWDELAY;
-			} else if (!strcasecmp(v->value, "throughput")) {
-				tos = IPTOS_THROUGHPUT;
-			} else if (!strcasecmp(v->value, "reliability")) {
-				tos = IPTOS_RELIABILITY;
-			} else if (!strcasecmp(v->value, "mincost")) {
-				tos = IPTOS_MINCOST;
-			} else if (!strcasecmp(v->value, "none")) {
-				tos = 0;
-			} else {
-				ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
+			if (ast_str2tos(v->value, &tos)) {
+				ast_log(LOG_WARNING, "Invalid tos value at line %d, for more info read doc/qos.tex\n", v->lineno);			
+			}
+		} else if (!strcasecmp(v->name, "cos")) {		
+			if (ast_str2cos(v->value, &cos)) {
+				ast_log(LOG_WARNING, "Invalid cos value at line %d, for more info read doc/qos.tex\n", v->lineno);			
 			}
 		} else if (!strcasecmp(v->name, "gatekeeper")) {
 			if (!strcasecmp(v->value, "DISABLE")) {

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Mon Apr 30 11:16:26 2007
@@ -177,6 +177,8 @@
 static int iaxdefaulttimeout = 5;		/* Default to wait no more than 5 seconds for a reply to come back */
 
 static unsigned int tos = 0;
+
+static unsigned int cos = 0;
 
 static int min_reg_expire;
 static int max_reg_expire;
@@ -8538,7 +8540,7 @@
 				sin.sin_addr.s_addr = INADDR_ANY;
 				if (ast_netsock_find(netsock, &sin)) {
 					sin.sin_addr.s_addr = orig_saddr;
-					sock = ast_netsock_bind(outsock, io, srcaddr, port, tos, socket_read, NULL);
+					sock = ast_netsock_bind(outsock, io, srcaddr, port, tos, cos, socket_read, NULL);
 					if (sock) {
 						sockfd = ast_netsock_sockfd(sock);
 						ast_netsock_unref(sock);
@@ -9204,7 +9206,13 @@
 	tosval = ast_variable_retrieve(cfg, "general", "tos");
 	if (tosval) {
 		if (ast_str2tos(tosval, &tos))
-			ast_log(LOG_WARNING, "Invalid tos value, see doc/ip-tos.txt for more information.\n");
+			ast_log(LOG_WARNING, "Invalid tos value, see doc/qos.tex for more information.\n");
+	}
+	/* Seed initial cos value */
+	tosval = ast_variable_retrieve(cfg, "general", "cos");
+	if (tosval) {
+		if (ast_str2cos(tosval, &cos))
+			ast_log(LOG_WARNING, "Invalid cos value, see doc/qos.tex for more information.\n");
 	}
 	while(v) {
 		if (!strcasecmp(v->name, "bindport")){ 
@@ -9272,7 +9280,7 @@
 			if (reload) {
 				ast_log(LOG_NOTICE, "Ignoring bindaddr on reload\n");
 			} else {
-				if (!(ns = ast_netsock_bind(netsock, io, v->value, portno, tos, socket_read, NULL))) {
+				if (!(ns = ast_netsock_bind(netsock, io, v->value, portno, tos, cos, socket_read, NULL))) {
 					ast_log(LOG_WARNING, "Unable apply binding to '%s' at line %d\n", v->value, v->lineno);
 				} else {
 					if (option_verbose > 1) {
@@ -9379,7 +9387,10 @@
 				ast_context_create(NULL, regcontext, "IAX2");
 		} else if (!strcasecmp(v->name, "tos")) {
 			if (ast_str2tos(v->value, &tos))
-				ast_log(LOG_WARNING, "Invalid tos value at line %d, see doc/ip-tos.txt for more information.'\n", v->lineno);
+				ast_log(LOG_WARNING, "Invalid tos value at line %d, see doc/qos.tex for more information.'\n", v->lineno);
+		} else if (!strcasecmp(v->name, "cos")) {
+			if (ast_str2cos(v->value, &cos))
+				ast_log(LOG_WARNING, "Invalid cos value at line %d, see doc/qos.tex for more information.'\n", v->lineno);
 		} else if (!strcasecmp(v->name, "accountcode")) {
 			ast_copy_string(accountcode, v->value, sizeof(accountcode));
 		} else if (!strcasecmp(v->name, "mohinterpret")) {
@@ -9409,7 +9420,7 @@
 	}
 	
 	if (defaultsockfd < 0) {
-		if (!(ns = ast_netsock_bind(netsock, io, "0.0.0.0", portno, tos, socket_read, NULL))) {
+		if (!(ns = ast_netsock_bind(netsock, io, "0.0.0.0", portno, tos, cos, socket_read, NULL))) {
 			ast_log(LOG_ERROR, "Unable to create network socket: %s\n", strerror(errno));
 		} else {
 			if (option_verbose > 1)

Modified: trunk/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_mgcp.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/channels/chan_mgcp.c (original)
+++ trunk/channels/chan_mgcp.c Mon Apr 30 11:16:26 2007
@@ -71,6 +71,7 @@
 #include "asterisk/app.h"
 #include "asterisk/musiconhold.h"
 #include "asterisk/utils.h"
+#include "asterisk/netsock.h"
 #include "asterisk/causes.h"
 #include "asterisk/dsp.h"
 #include "asterisk/devicestate.h"
@@ -163,7 +164,9 @@
 static ast_group_t cur_callergroup = 0;
 static ast_group_t cur_pickupgroup = 0;
 
-static int tos = 0;
+static unsigned int tos = 0;
+
+static unsigned int cos = 0;
 
 static int immediate = 0;
 
@@ -4163,20 +4166,11 @@
 			else
 				capability &= ~format;
 		} else if (!strcasecmp(v->name, "tos")) {
-			if (sscanf(v->value, "%d", &format) == 1)
-				tos = format & 0xff;
-			else if (!strcasecmp(v->value, "lowdelay"))
-				tos = IPTOS_LOWDELAY;
-			else if (!strcasecmp(v->value, "throughput"))
-				tos = IPTOS_THROUGHPUT;
-			else if (!strcasecmp(v->value, "reliability"))
-				tos = IPTOS_RELIABILITY;
-			else if (!strcasecmp(v->value, "mincost"))
-				tos = IPTOS_MINCOST;
-			else if (!strcasecmp(v->value, "none"))
-				tos = 0;
-			else
-				ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno);
+			if (ast_str2tos(v->value, &tos))
+			    ast_log(LOG_WARNING, "Invalid tos value at line %d, see doc/qos.tex for more information.\n", v->lineno);
+		} else if (!strcasecmp(v->name, "cos")) {				
+			if (ast_str2cos(v->value, &cos))
+			    ast_log(LOG_WARNING, "Invalid cos value at line %d, see doc/qos.tex for more information.\n", v->lineno);
 		} else if (!strcasecmp(v->name, "port")) {
 			if (sscanf(v->value, "%d", &ourport) == 1) {
 				bindaddr.sin_port = htons(ourport);
@@ -4263,10 +4257,8 @@
 			if (option_verbose > 1) {
 				ast_verbose(VERBOSE_PREFIX_2 "MGCP Listening on %s:%d\n", 
 					ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port));
-				ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos);
-			}
-			if (setsockopt(mgcpsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) 
-				ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
+			}
+			ast_netsock_set_qos(mgcpsock, tos, cos);
 		}
 	}
 	ast_mutex_unlock(&netlock);

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Mon Apr 30 11:16:26 2007
@@ -136,6 +136,7 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/monitor.h"
+#include "asterisk/netsock.h"
 #include "asterisk/localtime.h"
 #include "asterisk/abstract_jb.h"
 #include "asterisk/compiler.h"
@@ -511,6 +512,10 @@
 #define DEFAULT_TOS_AUDIO       0               /*!< Audio packets should be marked as DSCP EF (Expedited Forwarding), but the default is 0 to be compatible with previous versions. */
 #define DEFAULT_TOS_VIDEO       0               /*!< Video packets should be marked as DSCP AF41, but the default is 0 to be compatible with previous versions. */
 #define DEFAULT_TOS_TEXT        0               /*!< Text packets should be marked as XXXX XXXX, but the default is 0 to be compatible with previous versions. */
+#define DEFAULT_COS_SIP         4
+#define DEFAULT_COS_AUDIO       5
+#define DEFAULT_COS_VIDEO       6
+#define DEFAULT_COS_TEXT        0
 #define DEFAULT_ALLOW_EXT_DOM	TRUE
 #define DEFAULT_REALM		"asterisk"
 #define DEFAULT_NOTIFYRINGING	TRUE
@@ -564,6 +569,10 @@
 static unsigned int global_tos_audio;		/*!< IP type of service for audio RTP packets */
 static unsigned int global_tos_video;		/*!< IP type of service for video RTP packets */
 static unsigned int global_tos_text;		/*!< IP type of service for text RTP packets */
+static unsigned int global_cos_sip;		/*!< 802.1p class of service for SIP packets */
+static unsigned int global_cos_audio;		/*!< 802.1p class of service for audio RTP packets */
+static unsigned int global_cos_video;		/*!< 802.1p class of service for video RTP packets */
+static unsigned int global_cos_text;		/*!< 802.1p class of service for text RTP packets */
 static int compactheaders;		/*!< send compact sip headers */
 static int recordhistory;		/*!< Record SIP history. Off by default */
 static int dumphistory;			/*!< Dump history to verbose before destroying SIP dialog */
@@ -4605,14 +4614,14 @@
 			free(p);
 			return NULL;
 		}
+		ast_rtp_setqos(p->rtp, global_tos_audio, global_cos_audio);
 		ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
 		ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
-		ast_rtp_settos(p->rtp, global_tos_audio);
 		ast_rtp_set_rtptimeout(p->rtp, global_rtptimeout);
 		ast_rtp_set_rtpholdtimeout(p->rtp, global_rtpholdtimeout);
 		ast_rtp_set_rtpkeepalive(p->rtp, global_rtpkeepalive);
 		if (p->vrtp) {
-			ast_rtp_settos(p->vrtp, global_tos_video);
+			ast_rtp_setqos(p->vrtp, global_tos_video, global_cos_video);
 			ast_rtp_setdtmf(p->vrtp, 0);
 			ast_rtp_setdtmfcompensate(p->vrtp, 0);
 			ast_rtp_set_rtptimeout(p->vrtp, global_rtptimeout);
@@ -4620,12 +4629,12 @@
 			ast_rtp_set_rtpkeepalive(p->vrtp, global_rtpkeepalive);
 		}
 		if (p->trtp) {
-			ast_rtp_settos(p->trtp, global_tos_text);
+			ast_rtp_setqos(p->trtp, global_tos_text, global_cos_text);
 			ast_rtp_setdtmf(p->trtp, 0);
 			ast_rtp_setdtmfcompensate(p->trtp, 0);
 		}
 		if (p->udptl)
-			ast_udptl_settos(p->udptl, global_tos_audio);
+			ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
 		p->maxcallbitrate = default_maxcallbitrate;
 	}
 
@@ -11038,6 +11047,11 @@
 	ast_cli(fd, "  IP ToS RTP audio:       %s\n", ast_tos2str(global_tos_audio));
 	ast_cli(fd, "  IP ToS RTP video:       %s\n", ast_tos2str(global_tos_video));
 	ast_cli(fd, "  IP ToS RTP text:        %s\n", ast_tos2str(global_tos_text));
+	ast_cli(fd, "  802.1p CoS SIP:         %d\n", global_cos_sip);
+	ast_cli(fd, "  802.1p CoS RTP audio:   %d\n", global_cos_audio);
+	ast_cli(fd, "  802.1p CoS RTP video:   %d\n", global_cos_video);
+	ast_cli(fd, "  802.1p CoS RTP text:    %d\n", global_cos_text);
+
 	ast_cli(fd, "  T38 fax pt UDPTL:       %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_UDPTL) ? "Yes" : "No");
 #ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS
 	ast_cli(fd, "  T38 fax pt RTP:         %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_RTP) ? "Yes" : "No");
@@ -17019,6 +17033,11 @@
 	global_tos_audio = DEFAULT_TOS_AUDIO;
 	global_tos_video = DEFAULT_TOS_VIDEO;
 	global_tos_text = DEFAULT_TOS_TEXT;
+	global_cos_sip = DEFAULT_COS_SIP;
+	global_cos_audio = DEFAULT_COS_AUDIO;
+	global_cos_video = DEFAULT_COS_VIDEO;
+	global_cos_text = DEFAULT_COS_TEXT;
+
 	externhost[0] = '\0';			/* External host name (for behind NAT DynDNS support) */
 	externexpire = 0;			/* Expiration for DNS re-issuing */
 	externrefresh = 10;
@@ -17298,16 +17317,24 @@
 				registry_count++;
 		} else if (!strcasecmp(v->name, "tos_sip")) {
 			if (ast_str2tos(v->value, &global_tos_sip))
-				ast_log(LOG_WARNING, "Invalid tos_sip value at line %d, recommended value is 'cs3'. See doc/ip-tos.txt.\n", v->lineno);
+				ast_log(LOG_WARNING, "Invalid tos_sip value at line %d, recommended value is 'cs3'. See doc/qos.tex.\n", v->lineno);
 		} else if (!strcasecmp(v->name, "tos_audio")) {
 			if (ast_str2tos(v->value, &global_tos_audio))
-				ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, recommended value is 'ef'. See doc/ip-tos.txt.\n", v->lineno);
+				ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, recommended value is 'ef'. See doc/qos.tex.\n", v->lineno);
 		} else if (!strcasecmp(v->name, "tos_video")) {
 			if (ast_str2tos(v->value, &global_tos_video))
-				ast_log(LOG_WARNING, "Invalid tos_video value at line %d, recommended value is 'af41'. See doc/ip-tos.txt.\n", v->lineno);
+				ast_log(LOG_WARNING, "Invalid tos_video value at line %d, recommended value is 'af41'. See doc/qos.tex.\n", v->lineno);
 		} else if (!strcasecmp(v->name, "tos_text")) {
 			if (ast_str2tos(v->value, &global_tos_text))
-				ast_log(LOG_WARNING, "Invalid tos_text value at line %d, recommended value is 'af41'. See doc/ip-tos.txt.\n", v->lineno);
+				ast_log(LOG_WARNING, "Invalid tos_text value at line %d, recommended value is 'af41'. See doc/qos.tex.\n", v->lineno);
+		} else if (!strcasecmp(v->name, "cos_sip")) {
+			ast_str2cos(v->value, &global_cos_sip);
+		} else if (!strcasecmp(v->name, "cos_audio")) {
+			ast_str2cos(v->value, &global_cos_audio);
+		} else if (!strcasecmp(v->name, "cos_video")) {
+			ast_str2cos(v->value, &global_cos_video);
+		} else if (!strcasecmp(v->name, "cos_text")) {
+			ast_str2cos(v->value, &global_cos_text);
 		} else if (!strcasecmp(v->name, "bindport")) {
 			if (sscanf(v->value, "%d", &ourport) == 1) {
 				bindaddr.sin_port = htons(ourport);
@@ -17475,10 +17502,8 @@
 				if (option_verbose > 1)
 					ast_verbose(VERBOSE_PREFIX_2 "SIP Listening on %s:%d\n", 
 						ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port));
-				if (setsockopt(sipsock, IPPROTO_IP, IP_TOS, &global_tos_sip, sizeof(global_tos_sip))) 
-					ast_log(LOG_WARNING, "Unable to set SIP TOS to %s\n", ast_tos2str(global_tos_sip));
-				else if (option_verbose > 1)
-					ast_verbose(VERBOSE_PREFIX_2 "Using SIP TOS: %s\n", ast_tos2str(global_tos_sip));
+
+				ast_netsock_set_qos(sipsock, global_tos_sip, global_tos_sip);
 			}
 		}
 	}

Modified: trunk/channels/iax2-provision.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/iax2-provision.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/channels/iax2-provision.c (original)
+++ trunk/channels/iax2-provision.c Mon Apr 30 11:16:26 2007
@@ -332,7 +332,7 @@
 				ast_log(LOG_WARNING, "Ignoring invalid codec '%s' for '%s' at line %d\n", v->value, s, v->lineno);
 		} else if (!strcasecmp(v->name, "tos")) {
 			if (ast_str2tos(v->value, &cur->tos))
-				ast_log(LOG_WARNING, "Invalid tos value at line %d, see doc/ip-tos.txt for more information.\n", v->lineno);
+				ast_log(LOG_WARNING, "Invalid tos value at line %d, see doc/qos.tex for more information.\n", v->lineno);
 		} else if (!strcasecmp(v->name, "user")) {
 			strncpy(cur->user, v->value, sizeof(cur->user) - 1);
 			if (strcmp(cur->user, v->value))

Modified: trunk/configs/h323.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/h323.conf.sample?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/configs/h323.conf.sample (original)
+++ trunk/configs/h323.conf.sample Mon Apr 30 11:16:26 2007
@@ -4,7 +4,7 @@
 [general]
 port = 1720
 ;bindaddr = 1.2.3.4 	; this SHALL contain a single, valid IP address for this machine
-;tos=lowdelay
+;tos=ef
 ;
 ; You may specify a global default AMA flag for iaxtel calls.  It must be
 ; one of 'default', 'omit', 'billing', or 'documentation'.  These flags

Modified: trunk/configs/iax.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/iax.conf.sample?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/configs/iax.conf.sample (original)
+++ trunk/configs/iax.conf.sample Mon Apr 30 11:16:26 2007
@@ -225,8 +225,9 @@
 ;
 ;authdebug=no
 ;
-; See doc/README.tos for a description of the tos parameters.
+; See doc/qos.tex for a description of the tos parameters.
 ;tos=ef
+;cos=5
 ;
 ; If regcontext is specified, Asterisk will dynamically create and destroy
 ; a NoOp priority 1 extension for a given peer who registers or unregisters

Modified: trunk/configs/iaxprov.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/iaxprov.conf.sample?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/configs/iaxprov.conf.sample (original)
+++ trunk/configs/iaxprov.conf.sample Mon Apr 30 11:16:26 2007
@@ -53,7 +53,7 @@
 ;
 flags=register,heartbeat
 ;
-; See doc/README.tos for a description of this parameter.
+; See doc/qos.tex for a description of this parameter.
 ;tos=ef
 ;
 ; Example iaxy provisioning

Modified: trunk/configs/mgcp.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/mgcp.conf.sample?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/configs/mgcp.conf.sample (original)
+++ trunk/configs/mgcp.conf.sample Mon Apr 30 11:16:26 2007
@@ -4,6 +4,9 @@
 [general]
 ;port = 2427
 ;bindaddr = 0.0.0.0
+
+; See doc/qos.tex for a description of the tos parameters.
+;tos=ef
 
 ;------------------------------ JITTER BUFFER CONFIGURATION --------------------------
 ; jbenable = yes              ; Enables the use of a jitterbuffer on the receiving side of a

Modified: trunk/configs/sip.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/sip.conf.sample?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/configs/sip.conf.sample (original)
+++ trunk/configs/sip.conf.sample Mon Apr 30 11:16:26 2007
@@ -57,10 +57,16 @@
 				; and multiline formatted headers for strict
 				; SIP compatibility (defaults to "no")
 
-; See doc/README.tos for a description of these parameters.
+; See doc/qos.tex for a description of these parameters.
 ;tos_sip=cs3                    ; Sets TOS for SIP packets.
 ;tos_audio=ef                   ; Sets TOS for RTP audio packets.
 ;tos_video=af41                 ; Sets TOS for RTP video packets.
+;tos_text=af41                  ; Sets TOS for RTP text packets.
+
+;cos_sip=4                      ; Sets CoS for SIP packets.
+;cos_audio=6                    ; Sets CoS for RTP audio packets.
+;cos_video=5                    ; Sets CoS for RTP video packets.
+;cos_text=0                     ; Sets CoS for RTP text packets.
 
 ;maxexpiry=3600			; Maximum allowed time of incoming registrations
 				; and subscriptions (seconds)

Modified: trunk/doc/asterisk.tex
URL: http://svn.digium.com/view/asterisk/trunk/doc/asterisk.tex?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/doc/asterisk.tex (original)
+++ trunk/doc/asterisk.tex Mon Apr 30 11:16:26 2007
@@ -44,8 +44,8 @@
     \input{cliprompt.tex}
     \subsection{Extensions}
     \input{extensions.tex}
-    \subsection{IP Type of Service}
-    \input{ip-tos.tex}
+    \subsection{IP Quality of Service}
+    \input{qos.tex}
     \subsection{MP3 Support}
     \input{mp3.tex}
     \subsection{ICES}

Modified: trunk/include/asterisk/acl.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/acl.h?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/include/asterisk/acl.h (original)
+++ trunk/include/asterisk/acl.h Mon Apr 30 11:16:26 2007
@@ -57,6 +57,9 @@
 int ast_ouraddrfor(struct in_addr *them, struct in_addr *us);
 
 int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr);
+
+int ast_str2cos(const char *value, unsigned int *cos);
+
 int ast_str2tos(const char *value, unsigned int *tos);
 const char *ast_tos2str(unsigned int tos);
 

Modified: trunk/include/asterisk/netsock.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/netsock.h?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/include/asterisk/netsock.h (original)
+++ trunk/include/asterisk/netsock.h Mon Apr 30 11:16:26 2007
@@ -41,10 +41,10 @@
 int ast_netsock_init(struct ast_netsock_list *list);
 
 struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_context *ioc,
-				     const char *bindinfo, int defaultport, int tos, ast_io_cb callback, void *data);
+				     const char *bindinfo, int defaultport, int tos, int cos, ast_io_cb callback, void *data);
 
 struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct io_context *ioc,
-					 struct sockaddr_in *bindaddr, int tos, ast_io_cb callback, void *data);
+					 struct sockaddr_in *bindaddr, int tos, int cos, ast_io_cb callback, void *data);
 
 int ast_netsock_free(struct ast_netsock_list *list, struct ast_netsock *netsock);
 
@@ -52,6 +52,8 @@
 
 struct ast_netsock *ast_netsock_find(struct ast_netsock_list *list,
 				     struct sockaddr_in *sa);
+
+int ast_netsock_set_qos(int netsocket, int tos, int cos);
 
 int ast_netsock_sockfd(const struct ast_netsock *ns);
 

Modified: trunk/include/asterisk/rtp.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/rtp.h?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/include/asterisk/rtp.h (original)
+++ trunk/include/asterisk/rtp.h Mon Apr 30 11:16:26 2007
@@ -168,7 +168,7 @@
 
 int ast_rtp_sendcng(struct ast_rtp *rtp, int level);
 
-int ast_rtp_settos(struct ast_rtp *rtp, int tos);
+int ast_rtp_setqos(struct ast_rtp *rtp, int tos, int cos);
 
 /*! \brief  Setting RTP payload types from lines in a SDP description: */
 void ast_rtp_pt_clear(struct ast_rtp* rtp);

Modified: trunk/include/asterisk/udptl.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/udptl.h?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/include/asterisk/udptl.h (original)
+++ trunk/include/asterisk/udptl.h Mon Apr 30 11:16:26 2007
@@ -73,7 +73,7 @@
 
 int ast_udptl_fd(struct ast_udptl *udptl);
 
-int ast_udptl_settos(struct ast_udptl *udptl, int tos);
+int ast_udptl_setqos(struct ast_udptl *udptl, int tos, int cos);
 
 void ast_udptl_set_m_type(struct ast_udptl* udptl, int pt);
 

Modified: trunk/main/acl.c
URL: http://svn.digium.com/view/asterisk/trunk/main/acl.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/main/acl.c (original)
+++ trunk/main/acl.c Mon Apr 30 11:16:26 2007
@@ -278,6 +278,20 @@
 	{ "EF", 0x2E },
 };
 
+int ast_str2cos(const char *value, unsigned int *cos) 
+{
+	int fval;
+	
+	if (sscanf(value, "%d", &fval) == 1) {
+		if (fval < 8) {
+    		    *cos = fval;
+		    return 0;
+		}
+	}
+	
+	return -1;
+}
+
 int ast_str2tos(const char *value, unsigned int *tos)
 {
 	int fval;

Modified: trunk/main/netsock.c
URL: http://svn.digium.com/view/asterisk/trunk/main/netsock.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/main/netsock.c (original)
+++ trunk/main/netsock.c Mon Apr 30 11:16:26 2007
@@ -119,7 +119,7 @@
 	return sock;
 }
 
-struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct io_context *ioc, struct sockaddr_in *bindaddr, int tos, ast_io_cb callback, void *data)
+struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct io_context *ioc, struct sockaddr_in *bindaddr, int tos, int cos, ast_io_cb callback, void *data)
 {
 	int netsocket = -1;
 	int *ioref;
@@ -142,12 +142,9 @@
 		close(netsocket);
 		return NULL;
 	}
-	if (option_verbose > 1)
-		ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos);
-
-	if (setsockopt(netsocket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) 
-		ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
-
+
+	ast_netsock_set_qos(netsocket, tos, cos);
+		
 	ast_enable_packet_fragmentation(netsocket);
 
 	if (!(ns = ast_calloc(1, sizeof(struct ast_netsock)))) {
@@ -172,7 +169,31 @@
 	return ns;
 }
 
-struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_context *ioc, const char *bindinfo, int defaultport, int tos, ast_io_cb callback, void *data)
+int ast_netsock_set_qos(int netsocket, int tos, int cos)
+{
+	int res;
+	
+	if ((res = setsockopt(netsocket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))))
+		ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
+	else {
+	    if (option_verbose > 1)
+		ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos);
+	}
+
+#if defined(linux)								
+	if (setsockopt(netsocket, SOL_SOCKET, SO_PRIORITY, &cos, sizeof(cos)))
+	    ast_log(LOG_WARNING, "Unable to set CoS to %d\n", cos);
+	else {
+	    if (option_verbose > 1)
+		ast_verbose(VERBOSE_PREFIX_2 "Using CoS mark %d\n", tos);
+	}
+#endif
+							
+	return res;
+}
+													
+
+struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_context *ioc, const char *bindinfo, int defaultport, int tos, int cos, ast_io_cb callback, void *data)
 {
 	struct sockaddr_in sin;
 	char *tmp;
@@ -193,7 +214,7 @@
 
 	inet_aton(host, &sin.sin_addr);
 
-	return ast_netsock_bindaddr(list, ioc, &sin, tos, callback, data);
+	return ast_netsock_bindaddr(list, ioc, &sin, tos, cos, callback, data);
 }
 
 int ast_netsock_sockfd(const struct ast_netsock *ns)

Modified: trunk/main/rtp.c
URL: http://svn.digium.com/view/asterisk/trunk/main/rtp.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/main/rtp.c (original)
+++ trunk/main/rtp.c Mon Apr 30 11:16:26 2007
@@ -53,6 +53,7 @@
 #include "asterisk/config.h"
 #include "asterisk/lock.h"
 #include "asterisk/utils.h"
+#include "asterisk/netsock.h"
 #include "asterisk/cli.h"
 #include "asterisk/unaligned.h"
 #include "asterisk/utils.h"
@@ -2040,13 +2041,9 @@
 	return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia);
 }
 
-int ast_rtp_settos(struct ast_rtp *rtp, int tos)
-{
-	int res;
-
-	if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 
-		ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
-	return res;
+int ast_rtp_setqos(struct ast_rtp *rtp, int tos, int cos)
+{
+	return ast_netsock_set_qos(rtp->s, tos, cos);
 }
 
 void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them)

Modified: trunk/main/udptl.c
URL: http://svn.digium.com/view/asterisk/trunk/main/udptl.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/main/udptl.c (original)
+++ trunk/main/udptl.c Mon Apr 30 11:16:26 2007
@@ -73,6 +73,7 @@
 #include "asterisk/config.h"
 #include "asterisk/lock.h"
 #include "asterisk/utils.h"
+#include "asterisk/netsock.h"
 #include "asterisk/cli.h"
 #include "asterisk/unaligned.h"
 #include "asterisk/utils.h"
@@ -872,13 +873,9 @@
 	return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
 }
 
-int ast_udptl_settos(struct ast_udptl *udptl, int tos)
-{
-	int res;
-
-	if ((res = setsockopt(udptl->fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 
-		ast_log(LOG_WARNING, "UDPTL unable to set TOS to %d\n", tos);
-	return res;
+int ast_udptl_setqos(struct ast_udptl *udptl, int tos, int cos)
+{
+	return ast_netsock_set_qos(udptl->fd, tos, cos);
 }
 
 void ast_udptl_set_peer(struct ast_udptl *udptl, struct sockaddr_in *them)

Modified: trunk/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx/pbx_dundi.c?view=diff&rev=62457&r1=62456&r2=62457
==============================================================================
--- trunk/pbx/pbx_dundi.c (original)
+++ trunk/pbx/pbx_dundi.c Mon Apr 30 11:16:26 2007
@@ -68,6 +68,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/io.h"
 #include "asterisk/utils.h"
+#include "asterisk/netsock.h"
 #include "asterisk/crypto.h"
 #include "asterisk/astdb.h"
 #include "asterisk/acl.h"
@@ -4763,12 +4764,8 @@
 			ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), strerror(errno));
 		return AST_MODULE_LOAD_FAILURE;
 	}
-
-	if (option_verbose > 1)
-		ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos);
-
-	if (setsockopt(netsocket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) 
-		ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
+	
+	ast_netsock_set_qos(netsocket, tos, 0);
 	
 	if (start_network_thread()) {
 		ast_log(LOG_ERROR, "Unable to start network thread\n");



More information about the svn-commits mailing list