OpenVPN
socket.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 SOCKET_H
25 #define SOCKET_H
26 
27 #include "buffer.h"
28 #include "common.h"
29 #include "error.h"
30 #include "proto.h"
31 #include "mtu.h"
32 #include "win32.h"
33 #include "event.h"
34 #include "proxy.h"
35 #include "socks.h"
36 #include "misc.h"
37 #include "tun.h"
38 
39 /*
40  * OpenVPN's default port number as assigned by IANA.
41  */
42 #define OPENVPN_PORT "1194"
43 
44 /*
45  * Number of seconds that "resolv-retry infinite"
46  * represents.
47  */
48 #define RESOLV_RETRY_INFINITE 1000000000
49 
50 /*
51  * packet_size_type is used to communicate packet size
52  * over the wire when stream oriented protocols are
53  * being used
54  */
55 
56 typedef uint16_t packet_size_type;
57 
58 /* convert a packet_size_type from host to network order */
59 #define htonps(x) htons(x)
60 
61 /* convert a packet_size_type from network to host order */
62 #define ntohps(x) ntohs(x)
63 
64 /* OpenVPN sockaddr struct */
66 {
67  /*int dummy;*/ /* add offset to force a bug if sa not explicitly dereferenced */
68  union {
69  struct sockaddr sa;
70  struct sockaddr_in in4;
71  struct sockaddr_in6 in6;
72  } addr;
73 };
74 
75 /* struct to hold preresolved host names */
77  const char *hostname;
78  const char *servname;
79  int ai_family;
80  int flags;
81  struct addrinfo *ai;
83 };
84 
85 /* actual address of remote, based on source address of received packets */
87 {
88  /*int dummy;*/ /* add offset to force a bug if dest not explicitly dereferenced */
89 
91 #if ENABLE_IP_PKTINFO
92  union {
93 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
94  struct in_pktinfo in4;
95 #elif defined(IP_RECVDSTADDR)
96  struct in_addr in4;
97 #endif
98  struct in6_pktinfo in6;
99  } pi;
100 #endif
101 };
102 
103 /* IP addresses which are persistent across SIGUSR1s */
105 {
106  struct addrinfo *bind_local;
107  struct addrinfo *remote_list; /* complete remote list */
108  struct addrinfo *current_remote; /* remote used in the
109  * current connection attempt */
110  struct link_socket_actual actual; /* reply to this address */
111 };
112 
114 {
117  const char *ipchange_command;
118  const struct plugin_list *plugins;
120  int proto; /* Protocol (PROTO_x defined below) */
121  sa_family_t af; /* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/
123  int mtu_changed; /* Set to true when mtu value is changed */
124 };
125 
126 /*
127  * Used to extract packets encapsulated in streams into a buffer,
128  * in this case IP packets embedded in a TCP stream.
129  */
131 {
132  struct buffer buf_init;
133  struct buffer residual;
134  int maxlen;
136 
137  struct buffer buf;
138  struct buffer next;
139  int len; /* -1 if not yet known */
140 
141  bool error; /* if true, fatal TCP error has occurred,
142  * requiring that connection be restarted */
143 #if PORT_SHARE
144 #define PS_DISABLED 0
145 #define PS_ENABLED 1
146 #define PS_FOREIGN 2
147  int port_share_state;
148 #endif
149 };
150 
151 /*
152  * Used to set socket buffer sizes
153  */
155 {
156  int rcvbuf;
157  int sndbuf;
158 };
159 
167 void
169  const struct socket_buffer_size *sbs,
170  bool reduce_size);
171 
172 /*
173  * This is the main socket structure used by OpenVPN. The SOCKET_
174  * defines try to abstract away our implementation differences between
175  * using sockets on Posix vs. Win32.
176  */
178 {
180 
181  struct event_arg ev_arg;
187  socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
188 
189 #ifdef _WIN32
193  struct rw_handle listen_handle; /* For listening on TCP socket in server mode */
194 #endif
195 
196  /* used for printing status info only */
197  unsigned int rwflags_debug;
198 
199  /* used for long-term queueing of pre-accepted socket listen */
201 
202  const char *remote_host;
203  const char *remote_port;
204  const char *local_host;
205  const char *local_port;
208 
209 #define LS_MODE_DEFAULT 0
210 #define LS_MODE_TCP_LISTEN 1
211 #define LS_MODE_TCP_ACCEPT_FROM 2
212  int mode;
213 
216 
218 
219  int mtu; /* OS discovered MTU, or 0 if unknown */
220 
221 #define SF_USE_IP_PKTINFO (1<<0)
222 #define SF_TCP_NODELAY (1<<1)
223 #define SF_PORT_SHARE (1<<2)
224 #define SF_HOST_RANDOMIZE (1<<3)
225 #define SF_GETADDRINFO_DGRAM (1<<4)
226 #define SF_DCO_WIN (1<<5)
227 #define SF_PREPEND_SA (1<<6)
228  unsigned int sockflags;
229  int mark;
230  const char *bind_dev;
231 
232  /* for stream sockets */
236 
237  /* HTTP proxy */
239 
240  /* Socks proxy */
242  struct link_socket_actual socks_relay; /* Socks UDP relay address */
243 
244  /* The OpenVPN server we will use the proxy to connect to */
245  const char *proxy_dest_host;
246  const char *proxy_dest_port;
247 
248  /* Pointer to the server-poll to trigger the timeout in function which have
249  * their own loop instead of using the main oop */
251 
252 #if PASSTOS_CAPABILITY
253  /* used to get/set TOS. */
254 #if defined(TARGET_LINUX)
255  uint8_t ptos;
256 #else /* all the BSDs, Solaris, MacOS use plain "int" -> see "man ip" there */
257  int ptos;
258 #endif
259  bool ptos_defined;
260 #endif
261 
262 #ifdef ENABLE_DEBUG
263  int gremlin; /* --gremlin bits */
264 #endif
265 };
266 
267 /*
268  * Some Posix/Win32 differences.
269  */
270 
271 #ifndef MSG_NOSIGNAL
272 #define MSG_NOSIGNAL 0
273 #endif
274 
275 #ifdef _WIN32
276 
277 #define openvpn_close_socket(s) closesocket(s)
278 
279 int socket_recv_queue(struct link_socket *sock, int maxsize);
280 
281 int socket_send_queue(struct link_socket *sock,
282  struct buffer *buf,
283  const struct link_socket_actual *to);
284 
285 typedef struct {
286  union {
287  SOCKET s;
288  HANDLE h;
289  };
290  bool is_handle;
291  bool prepend_sa; /* are incoming packets prepended with sockaddr? */
293 
295  struct overlapped_io *io,
296  struct buffer *buf,
297  struct link_socket_actual *from);
298 
299 static inline BOOL
301 {
302  return sh.is_handle ?
303  GetOverlappedResult(sh.h, &io->overlapped, &io->size, FALSE) :
304  WSAGetOverlappedResult(sh.s, &io->overlapped, &io->size, FALSE, &io->flags);
305 }
306 
307 static inline int
309 {
310  return sh.is_handle ? (int)GetLastError() : WSAGetLastError();
311 }
312 
313 inline static void
315 {
316  sh.is_handle ? SetLastError(err) : WSASetLastError(err);
317 }
318 
319 static inline void
321 {
322  sh.is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(WSAEINVAL);
323 }
324 
325 #else /* ifdef _WIN32 */
326 
327 #define openvpn_close_socket(s) close(s)
328 
329 #endif /* ifdef _WIN32 */
330 
331 struct link_socket *link_socket_new(void);
332 
334  struct addrinfo *local,
335  int af_family,
336  const char *prefix,
337  bool ipv6only);
338 
340  const struct sockaddr *remote,
341  int connect_timeout,
342  volatile int *signal_received);
343 
344 
345 
346 /*
347  * Initialize link_socket object.
348  */
349 void
351  int sock_index,
352  int mode);
353 
354 void link_socket_init_phase2(struct context *c,
355  struct link_socket *sock);
356 
357 void do_preresolve(struct context *c);
358 
359 void link_socket_close(struct link_socket *sock);
360 
362 
363 #define PS_SHOW_PORT_IF_DEFINED (1<<0)
364 #define PS_SHOW_PORT (1<<1)
365 #define PS_SHOW_PKTINFO (1<<2)
366 #define PS_DONT_SHOW_ADDR (1<<3)
367 #define PS_DONT_SHOW_FAMILY (1<<4)
368 
369 const char *print_sockaddr_ex(const struct sockaddr *addr,
370  const char *separator,
371  const unsigned int flags,
372  struct gc_arena *gc);
373 
374 static inline
375 const char *
377  struct gc_arena *gc)
378 {
379  return print_sockaddr_ex(&addr->addr.sa, ":", PS_SHOW_PORT, gc);
380 }
381 
382 static inline
383 const char *
384 print_sockaddr(const struct sockaddr *addr,
385  struct gc_arena *gc)
386 {
387  return print_sockaddr_ex(addr, ":", PS_SHOW_PORT, gc);
388 }
389 
390 
391 
392 const char *print_link_socket_actual_ex(const struct link_socket_actual *act,
393  const char *separator,
394  const unsigned int flags,
395  struct gc_arena *gc);
396 
397 const char *print_link_socket_actual(const struct link_socket_actual *act,
398  struct gc_arena *gc);
399 
400 
401 #define IA_EMPTY_IF_UNDEF (1<<0)
402 #define IA_NET_ORDER (1<<1)
403 const char *print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc);
404 
405 const char *print_in6_addr(struct in6_addr addr6, unsigned int flags, struct gc_arena *gc);
406 
407 const char *print_in_port_t(in_port_t port, struct gc_arena *gc);
408 
409 struct in6_addr add_in6_addr( struct in6_addr base, uint32_t add );
410 
411 #define SA_IP_PORT (1<<0)
412 #define SA_SET_IF_NONZERO (1<<1)
413 void setenv_sockaddr(struct env_set *es,
414  const char *name_prefix,
415  const struct openvpn_sockaddr *addr,
416  const unsigned int flags);
417 
418 void setenv_in_addr_t(struct env_set *es,
419  const char *name_prefix,
420  in_addr_t addr,
421  const unsigned int flags);
422 
423 void setenv_in6_addr(struct env_set *es,
424  const char *name_prefix,
425  const struct in6_addr *addr,
426  const unsigned int flags);
427 
429  const char *name_prefix,
430  const struct link_socket_actual *act,
431  const unsigned int flags);
432 
433 void bad_address_length(int actual, int expected);
434 
435 /* IPV4_INVALID_ADDR: returned by link_socket_current_remote()
436  * to ease redirect-gateway logic for ipv4 tunnels on ipv6 endpoints
437  */
438 #define IPV4_INVALID_ADDR 0xffffffff
439 in_addr_t link_socket_current_remote(const struct link_socket_info *info);
440 
441 const struct in6_addr *link_socket_current_remote_ipv6
442  (const struct link_socket_info *info);
443 
445  const struct link_socket_actual *addr,
446  const char *common_name,
447  struct env_set *es);
448 
449 void link_socket_bad_incoming_addr(struct buffer *buf,
450  const struct link_socket_info *info,
451  const struct link_socket_actual *from_addr);
452 
453 void set_actual_address(struct link_socket_actual *actual,
454  struct addrinfo *ai);
455 
457 
458 void setenv_trusted(struct env_set *es, const struct link_socket_info *info);
459 
460 bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags);
461 
462 void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf);
463 
464 /*
465  * Low-level functions
466  */
467 
468 /* return values of openvpn_inet_aton */
469 #define OIA_HOSTNAME 0
470 #define OIA_IP 1
471 #define OIA_ERROR -1
472 int openvpn_inet_aton(const char *dotted_quad, struct in_addr *addr);
473 
474 /* integrity validation on pulled options */
475 bool ip_addr_dotted_quad_safe(const char *dotted_quad);
476 
477 bool ip_or_dns_addr_safe(const char *addr, const bool allow_fqdn);
478 
479 bool mac_addr_safe(const char *mac_addr);
480 
481 bool ipv6_addr_safe(const char *ipv6_text_addr);
482 
483 socket_descriptor_t create_socket_tcp(struct addrinfo *);
484 
486  struct link_socket_actual *act,
487  const bool nowait);
488 
489 #if UNIX_SOCK_SUPPORT
490 
491 socket_descriptor_t create_socket_unix(void);
492 
493 void socket_bind_unix(socket_descriptor_t sd,
494  struct sockaddr_un *local,
495  const char *prefix);
496 
497 socket_descriptor_t socket_accept_unix(socket_descriptor_t sd,
498  struct sockaddr_un *remote);
499 
500 int socket_connect_unix(socket_descriptor_t sd,
501  struct sockaddr_un *remote);
502 
503 void sockaddr_unix_init(struct sockaddr_un *local, const char *path);
504 
505 const char *sockaddr_unix_name(const struct sockaddr_un *local, const char *null);
506 
507 void socket_delete_unix(const struct sockaddr_un *local);
508 
509 bool unix_socket_get_peer_uid_gid(const socket_descriptor_t sd, int *uid, int *gid);
510 
511 #endif /* if UNIX_SOCK_SUPPORT */
512 
513 /*
514  * DNS resolution
515  */
516 
517 #define GETADDR_RESOLVE (1<<0)
518 #define GETADDR_FATAL (1<<1)
519 #define GETADDR_HOST_ORDER (1<<2)
520 #define GETADDR_MENTION_RESOLVE_RETRY (1<<3)
521 #define GETADDR_FATAL_ON_SIGNAL (1<<4)
522 #define GETADDR_WARN_ON_SIGNAL (1<<5)
523 #define GETADDR_MSG_VIRT_OUT (1<<6)
524 #define GETADDR_TRY_ONCE (1<<7)
525 #define GETADDR_UPDATE_MANAGEMENT_STATE (1<<8)
526 #define GETADDR_RANDOMIZE (1<<9)
527 #define GETADDR_PASSIVE (1<<10)
528 #define GETADDR_DATAGRAM (1<<11)
529 
530 #define GETADDR_CACHE_MASK (GETADDR_DATAGRAM|GETADDR_PASSIVE)
531 
538 in_addr_t getaddr(unsigned int flags,
539  const char *hostname,
540  int resolve_retry_seconds,
541  bool *succeeded,
542  struct signal_info *sig_info);
543 
547 bool get_ipv6_addr(const char *hostname, struct in6_addr *network,
548  unsigned int *netbits, int msglevel);
549 
550 int openvpn_getaddrinfo(unsigned int flags,
551  const char *hostname,
552  const char *servname,
553  int resolve_retry_seconds,
554  struct signal_info *sig_info,
555  int ai_family,
556  struct addrinfo **res);
557 
558 /*
559  * Transport protocol naming and other details.
560  */
561 
562 /*
563  * Use enum's instead of #define to allow for easier
564  * optional proto support
565  */
566 enum proto_num {
567  PROTO_NONE, /* catch for uninitialized */
573 };
574 
575 static inline bool
576 proto_is_net(int proto)
577 {
578  ASSERT(proto >= 0 && proto < PROTO_N);
579  return proto != PROTO_NONE;
580 }
581 
585 static inline bool
586 proto_is_udp(int proto)
587 {
588  ASSERT(proto >= 0 && proto < PROTO_N);
589  return proto == PROTO_UDP;
590 }
591 
596 static inline bool
597 proto_is_dgram(int proto)
598 {
599  return proto_is_udp(proto);
600 }
601 
605 static inline bool
606 proto_is_tcp(int proto)
607 {
608  ASSERT(proto >= 0 && proto < PROTO_N);
609  return proto == PROTO_TCP_CLIENT || proto == PROTO_TCP_SERVER;
610 }
611 
612 
613 int ascii2proto(const char *proto_name);
614 
615 sa_family_t ascii2af(const char *proto_name);
616 
617 const char *proto2ascii(int proto, sa_family_t af, bool display_form);
618 
619 const char *proto2ascii_all(struct gc_arena *gc);
620 
621 const char *proto_remote(int proto, bool remote);
622 
623 const char *addr_family_name(int af);
624 
625 /*
626  * Overhead added to packets by various protocols.
627  */
628 static inline int
630 {
631  int overhead = 0;
632  overhead += (proto == PROTO_UDP) ? 8 : 20;
633  overhead += (af == AF_INET) ? 20 : 40;
634  return overhead;
635 }
636 
637 /*
638  * Misc inline functions
639  */
640 
641 static inline bool
643 {
644  return !proto_is_dgram(proto);
645 }
646 
647 static inline bool
649 {
650  if (sock)
651  {
653  }
654  else
655  {
656  return false;
657  }
658 }
659 
660 static inline bool
661 addr_defined(const struct openvpn_sockaddr *addr)
662 {
663  if (!addr)
664  {
665  return 0;
666  }
667  switch (addr->addr.sa.sa_family)
668  {
669  case AF_INET: return addr->addr.in4.sin_addr.s_addr != 0;
670 
671  case AF_INET6: return !IN6_IS_ADDR_UNSPECIFIED(&addr->addr.in6.sin6_addr);
672 
673  default: return 0;
674  }
675 }
676 
677 static inline bool
678 addr_local(const struct sockaddr *addr)
679 {
680  if (!addr)
681  {
682  return false;
683  }
684  switch (addr->sa_family)
685  {
686  case AF_INET:
687  return ((const struct sockaddr_in *)addr)->sin_addr.s_addr == htonl(INADDR_LOOPBACK);
688 
689  case AF_INET6:
690  return IN6_IS_ADDR_LOOPBACK(&((const struct sockaddr_in6 *)addr)->sin6_addr);
691 
692  default:
693  return false;
694  }
695 }
696 
697 
698 static inline bool
700 {
701 #if ENABLE_IP_PKTINFO
702  if (!lsa)
703  {
704  return 0;
705  }
706  switch (lsa->dest.addr.sa.sa_family)
707  {
708 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
709  case AF_INET: return lsa->pi.in4.ipi_spec_dst.s_addr != 0;
710 
711 #elif defined(IP_RECVDSTADDR)
712  case AF_INET: return lsa->pi.in4.s_addr != 0;
713 
714 #endif
715  case AF_INET6: return !IN6_IS_ADDR_UNSPECIFIED(&lsa->pi.in6.ipi6_addr);
716 
717  default: return 0;
718  }
719 #else /* if ENABLE_IP_PKTINFO */
720  ASSERT(0);
721 #endif
722  return false;
723 }
724 
725 static inline bool
727 {
728  return act && addr_defined(&act->dest);
729 }
730 
731 static inline bool
732 addr_match(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
733 {
734  switch (a1->addr.sa.sa_family)
735  {
736  case AF_INET:
737  return a1->addr.in4.sin_addr.s_addr == a2->addr.in4.sin_addr.s_addr;
738 
739  case AF_INET6:
740  return IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &a2->addr.in6.sin6_addr);
741  }
742  ASSERT(0);
743  return false;
744 }
745 
746 static inline bool
747 addrlist_match(const struct openvpn_sockaddr *a1, const struct addrinfo *addrlist)
748 {
749  const struct addrinfo *curele;
750  for (curele = addrlist; curele; curele = curele->ai_next)
751  {
752  switch (a1->addr.sa.sa_family)
753  {
754  case AF_INET:
755  if (a1->addr.in4.sin_addr.s_addr == ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr)
756  {
757  return true;
758  }
759  break;
760 
761  case AF_INET6:
762  if (IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &((struct sockaddr_in6 *) curele->ai_addr)->sin6_addr))
763  {
764  return true;
765  }
766  break;
767 
768  default:
769  ASSERT(0);
770  }
771  }
772  return false;
773 }
774 
775 static inline bool
776 addrlist_port_match(const struct openvpn_sockaddr *a1, const struct addrinfo *a2)
777 {
778  const struct addrinfo *curele;
779  for (curele = a2; curele; curele = curele->ai_next)
780  {
781  switch (a1->addr.sa.sa_family)
782  {
783  case AF_INET:
784  if (curele->ai_family == AF_INET
785  && a1->addr.in4.sin_addr.s_addr == ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr
786  && a1->addr.in4.sin_port == ((struct sockaddr_in *)curele->ai_addr)->sin_port)
787  {
788  return true;
789  }
790  break;
791 
792  case AF_INET6:
793  if (curele->ai_family == AF_INET6
794  && IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &((struct sockaddr_in6 *) curele->ai_addr)->sin6_addr)
795  && a1->addr.in6.sin6_port == ((struct sockaddr_in6 *) curele->ai_addr)->sin6_port)
796  {
797  return true;
798  }
799  break;
800 
801  default:
802  ASSERT(0);
803  }
804  }
805  return false;
806 }
807 
808 
809 
810 static inline bool
811 addr_port_match(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
812 {
813  switch (a1->addr.sa.sa_family)
814  {
815  case AF_INET:
816  return a1->addr.in4.sin_addr.s_addr == a2->addr.in4.sin_addr.s_addr
817  && a1->addr.in4.sin_port == a2->addr.in4.sin_port;
818 
819  case AF_INET6:
820  return IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &a2->addr.in6.sin6_addr)
821  && a1->addr.in6.sin6_port == a2->addr.in6.sin6_port;
822  }
823  ASSERT(0);
824  return false;
825 }
826 
827 static inline bool
829  const struct openvpn_sockaddr *a2,
830  const int proto)
831 {
833  ? addr_match(a1, a2)
834  : addr_port_match(a1, a2);
835 }
836 
837 
838 static inline bool
840  struct addrinfo *addr_list,
841  const int proto)
842 {
844  ? addrlist_match(a1, addr_list)
845  : addrlist_port_match(a1, addr_list);
846 }
847 
848 static inline void
850 {
851  switch (addr->addr.sa.sa_family)
852  {
853  case AF_INET:
854  addr->addr.in4.sin_addr.s_addr = 0;
855  break;
856 
857  case AF_INET6:
858  memset(&addr->addr.in6.sin6_addr, 0, sizeof(struct in6_addr));
859  break;
860  }
861 }
862 
863 static inline int
865 {
866  switch (af)
867  {
868  case AF_INET: return sizeof(struct sockaddr_in);
869 
870  case AF_INET6: return sizeof(struct sockaddr_in6);
871 
872  default:
873 #if 0
874  /* could be called from socket_do_accept() with empty addr */
875  msg(M_ERR, "Bad address family: %d\n", af);
876  ASSERT(0);
877 #endif
878  return 0;
879  }
880 }
881 
882 static inline bool
884 {
885  return addr_port_match(&a1->dest, &a2->dest);
886 }
887 
888 #if PORT_SHARE
889 
890 static inline bool
891 socket_foreign_protocol_detected(const struct link_socket *sock)
892 {
894  && sock->stream_buf.port_share_state == PS_FOREIGN;
895 }
896 
897 static inline const struct buffer *
898 socket_foreign_protocol_head(const struct link_socket *sock)
899 {
900  return &sock->stream_buf.buf;
901 }
902 
903 static inline int
904 socket_foreign_protocol_sd(const struct link_socket *sock)
905 {
906  return sock->sd;
907 }
908 
909 #endif /* if PORT_SHARE */
910 
911 static inline bool
913 {
915  {
916  if (sock->stream_reset || sock->stream_buf.error)
917  {
918  return true;
919  }
920  else if (status < 0)
921  {
922  const int err = openvpn_errno();
923 #ifdef _WIN32
924  return err == WSAECONNRESET || err == WSAECONNABORTED
925  || err == ERROR_CONNECTION_ABORTED;
926 #else
927  return err == ECONNRESET;
928 #endif
929  }
930  }
931  return false;
932 }
933 
934 static inline bool
936  const struct link_socket_info *info,
937  const struct link_socket_actual *from_addr)
938 {
939  if (buf->len > 0)
940  {
941  switch (from_addr->dest.addr.sa.sa_family)
942  {
943  case AF_INET6:
944  case AF_INET:
945  if (!link_socket_actual_defined(from_addr))
946  {
947  return false;
948  }
949  if (info->remote_float || (!info->lsa->remote_list))
950  {
951  return true;
952  }
953  if (addrlist_match_proto(&from_addr->dest, info->lsa->remote_list, info->proto))
954  {
955  return true;
956  }
957  }
958  }
959  return false;
960 }
961 
962 static inline void
964  const struct link_socket_info *info,
965  struct link_socket_actual **act)
966 {
967  if (buf->len > 0)
968  {
969  struct link_socket_addr *lsa = info->lsa;
971  {
972  *act = &lsa->actual;
973  }
974  else
975  {
977  buf->len = 0;
978  *act = NULL;
979  }
980  }
981 }
982 
983 static inline void
985  const struct link_socket_actual *act,
986  const char *common_name,
987  struct env_set *es)
988 {
989  struct link_socket_addr *lsa = info->lsa;
990  if (
991  /* new or changed address? */
992  (!info->connection_established
993  || !addr_match_proto(&act->dest, &lsa->actual.dest, info->proto)
994  )
995  &&
996  /* address undef or address == remote or --float */
997  (info->remote_float
998  || (!lsa->remote_list || addrlist_match_proto(&act->dest, lsa->remote_list, info->proto))
999  )
1000  )
1001  {
1002  link_socket_connection_initiated(info, act, common_name, es);
1003  }
1004 }
1005 
1006 bool stream_buf_read_setup_dowork(struct link_socket *sock);
1007 
1008 static inline bool
1010 {
1012  {
1013  return stream_buf_read_setup_dowork(sock);
1014  }
1015  else
1016  {
1017  return true;
1018  }
1019 }
1020 
1026 static inline bool
1028 {
1029  return s->sockflags & SF_DCO_WIN;
1030 }
1031 
1032 /*
1033  * Socket Read Routines
1034  */
1035 
1036 int link_socket_read_tcp(struct link_socket *sock,
1037  struct buffer *buf);
1038 
1039 #ifdef _WIN32
1040 
1041 static inline int
1043  struct buffer *buf,
1044  struct link_socket_actual *from)
1045 {
1046  sockethandle_t sh = { .s = sock->sd };
1047  if (socket_is_dco_win(sock))
1048  {
1049  *from = sock->info.lsa->actual;
1050  sh.is_handle = true;
1051  sh.prepend_sa = sock->sockflags & SF_PREPEND_SA;
1052  }
1053  return sockethandle_finalize(sh, &sock->reads, buf, from);
1054 }
1055 
1056 #else /* ifdef _WIN32 */
1057 
1058 int link_socket_read_udp_posix(struct link_socket *sock,
1059  struct buffer *buf,
1060  struct link_socket_actual *from);
1061 
1062 #endif /* ifdef _WIN32 */
1063 
1064 /* read a TCP or UDP packet from link */
1065 static inline int
1067  struct buffer *buf,
1068  struct link_socket_actual *from)
1069 {
1070  if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
1071  /* unified UDPv4 and UDPv6, for DCO-WIN the kernel
1072  * will strip the length header */
1073  {
1074  int res;
1075 
1076 #ifdef _WIN32
1077  res = link_socket_read_udp_win32(sock, buf, from);
1078 #else
1079  res = link_socket_read_udp_posix(sock, buf, from);
1080 #endif
1081  return res;
1082  }
1083  else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
1084  {
1085  /* from address was returned by accept */
1086  from->dest = sock->info.lsa->actual.dest;
1087  return link_socket_read_tcp(sock, buf);
1088  }
1089  else
1090  {
1091  ASSERT(0);
1092  return -1; /* NOTREACHED */
1093  }
1094 }
1095 
1096 /*
1097  * Socket Write routines
1098  */
1099 
1100 ssize_t link_socket_write_tcp(struct link_socket *sock,
1101  struct buffer *buf,
1102  struct link_socket_actual *to);
1103 
1104 #ifdef _WIN32
1105 
1106 static inline int
1108  struct buffer *buf,
1109  struct link_socket_actual *to)
1110 {
1111  int err = 0;
1112  int status = 0;
1113  sockethandle_t sh = { .s = sock->sd, .is_handle = socket_is_dco_win(sock) };
1114  if (overlapped_io_active(&sock->writes))
1115  {
1116  status = sockethandle_finalize(sh, &sock->writes, NULL, NULL);
1117  if (status < 0)
1118  {
1119  err = SocketHandleGetLastError(sh);
1120  }
1121  }
1122 
1123  /* dco-win mp requires control packets to be prepended with sockaddr */
1124  if (sock->sockflags & SF_PREPEND_SA)
1125  {
1126  if (to->dest.addr.sa.sa_family == AF_INET)
1127  {
1128  buf_write_prepend(buf, &to->dest.addr.in4, sizeof(struct sockaddr_in));
1129  }
1130  else
1131  {
1132  buf_write_prepend(buf, &to->dest.addr.in6, sizeof(struct sockaddr_in6));
1133  }
1134  }
1135 
1136  socket_send_queue(sock, buf, to);
1137  if (status < 0)
1138  {
1139  SocketHandleSetLastError(sh, err);
1140  return status;
1141  }
1142  else
1143  {
1144  return BLEN(buf);
1145  }
1146 }
1147 
1148 #else /* ifdef _WIN32 */
1149 
1150 ssize_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
1151  struct buffer *buf,
1152  struct link_socket_actual *to);
1153 
1154 
1155 static inline ssize_t
1156 link_socket_write_udp_posix(struct link_socket *sock,
1157  struct buffer *buf,
1158  struct link_socket_actual *to)
1159 {
1160 #if ENABLE_IP_PKTINFO
1161  if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
1162  && addr_defined_ipi(to))
1163  {
1164  return link_socket_write_udp_posix_sendmsg(sock, buf, to);
1165  }
1166  else
1167 #endif
1168  return sendto(sock->sd, BPTR(buf), BLEN(buf), 0,
1169  (struct sockaddr *) &to->dest.addr.sa,
1170  (socklen_t) af_addr_size(to->dest.addr.sa.sa_family));
1171 }
1172 
1173 static inline ssize_t
1174 link_socket_write_tcp_posix(struct link_socket *sock,
1175  struct buffer *buf)
1176 {
1177  return send(sock->sd, BPTR(buf), BLEN(buf), MSG_NOSIGNAL);
1178 }
1179 
1180 #endif /* ifdef _WIN32 */
1181 
1182 static inline ssize_t
1184  struct buffer *buf,
1185  struct link_socket_actual *to)
1186 {
1187 #ifdef _WIN32
1188  return link_socket_write_win32(sock, buf, to);
1189 #else
1190  return link_socket_write_udp_posix(sock, buf, to);
1191 #endif
1192 }
1193 
1194 /* write a TCP or UDP packet to link */
1195 static inline ssize_t
1197  struct buffer *buf,
1198  struct link_socket_actual *to)
1199 {
1200  if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
1201  {
1202  /* unified UDPv4, UDPv6 and DCO-WIN (driver adds length header) */
1203  return link_socket_write_udp(sock, buf, to);
1204  }
1205  else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
1206  {
1207  return link_socket_write_tcp(sock, buf, to);
1208  }
1209  else
1210  {
1211  ASSERT(0);
1212  return -1; /* NOTREACHED */
1213  }
1214 }
1215 
1216 #if PASSTOS_CAPABILITY
1217 
1218 /*
1219  * Extract TOS bits. Assumes that ipbuf is a valid IPv4 packet.
1220  */
1221 static inline void
1222 link_socket_extract_tos(struct link_socket *sock, const struct buffer *ipbuf)
1223 {
1224  if (sock && ipbuf)
1225  {
1226  struct openvpn_iphdr *iph = (struct openvpn_iphdr *) BPTR(ipbuf);
1227  sock->ptos = iph->tos;
1228  sock->ptos_defined = true;
1229  }
1230 }
1231 
1232 /*
1233  * Set socket properties to reflect TOS bits which were extracted
1234  * from tunnel packet.
1235  */
1236 static inline void
1237 link_socket_set_tos(struct link_socket *sock)
1238 {
1239  if (sock && sock->ptos_defined)
1240  {
1241  setsockopt(sock->sd, IPPROTO_IP, IP_TOS, (const void *)&sock->ptos, sizeof(sock->ptos));
1242  }
1243 }
1244 
1245 #endif /* if PASSTOS_CAPABILITY */
1246 
1247 /*
1248  * Socket I/O wait functions
1249  */
1250 
1251 /*
1252  * Extends the pre-existing read residual logic
1253  * to all initialized sockets, ensuring the complete
1254  * packet is read.
1255  */
1256 bool sockets_read_residual(const struct context *c);
1257 
1258 static inline event_t
1260 {
1261 #ifdef _WIN32
1262  return &sock->rw_handle;
1263 #else
1264  return sock->sd;
1265 #endif
1266 }
1267 
1269 
1270 unsigned int
1271 socket_set(struct link_socket *sock,
1272  struct event_set *es,
1273  unsigned int rwflags,
1274  void *arg,
1275  unsigned int *persistent);
1276 
1277 static inline void
1279  struct event_set *es,
1280  void *arg)
1281 {
1282  if (sock && !sock->listen_persistent_queued)
1283  {
1285  sock->listen_persistent_queued = true;
1286  }
1287 }
1288 
1289 static inline void
1291 {
1292 #ifdef _WIN32
1293  reset_net_event_win32(&sock->listen_handle, sock->sd);
1294 #endif
1295 }
1296 
1297 const char *socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc);
1298 
1299 #endif /* SOCKET_H */
overlapped_io_active
static bool overlapped_io_active(struct overlapped_io *o)
Definition: win32.h:228
cached_dns_entry::flags
int flags
Definition: socket.h:80
setenv_link_socket_actual
void setenv_link_socket_actual(struct env_set *es, const char *name_prefix, const struct link_socket_actual *act, const unsigned int flags)
Definition: socket.c:3147
link_socket_read
static int link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition: socket.h:1066
proto_num
proto_num
Definition: socket.h:566
bad_address_length
void bad_address_length(int actual, int expected)
Definition: socket.c:3302
socket_is_dco_win
static bool socket_is_dco_win(const struct link_socket *s)
Returns true if we are on Windows and this link is running on DCO-WIN.
Definition: socket.h:1027
IN6_ARE_ADDR_EQUAL
#define IN6_ARE_ADDR_EQUAL(a, b)
Definition: win32.h:52
error.h
link_socket_init_phase1
void link_socket_init_phase1(struct context *c, int sock_index, int mode)
Definition: socket.c:1894
cached_dns_entry::hostname
const char * hostname
Definition: socket.h:77
stream_buf::residual
struct buffer residual
Definition: socket.h:133
print_link_socket_actual_ex
const char * print_link_socket_actual_ex(const struct link_socket_actual *act, const char *separator, const unsigned int flags, struct gc_arena *gc)
Definition: socket.c:2920
sockethandle_t::h
HANDLE h
Definition: socket.h:288
print_sockaddr
static const char * print_sockaddr(const struct sockaddr *addr, struct gc_arena *gc)
Definition: socket.h:384
print_link_socket_actual
const char * print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena *gc)
Definition: socket.c:2910
link_socket_close
void link_socket_close(struct link_socket *sock)
Definition: socket.c:2384
buffer::len
int len
Length in bytes of the actual content within the allocated memory.
Definition: buffer.h:66
win32.h
socket_stat
const char * socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc)
Definition: socket.c:2612
socket_listen_event_handle
event_t socket_listen_event_handle(struct link_socket *sock)
Definition: socket.c:2811
link_socket_write_tcp
ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition: socket.c:3488
context
Contains all state information for one tunnel.
Definition: openvpn.h:473
es
struct env_set * es
Definition: test_pkcs11.c:141
stream_buf::buf_init
struct buffer buf_init
Definition: socket.h:132
addrlist_port_match
static bool addrlist_port_match(const struct openvpn_sockaddr *a1, const struct addrinfo *a2)
Definition: socket.h:776
sockets_read_residual
bool sockets_read_residual(const struct context *c)
Definition: socket.c:46
http_proxy_info
Definition: proxy.h:64
link_socket_proto_connection_oriented
static bool link_socket_proto_connection_oriented(int proto)
Definition: socket.h:642
setenv_in6_addr
void setenv_in6_addr(struct env_set *es, const char *name_prefix, const struct in6_addr *addr, const unsigned int flags)
Definition: socket.c:3131
create_socket_tcp
socket_descriptor_t create_socket_tcp(struct addrinfo *)
Definition: socket.c:1053
print_sockaddr_ex
const char * print_sockaddr_ex(const struct sockaddr *addr, const char *separator, const unsigned int flags, struct gc_arena *gc)
Definition: socket.c:2829
link_socket_init_phase2
void link_socket_init_phase2(struct context *c, struct link_socket *sock)
Definition: socket.c:2261
openvpn_sockaddr
Definition: socket.h:65
link_socket_verify_incoming_addr
static bool link_socket_verify_incoming_addr(struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
Definition: socket.h:935
EVENT_READ
#define EVENT_READ
Definition: event.h:39
sd_close
void sd_close(socket_descriptor_t *sd)
Definition: socket.c:4054
proto_is_dgram
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
Definition: socket.h:597
socket_set_buffers
void socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer_size *sbs, bool reduce_size)
Sets the receive and send buffer sizes of a socket descriptor.
Definition: socket.c:945
PROTO_N
@ PROTO_N
Definition: socket.h:572
proto2ascii
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
Definition: socket.c:3213
link_socket_update_flags
bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags)
Definition: socket.c:1023
overlapped_io::flags
DWORD flags
Definition: win32.h:209
link_socket_connection_oriented
static bool link_socket_connection_oriented(const struct link_socket *sock)
Definition: socket.h:648
PROTO_TCP_SERVER
@ PROTO_TCP_SERVER
Definition: socket.h:570
addr_zero_host
static void addr_zero_host(struct openvpn_sockaddr *addr)
Definition: socket.h:849
openvpn_sockaddr::in6
struct sockaddr_in6 in6
Definition: socket.h:71
link_socket_read_tcp
int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
Definition: socket.c:3314
sa_family_t
unsigned short sa_family_t
Definition: syshead.h:395
cached_dns_entry::servname
const char * servname
Definition: socket.h:78
link_socket_read_udp_win32
static int link_socket_read_udp_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition: socket.h:1042
addr_match
static bool addr_match(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
Definition: socket.h:732
mtu.h
link_socket_write_win32
static int link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition: socket.h:1107
event_ctl
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
Definition: event.h:181
overlapped_io::overlapped
OVERLAPPED overlapped
Definition: win32.h:207
SF_PREPEND_SA
#define SF_PREPEND_SA
Definition: socket.h:227
socket_set
unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition: socket.c:4017
PS_SHOW_PORT
#define PS_SHOW_PORT
Definition: socket.h:364
link_socket_actual_defined
static bool link_socket_actual_defined(const struct link_socket_actual *act)
Definition: socket.h:726
ASSERT
#define ASSERT(x)
Definition: error.h:195
ip_or_dns_addr_safe
bool ip_or_dns_addr_safe(const char *addr, const bool allow_fqdn)
Definition: socket.c:823
PROTO_TCP_CLIENT
@ PROTO_TCP_CLIENT
Definition: socket.h:571
tun.h
openvpn_sockaddr::sa
struct sockaddr sa
Definition: socket.h:69
BLEN
#define BLEN(buf)
Definition: buffer.h:127
proto.h
openvpn_getaddrinfo
int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname, int resolve_retry_seconds, struct signal_info *sig_info, int ai_family, struct addrinfo **res)
Definition: socket.c:469
socket_buffer_size
Definition: socket.h:154
buf_write_prepend
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
Definition: buffer.h:680
ascii2af
sa_family_t ascii2af(const char *proto_name)
Definition: socket.c:3200
socket_event_handle
static event_t socket_event_handle(const struct link_socket *sock)
Definition: socket.h:1259
addrlist_match
static bool addrlist_match(const struct openvpn_sockaddr *a1, const struct addrinfo *addrlist)
Definition: socket.h:747
openvpn_sockaddr::in4
struct sockaddr_in in4
Definition: socket.h:70
stream_buf::maxlen
int maxlen
Definition: socket.h:134
stream_buf_read_setup_dowork
bool stream_buf_read_setup_dowork(struct link_socket *sock)
Definition: socket.c:2713
misc.h
set_actual_address
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
Definition: socket.c:1583
print_in_addr_t
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
Definition: socket.c:2991
socket_buffer_size::rcvbuf
int rcvbuf
Definition: socket.h:156
SocketHandleGetLastError
static int SocketHandleGetLastError(sockethandle_t sh)
Definition: socket.h:308
getaddr
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, struct signal_info *sig_info)
Translate an IPv4 addr or hostname from string form to in_addr_t.
Definition: socket.c:195
sockethandle_finalize
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
Definition: socket.c:3922
link_socket_bad_incoming_addr
void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
Definition: socket.c:2509
M_ERR
#define M_ERR
Definition: error.h:105
stream_buf::residual_fully_formed
bool residual_fully_formed
Definition: socket.h:135
stream_buf::error
bool error
Definition: socket.h:141
cached_dns_entry::next
struct cached_dns_entry * next
Definition: socket.h:82
buffer
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
proto_is_udp
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
Definition: socket.h:586
addr_defined_ipi
static bool addr_defined_ipi(const struct link_socket_actual *lsa)
Definition: socket.h:699
print_in6_addr
const char * print_in6_addr(struct in6_addr addr6, unsigned int flags, struct gc_arena *gc)
Definition: socket.c:3011
event_arg
Definition: event.h:141
event.h
ipv6_addr_safe
bool ipv6_addr_safe(const char *ipv6_text_addr)
Definition: socket.c:787
proto2ascii_all
const char * proto2ascii_all(struct gc_arena *gc)
Definition: socket.c:3234
addr_port_match
static bool addr_port_match(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
Definition: socket.h:811
link_socket_set_outgoing_addr
static void link_socket_set_outgoing_addr(struct link_socket_info *info, const struct link_socket_actual *act, const char *common_name, struct env_set *es)
Definition: socket.h:984
PROTO_NONE
@ PROTO_NONE
Definition: socket.h:567
sockethandle_t::prepend_sa
bool prepend_sa
Definition: socket.h:291
buffer.h
proxy.h
BPTR
#define BPTR(buf)
Definition: buffer.h:124
stream_buf::next
struct buffer next
Definition: socket.h:138
proto_is_net
static bool proto_is_net(int proto)
Definition: socket.h:576
socket_recv_queue
int socket_recv_queue(struct link_socket *sock, int maxsize)
Definition: socket.c:3601
link_socket_update_buffer_sizes
void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf)
Definition: socket.c:1037
socket_buffer_size::sndbuf
int sndbuf
Definition: socket.h:157
socks_proxy_info
Definition: socks.h:37
socket_send_queue
int socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
Definition: socket.c:3718
gc_arena
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
cached_dns_entry
Definition: socket.h:76
proto_remote
const char * proto_remote(int proto, bool remote)
Definition: socket.c:3274
SocketHandleSetInvalError
static void SocketHandleSetInvalError(sockethandle_t sh)
Definition: socket.h:320
stream_buf
Definition: socket.h:130
link_socket_new
struct link_socket * link_socket_new(void)
Definition: socket.c:1880
ip_addr_dotted_quad_safe
bool ip_addr_dotted_quad_safe(const char *dotted_quad)
Definition: socket.c:737
get_ipv6_addr
bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
Translate an IPv6 addr or hostname from string form to in6_addr.
Definition: socket.c:226
env_set
Definition: env_set.h:42
setenv_sockaddr
void setenv_sockaddr(struct env_set *es, const char *name_prefix, const struct openvpn_sockaddr *addr, const unsigned int flags)
Definition: socket.c:3065
mac_addr_safe
bool mac_addr_safe(const char *mac_addr)
Definition: socket.c:840
do_preresolve
void do_preresolve(struct context *c)
Definition: socket.c:343
reset_net_event_win32
long reset_net_event_win32(struct rw_handle *event, socket_descriptor_t sd)
Definition: win32.c:262
plugin_list
Definition: plugin.h:94
sockethandle_t
Definition: socket.h:285
socket_descriptor_t
SOCKET socket_descriptor_t
Definition: syshead.h:439
common.h
openvpn_connect
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
Definition: socket.c:1488
event_set
Definition: event.h:130
addr_family_name
const char * addr_family_name(int af)
Definition: socket.c:3250
socket_set_listen_persistent
static void socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
Definition: socket.h:1278
SF_DCO_WIN
#define SF_DCO_WIN
Definition: socket.h:226
addr_defined
static bool addr_defined(const struct openvpn_sockaddr *addr)
Definition: socket.h:661
packet_size_type
uint16_t packet_size_type
Definition: socket.h:56
signal_info
Definition: sig.h:41
openvpn_inet_aton
int openvpn_inet_aton(const char *dotted_quad, struct in_addr *addr)
Definition: socket.c:713
SocketHandleSetLastError
static void SocketHandleSetLastError(sockethandle_t sh, DWORD err)
Definition: socket.h:314
stream_buf_read_setup
static bool stream_buf_read_setup(struct link_socket *sock)
Definition: socket.h:1009
status
static SERVICE_STATUS status
Definition: interactive.c:53
add_in6_addr
struct in6_addr add_in6_addr(struct in6_addr base, uint32_t add)
Definition: socket.c:3042
cached_dns_entry::ai
struct addrinfo * ai
Definition: socket.h:81
cached_dns_entry::ai_family
int ai_family
Definition: socket.h:79
socket_connection_reset
static bool socket_connection_reset(const struct link_socket *sock, int status)
Definition: socket.h:912
rw_handle
Definition: win32.h:79
addr_match_proto
static bool addr_match_proto(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2, const int proto)
Definition: socket.h:828
print_in_port_t
const char * print_in_port_t(in_port_t port, struct gc_arena *gc)
Definition: socket.c:3027
addrlist_match_proto
static bool addrlist_match_proto(const struct openvpn_sockaddr *a1, struct addrinfo *addr_list, const int proto)
Definition: socket.h:839
proto_is_tcp
static bool proto_is_tcp(int proto)
returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
Definition: socket.h:606
link_socket_current_remote
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
Definition: socket.c:2544
stream_buf::len
int len
Definition: socket.h:139
stream_buf::buf
struct buffer buf
Definition: socket.h:137
setenv_in_addr_t
void setenv_in_addr_t(struct env_set *es, const char *name_prefix, in_addr_t addr, const unsigned int flags)
Definition: socket.c:3118
SocketHandleGetOverlappedResult
static BOOL SocketHandleGetOverlappedResult(sockethandle_t sh, struct overlapped_io *io)
Definition: socket.h:300
event_timeout
Definition: interval.h:136
link_socket_current_remote_ipv6
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
Definition: socket.c:2579
link_socket_write_udp
static ssize_t link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition: socket.h:1183
setenv_trusted
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
Definition: socket.c:2436
MSG_NOSIGNAL
#define MSG_NOSIGNAL
Definition: socket.h:272
openvpn_errno
#define openvpn_errno()
Definition: error.h:72
datagram_overhead
static int datagram_overhead(sa_family_t af, int proto)
Definition: socket.h:629
openvpn_iphdr::tos
uint8_t tos
Definition: proto.h:97
link_socket_write
static ssize_t link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition: socket.h:1196
openvpn_iphdr
Definition: proto.h:92
link_socket_bad_outgoing_addr
void link_socket_bad_outgoing_addr(void)
Definition: socket.c:2538
SF_USE_IP_PKTINFO
#define SF_USE_IP_PKTINFO
Definition: socket.h:221
print_openvpn_sockaddr
static const char * print_openvpn_sockaddr(const struct openvpn_sockaddr *addr, struct gc_arena *gc)
Definition: socket.h:376
addr_local
static bool addr_local(const struct sockaddr *addr)
Definition: socket.h:678
af_addr_size
static int af_addr_size(sa_family_t af)
Definition: socket.h:864
ascii2proto
int ascii2proto(const char *proto_name)
Definition: socket.c:3187
link_socket_get_outgoing_addr
static void link_socket_get_outgoing_addr(struct buffer *buf, const struct link_socket_info *info, struct link_socket_actual **act)
Definition: socket.h:963
msg
#define msg(flags,...)
Definition: error.h:144
sockethandle_t::s
SOCKET s
Definition: socket.h:287
socket_do_accept
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
Definition: socket.c:1268
link_socket_connection_initiated
void link_socket_connection_initiated(struct link_socket_info *info, const struct link_socket_actual *addr, const char *common_name, struct env_set *es)
Definition: socket.c:2458
sockethandle_t::is_handle
bool is_handle
Definition: socket.h:290
overlapped_io::size
DWORD size
Definition: win32.h:208
overlapped_io
Definition: win32.h:202
socks.h
openvpn_sockaddr::addr
union openvpn_sockaddr::@20 addr
PROTO_UDP
@ PROTO_UDP
Definition: socket.h:568
socket_reset_listen_persistent
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition: socket.h:1290
PROTO_TCP
@ PROTO_TCP
Definition: socket.h:569
socket_bind
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix, bool ipv6only)
Definition: socket.c:1434
link_socket_actual_match
static bool link_socket_actual_match(const struct link_socket_actual *a1, const struct link_socket_actual *a2)
Definition: socket.h:883
gc
struct gc_arena gc
Definition: test_ssl.c:155