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 uint8_t 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#define SF_PKTINFO_COPY_IIF (1 << 7)
199 unsigned int sockflags;
200 int mark;
201 const char *bind_dev;
202
203 /* for stream sockets */
207
208 /* HTTP proxy */
210
211 /* Socks proxy */
213 struct link_socket_actual socks_relay; /* Socks UDP relay address */
214
215 /* The OpenVPN server we will use the proxy to connect to */
216 const char *proxy_dest_host;
217 const char *proxy_dest_port;
218
219 /* Pointer to the server-poll to trigger the timeout in function which have
220 * their own loop instead of using the main oop */
222
223#if PASSTOS_CAPABILITY
224 /* used to get/set TOS. */
225#if defined(TARGET_LINUX)
226 uint8_t ptos;
227#else /* all the BSDs, Solaris, MacOS use plain "int" -> see "man ip" there */
228 int ptos;
229#endif
230 bool ptos_defined;
231#endif
232
233#ifdef ENABLE_DEBUG
234 int gremlin; /* --gremlin bits */
235#endif
236};
237
238/*
239 * Some Posix/Win32 differences.
240 */
241
242#ifndef MSG_NOSIGNAL
243#define MSG_NOSIGNAL 0
244#endif
245
246#ifdef _WIN32
247
248#define openvpn_close_socket(s) closesocket(s)
249
250int socket_recv_queue(struct link_socket *sock, int maxsize);
251
252int socket_send_queue(struct link_socket *sock, struct buffer *buf,
253 const struct link_socket_actual *to);
254
255typedef struct
256{
257 union
258 {
259 SOCKET s;
260 HANDLE h;
261 };
263 bool prepend_sa; /* are incoming packets prepended with sockaddr? */
265
266int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf,
267 struct link_socket_actual *from);
268
269static inline BOOL
271{
272 return sh.is_handle
273 ? GetOverlappedResult(sh.h, &io->overlapped, &io->size, FALSE)
274 : WSAGetOverlappedResult(sh.s, &io->overlapped, &io->size, FALSE, &io->flags);
275}
276
277static inline int
279{
280 return sh.is_handle ? (int)GetLastError() : WSAGetLastError();
281}
282
283inline static void
285{
286 sh.is_handle ? SetLastError(err) : WSASetLastError(err);
287}
288
289static inline void
291{
292 sh.is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(WSAEINVAL);
293}
294
295/* winsock(2).h uses slightly different types so to avoid conversion
296 errors we wrap these functions on Windows */
297
298static inline int
299openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds,
300 fd_set *exceptfds, struct timeval *timeout)
301{
302 (void)nfds; /* first argument ignored on Windows */
303 return select(0, readfds, writefds, exceptfds, timeout);
304}
305
306static inline ssize_t
307openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)
308{
309 ASSERT(len <= INT_MAX);
310 return send(sockfd, buf, (int)len, flags);
311}
312
313static inline int
314openvpn_bind(socket_descriptor_t sockfd, const struct sockaddr *addr, size_t addrlen)
315{
316 ASSERT(addrlen <= INT_MAX);
317 return bind(sockfd, addr, (int)addrlen);
318}
319
320#else /* ifdef _WIN32 */
321
322#define openvpn_close_socket(s) close(s)
323#define openvpn_select(nfds, readfds, writefds, exceptfds, timeout) \
324 select(nfds, readfds, writefds, exceptfds, timeout)
325#define openvpn_send(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
326#define openvpn_bind(sockfd, addr, addrlen) bind(sockfd, addr, addrlen)
327
328#endif /* ifdef _WIN32 */
329
330struct link_socket *link_socket_new(void);
331
332void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix,
333 bool ipv6only);
334
335int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout,
336 volatile int *signal_received);
337
338
339/*
340 * Initialize link_socket object.
341 */
342void link_socket_init_phase1(struct context *c, int sock_index, int mode);
343
344void link_socket_init_phase2(struct context *c, struct link_socket *sock);
345
346void do_preresolve(struct context *c);
347
348void link_socket_close(struct link_socket *sock);
349
351
352void bad_address_length(int actual, int expected);
353
354/* IPV4_INVALID_ADDR: returned by link_socket_current_remote()
355 * to ease redirect-gateway logic for ipv4 tunnels on ipv6 endpoints
356 */
357#define IPV4_INVALID_ADDR 0xffffffff
359
360const struct in6_addr *link_socket_current_remote_ipv6(const struct link_socket_info *info);
361
363 const struct link_socket_actual *addr,
364 const char *common_name, struct env_set *es);
365
366void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket_info *info,
367 const struct link_socket_actual *from_addr);
368
369void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai);
370
372
373void setenv_trusted(struct env_set *es, const struct link_socket_info *info);
374
375bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags);
376
377void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf);
378
379/*
380 * Low-level functions
381 */
382
383socket_descriptor_t create_socket_tcp(struct addrinfo *);
384
386 const bool nowait);
387
388#if UNIX_SOCK_SUPPORT
389
390socket_descriptor_t create_socket_unix(void);
391
392void socket_bind_unix(socket_descriptor_t sd, struct sockaddr_un *local, const char *prefix);
393
394socket_descriptor_t socket_accept_unix(socket_descriptor_t sd, struct sockaddr_un *remote);
395
396int socket_connect_unix(socket_descriptor_t sd, struct sockaddr_un *remote);
397
398void sockaddr_unix_init(struct sockaddr_un *local, const char *path);
399
400const char *sockaddr_unix_name(const struct sockaddr_un *local, const char *null);
401
402void socket_delete_unix(const struct sockaddr_un *local);
403
404bool unix_socket_get_peer_uid_gid(const socket_descriptor_t sd, uid_t *uid, gid_t *gid);
405
406#endif /* if UNIX_SOCK_SUPPORT */
407
408static inline bool
410{
411 if (sock)
412 {
414 }
415 else
416 {
417 return false;
418 }
419}
420
421#if PORT_SHARE
422
423static inline bool
424socket_foreign_protocol_detected(const struct link_socket *sock)
425{
426 return link_socket_connection_oriented(sock) && sock->stream_buf.port_share_state == PS_FOREIGN;
427}
428
429static inline const struct buffer *
431{
432 return &sock->stream_buf.buf;
433}
434
435static inline int
436socket_foreign_protocol_sd(const struct link_socket *sock)
437{
438 return sock->sd;
439}
440
441#endif /* if PORT_SHARE */
442
443static inline bool
445{
447 {
448 if (sock->stream_reset || sock->stream_buf.error)
449 {
450 return true;
451 }
452 else if (status < 0)
453 {
454 const int err = openvpn_errno();
455#ifdef _WIN32
456 return err == WSAECONNRESET || err == WSAECONNABORTED
458#else
459 return err == ECONNRESET;
460#endif
461 }
462 }
463 return false;
464}
465
466static inline bool
468 const struct link_socket_actual *from_addr)
469{
470 if (buf->len > 0)
471 {
472 switch (from_addr->dest.addr.sa.sa_family)
473 {
474 case AF_INET6:
475 case AF_INET:
477 {
478 return false;
479 }
480 if (info->remote_float || (!info->lsa->remote_list))
481 {
482 return true;
483 }
484 if (addrlist_match_proto(&from_addr->dest, info->lsa->remote_list, info->proto))
485 {
486 return true;
487 }
488 }
489 }
490 return false;
491}
492
493static inline void
495 struct link_socket_actual **act)
496{
497 if (buf->len > 0)
498 {
499 struct link_socket_addr *lsa = info->lsa;
501 {
502 *act = &lsa->actual;
503 }
504 else
505 {
507 buf->len = 0;
508 *act = NULL;
509 }
510 }
511}
512
513static inline void
515 const char *common_name, struct env_set *es)
516{
517 struct link_socket_addr *lsa = info->lsa;
518 if (
519 /* new or changed address? */
521 || !addr_match_proto(&act->dest, &lsa->actual.dest, info->proto))
522 &&
523 /* address undef or address == remote or --float */
524 (info->remote_float
525 || (!lsa->remote_list || addrlist_match_proto(&act->dest, lsa->remote_list, info->proto))))
526 {
527 link_socket_connection_initiated(info, act, common_name, es);
528 }
529}
530
532
533static inline bool
535{
537 {
538 return stream_buf_read_setup_dowork(sock);
539 }
540 else
541 {
542 return true;
543 }
544}
545
551static inline bool
553{
554 return s->sockflags & SF_DCO_WIN;
555}
556
557/*
558 * Socket Read Routines
559 */
560
561int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf);
562
563#ifdef _WIN32
564
565static inline int
567 struct link_socket_actual *from)
568{
569 sockethandle_t sh = { .s = sock->sd };
570 if (socket_is_dco_win(sock))
571 {
572 *from = sock->info.lsa->actual;
573 sh.is_handle = true;
575 }
576 return sockethandle_finalize(sh, &sock->reads, buf, from);
577}
578
579#else /* ifdef _WIN32 */
580
581int link_socket_read_udp_posix(struct link_socket *sock, struct buffer *buf,
582 struct link_socket_actual *from);
583
584#endif /* ifdef _WIN32 */
585
586/* read a TCP or UDP packet from link */
587static inline int
588link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
589{
590 if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
591 /* unified UDPv4 and UDPv6, for DCO-WIN the kernel
592 * will strip the length header */
593 {
594 int res;
595
596#ifdef _WIN32
597 res = link_socket_read_udp_win32(sock, buf, from);
598#else
599 res = link_socket_read_udp_posix(sock, buf, from);
600#endif
601 return res;
602 }
603 else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
604 {
605 /* from address was returned by accept */
606 from->dest = sock->info.lsa->actual.dest;
607 return link_socket_read_tcp(sock, buf);
608 }
609 else
610 {
611 ASSERT(0);
612 return -1; /* NOTREACHED */
613 }
614}
615
616/*
617 * Socket Write routines
618 */
619
620ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf,
621 struct link_socket_actual *to);
622
623#ifdef _WIN32
624
625static inline int
626link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
627{
628 int err = 0;
629 int status = 0;
630 sockethandle_t sh = { .s = sock->sd, .is_handle = socket_is_dco_win(sock) };
631 if (overlapped_io_active(&sock->writes))
632 {
633 status = sockethandle_finalize(sh, &sock->writes, NULL, NULL);
634 if (status < 0)
635 {
636 err = SocketHandleGetLastError(sh);
637 }
638 }
639
640 /* dco-win mp requires control packets to be prepended with sockaddr */
641 if (sock->sockflags & SF_PREPEND_SA)
642 {
643 if (to->dest.addr.sa.sa_family == AF_INET)
644 {
645 buf_write_prepend(buf, &to->dest.addr.in4, sizeof(struct sockaddr_in));
646 }
647 else
648 {
649 buf_write_prepend(buf, &to->dest.addr.in6, sizeof(struct sockaddr_in6));
650 }
651 }
652
653 socket_send_queue(sock, buf, to);
654 if (status < 0)
655 {
657 return status;
658 }
659 else
660 {
661 return BLEN(buf);
662 }
663}
664
665#else /* ifdef _WIN32 */
666
667ssize_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock, struct buffer *buf,
668 struct link_socket_actual *to);
669
670
671static inline ssize_t
672link_socket_write_udp_posix(struct link_socket *sock, struct buffer *buf,
673 struct link_socket_actual *to)
674{
675#if ENABLE_IP_PKTINFO
676 if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
677 && addr_defined_ipi(to))
678 {
679 return link_socket_write_udp_posix_sendmsg(sock, buf, to);
680 }
681 else
682#endif
683 return sendto(sock->sd, BPTR(buf), BLEN(buf), 0, (struct sockaddr *)&to->dest.addr.sa,
684 (socklen_t)af_addr_size(to->dest.addr.sa.sa_family));
685}
686
687static inline ssize_t
688link_socket_write_tcp_posix(struct link_socket *sock, struct buffer *buf)
689{
690 return send(sock->sd, BPTR(buf), BLEN(buf), MSG_NOSIGNAL);
691}
692
693#endif /* ifdef _WIN32 */
694
695static inline ssize_t
696link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
697{
698#ifdef _WIN32
699 return link_socket_write_win32(sock, buf, to);
700#else
701 return link_socket_write_udp_posix(sock, buf, to);
702#endif
703}
704
705/* write a TCP or UDP packet to link */
706static inline ssize_t
707link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
708{
709 if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
710 {
711 /* unified UDPv4, UDPv6 and DCO-WIN (driver adds length header) */
712 return link_socket_write_udp(sock, buf, to);
713 }
714 else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
715 {
716 return link_socket_write_tcp(sock, buf, to);
717 }
718 else
719 {
720 ASSERT(0);
721 return -1; /* NOTREACHED */
722 }
723}
724
725#if PASSTOS_CAPABILITY
726
727/*
728 * Extract TOS bits. Assumes that ipbuf is a valid IPv4 packet.
729 */
730static inline void
731link_socket_extract_tos(struct link_socket *sock, const struct buffer *ipbuf)
732{
733 if (sock && ipbuf)
734 {
735 struct openvpn_iphdr *iph = (struct openvpn_iphdr *)BPTR(ipbuf);
736 sock->ptos = iph->tos;
737 sock->ptos_defined = true;
738 }
739}
740
741/*
742 * Set socket properties to reflect TOS bits which were extracted
743 * from tunnel packet.
744 */
745static inline void
746link_socket_set_tos(struct link_socket *sock)
747{
748 if (sock && sock->ptos_defined)
749 {
750 setsockopt(sock->sd, IPPROTO_IP, IP_TOS, (const void *)&sock->ptos, sizeof(sock->ptos));
751 }
752}
753
754#endif /* if PASSTOS_CAPABILITY */
755
756/*
757 * Socket I/O wait functions
758 */
759
760/*
761 * Extends the pre-existing read residual logic
762 * to all initialized sockets, ensuring the complete
763 * packet is read.
764 */
765bool sockets_read_residual(const struct context *c);
766
767static inline event_t
769{
770#ifdef _WIN32
771 return &sock->rw_handle;
772#else
773 return sock->sd;
774#endif
775}
776
778
779unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags,
780 void *arg, unsigned int *persistent);
781
782static inline void
783socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
784{
785 if (sock && !sock->listen_persistent_queued)
786 {
788 sock->listen_persistent_queued = true;
789 }
790}
791
792static inline void
794{
795#ifdef _WIN32
797#endif
798}
799
800const char *socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc);
801
802#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:180
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:1388
static event_t socket_event_handle(const struct link_socket *sock)
Definition socket.h:768
const char * socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc)
Definition socket.c:2078
static BOOL SocketHandleGetOverlappedResult(sockethandle_t sh, struct overlapped_io *io)
Definition socket.h:270
void link_socket_init_phase2(struct context *c, struct link_socket *sock)
Definition socket.c:1731
int socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
Definition socket.c:2682
ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.c:2466
void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf)
Definition socket.c:567
event_t socket_listen_event_handle(struct link_socket *sock)
Definition socket.c:2265
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
Definition socket.c:2045
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
Definition socket.c:1100
static ssize_t link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:707
static void socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
Definition socket.h:783
#define SF_DCO_WIN
Definition socket.h:196
void bad_address_length(int actual, int expected)
Definition socket.c:2284
static bool link_socket_connection_oriented(const struct link_socket *sock)
Definition socket.h:409
static bool stream_buf_read_setup(struct link_socket *sock)
Definition socket.h:534
void sd_close(socket_descriptor_t *sd)
Definition socket.c:3001
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition socket.h:793
static int link_socket_read_udp_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:566
static void SocketHandleSetLastError(sockethandle_t sh, DWORD err)
Definition socket.h:284
static bool socket_connection_reset(const struct link_socket *sock, int status)
Definition socket.h:444
socket_descriptor_t create_socket_tcp(struct addrinfo *)
Definition socket.c:583
static int SocketHandleGetLastError(sockethandle_t sh)
Definition socket.h:278
static void SocketHandleSetInvalError(sockethandle_t sh)
Definition socket.h:290
bool stream_buf_read_setup_dowork(struct link_socket *sock)
Definition socket.c:2168
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
Definition socket.c:794
int socket_recv_queue(struct link_socket *sock, int maxsize)
Definition socket.c:2581
void link_socket_close(struct link_socket *sock)
Definition socket.c:1852
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:467
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:514
static int link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:588
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:481
static void link_socket_get_outgoing_addr(struct buffer *buf, const struct link_socket_info *info, struct link_socket_actual **act)
Definition socket.h:494
#define SF_USE_IP_PKTINFO
Definition socket.h:191
#define MSG_NOSIGNAL
Definition socket.h:243
uint16_t packet_size_type
Definition socket.h:56
void link_socket_bad_outgoing_addr(void)
Definition socket.c:2005
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:552
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
Definition socket.c:2874
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
Definition socket.c:2011
int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
Definition socket.c:2296
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
Definition socket.c:1007
#define SF_PREPEND_SA
Definition socket.h:197
void do_preresolve(struct context *c)
Definition socket.c:330
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:1978
unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition socket.c:2967
static int openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition socket.h:299
static ssize_t link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:696
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix, bool ipv6only)
Definition socket.c:957
static int link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:626
struct link_socket * link_socket_new(void)
Definition socket.c:1374
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:1926
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:314
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
Definition socket.c:1904
static ssize_t openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)
Definition socket.h:307
bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags)
Definition socket.c:553
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:471
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:262
bool prepend_sa
Definition socket.h:263
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:409
SOCKET socket_descriptor_t
Definition syshead.h:445
uint32_t in_addr_t
Definition syshead.h:52
struct env_set * es
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