OpenVPN
multi.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-2024 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, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#ifdef HAVE_SYS_INOTIFY_H
29#include <sys/inotify.h>
30#define INOTIFY_EVENT_BUFFER_SIZE 16384
31#endif
32
33#include "syshead.h"
34
35#include "forward.h"
36#include "multi.h"
37#include "push.h"
38#include "run_command.h"
39#include "otime.h"
40#include "gremlin.h"
41#include "mstats.h"
42#include "ssl_verify.h"
43#include "ssl_ncp.h"
44#include "vlan.h"
45#include <inttypes.h>
46
47#include "memdbg.h"
48
49
50#include "crypto_backend.h"
51#include "ssl_util.h"
52#include "dco.h"
53#include "reflect_filter.h"
54
55/*#define MULTI_DEBUG_EVENT_LOOP*/
56
57#ifdef MULTI_DEBUG_EVENT_LOOP
58static const char *
59id(struct multi_instance *mi)
60{
61 if (mi)
62 {
63 return tls_common_name(mi->context.c2.tls_multi, false);
64 }
65 else
66 {
67 return "NULL";
68 }
69}
70#endif
71
72#ifdef ENABLE_MANAGEMENT
73static void
74set_cc_config(struct multi_instance *mi, struct buffer_list *cc_config)
75{
77 mi->cc_config = cc_config;
78}
79#endif
80
81static inline void
82update_mstat_n_clients(const int n_clients)
83{
84#ifdef ENABLE_MEMSTATS
85 if (mmap_stats)
86 {
87 mmap_stats->n_clients = n_clients;
88 }
89#endif
90}
91
92static bool
94 const struct multi_instance *mi,
95 const char *op,
96 const struct mroute_addr *addr)
97{
98 struct gc_arena gc = gc_new();
99 struct env_set *es;
100 bool ret = true;
101 struct plugin_list *plugins;
102
103 /* get environmental variable source */
104 if (mi && mi->context.c2.es)
105 {
106 es = mi->context.c2.es;
107 }
108 else
109 {
110 es = env_set_create(&gc);
111 }
112
113 /* get plugin source */
114 if (mi)
115 {
116 plugins = mi->context.plugins;
117 }
118 else
119 {
120 plugins = m->top.plugins;
121 }
122
123 if (plugin_defined(plugins, OPENVPN_PLUGIN_LEARN_ADDRESS))
124 {
125 struct argv argv = argv_new();
126 argv_printf(&argv, "%s %s",
127 op,
128 mroute_addr_print(addr, &gc));
129 if (mi)
130 {
132 }
133 if (plugin_call(plugins, OPENVPN_PLUGIN_LEARN_ADDRESS, &argv, NULL, es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
134 {
135 msg(M_WARN, "WARNING: learn-address plugin call failed");
136 ret = false;
137 }
138 argv_free(&argv);
139 }
140
142 {
143 struct argv argv = argv_new();
144 setenv_str(es, "script_type", "learn-address");
146 argv_printf_cat(&argv, "%s %s", op, mroute_addr_print(addr, &gc));
147 if (mi)
148 {
150 }
151 if (!openvpn_run_script(&argv, es, 0, "--learn-address"))
152 {
153 ret = false;
154 }
155 argv_free(&argv);
156 }
157
158 gc_free(&gc);
159 return ret;
160}
161
162void
164{
165 /* write pool data to file */
166 if (m->ifconfig_pool
169 {
171 }
172}
173
174static void
176 int start_bucket,
177 int end_bucket)
178{
179 struct gc_arena gc = gc_new();
180 struct hash_iterator hi;
181 struct hash_element *he;
182
183 if (start_bucket < 0)
184 {
185 start_bucket = 0;
186 end_bucket = hash_n_buckets(m->vhash);
187 }
188
189 dmsg(D_MULTI_DEBUG, "MULTI: REAP range %d -> %d", start_bucket, end_bucket);
190 hash_iterator_init_range(m->vhash, &hi, start_bucket, end_bucket);
191 while ((he = hash_iterator_next(&hi)) != NULL)
192 {
193 struct multi_route *r = (struct multi_route *) he->value;
194 if (!multi_route_defined(m, r))
195 {
196 dmsg(D_MULTI_DEBUG, "MULTI: REAP DEL %s",
197 mroute_addr_print(&r->addr, &gc));
198 learn_address_script(m, NULL, "delete", &r->addr);
201 }
202 }
204 gc_free(&gc);
205}
206
207static void
209{
210 multi_reap_range(m, -1, 0);
211}
212
213static struct multi_reap *
215{
216 struct multi_reap *mr;
217 ALLOC_OBJ(mr, struct multi_reap);
218 mr->bucket_base = 0;
220 mr->last_call = now;
221 return mr;
222}
223
224void
226{
227 struct multi_reap *mr = m->reaper;
228 if (mr->bucket_base >= hash_n_buckets(m->vhash))
229 {
230 mr->bucket_base = 0;
231 }
233 mr->bucket_base += mr->buckets_per_pass;
234 mr->last_call = now;
235}
236
237static void
239{
240 free(mr);
241}
242
243/*
244 * How many buckets in vhash to reap per pass.
245 */
246static int
248{
249 return constrain_int(n_buckets / REAP_DIVISOR, REAP_MIN, REAP_MAX);
250}
251
252#ifdef ENABLE_MANAGEMENT
253
254static uint32_t
255cid_hash_function(const void *key, uint32_t iv)
256{
257 const unsigned long *k = (const unsigned long *)key;
258 return (uint32_t) *k;
259}
260
261static bool
262cid_compare_function(const void *key1, const void *key2)
263{
264 const unsigned long *k1 = (const unsigned long *)key1;
265 const unsigned long *k2 = (const unsigned long *)key2;
266 return *k1 == *k2;
267}
268
269#endif
270
271#ifdef ENABLE_ASYNC_PUSH
272static uint32_t
273/*
274 * inotify watcher descriptors are used as hash value
275 */
276int_hash_function(const void *key, uint32_t iv)
277{
278 return (unsigned long)key;
279}
280
281static bool
282int_compare_function(const void *key1, const void *key2)
283{
284 return (unsigned long)key1 == (unsigned long)key2;
285}
286#endif
287
288/*
289 * Main initialization function, init multi_context object.
290 */
291void
292multi_init(struct multi_context *m, struct context *t)
293{
294 int dev = DEV_TYPE_UNDEF;
295
296 msg(D_MULTI_LOW, "MULTI: multi_init called, r=%d v=%d",
299
300 /*
301 * Get tun/tap/null device type
302 */
304
305 /*
306 * Init our multi_context object.
307 */
308 CLEAR(*m);
309
310 /*
311 * Real address hash table (source port number is
312 * considered to be part of the address). Used
313 * to determine which client sent an incoming packet
314 * which is seen on the TCP/UDP socket.
315 */
317 get_random(),
320
321 /*
322 * Virtual address hash table. Used to determine
323 * which client to route a packet to.
324 */
326 get_random(),
329
330 /*
331 * This hash table is a clone of m->hash but with a
332 * bucket size of one so that it can be used
333 * for fast iteration through the list.
334 */
335 m->iter = hash_init(1,
336 get_random(),
339
340#ifdef ENABLE_MANAGEMENT
342 0,
345#endif
346
347#ifdef ENABLE_ASYNC_PUSH
348 /*
349 * Mapping between inotify watch descriptors and
350 * multi_instances.
351 */
352 m->inotify_watchers = hash_init(t->options.real_hash_size,
353 get_random(),
354 int_hash_function,
355 int_compare_function);
356#endif
357
358 /*
359 * This is our scheduler, for time-based wakeup
360 * events.
361 */
362 m->schedule = schedule_init();
363
364 /*
365 * Limit frequency of incoming connections to control
366 * DoS.
367 */
369 t->options.cf_per);
372
373 /*
374 * Allocate broadcast/multicast buffer list
375 */
377
378 /*
379 * Different status file format options are available
380 */
382
383 /*
384 * Possibly allocate an ifconfig pool, do it
385 * differently based on whether a tun or tap style
386 * tunnel.
387 */
390 {
392
393 if (dev == DEV_TYPE_TUN && t->options.topology == TOP_NET30)
394 {
396 }
397
399 pool_type,
406
407 /* reload pool data from file */
409 {
411 }
412 }
413
414 /*
415 * Help us keep track of routing table.
416 */
418
419 /*
420 * Initialize route and instance reaper.
421 */
423
424 /*
425 * Get local ifconfig address
426 */
427 CLEAR(m->local);
428 ASSERT(t->c1.tuntap);
430
431 /*
432 * Per-client limits
433 */
435
436 m->instances = calloc(m->max_clients, sizeof(struct multi_instance *));
437
438 m->top.c2.event_set = t->c2.event_set;
439
440 /*
441 * Initialize multi-socket I/O wait object
442 */
445
446 /*
447 * Allow client <-> client communication, without going through
448 * tun/tap interface and network stack?
449 */
451
452 /* initialize stale routes check timer */
454 {
455 msg(M_INFO, "Initializing stale route check timer to run every %i seconds and to removing routes with activity timeout older than %i seconds",
458 }
459
461}
462
463const char *
464multi_instance_string(const struct multi_instance *mi, bool null, struct gc_arena *gc)
465{
466 if (mi)
467 {
469 const char *cn = tls_common_name(mi->context.c2.tls_multi, true);
470
471 if (cn)
472 {
473 buf_printf(&out, "%s/", cn);
474 }
475 buf_printf(&out, "%s", mroute_addr_print(&mi->real, gc));
476 if (mi->context.c2.tls_multi
478 && dco_enabled(&mi->context.options))
479 {
480 buf_printf(&out, " peer-id=%d", mi->context.c2.tls_multi->peer_id);
481 }
482 return BSTR(&out);
483 }
484 else if (null)
485 {
486 return NULL;
487 }
488 else
489 {
490 return "UNDEF";
491 }
492}
493
494static void
496{
497 struct gc_arena gc = gc_new();
498 const char *prefix = multi_instance_string(mi, true, &gc);
499 if (prefix)
500 {
501 strncpynt(mi->msg_prefix, prefix, sizeof(mi->msg_prefix));
502 }
503 else
504 {
505 mi->msg_prefix[0] = '\0';
506 }
507 set_prefix(mi);
508 gc_free(&gc);
509}
510
511void
513{
514 mi->msg_prefix[0] = '\0';
515 set_prefix(mi);
516}
517
518/*
519 * Tell the route helper about deleted iroutes so
520 * that it can update its mask of currently used
521 * CIDR netlengths.
522 */
523static void
525 struct multi_instance *mi)
526{
527 const struct iroute *ir;
528 const struct iroute_ipv6 *ir6;
529
530 dco_delete_iroutes(m, mi);
531
533 {
534 for (ir = mi->context.options.iroutes; ir != NULL; ir = ir->next)
535 {
537 }
538
539 for (ir6 = mi->context.options.iroutes_ipv6; ir6 != NULL; ir6 = ir6->next)
540 {
542 }
543 }
544}
545
546static void
547setenv_stats(struct multi_context *m, struct context *c)
548{
549 if (dco_enabled(&m->top.options))
550 {
551 if (dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m, false) < 0)
552 {
553 return;
554 }
555 }
556
557 setenv_counter(c->c2.es, "bytes_received", c->c2.link_read_bytes + c->c2.dco_read_bytes);
558 setenv_counter(c->c2.es, "bytes_sent", c->c2.link_write_bytes + c->c2.dco_write_bytes);
559}
560
561static void
563{
564 /* setenv client real IP address */
566
567 /* setenv stats */
568 setenv_stats(m, &mi->context);
569
570 /* setenv connection duration */
571 setenv_long_long(mi->context.c2.es, "time_duration", now - mi->created);
572}
573
574static void
576{
578
579 if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONNECT))
580 {
581 if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONNECT, NULL, NULL, mi->context.c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
582 {
583 msg(M_WARN, "WARNING: client-disconnect plugin call failed");
584 }
585 }
586
588 {
589 struct argv argv = argv_new();
590 setenv_str(mi->context.c2.es, "script_type", "client-disconnect");
592 openvpn_run_script(&argv, mi->context.c2.es, 0, "--client-disconnect");
593 argv_free(&argv);
594 }
595#ifdef ENABLE_MANAGEMENT
596 if (management)
597 {
599 }
600#endif
601}
602
603void
605 struct multi_instance *mi,
606 bool shutdown)
607{
609
610 ASSERT(!mi->halt);
611 mi->halt = true;
612 bool is_dgram = proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto);
613
614 dmsg(D_MULTI_DEBUG, "MULTI: multi_close_instance called");
615
616 /* adjust current client connection count */
617 m->n_clients += mi->n_clients_delta;
619 mi->n_clients_delta = 0;
620
621 /* prevent dangling pointers */
622 if (m->pending == mi)
623 {
624 multi_set_pending(m, NULL);
625 }
626 if (m->earliest_wakeup == mi)
627 {
628 m->earliest_wakeup = NULL;
629 }
630
631 if (!shutdown)
632 {
633 if (mi->did_real_hash)
634 {
635 ASSERT(hash_remove(m->hash, &mi->real));
636 }
637 if (mi->did_iter)
638 {
639 ASSERT(hash_remove(m->iter, &mi->real));
640 }
641#ifdef ENABLE_MANAGEMENT
642 if (mi->did_cid_hash)
643 {
645 }
646#endif
647
648#ifdef ENABLE_ASYNC_PUSH
649 if (mi->inotify_watch != -1)
650 {
651 hash_remove(m->inotify_watchers, (void *) (unsigned long)mi->inotify_watch);
652 mi->inotify_watch = -1;
653 }
654#endif
655
657 {
658 m->instances[mi->context.c2.tls_multi->peer_id] = NULL;
659 }
660
662
663 ifconfig_pool_release(m->ifconfig_pool, mi->vaddr_handle, false);
664
665 if (mi->did_iroutes)
666 {
667 multi_del_iroutes(m, mi);
668 mi->did_iroutes = false;
669 }
670
671 if (!is_dgram)
672 {
674 }
675
677 }
678
679#ifdef ENABLE_MANAGEMENT
680 set_cc_config(mi, NULL);
681#endif
682
684 {
686 }
687
688 close_context(&mi->context, SIGTERM, CC_GC_FREE);
689
691
693
694 /*
695 * Don't actually delete the instance memory allocation yet,
696 * because virtual routes may still point to it. Let the
697 * vhash reaper deal with it.
698 */
700
701 perf_pop();
702}
703
704/*
705 * Called on shutdown or restart.
706 */
707void
709{
710 if (m->hash)
711 {
712 struct hash_iterator hi;
713 struct hash_element *he;
714
715 hash_iterator_init(m->iter, &hi);
716 while ((he = hash_iterator_next(&hi)))
717 {
718 struct multi_instance *mi = (struct multi_instance *) he->value;
719 mi->did_iter = false;
720 multi_close_instance(m, mi, true);
721 }
723
725
726 hash_free(m->hash);
727 hash_free(m->vhash);
728 hash_free(m->iter);
729#ifdef ENABLE_MANAGEMENT
731#endif
732 m->hash = NULL;
733
734 free(m->instances);
735
736#ifdef ENABLE_ASYNC_PUSH
737 hash_free(m->inotify_watchers);
738 m->inotify_watchers = NULL;
739#endif
740
742 mbuf_free(m->mbuf);
749 }
750}
751
752/*
753 * Create a client instance object for a newly connected client.
754 */
755struct multi_instance *
757 struct link_socket *sock)
758{
759 struct gc_arena gc = gc_new();
760 struct multi_instance *mi;
761
763
764 msg(D_MULTI_MEDIUM, "MULTI: multi_create_instance called");
765
767
768 mi->gc = gc_new();
770 mi->vaddr_handle = -1;
771 mi->created = now;
773
774 if (real)
775 {
776 mi->real = *real;
777 generate_prefix(mi);
778 }
779
780 inherit_context_child(&mi->context, &m->top, sock);
781 if (IS_SIG(&mi->context))
782 {
783 goto err;
784 }
785
787
788 if (hash_n_elements(m->hash) >= m->max_clients)
789 {
790 msg(D_MULTI_ERRORS, "MULTI: new incoming connection would exceed maximum number of clients (%d)", m->max_clients);
791 goto err;
792 }
793
794 if (!real) /* TCP mode? */
795 {
797 {
798 goto err;
799 }
800 generate_prefix(mi);
801 }
802
803 if (!hash_add(m->iter, &mi->real, mi, false))
804 {
805 msg(D_MULTI_LOW, "MULTI: unable to add real address [%s] to iterator hash table",
806 mroute_addr_print(&mi->real, &gc));
807 goto err;
808 }
809 mi->did_iter = true;
810
811#ifdef ENABLE_MANAGEMENT
812 do
813 {
815 } while (!hash_add(m->cid_hash, &mi->context.c2.mda_context.cid, mi, false));
816 mi->did_cid_hash = true;
817#endif
818
819 mi->context.c2.push_request_received = false;
820#ifdef ENABLE_ASYNC_PUSH
821 mi->inotify_watch = -1;
822#endif
823
825 {
826 msg(D_MULTI_ERRORS, "MULTI: signal occurred during client instance initialization");
827 goto err;
828 }
829
831 mi->ev_arg.u.mi = mi;
832
833 perf_pop();
834 gc_free(&gc);
835 return mi;
836
837err:
838 multi_close_instance(m, mi, false);
839 perf_pop();
840 gc_free(&gc);
841 return NULL;
842}
843
844/*
845 * Dump tables -- triggered by SIGUSR2.
846 * If status file is defined, write to file.
847 * If status file is NULL, write to syslog.
848 */
849void
850multi_print_status(struct multi_context *m, struct status_output *so, const int version)
851{
852 if (m->hash)
853 {
854 struct gc_arena gc_top = gc_new();
855 struct hash_iterator hi;
856 const struct hash_element *he;
857
858 status_reset(so);
859
860 if (dco_enabled(&m->top.options))
861 {
862 if (dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m, true) < 0)
863 {
864 return;
865 }
866 }
867
868 if (version == 1)
869 {
870 /*
871 * Status file version 1
872 */
873 status_printf(so, "OpenVPN CLIENT LIST");
874 status_printf(so, "Updated,%s", time_string(0, 0, false, &gc_top));
875 status_printf(so, "Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since");
876 hash_iterator_init(m->hash, &hi);
877 while ((he = hash_iterator_next(&hi)))
878 {
879 struct gc_arena gc = gc_new();
880 const struct multi_instance *mi = (struct multi_instance *) he->value;
881
882 if (!mi->halt)
883 {
884 status_printf(so, "%s,%s," counter_format "," counter_format ",%s",
886 mroute_addr_print(&mi->real, &gc),
889 time_string(mi->created, 0, false, &gc));
890 }
891 gc_free(&gc);
892 }
894
895 status_printf(so, "ROUTING TABLE");
896 status_printf(so, "Virtual Address,Common Name,Real Address,Last Ref");
897 hash_iterator_init(m->vhash, &hi);
898 while ((he = hash_iterator_next(&hi)))
899 {
900 struct gc_arena gc = gc_new();
901 const struct multi_route *route = (struct multi_route *) he->value;
902
904 {
905 const struct multi_instance *mi = route->instance;
906 const struct mroute_addr *ma = &route->addr;
907 char flags[2] = {0, 0};
908
909 if (route->flags & MULTI_ROUTE_CACHE)
910 {
911 flags[0] = 'C';
912 }
913 status_printf(so, "%s%s,%s,%s,%s",
915 flags,
917 mroute_addr_print(&mi->real, &gc),
918 time_string(route->last_reference, 0, false, &gc));
919 }
920 gc_free(&gc);
921 }
923
924 status_printf(so, "GLOBAL STATS");
925 if (m->mbuf)
926 {
927 status_printf(so, "Max bcast/mcast queue length,%d",
928 mbuf_maximum_queued(m->mbuf));
929 }
930
931 status_printf(so, "END");
932 }
933 else if (version == 2 || version == 3)
934 {
935 const char sep = (version == 3) ? '\t' : ',';
936
937 /*
938 * Status file version 2 and 3
939 */
940 status_printf(so, "TITLE%c%s", sep, title_string);
941 status_printf(so, "TIME%c%s%c%u", sep, time_string(now, 0, false, &gc_top), sep, (unsigned int)now);
942 status_printf(so, "HEADER%cCLIENT_LIST%cCommon Name%cReal Address%cVirtual Address%cVirtual IPv6 Address%cBytes Received%cBytes Sent%cConnected Since%cConnected Since (time_t)%cUsername%cClient ID%cPeer ID%cData Channel Cipher",
943 sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep);
944 hash_iterator_init(m->hash, &hi);
945 while ((he = hash_iterator_next(&hi)))
946 {
947 struct gc_arena gc = gc_new();
948 const struct multi_instance *mi = (struct multi_instance *) he->value;
949
950 if (!mi->halt)
951 {
952 status_printf(so, "CLIENT_LIST%c%s%c%s%c%s%c%s%c" counter_format "%c" counter_format "%c%s%c%u%c%s%c"
953#ifdef ENABLE_MANAGEMENT
954 "%lu"
955#else
956 ""
957#endif
958 "%c%" PRIu32 "%c%s",
959 sep, tls_common_name(mi->context.c2.tls_multi, false),
960 sep, mroute_addr_print(&mi->real, &gc),
965 sep, time_string(mi->created, 0, false, &gc),
966 sep, (unsigned int)mi->created,
967 sep, tls_username(mi->context.c2.tls_multi, false),
968#ifdef ENABLE_MANAGEMENT
969 sep, mi->context.c2.mda_context.cid,
970#else
971 sep,
972#endif
973 sep, mi->context.c2.tls_multi ? mi->context.c2.tls_multi->peer_id : UINT32_MAX,
975 }
976 gc_free(&gc);
977 }
979
980 status_printf(so, "HEADER%cROUTING_TABLE%cVirtual Address%cCommon Name%cReal Address%cLast Ref%cLast Ref (time_t)",
981 sep, sep, sep, sep, sep, sep);
982 hash_iterator_init(m->vhash, &hi);
983 while ((he = hash_iterator_next(&hi)))
984 {
985 struct gc_arena gc = gc_new();
986 const struct multi_route *route = (struct multi_route *) he->value;
987
989 {
990 const struct multi_instance *mi = route->instance;
991 const struct mroute_addr *ma = &route->addr;
992 char flags[2] = {0, 0};
993
994 if (route->flags & MULTI_ROUTE_CACHE)
995 {
996 flags[0] = 'C';
997 }
998 status_printf(so, "ROUTING_TABLE%c%s%s%c%s%c%s%c%s%c%u",
999 sep, mroute_addr_print(ma, &gc), flags,
1000 sep, tls_common_name(mi->context.c2.tls_multi, false),
1001 sep, mroute_addr_print(&mi->real, &gc),
1002 sep, time_string(route->last_reference, 0, false, &gc),
1003 sep, (unsigned int)route->last_reference);
1004 }
1005 gc_free(&gc);
1006 }
1008
1009 if (m->mbuf)
1010 {
1011 status_printf(so, "GLOBAL_STATS%cMax bcast/mcast queue length%c%d",
1012 sep, sep, mbuf_maximum_queued(m->mbuf));
1013 }
1014
1015 status_printf(so, "GLOBAL_STATS%cdco_enabled%c%d", sep, sep, dco_enabled(&m->top.options));
1016 status_printf(so, "END");
1017 }
1018 else
1019 {
1020 status_printf(so, "ERROR: bad status format version number");
1021 }
1022
1023#ifdef PACKET_TRUNCATION_CHECK
1024 {
1025 status_printf(so, "HEADER,ERRORS,Common Name,TUN Read Trunc,TUN Write Trunc,Pre-encrypt Trunc,Post-decrypt Trunc");
1026 hash_iterator_init(m->hash, &hi);
1027 while ((he = hash_iterator_next(&hi)))
1028 {
1029 struct gc_arena gc = gc_new();
1030 const struct multi_instance *mi = (struct multi_instance *) he->value;
1031
1032 if (!mi->halt)
1033 {
1035 tls_common_name(mi->context.c2.tls_multi, false),
1036 m->top.c2.n_trunc_tun_read,
1037 mi->context.c2.n_trunc_tun_write,
1038 mi->context.c2.n_trunc_pre_encrypt,
1039 mi->context.c2.n_trunc_post_decrypt);
1040 }
1041 gc_free(&gc);
1042 }
1043 hash_iterator_free(&hi);
1044 }
1045#endif /* ifdef PACKET_TRUNCATION_CHECK */
1046
1047 status_flush(so);
1048 gc_free(&gc_top);
1049 }
1050
1051#ifdef ENABLE_ASYNC_PUSH
1052 if (m->inotify_watchers)
1053 {
1054 msg(D_MULTI_DEBUG, "inotify watchers count: %d\n", hash_n_elements(m->inotify_watchers));
1055 }
1056#endif
1057}
1058
1059/*
1060 * Learn a virtual address or route.
1061 * The learn will fail if the learn address
1062 * script/plugin fails. In this case the
1063 * return value may be != mi.
1064 * Return the instance which owns this route,
1065 * or NULL if none.
1066 */
1067static struct multi_instance *
1069 struct multi_instance *mi,
1070 const struct mroute_addr *addr,
1071 const unsigned int flags)
1072{
1073 struct hash_element *he;
1074 const uint32_t hv = hash_value(m->vhash, addr);
1075 struct hash_bucket *bucket = hash_bucket(m->vhash, hv);
1076 struct multi_route *oldroute = NULL;
1077 struct multi_instance *owner = NULL;
1078 struct gc_arena gc = gc_new();
1079
1080 /* if route currently exists, get the instance which owns it */
1081 he = hash_lookup_fast(m->vhash, bucket, addr, hv);
1082 if (he)
1083 {
1084 oldroute = (struct multi_route *) he->value;
1085 }
1086 if (oldroute && multi_route_defined(m, oldroute))
1087 {
1088 owner = oldroute->instance;
1089 }
1090
1091 /* do we need to add address to hash table? */
1092 if ((!owner || owner != mi) && mroute_learnable_address(addr, &gc)
1093 && !mroute_addr_equal(addr, &m->local))
1094 {
1095 struct multi_route *newroute;
1096 bool learn_succeeded = false;
1097
1098 ALLOC_OBJ(newroute, struct multi_route);
1099 newroute->addr = *addr;
1100 newroute->instance = mi;
1101 newroute->flags = flags;
1102 newroute->last_reference = now;
1103 newroute->cache_generation = 0;
1104
1105 /* The cache is invalidated when cache_generation is incremented */
1107 {
1109 }
1110
1111 if (oldroute) /* route already exists? */
1112 {
1113 if (route_quota_test(mi) && learn_address_script(m, mi, "update", &newroute->addr))
1114 {
1115 learn_succeeded = true;
1116 owner = mi;
1118 route_quota_inc(mi);
1119
1120 /* delete old route */
1121 multi_route_del(oldroute);
1122
1123 /* modify hash table entry, replacing old route */
1124 he->key = &newroute->addr;
1125 he->value = newroute;
1126 }
1127 }
1128 else
1129 {
1130 if (route_quota_test(mi) && learn_address_script(m, mi, "add", &newroute->addr))
1131 {
1132 learn_succeeded = true;
1133 owner = mi;
1135 route_quota_inc(mi);
1136
1137 /* add new route */
1138 hash_add_fast(m->vhash, bucket, &newroute->addr, hv, newroute);
1139 }
1140 }
1141
1142 msg(D_MULTI_LOW, "MULTI: Learn%s: %s -> %s",
1143 learn_succeeded ? "" : " FAILED",
1144 mroute_addr_print(&newroute->addr, &gc),
1145 multi_instance_string(mi, false, &gc));
1146
1147 if (!learn_succeeded)
1148 {
1149 free(newroute);
1150 }
1151 }
1152 gc_free(&gc);
1153
1154 return owner;
1155}
1156
1157/*
1158 * Get client instance based on virtual address.
1159 */
1160static struct multi_instance *
1162 const struct mroute_addr *addr,
1163 bool cidr_routing)
1164{
1165 struct multi_route *route;
1166 struct multi_instance *ret = NULL;
1167
1168 /* check for local address */
1169 if (mroute_addr_equal(addr, &m->local))
1170 {
1171 return NULL;
1172 }
1173
1174 route = (struct multi_route *) hash_lookup(m->vhash, addr);
1175
1176 /* does host route (possible cached) exist? */
1177 if (route && multi_route_defined(m, route))
1178 {
1179 struct multi_instance *mi = route->instance;
1180 route->last_reference = now;
1181 ret = mi;
1182 }
1183 else if (cidr_routing) /* do we need to regenerate a host route cache entry? */
1184 {
1185 struct mroute_helper *rh = m->route_helper;
1186 struct mroute_addr tryaddr;
1187 int i;
1188
1189 /* cycle through each CIDR length */
1190 for (i = 0; i < rh->n_net_len; ++i)
1191 {
1192 tryaddr = *addr;
1194 tryaddr.netbits = rh->net_len[i];
1196
1197 /* look up a possible route with netbits netmask */
1198 route = (struct multi_route *) hash_lookup(m->vhash, &tryaddr);
1199
1200 if (route && multi_route_defined(m, route))
1201 {
1202 /* found an applicable route, cache host route */
1203 struct multi_instance *mi = route->instance;
1205 ret = mi;
1206 break;
1207 }
1208 }
1209 }
1210
1211#ifdef ENABLE_DEBUG
1213 {
1214 struct gc_arena gc = gc_new();
1215 const char *addr_text = mroute_addr_print(addr, &gc);
1216 if (ret)
1217 {
1218 dmsg(D_MULTI_DEBUG, "GET INST BY VIRT: %s -> %s via %s",
1219 addr_text,
1220 multi_instance_string(ret, false, &gc),
1221 mroute_addr_print(&route->addr, &gc));
1222 }
1223 else
1224 {
1225 dmsg(D_MULTI_DEBUG, "GET INST BY VIRT: %s [failed]",
1226 addr_text);
1227 }
1228 gc_free(&gc);
1229 }
1230#endif
1231
1232 ASSERT(!(ret && ret->halt));
1233 return ret;
1234}
1235
1236/*
1237 * Helper function to multi_learn_addr().
1238 */
1239static struct multi_instance *
1241 struct multi_instance *mi,
1242 in_addr_t a,
1243 int netbits, /* -1 if host route, otherwise # of network bits in address */
1244 bool primary)
1245{
1246 struct openvpn_sockaddr remote_si;
1247 struct mroute_addr addr = {0};
1248
1250 remote_si.addr.in4.sin_family = AF_INET;
1251 remote_si.addr.in4.sin_addr.s_addr = htonl(a);
1252 addr.proto = 0;
1254
1255 if (netbits >= 0)
1256 {
1257 addr.type |= MR_WITH_NETBITS;
1258 addr.netbits = (uint8_t) netbits;
1259 }
1260
1261 struct multi_instance *owner = multi_learn_addr(m, mi, &addr, 0);
1262#ifdef ENABLE_MANAGEMENT
1263 if (management && owner)
1264 {
1265 management_learn_addr(management, &mi->context.c2.mda_context, &addr, primary);
1266 }
1267#endif
1268 if (!primary)
1269 {
1270 /* "primary" is the VPN ifconfig address of the peer and already
1271 * known to DCO, so only install "extra" iroutes (primary = false)
1272 */
1273 ASSERT(netbits >= 0); /* DCO requires populated netbits */
1274 dco_install_iroute(m, mi, &addr);
1275 }
1276
1277 return owner;
1278}
1279
1280static struct multi_instance *
1282 struct multi_instance *mi,
1283 struct in6_addr a6,
1284 int netbits, /* -1 if host route, otherwise # of network bits in address */
1285 bool primary)
1286{
1287 struct mroute_addr addr = {0};
1288
1289 addr.len = 16;
1290 addr.type = MR_ADDR_IPV6;
1291 addr.netbits = 0;
1292 addr.v6.addr = a6;
1293
1294 if (netbits >= 0)
1295 {
1296 addr.type |= MR_WITH_NETBITS;
1297 addr.netbits = (uint8_t) netbits;
1299 }
1300
1301 struct multi_instance *owner = multi_learn_addr(m, mi, &addr, 0);
1302#ifdef ENABLE_MANAGEMENT
1303 if (management && owner)
1304 {
1305 management_learn_addr(management, &mi->context.c2.mda_context, &addr, primary);
1306 }
1307#endif
1308 if (!primary)
1309 {
1310 /* "primary" is the VPN ifconfig address of the peer and already
1311 * known to DCO, so only install "extra" iroutes (primary = false)
1312 */
1313 ASSERT(netbits >= 0); /* DCO requires populated netbits */
1314 dco_install_iroute(m, mi, &addr);
1315 }
1316
1317 return owner;
1318}
1319
1320/*
1321 * A new client has connected, add routes (server -> client)
1322 * to internal routing table.
1323 */
1324static void
1326 struct multi_instance *mi)
1327{
1328 struct gc_arena gc = gc_new();
1329 const struct iroute *ir;
1330 const struct iroute_ipv6 *ir6;
1332 {
1333 mi->did_iroutes = true;
1334 for (ir = mi->context.options.iroutes; ir != NULL; ir = ir->next)
1335 {
1336 if (ir->netbits >= 0)
1337 {
1338 msg(D_MULTI_LOW, "MULTI: internal route %s/%d -> %s",
1339 print_in_addr_t(ir->network, 0, &gc),
1340 ir->netbits,
1341 multi_instance_string(mi, false, &gc));
1342 }
1343 else
1344 {
1345 msg(D_MULTI_LOW, "MULTI: internal route %s -> %s",
1346 print_in_addr_t(ir->network, 0, &gc),
1347 multi_instance_string(mi, false, &gc));
1348 }
1349
1351
1352 multi_learn_in_addr_t(m, mi, ir->network, ir->netbits, false);
1353 }
1354 for (ir6 = mi->context.options.iroutes_ipv6; ir6 != NULL; ir6 = ir6->next)
1355 {
1356 msg(D_MULTI_LOW, "MULTI: internal route %s/%d -> %s",
1357 print_in6_addr(ir6->network, 0, &gc),
1358 ir6->netbits,
1359 multi_instance_string(mi, false, &gc));
1360
1362
1363 multi_learn_in6_addr(m, mi, ir6->network, ir6->netbits, false);
1364 }
1365 }
1366 gc_free(&gc);
1367}
1368
1369/*
1370 * Given an instance (new_mi), delete all other instances which use the
1371 * same common name.
1372 */
1373static void
1375{
1376 if (new_mi)
1377 {
1378 const char *new_cn = tls_common_name(new_mi->context.c2.tls_multi, true);
1379 if (new_cn)
1380 {
1381 struct hash_iterator hi;
1382 struct hash_element *he;
1383 int count = 0;
1384
1385 hash_iterator_init(m->iter, &hi);
1386 while ((he = hash_iterator_next(&hi)))
1387 {
1388 struct multi_instance *mi = (struct multi_instance *) he->value;
1389 if (mi != new_mi && !mi->halt)
1390 {
1391 const char *cn = tls_common_name(mi->context.c2.tls_multi, true);
1392 if (cn && !strcmp(cn, new_cn))
1393 {
1394 mi->did_iter = false;
1395 multi_close_instance(m, mi, false);
1397 ++count;
1398 }
1399 }
1400 }
1401 hash_iterator_free(&hi);
1402
1403 if (count)
1404 {
1405 msg(D_MULTI_LOW, "MULTI: new connection by client '%s' will cause previous active sessions by this client to be dropped. Remember to use the --duplicate-cn option if you want multiple clients using the same certificate or username to concurrently connect.", new_cn);
1406 }
1407 }
1408 }
1409}
1410
1411static void
1413{
1414
1415 struct gc_arena gc = gc_new();
1416 struct hash_iterator hi;
1417 struct hash_element *he;
1418
1419 dmsg(D_MULTI_DEBUG, "MULTI: Checking stale routes");
1421 while ((he = hash_iterator_next(&hi)) != NULL)
1422 {
1423 struct multi_route *r = (struct multi_route *) he->value;
1425 {
1426 dmsg(D_MULTI_DEBUG, "MULTI: Deleting stale route for address '%s'",
1427 mroute_addr_print(&r->addr, &gc));
1428 learn_address_script(m, NULL, "delete", &r->addr);
1429 multi_route_del(r);
1431 }
1432 }
1433 hash_iterator_free(&hi);
1434 gc_free(&gc);
1435}
1436
1437/*
1438 * Ensure that endpoint to be pushed to client
1439 * complies with --ifconfig-push-constraint directive.
1440 */
1441static bool
1443{
1444 const struct options *o = &c->options;
1446 {
1448 }
1449 else
1450 {
1451 return true;
1452 }
1453}
1454
1455/*
1456 * Select a virtual address for a new client instance.
1457 * Use an --ifconfig-push directive, if given (static IP).
1458 * Otherwise use an --ifconfig-pool address (dynamic IP).
1459 */
1460static void
1462{
1463 struct gc_arena gc = gc_new();
1464
1465 /*
1466 * If ifconfig addresses were set by dynamic config file,
1467 * release pool addresses, otherwise keep them.
1468 */
1470 {
1471 /* ifconfig addresses were set statically,
1472 * release dynamic allocation */
1473 if (mi->vaddr_handle >= 0)
1474 {
1476 mi->vaddr_handle = -1;
1477 }
1478
1479 mi->context.c2.push_ifconfig_defined = true;
1483
1484 /* the current implementation does not allow "static IPv4, pool IPv6",
1485 * (see below) so issue a warning if that happens - don't break the
1486 * session, though, as we don't even know if this client WANTS IPv6
1487 */
1490 {
1491 msg( M_INFO, "MULTI_sva: WARNING: if --ifconfig-push is used for IPv4, automatic IPv6 assignment from --ifconfig-ipv6-pool does not work. Use --ifconfig-ipv6-push for IPv6 then." );
1492 }
1493 }
1494 else if (m->ifconfig_pool && mi->vaddr_handle < 0) /* otherwise, choose a pool address */
1495 {
1496 in_addr_t local = 0, remote = 0;
1497 struct in6_addr remote_ipv6;
1498 const char *cn = NULL;
1499
1500 if (!mi->context.options.duplicate_cn)
1501 {
1502 cn = tls_common_name(mi->context.c2.tls_multi, true);
1503 }
1504
1505 CLEAR(remote_ipv6);
1506 mi->vaddr_handle = ifconfig_pool_acquire(m->ifconfig_pool, &local, &remote, &remote_ipv6, cn);
1507 if (mi->vaddr_handle >= 0)
1508 {
1509 const int tunnel_type = TUNNEL_TYPE(mi->context.c1.tuntap);
1510 const int tunnel_topology = TUNNEL_TOPOLOGY(mi->context.c1.tuntap);
1511
1512 msg( M_INFO, "MULTI_sva: pool returned IPv4=%s, IPv6=%s",
1514 ? print_in_addr_t(remote, 0, &gc)
1515 : "(Not enabled)"),
1517 ? print_in6_addr( remote_ipv6, 0, &gc )
1518 : "(Not enabled)") );
1519
1521 {
1522 /* set push_ifconfig_remote_netmask from pool ifconfig address(es) */
1523 mi->context.c2.push_ifconfig_local = remote;
1524 if (tunnel_type == DEV_TYPE_TAP || (tunnel_type == DEV_TYPE_TUN && tunnel_topology == TOP_SUBNET))
1525 {
1528 {
1530 }
1531 }
1532 else if (tunnel_type == DEV_TYPE_TUN)
1533 {
1534 if (tunnel_topology == TOP_P2P)
1535 {
1537 }
1538 else if (tunnel_topology == TOP_NET30)
1539 {
1541 }
1542 }
1543
1545 {
1546 mi->context.c2.push_ifconfig_defined = true;
1547 }
1548 else
1549 {
1551 "MULTI: no --ifconfig-pool netmask parameter is available to push to %s",
1552 multi_instance_string(mi, false, &gc));
1553 }
1554 }
1555
1557 {
1558 mi->context.c2.push_ifconfig_ipv6_local = remote_ipv6;
1564 }
1565 }
1566 else
1567 {
1568 msg(D_MULTI_ERRORS, "MULTI: no free --ifconfig-pool addresses are available");
1569 }
1570 }
1571
1572 /* IPv6 push_ifconfig is a bit problematic - since IPv6 shares the
1573 * pool handling with IPv4, the combination "static IPv4, dynamic IPv6"
1574 * will fail (because no pool will be allocated in this case).
1575 * OTOH, this doesn't make too much sense in reality - and the other
1576 * way round ("dynamic IPv4, static IPv6") or "both static" makes sense
1577 * -> and so it's implemented right now
1578 */
1580 {
1588
1589 msg( M_INFO, "MULTI_sva: push_ifconfig_ipv6 %s/%d",
1592 }
1593
1594 gc_free(&gc);
1595}
1596
1597/*
1598 * Set virtual address environmental variables.
1599 */
1600static void
1602{
1603 setenv_del(mi->context.c2.es, "ifconfig_pool_local_ip");
1604 setenv_del(mi->context.c2.es, "ifconfig_pool_remote_ip");
1605 setenv_del(mi->context.c2.es, "ifconfig_pool_netmask");
1606
1608 {
1609 const int tunnel_type = TUNNEL_TYPE(mi->context.c1.tuntap);
1610 const int tunnel_topology = TUNNEL_TOPOLOGY(mi->context.c1.tuntap);
1611
1613 "ifconfig_pool_remote_ip",
1616
1617 if (tunnel_type == DEV_TYPE_TAP || (tunnel_type == DEV_TYPE_TUN && tunnel_topology == TOP_SUBNET))
1618 {
1620 "ifconfig_pool_netmask",
1623 }
1624 else if (tunnel_type == DEV_TYPE_TUN)
1625 {
1627 "ifconfig_pool_local_ip",
1630 }
1631 }
1632
1633 setenv_del(mi->context.c2.es, "ifconfig_pool_local_ip6");
1634 setenv_del(mi->context.c2.es, "ifconfig_pool_remote_ip6");
1635 setenv_del(mi->context.c2.es, "ifconfig_pool_ip6_netbits");
1636
1638 {
1640 "ifconfig_pool_remote",
1644 "ifconfig_pool_local",
1647 setenv_int(mi->context.c2.es,
1648 "ifconfig_pool_ip6_netbits",
1650 }
1651}
1652
1653/*
1654 * Called after client-connect script is called
1655 */
1656static void
1658 struct multi_instance *mi,
1659 const char *dc_file,
1660 unsigned int *option_types_found)
1661{
1662 /* Did script generate a dynamic config file? */
1663 if (platform_test_file(dc_file))
1664 {
1666 dc_file,
1669 option_types_found,
1670 mi->context.c2.es);
1671
1672 /*
1673 * If the --client-connect script generates a config file
1674 * with an --ifconfig-push directive, it will override any
1675 * --ifconfig-push directive from the --client-config-dir
1676 * directory or any --ifconfig-pool dynamic address.
1677 */
1680 }
1681}
1682
1683#ifdef ENABLE_PLUGIN
1684
1685/*
1686 * Called after client-connect plug-in is called
1687 */
1688static void
1690 struct multi_instance *mi,
1691 const struct plugin_return *pr,
1692 unsigned int *option_types_found)
1693{
1694 struct plugin_return config;
1695
1696 plugin_return_get_column(pr, &config, "config");
1697
1698 /* Did script generate a dynamic config file? */
1699 if (plugin_return_defined(&config))
1700 {
1701 int i;
1702 for (i = 0; i < config.n; ++i)
1703 {
1704 if (config.list[i] && config.list[i]->value)
1705 {
1707 config.list[i]->value,
1710 option_types_found,
1711 mi->context.c2.es);
1712 }
1713 }
1714
1715 /*
1716 * If the --client-connect script generates a config file
1717 * with an --ifconfig-push directive, it will override any
1718 * --ifconfig-push directive from the --client-config-dir
1719 * directory or any --ifconfig-pool dynamic address.
1720 */
1723 }
1724}
1725
1726#endif /* ifdef ENABLE_PLUGIN */
1727
1728
1729/*
1730 * Called to load management-derived client-connect config
1731 */
1734 struct multi_instance *mi,
1735 bool deferred,
1736 unsigned int *option_types_found)
1737{
1738 /* We never return CC_RET_DEFERRED */
1739 ASSERT(!deferred);
1741#ifdef ENABLE_MANAGEMENT
1742 if (mi->cc_config)
1743 {
1744 struct buffer_entry *be;
1745 for (be = mi->cc_config->head; be != NULL; be = be->next)
1746 {
1747 const char *opt = BSTR(&be->buf);
1749 opt,
1752 option_types_found,
1753 mi->context.c2.es);
1754 }
1755
1756 /*
1757 * If the --client-connect script generates a config file
1758 * with an --ifconfig-push directive, it will override any
1759 * --ifconfig-push directive from the --client-config-dir
1760 * directory or any --ifconfig-pool dynamic address.
1761 */
1764
1765 ret = CC_RET_SUCCEEDED;
1766 }
1767#endif /* ifdef ENABLE_MANAGEMENT */
1768 return ret;
1769}
1770
1771static void
1773{
1774 struct gc_arena gc = gc_new();
1775
1776 /* setenv incoming cert common name for script */
1777 setenv_str(mi->context.c2.es, "common_name", tls_common_name(mi->context.c2.tls_multi, true));
1778
1779 /* setenv client real IP address */
1781
1782 /* setenv client virtual IP address */
1784
1785 /* setenv connection time */
1786 {
1787 const char *created_ascii = time_string(mi->created, 0, false, &gc);
1788 setenv_str(mi->context.c2.es, "time_ascii", created_ascii);
1789 setenv_long_long(mi->context.c2.es, "time_unix", mi->created);
1790 }
1791
1792 gc_free(&gc);
1793}
1794
1801static bool
1803{
1804 struct tls_multi *tls_multi = c->c2.tls_multi;
1805 const char *const peer_info = tls_multi->peer_info;
1806 struct options *o = &c->options;
1807
1808
1809 unsigned int proto = extract_iv_proto(peer_info);
1810 if (proto & IV_PROTO_DATA_V2)
1811 {
1812 tls_multi->use_peer_id = true;
1813 o->use_peer_id = true;
1814 }
1815 else if (dco_enabled(o))
1816 {
1817 msg(M_INFO, "Client does not support DATA_V2. Data channel offloading "
1818 "requires DATA_V2. Dropping client.");
1819 auth_set_client_reason(tls_multi, "Data channel negotiation "
1820 "failed (missing DATA_V2)");
1821 return false;
1822 }
1823
1824 /* Print a warning if we detect the client being in P2P mode and will
1825 * not accept our pushed ciphers */
1826 if (proto & IV_PROTO_NCP_P2P)
1827 {
1828 msg(M_WARN, "Note: peer reports running in P2P mode (no --pull/--client "
1829 "option). It will not negotiate ciphers with this server. "
1830 "Expect this connection to fail.");
1831 }
1832
1833 if (proto & IV_PROTO_REQUEST_PUSH)
1834 {
1835 c->c2.push_request_received = true;
1836 }
1837
1838#ifdef HAVE_EXPORT_KEYING_MATERIAL
1839 if (proto & IV_PROTO_TLS_KEY_EXPORT)
1840 {
1842 }
1843 else if (o->force_key_material_export)
1844 {
1845 msg(M_INFO, "PUSH: client does not support TLS Keying Material "
1846 "Exporters but --force-tls-key-material-export is enabled.");
1847 auth_set_client_reason(tls_multi, "Client incompatible with this "
1848 "server. Keying Material Exporters (RFC 5705) "
1849 "support missing. Upgrade to a client that "
1850 "supports this feature (OpenVPN 2.6.0+).");
1851 return false;
1852 }
1853 if (proto & IV_PROTO_DYN_TLS_CRYPT)
1854 {
1856 }
1857#endif
1858
1859 if (proto & IV_PROTO_CC_EXIT_NOTIFY)
1860 {
1862 }
1863
1864 /* Select cipher if client supports Negotiable Crypto Parameters */
1865
1866 /* if we have already created our key, we cannot *change* our own
1867 * cipher -> so log the fact and push the "what we have now" cipher
1868 * (so the client is always told what we expect it to use)
1869 */
1871 {
1872 msg(M_INFO, "PUSH: client wants to negotiate cipher (NCP), but "
1873 "server has already generated data channel keys, "
1874 "re-sending previously negotiated cipher '%s'",
1875 o->ciphername );
1876 return true;
1877 }
1878
1879 /*
1880 * Push the first cipher from --data-ciphers to the client that
1881 * the client announces to be supporting.
1882 */
1883 char *push_cipher = ncp_get_best_cipher(o->ncp_ciphers, peer_info,
1885 &o->gc);
1886 if (push_cipher)
1887 {
1888 /* Enable epoch data key format if supported and AEAD cipher in use */
1890 && (proto & IV_PROTO_DATA_EPOCH) && cipher_kt_mode_aead(push_cipher))
1891 {
1893 }
1894
1895 o->ciphername = push_cipher;
1896 return true;
1897 }
1898
1899 /* NCP cipher negotiation failed. Try to figure out why exactly it
1900 * failed and give good error messages and potentially do a fallback
1901 * for non NCP clients */
1902 struct gc_arena gc = gc_new();
1903 bool ret = false;
1904
1905 const char *peer_ciphers = tls_peer_ncp_list(peer_info, &gc);
1906 /* If we are in a situation where we know the client ciphers, there is no
1907 * reason to fall back to a cipher that will not be accepted by the other
1908 * side, in this situation we fail the auth*/
1909 if (strlen(peer_ciphers) > 0)
1910 {
1911 msg(M_INFO, "PUSH: No common cipher between server and client. "
1912 "Server data-ciphers: '%s'%s, client supported ciphers '%s'",
1913 o->ncp_ciphers_conf, ncp_expanded_ciphers(o, &gc), peer_ciphers);
1914 }
1915 else if (tls_multi->remote_ciphername)
1916 {
1917 msg(M_INFO, "PUSH: No common cipher between server and client. "
1918 "Server data-ciphers: '%s'%s, client supports cipher '%s'",
1921 }
1922 else
1923 {
1924 msg(M_INFO, "PUSH: No NCP or OCC cipher data received from peer.");
1925
1927 {
1928 msg(M_INFO, "Using data channel cipher '%s' since "
1929 "--data-ciphers-fallback is set.", o->ciphername);
1930 ret = true;
1931 }
1932 else
1933 {
1934 msg(M_INFO, "Use --data-ciphers-fallback with the cipher the "
1935 "client is using if you want to allow the client to connect");
1936 }
1937 }
1938 if (!ret)
1939 {
1940 auth_set_client_reason(tls_multi, "Data channel cipher negotiation "
1941 "failed (no shared cipher)");
1942 }
1943
1944 gc_free(&gc);
1945 return ret;
1946}
1947
1952static void
1954{
1956 if (!ccs->deferred_ret_file)
1957 {
1958 return;
1959 }
1960
1961 setenv_del(mi->context.c2.es, "client_connect_deferred_file");
1963 {
1964 msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s",
1965 ccs->deferred_ret_file);
1966 }
1967 free(ccs->deferred_ret_file);
1968 ccs->deferred_ret_file = NULL;
1969}
1970
1978static bool
1980{
1982 struct gc_arena gc = gc_new();
1983 const char *fn;
1984
1985 /* Delete file if it already exists */
1987
1989 if (!fn)
1990 {
1991 gc_free(&gc);
1992 return false;
1993 }
1994 ccs->deferred_ret_file = string_alloc(fn, NULL);
1995
1996 setenv_str(mi->context.c2.es, "client_connect_deferred_file",
1997 ccs->deferred_ret_file);
1998
1999 gc_free(&gc);
2000 return true;
2001}
2002
2011static enum client_connect_return
2013{
2015 FILE *fp = fopen(ccs->deferred_ret_file, "r");
2016 if (!fp)
2017 {
2018 return CC_RET_SKIPPED;
2019 }
2020
2022 const int c = fgetc(fp);
2023 switch (c)
2024 {
2025 case '0':
2026 ret = CC_RET_FAILED;
2027 break;
2028
2029 case '1':
2030 ret = CC_RET_SUCCEEDED;
2031 break;
2032
2033 case '2':
2034 ret = CC_RET_DEFERRED;
2035 break;
2036
2037 case EOF:
2038 if (feof(fp))
2039 {
2040 ret = CC_RET_SKIPPED;
2041 break;
2042 }
2043
2044 /* Not EOF but other error -> fall through to error state */
2045 default:
2046 /* We received an unknown/unexpected value. Assume failure. */
2047 msg(M_WARN, "WARNING: Unknown/unexpected value in deferred "
2048 "client-connect resultfile");
2049 ret = CC_RET_FAILED;
2050 }
2051 fclose(fp);
2052
2053 return ret;
2054}
2055
2061static void
2063{
2065 if (ccs->config_file)
2066 {
2067 setenv_del(mi->context.c2.es, "client_connect_config_file");
2068 if (!platform_unlink(ccs->config_file))
2069 {
2070 msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s",
2071 ccs->config_file);
2072 }
2073 free(ccs->config_file);
2074 ccs->config_file = NULL;
2075 }
2076}
2077
2085static bool
2087{
2089 struct gc_arena gc = gc_new();
2090 const char *fn;
2091
2092 if (ccs->config_file)
2093 {
2095 }
2096
2098 if (!fn)
2099 {
2100 gc_free(&gc);
2101 return false;
2102 }
2103 ccs->config_file = string_alloc(fn, NULL);
2104
2105 setenv_str(mi->context.c2.es, "client_connect_config_file",
2106 ccs->config_file);
2107
2108 gc_free(&gc);
2109 return true;
2110}
2111
2112static enum client_connect_return
2114 struct multi_instance *mi,
2115 bool deferred,
2116 unsigned int *option_types_found)
2117{
2119#ifdef ENABLE_PLUGIN
2120 ASSERT(m);
2121 ASSERT(mi);
2122 ASSERT(option_types_found);
2124
2125 /* deprecated callback, use a file for passing back return info */
2126 if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT))
2127 {
2128 struct argv argv = argv_new();
2129 int call;
2130
2131 if (!deferred)
2132 {
2133 call = OPENVPN_PLUGIN_CLIENT_CONNECT;
2134 if (!ccs_gen_config_file(mi)
2136 {
2137 ret = CC_RET_FAILED;
2138 goto cleanup;
2139 }
2140 }
2141 else
2142 {
2143 call = OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER;
2144 /* the initial call should have created these files */
2145 ASSERT(ccs->config_file);
2147 }
2148
2149 argv_printf(&argv, "%s", ccs->config_file);
2150 int plug_ret = plugin_call(mi->context.plugins, call,
2151 &argv, NULL, mi->context.c2.es);
2152 if (plug_ret == OPENVPN_PLUGIN_FUNC_SUCCESS)
2153 {
2154 ret = CC_RET_SUCCEEDED;
2155 }
2156 else if (plug_ret == OPENVPN_PLUGIN_FUNC_DEFERRED)
2157 {
2158 ret = CC_RET_DEFERRED;
2164 }
2165 else
2166 {
2167 msg(M_WARN, "WARNING: client-connect plugin call failed");
2168 ret = CC_RET_FAILED;
2169 }
2170
2171
2177 int file_ret = ccs_test_deferred_ret_file(mi);
2178
2179 if (file_ret == CC_RET_FAILED)
2180 {
2181 ret = CC_RET_FAILED;
2182 }
2183 else if (ret == CC_RET_SUCCEEDED && file_ret == CC_RET_DEFERRED)
2184 {
2185 ret = CC_RET_DEFERRED;
2186 }
2187
2188 /* if we still think we have succeeded, do postprocessing */
2189 if (ret == CC_RET_SUCCEEDED)
2190 {
2192 option_types_found);
2193 }
2194cleanup:
2195 argv_free(&argv);
2196
2197 if (ret != CC_RET_DEFERRED)
2198 {
2201 }
2202 }
2203#endif /* ifdef ENABLE_PLUGIN */
2204 return ret;
2205}
2206
2207static enum client_connect_return
2209 struct multi_instance *mi,
2210 bool deferred,
2211 unsigned int *option_types_found)
2212{
2214#ifdef ENABLE_PLUGIN
2215 ASSERT(m);
2216 ASSERT(mi);
2217 ASSERT(option_types_found);
2218
2219 int call = deferred ? OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 :
2220 OPENVPN_PLUGIN_CLIENT_CONNECT_V2;
2221 /* V2 callback, use a plugin_return struct for passing back return info */
2222 if (plugin_defined(mi->context.plugins, call))
2223 {
2224 struct plugin_return pr;
2225
2226 plugin_return_init(&pr);
2227
2228 int plug_ret = plugin_call(mi->context.plugins, call,
2229 NULL, &pr, mi->context.c2.es);
2230 if (plug_ret == OPENVPN_PLUGIN_FUNC_SUCCESS)
2231 {
2232 multi_client_connect_post_plugin(m, mi, &pr, option_types_found);
2233 ret = CC_RET_SUCCEEDED;
2234 }
2235 else if (plug_ret == OPENVPN_PLUGIN_FUNC_DEFERRED)
2236 {
2237 ret = CC_RET_DEFERRED;
2238 if (!(plugin_defined(mi->context.plugins,
2239 OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2)))
2240 {
2241 msg(M_WARN, "A plugin that defers from the "
2242 "OPENVPN_PLUGIN_CLIENT_CONNECT_V2 call must also "
2243 "declare support for "
2244 "OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2");
2245 ret = CC_RET_FAILED;
2246 }
2247 }
2248 else
2249 {
2250 msg(M_WARN, "WARNING: client-connect-v2 plugin call failed");
2251 ret = CC_RET_FAILED;
2252 }
2253
2254
2255 plugin_return_free(&pr);
2256 }
2257#endif /* ifdef ENABLE_PLUGIN */
2258 return ret;
2259}
2260
2261static enum client_connect_return
2263 struct multi_instance *mi,
2264 unsigned int *option_types_found)
2265{
2266 ASSERT(mi);
2267 ASSERT(option_types_found);
2270
2272
2273 if (ret == CC_RET_SKIPPED)
2274 {
2275 /*
2276 * Skipped and deferred are equivalent in this context.
2277 * skipped means that the called program has not yet
2278 * written a return status implicitly needing more time
2279 * while deferred is the explicit notification that it
2280 * needs more time
2281 */
2282 ret = CC_RET_DEFERRED;
2283 }
2284
2285 if (ret == CC_RET_SUCCEEDED)
2286 {
2291 }
2292 if (ret == CC_RET_FAILED)
2293 {
2294 msg(M_INFO, "MULTI: deferred --client-connect script returned CC_RET_FAILED");
2297 }
2298 return ret;
2299}
2300
2304static enum client_connect_return
2306 struct multi_instance *mi,
2307 bool deferred,
2308 unsigned int *option_types_found)
2309{
2310 if (deferred)
2311 {
2313 }
2314 ASSERT(m);
2315 ASSERT(mi);
2316
2319
2321 {
2322 struct argv argv = argv_new();
2323 struct gc_arena gc = gc_new();
2324
2325 setenv_str(mi->context.c2.es, "script_type", "client-connect");
2326
2327 if (!ccs_gen_config_file(mi)
2329 {
2330 ret = CC_RET_FAILED;
2331 goto cleanup;
2332 }
2333
2335 argv_printf_cat(&argv, "%s", ccs->config_file);
2336
2337 if (openvpn_run_script(&argv, mi->context.c2.es, 0, "--client-connect"))
2338 {
2340 {
2341 ret = CC_RET_DEFERRED;
2342 }
2343 else
2344 {
2346 option_types_found);
2347 ret = CC_RET_SUCCEEDED;
2348 }
2349 }
2350 else
2351 {
2352 ret = CC_RET_FAILED;
2353 }
2354cleanup:
2355 if (ret != CC_RET_DEFERRED)
2356 {
2359 }
2360 argv_free(&argv);
2361 gc_free(&gc);
2362 }
2363 return ret;
2364}
2365
2366static bool
2368 struct multi_instance *mi,
2369 struct gc_arena *gc)
2370{
2371 if (!dco_enabled(&mi->context.options))
2372 {
2373 /* DCO not enabled, nothing to do, return sucess */
2374 return true;
2375 }
2376 int ret = dco_multi_add_new_peer(m, mi);
2377 if (ret < 0)
2378 {
2379 msg(D_DCO, "Cannot add peer to DCO for %s: %s (%d)",
2380 multi_instance_string(mi, false, gc), strerror(-ret), ret);
2381 return false;
2382 }
2383
2384 return true;
2385}
2386
2390static bool
2392{
2393 struct frame *frame_fragment = NULL;
2394#ifdef ENABLE_FRAGMENT
2395 if (c->options.ce.fragment)
2396 {
2397 frame_fragment = &c->c2.frame_fragment;
2398 }
2399#endif
2402 &c->c2.frame, frame_fragment,
2404 &c->c1.tuntap->dco))
2405 {
2406 msg(D_TLS_ERRORS, "TLS Error: initializing data channel failed");
2407 register_signal(c->sig, SIGUSR1, "process-push-msg-failed");
2408 return false;
2409 }
2410
2411 return true;
2412}
2413
2414static void
2416 struct multi_instance *mi,
2417 const unsigned int option_types_found)
2418{
2419 ASSERT(m);
2420 ASSERT(mi);
2421
2422 struct gc_arena gc = gc_new();
2423 /*
2424 * Process sourced options.
2425 */
2426 do_deferred_options(&mi->context, option_types_found);
2427
2428 /*
2429 * make sure we got ifconfig settings from somewhere
2430 */
2432 {
2433 msg(D_MULTI_ERRORS, "MULTI: no dynamic or static remote "
2434 "--ifconfig address is available for %s",
2435 multi_instance_string(mi, false, &gc));
2436 }
2437
2438 /*
2439 * make sure that ifconfig settings comply with constraints
2440 */
2442 {
2443 const char *ifconfig_constraint_network =
2445 const char *ifconfig_constraint_netmask =
2447
2448 /* JYFIXME -- this should cause the connection to fail */
2449 msg(D_MULTI_ERRORS, "MULTI ERROR: primary virtual IP for %s (%s) "
2450 "violates tunnel network/netmask constraint (%s/%s)",
2451 multi_instance_string(mi, false, &gc),
2453 ifconfig_constraint_network, ifconfig_constraint_netmask);
2454 }
2455
2456 /* set our client's VPN endpoint for status reporting purposes */
2459
2460 /* set context-level authentication flag */
2462
2463 /* Since dco-win maintains iroute routing table (subnet -> peer),
2464 * peer must be added before iroutes. For other platforms it doesn't matter. */
2465
2466 /* authentication complete, calculate dynamic client specific options */
2468 {
2470 }
2471 /* only continue if setting protocol options worked */
2472 else if (!multi_client_setup_dco_initial(m, mi, &gc))
2473 {
2475 }
2476 /* Generate data channel keys only if setting protocol options
2477 * and DCO initial setup has not failed */
2479 {
2481 }
2482
2483 /* dco peer has been added, it is now safe for Windows to add iroutes */
2484
2485 /*
2486 * For routed tunnels, set up internal route to endpoint
2487 * plus add all iroute routes.
2488 */
2490 {
2492 {
2495 -1, true);
2496 msg(D_MULTI_LOW, "MULTI: primary virtual IP for %s: %s",
2497 multi_instance_string(mi, false, &gc),
2499 }
2500
2502 {
2505 -1, true);
2506 /* TODO: find out where addresses are "unlearned"!! */
2507 const char *ifconfig_local_ipv6 =
2509 msg(D_MULTI_LOW, "MULTI: primary virtual IPv6 for %s: %s",
2510 multi_instance_string(mi, false, &gc),
2511 ifconfig_local_ipv6);
2512 }
2513
2514 /* add routes locally, pointing to new client, if
2515 * --iroute options have been specified */
2516 multi_add_iroutes(m, mi);
2517
2518 /*
2519 * iroutes represent subnets which are "owned" by a particular
2520 * client. Therefore, do not actually push a route to a client
2521 * if it matches one of the client's iroutes.
2522 */
2524 }
2525 else if (mi->context.options.iroutes)
2526 {
2527 msg(D_MULTI_ERRORS, "MULTI: --iroute options rejected for %s -- iroute "
2528 "only works with tun-style tunnels",
2529 multi_instance_string(mi, false, &gc));
2530 }
2531
2532 /* send push reply if ready */
2534 {
2536 }
2537 gc_free(&gc);
2538}
2539
2540static void
2542 struct multi_instance *mi)
2543{
2544 ASSERT(mi->context.c1.tuntap);
2545 /*
2546 * lock down the common name and cert hashes so they can't change
2547 * during future TLS renegotiations
2548 */
2551
2552 /* generate a msg() prefix for this client instance */
2553 generate_prefix(mi);
2554
2555 /* delete instances of previous clients with same common-name */
2556 if (!mi->context.options.duplicate_cn)
2557 {
2558 multi_delete_dup(m, mi);
2559 }
2560
2561 /* reset pool handle to null */
2562 mi->vaddr_handle = -1;
2563
2564 /* do --client-connect setenvs */
2566
2568}
2569
2576static enum client_connect_return
2578 struct multi_instance *mi,
2579 bool deferred,
2580 unsigned int *option_types_found)
2581{
2582#ifdef USE_COMP
2583 struct options *o = &mi->context.options;
2584 const char *const peer_info = mi->context.c2.tls_multi->peer_info;
2585
2587 {
2588 if (peer_info && strstr(peer_info, "IV_COMP_STUBv2=1"))
2589 {
2590 push_option(o, "compress stub-v2", M_USAGE);
2591 }
2592 else
2593 {
2594 /* Client is old and does not support STUBv2 but since it
2595 * announced comp-lzo via OCC we assume it uses comp-lzo, so
2596 * switch to that and push the uncompressed variant. */
2597 push_option(o, "comp-lzo no", M_USAGE);
2598 o->comp.alg = COMP_ALG_STUB;
2599 *option_types_found |= OPT_P_COMP;
2600 }
2601 }
2602#endif
2603 return CC_RET_SUCCEEDED;
2604}
2605
2610static enum client_connect_return
2612 struct multi_instance *mi,
2613 bool deferred,
2614 unsigned int *option_types_found)
2615{
2616 /* Since we never return a CC_RET_DEFERRED, this indicates a serious
2617 * problem */
2618 ASSERT(!deferred);
2621 {
2622 struct gc_arena gc = gc_new();
2623 const char *ccd_file = NULL;
2624
2625 const char *ccd_client =
2627 tls_common_name(mi->context.c2.tls_multi, false),
2628 &gc);
2629
2630 const char *ccd_default =
2632 CCD_DEFAULT, &gc);
2633
2634
2635 /* try common-name file */
2636 if (platform_test_file(ccd_client))
2637 {
2638 ccd_file = ccd_client;
2639 }
2640 /* try default file */
2641 else if (platform_test_file(ccd_default))
2642 {
2643 ccd_file = ccd_default;
2644 }
2645
2646 if (ccd_file)
2647 {
2649 ccd_file,
2652 option_types_found,
2653 mi->context.c2.es);
2654 /*
2655 * Select a virtual address from either --ifconfig-push in
2656 * --client-config-dir file or --ifconfig-pool.
2657 */
2659
2661
2662 ret = CC_RET_SUCCEEDED;
2663 }
2664 gc_free(&gc);
2665 }
2666 return ret;
2667}
2668
2670 (struct multi_context *m, struct multi_instance *mi,
2671 bool from_deferred, unsigned int *option_types_found);
2672
2682
2683/*
2684 * Called as soon as the SSL/TLS connection is authenticated.
2685 *
2686 * Will collect the client specific configuration from the different
2687 * sources like ccd files, connect plugins and management interface.
2688 *
2689 * This method starts with cas_context CAS_PENDING and will move the
2690 * state machine to either CAS_SUCCEEDED on success or
2691 * CAS_FAILED/CAS_PARTIAL on failure.
2692 *
2693 * Instance-specific directives to be processed (CLIENT_CONNECT_OPT_MASK)
2694 * include:
2695 *
2696 * iroute start-ip end-ip
2697 * ifconfig-push local remote-netmask
2698 * push
2699 *
2700 *
2701 */
2702static void
2704{
2705 /* We are only called for the CAS_PENDING_x states, so we
2706 * can ignore other states here */
2707 bool from_deferred = (mi->context.c2.tls_multi->multi_state != CAS_PENDING);
2708
2709 int *cur_handler_index = &mi->client_connect_defer_state.cur_handler_index;
2710 unsigned int *option_types_found =
2712
2713 /* We are called for the first time */
2714 if (!from_deferred)
2715 {
2716 *cur_handler_index = 0;
2717 *option_types_found = 0;
2718 /* Initially we have no handler that has returned a result */
2720
2722 }
2723
2724 bool cc_succeeded = true;
2725
2726 while (cc_succeeded
2727 && client_connect_handlers[*cur_handler_index] != NULL)
2728 {
2729 enum client_connect_return ret;
2730 ret = client_connect_handlers[*cur_handler_index](m, mi, from_deferred,
2731 option_types_found);
2732
2733 from_deferred = false;
2734
2735 switch (ret)
2736 {
2737 case CC_RET_SUCCEEDED:
2738 /*
2739 * Remember that we already had at least one handler
2740 * returning a result should we go to into deferred state
2741 */
2742 mi->context.c2.tls_multi->multi_state = CAS_PENDING_DEFERRED_PARTIAL;
2743 break;
2744
2745 case CC_RET_SKIPPED:
2746 /*
2747 * Move on with the next handler without modifying any
2748 * other state
2749 */
2750 break;
2751
2752 case CC_RET_DEFERRED:
2753 /*
2754 * we already set multi_status to DEFERRED_RESULT or
2755 * DEFERRED_NO_RESULT. We just return
2756 * from the function as having multi_status
2757 */
2758 return;
2759
2760 case CC_RET_FAILED:
2761 /*
2762 * One handler failed. We abort the chain and set the final
2763 * result to failed
2764 */
2765 cc_succeeded = false;
2766 break;
2767
2768 default:
2769 ASSERT(0);
2770 }
2771
2772 /*
2773 * Check for "disable" directive in client-config-dir file
2774 * or config file generated by --client-connect script.
2775 */
2776 if (mi->context.options.disable)
2777 {
2778 msg(D_MULTI_ERRORS, "MULTI: client has been rejected due to "
2779 "'disable' directive");
2780 cc_succeeded = false;
2781 }
2782
2783 (*cur_handler_index)++;
2784 }
2785
2786 /* Check if we have forbidding options in the current mode */
2787 if (dco_enabled(&mi->context.options)
2789 {
2790 msg(D_MULTI_ERRORS, "MULTI: client has been rejected due to incompatible DCO options");
2791 cc_succeeded = false;
2792 }
2793
2795 {
2796 msg(D_MULTI_ERRORS, "MULTI: client has been rejected due to invalid compression options");
2797 cc_succeeded = false;
2798 }
2799
2800 if (cc_succeeded)
2801 {
2802 multi_client_connect_late_setup(m, mi, *option_types_found);
2803 }
2804 else
2805 {
2806 /* run the disconnect script if we had a connect script that
2807 * did not fail */
2809 {
2811 }
2812
2814 }
2815
2816 /* increment number of current authenticated clients */
2817 ++m->n_clients;
2819 --mi->n_clients_delta;
2820
2821#ifdef ENABLE_MANAGEMENT
2822 if (management)
2823 {
2825 &mi->context.c2.mda_context, mi->context.c2.es);
2826 }
2827#endif
2828}
2829
2830#ifdef ENABLE_ASYNC_PUSH
2831/*
2832 * Called when inotify event is fired, which happens when acf
2833 * or connect-status file is closed or deleted.
2834 * Continues authentication and sends push_reply
2835 * (or be deferred again by client-connect)
2836 */
2837void
2838multi_process_file_closed(struct multi_context *m, const unsigned int mpp_flags)
2839{
2840 char buffer[INOTIFY_EVENT_BUFFER_SIZE];
2841 size_t buffer_i = 0;
2842 int r = read(m->top.c2.inotify_fd, buffer, INOTIFY_EVENT_BUFFER_SIZE);
2843
2844 while (buffer_i < r)
2845 {
2846 /* parse inotify events */
2847 struct inotify_event *pevent = (struct inotify_event *) &buffer[buffer_i];
2848 size_t event_size = sizeof(struct inotify_event) + pevent->len;
2849 buffer_i += event_size;
2850
2851 msg(D_MULTI_DEBUG, "MULTI: modified fd %d, mask %d", pevent->wd, pevent->mask);
2852
2853 struct multi_instance *mi = hash_lookup(m->inotify_watchers, (void *) (unsigned long) pevent->wd);
2854
2855 if (pevent->mask & IN_CLOSE_WRITE)
2856 {
2857 if (mi)
2858 {
2859 /* continue authentication, perform NCP negotiation and send push_reply */
2860 multi_process_post(m, mi, mpp_flags);
2861 }
2862 else
2863 {
2864 msg(D_MULTI_ERRORS, "MULTI: multi_instance not found!");
2865 }
2866 }
2867 else if (pevent->mask & IN_IGNORED)
2868 {
2869 /* this event is _always_ fired when watch is removed or file is deleted */
2870 if (mi)
2871 {
2872 hash_remove(m->inotify_watchers, (void *) (unsigned long) pevent->wd);
2873 mi->inotify_watch = -1;
2874 }
2875 }
2876 else
2877 {
2878 msg(D_MULTI_ERRORS, "MULTI: unknown mask %d", pevent->mask);
2879 }
2880 }
2881}
2882#endif /* ifdef ENABLE_ASYNC_PUSH */
2883
2884/*
2885 * Add a mbuf buffer to a particular
2886 * instance.
2887 */
2888void
2890 struct multi_instance *mi,
2891 struct mbuf_buffer *mb)
2892{
2893 if (multi_output_queue_ready(m, mi))
2894 {
2895 struct mbuf_item item;
2896 item.buffer = mb;
2897 item.instance = mi;
2898 mbuf_add_item(m->mbuf, &item);
2899 }
2900 else
2901 {
2902 msg(D_MULTI_DROPPED, "MULTI: packet dropped due to output saturation (multi_add_mbuf)");
2903 }
2904}
2905
2906/*
2907 * Add a packet to a client instance output queue.
2908 */
2909static inline void
2911 const struct buffer *buf,
2912 struct multi_instance *mi)
2913{
2914 struct mbuf_buffer *mb;
2915
2916 if (BLEN(buf) > 0)
2917 {
2918 mb = mbuf_alloc_buf(buf);
2919 mb->flags = MF_UNICAST;
2920 multi_add_mbuf(m, mi, mb);
2921 mbuf_free_buf(mb);
2922 }
2923}
2924
2925/*
2926 * Broadcast a packet to all clients.
2927 */
2928static void
2930 const struct buffer *buf,
2931 const struct multi_instance *sender_instance,
2932 uint16_t vid)
2933{
2934 struct hash_iterator hi;
2935 struct hash_element *he;
2936 struct multi_instance *mi;
2937 struct mbuf_buffer *mb;
2938
2939 if (BLEN(buf) > 0)
2940 {
2942#ifdef MULTI_DEBUG_EVENT_LOOP
2943 printf("BCAST len=%d\n", BLEN(buf));
2944#endif
2945 mb = mbuf_alloc_buf(buf);
2946 hash_iterator_init(m->iter, &hi);
2947
2948 while ((he = hash_iterator_next(&hi)))
2949 {
2950 mi = (struct multi_instance *) he->value;
2951 if (mi != sender_instance && !mi->halt)
2952 {
2953 if (vid != 0 && vid != mi->context.options.vlan_pvid)
2954 {
2955 continue;
2956 }
2957 multi_add_mbuf(m, mi, mb);
2958 }
2959 }
2960
2961 hash_iterator_free(&hi);
2962 mbuf_free_buf(mb);
2963 perf_pop();
2964 }
2965}
2966
2967/*
2968 * Given a time delta, indicating that we wish to be
2969 * awoken by the scheduler at time now + delta, figure
2970 * a sigma parameter (in microseconds) that represents
2971 * a sort of fuzz factor around delta, so that we're
2972 * really telling the scheduler to wake us up any time
2973 * between now + delta - sigma and now + delta + sigma.
2974 *
2975 * The sigma parameter helps the scheduler to run more efficiently.
2976 * Sigma should be no larger than TV_WITHIN_SIGMA_MAX_USEC
2977 */
2978static inline unsigned int
2979compute_wakeup_sigma(const struct timeval *delta)
2980{
2981 if (delta->tv_sec < 1)
2982 {
2983 /* if < 1 sec, fuzz = # of microseconds / 8 */
2984 return delta->tv_usec >> 3;
2985 }
2986 else
2987 {
2988 /* if < 10 minutes, fuzz = 13.1% of timeout */
2989 if (delta->tv_sec < 600)
2990 {
2991 return delta->tv_sec << 17;
2992 }
2993 else
2994 {
2995 return 120000000; /* if >= 10 minutes, fuzz = 2 minutes */
2996 }
2997 }
2998}
2999
3000static void
3002{
3003 /* calculate an absolute wakeup time */
3004 ASSERT(!openvpn_gettimeofday(&mi->wakeup, NULL));
3005 tv_add(&mi->wakeup, &mi->context.c2.timeval);
3006
3007 /* tell scheduler to wake us up at some point in the future */
3009 (struct schedule_entry *) mi,
3010 &mi->wakeup,
3012}
3013
3014#if defined(ENABLE_ASYNC_PUSH)
3015static void
3016add_inotify_file_watch(struct multi_context *m, struct multi_instance *mi,
3017 int inotify_fd, const char *file)
3018{
3019 /* watch acf file */
3020 long watch_descriptor = inotify_add_watch(inotify_fd, file,
3021 IN_CLOSE_WRITE | IN_ONESHOT);
3022 if (watch_descriptor >= 0)
3023 {
3024 if (mi->inotify_watch != -1)
3025 {
3026 hash_remove(m->inotify_watchers,
3027 (void *) (unsigned long)mi->inotify_watch);
3028 }
3029 hash_add(m->inotify_watchers, (const uintptr_t *)watch_descriptor,
3030 mi, true);
3031 mi->inotify_watch = watch_descriptor;
3032 }
3033 else
3034 {
3035 msg(M_NONFATAL | M_ERRNO, "MULTI: inotify_add_watch error");
3036 }
3037}
3038#endif /* if defined(ENABLE_ASYNC_PUSH) */
3039
3040/*
3041 * Figure instance-specific timers, convert
3042 * earliest to absolute time in mi->wakeup,
3043 * call scheduler with our future wakeup time.
3044 *
3045 * Also close context on signal.
3046 */
3047bool
3048multi_process_post(struct multi_context *m, struct multi_instance *mi, const unsigned int flags)
3049{
3050 bool ret = true;
3051
3052 if (!IS_SIG(&mi->context) && ((flags & MPP_PRE_SELECT) || ((flags & MPP_CONDITIONAL_PRE_SELECT) && !ANY_OUT(&mi->context))))
3053 {
3054#if defined(ENABLE_ASYNC_PUSH)
3055 bool was_unauthenticated = true;
3056 struct key_state *ks = NULL;
3057 if (mi->context.c2.tls_multi)
3058 {
3060 was_unauthenticated = (ks->authenticated == KS_AUTH_FALSE);
3061 }
3062#endif
3063
3064 /* figure timeouts and fetch possible outgoing
3065 * to_link packets (such as ping or TLS control) */
3066 pre_select(&mi->context);
3067
3068#if defined(ENABLE_ASYNC_PUSH)
3069 /*
3070 * if we see the state transition from unauthenticated to deferred
3071 * and an auth_control_file, we assume it got just added and add
3072 * inotify watch to that file
3073 */
3074 if (ks && ks->plugin_auth.auth_control_file && was_unauthenticated
3075 && (ks->authenticated == KS_AUTH_DEFERRED))
3076 {
3077 add_inotify_file_watch(m, mi, m->top.c2.inotify_fd,
3079 }
3080 if (ks && ks->script_auth.auth_control_file && was_unauthenticated
3081 && (ks->authenticated == KS_AUTH_DEFERRED))
3082 {
3083 add_inotify_file_watch(m, mi, m->top.c2.inotify_fd,
3085 }
3086#endif
3087
3088 if (!IS_SIG(&mi->context))
3089 {
3090 /* connection is "established" when SSL/TLS key negotiation succeeds
3091 * and (if specified) auth user/pass succeeds */
3092
3094 {
3096 }
3097#if defined(ENABLE_ASYNC_PUSH)
3100 {
3101 add_inotify_file_watch(m, mi, m->top.c2.inotify_fd,
3103 deferred_ret_file);
3104 }
3105#endif
3106 /* tell scheduler to wake us up at some point in the future */
3108 }
3109 }
3110
3111 if (IS_SIG(&mi->context))
3112 {
3113 if (flags & MPP_CLOSE_ON_SIGNAL)
3114 {
3116 ret = false;
3117 }
3118 }
3119 else
3120 {
3121 /* continue to pend on output? */
3122 multi_set_pending(m, ANY_OUT(&mi->context) ? mi : NULL);
3123
3124#ifdef MULTI_DEBUG_EVENT_LOOP
3125 printf("POST %s[%d] to=%d lo=%d/%d w=%" PRIi64 "/%ld\n",
3126 id(mi),
3127 (int) (mi == m->pending),
3128 mi ? mi->context.c2.to_tun.len : -1,
3129 mi ? mi->context.c2.to_link.len : -1,
3130 (mi && mi->context.c2.fragment) ? mi->context.c2.fragment->outgoing.len : -1,
3131 (int64_t)mi->context.c2.timeval.tv_sec,
3132 (long)mi->context.c2.timeval.tv_usec);
3133#endif
3134 }
3135
3136 if ((flags & MPP_RECORD_TOUCH) && m->mpp_touched)
3137 {
3138 *m->mpp_touched = mi;
3139 }
3140
3141 return ret;
3142}
3143
3144void
3146 struct link_socket *sock)
3147{
3148 struct mroute_addr real = {0};
3149 struct hash *hash = m->hash;
3150 struct gc_arena gc = gc_new();
3151
3152 if (!mroute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true))
3153 {
3154 goto done;
3155 }
3156
3157 const uint32_t hv = hash_value(hash, &real);
3158 struct hash_bucket *bucket = hash_bucket(hash, hv);
3159
3160 /* make sure that we don't float to an address taken by another client */
3161 struct hash_element *he = hash_lookup_fast(hash, bucket, &real, hv);
3162 if (he)
3163 {
3164 struct multi_instance *ex_mi = (struct multi_instance *) he->value;
3165
3166 struct tls_multi *m1 = mi->context.c2.tls_multi;
3167 struct tls_multi *m2 = ex_mi->context.c2.tls_multi;
3168
3169 /* do not float if target address is taken by client with another cert */
3171 {
3172 msg(D_MULTI_LOW, "Disallow float to an address taken by another client %s",
3173 multi_instance_string(ex_mi, false, &gc));
3174
3175 mi->context.c2.buf.len = 0;
3176
3177 goto done;
3178 }
3179
3180 msg(D_MULTI_MEDIUM, "closing instance %s", multi_instance_string(ex_mi, false, &gc));
3181 multi_close_instance(m, ex_mi, false);
3182 }
3183
3184 msg(D_MULTI_MEDIUM, "peer %" PRIu32 " (%s) floated from %s to %s",
3186 tls_common_name(mi->context.c2.tls_multi, false),
3187 mroute_addr_print(&mi->real, &gc),
3189
3190 /* remove old address from hash table before changing address */
3191 ASSERT(hash_remove(m->hash, &mi->real));
3192 ASSERT(hash_remove(m->iter, &mi->real));
3193
3194 /* change external network address of the remote peer */
3195 mi->real = real;
3196 generate_prefix(mi);
3197
3198 mi->context.c2.from = m->top.c2.from;
3199 mi->context.c2.to_link_addr = &mi->context.c2.from;
3200
3201 /* inherit parent link_socket and link_socket_info */
3202 mi->context.c2.link_sockets[0] = sock;
3204
3206
3207 ASSERT(hash_add(m->hash, &mi->real, mi, false));
3208 ASSERT(hash_add(m->iter, &mi->real, mi, false));
3209
3210#ifdef ENABLE_MANAGEMENT
3211 ASSERT(hash_add(m->cid_hash, &mi->context.c2.mda_context.cid, mi, true));
3212#endif
3213
3214done:
3215 gc_free(&gc);
3216}
3217
3218/*
3219 * Called when an instance should be closed due to the
3220 * reception of a soft signal.
3221 */
3222void
3224{
3225 remap_signal(&mi->context);
3226 set_prefix(mi);
3227 print_signal(mi->context.sig, "client-instance", D_MULTI_LOW);
3228 clear_prefix();
3229 multi_close_instance(m, mi, false);
3230}
3231
3232#if (defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))) || defined(ENABLE_MANAGEMENT)
3233static void
3234multi_signal_instance(struct multi_context *m, struct multi_instance *mi, const int sig)
3235{
3236 mi->context.sig->signal_received = sig;
3238}
3239#endif
3240
3241#if defined(ENABLE_DCO) \
3242 && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(TARGET_WIN32))
3243static void
3244process_incoming_del_peer(struct multi_context *m, struct multi_instance *mi,
3246{
3247 const char *reason = "ovpn-dco: unknown reason";
3248 switch (dco->dco_del_peer_reason)
3249 {
3251 reason = "ovpn-dco: ping expired";
3252 break;
3253
3255 reason = "ovpn-dco: transport error";
3256 break;
3257
3259 reason = "ovpn-dco: transport disconnected";
3260 break;
3261
3263 /* We assume that is ourselves. Unfortunately, sometimes these
3264 * events happen with enough delay that they can have an order of
3265 *
3266 * dco_del_peer x
3267 * [new client connecting]
3268 * dco_new_peer x
3269 * event from dco_del_peer arrives.
3270 *
3271 * if we do not ignore this we get desynced with the kernel
3272 * since we assume the peer-id is free again. The other way would
3273 * be to send a dco_del_peer again
3274 */
3275 return;
3276 }
3277
3278 /* When kernel already deleted the peer, the socket is no longer
3279 * installed, and we do not need to clean up the state in the kernel */
3280 mi->context.c2.tls_multi->dco_peer_id = -1;
3281 mi->context.sig->signal_text = reason;
3282 mi->context.c2.dco_read_bytes = dco->dco_read_bytes;
3283 mi->context.c2.dco_write_bytes = dco->dco_write_bytes;
3284 multi_signal_instance(m, mi, SIGTERM);
3285}
3286
3287bool
3289{
3290 dco_context_t *dco = &m->top.c1.tuntap->dco;
3291
3292 struct multi_instance *mi = NULL;
3293
3294 int ret = dco_do_read(&m->top.c1.tuntap->dco);
3295
3296 int peer_id = dco->dco_message_peer_id;
3297
3298 /* no peer-specific message delivered -> nothing to process.
3299 * bail out right away
3300 */
3301 if (peer_id < 0)
3302 {
3303 return ret > 0;
3304 }
3305
3306 if ((peer_id < m->max_clients) && (m->instances[peer_id]))
3307 {
3308 mi = m->instances[peer_id];
3309 if (dco->dco_message_type == OVPN_CMD_DEL_PEER)
3310 {
3311 process_incoming_del_peer(m, mi, dco);
3312 }
3313 else if (dco->dco_message_type == OVPN_CMD_SWAP_KEYS)
3314 {
3316 }
3317 }
3318 else
3319 {
3320 int msglevel = D_DCO;
3321 if (dco->dco_message_type == OVPN_CMD_DEL_PEER
3322 && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
3323 {
3324 /* we receive OVPN_CMD_DEL_PEER message with reason USERSPACE
3325 * after we kill the peer ourselves. This peer may have already
3326 * been deleted, so we end up here.
3327 * In this case, print the following debug message with DCO_DEBUG
3328 * level only to avoid polluting the standard DCO level with this
3329 * harmless event.
3330 */
3331 msglevel = D_DCO_DEBUG;
3332 }
3333 msg(msglevel, "Received DCO message for unknown peer-id: %d, "
3334 "type %d, del_peer_reason %d", peer_id, dco->dco_message_type,
3335 dco->dco_del_peer_reason);
3336 }
3337
3338 dco->dco_message_type = 0;
3339 dco->dco_message_peer_id = -1;
3340 dco->dco_del_peer_reason = -1;
3341 dco->dco_read_bytes = 0;
3342 dco->dco_write_bytes = 0;
3343 return ret > 0;
3344}
3345#endif /* if defined(ENABLE_DCO) && defined(TARGET_LINUX) */
3346
3347/*
3348 * Process packets in the TCP/UDP socket -> TUN/TAP interface direction,
3349 * i.e. client -> server direction.
3350 */
3351bool
3353 const unsigned int mpp_flags, struct link_socket *sock)
3354{
3355 struct gc_arena gc = gc_new();
3356
3357 struct context *c;
3358 struct mroute_addr src, dest;
3359 unsigned int mroute_flags;
3360 struct multi_instance *mi;
3361 bool ret = true;
3362 bool floated = false;
3363
3364 if (m->pending)
3365 {
3366 return true;
3367 }
3368
3369 if (!instance)
3370 {
3371#ifdef MULTI_DEBUG_EVENT_LOOP
3372 printf("TCP/UDP -> TUN [%d]\n", BLEN(&m->top.c2.buf));
3373#endif
3374 multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));
3375 }
3376 else
3377 {
3378 multi_set_pending(m, instance);
3379 }
3380
3381 if (m->pending)
3382 {
3383 set_prefix(m->pending);
3384
3385 /* get instance context */
3386 c = &m->pending->context;
3387
3388 if (!instance)
3389 {
3390 /* transfer packet pointer from top-level context buffer to instance */
3391 c->c2.buf = m->top.c2.buf;
3392
3393 /* transfer from-addr from top-level context buffer to instance */
3394 if (!floated)
3395 {
3396 c->c2.from = m->top.c2.from;
3397 }
3398 }
3399
3400 if (BLEN(&c->c2.buf) > 0)
3401 {
3402 struct link_socket_info *lsi;
3403 const uint8_t *orig_buf;
3404
3405 /* decrypt in instance context */
3406
3408 lsi = &sock->info;
3409 orig_buf = c->c2.buf.data;
3410 if (process_incoming_link_part1(c, lsi, floated))
3411 {
3412 /* nonzero length means that we have a valid, decrypted packed */
3413 if (floated && c->c2.buf.len > 0)
3414 {
3415 multi_process_float(m, m->pending, sock);
3416 }
3417
3418 process_incoming_link_part2(c, lsi, orig_buf);
3419 }
3420 perf_pop();
3421
3423 {
3424 /* extract packet source and dest addresses */
3425 mroute_flags = mroute_extract_addr_from_packet(&src,
3426 &dest,
3427 0,
3428 &c->c2.to_tun,
3429 DEV_TYPE_TUN);
3430
3431 /* drop packet if extract failed */
3432 if (!(mroute_flags & MROUTE_EXTRACT_SUCCEEDED))
3433 {
3434 c->c2.to_tun.len = 0;
3435 }
3436 /* make sure that source address is associated with this client */
3437 else if (multi_get_instance_by_virtual_addr(m, &src, true) != m->pending)
3438 {
3439 /* IPv6 link-local address (fe80::xxx)? */
3440 if ( (src.type & MR_ADDR_MASK) == MR_ADDR_IPV6
3441 && IN6_IS_ADDR_LINKLOCAL(&src.v6.addr) )
3442 {
3443 /* do nothing, for now. TODO: add address learning */
3444 }
3445 else
3446 {
3447 msg(D_MULTI_DROPPED, "MULTI: bad source address from client [%s], packet dropped",
3448 mroute_addr_print(&src, &gc));
3449 }
3450 c->c2.to_tun.len = 0;
3451 }
3452 /* client-to-client communication enabled? */
3453 else if (m->enable_c2c)
3454 {
3455 /* multicast? */
3456 if (mroute_flags & MROUTE_EXTRACT_MCAST)
3457 {
3458 /* for now, treat multicast as broadcast */
3459 multi_bcast(m, &c->c2.to_tun, m->pending, 0);
3460 }
3461 else /* possible client to client routing */
3462 {
3463 ASSERT(!(mroute_flags & MROUTE_EXTRACT_BCAST));
3464 mi = multi_get_instance_by_virtual_addr(m, &dest, true);
3465
3466 /* if dest addr is a known client, route to it */
3467 if (mi)
3468 {
3469 {
3470 multi_unicast(m, &c->c2.to_tun, mi);
3472 }
3473 c->c2.to_tun.len = 0;
3474 }
3475 }
3476 }
3477 }
3478 else if (TUNNEL_TYPE(m->top.c1.tuntap) == DEV_TYPE_TAP)
3479 {
3480 uint16_t vid = 0;
3481
3482 if (m->top.options.vlan_tagging)
3483 {
3484 if (vlan_is_tagged(&c->c2.to_tun))
3485 {
3486 /* Drop VLAN-tagged frame. */
3487 msg(D_VLAN_DEBUG, "dropping incoming VLAN-tagged frame");
3488 c->c2.to_tun.len = 0;
3489 }
3490 else
3491 {
3492 vid = c->options.vlan_pvid;
3493 }
3494 }
3495 /* extract packet source and dest addresses */
3496 mroute_flags = mroute_extract_addr_from_packet(&src,
3497 &dest,
3498 vid,
3499 &c->c2.to_tun,
3500 DEV_TYPE_TAP);
3501
3502 if (mroute_flags & MROUTE_EXTRACT_SUCCEEDED)
3503 {
3504 if (multi_learn_addr(m, m->pending, &src, 0) == m->pending)
3505 {
3506 /* check for broadcast */
3507 if (m->enable_c2c)
3508 {
3509 if (mroute_flags & (MROUTE_EXTRACT_BCAST|MROUTE_EXTRACT_MCAST))
3510 {
3511 multi_bcast(m, &c->c2.to_tun, m->pending, vid);
3512 }
3513 else /* try client-to-client routing */
3514 {
3515 mi = multi_get_instance_by_virtual_addr(m, &dest, false);
3516
3517 /* if dest addr is a known client, route to it */
3518 if (mi)
3519 {
3520 multi_unicast(m, &c->c2.to_tun, mi);
3522 c->c2.to_tun.len = 0;
3523 }
3524 }
3525 }
3526 }
3527 else
3528 {
3529 msg(D_MULTI_DROPPED, "MULTI: bad source address from client [%s], packet dropped",
3530 mroute_addr_print(&src, &gc));
3531 c->c2.to_tun.len = 0;
3532 }
3533 }
3534 else
3535 {
3536 c->c2.to_tun.len = 0;
3537 }
3538 }
3539 }
3540
3541 /* postprocess and set wakeup */
3542 ret = multi_process_post(m, m->pending, mpp_flags);
3543
3544 clear_prefix();
3545 }
3546
3547 gc_free(&gc);
3548 return ret;
3549}
3550
3551/*
3552 * Process packets in the TUN/TAP interface -> TCP/UDP socket direction,
3553 * i.e. server -> client direction.
3554 */
3555bool
3556multi_process_incoming_tun(struct multi_context *m, const unsigned int mpp_flags)
3557{
3558 bool ret = true;
3559
3560 if (BLEN(&m->top.c2.buf) > 0)
3561 {
3562 unsigned int mroute_flags;
3563 struct mroute_addr src = {0}, dest = {0};
3564 const int dev_type = TUNNEL_TYPE(m->top.c1.tuntap);
3565 int16_t vid = 0;
3566
3567#ifdef MULTI_DEBUG_EVENT_LOOP
3568 printf("TUN -> TCP/UDP [%d]\n", BLEN(&m->top.c2.buf));
3569#endif
3570
3571 if (m->pending)
3572 {
3573 return true;
3574 }
3575
3576 if (dev_type == DEV_TYPE_TAP && m->top.options.vlan_tagging)
3577 {
3578 vid = vlan_decapsulate(&m->top, &m->top.c2.buf);
3579 if (vid < 0)
3580 {
3581 return false;
3582 }
3583 }
3584
3585 /*
3586 * Route an incoming tun/tap packet to
3587 * the appropriate multi_instance object.
3588 */
3589
3591 &dest,
3592 vid,
3593 &m->top.c2.buf,
3594 dev_type);
3595
3597 {
3598 struct context *c;
3599
3600 /* broadcast or multicast dest addr? */
3601 if (mroute_flags & (MROUTE_EXTRACT_BCAST|MROUTE_EXTRACT_MCAST))
3602 {
3603 /* for now, treat multicast as broadcast */
3604 multi_bcast(m, &m->top.c2.buf, NULL, vid);
3605 }
3606 else
3607 {
3609
3610 if (m->pending)
3611 {
3612 /* get instance context */
3613 c = &m->pending->context;
3614
3615 set_prefix(m->pending);
3616
3617 {
3619 {
3620 /* transfer packet pointer from top-level context buffer to instance */
3621 c->c2.buf = m->top.c2.buf;
3622 }
3623 else
3624 {
3625 /* drop packet */
3626 msg(D_MULTI_DROPPED, "MULTI: packet dropped due to output saturation (multi_process_incoming_tun)");
3627 buf_reset_len(&c->c2.buf);
3628 }
3629 }
3630
3631 /* encrypt in instance context */
3633
3634 /* postprocess and set wakeup */
3635 ret = multi_process_post(m, m->pending, mpp_flags);
3636
3637 clear_prefix();
3638 }
3639 }
3640 }
3641 }
3642 return ret;
3643}
3644
3645/*
3646 * Process a possible client-to-client/bcast/mcast message in the
3647 * queue.
3648 */
3649struct multi_instance *
3651{
3652 struct mbuf_item item;
3653
3654 if (mbuf_extract_item(ms, &item)) /* cleartext IP packet */
3655 {
3656 unsigned int pip_flags = PIPV4_PASSTOS | PIPV6_ICMP_NOHOST_SERVER;
3657
3658 set_prefix(item.instance);
3659 item.instance->context.c2.buf = item.buffer->buf;
3660 if (item.buffer->flags & MF_UNICAST) /* --mssfix doesn't make sense for broadcast or multicast */
3661 {
3662 pip_flags |= PIP_MSSFIX;
3663 }
3664 process_ip_header(&item.instance->context, pip_flags, &item.instance->context.c2.buf,
3665 item.instance->context.c2.link_sockets[0]);
3666 encrypt_sign(&item.instance->context, true);
3667 mbuf_free_buf(item.buffer);
3668
3669 dmsg(D_MULTI_DEBUG, "MULTI: C2C/MCAST/BCAST");
3670
3671 clear_prefix();
3672 return item.instance;
3673 }
3674 else
3675 {
3676 return NULL;
3677 }
3678}
3679
3680/*
3681 * Called when an I/O wait times out. Usually means that a particular
3682 * client instance object needs timer-based service.
3683 */
3684bool
3685multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
3686{
3687 bool ret = true;
3688
3689#ifdef MULTI_DEBUG_EVENT_LOOP
3690 printf("%s -> TIMEOUT\n", id(m->earliest_wakeup));
3691#endif
3692
3693 /* instance marked for wakeup? */
3694 if (m->earliest_wakeup)
3695 {
3697 {
3700 }
3701 else
3702 {
3704 ret = multi_process_post(m, m->earliest_wakeup, mpp_flags);
3705 clear_prefix();
3706 }
3707 m->earliest_wakeup = NULL;
3708 }
3709 return ret;
3710}
3711
3712/*
3713 * Drop a TUN/TAP outgoing packet..
3714 */
3715void
3716multi_process_drop_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags)
3717{
3718 struct multi_instance *mi = m->pending;
3719
3720 ASSERT(mi);
3721
3722 set_prefix(mi);
3723
3724 msg(D_MULTI_ERRORS, "MULTI: Outgoing TUN queue full, dropped packet len=%d",
3725 mi->context.c2.to_tun.len);
3726
3727 buf_reset(&mi->context.c2.to_tun);
3728
3729 multi_process_post(m, mi, mpp_flags);
3730 clear_prefix();
3731}
3732
3733/*
3734 * Per-client route quota management
3735 */
3736
3737void
3739{
3740 struct gc_arena gc = gc_new();
3741 msg(D_ROUTE_QUOTA, "MULTI ROUTE: route quota (%d) exceeded for %s (see --max-routes-per-client option)",
3743 multi_instance_string(mi, false, &gc));
3744 gc_free(&gc);
3745}
3746
3747#ifdef ENABLE_DEBUG
3748/*
3749 * Flood clients with random packets
3750 */
3751static void
3752gremlin_flood_clients(struct multi_context *m)
3753{
3754 const int level = GREMLIN_PACKET_FLOOD_LEVEL(m->top.options.gremlin);
3755 if (level)
3756 {
3757 struct gc_arena gc = gc_new();
3758 struct buffer buf = alloc_buf_gc(BUF_SIZE(&m->top.c2.frame), &gc);
3759 struct packet_flood_parms parm = get_packet_flood_parms(level);
3760 int i;
3761
3762 ASSERT(buf_init(&buf, m->top.c2.frame.buf.headroom));
3763 parm.packet_size = min_int(parm.packet_size, m->top.c2.frame.buf.payload_size);
3764
3765 msg(D_GREMLIN, "GREMLIN_FLOOD_CLIENTS: flooding clients with %d packets of size %d",
3766 parm.n_packets,
3767 parm.packet_size);
3768
3769 for (i = 0; i < parm.packet_size; ++i)
3770 {
3771 ASSERT(buf_write_u8(&buf, get_random() & 0xFF));
3772 }
3773
3774 for (i = 0; i < parm.n_packets; ++i)
3775 {
3776 multi_bcast(m, &buf, NULL, 0);
3777 }
3778
3779 gc_free(&gc);
3780 }
3781}
3782#endif /* ifdef ENABLE_DEBUG */
3783
3784static bool
3786{
3787 struct timeval null;
3788 CLEAR(null);
3790}
3791
3792/*
3793 * Process timers in the top-level context
3794 */
3795void
3797{
3798 /* possibly reap instances/routes in vhash */
3800
3801 /* possibly print to status log */
3802 if (m->top.c1.status_output)
3803 {
3805 {
3807 }
3808 }
3809
3810 /* possibly flush ifconfig-pool file */
3812
3813#ifdef ENABLE_DEBUG
3814 gremlin_flood_clients(m);
3815#endif
3816
3817 /* Should we check for stale routes? */
3819 {
3821 }
3822}
3823
3824void
3825multi_top_init(struct multi_context *m, struct context *top)
3826{
3827 inherit_context_top(&m->top, top);
3829}
3830
3831void
3837
3838static bool
3840{
3841 return (sig == SIGUSR1 || sig == SIGTERM || sig == SIGHUP || sig == SIGINT);
3842}
3843
3844static void
3846{
3847 struct hash_iterator hi;
3848 struct hash_element *he;
3849 struct timeval tv;
3850
3851 /* tell all clients to restart */
3852 hash_iterator_init(m->iter, &hi);
3853 while ((he = hash_iterator_next(&hi)))
3854 {
3855 struct multi_instance *mi = (struct multi_instance *) he->value;
3856 if (!mi->halt && proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto))
3857 {
3858 send_control_channel_string(&mi->context, next_server ? "RESTART,[N]" : "RESTART", D_PUSH);
3860 }
3861 }
3862 hash_iterator_free(&hi);
3863
3864 /* reschedule signal */
3866 tv.tv_sec = 2;
3867 tv.tv_usec = 0;
3869
3871
3876
3877 signal_reset(m->top.sig, 0);
3878}
3879
3880/*
3881 * Return true if event loop should break,
3882 * false if it should continue.
3883 */
3884bool
3886{
3887 if (signal_reset(m->top.sig, SIGUSR2) == SIGUSR2)
3888 {
3889 struct status_output *so = status_open(NULL, 0, M_INFO, NULL, 0);
3891 status_close(so);
3892 return false;
3893 }
3894 else if (has_udp_in_local_list(&m->top.options)
3898 {
3900 return false;
3901 }
3902 return true;
3903}
3904
3905/*
3906 * Management subsystem callbacks
3907 */
3908#ifdef ENABLE_MANAGEMENT
3909
3910static void
3911management_callback_status(void *arg, const int version, struct status_output *so)
3912{
3913 struct multi_context *m = (struct multi_context *) arg;
3914
3915 if (!version)
3916 {
3918 }
3919 else
3920 {
3921 multi_print_status(m, so, version);
3922 }
3923}
3924
3925static int
3927{
3928 struct multi_context *m = (struct multi_context *) arg;
3929 return m->n_clients;
3930}
3931
3932static int
3933management_callback_kill_by_cn(void *arg, const char *del_cn)
3934{
3935 struct multi_context *m = (struct multi_context *) arg;
3936 struct hash_iterator hi;
3937 struct hash_element *he;
3938 int count = 0;
3939
3940 hash_iterator_init(m->iter, &hi);
3941 while ((he = hash_iterator_next(&hi)))
3942 {
3943 struct multi_instance *mi = (struct multi_instance *) he->value;
3944 if (!mi->halt)
3945 {
3946 const char *cn = tls_common_name(mi->context.c2.tls_multi, false);
3947 if (cn && !strcmp(cn, del_cn))
3948 {
3949 multi_signal_instance(m, mi, SIGTERM);
3950 ++count;
3951 }
3952 }
3953 }
3954 hash_iterator_free(&hi);
3955 return count;
3956}
3957
3958static int
3959management_callback_kill_by_addr(void *arg, const in_addr_t addr,
3960 const int port, const int proto)
3961{
3962 struct multi_context *m = (struct multi_context *) arg;
3963 struct hash_iterator hi;
3964 struct hash_element *he;
3965 struct openvpn_sockaddr saddr;
3966 struct mroute_addr maddr;
3967 int count = 0;
3968
3969 CLEAR(saddr);
3970 saddr.addr.in4.sin_family = AF_INET;
3971 saddr.addr.in4.sin_addr.s_addr = htonl(addr);
3972 saddr.addr.in4.sin_port = htons(port);
3973 if (mroute_extract_openvpn_sockaddr(&maddr, &saddr, true))
3974 {
3975 maddr.proto = proto;
3976 hash_iterator_init(m->iter, &hi);
3977 while ((he = hash_iterator_next(&hi)))
3978 {
3979 struct multi_instance *mi = (struct multi_instance *) he->value;
3980 if (!mi->halt && mroute_addr_equal(&maddr, &mi->real))
3981 {
3982 multi_signal_instance(m, mi, SIGTERM);
3983 ++count;
3984 }
3985 }
3986 hash_iterator_free(&hi);
3987 }
3988 return count;
3989}
3990
3991static void
3993{
3994 struct multi_context *m = (struct multi_context *) arg;
3995 if (m->multi_io)
3996 {
3998 }
3999}
4000
4001static struct multi_instance *
4002lookup_by_cid(struct multi_context *m, const unsigned long cid)
4003{
4004 if (m)
4005 {
4006 struct multi_instance *mi = (struct multi_instance *) hash_lookup(m->cid_hash, &cid);
4007 if (mi && !mi->halt)
4008 {
4009 return mi;
4010 }
4011 }
4012 return NULL;
4013}
4014
4015static bool
4016management_kill_by_cid(void *arg, const unsigned long cid, const char *kill_msg)
4017{
4018 struct multi_context *m = (struct multi_context *) arg;
4019 struct multi_instance *mi = lookup_by_cid(m, cid);
4020 if (mi)
4021 {
4022 send_restart(&mi->context, kill_msg); /* was: multi_signal_instance (m, mi, SIGTERM); */
4024 return true;
4025 }
4026 else
4027 {
4028 return false;
4029 }
4030}
4031
4032static bool
4034 const unsigned long cid,
4035 const unsigned int mda_key_id,
4036 const char *extra,
4037 unsigned int timeout)
4038{
4039 struct multi_context *m = (struct multi_context *) arg;
4040 struct multi_instance *mi = lookup_by_cid(m, cid);
4041
4042 if (mi)
4043 {
4044 struct tls_multi *multi = mi->context.c2.tls_multi;
4045 struct tls_session *session;
4046
4047 if (multi->session[TM_INITIAL].key[KS_PRIMARY].mda_key_id == mda_key_id)
4048 {
4049 session = &multi->session[TM_INITIAL];
4050 }
4051 else if (multi->session[TM_ACTIVE].key[KS_PRIMARY].mda_key_id == mda_key_id)
4052 {
4053 session = &multi->session[TM_ACTIVE];
4054 }
4055 else
4056 {
4057 return false;
4058 }
4059
4060 /* sends INFO_PRE and AUTH_PENDING messages to client */
4061 bool ret = send_auth_pending_messages(multi, session, extra,
4062 timeout);
4065 return ret;
4066 }
4067 return false;
4068}
4069
4070
4071static bool
4073 const unsigned long cid,
4074 const unsigned int mda_key_id,
4075 const bool auth,
4076 const char *reason,
4077 const char *client_reason,
4078 struct buffer_list *cc_config) /* ownership transferred */
4079{
4080 struct multi_context *m = (struct multi_context *) arg;
4081 struct multi_instance *mi = lookup_by_cid(m, cid);
4082 bool cc_config_owned = true;
4083 bool ret = false;
4084
4085 if (mi)
4086 {
4087 ret = tls_authenticate_key(mi->context.c2.tls_multi, mda_key_id, auth, client_reason);
4088 if (ret)
4089 {
4090 if (auth)
4091 {
4093 {
4095 cc_config_owned = false;
4096 }
4097 }
4098 else if (reason)
4099 {
4100 msg(D_MULTI_LOW, "MULTI: connection rejected: %s, CLI:%s", reason, np(client_reason));
4101 }
4102 }
4103 }
4104 if (cc_config_owned && cc_config)
4105 {
4107 }
4108 return ret;
4109}
4110
4111static char *
4112management_get_peer_info(void *arg, const unsigned long cid)
4113{
4114 struct multi_context *m = (struct multi_context *) arg;
4115 struct multi_instance *mi = lookup_by_cid(m, cid);
4116 char *ret = NULL;
4117
4118 if (mi)
4119 {
4120 ret = mi->context.c2.tls_multi->peer_info;
4121 }
4122
4123 return ret;
4124}
4125
4126#endif /* ifdef ENABLE_MANAGEMENT */
4127
4128
4129void
4153
4154void
4156{
4157 /* max_clients must be less then max peer-id value */
4159
4160 for (int i = 0; i < m->max_clients; ++i)
4161 {
4162 if (!m->instances[i])
4163 {
4164 mi->context.c2.tls_multi->peer_id = i;
4165 m->instances[i] = mi;
4166 break;
4167 }
4168 }
4169
4170 /* should not really end up here, since multi_create_instance returns null
4171 * if amount of clients exceeds max_clients */
4173}
4174
4175/**************************************************************************/
4182static void
4184{
4185 int status;
4186
4187 while (true)
4188 {
4190
4191 /* wait on tun/socket list */
4192 multi_get_timeout(multi, &multi->top.c2.timeval);
4193 status = multi_io_wait(multi);
4194 MULTI_CHECK_SIG(multi);
4195
4196 /* check on status of coarse timers */
4198
4199 /* timeout? */
4200 if (status > 0)
4201 {
4202 /* process the I/O which triggered select */
4203 multi_io_process_io(multi);
4204 MULTI_CHECK_SIG(multi);
4205 }
4206 else if (status == 0)
4207 {
4208 multi_io_action(multi, NULL, TA_TIMEOUT, false);
4209 }
4210
4211 perf_pop();
4212 }
4213}
4214
4215/*
4216 * Top level event loop.
4217 */
4218void
4220{
4221 ASSERT(top->options.mode == MODE_SERVER);
4222
4223 struct multi_context multi;
4224
4225 top->mode = CM_TOP;
4227
4228 /* initialize top-tunnel instance */
4230 if (IS_SIG(top))
4231 {
4232 return;
4233 }
4234
4235 /* initialize global multi_context object */
4236 multi_init(&multi, top);
4237
4238 /* initialize our cloned top object */
4239 multi_top_init(&multi, top);
4240
4241 /* initialize management interface */
4243
4244 /* finished with initialization */
4245 initialization_sequence_completed(top, ISC_SERVER); /* --mode server --proto tcp-server */
4246
4247#ifdef ENABLE_ASYNC_PUSH
4248 multi.top.c2.inotify_fd = inotify_init();
4249 if (multi.top.c2.inotify_fd < 0)
4250 {
4251 msg(D_MULTI_ERRORS | M_ERRNO, "MULTI: inotify_init error");
4252 }
4253#endif
4254
4255 tunnel_server_loop(&multi);
4256
4257 #ifdef ENABLE_ASYNC_PUSH
4258 close(top->c2.inotify_fd);
4259#endif
4260
4261 /* shut down management interface */
4263
4264 /* save ifconfig-pool */
4265 multi_ifconfig_pool_persist(&multi, true);
4266
4267 /* tear down tunnel instance (unless --persist-tun) */
4268 multi_uninit(&multi);
4269 multi_top_free(&multi);
4271
4272}
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
Definition argv.c:483
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:102
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
Definition argv.c:440
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
Definition argv.c:464
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:88
bool buf_printf(struct buffer *buf, const char *format,...)
Definition buffer.c:240
void buffer_list_free(struct buffer_list *ol)
Frees a buffer list and all the buffers in it.
Definition buffer.c:1167
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Definition buffer.c:88
char * string_alloc(const char *str, struct gc_arena *gc)
Definition buffer.c:649
#define ALLOC_OBJ(dptr, type)
Definition buffer.h:1055
#define BSTR(buf)
Definition buffer.h:129
static void buf_reset(struct buffer *buf)
Definition buffer.h:303
static bool buf_write_u8(struct buffer *dest, uint8_t data)
Definition buffer.h:692
#define BLEN(buf)
Definition buffer.h:127
static void buf_reset_len(struct buffer *buf)
Definition buffer.h:312
static void strncpynt(char *dest, const char *src, size_t maxlen)
Definition buffer.h:361
static void gc_free(struct gc_arena *a)
Definition buffer.h:1033
#define ALLOC_OBJ_CLEAR(dptr, type)
Definition buffer.h:1060
#define buf_init(buf, offset)
Definition buffer.h:209
static struct gc_arena gc_new(void)
Definition buffer.h:1025
static const char *const key1
Definition cert_data.h:56
#define CCD_DEFAULT
Definition common.h:62
#define counter_format
Definition common.h:31
bool check_compression_settings_valid(struct compress_options *info, int msglevel)
Checks if the compression settings are valid.
Definition comp.c:163
#define COMP_ALG_STUB
Definition comp.h:48
#define COMP_F_MIGRATE
Definition comp.h:42
long int get_random(void)
Definition crypto.c:1757
const char * translate_cipher_name_to_openvpn(const char *cipher_name)
Translate a crypto library cipher name to an OpenVPN cipher name.
Definition crypto.c:1833
#define CO_USE_TLS_KEY_MATERIAL_EXPORT
Bit-flag indicating that data channel key derivation is done using TLS keying material export [RFC570...
Definition crypto.h:356
#define CO_USE_DYNAMIC_TLS_CRYPT
Bit-flag indicating that renegotiations are using tls-crypt with a TLS-EKM derived key.
Definition crypto.h:372
#define CO_EPOCH_DATA_KEY_FORMAT
Bit-flag indicating the epoch the data format.
Definition crypto.h:376
#define CO_USE_CC_EXIT_NOTIFY
Bit-flag indicating that explicit exit notifies should be sent via the control channel instead of usi...
Definition crypto.h:368
Data Channel Cryptography SSL library-specific backend interface.
bool cipher_kt_mode_aead(const char *ciphername)
Check if the supplied cipher is a supported AEAD mode cipher.
static int dco_do_read(dco_context_t *dco)
Definition dco.h:317
static int dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m, const bool raise_sigusr1_on_err)
Definition dco.h:379
static void dco_install_iroute(struct multi_context *m, struct multi_instance *mi, struct mroute_addr *addr)
Definition dco.h:368
static bool dco_check_option(int msglevel, const struct options *o)
Definition dco.h:282
void * dco_context_t
Definition dco.h:267
static int dco_multi_add_new_peer(struct multi_context *m, struct multi_instance *mi)
Definition dco.h:362
static void dco_delete_iroutes(struct multi_context *m, struct multi_instance *mi)
Definition dco.h:374
void setenv_counter(struct env_set *es, const char *name, counter_type value)
Definition env_set.c:259
void setenv_int(struct env_set *es, const char *name, int value)
Definition env_set.c:267
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:283
struct env_set * env_set_create(struct gc_arena *gc)
Definition env_set.c:156
void setenv_long_long(struct env_set *es, const char *name, long long value)
Definition env_set.c:275
void setenv_del(struct env_set *es, const char *name)
Definition env_set.c:328
#define D_PUSH
Definition errlevel.h:83
#define D_MULTI_ERRORS
Definition errlevel.h:65
#define D_VLAN_DEBUG
Definition errlevel.h:154
#define D_IMPORT_ERRORS
Definition errlevel.h:64
#define D_ROUTE_QUOTA
Definition errlevel.h:90
#define D_MULTI_MEDIUM
Definition errlevel.h:102
#define D_DCO
Definition errlevel.h:94
#define D_MULTI_DEBUG
Definition errlevel.h:127
#define D_MULTI_DROPPED
Definition errlevel.h:101
#define D_DCO_DEBUG
Definition errlevel.h:118
#define D_MULTI_LOW
Definition errlevel.h:86
#define D_TLS_ERRORS
Definition errlevel.h:59
#define M_INFO
Definition errlevel.h:55
#define D_GREMLIN
Definition errlevel.h:78
@ EVENT_ARG_MULTI_INSTANCE
Definition event.h:136
void reschedule_multi_process(struct context *c)
Reschedule tls_multi_process.
Definition forward.c:403
bool send_control_channel_string(struct context *c, const char *str, int msglevel)
Definition forward.c:410
void pre_select(struct context *c)
Definition forward.c:1997
void process_ip_header(struct context *c, unsigned int flags, struct buffer *buf, struct link_socket *sock)
Definition forward.c:1658
Interface functions to the internal and external multiplexers.
#define PIP_MSSFIX
Definition forward.h:307
#define PIPV6_ICMP_NOHOST_SERVER
Definition forward.h:312
static struct link_socket_info * get_link_socket_info(struct context *c)
Definition forward.h:321
#define ANY_OUT(c)
Definition forward.h:40
static void register_activity(struct context *c, const int size)
Definition forward.h:334
#define PIPV4_PASSTOS
Definition forward.h:306
#define TM_INITIAL
As yet un-trusted tls_session being negotiated.
Definition ssl_common.h:536
#define KS_PRIMARY
Primary key state index.
Definition ssl_common.h:456
#define TM_ACTIVE
Active tls_session.
Definition ssl_common.h:535
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:625
void tunnel_server(struct context *top)
Main event loop for OpenVPN in server mode.
Definition multi.c:4219
static void tunnel_server_loop(struct multi_context *multi)
Main event loop for OpenVPN in point-to-multipoint server mode.
Definition multi.c:4183
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:1000
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:1150
bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags, struct link_socket *sock)
Demultiplex and process a packet received over the external network interface.
Definition multi.c:3352
struct multi_instance * multi_get_create_instance_udp(struct multi_context *m, bool *floated, struct link_socket *sock)
Get, and if necessary create, the multi_instance associated with a packet's source address.
Definition mudp.c:190
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:1464
bool multi_process_incoming_tun(struct multi_context *m, const unsigned int mpp_flags)
Determine the destination VPN tunnel of a packet received over the virtual tun/tap network interface ...
Definition multi.c:3556
void uninit_management_callback(void)
Definition init.c:4532
void initialization_sequence_completed(struct context *c, const unsigned int flags)
Definition init.c:1590
void close_instance(struct context *c)
Definition init.c:4872
void inherit_context_top(struct context *dest, const struct context *src)
Definition init.c:5037
void free_context_buffers(struct context_buffers *b)
Definition init.c:3777
void init_instance_handle_signals(struct context *c, const struct env_set *env, const unsigned int flags)
Definition init.c:4558
void inherit_context_child(struct context *dest, const struct context *src, struct link_socket *sock)
Definition init.c:4947
void context_clear_2(struct context *c)
Definition init.c:89
void close_context(struct context *c, int sig, unsigned int flags)
Definition init.c:5084
void management_show_net_callback(void *arg, const int msglevel)
Definition init.c:4372
struct context_buffers * init_context_buffers(const struct frame *frame)
Definition init.c:3752
bool do_deferred_options(struct context *c, const unsigned int found)
Definition init.c:2670
#define CC_GC_FREE
Definition init.h:104
#define CC_HARD_USR1_TO_HUP
Definition init.h:106
#define ISC_SERVER
Definition init.h:116
static int min_int(int x, int y)
Definition integer.h:102
static int constrain_int(int x, int min, int max)
Definition integer.h:115
static SERVICE_STATUS status
Definition interactive.c:53
@ route
Definition interactive.c:87
@ read
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:43
#define ETT_DEFAULT
Definition interval.h:224
static void event_timeout_init(struct event_timeout *et, interval_t n, const time_t last)
Initialises a timer struct.
Definition interval.h:174
void hash_iterator_free(struct hash_iterator *hi)
Definition list.c:283
struct hash_element * hash_iterator_next(struct hash_iterator *hi)
Definition list.c:289
void hash_iterator_delete_element(struct hash_iterator *hi)
Definition list.c:321
struct hash_element * hash_lookup_fast(struct hash *hash, struct hash_bucket *bucket, const void *key, uint32_t hv)
Definition list.c:83
void hash_iterator_init(struct hash *hash, struct hash_iterator *hi)
Definition list.c:246
struct hash * hash_init(const int n_buckets, const uint32_t iv, uint32_t(*hash_function)(const void *key, uint32_t iv), bool(*compare_function)(const void *key1, const void *key2))
Definition list.c:38
void hash_iterator_init_range(struct hash *hash, struct hash_iterator *hi, int start_bucket, int end_bucket)
Definition list.c:223
void hash_free(struct hash *hash)
Definition list.c:63
bool hash_add(struct hash *hash, const void *key, void *value, bool replace)
Definition list.c:147
static bool hash_remove(struct hash *hash, const void *key)
Definition list.h:176
static void * hash_lookup(struct hash *hash, const void *key)
Definition list.h:140
static int hash_n_elements(const struct hash *hash)
Definition list.h:122
static uint32_t hash_value(const struct hash *hash, const void *key)
Definition list.h:116
static int hash_n_buckets(const struct hash *hash)
Definition list.h:128
static void hash_add_fast(struct hash *hash, struct hash_bucket *bucket, const void *key, uint32_t hv, void *value)
Definition list.h:158
void management_notify_client_close(struct management *management, struct man_def_auth_context *mdac, const struct env_set *es)
Definition manage.c:2997
void management_learn_addr(struct management *management, struct man_def_auth_context *mdac, const struct mroute_addr *addr, const bool primary)
Definition manage.c:3010
void management_connection_established(struct management *management, struct man_def_auth_context *mdac, const struct env_set *es)
Definition manage.c:2986
void management_set_callback(struct management *man, const struct management_callback *cb)
Definition manage.c:2732
#define MCF_SERVER
Definition manage.h:177
void mbuf_add_item(struct mbuf_set *ms, const struct mbuf_item *item)
Definition mbuf.c:89
struct mbuf_buffer * mbuf_alloc_buf(const struct buffer *buf)
Definition mbuf.c:65
void mbuf_free_buf(struct mbuf_buffer *mb)
Definition mbuf.c:76
void mbuf_dereference_instance(struct mbuf_set *ms, struct multi_instance *mi)
Definition mbuf.c:152
bool mbuf_extract_item(struct mbuf_set *ms, struct mbuf_item *item)
Definition mbuf.c:111
void mbuf_free(struct mbuf_set *ms)
Definition mbuf.c:49
struct mbuf_set * mbuf_init(unsigned int size)
Definition mbuf.c:39
#define MF_UNICAST
Definition mbuf.h:46
static int mbuf_maximum_queued(const struct mbuf_set *ms)
Definition mbuf.h:92
void mroute_addr_mask_host_bits(struct mroute_addr *ma)
Definition mroute.c:329
void mroute_helper_add_iroute46(struct mroute_helper *mh, int netbits)
Definition mroute.c:526
bool mroute_extract_openvpn_sockaddr(struct mroute_addr *addr, const struct openvpn_sockaddr *osaddr, bool use_port)
Definition mroute.c:264
const char * mroute_addr_print(const struct mroute_addr *ma, struct gc_arena *gc)
Definition mroute.c:384
uint32_t mroute_addr_hash_function(const void *key, uint32_t iv)
Definition mroute.c:369
void mroute_helper_del_iroute46(struct mroute_helper *mh, int netbits)
Definition mroute.c:541
bool mroute_learnable_address(const struct mroute_addr *addr, struct gc_arena *gc)
Definition mroute.c:65
bool mroute_addr_compare_function(const void *key1, const void *key2)
Definition mroute.c:377
struct mroute_helper * mroute_helper_init(int ageable_ttl_secs)
Definition mroute.c:488
void mroute_addr_init(struct mroute_addr *addr)
Definition mroute.c:39
void mroute_helper_free(struct mroute_helper *mh)
Definition mroute.c:557
#define MROUTE_EXTRACT_SUCCEEDED
Definition mroute.h:38
#define MROUTE_EXTRACT_MCAST
Definition mroute.h:40
static unsigned int mroute_extract_addr_from_packet(struct mroute_addr *src, struct mroute_addr *dest, uint16_t vid, const struct buffer *buf, int tunnel_type)
Definition mroute.h:181
#define MR_WITH_NETBITS
Definition mroute.h:70
static void mroute_extract_in_addr_t(struct mroute_addr *dest, const in_addr_t src)
Definition mroute.h:245
static bool mroute_addr_equal(const struct mroute_addr *a1, const struct mroute_addr *a2)
Definition mroute.h:210
#define MROUTE_EXTRACT_BCAST
Definition mroute.h:39
#define MR_ADDR_IPV6
Definition mroute.h:63
#define MR_ADDR_MASK
Definition mroute.h:64
void multi_tcp_instance_specific_free(struct multi_instance *mi)
Definition mtcp.c:126
void multi_tcp_delete_event(struct multi_io *multi_io, event_t event)
Definition mtcp.c:132
bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi)
Definition mtcp.c:102
void multi_tcp_dereference_instance(struct multi_io *multi_io, struct multi_instance *mi)
Definition mtcp.c:141
#define BUF_SIZE(f)
Definition mtu.h:172
static const char * np(const char *str)
Definition multi-auth.c:146
static struct multi_instance * multi_learn_addr(struct multi_context *m, struct multi_instance *mi, const struct mroute_addr *addr, const unsigned int flags)
Definition multi.c:1068
static void multi_schedule_context_wakeup(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:3001
static void multi_client_connect_early_setup(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:2541
static void multi_reap_free(struct multi_reap *mr)
Definition multi.c:238
static bool ccs_gen_deferred_ret_file(struct multi_instance *mi)
Create a temporary file for the return value of client connect and puts it into the client_connect_de...
Definition multi.c:1979
static struct multi_reap * multi_reap_new(int buckets_per_pass)
Definition multi.c:214
struct multi_instance * multi_create_instance(struct multi_context *m, const struct mroute_addr *real, struct link_socket *sock)
Definition multi.c:756
static void multi_add_iroutes(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:1325
void multi_ifconfig_pool_persist(struct multi_context *m, bool force)
Definition multi.c:163
static void multi_signal_instance(struct multi_context *m, struct multi_instance *mi, const int sig)
Definition multi.c:3234
void multi_reap_process_dowork(const struct multi_context *m)
Definition multi.c:225
static int management_callback_n_clients(void *arg)
Definition multi.c:3926
bool multi_process_signal(struct multi_context *m)
Definition multi.c:3885
static void multi_select_virtual_addr(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:1461
void multi_init(struct multi_context *m, struct context *t)
Definition multi.c:292
static enum client_connect_return multi_client_connect_call_script(struct multi_context *m, struct multi_instance *mi, bool deferred, unsigned int *option_types_found)
Runs the –client-connect script if one is defined.
Definition multi.c:2305
void multi_close_instance_on_signal(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:3223
bool multi_process_post(struct multi_context *m, struct multi_instance *mi, const unsigned int flags)
Perform postprocessing of a VPN tunnel instance.
Definition multi.c:3048
static void multi_connection_established(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:2703
void multi_process_per_second_timers_dowork(struct multi_context *m)
Definition multi.c:3796
static void multi_set_virtual_addr_env(struct multi_instance *mi)
Definition multi.c:1601
static void multi_client_connect_setenv(struct multi_instance *mi)
Definition multi.c:1772
struct multi_instance * multi_get_queue(struct mbuf_set *ms)
Definition multi.c:3650
bool multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
Definition multi.c:3685
void multi_process_float(struct multi_context *m, struct multi_instance *mi, struct link_socket *sock)
Handles peer floating.
Definition multi.c:3145
static int management_callback_kill_by_cn(void *arg, const char *del_cn)
Definition multi.c:3933
static bool stale_route_check_trigger(struct multi_context *m)
Definition multi.c:3785
static bool management_kill_by_cid(void *arg, const unsigned long cid, const char *kill_msg)
Definition multi.c:4016
static void generate_prefix(struct multi_instance *mi)
Definition multi.c:495
static void multi_del_iroutes(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:524
static void management_delete_event(void *arg, event_t event)
Definition multi.c:3992
static bool multi_client_setup_dco_initial(struct multi_context *m, struct multi_instance *mi, struct gc_arena *gc)
Definition multi.c:2367
static struct multi_instance * lookup_by_cid(struct multi_context *m, const unsigned long cid)
Definition multi.c:4002
const char * multi_instance_string(const struct multi_instance *mi, bool null, struct gc_arena *gc)
Definition multi.c:464
static void multi_client_connect_late_setup(struct multi_context *m, struct multi_instance *mi, const unsigned int option_types_found)
Definition multi.c:2415
static unsigned int compute_wakeup_sigma(const struct timeval *delta)
Definition multi.c:2979
static bool learn_address_script(const struct multi_context *m, const struct multi_instance *mi, const char *op, const struct mroute_addr *addr)
Definition multi.c:93
static void multi_unicast(struct multi_context *m, const struct buffer *buf, struct multi_instance *mi)
Definition multi.c:2910
void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown)
Definition multi.c:604
static bool management_client_pending_auth(void *arg, const unsigned long cid, const unsigned int mda_key_id, const char *extra, unsigned int timeout)
Definition multi.c:4033
enum client_connect_return(* multi_client_connect_handler)(struct multi_context *m, struct multi_instance *mi, bool from_deferred, unsigned int *option_types_found)
Definition multi.c:2670
static void multi_push_restart_schedule_exit(struct multi_context *m, bool next_server)
Definition multi.c:3845
static void multi_client_disconnect_script(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:575
static bool ccs_gen_config_file(struct multi_instance *mi)
Create a temporary file for the config directives of the client connect script and puts it into the c...
Definition multi.c:2086
static void check_stale_routes(struct multi_context *m)
Definition multi.c:1412
static int management_callback_kill_by_addr(void *arg, const in_addr_t addr, const int port, const int proto)
Definition multi.c:3959
static void multi_reap_range(const struct multi_context *m, int start_bucket, int end_bucket)
Definition multi.c:175
static bool management_client_auth(void *arg, const unsigned long cid, const unsigned int mda_key_id, const bool auth, const char *reason, const char *client_reason, struct buffer_list *cc_config)
Definition multi.c:4072
static void multi_bcast(struct multi_context *m, const struct buffer *buf, const struct multi_instance *sender_instance, uint16_t vid)
Definition multi.c:2929
static enum client_connect_return multi_client_connect_compress_migrate(struct multi_context *m, struct multi_instance *mi, bool deferred, unsigned int *option_types_found)
Do the necessary modification for doing the compress migrate.
Definition multi.c:2577
static void multi_reap_all(const struct multi_context *m)
Definition multi.c:208
void multi_add_mbuf(struct multi_context *m, struct multi_instance *mi, struct mbuf_buffer *mb)
Definition multi.c:2889
static int reap_buckets_per_pass(int n_buckets)
Definition multi.c:247
void route_quota_exceeded(const struct multi_instance *mi)
Definition multi.c:3738
void ungenerate_prefix(struct multi_instance *mi)
Definition multi.c:512
void multi_top_free(struct multi_context *m)
Definition multi.c:3832
void multi_assign_peer_id(struct multi_context *m, struct multi_instance *mi)
Assigns a peer-id to a a client and adds the instance to the the instances array of the multi_context...
Definition multi.c:4155
static enum client_connect_return multi_client_connect_call_plugin_v2(struct multi_context *m, struct multi_instance *mi, bool deferred, unsigned int *option_types_found)
Definition multi.c:2208
static enum client_connect_return multi_client_connect_source_ccd(struct multi_context *m, struct multi_instance *mi, bool deferred, unsigned int *option_types_found)
Try to source a dynamic config file from the –client-config-dir directory.
Definition multi.c:2611
static enum client_connect_return multi_client_connect_call_plugin_v1(struct multi_context *m, struct multi_instance *mi, bool deferred, unsigned int *option_types_found)
Definition multi.c:2113
static void multi_client_connect_post(struct multi_context *m, struct multi_instance *mi, const char *dc_file, unsigned int *option_types_found)
Definition multi.c:1657
static void multi_delete_dup(struct multi_context *m, struct multi_instance *new_mi)
Definition multi.c:1374
static struct multi_instance * multi_get_instance_by_virtual_addr(struct multi_context *m, const struct mroute_addr *addr, bool cidr_routing)
Definition multi.c:1161
void multi_top_init(struct multi_context *m, struct context *top)
Definition multi.c:3825
void init_management_callback_multi(struct multi_context *m)
Definition multi.c:4130
static enum client_connect_return ccs_test_deferred_ret_file(struct multi_instance *mi)
Tests whether the deferred return value file exists and returns the contained return value.
Definition multi.c:2012
static char * management_get_peer_info(void *arg, const unsigned long cid)
Definition multi.c:4112
static enum client_connect_return multi_client_connect_script_deferred(struct multi_context *m, struct multi_instance *mi, unsigned int *option_types_found)
Definition multi.c:2262
static bool multi_client_set_protocol_options(struct context *c)
Calculates the options that depend on the client capabilities based on local options and available pe...
Definition multi.c:1802
static void multi_client_connect_post_plugin(struct multi_context *m, struct multi_instance *mi, const struct plugin_return *pr, unsigned int *option_types_found)
Definition multi.c:1689
static struct multi_instance * multi_learn_in_addr_t(struct multi_context *m, struct multi_instance *mi, in_addr_t a, int netbits, bool primary)
Definition multi.c:1240
static bool is_exit_restart(int sig)
Definition multi.c:3839
static bool ifconfig_push_constraint_satisfied(const struct context *c)
Definition multi.c:1442
static void set_cc_config(struct multi_instance *mi, struct buffer_list *cc_config)
Definition multi.c:74
void multi_process_drop_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags)
Definition multi.c:3716
static bool cid_compare_function(const void *key1, const void *key2)
Definition multi.c:262
enum client_connect_return multi_client_connect_mda(struct multi_context *m, struct multi_instance *mi, bool deferred, unsigned int *option_types_found)
Definition multi.c:1733
static bool multi_client_generate_tls_keys(struct context *c)
Generates the data channel keys.
Definition multi.c:2391
static struct multi_instance * multi_learn_in6_addr(struct multi_context *m, struct multi_instance *mi, struct in6_addr a6, int netbits, bool primary)
Definition multi.c:1281
static void setenv_stats(struct multi_context *m, struct context *c)
Definition multi.c:547
static uint32_t cid_hash_function(const void *key, uint32_t iv)
Definition multi.c:255
static void management_callback_status(void *arg, const int version, struct status_output *so)
Definition multi.c:3911
static void update_mstat_n_clients(const int n_clients)
Definition multi.c:82
static void ccs_delete_config_file(struct multi_instance *mi)
Deletes the temporary file for the config directives of the client connect script and removes it into...
Definition multi.c:2062
static void ccs_delete_deferred_ret_file(struct multi_instance *mi)
Delete the temporary file for the return value of client connect It also removes it from client_conne...
Definition multi.c:1953
void multi_print_status(struct multi_context *m, struct status_output *so, const int version)
Definition multi.c:850
static const multi_client_connect_handler client_connect_handlers[]
Definition multi.c:2673
void multi_uninit(struct multi_context *m)
Definition multi.c:708
static void multi_client_disconnect_setenv(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:562
Header file for server-mode related structures and functions.
bool multi_process_incoming_dco(struct multi_context *m)
Process an incoming DCO message (from kernel space).
#define MPP_CONDITIONAL_PRE_SELECT
Definition multi.h:293
client_connect_return
Return values used by the client connect call-back functions.
Definition multi.h:226
@ CC_RET_DEFERRED
Definition multi.h:229
@ CC_RET_FAILED
Definition multi.h:227
@ CC_RET_SKIPPED
Definition multi.h:230
@ CC_RET_SUCCEEDED
Definition multi.h:228
static bool multi_output_queue_ready(const struct multi_context *m, const struct multi_instance *mi)
Definition multi.h:413
#define MULTI_PREFIX_MAX_LENGTH
Definition multi.h:46
#define MULTI_CHECK_SIG(m)
Definition multi.h:696
#define REAP_MIN
Definition multi.h:575
static void set_prefix(struct multi_instance *mi)
Definition multi.h:544
static void multi_route_del(struct multi_route *route)
Definition multi.h:501
static void multi_reap_process(const struct multi_context *m)
Definition multi.h:589
static void route_quota_inc(struct multi_instance *mi)
Definition multi.h:454
#define MULTI_ROUTE_CACHE
Definition multi.h:241
static void clear_prefix(void)
Definition multi.h:556
static bool multi_route_defined(const struct multi_context *m, const struct multi_route *r)
Definition multi.h:510
#define REAP_DIVISOR
Definition multi.h:574
#define MULTI_CACHE_ROUTE_TTL
Definition multi.h:582
#define MPP_CLOSE_ON_SIGNAL
Definition multi.h:294
#define REAP_MAX
Definition multi.h:576
static void multi_instance_dec_refcount(struct multi_instance *mi)
Definition multi.h:491
static void multi_instance_inc_refcount(struct multi_instance *mi)
Definition multi.h:485
static void multi_get_timeout(struct multi_context *m, struct timeval *dest)
Definition multi.h:616
#define CLIENT_CONNECT_OPT_MASK
Definition multi.h:678
static void multi_set_pending(struct multi_context *m, struct multi_instance *mi)
Definition multi.h:699
#define MULTI_ROUTE_AGEABLE
Definition multi.h:242
#define MPP_RECORD_TOUCH
Definition multi.h:295
#define MPP_PRE_SELECT
Definition multi.h:292
static void multi_process_per_second_timers(struct multi_context *m)
Definition multi.h:598
static bool route_quota_test(const struct multi_instance *mi)
Definition multi.h:467
void multi_io_process_io(struct multi_context *m)
Definition multi_io.c:441
struct multi_io * multi_io_init(int maxevents, int *maxclients)
Definition multi_io.c:117
void multi_io_free(struct multi_io *multi_io)
Definition multi_io.c:163
int multi_io_wait(struct multi_context *m)
Definition multi_io.c:174
void multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
Definition multi_io.c:577
#define TA_TIMEOUT
Definition multi_io.h:46
#define CLEAR(x)
Definition basic.h:33
#define M_OPTERR
Definition error.h:100
#define M_USAGE
Definition error.h:106
static bool check_debug_level(unsigned int level)
Definition error.h:220
#define M_NONFATAL
Definition error.h:90
#define dmsg(flags,...)
Definition error.h:148
#define msg(flags,...)
Definition error.h:144
#define ASSERT(x)
Definition error.h:195
#define M_WARN
Definition error.h:91
#define M_ERRNO
Definition error.h:94
static bool is_cas_pending(enum multi_status cas)
Definition openvpn.h:208
#define MAX_PEER_ID
Definition openvpn.h:546
#define CM_TOP
Definition openvpn.h:483
void options_server_import(struct options *o, const char *filename, int msglevel, unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
Definition options.c:5643
void options_string_import(struct options *options, const char *config, const int msglevel, const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
Definition options.c:5663
const char title_string[]
Definition options.c:69
bool has_udp_in_local_list(const struct options *options)
Definition options.c:9671
#define MODE_SERVER
Definition options.h:259
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:929
#define OPT_P_COMP
Definition options.h:740
const char * time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc)
Definition otime.c:108
struct frequency_limit * frequency_limit_init(int max, int per)
Definition otime.c:146
time_t now
Definition otime.c:34
void frequency_limit_free(struct frequency_limit *f)
Definition otime.c:161
static int openvpn_gettimeofday(struct timeval *tv, void *tz)
Definition otime.h:64
static void tv_add(struct timeval *dest, const struct timeval *src)
Definition otime.h:132
@ OVPN_CMD_SWAP_KEYS
@ OVPN_CMD_DEL_PEER
@OVPN_CMD_DEL_PEER: Remove peer from internal table
@ OVPN_DEL_PEER_REASON_EXPIRED
@ OVPN_DEL_PEER_REASON_TRANSPORT_DISCONNECT
@ OVPN_DEL_PEER_REASON_TRANSPORT_ERROR
@ OVPN_DEL_PEER_REASON_USERSPACE
#define PERF_MULTI_BCAST
Definition perf.h:48
static void perf_push(int type)
Definition perf.h:78
#define PERF_EVENT_LOOP
Definition perf.h:44
#define PERF_MULTI_CLOSE_INSTANCE
Definition perf.h:46
#define PERF_PROC_IN_LINK
Definition perf.h:52
static void perf_pop(void)
Definition perf.h:82
#define PERF_MULTI_CREATE_INSTANCE
Definition perf.h:45
bool platform_test_file(const char *filename)
Return true if filename can be opened for read.
Definition platform.c:660
const char * platform_create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc)
Create a temporary file in directory, returns the filename of the created file.
Definition platform.c:541
const char * platform_gen_path(const char *directory, const char *filename, struct gc_arena *gc)
Put a directory and filename together.
Definition platform.c:594
bool platform_unlink(const char *filename)
Definition platform.c:488
void plugin_return_free(struct plugin_return *pr)
Definition plugin.c:1015
void plugin_return_get_column(const struct plugin_return *src, struct plugin_return *dest, const char *colname)
Definition plugin.c:1000
bool plugin_defined(const struct plugin_list *pl, const int type)
Definition plugin.c:932
static void plugin_return_init(struct plugin_return *pr)
Definition plugin.h:171
static int plugin_call(const struct plugin_list *pl, const int type, const struct argv *av, struct plugin_return *pr, struct env_set *es)
Definition plugin.h:202
static bool plugin_return_defined(const struct plugin_return *pr)
Definition plugin.h:165
ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local, in_addr_t *remote, struct in6_addr *remote_ipv6, const char *common_name)
Definition pool.c:306
bool ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handle hand, const bool hard)
Definition pool.c:357
void ifconfig_pool_write(struct ifconfig_pool_persist *persist, const struct ifconfig_pool *pool)
Definition pool.c:733
bool ifconfig_pool_write_trigger(struct ifconfig_pool_persist *persist)
Definition pool.c:585
void ifconfig_pool_free(struct ifconfig_pool *pool)
Definition pool.c:290
void ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool *pool)
Definition pool.c:598
struct ifconfig_pool * ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, in_addr_t end, const bool duplicate_cn, const bool ipv6_pool, const struct in6_addr ipv6_base, const int ipv6_netbits)
Definition pool.c:146
pool_type
Definition pool.h:36
@ IFCONFIG_POOL_30NET
Definition pool.h:37
@ IFCONFIG_POOL_INDIV
Definition pool.h:38
#define DEV_TYPE_TAP
Definition proto.h:37
#define DEV_TYPE_UNDEF
Definition proto.h:35
#define TOP_NET30
Definition proto.h:42
#define DEV_TYPE_TUN
Definition proto.h:36
#define TOP_P2P
Definition proto.h:43
#define TOP_SUBNET
Definition proto.h:44
int process_incoming_push_request(struct context *c)
Definition push.c:967
void send_restart(struct context *c, const char *kill_msg)
Definition push.c:496
void push_option(struct options *o, const char *opt, int msglevel)
Definition push.c:875
bool send_auth_pending_messages(struct tls_multi *tls_multi, struct tls_session *session, const char *extra, unsigned int timeout)
Sends the auth pending control messages to a client.
Definition push.c:439
void remove_iroutes_from_push_route_list(struct options *o)
Definition push.c:1117
void initial_rate_limit_free(struct initial_packet_rate_limit *irl)
free the initial-packet rate limiter structure
struct initial_packet_rate_limit * initial_rate_limit_init(int max_per_period, int period_length)
allocate and initialize the initial-packet rate limiter structure
static int openvpn_run_script(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *hook)
Will run a script and return the exit code of the script if between 0 and 255, -1 otherwise.
Definition run_command.h:87
void schedule_remove_entry(struct schedule *s, struct schedule_entry *e)
Definition schedule.c:427
struct schedule * schedule_init(void)
Definition schedule.c:412
void schedule_free(struct schedule *s)
Definition schedule.c:421
static void schedule_add_entry(struct schedule *s, struct schedule_entry *e, const struct timeval *tv, unsigned int sigma)
Definition schedule.h:98
int signal_reset(struct signal_info *si, int signum)
Clear the signal if its current value equals signum.
Definition sig.c:266
void remap_signal(struct context *c)
Definition sig.c:591
void throw_signal(const int signum)
Throw a hard signal.
Definition sig.c:177
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:231
void print_signal(const struct signal_info *si, const char *title, int msglevel)
Definition sig.c:294
#define IS_SIG(c)
Definition sig.h:48
void setenv_in_addr_t(struct env_set *es, const char *name_prefix, in_addr_t addr, const unsigned int flags)
Definition socket.c:3101
void setenv_in6_addr(struct env_set *es, const char *name_prefix, const struct in6_addr *addr, const unsigned int flags)
Definition socket.c:3114
const char * print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena *gc)
Definition socket.c:2893
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
Definition socket.c:2994
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
Definition socket.c:2974
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
Definition socket.c:2419
#define IA_EMPTY_IF_UNDEF
Definition socket.h:401
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
Definition socket.h:597
#define SA_SET_IF_NONZERO
Definition socket.h:412
void tls_update_remote_addr(struct tls_multi *multi, const struct link_socket_actual *addr)
Updates remote address in TLS sessions.
Definition ssl.c:4216
void tls_session_soft_reset(struct tls_multi *tls_multi)
Definition ssl.c:1842
bool tls_session_update_crypto_params(struct tls_multi *multi, struct tls_session *session, struct options *options, struct frame *frame, struct frame *frame_fragment, struct link_socket_info *lsi, dco_context_t *dco)
Update TLS session crypto parameters (cipher and auth) and derive data channel keys based on the supp...
Definition ssl.c:1707
#define IV_PROTO_CC_EXIT_NOTIFY
Support for explicit exit notify via control channel This also includes support for the protocol-flag...
Definition ssl.h:102
#define IV_PROTO_DATA_EPOCH
Support the extended packet id and epoch format for data channel packets.
Definition ssl.h:111
#define IV_PROTO_DATA_V2
Support P_DATA_V2.
Definition ssl.h:80
#define IV_PROTO_TLS_KEY_EXPORT
Supports key derivation via TLS key material exporter [RFC5705].
Definition ssl.h:87
#define IV_PROTO_DYN_TLS_CRYPT
Support to dynamic tls-crypt (renegotiation with TLS-EKM derived tls-crypt key)
Definition ssl.h:108
#define IV_PROTO_REQUEST_PUSH
Assume client will send a push request and server does not need to wait for a push-request to send a ...
Definition ssl.h:84
#define IV_PROTO_NCP_P2P
Support doing NCP in P2P mode.
Definition ssl.h:95
@ CAS_CONNECT_DONE
Definition ssl_common.h:579
@ CAS_PENDING_DEFERRED
Waiting on an async option import handler.
Definition ssl_common.h:571
@ CAS_WAITING_AUTH
Initial TLS connection established but deferred auth is not yet finished.
Definition ssl_common.h:569
@ CAS_PENDING_DEFERRED_PARTIAL
at least handler succeeded but another is still pending
Definition ssl_common.h:572
@ CAS_PENDING
Options import (Connect script/plugin, ccd,...)
Definition ssl_common.h:570
@ CAS_NOT_CONNECTED
Definition ssl_common.h:568
@ CAS_FAILED
Option import failed or explicitly denied the client.
Definition ssl_common.h:573
@ KS_AUTH_FALSE
Key state is not authenticated
Definition ssl_common.h:148
@ KS_AUTH_DEFERRED
Key state authentication is being deferred, by async auth.
Definition ssl_common.h:149
static const struct key_state * get_primary_key(const struct tls_multi *multi)
gets an item of key_state objects in the order they should be scanned by data channel modules.
Definition ssl_common.h:728
char * ncp_get_best_cipher(const char *server_list, const char *peer_info, const char *remote_cipher, struct gc_arena *gc)
Iterates through the ciphers in server_list and return the first cipher that is also supported by the...
Definition ssl_ncp.c:250
const char * tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc)
Returns the support cipher list from the peer according to the IV_NCP and IV_CIPHER values in peer_in...
Definition ssl_ncp.c:229
const char * ncp_expanded_ciphers(struct options *o, struct gc_arena *gc)
returns the o->ncp_ciphers in brackets, e.g.
Definition ssl_ncp.c:634
Control Channel SSL/Data dynamic negotiation Module This file is split from ssl.h to be able to unit ...
unsigned int extract_iv_proto(const char *peer_info)
Extracts the IV_PROTO variable and returns its value or 0 if it cannot be extracted.
Definition ssl_util.c:62
SSL utility functions.
bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason)
bool cert_hash_compare(const struct cert_hash_set *chs1, const struct cert_hash_set *chs2)
Compares certificates hashes, returns true if hashes are equal.
Definition ssl_verify.c:232
void tls_lock_cert_hash_set(struct tls_multi *multi)
Locks the certificate hash set used in the given tunnel.
Definition ssl_verify.c:290
void tls_lock_common_name(struct tls_multi *multi)
Locks the common name field for the given tunnel.
Definition ssl_verify.c:139
const char * tls_username(const struct tls_multi *multi, const bool null)
Returns the username field for the given tunnel.
Definition ssl_verify.c:175
void auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
Sets the reason why authentication of a client failed.
Definition ssl_verify.c:808
const char * tls_common_name(const struct tls_multi *multi, const bool null)
Returns the common name field for the given tunnel.
Definition ssl_verify.c:114
Control Channel Verification Module.
bool status_trigger(struct status_output *so)
Definition status.c:133
void status_printf(struct status_output *so, const char *format,...)
Definition status.c:222
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
Definition status.c:61
void status_flush(struct status_output *so)
Definition status.c:157
void status_reset(struct status_output *so)
Definition status.c:148
bool status_close(struct status_output *so)
Definition status.c:188
Definition argv.h:35
Definition buffer.h:1115
struct buffer_entry * next
Definition buffer.h:1117
struct buffer buf
Definition buffer.h:1116
struct buffer_entry * head
Definition buffer.h:1122
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
Detached client connection state.
Definition multi.h:73
char * config_file
The temporary file name that contains the config directives returned by the client-connect script.
Definition multi.h:90
unsigned int option_types_found
Definition multi.h:78
char * deferred_ret_file
The temporary file name that contains the return status of the client-connect script if it exits with...
Definition multi.h:84
unsigned int flags
Definition comp.h:69
int explicit_exit_notification
Definition options.h:148
int fragment
Definition options.h:139
struct ifconfig_pool_persist * ifconfig_pool_persist
Definition openvpn.h:196
struct status_output * status_output
Definition openvpn.h:184
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:171
bool push_request_received
Definition openvpn.h:427
counter_type link_read_bytes
Definition openvpn.h:266
counter_type link_write_bytes
Definition openvpn.h:269
bool push_ifconfig_ipv6_defined
Definition openvpn.h:434
struct fragment_master * fragment
Definition openvpn.h:252
bool push_ifconfig_defined
Definition openvpn.h:428
counter_type dco_read_bytes
Definition openvpn.h:267
struct man_def_auth_context mda_context
Definition openvpn.h:453
counter_type dco_write_bytes
Definition openvpn.h:270
struct env_set * es
Definition openvpn.h:420
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition openvpn.h:323
struct frame frame
Definition openvpn.h:248
struct in6_addr push_ifconfig_ipv6_remote
Definition openvpn.h:437
struct link_socket_actual from
Definition openvpn.h:245
struct frame frame_fragment
Definition openvpn.h:253
int push_ifconfig_ipv6_netbits
Definition openvpn.h:436
struct buffer to_link
Definition openvpn.h:377
struct buffer to_tun
Definition openvpn.h:376
struct in6_addr push_ifconfig_ipv6_local
Definition openvpn.h:435
struct link_socket ** link_sockets
Definition openvpn.h:237
in_addr_t push_ifconfig_local_alias
Definition openvpn.h:432
struct link_socket_info ** link_socket_infos
Definition openvpn.h:238
struct link_socket_actual * to_link_addr
Definition openvpn.h:244
in_addr_t push_ifconfig_remote_netmask
Definition openvpn.h:431
struct buffer buf
Definition openvpn.h:375
struct timeval timeval
Time to next event of timers and similar.
Definition openvpn.h:396
struct event_set * event_set
Definition openvpn.h:230
struct context_buffers * buffers
Definition openvpn.h:367
in_addr_t push_ifconfig_local
Definition openvpn.h:430
Contains all state information for one tunnel.
Definition openvpn.h:474
int mode
Role of this context within the OpenVPN process.
Definition openvpn.h:487
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:500
struct plugin_list * plugins
List of plug-ins.
Definition openvpn.h:502
struct context_2 c2
Level 2 context.
Definition openvpn.h:514
struct env_set * es
Set of environment variables.
Definition openvpn.h:496
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:475
struct context_1 c1
Level 1 context.
Definition openvpn.h:513
Security parameter state for processing data channel packets.
Definition crypto.h:292
struct key_ctx_bi key_ctx_bi
OpenSSL cipher and HMAC contexts for both sending and receiving directions.
Definition crypto.h:293
int signal_received
Definition multi.h:64
struct timeval wakeup
Definition multi.h:65
struct multi_instance * mi
Definition event.h:145
union event_arg::@1 u
event_arg_t type
Definition event.h:143
struct buffer outgoing
Buffer containing the remaining parts of the fragmented packet being sent.
Definition fragment.h:170
Packet geometry parameters.
Definition mtu.h:98
int payload_size
the maximum size that a payload that our buffers can hold from either tun device or network link.
Definition mtu.h:102
int headroom
the headroom in the buffer, this is choosen to allow all potential header to be added before the pack...
Definition mtu.h:108
struct frame::@8 buf
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:117
void * value
Definition list.h:45
const void * key
Definition list.h:46
Definition list.h:57
struct iroute_ipv6 * next
Definition route.h:250
unsigned int netbits
Definition route.h:249
struct in6_addr network
Definition route.h:248
in_addr_t network
Definition route.h:242
int netbits
Definition route.h:243
struct iroute * next
Definition route.h:244
Container for bidirectional cipher and HMAC key material.
Definition crypto.h:239
bool initialized
Definition crypto.h:284
Security parameter state of one TLS and data channel key session.
Definition ssl_common.h:200
struct auth_deferred_status plugin_auth
Definition ssl_common.h:260
unsigned int mda_key_id
Definition ssl_common.h:255
struct auth_deferred_status script_auth
Definition ssl_common.h:261
enum ks_auth_state authenticated
Definition ssl_common.h:251
Container for unidirectional cipher and HMAC key material.
Definition crypto.h:152
unsigned long cid
Definition manage.h:65
char *(* get_peer_info)(void *arg, const unsigned long cid)
Definition manage.h:200
bool(* client_auth)(void *arg, const unsigned long cid, const unsigned int mda_key_id, const bool auth, const char *reason, const char *client_reason, struct buffer_list *cc_config)
Definition manage.h:188
void(* delete_event)(void *arg, event_t event)
Definition manage.h:184
int(* kill_by_addr)(void *arg, const in_addr_t addr, const int port, const int proto)
Definition manage.h:183
bool(* client_pending_auth)(void *arg, const unsigned long cid, const unsigned int kid, const char *extra, unsigned int timeout)
Definition manage.h:195
int(* n_clients)(void *arg)
Definition manage.h:185
void(* status)(void *arg, const int version, struct status_output *so)
Definition manage.h:180
unsigned int flags
Definition manage.h:178
int(* kill_by_cn)(void *arg, const char *common_name)
Definition manage.h:182
bool(* kill_by_cid)(void *arg, const unsigned long cid, const char *kill_msg)
Definition manage.h:187
void(* show_net)(void *arg, const int msglevel)
Definition manage.h:181
unsigned int flags
Definition mbuf.h:47
struct buffer buf
Definition mbuf.h:43
struct mbuf_buffer * buffer
Definition mbuf.h:52
struct multi_instance * instance
Definition mbuf.h:53
uint16_t vid
Definition mroute.h:88
struct mroute_addr::@2::@6 v6
uint8_t addr[OPENVPN_ETH_ALEN]
Definition mroute.h:87
uint8_t proto
Definition mroute.h:80
uint8_t type
Definition mroute.h:81
in_port_t port
Definition mroute.h:92
uint8_t len
Definition mroute.h:79
uint8_t netbits
Definition mroute.h:82
unsigned int cache_generation
Definition mroute.h:125
Main OpenVPN server state structure.
Definition multi.h:163
int n_clients
Definition multi.h:189
struct mroute_addr local
Definition multi.h:184
struct schedule * schedule
Definition multi.h:174
struct mbuf_set * mbuf
Set of buffers for passing data channel packets between VPN tunnel instances.
Definition multi.h:175
struct initial_packet_rate_limit * initial_rate_limiter
Definition multi.h:181
struct deferred_signal_schedule_entry deferred_shutdown_signal
Definition multi.h:219
int max_clients
Definition multi.h:186
struct multi_reap * reaper
Definition multi.h:183
struct multi_io * multi_io
I/O state and events tracker.
Definition multi.h:178
struct hash * hash
VPN tunnel instances indexed by real address of the remote peer.
Definition multi.h:167
struct hash * cid_hash
Definition multi.h:192
unsigned long cid_counter
Definition multi.h:193
struct event_timeout stale_routes_check_et
Definition multi.h:212
int tcp_queue_limit
Definition multi.h:187
struct ifconfig_pool * ifconfig_pool
Definition multi.h:179
struct frequency_limit * new_connection_limiter
Definition multi.h:180
struct context top
Storage structure for process-wide configuration.
Definition multi.h:202
int status_file_version
Definition multi.h:188
struct multi_instance * pending
Definition multi.h:196
struct hash * vhash
VPN tunnel instances indexed by virtual address of remote hosts.
Definition multi.h:169
struct hash * iter
VPN tunnel instances indexed by real address of the remote peer, optimized for iteration.
Definition multi.h:171
struct multi_instance ** instances
Array of multi_instances.
Definition multi.h:164
struct multi_instance ** mpp_touched
Definition multi.h:198
bool enable_c2c
Definition multi.h:185
struct multi_instance * earliest_wakeup
Definition multi.h:197
struct mroute_helper * route_helper
Definition multi.h:182
Server-mode state structure for one single VPN tunnel.
Definition multi.h:103
struct buffer_list * cc_config
Definition multi.h:139
struct client_connect_defer_state client_connect_defer_state
Definition multi.h:146
bool did_cid_hash
Definition multi.h:138
time_t created
Time at which a VPN tunnel instance was created.
Definition multi.h:117
in_addr_t reporting_addr
Definition multi.h:132
char msg_prefix[MULTI_PREFIX_MAX_LENGTH]
Definition multi.h:125
struct mroute_addr real
External network address of the remote peer.
Definition multi.h:122
bool did_iroutes
Definition multi.h:141
ifconfig_pool_handle vaddr_handle
Definition multi.h:124
bool did_real_hash
Definition multi.h:135
struct gc_arena gc
Definition multi.h:113
struct in6_addr reporting_addr_ipv6
Definition multi.h:133
struct timeval wakeup
Definition multi.h:121
struct event_arg ev_arg
this struct will store a pointer to either mi or link_socket, depending on the event type,...
Definition multi.h:108
bool did_iter
Definition multi.h:136
struct context context
The context structure storing state for this VPN tunnel.
Definition multi.h:144
int n_clients_delta
Definition multi.h:142
time_t last_call
Definition multi.h:57
int buckets_per_pass
Definition multi.h:56
int bucket_base
Definition multi.h:55
struct mroute_addr addr
Definition multi.h:238
time_t last_reference
Definition multi.h:246
unsigned int cache_generation
Definition multi.h:245
unsigned int flags
Definition multi.h:243
struct multi_instance * instance
Definition multi.h:239
union openvpn_sockaddr::@20 addr
struct sockaddr_in in4
Definition socket.h:70
struct compress_options comp
Definition options.h:411
int push_ifconfig_ipv6_netbits
Definition options.h:522
int max_routes_per_client
Definition options.h:535
const char * ncp_ciphers_conf
The original ncp_ciphers specified by the user in the configuration.
Definition options.h:576
int status_file_version
Definition options.h:405
in_addr_t push_ifconfig_constraint_network
Definition options.h:517
const char * tmp_dir
Definition options.h:466
unsigned int imported_protocol_flags
Definition options.h:722
int stale_routes_ageing_time
Definition options.h:537
bool duplicate_cn
Definition options.h:526
bool use_peer_id
Definition options.h:700
in_addr_t ifconfig_pool_netmask
Definition options.h:491
int cf_max
Definition options.h:528
const char * dev_type
Definition options.h:317
bool push_ifconfig_defined
Definition options.h:512
bool ifconfig_pool_defined
Definition options.h:488
bool vlan_tagging
Definition options.h:711
in_addr_t ifconfig_pool_end
Definition options.h:490
bool ifconfig_ipv6_pool_defined
Definition options.h:495
const char * client_disconnect_script
Definition options.h:502
int n_bcast_buf
Definition options.h:508
struct connection_entry ce
Definition options.h:288
struct iroute_ipv6 * iroutes_ipv6
Definition options.h:511
in_addr_t push_ifconfig_local_alias
Definition options.h:515
int topology
Definition options.h:320
const char * ncp_ciphers
Definition options.h:577
const char * learn_address_script
Definition options.h:503
const char * ciphername
Definition options.h:572
int cf_initial_max
Definition options.h:531
int stale_routes_check_interval
Definition options.h:536
uint16_t vlan_pvid
Definition options.h:713
int mode
Definition options.h:260
int ifconfig_ipv6_pool_netbits
Definition options.h:497
in_addr_t push_ifconfig_constraint_netmask
Definition options.h:518
bool enable_ncp_fallback
If defined fall back to ciphername if NCP fails.
Definition options.h:573
int real_hash_size
Definition options.h:499
in_addr_t push_ifconfig_local
Definition options.h:513
struct gc_arena gc
Definition options.h:251
bool push_ifconfig_constraint_defined
Definition options.h:516
int cf_initial_per
Definition options.h:532
bool force_key_material_export
Definition options.h:709
struct iroute * iroutes
Definition options.h:510
struct in6_addr push_ifconfig_ipv6_remote
Definition options.h:523
const char * client_connect_script
Definition options.h:501
bool push_ifconfig_ipv6_defined
Definition options.h:520
int tcp_queue_limit
Definition options.h:509
int virtual_hash_size
Definition options.h:500
struct in6_addr push_ifconfig_ipv6_local
Definition options.h:521
int max_clients
Definition options.h:534
bool enable_c2c
Definition options.h:525
int cf_per
Definition options.h:529
in_addr_t ifconfig_pool_start
Definition options.h:489
in_addr_t push_ifconfig_remote_netmask
Definition options.h:514
const char * dev
Definition options.h:316
struct in6_addr ifconfig_ipv6_pool_base
Definition options.h:496
const char * client_config_dir
Definition options.h:505
int ifconfig_ipv6_netbits
Definition options.h:324
struct openvpn_plugin_string_list * list[MAX_PLUGINS]
Definition plugin.h:104
Definition schedule.h:45
const char * signal_text
Definition sig.h:45
volatile int signal_received
Definition sig.h:43
Security parameter state for a single VPN tunnel.
Definition ssl_common.h:597
bool remote_usescomp
remote announced comp-lzo in OCC string
Definition ssl_common.h:676
dco_context_t * dco
Definition ssl_common.h:698
char * peer_info
Definition ssl_common.h:649
char * remote_ciphername
cipher specified in peer's config file
Definition ssl_common.h:675
enum multi_status multi_state
Definition ssl_common.h:618
struct tls_session session[TM_SIZE]
Array of tls_session objects representing control channel sessions with the remote peer.
Definition ssl_common.h:681
struct cert_hash_set * locked_cert_hash_set
Definition ssl_common.h:631
uint32_t peer_id
Definition ssl_common.h:672
bool use_peer_id
Definition ssl_common.h:673
int dco_peer_id
This is the handle that DCO uses to identify this session with the kernel.
Definition ssl_common.h:696
bool data_epoch_supported
whether our underlying data channel supports new data channel features (epoch keys with AEAD tag at t...
Definition ssl_common.h:373
Security parameter state of a single session within a VPN tunnel.
Definition ssl_common.h:480
struct key_state key[KS_SIZE]
Definition ssl_common.h:515
struct tls_options * opt
Definition ssl_common.h:482
in_addr_t local
Definition tun.h:208
struct in6_addr local_ipv6
Definition tun.h:211
dco_context_t dco
Definition tun.h:249
in_addr_t remote_netmask
Definition tun.h:209
struct env_set * es
static int cleanup(void **state)
struct gc_arena gc
Definition test_ssl.c:155
int dev_type_enum(const char *dev, const char *dev_type)
Definition tun.c:467
#define TUNNEL_TOPOLOGY(tt)
Definition tun.h:185
#define TUNNEL_TYPE(tt)
Definition tun.h:182
int16_t vlan_decapsulate(const struct context *c, struct buffer *buf)
Definition vlan.c:82
bool vlan_is_tagged(const struct buffer *buf)
Definition vlan.c:266