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 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#else /* ifdef _WIN32 */
295
296#define openvpn_close_socket(s) close(s)
297
298#endif /* ifdef _WIN32 */
299
300struct link_socket *link_socket_new(void);
301
302void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix,
303 bool ipv6only);
304
305int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout,
306 volatile int *signal_received);
307
308
309/*
310 * Initialize link_socket object.
311 */
312void link_socket_init_phase1(struct context *c, int sock_index, int mode);
313
314void link_socket_init_phase2(struct context *c, struct link_socket *sock);
315
316void do_preresolve(struct context *c);
317
318void link_socket_close(struct link_socket *sock);
319
321
322void bad_address_length(int actual, int expected);
323
324/* IPV4_INVALID_ADDR: returned by link_socket_current_remote()
325 * to ease redirect-gateway logic for ipv4 tunnels on ipv6 endpoints
326 */
327#define IPV4_INVALID_ADDR 0xffffffff
328in_addr_t link_socket_current_remote(const struct link_socket_info *info);
329
330const struct in6_addr *link_socket_current_remote_ipv6(const struct link_socket_info *info);
331
333 const struct link_socket_actual *addr,
334 const char *common_name, struct env_set *es);
335
336void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket_info *info,
337 const struct link_socket_actual *from_addr);
338
339void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai);
340
342
343void setenv_trusted(struct env_set *es, const struct link_socket_info *info);
344
345bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags);
346
347void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf);
348
349/*
350 * Low-level functions
351 */
352
353socket_descriptor_t create_socket_tcp(struct addrinfo *);
354
356 const bool nowait);
357
358#if UNIX_SOCK_SUPPORT
359
360socket_descriptor_t create_socket_unix(void);
361
362void socket_bind_unix(socket_descriptor_t sd, struct sockaddr_un *local, const char *prefix);
363
364socket_descriptor_t socket_accept_unix(socket_descriptor_t sd, struct sockaddr_un *remote);
365
366int socket_connect_unix(socket_descriptor_t sd, struct sockaddr_un *remote);
367
368void sockaddr_unix_init(struct sockaddr_un *local, const char *path);
369
370const char *sockaddr_unix_name(const struct sockaddr_un *local, const char *null);
371
372void socket_delete_unix(const struct sockaddr_un *local);
373
374bool unix_socket_get_peer_uid_gid(const socket_descriptor_t sd, int *uid, int *gid);
375
376#endif /* if UNIX_SOCK_SUPPORT */
377
378static inline bool
380{
381 if (sock)
382 {
384 }
385 else
386 {
387 return false;
388 }
389}
390
391#if PORT_SHARE
392
393static inline bool
394socket_foreign_protocol_detected(const struct link_socket *sock)
395{
396 return link_socket_connection_oriented(sock) && sock->stream_buf.port_share_state == PS_FOREIGN;
397}
398
399static inline const struct buffer *
401{
402 return &sock->stream_buf.buf;
403}
404
405static inline int
406socket_foreign_protocol_sd(const struct link_socket *sock)
407{
408 return sock->sd;
409}
410
411#endif /* if PORT_SHARE */
412
413static inline bool
415{
417 {
418 if (sock->stream_reset || sock->stream_buf.error)
419 {
420 return true;
421 }
422 else if (status < 0)
423 {
424 const int err = openvpn_errno();
425#ifdef _WIN32
426 return err == WSAECONNRESET || err == WSAECONNABORTED
428#else
429 return err == ECONNRESET;
430#endif
431 }
432 }
433 return false;
434}
435
436static inline bool
438 const struct link_socket_actual *from_addr)
439{
440 if (buf->len > 0)
441 {
442 switch (from_addr->dest.addr.sa.sa_family)
443 {
444 case AF_INET6:
445 case AF_INET:
447 {
448 return false;
449 }
450 if (info->remote_float || (!info->lsa->remote_list))
451 {
452 return true;
453 }
454 if (addrlist_match_proto(&from_addr->dest, info->lsa->remote_list, info->proto))
455 {
456 return true;
457 }
458 }
459 }
460 return false;
461}
462
463static inline void
465 struct link_socket_actual **act)
466{
467 if (buf->len > 0)
468 {
469 struct link_socket_addr *lsa = info->lsa;
471 {
472 *act = &lsa->actual;
473 }
474 else
475 {
477 buf->len = 0;
478 *act = NULL;
479 }
480 }
481}
482
483static inline void
485 const char *common_name, struct env_set *es)
486{
487 struct link_socket_addr *lsa = info->lsa;
488 if (
489 /* new or changed address? */
491 || !addr_match_proto(&act->dest, &lsa->actual.dest, info->proto))
492 &&
493 /* address undef or address == remote or --float */
494 (info->remote_float
495 || (!lsa->remote_list || addrlist_match_proto(&act->dest, lsa->remote_list, info->proto))))
496 {
497 link_socket_connection_initiated(info, act, common_name, es);
498 }
499}
500
502
503static inline bool
505{
507 {
508 return stream_buf_read_setup_dowork(sock);
509 }
510 else
511 {
512 return true;
513 }
514}
515
521static inline bool
523{
524 return s->sockflags & SF_DCO_WIN;
525}
526
527/*
528 * Socket Read Routines
529 */
530
531int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf);
532
533#ifdef _WIN32
534
535static inline int
537 struct link_socket_actual *from)
538{
539 sockethandle_t sh = { .s = sock->sd };
540 if (socket_is_dco_win(sock))
541 {
542 *from = sock->info.lsa->actual;
543 sh.is_handle = true;
545 }
546 return sockethandle_finalize(sh, &sock->reads, buf, from);
547}
548
549#else /* ifdef _WIN32 */
550
551int link_socket_read_udp_posix(struct link_socket *sock, struct buffer *buf,
552 struct link_socket_actual *from);
553
554#endif /* ifdef _WIN32 */
555
556/* read a TCP or UDP packet from link */
557static inline int
558link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
559{
560 if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
561 /* unified UDPv4 and UDPv6, for DCO-WIN the kernel
562 * will strip the length header */
563 {
564 int res;
565
566#ifdef _WIN32
567 res = link_socket_read_udp_win32(sock, buf, from);
568#else
569 res = link_socket_read_udp_posix(sock, buf, from);
570#endif
571 return res;
572 }
573 else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
574 {
575 /* from address was returned by accept */
576 from->dest = sock->info.lsa->actual.dest;
577 return link_socket_read_tcp(sock, buf);
578 }
579 else
580 {
581 ASSERT(0);
582 return -1; /* NOTREACHED */
583 }
584}
585
586/*
587 * Socket Write routines
588 */
589
590ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf,
591 struct link_socket_actual *to);
592
593#ifdef _WIN32
594
595static inline int
596link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
597{
598 int err = 0;
599 int status = 0;
600 sockethandle_t sh = { .s = sock->sd, .is_handle = socket_is_dco_win(sock) };
601 if (overlapped_io_active(&sock->writes))
602 {
603 status = sockethandle_finalize(sh, &sock->writes, NULL, NULL);
604 if (status < 0)
605 {
606 err = SocketHandleGetLastError(sh);
607 }
608 }
609
610 /* dco-win mp requires control packets to be prepended with sockaddr */
611 if (sock->sockflags & SF_PREPEND_SA)
612 {
613 if (to->dest.addr.sa.sa_family == AF_INET)
614 {
615 buf_write_prepend(buf, &to->dest.addr.in4, sizeof(struct sockaddr_in));
616 }
617 else
618 {
619 buf_write_prepend(buf, &to->dest.addr.in6, sizeof(struct sockaddr_in6));
620 }
621 }
622
623 socket_send_queue(sock, buf, to);
624 if (status < 0)
625 {
627 return status;
628 }
629 else
630 {
631 return BLEN(buf);
632 }
633}
634
635#else /* ifdef _WIN32 */
636
637ssize_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock, struct buffer *buf,
638 struct link_socket_actual *to);
639
640
641static inline ssize_t
642link_socket_write_udp_posix(struct link_socket *sock, struct buffer *buf,
643 struct link_socket_actual *to)
644{
645#if ENABLE_IP_PKTINFO
646 if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
647 && addr_defined_ipi(to))
648 {
649 return link_socket_write_udp_posix_sendmsg(sock, buf, to);
650 }
651 else
652#endif
653 return sendto(sock->sd, BPTR(buf), BLEN(buf), 0, (struct sockaddr *)&to->dest.addr.sa,
654 (socklen_t)af_addr_size(to->dest.addr.sa.sa_family));
655}
656
657static inline ssize_t
658link_socket_write_tcp_posix(struct link_socket *sock, struct buffer *buf)
659{
660 return send(sock->sd, BPTR(buf), BLEN(buf), MSG_NOSIGNAL);
661}
662
663#endif /* ifdef _WIN32 */
664
665static inline ssize_t
666link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
667{
668#ifdef _WIN32
669 return link_socket_write_win32(sock, buf, to);
670#else
671 return link_socket_write_udp_posix(sock, buf, to);
672#endif
673}
674
675/* write a TCP or UDP packet to link */
676static inline ssize_t
677link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
678{
679 if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
680 {
681 /* unified UDPv4, UDPv6 and DCO-WIN (driver adds length header) */
682 return link_socket_write_udp(sock, buf, to);
683 }
684 else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
685 {
686 return link_socket_write_tcp(sock, buf, to);
687 }
688 else
689 {
690 ASSERT(0);
691 return -1; /* NOTREACHED */
692 }
693}
694
695#if PASSTOS_CAPABILITY
696
697/*
698 * Extract TOS bits. Assumes that ipbuf is a valid IPv4 packet.
699 */
700static inline void
701link_socket_extract_tos(struct link_socket *sock, const struct buffer *ipbuf)
702{
703 if (sock && ipbuf)
704 {
705 struct openvpn_iphdr *iph = (struct openvpn_iphdr *)BPTR(ipbuf);
706 sock->ptos = iph->tos;
707 sock->ptos_defined = true;
708 }
709}
710
711/*
712 * Set socket properties to reflect TOS bits which were extracted
713 * from tunnel packet.
714 */
715static inline void
716link_socket_set_tos(struct link_socket *sock)
717{
718 if (sock && sock->ptos_defined)
719 {
720 setsockopt(sock->sd, IPPROTO_IP, IP_TOS, (const void *)&sock->ptos, sizeof(sock->ptos));
721 }
722}
723
724#endif /* if PASSTOS_CAPABILITY */
725
726/*
727 * Socket I/O wait functions
728 */
729
730/*
731 * Extends the pre-existing read residual logic
732 * to all initialized sockets, ensuring the complete
733 * packet is read.
734 */
735bool sockets_read_residual(const struct context *c);
736
737static inline event_t
739{
740#ifdef _WIN32
741 return &sock->rw_handle;
742#else
743 return sock->sd;
744#endif
745}
746
748
749unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags,
750 void *arg, unsigned int *persistent);
751
752static inline void
753socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
754{
755 if (sock && !sock->listen_persistent_queued)
756 {
758 sock->listen_persistent_queued = true;
759 }
760}
761
762static inline void
764{
765#ifdef _WIN32
767#endif
768}
769
770const char *socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc);
771
772#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:38
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
Definition event.h:183
static SERVICE_STATUS status
Definition interactive.c:51
#define openvpn_errno()
Definition error.h:71
#define ASSERT(x)
Definition error.h:217
void link_socket_init_phase1(struct context *c, int sock_index, int mode)
Definition socket.c:1361
static event_t socket_event_handle(const struct link_socket *sock)
Definition socket.h:738
const char * socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc)
Definition socket.c:2051
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:1704
int socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
Definition socket.c:2649
ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.c:2437
void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf)
Definition socket.c:551
event_t socket_listen_event_handle(struct link_socket *sock)
Definition socket.c:2238
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
Definition socket.c:2018
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
Definition socket.c:1078
static ssize_t link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:677
static void socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
Definition socket.h:753
#define SF_DCO_WIN
Definition socket.h:196
void bad_address_length(int actual, int expected)
Definition socket.c:2257
static bool link_socket_connection_oriented(const struct link_socket *sock)
Definition socket.h:379
static bool stream_buf_read_setup(struct link_socket *sock)
Definition socket.h:504
void sd_close(socket_descriptor_t *sd)
Definition socket.c:2968
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition socket.h:763
static int link_socket_read_udp_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:536
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:414
socket_descriptor_t create_socket_tcp(struct addrinfo *)
Definition socket.c:567
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:2141
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
Definition socket.c:776
int socket_recv_queue(struct link_socket *sock, int maxsize)
Definition socket.c:2548
void link_socket_close(struct link_socket *sock)
Definition socket.c:1825
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:437
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:484
static int link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:558
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:465
static void link_socket_get_outgoing_addr(struct buffer *buf, const struct link_socket_info *info, struct link_socket_actual **act)
Definition socket.h:464
#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:1978
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:522
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
Definition socket.c:2841
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
Definition socket.c:1984
int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
Definition socket.c:2269
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
Definition socket.c:985
#define SF_PREPEND_SA
Definition socket.h:197
void do_preresolve(struct context *c)
Definition socket.c:314
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:1951
unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition socket.c:2934
static ssize_t link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:666
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix, bool ipv6only)
Definition socket.c:935
static int link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:596
struct link_socket * link_socket_new(void)
Definition socket.c:1347
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:1899
bool sockets_read_residual(const struct context *c)
Definition socket.c:45
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
Definition socket.c:1877
bool link_socket_update_flags(struct link_socket *sock, unsigned int sockflags)
Definition socket.c:537
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
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:154
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