Browse Source

refine tos setsockopt in redir and udprelay

make tos setup working at ipv4 and ipv6
pull/2592/head
babarosaM33 5 years ago
parent
commit
4d617adfb0
2 changed files with 15 additions and 4 deletions
  1. 9
      src/redir.c
  2. 10
      src/udprelay.c

9
src/redir.c

@ -752,8 +752,13 @@ accept_cb(EV_P_ ev_io *w, int revents)
setnonblocking(remotefd);
if (listener->tos >= 0) {
if (setsockopt(remotefd, IPPROTO_IP, IP_TOS, &listener->tos, sizeof(listener->tos)) != 0) {
ERROR("setsockopt IP_TOS");
int rc = setsockopt(remotefd, IPPROTO_IP, IP_TOS, &listener->tos, sizeof(listener->tos));
if (rc < 0 && errno != ENOPROTOOPT) {
LOGE("setting ipv4 dscp failed: %d", errno);
}
rc = setsockopt(remotefd, IPPROTO_IPV6, IPV6_TCLASS, &listener->tos, sizeof(listener->tos));
if (rc < 0 && errno != ENOPROTOOPT) {
LOGE("setting ipv6 dscp failed: %d", errno);
}
}

10
src/udprelay.c

@ -497,8 +497,14 @@ create_server_socket(const char *host, const char *port)
#ifdef IP_TOS
// Set QoS flag
int tos = 46 << 2;
int proto = rp->ai_family == AF_INET6 ? IPPROTO_IP : IPPROTO_IPV6;
setsockopt(server_sock, proto, IP_TOS, &tos, sizeof(tos));
int rc = setsockopt(server_sock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
if (rc < 0 && errno != ENOPROTOOPT) {
LOGE("setting ipv4 dscp failed: %d", errno);
}
rc = setsockopt(server_sock, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos));
if (rc < 0 && errno != ENOPROTOOPT) {
LOGE("setting ipv6 dscp failed: %d", errno);
}
#endif
#ifdef MODULE_REDIR

Loading…
Cancel
Save