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