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>
... | ... |
@@ -1402,8 +1402,19 @@ do_open_tun (struct context *c) |
1402 | 1402 |
c->c2.ipv4_tun = (!c->options.tun_ipv6 |
1403 | 1403 |
&& is_dev_type (c->options.dev, c->options.dev_type, "tun")); |
1404 | 1404 |
|
1405 |
+#ifndef TARGET_ANDROID |
|
1405 | 1406 |
if (!c->c1.tuntap) |
1406 | 1407 |
{ |
1408 |
+#endif |
|
1409 |
+ |
|
1410 |
+#ifdef TARGET_ANDROID |
|
1411 |
+ /* If we emulate persist-tun on android we still have to open a new tun and |
|
1412 |
+ then close the old */ |
|
1413 |
+ int oldtunfd=-1; |
|
1414 |
+ if (c->c1.tuntap) |
|
1415 |
+ oldtunfd = c->c1.tuntap->fd; |
|
1416 |
+#endif |
|
1417 |
+ |
|
1407 | 1418 |
/* initialize (but do not open) tun/tap object */ |
1408 | 1419 |
do_init_tun (c); |
1409 | 1420 |
|
... | ... |
@@ -1439,7 +1450,10 @@ do_open_tun (struct context *c) |
1439 | 1439 |
/* open the tun device */ |
1440 | 1440 |
open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, |
1441 | 1441 |
c->c1.tuntap); |
1442 |
- |
|
1442 |
+#ifdef TARGET_ANDROID |
|
1443 |
+ if (oldtunfd>=0) |
|
1444 |
+ close(oldtunfd); |
|
1445 |
+#endif |
|
1443 | 1446 |
/* set the hardware address */ |
1444 | 1447 |
if (c->options.lladdr) |
1445 | 1448 |
set_lladdr(c->c1.tuntap->actual_name, c->options.lladdr, c->c2.es); |
... | ... |
@@ -1481,6 +1495,7 @@ do_open_tun (struct context *c) |
1481 | 1481 |
|
1482 | 1482 |
ret = true; |
1483 | 1483 |
static_context = c; |
1484 |
+#ifndef TARGET_ANDROID |
|
1484 | 1485 |
} |
1485 | 1486 |
else |
1486 | 1487 |
{ |
... | ... |
@@ -1503,6 +1518,7 @@ do_open_tun (struct context *c) |
1503 | 1503 |
"up", |
1504 | 1504 |
c->c2.es); |
1505 | 1505 |
} |
1506 |
+#endif |
|
1506 | 1507 |
gc_free (&gc); |
1507 | 1508 |
return ret; |
1508 | 1509 |
} |