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-2025 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef SOCKET_H
24#define SOCKET_H
25
26#include "buffer.h"
27#include "common.h"
28#include "error.h"
29#include "proto.h"
30#include "mtu.h"
31#include "win32.h"
32#include "event.h"
33#include "proxy.h"
34#include "socks.h"
35#include "misc.h"
36#include "tun.h"
37#include "socket_util.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
56typedef 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/* struct to hold preresolved host names */
66{
67 const char *hostname;
68 const char *servname;
70 unsigned int flags;
71 struct addrinfo *ai;
73};
74
75/* IP addresses which are persistent across SIGUSR1s */
77{
78 struct addrinfo *bind_local;
79 struct addrinfo *remote_list; /* complete remote list */
80 struct addrinfo *current_remote; /* remote used in the
81 * current connection attempt */
82 struct link_socket_actual actual; /* reply to this address */
83};
84
86{
89 const char *ipchange_command;
90 const struct plugin_list *plugins;
92 int proto; /* Protocol (PROTO_x defined below) */
93 sa_family_t af; /* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/
95 int mtu_changed; /* Set to true when mtu value is changed */
96};
97
98/*
99 * Used to extract packets encapsulated in streams into a buffer,
100 * in this case IP packets embedded in a TCP stream.
101 */
103{
108
109 struct buffer buf;
110 struct buffer next;
111 int len; /* -1 if not yet known */
112
113 bool error; /* if true, fatal TCP error has occurred,
114 * requiring that connection be restarted */
115#if PORT_SHARE
116#define PS_DISABLED 0
117#define PS_ENABLED 1
118#define PS_FOREIGN 2
120#endif
121};
122
123/*
124 * Used to set socket buffer sizes
125 */
127{
130};
131
140 bool reduce_size);
141
142/*
143 * This is the main socket structure used by OpenVPN. The SOCKET_
144 * defines try to abstract away our implementation differences between
145 * using sockets on Posix vs. Win32.
146 */
148{
150
157 socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
158
159#ifdef _WIN32
163 struct rw_handle listen_handle; /* For listening on TCP socket in server mode */
164#endif
165
166 /* used for printing status info only */
167 unsigned int rwflags_debug;
168
169 /* used for long-term queueing of pre-accepted socket listen */
171
172 const char *remote_host;
173 const char *remote_port;
174 const char *local_host;
175 const char *local_port;
178
179#define LS_MODE_DEFAULT 0
180#define LS_MODE_TCP_LISTEN 1
181#define LS_MODE_TCP_ACCEPT_FROM 2
182 int mode;
183
186
188
189 int mtu; /* OS discovered MTU, or 0 if unknown */
190
191#define SF_USE_IP_PKTINFO (1 << 0)
192#define SF_TCP_NODELAY (1 << 1)
193#define SF_PORT_SHARE (1 << 2)
194#define SF_HOST_RANDOMIZE (1 << 3)
195#define SF_GETADDRINFO_DGRAM (1 << 4)
196#define SF_DCO_WIN (1 << 5)
197#define SF_PREPEND_SA (1 << 6)
198 unsigned int sockflags;
199 int mark;
200 const char *bind_dev;
201
202 /* for stream sockets */
206
207 /* HTTP proxy */
209
210 /* Socks proxy */
212 struct link_socket_actual socks_relay; /* Socks UDP relay address */
213
214 /* The OpenVPN server we will use the proxy to connect to */
215 const char *proxy_dest_host;
216 const char *proxy_dest_port;
217
218 /* Pointer to the server-poll to trigger the timeout in function which have
219 * their own loop instead of using the main oop */
221
222#if PASSTOS_CAPABILITY
223 /* used to get/set TOS. */
224#if defined(TARGET_LINUX)
225 uint8_t ptos;
226#else /* all the BSDs, Solaris, MacOS use plain "int" -> see "man ip" there */
227 int ptos;
228#endif
229 bool ptos_defined;
230#endif
231
232#ifdef ENABLE_DEBUG
233 int gremlin; /* --gremlin bits */
234#endif
235};
236
237/*
238 * Some Posix/Win32 differences.
239 */
240
241#ifndef MSG_NOSIGNAL
242#define MSG_NOSIGNAL 0
243#endif
244
245#ifdef _WIN32
246
247#define openvpn_close_socket(s) closesocket(s)
248
249int socket_recv_queue(struct link_socket *sock, int maxsize);
250
251int socket_send_queue(struct link_socket *sock, struct buffer *buf,
252 const struct link_socket_actual *to);
253
254typedef struct
255{
256 union
257 {
258 SOCKET s;
259 HANDLE h;
260 };
262 bool prepend_sa; /* are incoming packets prepended with sockaddr? */
264
265int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf,
266 struct link_socket_actual *from);
267
268static inline BOOL
270{
271 return sh.is_handle
272 ? GetOverlappedResult(sh.h, &io->overlapped, &io->size, FALSE)
273 : WSAGetOverlappedResult(sh.s, &io->overlapped, &io->size, FALSE, &io->flags);
274}
275
276static inline int
278{
279 return sh.is_handle ? (int)GetLastError() : WSAGetLastError();
280}
281
282inline static void
284{
285 sh.is_handle ? SetLastError(err) : WSASetLastError(err);
286}
287
288static inline void
290{
291 sh.is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(WSAEINVAL);
292}
293
294/* winsock(2).h uses slightly different types so to avoid conversion
295 errors we wrap these functions on Windows */
296
297static inline int
298openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds,
299 fd_set *exceptfds, struct timeval *timeout)
300{
301 (void)nfds; /* first argument ignored on Windows */
302 return select(0, readfds, writefds, exceptfds, timeout);
303}
304
305static inline ssize_t
306openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)
307{
308 ASSERT(len <= INT_MAX);
309 return send(sockfd, buf, (int)len, flags);
310}
311
312static inline int
313openvpn_bind(socket_descriptor_t sockfd, const struct sockaddr *addr, size_t addrlen)
314{
315 ASSERT(addrlen <= INT_MAX);
316 return bind(sockfd, addr, (int)addrlen);
317}
318
319#else /* ifdef _WIN32 */
320
321#define openvpn_close_socket(s) close(s)
322#define openvpn_select(nfds, readfds, writefds, exceptfds, timeout) \
323 select(nfds, readfds, writefds, exceptfds, timeout)
324#define openvpn_send(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
325#define openvpn_bind(sockfd, addr, addrlen) bind(sockfd, addr, addrlen)
326
327#endif /* ifdef _WIN32 */
328
329struct link_socket *link_socket_new(void);
330
331void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix,
332 bool ipv6only);
333
334int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout,
335 volatile int *signal_received);
336
337
338/*
339 * Initialize link_socket object.
340 */
341void link_socket_init_phase1(struct context *c, int sock_index, int mode);
342
343void link_socket_init_phase2(struct context *c, struct link_socket *sock);
344
345void do_preresolve(struct context *c);
346
347void link_socket_close(struct link_socket *sock);
348
350
351void bad_address_length(int actual, int expected);
352
353/* IPV4_INVALID_ADDR: returned by link_socket_current_remote()
354 * to ease redirect-gateway logic for ipv4 tunnels on ipv6 endpoints
355 */
356#define IPV4_INVALID_ADDR 0xffffffff
357in_addr_t link_socket_current_remote(const struct link_socket_info *info);
358
359const struct in6_addr *link_socket_current_remote_ipv6(const struct link_socket_info *info);
360
362 const struct link_socket_actual *addr,
363 const char *common_name, struct env_set *es);
364
365void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket_info *info,
366 const struct link_socket_actual *from_addr);
367
368void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai);
369
371
372void setenv_trusted(struct env_set *es, const struct link_socket_info *info);
373
374bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags);
375
376void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf);
377
378/*
379 * Low-level functions
380 */
381
382socket_descriptor_t create_socket_tcp(struct addrinfo *);
383
385 const bool nowait);
386
387#if UNIX_SOCK_SUPPORT
388
389socket_descriptor_t create_socket_unix(void);
390
391void socket_bind_unix(socket_descriptor_t sd, struct sockaddr_un *local, const char *prefix);
392
393socket_descriptor_t socket_accept_unix(socket_descriptor_t sd, struct sockaddr_un *remote);
394
395int socket_connect_unix(socket_descriptor_t sd, struct sockaddr_un *remote);
396
397void sockaddr_unix_init(struct sockaddr_un *local, const char *path);
398
399const char *sockaddr_unix_name(const struct sockaddr_un *local, const char *null);
400
401void socket_delete_unix(const struct sockaddr_un *local);
402
403bool unix_socket_get_peer_uid_gid(const socket_descriptor_t sd, uid_t *uid, gid_t *gid);
404
405#endif /* if UNIX_SOCK_SUPPORT */
406
407static inline bool
409{
410 if (sock)
411 {
413 }
414 else
415 {
416 return false;
417 }
418}
419
420#if PORT_SHARE
421
422static inline bool
423socket_foreign_protocol_detected(const struct link_socket *sock)
424{
425 return link_socket_connection_oriented(sock) && sock->stream_buf.port_share_state == PS_FOREIGN;
426}
427
428static inline const struct buffer *
430{
431 return &sock->stream_buf.buf;
432}
433
434static inline int
435socket_foreign_protocol_sd(const struct link_socket *sock)
436{
437 return sock->sd;
438}
439
440#endif /* if PORT_SHARE */
441
442static inline bool
444{
446 {
447 if (sock->stream_reset || sock->stream_buf.error)
448 {
449 return true;
450 }
451 else if (status < 0)
452 {
453 const int err = openvpn_errno();
454#ifdef _WIN32
455 return err == WSAECONNRESET || err == WSAECONNABORTED
457#else
458 return err == ECONNRESET;
459#endif
460 }
461 }
462 return false;
463}
464
465static inline bool
467 const struct link_socket_actual *from_addr)
468{
469 if (buf->len > 0)
470 {
471 switch (from_addr->dest.addr.sa.sa_family)
472 {
473 case AF_INET6:
474 case AF_INET:
476 {
477 return false;
478 }
479 if (info->remote_float || (!info->lsa->remote_list))
480 {
481 return true;
482 }
483 if (addrlist_match_proto(&from_addr->dest, info->lsa->remote_list, info->proto))
484 {
485 return true;
486 }
487 }
488 }
489 return false;
490}
491
492static inline void
494 struct link_socket_actual **act)
495{
496 if (buf->len > 0)
497 {
498 struct link_socket_addr *lsa = info->lsa;
500 {
501 *act = &lsa->actual;
502 }
503 else
504 {
506 buf->len = 0;
507 *act = NULL;
508 }
509 }
510}
511
512static inline void
514 const char *common_name, struct env_set *es)
515{
516 struct link_socket_addr *lsa = info->lsa;
517 if (
518 /* new or changed address? */
520 || !addr_match_proto(&act->dest, &lsa->actual.dest, info->proto))
521 &&
522 /* address undef or address == remote or --float */
523 (info->remote_float
524 || (!lsa->remote_list || addrlist_match_proto(&act->dest, lsa->remote_list, info->proto))))
525 {
526 link_socket_connection_initiated(info, act, common_name, es);
527 }
528}
529
531
532static inline bool
534{
536 {
537 return stream_buf_read_setup_dowork(sock);
538 }
539 else
540 {
541 return true;
542 }
543}
544
550static inline bool
552{
553 return s->sockflags & SF_DCO_WIN;
554}
555
556/*
557 * Socket Read Routines
558 */
559
560int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf);
561
562#ifdef _WIN32
563
564static inline int
566 struct link_socket_actual *from)
567{
568 sockethandle_t sh = { .s = sock->sd };
569 if (socket_is_dco_win(sock))
570 {
571 *from = sock->info.lsa->actual;
572 sh.is_handle = true;
574 }
575 return sockethandle_finalize(sh, &sock->reads, buf, from);
576}
577
578#else /* ifdef _WIN32 */
579
580int link_socket_read_udp_posix(struct link_socket *sock, struct buffer *buf,
581 struct link_socket_actual *from);
582
583#endif /* ifdef _WIN32 */
584
585/* read a TCP or UDP packet from link */
586static inline int
587link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
588{
589 if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
590 /* unified UDPv4 and UDPv6, for DCO-WIN the kernel
591 * will strip the length header */
592 {
593 int res;
594
595#ifdef _WIN32
596 res = link_socket_read_udp_win32(sock, buf, from);
597#else
598 res = link_socket_read_udp_posix(sock, buf, from);
599#endif
600 return res;
601 }
602 else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
603 {
604 /* from address was returned by accept */
605 from->dest = sock->info.lsa->actual.dest;
606 return link_socket_read_tcp(sock, buf);
607 }
608 else
609 {
610 ASSERT(0);
611 return -1; /* NOTREACHED */
612 }
613}
614
615/*
616 * Socket Write routines
617 */
618
619ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf,
620 struct link_socket_actual *to);
621
622#ifdef _WIN32
623
624static inline int
625link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
626{
627 int err = 0;
628 int status = 0;
629 sockethandle_t sh = { .s = sock->sd, .is_handle = socket_is_dco_win(sock) };
630 if (overlapped_io_active(&sock->writes))
631 {
632 status = sockethandle_finalize(sh, &sock->writes, NULL, NULL);
633 if (status < 0)
634 {
635 err = SocketHandleGetLastError(sh);
636 }
637 }
638
639 /* dco-win mp requires control packets to be prepended with sockaddr */
640 if (sock->sockflags & SF_PREPEND_SA)
641 {
642 if (to->dest.addr.sa.sa_family == AF_INET)
643 {
644 buf_write_prepend(buf, &to->dest.addr.in4, sizeof(struct sockaddr_in));
645 }
646 else
647 {
648 buf_write_prepend(buf, &to->dest.addr.in6, sizeof(struct sockaddr_in6));
649 }
650 }
651
652 socket_send_queue(sock, buf, to);
653 if (status < 0)
654 {
656 return status;
657 }
658 else
659 {
660 return BLEN(buf);
661 }
662}
663
664#else /* ifdef _WIN32 */
665
666ssize_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock, struct buffer *buf,
667 struct link_socket_actual *to);
668
669
670static inline ssize_t
671link_socket_write_udp_posix(struct link_socket *sock, struct buffer *buf,
672 struct link_socket_actual *to)
673{
674#if ENABLE_IP_PKTINFO
675 if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
676 && addr_defined_ipi(to))
677 {
678 return link_socket_write_udp_posix_sendmsg(sock, buf, to);
679 }
680 else
681#endif
682 return sendto(sock->sd, BPTR(buf), BLEN(buf), 0, (struct sockaddr *)&to->dest.addr.sa,
683 (socklen_t)af_addr_size(to->dest.addr.sa.sa_family));
684}
685
686static inline ssize_t
687link_socket_write_tcp_posix(struct link_socket *sock, struct buffer *buf)
688{
689 return send(sock->sd, BPTR(buf), BLEN(buf), MSG_NOSIGNAL);
690}
691
692#endif /* ifdef _WIN32 */
693
694static inline ssize_t
695link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
696{
697#ifdef _WIN32
698 return link_socket_write_win32(sock, buf, to);
699#else
700 return link_socket_write_udp_posix(sock, buf, to);
701#endif
702}
703
704/* write a TCP or UDP packet to link */
705static inline ssize_t
706link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
707{
708 if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
709 {
710 /* unified UDPv4, UDPv6 and DCO-WIN (driver adds length header) */
711 return link_socket_write_udp(sock, buf, to);
712 }
713 else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
714 {
715 return link_socket_write_tcp(sock, buf, to);
716 }
717 else
718 {
719 ASSERT(0);
720 return -1; /* NOTREACHED */
721 }
722}
723
724#if PASSTOS_CAPABILITY
725
726/*
727 * Extract TOS bits. Assumes that ipbuf is a valid IPv4 packet.
728 */
729static inline void
730link_socket_extract_tos(struct link_socket *sock, const struct buffer *ipbuf)
731{
732 if (sock && ipbuf)
733 {
734 struct openvpn_iphdr *iph = (struct openvpn_iphdr *)BPTR(ipbuf);
735 sock->ptos = iph->tos;
736 sock->ptos_defined = true;
737 }
738}
739
740/*
741 * Set socket properties to reflect TOS bits which were extracted
742 * from tunnel packet.
743 */
744static inline void
745link_socket_set_tos(struct link_socket *sock)
746{
747 if (sock && sock->ptos_defined)
748 {
749 setsockopt(sock->sd, IPPROTO_IP, IP_TOS, (const void *)&sock->ptos, sizeof(sock->ptos));
750 }
751}
752
753#endif /* if PASSTOS_CAPABILITY */
754
755/*
756 * Socket I/O wait functions
757 */
758
759/*
760 * Extends the pre-existing read residual logic
761 * to all initialized sockets, ensuring the complete
762 * packet is read.
763 */
764bool sockets_read_residual(const struct context *c);
765
766static inline event_t
768{
769#ifdef _WIN32
770 return &sock->rw_handle;
771#else
772 return sock->sd;
773#endif
774}
775
777
778unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags,
779 void *arg, unsigned int *persistent);
780
781static inline void
782socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
783{
784 if (sock && !sock->listen_persistent_queued)
785 {
787 sock->listen_persistent_queued = true;
788 }
789}
790
791static inline void
793{
794#ifdef _WIN32
796#endif
797}
798
799const char *socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc);
800
801#endif /* SOCKET_H */
#define BPTR(buf)
Definition buffer.h:123
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
Definition buffer.h:672
#define BLEN(buf)
Definition buffer.h:126
#define EVENT_READ
Definition event.h:37
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
Definition event.h:182
static SERVICE_STATUS status
Definition interactive.c:51
#define openvpn_errno()
Definition error.h:71
#define ASSERT(x)
Definition error.h:219
void link_socket_init_phase1(struct context *c, int sock_index, int mode)
Definition socket.c:1376
static event_t socket_event_handle(const struct link_socket *sock)
Definition socket.h:767
const char * socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc)
Definition socket.c:2066
static BOOL SocketHandleGetOverlappedResult(sockethandle_t sh, struct overlapped_io *io)
Definition socket.h:269
void link_socket_init_phase2(struct context *c, struct link_socket *sock)
Definition socket.c:1719
int socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
Definition socket.c:2668
ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.c:2452
void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf)
Definition socket.c:557
event_t socket_listen_event_handle(struct link_socket *sock)
Definition socket.c:2253
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
Definition socket.c:2033
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
Definition socket.c:1088
static ssize_t link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:706
static void socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
Definition socket.h:782
#define SF_DCO_WIN
Definition socket.h:196
void bad_address_length(int actual, int expected)
Definition socket.c:2272
static bool link_socket_connection_oriented(const struct link_socket *sock)
Definition socket.h:408
static bool stream_buf_read_setup(struct link_socket *sock)
Definition socket.h:533
void sd_close(socket_descriptor_t *sd)
Definition socket.c:2987
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition socket.h:792
static int link_socket_read_udp_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:565
static void SocketHandleSetLastError(sockethandle_t sh, DWORD err)
Definition socket.h:283
static bool socket_connection_reset(const struct link_socket *sock, int status)
Definition socket.h:443
socket_descriptor_t create_socket_tcp(struct addrinfo *)
Definition socket.c:573
static int SocketHandleGetLastError(sockethandle_t sh)
Definition socket.h:277
static void SocketHandleSetInvalError(sockethandle_t sh)
Definition socket.h:289
bool stream_buf_read_setup_dowork(struct link_socket *sock)
Definition socket.c:2156
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
Definition socket.c:782
int socket_recv_queue(struct link_socket *sock, int maxsize)
Definition socket.c:2567
void link_socket_close(struct link_socket *sock)
Definition socket.c:1840
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:466
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:513
static int link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:587
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:471
static void link_socket_get_outgoing_addr(struct buffer *buf, const struct link_socket_info *info, struct link_socket_actual **act)
Definition socket.h:493
#define SF_USE_IP_PKTINFO
Definition socket.h:191
#define MSG_NOSIGNAL
Definition socket.h:242
uint16_t packet_size_type
Definition socket.h:56
void link_socket_bad_outgoing_addr(void)
Definition socket.c:1993
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:551
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
Definition socket.c:2860
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
Definition socket.c:1999
int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
Definition socket.c:2284
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
Definition socket.c:995
#define SF_PREPEND_SA
Definition socket.h:197
void do_preresolve(struct context *c)
Definition socket.c:320
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:1966
unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition socket.c:2953
static int openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition socket.h:298
static ssize_t link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:695
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix, bool ipv6only)
Definition socket.c:945
static int link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:625
struct link_socket * link_socket_new(void)
Definition socket.c:1362
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:1914
bool sockets_read_residual(const struct context *c)
Definition socket.c:45
static int openvpn_bind(socket_descriptor_t sockfd, const struct sockaddr *addr, size_t addrlen)
Definition socket.h:313
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
Definition socket.c:1892
static ssize_t openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)
Definition socket.h:306
bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags)
Definition socket.c:543
static bool link_socket_actual_defined(const struct link_socket_actual *act)
static bool addr_match_proto(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2, const int proto)
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
static bool proto_is_tcp(int proto)
returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
static bool addr_defined_ipi(const struct link_socket_actual *lsa)
static int af_addr_size(sa_family_t af)
static bool link_socket_proto_connection_oriented(int proto)
static bool addrlist_match_proto(const struct openvpn_sockaddr *a1, struct addrinfo *addr_list, const int proto)
Wrapper structure for dynamically allocated memory.
Definition buffer.h:60
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:65
Definition socket.h:66
const char * hostname
Definition socket.h:67
int ai_family
Definition socket.h:69
const char * servname
Definition socket.h:68
unsigned int flags
Definition socket.h:70
struct addrinfo * ai
Definition socket.h:71
struct cached_dns_entry * next
Definition socket.h:72
Contains all state information for one tunnel.
Definition openvpn.h:474
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:116
uint8_t tos
Definition proto.h:95
union openvpn_sockaddr::@27 addr
struct sockaddr sa
Definition socket_util.h:42
struct sockaddr_in in4
Definition socket_util.h:43
struct sockaddr_in6 in6
Definition socket_util.h:44
DWORD flags
Definition win32.h:211
DWORD size
Definition win32.h:210
OVERLAPPED overlapped
Definition win32.h:209
bool is_handle
Definition socket.h:261
bool prepend_sa
Definition socket.h:262
struct buffer buf
Definition socket.h:109
bool error
Definition socket.h:113
struct buffer residual
Definition socket.h:105
bool residual_fully_formed
Definition socket.h:107
int maxlen
Definition socket.h:106
int len
Definition socket.h:111
struct buffer next
Definition socket.h:110
struct buffer buf_init
Definition socket.h:104
unsigned short sa_family_t
Definition syshead.h:396
SOCKET socket_descriptor_t
Definition syshead.h:440
struct env_set * es
char ** res
struct gc_arena gc
Definition test_ssl.c:131
long reset_net_event_win32(struct rw_handle *event, socket_descriptor_t sd)
Definition win32.c:259
static bool overlapped_io_active(struct overlapped_io *o)
Definition win32.h:229