From: "plaisthos (Code Review)" Date: Tue, 17 Sep 2024 15:46:17 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="ytBEappxrrc="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: Introduce DRIVER_AFUNIX backend for use with lwipovpn List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --ytBEappxrrc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=3Demail 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 Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7 Signed-off-by: Arne Schwabe --- 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index ad620fa..6271574 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/Changes.rst b/Changes.rst index 439352a..7d19577 100644 --- a/Changes.rst +++ b/Changes.rst @@ -9,6 +9,19 @@ the user experience as the client shows an error instead of running in= to 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/l= wipovpn). + Deprecated features ------------------- ``secret`` support has been removed by default. diff --git a/doc/man-sections/vpn-network-options.rst b/doc/man-sections/vp= n-network-options.rst index 84d4273..fc76939 100644 --- a/doc/man-sections/vpn-network-options.rst +++ b/doc/man-sections/vpn-network-options.rst @@ -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 pas= sed + 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 diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am index 3784a98..ecb2bcf 100644 --- a/src/openvpn/Makefile.am +++ b/src/openvpn/Makefile.am @@ -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 \ diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 7b23131..9c78adf 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -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 =3D read_tun(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame= .buf.payload_size); + if (c->c1.tuntap->backend_driver =3D=3D DRIVER_AFUNIX) + { + c->c2.buf.len =3D tun_afunix_read(c->c1.tuntap, BPTR(&c->c2.buf), = c->c2.frame.buf.payload_size); + } + else + { + c->c2.buf.len =3D read_tun(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.f= rame.buf.payload_size); + } #endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK @@ -1926,7 +1934,14 @@ #ifdef _WIN32 size =3D write_tun_buffered(c->c1.tuntap, &c->c2.to_tun); #else - size =3D write_tun(c->c1.tuntap, BPTR(&c->c2.to_tun), BLEN(&c->c2.= to_tun)); + if (c->c1.tuntap->backend_driver =3D=3D DRIVER_AFUNIX) + { + size =3D tun_afunix_write(c->c1.tuntap, BPTR(&c->c2.to_tun), B= LEN(&c->c2.to_tun)); + } + else + { + size =3D write_tun(c->c1.tuntap, BPTR(&c->c2.to_tun), BLEN(&c-= >c2.to_tun)); + } #endif if (size > 0) diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 83cc670..b516608 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -54,6 +54,7 @@ #include "mss.h" #include "mudp.h" #include "dco.h" +#include "tun_afunix.h" #include "memdbg.h" @@ -1758,10 +1759,18 @@ &c->net_ctx, c->c1.tuntap); + if (is_tun_afunix(c->options.dev_node)) + { + /* Using AF_UNIX trumps using DCO */ + c->c1.tuntap->backend_driver =3D DRIVER_AFUNIX; + } #ifdef _WIN32 - c->c1.tuntap->backend_driver =3D c->options.windows_driver; + else + { + c->c1.tuntap->backend_driver =3D c->options.windows_driver; + } #else - if (dco_enabled(&c->options)) + else if (dco_enabled(&c->options)) { c->c1.tuntap->backend_driver =3D DRIVER_DCO; } @@ -1786,6 +1795,10 @@ static bool can_preserve_tun(struct tuntap *tt) { + if (tt && tt->backend_driver =3D=3D DRIVER_AFUNIX) + { + return false; + } #ifdef TARGET_ANDROID return false; #else @@ -1841,6 +1854,22 @@ #endif } +static void +open_tun_backend(struct context *c) +{ + struct tuntap *tt =3D c->c1.tuntap; + if (tt->backend_driver =3D=3D DRIVER_AFUNIX) + { + open_tun_afunix(&c->options, c->c2.frame.tun_mtu, tt, c->c2.es); + } + else + { + open_tun(c->options.dev, c->options.dev_type, c->options.dev_node, + tt, &c->net_ctx); + } +} + + static bool do_open_tun(struct context *c, int *error_flags) { @@ -1863,7 +1892,8 @@ } #endif - /* initialize (but do not open) tun/tap object */ + /* initialize (but do not open) tun/tap object, this also sets + * the backend driver type */ do_init_tun(c); /* inherit the dco context from the tuntap object */ @@ -1898,7 +1928,7 @@ /* do ifconfig */ if (!c->options.ifconfig_noexec - && ifconfig_order() =3D=3D IFCONFIG_BEFORE_TUN_OPEN) + && ifconfig_order(c->c1.tuntap) =3D=3D IFCONFIG_BEFORE_TUN_OPE= N) { /* guess actual tun/tap unit number that will be returned * by open_tun */ @@ -1911,7 +1941,7 @@ } /* possibly add routes */ - if (route_order() =3D=3D ROUTE_BEFORE_TUN) + if (route_order(c->c1.tuntap) =3D=3D ROUTE_BEFORE_TUN) { /* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be igno= red */ bool status =3D do_route(&c->options, c->c1.route_list, c->c1.= route_ipv6_list, @@ -1928,8 +1958,7 @@ } /* open the tun device */ - open_tun(c->options.dev, c->options.dev_type, c->options.dev_node, - c->c1.tuntap, &c->net_ctx); + open_tun_backend(c); /* set the hardware address */ if (c->options.lladdr) @@ -1940,7 +1969,7 @@ /* do ifconfig */ if (!c->options.ifconfig_noexec - && ifconfig_order() =3D=3D IFCONFIG_AFTER_TUN_OPEN) + && ifconfig_order(c->c1.tuntap) =3D=3D IFCONFIG_AFTER_TUN_OPEN) { do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); @@ -1966,7 +1995,7 @@ add_wfp_block(c); /* possibly add routes */ - if ((route_order() =3D=3D ROUTE_AFTER_TUN) && (!c->options.route_d= elay_defined)) + if ((route_order(c->c1.tuntap) =3D=3D ROUTE_AFTER_TUN) && (!c->opt= ions.route_delay_defined)) { int status =3D do_route(&c->options, c->c1.route_list, c->c1.r= oute_ipv6_list, c->c1.tuntap, c->plugins, c->c2.es, &c->= net_ctx); @@ -2026,7 +2055,14 @@ { undo_ifconfig(c->c1.tuntap, &c->net_ctx); } - close_tun(c->c1.tuntap, &c->net_ctx); + if (c->c1.tuntap->backend_driver =3D=3D DRIVER_AFUNIX) + { + tun_afunix_close(c->c1.tuntap); + } + else + { + close_tun(c->c1.tuntap, &c->net_ctx); + } c->c1.tuntap =3D NULL; } c->c1.tuntap_owned =3D false; @@ -2466,7 +2502,7 @@ c->c1.pulled_options_digest_save =3D c->c2.pulled_options_dige= st; /* if --route-delay was specified, start timer */ - if ((route_order() =3D=3D ROUTE_AFTER_TUN) && c->options.route= _delay_defined) + if ((route_order(c->c1.tuntap) =3D=3D ROUTE_AFTER_TUN) && c->o= ptions.route_delay_defined) { event_timeout_init(&c->c2.route_wakeup, c->options.route_d= elay, now); event_timeout_init(&c->c2.route_wakeup_expire, c->options.= route_delay + c->options.route_delay_window, now); diff --git a/src/openvpn/run_command.c b/src/openvpn/run_command.c index 292e81f..d757823 100644 --- a/src/openvpn/run_command.c +++ b/src/openvpn/run_command.c @@ -155,6 +155,10 @@ { msg(M_ERR, "openvpn_execve: unable to fork"); } + else if (flags & S_NOWAITPID) + { + ret =3D pid; + } else /* parent side */ { if (waitpid(pid, &ret, 0) !=3D pid) @@ -204,6 +208,11 @@ goto done; } } + else if (flags & S_NOWAITPID && (stat > 0)) + { + ret =3D stat; + goto done; + } else if (platform_system_ok(stat)) { ret =3D true; diff --git a/src/openvpn/run_command.h b/src/openvpn/run_command.h index ccad307..c1ee25e 100644 --- a/src/openvpn/run_command.h +++ b/src/openvpn/run_command.h @@ -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); diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index aee59a6..5032f18 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -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"; diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index e41b616..2f7bd4a 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -50,6 +50,10 @@ #else DRIVER_GENERIC_TUNTAP, #endif + /** using an AF_UNIX socket to pass packets from/to an external progra= m. + * 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_OPEN static inline int -ifconfig_order(void) +ifconfig_order(struct tuntap *tt) { +#if defined AF_UNIX + if (tt->backend_driver =3D=3D 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_TUN static inline int -route_order(void) +route_order(struct tuntap *tt) { +#if defined AF_UNIX + if (tt->backend_driver =3D=3D DRIVER_AFUNIX) + { + return ROUTE_BEFORE_TUN; + } +#endif #if defined(TARGET_ANDROID) return ROUTE_BEFORE_TUN; #else @@ -759,5 +792,4 @@ { return tt && tt->type !=3D DEV_TYPE_UNDEF; } - #endif /* TUN_H */ diff --git a/src/openvpn/tun_afunix.c b/src/openvpn/tun_afunix.c new file mode 100644 index 0000000..27cdb01 --- /dev/null +++ b/src/openvpn/tun_afunix.c @@ -0,0 +1,178 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single TCP/UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2002-2024 OpenVPN Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "syshead.h" + +#include "tun.h" +#include "fdmisc.h" +#include "run_command.h" +#include "manage.h" +#include "win32.h" +#include "wfp_block.h" +#include "argv.h" +#include "options.h" + +#if defined(AF_UNIX) && !defined(WIN32) +/* Windows does implement some AF_UNIX functionality but key features + * like socketpair() and SOCK_DGRAM are missing */ + +#include +#include +#include +#include +#include + +static void +tun_afunix_exec_child(const char *dev_node, struct tuntap *tt, struct env_= set *env) +{ + struct argv argv =3D argv_new(); + + /* since we know that dev-node starts with unix: we can just skip that + * to get the program name */ + const char *program =3D dev_node + strlen("unix:"); + + argv_printf(&argv, "%s", program); + + argv_msg(M_INFO, &argv); + tt->afunix.childprocess =3D openvpn_execve_check(&argv, env, S_NOWAITP= ID, + "ERROR: failure executi= ng " + "process for tun"); + argv_free(&argv); +} + +void +open_tun_afunix(struct options *o, + int mtu, + struct tuntap *tt, + struct env_set *orig_env) +{ + struct gc_arena gc =3D gc_new(); + + int fds[2]; + if (!(socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) =3D=3D 0)) + { + msg(M_ERR, "Cannot create socket pair for AF_UNIX socket to extern= al " + "program"); + return; + } + + /* Use the first file descriptor for our side and avoid passing it + * to the child */ + tt->fd =3D fds[1]; + set_cloexec(tt->fd); + + /* Make a copy of the env, so we do not need to delete our custom + * environment variables later */ + struct env_set *env =3D env_set_create(&gc); + env_set_inherit(env, orig_env); + + setenv_int(env, "TUNTAP_SOCKET_FD", fds[0]); + setenv_str(env, "TUNTAP_DEV_TYPE", dev_type_string(o->dev, o->dev_type= )); + setenv_int(env, "TUNTAP_MTU", mtu); + if (o->route_default_gateway) + { + setenv_str(env, "ifconfig_gateway", o->route_default_gateway); + } + if (o->lladdr) + { + setenv_str(env, "TUNTAP_LLADDR", o->lladdr); + } + + tun_afunix_exec_child(o->dev_node, tt, env); + + close(fds[0]); + + /* tt->actual_name is passed to up and down scripts and used as the if= config dev name */ + tt->actual_name =3D string_alloc("internal:af_unix", NULL); + + gc_free(&gc); +} + +void +tun_afunix_close(struct tuntap *tt) +{ + ASSERT(tt); + if (tt->fd >=3D 0) + { + close(tt->fd); + tt->fd =3D 0; + } + kill(tt->afunix.childprocess, SIGINT); + + free(tt->actual_name); + free(tt); +} + +ssize_t +tun_afunix_write(struct tuntap *tt, uint8_t *buf, int len) +{ + int ret; + pid_t pidret =3D waitpid(tt->afunix.childprocess, &ret, WNOHANG); + if (pidret =3D=3D tt->afunix.childprocess) + { + msg(M_INFO, "Child process PID %d for afunix dead? Return code: %d= ", + tt->afunix.childprocess, ret); + return -ENXIO; + } + return write(tt->fd, buf, len); +} + +ssize_t +tun_afunix_read(struct tuntap *tt, uint8_t *buf, int len) +{ + return read(tt->fd, buf, len); +} +#else /* ifdef AF_UNIX */ +void +open_tun_afunix(const char *dev, const char *dev_type, int mtu, + struct tuntap *tt, struct env_set env) +{ + msg(M_ERR, "AF_UNIX socket support not available on this platform"); +} + +void +tun_afunix_close(struct tuntap *tt) +{ + /* should never be called as open_tun_afunix always fails */ + ASSERT(0); +} + +ssize_t +tun_afunix_write(struct tuntap *tt, uint8_t *buf, int len) +{ + /* should never be called as open_tun_afunix always fails */ + ASSERT(0); +} + +ssize_t +tun_afunix_read(struct tuntap *tt, uint8_t *buf, int len) +{ + /* should never be called as open_tun_afunix always fails */ + ASSERT(0); +} + +#endif /* ifdef AF_UNIX */ diff --git a/src/openvpn/tun_afunix.h b/src/openvpn/tun_afunix.h new file mode 100644 index 0000000..f7d0407 --- /dev/null +++ b/src/openvpn/tun_afunix.h @@ -0,0 +1,72 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single TCP/UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2002-2024 OpenVPN Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef AFUNIX_TUN_H +#define AFUNIX_TUN_H +#include + +#include "tun.h" + +/** + * Opens an AF_UNIX based tun device. This also executes the command that + * the user provided taking care of implementing the actual tun + * device. + */ +void +open_tun_afunix(struct options *o, + int mtu, + struct tuntap *tt, + struct env_set *env); + + +/** + * Closes the socket used for the AF_UNIX based device. Also sends a + * SIGINT to the child process that was spawned to handle the tun device + */ +void +tun_afunix_close(struct tuntap *tt); + +/** + * Writes a packet to a AF_UNIX based tun device. + */ +ssize_t +tun_afunix_write(struct tuntap *tt, uint8_t *buf, int len); + +/** + * Reads a packet from a AF_UNIX based tun device. + */ +ssize_t +tun_afunix_read(struct tuntap *tt, uint8_t *buf, int len); + +#endif /* AFUNIX_TUN_H */ + +/** + * Checks whether a --dev-node parameter specifies a AF_UNIX device + * @param devnode the string to check + * @return true if the string starts with unix: + */ +static inline bool +is_tun_afunix(const char *devnode) +{ + return devnode && strprefix(devnode, "unix:"); +} -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/747?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7 Gerrit-Change-Number: 747 Gerrit-PatchSet: 6 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --ytBEappxrrc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

plaisthos uploaded patch set #6 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/747?usp=3Demail">View Chang= e

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 h= ost.

For more information about lwipovpn see https://github.com/Open= VPN/lwipovpn

Change-Id: I65099ef00822d08fd3f5480c80892f3bf86c56e7Signed-off-by: Arne Schwabe <arne@...1227...>
---
M CMakeLists= .txt
M Changes.rst
M doc/man-sections/vpn-network-options.rst
M sr= c/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.cM src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvp= n/tun.c
M src/openvpn/tun.h
A src/openvpn/tun_afunix.c
A src/openv= pn/tun_afunix.h
12 files changed, 390 insertions(+), 16 deletions(-)
=
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/747/=
6
diff --git a/CMakeLists.txt b/CMakeLists.txt
inde= x ad620fa..6271574 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
sr= c/openvpn/networking_sitnl.c
src/openvpn/networking_fr= eebsd.c
src/openvpn/auth_token.c
diff = --git a/Changes.rst b/Changes.rst
index 439352a..7d19577 10= 0644
--- a/Changes.rst
+++ b/Changes.rst

@@ -9,6 +9,19 @@
the user experience as = the client shows an error instead of running into
a ti= meout when the server just stops responding completely.

+Support for tun/tap v= ia unix domain socket and lwipovpn support
+ To allow better testing and emulating a full cli= ent 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-n= ode unix:/path/to/lwipovpn`` can emulate a full client that
+ can be pinged, can serve a webs= ite and more without requiring any

+ elevated permission. This can make testing OpenVPN much = easier.
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ For more details see [lwipo= vpn on Gihtub](https://github.com/OpenVPN/lwipovpn).
+
Deprecated features
-------------------
``secret`` support has b= een removed by default.
diff --git a/doc/man-sections/vpn-n= etwork-options.rst b/doc/man-sections/vpn-network-options.rst
index 84d4273..fc76939 100644

--- a/doc/man-sections/vpn= -network-options.rst
+++ b/doc/man-sections/vpn-network-opt= ions.rst
@@ -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<= br>+ of the argument as a prog= ram.
+ OpenVPN will = start the program and create a temporary unix domain socket that
= + will be passed to the progra= m together with the tun configuration as
+ environment variables. The temporary unix domain so= cket will be be passed
+ in the environment variable :code:`TUNTAP_SOCKET_FD`.
+
+ This ``unix:`` mode is designed mainly to use with t= he lwipovpn network
+= emulator (https://github.com/OpenVPN/lwipovpn).
+
--dev-type device-type
Which device type are we using? ``device-type`` should be :c= ode:`tun`
(OSI Layer 3) or :code:`tap` (OSI Layer 2). Us= e this option only if
diff --git a/src/openvpn/Makefile.am = b/src/openvpn/Makefile.am
index 3784a98..ecb2bcf 100644
--- a/src/openvpn/Makefile.am
+++ b/src/openvp= n/Makefile.am
@@ -140,6 +140,7 @@
syshead= .h \
tls_crypt.c tls_crypt.h \
tun.c tu= n.h \
+ tun_afunix.c = tun_afunix.h \
vlan.c vlan.h \
xkey_pro= vider.c xkey_common.h \
xkey_helper.c \
d= iff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
i= ndex 7b23131..9c78adf 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -41,6 +41,7 @@=
#include "ssl_verify.h"
#inclu= de "dco.h"
#include "auth_token.h"
+#include "tun_afun= ix.h"

#include "memdbg.h"=

@@ -1319,7 +1320,14 @@
= #else /* ifdef _WIN32 */
ASSERT(buf_init(&c->c= 2.buf, c->c2.frame.buf.headroom));
ASSERT(buf_safe(= &c->c2.buf, c->c2.frame.buf.payload_size));
- c->c2.buf.len =3D read_tun(c->c1.= tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);+ if (c->c1.tuntap->= backend_driver =3D=3D DRIVER_AFUNIX)
+ {
+ }
+ else
+ {
+ c-= >c2.buf.len =3D 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 = =3D write_tun_buffered(c->c1.tuntap, &c->c2.to_tun);
#else

- siz= e =3D write_tun(c->c1.tuntap, BPTR(&c->c2.to_tun), BLEN(&c-&g= t;c2.to_tun));
+ = if (c->c1.tuntap->backend_driver =3D=3D DRIVER_AFUNIX)
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

+ size =3D tun_afunix_write(c-&= gt;c1.tuntap, BPTR(&c->c2.to_tun), BLEN(&c->c2.to_tun));
+ }
+ else

+ {
+ size =3D write_tun(c->c1.tuntap, BPT= R(&c->c2.to_tun), BLEN(&c->c2.to_tun));
+ }
#endif<= br>
if (size > 0)
diff -= -git a/src/openvpn/init.c b/src/openvpn/init.c
index 83cc67= 0..b516608 100644
--- a/src/openvpn/init.c
= +++ b/src/openvpn/init.c
@@ -54,6 +54,7 @@
= #include "mss.h"
#include "mudp.h"
#include "dco.h"
+#include "tun_afunix.h"

#include "memdbg.h"

<= span>@@ -1758,10 +1759,18 @@

&= amp;c->net_ctx,
c->c1.tu= ntap);

+ if (is_tun_afunix(c->options.dev_node))
+ {
+ /* Using AF_UNIX trumps using DCO */
= + c->c1.tuntap->ba= ckend_driver =3D DRIVER_AFUNIX;
+ }
#ifdef _WIN32
- c->c1.tuntap->backend_driver =3D c->= ;options.windows_driver;
+ else
+ {<= /span>
+ c->c1.tun= tap->backend_driver =3D c->options.windows_driver;
+ }
#else- if (dco_enabled(&c->= options))
+ else i= f (dco_enabled(&c->options))
{
= c->c1.tuntap->backend_driver =3D DRIVER_DCO;
}

@@ -1786,6 +1795,10 @@
static bool=
can_preserve_tun(struct tuntap *tt)
{
+ if (tt && = tt->backend_driver =3D=3D DRIVER_AFUNIX)
+ {
+ return false;
+ }
#ifdef TARGET_ANDROID
= return false;
#else
@@ -1841,6 +1854,22= @@
#endif
}

= +static void
+open_tun_backend(struct context *c)
+{
+ struct tuntap *tt =3D c->c1.tunta= p;
+ if (tt->ba= ckend_driver =3D=3D DRIVER_AFUNIX)
+ {
= + open_tun_afunix(&c->options, c->c2.frame.tun_mtu, tt, c-= >c2.es);
+ }
+ else
+ {

+ open_tun(c->options.dev, c->optio= ns.dev_type, c->options.dev_node,
+ tt, &c->net_ctx);
+ }
+}
+
+
<= span> static bool

do_open_tun(struct context *c, int *erro= r_flags)
{
@@ -1863,7 +1892,8 @@ }
#endif

- /* initialize (but do not ope= n) tun/tap object */

= + /* initialize (but do not open) tun/tap object, this also sets
+ * the backend = driver type */
do_init_tun(c);

/* inherit the dco context from the tuntap object *= /
@@ -1898,7 +1928,7 @@

= /* do ifconfig */
if (!c->options.ifcon= fig_noexec
- = && ifconfig_order() =3D=3D IFCONFIG_BEFORE_TUN_OPEN)
+ && ifconfig_o= rder(c->c1.tuntap) =3D=3D IFCONFIG_BEFORE_TUN_OPEN)

= {
/* guess actual tun/tap unit number tha= t will be returned
* by open_tun */@@ -1911,7 +1941,7 @@
}

/* possibly add routes */
- if (route_order() =3D=3D ROUTE_BEFORE_T= UN)
+ if (rout= e_order(c->c1.tuntap) =3D=3D ROUTE_BEFORE_TUN)
= {
/* Ignore route_delay, would cause ROUTE_BEF= ORE_TUN to be ignored */
bool status =3D do_ro= ute(&c->options, c->c1.route_list, c->c1.route_ipv6_list,
@@ -1928,8 +1958,7 @@
}

/* open the tun device */
- open_tun(c->options.dev, c->= options.dev_type, c->options.dev_node,
- c->c1.tuntap, &c->net_ctx);<= /span>
+ open_tun_bac= kend(c);

/* set the hardware add= ress */
if (c->options.lladdr)
= @@ -1940,7 +1969,7 @@

/* do ifco= nfig */
if (!c->options.ifconfig_noexec<= br>- && ifconf= ig_order() =3D=3D IFCONFIG_AFTER_TUN_OPEN)
+ && ifconfig_order(c->c1.tunta= p) =3D=3D IFCONFIG_AFTER_TUN_OPEN)
{
do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_nam= e,

c->c2.frame.tun_mtu, c->c= 2.es, &c->net_ctx);
@@ -1966,7 +1995,7 @@
= add_wfp_block(c);

= /* possibly add routes */
- if ((route_order() =3D=3D ROUTE_AFTER_TUN) && (!c->= options.route_delay_defined))
+ if ((route_order(c->c1.tuntap) =3D=3D ROUTE_AFTER_TUN)= && (!c->options.route_delay_defined))
= {
int status =3D do_route(&c->options, = c->c1.route_list, c->c1.route_ipv6_list,
= c->c1.tuntap, c->plugins, c->c2.es, &c-= >net_ctx);
@@ -2026,7 +2055,14 @@
= {
undo_ifconfig(c->c1.tuntap, &c->= ;net_ctx);
}
- close_tun(c->c1.tuntap, &c->net_ctx);
+ if (c->c1.tu= ntap->backend_driver =3D=3D DRIVER_AFUNIX)
+ {
+ tun_afunix_close(c->c1.tuntap);
+ }

+ else
+ {
+ close_tun(c->c1.tuntap, &c->net_ctx)= ;
+ } c->c1.tuntap =3D NULL;
} c->c1.tuntap_owned =3D false;
@@ -2466,7 +25= 02,7 @@
c->c1.pulled_options_digest_save = =3D c->c2.pulled_options_digest;

= /* if --route-delay was specified, start timer */
- if ((route_order() =3D=3D R= OUTE_AFTER_TUN) && c->options.route_delay_defined)
+ if ((route_order(c-&g= t;c1.tuntap) =3D=3D ROUTE_AFTER_TUN) && c->options.route_delay_d= efined)

{
eve= nt_timeout_init(&c->c2.route_wakeup, c->options.route_delay, now)= ;
event_timeout_init(&c->c2.route_w= akeup_expire, c->options.route_delay + c->options.route_delay_window,= now);
diff --git a/src/openvpn/run_command.c b/src/openvpn= /run_command.c
index 292e81f..d757823 100644
--- a/src/openvpn/run_command.c

+++ b/src/openvpn/run_com= mand.c
@@ -155,6 +155,10 @@
{<= /span>
msg(M_ERR, "openvpn_execve: unable to= fork");
}
+ else if (flags & S_NOWAITPID)
+ {
= + ret =3D pid;
+ }<= br> else /* parent side */
{=
if (waitpid(pid, &ret, 0) !=3D pid)
@@ -204,6 +208,11 @@
goto done;=
}
}
+ else if (flags & S_NOWAITPID &&a= mp; (stat > 0))
+ = {
+ ret =3D= stat;
+ goto = done;
+ } else if (platform_system_ok(stat))
{
ret =3D true;
diff --git a/src/openvpn= /run_command.h b/src/openvpn/run_command.h
index ccad307..c= 1ee25e 100644
--- a/src/openvpn/run_command.h
+++ b/src/openvpn/run_command.h

@@ -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 repo= rt the status,
+ * re= turn the pid of the child process */
+#define S_NOWAITPID (1<<3)

/* wrapper around the execve() call */
int ope= nvpn_popen(const struct argv *a, const struct env_set *es);
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index = aee59a6..5032f18 100644
--- a/src/openvpn/tun.c
<= span>+++ b/src/openvpn/tun.c
@@ -75,6 +75,9 @@
case DRIVER_DCO:
return "ovp= n-dco";

+ case DRIVER_AFUNIX:
+ return "unix";
+
#ifdef HAVE_NET_IF_UT= UN_H
case DRIVER_UTUN:
= return "utun";
diff --git a/src/openvpn/tun.h b= /src/openvpn/tun.h
index e41b616..2f7bd4a 100644
= --- a/src/openvpn/tun.h
+++ b/src/openvpn/tun.h
@@ -50,6 +50,10 @@
#else
D= RIVER_GENERIC_TUNTAP,
#endif
+ /** using an AF_UNIX socket to pass packets f= rom/to an external program.
+ * This is always defined. We error out if a user tries to ope= n 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_co= ntext
+{
+ pid_t childprocess;+} afunix_context_t;+
+#else /* if defined(AF_UNIX) && !define= d(WIN32) */
+typedef = struct {
+ int dum= my;
+} afunix_context= _t;
+#endif
struct tuntap
{
= @@ -179,7 +194,12 @@
*/
enum tun= _driver_type backend_driver;

+ /** if the internal variables related to ifc= onfig 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 str= uct 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_deb= ug;

dco_context_t dco;
+ afunix_context_t afunix;
};

static inline bool
@@ -354,8 +375,14 @@
#define IFCONFIG_DEFAULT = IFCONFIG_AFTER_TUN_OPEN

static in= line int
-ifconfig_orde= r(void)
+ifconfig_ord= er(struct tuntap *tt)
{
+#if defined AF_UNIX
+ if (tt->backend_driver =3D=3D DRIVER_AFUNIX)
+ {
+ return IFCONFIG_BEFORE_TUN_O= PEN;
+ }+#endif
#if d= efined(TARGET_LINUX)
return IFCONFIG_AFTER_TUN_OPEN;
#elif defined(TARGET_SOLARIS)
@@ -380,8 +40= 7,14 @@
#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN=

static inline int
-route_order(void)
+route_order(struct tuntap *tt)
{
+#if defined AF_UNIX
+ if (tt->backend= _driver =3D=3D DRIVER_AFUNIX)
+ {
+ = return ROUTE_BEFORE_TUN;
+ }
+#endi= f
#if defined(TARGET_ANDROID)
return = ROUTE_BEFORE_TUN;
#else
@@ -759,5 +792,4 @= @
{
return tt && tt->type = !=3D DEV_TYPE_UNDEF;
}
-
#endif /* TUN_H */
diff= --git a/src/openvpn/tun_afunix.c b/src/openvpn/tun_afunix.c
new file mode 100644

index 0000000..27cdb01
--- /dev/null

+++ b/src/openvpn/tun_afunix.c
<= span>@@ -0,0 +1,178 @@

+ * OpenVPN --= An application to securely tunnel IP networks
+ * over a single TCP/UDP port, with = support for SSL/TLS-based
+ * session authentication and key exchange,
+ * packet encryption,= packet authentication, and

+ * packet compression.
+ *
+ * Copyright (C) 2002-2024 OpenVPN Inc <sales@...515...>
+ *
+ * This program is free software; you ca= n redistribute it and/or modify
+ * it under the terms of the GNU General Public License versio= n 2
+ * as published= by the Free Software Foundation.
+ *
+ * = This program is distributed in the hope that it will be useful,
= + * but WITHOUT ANY WARRANTY; = without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. = See the
+ * GNU Gene= ral Public License for more details.
+ *
+= * You should have received a copy of the GNU General Public License along=
+ * with this progr= am; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, B= oston, MA 02110-1301 USA.
+ */
++#ifdef HAVE_CONFIG_H+#include "config.h"= ;
+#endif
<= span style=3D"color: hsl(120, 100%, 40%);">+

+#include "syshead.h"
+
+#include "tun.h"
+#include "fdmisc.h"
+#include "run_command.h"=
+#include "manage.h&qu= ot;
+#include "w= in32.h"
+#includ= e "wfp_block.h"
+#include "argv.h"
+#include "options.h"
+
+#if defined(AF_UNIX) && !defined(WIN32)
+/* Windows does implement some AF_UNIX fu= nctionality but key features
+ * like socketpair() and SOCK_DGRAM are missing */
+

+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <signal.h><= br>+#include <stdlib.h>
+
+static void
+tun_afunix_exec_child(const char *dev_node, stru= ct tuntap *tt, struct env_set *env)
+{
+ = struct argv argv =3D argv_new();
+
+ = /* since we know that dev-node starts with unix: we can just skip that
+ * to get the progra= m name */
+ const = char *program =3D dev_node + strlen("unix:");
+
+ argv_printf(&argv, "%s", program);
+
+ argv_msg(M_INFO, &argv);
<= span style=3D"color: hsl(120, 100%, 40%);">+ tt->afunix.childprocess = =3D openvpn_execve_check(&argv, env, S_NOWAITPID,

+ = "ERROR: failure executing "
+ = "process for tun");
+ argv_free(&argv);
+}
+
+void
+open_tun_afunix(struct options *= o,

+ i= nt mtu,
+ = struct tuntap *tt,
+{
+ struct gc_arena gc =3D gc_new();
+
+ int fds[2];
= + if (!(socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) =3D=3D 0))
+ {

+ msg(M_ERR, "Cannot create socket p= air for AF_UNIX socket to external "
+ "program");
+ return;
+ }
+
= + /* Use the first file descriptor for our side and avoid passing it

+ * to the child */<= /span>
+ tt->fd =3D fd= s[1];
+ set_cloexe= c(tt->fd);
+
+ /* Make a copy of the= env, so we do not need to delete our custom
+ * environment variables later */
+ struct env_set *env =3D env_= set_create(&gc);

= + env_set_inherit(env, orig_env);
+
+ = setenv_int(env, "TUNTAP_SOCKET_FD", fds[0]);
+ setenv_str(env, "TUNTAP_DEV_T= YPE", dev_type_string(o->dev, o->dev_type));
+ setenv_int(env, "TUNTAP_MTU&qu= ot;, mtu);
+ if (o= ->route_default_gateway)
+ {
+ = setenv_str(env, "ifconfig_gateway", o->route_default_gateway= );
+ }
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (o->lladdr)
+ {
+ setenv_str(env, "TUNTAP_LLAD= DR", o->lladdr);
+ }
++ tun_afunix_exec_child(o-= >dev_node, tt, env);
+
+ close(fds[0= ]);
+
+ /* tt->actual_name is passed= to up and down scripts and used as the ifconfig dev name */
+ tt->actual_name =3D string_= alloc("internal:af_unix", NULL);
+
+ gc_free(&gc);
+}
+
<= span style=3D"color: hsl(120, 100%, 40%);">+void
+tun_afunix_close(struct tuntap *tt)
= +{
+ ASSERT(tt);
+ if (tt->fd >=3D 0)
+ {
+ close(tt->fd);
+ tt->fd =3D 0;
+ }
+ kill(tt->afunix.childprocess, SIGINT);
+
+ free(tt->actual_name);
+ free(tt);
+}
+
+ssize_t
+tun_afunix_write(stru= ct tuntap *tt, uint8_t *buf, int len)
+{
+= int ret;
+ pid= _t pidret =3D waitpid(tt->afunix.childprocess, &ret, WNOHANG);

+ if (pidret =3D=3D tt-= >afunix.childprocess)
+ {
+ m= sg(M_INFO, "Child process PID %d for afunix dead? Return code: %d"= ;,
+ tt-&g= t;afunix.childprocess, ret);
+ return -ENXIO;
+ }
+ = return write(tt->fd, buf, len);
+}
+<= /span>
+ssize_t
+tun_afunix_read(struct tuntap *t= t, uint8_t *buf, int len)

+{
+ return r= ead(tt->fd, buf, len);
+}
+#else /* if= def AF_UNIX */
+void<= /span>
+open_tun_afunix(cons= t char *dev, const char *dev_type, int mtu,
+ struct tuntap *tt, struct env_set e= nv)
+{
+ msg(M_ERR, "AF_UNIX socke= t support not available on this platform");

+}
+
+void

+tun_afunix_close(struct= tuntap *tt)
+{
+ /* should never be ca= lled as open_tun_afunix always fails */
+ ASSERT(0);
+}
+
+ssize_t
+tun_afunix_write(struct tuntap *tt= , uint8_t *buf, int len)

+{
+ /* should= never be called as open_tun_afunix always fails */
+ ASSERT(0);
+}
+
+ssize_t<= /span>
+tun_afunix_read(stru= ct tuntap *tt, uint8_t *buf, int len)
+{
+= /* should never be called as open_tun_afunix always fails */
= + ASSERT(0);
+}

+
+/*
+ * OpenVPN -- An application to securel= y tunnel IP networks
= + * over a single TCP/UDP port, with support for SSL/TLS-based<= /span>
+ * sessi= on authentication and key exchange,
+ * packet encryption, packet authentication, an= d
+ * pac= ket compression.
+ *<= /span>
+ * Copyright (C) 20= 02-2024 OpenVPN Inc <sales@...515...>
+ *
+ * This program is free software; you can redistribute it and/or mo= dify
+ * it under th= e terms of the GNU General Public License version 2
+ * as published by the Free Software Fou= ndation.
+ *+ * This program is distribu= ted in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied = warranty of
+ * MERC= HANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for mo= re details.
+ *
+ * You should have recei= ved a copy of the GNU General Public License along
+ * with this program; if not, write to the = Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.=
+ */
+

+#ifndef AFUNIX_TUN_H
+#define AFUNIX_TUN_H
+#include <sys/types.h>
+
+#include "tun.h"
+
+ * Opens an A= F_UNIX based tun device. This also executes the command that
+ * the user provided taking care o= f implementing the actual tun

+ * device.
= + */
+void
= +open_tun_afunix(struct options= *o,
+ = int mtu,
+ = struct tuntap *tt,
+ struct env_set *env);
+
+
+/**
<= span style=3D"color: hsl(120, 100%, 40%);">+ * Closes the socket used for t= he AF_UNIX based device. Also sends a

+ * SIGINT to the child process that was spawned to handle= the tun device
+ */<= /span>
+void
+tun_afunix_close(struct tuntap *tt)= ;

+
+/**
+ * Writes a packet to a AF_UNIX based tun device.
+ */
+ssize_t
+tun_afunix_write(struct tuntap *tt, uint8_t *buf, i= nt len);
+
= +/**
+ * Reads a packet from a AF_UNIX based tun dev= ice.
+ */
<= span style=3D"color: hsl(120, 100%, 40%);">+ssize_t

+tun_afunix_read(struct tuntap *tt, uint8_= t *buf, int len);
+
+#endif /* AFUNIX_TUN_= H */
+
+/**

+ * Checks whether a --dev-node parameter specifies= a AF_UNIX device
+ *= @param devnode the string to check
+ * @return true if the string starts with unix:<= /span>
+ */
+static inline bool
+is_tun_afunix(const char *devnode)
+{
+ return devnode && strprefix(= devnode, "unix:");
+}

To view, visit change 747. To uns= ubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I65099ef00822d08fd3f5480c808= 92f3bf86c56e7
Gerrit-Change-Number: 747
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--ytBEappxrrc=--