case DRIVER_AFUNIX:
return "unix";
+ case DRIVER_NULL:
+ return "null";
+
case DRIVER_UTUN:
return "utun";
int
dev_type_enum(const char *dev, const char *dev_type)
{
- if (is_dev_type(dev, dev_type, "tun"))
+ /* We pretend that the null device is also a tun device but it does not
+ * really matter as it will discard everything anyway */
+ if (is_dev_type(dev, dev_type, "tun") || is_dev_type(dev, dev_type, "null"))
{
return DEV_TYPE_TUN;
}
{
return DEV_TYPE_TAP;
}
- else if (is_dev_type(dev, dev_type, "null"))
- {
- return DEV_TYPE_NULL;
- }
else
{
return DEV_TYPE_UNDEF;
case DEV_TYPE_TAP:
return "tap";
- case DEV_TYPE_NULL:
- return "null";
-
default:
return "[unknown-dev-type]";
}
bool tun_p2p = false;
if (tt->type == DEV_TYPE_TAP
- || (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
- || tt->type == DEV_TYPE_NULL)
+ || (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET))
{
tun_p2p = false;
}
else
{
msg(M_FATAL, "Error: problem with tun vs. tap setting"); /* JYFIXME -- needs to be caught earlier, in init_tun? */
-
}
return tun_p2p;
}
void
undo_ifconfig(struct tuntap *tt, openvpn_net_ctx_t *ctx)
{
- if (tt->type != DEV_TYPE_NULL)
+ if (tt->backend_driver != DRIVER_NULL)
{
if (tt->did_ifconfig_setup)
{
#endif
}
-static void
-open_null(struct tuntap *tt)
-{
- tt->actual_name = string_alloc("null", NULL);
-}
-
-
#if defined (TARGET_OPENBSD) || (defined(TARGET_DARWIN) && HAVE_NET_IF_UTUN_H)
/*
char dynamic_name[256];
bool dynamic_opened = false;
- if (tt->type == DEV_TYPE_NULL)
+ /*
+ * --dev-node specified, so open an explicit device node
+ */
+ if (dev_node)
{
- open_null(tt);
+ snprintf(tunname, sizeof(tunname), "%s", dev_node);
}
else
{
/*
- * --dev-node specified, so open an explicit device node
+ * dynamic open is indicated by --dev specified without
+ * explicit unit number. Try opening /dev/[dev]n
+ * where n = [0, 255].
*/
- if (dev_node)
- {
- snprintf(tunname, sizeof(tunname), "%s", dev_node);
- }
- else
- {
- /*
- * dynamic open is indicated by --dev specified without
- * explicit unit number. Try opening /dev/[dev]n
- * where n = [0, 255].
- */
- if (!tun_name_is_fixed(dev))
+ if (!tun_name_is_fixed(dev))
+ {
+ for (int i = 0; i < 256; ++i)
{
- for (int i = 0; i < 256; ++i)
- {
- snprintf(tunname, sizeof(tunname),
- "/dev/%s%d", dev, i);
- snprintf(dynamic_name, sizeof(dynamic_name),
- "%s%d", dev, i);
- if ((tt->fd = open(tunname, O_RDWR)) > 0)
- {
- dynamic_opened = true;
- break;
- }
- msg(D_READ_WRITE | M_ERRNO, "Tried opening %s (failed)", tunname);
- }
- if (!dynamic_opened)
+ snprintf(tunname, sizeof(tunname),
+ "/dev/%s%d", dev, i);
+ snprintf(dynamic_name, sizeof(dynamic_name),
+ "%s%d", dev, i);
+ if ((tt->fd = open(tunname, O_RDWR)) > 0)
{
- msg(M_FATAL, "Cannot allocate TUN/TAP dev dynamically");
+ dynamic_opened = true;
+ break;
}
+ msg(D_READ_WRITE | M_ERRNO, "Tried opening %s (failed)", tunname);
}
- /*
- * explicit unit number specified
- */
- else
+ if (!dynamic_opened)
{
- snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
+ msg(M_FATAL, "Cannot allocate TUN/TAP dev dynamically");
}
}
+ /*
+ * explicit unit number specified
+ */
+ else
+ {
+ snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
+ }
+ }
- if (!dynamic_opened)
+ if (!dynamic_opened)
+ {
+ /* has named device existed before? if so, don't destroy at end */
+ if (if_nametoindex( dev ) > 0)
{
- /* 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;
- }
+ 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);
- }
+ if ((tt->fd = open(tunname, O_RDWR)) < 0)
+ {
+ msg(M_ERR, "Cannot open TUN/TAP dev %s", tunname);
}
+ }
- set_nonblock(tt->fd);
- set_cloexec(tt->fd); /* don't pass fd to scripts */
- msg(M_INFO, "TUN/TAP device %s opened", tunname);
+ set_nonblock(tt->fd);
+ set_cloexec(tt->fd); /* don't pass fd to scripts */
+ msg(M_INFO, "TUN/TAP device %s opened", tunname);
+
+ /* tt->actual_name is passed to up and down scripts and used as the ifconfig dev name */
+ tt->actual_name = string_alloc(dynamic_opened ? dynamic_name : dev, NULL);
- /* tt->actual_name is passed to up and down scripts and used as the ifconfig dev name */
- tt->actual_name = string_alloc(dynamic_opened ? dynamic_name : dev, NULL);
- }
}
#endif /* !_WIN32 && !TARGET_LINUX && !TARGET_FREEBSD*/
char dynamic_name[256];
bool dynamic_opened = false;
- if (tt->type == DEV_TYPE_NULL)
- {
- open_null(tt);
- return;
- }
-
/*
* unlike "open_tun_generic()", DCO on Linux and FreeBSD follows
* the device naming model of "non-DCO linux", that is:
{
struct ifreq ifr;
- /*
- * We handle --dev null specially, we do not open /dev/null for this.
- */
- if (tt->type == DEV_TYPE_NULL)
- {
- open_null(tt);
- }
- else if (tun_dco_enabled(tt))
+ if (tun_dco_enabled(tt))
{
open_tun_dco_generic(dev, dev_type, tt, ctx);
}
*/
CLEAR(ifr);
- if (tt->type == DEV_TYPE_NULL)
- {
- open_null(tt);
- return;
- }
-
if (tt->type == DEV_TYPE_TUN)
{
ip_node = "/dev/udp";
char dynamic_name[20];
const char *p;
- if (tt->type == DEV_TYPE_NULL)
- {
- open_null(tt);
- return;
- }
-
if (tt->type == DEV_TYPE_TUN)
{
msg(M_FATAL, "no support for 'tun' devices on AIX" );
msg( M_INFO, "open_tun");
- if (tt->type == DEV_TYPE_NULL)
- {
- open_null(tt);
- return;
- }
- else if (tt->type != DEV_TYPE_TAP && tt->type != DEV_TYPE_TUN)
+ if (tt->type != DEV_TYPE_TAP && tt->type != DEV_TYPE_TUN)
{
msg(M_FATAL|M_NOPREFIX, "Unknown virtual device type: '%s'", dev);
}