#elif defined(TARGET_OPENBSD)
/*
- * On OpenBSD, tun interfaces are persistant if created with
+ * On OpenBSD, tun interfaces are persistent if created with
* "ifconfig tunX create", and auto-destroyed if created by
* opening "/dev/tunX" (so we just use the /dev/tunX)
*/
gc_free (&gc);
}
-void
+static void
clear_tuntap (struct tuntap *tuntap)
{
CLEAR (*tuntap);
if (!dynamic_opened)
{
+ /* has named device existed before? if so, don't destroy at end */
+ if ( if_nametoindex( dev ) > 0 )
+ {
+ msg (M_INFO, "TUN/TAP device %s exists previously, keep at program end", dev );
+ tt->persistent_if = true;
+ }
+
if ((tt->fd = open (tunname, O_RDWR)) < 0)
msg (M_ERR, "Cannot open TUN/TAP dev %s", tunname);
}
{
/* only *TAP* devices need destroying, tun devices auto-self-destruct
*/
- if (tt && tt->type == DEV_TYPE_TUN )
+ if (tt && (tt->type == DEV_TYPE_TUN || tt->persistent_if ) )
{
close_tun_generic (tt);
free(tt);
{
/* only tun devices need destroying, tap devices auto-self-destruct
*/
- if (tt && tt->type != DEV_TYPE_TUN )
+ if (tt && ( tt->type != DEV_TYPE_TUN || tt->persistent_if ) )
{
close_tun_generic (tt);
free(tt);
void
close_tun (struct tuntap *tt)
{
- if (tt)
+ if (tt && tt->persistent_if ) /* keep pre-existing if around */
+ {
+ close_tun_generic (tt);
+ free (tt);
+ }
+ else if (tt) /* close and destroy */
{
struct gc_arena gc = gc_new ();
struct argv argv;
bool ipv6;
+ bool persistent_if; /* if existed before, keep on program end */
+
struct tuntap_options options; /* options set on command line */
char *actual_name; /* actual name of TUN/TAP dev, usually including unit number */
* Function prototypes
*/
-void clear_tuntap (struct tuntap *tuntap);
+static void clear_tuntap (struct tuntap *tuntap);
void open_tun (const char *dev, const char *dev_type, const char *dev_node,
struct tuntap *tt);