OpenVPN
Data Structures | Macros | Functions | Variables
tun.c File Reference
#include "syshead.h"
#include "tun.h"
#include "fdmisc.h"
#include "common.h"
#include "run_command.h"
#include "socket.h"
#include "manage.h"
#include "route.h"
#include "win32.h"
#include "block_dns.h"
#include "networking.h"
#include "memdbg.h"
#include "openvpn-msg.h"
#include <string.h>
Include dependency graph for tun.c:

Go to the source code of this file.

Data Structures

struct  ipset_names
 

Macros

#define NI_TEST_FIRST   (1<<0)
 
#define NI_IP_NETMASK   (1<<1)
 
#define NI_OPTIONS   (1<<2)
 
#define DHCP_STATUS_UNDEF   0
 
#define DHCP_STATUS_ENABLED   1
 
#define DHCP_STATUS_DISABLED   2
 

Functions

static void netsh_ifconfig (const struct tuntap_options *to, const char *flex_name, const in_addr_t ip, const in_addr_t netmask, const unsigned int flags)
 
static void netsh_set_dns6_servers (const struct in6_addr *addr_list, const int addr_len, const char *flex_name)
 Set the ipv6 dns servers on the specified interface. More...
 
static void netsh_command (const struct argv *a, int n, int msglevel)
 
static const char * netsh_get_id (const char *dev_node, struct gc_arena *gc)
 
static DWORD get_adapter_index_flexible (const char *name)
 
static bool do_address_service (const bool add, const short family, const struct tuntap *tt)
 
static bool do_dns_service (bool add, const short family, const struct tuntap *tt)
 
static void clear_tuntap (struct tuntap *tuntap)
 
bool is_dev_type (const char *dev, const char *dev_type, const char *match_type)
 
int dev_type_enum (const char *dev, const char *dev_type)
 
const char * dev_type_string (const char *dev, const char *dev_type)
 
const char * guess_tuntap_dev (const char *dev, const char *dev_type, const char *dev_node, struct gc_arena *gc)
 
static void ifconfig_sanity_check (bool tun, in_addr_t addr, int topology)
 
static void check_addr_clash (const char *name, int type, in_addr_t public, in_addr_t local, in_addr_t remote_netmask)
 
void check_subnet_conflict (const in_addr_t ip, const in_addr_t netmask, const char *prefix)
 
void warn_on_use_of_common_subnets (openvpn_net_ctx_t *ctx)
 
const char * ifconfig_options_string (const struct tuntap *tt, bool remote, bool disable, struct gc_arena *gc)
 
const char * tun_stat (const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc)
 
bool is_tun_p2p (const struct tuntap *tt)
 
void do_ifconfig_setenv (const struct tuntap *tt, struct env_set *es)
 
struct tuntapinit_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)
 
void init_tun_post (struct tuntap *tt, const struct frame *frame, const struct tuntap_options *options)
 
static void add_route_connected_v6_net (struct tuntap *tt, const struct env_set *es)
 
void delete_route_connected_v6_net (struct tuntap *tt, const struct env_set *es)
 
static void do_ifconfig_ipv6 (struct tuntap *tt, const char *ifname, int tun_mtu, const struct env_set *es, openvpn_net_ctx_t *ctx)
 do_ifconfig_ipv6 - perform platform specific ifconfig6 commands More...
 
static void do_ifconfig_ipv4 (struct tuntap *tt, const char *ifname, int tun_mtu, const struct env_set *es, openvpn_net_ctx_t *ctx)
 do_ifconfig_ipv4 - perform platform specific ifconfig commands More...
 
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 More...
 
static void open_null (struct tuntap *tt)
 
static const char * print_windows_driver (enum windows_driver_type windows_driver)
 
int tun_read_queue (struct tuntap *tt, int maxsize)
 
int tun_write_queue (struct tuntap *tt, struct buffer *buf)
 
int tun_finalize (HANDLE h, struct overlapped_io *io, struct buffer *buf)
 
static const struct device_instance_id_interfaceget_device_instance_id_interface (struct gc_arena *gc)
 
static const struct tap_regget_tap_reg (struct gc_arena *gc)
 
static const struct panel_regget_panel_reg (struct gc_arena *gc)
 
void verify_255_255_255_252 (in_addr_t local, in_addr_t remote)
 
void show_valid_win32_tun_subnets (void)
 
void show_tap_win_adapters (int msglev, int warnlev)
 
static const struct tap_regget_adapter_by_guid (const char *guid, const struct tap_reg *tap_reg)
 
static const char * guid_to_name (const char *guid, const struct panel_reg *panel_reg)
 
static const struct tap_regget_adapter_by_name (const char *name, const struct tap_reg *tap_reg, const struct panel_reg *panel_reg)
 
static void at_least_one_tap_win (const struct tap_reg *tap_reg)
 
static const char * get_unspecified_device_guid (const int device_number, char *actual_name, int actual_name_size, const struct tap_reg *tap_reg_src, const struct panel_reg *panel_reg_src, enum windows_driver_type *windows_driver, struct gc_arena *gc)
 
static const char * get_device_guid (const char *name, char *actual_name, int actual_name_size, enum windows_driver_type *windows_driver, const struct tap_reg *tap_reg, const struct panel_reg *panel_reg, struct gc_arena *gc)
 
const IP_ADAPTER_INFO * get_adapter_info_list (struct gc_arena *gc)
 
const IP_PER_ADAPTER_INFO * get_per_adapter_info (const DWORD index, struct gc_arena *gc)
 
static const IP_INTERFACE_INFO * get_interface_info_list (struct gc_arena *gc)
 
static const IP_ADAPTER_INDEX_MAP * get_interface_info (DWORD index, struct gc_arena *gc)
 
const IP_ADAPTER_INFO * get_adapter (const IP_ADAPTER_INFO *ai, DWORD index)
 
const IP_ADAPTER_INFO * get_adapter_info (DWORD index, struct gc_arena *gc)
 
static int get_adapter_n_ip_netmask (const IP_ADAPTER_INFO *ai)
 
static bool get_adapter_ip_netmask (const IP_ADAPTER_INFO *ai, const int n, in_addr_t *ip, in_addr_t *netmask)
 
static bool test_adapter_ip_netmask (const IP_ADAPTER_INFO *ai, const in_addr_t ip, const in_addr_t netmask)
 
const IP_ADAPTER_INFO * get_tun_adapter (const struct tuntap *tt, const IP_ADAPTER_INFO *list)
 
bool is_adapter_up (const struct tuntap *tt, const IP_ADAPTER_INFO *list)
 
bool is_ip_in_adapter_subnet (const IP_ADAPTER_INFO *ai, const in_addr_t ip, in_addr_t *highest_netmask)
 
DWORD adapter_index_of_ip (const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count, in_addr_t *netmask)
 
static int dhcp_status (DWORD index)
 
static void delete_temp_addresses (DWORD index)
 
static DWORD get_adapter_index_method_1 (const char *guid)
 
static DWORD get_adapter_index_method_2 (const char *guid)
 
static DWORD get_adapter_index (const char *guid)
 
static const char * format_ip_addr_string (const IP_ADDR_STRING *ip, struct gc_arena *gc)
 
static void show_adapter (int msglev, const IP_ADAPTER_INFO *a, struct gc_arena *gc)
 
void show_adapters (int msglev)
 
static void tap_allow_nonadmin_access_handle (const char *device_path, HANDLE hand)
 
void tap_allow_nonadmin_access (const char *dev_node)
 
bool dhcp_release_by_adapter_index (const DWORD adapter_index)
 
static bool dhcp_release (const struct tuntap *tt)
 
bool dhcp_renew_by_adapter_index (const DWORD adapter_index)
 
static bool dhcp_renew (const struct tuntap *tt)
 
void ipconfig_register_dns (const struct env_set *es)
 
void ip_addr_string_to_array (in_addr_t *dest, int *dest_len, const IP_ADDR_STRING *src)
 
static bool ip_addr_one_to_one (const in_addr_t *a1, const int a1len, const IP_ADDR_STRING *ias)
 
static bool ip_addr_member_of (const in_addr_t addr, const IP_ADDR_STRING *ias)
 
static void netsh_ifconfig_options (const char *type, const in_addr_t *addr_list, const int addr_len, const IP_ADDR_STRING *current, const char *flex_name, const bool test_first)
 
static void init_ip_addr_string2 (IP_ADDR_STRING *dest, const IP_ADDR_STRING *src1, const IP_ADDR_STRING *src2)
 
static void netsh_enable_dhcp (const char *actual_name)
 
static bool service_enable_dhcp (const struct tuntap *tt)
 
void tun_standby_init (struct tuntap *tt)
 
bool tun_standby (struct tuntap *tt)
 
static void write_dhcp_u8 (struct buffer *buf, const int type, const int data, bool *error)
 
static void write_dhcp_u32_array (struct buffer *buf, const int type, const uint32_t *data, const unsigned int len, bool *error)
 
static void write_dhcp_str (struct buffer *buf, const int type, const char *str, bool *error)
 
static bool build_dhcp_options_string (struct buffer *buf, const struct tuntap_options *o)
 
static void fork_dhcp_action (struct tuntap *tt)
 
static void register_dns_service (const struct tuntap *tt)
 
static bool service_register_ring_buffers (const struct tuntap *tt)
 
void fork_register_dns_action (struct tuntap *tt)
 
static uint32_t dhcp_masq_addr (const in_addr_t local, const in_addr_t netmask, const int offset)
 
static void tuntap_get_version_info (const struct tuntap *tt)
 
static void tuntap_get_mtu (struct tuntap *tt)
 
static void tuntap_set_ip_addr (struct tuntap *tt, const char *device_guid, bool dhcp_masq_post)
 
static bool wintun_register_ring_buffer (struct tuntap *tt, const char *device_guid)
 
static void tuntap_set_connected (const struct tuntap *tt)
 
static void tuntap_set_ptp (const struct tuntap *tt)
 
static void tuntap_dhcp_mask (const struct tuntap *tt, const char *device_guid)
 
static bool tun_try_open_device (struct tuntap *tt, const char *device_guid, const struct device_instance_id_interface *device_instance_id_interface)
 
static void tun_open_device (struct tuntap *tt, const char *dev_node, const char **device_guid, struct gc_arena *gc)
 
static void tuntap_set_ip_props (const struct tuntap *tt, bool *dhcp_masq, bool *dhcp_masq_post)
 
static void tuntap_post_open (struct tuntap *tt, const char *device_guid)
 
void open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
 
const char * tap_win_getinfo (const struct tuntap *tt, struct gc_arena *gc)
 
void tun_show_debug (struct tuntap *tt)
 
static void netsh_delete_address_dns (const struct tuntap *tt, bool ipv6, struct gc_arena *gc)
 
void close_tun (struct tuntap *tt, openvpn_net_ctx_t *ctx)
 
int ascii2ipset (const char *name)
 
const char * ipset2ascii (int index)
 
const char * ipset2ascii_all (struct gc_arena *gc)
 

Variables

static const GUID GUID_DEVCLASS_NET = { 0x4d36e972L, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } }
 
static const GUID GUID_DEVINTERFACE_NET = { 0xcac88484, 0x7515, 0x4c03, { 0x82, 0xe6, 0x71, 0xa8, 0x7a, 0xba, 0xc3, 0x61 } }
 
static const char ifconfig_warn_how_to_silence [] = "(silence this warning with --ifconfig-nowarn)"
 
static const struct ipset_names ipset_names []
 

Macro Definition Documentation

◆ DHCP_STATUS_DISABLED

#define DHCP_STATUS_DISABLED   2

Definition at line 4585 of file tun.c.

Referenced by dhcp_status(), tuntap_set_ip_addr(), and tuntap_set_ip_props().

◆ DHCP_STATUS_ENABLED

#define DHCP_STATUS_ENABLED   1

Definition at line 4584 of file tun.c.

Referenced by dhcp_status(), and tuntap_set_ip_props().

◆ DHCP_STATUS_UNDEF

#define DHCP_STATUS_UNDEF   0

Definition at line 4583 of file tun.c.

Referenced by dhcp_status().

◆ NI_IP_NETMASK

#define NI_IP_NETMASK   (1<<1)

Definition at line 67 of file tun.c.

Referenced by do_ifconfig_ipv4(), netsh_ifconfig(), tun_standby(), and tuntap_set_ip_props().

◆ NI_OPTIONS

#define NI_OPTIONS   (1<<2)

Definition at line 68 of file tun.c.

Referenced by do_ifconfig_ipv4(), netsh_ifconfig(), tun_standby(), and tuntap_set_ip_props().

◆ NI_TEST_FIRST

#define NI_TEST_FIRST   (1<<0)

Definition at line 66 of file tun.c.

Referenced by netsh_ifconfig(), tun_standby(), and tuntap_set_ip_props().

Function Documentation

◆ adapter_index_of_ip()

DWORD adapter_index_of_ip ( const IP_ADAPTER_INFO *  list,
const in_addr_t  ip,
int *  count,
in_addr_t netmask 
)

◆ add_route_connected_v6_net()

static void add_route_connected_v6_net ( struct tuntap tt,
const struct env_set es 
)
static

◆ ascii2ipset()

int ascii2ipset ( const char *  name)

Definition at line 6640 of file tun.c.

References ASSERT, IPW32_SET_N, ipset_names::short_form, and SIZE.

Referenced by add_option().

◆ at_least_one_tap_win()

static void at_least_one_tap_win ( const struct tap_reg tap_reg)
static

Definition at line 4047 of file tun.c.

References M_FATAL, and msg.

Referenced by netsh_get_id(), tap_allow_nonadmin_access(), and tun_open_device().

◆ build_dhcp_options_string()

static bool build_dhcp_options_string ( struct buffer buf,
const struct tuntap_options o 
)
static

◆ check_addr_clash()

static void check_addr_clash ( const char *  name,
int  type,
in_addr_t  public,
in_addr_t  local,
in_addr_t  remote_netmask 
)
static

◆ check_subnet_conflict()

void check_subnet_conflict ( const in_addr_t  ip,
const in_addr_t  netmask,
const char *  prefix 
)

Definition at line 427 of file tun.c.

References gc_free(), gc_new(), get_default_gateway(), in_addr_t, M_WARN, msg, and print_in_addr_t().

Referenced by add_routes(), init_tun(), and tuntap_ring_empty().

◆ clear_tuntap()

static void clear_tuntap ( struct tuntap tuntap)
static

Definition at line 1453 of file tun.c.

References CLEAR, and tuntap::hand.

Referenced by close_tun(), do_dns_service(), init_tun(), and open_null().

◆ close_tun()

void close_tun ( struct tuntap tt,
openvpn_net_ctx_t ctx 
)

◆ delete_route_connected_v6_net()

void delete_route_connected_v6_net ( struct tuntap tt,
const struct env_set es 
)

◆ delete_temp_addresses()

static void delete_temp_addresses ( DWORD  index)
static

Definition at line 4617 of file tun.c.

References gc_free(), gc_new(), get_adapter_info(), M_INFO, msg, and status.

Referenced by tuntap_set_ip_addr().

◆ dev_type_enum()

int dev_type_enum ( const char *  dev,
const char *  dev_type 
)

◆ dev_type_string()

const char* dev_type_string ( const char *  dev,
const char *  dev_type 
)

Definition at line 273 of file tun.c.

References dev_type_enum(), DEV_TYPE_NULL, DEV_TYPE_TAP, and DEV_TYPE_TUN.

Referenced by do_open_tun(), open_null(), options_string(), and tuntap_ring_empty().

◆ dhcp_masq_addr()

static uint32_t dhcp_masq_addr ( const in_addr_t  local,
const in_addr_t  netmask,
const int  offset 
)
static

Definition at line 5736 of file tun.c.

References gc_free(), gc_new(), in_addr_t, M_FATAL, msg, and print_in_addr_t().

Referenced by tuntap_dhcp_mask().

◆ dhcp_release()

static bool dhcp_release ( const struct tuntap tt)
static

◆ dhcp_release_by_adapter_index()

bool dhcp_release_by_adapter_index ( const DWORD  adapter_index)

Definition at line 4954 of file tun.c.

References D_TUNTAP_INFO, gc_free(), gc_new(), get_interface_info(), M_WARN, msg, status, and strerror_win32().

Referenced by add_option(), and dhcp_release().

◆ dhcp_renew()

static bool dhcp_renew ( const struct tuntap tt)
static

◆ dhcp_renew_by_adapter_index()

bool dhcp_renew_by_adapter_index ( const DWORD  adapter_index)

Definition at line 4994 of file tun.c.

References D_TUNTAP_INFO, gc_free(), gc_new(), get_interface_info(), M_WARN, msg, status, and strerror_win32().

Referenced by add_option(), and dhcp_renew().

◆ dhcp_status()

static int dhcp_status ( DWORD  index)
static

◆ do_address_service()

static bool do_address_service ( const bool  add,
const short  family,
const struct tuntap tt 
)
static

◆ do_dns_service()

static bool do_dns_service ( bool  add,
const short  family,
const struct tuntap tt 
)
static

◆ do_ifconfig()

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

Parameters
ttthe tuntap interface context
ifnamethe human readable interface name
mtuthe MTU value to set the interface to
esthe environment to be used when executing the commands
ctxthe networking API opaque context

Definition at line 1419 of file tun.c.

References D_LOW, tuntap::did_ifconfig_ipv6_setup, tuntap::did_ifconfig_setup, do_ifconfig_ipv4(), do_ifconfig_ipv6(), tuntap::local, tuntap::local_ipv6, management_set_state(), msg, net_ctx_free(), and OPENVPN_STATE_ASSIGN_IP.

Referenced by do_open_tun(), and tuntap_ring_empty().

◆ do_ifconfig_ipv4()

static void do_ifconfig_ipv4 ( struct tuntap tt,
const char *  ifname,
int  tun_mtu,
const struct env_set es,
openvpn_net_ctx_t ctx 
)
static

◆ do_ifconfig_ipv6()

static void do_ifconfig_ipv6 ( struct tuntap tt,
const char *  ifname,
int  tun_mtu,
const struct env_set es,
openvpn_net_ctx_t ctx 
)
static

do_ifconfig_ipv6 - perform platform specific ifconfig6 commands

Parameters
ttthe tuntap interface context
ifnamethe human readable interface name
mtuthe MTU value to set the interface to
esthe environment to be used when executing the commands
ctxthe networking API opaque context

Definition at line 900 of file tun.c.

References tuntap::adapter_index, add_route_connected_v6_net(), argv_free(), argv_msg(), argv_new(), argv_printf(), DEV_TYPE_TUN, tuntap_options::dns6, tuntap_options::dns6_len, do_address_service(), do_dns_service(), env_set_add(), env_set_create(), env_set_destroy(), gc_free(), gc_new(), get_win_sys_path(), iface, IFCONFIG_PATH, tuntap_options::ip_win32_type, IPW32_SET_MANUAL, tuntap::local_ipv6, M_FATAL, M_INFO, msg, tuntap_options::msg_channel, tuntap::netbits_ipv6, netsh_command(), NETSH_PATH_SUFFIX, netsh_set_dns6_servers(), openvpn_execve_check(), openvpn_snprintf(), tuntap::options, print_in6_addr(), tuntap::remote_ipv6, S_FATAL, and tuntap::type.

Referenced by do_ifconfig().

◆ do_ifconfig_setenv()

void do_ifconfig_setenv ( const struct tuntap tt,
struct env_set es 
)

◆ fork_dhcp_action()

static void fork_dhcp_action ( struct tuntap tt)
static

◆ fork_register_dns_action()

void fork_register_dns_action ( struct tuntap tt)

◆ format_ip_addr_string()

static const char* format_ip_addr_string ( const IP_ADDR_STRING *  ip,
struct gc_arena gc 
)
static

Definition at line 4749 of file tun.c.

References alloc_buf_gc(), BSTR, and buf_printf().

Referenced by show_adapter().

◆ get_adapter()

const IP_ADAPTER_INFO* get_adapter ( const IP_ADAPTER_INFO *  ai,
DWORD  index 
)

◆ get_adapter_by_guid()

static const struct tap_reg* get_adapter_by_guid ( const char *  guid,
const struct tap_reg tap_reg 
)
static

Definition at line 3999 of file tun.c.

References tap_reg::guid, and tap_reg::next.

Referenced by get_adapter_by_name(), and get_device_guid().

◆ get_adapter_by_name()

static const struct tap_reg* get_adapter_by_name ( const char *  name,
const struct tap_reg tap_reg,
const struct panel_reg panel_reg 
)
static

◆ get_adapter_index()

static DWORD get_adapter_index ( const char *  guid)
static

◆ get_adapter_index_flexible()

static DWORD get_adapter_index_flexible ( const char *  name)
static

◆ get_adapter_index_method_1()

static DWORD get_adapter_index_method_1 ( const char *  guid)
static

Definition at line 4658 of file tun.c.

References openvpn_swprintf(), SIZE, and TUN_ADAPTER_INDEX_INVALID.

Referenced by get_adapter_index(), and get_adapter_index_flexible().

◆ get_adapter_index_method_2()

static DWORD get_adapter_index_method_2 ( const char *  guid)
static

◆ get_adapter_info()

const IP_ADAPTER_INFO* get_adapter_info ( DWORD  index,
struct gc_arena gc 
)

Definition at line 4328 of file tun.c.

References get_adapter(), and get_adapter_info_list().

Referenced by delete_temp_addresses(), dhcp_status(), and get_bypass_addresses().

◆ get_adapter_info_list()

const IP_ADAPTER_INFO* get_adapter_info_list ( struct gc_arena gc)

◆ get_adapter_ip_netmask()

static bool get_adapter_ip_netmask ( const IP_ADAPTER_INFO *  ai,
const int  n,
in_addr_t ip,
in_addr_t netmask 
)
static

Definition at line 4355 of file tun.c.

References getaddr(), and GETADDR_HOST_ORDER.

Referenced by is_adapter_up(), is_ip_in_adapter_subnet(), and test_adapter_ip_netmask().

◆ get_adapter_n_ip_netmask()

static int get_adapter_n_ip_netmask ( const IP_ADAPTER_INFO *  ai)
static

Definition at line 4334 of file tun.c.

Referenced by is_adapter_up(), and is_ip_in_adapter_subnet().

◆ get_device_guid()

static const char* get_device_guid ( const char *  name,
char *  actual_name,
int  actual_name_size,
enum windows_driver_type windows_driver,
const struct tap_reg tap_reg,
const struct panel_reg panel_reg,
struct gc_arena gc 
)
static

◆ get_device_instance_id_interface()

static const struct device_instance_id_interface* get_device_instance_id_interface ( struct gc_arena gc)
static

◆ get_interface_info()

static const IP_ADAPTER_INDEX_MAP* get_interface_info ( DWORD  index,
struct gc_arena gc 
)
static

Definition at line 4285 of file tun.c.

References get_interface_info_list().

Referenced by dhcp_release_by_adapter_index(), and dhcp_renew_by_adapter_index().

◆ get_interface_info_list()

static const IP_INTERFACE_INFO* get_interface_info_list ( struct gc_arena gc)
static

Definition at line 4255 of file tun.c.

References gc_malloc(), M_INFO, msg, status, and strerror_win32().

Referenced by get_interface_info().

◆ get_panel_reg()

static const struct panel_reg* get_panel_reg ( struct gc_arena gc)
static

◆ get_per_adapter_info()

const IP_PER_ADAPTER_INFO* get_per_adapter_info ( const DWORD  index,
struct gc_arena gc 
)

◆ get_tap_reg()

static const struct tap_reg* get_tap_reg ( struct gc_arena gc)
static

◆ get_tun_adapter()

const IP_ADAPTER_INFO* get_tun_adapter ( const struct tuntap tt,
const IP_ADAPTER_INFO *  list 
)

Definition at line 4413 of file tun.c.

References tuntap::adapter_index, and get_adapter().

Referenced by is_adapter_up(), and windows_route_find_if_index().

◆ get_unspecified_device_guid()

static const char* get_unspecified_device_guid ( const int  device_number,
char *  actual_name,
int  actual_name_size,
const struct tap_reg tap_reg_src,
const struct panel_reg panel_reg_src,
enum windows_driver_type windows_driver,
struct gc_arena gc 
)
static

◆ guess_tuntap_dev()

const char* guess_tuntap_dev ( const char *  dev,
const char *  dev_type,
const char *  dev_node,
struct gc_arena gc 
)

Definition at line 296 of file tun.c.

References dev_type_enum(), DEV_TYPE_TAP, DEV_TYPE_TUN, and netsh_get_id().

Referenced by do_open_tun(), and tuntap_ring_empty().

◆ guid_to_name()

static const char* guid_to_name ( const char *  guid,
const struct panel_reg panel_reg 
)
static

Definition at line 4015 of file tun.c.

References panel_reg::guid, panel_reg::name, and panel_reg::next.

Referenced by get_device_guid(), and get_unspecified_device_guid().

◆ ifconfig_options_string()

const char* ifconfig_options_string ( const struct tuntap tt,
bool  remote,
bool  disable,
struct gc_arena gc 
)

◆ ifconfig_sanity_check()

static void ifconfig_sanity_check ( bool  tun,
in_addr_t  addr,
int  topology 
)
static

Definition at line 325 of file tun.c.

References gc_free(), gc_new(), ifconfig_warn_how_to_silence, M_WARN, msg, print_in_addr_t(), TOP_NET30, and TOP_P2P.

Referenced by init_tun().

◆ init_ip_addr_string2()

static void init_ip_addr_string2 ( IP_ADDR_STRING *  dest,
const IP_ADDR_STRING *  src1,
const IP_ADDR_STRING *  src2 
)
static

Definition at line 5289 of file tun.c.

References CLEAR.

Referenced by netsh_ifconfig().

◆ init_tun()

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 
)

◆ init_tun_post()

void init_tun_post ( struct tuntap tt,
const struct frame frame,
const struct tuntap_options options 
)

◆ ip_addr_member_of()

static bool ip_addr_member_of ( const in_addr_t  addr,
const IP_ADDR_STRING *  ias 
)
static

Definition at line 5153 of file tun.c.

References in_addr_t, ip_addr_string_to_array(), and SIZE.

Referenced by netsh_ifconfig_options().

◆ ip_addr_one_to_one()

static bool ip_addr_one_to_one ( const in_addr_t a1,
const int  a1len,
const IP_ADDR_STRING *  ias 
)
static

Definition at line 5129 of file tun.c.

References in_addr_t, ip_addr_string_to_array(), and SIZE.

Referenced by netsh_ifconfig_options().

◆ ip_addr_string_to_array()

void ip_addr_string_to_array ( in_addr_t dest,
int *  dest_len,
const IP_ADDR_STRING *  src 
)

◆ ipconfig_register_dns()

void ipconfig_register_dns ( const struct env_set es)

◆ ipset2ascii()

const char* ipset2ascii ( int  index)

Definition at line 6655 of file tun.c.

References ASSERT, IPW32_SET_N, ipset_names::short_form, and SIZE.

Referenced by ipset2ascii_all().

◆ ipset2ascii_all()

const char* ipset2ascii_all ( struct gc_arena gc)

◆ is_adapter_up()

bool is_adapter_up ( const struct tuntap tt,
const IP_ADAPTER_INFO *  list 
)

◆ is_dev_type()

bool is_dev_type ( const char *  dev,
const char *  dev_type,
const char *  match_type 
)

Definition at line 234 of file tun.c.

References ASSERT.

Referenced by dev_type_enum(), and tuntap_ring_empty().

◆ is_ip_in_adapter_subnet()

bool is_ip_in_adapter_subnet ( const IP_ADAPTER_INFO *  ai,
const in_addr_t  ip,
in_addr_t highest_netmask 
)

◆ is_tun_p2p()

bool is_tun_p2p ( const struct tuntap tt)

◆ netsh_command()

static void netsh_command ( const struct argv a,
int  n,
int  msglevel 
)
static

◆ netsh_delete_address_dns()

static void netsh_delete_address_dns ( const struct tuntap tt,
bool  ipv6,
struct gc_arena gc 
)
static

◆ netsh_enable_dhcp()

static void netsh_enable_dhcp ( const char *  actual_name)
static

◆ netsh_get_id()

static const char * netsh_get_id ( const char *  dev_node,
struct gc_arena gc 
)
static

◆ netsh_ifconfig()

static void netsh_ifconfig ( const struct tuntap_options to,
const char *  flex_name,
const in_addr_t  ip,
const in_addr_t  netmask,
const unsigned int  flags 
)
static

◆ netsh_ifconfig_options()

static void netsh_ifconfig_options ( const char *  type,
const in_addr_t addr_list,
const int  addr_len,
const IP_ADDR_STRING *  current,
const char *  flex_name,
const bool  test_first 
)
static

◆ netsh_set_dns6_servers()

static void netsh_set_dns6_servers ( const struct in6_addr *  addr_list,
const int  addr_len,
const char *  flex_name 
)
static

Set the ipv6 dns servers on the specified interface.

The list of dns servers currently set on the interface are cleared first. No action is taken if number of addresses (addr_len) < 1.

Definition at line 5177 of file tun.c.

References argv_free(), argv_new(), argv_printf(), argv_printf_cat(), gc_free(), gc_new(), get_win_sys_path(), M_FATAL, M_NONFATAL, netsh_command(), NETSH_PATH_SUFFIX, print_in6_addr(), win32_version_info(), and WIN_7.

Referenced by do_ifconfig_ipv6().

◆ open_null()

static void open_null ( struct tuntap tt)
static

◆ open_tun()

void open_tun ( const char *  dev,
const char *  dev_type,
const char *  dev_node,
struct tuntap tt 
)

◆ print_windows_driver()

static const char* print_windows_driver ( enum windows_driver_type  windows_driver)
static

◆ register_dns_service()

static void register_dns_service ( const struct tuntap tt)
static

◆ service_enable_dhcp()

static bool service_enable_dhcp ( const struct tuntap tt)
static

◆ service_register_ring_buffers()

static bool service_register_ring_buffers ( const struct tuntap tt)
static

◆ show_adapter()

static void show_adapter ( int  msglev,
const IP_ADAPTER_INFO *  a,
struct gc_arena gc 
)
static

Definition at line 4770 of file tun.c.

References format_hex_ex(), format_ip_addr_string(), get_per_adapter_info(), msg, and time_string().

Referenced by show_adapters().

◆ show_adapters()

void show_adapters ( int  msglev)

◆ show_tap_win_adapters()

void show_tap_win_adapters ( int  msglev,
int  warnlev 
)

◆ show_valid_win32_tun_subnets()

void show_valid_win32_tun_subnets ( void  )

Definition at line 3884 of file tun.c.

Referenced by add_option().

◆ tap_allow_nonadmin_access()

void tap_allow_nonadmin_access ( const char *  dev_node)

◆ tap_allow_nonadmin_access_handle()

static void tap_allow_nonadmin_access_handle ( const char *  device_path,
HANDLE  hand 
)
static

◆ tap_win_getinfo()

const char* tap_win_getinfo ( const struct tuntap tt,
struct gc_arena gc 
)

◆ test_adapter_ip_netmask()

static bool test_adapter_ip_netmask ( const IP_ADAPTER_INFO *  ai,
const in_addr_t  ip,
const in_addr_t  netmask 
)
static

Definition at line 4397 of file tun.c.

References get_adapter_ip_netmask(), in_addr_t, and status.

Referenced by netsh_ifconfig().

◆ tun_finalize()

int tun_finalize ( HANDLE  h,
struct overlapped_io io,
struct buffer buf 
)

◆ tun_open_device()

static void tun_open_device ( struct tuntap tt,
const char *  dev_node,
const char **  device_guid,
struct gc_arena gc 
)
static

◆ tun_read_queue()

int tun_read_queue ( struct tuntap tt,
int  maxsize 
)

◆ tun_show_debug()

void tun_show_debug ( struct tuntap tt)

◆ tun_standby()

bool tun_standby ( struct tuntap tt)

◆ tun_standby_init()

void tun_standby_init ( struct tuntap tt)

Definition at line 5480 of file tun.c.

References tuntap::standby_iter.

Referenced by do_up(), and write_tun_buffered().

◆ tun_stat()

const char* tun_stat ( const struct tuntap tt,
unsigned int  rwflags,
struct gc_arena gc 
)

◆ tun_try_open_device()

static bool tun_try_open_device ( struct tuntap tt,
const char *  device_guid,
const struct device_instance_id_interface device_instance_id_interface 
)
static

◆ tun_write_queue()

int tun_write_queue ( struct tuntap tt,
struct buffer buf 
)

◆ tuntap_dhcp_mask()

static void tuntap_dhcp_mask ( const struct tuntap tt,
const char *  device_guid 
)
static

◆ tuntap_get_mtu()

static void tuntap_get_mtu ( struct tuntap tt)
static

Definition at line 5806 of file tun.c.

References D_MTU_INFO, tuntap::hand, msg, and tuntap::post_open_mtu.

Referenced by tuntap_post_open().

◆ tuntap_get_version_info()

static void tuntap_get_version_info ( const struct tuntap tt)
static

◆ tuntap_post_open()

static void tuntap_post_open ( struct tuntap tt,
const char *  device_guid 
)
static

◆ tuntap_set_connected()

static void tuntap_set_connected ( const struct tuntap tt)
static

◆ tuntap_set_ip_addr()

static void tuntap_set_ip_addr ( struct tuntap tt,
const char *  device_guid,
bool  dhcp_masq_post 
)
static

◆ tuntap_set_ip_props()

static void tuntap_set_ip_props ( const struct tuntap tt,
bool dhcp_masq,
bool dhcp_masq_post 
)
static

◆ tuntap_set_ptp()

static void tuntap_set_ptp ( const struct tuntap tt)
static

◆ verify_255_255_255_252()

void verify_255_255_255_252 ( in_addr_t  local,
in_addr_t  remote 
)

Definition at line 3847 of file tun.c.

References gc_free(), gc_new(), M_FATAL, msg, PACKAGE, and print_in_addr_t().

Referenced by init_tun().

◆ warn_on_use_of_common_subnets()

void warn_on_use_of_common_subnets ( openvpn_net_ctx_t ctx)

◆ wintun_register_ring_buffer()

static bool wintun_register_ring_buffer ( struct tuntap tt,
const char *  device_guid 
)
static

◆ write_dhcp_str()

static void write_dhcp_str ( struct buffer buf,
const int  type,
const char *  str,
bool error 
)
static

Definition at line 5558 of file tun.c.

References buf_safe(), buf_write(), buf_write_u8(), buffer::len, M_WARN, and msg.

Referenced by build_dhcp_options_string().

◆ write_dhcp_u32_array()

static void write_dhcp_u32_array ( struct buffer buf,
const int  type,
const uint32_t data,
const unsigned int  len,
bool error 
)
static

Definition at line 5529 of file tun.c.

References buf_safe(), buf_write_u32(), buf_write_u8(), buffer::len, M_WARN, and msg.

Referenced by build_dhcp_options_string().

◆ write_dhcp_u8()

static void write_dhcp_u8 ( struct buffer buf,
const int  type,
const int  data,
bool error 
)
static

Definition at line 5515 of file tun.c.

References buf_safe(), buf_write_u8(), M_WARN, and msg.

Referenced by build_dhcp_options_string().

Variable Documentation

◆ GUID_DEVCLASS_NET

const GUID GUID_DEVCLASS_NET = { 0x4d36e972L, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } }
static

Definition at line 61 of file tun.c.

Referenced by get_device_instance_id_interface().

◆ GUID_DEVINTERFACE_NET

const GUID GUID_DEVINTERFACE_NET = { 0xcac88484, 0x7515, 0x4c03, { 0x82, 0xe6, 0x71, 0xa8, 0x7a, 0xba, 0xc3, 0x61 } }
static

Definition at line 62 of file tun.c.

Referenced by get_device_instance_id_interface().

◆ ifconfig_warn_how_to_silence

const char ifconfig_warn_how_to_silence[] = "(silence this warning with --ifconfig-nowarn)"
static

Definition at line 315 of file tun.c.

Referenced by check_addr_clash(), and ifconfig_sanity_check().

◆ ipset_names

const struct ipset_names ipset_names[]
static
Initial value:
= {
{"manual"},
{"netsh"},
{"ipapi"},
{"dynamic"},
{"adaptive"}
}

Definition at line 6631 of file tun.c.