Change in openvpn[master]: Introduce DRIVER_AFUNIX backend for use with lwipovpn
A message that is not in the archive (sent off-list or not yet received): gerrit.1726491830000.I65099ef00822d08fd3f5480c80892f3bf86c56e7@...2715...
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
to review the following change.
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/ssl.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
13 files changed, 383 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/1
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``dev-node:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can server a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will create a temporary unix domain socket and start the program + will pass the tun configuration as environment variables. + The temporary unix will be be passed in the environment variable + :code:`TUN_UNIXAF_PATH`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -138,6 +138,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =tun_afunix_read (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =tun_afunix_write (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +43 -10
127 lines not on this page · raw message
src/openvpn/run_command.c +5 -0
@@ -204,6 +204,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process exist status return the +* pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/ssl.h +1 -1
@@ -219,7 +219,7 @@void tls_multi_free (struct tls_multi *multi,bool clear);/** @} name Functions for initialization and cleanup of tls_multi structures */ - +\/** @} addtogroup control_processor */ #define TLSMP_INACTIVE 0
src/openvpn/tun.c +3 -0
@@ -75,6 +75,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +#ifdef HAVE_NET_IF_UTUN_H case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +33 -3
@@ -50,6 +50,10 @@#else DRIVER_GENERIC_TUNTAP,#endif +/** using an AF_UNIX socket to pass packet from/to an external program +* this is always defined. We error out if a user tries to open this type +* on unsupported platforms*/ + DRIVER_AFUNIX, DRIVER_DCO,#ifdef HAVE_NET_IF_UTUN_H DRIVER_UTUN
@@ -165,6 +169,15 @@/* * Define a TUN/TAP dev. */ +#ifdef AF_UNIX +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* ifdef AF_UNIX */ +typedef struct {}afunix_context_t ; +#endif struct tuntap {
@@ -179,7 +192,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -231,6 +249,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -354,8 +373,14 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + } +#endif #if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -380,8 +405,14 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + } +#endif #if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -759,5 +790,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +180 -0
180 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
Signature · 13 lines
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7 Gerrit-Change-Number: 747 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos <[email protected]...> Gerrit-Reviewer: flichtenheld <[email protected]...> Gerrit-CC: openvpn-devel <[email protected]> Gerrit-Attention: flichtenheld <[email protected]...> Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
to look at the new patch set (#2).
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/ssl.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
13 files changed, 380 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/2
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``dev-node:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can server a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will create a temporary unix domain socket and start the program + will pass the tun configuration as environment variables. + The temporary unix will be be passed in the environment variable + :code:`TUN_UNIXAF_PATH`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -138,6 +138,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =tun_afunix_read (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =tun_afunix_write (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +43 -10
127 lines not on this page · raw message
src/openvpn/run_command.c +5 -0
@@ -204,6 +204,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process exist status return the +* pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/ssl.h +1 -1
@@ -219,7 +219,7 @@void tls_multi_free (struct tls_multi *multi,bool clear);/** @} name Functions for initialization and cleanup of tls_multi structures */ - +\/** @} addtogroup control_processor */ #define TLSMP_INACTIVE 0
src/openvpn/tun.c +3 -0
@@ -75,6 +75,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +#ifdef HAVE_NET_IF_UTUN_H case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +33 -3
@@ -50,6 +50,10 @@#else DRIVER_GENERIC_TUNTAP,#endif +/** using an AF_UNIX socket to pass packet from/to an external program +* this is always defined. We error out if a user tries to open this type +* on unsupported platforms*/ + DRIVER_AFUNIX, DRIVER_DCO,#ifdef HAVE_NET_IF_UTUN_H DRIVER_UTUN
@@ -165,6 +169,15 @@/* * Define a TUN/TAP dev. */ +#ifdef AF_UNIX +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* ifdef AF_UNIX */ +typedef struct {}afunix_context_t ; +#endif struct tuntap {
@@ -179,7 +192,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -231,6 +249,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -354,8 +373,14 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + } +#endif #if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -380,8 +405,14 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + } +#endif #if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -759,5 +790,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +177 -0
177 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Patch Set 2: Code-Review-1
(12 comments)
File Changes.rst:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/99476969_1d8d6408 :
PS1, Line 19: ``dev-node:/path/to/lwipovpn`` can emulate a full client that
Shouldn't that be "unix:" ?
http://gerrit.openvpn.net/c/openvpn/+/747/comment/4595f086_fbf96ee6 :
PS1, Line 20: can be pinged, can server a website and more without requiring any
"serve"
File doc/man-sections/vpn-network-options.rst:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/8717edec_dfc8d582 :
PS1, Line 123: will pass the tun configuration as environment variables.
". It will pass" ?
http://gerrit.openvpn.net/c/openvpn/+/747/comment/cd99d110_cddddeda :
PS1, Line 124: The temporary unix will be be passed in the environment variable
"unix domain socket" ?
File src/openvpn/run_command.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/7a11ae03_196cec21 :
PS1, Line 50: /** instead of waiting for child process exist status return the "exist" -> "exit"?
File src/openvpn/run_command.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/3b124102_8e33ed47 :
PS1, Line 196: openvpn_execve
Aren't there changes missing to openvpn_execve in this patch?
File src/openvpn/ssl.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/d01d26be_8db826f8 :
PS1, Line 222: \
Spurious change?
File src/openvpn/tun.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/f4047f82_66d132b0 :
PS1, Line 54: * this is always defined. We error out if a user tries to open this type
". This"
http://gerrit.openvpn.net/c/openvpn/+/747/comment/99d6ccec_0c9c6678 :
PS1, Line 55: * on unsupported platforms*/
"platforms. "
File src/openvpn/tun_afunix.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/89a22cf1_1fdfde67 :
PS1, Line 32: * the user provided to that will take care of implementing the actual tun Superfluous "to"?
http://gerrit.openvpn.net/c/openvpn/+/747/comment/7325e601_60f01d40 :
PS1, Line 33: * device
Missing full stop "."
http://gerrit.openvpn.net/c/openvpn/+/747/comment/5cee7cb8_700a23b3 :
PS1, Line 56: * Reads a packet from a AF_UNIX based tun devices "device"
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Mon, 16 Sep 2024 15:10:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
to look at the new patch set (#3).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/ssl.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
13 files changed, 389 insertions(+), 17 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/3
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``dev-node:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can server a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will create a temporary unix domain socket and start the program + will pass the tun configuration as environment variables. + The temporary unix will be be passed in the environment variable + :code:`TUN_UNIXAF_PATH`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -138,6 +138,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =tun_afunix_read (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =tun_afunix_write (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +47 -11
132 lines not on this page · raw message
src/openvpn/run_command.c +9 -0
@@ -155,6 +155,10 @@ {msg (M_ERR ,"openvpn_execve: unable to fork" ); } + else if (flags & S_NOWAITPID) + { + ret = pid; + } else /* parent side */ {if (waitpid (pid, &ret,0 ) != pid)
@@ -204,6 +208,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process exist status return the +* pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/ssl.h +1 -1
@@ -219,7 +219,7 @@void tls_multi_free (struct tls_multi *multi,bool clear);/** @} name Functions for initialization and cleanup of tls_multi structures */ - +\/** @} addtogroup control_processor */ #define TLSMP_INACTIVE 0
src/openvpn/tun.c +3 -0
@@ -75,6 +75,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +#ifdef HAVE_NET_IF_UTUN_H case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +33 -3
@@ -50,6 +50,10 @@#else DRIVER_GENERIC_TUNTAP,#endif +/** using an AF_UNIX socket to pass packet from/to an external program +* this is always defined. We error out if a user tries to open this type +* on unsupported platforms*/ + DRIVER_AFUNIX, DRIVER_DCO,#ifdef HAVE_NET_IF_UTUN_H DRIVER_UTUN
@@ -165,6 +169,15 @@/* * Define a TUN/TAP dev. */ +#ifdef AF_UNIX +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* ifdef AF_UNIX */ +typedef struct {}afunix_context_t ; +#endif struct tuntap {
@@ -179,7 +192,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -231,6 +249,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -354,8 +373,14 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + } +#endif #if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -380,8 +405,14 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + } +#endif #if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -759,5 +790,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +178 -0
178 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
to look at the new patch set (#4).
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/ssl.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
13 files changed, 391 insertions(+), 17 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/4
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``dev-node:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can server a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will create a temporary unix domain socket and start the program + will pass the tun configuration as environment variables. + The temporary unix will be be passed in the environment variable + :code:`TUN_UNIXAF_PATH`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -138,6 +138,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =tun_afunix_read (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =tun_afunix_write (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +47 -11
132 lines not on this page · raw message
src/openvpn/run_command.c +9 -0
@@ -155,6 +155,10 @@ {msg (M_ERR ,"openvpn_execve: unable to fork" ); } + else if (flags & S_NOWAITPID) + { + ret = pid; + } else /* parent side */ {if (waitpid (pid, &ret,0 ) != pid)
@@ -204,6 +208,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process exist status return the +* pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/ssl.h +1 -1
@@ -219,7 +219,7 @@void tls_multi_free (struct tls_multi *multi,bool clear);/** @} name Functions for initialization and cleanup of tls_multi structures */ - +\/** @} addtogroup control_processor */ #define TLSMP_INACTIVE 0
src/openvpn/tun.c +3 -0
@@ -75,6 +75,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +#ifdef HAVE_NET_IF_UTUN_H case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +35 -3
@@ -50,6 +50,10 @@#else DRIVER_GENERIC_TUNTAP,#endif +/** using an AF_UNIX socket to pass packet from/to an external program +* this is always defined. We error out if a user tries to open this type +* on unsupported platforms*/ + DRIVER_AFUNIX, DRIVER_DCO,#ifdef HAVE_NET_IF_UTUN_H DRIVER_UTUN
@@ -165,6 +169,17 @@/* * Define a TUN/TAP dev. */ +#if defined(AF_UNIX ) && !defined(WIN32 ) +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* if defined(AF_UNIX) && !defined(WIN32) */ +typedef struct { +int dummy; +}afunix_context_t ; +#endif struct tuntap {
@@ -179,7 +194,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -231,6 +251,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -354,8 +375,14 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + } +#endif #if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -380,8 +407,14 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + } +#endif #if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -759,5 +792,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +178 -0
178 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
to look at the new patch set (#6).
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
12 files changed, 390 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/6
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``--dev-node unix:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can serve a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will start the program and create a temporary unix domain socket that + will be passed to the program together with the tun configuration as + environment variables. The temporary unix domain socket will be be passed + in the environment variable :code:`TUNTAP_SOCKET_FD`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -140,6 +140,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =tun_afunix_read (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =tun_afunix_write (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +47 -11
132 lines not on this page · raw message
src/openvpn/run_command.c +9 -0
@@ -155,6 +155,10 @@ {msg (M_ERR ,"openvpn_execve: unable to fork" ); } + else if (flags & S_NOWAITPID) + { + ret = pid; + } else /* parent side */ {if (waitpid (pid, &ret,0 ) != pid)
@@ -204,6 +208,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process to exit and report the status, +* return the pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/tun.c +3 -0
@@ -75,6 +75,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +#ifdef HAVE_NET_IF_UTUN_H case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +35 -3
@@ -50,6 +50,10 @@#else DRIVER_GENERIC_TUNTAP,#endif +/** using an AF_UNIX socket to pass packets from/to an external program. +* This is always defined. We error out if a user tries to open this type +* of backend on unsupported platforms. */ + DRIVER_AFUNIX, DRIVER_DCO,#ifdef HAVE_NET_IF_UTUN_H DRIVER_UTUN
@@ -165,6 +169,17 @@/* * Define a TUN/TAP dev. */ +#if defined(AF_UNIX ) && !defined(WIN32 ) +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* if defined(AF_UNIX) && !defined(WIN32) */ +typedef struct { +int dummy; +}afunix_context_t ; +#endif struct tuntap {
@@ -179,7 +194,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -231,6 +251,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -354,8 +375,14 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + } +#endif #if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -380,8 +407,14 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + } +#endif #if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -759,5 +792,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +178 -0
178 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Patch Set 6:
(11 comments)
File Changes.rst:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/b63d509d_2a0f71c0 :
PS1, Line 19: ``dev-node:/path/to/lwipovpn`` can emulate a full client that
Quoted 1 line
Shouldn't that be "unix:" ?
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/747/comment/3afc6112_dfb74e8e :
PS1, Line 20: can be pinged, can server a website and more without requiring any
Quoted 1 line
"serve"
Acknowledged
File doc/man-sections/vpn-network-options.rst:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/dbeb5e05_fce150de :
PS1, Line 123: will pass the tun configuration as environment variables.
Quoted 1 line
". […]
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/747/comment/b77c1645_98184cf9 :
PS1, Line 124: The temporary unix will be be passed in the environment variable
Quoted 1 line
"unix domain socket" ?
Acknowledged
File src/openvpn/run_command.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/25287472_63072ada :
PS1, Line 50: /** instead of waiting for child process exist status return the
Quoted 1 line
"exist" -> "exit"?
Acknowledged
File src/openvpn/run_command.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/ec7cc4f3_75a1d08b :
PS1, Line 196: openvpn_execve
Quoted 1 line
Aren't there changes missing to
openvpn_execvein this patch?
Yes. They should be now there in the current. version
File src/openvpn/ssl.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/67544632_76ef8bbc :
PS1, Line 222: \
Quoted 1 line
Spurious change?
Acknowledged
File src/openvpn/tun.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/fcd22e1e_00ef5a87 :
PS1, Line 54: * this is always defined. We error out if a user tries to open this type
Quoted 1 line
". […]
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/747/comment/76c790a0_ec4dad57 :
PS1, Line 55: * on unsupported platforms*/
Quoted 1 line
"platforms. […]
Acknowledged
File src/openvpn/tun_afunix.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/f537515b_57d9a083 :
PS1, Line 32: * the user provided to that will take care of implementing the actual tun
Quoted 1 line
Superfluous "to"?
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/747/comment/1841cd16_fe4cde55 :
PS1, Line 33: * device
Quoted 1 line
Missing full stop ". […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Sep 2024 16:31:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Patch Set 6:
(1 comment)
File src/openvpn/tun_afunix.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/81f89bfa_53901669 :
PS1, Line 56: * Reads a packet from a AF_UNIX based tun devices
Quoted 1 line
"device"
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 18 Sep 2024 12:48:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
to look at the new patch set (#7).
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
13 files changed, 398 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/7
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``--dev-node unix:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can serve a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will start the program and create a temporary unix domain socket that + will be passed to the program together with the tun configuration as + environment variables. The temporary unix domain socket will be be passed + in the environment variable :code:`TUNTAP_SOCKET_FD`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -140,6 +140,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/dco.c +8 -0
@@ -41,6 +41,7 @@#include "ssl_common.h" #include "ssl_ncp.h" #include "tun.h" +#include "tun_afunix.h" #ifdef HAVE_LIBCAPNG #include <cap-ng.h>
@@ -298,6 +299,13 @@return false; } +if (is_tun_afunix (o->dev_node)) + { +msg (msglevel,"Note: afunix tun type selected, disabling data channel" +"offload" ); +return false; + } +if (o->connection_list) {const struct connection_list *l = o->connection_list;
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =tun_afunix_read (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =tun_afunix_write (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +47 -11
132 lines not on this page · raw message
src/openvpn/run_command.c +9 -0
@@ -155,6 +155,10 @@ {msg (M_ERR ,"openvpn_execve: unable to fork" ); } + else if (flags & S_NOWAITPID) + { + ret = pid; + } else /* parent side */ {if (waitpid (pid, &ret,0 ) != pid)
@@ -204,6 +208,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process to exit and report the status, +* return the pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/tun.c +3 -0
@@ -72,6 +72,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +35 -3
@@ -47,6 +47,10 @@WINDOWS_DRIVER_TAP_WINDOWS6 ,WINDOWS_DRIVER_WINTUN ,DRIVER_GENERIC_TUNTAP , +/** using an AF_UNIX socket to pass packets from/to an external program. +* This is always defined. We error out if a user tries to open this type +* of backend on unsupported platforms. */ +DRIVER_AFUNIX ,DRIVER_DCO ,/** macOS internal tun driver */ DRIVER_UTUN
@@ -161,6 +165,17 @@/* * Define a TUN/TAP dev. */ +#if defined(AF_UNIX ) && !defined(WIN32 ) +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* if defined(AF_UNIX) && !defined(WIN32) */ +typedef struct { +int dummy; +}afunix_context_t ; +#endif struct tuntap {
@@ -175,7 +190,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -227,6 +247,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -350,8 +371,14 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + } +#endif #if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -376,8 +403,14 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +#if definedAF_UNIX +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + } +#endif #if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -755,5 +788,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +178 -0
178 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Patch Set 10: Code-Review-1
(8 comments)
Patchset:
PS10:
I haven't seen any hard show-stopper, but a few minor nags...
File src/openvpn/dco.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/df7a0350_ee091375 :
PS10, Line 306: return false;
blank missing, and I would not wrap a single word
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/f9ab8f69_a3d074cf :
PS10, Line 1325: c->c2.buf.len = tun_afunix_read(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
the monk in me complains that read_tun() should be paired with read_tun_afunix()... but that is minor
http://gerrit.openvpn.net/c/openvpn/+/747/comment/6ded27c5_58f53265 :
PS10, Line 1939: size = tun_afunix_write(c->c1.tuntap, BPTR(&c->c2.to_tun), BLEN(&c->c2.to_tun));
see above ;-)
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/57540e5b_f2836507 :
PS10, Line 2060: tun_afunix_close(c->c1.tuntap);
you are using open_tun_afunix() for open_tun(), so this really should be close_tun_afunix() then...
File src/openvpn/run_command.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/c06210e8_581e4f52 :
PS10, Line 52: #define S_NOWAITPID (1<<3)
the indenting here looks like one is using tab, one is using spaces
File src/openvpn/tun_afunix.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/57db59bc_b1c8c8db :
PS10, Line 39: #if defined(AF_UNIX) && !defined(WIN32)
I do wonder if the conditional on AF_UNIX is really needed (here and elsewhere). All OSes we support have AF_UNIX sockets...
http://gerrit.openvpn.net/c/openvpn/+/747/comment/50341699_b37fbb94 :
PS10, Line 125:
should we wait()? Or are we handling SIGCHLD elsewhere?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 23 Sep 2024 15:18:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Patch Set 10:
(7 comments)
File src/openvpn/dco.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/dc90dae1_5d368c9f :
PS10, Line 306: return false;
Quoted 1 line
blank missing, and I would not wrap a single word
Done
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/786d9bf0_01d92300 :
PS10, Line 1325: c->c2.buf.len = tun_afunix_read(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
Quoted 1 line
the monk in me complains that
read_tun()should be paired withread_tun_afunix()... […]
Done
http://gerrit.openvpn.net/c/openvpn/+/747/comment/4985ee6c_466dd8db :
PS10, Line 1939: size = tun_afunix_write(c->c1.tuntap, BPTR(&c->c2.to_tun), BLEN(&c->c2.to_tun));
Quoted 1 line
see above ;-)
Done
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/9d2a0551_4486932b :
PS10, Line 2060: tun_afunix_close(c->c1.tuntap);
Quoted 1 line
you are using
open_tun_afunix()foropen_tun(), so this really should beclose_tun_afunix()th […]
Done
File src/openvpn/run_command.h:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/128d3fd4_13147565 :
PS10, Line 52: #define S_NOWAITPID (1<<3)
Quoted 1 line
the indenting here looks like one is using tab, one is using spaces
Done
File src/openvpn/tun_afunix.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/56f93adc_cb7474df :
PS10, Line 39: #if defined(AF_UNIX) && !defined(WIN32)
Quoted 1 line
I do wonder if the conditional on
AF_UNIXis really needed (here and elsewhere). […]
Done
http://gerrit.openvpn.net/c/openvpn/+/747/comment/11503245_d6c4ddaf :
PS10, Line 125:
Quoted 1 line
should we
wait()? Or are we handling SIGCHLD elsewhere?
I am not sure that waiting is really needed. We could wait to ensure that the child really exits. We currently ignore SIGCHLD and that means that the process will just die.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 24 Sep 2024 08:21:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld.
Hello cron2, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
to look at the new patch set (#11).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
13 files changed, 394 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/11
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``--dev-node unix:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can serve a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will start the program and create a temporary unix domain socket that + will be passed to the program together with the tun configuration as + environment variables. The temporary unix domain socket will be be passed + in the environment variable :code:`TUNTAP_SOCKET_FD`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -140,6 +140,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/dco.c +8 -0
@@ -41,6 +41,7 @@#include "ssl_common.h" #include "ssl_ncp.h" #include "tun.h" +#include "tun_afunix.h" #ifdef HAVE_LIBCAPNG #include <cap-ng.h>
@@ -298,6 +299,13 @@return false; } +if (is_tun_afunix (o->dev_node)) + { +msg (msglevel,"Note: afunix tun type selected, disabling data channel" +"offload" ); +return false; + } +if (o->connection_list) {const struct connection_list *l = o->connection_list;
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =read_tun_afunix (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =write_tun_afunix (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +47 -11
132 lines not on this page · raw message
src/openvpn/run_command.c +9 -0
@@ -155,6 +155,10 @@ {msg (M_ERR ,"openvpn_execve: unable to fork" ); } + else if (flags & S_NOWAITPID) + { + ret = pid; + } else /* parent side */ {if (waitpid (pid, &ret,0 ) != pid)
@@ -204,6 +208,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process to exit and report the status, +* return the pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/tun.c +3 -0
@@ -72,6 +72,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +31 -3
@@ -47,6 +47,10 @@WINDOWS_DRIVER_TAP_WINDOWS6 ,WINDOWS_DRIVER_WINTUN ,DRIVER_GENERIC_TUNTAP , +/** using an AF_UNIX socket to pass packets from/to an external program. +* This is always defined. We error out if a user tries to open this type +* of backend on unsupported platforms. */ +DRIVER_AFUNIX ,DRIVER_DCO ,/** macOS internal tun driver */ DRIVER_UTUN
@@ -161,6 +165,17 @@/* * Define a TUN/TAP dev. */ +#ifndef WIN32 +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* ifndef WIN32 */ +typedef struct { +int dummy; +}afunix_context_t ; +#endif struct tuntap {
@@ -175,7 +190,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -227,6 +247,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -350,8 +371,12 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + }#if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -376,8 +401,12 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + }#if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -755,5 +784,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +178 -0
178 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 11
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Patch Set 11: Code-Review-1
(3 comments)
Patchset:
PS11:
the dco.c string fix was overlooked, the rest is ready to be merged now (not sure why the builds fail in t_server_null)
File src/openvpn/dco.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/9fcc0c82_242360d5 :
PS10, Line 306: return false;
Quoted 1 line
Done
Umm. This does not look changed between 10 and 11? I saw a similar code fragment changed in a different patch, but not here...
File src/openvpn/tun_afunix.c:
http://gerrit.openvpn.net/c/openvpn/+/747/comment/42b0e935_ab5748b8 :
PS10, Line 125:
Quoted 1 line
I am not sure that waiting is really needed. We could wait to ensure that the child really exits. […]
ignoring SIGCHLD is good enough
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 11
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 24 Sep 2024 10:42:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Patch Set 11: Code-Review+2
(1 comment)
Patchset:
PS11:
the build fails were unrelated (stuck openvpn process from a previous t_server_null run, breaking all future runs). Agreed to handle the wrapped word on-the-fly.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 11
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 24 Sep 2024 11:00:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v11 1/1 Introduce DRIVER_AFUNIX backend for use with lwipovpn
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/747
This mail reflects revision 11 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``--dev-node unix:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can serve a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will start the program and create a temporary unix domain socket that + will be passed to the program together with the tun configuration as + environment variables. The temporary unix domain socket will be be passed + in the environment variable :code:`TUNTAP_SOCKET_FD`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -140,6 +140,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/dco.c +8 -0
@@ -41,6 +41,7 @@#include "ssl_common.h" #include "ssl_ncp.h" #include "tun.h" +#include "tun_afunix.h" #ifdef HAVE_LIBCAPNG #include <cap-ng.h>
@@ -298,6 +299,13 @@return false; } +if (is_tun_afunix (o->dev_node)) + { +msg (msglevel,"Note: afunix tun type selected, disabling data channel" +"offload" ); +return false; + } +if (o->connection_list) {const struct connection_list *l = o->connection_list;
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =read_tun_afunix (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =write_tun_afunix (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +47 -11
132 lines not on this page · raw message
src/openvpn/run_command.c +9 -0
@@ -155,6 +155,10 @@ {msg (M_ERR ,"openvpn_execve: unable to fork" ); } + else if (flags & S_NOWAITPID) + { + ret = pid; + } else /* parent side */ {if (waitpid (pid, &ret,0 ) != pid)
@@ -204,6 +208,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process to exit and report the status, +* return the pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/tun.c +3 -0
@@ -72,6 +72,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +31 -3
@@ -47,6 +47,10 @@WINDOWS_DRIVER_TAP_WINDOWS6 ,WINDOWS_DRIVER_WINTUN ,DRIVER_GENERIC_TUNTAP , +/** using an AF_UNIX socket to pass packets from/to an external program. +* This is always defined. We error out if a user tries to open this type +* of backend on unsupported platforms. */ +DRIVER_AFUNIX ,DRIVER_DCO ,/** macOS internal tun driver */ DRIVER_UTUN
@@ -161,6 +165,17 @@/* * Define a TUN/TAP dev. */ +#ifndef WIN32 +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* ifndef WIN32 */ +typedef struct { +int dummy; +}afunix_context_t ; +#endif struct tuntap {
@@ -175,7 +190,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -227,6 +247,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -350,8 +371,12 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + }#if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -376,8 +401,12 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + }#if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -755,5 +784,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +178 -0
178 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
[Openvpn-devel] [PATCH applied] Re: Introduce DRIVER_AFUNIX backend for use with lwipovpn
This patch "in itself" is not that complex, but the implications on testing ("run server and client on the same machine, do a full 'ping' or even 'http' through the tunnel without namespace/VRF/... support") are very nice :-)
Stared-at-code, fed to GHA and local test builds, and ran one of my t_client.rc stanzas with
... --dev-node $path/lwipovpn --ifconfig-noexec --route-noexec
and lo and behold :-)
lwipovpn init complete: type=tun mtu=1500 local_ip=10.194.2.54 netmask=(not set) gw=(not set) local_ipv6=FD00:ABCD:194:2::100C
... ping through the tunnel works.
This patch itself is still rough (needs explicit --ifconfig-noexec, triggers some warnings about "ifconfig_netmask=(not set)", etc.) but that is fixed by the following patches in the series.
As discussed on IRC and noted in Gerrit, I have unwrapped the missing-space-word-wrapped "offload" - our 80 char line length is a somewhat soft limit, in case wrapping gets even more ugly.
Your patch has been applied to the master branch.
commit d0a93625a335fdc42fff808c9e9d2b62b232eef2
Author: Arne Schwabe Date: Tue Sep 24 13:01:29 2024 +0200
Introduce DRIVER_AFUNIX backend for use with lwipovpn
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29379.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#12) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29379.html
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
13 files changed, 393 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/12
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``--dev-node unix:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can serve a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will start the program and create a temporary unix domain socket that + will be passed to the program together with the tun configuration as + environment variables. The temporary unix domain socket will be be passed + in the environment variable :code:`TUNTAP_SOCKET_FD`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -140,6 +140,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/dco.c +7 -0
@@ -41,6 +41,7 @@#include "ssl_common.h" #include "ssl_ncp.h" #include "tun.h" +#include "tun_afunix.h" #ifdef HAVE_LIBCAPNG #include <cap-ng.h>
@@ -298,6 +299,12 @@return false; } +if (is_tun_afunix (o->dev_node)) + { +msg (msglevel,"Note: afunix tun type selected, disabling data channel offload" ); +return false; + } +if (o->connection_list) {const struct connection_list *l = o->connection_list;
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =read_tun_afunix (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =write_tun_afunix (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +47 -11
132 lines not on this page · raw message
src/openvpn/run_command.c +9 -0
@@ -155,6 +155,10 @@ {msg (M_ERR ,"openvpn_execve: unable to fork" ); } + else if (flags & S_NOWAITPID) + { + ret = pid; + } else /* parent side */ {if (waitpid (pid, &ret,0 ) != pid)
@@ -204,6 +208,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process to exit and report the status, +* return the pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/tun.c +3 -0
@@ -72,6 +72,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +31 -3
@@ -47,6 +47,10 @@WINDOWS_DRIVER_TAP_WINDOWS6 ,WINDOWS_DRIVER_WINTUN ,DRIVER_GENERIC_TUNTAP , +/** using an AF_UNIX socket to pass packets from/to an external program. +* This is always defined. We error out if a user tries to open this type +* of backend on unsupported platforms. */ +DRIVER_AFUNIX ,DRIVER_DCO ,/** macOS internal tun driver */ DRIVER_UTUN
@@ -161,6 +165,17 @@/* * Define a TUN/TAP dev. */ +#ifndef WIN32 +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* ifndef WIN32 */ +typedef struct { +int dummy; +}afunix_context_t ; +#endif struct tuntap {
@@ -175,7 +190,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -227,6 +247,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -350,8 +371,12 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + }#if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -376,8 +401,12 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + }#if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -755,5 +784,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +178 -0
178 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 12
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/747?usp=email )
Change subject: Introduce DRIVER_AFUNIX backend for use with lwipovpn
......................................................................
Introduce DRIVER_AFUNIX backend for use with lwipovpn
lwipovpn is a using lwip TCP/IP implementation with an AF_UNIX implementation to emulate a tun/tap device without messing with the TCP/IP stack of the host.
For more information about lwipovpn see https://github.com/OpenVPN/lwipovpn
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29379.html
---
M CMakeLists.txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/Makefile.am
M src/openvpn/dco.c
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openvpn/tun_afunix.h
13 files changed, 393 insertions(+), 16 deletions(-)
CMakeLists.txt +2 -0
@@ -536,6 +536,8 @@ src/openvpn/tls_crypt.c src/openvpn/tun.c src/openvpn/tun.h + src/openvpn/tun_afunix.c + src/openvpn/tun_afunix.h src/openvpn/networking_sitnl.c src/openvpn/networking_freebsd.c src/openvpn/auth_token.c
Changes.rst +13 -0
@@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running into a timeout when the server just stops responding completely. +Support for tun/tap via unix domain socket and lwipovpn support + To allow better testing and emulating a full client with a full + network stack OpenVPN now allows a program executed to provide + a tun/tap device instead of opening a device. + + The co-developed lwipovpn program based on lwIP stack allows to + simulate full IP stack and an OpenVPN client using + ``--dev-node unix:/path/to/lwipovpn`` can emulate a full client that + can be pinged, can serve a website and more without requiring any + elevated permission. This can make testing OpenVPN much easier. + + For more details see [lwipovpn on Gihtub](https://github.com/OpenVPN/lwipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default.
doc/man-sections/vpn-network-options.rst +10 -0
@@ -117,6 +117,16 @@ figure out whether ``node`` is a TUN or TAP device based on the name, you should also specify ``--dev-type tun`` or ``--dev-type tap``. + If ``node`` starts with the string ``unix:`` openvpn will treat the rest + of the argument as a program. + OpenVPN will start the program and create a temporary unix domain socket that + will be passed to the program together with the tun configuration as + environment variables. The temporary unix domain socket will be be passed + in the environment variable :code:`TUNTAP_SOCKET_FD`. + + This ``unix:`` mode is designed mainly to use with the lwipovpn network + emulator (https://github.com/OpenVPN/lwipovpn). + --dev-type device-type Which device type are we using? ``device-type`` should be :code:`tun` (OSI Layer 3) or :code:`tap` (OSI Layer 2). Use this option only if
src/openvpn/Makefile.am +1 -0
@@ -140,6 +140,7 @@ syshead.h \ tls_crypt.c tls_crypt.h \ tun.c tun.h \ + tun_afunix.c tun_afunix.h \ vlan.c vlan.h \ xkey_provider.c xkey_common.h \ xkey_helper.c \
src/openvpn/dco.c +7 -0
@@ -41,6 +41,7 @@#include "ssl_common.h" #include "ssl_ncp.h" #include "tun.h" +#include "tun_afunix.h" #ifdef HAVE_LIBCAPNG #include <cap-ng.h>
@@ -298,6 +299,12 @@return false; } +if (is_tun_afunix (o->dev_node)) + { +msg (msglevel,"Note: afunix tun type selected, disabling data channel offload" ); +return false; + } +if (o->connection_list) {const struct connection_list *l = o->connection_list;
src/openvpn/forward.c +17 -2
@@ -41,6 +41,7 @@#include "ssl_verify.h" #include "dco.h" #include "auth_token.h" +#include "tun_afunix.h" #include "memdbg.h"
@@ -1319,7 +1320,14 @@#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf, c->c2.frame.buf.headroom));ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + c->c2.buf.len =read_tun_afunix (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + } +else + { + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size); + }#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1926,7 +1934,14 @@#ifdef _WIN32 size =write_tun_buffered (c->c1.tuntap, &c->c2.to_tun);#else - size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); +if (c->c1.tuntap->backend_driver ==DRIVER_AFUNIX ) + { + size =write_tun_afunix (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + } +else + { + size =write_tun (c->c1.tuntap,BPTR (&c->c2.to_tun),BLEN (&c->c2.to_tun)); + }#endif if (size >0 )
src/openvpn/init.c +47 -11
132 lines not on this page · raw message
src/openvpn/run_command.c +9 -0
@@ -155,6 +155,10 @@ {msg (M_ERR ,"openvpn_execve: unable to fork" ); } + else if (flags & S_NOWAITPID) + { + ret = pid; + } else /* parent side */ {if (waitpid (pid, &ret,0 ) != pid)
@@ -204,6 +208,11 @@ goto done; } } +else if (flags &S_NOWAITPID && (stat >0 )) + { + ret = stat; + goto done; + }else if (platform_system_ok (stat)) { ret = true;
src/openvpn/run_command.h +3 -0
@@ -47,6 +47,9 @@/** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ #define S_EXITCODE (1<<2) +/** instead of waiting for child process to exit and report the status, +* return the pid of the child process */ +#define S_NOWAITPID (1<<3)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);
src/openvpn/tun.c +3 -0
@@ -72,6 +72,9 @@case DRIVER_DCO :return "ovpn-dco" ; +case DRIVER_AFUNIX : +return "unix" ; +case DRIVER_UTUN :return "utun" ;
src/openvpn/tun.h +31 -3
@@ -47,6 +47,10 @@WINDOWS_DRIVER_TAP_WINDOWS6 ,WINDOWS_DRIVER_WINTUN ,DRIVER_GENERIC_TUNTAP , +/** using an AF_UNIX socket to pass packets from/to an external program. +* This is always defined. We error out if a user tries to open this type +* of backend on unsupported platforms. */ +DRIVER_AFUNIX ,DRIVER_DCO ,/** macOS internal tun driver */ DRIVER_UTUN
@@ -161,6 +165,17 @@/* * Define a TUN/TAP dev. */ +#ifndef WIN32 +typedef struct afunix_context +{ +pid_t childprocess; +}afunix_context_t ; + +#else /* ifndef WIN32 */ +typedef struct { +int dummy; +}afunix_context_t ; +#endif struct tuntap {
@@ -175,7 +190,12 @@*/ enum tun_driver_type backend_driver; +/** if the internal variables related to ifconfig of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_setup; + +/** if the internal variables related to ifconfig-ipv6 of this struct have +* been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup;bool persistent_if;/* if existed before, keep on program end */
@@ -227,6 +247,7 @@unsigned int rwflags_debug;dco_context_t dco; +afunix_context_t afunix; }; static inline bool
@@ -350,8 +371,12 @@#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPENstatic inline int -ifconfig_order (void ) +ifconfig_order (struct tuntap *tt) { +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return IFCONFIG_BEFORE_TUN_OPEN ; + }#if defined(TARGET_LINUX )return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(TARGET_SOLARIS )
@@ -376,8 +401,12 @@#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUNstatic inline int -route_order (void ) +route_order (struct tuntap *tt) { +if (tt->backend_driver ==DRIVER_AFUNIX ) + { +return ROUTE_BEFORE_TUN ; + }#if defined(TARGET_ANDROID )return ROUTE_BEFORE_TUN ;#else
@@ -755,5 +784,4 @@ {return tt && tt->type !=DEV_TYPE_UNDEF ; } -#endif /* TUN_H */
src/openvpn/tun_afunix.c new file +178 -0
178 lines not on this page · raw message
src/openvpn/tun_afunix.h new file +72 -0
72 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 12
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged