diff --git a/daemon/call.c b/daemon/call.c index 6a6402e25..15a2043e5 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -735,6 +735,7 @@ alloc: g_queue_push_tail(&em->intf_sfds, em_il); while ((sock = g_queue_pop_head(&il->list))) { + set_tos(sock, media->call->tos); sfd = stream_fd_new(sock, media->call, il->local_intf); g_queue_push_tail(&em_il->list, sfd); /* not referenced */ } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 0d590df14..dee91d2cf 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -377,23 +377,7 @@ struct local_intf *get_any_interface_address(const struct logical_intf *lif, soc -/* XXX family specific */ -void set_tos(socket_t *sock, unsigned int tos) { - unsigned char ctos; - - ctos = tos; - - setsockopt(sock->fd, IPPROTO_IP, IP_TOS, &ctos, sizeof(tos)); -#ifdef IPV6_TCLASS - setsockopt(sock->fd, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)); -#else -#warning "Will not set IPv6 traffic class" -#endif -} - - /* XXX family specific? unify? */ -/* XXX set TOS after opening! */ static int get_port6(socket_t *r, unsigned int port, struct intf_spec *spec) { if (open_socket(r, SOCK_DGRAM, port, &spec->address.addr)) return -1; diff --git a/daemon/media_socket.h b/daemon/media_socket.h index c09897e71..4589d0625 100644 --- a/daemon/media_socket.h +++ b/daemon/media_socket.h @@ -74,7 +74,9 @@ void interfaces_exclude_port(unsigned int port); //int get_port(socket_t *r, unsigned int port, const struct local_intf *lif, const struct call *c); //void release_port(socket_t *r, const struct local_intf *); -void set_tos(socket_t *, unsigned int tos); +INLINE void set_tos(socket_t *s, unsigned int tos) { + s->family->tos(s, tos); +} int get_consecutive_ports(GQueue *out, unsigned int num_ports, const struct logical_intf *log); struct stream_fd *stream_fd_new(socket_t *fd, struct call *call, const struct local_intf *lif); diff --git a/daemon/socket.c b/daemon/socket.c index c3e000e02..65b1d13f9 100644 --- a/daemon/socket.c +++ b/daemon/socket.c @@ -27,6 +27,8 @@ static int __ip6_addrport2sockaddr(void *, const sockaddr_t *, unsigned int); static ssize_t __ip_recvfrom(socket_t *s, void *buf, size_t len, endpoint_t *ep); static ssize_t __ip_sendmsg(socket_t *s, struct msghdr *mh, const endpoint_t *ep); static ssize_t __ip_sendto(socket_t *s, const void *buf, size_t len, const endpoint_t *ep); +static int __ip4_tos(socket_t *, unsigned int); +static int __ip6_tos(socket_t *, unsigned int); @@ -57,6 +59,7 @@ static struct socket_family __socket_families[__SF_LAST] = { .recvfrom = __ip_recvfrom, .sendmsg = __ip_sendmsg, .sendto = __ip_sendto, + .tos = __ip4_tos, }, [SF_IP6] = { .af = AF_INET6, @@ -77,6 +80,7 @@ static struct socket_family __socket_families[__SF_LAST] = { .recvfrom = __ip_recvfrom, .sendmsg = __ip_sendmsg, .sendto = __ip_sendto, + .tos = __ip6_tos, }, }; @@ -233,6 +237,16 @@ static ssize_t __ip_sendto(socket_t *s, const void *buf, size_t len, const endpo s->family->endpoint2sockaddr(&sin, ep); return sendto(s->fd, buf, len, 0, (void *) &sin, s->family->sockaddr_size); } +static int __ip4_tos(socket_t *s, unsigned int tos) { + unsigned char ctos; + ctos = tos; + setsockopt(s->fd, IPPROTO_IP, IP_TOS, &ctos, sizeof(ctos)); + return 0; +} +static int __ip6_tos(socket_t *s, unsigned int tos) { + setsockopt(s->fd, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)); + return 0; +} diff --git a/daemon/socket.h b/daemon/socket.h index c00f5b85c..22b10dd56 100644 --- a/daemon/socket.h +++ b/daemon/socket.h @@ -60,6 +60,7 @@ struct socket_family { ssize_t (*recvfrom)(socket_t *, void *, size_t, endpoint_t *); ssize_t (*sendmsg)(socket_t *, struct msghdr *, const endpoint_t *); ssize_t (*sendto)(socket_t *, const void *, size_t, const endpoint_t *); + int (*tos)(socket_t *, unsigned int); }; struct socket_address { sockfamily_t *family;