OpenVPN
Data Structures | Macros | Functions
tun.h File Reference
#include <winioctl.h>
#include <tap-windows.h>
#include "buffer.h"
#include "error.h"
#include "mtu.h"
#include "win32.h"
#include "event.h"
#include "proto.h"
#include "misc.h"
Include dependency graph for tun.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tuntap_options
 
struct  tuntap
 
struct  tap_reg
 
struct  panel_reg
 

Macros

#define TUN_ADAPTER_INDEX_INVALID   ((DWORD)-1)
 
#define IPW32_SET_ADAPTIVE_DELAY_WINDOW   300
 
#define IPW32_SET_ADAPTIVE_TRY_NETSH   20
 
#define IPW32_SET_MANUAL   0 /* "--ip-win32 manual" */
 
#define IPW32_SET_NETSH   1 /* "--ip-win32 netsh" */
 
#define IPW32_SET_IPAPI   2 /* "--ip-win32 ipapi" */
 
#define IPW32_SET_DHCP_MASQ   3 /* "--ip-win32 dynamic" */
 
#define IPW32_SET_ADAPTIVE   4 /* "--ip-win32 adaptive" */
 
#define IPW32_SET_N   5
 
#define N_DHCP_ADDR
 
#define TUNNEL_TYPE(tt)   ((tt) ? ((tt)->type) : DEV_TYPE_UNDEF)
 
#define TUNNEL_TOPOLOGY(tt)   ((tt) ? ((tt)->topology) : TOP_UNDEF)
 
#define IFCONFIG_BEFORE_TUN_OPEN   0
 
#define IFCONFIG_AFTER_TUN_OPEN   1
 
#define IFCONFIG_DEFAULT   IFCONFIG_AFTER_TUN_OPEN
 
#define ROUTE_BEFORE_TUN   0
 
#define ROUTE_AFTER_TUN   1
 
#define ROUTE_ORDER_DEFAULT   ROUTE_AFTER_TUN
 
#define TUN_PASS_BUFFER
 

Functions

static bool tuntap_defined (const struct tuntap *tt)
 
void open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
 
void close_tun (struct tuntap *tt)
 
int write_tun (struct tuntap *tt, uint8_t *buf, int len)
 
int read_tun (struct tuntap *tt, uint8_t *buf, int len)
 
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)
 
const char * guess_tuntap_dev (const char *dev, const char *dev_type, const char *dev_node, struct gc_arena *gc)
 
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)
 
void init_tun_post (struct tuntap *tt, const struct frame *frame, const struct tuntap_options *options)
 
void do_ifconfig_setenv (const struct tuntap *tt, struct env_set *es)
 
void do_ifconfig (struct tuntap *tt, const char *ifname, int tun_mtu, const struct env_set *es)
 do_ifconfig - configure the tunnel interface More...
 
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 * ifconfig_options_string (const struct tuntap *tt, bool remote, bool disable, struct gc_arena *gc)
 
bool is_tun_p2p (const struct tuntap *tt)
 
void check_subnet_conflict (const in_addr_t ip, const in_addr_t netmask, const char *prefix)
 
void warn_on_use_of_common_subnets (void)
 
static void tun_adjust_frame_parameters (struct frame *frame, int size)
 
static int ifconfig_order (void)
 
static int route_order (void)
 
int ascii2ipset (const char *name)
 
const char * ipset2ascii (int index)
 
const char * ipset2ascii_all (struct gc_arena *gc)
 
void verify_255_255_255_252 (in_addr_t local, in_addr_t remote)
 
const IP_ADAPTER_INFO * get_adapter_info_list (struct gc_arena *gc)
 
const IP_ADAPTER_INFO * get_tun_adapter (const struct tuntap *tt, const IP_ADAPTER_INFO *list)
 
const IP_ADAPTER_INFO * get_adapter_info (DWORD index, struct gc_arena *gc)
 
const IP_PER_ADAPTER_INFO * get_per_adapter_info (const DWORD index, struct gc_arena *gc)
 
const IP_ADAPTER_INFO * get_adapter (const IP_ADAPTER_INFO *ai, DWORD index)
 
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)
 
void show_tap_win_adapters (int msglev, int warnlev)
 
void show_adapters (int msglev)
 
void tap_allow_nonadmin_access (const char *dev_node)
 
void show_valid_win32_tun_subnets (void)
 
const char * tap_win_getinfo (const struct tuntap *tt, struct gc_arena *gc)
 
void tun_show_debug (struct tuntap *tt)
 
bool dhcp_release_by_adapter_index (const DWORD adapter_index)
 
bool dhcp_renew_by_adapter_index (const DWORD adapter_index)
 
void fork_register_dns_action (struct tuntap *tt)
 
void ipconfig_register_dns (const struct env_set *es)
 
void tun_standby_init (struct tuntap *tt)
 
bool tun_standby (struct tuntap *tt)
 
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 bool tuntap_stop (int status)
 
static bool tuntap_abort (int status)
 
static int tun_write_win32 (struct tuntap *tt, struct buffer *buf)
 
static int read_tun_buffered (struct tuntap *tt, struct buffer *buf, int maxsize)
 
static int write_tun_buffered (struct tuntap *tt, struct buffer *buf)
 
static event_t tun_event_handle (const struct tuntap *tt)
 
static unsigned int tun_set (struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
 
const char * tun_stat (const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc)
 

Macro Definition Documentation

◆ IFCONFIG_AFTER_TUN_OPEN

#define IFCONFIG_AFTER_TUN_OPEN   1

Definition at line 292 of file tun.h.

Referenced by do_open_tun(), and ifconfig_order().

◆ IFCONFIG_BEFORE_TUN_OPEN

#define IFCONFIG_BEFORE_TUN_OPEN   0

Definition at line 291 of file tun.h.

Referenced by do_open_tun(), and ifconfig_order().

◆ IFCONFIG_DEFAULT

#define IFCONFIG_DEFAULT   IFCONFIG_AFTER_TUN_OPEN

Definition at line 294 of file tun.h.

Referenced by ifconfig_order().

◆ IPW32_SET_ADAPTIVE

#define IPW32_SET_ADAPTIVE   4 /* "--ip-win32 adaptive" */

Definition at line 56 of file tun.h.

Referenced by add_option(), init_options(), open_tun(), options_postprocess_verify_ce(), and tun_standby().

◆ IPW32_SET_ADAPTIVE_DELAY_WINDOW

#define IPW32_SET_ADAPTIVE_DELAY_WINDOW   300

Definition at line 45 of file tun.h.

Referenced by add_option().

◆ IPW32_SET_ADAPTIVE_TRY_NETSH

#define IPW32_SET_ADAPTIVE_TRY_NETSH   20

Definition at line 46 of file tun.h.

Referenced by tun_standby().

◆ IPW32_SET_DHCP_MASQ

#define IPW32_SET_DHCP_MASQ   3 /* "--ip-win32 dynamic" */

◆ IPW32_SET_IPAPI

#define IPW32_SET_IPAPI   2 /* "--ip-win32 ipapi" */

Definition at line 54 of file tun.h.

Referenced by open_tun().

◆ IPW32_SET_MANUAL

#define IPW32_SET_MANUAL   0 /* "--ip-win32 manual" */

Definition at line 52 of file tun.h.

Referenced by do_ifconfig_ipv4(), do_ifconfig_ipv6(), and options_postprocess_mutate_invariant().

◆ IPW32_SET_N

#define IPW32_SET_N   5

Definition at line 57 of file tun.h.

Referenced by ascii2ipset(), ipset2ascii(), and ipset2ascii_all().

◆ IPW32_SET_NETSH

#define IPW32_SET_NETSH   1 /* "--ip-win32 netsh" */

Definition at line 53 of file tun.h.

Referenced by do_ifconfig_ipv4().

◆ N_DHCP_ADDR

#define N_DHCP_ADDR
Value:
4 /* Max # of addresses allowed for
* DNS, WINS, etc. */

Definition at line 82 of file tun.h.

Referenced by dhcp_option_address_parse(), and dhcp_option_dns6_parse().

◆ ROUTE_AFTER_TUN

#define ROUTE_AFTER_TUN   1

Definition at line 319 of file tun.h.

Referenced by do_open_tun(), and do_up().

◆ ROUTE_BEFORE_TUN

#define ROUTE_BEFORE_TUN   0

Definition at line 318 of file tun.h.

Referenced by do_open_tun(), and route_order().

◆ ROUTE_ORDER_DEFAULT

#define ROUTE_ORDER_DEFAULT   ROUTE_AFTER_TUN

Definition at line 320 of file tun.h.

Referenced by route_order().

◆ TUN_ADAPTER_INDEX_INVALID

#define TUN_ADAPTER_INDEX_INVALID   ((DWORD)-1)

◆ TUN_PASS_BUFFER

#define TUN_PASS_BUFFER

Definition at line 335 of file tun.h.

◆ TUNNEL_TOPOLOGY

#define TUNNEL_TOPOLOGY (   tt)    ((tt) ? ((tt)->topology) : TOP_UNDEF)

Definition at line 136 of file tun.h.

Referenced by multi_select_virtual_addr(), and multi_set_virtual_addr_env().

◆ TUNNEL_TYPE

#define TUNNEL_TYPE (   tt)    ((tt) ? ((tt)->type) : DEV_TYPE_UNDEF)

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 
)

◆ ascii2ipset()

int ascii2ipset ( const char *  name)

Definition at line 6192 of file tun.c.

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

Referenced by add_option().

◆ check_subnet_conflict()

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

Definition at line 424 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_defined().

◆ close_tun()

void close_tun ( struct tuntap tt)

◆ 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 260 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_defined().

◆ dhcp_release_by_adapter_index()

bool dhcp_release_by_adapter_index ( const DWORD  adapter_index)

Definition at line 4763 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_by_adapter_index()

bool dhcp_renew_by_adapter_index ( const DWORD  adapter_index)

Definition at line 4803 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().

◆ do_ifconfig()

void do_ifconfig ( struct tuntap tt,
const char *  ifname,
int  tun_mtu,
const struct env_set es 
)

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

Definition at line 1409 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, and OPENVPN_STATE_ASSIGN_IP.

Referenced by do_open_tun(), and tuntap_defined().

◆ do_ifconfig_setenv()

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

◆ fork_register_dns_action()

void fork_register_dns_action ( struct tuntap tt)

◆ get_adapter()

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

◆ get_adapter_info()

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

Definition at line 4141 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_per_adapter_info()

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

◆ get_tun_adapter()

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

Definition at line 4226 of file tun.c.

References tuntap::adapter_index, and get_adapter().

Referenced by is_adapter_up(), and windows_route_find_if_index().

◆ 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 283 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_defined().

◆ ifconfig_options_string()

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

◆ ifconfig_order()

static int ifconfig_order ( void  )
inlinestatic

Definition at line 297 of file tun.h.

References IFCONFIG_AFTER_TUN_OPEN, IFCONFIG_BEFORE_TUN_OPEN, and IFCONFIG_DEFAULT.

Referenced by do_open_tun().

◆ 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 
)

◆ init_tun_post()

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

◆ ipconfig_register_dns()

void ipconfig_register_dns ( const struct env_set es)

◆ ipset2ascii()

const char* ipset2ascii ( int  index)

Definition at line 6207 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 221 of file tun.c.

References ASSERT.

Referenced by dev_type_enum(), and tuntap_defined().

◆ 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)

◆ open_tun()

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

Definition at line 5528 of file tun.c.

References tuntap::actual_name, tuntap::adapter_index, tuntap::adapter_netmask, alloc_buf(), ASSERT, at_least_one_tap_win(), BLEN, BPTR, build_dhcp_options_string(), CLEAR, D_DHCP_OPT, D_MTU_INFO, D_TUNTAP_INFO, delete_temp_addresses(), DEV_TYPE_NULL, DEV_TYPE_TAP, DEV_TYPE_TUN, tuntap_options::dhcp_lease_time, dhcp_masq_addr(), tuntap_options::dhcp_masq_custom_offset, tuntap_options::dhcp_masq_offset, tuntap_options::dhcp_options, tuntap_options::dhcp_pre_release, dhcp_release(), tuntap_options::dhcp_renew, dhcp_renew(), dhcp_status(), DHCP_STATUS_DISABLED, DHCP_STATUS_ENABLED, tuntap::did_ifconfig_ipv6_setup, tuntap::did_ifconfig_setup, ack_message_t::error_number, fork_dhcp_action(), format_hex(), free_buf(), gc_free(), gc_new(), get_adapter_index(), get_device_guid(), get_panel_reg(), get_tap_reg(), get_unspecified_device_guid(), tuntap::hand, IA_NET_ORDER, in_addr_t, tuntap_options::ip_win32_type, tuntap::ipapi_context, tuntap::ipapi_context_defined, tuntap::ipapi_instance, IPW32_SET_ADAPTIVE, IPW32_SET_DHCP_MASQ, IPW32_SET_IPAPI, tuntap::local, M_ERR, M_FATAL, M_INFO, M_NOPREFIX, M_WARN, management_sleep(), msg, tuntap_options::msg_channel, msg_flush_neighbors, netsh_enable_dhcp(), netsh_ifconfig(), NI_IP_NETMASK, NI_OPTIONS, NI_TEST_FIRST, open_null(), openvpn_snprintf(), tuntap::options, PACKAGE_NAME, tuntap::post_open_mtu, print_in_addr_t(), tuntap::remote_netmask, send_msg_iservice(), service_enable_dhcp(), status, strerror_win32(), string_alloc(), tuntap_options::tap_sleep, TAP_WIN_MIN_MAJOR, TAP_WIN_MIN_MINOR, TOP_SUBNET, tuntap::topology, TUN_ADAPTER_INDEX_INVALID, and tuntap::type.

Referenced by do_open_tun(), ipset2ascii_all(), open_null(), and tuntap_defined().

◆ read_tun()

int read_tun ( struct tuntap tt,
uint8_t buf,
int  len 
)

◆ read_tun_buffered()

static int read_tun_buffered ( struct tuntap tt,
struct buffer buf,
int  maxsize 
)
inlinestatic

Definition at line 460 of file tun.h.

References tuntap::hand, tuntap::reads, and tun_finalize().

Referenced by read_incoming_tun().

◆ route_order()

static int route_order ( void  )
inlinestatic

Definition at line 323 of file tun.h.

References ROUTE_BEFORE_TUN, and ROUTE_ORDER_DEFAULT.

Referenced by do_open_tun(), and do_up().

◆ 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 3713 of file tun.c.

Referenced by add_option().

◆ tap_allow_nonadmin_access()

void tap_allow_nonadmin_access ( const char *  dev_node)

◆ tap_win_getinfo()

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

Definition at line 6036 of file tun.c.

References alloc_buf_gc(), BCAP, BSTR, tuntap::hand, and buffer::len.

Referenced by print_status(), and x_check_status().

◆ tun_adjust_frame_parameters()

static void tun_adjust_frame_parameters ( struct frame frame,
int  size 
)
inlinestatic

Definition at line 281 of file tun.h.

References frame_add_to_extra_tun().

Referenced by do_init_frame().

◆ tun_event_handle()

static event_t tun_event_handle ( const struct tuntap tt)
inlinestatic

Definition at line 503 of file tun.h.

References tuntap::rw_handle.

Referenced by tun_set().

◆ tun_finalize()

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

◆ tun_read_queue()

int tun_read_queue ( struct tuntap tt,
int  maxsize 
)

◆ tun_set()

static unsigned int tun_set ( struct tuntap tt,
struct event_set es,
unsigned int  rwflags,
void *  arg,
unsigned int *  persistent 
)
inlinestatic

◆ tun_show_debug()

void tun_show_debug ( struct tuntap tt)

Definition at line 6054 of file tun.c.

References alloc_buf(), BCAP, BSTR, D_TAP_WIN_DEBUG, free_buf(), tuntap::hand, buffer::len, and msg.

Referenced by pre_select().

◆ tun_standby()

bool tun_standby ( struct tuntap tt)

◆ tun_standby_init()

void tun_standby_init ( struct tuntap tt)

Definition at line 5283 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_write_queue()

int tun_write_queue ( struct tuntap tt,
struct buffer buf 
)

◆ tun_write_win32()

static int tun_write_win32 ( struct tuntap tt,
struct buffer buf 
)
inlinestatic

◆ tuncfg()

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 
)

◆ tuntap_abort()

static bool tuntap_abort ( int  status)
inlinestatic

Definition at line 422 of file tun.h.

References openvpn_errno.

Referenced by read_incoming_tun(), and write_tun_buffered().

◆ tuntap_defined()

static bool tuntap_defined ( const struct tuntap tt)
inlinestatic

◆ tuntap_stop()

static bool tuntap_stop ( int  status)
inlinestatic

Definition at line 408 of file tun.h.

References openvpn_errno.

Referenced by read_incoming_tun(), and write_tun_buffered().

◆ verify_255_255_255_252()

void verify_255_255_255_252 ( in_addr_t  local,
in_addr_t  remote 
)

Definition at line 3676 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 ( void  )

◆ write_tun()

int write_tun ( struct tuntap tt,
uint8_t buf,
int  len 
)

◆ write_tun_buffered()

static int write_tun_buffered ( struct tuntap tt,
struct buffer buf 
)
inlinestatic

Definition at line 466 of file tun.h.

References status, tun_standby(), tun_standby_init(), tun_write_win32(), tuntap_abort(), and tuntap_stop().

Referenced by process_outgoing_tun().