Skip to contentSkip to conversation

add --dev-pipe option, use stdio of forked process for network frames

PATCH New Eric Wheeler 1 participant 1 message Feb 17, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add --dev-pipe option, use stdio of forked process for network frames

Hello all,

I wrote this back in the openvpn-2.2-beta3 days and always wanted to submit the code but never got to it---so here it is! I used it with a userspace slirp-stdio implementation to get a tunnel without root priveleges.

--dev-pipe /usr/local/bin/some_script arg1 arg2 ... arg15
Fork a program (such as /usr/local/bin/some_script ) and use
its stdio for network frames. OpenVPN will not open a
TUN/TAP device, thus root privelege is not required.

You must specify tun or tap as your --device-type if --dev does not provide auto-detection of the device type. (The
--dev device you specify will not be used.) Note that tun
and tap use different network frames: The tun interface excludes the Ethernet frame header, and is not suitable for use with programs like SLiRP. The tap interface uses a com‐ plete Ethernet frame.

I just forward-ported to 2.3.9 if anyone would like to test it and merge it in upstream (2.4 changed files around, it seems, so not sure about porting beyond 2.3.9). Tested and working in 2.2-beta3, compile-only tested in 2.3.9.

Cheers,

--
Eric Wheeler
https://www.linuxglobal.com

From 8cb721c4e76f4606f4452fd20a9c4d9bffc7685e Mon Sep 17 00:00:00 2001
From: Eric Wheeler <[email protected]...>
Date: Fri, 17 Feb 2017 14:18:40 -0800
Subject: [PATCH] Added --dev-pipe

---
 doc/openvpn.8         | 33 +++++++++++++++++++
 src/openvpn/init.c    | 91 +++++++++++++++++++++++++++++++++++++--------------
 src/openvpn/options.c | 10 ++++++
 src/openvpn/options.h |  2 ++
 4 files changed, 112 insertions(+), 24 deletions(-)
doc/openvpn.8 +33 -0
index d302baa..285ac39 100644
@@ -739,6 +739,39 @@ or
 .B tap.
 .\"*********************************************************
 .TP
+.B \-\-dev\-pipe /usr/local/bin/some_script arg1 arg2 ... arg15
+Fork a program (such as
+.B /usr/local/bin/some_script
+) and use its 
+.B stdio
+for network frames.  OpenVPN will not open a TUN/TAP device, thus root
+privelege is not required.  
+
+You must specify
+.B tun
+or
+.B tap
+as your 
+.B \-\-device\-type
+if
+.B \-\-dev
+does not provide auto-detection of the device type.
+(The
+.B \-\-dev
+device you specify will not be used.)  Note that
+.B tun
+and 
+.B tap
+use different network frames:  The
+.B tun
+interface excludes the Ethernet frame header, and is not suitable for use with
+programs like 
+.B SLiRP.
+The
+.B tap
+interface uses a complete Ethernet frame.  
+.\"*********************************************************
+.TP
 .B \-\-topology mode
 Configure virtual addressing topology when running in
 .B \-\-dev tun
src/openvpn/init.c +64 -24

97 lines not on this page · raw message

src/openvpn/options.c +10 -0
index 1832bc5..d3b70df 100644
@@ -178,6 +178,8 @@ static const char usage_message[] =
   "--dev-type dt   : Which device type are we using? (dt = tun or tap) Use\n"
   "                  this option only if the tun/tap device used with --dev\n"
   "                  does not begin with \"tun\" or \"tap\".\n"
+  "--dev-pipe prog : Use `prog`'s stdio for network frames instead of tun/tap\n"
+  "                  This does not need root since it will not open a device\n"
   "--dev-node node : Explicitly set the device node rather than using\n"
   "                  /dev/net/tun, /dev/tun, /dev/tap, etc.\n"
   "--lladdr hw     : Set the link layer address of the tap device.\n"
@@ -1450,6 +1452,7 @@ show_settings (const struct options *o)
   SHOW_STR (dev);
   SHOW_STR (dev_type);
   SHOW_STR (dev_node);
+  SHOW_STR (dev_pipe[0]);
   SHOW_STR (lladdr);
   SHOW_INT (topology);
   SHOW_BOOL (tun_ipv6);
@@ -4440,6 +4443,13 @@ add_option (struct options *options,
       VERIFY_PERMISSION (OPT_P_GENERAL);
       options->dev_type = p[1];
     }
+  else if (streq (p[0], "dev-pipe") && p[1])
+    {
+      int i;
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      for (i = 1; i < MAX_PARMS && p[i]; i++)
+        options->dev_pipe[i-1] = p[i];
+    }
   else if (streq (p[0], "dev-node") && p[1])
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
src/openvpn/options.h +2 -0
index 622706a..b9cde96 100644
@@ -598,6 +598,8 @@ struct options
 
   bool use_peer_id;
   uint32_t peer_id;
+
+  char *dev_pipe[MAX_PARMS];
 };
 
 #define streq(x, y) (!strcmp((x), (y)))
Signature · 1 line
1.8.3.1