OpenVPN
test_push_update_msg.c
Go to the documentation of this file.
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <stdlib.h>
6#include <stdarg.h>
7#include <setjmp.h>
8#include <cmocka.h>
9#include "push.h"
10#include "options_util.h"
11#include "multi.h"
12
13#include "push_util.c"
14
15/*
16 * Counters to track route accumulation across continuation messages.
17 * Used to verify the bug where update_options_found resets per message.
18 */
19static int route_reset_count = 0;
20static int route_add_count = 0;
21
22static void
28
29bool
30apply_push_options(struct context *c, struct options *options, struct buffer *buf,
31 uint64_t permission_mask, uint64_t *option_types_found,
32 struct env_set *es, bool is_update)
33{
34 char line[OPTION_PARM_SIZE];
35
36 /*
37 * Use persistent push_update_options_found from options struct to track
38 * which option types have been reset across continuation messages.
39 * This is the FIXED behavior - routes are only reset once per PUSH_UPDATE sequence.
40 */
41
42 while (buf_parse(buf, ',', line, sizeof(line)))
43 {
44 uint64_t push_update_option_flags = 0;
45 int i = 0;
46
47 if (is_update || options->pull_filter_list)
48 {
49 /* skip leading spaces matching the behaviour of parse_line */
50 while (isspace(line[i]))
51 {
52 i++;
53 }
54
55 if ((is_update && !check_push_update_option_flags(line, &i, &push_update_option_flags))
57 {
58 if (push_update_option_flags & PUSH_OPT_OPTIONAL)
59 {
60 continue; /* Ignoring this option */
61 }
62 return false; /* Cause push/pull error and stop push processing */
63 }
64 }
65
66 /* Simulate route handling from update_option() in options.c */
67 if (strncmp(&line[i], "route ", 6) == 0)
68 {
70 {
71 /* First route in entire PUSH_UPDATE sequence - reset routes once */
74 }
76 }
77 /* Simulate add_option() push-continuation logic */
78 else if (!strcmp(&line[i], "push-continuation 2"))
79 {
81 }
82 else if (!strcmp(&line[i], "push-continuation 1"))
83 {
85 }
86 }
87 return true;
88}
89
90int
92 bool honor_received_options, uint64_t permission_mask,
93 uint64_t *option_types_found)
94{
95 struct buffer buf = *buffer;
96
97 if (buf_string_compare_advance(&buf, "PUSH_REQUEST"))
98 {
99 return PUSH_MSG_REQUEST;
100 }
102 {
103 return PUSH_MSG_REPLY;
104 }
106 {
107 return process_push_update(c, &c->options, permission_mask, option_types_found, &buf, false);
108 }
109 else
110 {
111 return PUSH_MSG_ERROR;
112 }
113}
114
115const char *
116tls_common_name(const struct tls_multi *multi, const bool null)
117{
118 return NULL;
119}
120
121#ifndef ENABLE_MANAGEMENT
122bool
123send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
124{
125 return true;
126}
127#else /* ifndef ENABLE_MANAGEMENT */
128
129bool
130send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
131{
133 return true;
134}
135
136struct multi_instance *
137lookup_by_cid(struct multi_context *m, const unsigned long cid)
138{
139 return *(m->instances);
140}
141
142bool
144 const struct openvpn_sockaddr *osaddr,
145 bool use_port)
146{
147 return true;
148}
149#endif /* ifdef ENABLE_MANAGEMENT */
150
151/* tests */
152
153static void
155{
156 struct context *c = *state;
157 struct buffer buf = alloc_buf(256);
158 const char *update_msg =
159 "PUSH_UPDATE,dhcp-option DNS 8.8.8.8, route 0.0.0.0 0.0.0.0 10.10.10.1";
161 uint64_t option_types_found = 0;
162
164 &option_types_found),
166
167 free_buf(&buf);
168}
169
170static void
172{
173 struct context *c = *state;
174 struct buffer buf = alloc_buf(256);
175 const char *update_msg = "PUSH_UPDATEerr,dhcp-option DNS 8.8.8.8";
177 uint64_t option_types_found = 0;
178
180 &option_types_found),
182
183 free_buf(&buf);
184}
185
186static void
188{
189 struct context *c = *state;
190 struct buffer buf = alloc_buf(256);
191 const char *update_msg = "PUSH_UPDATE ,dhcp-option DNS 8.8.8.8";
193 uint64_t option_types_found = 0;
194
196 &option_types_found),
198
199 free_buf(&buf);
200}
201
202static void
204{
205 struct context *c = *state;
206 struct buffer buf = alloc_buf(256);
207 const char *update_msg = "PUSH_UPDATE, -?dns, route something, ?dhcp-option DNS 8.8.8.8";
209 uint64_t option_types_found = 0;
210
212 &option_types_found),
214
215 free_buf(&buf);
216}
217
218static void
220{
221 struct context *c = *state;
222 struct buffer buf = alloc_buf(256);
223 const char *update_msg = "PUSH_UPDATE, -dhcp-option, ?-dns";
225 uint64_t option_types_found = 0;
226
228 &option_types_found),
230
231 free_buf(&buf);
232}
233
234static void
236{
237 struct context *c = *state;
238 struct buffer buf = alloc_buf(256);
239 const char *update_msg = "PUSH_UPDATE, dev tun";
241 uint64_t option_types_found = 0;
242
244 &option_types_found),
246
247 free_buf(&buf);
248}
249
250static void
252{
253 struct context *c = *state;
254 struct buffer buf = alloc_buf(256);
255 const char *update_msg =
256 "PUSH_UPDATE,-dhcp-option, route 10.10.10.0, dhcp-option DNS 1.1.1.1, route 10.11.12.0, dhcp-option DOMAIN corp.local, keepalive 10 60";
258 uint64_t option_types_found = 0;
259
261 &option_types_found),
263
264 free_buf(&buf);
265}
266
267static void
269{
270 struct context *c = *state;
271 struct buffer buf = alloc_buf(256);
272 const char *update_msg =
273 "PUSH_UPDATE,-dhcp-option,dhcp-option DNS 8.8.8.8,redirect-gateway local,route 192.168.1.0 255.255.255.0";
275 uint64_t option_types_found = 0;
276
278 &option_types_found),
280
281 free_buf(&buf);
282}
283
295static void
297{
298 struct context *c = *state;
299 uint64_t option_types_found = 0;
300
302
303 /* Message 1: first batch of routes, continuation 2 (more coming) */
304 struct buffer buf1 = alloc_buf(512);
305 const char *cont_msg1 = "PUSH_UPDATE, route 10.1.0.0 255.255.0.0, route 10.2.0.0 255.255.0.0, route 10.3.0.0 255.255.0.0,push-continuation 2";
307
309 &option_types_found),
311 free_buf(&buf1);
312
313 /* Message 2: more routes, continuation 2 (more coming) */
314 struct buffer buf2 = alloc_buf(512);
315 const char *cont_msg2 = "PUSH_UPDATE, route 10.4.0.0 255.255.0.0, route 10.5.0.0 255.255.0.0, route 10.6.0.0 255.255.0.0,push-continuation 2";
317
319 &option_types_found),
321 free_buf(&buf2);
322
323 /* Message 3: final batch of routes, continuation 1 (last message) */
324 struct buffer buf3 = alloc_buf(512);
325 const char *cont_msg3 = "PUSH_UPDATE, route 10.7.0.0 255.255.0.0, route 10.8.0.0 255.255.0.0, route 10.9.0.0 255.255.0.0,push-continuation 1";
327
329 &option_types_found),
331 free_buf(&buf3);
332
333 /* Verify: all 9 routes should have been added */
335
336 /*
337 * Verify: route option is reset only one time in the first message
338 * if a push-continuation is present.
339 */
341}
342
343#ifdef ENABLE_MANAGEMENT
344char *r0[] = {
345 "PUSH_UPDATE,redirect-gateway local,route 192.168.1.0 255.255.255.0",
346 NULL
347};
348char *r1[] = {
349 "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
350 "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway local,push-continuation 2",
351 "PUSH_UPDATE,route 192.168.1.0 255.255.255.0,push-continuation 1",
352 NULL
353};
354char *r3[] = {
355 "PUSH_UPDATE,,,",
356 NULL
357};
358char *r4[] = {
359 "PUSH_UPDATE,-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
360 "PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local,push-continuation 2",
361 "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,,push-continuation 1",
362 NULL
363};
364char *r5[] = {
365 "PUSH_UPDATE,,-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
366 "PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local,push-continuation 2",
367 "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,push-continuation 1",
368 NULL
369};
370char *r6[] = {
371 "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
372 "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8, redirect-gateway 10.10.10.10,,push-continuation 2",
373 "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,,push-continuation 1",
374 NULL
375};
376char *r7[] = {
377 "PUSH_UPDATE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,push-continuation 2",
378 "PUSH_UPDATE,,,,,,,,,,,,,,,,,,,push-continuation 1",
379 NULL
380};
381char *r8[] = {
382 "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
383 "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway\n local,push-continuation 2",
384 "PUSH_UPDATE,route 192.168.1.0 255.255.255.0\n\n\n,push-continuation 1",
385 NULL
386};
387char *r9[] = {
388 "PUSH_UPDATE,,",
389 NULL
390};
391char *r11[] = {
392 "PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 2",
393 "PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 2",
394 "PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 2",
395 "PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 2",
396 "PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 1",
397 NULL
398};
399char *r12[] = {
400 "PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,push-continuation 2",
401 "PUSH_UPDATE,abc,push-continuation 1",
402 NULL
403};
404char *r13[] = {
405 "PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,",
406 NULL
407};
408char *r14[] = {
409 "PUSH_UPDATE,a,push-continuation 2",
410 "PUSH_UPDATE,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,push-continuation 2",
411 "PUSH_UPDATE,a,push-continuation 1",
412 NULL
413};
414
415const char *msg0 = "redirect-gateway local,route 192.168.1.0 255.255.255.0";
416const char *msg1 = "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
417 " akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway local,route 192.168.1.0 255.255.255.0";
418const char *msg2 = "";
419const char *msg3 = ",,";
420const char *msg4 = "-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
421 " akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local, route 192.168.1.0 255.255.255.0,";
422const char *msg5 = ",-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
423 " akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local, route 192.168.1.0 255.255.255.0";
424const char *msg6 = "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf, akakakakakakakakakakakaf,"
425 " dhcp-option DNS 8.8.8.8, redirect-gateway 10.10.10.10,, route 192.168.1.0 255.255.255.0,";
426const char *msg7 = ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
427const char *msg8 = "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf, akakakakakakakakakakakaf,"
428 " dhcp-option DNS 8.8.8.8,redirect-gateway\n local,route 192.168.1.0 255.255.255.0\n\n\n";
429const char *msg9 = ",";
430
431const char *msg10 = "abandon ability able about above absent absorb abstract absurd abuse access accident account accuse achieve"
432 "acid acoustic acquire across act action actor actress actual adapt add addict address adjust"
433 "baby bachelor bacon badge bag balance balcony ball bamboo banana banner bar barely bargain barrel base basic"
434 "basket battle beach bean beauty because become beef before begin behave behind"
435 "cabbage cabin cable cactus cage cake call calm camera camp can canal cancel candy cannon canoe canvas canyon"
436 "capable capital captain car carbon card cargo carpet carry cart case"
437 "daisy damage damp dance danger daring dash daughter dawn day deal debate debris decade december decide decline"
438 "decorate decrease deer defense define defy degree delay deliver demand demise denial";
439
440const char *msg11 = "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,"
441 "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,"
442 "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,"
443 "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,"
444 "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a";
445
446const char *msg12 = "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,abc";
447
448const char *msg13 = "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,";
449
450const char *msg14 = "a,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,a";
451
452#define PUSH_BUNDLE_SIZE_TEST 184
453
454#define expect_control_channel_strings(res) \
455 do \
456 { \
457 for (int j = 0; res[j] != NULL; j++) \
458 { \
459 expect_string(send_control_channel_string, str, res[j]); \
460 } \
461 } while (0)
462
463static void
465{
466 struct multi_context *m = *state;
467 const unsigned long cid = 0;
469 assert_int_equal(send_push_update(m, &cid, msg0, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
470}
471
472static void
474{
475 struct multi_context *m = *state;
476 const unsigned long cid = 0;
478 assert_int_equal(send_push_update(m, &cid, msg1, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
479}
480
481static void
483{
484 struct multi_context *m = *state;
485 const unsigned long cid = 0;
486 assert_int_equal(send_push_update(m, &cid, msg2, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), -EINVAL);
487}
488
489static void
491{
492 struct multi_context *m = *state;
493 const unsigned long cid = 0;
495 assert_int_equal(send_push_update(m, &cid, msg3, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
496}
497
498static void
500{
501 struct multi_context *m = *state;
502 const unsigned long cid = 0;
504 assert_int_equal(send_push_update(m, &cid, msg4, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
505}
506
507static void
509{
510 struct multi_context *m = *state;
511 const unsigned long cid = 0;
513 assert_int_equal(send_push_update(m, &cid, msg5, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
514}
515
516static void
518{
519 struct multi_context *m = *state;
520 const unsigned long cid = 0;
522 assert_int_equal(send_push_update(m, &cid, msg6, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
523}
524
525static void
527{
528 struct multi_context *m = *state;
529 const unsigned long cid = 0;
531 assert_int_equal(send_push_update(m, &cid, msg7, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
532}
533
534static void
536{
537 struct multi_context *m = *state;
538 const unsigned long cid = 0;
540 assert_int_equal(send_push_update(m, &cid, msg8, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
541}
542
543static void
545{
546 struct multi_context *m = *state;
547 const unsigned long cid = 0;
549 assert_int_equal(send_push_update(m, &cid, msg9, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
550}
551
552static void
554{
555 struct multi_context *m = *state;
556 const unsigned long cid = 0;
557 assert_int_equal(send_push_update(m, &cid, msg10, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), -EINVAL);
558}
559
560static void
562{
563 struct multi_context *m = *state;
564 const unsigned long cid = 0;
566 assert_int_equal(send_push_update(m, &cid, msg11, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
567}
568
569static void
571{
572 struct multi_context *m = *state;
573 const unsigned long cid = 0;
575 assert_int_equal(send_push_update(m, &cid, msg12, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
576}
577
578static void
580{
581 struct multi_context *m = *state;
582 const unsigned long cid = 0;
584 assert_int_equal(send_push_update(m, &cid, msg13, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
585}
586
587static void
589{
590 struct multi_context *m = *state;
591 const unsigned long cid = 0;
593 assert_int_equal(send_push_update(m, &cid, msg14, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
594}
595
596#undef PUSH_BUNDLE_SIZE_TEST
597
598static int
599setup2(void **state)
600{
601 struct multi_context *m = calloc(1, sizeof(struct multi_context));
602 m->instances = calloc(1, sizeof(struct multi_instance *));
603 struct multi_instance *mi = calloc(1, sizeof(struct multi_instance));
604 mi->context.c2.tls_multi = calloc(1, sizeof(struct tls_multi));
605 mi->context.c2.tls_multi->peer_info = "IV_PROTO=4096"; // IV_PROTO_PUSH_UPDATE
606 *(m->instances) = mi;
607 m->top.options.disable_dco = true;
608 *state = m;
609 return 0;
610}
611
612static int
613teardown2(void **state)
614{
615 struct multi_context *m = *state;
616 free((*(m->instances))->context.c2.tls_multi);
617 free(*(m->instances));
618 free(m->instances);
619 free(m);
620 return 0;
621}
622#endif /* ifdef ENABLE_MANAGEMENT */
623
624static int
625setup(void **state)
626{
627 struct context *c = calloc(1, sizeof(struct context));
628 c->options.pull = true;
629 c->options.route_nopull = false;
630 *state = c;
631 return 0;
632}
633
634static int
635teardown(void **state)
636{
637 struct context *c = *state;
638 free(c);
639 return 0;
640}
641
642int
643main(void)
644{
645 const struct CMUnitTest tests[] = {
646 cmocka_unit_test_setup_teardown(test_incoming_push_message_basic, setup, teardown),
647 cmocka_unit_test_setup_teardown(test_incoming_push_message_error1, setup, teardown),
648 cmocka_unit_test_setup_teardown(test_incoming_push_message_error2, setup, teardown),
649 cmocka_unit_test_setup_teardown(test_incoming_push_message_not_updatable_option, setup,
650 teardown),
651 cmocka_unit_test_setup_teardown(test_incoming_push_message_1, setup, teardown),
652 cmocka_unit_test_setup_teardown(test_incoming_push_message_bad_format, setup, teardown),
653 cmocka_unit_test_setup_teardown(test_incoming_push_message_mix, setup, teardown),
654 cmocka_unit_test_setup_teardown(test_incoming_push_message_mix2, setup, teardown),
655 cmocka_unit_test_setup_teardown(test_incoming_push_continuation_route_accumulation, setup,
656 teardown),
657#ifdef ENABLE_MANAGEMENT
658
659 cmocka_unit_test_setup_teardown(test_send_push_msg0, setup2, teardown2),
660 cmocka_unit_test_setup_teardown(test_send_push_msg1, setup2, teardown2),
661 cmocka_unit_test_setup_teardown(test_send_push_msg2, setup2, teardown2),
662 cmocka_unit_test_setup_teardown(test_send_push_msg3, setup2, teardown2),
663 cmocka_unit_test_setup_teardown(test_send_push_msg4, setup2, teardown2),
664 cmocka_unit_test_setup_teardown(test_send_push_msg5, setup2, teardown2),
665 cmocka_unit_test_setup_teardown(test_send_push_msg6, setup2, teardown2),
666 cmocka_unit_test_setup_teardown(test_send_push_msg7, setup2, teardown2),
667 cmocka_unit_test_setup_teardown(test_send_push_msg8, setup2, teardown2),
668 cmocka_unit_test_setup_teardown(test_send_push_msg9, setup2, teardown2),
669 cmocka_unit_test_setup_teardown(test_send_push_msg10, setup2, teardown2),
670 cmocka_unit_test_setup_teardown(test_send_push_msg11, setup2, teardown2),
671 cmocka_unit_test_setup_teardown(test_send_push_msg12, setup2, teardown2),
672 cmocka_unit_test_setup_teardown(test_send_push_msg13, setup2, teardown2),
673 cmocka_unit_test_setup_teardown(test_send_push_msg14, setup2, teardown2)
674#endif
675 };
676
677 return cmocka_run_group_tests(tests, NULL, NULL);
678}
bool buf_string_compare_advance(struct buffer *src, const char *match)
Compare the head of src with match and advance past it if equal.
Definition buffer.c:739
void free_buf(struct buffer *buf)
Free the memory allocated for a buffer.
Definition buffer.c:169
struct buffer alloc_buf(size_t size)
Allocate a buffer of the given size.
Definition buffer.c:60
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)
Extract the next token from a buffer, delimited by a given character.
Definition buffer.c:775
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Append data to a buffer.
Definition buffer.h:1198
uint64_t pull_permission_mask(const struct context *c)
Definition init.c:2512
Header file for server-mode related structures and functions.
unsigned int msglvl_t
Definition error.h:77
#define OPTION_PARM_SIZE
Definition options.h:56
#define OPT_P_U_ROUTE
Definition options.h:791
bool check_push_update_option_flags(char *line, int *i, uint64_t *flags)
Checks the formatting and validity of options inside push-update messages.
bool apply_pull_filter(const struct options *o, char *line)
Filter an option line by all pull filters.
int process_push_update(struct context *c, struct options *o, uint64_t permission_mask, uint64_t *option_types_found, struct buffer *buf, bool msg_sender)
Handles the receiving of a push-update message and applies updates to the specified options.
Definition push_util.c:14
@ UPT_BY_CID
Definition push.h:49
#define PUSH_MSG_REQUEST
Definition push.h:29
#define PUSH_OPT_OPTIONAL
Definition push.h:42
#define PUSH_MSG_ERROR
Definition push.h:28
#define PUSH_MSG_REPLY
Definition push.h:30
#define PUSH_MSG_UPDATE
Definition push.h:35
#define push_update_cmd
Definition push.h:38
#define push_reply_cmd
Definition push.h:37
#define PUSH_MSG_CONTINUATION
Definition push.h:33
static int send_push_update(struct multi_context *m, const void *target, const char *msg, const push_update_type type, const size_t push_bundle_size)
A function to send a PUSH_UPDATE control message from server to client(s).
Definition push_util.c:254
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition openvpn.h:324
Contains all state information for one tunnel.
Definition openvpn.h:471
struct context_2 c2
Level 2 context.
Definition openvpn.h:514
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:472
Main OpenVPN server state structure.
Definition multi.h:162
struct context top
Storage structure for process-wide configuration.
Definition multi.h:201
struct multi_instance ** instances
Array of multi_instances with the size of max_clients.
Definition multi.h:163
Server-mode state structure for one single VPN tunnel.
Definition multi.h:102
struct context context
The context structure storing state for this VPN tunnel.
Definition multi.h:142
bool route_nopull
Definition options.h:437
int push_continuation
Definition options.h:557
bool disable_dco
Definition options.h:374
bool pull
Definition options.h:556
struct pull_filter_list * pull_filter_list
Definition options.h:716
uint64_t push_update_options_found
Definition options.h:559
Security parameter state for a single VPN tunnel.
Definition ssl_common.h:611
char * peer_info
A multi-line string of general-purpose info received from peer over control channel.
Definition ssl_common.h:672
struct env_set * es
const char * msg2
static void test_send_push_msg2(void **state)
bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
const char * msg10
static int teardown(void **state)
char * r13[]
char * r4[]
const char * msg11
const char * msg13
static void test_send_push_msg9(void **state)
static void test_send_push_msg11(void **state)
static void test_send_push_msg4(void **state)
const char * msg1
static void test_send_push_msg1(void **state)
bool mroute_extract_openvpn_sockaddr(struct mroute_addr *addr, const struct openvpn_sockaddr *osaddr, bool use_port)
const char * msg8
static void test_send_push_msg3(void **state)
static void reset_route_counters(void)
char * r9[]
static void test_send_push_msg0(void **state)
const char * msg6
static void test_send_push_msg8(void **state)
struct multi_instance * lookup_by_cid(struct multi_context *m, const unsigned long cid)
static void test_send_push_msg12(void **state)
static int teardown2(void **state)
char * r5[]
const char * msg0
static int route_add_count
static void test_incoming_push_message_bad_format(void **state)
#define expect_control_channel_strings(res)
char * r3[]
static void test_send_push_msg6(void **state)
static void test_send_push_msg7(void **state)
const char * msg4
int main(void)
const char * msg5
char * r14[]
static void test_incoming_push_message_error2(void **state)
static void test_send_push_msg5(void **state)
const char * msg7
static int setup2(void **state)
static void test_incoming_push_continuation_route_accumulation(void **state)
Test that routes accumulate correctly across multiple continuation messages.
static int route_reset_count
static void test_send_push_msg10(void **state)
char * r6[]
static void test_incoming_push_message_mix(void **state)
char * r11[]
static int setup(void **state)
static void test_incoming_push_message_basic(void **state)
int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, uint64_t permission_mask, uint64_t *option_types_found)
static void test_incoming_push_message_1(void **state)
static void test_incoming_push_message_error1(void **state)
bool apply_push_options(struct context *c, struct options *options, struct buffer *buf, uint64_t permission_mask, uint64_t *option_types_found, struct env_set *es, bool is_update)
static void test_incoming_push_message_mix2(void **state)
static void test_send_push_msg13(void **state)
const char * msg9
static void test_incoming_push_message_not_updatable_option(void **state)
#define PUSH_BUNDLE_SIZE_TEST
static void test_send_push_msg14(void **state)
const char * msg14
char * r8[]
const char * tls_common_name(const struct tls_multi *multi, const bool null)
Returns the common name field for the given tunnel.
char * r1[]
char * r0[]
char * r7[]
const char * msg3
const char * msg12
char * r12[]