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