]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Added --tcp-nodelay option: Macro that sets TCP_NODELAY socket
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Tue, 18 Nov 2008 05:15:22 +0000 (05:15 +0000)
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Tue, 18 Nov 2008 05:15:22 +0000 (05:15 +0000)
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
helper.h
openvpn.8
options.c
options.h

index 2abb417e7a0895a7157e51778947cb826f8a619a..a8bbea02d7a54fcb6ff8d734d920ebef4b489cc1 100644 (file)
--- 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
+}
index 2677f58942300ce36857e7ac009e17fa565de6a1..52a3a40c1ee581d0fc7924902bc1fbc01e9587e9 100644 (file)
--- 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
index 790501d29d2a3ee1b4ceebad545deaccfcdd8739..ab56e97f5f32d1c634bd3accf69435ee1a3223b2 100644 (file)
--- 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
index 33234c5b5a530ac61f92bb1d2a467ecb54a77c2d..44f12a19f06aa9c2d890ffc310610eb489097900 100644 (file)
--- 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"))
index 7ea4191ffe93577b7eac5826486204cb10caaf4f..a7a039155614ef953e09f8a50187ff0b3b7186e0 100644 (file)
--- 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;