1 /* $NetBSD: proxyudp_test.c,v 1.2 2025/01/26 16:25:50 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #include <inttypes.h> 17 #include <sched.h> /* IWYU pragma: keep */ 18 #include <setjmp.h> 19 #include <signal.h> 20 #include <stdarg.h> 21 #include <stdlib.h> 22 #include <unistd.h> 23 24 /* 25 * As a workaround, include an OpenSSL header file before including cmocka.h, 26 * because OpenSSL 3.1.0 uses __attribute__(malloc), conflicting with a 27 * redefined malloc in cmocka.h. 28 */ 29 #include <openssl/err.h> 30 31 #define UNIT_TESTING 32 #include <cmocka.h> 33 34 #include <isc/async.h> 35 #include <isc/job.h> 36 #include <isc/nonce.h> 37 #include <isc/os.h> 38 #include <isc/quota.h> 39 #include <isc/refcount.h> 40 #include <isc/sockaddr.h> 41 #include <isc/thread.h> 42 #include <isc/util.h> 43 44 #include "uv_wrap.h" 45 #define KEEP_BEFORE 46 47 #include "netmgr/socket.c" 48 #include "netmgr/udp.c" 49 #include "netmgr_common.h" 50 #include "uv.c" 51 52 #include <tests/isc.h> 53 54 static isc_nm_proxyheader_info_t custom_info; 55 56 char complete_proxy_data[] = { 0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x0d, 0x0a, 57 0x51, 0x55, 0x49, 0x54, 0x0a, 0x21, 0x12, 58 0x00, 0x0c, 0x01, 0x02, 0x03, 0x04, 0x04, 59 0x03, 0x02, 0x01, 0x14, 0xe9, 0x14, 0xe9 }; 60 61 ISC_LOOP_TEST_IMPL(proxyudp_noop) { udp_noop(arg); } 62 63 ISC_LOOP_TEST_IMPL(proxyudp_noresponse) { udp_noresponse(arg); } 64 65 ISC_LOOP_TEST_IMPL(proxyudp_timeout_recovery) { udp_timeout_recovery(arg); } 66 67 ISC_LOOP_TEST_IMPL(proxyudp_shutdown_connect) { udp_shutdown_connect(arg); } 68 69 ISC_LOOP_TEST_IMPL(proxyudp_shutdown_read) { udp_shutdown_read(arg); } 70 71 ISC_LOOP_TEST_IMPL(proxyudp_cancel_read) { udp_cancel_read(arg); } 72 73 ISC_LOOP_TEST_IMPL(proxyudp_recv_one) { udp_recv_one(arg); } 74 75 ISC_LOOP_TEST_IMPL(proxyudp_recv_one_prerendered) { 76 isc_region_t header = { 0 }; 77 header.base = (unsigned char *)complete_proxy_data; 78 header.length = sizeof(complete_proxy_data); 79 80 isc_nm_proxyheader_info_init_complete(&custom_info, &header); 81 82 set_proxyheader_info(&custom_info); 83 84 udp_recv_one(arg); 85 } 86 87 ISC_LOOP_TEST_IMPL(proxyudp_recv_two) { udp_recv_two(arg); } 88 89 ISC_LOOP_TEST_IMPL(proxyudp_recv_send) { udp_recv_send(arg); } 90 91 ISC_LOOP_TEST_IMPL(proxyudp_double_read) { udp_double_read(arg); } 92 93 ISC_TEST_LIST_START 94 95 ISC_TEST_ENTRY_CUSTOM(proxyudp_noop, proxyudp_noop_setup, 96 proxyudp_noop_teardown) 97 ISC_TEST_ENTRY_CUSTOM(proxyudp_noresponse, proxyudp_noresponse_setup, 98 proxyudp_noresponse_teardown) 99 ISC_TEST_ENTRY_CUSTOM(proxyudp_timeout_recovery, 100 proxyudp_timeout_recovery_setup, 101 proxyudp_timeout_recovery_teardown) 102 ISC_TEST_ENTRY_CUSTOM(proxyudp_shutdown_read, proxyudp_shutdown_read_setup, 103 proxyudp_shutdown_read_teardown) 104 ISC_TEST_ENTRY_CUSTOM(proxyudp_cancel_read, proxyudp_cancel_read_setup, 105 proxyudp_cancel_read_teardown) 106 ISC_TEST_ENTRY_CUSTOM(proxyudp_shutdown_connect, 107 proxyudp_shutdown_connect_setup, 108 proxyudp_shutdown_connect_teardown) 109 ISC_TEST_ENTRY_CUSTOM(proxyudp_double_read, proxyudp_double_read_setup, 110 proxyudp_double_read_teardown) 111 ISC_TEST_ENTRY_CUSTOM(proxyudp_recv_one, proxyudp_recv_one_setup, 112 proxyudp_recv_one_teardown) 113 ISC_TEST_ENTRY_CUSTOM(proxyudp_recv_one_prerendered, proxyudp_recv_one_setup, 114 proxyudp_recv_one_teardown) 115 ISC_TEST_ENTRY_CUSTOM(proxyudp_recv_two, proxyudp_recv_two_setup, 116 proxyudp_recv_two_teardown) 117 ISC_TEST_ENTRY_CUSTOM(proxyudp_recv_send, proxyudp_recv_send_setup, 118 proxyudp_recv_send_teardown) 119 120 ISC_TEST_LIST_END 121 122 ISC_TEST_MAIN 123