o->tuntap_options.dhcp_masq_offset = 0; /* use network address as internal DHCP server address */
o->route_method = ROUTE_METHOD_ADAPTIVE;
o->block_outside_dns = false;
- o->wintun = false;
+ o->windows_driver = WINDOWS_DRIVER_TAP_WINDOWS6;
#endif
o->vlan_accept = VLAN_ALL;
o->vlan_pvid = 1;
#ifdef _WIN32
/* when using wintun, kernel doesn't send DHCP requests, so use netsh to set IP address and netmask */
- if (options->wintun)
+ if (options->windows_driver == WINDOWS_DRIVER_WINTUN)
{
options->tuntap_options.ip_win32_type = IPW32_SET_NETSH;
}
*
* @param str value of --windows-driver option
* @param msglevel msglevel to report parsing error
- * @return bool true if --windows-driver is wintun, false otherwise
+ * @return enum windows_driver_type driver type, WINDOWS_DRIVER_UNSPECIFIED on unknown --windows-driver value
*/
-static bool
+static enum windows_driver_type
parse_windows_driver(const char *str, const int msglevel)
{
if (streq(str, "tap-windows6"))
{
- return false;
+ return WINDOWS_DRIVER_TAP_WINDOWS6;
}
else if (streq(str, "wintun"))
{
- return true;
+ return WINDOWS_DRIVER_WINTUN;
}
else
{
msg(msglevel, "--windows-driver must be tap-windows6 or wintun");
- return false;
+ return WINDOWS_DRIVER_UNSPECIFIED;
}
}
#endif
else if (streq(p[0], "windows-driver") && p[1] && !p[2])
{
VERIFY_PERMISSION(OPT_P_GENERAL);
- options->wintun = parse_windows_driver(p[1], M_FATAL);
+ options->windows_driver = parse_windows_driver(p[1], M_FATAL);
}
#endif
else if (streq(p[0], "dev-node") && p[1] && !p[2])
overlapped_io_init(&tt->writes, frame, TRUE, true);
tt->adapter_index = TUN_ADAPTER_INDEX_INVALID;
- if (tt->wintun)
+ if (tt->windows_driver == WINDOWS_DRIVER_WINTUN)
{
tt->wintun_send_ring_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE,
{
ASSERT(ifname != NULL);
- if (tt->options.msg_channel && tt->wintun)
+ if (tt->options.msg_channel && tt->windows_driver == WINDOWS_DRIVER_WINTUN)
{
do_address_service(true, AF_INET, tt);
do_dns_service(true, AF_INET, tt);
#elif defined(_WIN32)
+static const char *
+print_windows_driver(enum windows_driver_type windows_driver)
+{
+ switch (windows_driver)
+ {
+ case WINDOWS_DRIVER_TAP_WINDOWS6:
+ return "tap-windows6";
+
+ case WINDOWS_DRIVER_WINTUN:
+ return "wintun";
+
+ default:
+ return "unspecified";
+ }
+}
+
int
tun_read_queue(struct tuntap *tt, int maxsize)
{
if (status == ERROR_SUCCESS && data_type == REG_SZ)
{
- if (!strcmp(component_id, TAP_WIN_COMPONENT_ID) ||
- !strcmp(component_id, "root\\" TAP_WIN_COMPONENT_ID) ||
- !strcmp(component_id, WINTUN_COMPONENT_ID))
+ enum windows_driver_type windows_driver = WINDOWS_DRIVER_UNSPECIFIED;
+
+ if ((windows_driver = WINDOWS_DRIVER_TAP_WINDOWS6, !strcmp(component_id, TAP_WIN_COMPONENT_ID))
+ || (windows_driver = WINDOWS_DRIVER_TAP_WINDOWS6, !strcmp(component_id, "root\\" TAP_WIN_COMPONENT_ID))
+ || (windows_driver = WINDOWS_DRIVER_WINTUN, !strcmp(component_id, WINTUN_COMPONENT_ID)))
{
struct tap_reg *reg;
ALLOC_OBJ_CLEAR_GC(reg, struct tap_reg, gc);
reg->guid = string_alloc(net_cfg_instance_id, gc);
- reg->wintun = !strcmp(component_id, WINTUN_COMPONENT_ID);
+ reg->windows_driver = windows_driver;
/* link into return list */
if (!first)
{
if (!strcmp(tr->guid, pr->guid))
{
- msg(msglev, "'%s' %s %s", pr->name, tr->guid, tr->wintun ? "wintun" : "tap-windows6");
+ msg(msglev, "'%s' %s %s", pr->name, tr->guid, print_windows_driver(tr->windows_driver));
++links;
}
}
int actual_name_size,
const struct tap_reg *tap_reg_src,
const struct panel_reg *panel_reg_src,
- bool *wintun,
+ enum windows_driver_type *windows_driver,
struct gc_arena *gc)
{
const struct tap_reg *tap_reg = tap_reg_src;
/* Save GUID for return value */
ret = alloc_buf_gc(256, gc);
buf_printf(&ret, "%s", tap_reg->guid);
- if (wintun != NULL)
+ if (windows_driver != NULL)
{
- *wintun = tap_reg->wintun;
+ *windows_driver = tap_reg->windows_driver;
}
return BSTR(&ret);
}
get_device_guid(const char *name,
char *actual_name,
int actual_name_size,
- bool *wintun,
+ enum windows_driver_type *windows_driver,
const struct tap_reg *tap_reg,
const struct panel_reg *panel_reg,
struct gc_arena *gc)
{
buf_printf(&actual, "%s", name);
}
- if (wintun)
+ if (windows_driver)
{
- *wintun = tr->wintun;
+ *windows_driver = tr->windows_driver;
}
return BSTR(&ret);
}
if (tr)
{
buf_printf(&actual, "%s", name);
- if (wintun)
+ if (windows_driver)
{
- *wintun = tr->wintun;
+ *windows_driver = tr->windows_driver;
}
buf_printf(&ret, "%s", tr->guid);
return BSTR(&ret);
const char *path = NULL;
char tuntap_device_path[256];
- if (tt->wintun)
+ if (tt->windows_driver == WINDOWS_DRIVER_WINTUN)
{
const struct device_instance_id_interface *dev_if;
0);
if (tt->hand == INVALID_HANDLE_VALUE)
{
- msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "Wintun" : "TAP-Windows", path);
+ msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", print_windows_driver(tt->windows_driver), path);
return false;
}
- if (tt->wintun)
+ if (tt->windows_driver == WINDOWS_DRIVER_WINTUN)
{
/* Wintun adapter may be considered "open" after ring buffers are successfuly registered. */
if (!wintun_register_ring_buffer(tt))
*/
if (dev_node)
{
- bool is_picked_device_wintun = false;
+ enum windows_driver_type windows_driver = WINDOWS_DRIVER_UNSPECIFIED;
/* Get the device GUID for the device specified with --dev-node. */
- *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), &is_picked_device_wintun, tap_reg, panel_reg, &gc);
+ *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), &windows_driver, tap_reg, panel_reg, &gc);
if (!*device_guid)
{
msg(M_FATAL, "Adapter '%s' not found", dev_node);
}
- if (tt->wintun)
- {
- if (!is_picked_device_wintun)
- {
- msg(M_FATAL, "Adapter '%s' is TAP-Windows, Wintun expected. If you want to use this device, remove --windows-driver wintun.", dev_node);
- }
- }
- else
+ if (tt->windows_driver != windows_driver)
{
- if (is_picked_device_wintun)
- {
- msg(M_FATAL, "Adapter '%s' is Wintun, TAP-Windows expected. If you want to use this device, add --windows-driver wintun.", dev_node);
- }
+ msg(M_FATAL, "Adapter '%s' is using %s driver, %s expected. If you want to use this device, adjust --windows-driver.", dev_node, print_windows_driver(windows_driver), print_windows_driver(tt->windows_driver));
}
if (!tun_try_open_device(tt, *device_guid, device_instance_id_interface))
{
- msg(M_FATAL, "Failed to open %s adapter: %s", tt->wintun ? "Wintun" : "TAP-Windows", dev_node);
+ msg(M_FATAL, "Failed to open %s adapter: %s", print_windows_driver(tt->windows_driver), dev_node);
}
}
else
/* Try opening all TAP devices until we find one available */
while (true)
{
- bool is_picked_device_wintun = false;
+ enum windows_driver_type windows_driver = WINDOWS_DRIVER_UNSPECIFIED;
*device_guid = get_unspecified_device_guid(device_number,
actual_buffer,
sizeof(actual_buffer),
tap_reg,
panel_reg,
- &is_picked_device_wintun,
+ &windows_driver,
&gc);
if (!*device_guid)
{
- msg(M_FATAL, "All %s adapters on this system are currently in use.", tt->wintun ? "wintun" : "TAP - Windows");
+ msg(M_FATAL, "All %s adapters on this system are currently in use.", print_windows_driver(tt->windows_driver));
}
- if (tt->wintun)
- {
- if (!is_picked_device_wintun)
- {
- /* wintun driver specified but picked adapter is not wintun, proceed to next one */
- goto next;
- }
- }
- else
+ if (tt->windows_driver != windows_driver)
{
- if (is_picked_device_wintun)
- {
- /* tap-windows6 driver specified but picked adapter is wintun, proceed to next one */
- goto next;
- }
+ goto next;
}
if (tun_try_open_device(tt, *device_guid, device_instance_id_interface))
* GUID using the registry */
tt->actual_name = string_alloc(actual_buffer, NULL);
- msg(M_INFO, "%s device [%s] opened", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name);
+ msg(M_INFO, "%s device [%s] opened", print_windows_driver(tt->windows_driver), tt->actual_name);
tt->adapter_index = get_adapter_index(*device_guid);
gc_free(&gc);
tun_open_device(tt, dev_node, &device_guid);
- if (!tt->wintun)
+ if (tt->windows_driver == WINDOWS_DRIVER_TAP_WINDOWS6)
{
tuntap_post_open(tt, device_guid);
}
const char *
tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
{
- if (!tt->wintun)
+ if (tt->windows_driver == WINDOWS_DRIVER_TAP_WINDOWS6)
{
struct buffer out = alloc_buf_gc(256, gc);
DWORD len;
void
tun_show_debug(struct tuntap *tt)
{
- if (!tt->wintun)
+ if (tt->windows_driver == WINDOWS_DRIVER_TAP_WINDOWS6)
{
struct buffer out = alloc_buf(1024);
DWORD len;
}
}
#if 1
- if (tt->wintun)
+ if (tt->windows_driver == WINDOWS_DRIVER_WINTUN)
{
if (tt->options.msg_channel)
{
free(tt->actual_name);
}
- if (tt->wintun)
+ if (tt->windows_driver == WINDOWS_DRIVER_WINTUN)
{
CloseHandle(tt->rw_handle.read);
CloseHandle(tt->rw_handle.write);