1#- 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2024 Michal Scigocki <michal.os@hotmail.com> 5# 6 7. $(atf_get_srcdir)/syslogd_format_test_common.sh 8 9readonly SERVER_1_PORT="5140" 10readonly SERVER_2_PORT="5141" 11readonly SERVER_3_PORT="5142" 12 13# Relayed messages tests 14# [Host] ---UDP--> [Relay] ---UDP--> [Central] 15setup_relayed_format_test() 16{ 17 local format="$1" 18 local logfile="$2" 19 local pcapfile="$3" 20 21 confirm_INET_support_or_skip 22 23 # Begin packet capture for single packet 24 tcpdump --immediate-mode -c 1 -i lo0 -w "${pcapfile}" dst port \ 25 "${SERVER_1_PORT}" & 26 tcpdump_pid="$!" 27 28 # Start first (central) server: receive UDP, log to file 29 printf "user.debug\t${logfile}\n" \ 30 > "$(config_filename ${SERVER_1_PORT})" 31 syslogd_start_on_port "${SERVER_1_PORT}" -O "${format}" 32 33 # Start second (relay) server: send UDP, log to central server 34 printf "user.debug\t@127.0.0.1:${SERVER_1_PORT}\n" \ 35 > "$(config_filename ${SERVER_2_PORT})" 36 syslogd_start_on_port "${SERVER_2_PORT}" -O "${format}" 37 38 # Start third logging host: send UDP, log to relay server 39 printf "user.debug\t@127.0.0.1:${SERVER_2_PORT}\n" \ 40 > "$(config_filename ${SERVER_3_PORT})" 41 syslogd_start_on_port "${SERVER_3_PORT}" -O "${format}" 42 43 # Send test syslog message 44 syslogd_log -4 -p user.debug -t "${TAG}" -h 127.0.0.1 \ 45 -P "${SERVER_3_PORT}" -H "${HOSTNAME}" "${MSG}" 46 47 wait "${tcpdump_pid}" # Wait for packet capture to finish 48} 49 50atf_test_case "O_flag_bsd_relayed" "cleanup" 51O_flag_bsd_relayed_head() 52{ 53 atf_set descr "bsd format test on a relayed syslog message" 54 set_common_atf_metadata 55} 56O_flag_bsd_relayed_body() 57{ 58 local format="bsd" 59 local logfile="${PWD}/${format}_relayed.log" 60 local pcapfile="${PWD}/${format}_relayed.pcap" 61 62 setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}" 63 64 atf_expect_fail "PR 220246 issue with the legacy bsd format" 65 atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}" 66 atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \ 67 tcpdump -A -r "${pcapfile}" 68} 69O_flag_bsd_relayed_cleanup() 70{ 71 syslogd_stop_on_ports \ 72 "${SERVER_1_PORT}" \ 73 "${SERVER_2_PORT}" \ 74 "${SERVER_3_PORT}" 75} 76 77atf_test_case "O_flag_rfc3164_relayed" "cleanup" 78O_flag_rfc3164_relayed_head() 79{ 80 atf_set descr "rfc3164 format test on a relayed syslog message" 81 set_common_atf_metadata 82} 83O_flag_rfc3164_relayed_body() 84{ 85 local format="rfc3164" 86 local logfile="${PWD}/${format}_relayed.log" 87 local pcapfile="${PWD}/${format}_relayed.pcap" 88 89 setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}" 90 91 atf_expect_fail "PR 220246 issue with the legacy rfc3164 format" 92 atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}" 93 atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \ 94 tcpdump -A -r "${pcapfile}" 95} 96O_flag_rfc3164_relayed_cleanup() 97{ 98 syslogd_stop_on_ports \ 99 "${SERVER_1_PORT}" \ 100 "${SERVER_2_PORT}" \ 101 "${SERVER_3_PORT}" 102} 103 104atf_test_case "O_flag_rfc3164strict_relayed" "cleanup" 105O_flag_rfc3164strict_relayed_head() 106{ 107 atf_set descr "rfc3164-strict format test on a relayed syslog message" 108 set_common_atf_metadata 109} 110O_flag_rfc3164strict_relayed_body() 111{ 112 local format="rfc3164-strict" 113 local logfile="${PWD}/${format}_relayed.log" 114 local pcapfile="${PWD}/${format}_relayed.pcap" 115 116 setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}" 117 118 atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}" 119 atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \ 120 tcpdump -A -r "${pcapfile}" 121} 122O_flag_rfc3164strict_relayed_cleanup() 123{ 124 syslogd_stop_on_ports \ 125 "${SYSLOGD_UDP_PORT_1}" \ 126 "${SYSLOGD_UDP_PORT_2}" \ 127 "${SYSLOGD_UDP_PORT_3}" 128} 129 130atf_test_case "O_flag_syslog_relayed" "cleanup" 131O_flag_syslog_relayed_head() 132{ 133 atf_set descr "syslog format test on a relayed syslog message" 134 set_common_atf_metadata 135} 136O_flag_syslog_relayed_body() 137{ 138 local format="syslog" 139 local logfile="${PWD}/${format}_relayed.log" 140 local pcapfile="${PWD}/${format}_relayed.pcap" 141 142 setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}" 143 144 atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}" 145 atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC5424_PAYLOAD}" \ 146 tcpdump -A -r "${pcapfile}" 147} 148O_flag_syslog_relayed_cleanup() 149{ 150 syslogd_stop_on_ports \ 151 "${SERVER_1_PORT}" \ 152 "${SERVER_2_PORT}" \ 153 "${SERVER_3_PORT}" 154} 155 156atf_test_case "O_flag_rfc5424_relayed" "cleanup" 157O_flag_rfc5424_relayed_head() 158{ 159 atf_set descr "rfc5424 format test on a relayed syslog message" 160 set_common_atf_metadata 161} 162O_flag_rfc5424_relayed_body() 163{ 164 local format="rfc5424" 165 local logfile="${PWD}/${format}_relayed.log" 166 local pcapfile="${PWD}/${format}_relayed.pcap" 167 168 setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}" 169 170 atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}" 171 atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC5424_PAYLOAD}" \ 172 tcpdump -A -r "${pcapfile}" 173} 174O_flag_rfc5424_relayed_cleanup() 175{ 176 syslogd_stop_on_ports \ 177 "${SERVER_1_PORT}" \ 178 "${SERVER_2_PORT}" \ 179 "${SERVER_3_PORT}" 180} 181 182atf_init_test_cases() 183{ 184 atf_add_test_case "O_flag_bsd_relayed" 185 atf_add_test_case "O_flag_rfc3164_relayed" 186 atf_add_test_case "O_flag_rfc3164strict_relayed" 187 atf_add_test_case "O_flag_syslog_relayed" 188 atf_add_test_case "O_flag_rfc5424_relayed" 189} 190