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-2026 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
107{
108 /* Buffer to hold the initial buffer that will be used to reset buf */
110
114
117
121
123 struct buffer buf;
124
128 int len;
129
132 bool error;
133#if PORT_SHARE
134#define PS_DISABLED 0
135#define PS_ENABLED 1
136#define PS_FOREIGN 2
138#endif
139};
140
141/*
142 * Used to set socket buffer sizes
143 */
145{
148};
149
158 bool reduce_size);
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
175 socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
176
177#ifdef _WIN32
181 struct rw_handle listen_handle; /* For listening on TCP socket in server mode */
182#endif
183
184 /* used for printing status info only */
185 unsigned int rwflags_debug;
186
187 /* used for long-term queueing of pre-accepted socket listen */
189
190 const char *remote_host;
191 const char *remote_port;
192 const char *local_host;
193 const char *local_port;
196
197#define LS_MODE_DEFAULT 0
198#define LS_MODE_TCP_LISTEN 1
199#define LS_MODE_TCP_ACCEPT_FROM 2
200 int mode;
201
204
206
207 int mtu; /* OS discovered MTU, or 0 if unknown */
208
209#define SF_USE_IP_PKTINFO (1 << 0)
210#define SF_TCP_NODELAY (1 << 1)
211#define SF_PORT_SHARE (1 << 2)
212#define SF_HOST_RANDOMIZE (1 << 3)
213#define SF_GETADDRINFO_DGRAM (1 << 4)
214#define SF_DCO_WIN (1 << 5)
215#define SF_PREPEND_SA (1 << 6)
216#define SF_PKTINFO_COPY_IIF (1 << 7)
217 unsigned int sockflags;
218 int mark;
219 const char *bind_dev;
220
221 /* for stream sockets */
225
226 /* HTTP proxy */
228
229 /* Socks proxy */
231 struct link_socket_actual socks_relay; /* Socks UDP relay address */
232
233 /* The OpenVPN server we will use the proxy to connect to */
234 const char *proxy_dest_host;
235 const char *proxy_dest_port;
236
237 /* Pointer to the server-poll to trigger the timeout in function which have
238 * their own loop instead of using the main oop */
240
241#if PASSTOS_CAPABILITY
242 /* used to get/set TOS. */
243#if defined(TARGET_LINUX)
244 uint8_t ptos;
245#else /* all the BSDs, Solaris, MacOS use plain "int" -> see "man ip" there */
246 int ptos;
247#endif
248 bool ptos_defined;
249#endif
250
251#ifdef ENABLE_DEBUG
252 int gremlin; /* --gremlin bits */
253#endif
254};
255
256/*
257 * Some Posix/Win32 differences.
258 */
259
260#ifndef MSG_NOSIGNAL
261#define MSG_NOSIGNAL 0
262#endif
263
264#ifdef _WIN32
265
266#define openvpn_close_socket(s) closesocket(s)
267
268int socket_recv_queue(struct link_socket *sock, int maxsize);
269
270int socket_send_queue(struct link_socket *sock, struct buffer *buf,
271 const struct link_socket_actual *to);
272
273typedef struct
274{
275 union
276 {
277 SOCKET s;
278 HANDLE h;
279 };
281 bool prepend_sa; /* are incoming packets prepended with sockaddr? */
283
284int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf,
285 struct link_socket_actual *from);
286
287static inline BOOL
289{
290 return sh.is_handle
291 ? GetOverlappedResult(sh.h, &io->overlapped, &io->size, FALSE)
292 : WSAGetOverlappedResult(sh.s, &io->overlapped, &io->size, FALSE, &io->flags);
293}
294
295static inline int
297{
298 return sh.is_handle ? (int)GetLastError() : WSAGetLastError();
299}
300
301inline static void
303{
304 sh.is_handle ? SetLastError(err) : WSASetLastError(err);
305}
306
307static inline void
309{
310 sh.is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(WSAEINVAL);
311}
312
313/* winsock(2).h uses slightly different types so to avoid conversion
314 errors we wrap these functions on Windows */
315
316static inline int
317openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds,
318 fd_set *exceptfds, struct timeval *timeout)
319{
320 (void)nfds; /* first argument ignored on Windows */
321 return select(0, readfds, writefds, exceptfds, timeout);
322}
323
324static inline ssize_t
325openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)
326{
327 ASSERT(len <= INT_MAX);
328 return send(sockfd, buf, (int)len, flags);
329}
330
331static inline int
332openvpn_bind(socket_descriptor_t sockfd, const struct sockaddr *addr, size_t addrlen)
333{
334 ASSERT(addrlen <= INT_MAX);
335 return bind(sockfd, addr, (int)addrlen);
336}
337
338#else /* ifdef _WIN32 */
339
340#define openvpn_close_socket(s) close(s)
341#define openvpn_select(nfds, readfds, writefds, exceptfds, timeout) \
342 select(nfds, readfds, writefds, exceptfds, timeout)
343#define openvpn_send(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
344#define openvpn_bind(sockfd, addr, addrlen) bind(sockfd, addr, addrlen)
345
346#endif /* ifdef _WIN32 */
347
348struct link_socket *link_socket_new(void);
349
350void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix,
351 bool ipv6only);
352
353int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout,
354 volatile int *signal_received);
355
356
357/*
358 * Initialize link_socket object.
359 */
360void link_socket_init_phase1(struct context *c, int sock_index, int mode);
361
362void link_socket_init_phase2(struct context *c, struct link_socket *sock);
363
364void do_preresolve(struct context *c);
365
366void link_socket_close(struct link_socket *sock);
367
369
370void bad_address_length(int actual, int expected);
371
372/* IPV4_INVALID_ADDR: returned by link_socket_current_remote()
373 * to ease redirect-gateway logic for ipv4 tunnels on ipv6 endpoints
374 */
375#define IPV4_INVALID_ADDR 0xffffffff
377
378const struct in6_addr *link_socket_current_remote_ipv6(const struct link_socket_info *info);
379
381 const struct link_socket_actual *addr,
382 const char *common_name, struct env_set *es);
383
384void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket_info *info,
385 const struct link_socket_actual *from_addr);
386
387void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai);
388
390
391void setenv_trusted(struct env_set *es, const struct link_socket_info *info);
392
393bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags);
394
395void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf);
396
397/*
398 * Low-level functions
399 */
400
401socket_descriptor_t create_socket_tcp(struct addrinfo *);
402
404 const bool nowait);
405
406#if UNIX_SOCK_SUPPORT
407
408socket_descriptor_t create_socket_unix(void);
409
410void socket_bind_unix(socket_descriptor_t sd, struct sockaddr_un *local, const char *prefix);
411
412socket_descriptor_t socket_accept_unix(socket_descriptor_t sd, struct sockaddr_un *remote);
413
414int socket_connect_unix(socket_descriptor_t sd, struct sockaddr_un *remote);
415
416void sockaddr_unix_init(struct sockaddr_un *local, const char *path);
417
418const char *sockaddr_unix_name(const struct sockaddr_un *local, const char *null);
419
420void socket_delete_unix(const struct sockaddr_un *local);
421
422bool unix_socket_get_peer_uid_gid(const socket_descriptor_t sd, uid_t *uid, gid_t *gid);
423
424#endif /* if UNIX_SOCK_SUPPORT */
425
426static inline bool
428{
429 if (sock)
430 {
432 }
433 else
434 {
435 return false;
436 }
437}
438
439#if PORT_SHARE
440
441static inline bool
442socket_foreign_protocol_detected(const struct link_socket *sock)
443{
444 return link_socket_connection_oriented(sock) && sock->stream_buf.port_share_state == PS_FOREIGN;
445}
446
447static inline const struct buffer *
449{
450 return &sock->stream_buf.buf;
451}
452
453static inline int
454socket_foreign_protocol_sd(const struct link_socket *sock)
455{
456 return sock->sd;
457}
458
459#endif /* if PORT_SHARE */
460
461static inline bool
463{
465 {
466 if (sock->stream_reset || sock->stream_buf.error)
467 {
468 return true;
469 }
470 else if (status < 0)
471 {
472 const int err = openvpn_errno();
473#ifdef _WIN32
474 return err == WSAECONNRESET || err == WSAECONNABORTED
476#else
477 return err == ECONNRESET;
478#endif
479 }
480 }
481 return false;
482}
483
484static inline bool
486 const struct link_socket_actual *from_addr)
487{
488 if (buf->len > 0)
489 {
490 switch (from_addr->dest.addr.sa.sa_family)
491 {
492 case AF_INET6:
493 case AF_INET:
495 {
496 return false;
497 }
498 if (info->remote_float || (!info->lsa->remote_list))
499 {
500 return true;
501 }
502 if (addrlist_match_proto(&from_addr->dest, info->lsa->remote_list, info->proto))
503 {
504 return true;
505 }
506 }
507 }
508 return false;
509}
510
511static inline void
513 struct link_socket_actual **act)
514{
515 if (buf->len > 0)
516 {
517 struct link_socket_addr *lsa = info->lsa;
519 {
520 *act = &lsa->actual;
521 }
522 else
523 {
525 buf->len = 0;
526 *act = NULL;
527 }
528 }
529}
530
531static inline void
533 const char *common_name, struct env_set *es)
534{
535 struct link_socket_addr *lsa = info->lsa;
536 if (
537 /* new or changed address? */
539 || !addr_match_proto(&act->dest, &lsa->actual.dest, info->proto))
540 &&
541 /* address undef or address == remote or --float */
542 (info->remote_float
543 || (!lsa->remote_list || addrlist_match_proto(&act->dest, lsa->remote_list, info->proto))))
544 {
545 link_socket_connection_initiated(info, act, common_name, es);
546 }
547}
548
560
561static inline bool
563{
565 {
567 }
568 else
569 {
570 return true;
571 }
572}
573
579static inline bool
581{
582 return s->sockflags & SF_DCO_WIN;
583}
584
585/*
586 * Socket Read Routines
587 */
588
589int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf);
590
591#ifdef _WIN32
592
593static inline int
595 struct link_socket_actual *from)
596{
597 sockethandle_t sh = { .s = sock->sd };
598 if (socket_is_dco_win(sock))
599 {
600 *from = sock->info.lsa->actual;
601 sh.is_handle = true;
603 }
604 return sockethandle_finalize(sh, &sock->reads, buf, from);
605}
606
607#else /* ifdef _WIN32 */
608
609int link_socket_read_udp_posix(struct link_socket *sock, struct buffer *buf,
610 struct link_socket_actual *from);
611
612#endif /* ifdef _WIN32 */
613
614/* read a TCP or UDP packet from link */
615static inline int
616link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
617{
618 if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
619 /* unified UDPv4 and UDPv6, for DCO-WIN the kernel
620 * will strip the length header */
621 {
622 int res;
623
624#ifdef _WIN32
625 res = link_socket_read_udp_win32(sock, buf, from);
626#else
627 res = link_socket_read_udp_posix(sock, buf, from);
628#endif
629 return res;
630 }
631 else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
632 {
633 /* from address was returned by accept */
634 from->dest = sock->info.lsa->actual.dest;
635 return link_socket_read_tcp(sock, buf);
636 }
637 else
638 {
639 ASSERT(0);
640 return -1; /* NOTREACHED */
641 }
642}
643
644/*
645 * Socket Write routines
646 */
647
648ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf,
649 struct link_socket_actual *to);
650
651#ifdef _WIN32
652
653static inline int
654link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
655{
656 int err = 0;
657 int status = 0;
658 sockethandle_t sh = { .s = sock->sd, .is_handle = socket_is_dco_win(sock) };
659 if (overlapped_io_active(&sock->writes))
660 {
661 status = sockethandle_finalize(sh, &sock->writes, NULL, NULL);
662 if (status < 0)
663 {
664 err = SocketHandleGetLastError(sh);
665 }
666 }
667
668 /* dco-win mp requires control packets to be prepended with sockaddr */
669 if (sock->sockflags & SF_PREPEND_SA)
670 {
671 if (to->dest.addr.sa.sa_family == AF_INET)
672 {
673 buf_write_prepend(buf, &to->dest.addr.in4, sizeof(struct sockaddr_in));
674 }
675 else
676 {
677 buf_write_prepend(buf, &to->dest.addr.in6, sizeof(struct sockaddr_in6));
678 }
679 }
680
681 socket_send_queue(sock, buf, to);
682 if (status < 0)
683 {
685 return status;
686 }
687 else
688 {
689 return BLEN(buf);
690 }
691}
692
693#else /* ifdef _WIN32 */
694
695ssize_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock, struct buffer *buf,
696 struct link_socket_actual *to);
697
698
699static inline ssize_t
700link_socket_write_udp_posix(struct link_socket *sock, struct buffer *buf,
701 struct link_socket_actual *to)
702{
703#if ENABLE_IP_PKTINFO
704 if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
705 && addr_defined_ipi(to))
706 {
707 return link_socket_write_udp_posix_sendmsg(sock, buf, to);
708 }
709 else
710#endif
711 return sendto(sock->sd, BPTR(buf), BLENZ(buf), 0, (struct sockaddr *)&to->dest.addr.sa,
712 (socklen_t)af_addr_size(to->dest.addr.sa.sa_family));
713}
714
715static inline ssize_t
716link_socket_write_tcp_posix(struct link_socket *sock, struct buffer *buf)
717{
718 return send(sock->sd, BPTR(buf), BLENZ(buf), MSG_NOSIGNAL);
719}
720
721#endif /* ifdef _WIN32 */
722
723static inline ssize_t
724link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
725{
726#ifdef _WIN32
727 return link_socket_write_win32(sock, buf, to);
728#else
729 return link_socket_write_udp_posix(sock, buf, to);
730#endif
731}
732
733/* write a TCP or UDP packet to link */
734static inline ssize_t
735link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
736{
737 if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
738 {
739 /* unified UDPv4, UDPv6 and DCO-WIN (driver adds length header) */
740 return link_socket_write_udp(sock, buf, to);
741 }
742 else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
743 {
744 return link_socket_write_tcp(sock, buf, to);
745 }
746 else
747 {
748 ASSERT(0);
749 return -1; /* NOTREACHED */
750 }
751}
752
753#if PASSTOS_CAPABILITY
754
755/*
756 * Extract TOS bits. Assumes that ipbuf is a valid IPv4 packet.
757 */
758static inline void
759link_socket_extract_tos(struct link_socket *sock, const struct buffer *ipbuf)
760{
761 if (sock && ipbuf)
762 {
763 struct openvpn_iphdr *iph = (struct openvpn_iphdr *)BPTR(ipbuf);
764 sock->ptos = iph->tos;
765 sock->ptos_defined = true;
766 }
767}
768
769/*
770 * Set socket properties to reflect TOS bits which were extracted
771 * from tunnel packet.
772 */
773static inline void
774link_socket_set_tos(struct link_socket *sock)
775{
776 if (sock && sock->ptos_defined)
777 {
778 setsockopt(sock->sd, IPPROTO_IP, IP_TOS, (const void *)&sock->ptos, sizeof(sock->ptos));
779 }
780}
781
782#endif /* if PASSTOS_CAPABILITY */
783
784/*
785 * Socket I/O wait functions
786 */
787
788/*
789 * Extends the pre-existing read residual logic
790 * to all initialized sockets, ensuring the complete
791 * packet is read.
792 */
793bool sockets_read_residual(const struct context *c);
794
795static inline event_t
797{
798#ifdef _WIN32
799 return &sock->rw_handle;
800#else
801 return sock->sd;
802#endif
803}
804
806
807unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags,
808 void *arg, unsigned int *persistent);
809
810static inline void
811socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
812{
813 if (sock && !sock->listen_persistent_queued)
814 {
816 sock->listen_persistent_queued = true;
817 }
818}
819
820static inline void
822{
823#ifdef _WIN32
825#endif
826}
827
828const char *socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc);
829
830#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:673
#define BLEN(buf)
Definition buffer.h:126
#define BLENZ(buf)
Definition buffer.h:127
#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:1343
static event_t socket_event_handle(const struct link_socket *sock)
Definition socket.h:796
const char * socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc)
Definition socket.c:2022
static BOOL SocketHandleGetOverlappedResult(sockethandle_t sh, struct overlapped_io *io)
Definition socket.h:288
void link_socket_init_phase2(struct context *c, struct link_socket *sock)
Definition socket.c:1686
int socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
Definition socket.c:2654
ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.c:2439
void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf)
Definition socket.c:548
event_t socket_listen_event_handle(struct link_socket *sock)
Definition socket.c:2239
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
Definition socket.c:1989
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
Definition socket.c:1060
static ssize_t link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:735
static void socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
Definition socket.h:811
#define SF_DCO_WIN
Definition socket.h:214
void bad_address_length(int actual, int expected)
Definition socket.c:2258
static bool link_socket_connection_oriented(const struct link_socket *sock)
Definition socket.h:427
static bool stream_buf_read_setup(struct link_socket *sock)
Definition socket.h:562
void sd_close(socket_descriptor_t *sd)
Definition socket.c:2973
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition socket.h:821
static int link_socket_read_udp_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:594
static void SocketHandleSetLastError(sockethandle_t sh, DWORD err)
Definition socket.h:302
static bool socket_connection_reset(const struct link_socket *sock, int status)
Definition socket.h:462
socket_descriptor_t create_socket_tcp(struct addrinfo *)
Definition socket.c:564
static int SocketHandleGetLastError(sockethandle_t sh)
Definition socket.h:296
static void SocketHandleSetInvalError(sockethandle_t sh)
Definition socket.h:308
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
Definition socket.c:784
int socket_recv_queue(struct link_socket *sock, int maxsize)
Definition socket.c:2554
void link_socket_close(struct link_socket *sock)
Definition socket.c:1796
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:485
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:532
static int link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:616
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:462
bool stream_buf_read_setup_dowork(struct stream_buf *sb)
Will try to check if the buffers in stream form a full packet.
Definition socket.c:2126
static void link_socket_get_outgoing_addr(struct buffer *buf, const struct link_socket_info *info, struct link_socket_actual **act)
Definition socket.h:512
#define SF_USE_IP_PKTINFO
Definition socket.h:209
#define MSG_NOSIGNAL
Definition socket.h:261
uint16_t packet_size_type
Definition socket.h:56
void link_socket_bad_outgoing_addr(void)
Definition socket.c:1949
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:580
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
Definition socket.c:2846
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
Definition socket.c:1955
int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
Definition socket.c:2270
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
Definition socket.c:967
#define SF_PREPEND_SA
Definition socket.h:215
void do_preresolve(struct context *c)
Definition socket.c:323
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:1922
unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition socket.c:2939
static int openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition socket.h:317
static ssize_t link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:724
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix, bool ipv6only)
Definition socket.c:917
static int link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:654
struct link_socket * link_socket_new(void)
Definition socket.c:1329
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:1870
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:332
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
Definition socket.c:1848
static ssize_t openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)
Definition socket.h:325
bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags)
Definition socket.c:534
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:280
bool prepend_sa
Definition socket.h:281
struct used to extract packets encapsulated in streams into a buffer, in this case OpenVPN packets (d...
Definition socket.h:107
struct buffer buf
Holds the data of the current packet.
Definition socket.h:123
bool error
if true, a fatal TCP error has occurred, requiring that connection be restarted
Definition socket.h:132
struct buffer residual
buffer holding the excess bytes that are not part of the packet.
Definition socket.h:113
bool residual_fully_formed
The buffer in buf contains a full packet without a header.
Definition socket.h:120
int maxlen
Maximum length of a packet that we accept.
Definition socket.h:116
int len
-1 if not yet known.
Definition socket.h:128
struct buffer buf_init
Definition socket.h:109
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