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
1.6.0
Russell Bryant 18 years ago
parent a91f9b138d
commit b419fc1134

@ -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")) {

@ -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)

@ -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);

@ -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);
}
}
}

@ -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))

@ -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

@ -225,8 +225,9 @@ forcejitterbuffer=no
;
;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

@ -53,7 +53,7 @@ codec=ulaw
;
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

@ -5,6 +5,9 @@
;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
; MGCP channel. Defaults to "no". An enabled jitterbuffer will

@ -57,10 +57,16 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
; 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)

@ -44,8 +44,8 @@ reference purposes.
\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}

@ -57,6 +57,9 @@ int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *se
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);

@ -41,10 +41,10 @@ struct ast_netsock_list *ast_netsock_list_alloc(void);
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);
@ -53,6 +53,8 @@ int ast_netsock_release(struct ast_netsock_list *list);
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);
const struct sockaddr_in *ast_netsock_boundaddr(const struct ast_netsock *ns);

@ -168,7 +168,7 @@ int ast_rtp_senddigit_end(struct ast_rtp *rtp, char digit);
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);

@ -73,7 +73,7 @@ struct ast_frame *ast_udptl_read(struct ast_udptl *udptl);
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);

@ -278,6 +278,20 @@ static const struct dscp_codepoint dscp_pool1[] = {
{ "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;

@ -119,7 +119,7 @@ struct ast_netsock *ast_netsock_find(struct ast_netsock_list *list,
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 @@ struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct i
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 @@ struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct i
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 @@ struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_co
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)

@ -53,6 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#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 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io,
return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia);
}
int ast_rtp_settos(struct ast_rtp *rtp, int tos)
int ast_rtp_setqos(struct ast_rtp *rtp, int tos, int cos)
{
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;
return ast_netsock_set_qos(rtp->s, tos, cos);
}
void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them)

@ -73,6 +73,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#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 @@ struct ast_udptl *ast_udptl_new(struct sched_context *sched, struct io_context *
return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
}
int ast_udptl_settos(struct ast_udptl *udptl, int tos)
int ast_udptl_setqos(struct ast_udptl *udptl, int tos, int cos)
{
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;
return ast_netsock_set_qos(udptl->fd, tos, cos);
}
void ast_udptl_set_peer(struct ast_udptl *udptl, struct sockaddr_in *them)

@ -68,6 +68,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#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 @@ static int load_module(void)
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");

Loading…
Cancel
Save