OpenVPN
tun.h
Go to the documentation of this file.
1 /*
2  * OpenVPN -- An application to securely tunnel IP networks
3  * over a single TCP/UDP port, with support for SSL/TLS-based
4  * session authentication and key exchange,
5  * packet encryption, packet authentication, and
6  * packet compression.
7  *
8  * Copyright (C) 2002-2021 OpenVPN Inc <sales@openvpn.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef TUN_H
25 #define TUN_H
26 
27 #ifdef _WIN32
28 #include <winioctl.h>
29 #include <tap-windows.h>
30 #include <setupapi.h>
31 #include <cfgmgr32.h>
32 #endif
33 
34 #include "buffer.h"
35 #include "error.h"
36 #include "mtu.h"
37 #include "win32.h"
38 #include "event.h"
39 #include "proto.h"
40 #include "misc.h"
41 #include "networking.h"
42 #include "ring_buffer.h"
43 
44 #ifdef _WIN32
45 #define WINTUN_COMPONENT_ID "wintun"
46 
51 };
52 #endif
53 
54 #if defined(_WIN32) || defined(TARGET_ANDROID)
55 
56 #define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
57 
58 /* time constants for --ip-win32 adaptive */
59 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
60 #define IPW32_SET_ADAPTIVE_TRY_NETSH 20
61 
63  /* --ip-win32 options */
65 
66 #define IPW32_SET_MANUAL 0 /* "--ip-win32 manual" */
67 #define IPW32_SET_NETSH 1 /* "--ip-win32 netsh" */
68 #define IPW32_SET_IPAPI 2 /* "--ip-win32 ipapi" */
69 #define IPW32_SET_DHCP_MASQ 3 /* "--ip-win32 dynamic" */
70 #define IPW32_SET_ADAPTIVE 4 /* "--ip-win32 adaptive" */
71 #define IPW32_SET_N 5
73 
74 #ifdef _WIN32
75  HANDLE msg_channel;
76 #endif
77 
78  /* --ip-win32 dynamic options */
82 
83  /* --tap-sleep option */
84  int tap_sleep;
85 
86  /* --dhcp-option options */
87 
89 
90  const char *domain; /* DOMAIN (15) */
91 
92  const char *netbios_scope; /* NBS (47) */
93 
94  int netbios_node_type; /* NBT 1,2,4,8 (46) */
95 
96 #define N_DHCP_ADDR 4 /* Max # of addresses allowed for
97  * DNS, WINS, etc. */
98 
99  /* DNS (6) */
101  int dns_len;
102 
103  /* WINS (44) */
105  int wins_len;
106 
107  /* NTP (42) */
109  int ntp_len;
110 
111  /* NBDD (45) */
113  int nbdd_len;
114 
115 #define N_SEARCH_LIST_LEN 10 /* Max # of entries in domin-search list */
116 
117  /* SEARCH (119), MacOS, Linux, Win10 1809+ */
120 
121  /* DISABLE_NBT (43, Vendor option 001) */
123 
126 
128 
129  struct in6_addr dns6[N_DHCP_ADDR];
130  int dns6_len;
131 #if defined(TARGET_ANDROID)
132  const char *http_proxy;
133  int http_proxy_port;
134 #endif
135 };
136 
137 #elif defined(TARGET_LINUX)
138 
139 struct tuntap_options {
140  int txqueuelen;
141 };
142 
143 #else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
144 
145 struct tuntap_options {
146  int dummy; /* not used */
147 };
148 
149 #endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
150 
151 /*
152  * Define a TUN/TAP dev.
153  */
154 
155 struct tuntap
156 {
157 #define TUNNEL_TYPE(tt) ((tt) ? ((tt)->type) : DEV_TYPE_UNDEF)
158  int type; /* DEV_TYPE_x as defined in proto.h */
159 
160 #define TUNNEL_TOPOLOGY(tt) ((tt) ? ((tt)->topology) : TOP_UNDEF)
161  int topology; /* one of the TOP_x values */
162 
165 
166  bool persistent_if; /* if existed before, keep on program end */
167 
168  struct tuntap_options options; /* options set on command line */
169 
170  char *actual_name; /* actual name of TUN/TAP dev, usually including unit number */
171 
172  /* ifconfig parameters */
175 
176  struct in6_addr local_ipv6;
177  struct in6_addr remote_ipv6;
179 
180 #ifdef _WIN32
181  HANDLE hand;
182  struct overlapped_io reads;
183  struct overlapped_io writes;
185 
186  /* used for setting interface address via IP Helper API
187  * or DHCP masquerade */
192 
193  /* Windows adapter index for TAP-Windows adapter,
194  * ~0 if undefined */
196 
197  enum windows_driver_type windows_driver;
199 
204 #else /* ifdef _WIN32 */
205  int fd; /* file descriptor for TUN/TAP dev */
206 #endif /* ifdef _WIN32 */
207 
208 #ifdef TARGET_SOLARIS
209  int ip_fd;
210 #endif
211 
212 #ifdef HAVE_NET_IF_UTUN_H
213  bool is_utun;
214 #endif
215  /* used for printing status info only */
216  unsigned int rwflags_debug;
217 
218  /* Some TUN/TAP drivers like to be ioctled for mtu
219  * after open */
221 };
222 
223 static inline bool
224 tuntap_defined(const struct tuntap *tt)
225 {
226 #ifdef _WIN32
227  return tt && tt->hand != NULL;
228 #else
229  return tt && tt->fd >= 0;
230 #endif
231 }
232 
233 #ifdef _WIN32
234 static inline bool
236 {
237  return tt && tt->windows_driver == WINDOWS_DRIVER_WINTUN;
238 }
239 
240 static inline bool
242 {
243  return tuntap_is_wintun(tt) && (tt->wintun_send_ring->head == tt->wintun_send_ring->tail);
244 }
245 #endif
246 
247 /*
248  * Function prototypes
249  */
250 
251 void open_tun(const char *dev, const char *dev_type, const char *dev_node,
252  struct tuntap *tt);
253 
254 void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx);
255 
256 int write_tun(struct tuntap *tt, uint8_t *buf, int len);
257 
258 int read_tun(struct tuntap *tt, uint8_t *buf, int len);
259 
260 void tuncfg(const char *dev, const char *dev_type, const char *dev_node,
261  int persist_mode, const char *username,
262  const char *groupname, const struct tuntap_options *options,
263  openvpn_net_ctx_t *ctx);
264 
265 const char *guess_tuntap_dev(const char *dev,
266  const char *dev_type,
267  const char *dev_node,
268  struct gc_arena *gc);
269 
270 struct tuntap *init_tun(const char *dev, /* --dev option */
271  const char *dev_type, /* --dev-type option */
272  int topology, /* one of the TOP_x values */
273  const char *ifconfig_local_parm, /* --ifconfig parm 1 */
274  const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
275  const char *ifconfig_ipv6_local_parm, /* --ifconfig parm 1 / IPv6 */
276  int ifconfig_ipv6_netbits_parm, /* --ifconfig parm 1 / bits */
277  const char *ifconfig_ipv6_remote_parm, /* --ifconfig parm 2 / IPv6 */
278  struct addrinfo *local_public,
279  struct addrinfo *remote_public,
280  const bool strict_warn,
281  struct env_set *es,
282  openvpn_net_ctx_t *ctx);
283 
284 void init_tun_post(struct tuntap *tt,
285  const struct frame *frame,
286  const struct tuntap_options *options);
287 
288 void do_ifconfig_setenv(const struct tuntap *tt,
289  struct env_set *es);
290 
300 void do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu,
301  const struct env_set *es, openvpn_net_ctx_t *ctx);
302 
303 bool is_dev_type(const char *dev, const char *dev_type, const char *match_type);
304 
305 int dev_type_enum(const char *dev, const char *dev_type);
306 
307 const char *dev_type_string(const char *dev, const char *dev_type);
308 
309 const char *ifconfig_options_string(const struct tuntap *tt, bool remote, bool disable, struct gc_arena *gc);
310 
311 bool is_tun_p2p(const struct tuntap *tt);
312 
313 void check_subnet_conflict(const in_addr_t ip,
314  const in_addr_t netmask,
315  const char *prefix);
316 
318 
319 /*
320  * Should ifconfig be called before or after
321  * tun dev open?
322  */
323 
324 #define IFCONFIG_BEFORE_TUN_OPEN 0
325 #define IFCONFIG_AFTER_TUN_OPEN 1
326 
327 #define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPEN
328 
329 static inline int
331 {
332 #if defined(TARGET_LINUX)
334 #elif defined(TARGET_SOLARIS)
336 #elif defined(TARGET_OPENBSD)
338 #elif defined(TARGET_DARWIN)
340 #elif defined(TARGET_NETBSD)
342 #elif defined(_WIN32)
344 #elif defined(TARGET_ANDROID)
346 #else /* if defined(TARGET_LINUX) */
347  return IFCONFIG_DEFAULT;
348 #endif
349 }
350 
351 #define ROUTE_BEFORE_TUN 0
352 #define ROUTE_AFTER_TUN 1
353 #define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN
354 
355 static inline int
357 {
358 #if defined(TARGET_ANDROID)
359  return ROUTE_BEFORE_TUN;
360 #else
361  return ROUTE_ORDER_DEFAULT;
362 #endif
363 }
364 
365 
366 #ifdef _WIN32
367 
368 struct tap_reg
369 {
370  const char *guid;
371  enum windows_driver_type windows_driver;
372  struct tap_reg *next;
373 };
374 
375 struct panel_reg
376 {
377  const char *name;
378  const char *guid;
379  struct panel_reg *next;
380 };
381 
383 {
387 };
388 
389 int ascii2ipset(const char *name);
390 
391 const char *ipset2ascii(int index);
392 
393 const char *ipset2ascii_all(struct gc_arena *gc);
394 
395 void verify_255_255_255_252(in_addr_t local, in_addr_t remote);
396 
397 const IP_ADAPTER_INFO *get_adapter_info_list(struct gc_arena *gc);
398 
399 const IP_ADAPTER_INFO *get_tun_adapter(const struct tuntap *tt, const IP_ADAPTER_INFO *list);
400 
401 const IP_ADAPTER_INFO *get_adapter_info(DWORD index, struct gc_arena *gc);
402 
403 const IP_PER_ADAPTER_INFO *get_per_adapter_info(const DWORD index, struct gc_arena *gc);
404 
405 const IP_ADAPTER_INFO *get_adapter(const IP_ADAPTER_INFO *ai, DWORD index);
406 
407 bool is_adapter_up(const struct tuntap *tt, const IP_ADAPTER_INFO *list);
408 
409 bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai, const in_addr_t ip, in_addr_t *highest_netmask);
410 
411 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list,
412  const in_addr_t ip,
413  int *count,
414  in_addr_t *netmask);
415 
416 void show_tap_win_adapters(int msglev, int warnlev);
417 
418 void show_adapters(int msglev);
419 
420 void tap_allow_nonadmin_access(const char *dev_node);
421 
423 
424 const char *tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc);
425 
426 void tun_show_debug(struct tuntap *tt);
427 
428 bool dhcp_release_by_adapter_index(const DWORD adapter_index);
429 
430 bool dhcp_renew_by_adapter_index(const DWORD adapter_index);
431 
432 void fork_register_dns_action(struct tuntap *tt);
433 
434 void ipconfig_register_dns(const struct env_set *es);
435 
436 void tun_standby_init(struct tuntap *tt);
437 
438 bool tun_standby(struct tuntap *tt);
439 
440 int tun_read_queue(struct tuntap *tt, int maxsize);
441 
442 int tun_write_queue(struct tuntap *tt, struct buffer *buf);
443 
444 int tun_finalize(HANDLE h, struct overlapped_io *io, struct buffer *buf);
445 
446 static inline bool
448 {
449  /*
450  * This corresponds to the STATUS_NO_SUCH_DEVICE
451  * error in tapdrvr.c.
452  */
453  if (status < 0)
454  {
455  return openvpn_errno() == ERROR_FILE_NOT_FOUND;
456  }
457  return false;
458 }
459 
460 static inline bool
462 {
463  /*
464  * Typically generated when driver is halted.
465  */
466  if (status < 0)
467  {
468  return openvpn_errno() == ERROR_OPERATION_ABORTED;
469  }
470  return false;
471 }
472 
473 static inline int
474 tun_write_win32(struct tuntap *tt, struct buffer *buf)
475 {
476  int err = 0;
477  int status = 0;
478  if (overlapped_io_active(&tt->writes))
479  {
480  status = tun_finalize(tt->hand, &tt->writes, NULL);
481  if (status < 0)
482  {
483  err = GetLastError();
484  }
485  }
486  tun_write_queue(tt, buf);
487  if (status < 0)
488  {
489  SetLastError(err);
490  return status;
491  }
492  else
493  {
494  return BLEN(buf);
495  }
496 }
497 
498 static inline int
499 read_tun_buffered(struct tuntap *tt, struct buffer *buf)
500 {
501  return tun_finalize(tt->hand, &tt->reads, buf);
502 }
503 
504 static inline ULONG
506 {
507  return (size + (WINTUN_PACKET_ALIGN - 1)) & ~(WINTUN_PACKET_ALIGN - 1);
508 }
509 
510 static inline ULONG
511 wintun_ring_wrap(ULONG value)
512 {
513  return value & (WINTUN_RING_CAPACITY - 1);
514 }
515 
516 static inline void
517 read_wintun(struct tuntap *tt, struct buffer *buf)
518 {
519  struct tun_ring *ring = tt->wintun_send_ring;
520  ULONG head = ring->head;
521  ULONG tail = ring->tail;
522  ULONG content_len;
523  struct TUN_PACKET *packet;
524  ULONG aligned_packet_size;
525 
526  *buf = tt->reads.buf_init;
527  buf->len = 0;
528 
529  if ((head >= WINTUN_RING_CAPACITY) || (tail >= WINTUN_RING_CAPACITY))
530  {
531  msg(M_INFO, "Wintun: ring capacity exceeded");
532  buf->len = -1;
533  return;
534  }
535 
536  if (head == tail)
537  {
538  /* nothing to read */
539  return;
540  }
541 
542  content_len = wintun_ring_wrap(tail - head);
543  if (content_len < sizeof(struct TUN_PACKET_HEADER))
544  {
545  msg(M_INFO, "Wintun: incomplete packet header in send ring");
546  buf->len = -1;
547  return;
548  }
549 
550  packet = (struct TUN_PACKET *) &ring->data[head];
551  if (packet->size > WINTUN_MAX_PACKET_SIZE)
552  {
553  msg(M_INFO, "Wintun: packet too big in send ring");
554  buf->len = -1;
555  return;
556  }
557 
558  aligned_packet_size = wintun_ring_packet_align(sizeof(struct TUN_PACKET_HEADER) + packet->size);
559  if (aligned_packet_size > content_len)
560  {
561  msg(M_INFO, "Wintun: incomplete packet in send ring");
562  buf->len = -1;
563  return;
564  }
565 
566  buf_write(buf, packet->data, packet->size);
567 
568  head = wintun_ring_wrap(head + aligned_packet_size);
569  ring->head = head;
570 }
571 
572 static inline bool
573 is_ip_packet_valid(const struct buffer *buf)
574 {
575  const struct openvpn_iphdr *ih = (const struct openvpn_iphdr *)BPTR(buf);
576 
577  if (OPENVPN_IPH_GET_VER(ih->version_len) == 4)
578  {
579  if (BLEN(buf) < sizeof(struct openvpn_iphdr))
580  {
581  return false;
582  }
583  }
584  else if (OPENVPN_IPH_GET_VER(ih->version_len) == 6)
585  {
586  if (BLEN(buf) < sizeof(struct openvpn_ipv6hdr))
587  {
588  return false;
589  }
590  }
591  else
592  {
593  return false;
594  }
595 
596  return true;
597 }
598 
599 static inline int
600 write_wintun(struct tuntap *tt, struct buffer *buf)
601 {
602  struct tun_ring *ring = tt->wintun_receive_ring;
603  ULONG head = ring->head;
604  ULONG tail = ring->tail;
605  ULONG aligned_packet_size;
606  ULONG buf_space;
607  struct TUN_PACKET *packet;
608 
609  /* wintun marks ring as corrupted (overcapacity) if it receives invalid IP packet */
610  if (!is_ip_packet_valid(buf))
611  {
612  msg(D_LOW, "write_wintun(): drop invalid IP packet");
613  return 0;
614  }
615 
616  if ((head >= WINTUN_RING_CAPACITY) || (tail >= WINTUN_RING_CAPACITY))
617  {
618  msg(M_INFO, "write_wintun(): head/tail value is over capacity");
619  return -1;
620  }
621 
622  aligned_packet_size = wintun_ring_packet_align(sizeof(struct TUN_PACKET_HEADER) + BLEN(buf));
623  buf_space = wintun_ring_wrap(head - tail - WINTUN_PACKET_ALIGN);
624  if (aligned_packet_size > buf_space)
625  {
626  msg(M_INFO, "write_wintun(): ring is full");
627  return 0;
628  }
629 
630  /* copy packet size and data into ring */
631  packet = (struct TUN_PACKET * )&ring->data[tail];
632  packet->size = BLEN(buf);
633  memcpy(packet->data, BPTR(buf), BLEN(buf));
634 
635  /* move ring tail */
636  ring->tail = wintun_ring_wrap(tail + aligned_packet_size);
637  if (ring->alertable != 0)
638  {
639  SetEvent(tt->rw_handle.write);
640  }
641 
642  return BLEN(buf);
643 }
644 
645 static inline int
646 write_tun_buffered(struct tuntap *tt, struct buffer *buf)
647 {
649  {
650  return write_wintun(tt, buf);
651  }
652  else
653  {
654  return tun_write_win32(tt, buf);
655  }
656 }
657 
658 #else /* ifdef _WIN32 */
659 
660 static inline bool
661 tuntap_stop(int status)
662 {
663  return false;
664 }
665 
666 static inline bool
667 tuntap_abort(int status)
668 {
669  return false;
670 }
671 
672 static inline void
673 tun_standby_init(struct tuntap *tt)
674 {
675 }
676 
677 static inline bool
678 tun_standby(struct tuntap *tt)
679 {
680  return true;
681 }
682 
683 #endif /* ifdef _WIN32 */
684 
685 /*
686  * TUN/TAP I/O wait functions
687  */
688 
689 static inline event_t
690 tun_event_handle(const struct tuntap *tt)
691 {
692 #ifdef _WIN32
693  return &tt->rw_handle;
694 #else
695  return tt->fd;
696 #endif
697 }
698 
699 static inline void
700 tun_set(struct tuntap *tt,
701  struct event_set *es,
702  unsigned int rwflags,
703  void *arg,
704  unsigned int *persistent)
705 {
706  if (tuntap_defined(tt))
707  {
708  /* if persistent is defined, call event_ctl only if rwflags has changed since last call */
709  if (!persistent || *persistent != rwflags)
710  {
711  event_ctl(es, tun_event_handle(tt), rwflags, arg);
712  if (persistent)
713  {
714  *persistent = rwflags;
715  }
716  }
717 #ifdef _WIN32
718  if (tt->windows_driver == WINDOWS_DRIVER_TAP_WINDOWS6 && (rwflags & EVENT_READ))
719  {
720  tun_read_queue(tt, 0);
721  }
722 #endif
723  tt->rwflags_debug = rwflags;
724  }
725 }
726 
727 const char *tun_stat(const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc);
728 
729 #endif /* TUN_H */
bool register_dns
Definition: tun.h:127
uint8_t version_len
Definition: proto.h:109
void tun_show_debug(struct tuntap *tt)
Definition: tun.c:6703
int netbits_ipv6
Definition: tun.h:178
struct buffer buf_init
Definition: win32.h:214
int dev_type_enum(const char *dev, const char *dev_type)
Definition: tun.c:361
Definition: tun.h:155
static ULONG wintun_ring_wrap(ULONG value)
Definition: tun.h:511
static bool tuntap_abort(int status)
Definition: tun.h:461
in_addr_t ntp[N_DHCP_ADDR]
Definition: tun.h:108
void open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
Definition: tun.c:6656
struct overlapped_io writes
Definition: tun.h:183
int netbios_node_type
Definition: tun.h:94
#define openvpn_errno()
Definition: error.h:78
#define ROUTE_ORDER_DEFAULT
Definition: tun.h:353
void check_subnet_conflict(const in_addr_t ip, const in_addr_t netmask, const char *prefix)
Definition: tun.c:536
#define M_INFO
Definition: errlevel.h:55
const char * domain_search_list[N_SEARCH_LIST_LEN]
Definition: tun.h:118
Packet geometry parameters.
Definition: mtu.h:93
HANDLE wintun_send_ring_handle
Definition: tun.h:200
ULONG ipapi_context
Definition: tun.h:189
volatile ULONG head
Definition: ring_buffer.h:52
int ntp_len
Definition: tun.h:109
const char * netbios_scope
Definition: tun.h:92
#define IFCONFIG_BEFORE_TUN_OPEN
Definition: tun.h:324
in_addr_t nbdd[N_DHCP_ADDR]
Definition: tun.h:112
void tun_standby_init(struct tuntap *tt)
Definition: tun.c:5664
int tap_sleep
Definition: tun.h:84
#define IFCONFIG_DEFAULT
Definition: tun.h:327
bool dhcp_masq_custom_offset
Definition: tun.h:79
in_addr_t remote_netmask
Definition: tun.h:174
int read_tun(struct tuntap *tt, uint8_t *buf, int len)
bool dhcp_renew
Definition: tun.h:124
void do_ifconfig_setenv(const struct tuntap *tt, struct env_set *es)
Definition: tun.c:689
static bool overlapped_io_active(struct overlapped_io *o)
Definition: win32.h:226
volatile ULONG tail
Definition: ring_buffer.h:53
HANDLE hand
Definition: tun.h:181
void show_adapters(int msglev)
Definition: tun.c:4944
#define in_addr_t
Definition: config-msvc.h:103
void * openvpn_net_ctx_t
Definition: networking.h:26
void fork_register_dns_action(struct tuntap *tt)
Definition: tun.c:5977
#define WINTUN_PACKET_ALIGN
Definition: ring_buffer.h:42
static void read_wintun(struct tuntap *tt, struct buffer *buf)
Definition: tun.h:517
static int ifconfig_order(void)
Definition: tun.h:330
const char * guid
Definition: tun.h:370
#define OPENVPN_IPH_GET_VER(v)
Definition: proto.h:107
const char * tun_stat(const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc)
Definition: tun.c:628
bool ip_win32_defined
Definition: tun.h:64
static bool tuntap_defined(const struct tuntap *tt)
Definition: tun.h:224
void ipconfig_register_dns(const struct env_set *es)
Definition: tun.c:5199
#define N_SEARCH_LIST_LEN
Definition: tun.h:115
#define D_LOW
Definition: errlevel.h:97
int write_tun(struct tuntap *tt, uint8_t *buf, int len)
struct tun_ring * wintun_send_ring
Definition: tun.h:202
bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai, const in_addr_t ip, in_addr_t *highest_netmask)
Definition: tun.c:4644
int len
Length in bytes of the actual content within the allocated memory.
Definition: buffer.h:66
static ULONG wintun_ring_packet_align(ULONG size)
Definition: tun.h:505
#define BPTR(buf)
Definition: buffer.h:124
const IP_ADAPTER_INFO * get_tun_adapter(const struct tuntap *tt, const IP_ADAPTER_INFO *list)
Definition: tun.c:4586
const IP_ADAPTER_INFO * get_adapter_info_list(struct gc_arena *gc)
Definition: tun.c:4368
int standby_iter
Definition: tun.h:198
int tun_read_queue(struct tuntap *tt, int maxsize)
Definition: tun.c:3437
bool dhcp_renew_by_adapter_index(const DWORD adapter_index)
Definition: tun.c:5135
void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
Definition: tun.c:6780
bool is_dev_type(const char *dev, const char *dev_type, const char *match_type)
Definition: tun.c:343
uint32_t size
Definition: ring_buffer.h:79
in_addr_t local
Definition: tun.h:173
struct panel_reg * next
Definition: tun.h:379
#define IFCONFIG_AFTER_TUN_OPEN
Definition: tun.h:325
bool did_ifconfig_setup
Definition: tun.h:163
int type
Definition: tun.h:158
static int write_tun_buffered(struct tuntap *tt, struct buffer *buf)
Definition: tun.h:646
static event_t tun_event_handle(const struct tuntap *tt)
Definition: tun.h:690
#define ROUTE_BEFORE_TUN
Definition: tun.h:351
const char * name
Definition: tun.h:377
void init_tun_post(struct tuntap *tt, const struct frame *frame, const struct tuntap_options *options)
Definition: tun.c:888
const IP_ADAPTER_INFO * get_adapter_info(DWORD index, struct gc_arena *gc)
Definition: tun.c:4501
int dns6_len
Definition: tun.h:130
UCHAR data[WINTUN_MAX_PACKET_SIZE]
Definition: ring_buffer.h:80
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)
const IP_PER_ADAPTER_INFO * get_per_adapter_info(const DWORD index, struct gc_arena *gc)
Definition: tun.c:4395
const IP_ADAPTER_INFO * get_adapter(const IP_ADAPTER_INFO *ai, DWORD index)
Definition: tun.c:4482
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
Definition: event.h:157
int wins_len
Definition: tun.h:105
int ip_win32_type
Definition: tun.h:72
struct rw_handle rw_handle
Definition: tun.h:184
bool is_adapter_up(const struct tuntap *tt, const IP_ADAPTER_INFO *list)
Definition: tun.c:4599
windows_driver_type
Definition: tun.h:47
void tap_allow_nonadmin_access(const char *dev_node)
Definition: tun.c:4993
in_addr_t wins[N_DHCP_ADDR]
Definition: tun.h:104
static int route_order(void)
Definition: tun.h:356
bool persistent_if
Definition: tun.h:166
DWORD adapter_index
Definition: tun.h:195
const char * tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
Definition: tun.c:6685
const char * domain
Definition: tun.h:90
struct overlapped_io reads
Definition: tun.h:182
static bool tuntap_is_wintun(struct tuntap *tt)
Definition: tun.h:235
void verify_255_255_255_252(in_addr_t local, in_addr_t remote)
Definition: tun.c:4020
int tun_finalize(HANDLE h, struct overlapped_io *io, struct buffer *buf)
Definition: tun.c:3564
#define EVENT_READ
Definition: event.h:39
#define BLEN(buf)
Definition: buffer.h:127
ULONG ipapi_instance
Definition: tun.h:190
static bool is_ip_packet_valid(const struct buffer *buf)
Definition: tun.h:573
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)
Definition: tun.c:733
HANDLE msg_channel
Definition: tun.h:75
bool did_ifconfig_ipv6_setup
Definition: tun.h:164
struct tap_reg * next
Definition: tun.h:372
#define msg(flags,...)
Definition: error.h:153
int post_open_mtu
Definition: tun.h:220
DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count, in_addr_t *netmask)
Definition: tun.c:4677
Definition: tun.h:375
static bool tuntap_ring_empty(struct tuntap *tt)
Definition: tun.h:241
static int write_wintun(struct tuntap *tt, struct buffer *buf)
Definition: tun.h:600
const char * ipset2ascii_all(struct gc_arena *gc)
Definition: tun.c:6937
HANDLE write
Definition: win32.h:78
const char * ipset2ascii(int index)
Definition: tun.c:6923
const char * ifconfig_options_string(const struct tuntap *tt, bool remote, bool disable, struct gc_arena *gc)
Definition: tun.c:590
struct in6_addr dns6[N_DHCP_ADDR]
Definition: tun.h:129
int dhcp_masq_offset
Definition: tun.h:80
int nbdd_len
Definition: tun.h:113
int topology
Definition: tun.h:161
void warn_on_use_of_common_subnets(openvpn_net_ctx_t *ctx)
Definition: tun.c:567
static int tun_write_win32(struct tuntap *tt, struct buffer *buf)
Definition: tun.h:474
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
volatile LONG alertable
Definition: ring_buffer.h:54
int dns_len
Definition: tun.h:101
struct tun_ring * wintun_receive_ring
Definition: tun.h:203
bool disable_nbt
Definition: tun.h:122
struct device_instance_id_interface * next
Definition: tun.h:386
#define N_DHCP_ADDR
Definition: tun.h:96
#define WINTUN_RING_CAPACITY
Definition: ring_buffer.h:39
const char * guid
Definition: tun.h:378
int tun_write_queue(struct tuntap *tt, struct buffer *buf)
Definition: tun.c:3501
UCHAR data[WINTUN_RING_CAPACITY+WINTUN_RING_TRAILING_BYTES]
Definition: ring_buffer.h:55
#define WINTUN_MAX_PACKET_SIZE
Definition: ring_buffer.h:41
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Definition: buffer.h:689
void show_tap_win_adapters(int msglev, int warnlev)
Definition: tun.c:4090
void show_valid_win32_tun_subnets(void)
Definition: tun.c:4057
bool tun_standby(struct tuntap *tt)
Definition: tun.c:5670
static int read_tun_buffered(struct tuntap *tt, struct buffer *buf)
Definition: tun.h:499
bool dhcp_pre_release
Definition: tun.h:125
in_addr_t adapter_netmask
Definition: tun.h:191
const char * device_interface_list
Definition: tun.h:385
Wintun ring buffer See https://github.com/WireGuard/wintun#ring-layout.
Definition: ring_buffer.h:50
bool dhcp_release_by_adapter_index(const DWORD adapter_index)
Definition: tun.c:5095
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
Definition: tun.c:1575
char * actual_name
Definition: tun.h:170
const char * guess_tuntap_dev(const char *dev, const char *dev_type, const char *dev_node, struct gc_arena *gc)
Definition: tun.c:405
static bool tuntap_stop(int status)
Definition: tun.h:447
const char * dev_type_string(const char *dev, const char *dev_type)
Definition: tun.c:382
static SERVICE_STATUS status
Definition: interactive.c:56
bool ipapi_context_defined
Definition: tun.h:188
HANDLE wintun_receive_ring_handle
Definition: tun.h:201
Definition: tun.h:368
bool is_tun_p2p(const struct tuntap *tt)
Definition: tun.c:663
unsigned int rwflags_debug
Definition: tun.h:216
int domain_search_list_len
Definition: tun.h:119
int ascii2ipset(const char *name)
Definition: tun.c:6908
in_addr_t dns[N_DHCP_ADDR]
Definition: tun.h:100
int dhcp_lease_time
Definition: tun.h:81
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition: tun.h:700
enum windows_driver_type windows_driver
Definition: tun.h:197
bool dhcp_options
Definition: tun.h:88