diff --git a/libtransmission/net.c b/libtransmission/net.c index fd5f37e65..ecc99aded 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -176,33 +176,11 @@ void tr_netSetTOS(tr_socket_t s, int tos, tr_address_type type) else if (type == TR_AF_INET6) { #if defined(IPV6_TCLASS) && !defined(_WIN32) - - int dscp = 0; - - switch (tos) - { - case 0x10: - dscp = 0x20; /* lowcost (CS1) */ - break; - - case 0x08: - dscp = 0x28; /* throughput (AF11) */ - break; - - case 0x04: - dscp = 0x04; /* reliability */ - break; - - case 0x02: - dscp = 0x30; /* low delay (AF12) */ - break; - } - - if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, (void const*)&dscp, sizeof(dscp)) == -1) + if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, (void const*)&tos, sizeof(tos)) == -1) { char err_buf[512]; tr_net_strerror(err_buf, sizeof(err_buf), sockerrno); - tr_logAddNamedInfo("Net", "Can't set IPv6 QoS '%d': %s", dscp, err_buf); + tr_logAddNamedInfo("Net", "Can't set IPv6 QoS '%d': %s", tos, err_buf); } #else diff --git a/libtransmission/net.h b/libtransmission/net.h index 66b3449e7..1e4361061 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -118,6 +118,15 @@ static inline bool tr_address_is_valid(tr_address const* a) * Sockets **********************************************************************/ +/* https://en.wikipedia.org/wiki/Differentiated_services#Class_Selector */ +enum +{ + TR_IPTOS_LOWCOST = 0x38, /* AF13: low prio, high drop */ + TR_IPTOS_LOWDELAY = 0x70, /* AF32: high prio, mid drop */ + TR_IPTOS_THRUPUT = 0x20, /* CS1: low prio, undef drop */ + TR_IPTOS_RELIABLE = 0x28 /* AF11: low prio, low drop */ +}; + struct tr_session; struct tr_peer_socket tr_netOpenPeerSocket(tr_session* session, tr_address const* addr, tr_port port, bool clientIsSeed); diff --git a/libtransmission/session.c b/libtransmission/session.c index 73e1f2569..94faf446d 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -265,27 +265,27 @@ static int parse_tos(char const* str) if (evutil_ascii_strcasecmp(str, "lowcost") == 0) { - return 0x10; + return TR_IPTOS_LOWCOST; } if (evutil_ascii_strcasecmp(str, "mincost") == 0) { - return 0x10; + return TR_IPTOS_LOWCOST; } if (evutil_ascii_strcasecmp(str, "throughput") == 0) { - return 0x08; + return TR_IPTOS_THRUPUT; } if (evutil_ascii_strcasecmp(str, "reliability") == 0) { - return 0x04; + return TR_IPTOS_RELIABLE; } if (evutil_ascii_strcasecmp(str, "lowdelay") == 0) { - return 0x02; + return TR_IPTOS_LOWDELAY; } value = strtol(str, &p, 0); @@ -307,16 +307,16 @@ static char const* format_tos(int value) case 0: return "default"; - case 0x10: + case TR_IPTOS_LOWCOST: return "lowcost"; - case 0x08: + case TR_IPTOS_THRUPUT: return "throughput"; - case 0x04: + case TR_IPTOS_RELIABLE: return "reliability"; - case 0x02: + case TR_IPTOS_LOWDELAY: return "lowdelay"; default: