diff options
author | Russell Bryant <russell@russellbryant.com> | 2007-04-30 16:16:26 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2007-04-30 16:16:26 +0000 |
commit | b419fc1134c7cb0b0ba92428185d3546be98cf11 (patch) | |
tree | d7bac5beb193490f4242d9a69cad3457727ba5d8 /channels | |
parent | a91f9b138db6eecfe65b29f788c82a688526b9cf (diff) |
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)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@62457 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_h323.c | 27 | ||||
-rw-r--r-- | channels/chan_iax2.c | 21 | ||||
-rw-r--r-- | channels/chan_mgcp.c | 28 | ||||
-rw-r--r-- | channels/chan_sip.c | 49 | ||||
-rw-r--r-- | channels/iax2-provision.c | 2 |
5 files changed, 74 insertions, 53 deletions
diff --git a/channels/chan_h323.c b/channels/chan_h323.c index 70725aca7..65154b618 100644 --- a/channels/chan_h323.c +++ b/channels/chan_h323.c @@ -149,7 +149,8 @@ static int gkroute = 0; /* 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 @@ static int __oh323_rtp_create(struct oh323_pvt *pvt) 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 struct ast_cli_entry cli_h323[] = { 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 @@ static int reload_config(int is_reload) 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 @@ static int reload_config(int is_reload) 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")) { diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 6b943ea58..a250899a6 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -178,6 +178,8 @@ static int iaxdefaulttimeout = 5; /* Default to wait no more than 5 seconds for static unsigned int tos = 0; +static unsigned int cos = 0; + static int min_reg_expire; static int max_reg_expire; @@ -8538,7 +8540,7 @@ static int peer_set_srcaddr(struct iax2_peer *peer, const char *srcaddr) 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 @@ static int set_config(char *config_file, int reload) 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 @@ static int set_config(char *config_file, int reload) 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 @@ static int set_config(char *config_file, int reload) 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 @@ static int set_config(char *config_file, int reload) } 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) diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index b39e1fbdd..f9caf584d 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -71,6 +71,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #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 int nat = 0; 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 @@ static int reload_config(void) 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 @@ static int reload_config(void) 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); diff --git a/channels/chan_sip.c b/channels/chan_sip.c index cdff58927..174e2c361 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -136,6 +136,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #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 @@ static const struct cfsip_options { #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_sip; /*!< IP type of service for SIP packets */ 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 @@ static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *si 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 @@ static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *si 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 @@ static int sip_show_settings(int fd, int argc, char *argv[]) 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 @@ static int reload_config(enum channelreloadreason reason) 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 @@ static int reload_config(enum channelreloadreason reason) 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 @@ static int reload_config(enum channelreloadreason reason) 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); } } } diff --git a/channels/iax2-provision.c b/channels/iax2-provision.c index 159d8686e..5a484fda5 100644 --- a/channels/iax2-provision.c +++ b/channels/iax2-provision.c @@ -332,7 +332,7 @@ static int iax_template_parse(struct iax_template *cur, struct ast_config *cfg, 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)) |