mirror of
https://github.com/clearml/dropbear
synced 2025-02-12 07:25:30 +00:00
- new function to set "low delay" for a packet, set the ip TOS bit
(can help significantly over some links) --HG-- extra : convert_revision : 685c1004b66533aebbd45810533de698a786a4ea
This commit is contained in:
parent
a43af44e9c
commit
a2d343b108
30
dbutil.c
30
dbutil.c
@ -153,6 +153,30 @@ void dropbear_trace(const char* format, ...) {
|
|||||||
}
|
}
|
||||||
#endif /* DEBUG_TRACE */
|
#endif /* DEBUG_TRACE */
|
||||||
|
|
||||||
|
static void set_sock_priority(int sock) {
|
||||||
|
|
||||||
|
int val;
|
||||||
|
|
||||||
|
/* disable nagle */
|
||||||
|
val = 1;
|
||||||
|
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val));
|
||||||
|
|
||||||
|
/* set the TOS bit. note that this will fail for ipv6, I can't find any
|
||||||
|
* equivalent. */
|
||||||
|
#ifdef IPTOS_LOWDELAY
|
||||||
|
val = IPTOS_LOWDELAY;
|
||||||
|
setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val));
|
||||||
|
#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));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Listen on address:port. Unless address is NULL, in which case listen on
|
/* Listen on address:port. Unless address is NULL, in which case listen on
|
||||||
* everything. If called with address == "", we'll listen on localhost/loopback.
|
* everything. If called with address == "", we'll listen on localhost/loopback.
|
||||||
* Returns the number of sockets bound on success, or -1 on failure. On
|
* Returns the number of sockets bound on success, or -1 on failure. On
|
||||||
@ -223,8 +247,7 @@ int dropbear_listen(const char* address, const char* port,
|
|||||||
linger.l_linger = 5;
|
linger.l_linger = 5;
|
||||||
setsockopt(sock, SOL_SOCKET, SO_LINGER, (void*)&linger, sizeof(linger));
|
setsockopt(sock, SOL_SOCKET, SO_LINGER, (void*)&linger, sizeof(linger));
|
||||||
|
|
||||||
/* disable nagle */
|
set_sock_priority(sock);
|
||||||
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val));
|
|
||||||
|
|
||||||
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
|
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
|
||||||
err = errno;
|
err = errno;
|
||||||
@ -347,8 +370,7 @@ int connect_remote(const char* remotehost, const char* remoteport,
|
|||||||
TRACE(("Error connecting: %s", strerror(err)))
|
TRACE(("Error connecting: %s", strerror(err)))
|
||||||
} else {
|
} else {
|
||||||
/* Success */
|
/* Success */
|
||||||
/* (err is used as a dummy var here) */
|
set_sock_priority(sock);
|
||||||
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&err, sizeof(err));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/ip.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user