Go to the documentation of this file.
29 #include <tap-windows.h>
46 #define WINTUN_COMPONENT_ID "wintun"
47 #define DCO_WIN_REFERENCE_STRING "ovpn-dco"
57 #if defined(_WIN32) || defined(TARGET_ANDROID)
59 #define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
62 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
63 #define IPW32_SET_ADAPTIVE_TRY_NETSH 20
66 #define DHCP_OPTIONS_DHCP_OPTIONAL (1<<0)
67 #define DHCP_OPTIONS_DHCP_REQUIRED (1<<1)
75 #define IPW32_SET_MANUAL 0
76 #define IPW32_SET_NETSH 1
77 #define IPW32_SET_IPAPI 2
78 #define IPW32_SET_DHCP_MASQ 3
79 #define IPW32_SET_ADAPTIVE 4
105 #define N_DHCP_ADDR 4
124 #define N_SEARCH_LIST_LEN 10
140 #if defined(TARGET_ANDROID)
141 const char *http_proxy;
146 #elif defined(TARGET_LINUX)
153 #elif defined(TARGET_FREEBSD)
174 #define TUNNEL_TYPE(tt) ((tt) ? ((tt)->type) : DEV_TYPE_UNDEF)
177 #define TUNNEL_TOPOLOGY(tt) ((tt) ? ((tt)->topology) : TOP_UNDEF)
225 #ifdef TARGET_SOLARIS
229 #ifdef HAVE_NET_IF_UTUN_H
242 return tt && tt->
hand != NULL;
244 return tt && tt->fd >= 0;
266 void open_tun(
const char *dev,
const char *dev_type,
const char *dev_node,
272 const char **device_guid,
struct gc_arena *gc);
280 void tuncfg(
const char *dev,
const char *dev_type,
const char *dev_node,
281 int persist_mode,
const char *username,
286 const char *dev_type,
287 const char *dev_node,
291 const char *dev_type,
293 const char *ifconfig_local_parm,
294 const char *ifconfig_remote_netmask_parm,
295 const char *ifconfig_ipv6_local_parm,
296 int ifconfig_ipv6_netbits_parm,
297 const char *ifconfig_ipv6_remote_parm,
298 struct addrinfo *local_public,
299 struct addrinfo *remote_public,
300 const bool strict_warn,
332 bool is_dev_type(
const char *dev,
const char *dev_type,
const char *match_type);
343 const in_addr_t netmask,
353 #define IFCONFIG_BEFORE_TUN_OPEN 0
354 #define IFCONFIG_AFTER_TUN_OPEN 1
356 #define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPEN
361 #if defined(TARGET_LINUX)
363 #elif defined(TARGET_SOLARIS)
365 #elif defined(TARGET_OPENBSD)
367 #elif defined(TARGET_DARWIN)
369 #elif defined(TARGET_NETBSD)
371 #elif defined(_WIN32)
373 #elif defined(TARGET_ANDROID)
380 #define ROUTE_BEFORE_TUN 0
381 #define ROUTE_AFTER_TUN 1
382 #define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN
387 #if defined(TARGET_ANDROID)
434 const IP_ADAPTER_INFO *
get_adapter(
const IP_ADAPTER_INFO *ai, DWORD index);
482 return GetLastError() == ERROR_FILE_NOT_FOUND;
495 return GetLastError() == ERROR_OPERATION_ABORTED;
522 ULONG aligned_packet_size;
529 msg(
M_INFO,
"Wintun: ring capacity exceeded");
543 msg(
M_INFO,
"Wintun: incomplete packet header in send ring");
551 msg(
M_INFO,
"Wintun: packet too big in send ring");
557 if (aligned_packet_size > content_len)
559 msg(
M_INFO,
"Wintun: incomplete packet in send ring");
603 ULONG aligned_packet_size;
610 msg(
D_LOW,
"write_wintun(): drop invalid IP packet");
616 msg(
M_INFO,
"write_wintun(): head/tail value is over capacity");
622 if (aligned_packet_size > buf_space)
624 msg(
M_INFO,
"write_wintun(): ring is full");
728 unsigned int rwflags,
730 unsigned int *persistent)
738 if (!persistent || *persistent != rwflags)
743 *persistent = rwflags;
void tun_show_debug(struct tuntap *tt)
struct overlapped_io reads
int read_tun(struct tuntap *tt, uint8_t *buf, int len)
bool dhcp_masq_custom_offset
#define WINTUN_RING_CAPACITY
in_addr_t dns[N_DHCP_ADDR]
const char * domain_search_list[N_SEARCH_LIST_LEN]
#define WINTUN_PACKET_ALIGN
int tun_write_queue(struct tuntap *tt, struct buffer *buf)
@ WINDOWS_DRIVER_UNSPECIFIED
void open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt, openvpn_net_ctx_t *ctx)
struct device_instance_id_interface * next
static event_t tun_event_handle(const struct tuntap *tt)
#define ROUTE_ORDER_DEFAULT
int len
Length in bytes of the actual content within the allocated memory.
in_addr_t nbdd[N_DHCP_ADDR]
bool is_tun_p2p(const struct tuntap *tt)
enum windows_driver_type windows_driver
int domain_search_list_len
static bool tuntap_is_wintun(struct tuntap *tt)
const char * print_windows_driver(enum windows_driver_type windows_driver)
UCHAR data[WINTUN_MAX_PACKET_SIZE]
void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
struct tun_ring * wintun_receive_ring
static ULONG wintun_ring_wrap(ULONG value)
struct tun_ring * wintun_send_ring
static bool tuntap_abort(int status)
void close_tun_handle(struct tuntap *tt)
const char * netbios_scope
void warn_on_use_of_common_subnets(openvpn_net_ctx_t *ctx)
void tun_standby_init(struct tuntap *tt)
static bool is_ip_packet_valid(const struct buffer *buf)
bool dhcp_renew_by_adapter_index(const DWORD adapter_index)
HANDLE wintun_send_ring_handle
const IP_ADAPTER_INFO * get_tun_adapter(const struct tuntap *tt, const IP_ADAPTER_INFO *list)
int tun_write_win32(struct tuntap *tt, struct buffer *buf)
void init_tun_post(struct tuntap *tt, const struct frame *frame, const struct tuntap_options *options)
static int write_wintun(struct tuntap *tt, struct buffer *buf)
Packet geometry parameters.
#define IFCONFIG_AFTER_TUN_OPEN
#define N_SEARCH_LIST_LEN
static int route_order(void)
const IP_ADAPTER_INFO * get_adapter(const IP_ADAPTER_INFO *ai, DWORD index)
static bool is_tun_type_set(const struct tuntap *tt)
int tun_read_queue(struct tuntap *tt, int maxsize)
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
const IP_ADAPTER_INFO * get_adapter_info(DWORD index, struct gc_arena *gc)
static bool tuntap_defined(const struct tuntap *tt)
bool did_ifconfig_ipv6_setup
struct in6_addr local_ipv6
unsigned int rwflags_debug
bool is_dev_type(const char *dev, const char *dev_type, const char *match_type)
static ULONG wintun_ring_packet_align(ULONG size)
Wintun ring buffer See https://github.com/WireGuard/wintun#ring-layout.
const char * guess_tuntap_dev(const char *dev, const char *dev_type, const char *dev_node, struct gc_arena *gc)
#define WINTUN_MAX_PACKET_SIZE
const char * dev_type_string(const char *dev, const char *dev_type)
bool tun_standby(struct tuntap *tt)
struct rw_handle rw_handle
const char * ipset2ascii(int index)
void check_subnet_conflict(const in_addr_t ip, const in_addr_t netmask, const char *prefix)
void show_valid_win32_tun_subnets(void)
void ipconfig_register_dns(const struct env_set *es)
#define IFCONFIG_BEFORE_TUN_OPEN
in_addr_t adapter_netmask
static bool tuntap_ring_empty(struct tuntap *tt)
Wrapper structure for dynamically allocated memory.
void show_adapters(int msglev)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai, const in_addr_t ip, in_addr_t *highest_netmask)
bool is_adapter_up(const struct tuntap *tt, const IP_ADAPTER_INFO *list)
const IP_ADAPTER_INFO * get_adapter_info_list(struct gc_arena *gc)
Garbage collection arena used to keep track of dynamically allocated memory.
DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count, in_addr_t *netmask)
void show_tap_win_adapters(int msglev, int warnlev)
struct overlapped_io writes
const char * ifconfig_options_string(const struct tuntap *tt, bool remote, bool disable, struct gc_arena *gc)
void fork_register_dns_action(struct tuntap *tt)
static bool tuntap_is_dco_win_timeout(struct tuntap *tt, int status)
int ascii2ipset(const char *name)
in_addr_t wins[N_DHCP_ADDR]
static void read_wintun(struct tuntap *tt, struct buffer *buf)
bool dhcp_release_by_adapter_index(const DWORD adapter_index)
const IP_PER_ADAPTER_INFO * get_per_adapter_info(const DWORD index, struct gc_arena *gc)
#define OPENVPN_IPH_GET_VER(v)
static SERVICE_STATUS status
struct in6_addr dns6[N_DHCP_ADDR]
struct in6_addr remote_ipv6
void tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_guid, struct gc_arena *gc)
@ WINDOWS_DRIVER_TAP_WINDOWS6
const char * tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
static int ifconfig_order(void)
const char * device_interface
void do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, const struct env_set *es, openvpn_net_ctx_t *ctx)
do_ifconfig - configure the tunnel interface
enum windows_driver_type windows_driver
int dev_type_enum(const char *dev, const char *dev_type)
void verify_255_255_255_252(in_addr_t local, in_addr_t remote)
const char * tun_stat(const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc)
void tuncfg(const char *dev, const char *dev_type, const char *dev_node, int persist_mode, const char *username, const char *groupname, const struct tuntap_options *options, openvpn_net_ctx_t *ctx)
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
bool tun_name_is_fixed(const char *dev)
const char * ipset2ascii_all(struct gc_arena *gc)
LPBYTE net_cfg_instance_id
static bool tuntap_stop(int status)
UCHAR data[WINTUN_RING_CAPACITY+WINTUN_RING_TRAILING_BYTES]
struct tuntap * init_tun(const char *dev, const char *dev_type, int topology, const char *ifconfig_local_parm, const char *ifconfig_remote_netmask_parm, const char *ifconfig_ipv6_local_parm, int ifconfig_ipv6_netbits_parm, const char *ifconfig_ipv6_remote_parm, struct addrinfo *local_public, struct addrinfo *remote_public, const bool strict_warn, struct env_set *es, openvpn_net_ctx_t *ctx, struct tuntap *tt)
void tap_allow_nonadmin_access(const char *dev_node)
static bool tuntap_is_dco_win(struct tuntap *tt)
bool ipapi_context_defined
void do_ifconfig_setenv(const struct tuntap *tt, struct env_set *es)
int write_tun(struct tuntap *tt, uint8_t *buf, int len)
in_addr_t ntp[N_DHCP_ADDR]
static int write_tun_buffered(struct tuntap *tt, struct buffer *buf)
void undo_ifconfig(struct tuntap *tt, openvpn_net_ctx_t *ctx)
undo_ifconfig - undo configuration of the tunnel interface
HANDLE wintun_receive_ring_handle