OpenVPN
forward.c
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#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "syshead.h"
28
29#include "forward.h"
30#include "init.h"
31#include "push.h"
32#include "gremlin.h"
33#include "mss.h"
34#include "event.h"
35#include "occ.h"
36#include "otime.h"
37#include "ping.h"
38#include "ps.h"
39#include "dhcp.h"
40#include "common.h"
41#include "ssl_verify.h"
42#include "dco.h"
43#include "auth_token.h"
44#include "tun_afunix.h"
45#include "acc.h"
46
47#include "memdbg.h"
48
51
52/* show event wait debugging info */
53
54#ifndef ENABLE_SMALL
55
56static const char *
58{
59 struct buffer out = alloc_buf_gc(64, gc);
60
61 buf_printf(&out, "I/O WAIT %s|%s| %s", tun_stat(c->c1.tuntap, EVENT_READ, gc),
62 tun_stat(c->c1.tuntap, EVENT_WRITE, gc), tv_string(&c->c2.timeval, gc));
63 for (int i = 0; i < c->c1.link_sockets_num; i++)
64 {
65 buf_printf(&out, "\n %s|%s", socket_stat(c->c2.link_sockets[i], EVENT_READ, gc),
66 socket_stat(c->c2.link_sockets[i], EVENT_WRITE, gc));
67 }
68 return BSTR(&out);
69}
70
71static void
73{
74 struct gc_arena gc = gc_new();
76 gc_free(&gc);
77}
78
79#endif
80
81static void
83{
84 msg(D_STREAM_ERRORS, "Fatal TLS error (check_tls_errors_co), restarting");
85 register_signal(c->sig, c->c2.tls_exit_signal, "tls-error"); /* SOFT-SIGUSR1 -- TLS error */
86}
87
88static void
90{
91 register_signal(c->sig, c->c2.tls_exit_signal, "tls-error"); /* SOFT-SIGUSR1 -- TLS error */
92}
93
94/*
95 * TLS errors are fatal in TCP mode.
96 * Also check for --tls-exit trigger.
97 */
98static inline void
100{
101 if (c->c2.tls_multi && c->c2.tls_exit_signal)
102 {
104 {
105 if (c->c2.tls_multi->n_soft_errors)
106 {
108 }
109 }
110 else
111 {
112 if (c->c2.tls_multi->n_hard_errors)
113 {
115 }
116 }
117 }
118}
119
120/*
121 * Set our wakeup to 0 seconds, so we will be rescheduled
122 * immediately.
123 */
124static inline void
126{
127 c->c2.timeval.tv_sec = 0; /* ZERO-TIMEOUT */
128 c->c2.timeval.tv_usec = 0;
129}
130
131static inline void
132context_reschedule_sec(struct context *c, time_t sec)
133{
134 if (sec < 0)
135 {
136 sec = 0;
137 }
138 if (sec < c->c2.timeval.tv_sec)
139 {
140 c->c2.timeval.tv_sec = (tv_sec_t)sec;
141 c->c2.timeval.tv_usec = 0;
142 }
143}
144
145void
147{
148 /* DCO context is not yet initialised or enabled */
149 if (!dco_enabled(&c->options))
150 {
151 return;
152 }
153
154 /* no active peer (p2p tls-server mode) */
155 if (c->c2.tls_multi->dco_peer_id == -1)
156 {
157 return;
158 }
159
160 if (!dco_update_keys(&c->c1.tuntap->dco, c->c2.tls_multi))
161 {
162 /* Something bad happened. Kill the connection to
163 * be able to recover. */
164 register_signal(c->sig, SIGUSR1, "dco update keys error");
165 }
166}
167
168/*
169 * In TLS mode, let TLS level respond to any control-channel
170 * packets which were received, or prepare any packets for
171 * transmission.
172 *
173 * tmp_int is purely an optimization that allows us to call
174 * tls_multi_process less frequently when there's not much
175 * traffic on the control-channel.
176 *
177 */
178static void
180{
181 interval_t wakeup = BIG_TIMEOUT;
182
183 if (interval_test(&c->c2.tmp_int))
184 {
185 const int tmp_status = tls_multi_process(
186 c->c2.tls_multi, &c->c2.to_link, &c->c2.to_link_addr, get_link_socket_info(c), &wakeup);
187
188 if (tmp_status == TLSMP_RECONNECT)
189 {
192 }
193
194 if (tmp_status == TLSMP_ACTIVE || tmp_status == TLSMP_RECONNECT)
195 {
196 update_time();
198 }
199 else if (tmp_status == TLSMP_KILL)
200 {
201 if (c->options.mode == MODE_SERVER)
202 {
204 }
205 else
206 {
207 register_signal(c->sig, SIGTERM, "auth-control-exit");
208 }
209 }
210 else if (tmp_status == TLSMP_RESTART)
211 {
212 /* The session cannot recover on its own. Kill the connection so
213 * that it is set up again from scratch */
214 register_signal(c->sig, SIGUSR1, "dco key state desync");
215 }
216
218 }
219
220 interval_schedule_wakeup(&c->c2.tmp_int, &wakeup);
221
222 /*
223 * Our current code has no good hooks in the TLS machinery to update
224 * DCO keys. So we check the key status after the whole TLS machinery
225 * has been completed and potentially update them
226 *
227 * We have a hidden state transition from secondary to primary key based
228 * on ks->auth_deferred_expire that DCO needs to check that the normal
229 * TLS state engine does not check. So we call the \c check_dco_key_status
230 * function even if tmp_status does not indicate that something has changed.
231 */
233
234 if (wakeup)
235 {
236 context_reschedule_sec(c, wakeup);
237 }
238}
239
240static void
242{
243 if (buf_string_match_head_str(buf, "AUTH_FAILED"))
244 {
245 receive_auth_failed(c, buf);
246 }
247 else if (buf_string_match_head_str(buf, "PUSH_"))
248 {
249 incoming_push_message(c, buf);
250 }
251 else if (buf_string_match_head_str(buf, "RESTART"))
252 {
253 server_pushed_signal(c, buf, true, 7);
254 }
255 else if (buf_string_match_head_str(buf, "HALT"))
256 {
257 server_pushed_signal(c, buf, false, 4);
258 }
259 else if (buf_string_match_head_str(buf, "INFO_PRE"))
260 {
261 peer_pushed_info(c, buf, 8);
262 }
263 else if (buf_string_match_head_str(buf, "INFO"))
264 {
265 peer_pushed_info(c, buf, 4);
266 }
267 else if (buf_string_match_head_str(buf, "CR_RESPONSE"))
268 {
269 receive_cr_response(c, buf);
270 }
271 else if (buf_string_match_head_str(buf, "AUTH_PENDING"))
272 {
273 receive_auth_pending(c, buf);
274 }
275 else if (buf_string_match_head_str(buf, "ACC"))
276 {
277 receive_acc_message(c, buf);
278 }
279 else if (buf_string_match_head_str(buf, "EXIT"))
280 {
282 }
283 else
284 {
285 msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", CBSTR(buf));
286 }
287}
288
289#if defined(__GNUC__) || defined(__clang__)
290#pragma GCC diagnostic push
291#pragma GCC diagnostic ignored "-Wsign-conversion"
292#endif
293
294/*
295 * Handle incoming configuration
296 * messages on the control channel.
297 */
298static void
300{
301 int len = tls_test_payload_len(c->c2.tls_multi);
302 /* We should only be called with len >0 */
303 ASSERT(len > 0);
304
305 struct gc_arena gc = gc_new();
306 struct buffer buf = alloc_buf_gc(len, &gc);
307 if (tls_rec_payload(c->c2.tls_multi, &buf))
308 {
309 while (BLEN(&buf) > 1)
310 {
311 struct buffer cmdbuf = extract_command_buffer(&buf, &gc);
312
313 if (cmdbuf.len > 0)
314 {
316 }
317 }
318 }
319 else
320 {
321 msg(D_PUSH_ERRORS, "WARNING: Receive control message failed");
322 }
323
324 gc_free(&gc);
325}
326
327/*
328 * Periodically resend PUSH_REQUEST until PUSH message received
329 */
330static void
332{
334
335 /* if no response to first push_request, retry at PUSH_REQUEST_INTERVAL second intervals */
336 event_timeout_modify_wakeup(&c->c2.push_request_interval, PUSH_REQUEST_INTERVAL);
337}
338
339/*
340 * Things that need to happen immediately after connection initiation should go here.
341 *
342 * Options like --up-delay need to be triggered by this function which
343 * checks for connection establishment.
344 *
345 * Note: The process_incoming_push_reply currently assumes that this function
346 * only sets up the pull request timer when pull is enabled.
347 */
348static void
350{
352 {
353 /* if --pull was specified, send a push request to server */
354 if (c->c2.tls_multi && c->options.pull)
355 {
356#ifdef ENABLE_MANAGEMENT
357 if (management)
358 {
360 NULL);
361 }
362#endif
363 /* fire up push request right away (already 1s delayed) */
364 /* We might receive a AUTH_PENDING request before we armed this
365 * timer. In that case we don't change the value */
366 if (c->c2.push_request_timeout < now)
367 {
368 c->c2.push_request_timeout = now + c->options.handshake_window;
369 }
370 event_timeout_init(&c->c2.push_request_interval, 0, now);
372 }
373 else
374 {
375 if (!do_up(c, false, 0))
376 {
377 register_signal(c->sig, SIGUSR1, "connection initialisation failed");
378 }
379 }
380
381 event_timeout_clear(&c->c2.wait_for_connect);
382 }
383}
384
385bool
387 msglvl_t msglevel)
388{
389 struct gc_arena gc = gc_new();
390 bool stat;
391
393 struct key_state *ks = &session->key[KS_PRIMARY];
394
395 /* buffered cleartext write onto TLS control channel */
396 stat = tls_send_payload(ks, (uint8_t *)str, strlen(str) + 1);
397
398 msg(msglevel, "SENT CONTROL [%s]: '%s' (status=%d)",
399 session->common_name ? session->common_name : "UNDEF", sanitize_control_message(str, &gc),
400 (int)stat);
401
402 gc_free(&gc);
403 return stat;
404}
405
406void
408{
410 context_immediate_reschedule(c); /* ZERO-TIMEOUT */
411}
412
413bool
414send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
415{
416 if (c->c2.tls_multi)
417 {
419 bool ret = send_control_channel_string_dowork(session, str, msglevel);
421
422 return ret;
423 }
424 return true;
425}
426/*
427 * Add routes.
428 */
429
430static void
431check_add_routes_action(struct context *c, const bool errors)
432{
433 bool route_status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap,
434 c->plugins, c->c2.es, &c->net_ctx);
435
436 int flags = (errors ? ISC_ERRORS : 0);
437 flags |= (!route_status ? ISC_ROUTE_ERRORS : 0);
438
439 update_time();
442 initialization_sequence_completed(c, flags); /* client/p2p --route-delay was defined */
443}
444
445static void
447{
448 if (test_routes(c->c1.route_list, c->c1.tuntap))
449 {
450 check_add_routes_action(c, false);
451 }
453 {
455 }
456 else
457 {
458 msg(D_ROUTE, "Route: Waiting for TUN/TAP interface to come up...");
459 if (c->c1.tuntap)
460 {
461 if (!tun_standby(c->c1.tuntap))
462 {
463 register_signal(c->sig, SIGHUP, "ip-fail");
465#ifdef _WIN32
468#endif
469 }
470 }
471 update_time();
472 if (c->c2.route_wakeup.n != 1)
473 {
475 }
477 }
478}
479
480/*
481 * Should we exit due to inactivity timeout?
482 *
483 * In the non-dco case, the timeout is reset via register_activity()
484 * whenever there is sufficient activity on tun or link, so this function
485 * is only ever called to raise the TERM signal.
486 *
487 * With DCO, OpenVPN does not see incoming or outgoing data packets anymore
488 * and the logic needs to change - we permit the event to trigger and check
489 * kernel DCO counters here, returning and rearming the timer if there was
490 * sufficient traffic.
491 *
492 * NOTE: FreeBSD DCO does not supply "tun bytes" (= decrypted payload) today,
493 * so "dco bytes" (encrypted bytes, including keepalives) is used instead
494 */
495static void
497{
498 if (dco_enabled(&c->options) && dco_get_peer_stats(c, true) == 0)
499 {
500#ifdef TARGET_FREEBSD
501 int64_t tot_bytes = c->c2.dco_read_bytes + c->c2.dco_write_bytes;
502#else
503 int64_t tot_bytes = c->c2.tun_read_bytes + c->c2.tun_write_bytes;
504#endif
505 int64_t new_bytes = tot_bytes - c->c2.inactivity_bytes;
506
507 if (new_bytes > c->options.inactivity_minimum_bytes)
508 {
509 c->c2.inactivity_bytes = tot_bytes;
511 return;
512 }
513 }
514
515 msg(M_INFO, "Inactivity timeout (--inactive), exiting");
516 register_signal(c->sig, SIGTERM, "inactive");
517}
518
519int
520get_server_poll_remaining_time(const struct event_timeout *server_poll_timeout)
521{
522 update_time();
523 int remaining = event_timeout_remaining(server_poll_timeout);
524 return max_int(0, remaining);
525}
526
527static void
529{
531 ASSERT(c->c2.tls_multi);
533 {
534 msg(M_INFO, "Server poll timeout, restarting");
535 register_signal(c->sig, SIGUSR1, "server_poll");
537 }
538}
539
540/*
541 * Schedule a SIGTERM signal c->options.scheduled_exit_interval seconds from now.
542 */
543bool
545{
546 const int n_seconds = c->options.scheduled_exit_interval;
547 /* don't reschedule if already scheduled. */
549 {
550 return false;
551 }
552
553 /* DCO iroutes must be removed now, because the delay introduced by this
554 * timer can create a race condition:
555 * the same client may reconnect before the old instance is purged, leading
556 * to DCO iroutes removal *after* reconnection, thus killing the routes
557 * for the new instance too.
558 *
559 * Standard/virtual iroutes (non-DCO case) are not affected because the
560 * last connecting client claiming the iroutes takes ownership. Therefore
561 * they are not removed during delayed cleanup.
562 */
563 if (c->did_dco_iroutes)
564 {
565 c->did_dco_iroutes = false;
567 }
568
570 update_time();
572 event_timeout_init(&c->c2.scheduled_exit, n_seconds, now);
574 msg(D_SCHED_EXIT, "Delayed exit in %d seconds", n_seconds);
575 return true;
576}
577
578/*
579 * Scheduled exit?
580 */
581static void
583{
584 register_signal(c->sig, c->c2.scheduled_exit_signal, "delayed-exit");
585}
586
587/*
588 * Should we write timer-triggered status file.
589 */
590static void
592{
593 if (c->c1.status_output)
594 {
596 }
597}
598
599#ifdef ENABLE_FRAGMENT
600/*
601 * Should we deliver a datagram fragment to remote?
602 * c is expected to be a single-link context (p2p or child)
603 */
604static void
606{
607 struct link_socket_info *lsi = get_link_socket_info(c);
608
609 /* OS MTU Hint? */
610 if (lsi->mtu_changed && lsi->lsa)
611 {
613 lsi->mtu_changed = false;
614 }
615
617 {
618 if (!c->c2.to_link.len)
619 {
620 /* encrypt a fragment for output to TCP/UDP port */
622 encrypt_sign(c, false);
623 }
624 }
625
627}
628#endif /* ifdef ENABLE_FRAGMENT */
629
630/*
631 * Buffer reallocation, for use with null encryption.
632 */
633static inline void
634buffer_turnover(const uint8_t *orig_buf, struct buffer *dest_stub, const struct buffer *src_stub,
635 struct buffer *storage)
636{
637 if (orig_buf == src_stub->data && src_stub->data != storage->data)
638 {
639 buf_assign(storage, src_stub);
640 *dest_stub = *storage;
641 }
642 else
643 {
644 *dest_stub = *src_stub;
645 }
646}
647
648/*
649 * Compress, fragment, encrypt and HMAC-sign an outgoing packet.
650 * Input: c->c2.buf
651 * Output: c->c2.to_link
652 */
653void
654encrypt_sign(struct context *c, bool comp_frag)
655{
656 struct context_buffers *b = c->c2.buffers;
657 const uint8_t *orig_buf = c->c2.buf.data;
658 struct crypto_options *co = NULL;
659
660 if (dco_enabled(&c->options))
661 {
662 msg(M_WARN, "Attempting to send data packet while data channel offload is in use. "
663 "Dropping packet");
664 c->c2.buf.len = 0;
665 }
666
667 /*
668 * Drop non-TLS outgoing packet if client-connect script/plugin
669 * has not yet succeeded. In non-TLS tls_multi mode is not defined
670 * and we always pass packets.
671 */
673 {
674 c->c2.buf.len = 0;
675 }
676
677 if (comp_frag)
678 {
679#ifdef USE_COMP
680 /* Compress the packet. */
681 if (c->c2.comp_context)
682 {
683 (*c->c2.comp_context->alg.compress)(&c->c2.buf, b->compress_buf, c->c2.comp_context,
684 &c->c2.frame);
685 }
686#endif
687#ifdef ENABLE_FRAGMENT
688 if (c->c2.fragment)
689 {
691 }
692#endif
693 }
694
695 /* initialize work buffer with buf.headroom bytes of prepend capacity */
697
698 if (c->c2.tls_multi)
699 {
700 /* Get the key we will use to encrypt the packet. */
701 tls_pre_encrypt(c->c2.tls_multi, &c->c2.buf, &co);
702 /* If using P_DATA_V2, prepend the 1-byte opcode and 3-byte peer-id to the
703 * packet before openvpn_encrypt(), so we can authenticate the opcode too.
704 */
705 if (c->c2.buf.len > 0 && c->c2.tls_multi->use_peer_id)
706 {
708 }
709 }
710 else
711 {
712 co = &c->c2.crypto_options;
713 }
714
715 /* Encrypt and authenticate the packet */
716 openvpn_encrypt(&c->c2.buf, b->encrypt_buf, co);
717
718 /* Do packet administration */
719 if (c->c2.tls_multi)
720 {
721 if (c->c2.buf.len > 0 && !c->c2.tls_multi->use_peer_id)
722 {
724 }
726 }
727
728 /*
729 * Get the address we will be sending the packet to.
730 */
732
733 /* if null encryption, copy result to read_tun_buf */
734 buffer_turnover(orig_buf, &c->c2.to_link, &c->c2.buf, &b->read_tun_buf);
735}
736
737/*
738 * Should we exit due to session timeout?
739 */
740static void
742{
745 {
746 msg(M_INFO, "Session timeout, exiting");
747 register_signal(c->sig, SIGTERM, "session-timeout");
748 }
749}
750
751/*
752 * Coarse timers work to 1 second resolution.
753 */
754static void
756{
757 /* Should we write timer-triggered status file */
758 if (c->c1.status_output
760 {
762 }
763
764 /* process connection establishment items */
766 {
768 }
769
770 /* see if we should send a push_request (option --pull) */
772 {
774 }
775
776 /* process --route options */
778 {
780 }
781
782 /* check if we want to refresh the auth-token */
784 {
786 }
787
788 /* possibly exit due to --inactive */
791 {
793 }
794
795 if (c->sig->signal_received)
796 {
797 return;
798 }
799
800 /* kill session if time is over */
802 if (c->sig->signal_received)
803 {
804 return;
805 }
806
807 /* restart if ping not received */
809 if (c->sig->signal_received)
810 {
811 return;
812 }
813
814 if (c->c2.tls_multi)
815 {
818 {
820 }
821 if (c->sig->signal_received)
822 {
823 return;
824 }
826 {
828 }
829 if (c->sig->signal_received)
830 {
831 return;
832 }
833 }
834
835 /* Should we send an OCC_REQUEST message? */
837
838 /* Should we send an MTU load test? */
840
841 /* Should we send an OCC_EXIT message to remote? */
843 {
845 }
846
847 /* Should we ping the remote? */
849
850#ifdef ENABLE_MANAGEMENT
851 if (management)
852 {
854 }
855#endif /* ENABLE_MANAGEMENT */
856}
857
858static void
860{
861 if (now < c->c2.coarse_timer_wakeup)
862 {
864 return;
865 }
866
867 const struct timeval save = c->c2.timeval;
868 c->c2.timeval.tv_sec = BIG_TIMEOUT;
869 c->c2.timeval.tv_usec = 0;
871 c->c2.coarse_timer_wakeup = now + c->c2.timeval.tv_sec;
872
873 dmsg(D_INTERVAL, "TIMER: coarse timer wakeup %" PRIi64 " seconds",
874 (int64_t)c->c2.timeval.tv_sec);
875
876 /* Is the coarse timeout NOT the earliest one? */
877 if (c->c2.timeval.tv_sec > save.tv_sec)
878 {
879 c->c2.timeval = save;
880 }
881}
882
883static void
885{
886 const int update_interval = 10; /* seconds */
887 c->c2.update_timeout_random_component = now + update_interval;
888 c->c2.timeout_random_component.tv_usec = (time_t)get_random() & 0x0003FFFF;
889 c->c2.timeout_random_component.tv_sec = 0;
890
891 dmsg(D_INTERVAL, "RANDOM USEC=%ld", (long)c->c2.timeout_random_component.tv_usec);
892}
893
894static inline void
896{
898 {
900 }
901 if (c->c2.timeval.tv_sec >= 1)
902 {
904 }
905}
906
907/*
908 * Handle addition and removal of the 10-byte Socks5 header
909 * in UDP packets.
910 */
911
912static inline void
914{
915 if (sock->socks_proxy && sock->info.proto == PROTO_UDP)
916 {
918 }
919}
920
921static inline void
923 struct link_socket_actual **to_addr, int *size_delta)
924{
925 if (sock->socks_proxy && sock->info.proto == PROTO_UDP)
926 {
927 *size_delta += socks_process_outgoing_udp(&c->c2.to_link, c->c2.to_link_addr);
928 *to_addr = &sock->socks_relay;
929 }
930}
931
932/* undo effect of socks_preprocess_outgoing_link */
933static inline void
934link_socket_write_post_size_adjust(int *size, int size_delta, struct buffer *buf)
935{
936 if (size_delta > 0 && *size > size_delta)
937 {
938 *size -= size_delta;
939 if (!buf_advance(buf, size_delta))
940 {
941 *size = 0;
942 }
943 }
944}
945
946/*
947 * Output: c->c2.buf
948 */
949
950void
951read_incoming_link(struct context *c, struct link_socket *sock)
952{
953 /*
954 * Set up for recvfrom call to read datagram
955 * sent to our TCP/UDP port.
956 */
957 /*ASSERT (!c->c2.to_tun.len);*/
958
959 c->c2.buf = c->c2.buffers->read_link_buf;
961
962 ssize_t status = link_socket_read(sock, &c->c2.buf, &c->c2.from);
963
965 {
966#if PORT_SHARE
967 if (port_share && socket_foreign_protocol_detected(sock))
968 {
969 const struct buffer *fbuf = socket_foreign_protocol_head(sock);
970 const int sd = socket_foreign_protocol_sd(sock);
972 register_signal(c->sig, SIGTERM, "port-share-redirect");
973 }
974 else
975#endif
976 {
977 /* received a disconnect from a connection-oriented protocol */
978 if (event_timeout_defined(&c->c2.explicit_exit_notification_interval))
979 {
981 "Connection reset during exit notification period, ignoring [%zd]", status);
983 }
984 else
985 {
987 "connection-reset"); /* SOFT-SIGUSR1 -- TCP connection reset */
988 msg(D_STREAM_ERRORS, "Connection reset, restarting [%zd]", status);
989 }
990 }
991 return;
992 }
993
994 /* check_status() call below resets last-error code */
996
997 /* check recvfrom status */
998 check_status(status, "read", sock, NULL);
999
1000 if (dco_win_timeout)
1001 {
1003 }
1004
1005 /* Remove socks header if applicable */
1007}
1008
1009bool
1011{
1012 struct gc_arena gc = gc_new();
1013 bool decrypt_status = false;
1014
1015 if (c->c2.buf.len > 0)
1016 {
1017 c->c2.link_read_bytes += c->c2.buf.len;
1019 c->c2.original_recv_size = c->c2.buf.len;
1020 }
1021 else
1022 {
1023 c->c2.original_recv_size = 0;
1024 }
1025
1026#ifdef ENABLE_DEBUG
1027 /* take action to corrupt packet if we are in gremlin test mode */
1028 if (c->options.gremlin)
1029 {
1030 if (!ask_gremlin(c->options.gremlin))
1031 {
1032 c->c2.buf.len = 0;
1033 }
1034 corrupt_gremlin(&c->c2.buf, c->options.gremlin);
1035 }
1036#endif
1037
1038 /* log incoming packet */
1039#ifdef LOG_RW
1040 if (c->c2.log_rw && c->c2.buf.len > 0)
1041 {
1042 fprintf(stderr, "R");
1043 }
1044#endif
1045 msg(D_LINK_RW, "%s READ [%d] from %s: %s", proto2ascii(lsi->proto, lsi->af, true),
1046 BLEN(&c->c2.buf), print_link_socket_actual(&c->c2.from, &gc), PROTO_DUMP(&c->c2.buf, &gc));
1047
1048 /*
1049 * Good, non-zero length packet received.
1050 * Commence multi-stage processing of packet,
1051 * such as authenticate, decrypt, decompress.
1052 * If any stage fails, it sets buf.len to 0,
1053 * telling downstream stages to ignore the packet.
1054 */
1055 if (c->c2.buf.len > 0)
1056 {
1057 struct crypto_options *co = NULL;
1058 const uint8_t *ad_start = NULL;
1059 if (!link_socket_verify_incoming_addr(&c->c2.buf, lsi, &c->c2.from))
1060 {
1062 }
1063
1064 if (c->c2.tls_multi)
1065 {
1066 uint8_t opcode = *BPTR(&c->c2.buf) >> P_OPCODE_SHIFT;
1067
1068 /*
1069 * If DCO is enabled, the kernel drivers require that the
1070 * other end only sends P_DATA_V2 packets. V1 are unknown
1071 * to kernel and passed to userland, but we cannot handle them
1072 * either because crypto context is missing - so drop the packet.
1073 *
1074 * This can only happen with particular old (2.4.0-2.4.4) servers.
1075 */
1076 if ((opcode == P_DATA_V1) && dco_enabled(&c->options))
1077 {
1078 msg(D_LINK_ERRORS, "Data Channel Offload doesn't support DATA_V1 packets. "
1079 "Upgrade your server to 2.4.5 or newer.");
1080 c->c2.buf.len = 0;
1081 }
1082
1083 /*
1084 * If tls_pre_decrypt returns true, it means the incoming
1085 * packet was a good TLS control channel packet. If so, TLS code
1086 * will deal with the packet and set buf.len to 0 so downstream
1087 * stages ignore it.
1088 *
1089 * If the packet is a data channel packet, tls_pre_decrypt
1090 * will load crypto_options with the correct encryption key
1091 * and return false.
1092 */
1093 if (tls_pre_decrypt(c->c2.tls_multi, &c->c2.from, &c->c2.buf, &co, floated, &ad_start))
1094 {
1096
1097 /* reset packet received timer if TLS packet */
1099 {
1101 }
1102 }
1103 }
1104 else
1105 {
1106 co = &c->c2.crypto_options;
1107 }
1108
1109 /*
1110 * Drop non-TLS packet if client-connect script/plugin and cipher selection
1111 * has not yet succeeded. In non-TLS mode tls_multi is not defined
1112 * and we always pass packets.
1113 */
1115 {
1116 c->c2.buf.len = 0;
1117 }
1118
1119 /* authenticate and decrypt the incoming packet */
1120 decrypt_status =
1121 openvpn_decrypt(&c->c2.buf, c->c2.buffers->decrypt_buf, co, &c->c2.frame, ad_start);
1122
1123 if (!decrypt_status
1124 /* on the instance context we have only one socket, so just check the first one */
1126 {
1127 /* decryption errors are fatal in TCP mode */
1129 "decryption-error"); /* SOFT-SIGUSR1 -- decryption error in TCP mode */
1130 msg(D_STREAM_ERRORS, "Fatal decryption error (process_incoming_link), restarting");
1131 }
1132 }
1133 else
1134 {
1135 buf_reset(&c->c2.to_tun);
1136 }
1137 gc_free(&gc);
1138
1139 return decrypt_status;
1140}
1141
1142void
1144 const uint8_t *orig_buf)
1145{
1146 if (c->c2.buf.len > 0)
1147 {
1148#ifdef ENABLE_FRAGMENT
1149 if (c->c2.fragment)
1150 {
1152 }
1153#endif
1154
1155#ifdef USE_COMP
1156 /* decompress the incoming packet */
1157 if (c->c2.comp_context)
1158 {
1159 (*c->c2.comp_context->alg.decompress)(&c->c2.buf, c->c2.buffers->decompress_buf,
1160 c->c2.comp_context, &c->c2.frame);
1161 }
1162#endif
1163
1164 /*
1165 * Set our "official" outgoing address, since
1166 * if buf.len is non-zero, we know the packet
1167 * authenticated. In TLS mode we do nothing
1168 * because TLS mode takes care of source address
1169 * authentication.
1170 *
1171 * Also, update the persisted version of our packet-id.
1172 */
1173 if (!TLS_MODE(c) && c->c2.buf.len > 0)
1174 {
1175 link_socket_set_outgoing_addr(lsi, &c->c2.from, NULL, c->c2.es);
1176 }
1177
1178 /* reset packet received timer */
1179 if (c->options.ping_rec_timeout && c->c2.buf.len > 0)
1180 {
1182 }
1183
1184 /* increment authenticated receive byte count */
1185 if (c->c2.buf.len > 0)
1186 {
1187 c->c2.link_read_bytes_auth += c->c2.buf.len;
1190 }
1191
1192 /* Did we just receive an openvpn ping packet? */
1193 if (is_ping_msg(&c->c2.buf))
1194 {
1195 dmsg(D_PING, "RECEIVED PING PACKET");
1196 c->c2.buf.len = 0; /* drop packet */
1197 }
1198
1199 /* Did we just receive an OCC packet? */
1200 if (is_occ_msg(&c->c2.buf))
1201 {
1203 }
1204
1205 buffer_turnover(orig_buf, &c->c2.to_tun, &c->c2.buf, &c->c2.buffers->read_link_buf);
1206
1207 /* to_tun defined + unopened tuntap can cause deadlock */
1208 if (!tuntap_defined(c->c1.tuntap))
1209 {
1210 c->c2.to_tun.len = 0;
1211 }
1212 }
1213 else
1214 {
1215 buf_reset(&c->c2.to_tun);
1216 }
1217}
1218
1219static void
1221{
1222 struct link_socket_info *lsi = &sock->info;
1223 const uint8_t *orig_buf = c->c2.buf.data;
1224
1225 process_incoming_link_part1(c, lsi, false);
1226 process_incoming_link_part2(c, lsi, orig_buf);
1227}
1228
1229void
1230extract_dco_float_peer_addr(const sa_family_t socket_family, struct openvpn_sockaddr *out_osaddr,
1231 const struct sockaddr *float_sa)
1232{
1233 if (float_sa->sa_family == AF_INET)
1234 {
1235 const struct sockaddr_in *float4 = (struct sockaddr_in *)float_sa;
1236 /* DCO treats IPv4-mapped IPv6 addresses as pure IPv4. However, on a
1237 * dual-stack socket, we need to preserve the mapping otherwise openvpn
1238 * will not be able to find the peer by its transport address.
1239 */
1240 if (socket_family == AF_INET6)
1241 {
1242 out_osaddr->addr.in6.sin6_family = AF_INET6;
1243 out_osaddr->addr.in6.sin6_port = float4->sin_port;
1244
1245 memset(&out_osaddr->addr.in6.sin6_addr.s6_addr, 0, 10);
1246 out_osaddr->addr.in6.sin6_addr.s6_addr[10] = 0xff;
1247 out_osaddr->addr.in6.sin6_addr.s6_addr[11] = 0xff;
1248 memcpy(&out_osaddr->addr.in6.sin6_addr.s6_addr[12], &float4->sin_addr.s_addr,
1249 sizeof(in_addr_t));
1250 }
1251 else
1252 {
1253 memcpy(&out_osaddr->addr.in4, float4, sizeof(struct sockaddr_in));
1254 }
1255 }
1256 else
1257 {
1258 const struct sockaddr_in6 *float6 = (struct sockaddr_in6 *)float_sa;
1259 memcpy(&out_osaddr->addr.in6, float6, sizeof(struct sockaddr_in6));
1260 }
1261}
1262
1263void
1265{
1266#if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))
1267 struct context *c = dco->c;
1268
1269 /* FreeBSD currently sends us removal notifcation with the old peer-id in
1270 * p2p mode with the ping timeout reason, so ignore that one to not shoot
1271 * ourselves in the foot and removing the just established session */
1272 if (dco->dco_message_peer_id != c->c2.tls_multi->dco_peer_id)
1273 {
1275 "%s: received message for mismatching peer-id %d, "
1276 "expected %d",
1277 __func__, dco->dco_message_peer_id, c->c2.tls_multi->dco_peer_id);
1278 return;
1279 }
1280
1281 switch (dco->dco_message_type)
1282 {
1283 case OVPN_CMD_DEL_PEER:
1284 /* peer is gone, unset ID to prevent more kernel calls */
1285 c->c2.tls_multi->dco_peer_id = -1;
1286 if (dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_EXPIRED)
1287 {
1289 "%s: received peer expired notification of for peer-id "
1290 "%d",
1291 __func__, dco->dco_message_peer_id);
1293 return;
1294 }
1295 break;
1296
1297 case OVPN_CMD_SWAP_KEYS:
1298 msg(D_DCO_DEBUG, "%s: received key rotation notification for peer-id %d", __func__,
1299 dco->dco_message_peer_id);
1301 break;
1302
1303 default:
1304 msg(D_DCO_DEBUG, "%s: received message of type %d - ignoring", __func__,
1305 dco->dco_message_type);
1306 return;
1307 }
1308
1309#endif /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD)) */
1310}
1311
1312/*
1313 * Output: c->c2.buf
1314 */
1315
1316void
1318{
1319 /*
1320 * Setup for read() call on TUN/TAP device.
1321 */
1322 /*ASSERT (!c->c2.to_link.len);*/
1323
1324 c->c2.buf = c->c2.buffers->read_tun_buf;
1325
1326#ifdef _WIN32
1327 /* we cannot end up here when using dco */
1328 ASSERT(!dco_enabled(&c->options));
1329
1330 sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = false };
1331 sockethandle_finalize(sh, &c->c1.tuntap->reads, &c->c2.buf, NULL);
1332#else /* ifdef _WIN32 */
1336 {
1337 c->c2.buf.len =
1339 }
1340 else
1341 {
1342 c->c2.buf.len = (int)read_tun(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
1343 }
1344#endif /* ifdef _WIN32 */
1345
1346 /* Was TUN/TAP interface stopped? */
1347 if (tuntap_stop(c->c2.buf.len))
1348 {
1349 register_signal(c->sig, SIGTERM, "tun-stop");
1350 msg(M_INFO, "TUN/TAP interface has been stopped, exiting");
1351 return;
1352 }
1353
1354 /* Was TUN/TAP I/O operation aborted? */
1355 if (tuntap_abort(c->c2.buf.len))
1356 {
1357 register_signal(c->sig, SIGHUP, "tun-abort");
1359 msg(M_INFO, "TUN/TAP I/O operation aborted, restarting");
1360 return;
1361 }
1362
1363 /* Check the status return from read() */
1364 check_status(c->c2.buf.len, "read from TUN/TAP", NULL, c->c1.tuntap);
1365}
1366
1375static void
1377{
1378 if (c->c2.to_link_addr == NULL) /* no remote addr known */
1379 {
1380 return;
1381 }
1382
1383 const struct openvpn_sockaddr *link_addr = &c->c2.to_link_addr->dest;
1384 const struct link_socket_info *lsi = get_link_socket_info(c);
1385
1386 int ip_hdr_offset = 0;
1387 int tun_ip_ver = get_tun_ip_ver(TUNNEL_TYPE(c->c1.tuntap), buf, &ip_hdr_offset);
1388
1389 if (tun_ip_ver == 4)
1390 {
1391 /* Ensure we can safely read the IPv4 header */
1392 const int min_ip_header = ip_hdr_offset + sizeof(struct openvpn_iphdr);
1393 if (BLEN(buf) < min_ip_header)
1394 {
1395 return;
1396 }
1397
1398 struct openvpn_iphdr *pip = (struct openvpn_iphdr *)(BPTR(buf) + ip_hdr_offset);
1399 const int ip_hlen = OPENVPN_IPH_GET_LEN(pip->version_len);
1400 /* Reject malformed or truncated headers */
1401 if (ip_hlen < (int)sizeof(struct openvpn_iphdr)
1402 || BLENZ(buf) < ip_hdr_offset + ip_hlen + sizeof(uint16_t) * 2)
1403 {
1404 return;
1405 }
1406
1407 /* skip ipv4 packets for ipv6 tun */
1408 if (link_addr->addr.sa.sa_family != AF_INET)
1409 {
1410 return;
1411 }
1412
1413 /* skip if tun protocol doesn't match link protocol */
1414 if ((lsi->proto == PROTO_TCP && pip->protocol != OPENVPN_IPPROTO_TCP)
1415 || (lsi->proto == PROTO_UDP && pip->protocol != OPENVPN_IPPROTO_UDP))
1416 {
1417 return;
1418 }
1419
1420 /* drop packets with same dest addr and port as remote */
1421 const uint8_t *l4_hdr = (uint8_t *)pip + ip_hlen;
1422
1423 uint16_t link_port = ntohs(link_addr->addr.in4.sin_port);
1424
1425 /* TCP and UDP ports are at the same place in the header, and other protocols
1426 * can not happen here due to the lsi->proto check above */
1427 uint16_t src_port = ntohs(*(uint16_t *)l4_hdr);
1428 uint16_t dst_port = ntohs(*(uint16_t *)(l4_hdr + sizeof(uint16_t)));
1429 if ((memcmp(&link_addr->addr.in4.sin_addr.s_addr, &pip->daddr, sizeof(pip->daddr)) == 0) && (link_port == dst_port))
1430 {
1431 buf->len = 0;
1432
1433 struct gc_arena gc = gc_new();
1434 msg(D_LOW, "Recursive routing detected, packet dropped %s:%" PRIu16 " -> %s",
1436 src_port,
1438 gc_free(&gc);
1439 }
1440 }
1441 else if (tun_ip_ver == 6)
1442 {
1443 /* make sure we got whole IPv6 header and TCP/UDP src/dst ports */
1444 const int min_ipv6 = ip_hdr_offset + sizeof(struct openvpn_ipv6hdr) + sizeof(uint16_t) * 2;
1445 if (BLEN(buf) < min_ipv6)
1446 {
1447 return;
1448 }
1449
1450 /* skip ipv6 packets for ipv4 tun */
1451 if (link_addr->addr.sa.sa_family != AF_INET6)
1452 {
1453 return;
1454 }
1455
1456 struct openvpn_ipv6hdr *pip6 = (struct openvpn_ipv6hdr *)(BPTR(buf) + ip_hdr_offset);
1457
1458 /* skip if tun protocol doesn't match link protocol */
1459 if ((lsi->proto == PROTO_TCP && pip6->nexthdr != OPENVPN_IPPROTO_TCP)
1460 || (lsi->proto == PROTO_UDP && pip6->nexthdr != OPENVPN_IPPROTO_UDP))
1461 {
1462 return;
1463 }
1464
1465 uint16_t link_port = ntohs(link_addr->addr.in6.sin6_port);
1466
1467 /* drop packets with same dest addr and port as remote */
1468 const uint8_t *l4_hdr = (uint8_t *)pip6 + sizeof(struct openvpn_ipv6hdr);
1469 uint16_t src_port = ntohs(*(uint16_t *)l4_hdr);
1470 uint16_t dst_port = ntohs(*(uint16_t *)(l4_hdr + sizeof(uint16_t)));
1471 if ((OPENVPN_IN6_ARE_ADDR_EQUAL(&link_addr->addr.in6.sin6_addr, &pip6->daddr)) && (link_port == dst_port))
1472 {
1473 buf->len = 0;
1474
1475 struct gc_arena gc = gc_new();
1476 msg(D_LOW, "Recursive routing detected, packet dropped %s:%" PRIu16 " -> %s",
1478 src_port,
1480 gc_free(&gc);
1481 }
1482 }
1483}
1484
1485/*
1486 * Input: c->c2.buf
1487 * Output: c->c2.to_link
1488 */
1489
1490void
1491process_incoming_tun(struct context *c, struct link_socket *out_sock)
1492{
1493 if (c->c2.buf.len > 0)
1494 {
1495 c->c2.tun_read_bytes += c->c2.buf.len;
1496 }
1497
1498#ifdef LOG_RW
1499 if (c->c2.log_rw && c->c2.buf.len > 0)
1500 {
1501 fprintf(stderr, "r");
1502 }
1503#endif
1504
1505 /* Show packet content */
1506 dmsg(D_TUN_RW, "TUN READ [%d]", BLEN(&c->c2.buf));
1507
1508 if (c->c2.buf.len > 0)
1509 {
1511 {
1513 }
1514 /*
1515 * The --passtos and --mssfix options require
1516 * us to examine the IP header (IPv4 or IPv6).
1517 */
1518 unsigned int flags =
1520 process_ip_header(c, flags, &c->c2.buf, out_sock);
1521 }
1522 if (c->c2.buf.len > 0)
1523 {
1524 encrypt_sign(c, true);
1525 }
1526 else
1527 {
1528 buf_reset(&c->c2.to_link);
1529 }
1530}
1531
1542void
1543ipv6_send_icmp_unreachable(struct context *c, const struct buffer *buf, bool client)
1544{
1545#define MAX_ICMPV6LEN 1280
1546 struct openvpn_icmp6hdr icmp6out;
1547 CLEAR(icmp6out);
1548
1549 /*
1550 * Get a buffer to the ip packet, is_ipv6 automatically forwards
1551 * the buffer to the ip packet
1552 */
1553 struct buffer inputipbuf = *buf;
1554
1555 is_ipv6(TUNNEL_TYPE(c->c1.tuntap), &inputipbuf);
1556
1557 if (BLEN(&inputipbuf) < (int)sizeof(struct openvpn_ipv6hdr))
1558 {
1559 return;
1560 }
1561
1562 const struct openvpn_ipv6hdr *pip6 = (struct openvpn_ipv6hdr *)BPTR(&inputipbuf);
1563
1564 /* Copy version, traffic class, flow label from input packet */
1565 struct openvpn_ipv6hdr pip6out = *pip6;
1566
1567 pip6out.version_prio = pip6->version_prio;
1568 pip6out.daddr = pip6->saddr;
1569
1570 /*
1571 * Use the IPv6 remote address if we have one, otherwise use a fake one
1572 * using the remote address is preferred since it makes debugging and
1573 * understanding where the ICMPv6 error originates easier
1574 */
1576 {
1577 inet_pton(AF_INET6, c->options.ifconfig_ipv6_remote, &pip6out.saddr);
1578 }
1579 else
1580 {
1581 inet_pton(AF_INET6, "fe80::7", &pip6out.saddr);
1582 }
1583
1585
1586 /*
1587 * The ICMPv6 unreachable code worked best in my (arne) tests with Windows,
1588 * Linux and Android. Windows did not like the administratively prohibited
1589 * return code (no fast fail)
1590 */
1593
1594 const int icmpheader_len = sizeof(struct openvpn_ipv6hdr) + sizeof(struct openvpn_icmp6hdr);
1595 int totalheader_len = icmpheader_len;
1596
1597 if (TUNNEL_TYPE(c->c1.tuntap) == DEV_TYPE_TAP)
1598 {
1599 totalheader_len += sizeof(struct openvpn_ethhdr);
1600 }
1601
1602 /*
1603 * Calculate size for payload, defined in the standard that the resulting
1604 * frame should be <= 1280 and have as much as possible of the original
1605 * packet
1606 */
1607 int max_payload_size = min_int(MAX_ICMPV6LEN, c->c2.frame.tun_mtu - icmpheader_len);
1608 /* Ensure that minimum payload size is at least 64 bytes as extra safety layer */
1609 max_payload_size = max_int(max_payload_size, 64);
1610 const int payload_len = min_int(max_payload_size, BLEN(&inputipbuf));
1611 const uint16_t icmp_len = (uint16_t)(sizeof(struct openvpn_icmp6hdr) + payload_len);
1612
1613 pip6out.payload_len = htons(icmp_len);
1614
1615 /* Construct the packet as outgoing packet back to the client */
1616 struct buffer *outbuf;
1617 if (client)
1618 {
1619 c->c2.to_tun = c->c2.buffers->aux_buf;
1620 outbuf = &(c->c2.to_tun);
1621 }
1622 else
1623 {
1624 c->c2.to_link = c->c2.buffers->aux_buf;
1625 outbuf = &(c->c2.to_link);
1626 }
1628
1629 /* Fill the end of the buffer with original packet */
1630 ASSERT(buf_safe(outbuf, payload_len));
1631 ASSERT(buf_copy_n(outbuf, &inputipbuf, payload_len));
1632
1633 /* ICMP Header, copy into buffer to allow checksum calculation */
1635
1636 /* Calculate checksum over the packet and write to header */
1637
1641 ((struct openvpn_icmp6hdr *)BPTR(outbuf))->icmp6_cksum = htons(new_csum);
1642
1643
1644 /* IPv6 Header */
1645 ASSERT(buf_write_prepend(outbuf, &pip6out, sizeof(struct openvpn_ipv6hdr)));
1646
1647 /*
1648 * Tap mode, we also need to create an Ethernet header.
1649 */
1650 if (TUNNEL_TYPE(c->c1.tuntap) == DEV_TYPE_TAP)
1651 {
1652 if (BLEN(buf) < (int)sizeof(struct openvpn_ethhdr))
1653 {
1654 return;
1655 }
1656
1657 const struct openvpn_ethhdr *orig_ethhdr = (const struct openvpn_ethhdr *)CBPTR(buf);
1658
1659 /* Copy frametype and reverse source/destination for the response */
1660 struct openvpn_ethhdr ethhdr;
1661 memcpy(ethhdr.source, orig_ethhdr->dest, OPENVPN_ETH_ALEN);
1662 memcpy(ethhdr.dest, orig_ethhdr->source, OPENVPN_ETH_ALEN);
1663 ethhdr.proto = htons(OPENVPN_ETH_P_IPV6);
1664 ASSERT(buf_write_prepend(outbuf, &ethhdr, sizeof(struct openvpn_ethhdr)));
1665 }
1666#undef MAX_ICMPV6LEN
1667}
1668
1669void
1670process_ip_header(struct context *c, unsigned int flags, struct buffer *buf,
1671 struct link_socket *sock)
1672{
1673 if (!c->options.ce.mssfix)
1674 {
1675 flags &= ~PIP_MSSFIX;
1676 }
1677#if PASSTOS_CAPABILITY
1678 if (!c->options.passtos)
1679 {
1680 flags &= ~PIPV4_PASSTOS;
1681 }
1682#endif
1683 if (!c->options.client_nat)
1684 {
1685 flags &= ~PIPV4_CLIENT_NAT;
1686 }
1688 {
1689 flags &= ~PIPV4_EXTRACT_DHCP_ROUTER;
1690 }
1691 if (!c->options.block_ipv6)
1692 {
1694 }
1695
1696 if (buf->len > 0)
1697 {
1698 struct buffer ipbuf = *buf;
1699 if (is_ipv4(TUNNEL_TYPE(c->c1.tuntap), &ipbuf))
1700 {
1701#if PASSTOS_CAPABILITY
1702 /* extract TOS from IP header */
1703 if (flags & PIPV4_PASSTOS)
1704 {
1706 }
1707#endif
1708
1709 /* possibly alter the TCP MSS */
1710 if (flags & PIP_MSSFIX)
1711 {
1712 mss_fixup_ipv4(&ipbuf, c->c2.frame.mss_fix);
1713 }
1714
1715 /* possibly do NAT on packet */
1716 if ((flags & PIPV4_CLIENT_NAT) && c->options.client_nat)
1717 {
1718 const int direction = (flags & PIP_OUTGOING) ? CN_INCOMING : CN_OUTGOING;
1719 client_nat_transform(c->options.client_nat, &ipbuf, direction);
1720 }
1721 /* possibly extract a DHCP router message */
1722 if (flags & PIPV4_EXTRACT_DHCP_ROUTER)
1723 {
1725 if (dhcp_router)
1726 {
1727 route_list_add_vpn_gateway(c->c1.route_list, c->c2.es, dhcp_router);
1728 }
1729 }
1730 }
1731 else if (is_ipv6(TUNNEL_TYPE(c->c1.tuntap), &ipbuf))
1732 {
1733 /* possibly alter the TCP MSS */
1734 if (flags & PIP_MSSFIX)
1735 {
1736 mss_fixup_ipv6(&ipbuf, c->c2.frame.mss_fix);
1737 }
1738 if (!(flags & PIP_OUTGOING)
1740 {
1742 /* Drop the IPv6 packet */
1743 buf->len = 0;
1744 }
1745 }
1746 }
1747}
1748
1749/*
1750 * Input: c->c2.to_link
1751 */
1752
1753void
1755{
1756 struct gc_arena gc = gc_new();
1757
1758 if (c->c2.to_link.len > 0 && c->c2.to_link.len <= c->c2.frame.buf.payload_size)
1759 {
1760 /*
1761 * Setup for call to send/sendto which will send
1762 * packet to remote over the TCP/UDP port.
1763 */
1764 int size = 0;
1766
1767#ifdef ENABLE_DEBUG
1768 /* In gremlin-test mode, we may choose to drop this packet */
1769 if (!c->options.gremlin || ask_gremlin(c->options.gremlin))
1770#endif
1771 {
1772 /*
1773 * Let the traffic shaper know how many bytes
1774 * we wrote.
1775 */
1776 if (c->options.shaper)
1777 {
1778 int overhead =
1779 datagram_overhead(c->c2.to_link_addr->dest.addr.sa.sa_family, sock->info.proto);
1780 shaper_wrote_bytes(&c->c2.shaper, BLEN(&c->c2.to_link) + overhead);
1781 }
1782
1783 /*
1784 * Let the pinger know that we sent a packet.
1785 */
1787 {
1789 }
1790
1791#if PASSTOS_CAPABILITY
1792 /* Set TOS */
1793 link_socket_set_tos(sock);
1794#endif
1795
1796 /* Log packet send */
1797#ifdef LOG_RW
1798 if (c->c2.log_rw)
1799 {
1800 fprintf(stderr, "W");
1801 }
1802#endif
1803 msg(D_LINK_RW, "%s WRITE [%d] to %s: %s",
1804 proto2ascii(sock->info.proto, sock->info.af, true), BLEN(&c->c2.to_link),
1806
1807 /* Packet send complexified by possible Socks5 usage */
1808 {
1809 struct link_socket_actual *to_addr = c->c2.to_link_addr;
1810 int size_delta = 0;
1811
1812 /* If Socks5 over UDP, prepend header */
1813 socks_preprocess_outgoing_link(c, sock, &to_addr, &size_delta);
1814
1815 /* Send packet */
1816 size = (int)link_socket_write(sock, &c->c2.to_link, to_addr);
1817
1818 /* Undo effect of prepend */
1819 link_socket_write_post_size_adjust(&size, size_delta, &c->c2.to_link);
1820 }
1821
1822 if (size > 0)
1823 {
1825 c->c2.link_write_bytes += size;
1827 }
1828 }
1829
1830 /* Check return status */
1831 int error_code = openvpn_errno();
1832 check_status(size, "write", sock, NULL);
1833
1834 if (size > 0)
1835 {
1836 /* Did we write a different size packet than we intended? */
1837 if (size != BLEN(&c->c2.to_link))
1838 {
1840 "TCP/UDP packet was truncated/expanded on write to %s (tried=%d,actual=%d)",
1842 }
1843 }
1844
1845 /* if not a ping/control message, indicate activity regarding --inactive parameter */
1846 if (c->c2.buf.len > 0)
1847 {
1848 register_activity(c, size);
1849 }
1850
1851 /* for unreachable network and "connecting" state switch to the next host */
1852
1853 bool unreachable = error_code ==
1854#ifdef _WIN32
1855 WSAENETUNREACH;
1856#else
1857 ENETUNREACH;
1858#endif
1859 if (size < 0 && unreachable && c->c2.tls_multi
1862 {
1863 msg(M_INFO, "Network unreachable, restarting");
1864 register_signal(c->sig, SIGUSR1, "network-unreachable");
1865 }
1866 }
1867 else
1868 {
1869 if (c->c2.to_link.len > 0)
1870 {
1871 msg(D_LINK_ERRORS, "TCP/UDP packet too large on write to %s (tried=%d,max=%d)",
1874 }
1875 }
1876
1877 buf_reset(&c->c2.to_link);
1878
1879 gc_free(&gc);
1880}
1881
1882/*
1883 * Input: c->c2.to_tun
1884 */
1885
1886void
1887process_outgoing_tun(struct context *c, struct link_socket *in_sock)
1888{
1889 /*
1890 * Set up for write() call to TUN/TAP
1891 * device.
1892 */
1893 if (c->c2.to_tun.len <= 0)
1894 {
1895 return;
1896 }
1897
1898 /*
1899 * The --mssfix option requires
1900 * us to examine the IP header (IPv4 or IPv6).
1901 */
1903 &c->c2.to_tun, in_sock);
1904
1905 if (c->c2.to_tun.len <= c->c2.frame.buf.payload_size)
1906 {
1907 /*
1908 * Write to TUN/TAP device.
1909 */
1910 ssize_t size;
1911
1912#ifdef LOG_RW
1913 if (c->c2.log_rw)
1914 {
1915 fprintf(stderr, "w");
1916 }
1917#endif
1918 dmsg(D_TUN_RW, "TUN WRITE [%d]", BLEN(&c->c2.to_tun));
1919
1920#ifdef _WIN32
1921 size = tun_write_win32(c->c1.tuntap, &c->c2.to_tun);
1922#else
1924 {
1925 size = write_tun_afunix(c->c1.tuntap, BPTR(&c->c2.to_tun), BLEN(&c->c2.to_tun));
1926 }
1927 else
1928 {
1929 size = write_tun(c->c1.tuntap, BPTR(&c->c2.to_tun), BLEN(&c->c2.to_tun));
1930 }
1931#endif
1932
1933 if (size > 0)
1934 {
1935 c->c2.tun_write_bytes += size;
1936 }
1937 check_status(size, "write to TUN/TAP", NULL, c->c1.tuntap);
1938
1939 /* check written packet size */
1940 if (size > 0)
1941 {
1942 /* Did we write a different size packet than we intended? */
1943 if (size != BLEN(&c->c2.to_tun))
1944 {
1946 "TUN/TAP packet was destructively fragmented on write to %s (tried=%d,actual=%zd)",
1947 c->c1.tuntap->actual_name, BLEN(&c->c2.to_tun), size);
1948 }
1949
1950 /* indicate activity regarding --inactive parameter */
1951 register_activity(c, size);
1952 }
1953 }
1954 else
1955 {
1956 /*
1957 * This should never happen, probably indicates some kind
1958 * of MTU mismatch.
1959 */
1960 msg(D_LINK_ERRORS, "tun packet too large on write (tried=%d,max=%d)", c->c2.to_tun.len,
1962 }
1963
1964 buf_reset(&c->c2.to_tun);
1965}
1966
1967void
1969{
1970 /* make sure current time (now) is updated on function entry */
1971
1972 /*
1973 * Start with an effectively infinite timeout, then let it
1974 * reduce to a timeout that reflects the component which
1975 * needs the earliest service.
1976 */
1977 c->c2.timeval.tv_sec = BIG_TIMEOUT;
1978 c->c2.timeval.tv_usec = 0;
1979
1980#if defined(_WIN32)
1982 {
1983 c->c2.timeval.tv_sec = 1;
1984 if (tuntap_defined(c->c1.tuntap))
1985 {
1987 }
1988 }
1989#endif
1990
1991 /* check coarse timers? */
1993 if (c->sig->signal_received)
1994 {
1995 return;
1996 }
1997
1998 /* If tls is enabled, do tls control channel packet processing. */
1999 if (c->c2.tls_multi)
2000 {
2001 check_tls(c);
2002 }
2003
2004 /* In certain cases, TLS errors will require a restart */
2006 if (c->sig->signal_received)
2007 {
2008 return;
2009 }
2010
2011 /* check for incoming control messages on the control channel like
2012 * push request/reply/update, or authentication failure and 2FA messages */
2013 if (tls_test_payload_len(c->c2.tls_multi) > 0)
2014 {
2016 }
2017
2018 /* Should we send an OCC message? */
2020
2021#ifdef ENABLE_FRAGMENT
2022 /* Should we deliver a datagram fragment to remote? */
2023 if (c->c2.fragment)
2024 {
2025 check_fragment(c);
2026 }
2027#endif
2028
2029 /* Update random component of timeout */
2031}
2032
2033#if defined(__GNUC__) || defined(__clang__)
2034#pragma GCC diagnostic pop
2035#endif
2036
2037void
2038multi_io_process_flags(struct context *c, struct event_set *es, struct link_socket *sock, const unsigned int flags)
2039{
2040 unsigned int socket = 0;
2041 unsigned int tuntap = 0;
2042 static uintptr_t tun_shift = TUN_SHIFT;
2043
2044 /*
2045 * Calculate the flags based on the provided 'flags' argument.
2046 */
2047 if ((c->options.mode != MODE_SERVER) && (flags & IOW_WAIT_SIGNAL))
2048 {
2049 static uintptr_t err_shift = ERR_SHIFT;
2050 wait_signal(es, (void *)err_shift);
2051 }
2052
2053 if (flags & IOW_TO_LINK)
2054 {
2055 if (flags & IOW_SHAPER)
2056 {
2057 /*
2058 * If sending this packet would put us over our traffic shaping
2059 * quota, don't send -- instead compute the delay we must wait
2060 * until it will be OK to send the packet.
2061 */
2062 int delay = 0;
2063
2064 /* set traffic shaping delay in microseconds */
2065 if (c->options.shaper)
2066 {
2067 delay = max_int(delay, shaper_delay(&c->c2.shaper));
2068 }
2069
2070 if (delay < 1000)
2071 {
2072 socket |= EVENT_WRITE;
2073 }
2074 else
2075 {
2076 shaper_soonest_event(&c->c2.timeval, delay);
2077 }
2078 }
2079 else
2080 {
2081 socket |= EVENT_WRITE;
2082 }
2083 }
2084 else if (!((flags & IOW_FRAG) && TO_LINK_FRAG(c)))
2085 {
2086 if (flags & IOW_READ_TUN)
2087 {
2088 tuntap |= EVENT_READ;
2089 }
2090 }
2091
2092 /*
2093 * If outgoing data (for TUN/TAP device) pending, wait for ready-to-send status
2094 * from device. Otherwise, wait for incoming data on TCP/UDP port.
2095 */
2096 if (flags & IOW_TO_TUN)
2097 {
2099 }
2100 else
2101 {
2102 if (flags & IOW_READ_LINK)
2103 {
2104 socket |= EVENT_READ;
2105 }
2106 }
2107
2108 /*
2109 * Force wait on TUN input, even if also waiting on TCP/UDP output
2110 */
2111 if (flags & IOW_READ_TUN_FORCE)
2112 {
2113 tuntap |= EVENT_READ;
2114 }
2115
2116 /*
2117 * Configure event wait based on socket, tuntap flags.
2118 * (for TCP server sockets this happens in
2119 * socket_set_listen_persistent()).
2120 */
2121 socket_set(sock, es, socket, &sock->ev_arg, NULL);
2122 tun_set(c->c1.tuntap, es, tuntap, (void *)tun_shift, NULL);
2123}
2124
2125/*
2126 * This is the core I/O wait function, used for all I/O waits.
2127 *
2128 * Invoked by P2P instances in tunnel_point_to_point() or by P2MP
2129 * instances within the per-client context in multi_io.c.
2130 */
2131void
2132io_wait(struct context *c, const unsigned int flags)
2133{
2134 struct event_set_return esr[4];
2135
2136 /* These shifts all depend on EVENT_READ and EVENT_WRITE */
2137 static uintptr_t socket_shift = SOCKET_SHIFT; /* depends on SOCKET_READ and SOCKET_WRITE */
2138#ifdef ENABLE_MANAGEMENT
2139 static uintptr_t management_shift =
2140 MANAGEMENT_SHIFT; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
2141#endif
2142
2143#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
2144 static uintptr_t dco_shift = DCO_SHIFT; /* Event from DCO linux kernel module */
2145#endif
2146
2147 /*
2148 * Decide what kind of events we want to wait for.
2149 */
2151
2152 multi_io_process_flags(c, c->c2.event_set, c->c2.link_sockets[0], flags);
2153
2154#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
2155 if (c->c1.tuntap)
2156 {
2157 dco_event_set(&c->c1.tuntap->dco, c->c2.event_set, (void *)dco_shift);
2158 }
2159#endif
2160
2161#ifdef ENABLE_MANAGEMENT
2162 if (management)
2163 {
2164 management_socket_set(management, c->c2.event_set, (void *)management_shift, NULL);
2165 }
2166#endif
2167
2168 /*
2169 * Possible scenarios:
2170 * (1) tcp/udp port has data available to read
2171 * (2) tcp/udp port is ready to accept more data to write
2172 * (3) tun dev has data available to read
2173 * (4) tun dev is ready to accept more data to write
2174 * (5) we received a signal (handler sets signal_received)
2175 * (6) timeout (tv) expired
2176 */
2177
2179
2180 if (!c->sig->signal_received)
2181 {
2182 if (!(flags & IOW_CHECK_RESIDUAL) || !sockets_read_residual(c))
2183 {
2184 int status;
2185
2186#ifndef ENABLE_SMALL
2188 {
2190 }
2191#endif
2192
2193 /*
2194 * Wait for something to happen.
2195 */
2196 status = event_wait(c->c2.event_set, &c->c2.timeval, esr, SIZE(esr));
2197
2198 check_status(status, "event_wait", NULL, NULL);
2199
2200 if (status > 0)
2201 {
2202 int i;
2203 c->c2.event_set_status = 0;
2204 for (i = 0; i < status; ++i)
2205 {
2206 const struct event_set_return *e = &esr[i];
2207 uintptr_t shift;
2208
2209 if (e->arg >= MULTI_N)
2210 {
2211 const struct event_arg *ev_arg = (struct event_arg *)e->arg;
2212 if (ev_arg->type != EVENT_ARG_LINK_SOCKET)
2213 {
2215 msg(D_LINK_ERRORS, "io_work: non socket event delivered");
2216 return;
2217 }
2218
2219 shift = socket_shift;
2220 }
2221 else
2222 {
2223 shift = (uintptr_t)e->arg;
2224 }
2225
2226 c->c2.event_set_status |= ((e->rwflags & 3) << shift);
2227 }
2228 }
2229 else if (status == 0)
2230 {
2232 }
2233 }
2234 else
2235 {
2237 }
2238 }
2239
2240 /* 'now' should always be a reasonably up-to-date timestamp */
2241 update_time();
2242
2243 /* set signal_received if a signal was received */
2244 if (c->c2.event_set_status & ES_ERROR)
2245 {
2247 }
2248
2249 dmsg(D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status);
2250}
2251
2252void
2254{
2255 const unsigned int status = c->c2.event_set_status;
2256
2257#ifdef ENABLE_MANAGEMENT
2259 {
2262 }
2263#endif
2264
2265 /* TCP/UDP port ready to accept write */
2266 if (status & SOCKET_WRITE)
2267 {
2269 }
2270 /* TUN device ready to accept write */
2271 else if (status & TUN_WRITE)
2272 {
2274 }
2275 /* Incoming data on TCP/UDP port */
2276 else if (status & SOCKET_READ)
2277 {
2279 if (!IS_SIG(c))
2280 {
2282 }
2283 }
2284 /* Incoming data on TUN device */
2285 else if (status & TUN_READ)
2286 {
2288 if (!IS_SIG(c))
2289 {
2291 }
2292 }
2293 else if (status & DCO_READ)
2294 {
2295 if (!IS_SIG(c))
2296 {
2298 }
2299 }
2300}
void receive_acc_message(struct context *c, const struct buffer *buffer)
This method parses an app custom control message and delivers it to the management interface.
Definition acc.c:152
void check_send_auth_token(struct context *c)
Checks if the timer to resend the auth-token has expired and if a new auth-token should be send to th...
Definition auth_token.c:437
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:231
bool buf_assign(struct buffer *dest, const struct buffer *src)
Assign the content of one buffer to another.
Definition buffer.c:164
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
Definition buffer.c:77
bool buf_string_match_head_str(const struct buffer *src, const char *match)
Return true if the head of src matches the string match.
Definition buffer.c:727
#define BSTR(buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:157
#define BPTR(buf)
Return a pointer to the start of the buffer content.
Definition buffer.h:139
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
Prepend data to a buffer.
Definition buffer.h:1268
static bool buf_copy_n(struct buffer *dest, struct buffer *src, int n)
Read n bytes from src and append them to dest.
Definition buffer.h:1365
static void buf_reset(struct buffer *buf)
Reset a buffer to an undefined (unallocated) state.
Definition buffer.h:599
static bool buf_safe(const struct buffer *buf, size_t len)
Check whether len bytes can be appended to a buffer.
Definition buffer.h:994
#define CBPTR(buf)
Return a const pointer to the start of the buffer content.
Definition buffer.h:141
static bool buf_advance(struct buffer *buf, ssize_t size)
Advance the content start of a buffer, consuming bytes from the front.
Definition buffer.h:1165
#define BLEN(buf)
Return the length of the buffer content in bytes.
Definition buffer.h:151
#define BLENZ(buf)
Return the length of the buffer content as a size_t.
Definition buffer.h:153
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
#define CBSTR(buf)
Return the buffer content pointer cast to const char *.
Definition buffer.h:159
#define buf_init(buf, offset)
Definition buffer.h:364
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf, const int direction)
Definition clinat.c:184
#define CN_INCOMING
Definition clinat.h:31
#define CN_OUTGOING
Definition clinat.h:30
uint64_t counter_type
Definition common.h:31
int interval_t
Definition common.h:37
#define PUSH_REQUEST_INTERVAL
Definition common.h:94
#define BIG_TIMEOUT
Definition common.h:42
int64_t get_random(void)
an analogue to the random() function, but use prng_bytes and also int64_t instead of long to avoid LL...
Definition crypto.c:1703
static void dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
Definition dco.h:316
static void dco_delete_iroutes(openvpn_net_ctx_t *net_ctx, const struct context *c)
Definition dco.h:364
static int dco_read_and_process(dco_context_t *dco)
Definition dco.h:309
static bool dco_update_keys(dco_context_t *dco, struct tls_multi *multi)
Definition dco.h:328
void * dco_context_t
Definition dco.h:259
static int dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err)
Definition dco.h:375
in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf)
Definition dhcp.c:153
#define D_TUN_RW
Definition errlevel.h:111
#define D_TAP_WIN_DEBUG
Definition errlevel.h:112
#define D_PING
Definition errlevel.h:140
#define D_EVENT_WAIT
Definition errlevel.h:158
#define D_INTERVAL
Definition errlevel.h:154
#define D_STREAM_ERRORS
Definition errlevel.h:62
#define D_DCO_DEBUG
Definition errlevel.h:115
#define D_PUSH_ERRORS
Definition errlevel.h:66
#define D_LOW
Definition errlevel.h:95
#define M_INFO
Definition errlevel.h:54
#define D_SCHED_EXIT
Definition errlevel.h:87
#define D_ROUTE
Definition errlevel.h:78
#define D_LINK_ERRORS
Definition errlevel.h:56
#define D_LINK_RW
Definition errlevel.h:110
#define DCO_READ
Definition event.h:72
#define MANAGEMENT_SHIFT
Definition event.h:68
#define SOCKET_SHIFT
Definition event.h:59
#define TUN_WRITE
Definition event.h:64
#define SOCKET_READ
Definition event.h:60
#define MANAGEMENT_READ
Definition event.h:69
#define MANAGEMENT_WRITE
Definition event.h:70
static int event_wait(struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen)
Definition event.h:186
#define ES_ERROR
Definition event.h:66
#define SOCKET_WRITE
Definition event.h:61
#define ES_TIMEOUT
Definition event.h:67
#define EVENT_WRITE
Definition event.h:38
#define MULTI_N
Definition event.h:85
#define TUN_SHIFT
Definition event.h:62
#define EVENT_READ
Definition event.h:37
#define TUN_READ
Definition event.h:63
static void event_reset(struct event_set *es)
Definition event.h:168
static void wait_signal(struct event_set *es, void *arg)
Definition event.h:196
#define DCO_SHIFT
Definition event.h:71
#define ERR_SHIFT
Definition event.h:65
@ EVENT_ARG_LINK_SOCKET
Definition event.h:135
int get_server_poll_remaining_time(const struct event_timeout *server_poll_timeout)
Definition forward.c:520
void process_incoming_dco(dco_context_t *dco)
Process an incoming DCO message (from kernel space).
Definition forward.c:1264
counter_type link_write_bytes_global
Definition forward.c:50
static void check_inactivity_timeout(struct context *c)
Definition forward.c:496
void reschedule_multi_process(struct context *c)
Reschedule tls_multi_process.
Definition forward.c:407
bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
Definition forward.c:414
static void context_reschedule_sec(struct context *c, time_t sec)
Definition forward.c:132
static void check_fragment(struct context *c)
Definition forward.c:605
static void check_tls_errors(struct context *c)
Definition forward.c:99
static void check_scheduled_exit(struct context *c)
Definition forward.c:582
#define MAX_ICMPV6LEN
static void check_session_timeout(struct context *c)
Definition forward.c:741
static void parse_incoming_control_channel_command(struct context *c, const struct buffer *buf)
Definition forward.c:241
void process_io(struct context *c, struct link_socket *sock)
Definition forward.c:2253
static void socks_postprocess_incoming_link(struct context *c, const struct link_socket *sock)
Definition forward.c:913
static void show_wait_status(struct context *c)
Definition forward.c:72
static void check_timeout_random_component(struct context *c)
Definition forward.c:895
bool schedule_exit(struct context *c)
Definition forward.c:544
static void process_coarse_timers(struct context *c)
Definition forward.c:755
void ipv6_send_icmp_unreachable(struct context *c, const struct buffer *buf, bool client)
Forges a IPv6 ICMP packet with a no route to host error code from the IPv6 packet in buf and sends it...
Definition forward.c:1543
static void check_connection_established(struct context *c)
Definition forward.c:349
static void check_timeout_random_component_dowork(struct context *c)
Definition forward.c:884
static const char * wait_status_string(struct context *c, struct gc_arena *gc)
Definition forward.c:57
static void buffer_turnover(const uint8_t *orig_buf, struct buffer *dest_stub, const struct buffer *src_stub, struct buffer *storage)
Definition forward.c:634
static void check_tls_errors_nco(struct context *c)
Definition forward.c:89
bool send_control_channel_string_dowork(struct tls_session *session, const char *str, msglvl_t msglevel)
Definition forward.c:386
void pre_select(struct context *c)
Definition forward.c:1968
static void check_incoming_control_channel(struct context *c)
Definition forward.c:299
static void check_add_routes(struct context *c)
Definition forward.c:446
static void check_server_poll_timeout(struct context *c)
Definition forward.c:528
static void check_push_request(struct context *c)
Definition forward.c:331
static void process_incoming_link(struct context *c, struct link_socket *sock)
Definition forward.c:1220
static void check_tls_errors_co(struct context *c)
Definition forward.c:82
static void socks_preprocess_outgoing_link(struct context *c, struct link_socket *sock, struct link_socket_actual **to_addr, int *size_delta)
Definition forward.c:922
void io_wait(struct context *c, const unsigned int flags)
Definition forward.c:2132
static void link_socket_write_post_size_adjust(int *size, int size_delta, struct buffer *buf)
Definition forward.c:934
static void context_immediate_reschedule(struct context *c)
Definition forward.c:125
static void check_add_routes_action(struct context *c, const bool errors)
Definition forward.c:431
static void drop_if_recursive_routing(struct context *c, struct buffer *buf)
Drops UDP packets which OS decided to route via tun.
Definition forward.c:1376
counter_type link_read_bytes_global
Definition forward.c:49
static void check_coarse_timers(struct context *c)
Definition forward.c:859
void multi_io_process_flags(struct context *c, struct event_set *es, struct link_socket *sock, const unsigned int flags)
Processes I/O flags to configure socket and TUN/TAP event monitors.
Definition forward.c:2038
void check_dco_key_status(struct context *c)
Definition forward.c:146
void process_ip_header(struct context *c, unsigned int flags, struct buffer *buf, struct link_socket *sock)
Definition forward.c:1670
void extract_dco_float_peer_addr(const sa_family_t socket_family, struct openvpn_sockaddr *out_osaddr, const struct sockaddr *float_sa)
Transfers float_sa data extracted from an incoming DCO PEER_FLOAT_NTF to out_osaddr for later process...
Definition forward.c:1230
static void check_tls(struct context *c)
Definition forward.c:179
static void check_status_file(struct context *c)
Definition forward.c:591
Interface functions to the internal and external multiplexers.
#define PIP_MSSFIX
Definition forward.h:337
#define PIPV4_CLIENT_NAT
Definition forward.h:340
static void register_activity(struct context *c, const int64_t size)
Definition forward.h:364
#define IOW_WAIT_SIGNAL
Definition forward.h:62
#define IOW_READ_TUN
Definition forward.h:56
#define PIPV4_EXTRACT_DHCP_ROUTER
Definition forward.h:339
#define PIPV6_ICMP_NOHOST_SERVER
Definition forward.h:342
#define PIPV6_ICMP_NOHOST_CLIENT
Definition forward.h:341
#define IOW_SHAPER
Definition forward.h:58
#define IOW_FRAG
Definition forward.h:60
static struct link_socket_info * get_link_socket_info(struct context *c)
Definition forward.h:351
#define IOW_READ_LINK
Definition forward.h:57
#define IOW_CHECK_RESIDUAL
Definition forward.h:59
#define TO_LINK_FRAG(c)
Definition forward.h:42
static bool connection_established(struct context *c)
Definition forward.h:398
#define IOW_TO_TUN
Definition forward.h:54
#define PIPV4_PASSTOS
Definition forward.h:336
#define IOW_READ_TUN_FORCE
Definition forward.h:61
#define PIP_OUTGOING
Definition forward.h:338
#define IOW_TO_LINK
Definition forward.h:55
#define KS_PRIMARY
Primary key state index.
Definition ssl_common.h:472
#define TM_ACTIVE
Active tls_session.
Definition ssl_common.h:552
void encrypt_sign(struct context *c, bool comp_frag)
Process a data channel packet that will be sent through a VPN tunnel.
Definition forward.c:654
void tls_post_encrypt(struct tls_multi *multi, const struct buffer *buf)
Perform some accounting for the key state used.
Definition ssl.c:4302
void openvpn_encrypt(struct buffer *buf, struct buffer work, struct crypto_options *opt)
Encrypt and HMAC sign a packet so that it can be sent as a data channel VPN tunnel packet to a remote...
Definition crypto.c:333
void tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *buf)
Prepend a one-byte OpenVPN data channel P_DATA_V1 opcode to the packet.
Definition ssl.c:4274
void tls_pre_encrypt(struct tls_multi *multi, struct buffer *buf, struct crypto_options **opt)
Choose the appropriate security parameters with which to process an outgoing packet.
Definition ssl.c:4242
void tls_prepend_opcode_v2(const struct tls_multi *multi, struct buffer *buf)
Prepend an OpenVPN data channel P_DATA_V2 header to the packet.
Definition ssl.c:4288
bool openvpn_decrypt(struct buffer *buf, struct buffer work, struct crypto_options *opt, const struct frame *frame, const uint8_t *ad_start)
HMAC verify and decrypt a data channel packet received from a remote OpenVPN peer.
Definition crypto.c:776
void process_incoming_link_part2(struct context *c, struct link_socket_info *lsi, const uint8_t *orig_buf)
Continues processing a packet read from the external network interface.
Definition forward.c:1143
void process_outgoing_link(struct context *c, struct link_socket *sock)
Write a packet to the external network interface.
Definition forward.c:1754
void read_incoming_link(struct context *c, struct link_socket *sock)
Read a packet from the external network interface.
Definition forward.c:951
bool tls_pre_decrypt(struct tls_multi *multi, const struct link_socket_actual *from, struct buffer *buf, struct crypto_options **opt, bool floated, const uint8_t **ad_start)
Determine whether an incoming packet is a data channel or control channel packet, and process accordi...
Definition ssl.c:3887
bool process_incoming_link_part1(struct context *c, const struct link_socket_info *lsi, bool floated)
Starts processing a packet read from the external network interface.
Definition forward.c:1010
static void fragment_housekeeping(struct fragment_master *f, struct frame *frame, struct timeval *tv)
Perform housekeeping of a fragment_master structure.
Definition fragment.h:456
static bool fragment_outgoing_defined(struct fragment_master *f)
Check whether a fragment_master structure contains fragments ready to be sent.
Definition fragment.h:428
void fragment_outgoing(struct fragment_master *f, struct buffer *buf, const struct frame *frame)
Process an outgoing packet, which may or may not need to be fragmented.
Definition fragment.c:322
void fragment_incoming(struct fragment_master *f, struct buffer *buf, const struct frame *frame)
Process an incoming packet, which may or may not be fragmented.
Definition fragment.c:144
bool fragment_ready_to_send(struct fragment_master *f, struct buffer *buf, const struct frame *frame)
Check whether outgoing fragments are ready to be send, and if so make one available.
Definition fragment.c:372
void read_incoming_tun(struct context *c)
Read a packet from the virtual tun/tap network interface.
Definition forward.c:1317
void process_incoming_tun(struct context *c, struct link_socket *out_sock)
Process a packet read from the virtual tun/tap network interface.
Definition forward.c:1491
void process_outgoing_tun(struct context *c, struct link_socket *in_sock)
Write a packet to the virtual tun/tap network interface.
Definition forward.c:1887
void initialization_sequence_completed(struct context *c, const unsigned int flags)
Definition init.c:1487
void reset_coarse_timers(struct context *c)
Definition init.c:1261
bool do_up(struct context *c, bool pulled_options, uint64_t option_types_found)
Definition init.c:2305
bool do_route(const struct options *options, struct route_list *route_list, struct route_ipv6_list *route_ipv6_list, const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, openvpn_net_ctx_t *ctx)
Definition init.c:1608
#define ISC_ERRORS
Definition init.h:120
#define ISC_ROUTE_ERRORS
Definition init.h:122
static int min_int(int x, int y)
Definition integer.h:105
static int max_int(int x, int y)
Definition integer.h:92
static SERVICE_STATUS status
Definition interactive.c:52
bool event_timeout_trigger(struct event_timeout *et, struct timeval *tv, const int et_const_retry)
This is the principal function for testing and triggering recurring timers.
Definition interval.c:42
#define ETT_DEFAULT
Definition interval.h:222
static void interval_future_trigger(struct interval *top, interval_t wakeup)
Definition interval.h:106
static void event_timeout_reset(struct event_timeout *et)
Resets a timer.
Definition interval.h:187
static void interval_action(struct interval *top)
Definition interval.h:122
static bool event_timeout_defined(const struct event_timeout *et)
Definition interval.h:142
static void event_timeout_init(struct event_timeout *et, interval_t n, const time_t last)
Initialises a timer struct.
Definition interval.h:172
static void interval_schedule_wakeup(const struct interval *top, interval_t *wakeup)
Definition interval.h:92
static void event_timeout_clear(struct event_timeout *et)
Clears the timeout and reset all values to 0.
Definition interval.h:153
static interval_t event_timeout_remaining(const struct event_timeout *et)
Returns the time until the timeout should triggered, from now.
Definition interval.h:217
static void event_timeout_modify_wakeup(struct event_timeout *et, interval_t n)
Sets the interval n of a timeout.
Definition interval.h:204
static bool interval_test(struct interval *top)
Definition interval.h:65
void management_socket_set(struct management *man, struct event_set *es, void *arg, unsigned int *persistent)
Definition manage.c:3312
void management_set_state(struct management *man, const int state, const char *detail, const in_addr_t *tun_local_ip, const struct in6_addr *tun_local_ip6, const struct openvpn_sockaddr *local, const struct openvpn_sockaddr *remote)
Definition manage.c:2948
void management_io(struct management *man)
Definition manage.c:3350
void management_check_bytecount_client(struct context *c, struct management *man, struct timeval *timeval)
Definition manage.c:4363
void management_sleep(const int n)
A sleep function that services the management layer for n seconds rather than doing nothing.
Definition manage.c:4335
#define OPENVPN_STATE_GET_CONFIG
Definition manage.h:470
const char * sanitize_control_message(const char *src, struct gc_arena *gc)
Definition misc.c:673
void mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss)
Definition mss.c:83
void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss)
Definition mss.c:46
void frame_adjust_path_mtu(struct context *c)
Checks and adjusts the fragment and mssfix value according to the discovered path mtu value.
Definition mss.c:345
void process_received_occ_msg(struct context *c)
Definition occ.c:357
static void check_send_occ_msg(struct context *c)
Definition occ.h:138
static bool is_occ_msg(const struct buffer *buf)
Definition occ.h:83
static void check_send_occ_req(struct context *c)
Definition occ.h:110
static void check_send_occ_load_test(struct context *c)
Definition occ.h:124
#define CLEAR(x)
Definition basic.h:32
#define SIZE(x)
Definition basic.h:29
static bool check_debug_level(msglvl_t level)
Definition error.h:253
#define M_NOPREFIX
Definition error.h:98
static void check_status(ssize_t status, const char *description, struct link_socket *sock, const struct tuntap *tt)
Definition error.h:310
#define dmsg(flags,...)
Definition error.h:164
#define openvpn_errno()
Definition error.h:71
#define msg(flags,...)
Definition error.h:152
unsigned int msglvl_t
Definition error.h:77
#define ASSERT(x)
Definition error.h:221
#define M_WARN
Definition error.h:92
#define TLS_MODE(c)
Definition openvpn.h:515
#define PROTO_DUMP(buf, gc)
Definition openvpn.h:517
#define MODE_POINT_TO_POINT
Definition options.h:264
#define MODE_SERVER
Definition options.h:265
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:981
time_t now
Definition otime.c:33
const char * tv_string(const struct timeval *tv, struct gc_arena *gc)
Definition otime.c:83
static void update_time(void)
Definition otime.h:84
long tv_sec_t
Definition otime.h:31
static void tv_add(struct timeval *dest, const struct timeval *src)
Definition otime.h:129
@ OVPN_DEL_PEER_REASON_EXPIRED
@ OVPN_CMD_SWAP_KEYS
@ OVPN_CMD_DEL_PEER
void trigger_ping_timeout_signal(struct context *c)
Trigger the correct signal on a –ping timeout depending if –ping-exit is set (SIGTERM) or not (SIGUSR...
Definition ping.c:45
static void check_ping_restart(struct context *c)
Definition ping.h:59
static bool is_ping_msg(const struct buffer *buf)
Definition ping.h:40
static void check_ping_send(struct context *c)
Definition ping.h:76
bool is_ipv4(int tunnel_type, struct buffer *buf)
Definition proto.c:107
bool is_ipv6(int tunnel_type, struct buffer *buf)
Definition proto.c:112
uint16_t ip_checksum(const sa_family_t af, const uint8_t *payload, const int len_payload, const uint8_t *src_addr, const uint8_t *dest_addr, const int proto)
Calculates an IP or IPv6 checksum with a pseudo header as required by TCP, UDP and ICMPv6.
Definition proto.c:119
#define OPENVPN_IPH_GET_LEN(v)
Definition proto.h:92
static int get_tun_ip_ver(int tunnel_type, const struct buffer *buf, int *ip_hdr_offset)
Definition proto.h:251
#define DEV_TYPE_TAP
Definition proto.h:36
#define OPENVPN_ETH_ALEN
Definition proto.h:52
#define OPENVPN_ETH_P_IPV6
Definition proto.h:59
#define OPENVPN_IPPROTO_ICMPV6
Definition proto.h:107
#define OPENVPN_IN6_ARE_ADDR_EQUAL(a, b)
Version of IN6_ARE_ADDR_EQUAL that is guaranteed to work for unaligned access.
Definition proto.h:87
#define OPENVPN_IPPROTO_UDP
Definition proto.h:106
#define OPENVPN_ICMP6_DESTINATION_UNREACHABLE
Definition proto.h:136
#define OPENVPN_IPPROTO_TCP
Definition proto.h:105
#define OPENVPN_ICMP6_DU_NOROUTE
Definition proto.h:144
void receive_auth_pending(struct context *c, const struct buffer *buffer)
Parses an AUTH_PENDING message and if in pull mode extends the timeout.
Definition push.c:398
void receive_auth_failed(struct context *c, const struct buffer *buffer)
Definition push.c:51
void server_pushed_signal(struct context *c, const struct buffer *buffer, const bool restart, const int adv)
Definition push.c:131
void receive_cr_response(struct context *c, const struct buffer *buffer)
Definition push.c:319
void send_auth_failed(struct context *c, const char *client_reason)
Definition push.c:455
void peer_pushed_info(struct context *c, const struct buffer *buffer, const int adv)
This message is called when an INFO or INFO_PRE message is received from a peer.
Definition push.c:275
void receive_exit_message(struct context *c)
Definition push.c:192
bool send_push_request(struct context *c)
Definition push.c:632
void incoming_push_message(struct context *c, const struct buffer *buffer)
Definition push.c:566
bool test_routes(const struct route_list *rl, const struct tuntap *tt)
Definition route.c:2387
void route_list_add_vpn_gateway(struct route_list *rl, struct env_set *es, const in_addr_t addr)
Definition route.c:525
void show_routes(msglvl_t msglevel)
Definition route.c:3011
bool shaper_soonest_event(struct timeval *tv, int delay)
Definition shaper.c:36
static void shaper_wrote_bytes(struct shaper *s, int nbytes)
Definition shaper.h:121
static int shaper_delay(struct shaper *s)
Definition shaper.h:96
void print_status(struct context *c, struct status_output *so)
Definition sig.c:478
void process_explicit_exit_notification_timer_wakeup(struct context *c)
Definition sig.c:557
void register_signal(struct signal_info *si, int signum, const char *signal_text)
Register a soft signal in the signal_info struct si respecting priority.
Definition sig.c:228
#define IS_SIG(c)
Definition sig.h:47
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
Definition sig.h:109
const char * socket_stat(const struct link_socket *s, unsigned int rwflags, struct gc_arena *gc)
Definition socket.c:1668
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
Definition socket.c:2503
unsigned int socket_set(struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition socket.c:2596
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:1568
bool sockets_read_residual(const struct context *c)
Definition socket.c:46
static ssize_t link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
Definition socket.h:635
static bool socket_connection_reset(const struct link_socket *sock, ssize_t status)
Definition socket.h:477
static ssize_t link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
Definition socket.h:763
static bool link_socket_verify_incoming_addr(const struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
Definition socket.h:504
static bool link_socket_connection_oriented(const struct link_socket *sock)
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:551
static void link_socket_get_outgoing_addr(struct buffer *buf, const struct link_socket_info *info, struct link_socket_actual **act)
Definition socket.h:531
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
const char * print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena *gc)
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
static bool link_socket_actual_defined(const struct link_socket_actual *act)
static int datagram_overhead(sa_family_t af, int proto)
Overhead added to packets by various protocols.
@ PROTO_UDP
@ PROTO_TCP
#define IA_NET_ORDER
Definition socket_util.h:90
int socks_process_outgoing_udp(struct buffer *buf, const struct link_socket_actual *to)
Definition socks.c:489
void socks_process_incoming_udp(struct buffer *buf, struct link_socket_actual *from)
Definition socks.c:451
bool tls_send_payload(struct key_state *ks, const uint8_t *data, size_t size)
Definition ssl.c:4322
bool tls_rec_payload(struct tls_multi *multi, struct buffer *buf)
Definition ssl.c:4355
void tls_session_soft_reset(struct tls_multi *tls_multi)
Definition ssl.c:1858
int tls_multi_process(struct tls_multi *multi, struct buffer *to_link, struct link_socket_actual **to_link_addr, struct link_socket_info *to_link_socket_info, interval_t *wakeup)
Definition ssl.c:3398
#define TLSMP_RECONNECT
Definition ssl.h:232
#define TLSMP_ACTIVE
Definition ssl.h:230
static bool tls_initial_packet_received(const struct tls_multi *multi)
Definition ssl.h:493
#define TLSMP_RESTART
the session cannot recover on its own and has to be restarted
Definition ssl.h:234
static void tls_set_single_session(struct tls_multi *multi)
Definition ssl.h:513
#define TLSMP_KILL
Definition ssl.h:231
static int tls_test_payload_len(const struct tls_multi *multi)
Definition ssl.h:499
@ CAS_CONNECT_DONE
Definition ssl_common.h:601
struct buffer extract_command_buffer(struct buffer *buf, struct gc_arena *gc)
Extracts a control channel message from buf and adjusts the size of buf after the message has been ex...
Definition ssl_pkt.c:561
#define P_DATA_V1
Definition ssl_pkt.h:47
#define P_OPCODE_SHIFT
Definition ssl_pkt.h:39
Control Channel Verification Module.
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
uint8_t * data
Pointer to the allocated memory.
Definition buffer.h:78
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
int mssfix
Definition options.h:146
int connect_timeout
Definition options.h:123
struct status_output * status_output
Definition openvpn.h:168
struct route_list * route_list
List of routing information.
Definition openvpn.h:160
struct route_ipv6_list * route_ipv6_list
Definition openvpn.h:165
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:155
counter_type link_read_bytes
Definition openvpn.h:249
counter_type link_write_bytes
Definition openvpn.h:252
struct event_timeout server_poll_interval
Definition openvpn.h:382
int max_recv_size_local
Definition openvpn.h:285
struct fragment_master * fragment
Definition openvpn.h:235
time_t update_timeout_random_component
Definition openvpn.h:377
unsigned int event_set_status
Definition openvpn.h:218
counter_type dco_read_bytes
Definition openvpn.h:250
struct event_timeout route_wakeup_expire
Definition openvpn.h:358
struct event_timeout ping_send_interval
Definition openvpn.h:260
int max_send_size_local
Definition openvpn.h:287
struct timeval timeout_random_component
Definition openvpn.h:378
counter_type tun_read_bytes
Definition openvpn.h:247
counter_type dco_write_bytes
Definition openvpn.h:253
struct event_timeout scheduled_exit
Definition openvpn.h:418
struct env_set * es
Definition openvpn.h:394
struct interval tmp_int
Definition openvpn.h:320
struct event_timeout auth_token_renewal_interval
Definition openvpn.h:270
struct event_timeout wait_for_connect
Definition openvpn.h:259
struct shaper shaper
Definition openvpn.h:242
struct event_timeout push_request_interval
Definition openvpn.h:410
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition openvpn.h:300
time_t coarse_timer_wakeup
Definition openvpn.h:373
int scheduled_exit_signal
Definition openvpn.h:419
struct frame frame
Definition openvpn.h:231
struct link_socket_actual from
Definition openvpn.h:228
struct frame frame_fragment
Definition openvpn.h:236
struct buffer to_link
Definition openvpn.h:351
int64_t inactivity_bytes
Definition openvpn.h:265
struct crypto_options crypto_options
Security parameters and crypto state used by the Data Channel Crypto module to process data channel p...
Definition openvpn.h:325
struct buffer to_tun
Definition openvpn.h:350
counter_type tun_write_bytes
Definition openvpn.h:248
struct link_socket ** link_sockets
Definition openvpn.h:220
counter_type link_read_bytes_auth
Definition openvpn.h:251
struct link_socket_actual * to_link_addr
Definition openvpn.h:227
struct event_timeout session_interval
Definition openvpn.h:267
int original_recv_size
Definition openvpn.h:284
struct buffer buf
Definition openvpn.h:349
struct timeval timeval
Time to next event of timers and similar.
Definition openvpn.h:370
time_t explicit_exit_notification_time_wait
Definition openvpn.h:390
bool log_rw
Definition openvpn.h:354
struct event_set * event_set
Definition openvpn.h:213
struct context_buffers * buffers
Definition openvpn.h:341
struct event_timeout route_wakeup
Definition openvpn.h:357
int tls_exit_signal
Definition openvpn.h:323
struct event_timeout inactivity_interval
Definition openvpn.h:264
struct event_timeout ping_rec_interval
Definition openvpn.h:261
struct buffer read_link_buf
Definition openvpn.h:99
struct buffer encrypt_buf
Definition openvpn.h:86
struct buffer read_tun_buf
Definition openvpn.h:100
struct buffer decrypt_buf
Definition openvpn.h:87
int restart_sleep_seconds
Definition openvpn.h:108
Contains all state information for one tunnel.
Definition openvpn.h:445
bool did_dco_iroutes
Whether DCO iroutes have been installed.
Definition openvpn.h:484
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:474
openvpn_net_ctx_t net_ctx
Networking API opaque context.
Definition openvpn.h:472
struct plugin_list * plugins
List of plug-ins.
Definition openvpn.h:476
struct context_2 c2
Level 2 context.
Definition openvpn.h:490
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:446
struct context_1 c1
Level 1 context.
Definition openvpn.h:489
struct context_persist persist
Persistent context.
Definition openvpn.h:486
Security parameter state for processing data channel packets.
Definition crypto.h:286
struct link_socket * sock
Definition event.h:145
event_arg_t type
Definition event.h:141
unsigned int rwflags
Definition event.h:123
interval_t n
periodic interval for periodic timeouts
Definition interval.h:137
int tun_mtu
the (user) configured tun-mtu.
Definition mtu.h:147
int payload_size
the maximum size that a payload that our buffers can hold from either tun device or network link.
Definition mtu.h:118
int headroom
the headroom in the buffer, this is choosen to allow all potential header to be added before the pack...
Definition mtu.h:124
struct frame::@8 buf
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
Security parameter state of one TLS and data channel key session.
Definition ssl_common.h:208
uint8_t dest[OPENVPN_ETH_ALEN]
Definition proto.h:55
uint16_t proto
Definition proto.h:62
uint8_t source[OPENVPN_ETH_ALEN]
Definition proto.h:56
uint8_t icmp6_type
Definition proto.h:143
uint16_t icmp6_cksum
Definition proto.h:147
uint8_t icmp6_code
Definition proto.h:146
uint32_t saddr
Definition proto.h:111
uint32_t daddr
Definition proto.h:112
uint8_t protocol
Definition proto.h:108
uint8_t version_len
Definition proto.h:93
uint8_t version_prio
Definition proto.h:121
struct in6_addr saddr
Definition proto.h:127
struct in6_addr daddr
Definition proto.h:128
uint8_t nexthdr
Definition proto.h:124
uint16_t payload_len
Definition proto.h:123
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
const char * ifconfig_ipv6_remote
Definition options.h:331
int scheduled_exit_interval
Definition options.h:566
int shaper
Definition options.h:334
bool allow_recursive_routing
Definition options.h:732
int64_t inactivity_minimum_bytes
Definition options.h:346
int inactivity_timeout
Definition options.h:345
struct connection_entry ce
Definition options.h:294
int mode
Definition options.h:266
bool block_ipv6
Definition options.h:436
int ping_rec_timeout
Definition options.h:351
int ping_send_timeout
Definition options.h:350
bool route_gateway_via_dhcp
Definition options.h:438
struct client_nat_option_list * client_nat
Definition options.h:440
int session_timeout
Definition options.h:348
volatile int signal_received
Definition sig.h:42
bool is_handle
Definition socket.h:270
struct event_timeout et
Definition status.h:62
int n_hard_errors
Definition ssl_common.h:645
enum multi_status multi_state
Definition ssl_common.h:640
struct tls_session session[TM_SIZE]
Array of tls_session objects representing control channel sessions with the remote peer.
Definition ssl_common.h:721
char * client_reason
An error message to send to client on AUTH_FAILED.
Definition ssl_common.h:674
bool use_peer_id
Definition ssl_common.h:709
int dco_peer_id
This is the handle that DCO uses to identify this session with the kernel.
Definition ssl_common.h:733
int n_soft_errors
Definition ssl_common.h:646
Security parameter state of a single session within a VPN tunnel.
Definition ssl_common.h:497
Definition tun.h:181
enum tun_driver_type backend_driver
The backend driver that used for this tun/tap device.
Definition tun.h:191
HANDLE hand
Definition tun.h:216
struct overlapped_io reads
Definition tun.h:219
dco_context_t dco
Definition tun.h:247
char * actual_name
Definition tun.h:205
#define SIGHUP
Definition syshead.h:55
unsigned short sa_family_t
Definition syshead.h:405
#define SIGTERM
Definition syshead.h:59
#define SIGUSR1
Definition syshead.h:57
uint32_t in_addr_t
Definition syshead.h:52
struct gc_arena gc
Definition test_ssl.c:138
int tun_write_win32(struct tuntap *tt, const struct buffer *buf)
Definition tun.c:3485
const char * tun_stat(const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc)
Definition tun.c:735
bool tun_standby(struct tuntap *tt)
Definition tun.c:5417
void show_adapters(msglvl_t msglevel)
Definition tun.c:4758
void tun_show_debug(const struct tuntap *tt)
Definition tun.c:6159
static bool tuntap_abort(int status)
Definition tun.h:490
ssize_t read_tun(const struct tuntap *tt, uint8_t *buf, int len)
static bool tuntap_is_dco_win_timeout(const struct tuntap *tt, ssize_t status)
Definition tun.h:538
#define TUNNEL_TYPE(tt)
Definition tun.h:182
static bool tuntap_defined(const struct tuntap *tt)
Definition tun.h:252
@ DRIVER_AFUNIX
using an AF_UNIX socket to pass packets from/to an external program.
Definition tun.h:51
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition tun.h:601
ssize_t write_tun(const struct tuntap *tt, const uint8_t *buf, int len)
static bool tuntap_stop(int status)
Definition tun.h:476
ssize_t write_tun_afunix(struct tuntap *tt, const uint8_t *buf, int len)
Writes a packet to a AF_UNIX based tun device.
Definition tun_afunix.c:154
ssize_t read_tun_afunix(struct tuntap *tt, uint8_t *buf, int len)
Reads a packet from a AF_UNIX based tun device.
Definition tun_afunix.c:167