summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2007-04-30 16:16:26 +0000
committerRussell Bryant <russell@russellbryant.com>2007-04-30 16:16:26 +0000
commitb419fc1134c7cb0b0ba92428185d3546be98cf11 (patch)
treed7bac5beb193490f4242d9a69cad3457727ba5d8 /main
parenta91f9b138db6eecfe65b29f788c82a688526b9cf (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 'main')
-rw-r--r--main/acl.c14
-rw-r--r--main/netsock.c37
-rw-r--r--main/rtp.c9
-rw-r--r--main/udptl.c9
4 files changed, 49 insertions, 20 deletions
diff --git a/main/acl.c b/main/acl.c
index 8d7dc4277..55654f714 100644
--- a/main/acl.c
+++ b/main/acl.c
@@ -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;
diff --git a/main/netsock.c b/main/netsock.c
index 9fa842ec3..6e01432d7 100644
--- a/main/netsock.c
+++ b/main/netsock.c
@@ -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)
diff --git a/main/rtp.c b/main/rtp.c
index 2c5347413..23d080639 100644
--- a/main/rtp.c
+++ b/main/rtp.c
@@ -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)
diff --git a/main/udptl.c b/main/udptl.c
index 39c047183..d255f9375 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -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)