Skip to content

Commit

Permalink
tun.c: use new networking API to handle tun interface on Linux
Browse files Browse the repository at this point in the history
By switching to the networking API (for Linux) openvpn will
now use any of the available implementations to handle the tun
interface.

At the moment only iproute2 and sitnl (NetLink) is implemented.

Signed-off-by: Antonio Quartulli <[email protected]>
Acked-by: Arne Schwabe <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg18028.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
ordex authored and cron2 committed Jun 2, 2019
1 parent c654225 commit dc7fcd7
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 121 deletions.
22 changes: 14 additions & 8 deletions src/openvpn/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ do_genkey(const struct options *options)
* Persistent TUN/TAP device management mode?
*/
bool
do_persist_tuntap(const struct options *options)
do_persist_tuntap(const struct options *options, openvpn_net_ctx_t *ctx)
{
if (options->persist_config)
{
Expand All @@ -1123,7 +1123,8 @@ do_persist_tuntap(const struct options *options)
#ifdef ENABLE_FEATURE_TUN_PERSIST
tuncfg(options->dev, options->dev_type, options->dev_node,
options->persist_mode,
options->username, options->groupname, &options->tuntap_options);
options->username, options->groupname, &options->tuntap_options,
ctx);
if (options->persist_mode && options->lladdr)
{
set_lladdr(options->dev, options->lladdr, NULL);
Expand Down Expand Up @@ -1694,7 +1695,8 @@ do_init_tun(struct context *c)
c->c1.link_socket_addr.bind_local,
c->c1.link_socket_addr.remote_list,
!c->options.ifconfig_nowarn,
c->c2.es);
c->c2.es,
&c->net_ctx);

init_tun_post(c->c1.tuntap,
&c->c2.frame,
Expand Down Expand Up @@ -1766,7 +1768,8 @@ do_open_tun(struct context *c)
c->options.dev_type,
c->options.dev_node,
&gc);
do_ifconfig(c->c1.tuntap, guess, TUN_MTU_SIZE(&c->c2.frame), c->c2.es);
do_ifconfig(c->c1.tuntap, guess, TUN_MTU_SIZE(&c->c2.frame), c->c2.es,
&c->net_ctx);
}

/* possibly add routes */
Expand Down Expand Up @@ -1794,7 +1797,8 @@ do_open_tun(struct context *c)
if (!c->options.ifconfig_noexec
&& ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN)
{
do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name, TUN_MTU_SIZE(&c->c2.frame), c->c2.es);
do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name,
TUN_MTU_SIZE(&c->c2.frame), c->c2.es, &c->net_ctx);
}

/* run the up script */
Expand Down Expand Up @@ -1902,7 +1906,7 @@ do_close_tun_simple(struct context *c)
msg(D_CLOSE, "Closing TUN/TAP interface");
if (c->c1.tuntap)
{
close_tun(c->c1.tuntap);
close_tun(c->c1.tuntap, &c->net_ctx);
c->c1.tuntap = NULL;
}
c->c1.tuntap_owned = false;
Expand Down Expand Up @@ -3380,9 +3384,11 @@ do_compute_occ_strings(struct context *c)
struct gc_arena gc = gc_new();

c->c2.options_string_local =
options_string(&c->options, &c->c2.frame, c->c1.tuntap, false, &gc);
options_string(&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ctx,
false, &gc);
c->c2.options_string_remote =
options_string(&c->options, &c->c2.frame, c->c1.tuntap, true, &gc);
options_string(&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ctx,
true, &gc);

msg(D_SHOW_OCC, "Local Options String (VER=%s): '%s'",
options_string_version(c->c2.options_string_local, &gc),
Expand Down
2 changes: 1 addition & 1 deletion src/openvpn/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool print_openssl_info(const struct options *options);

bool do_genkey(const struct options *options);

bool do_persist_tuntap(const struct options *options);
bool do_persist_tuntap(const struct options *options, openvpn_net_ctx_t *ctx);

bool possibly_become_daemon(const struct options *options);

Expand Down
6 changes: 0 additions & 6 deletions src/openvpn/networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
#ifndef NETWORKING_H_
#define NETWORKING_H_

#ifdef HAVE_CONFIG_H
#include "config.h"
#elif defined(_MSC_VER)
#include "config-msvc.h"
#endif

#include "syshead.h"

struct context;
Expand Down
4 changes: 3 additions & 1 deletion src/openvpn/openvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ openvpn_main(int argc, char *argv[])
open_plugins(&c, true, OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE);
#endif

net_ctx_init(&c, &c.net_ctx);

/* init verbosity and mute levels */
init_verb_mute(&c, IVM_LEVEL_1);

Expand All @@ -234,7 +236,7 @@ openvpn_main(int argc, char *argv[])
}

/* tun/tap persist command? */
if (do_persist_tuntap(&c.options))
if (do_persist_tuntap(&c.options, &c.net_ctx))
{
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/openvpn/openvpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ struct context

struct env_set *es; /**< Set of environment variables. */

openvpn_net_ctx_t net_ctx; /**< Networking API opaque context */

struct signal_info *sig; /**< Internal error signaling object. */

struct plugin_list *plugins; /**< List of plug-ins. */
Expand Down
4 changes: 3 additions & 1 deletion src/openvpn/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -3548,6 +3548,7 @@ char *
options_string(const struct options *o,
const struct frame *frame,
struct tuntap *tt,
openvpn_net_ctx_t *ctx,
bool remote,
struct gc_arena *gc)
{
Expand Down Expand Up @@ -3590,7 +3591,8 @@ options_string(const struct options *o,
NULL,
NULL,
false,
NULL);
NULL,
ctx);
if (tt)
{
tt_local = true;
Expand Down
1 change: 1 addition & 0 deletions src/openvpn/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ const char *options_string_version(const char *s, struct gc_arena *gc);
char *options_string(const struct options *o,
const struct frame *frame,
struct tuntap *tt,
openvpn_net_ctx_t *ctx,
bool remote,
struct gc_arena *gc);

Expand Down
Loading

0 comments on commit dc7fcd7

Please sign in to comment.