summaryrefslogtreecommitdiffstats
path: root/src/openvpn/init.c
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-04-26 21:59:32 +0200
committerGert Doering <gert@greenie.muc.de>2013-05-01 12:27:54 +0200
commitbd14d55d87248d18088fc9897e9ffd46a59e147b (patch)
tree4196de95e5457d31be884203736cd3b09ac01982 /src/openvpn/init.c
parenta55b3cdb236ebfd181c24f54ead4b4c27c7bdda7 (diff)
downloadopenvpn-bd14d55d87248d18088fc9897e9ffd46a59e147b.tar.gz
openvpn-bd14d55d87248d18088fc9897e9ffd46a59e147b.tar.xz
openvpn-bd14d55d87248d18088fc9897e9ffd46a59e147b.zip
Emulate persist-tun on Android
On Android changing the configuration of tun is not possible. So instead of reconfiguring the tun device, open a new tun device and close the old one if needed. Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <1367006372-14815-1-git-send-email-arne@rfc2549.org> URL: http://article.gmane.org/gmane.network.openvpn.devel/7558 Signed-off-by: Gert Doering <gert@greenie.muc.de>
Diffstat (limited to 'src/openvpn/init.c')
-rw-r--r--src/openvpn/init.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index e7c16e0..98f5489 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -1402,8 +1402,19 @@ do_open_tun (struct context *c)
c->c2.ipv4_tun = (!c->options.tun_ipv6
&& is_dev_type (c->options.dev, c->options.dev_type, "tun"));
+#ifndef TARGET_ANDROID
if (!c->c1.tuntap)
{
+#endif
+
+#ifdef TARGET_ANDROID
+ /* If we emulate persist-tun on android we still have to open a new tun and
+ then close the old */
+ int oldtunfd=-1;
+ if (c->c1.tuntap)
+ oldtunfd = c->c1.tuntap->fd;
+#endif
+
/* initialize (but do not open) tun/tap object */
do_init_tun (c);
@@ -1439,7 +1450,10 @@ do_open_tun (struct context *c)
/* open the tun device */
open_tun (c->options.dev, c->options.dev_type, c->options.dev_node,
c->c1.tuntap);
-
+#ifdef TARGET_ANDROID
+ if (oldtunfd>=0)
+ close(oldtunfd);
+#endif
/* set the hardware address */
if (c->options.lladdr)
set_lladdr(c->c1.tuntap->actual_name, c->options.lladdr, c->c2.es);
@@ -1481,6 +1495,7 @@ do_open_tun (struct context *c)
ret = true;
static_context = c;
+#ifndef TARGET_ANDROID
}
else
{
@@ -1503,6 +1518,7 @@ do_open_tun (struct context *c)
"up",
c->c2.es);
}
+#endif
gc_free (&gc);
return ret;
}