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/* mocks */
16
17void
18throw_signal_soft(const int signum, const char *signal_text)
19{
20 msg(M_WARN, "Offending option received from server");
21}
22
23unsigned int
32
33void
35{
36 return;
37}
38
39void
41{
42 return;
43}
44
45void
46update_vhash(struct multi_context *m, struct multi_instance *mi, const char *new_ip, const char *new_ipv6)
47{
48 return;
49}
50
51bool
53{
54 return true;
55}
56
57/*
58 * Counters to track route accumulation across continuation messages.
59 * Used to verify the bug where update_options_found resets per message.
60 */
61static int route_reset_count = 0;
62static int route_add_count = 0;
63
64static void
70
71bool
72apply_push_options(struct context *c, struct options *options, struct buffer *buf,
73 unsigned int permission_mask, unsigned int *option_types_found,
74 struct env_set *es, bool is_update)
75{
76 char line[OPTION_PARM_SIZE];
77
78 /*
79 * Use persistent push_update_options_found from options struct to track
80 * which option types have been reset across continuation messages.
81 * This is the FIXED behavior - routes are only reset once per PUSH_UPDATE sequence.
82 */
83
84 while (buf_parse(buf, ',', line, sizeof(line)))
85 {
86 unsigned int push_update_option_flags = 0;
87 int i = 0;
88
89 if (is_update || options->pull_filter_list)
90 {
91 /* skip leading spaces matching the behaviour of parse_line */
92 while (isspace(line[i]))
93 {
94 i++;
95 }
96
97 if ((is_update && !check_push_update_option_flags(line, &i, &push_update_option_flags))
99 {
100 if (push_update_option_flags & PUSH_OPT_OPTIONAL)
101 {
102 continue; /* Ignoring this option */
103 }
104 return false; /* Cause push/pull error and stop push processing */
105 }
106 }
107
108 /* Simulate route handling from update_option() in options.c */
109 if (strncmp(&line[i], "route ", 6) == 0)
110 {
112 {
113 /* First route in entire PUSH_UPDATE sequence - reset routes once */
116 }
118 }
119 /* Simulate add_option() push-continuation logic */
120 else if (!strcmp(&line[i], "push-continuation 2"))
121 {
123 }
124 else if (!strcmp(&line[i], "push-continuation 1"))
125 {
127 }
128 }
129 return true;
130}
131
132int
134 bool honor_received_options, unsigned int permission_mask,
135 unsigned int *option_types_found)
136{
137 struct buffer buf = *buffer;
138
139 if (buf_string_compare_advance(&buf, "PUSH_REQUEST"))
140 {
141 return PUSH_MSG_REQUEST;
142 }
144 {
145 return PUSH_MSG_REPLY;
146 }
148 {
149 return process_push_update(c, &c->options, permission_mask, option_types_found, &buf, false);
150 }
151 else
152 {
153 return PUSH_MSG_ERROR;
154 }
155}
156
157const char *
158tls_common_name(const struct tls_multi *multi, const bool null)
159{
160 return NULL;
161}
162
163#ifndef ENABLE_MANAGEMENT
164bool
165send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
166{
167 return true;
168}
169#else /* ifndef ENABLE_MANAGEMENT */
170
171bool
172send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
173{
175 return true;
176}
177
178struct multi_instance *
179lookup_by_cid(struct multi_context *m, const unsigned long cid)
180{
181 return *(m->instances);
182}
183
184bool
186 const struct openvpn_sockaddr *osaddr,
187 bool use_port)
188{
189 return true;
190}
191
192unsigned int
193extract_iv_proto(const char *peer_info)
194{
196}
197#endif /* ifdef ENABLE_MANAGEMENT */
198
199/* tests */
200
201static void
203{
204 struct context *c = *state;
205 struct buffer buf = alloc_buf(256);
206 const char *update_msg =
207 "PUSH_UPDATE,dhcp-option DNS 8.8.8.8, route 0.0.0.0 0.0.0.0 10.10.10.1";
209 unsigned int 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_UPDATEerr,dhcp-option DNS 8.8.8.8";
225 unsigned int 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 ,dhcp-option DNS 8.8.8.8";
241 unsigned int 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 = "PUSH_UPDATE, -?dns, route something, ?dhcp-option DNS 8.8.8.8";
257 unsigned int option_types_found = 0;
258
260 &option_types_found),
262
263 free_buf(&buf);
264}
265
266static void
268{
269 struct context *c = *state;
270 struct buffer buf = alloc_buf(256);
271 const char *update_msg = "PUSH_UPDATE, -dhcp-option, ?-dns";
273 unsigned int option_types_found = 0;
274
276 &option_types_found),
278
279 free_buf(&buf);
280}
281
282static void
284{
285 struct context *c = *state;
286 struct buffer buf = alloc_buf(256);
287 const char *update_msg = "PUSH_UPDATE, dev tun";
289 unsigned int option_types_found = 0;
290
292 &option_types_found),
294
295 free_buf(&buf);
296}
297
298static void
300{
301 struct context *c = *state;
302 struct buffer buf = alloc_buf(256);
303 const char *update_msg =
304 "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";
306 unsigned int option_types_found = 0;
307
309 &option_types_found),
311
312 free_buf(&buf);
313}
314
315static void
317{
318 struct context *c = *state;
319 struct buffer buf = alloc_buf(256);
320 const char *update_msg =
321 "PUSH_UPDATE,-dhcp-option,dhcp-option DNS 8.8.8.8,redirect-gateway local,route 192.168.1.0 255.255.255.0";
323 unsigned int option_types_found = 0;
324
326 &option_types_found),
328
329 free_buf(&buf);
330}
331
343static void
345{
346 struct context *c = *state;
347 unsigned int option_types_found = 0;
348
350
351 /* Message 1: first batch of routes, continuation 2 (more coming) */
352 struct buffer buf1 = alloc_buf(512);
353 const char *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";
355
357 &option_types_found),
359 free_buf(&buf1);
360
361 /* Message 2: more routes, continuation 2 (more coming) */
362 struct buffer buf2 = alloc_buf(512);
363 const char *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";
365
367 &option_types_found),
369 free_buf(&buf2);
370
371 /* Message 3: final batch of routes, continuation 1 (last message) */
372 struct buffer buf3 = alloc_buf(512);
373 const char *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";
375
377 &option_types_found),
379 free_buf(&buf3);
380
381 /* Verify: all 9 routes should have been added */
383
384 /*
385 * Verify: route option is reset only one time in the first message
386 * if a push-continuation is present.
387 */
389}
390
391#ifdef ENABLE_MANAGEMENT
392char *r0[] = {
393 "PUSH_UPDATE,redirect-gateway local,route 192.168.1.0 255.255.255.0",
394 NULL
395};
396char *r1[] = {
397 "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
398 "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway local,push-continuation 2",
399 "PUSH_UPDATE,route 192.168.1.0 255.255.255.0,push-continuation 1",
400 NULL
401};
402char *r3[] = {
403 "PUSH_UPDATE,,,",
404 NULL
405};
406char *r4[] = {
407 "PUSH_UPDATE,-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
408 "PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local,push-continuation 2",
409 "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,,push-continuation 1",
410 NULL
411};
412char *r5[] = {
413 "PUSH_UPDATE,,-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
414 "PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local,push-continuation 2",
415 "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,push-continuation 1",
416 NULL
417};
418char *r6[] = {
419 "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
420 "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8, redirect-gateway 10.10.10.10,,push-continuation 2",
421 "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,,push-continuation 1",
422 NULL
423};
424char *r7[] = {
425 "PUSH_UPDATE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,push-continuation 2",
426 "PUSH_UPDATE,,,,,,,,,,,,,,,,,,,push-continuation 1",
427 NULL
428};
429char *r8[] = {
430 "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
431 "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway\n local,push-continuation 2",
432 "PUSH_UPDATE,route 192.168.1.0 255.255.255.0\n\n\n,push-continuation 1",
433 NULL
434};
435char *r9[] = {
436 "PUSH_UPDATE,,",
437 NULL
438};
439char *r11[] = {
440 "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",
441 "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",
442 "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",
443 "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",
444 "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",
445 NULL
446};
447char *r12[] = {
448 "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",
449 "PUSH_UPDATE,abc,push-continuation 1",
450 NULL
451};
452char *r13[] = {
453 "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,",
454 NULL
455};
456char *r14[] = {
457 "PUSH_UPDATE,a,push-continuation 2",
458 "PUSH_UPDATE,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,push-continuation 2",
459 "PUSH_UPDATE,a,push-continuation 1",
460 NULL
461};
462
463const char *msg0 = "redirect-gateway local,route 192.168.1.0 255.255.255.0";
464const char *msg1 = "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
465 " akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway local,route 192.168.1.0 255.255.255.0";
466const char *msg2 = "";
467const char *msg3 = ",,";
468const char *msg4 = "-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
469 " akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local, route 192.168.1.0 255.255.255.0,";
470const char *msg5 = ",-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
471 " akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local, route 192.168.1.0 255.255.255.0";
472const char *msg6 = "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf, akakakakakakakakakakakaf,"
473 " dhcp-option DNS 8.8.8.8, redirect-gateway 10.10.10.10,, route 192.168.1.0 255.255.255.0,";
474const char *msg7 = ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
475const char *msg8 = "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf, akakakakakakakakakakakaf,"
476 " dhcp-option DNS 8.8.8.8,redirect-gateway\n local,route 192.168.1.0 255.255.255.0\n\n\n";
477const char *msg9 = ",";
478
479const char *msg10 = "abandon ability able about above absent absorb abstract absurd abuse access accident account accuse achieve"
480 "acid acoustic acquire across act action actor actress actual adapt add addict address adjust"
481 "baby bachelor bacon badge bag balance balcony ball bamboo banana banner bar barely bargain barrel base basic"
482 "basket battle beach bean beauty because become beef before begin behave behind"
483 "cabbage cabin cable cactus cage cake call calm camera camp can canal cancel candy cannon canoe canvas canyon"
484 "capable capital captain car carbon card cargo carpet carry cart case"
485 "daisy damage damp dance danger daring dash daughter dawn day deal debate debris decade december decide decline"
486 "decorate decrease deer defense define defy degree delay deliver demand demise denial";
487
488const 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,"
489 "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,"
490 "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,"
491 "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,"
492 "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";
493
494const 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";
495
496const 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,";
497
498const char *msg14 = "a,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,a";
499
500#define PUSH_BUNDLE_SIZE_TEST 184
501
502#define expect_control_channel_strings(res) \
503 do \
504 { \
505 for (int j = 0; res[j] != NULL; j++) \
506 { \
507 expect_string(send_control_channel_string, str, res[j]); \
508 } \
509 } while (0)
510
511static void
513{
514 struct multi_context *m = *state;
515 const unsigned long cid = 0;
517 assert_int_equal(send_push_update(m, &cid, msg0, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
518}
519
520static void
522{
523 struct multi_context *m = *state;
524 const unsigned long cid = 0;
526 assert_int_equal(send_push_update(m, &cid, msg1, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
527}
528
529static void
531{
532 struct multi_context *m = *state;
533 const unsigned long cid = 0;
534 assert_int_equal(send_push_update(m, &cid, msg2, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), -EINVAL);
535}
536
537static void
539{
540 struct multi_context *m = *state;
541 const unsigned long cid = 0;
543 assert_int_equal(send_push_update(m, &cid, msg3, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
544}
545
546static void
548{
549 struct multi_context *m = *state;
550 const unsigned long cid = 0;
552 assert_int_equal(send_push_update(m, &cid, msg4, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
553}
554
555static void
557{
558 struct multi_context *m = *state;
559 const unsigned long cid = 0;
561 assert_int_equal(send_push_update(m, &cid, msg5, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
562}
563
564static void
566{
567 struct multi_context *m = *state;
568 const unsigned long cid = 0;
570 assert_int_equal(send_push_update(m, &cid, msg6, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
571}
572
573static void
575{
576 struct multi_context *m = *state;
577 const unsigned long cid = 0;
579 assert_int_equal(send_push_update(m, &cid, msg7, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
580}
581
582static void
584{
585 struct multi_context *m = *state;
586 const unsigned long cid = 0;
588 assert_int_equal(send_push_update(m, &cid, msg8, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
589}
590
591static void
593{
594 struct multi_context *m = *state;
595 const unsigned long cid = 0;
597 assert_int_equal(send_push_update(m, &cid, msg9, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
598}
599
600static void
602{
603 struct multi_context *m = *state;
604 const unsigned long cid = 0;
605 assert_int_equal(send_push_update(m, &cid, msg10, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), -EINVAL);
606}
607
608static void
610{
611 struct multi_context *m = *state;
612 const unsigned long cid = 0;
614 assert_int_equal(send_push_update(m, &cid, msg11, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
615}
616
617static void
619{
620 struct multi_context *m = *state;
621 const unsigned long cid = 0;
623 assert_int_equal(send_push_update(m, &cid, msg12, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
624}
625
626static void
628{
629 struct multi_context *m = *state;
630 const unsigned long cid = 0;
632 assert_int_equal(send_push_update(m, &cid, msg13, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
633}
634
635static void
637{
638 struct multi_context *m = *state;
639 const unsigned long cid = 0;
641 assert_int_equal(send_push_update(m, &cid, msg14, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
642}
643
644#undef PUSH_BUNDLE_SIZE_TEST
645
646static int
647setup2(void **state)
648{
649 struct multi_context *m = calloc(1, sizeof(struct multi_context));
650 m->instances = calloc(1, sizeof(struct multi_instance *));
651 struct multi_instance *mi = calloc(1, sizeof(struct multi_instance));
652 mi->context.c2.tls_multi = calloc(1, sizeof(struct tls_multi));
653 *(m->instances) = mi;
654 m->top.options.disable_dco = true;
655 *state = m;
656 return 0;
657}
658
659static int
660teardown2(void **state)
661{
662 struct multi_context *m = *state;
663 free((*(m->instances))->context.c2.tls_multi);
664 free(*(m->instances));
665 free(m->instances);
666 free(m);
667 return 0;
668}
669#endif /* ifdef ENABLE_MANAGEMENT */
670
671static int
672setup(void **state)
673{
674 struct context *c = calloc(1, sizeof(struct context));
675 c->options.pull = true;
676 c->options.route_nopull = false;
677 *state = c;
678 return 0;
679}
680
681static int
682teardown(void **state)
683{
684 struct context *c = *state;
685 free(c);
686 return 0;
687}
688
689int
690main(void)
691{
692 const struct CMUnitTest tests[] = {
693 cmocka_unit_test_setup_teardown(test_incoming_push_message_basic, setup, teardown),
694 cmocka_unit_test_setup_teardown(test_incoming_push_message_error1, setup, teardown),
695 cmocka_unit_test_setup_teardown(test_incoming_push_message_error2, setup, teardown),
696 cmocka_unit_test_setup_teardown(test_incoming_push_message_not_updatable_option, setup,
697 teardown),
698 cmocka_unit_test_setup_teardown(test_incoming_push_message_1, setup, teardown),
699 cmocka_unit_test_setup_teardown(test_incoming_push_message_bad_format, setup, teardown),
700 cmocka_unit_test_setup_teardown(test_incoming_push_message_mix, setup, teardown),
701 cmocka_unit_test_setup_teardown(test_incoming_push_message_mix2, setup, teardown),
702 cmocka_unit_test_setup_teardown(test_incoming_push_continuation_route_accumulation, setup,
703 teardown),
704#ifdef ENABLE_MANAGEMENT
705
706 cmocka_unit_test_setup_teardown(test_send_push_msg0, setup2, teardown2),
707 cmocka_unit_test_setup_teardown(test_send_push_msg1, setup2, teardown2),
708 cmocka_unit_test_setup_teardown(test_send_push_msg2, setup2, teardown2),
709 cmocka_unit_test_setup_teardown(test_send_push_msg3, setup2, teardown2),
710 cmocka_unit_test_setup_teardown(test_send_push_msg4, setup2, teardown2),
711 cmocka_unit_test_setup_teardown(test_send_push_msg5, setup2, teardown2),
712 cmocka_unit_test_setup_teardown(test_send_push_msg6, setup2, teardown2),
713 cmocka_unit_test_setup_teardown(test_send_push_msg7, setup2, teardown2),
714 cmocka_unit_test_setup_teardown(test_send_push_msg8, setup2, teardown2),
715 cmocka_unit_test_setup_teardown(test_send_push_msg9, setup2, teardown2),
716 cmocka_unit_test_setup_teardown(test_send_push_msg10, setup2, teardown2),
717 cmocka_unit_test_setup_teardown(test_send_push_msg11, setup2, teardown2),
718 cmocka_unit_test_setup_teardown(test_send_push_msg12, setup2, teardown2),
719 cmocka_unit_test_setup_teardown(test_send_push_msg13, setup2, teardown2),
720 cmocka_unit_test_setup_teardown(test_send_push_msg14, setup2, teardown2)
721#endif
722 };
723
724 return cmocka_run_group_tests(tests, NULL, NULL);
725}
bool buf_string_compare_advance(struct buffer *src, const char *match)
Definition buffer.c:788
void free_buf(struct buffer *buf)
Definition buffer.c:184
struct buffer alloc_buf(size_t size)
Definition buffer.c:63
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)
Definition buffer.c:824
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Definition buffer.h:660
Header file for server-mode related structures and functions.
#define msg(flags,...)
Definition error.h:152
unsigned int msglvl_t
Definition error.h:77
#define M_WARN
Definition error.h:92
#define OPT_P_UP
Definition options.h:732
#define OPT_P_NCP
Negotiable crypto parameters.
Definition options.h:743
#define OPT_P_ECHO
Definition options.h:751
#define OPT_P_EXPLICIT_NOTIFY
Definition options.h:750
#define OPT_P_SHAPER
Definition options.h:737
#define OPT_P_SOCKFLAGS
Definition options.h:757
#define OPT_P_MESSAGES
Definition options.h:742
#define OPT_P_SETENV
Definition options.h:736
#define OPT_P_SOCKBUF
Definition options.h:756
#define OPTION_PARM_SIZE
Definition options.h:56
#define OPT_P_TIMER
Definition options.h:738
#define OPT_P_DHCPDNS
Definition options.h:734
#define OPT_P_PULL_MODE
Definition options.h:754
#define OPT_P_PUSH_MTU
Definition options.h:761
#define OPT_P_PERSIST
Definition options.h:739
#define OPT_P_U_ROUTE
Definition options.h:791
#define OPT_P_COMP
Definition options.h:741
#define OPT_P_ROUTE_EXTRAS
Definition options.h:753
#define OPT_P_PEER_ID
Definition options.h:759
#define OPT_P_ROUTE
Definition options.h:733
bool check_push_update_option_flags(char *line, int *i, unsigned int *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.
@ UPT_BY_CID
Definition push.h:49
#define PUSH_MSG_REQUEST
Definition push.h:29
int process_push_update(struct context *c, struct options *o, unsigned int permission_mask, unsigned int *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
#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
#define IV_PROTO_PUSH_UPDATE
Supports push-update.
Definition ssl.h:117
Wrapper structure for dynamically allocated memory.
Definition buffer.h:60
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:65
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition openvpn.h:323
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:163
struct context top
Storage structure for process-wide configuration.
Definition multi.h:202
struct multi_instance ** instances
Array of multi_instances.
Definition multi.h:164
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:143
bool route_nopull
Definition options.h:436
unsigned int push_update_options_found
Definition options.h:558
int push_continuation
Definition options.h:556
bool disable_dco
Definition options.h:373
bool pull
Definition options.h:555
struct pull_filter_list * pull_filter_list
Definition options.h:716
Security parameter state for a single VPN tunnel.
Definition ssl_common.h:613
struct env_set * es
bool options_postprocess_pull(struct options *options, 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)
void throw_signal_soft(const int signum, const char *signal_text)
Throw a soft global signal.
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
bool apply_push_options(struct context *c, struct options *options, struct buffer *buf, unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es, bool is_update)
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)
static void test_incoming_push_message_1(void **state)
static void test_incoming_push_message_error1(void **state)
static void test_incoming_push_message_mix2(void **state)
static void test_send_push_msg13(void **state)
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.
const char * msg9
void unlearn_ifconfig_ipv6(struct multi_context *m, struct multi_instance *mi)
void unlearn_ifconfig(struct multi_context *m, struct multi_instance *mi)
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
void update_vhash(struct multi_context *m, struct multi_instance *mi, const char *new_ip, const char *new_ipv6)
Update the vhash with new IP/IPv6 addresses in the multi_context when a push-update message containin...
unsigned int pull_permission_mask(const struct context *c)
int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask, unsigned int *option_types_found)
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[]