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 
160 /*
161  * This is the main socket structure used by OpenVPN. The SOCKET_
162  * defines try to abstract away our implementation differences between
163  * using sockets on Posix vs. Win32.
164  */
166 {
168 
170  socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
171 
172 #ifdef _WIN32
176  struct rw_handle listen_handle; /* For listening on TCP socket in server mode */
177 #endif
178 
179  /* used for printing status info only */
180  unsigned int rwflags_debug;
181 
182  /* used for long-term queueing of pre-accepted socket listen */
184 
185  const char *remote_host;
186  const char *remote_port;
187  const char *local_host;
188  const char *local_port;
191 
192 #define LS_MODE_DEFAULT 0
193 #define LS_MODE_TCP_LISTEN 1
194 #define LS_MODE_TCP_ACCEPT_FROM 2
195  int mode;
196 
199 
201 
202  int mtu; /* OS discovered MTU, or 0 if unknown */
203 
204 #define SF_USE_IP_PKTINFO (1<<0)
205 #define SF_TCP_NODELAY (1<<1)
206 #define SF_PORT_SHARE (1<<2)
207 #define SF_HOST_RANDOMIZE (1<<3)
208 #define SF_GETADDRINFO_DGRAM (1<<4)
209 #define SF_DCO_WIN (1<<5)
210  unsigned int sockflags;
211  int mark;
212  const char *bind_dev;
213 
214  /* for stream sockets */
218 
219  /* HTTP proxy */
221 
222  /* Socks proxy */
224  struct link_socket_actual socks_relay; /* Socks UDP relay address */
225 
226  /* The OpenVPN server we will use the proxy to connect to */
227  const char *proxy_dest_host;
228  const char *proxy_dest_port;
229 
230  /* Pointer to the server-poll to trigger the timeout in function which have
231  * their own loop instead of using the main oop */
233 
234 #if PASSTOS_CAPABILITY
235  /* used to get/set TOS. */
236 #if defined(TARGET_LINUX)
237  uint8_t ptos;
238 #else /* all the BSDs, Solaris, MacOS use plain "int" -> see "man ip" there */
239  int ptos;
240 #endif
241  bool ptos_defined;
242 #endif
243 
244 #ifdef ENABLE_DEBUG
245  int gremlin; /* --gremlin bits */
246 #endif
247 };
248 
249 /*
250  * Some Posix/Win32 differences.
251  */
252 
253 #ifndef MSG_NOSIGNAL
254 #define MSG_NOSIGNAL 0
255 #endif
256 
257 #ifdef _WIN32
258 
259 #define openvpn_close_socket(s) closesocket(s)
260 
261 int socket_recv_queue(struct link_socket *sock, int maxsize);
262 
263 int socket_send_queue(struct link_socket *sock,
264  struct buffer *buf,
265  const struct link_socket_actual *to);
266 
267 typedef struct {
268  union {
269  SOCKET s;
270  HANDLE h;
271  };
272  bool is_handle;
274 
276  struct overlapped_io *io,
277  struct buffer *buf,
278  struct link_socket_actual *from);
279 
280 static inline BOOL
282 {
283  return sh.is_handle ?
284  GetOverlappedResult(sh.h, &io->overlapped, &io->size, FALSE) :
285  WSAGetOverlappedResult(sh.s, &io->overlapped, &io->size, FALSE, &io->flags);
286 }
287 
288 static inline int
290 {
291  return sh.is_handle ? (int)GetLastError() : WSAGetLastError();
292 }
293 
294 inline static void
296 {
297  sh.is_handle ? SetLastError(err) : WSASetLastError(err);
298 }
299 
300 static inline void
302 {
303  sh.is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(WSAEINVAL);
304 }
305 
306 #else /* ifdef _WIN32 */
307 
308 #define openvpn_close_socket(s) close(s)
309 
310 #endif /* ifdef _WIN32 */
311 
312 struct link_socket *link_socket_new(void);
313 
315  struct addrinfo *local,
316  int af_family,
317  const char *prefix,
318  bool ipv6only);
319 
321  const struct sockaddr *remote,
322  int connect_timeout,
323  volatile int *signal_received);
324 
325 
326 
327 /*
328  * Initialize link_socket object.
329  */
330 void link_socket_init_phase1(struct context *c, int mode);
331 
332 void link_socket_init_phase2(struct context *c);
333 
334 void do_preresolve(struct context *c);
335 
336 void link_socket_close(struct link_socket *sock);
337 
339 
340 #define PS_SHOW_PORT_IF_DEFINED (1<<0)
341 #define PS_SHOW_PORT (1<<1)
342 #define PS_SHOW_PKTINFO (1<<2)
343 #define PS_DONT_SHOW_ADDR (1<<3)
344 #define PS_DONT_SHOW_FAMILY (1<<4)
345 
346 const char *print_sockaddr_ex(const struct sockaddr *addr,
347  const char *separator,
348  const unsigned int flags,
349  struct gc_arena *gc);
350 
351 static inline
352 const char *
354  const char *separator,
355  const unsigned int flags,
356  struct gc_arena *gc)
357 {
358  return print_sockaddr_ex(&addr->addr.sa, separator, flags, gc);
359 }
360 
361 static inline
362 const char *
364  struct gc_arena *gc)
365 {
366  return print_sockaddr_ex(&addr->addr.sa, ":", PS_SHOW_PORT, gc);
367 }
368 
369 static inline
370 const char *
371 print_sockaddr(const struct sockaddr *addr,
372  struct gc_arena *gc)
373 {
374  return print_sockaddr_ex(addr, ":", PS_SHOW_PORT, gc);
375 }
376 
377 
378 
379 const char *print_link_socket_actual_ex(const struct link_socket_actual *act,
380  const char *separator,
381  const unsigned int flags,
382  struct gc_arena *gc);
383 
384 const char *print_link_socket_actual(const struct link_socket_actual *act,
385  struct gc_arena *gc);
386 
387 
388 #define IA_EMPTY_IF_UNDEF (1<<0)
389 #define IA_NET_ORDER (1<<1)
390 const char *print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc);
391 
392 const char *print_in6_addr(struct in6_addr addr6, unsigned int flags, struct gc_arena *gc);
393 
394 const char *print_in_port_t(in_port_t port, struct gc_arena *gc);
395 
396 struct in6_addr add_in6_addr( struct in6_addr base, uint32_t add );
397 
398 #define SA_IP_PORT (1<<0)
399 #define SA_SET_IF_NONZERO (1<<1)
400 void setenv_sockaddr(struct env_set *es,
401  const char *name_prefix,
402  const struct openvpn_sockaddr *addr,
403  const unsigned int flags);
404 
405 void setenv_in_addr_t(struct env_set *es,
406  const char *name_prefix,
407  in_addr_t addr,
408  const unsigned int flags);
409 
410 void setenv_in6_addr(struct env_set *es,
411  const char *name_prefix,
412  const struct in6_addr *addr,
413  const unsigned int flags);
414 
416  const char *name_prefix,
417  const struct link_socket_actual *act,
418  const unsigned int flags);
419 
420 void bad_address_length(int actual, int expected);
421 
422 /* IPV4_INVALID_ADDR: returned by link_socket_current_remote()
423  * to ease redirect-gateway logic for ipv4 tunnels on ipv6 endpoints
424  */
425 #define IPV4_INVALID_ADDR 0xffffffff
426 in_addr_t link_socket_current_remote(const struct link_socket_info *info);
427 
428 const struct in6_addr *link_socket_current_remote_ipv6
429  (const struct link_socket_info *info);
430 
432  const struct link_socket_actual *addr,
433  const char *common_name,
434  struct env_set *es);
435 
436 void link_socket_bad_incoming_addr(struct buffer *buf,
437  const struct link_socket_info *info,
438  const struct link_socket_actual *from_addr);
439 
440 void set_actual_address(struct link_socket_actual *actual,
441  struct addrinfo *ai);
442 
444 
445 void setenv_trusted(struct env_set *es, const struct link_socket_info *info);
446 
447 bool link_socket_update_flags(struct link_socket *ls, unsigned int sockflags);
448 
449 void link_socket_update_buffer_sizes(struct link_socket *ls, int rcvbuf, int sndbuf);
450 
451 /*
452  * Low-level functions
453  */
454 
455 /* return values of openvpn_inet_aton */
456 #define OIA_HOSTNAME 0
457 #define OIA_IP 1
458 #define OIA_ERROR -1
459 int openvpn_inet_aton(const char *dotted_quad, struct in_addr *addr);
460 
461 /* integrity validation on pulled options */
462 bool ip_addr_dotted_quad_safe(const char *dotted_quad);
463 
464 bool ip_or_dns_addr_safe(const char *addr, const bool allow_fqdn);
465 
466 bool mac_addr_safe(const char *mac_addr);
467 
468 bool ipv6_addr_safe(const char *ipv6_text_addr);
469 
470 socket_descriptor_t create_socket_tcp(struct addrinfo *);
471 
473  struct link_socket_actual *act,
474  const bool nowait);
475 
476 #if UNIX_SOCK_SUPPORT
477 
478 socket_descriptor_t create_socket_unix(void);
479 
480 void socket_bind_unix(socket_descriptor_t sd,
481  struct sockaddr_un *local,
482  const char *prefix);
483 
484 socket_descriptor_t socket_accept_unix(socket_descriptor_t sd,
485  struct sockaddr_un *remote);
486 
487 int socket_connect_unix(socket_descriptor_t sd,
488  struct sockaddr_un *remote);
489 
490 void sockaddr_unix_init(struct sockaddr_un *local, const char *path);
491 
492 const char *sockaddr_unix_name(const struct sockaddr_un *local, const char *null);
493 
494 void socket_delete_unix(const struct sockaddr_un *local);
495 
496 bool unix_socket_get_peer_uid_gid(const socket_descriptor_t sd, int *uid, int *gid);
497 
498 #endif /* if UNIX_SOCK_SUPPORT */
499 
500 /*
501  * DNS resolution
502  */
503 
504 #define GETADDR_RESOLVE (1<<0)
505 #define GETADDR_FATAL (1<<1)
506 #define GETADDR_HOST_ORDER (1<<2)
507 #define GETADDR_MENTION_RESOLVE_RETRY (1<<3)
508 #define GETADDR_FATAL_ON_SIGNAL (1<<4)
509 #define GETADDR_WARN_ON_SIGNAL (1<<5)
510 #define GETADDR_MSG_VIRT_OUT (1<<6)
511 #define GETADDR_TRY_ONCE (1<<7)
512 #define GETADDR_UPDATE_MANAGEMENT_STATE (1<<8)
513 #define GETADDR_RANDOMIZE (1<<9)
514 #define GETADDR_PASSIVE (1<<10)
515 #define GETADDR_DATAGRAM (1<<11)
516 
517 #define GETADDR_CACHE_MASK (GETADDR_DATAGRAM|GETADDR_PASSIVE)
518 
525 in_addr_t getaddr(unsigned int flags,
526  const char *hostname,
527  int resolve_retry_seconds,
528  bool *succeeded,
529  struct signal_info *sig_info);
530 
534 bool get_ipv6_addr(const char *hostname, struct in6_addr *network,
535  unsigned int *netbits, int msglevel);
536 
537 int openvpn_getaddrinfo(unsigned int flags,
538  const char *hostname,
539  const char *servname,
540  int resolve_retry_seconds,
541  struct signal_info *sig_info,
542  int ai_family,
543  struct addrinfo **res);
544 
545 /*
546  * Transport protocol naming and other details.
547  */
548 
549 /*
550  * Use enum's instead of #define to allow for easier
551  * optional proto support
552  */
553 enum proto_num {
554  PROTO_NONE, /* catch for uninitialized */
560 };
561 
562 static inline bool
563 proto_is_net(int proto)
564 {
565  ASSERT(proto >= 0 && proto < PROTO_N);
566  return proto != PROTO_NONE;
567 }
568 
572 static inline bool
573 proto_is_udp(int proto)
574 {
575  ASSERT(proto >= 0 && proto < PROTO_N);
576  return proto == PROTO_UDP;
577 }
578 
583 static inline bool
584 proto_is_dgram(int proto)
585 {
586  return proto_is_udp(proto);
587 }
588 
592 static inline bool
593 proto_is_tcp(int proto)
594 {
595  ASSERT(proto >= 0 && proto < PROTO_N);
596  return proto == PROTO_TCP_CLIENT || proto == PROTO_TCP_SERVER;
597 }
598 
599 
600 int ascii2proto(const char *proto_name);
601 
602 sa_family_t ascii2af(const char *proto_name);
603 
604 const char *proto2ascii(int proto, sa_family_t af, bool display_form);
605 
606 const char *proto2ascii_all(struct gc_arena *gc);
607 
608 const char *proto_remote(int proto, bool remote);
609 
610 const char *addr_family_name(int af);
611 
612 /*
613  * Overhead added to packets by various protocols.
614  */
615 static inline int
617 {
618  int overhead = 0;
619  overhead += (proto == PROTO_UDP) ? 8 : 20;
620  overhead += (af == AF_INET) ? 20 : 40;
621  return overhead;
622 }
623 
624 /*
625  * Misc inline functions
626  */
627 
628 static inline bool
630 {
631  return !proto_is_dgram(proto);
632 }
633 
634 static inline bool
636 {
637  if (sock)
638  {
640  }
641  else
642  {
643  return false;
644  }
645 }
646 
647 static inline bool
648 addr_defined(const struct openvpn_sockaddr *addr)
649 {
650  if (!addr)
651  {
652  return 0;
653  }
654  switch (addr->addr.sa.sa_family)
655  {
656  case AF_INET: return addr->addr.in4.sin_addr.s_addr != 0;
657 
658  case AF_INET6: return !IN6_IS_ADDR_UNSPECIFIED(&addr->addr.in6.sin6_addr);
659 
660  default: return 0;
661  }
662 }
663 
664 static inline bool
665 addr_local(const struct sockaddr *addr)
666 {
667  if (!addr)
668  {
669  return false;
670  }
671  switch (addr->sa_family)
672  {
673  case AF_INET:
674  return ((const struct sockaddr_in *)addr)->sin_addr.s_addr == htonl(INADDR_LOOPBACK);
675 
676  case AF_INET6:
677  return IN6_IS_ADDR_LOOPBACK(&((const struct sockaddr_in6 *)addr)->sin6_addr);
678 
679  default:
680  return false;
681  }
682 }
683 
684 
685 static inline bool
687 {
688 #if ENABLE_IP_PKTINFO
689  if (!lsa)
690  {
691  return 0;
692  }
693  switch (lsa->dest.addr.sa.sa_family)
694  {
695 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
696  case AF_INET: return lsa->pi.in4.ipi_spec_dst.s_addr != 0;
697 
698 #elif defined(IP_RECVDSTADDR)
699  case AF_INET: return lsa->pi.in4.s_addr != 0;
700 
701 #endif
702  case AF_INET6: return !IN6_IS_ADDR_UNSPECIFIED(&lsa->pi.in6.ipi6_addr);
703 
704  default: return 0;
705  }
706 #else /* if ENABLE_IP_PKTINFO */
707  ASSERT(0);
708 #endif
709  return false;
710 }
711 
712 static inline bool
714 {
715  return act && addr_defined(&act->dest);
716 }
717 
718 static inline bool
719 addr_match(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
720 {
721  switch (a1->addr.sa.sa_family)
722  {
723  case AF_INET:
724  return a1->addr.in4.sin_addr.s_addr == a2->addr.in4.sin_addr.s_addr;
725 
726  case AF_INET6:
727  return IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &a2->addr.in6.sin6_addr);
728  }
729  ASSERT(0);
730  return false;
731 }
732 
733 static inline bool
734 addrlist_match(const struct openvpn_sockaddr *a1, const struct addrinfo *addrlist)
735 {
736  const struct addrinfo *curele;
737  for (curele = addrlist; curele; curele = curele->ai_next)
738  {
739  switch (a1->addr.sa.sa_family)
740  {
741  case AF_INET:
742  if (a1->addr.in4.sin_addr.s_addr == ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr)
743  {
744  return true;
745  }
746  break;
747 
748  case AF_INET6:
749  if (IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &((struct sockaddr_in6 *) curele->ai_addr)->sin6_addr))
750  {
751  return true;
752  }
753  break;
754 
755  default:
756  ASSERT(0);
757  }
758  }
759  return false;
760 }
761 
762 static inline in_addr_t
763 addr_host(const struct openvpn_sockaddr *addr)
764 {
765  /*
766  * "public" addr returned is checked against ifconfig for
767  * possible clash: non sense for now given
768  * that we do ifconfig only IPv4
769  */
770  if (addr->addr.sa.sa_family != AF_INET)
771  {
772  return 0;
773  }
774  return ntohl(addr->addr.in4.sin_addr.s_addr);
775 }
776 
777 
778 static inline bool
779 addrlist_port_match(const struct openvpn_sockaddr *a1, const struct addrinfo *a2)
780 {
781  const struct addrinfo *curele;
782  for (curele = a2; curele; curele = curele->ai_next)
783  {
784  switch (a1->addr.sa.sa_family)
785  {
786  case AF_INET:
787  if (curele->ai_family == AF_INET
788  && a1->addr.in4.sin_addr.s_addr == ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr
789  && a1->addr.in4.sin_port == ((struct sockaddr_in *)curele->ai_addr)->sin_port)
790  {
791  return true;
792  }
793  break;
794 
795  case AF_INET6:
796  if (curele->ai_family == AF_INET6
797  && IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &((struct sockaddr_in6 *) curele->ai_addr)->sin6_addr)
798  && a1->addr.in6.sin6_port == ((struct sockaddr_in6 *) curele->ai_addr)->sin6_port)
799  {
800  return true;
801  }
802  break;
803 
804  default:
805  ASSERT(0);
806  }
807  }
808  return false;
809 }
810 
811 
812 
813 static inline bool
814 addr_port_match(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
815 {
816  switch (a1->addr.sa.sa_family)
817  {
818  case AF_INET:
819  return a1->addr.in4.sin_addr.s_addr == a2->addr.in4.sin_addr.s_addr
820  && a1->addr.in4.sin_port == a2->addr.in4.sin_port;
821 
822  case AF_INET6:
823  return IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &a2->addr.in6.sin6_addr)
824  && a1->addr.in6.sin6_port == a2->addr.in6.sin6_port;
825  }
826  ASSERT(0);
827  return false;
828 }
829 
830 static inline bool
832  const struct openvpn_sockaddr *a2,
833  const int proto)
834 {
836  ? addr_match(a1, a2)
837  : addr_port_match(a1, a2);
838 }
839 
840 
841 static inline bool
843  struct addrinfo *addr_list,
844  const int proto)
845 {
847  ? addrlist_match(a1, addr_list)
848  : addrlist_port_match(a1, addr_list);
849 }
850 
851 static inline void
853 {
854  switch (addr->addr.sa.sa_family)
855  {
856  case AF_INET:
857  addr->addr.in4.sin_addr.s_addr = 0;
858  break;
859 
860  case AF_INET6:
861  memset(&addr->addr.in6.sin6_addr, 0, sizeof(struct in6_addr));
862  break;
863  }
864 }
865 
866 static inline int
868 {
869  switch (af)
870  {
871  case AF_INET: return sizeof(struct sockaddr_in);
872 
873  case AF_INET6: return sizeof(struct sockaddr_in6);
874 
875  default:
876 #if 0
877  /* could be called from socket_do_accept() with empty addr */
878  msg(M_ERR, "Bad address family: %d\n", af);
879  ASSERT(0);
880 #endif
881  return 0;
882  }
883 }
884 
885 static inline bool
887 {
888  return addr_port_match(&a1->dest, &a2->dest);
889 }
890 
891 #if PORT_SHARE
892 
893 static inline bool
894 socket_foreign_protocol_detected(const struct link_socket *sock)
895 {
897  && sock->stream_buf.port_share_state == PS_FOREIGN;
898 }
899 
900 static inline const struct buffer *
901 socket_foreign_protocol_head(const struct link_socket *sock)
902 {
903  return &sock->stream_buf.buf;
904 }
905 
906 static inline int
907 socket_foreign_protocol_sd(const struct link_socket *sock)
908 {
909  return sock->sd;
910 }
911 
912 #endif /* if PORT_SHARE */
913 
914 static inline bool
916 {
918  {
919  if (sock->stream_reset || sock->stream_buf.error)
920  {
921  return true;
922  }
923  else if (status < 0)
924  {
925  const int err = openvpn_errno();
926 #ifdef _WIN32
927  return err == WSAECONNRESET || err == WSAECONNABORTED
928  || err == ERROR_CONNECTION_ABORTED;
929 #else
930  return err == ECONNRESET;
931 #endif
932  }
933  }
934  return false;
935 }
936 
937 static inline bool
939  const struct link_socket_info *info,
940  const struct link_socket_actual *from_addr)
941 {
942  if (buf->len > 0)
943  {
944  switch (from_addr->dest.addr.sa.sa_family)
945  {
946  case AF_INET6:
947  case AF_INET:
948  if (!link_socket_actual_defined(from_addr))
949  {
950  return false;
951  }
952  if (info->remote_float || (!info->lsa->remote_list))
953  {
954  return true;
955  }
956  if (addrlist_match_proto(&from_addr->dest, info->lsa->remote_list, info->proto))
957  {
958  return true;
959  }
960  }
961  }
962  return false;
963 }
964 
965 static inline void
967  const struct link_socket_info *info,
968  struct link_socket_actual **act)
969 {
970  if (buf->len > 0)
971  {
972  struct link_socket_addr *lsa = info->lsa;
974  {
975  *act = &lsa->actual;
976  }
977  else
978  {
980  buf->len = 0;
981  *act = NULL;
982  }
983  }
984 }
985 
986 static inline void
988  const struct link_socket_actual *act,
989  const char *common_name,
990  struct env_set *es)
991 {
992  struct link_socket_addr *lsa = info->lsa;
993  if (
994  /* new or changed address? */
995  (!info->connection_established
996  || !addr_match_proto(&act->dest, &lsa->actual.dest, info->proto)
997  )
998  &&
999  /* address undef or address == remote or --float */
1000  (info->remote_float
1001  || (!lsa->remote_list || addrlist_match_proto(&act->dest, lsa->remote_list, info->proto))
1002  )
1003  )
1004  {
1005  link_socket_connection_initiated(info, act, common_name, es);
1006  }
1007 }
1008 
1009 bool stream_buf_read_setup_dowork(struct link_socket *sock);
1010 
1011 static inline bool
1013 {
1015  {
1016  return stream_buf_read_setup_dowork(sock);
1017  }
1018  else
1019  {
1020  return true;
1021  }
1022 }
1023 
1029 static inline bool
1031 {
1032  return s->sockflags & SF_DCO_WIN;
1033 }
1034 
1035 /*
1036  * Socket Read Routines
1037  */
1038 
1039 int link_socket_read_tcp(struct link_socket *sock,
1040  struct buffer *buf);
1041 
1042 #ifdef _WIN32
1043 
1044 static inline int
1046  struct buffer *buf,
1047  struct link_socket_actual *from)
1048 {
1049  sockethandle_t sh = { .s = sock->sd };
1050  if (socket_is_dco_win(sock))
1051  {
1052  *from = sock->info.lsa->actual;
1053  sh.is_handle = true;
1054  }
1055  return sockethandle_finalize(sh, &sock->reads, buf, from);
1056 }
1057 
1058 #else /* ifdef _WIN32 */
1059 
1060 int link_socket_read_udp_posix(struct link_socket *sock,
1061  struct buffer *buf,
1062  struct link_socket_actual *from);
1063 
1064 #endif /* ifdef _WIN32 */
1065 
1066 /* read a TCP or UDP packet from link */
1067 static inline int
1069  struct buffer *buf,
1070  struct link_socket_actual *from)
1071 {
1072  if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
1073  /* unified UDPv4 and UDPv6, for DCO-WIN the kernel
1074  * will strip the length header */
1075  {
1076  int res;
1077 
1078 #ifdef _WIN32
1079  res = link_socket_read_udp_win32(sock, buf, from);
1080 #else
1081  res = link_socket_read_udp_posix(sock, buf, from);
1082 #endif
1083  return res;
1084  }
1085  else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
1086  {
1087  /* from address was returned by accept */
1088  from->dest = sock->info.lsa->actual.dest;
1089  return link_socket_read_tcp(sock, buf);
1090  }
1091  else
1092  {
1093  ASSERT(0);
1094  return -1; /* NOTREACHED */
1095  }
1096 }
1097 
1098 /*
1099  * Socket Write routines
1100  */
1101 
1102 int link_socket_write_tcp(struct link_socket *sock,
1103  struct buffer *buf,
1104  struct link_socket_actual *to);
1105 
1106 #ifdef _WIN32
1107 
1108 static inline int
1110  struct buffer *buf,
1111  struct link_socket_actual *to)
1112 {
1113  int err = 0;
1114  int status = 0;
1115  sockethandle_t sh = { .s = sock->sd, .is_handle = socket_is_dco_win(sock) };
1116  if (overlapped_io_active(&sock->writes))
1117  {
1118  status = sockethandle_finalize(sh, &sock->writes, NULL, NULL);
1119  if (status < 0)
1120  {
1121  err = SocketHandleGetLastError(sh);
1122  }
1123  }
1124  socket_send_queue(sock, buf, to);
1125  if (status < 0)
1126  {
1127  SocketHandleSetLastError(sh, err);
1128  return status;
1129  }
1130  else
1131  {
1132  return BLEN(buf);
1133  }
1134 }
1135 
1136 #else /* ifdef _WIN32 */
1137 
1138 size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
1139  struct buffer *buf,
1140  struct link_socket_actual *to);
1141 
1142 
1143 static inline size_t
1144 link_socket_write_udp_posix(struct link_socket *sock,
1145  struct buffer *buf,
1146  struct link_socket_actual *to)
1147 {
1148 #if ENABLE_IP_PKTINFO
1149  if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
1150  && addr_defined_ipi(to))
1151  {
1152  return link_socket_write_udp_posix_sendmsg(sock, buf, to);
1153  }
1154  else
1155 #endif
1156  return sendto(sock->sd, BPTR(buf), BLEN(buf), 0,
1157  (struct sockaddr *) &to->dest.addr.sa,
1158  (socklen_t) af_addr_size(to->dest.addr.sa.sa_family));
1159 }
1160 
1161 static inline size_t
1162 link_socket_write_tcp_posix(struct link_socket *sock,
1163  struct buffer *buf,
1164  struct link_socket_actual *to)
1165 {
1166  return send(sock->sd, BPTR(buf), BLEN(buf), MSG_NOSIGNAL);
1167 }
1168 
1169 #endif /* ifdef _WIN32 */
1170 
1171 static inline size_t
1173  struct buffer *buf,
1174  struct link_socket_actual *to)
1175 {
1176 #ifdef _WIN32
1177  return link_socket_write_win32(sock, buf, to);
1178 #else
1179  return link_socket_write_udp_posix(sock, buf, to);
1180 #endif
1181 }
1182 
1183 /* write a TCP or UDP packet to link */
1184 static inline int
1186  struct buffer *buf,
1187  struct link_socket_actual *to)
1188 {
1189  if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
1190  {
1191  /* unified UDPv4, UDPv6 and DCO-WIN (driver adds length header) */
1192  return link_socket_write_udp(sock, buf, to);
1193  }
1194  else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
1195  {
1196  return link_socket_write_tcp(sock, buf, to);
1197  }
1198  else
1199  {
1200  ASSERT(0);
1201  return -1; /* NOTREACHED */
1202  }
1203 }
1204 
1205 #if PASSTOS_CAPABILITY
1206 
1207 /*
1208  * Extract TOS bits. Assumes that ipbuf is a valid IPv4 packet.
1209  */
1210 static inline void
1211 link_socket_extract_tos(struct link_socket *ls, const struct buffer *ipbuf)
1212 {
1213  if (ls && ipbuf)
1214  {
1215  struct openvpn_iphdr *iph = (struct openvpn_iphdr *) BPTR(ipbuf);
1216  ls->ptos = iph->tos;
1217  ls->ptos_defined = true;
1218  }
1219 }
1220 
1221 /*
1222  * Set socket properties to reflect TOS bits which were extracted
1223  * from tunnel packet.
1224  */
1225 static inline void
1226 link_socket_set_tos(struct link_socket *ls)
1227 {
1228  if (ls && ls->ptos_defined)
1229  {
1230  setsockopt(ls->sd, IPPROTO_IP, IP_TOS, (const void *)&ls->ptos, sizeof(ls->ptos));
1231  }
1232 }
1233 
1234 #endif /* if PASSTOS_CAPABILITY */
1235 
1236 /*
1237  * Socket I/O wait functions
1238  */
1239 
1240 static inline bool
1242 {
1243  return s && s->stream_buf.residual_fully_formed;
1244 }
1245 
1246 static inline event_t
1248 {
1249 #ifdef _WIN32
1250  return &s->rw_handle;
1251 #else
1252  return s->sd;
1253 #endif
1254 }
1255 
1257 
1258 unsigned int
1259 socket_set(struct link_socket *s,
1260  struct event_set *es,
1261  unsigned int rwflags,
1262  void *arg,
1263  unsigned int *persistent);
1264 
1265 static inline void
1267  struct event_set *es,
1268  void *arg)
1269 {
1270  if (s && !s->listen_persistent_queued)
1271  {
1273  s->listen_persistent_queued = true;
1274  }
1275 }
1276 
1277 static inline void
1279 {
1280 #ifdef _WIN32
1282 #endif
1283 }
1284 
1285 const char *socket_stat(const struct link_socket *s, unsigned int rwflags, struct gc_arena *gc);
1286 
1287 #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:3060
link_socket_read
static int link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition: socket.h:1068
proto_num
proto_num
Definition: socket.h:553
bad_address_length
void bad_address_length(int actual, int expected)
Definition: socket.c:3219
openvpn_sockaddr::addr
union openvpn_sockaddr::@14 addr
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:1030
IN6_ARE_ADDR_EQUAL
#define IN6_ARE_ADDR_EQUAL(a, b)
Definition: win32.h:52
error.h
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:2833
sockethandle_t::h
HANDLE h
Definition: socket.h:270
print_sockaddr
static const char * print_sockaddr(const struct sockaddr *addr, struct gc_arena *gc)
Definition: socket.h:371
print_link_socket_actual
const char * print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena *gc)
Definition: socket.c:2823
link_socket_close
void link_socket_close(struct link_socket *sock)
Definition: socket.c:2297
buffer::len
int len
Length in bytes of the actual content within the allocated memory.
Definition: buffer.h:66
link_socket_update_flags
bool link_socket_update_flags(struct link_socket *ls, unsigned int sockflags)
Definition: socket.c:969
win32.h
context
Contains all state information for one tunnel.
Definition: openvpn.h:476
es
struct env_set * es
Definition: test_pkcs11.c:133
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:779
http_proxy_info
Definition: proxy.h:70
link_socket_proto_connection_oriented
static bool link_socket_proto_connection_oriented(int proto)
Definition: socket.h:629
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:3044
create_socket_tcp
socket_descriptor_t create_socket_tcp(struct addrinfo *)
Definition: socket.c:999
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:2742
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:938
EVENT_READ
#define EVENT_READ
Definition: event.h:39
sd_close
void sd_close(socket_descriptor_t *sd)
Definition: socket.c:3915
proto_is_dgram
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
Definition: socket.h:584
socket_set
unsigned int socket_set(struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition: socket.c:3878
PROTO_N
@ PROTO_N
Definition: socket.h:559
proto2ascii
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
Definition: socket.c:3128
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:635
PROTO_TCP_SERVER
@ PROTO_TCP_SERVER
Definition: socket.h:557
addr_zero_host
static void addr_zero_host(struct openvpn_sockaddr *addr)
Definition: socket.h:852
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:3231
addr_host
static in_addr_t addr_host(const struct openvpn_sockaddr *addr)
Definition: socket.h:763
sa_family_t
unsigned short sa_family_t
Definition: syshead.h:385
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:1045
addr_match
static bool addr_match(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
Definition: socket.h:719
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:1109
event_ctl
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
Definition: event.h:160
overlapped_io::overlapped
OVERLAPPED overlapped
Definition: win32.h:207
socket_event_handle
static event_t socket_event_handle(const struct link_socket *s)
Definition: socket.h:1247
PS_SHOW_PORT
#define PS_SHOW_PORT
Definition: socket.h:341
link_socket_actual_defined
static bool link_socket_actual_defined(const struct link_socket_actual *act)
Definition: socket.h:713
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:772
link_socket_update_buffer_sizes
void link_socket_update_buffer_sizes(struct link_socket *ls, int rcvbuf, int sndbuf)
Definition: socket.c:983
PROTO_TCP_CLIENT
@ PROTO_TCP_CLIENT
Definition: socket.h:558
tun.h
openvpn_sockaddr::sa
struct sockaddr sa
Definition: socket.h:69
BLEN
#define BLEN(buf)
Definition: buffer.h:127
link_socket_write_udp
static size_t link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition: socket.h:1172
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:429
socket_buffer_size
Definition: socket.h:154
link_socket_write_tcp
int link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition: socket.c:3403
ascii2af
sa_family_t ascii2af(const char *proto_name)
Definition: socket.c:3114
addrlist_match
static bool addrlist_match(const struct openvpn_sockaddr *a1, const struct addrinfo *addrlist)
Definition: socket.h:734
openvpn_sockaddr::in4
struct sockaddr_in in4
Definition: socket.h:70
stream_buf::maxlen
int maxlen
Definition: socket.h:134
link_socket_init_phase2
void link_socket_init_phase2(struct context *c)
Definition: socket.c:2169
stream_buf_read_setup_dowork
bool stream_buf_read_setup_dowork(struct link_socket *sock)
Definition: socket.c:2626
misc.h
set_actual_address
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
Definition: socket.c:1530
print_in_addr_t
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
Definition: socket.c:2904
socket_buffer_size::rcvbuf
int rcvbuf
Definition: socket.h:156
SocketHandleGetLastError
static int SocketHandleGetLastError(sockethandle_t sh)
Definition: socket.h:289
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:180
sockethandle_finalize
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
Definition: socket.c:3752
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:2422
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
socket_listen_event_handle
event_t socket_listen_event_handle(struct link_socket *s)
Definition: socket.c:2724
link_socket_write
static int link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition: socket.h:1185
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:573
addr_defined_ipi
static bool addr_defined_ipi(const struct link_socket_actual *lsa)
Definition: socket.h:686
print_in6_addr
const char * print_in6_addr(struct in6_addr addr6, unsigned int flags, struct gc_arena *gc)
Definition: socket.c:2924
event.h
ipv6_addr_safe
bool ipv6_addr_safe(const char *ipv6_text_addr)
Definition: socket.c:736
proto2ascii_all
const char * proto2ascii_all(struct gc_arena *gc)
Definition: socket.c:3150
addr_port_match
static bool addr_port_match(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
Definition: socket.h:814
link_socket_init_phase1
void link_socket_init_phase1(struct context *c, int mode)
Definition: socket.c:1834
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:987
PROTO_NONE
@ PROTO_NONE
Definition: socket.h:554
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:563
socket_reset_listen_persistent
static void socket_reset_listen_persistent(struct link_socket *s)
Definition: socket.h:1278
socket_recv_queue
int socket_recv_queue(struct link_socket *sock, int maxsize)
Definition: socket.c:3516
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:3633
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:3191
SocketHandleSetInvalError
static void SocketHandleSetInvalError(sockethandle_t sh)
Definition: socket.h:301
stream_buf
Definition: socket.h:130
link_socket_new
struct link_socket * link_socket_new(void)
Definition: socket.c:1823
ip_addr_dotted_quad_safe
bool ip_addr_dotted_quad_safe(const char *dotted_quad)
Definition: socket.c:686
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:211
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:2978
mac_addr_safe
bool mac_addr_safe(const char *mac_addr)
Definition: socket.c:789
do_preresolve
void do_preresolve(struct context *c)
Definition: socket.c:328
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:267
socket_descriptor_t
SOCKET socket_descriptor_t
Definition: syshead.h:429
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:1434
event_set
Definition: event.h:124
addr_family_name
const char * addr_family_name(int af)
Definition: socket.c:3167
SF_DCO_WIN
#define SF_DCO_WIN
Definition: socket.h:209
addr_defined
static bool addr_defined(const struct openvpn_sockaddr *addr)
Definition: socket.h:648
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:662
SocketHandleSetLastError
static void SocketHandleSetLastError(sockethandle_t sh, DWORD err)
Definition: socket.h:295
stream_buf_read_setup
static bool stream_buf_read_setup(struct link_socket *sock)
Definition: socket.h:1012
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:2955
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:915
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:831
print_in_port_t
const char * print_in_port_t(in_port_t port, struct gc_arena *gc)
Definition: socket.c:2940
addrlist_match_proto
static bool addrlist_match_proto(const struct openvpn_sockaddr *a1, struct addrinfo *addr_list, const int proto)
Definition: socket.h:842
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:593
link_socket_current_remote
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
Definition: socket.c:2457
socket_set_listen_persistent
static void socket_set_listen_persistent(struct link_socket *s, struct event_set *es, void *arg)
Definition: socket.h:1266
socket_read_residual
static bool socket_read_residual(const struct link_socket *s)
Definition: socket.h:1241
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:3031
SocketHandleGetOverlappedResult
static BOOL SocketHandleGetOverlappedResult(sockethandle_t sh, struct overlapped_io *io)
Definition: socket.h:281
print_openvpn_sockaddr_ex
static const char * print_openvpn_sockaddr_ex(const struct openvpn_sockaddr *addr, const char *separator, const unsigned int flags, struct gc_arena *gc)
Definition: socket.h:353
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:2492
setenv_trusted
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
Definition: socket.c:2349
MSG_NOSIGNAL
#define MSG_NOSIGNAL
Definition: socket.h:254
openvpn_errno
#define openvpn_errno()
Definition: error.h:72
datagram_overhead
static int datagram_overhead(sa_family_t af, int proto)
Definition: socket.h:616
openvpn_iphdr::tos
uint8_t tos
Definition: proto.h:111
openvpn_iphdr
Definition: proto.h:106
link_socket_bad_outgoing_addr
void link_socket_bad_outgoing_addr(void)
Definition: socket.c:2451
SF_USE_IP_PKTINFO
#define SF_USE_IP_PKTINFO
Definition: socket.h:204
socket_stat
const char * socket_stat(const struct link_socket *s, unsigned int rwflags, struct gc_arena *gc)
Definition: socket.c:2525
print_openvpn_sockaddr
static const char * print_openvpn_sockaddr(const struct openvpn_sockaddr *addr, struct gc_arena *gc)
Definition: socket.h:363
addr_local
static bool addr_local(const struct sockaddr *addr)
Definition: socket.h:665
af_addr_size
static int af_addr_size(sa_family_t af)
Definition: socket.h:867
ascii2proto
int ascii2proto(const char *proto_name)
Definition: socket.c:3100
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:966
msg
#define msg(flags,...)
Definition: error.h:144
sockethandle_t::s
SOCKET s
Definition: socket.h:269
socket_do_accept
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
Definition: socket.c:1214
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:2371
sockethandle_t::is_handle
bool is_handle
Definition: socket.h:272
overlapped_io::size
DWORD size
Definition: win32.h:208
overlapped_io
Definition: win32.h:202
socks.h
PROTO_UDP
@ PROTO_UDP
Definition: socket.h:555
PROTO_TCP
@ PROTO_TCP
Definition: socket.h:556
socket_bind
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix, bool ipv6only)
Definition: socket.c:1380
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:886