From ae3b37460b677ebd6f1ad12dab76055e7879fcaf Mon Sep 17 00:00:00 2001 From: james Date: Tue, 18 Nov 2008 05:15:22 +0000 Subject: Added --tcp-nodelay option: Macro that sets TCP_NODELAY socket flag on the server as well as pushes it to connecting clients. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@3513 e7ae566f-a301-0410-adde-c780ea21d3b5 --- helper.c | 39 +++++++++++++++++++++++++++++++++++++++ helper.h | 1 + openvpn.8 | 25 +++++++++++++++++++++++++ options.c | 10 ++++++++++ options.h | 1 + 5 files changed, 76 insertions(+) diff --git a/helper.c b/helper.c index 2abb417..a8bbea0 100644 --- a/helper.c +++ b/helper.c @@ -96,6 +96,14 @@ print_str_int (const char *str, const int i, struct gc_arena *gc) return BSTR (&out); } +static const char * +print_str (const char *str, struct gc_arena *gc) +{ + struct buffer out = alloc_buf_gc (128, gc); + buf_printf (&out, "%s", str); + return BSTR (&out); +} + static void helper_add_route (const in_addr_t network, const in_addr_t netmask, struct options *o) { @@ -438,3 +446,34 @@ helper_keepalive (struct options *o) } } } + +/* + * + * HELPER DIRECTIVE: + * + * tcp-nodelay + * + * EXPANDS TO: + * + * if mode server: + * socket-flags TCP_NODELAY + * push "socket-flags TCP_NODELAY" + */ +void +helper_tcp_nodelay (struct options *o) +{ +#if P2MP_SERVER + if (o->server_flags & SF_TCP_NODELAY_HELPER) + { + if (o->mode == MODE_SERVER) + { + o->sockflags |= SF_TCP_NODELAY; + push_option (o, print_str ("socket-flags TCP_NODELAY", &o->gc), M_USAGE); + } + else + { + ASSERT (0); + } + } +#endif +} diff --git a/helper.h b/helper.h index 2677f58..52a3a40 100644 --- a/helper.h +++ b/helper.h @@ -33,5 +33,6 @@ void helper_keepalive (struct options *o); void helper_client_server (struct options *o); +void helper_tcp_nodelay (struct options *o); #endif diff --git a/openvpn.8 b/openvpn.8 index 790501d..ab56e97 100644 --- a/openvpn.8 +++ b/openvpn.8 @@ -2866,6 +2866,31 @@ OpenVPN will start to drop outgoing packets directed at this client. .\"********************************************************* .TP +.B --tcp-nodelay +This macro sets the TCP_NODELAY socket flag on the server +as well as pushes it to connecting clients. The TCP_NODELAY +flag disables the Nagle algorithm on TCP sockets causing +packets to be transmitted immediately with low latency, +rather than waiting a short period of time in order +to aggregate several packets into a larger containing +packet. In VPN applications over TCP, TCP_NODELAY +is generally a good latency optimization. + +The macro expands as follows: + +.RS +.ft 3 +.nf +.sp + if mode server: + socket-flags TCP_NODELAY + push "socket-flags TCP_NODELAY" +.ft +.LP +.RE +.fi +.\"********************************************************* +.TP .B --max-clients n Limit server to a maximum of .B n diff --git a/options.c b/options.c index 33234c5..44f12a1 100644 --- a/options.c +++ b/options.c @@ -402,6 +402,8 @@ static const char usage_message[] = " virtual address table to v.\n" "--bcast-buffers n : Allocate n broadcast buffers.\n" "--tcp-queue-limit n : Maximum number of queued TCP output packets.\n" + "--tcp-nodelay : Macro that sets TCP_NODELAY socket flag on the server\n" + " as well as pushes it to connecting clients.\n" "--learn-address cmd : Run script cmd to validate client virtual addresses.\n" "--connect-freq n s : Allow a maximum of n new connections per s seconds.\n" "--max-clients n : Allow a maximum of n simultaneously connected clients.\n" @@ -1764,6 +1766,8 @@ options_postprocess_verify_ce (const struct options *options, const struct conne msg (M_USAGE, "--no-name-remapping requires --mode server"); if (options->ssl_flags & SSLF_OPT_VERIFY) msg (M_USAGE, "--opt-verify requires --mode server"); + if (options->server_flags & SF_TCP_NODELAY_HELPER) + msg (M_USAGE, "--tcp-nodelay requires --mode server"); if (options->auth_user_pass_verify_script) msg (M_USAGE, "--auth-user-pass-verify requires --mode server"); #if PORT_SHARE @@ -2065,6 +2069,7 @@ options_postprocess_mutate (struct options *o) */ helper_client_server (o); helper_keepalive (o); + helper_tcp_nodelay (o); options_postprocess_mutate_invariant (o); @@ -4797,6 +4802,11 @@ add_option (struct options *options, VERIFY_PERMISSION (OPT_P_INSTANCE); options->disable = true; } + else if (streq (p[0], "tcp-nodelay")) + { + VERIFY_PERMISSION (OPT_P_GENERAL); + options->server_flags |= SF_TCP_NODELAY_HELPER; + } #endif /* P2MP_SERVER */ else if (streq (p[0], "client")) diff --git a/options.h b/options.h index 7ea4191..a7a0391 100644 --- a/options.h +++ b/options.h @@ -346,6 +346,7 @@ struct options in_addr_t server_netmask; # define SF_NOPOOL (1<<0) +# define SF_TCP_NODELAY_HELPER (1<<1) unsigned int server_flags; bool server_bridge_proxy_dhcp; -- cgit v1.2.3