# HG changeset patch # User Catalin Patulea # Date 1385996143 -28800 # Node ID 80af450dae76a265e5baa5fbaf4ed8323d4766dd # Parent c63e7644db604fa1612def0d0c11dc95bd6b0a18 Set IPTOS_LOWDELAY on PTY sessions only diff -r c63e7644db60 -r 80af450dae76 cli-chansession.c --- a/cli-chansession.c Mon Dec 02 22:15:17 2013 +0800 +++ b/cli-chansession.c Mon Dec 02 22:55:43 2013 +0800 @@ -369,6 +369,7 @@ if (cli_opts.wantpty) { send_chansess_pty_req(channel); + set_sock_priority(ses.sock_out); } send_chansess_shell_req(channel); diff -r c63e7644db60 -r 80af450dae76 dbutil.c --- a/dbutil.c Mon Dec 02 22:15:17 2013 +0800 +++ b/dbutil.c Mon Dec 02 22:55:43 2013 +0800 @@ -177,28 +177,41 @@ } #endif /* DEBUG_TRACE */ -static void set_sock_priority(int sock) { - +void set_sock_nodelay(int sock) { int val; /* disable nagle */ val = 1; setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); +} + +void set_sock_priority(int sock) { + + int val, rc; /* set the TOS bit for either ipv4 or ipv6 */ #ifdef IPTOS_LOWDELAY val = IPTOS_LOWDELAY; #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) - setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val)); + rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val)); + if (rc < 0) + dropbear_log(LOG_WARNING, "Couldn't set IPV6_TCLASS (%s)", + strerror(errno)); #endif - setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val)); + rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val)); + if (rc < 0) + dropbear_log(LOG_WARNING, "Couldn't set IP_TOS (%s)", + strerror(errno)); #endif #ifdef SO_PRIORITY /* linux specific, sets QoS class. * 6 looks to be optimal for interactive traffic (see tc-prio(8) ). */ - val = 6; - setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val)); + val = TC_PRIO_INTERACTIVE; + rc = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val)); + if (rc < 0) + dropbear_log(LOG_WARNING, "Couldn't set SO_PRIORITY (%s)", + strerror(errno)); #endif } @@ -290,7 +303,7 @@ } #endif - set_sock_priority(sock); + set_sock_nodelay(sock); if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) { err = errno; @@ -429,7 +442,7 @@ TRACE(("Error connecting: %s", strerror(err))) } else { /* Success */ - set_sock_priority(sock); + set_sock_nodelay(sock); } freeaddrinfo(res0); diff -r c63e7644db60 -r 80af450dae76 dbutil.h --- a/dbutil.h Mon Dec 02 22:15:17 2013 +0800 +++ b/dbutil.h Mon Dec 02 22:55:43 2013 +0800 @@ -66,6 +66,8 @@ char **remote_host, char **remote_port, int host_lookup); void getaddrstring(struct sockaddr_storage* addr, char **ret_host, char **ret_port, int host_lookup); +void set_sock_nodelay(int sock); +void set_sock_priority(int sock); int dropbear_listen(const char* address, const char* port, int *socks, unsigned int sockcount, char **errstring, int *maxfd); int spawn_command(void(*exec_fn)(void *user_data), void *exec_data, diff -r c63e7644db60 -r 80af450dae76 includes.h --- a/includes.h Mon Dec 02 22:15:17 2013 +0800 +++ b/includes.h Mon Dec 02 22:55:43 2013 +0800 @@ -156,6 +156,10 @@ typedef u_int32_t uint32_t; #endif /* HAVE_UINT32_T */ +#ifdef SO_PRIORITY +#include +#endif + #include "fake-rfc2553.h" #ifndef LOG_AUTHPRIV diff -r c63e7644db60 -r 80af450dae76 svr-chansession.c --- a/svr-chansession.c Mon Dec 02 22:15:17 2013 +0800 +++ b/svr-chansession.c Mon Dec 02 22:55:43 2013 +0800 @@ -580,6 +580,8 @@ /* Read the terminal modes */ get_termmodes(chansess); + set_sock_priority(ses.sock_out); + TRACE(("leave sessionpty")) return DROPBEAR_SUCCESS; }