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-2024 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 #include "dco.h"
44 
58 };
59 
60 #ifdef _WIN32
61 #define WINTUN_COMPONENT_ID "wintun"
62 #define DCO_WIN_REFERENCE_STRING "ovpn-dco"
63 #endif
64 
65 #if defined(_WIN32) || defined(TARGET_ANDROID)
66 
67 #define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
68 
69 /* time constants for --ip-win32 adaptive */
70 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
71 #define IPW32_SET_ADAPTIVE_TRY_NETSH 20
72 
73 /* bit flags for DHCP options */
74 #define DHCP_OPTIONS_DHCP_OPTIONAL (1<<0)
75 #define DHCP_OPTIONS_DHCP_REQUIRED (1<<1)
76 
78  /* --ip-win32 options */
80 
81 #define IPW32_SET_MANUAL 0 /* "--ip-win32 manual" */
82 #define IPW32_SET_NETSH 1 /* "--ip-win32 netsh" */
83 #define IPW32_SET_IPAPI 2 /* "--ip-win32 ipapi" */
84 #define IPW32_SET_DHCP_MASQ 3 /* "--ip-win32 dynamic" */
85 #define IPW32_SET_ADAPTIVE 4 /* "--ip-win32 adaptive" */
86 #define IPW32_SET_N 5
88 
89 #ifdef _WIN32
90  HANDLE msg_channel;
91 #endif
92 
93  /* --ip-win32 dynamic options */
97 
98  /* --tap-sleep option */
99  int tap_sleep;
100 
101  /* --dhcp-option options */
102 
104 
105  const char *domain; /* DOMAIN (15) */
106 
107  const char *netbios_scope; /* NBS (47) */
108 
109  int netbios_node_type; /* NBT 1,2,4,8 (46) */
110 
111 #define N_DHCP_ADDR 4 /* Max # of addresses allowed for
112  * DNS, WINS, etc. */
113 
114  /* DNS (6) */
115  in_addr_t dns[N_DHCP_ADDR];
116  int dns_len;
117 
118  /* WINS (44) */
119  in_addr_t wins[N_DHCP_ADDR];
120  int wins_len;
121 
122  /* NTP (42) */
123  in_addr_t ntp[N_DHCP_ADDR];
124  int ntp_len;
125 
126  /* NBDD (45) */
127  in_addr_t nbdd[N_DHCP_ADDR];
128  int nbdd_len;
129 
130 #define N_SEARCH_LIST_LEN 10 /* Max # of entries in domin-search list */
131 
132  /* SEARCH (119), MacOS, Linux, Win10 1809+ */
135 
136  /* DISABLE_NBT (43, Vendor option 001) */
137  bool disable_nbt;
138 
140  bool dhcp_pre_release;
141 
142  bool register_dns;
143 
144  struct in6_addr dns6[N_DHCP_ADDR];
145  int dns6_len;
146 #if defined(TARGET_ANDROID)
147  const char *http_proxy;
148  int http_proxy_port;
149 #endif
150 };
151 
152 #elif defined(TARGET_LINUX)
153 
154 struct tuntap_options {
155  int txqueuelen;
156 };
157 
158 #else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
159 
160 struct tuntap_options {
161  int dummy; /* not used */
162 };
163 
164 #endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
165 
166 /*
167  * Define a TUN/TAP dev.
168  */
169 #ifndef WIN32
170 typedef struct afunix_context
171 {
172  pid_t childprocess;
174 
175 #else /* ifndef WIN32 */
176 typedef struct {
177  int dummy;
179 #endif
180 
181 struct tuntap
182 {
183 #define TUNNEL_TYPE(tt) ((tt) ? ((tt)->type) : DEV_TYPE_UNDEF)
184  int type; /* DEV_TYPE_x as defined in proto.h */
185 
186 #define TUNNEL_TOPOLOGY(tt) ((tt) ? ((tt)->topology) : TOP_UNDEF)
187  int topology; /* one of the TOP_x values */
188 
193 
196  bool did_ifconfig_setup;
197 
201 
202  bool persistent_if; /* if existed before, keep on program end */
203 
204  struct tuntap_options options; /* options set on command line */
205 
206  char *actual_name; /* actual name of TUN/TAP dev, usually including unit number */
207 
208  /* ifconfig parameters */
209  in_addr_t local;
210  in_addr_t remote_netmask;
211 
212  struct in6_addr local_ipv6;
213  struct in6_addr remote_ipv6;
214  int netbits_ipv6;
215 
216 #ifdef _WIN32
217  HANDLE hand;
220  struct rw_handle rw_handle;
221 
222  /* used for setting interface address via IP Helper API
223  * or DHCP masquerade */
227  in_addr_t adapter_netmask;
228 
229  /* Windows adapter index for TAP-Windows adapter,
230  * ~0 if undefined */
231  DWORD adapter_index;
232 
233  int standby_iter;
234 
239 #else /* ifdef _WIN32 */
240  int fd; /* file descriptor for TUN/TAP dev */
241 #endif /* ifdef _WIN32 */
242 
243 #ifdef TARGET_SOLARIS
244  int ip_fd;
245 #endif
246 
247  /* used for printing status info only */
248  unsigned int rwflags_debug;
249 
252 };
253 
254 static inline bool
255 tuntap_defined(const struct tuntap *tt)
256 {
257 #ifdef _WIN32
258  return tt && tt->hand != NULL;
259 #else
260  return tt && tt->fd >= 0;
261 #endif
262 }
263 
264 #ifdef _WIN32
265 static inline bool
266 tuntap_is_wintun(struct tuntap *tt)
267 {
268  return tt && tt->backend_driver == WINDOWS_DRIVER_WINTUN;
269 }
270 
271 static inline bool
272 tuntap_ring_empty(struct tuntap *tt)
273 {
274  return tuntap_is_wintun(tt) && (tt->wintun_send_ring->head == tt->wintun_send_ring->tail);
275 }
276 #endif
277 
278 /*
279  * Function prototypes
280  */
281 
282 void open_tun(const char *dev, const char *dev_type, const char *dev_node,
283  struct tuntap *tt, openvpn_net_ctx_t *ctx);
284 
285 void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx);
286 
287 void tun_open_device(struct tuntap *tt, const char *dev_node,
288  const char **device_guid, struct gc_arena *gc);
289 
290 void close_tun_handle(struct tuntap *tt);
291 
292 int write_tun(struct tuntap *tt, uint8_t *buf, int len);
293 
294 int read_tun(struct tuntap *tt, uint8_t *buf, int len);
295 
296 void tuncfg(const char *dev, const char *dev_type, const char *dev_node,
297  int persist_mode, const char *username,
298  const char *groupname, const struct tuntap_options *options,
299  openvpn_net_ctx_t *ctx);
300 
301 const char *guess_tuntap_dev(const char *dev,
302  const char *dev_type,
303  const char *dev_node,
304  struct gc_arena *gc);
305 
306 struct tuntap *init_tun(const char *dev, /* --dev option */
307  const char *dev_type, /* --dev-type option */
308  int topology, /* one of the TOP_x values */
309  const char *ifconfig_local_parm, /* --ifconfig parm 1 */
310  const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
311  const char *ifconfig_ipv6_local_parm, /* --ifconfig parm 1 / IPv6 */
312  int ifconfig_ipv6_netbits_parm, /* --ifconfig parm 1 / bits */
313  const char *ifconfig_ipv6_remote_parm, /* --ifconfig parm 2 / IPv6 */
314  struct addrinfo *local_public,
315  struct addrinfo *remote_public,
316  const bool strict_warn,
317  struct env_set *es,
318  openvpn_net_ctx_t *ctx,
319  struct tuntap *tt);
320 
321 void init_tun_post(struct tuntap *tt,
322  const struct frame *frame,
323  const struct tuntap_options *options);
324 
325 void do_ifconfig_setenv(const struct tuntap *tt,
326  struct env_set *es);
327 
337 void do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu,
338  const struct env_set *es, openvpn_net_ctx_t *ctx);
339 
346 void undo_ifconfig(struct tuntap *tt, openvpn_net_ctx_t *ctx);
347 
348 bool is_dev_type(const char *dev, const char *dev_type, const char *match_type);
349 
350 int dev_type_enum(const char *dev, const char *dev_type);
351 
352 const char *dev_type_string(const char *dev, const char *dev_type);
353 
354 const char *ifconfig_options_string(const struct tuntap *tt, bool remote, bool disable, struct gc_arena *gc);
355 
356 bool is_tun_p2p(const struct tuntap *tt);
357 
359 
363 const char *
365 
366 /*
367  * Should ifconfig be called before or after
368  * tun dev open?
369  */
370 
371 #define IFCONFIG_BEFORE_TUN_OPEN 0
372 #define IFCONFIG_AFTER_TUN_OPEN 1
373 
374 #define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPEN
375 
376 static inline int
377 ifconfig_order(struct tuntap *tt)
378 {
379  if (tt->backend_driver == DRIVER_AFUNIX)
380  {
382  }
383 #if defined(TARGET_LINUX)
385 #elif defined(TARGET_SOLARIS)
387 #elif defined(TARGET_OPENBSD)
389 #elif defined(TARGET_DARWIN)
391 #elif defined(TARGET_NETBSD)
393 #elif defined(_WIN32)
395 #elif defined(TARGET_ANDROID)
397 #else /* if defined(TARGET_LINUX) */
398  return IFCONFIG_DEFAULT;
399 #endif
400 }
401 
402 #define ROUTE_BEFORE_TUN 0
403 #define ROUTE_AFTER_TUN 1
404 #define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN
405 
406 static inline int
407 route_order(struct tuntap *tt)
408 {
409  if (tt->backend_driver == DRIVER_AFUNIX)
410  {
411  return ROUTE_BEFORE_TUN;
412  }
413 #if defined(TARGET_ANDROID)
414  return ROUTE_BEFORE_TUN;
415 #else
416  return ROUTE_ORDER_DEFAULT;
417 #endif
418 }
419 
420 
421 #ifdef _WIN32
422 
423 struct tap_reg
424 {
425  const char *guid;
427  struct tap_reg *next;
428 };
429 
430 struct panel_reg
431 {
432  const char *name;
433  const char *guid;
434  struct panel_reg *next;
435 };
436 
438 {
440  const char *device_interface;
442 };
443 
444 int ascii2ipset(const char *name);
445 
446 const char *ipset2ascii(int index);
447 
448 const char *ipset2ascii_all(struct gc_arena *gc);
449 
450 void verify_255_255_255_252(in_addr_t local, in_addr_t remote);
451 
452 const IP_ADAPTER_INFO *get_adapter_info_list(struct gc_arena *gc);
453 
454 const IP_ADAPTER_INFO *get_tun_adapter(const struct tuntap *tt, const IP_ADAPTER_INFO *list);
455 
456 const IP_ADAPTER_INFO *get_adapter_info(DWORD index, struct gc_arena *gc);
457 
458 const IP_PER_ADAPTER_INFO *get_per_adapter_info(const DWORD index, struct gc_arena *gc);
459 
460 const IP_ADAPTER_INFO *get_adapter(const IP_ADAPTER_INFO *ai, DWORD index);
461 
462 bool is_adapter_up(const struct tuntap *tt, const IP_ADAPTER_INFO *list);
463 
464 bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai, const in_addr_t ip, in_addr_t *highest_netmask);
465 
466 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list,
467  const in_addr_t ip,
468  int *count,
469  in_addr_t *netmask);
470 
471 void show_tap_win_adapters(int msglev, int warnlev);
472 
473 void show_adapters(int msglev);
474 
475 void tap_allow_nonadmin_access(const char *dev_node);
476 
478 
479 const char *tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc);
480 
481 void tun_show_debug(struct tuntap *tt);
482 
483 bool dhcp_release_by_adapter_index(const DWORD adapter_index);
484 
485 bool dhcp_renew_by_adapter_index(const DWORD adapter_index);
486 
487 void fork_register_dns_action(struct tuntap *tt);
488 
489 void ipconfig_register_dns(const struct env_set *es);
490 
491 void tun_standby_init(struct tuntap *tt);
492 
493 bool tun_standby(struct tuntap *tt);
494 
495 int tun_read_queue(struct tuntap *tt, int maxsize);
496 
497 int tun_write_queue(struct tuntap *tt, struct buffer *buf);
498 
499 static inline bool
500 tuntap_stop(int status)
501 {
502  /*
503  * This corresponds to the STATUS_NO_SUCH_DEVICE
504  * error in tapdrvr.c.
505  */
506  if (status < 0)
507  {
508  return GetLastError() == ERROR_FILE_NOT_FOUND;
509  }
510  return false;
511 }
512 
513 static inline bool
514 tuntap_abort(int status)
515 {
516  /*
517  * Typically generated when driver is halted.
518  */
519  if (status < 0)
520  {
521  return GetLastError() == ERROR_OPERATION_ABORTED;
522  }
523  return false;
524 }
525 
526 int tun_write_win32(struct tuntap *tt, struct buffer *buf);
527 
528 static inline ULONG
529 wintun_ring_packet_align(ULONG size)
530 {
531  return (size + (WINTUN_PACKET_ALIGN - 1)) & ~(WINTUN_PACKET_ALIGN - 1);
532 }
533 
534 static inline ULONG
535 wintun_ring_wrap(ULONG value)
536 {
537  return value & (WINTUN_RING_CAPACITY - 1);
538 }
539 
540 static inline void
541 read_wintun(struct tuntap *tt, struct buffer *buf)
542 {
543  struct tun_ring *ring = tt->wintun_send_ring;
544  ULONG head = ring->head;
545  ULONG tail = ring->tail;
546  ULONG content_len;
547  struct TUN_PACKET *packet;
548  ULONG aligned_packet_size;
549 
550  *buf = tt->reads.buf_init;
551  buf->len = 0;
552 
553  if ((head >= WINTUN_RING_CAPACITY) || (tail >= WINTUN_RING_CAPACITY))
554  {
555  msg(M_INFO, "Wintun: ring capacity exceeded");
556  buf->len = -1;
557  return;
558  }
559 
560  if (head == tail)
561  {
562  /* nothing to read */
563  return;
564  }
565 
566  content_len = wintun_ring_wrap(tail - head);
567  if (content_len < sizeof(struct TUN_PACKET_HEADER))
568  {
569  msg(M_INFO, "Wintun: incomplete packet header in send ring");
570  buf->len = -1;
571  return;
572  }
573 
574  packet = (struct TUN_PACKET *) &ring->data[head];
575  if (packet->size > WINTUN_MAX_PACKET_SIZE)
576  {
577  msg(M_INFO, "Wintun: packet too big in send ring");
578  buf->len = -1;
579  return;
580  }
581 
582  aligned_packet_size = wintun_ring_packet_align(sizeof(struct TUN_PACKET_HEADER) + packet->size);
583  if (aligned_packet_size > content_len)
584  {
585  msg(M_INFO, "Wintun: incomplete packet in send ring");
586  buf->len = -1;
587  return;
588  }
589 
590  buf_write(buf, packet->data, packet->size);
591 
592  head = wintun_ring_wrap(head + aligned_packet_size);
593  ring->head = head;
594 }
595 
596 static inline bool
597 is_ip_packet_valid(const struct buffer *buf)
598 {
599  const struct openvpn_iphdr *ih = (const struct openvpn_iphdr *)BPTR(buf);
600 
601  if (OPENVPN_IPH_GET_VER(ih->version_len) == 4)
602  {
603  if (BLEN(buf) < sizeof(struct openvpn_iphdr))
604  {
605  return false;
606  }
607  }
608  else if (OPENVPN_IPH_GET_VER(ih->version_len) == 6)
609  {
610  if (BLEN(buf) < sizeof(struct openvpn_ipv6hdr))
611  {
612  return false;
613  }
614  }
615  else
616  {
617  return false;
618  }
619 
620  return true;
621 }
622 
623 static inline int
624 write_wintun(struct tuntap *tt, struct buffer *buf)
625 {
626  struct tun_ring *ring = tt->wintun_receive_ring;
627  ULONG head = ring->head;
628  ULONG tail = ring->tail;
629  ULONG aligned_packet_size;
630  ULONG buf_space;
631  struct TUN_PACKET *packet;
632 
633  /* wintun marks ring as corrupted (overcapacity) if it receives invalid IP packet */
634  if (!is_ip_packet_valid(buf))
635  {
636  msg(D_LOW, "write_wintun(): drop invalid IP packet");
637  return 0;
638  }
639 
640  if ((head >= WINTUN_RING_CAPACITY) || (tail >= WINTUN_RING_CAPACITY))
641  {
642  msg(M_INFO, "write_wintun(): head/tail value is over capacity");
643  return -1;
644  }
645 
646  aligned_packet_size = wintun_ring_packet_align(sizeof(struct TUN_PACKET_HEADER) + BLEN(buf));
647  buf_space = wintun_ring_wrap(head - tail - WINTUN_PACKET_ALIGN);
648  if (aligned_packet_size > buf_space)
649  {
650  msg(M_INFO, "write_wintun(): ring is full");
651  return 0;
652  }
653 
654  /* copy packet size and data into ring */
655  packet = (struct TUN_PACKET * )&ring->data[tail];
656  packet->size = BLEN(buf);
657  memcpy(packet->data, BPTR(buf), BLEN(buf));
658 
659  /* move ring tail */
660  ring->tail = wintun_ring_wrap(tail + aligned_packet_size);
661  if (ring->alertable != 0)
662  {
663  SetEvent(tt->rw_handle.write);
664  }
665 
666  return BLEN(buf);
667 }
668 
669 static inline int
670 write_tun_buffered(struct tuntap *tt, struct buffer *buf)
671 {
673  {
674  return write_wintun(tt, buf);
675  }
676  else
677  {
678  return tun_write_win32(tt, buf);
679  }
680 }
681 
682 static inline bool
683 tuntap_is_dco_win(struct tuntap *tt)
684 {
685  return tt && tt->backend_driver == DRIVER_DCO;
686 }
687 
688 static inline bool
689 tuntap_is_dco_win_timeout(struct tuntap *tt, int status)
690 {
691  return tuntap_is_dco_win(tt) && (status < 0) && (openvpn_errno() == ERROR_NETNAME_DELETED);
692 }
693 
694 #else /* ifdef _WIN32 */
695 
696 static inline bool
697 tuntap_stop(int status)
698 {
699  return false;
700 }
701 
702 static inline bool
703 tuntap_abort(int status)
704 {
705  return false;
706 }
707 
708 static inline void
709 tun_standby_init(struct tuntap *tt)
710 {
711 }
712 
713 static inline bool
714 tun_standby(struct tuntap *tt)
715 {
716  return true;
717 }
718 
719 
720 static inline bool
721 tuntap_is_dco_win(struct tuntap *tt)
722 {
723  return false;
724 }
725 
726 static inline bool
727 tuntap_is_dco_win_timeout(struct tuntap *tt, int status)
728 {
729  return false;
730 }
731 
732 #endif /* ifdef _WIN32 */
733 
734 /*
735  * TUN/TAP I/O wait functions
736  */
737 
738 static inline event_t
739 tun_event_handle(const struct tuntap *tt)
740 {
741 #ifdef _WIN32
742  return &tt->rw_handle;
743 #else
744  return tt->fd;
745 #endif
746 }
747 
748 static inline void
749 tun_set(struct tuntap *tt,
750  struct event_set *es,
751  unsigned int rwflags,
752  void *arg,
753  unsigned int *persistent)
754 {
755  if (!tuntap_defined(tt) || tuntap_is_dco_win(tt))
756  {
757  return;
758  }
759 
760  /* if persistent is defined, call event_ctl only if rwflags has changed since last call */
761  if (!persistent || *persistent != rwflags)
762  {
763  event_ctl(es, tun_event_handle(tt), rwflags, arg);
764  if (persistent)
765  {
766  *persistent = rwflags;
767  }
768  }
769 #ifdef _WIN32
770  if (tt->backend_driver == WINDOWS_DRIVER_TAP_WINDOWS6 && (rwflags & EVENT_READ))
771  {
772  tun_read_queue(tt, 0);
773  }
774 #endif
775  tt->rwflags_debug = rwflags;
776 
777 }
778 
779 const char *tun_stat(const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc);
780 bool tun_name_is_fixed(const char *dev);
781 
782 static inline bool
783 is_tun_type_set(const struct tuntap *tt)
784 {
785  return tt && tt->type != DEV_TYPE_UNDEF;
786 }
787 
788 static inline void
789 open_tun_null(struct tuntap *tt)
790 {
791  tt->actual_name = string_alloc("null", NULL);
792 }
793 #endif /* TUN_H */
tun_show_debug
void tun_show_debug(struct tuntap *tt)
Definition: tun.c:6810
tuntap::reads
struct overlapped_io reads
Definition: tun.h:217
read_tun
int read_tun(struct tuntap *tt, uint8_t *buf, int len)
tuntap_options::dhcp_masq_custom_offset
bool dhcp_masq_custom_offset
Definition: tun.h:94
WINTUN_RING_CAPACITY
#define WINTUN_RING_CAPACITY
Definition: ring_buffer.h:39
tuntap_options::dns
in_addr_t dns[N_DHCP_ADDR]
Definition: tun.h:114
DRIVER_NULL
@ DRIVER_NULL
Definition: tun.h:54
tuntap_options::domain_search_list
const char * domain_search_list[N_SEARCH_LIST_LEN]
Definition: tun.h:132
M_INFO
#define M_INFO
Definition: errlevel.h:55
WINTUN_PACKET_ALIGN
#define WINTUN_PACKET_ALIGN
Definition: ring_buffer.h:42
tun_write_queue
int tun_write_queue(struct tuntap *tt, struct buffer *buf)
Definition: tun.c:3628
tuntap::did_ifconfig_setup
bool did_ifconfig_setup
if the internal variables related to ifconfig of this struct have been set up.
Definition: tun.h:195
tuntap_options::dhcp_renew
bool dhcp_renew
Definition: tun.h:138
open_tun
void open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt, openvpn_net_ctx_t *ctx)
Definition: tun.c:6753
error.h
device_instance_id_interface::next
struct device_instance_id_interface * next
Definition: tun.h:440
tun_event_handle
static event_t tun_event_handle(const struct tuntap *tt)
Definition: tun.h:738
ROUTE_ORDER_DEFAULT
#define ROUTE_ORDER_DEFAULT
Definition: tun.h:403
ROUTE_BEFORE_TUN
#define ROUTE_BEFORE_TUN
Definition: tun.h:401
tuntap_options::register_dns
bool register_dns
Definition: tun.h:141
networking.h
buffer::len
int len
Length in bytes of the actual content within the allocated memory.
Definition: buffer.h:66
tuntap_options::nbdd
in_addr_t nbdd[N_DHCP_ADDR]
Definition: tun.h:126
is_tun_p2p
bool is_tun_p2p(const struct tuntap *tt)
Definition: tun.c:748
tuntap_options::tap_sleep
int tap_sleep
Definition: tun.h:99
win32.h
tuntap_options::domain_search_list_len
int domain_search_list_len
Definition: tun.h:133
tuntap_is_wintun
static bool tuntap_is_wintun(struct tuntap *tt)
Definition: tun.h:265
es
struct env_set * es
Definition: test_pkcs11.c:141
tuntap_options::netbios_node_type
int netbios_node_type
Definition: tun.h:109
tuntap::type
int type
Definition: tun.h:183
TUN_PACKET::data
UCHAR data[WINTUN_MAX_PACKET_SIZE]
Definition: ring_buffer.h:80
close_tun
void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
Definition: tun.c:6928
tuntap::wintun_receive_ring
struct tun_ring * wintun_receive_ring
Definition: tun.h:237
wintun_ring_wrap
static ULONG wintun_ring_wrap(ULONG value)
Definition: tun.h:534
tuntap::wintun_send_ring
struct tun_ring * wintun_send_ring
Definition: tun.h:236
tuntap_abort
static bool tuntap_abort(int status)
Definition: tun.h:513
close_tun_handle
void close_tun_handle(struct tuntap *tt)
Definition: tun.c:6887
panel_reg
Definition: tun.h:429
tuntap_options::netbios_scope
const char * netbios_scope
Definition: tun.h:107
warn_on_use_of_common_subnets
void warn_on_use_of_common_subnets(openvpn_net_ctx_t *ctx)
Definition: tun.c:652
tuntap_options::ntp_len
int ntp_len
Definition: tun.h:123
DRIVER_AFUNIX
@ DRIVER_AFUNIX
using an AF_UNIX socket to pass packets from/to an external program.
Definition: tun.h:53
openvpn_net_ctx_t
void * openvpn_net_ctx_t
Definition: networking.h:28
D_LOW
#define D_LOW
Definition: errlevel.h:97
tun_standby_init
void tun_standby_init(struct tuntap *tt)
Definition: tun.c:5756
is_ip_packet_valid
static bool is_ip_packet_valid(const struct buffer *buf)
Definition: tun.h:596
EVENT_READ
#define EVENT_READ
Definition: event.h:39
dhcp_renew_by_adapter_index
bool dhcp_renew_by_adapter_index(const DWORD adapter_index)
Definition: tun.c:5225
tuntap::wintun_send_ring_handle
HANDLE wintun_send_ring_handle
Definition: tun.h:234
get_tun_adapter
const IP_ADAPTER_INFO * get_tun_adapter(const struct tuntap *tt, const IP_ADAPTER_INFO *list)
Definition: tun.c:4676
tun_write_win32
int tun_write_win32(struct tuntap *tt, struct buffer *buf)
Definition: tun.c:3691
init_tun_post
void init_tun_post(struct tuntap *tt, const struct frame *frame, const struct tuntap_options *options)
Definition: tun.c:962
write_wintun
static int write_wintun(struct tuntap *tt, struct buffer *buf)
Definition: tun.h:623
frame
Packet geometry parameters.
Definition: mtu.h:98
IFCONFIG_AFTER_TUN_OPEN
#define IFCONFIG_AFTER_TUN_OPEN
Definition: tun.h:371
N_SEARCH_LIST_LEN
#define N_SEARCH_LIST_LEN
Definition: tun.h:129
WINDOWS_DRIVER_UNSPECIFIED
@ WINDOWS_DRIVER_UNSPECIFIED
Definition: tun.h:46
TUN_PACKET_HEADER
Definition: ring_buffer.h:72
tuntap::backend_driver
enum tun_driver_type backend_driver
The backend driver that used for this tun/tap device.
Definition: tun.h:191
get_adapter
const IP_ADAPTER_INFO * get_adapter(const IP_ADAPTER_INFO *ai, DWORD index)
Definition: tun.c:4572
tuntap::actual_name
char * actual_name
Definition: tun.h:205
is_tun_type_set
static bool is_tun_type_set(const struct tuntap *tt)
Definition: tun.h:782
tun_read_queue
int tun_read_queue(struct tuntap *tt, int maxsize)
Definition: tun.c:3564
mtu.h
event_ctl
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
Definition: event.h:181
N_DHCP_ADDR
#define N_DHCP_ADDR
Definition: tun.h:111
tun_ring::tail
volatile ULONG tail
Definition: ring_buffer.h:53
get_adapter_info
const IP_ADAPTER_INFO * get_adapter_info(DWORD index, struct gc_arena *gc)
Definition: tun.c:4591
tuntap_defined
static bool tuntap_defined(const struct tuntap *tt)
Definition: tun.h:254
tuntap_options::ip_win32_defined
bool ip_win32_defined
Definition: tun.h:79
tuntap::did_ifconfig_ipv6_setup
bool did_ifconfig_ipv6_setup
if the internal variables related to ifconfig-ipv6 of this struct have been set up.
Definition: tun.h:199
string_alloc
char * string_alloc(const char *str, struct gc_arena *gc)
Definition: buffer.c:649
tap_reg::guid
const char * guid
Definition: tun.h:424
tuntap::hand
HANDLE hand
Definition: tun.h:216
tuntap::local_ipv6
struct in6_addr local_ipv6
Definition: tun.h:211
tuntap::rwflags_debug
unsigned int rwflags_debug
Definition: tun.h:247
is_dev_type
bool is_dev_type(const char *dev, const char *dev_type, const char *match_type)
Definition: tun.c:471
panel_reg::next
struct panel_reg * next
Definition: tun.h:433
tuntap::afunix
afunix_context_t afunix
Definition: tun.h:250
wintun_ring_packet_align
static ULONG wintun_ring_packet_align(ULONG size)
Definition: tun.h:528
tun_ring
Wintun ring buffer See https://github.com/WireGuard/wintun#ring-layout.
Definition: ring_buffer.h:50
tuntap_options::ip_win32_type
int ip_win32_type
Definition: tun.h:87
guess_tuntap_dev
const char * guess_tuntap_dev(const char *dev, const char *dev_type, const char *dev_node, struct gc_arena *gc)
Definition: tun.c:528
WINTUN_MAX_PACKET_SIZE
#define WINTUN_MAX_PACKET_SIZE
Definition: ring_buffer.h:41
afunix_context
Definition: tun.h:169
BLEN
#define BLEN(buf)
Definition: buffer.h:127
proto.h
dev_type_string
const char * dev_type_string(const char *dev, const char *dev_type)
Definition: tun.c:508
tun_standby
bool tun_standby(struct tuntap *tt)
Definition: tun.c:5762
tuntap::rw_handle
struct rw_handle rw_handle
Definition: tun.h:219
ipset2ascii
const char * ipset2ascii(int index)
Definition: tun.c:7046
tuntap::ipapi_instance
ULONG ipapi_instance
Definition: tun.h:225
TUN_PACKET
Definition: ring_buffer.h:77
misc.h
show_valid_win32_tun_subnets
void show_valid_win32_tun_subnets(void)
Definition: tun.c:4146
tap_reg::windows_driver
enum tun_driver_type windows_driver
Definition: tun.h:425
TUN_PACKET::size
uint32_t size
Definition: ring_buffer.h:79
ipconfig_register_dns
void ipconfig_register_dns(const struct env_set *es)
Definition: tun.c:5291
tuntap::adapter_index
DWORD adapter_index
Definition: tun.h:230
IFCONFIG_BEFORE_TUN_OPEN
#define IFCONFIG_BEFORE_TUN_OPEN
Definition: tun.h:370
options
Definition: options.h:249
tuntap::adapter_netmask
in_addr_t adapter_netmask
Definition: tun.h:226
WINDOWS_DRIVER_TAP_WINDOWS6
@ WINDOWS_DRIVER_TAP_WINDOWS6
Definition: tun.h:47
dco_context_t
void * dco_context_t
Definition: dco.h:267
tuntap_options
Definition: tun.h:77
tuntap_ring_empty
static bool tuntap_ring_empty(struct tuntap *tt)
Definition: tun.h:271
buffer
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
panel_reg::name
const char * name
Definition: tun.h:431
route_order
static int route_order(struct tuntap *tt)
Definition: tun.h:406
DRIVER_GENERIC_TUNTAP
@ DRIVER_GENERIC_TUNTAP
Definition: tun.h:49
show_adapters
void show_adapters(int msglev)
Definition: tun.c:5034
event.h
tuntap_options::msg_channel
HANDLE msg_channel
Definition: tun.h:90
buf_write
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Definition: buffer.h:668
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)
Definition: tun.c:4734
tap_reg::next
struct tap_reg * next
Definition: tun.h:426
DRIVER_UTUN
@ DRIVER_UTUN
macOS internal tun driver
Definition: tun.h:57
buffer.h
is_adapter_up
bool is_adapter_up(const struct tuntap *tt, const IP_ADAPTER_INFO *list)
Definition: tun.c:4689
get_adapter_info_list
const IP_ADAPTER_INFO * get_adapter_info_list(struct gc_arena *gc)
Definition: tun.c:4458
tuntap_options::wins_len
int wins_len
Definition: tun.h:119
BPTR
#define BPTR(buf)
Definition: buffer.h:124
afunix_context::childprocess
pid_t childprocess
Definition: tun.h:171
gc_arena
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
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)
Definition: tun.c:4767
tuntap_options::nbdd_len
int nbdd_len
Definition: tun.h:127
show_tap_win_adapters
void show_tap_win_adapters(int msglev, int warnlev)
Definition: tun.c:4179
tuntap::writes
struct overlapped_io writes
Definition: tun.h:218
openvpn_ipv6hdr
Definition: proto.h:121
ifconfig_order
static int ifconfig_order(struct tuntap *tt)
Definition: tun.h:376
ifconfig_options_string
const char * ifconfig_options_string(const struct tuntap *tt, bool remote, bool disable, struct gc_arena *gc)
Definition: tun.c:675
tuntap_options::dhcp_masq_offset
int dhcp_masq_offset
Definition: tun.h:95
env_set
Definition: env_set.h:42
print_tun_backend_driver
const char * print_tun_backend_driver(enum tun_driver_type driver)
Return a string representation of the tun backed driver type.
Definition: tun.c:59
ring_buffer.h
tuntap_options::disable_nbt
bool disable_nbt
Definition: tun.h:136
tuntap_options::dns6_len
int dns6_len
Definition: tun.h:144
dco.h
fork_register_dns_action
void fork_register_dns_action(struct tuntap *tt)
Definition: tun.c:6069
tuntap_is_dco_win_timeout
static bool tuntap_is_dco_win_timeout(struct tuntap *tt, int status)
Definition: tun.h:688
ascii2ipset
int ascii2ipset(const char *name)
Definition: tun.c:7031
tuntap::ipapi_context
ULONG ipapi_context
Definition: tun.h:224
event_set
Definition: event.h:130
tun_ring::alertable
volatile LONG alertable
Definition: ring_buffer.h:54
tuntap::local
in_addr_t local
Definition: tun.h:208
tuntap_options::dhcp_pre_release
bool dhcp_pre_release
Definition: tun.h:139
overlapped_io::buf_init
struct buffer buf_init
Definition: win32.h:217
tuntap_options::wins
in_addr_t wins[N_DHCP_ADDR]
Definition: tun.h:118
tuntap::dco
dco_context_t dco
Definition: tun.h:249
read_wintun
static void read_wintun(struct tuntap *tt, struct buffer *buf)
Definition: tun.h:540
dhcp_release_by_adapter_index
bool dhcp_release_by_adapter_index(const DWORD adapter_index)
Definition: tun.c:5185
panel_reg::guid
const char * guid
Definition: tun.h:432
tun_driver_type
tun_driver_type
Definition: tun.h:45
get_per_adapter_info
const IP_PER_ADAPTER_INFO * get_per_adapter_info(const DWORD index, struct gc_arena *gc)
Definition: tun.c:4485
OPENVPN_IPH_GET_VER
#define OPENVPN_IPH_GET_VER(v)
Definition: proto.h:93
openvpn_iphdr::version_len
uint8_t version_len
Definition: proto.h:95
status
static SERVICE_STATUS status
Definition: interactive.c:53
rw_handle::write
HANDLE write
Definition: win32.h:81
tuntap_options::dns6
struct in6_addr dns6[N_DHCP_ADDR]
Definition: tun.h:143
tuntap_options::domain
const char * domain
Definition: tun.h:105
tuntap::remote_netmask
in_addr_t remote_netmask
Definition: tun.h:209
WINDOWS_DRIVER_WINTUN
@ WINDOWS_DRIVER_WINTUN
Definition: tun.h:48
tuntap
Definition: tun.h:180
rw_handle
Definition: win32.h:79
tap_reg
Definition: tun.h:422
tuntap::remote_ipv6
struct in6_addr remote_ipv6
Definition: tun.h:212
tun_open_device
void tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_guid, struct gc_arena *gc)
Definition: tun.c:6587
tuntap_options::dhcp_lease_time
int dhcp_lease_time
Definition: tun.h:96
DRIVER_DCO
@ DRIVER_DCO
Definition: tun.h:55
device_instance_id_interface
Definition: tun.h:436
tuntap::netbits_ipv6
int netbits_ipv6
Definition: tun.h:213
tap_win_getinfo
const char * tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
Definition: tun.c:6792
tuntap_options::dns_len
int dns_len
Definition: tun.h:115
device_instance_id_interface::device_interface
const char * device_interface
Definition: tun.h:439
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
Definition: tun.c:1628
tuntap_options::dhcp_options
int dhcp_options
Definition: tun.h:103
dev_type_enum
int dev_type_enum(const char *dev, const char *dev_type)
Definition: tun.c:489
verify_255_255_255_252
void verify_255_255_255_252(in_addr_t local, in_addr_t remote)
Definition: tun.c:4109
tun_stat
const char * tun_stat(const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc)
Definition: tun.c:713
openvpn_errno
#define openvpn_errno()
Definition: error.h:72
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, openvpn_net_ctx_t *ctx)
openvpn_iphdr
Definition: proto.h:92
tuntap::persistent_if
bool persistent_if
Definition: tun.h:201
DEV_TYPE_UNDEF
#define DEV_TYPE_UNDEF
Definition: proto.h:35
tun_set
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition: tun.h:748
tun_name_is_fixed
bool tun_name_is_fixed(const char *dev)
Definition: tun.c:1852
ipset2ascii_all
const char * ipset2ascii_all(struct gc_arena *gc)
Definition: tun.c:7060
msg
#define msg(flags,...)
Definition: error.h:144
device_instance_id_interface::net_cfg_instance_id
LPBYTE net_cfg_instance_id
Definition: tun.h:438
tuntap_stop
static bool tuntap_stop(int status)
Definition: tun.h:499
tun_ring::data
UCHAR data[WINTUN_RING_CAPACITY+WINTUN_RING_TRAILING_BYTES]
Definition: ring_buffer.h:55
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, struct tuntap *tt)
Definition: tun.c:816
tuntap::topology
int topology
Definition: tun.h:186
IFCONFIG_DEFAULT
#define IFCONFIG_DEFAULT
Definition: tun.h:373
tap_allow_nonadmin_access
void tap_allow_nonadmin_access(const char *dev_node)
Definition: tun.c:5083
open_tun_null
static void open_tun_null(struct tuntap *tt)
Definition: tun.h:788
overlapped_io
Definition: win32.h:202
afunix_context_t
struct afunix_context afunix_context_t
tuntap_is_dco_win
static bool tuntap_is_dco_win(struct tuntap *tt)
Definition: tun.h:682
tuntap::ipapi_context_defined
bool ipapi_context_defined
Definition: tun.h:223
do_ifconfig_setenv
void do_ifconfig_setenv(const struct tuntap *tt, struct env_set *es)
Definition: tun.c:772
write_tun
int write_tun(struct tuntap *tt, uint8_t *buf, int len)
tuntap_options::ntp
in_addr_t ntp[N_DHCP_ADDR]
Definition: tun.h:122
tun_ring::head
volatile ULONG head
Definition: ring_buffer.h:52
tuntap::standby_iter
int standby_iter
Definition: tun.h:232
write_tun_buffered
static int write_tun_buffered(struct tuntap *tt, struct buffer *buf)
Definition: tun.h:669
undo_ifconfig
void undo_ifconfig(struct tuntap *tt, openvpn_net_ctx_t *ctx)
undo_ifconfig - undo configuration of the tunnel interface
Definition: tun.c:1727
tuntap::wintun_receive_ring_handle
HANDLE wintun_receive_ring_handle
Definition: tun.h:235
gc
struct gc_arena gc
Definition: test_ssl.c:155