Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 8749) +++ channels/chan_sip.c (working copy) @@ -356,7 +356,9 @@ #define DEFAULT_VIDEOSUPPORT FALSE #define DEFAULT_SRVLOOKUP FALSE /*!< Recommended setting is ON */ #define DEFAULT_COMPACTHEADERS FALSE -#define DEFAULT_TOS FALSE +#define DEFAULT_TOS_SIP 0 /*!< Call signalling packets should be marked as DSCP CS3, but the default is 0 to be compatible with previous versions. */ +#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_ALLOW_EXT_DOM TRUE #define DEFAULT_REALM "asterisk" #define DEFAULT_NOTIFYRINGING TRUE @@ -392,7 +394,9 @@ static int global_regattempts_max; /*!< Registration attempts before giving up */ static int global_allowguest; /*!< allow unauthenticated users/peers to connect? */ static int global_mwitime; /*!< Time between MWI checks for peers */ -static int global_tos; /*!< IP Type of service */ +static int global_tos_sip; /*!< IP type of service for SIP packets */ +static int global_tos_audio; /*!< IP type of service for audio RTP packets */ +static int global_tos_video; /*!< IP type of service for video RTP packets */ static int global_videosupport; /*!< Videosupport on or off */ static int compactheaders; /*!< send compact sip headers */ static int recordhistory; /*!< Record SIP history. Off by default */ @@ -3175,9 +3179,9 @@ free(p); return NULL; } - ast_rtp_settos(p->rtp, global_tos); + ast_rtp_settos(p->rtp, global_tos_audio); if (p->vrtp) - ast_rtp_settos(p->vrtp, global_tos); + ast_rtp_settos(p->vrtp, global_tos_video); p->rtptimeout = global_rtptimeout; p->rtpholdtimeout = global_rtpholdtimeout; p->rtpkeepalive = global_rtpkeepalive; @@ -8301,7 +8305,9 @@ ast_cli(fd, " From: Domain: %s\n", default_fromdomain); ast_cli(fd, " Record SIP history: %s\n", recordhistory ? "On" : "Off"); ast_cli(fd, " Call Events: %s\n", callevents ? "On" : "Off"); - ast_cli(fd, " IP ToS: 0x%x\n", global_tos); + ast_cli(fd, " IP ToS SIP: 0x%x\n", global_tos_sip); + ast_cli(fd, " IP ToS RTP audio: 0x%x\n", global_tos_audio); + ast_cli(fd, " IP ToS RTP video: 0x%x\n", global_tos_video); #ifdef OSP_SUPPORT ast_cli(fd, " OSP Support: Yes\n"); #else @@ -12362,6 +12368,7 @@ int auto_sip_domains = 0; struct sockaddr_in old_bindaddr = bindaddr; int registry_count = 0, peer_count = 0, user_count = 0; + int temp_tos = 0; cfg = ast_config_load(config); @@ -12383,7 +12390,9 @@ outboundproxyip.sin_family = AF_INET; /* Type of address: IPv4 */ ourport = DEFAULT_SIP_PORT; srvlookup = DEFAULT_SRVLOOKUP; - global_tos = DEFAULT_TOS; + global_tos_sip = DEFAULT_TOS_SIP; + global_tos_audio = DEFAULT_TOS_AUDIO; + global_tos_video = DEFAULT_TOS_VIDEO; externhost[0] = '\0'; /* External host name (for behind NAT DynDNS support) */ externexpire = 0; /* Expiration for DNS re-issuing */ externrefresh = 10; @@ -12600,8 +12609,22 @@ if (sip_register(v->value, v->lineno) == 0) registry_count++; } else if (!strcasecmp(v->name, "tos")) { - if (ast_str2tos(v->value, &global_tos)) - 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, &temp_tos)) { + global_tos_sip = temp_tos; + global_tos_audio = temp_tos; + global_tos_video = temp_tos; + ast_log(LOG_WARNING, "tos value at line %s is deprecated. See doc/README.tos for more information.", v->lineno); + } else + ast_log(LOG_WARNING, "Invalid tos value at line %d, See doc/README.tos for more information.\n", v->lineno); + } 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/README.tos.\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/README.tos.\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/README.tos.\n", v->lineno); } else if (!strcasecmp(v->name, "bindport")) { if (sscanf(v->value, "%d", &ourport) == 1) { bindaddr.sin_port = htons(ourport); @@ -12710,10 +12733,10 @@ if (option_verbose > 1) { ast_verbose(VERBOSE_PREFIX_2 "SIP Listening on %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port)); - ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", global_tos); + ast_verbose(VERBOSE_PREFIX_2 "Using SIP TOS bits %d\n", global_tos_sip); } - if (setsockopt(sipsock, IPPROTO_IP, IP_TOS, &global_tos, sizeof(global_tos))) - ast_log(LOG_WARNING, "Unable to set TOS to %d\n", global_tos); + if (setsockopt(sipsock, IPPROTO_IP, IP_TOS, &global_tos_sip, sizeof(global_tos_sip))) + ast_log(LOG_WARNING, "Unable to set SIP TOS to %d\n", global_tos_sip); } } } Index: doc/README.tos =================================================================== --- doc/README.tos (revision 0) +++ doc/README.tos (revision 0) @@ -0,0 +1,28 @@ +In chan_sip different QoS settings are possible for different types of +traffic. By default the IP TOS is set to "0" in the code (otherwise +known as "best effort") in order to be compatible with previous +versions of Asterisk. + +SIP packets should be set to DSCP CS3, RTP audio packets should be set +to DSCP EF, and RTP video packets are should be to DSCP AF41. The +sample config file has commented out settings that match this scheme. +For more information on why the TOS is set this way see the +"Enterprise QoS Solution Reference Network Design Guide" version 3.3 +from Cisco at: + +http://www.cisco.com/application/pdf/en/us/guest/netsol/ns432/c649/ccmigration_09186a008049b062.pdf + +There are three parameters that control the TOS for chan_sip: tos_sip, +tos_audio, and tos_video. tos_sip controls what TOS SIP call +signalling packets are set to. The allowable values for any of the +tos* parameters are: + +be, cs1, af11, af12, af13, cs2, af21, af22, af23, cs3, af31, af32, +af33, cs4, af41, af42, af42, ef, lowdelay, throughput, reliability, +mincost, none + +The tos* parameters will also take numeric values. + +The lowdelay, throughput, reliability, mincost, and none values are +deprecated. The old "tos" parameter is deprecated because it sets the +IP QoS for all three types of packets to the same QoS value. Index: acl.c =================================================================== --- acl.c (revision 8749) +++ acl.c (working copy) @@ -253,16 +253,57 @@ int fval; if (sscanf(value, "%i", &fval) == 1) *tos = fval & 0xff; - else if (!strcasecmp(value, "lowdelay")) + else if (!strcasecmp(value, "lowdelay")) { *tos = IPTOS_LOWDELAY; - else if (!strcasecmp(value, "throughput")) + ast_log(LOG_WARNING, "tos value %s is deprecated. See doc/README.tos for more information.", value); + } else if (!strcasecmp(value, "throughput")) { *tos = IPTOS_THROUGHPUT; - else if (!strcasecmp(value, "reliability")) + ast_log(LOG_WARNING, "tos value %s is deprecated. See doc/README.tos for more information.", value); + } else if (!strcasecmp(value, "reliability")) { *tos = IPTOS_RELIABILITY; - else if (!strcasecmp(value, "mincost")) + ast_log(LOG_WARNING, "tos value %s is deprecated. See doc/README.tos for more information.", value); + } else if (!strcasecmp(value, "mincost")) { *tos = IPTOS_MINCOST; - else if (!strcasecmp(value, "none")) + ast_log(LOG_WARNING, "tos value %s is deprecated. See doc/README.tos for more information.", value); + } else if (!strcasecmp(value, "none")) { *tos = 0; + ast_log(LOG_WARNING, "tos value %s is deprecated. See doc/README.tos for more information.", value); + } else if (!strcasecmp(value, "ef")) + *tos = 46 << 2; + else if (!strcasecmp(value, "af43")) + *tos = 38 << 2; + else if (!strcasecmp(value, "af42")) + *tos = 36 << 2; + else if (!strcasecmp(value, "af41")) + *tos = 34 << 2; + else if (!strcasecmp(value, "cs4")) + *tos = 32 << 2; + else if (!strcasecmp(value, "af33")) + *tos = 30 << 2; + else if (!strcasecmp(value, "af32")) + *tos = 28 << 2; + else if (!strcasecmp(value, "af31")) + *tos = 26 << 2; + else if (!strcasecmp(value, "cs3")) + *tos = 24 << 2; + else if (!strcasecmp(value, "af23")) + *tos = 22 << 2; + else if (!strcasecmp(value, "af22")) + *tos = 20 << 2; + else if (!strcasecmp(value, "af21")) + *tos = 18 << 2; + else if (!strcasecmp(value, "cs2")) + *tos = 16 << 2; + else if (!strcasecmp(value, "af13")) + *tos = 14 << 2; + else if (!strcasecmp(value, "af12")) + *tos = 12 << 2; + else if (!strcasecmp(value, "af11")) + *tos = 10 << 2; + else if (!strcasecmp(value, "cs1")) + *tos = 8 << 2; + else if (!strcasecmp(value, "be")) + *tos = 0; else return -1; return 0; Index: configs/sip.conf.sample =================================================================== --- configs/sip.conf.sample (revision 8749) +++ configs/sip.conf.sample (working copy) @@ -56,8 +56,12 @@ ;pedantic=yes ; Enable slow, pedantic checking for Pingtel ; and multiline formatted headers for strict ; SIP compatibility (defaults to "no") -;tos=184 ; Set IP QoS to either a keyword or numeric val -;tos=lowdelay ; lowdelay,throughput,reliability,mincost,none + +; See doc/README.tos 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. + ;maxexpiry=3600 ; Max length of incoming registrations/subscriptions we allow (seconds) ;minexpiry=60 ; Minimum length of registrations/subscriptions (default 60) ;defaultexpiry=120 ; Default length of incoming/outoing registration