mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-26 20:12:44 +00:00
Merge 2fd46ebde9
into f2233ac33a
This commit is contained in:
commit
6b7fe0200c
@ -269,14 +269,23 @@ The values
|
||||
.Ar bsd
|
||||
and
|
||||
.Ar rfc3164
|
||||
are used to generate RFC 3164 log messages.
|
||||
are used to generate legacy RFC 3164 log messages.
|
||||
The values
|
||||
.Ar strict
|
||||
and
|
||||
.Ar rfc3164-strict
|
||||
are used to generate log messages using the RFC 3164 recommended format,
|
||||
where messages sent over the network include the hostname,
|
||||
and messages forwarded by a relay exclude the
|
||||
.Dq Forwarded from
|
||||
field.
|
||||
The values
|
||||
.Ar syslog
|
||||
and
|
||||
.Ar rfc5424
|
||||
are used to generate RFC 5424 log messages,
|
||||
having RFC 3339 timestamps with microsecond precision.
|
||||
The default is to generate RFC 3164 log messages.
|
||||
The default is to generate legacy RFC 3164 log messages.
|
||||
.It Fl o
|
||||
Prefix kernel messages with the full kernel boot file as determined by
|
||||
.Xr getbootfile 3 .
|
||||
|
@ -421,6 +421,7 @@ static bool KeepKernFac; /* Keep remotely logged kernel facility */
|
||||
static bool needdofsync = true; /* Are any file(s) waiting to be fsynced? */
|
||||
static struct pidfh *pfh;
|
||||
static bool RFC3164OutputFormat = true; /* Use legacy format by default. */
|
||||
static bool RFC3164OutputFormatStrict = false; /* Use recommended format. */
|
||||
|
||||
struct iovlist;
|
||||
|
||||
@ -730,7 +731,11 @@ main(int argc, char *argv[])
|
||||
else if (strcmp(optarg, "syslog") == 0 ||
|
||||
strcmp(optarg, "rfc5424") == 0)
|
||||
RFC3164OutputFormat = false;
|
||||
else
|
||||
else if (strcmp(optarg, "strict") == 0 ||
|
||||
strcmp(optarg, "rfc3164-strict") == 0) {
|
||||
RFC3164OutputFormat = true;
|
||||
RFC3164OutputFormatStrict = true;
|
||||
} else
|
||||
usage();
|
||||
break;
|
||||
case 'o':
|
||||
@ -2061,7 +2066,10 @@ fprintlog_rfc3164(struct filed *f, const char *hostname, const char *app_name,
|
||||
iovlist_append(&il, priority_number);
|
||||
iovlist_append(&il, ">");
|
||||
iovlist_append(&il, timebuf);
|
||||
if (strcasecmp(hostname, LocalHostName) != 0) {
|
||||
if (RFC3164OutputFormatStrict) {
|
||||
iovlist_append(&il, " ");
|
||||
iovlist_append(&il, hostname);
|
||||
} else if (strcasecmp(hostname, LocalHostName) != 0) {
|
||||
iovlist_append(&il, " Forwarded from ");
|
||||
iovlist_append(&il, hostname);
|
||||
iovlist_append(&il, ":");
|
||||
|
@ -1,5 +1,14 @@
|
||||
ATF_TESTS_SH+= syslogd_test
|
||||
PACKAGE= tests
|
||||
|
||||
ATF_TESTS_SH= syslogd_basic_format_test \
|
||||
syslogd_forwarded_format_test \
|
||||
syslogd_relayed_format_test \
|
||||
syslogd_test
|
||||
|
||||
# Several syslogd listening on the same port prevent parallel operation
|
||||
TEST_METADATA+= is_exclusive="true"
|
||||
|
||||
${PACKAGE}FILES=syslogd_format_test_common.sh \
|
||||
syslogd_test_common.sh
|
||||
|
||||
.include <bsd.test.mk>
|
||||
|
168
usr.sbin/syslogd/tests/syslogd_basic_format_test.sh
Normal file
168
usr.sbin/syslogd/tests/syslogd_basic_format_test.sh
Normal file
@ -0,0 +1,168 @@
|
||||
#-
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# Copyright (c) 2024 Michal Scigocki <michal.os@hotmail.com>
|
||||
#
|
||||
|
||||
. $(atf_get_srcdir)/syslogd_format_test_common.sh
|
||||
|
||||
readonly SERVER_REF="no_port"
|
||||
|
||||
# Basic format tests
|
||||
# Single server, logging to local socket (inet disabled)
|
||||
setup_basic_format_test()
|
||||
{
|
||||
local format="$1"
|
||||
local logfile="$2"
|
||||
|
||||
printf "user.debug\t${logfile}\n" > "$(config_filename ${SERVER_REF})"
|
||||
|
||||
syslogd \
|
||||
-C \
|
||||
-d \
|
||||
-f "$(config_filename ${SERVER_REF})" \
|
||||
-H \
|
||||
-p "$(local_socket_filename ${SERVER_REF})" \
|
||||
-P "$(pid_filename ${SERVER_REF})" \
|
||||
-S "$(local_privsocket_filename ${SERVER_REF})" \
|
||||
-O "${format}" \
|
||||
-N \
|
||||
-ss \
|
||||
&
|
||||
|
||||
wait_for_syslogd_socket_or_fail "$(local_socket_filename ${SERVER_REF})"
|
||||
|
||||
syslogd_log -p user.debug -t "${TAG}" \
|
||||
-h "$(local_socket_filename ${SERVER_REF})" \
|
||||
-H "${HOSTNAME}" "${MSG}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_bsd_basic" "cleanup"
|
||||
O_flag_bsd_basic_head()
|
||||
{
|
||||
atf_set descr "bsd format test on local syslog message"
|
||||
atf_set require.progs "logger"
|
||||
}
|
||||
O_flag_bsd_basic_body()
|
||||
{
|
||||
local format="bsd"
|
||||
local logfile="${PWD}/O_flag_${format}_basic.log"
|
||||
|
||||
setup_basic_format_test "${format}" "${logfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
}
|
||||
O_flag_bsd_basic_cleanup()
|
||||
{
|
||||
syslogd_stop_by_ref "${SERVER_REF}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc3164_basic" "cleanup"
|
||||
O_flag_rfc3164_basic_head()
|
||||
{
|
||||
atf_set descr "rfc3164 format test on local syslog message"
|
||||
atf_set require.progs "logger"
|
||||
}
|
||||
O_flag_rfc3164_basic_body()
|
||||
{
|
||||
local format="rfc3164"
|
||||
local logfile="${PWD}/O_flag_${format}_basic.log"
|
||||
|
||||
setup_basic_format_test "${format}" "${logfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
}
|
||||
O_flag_rfc3164_basic_cleanup()
|
||||
{
|
||||
syslogd_stop_by_ref "${SERVER_REF}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_strict_basic" "cleanup"
|
||||
O_flag_strict_basic_head()
|
||||
{
|
||||
atf_set descr "strict format test on local syslog message"
|
||||
atf_set require.progs "logger"
|
||||
}
|
||||
O_flag_strict_basic_body()
|
||||
{
|
||||
local format="strict"
|
||||
local logfile="${PWD}/O_flag_${format}_basic.log"
|
||||
|
||||
setup_basic_format_test "${format}" "${logfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
}
|
||||
O_flag_strict_basic_cleanup()
|
||||
{
|
||||
syslogd_stop_by_ref "${SERVER_REF}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc3164strict_basic" "cleanup"
|
||||
O_flag_rfc3164strict_basic_head()
|
||||
{
|
||||
atf_set descr "rfc3164-strict format test on local syslog message"
|
||||
atf_set require.progs "logger"
|
||||
}
|
||||
O_flag_rfc3164strict_basic_body()
|
||||
{
|
||||
local format="rfc3164-strict"
|
||||
local logfile="${PWD}/O_flag_${format}_basic.log"
|
||||
|
||||
setup_basic_format_test "${format}" "${logfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
}
|
||||
O_flag_rfc3164strict_basic_cleanup()
|
||||
{
|
||||
syslogd_stop_by_ref "${SERVER_REF}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_syslog_basic" "cleanup"
|
||||
O_flag_syslog_basic_head()
|
||||
{
|
||||
atf_set descr "syslog format test on local syslog message"
|
||||
atf_set require.progs "logger"
|
||||
}
|
||||
O_flag_syslog_basic_body()
|
||||
{
|
||||
local format="syslog"
|
||||
local logfile="${PWD}/O_flag_${format}_basic.log"
|
||||
|
||||
setup_basic_format_test "${format}" "${logfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}"
|
||||
}
|
||||
O_flag_syslog_basic_cleanup()
|
||||
{
|
||||
syslogd_stop_by_ref "${SERVER_REF}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc5424_basic" "cleanup"
|
||||
O_flag_rfc5424_basic_head()
|
||||
{
|
||||
atf_set descr "rfc5424 format test on local syslog message"
|
||||
atf_set require.progs "logger"
|
||||
}
|
||||
O_flag_rfc5424_basic_body()
|
||||
{
|
||||
local format="rfc5424"
|
||||
local logfile="${PWD}/O_flag_${format}_basic.log"
|
||||
|
||||
setup_basic_format_test "${format}" "${logfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}"
|
||||
}
|
||||
O_flag_rfc5424_basic_cleanup()
|
||||
{
|
||||
syslogd_stop_by_ref "${SERVER_REF}"
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case "O_flag_bsd_basic"
|
||||
atf_add_test_case "O_flag_rfc3164_basic"
|
||||
atf_add_test_case "O_flag_strict_basic"
|
||||
atf_add_test_case "O_flag_rfc3164strict_basic"
|
||||
atf_add_test_case "O_flag_syslog_basic"
|
||||
atf_add_test_case "O_flag_rfc5424_basic"
|
||||
}
|
107
usr.sbin/syslogd/tests/syslogd_format_test_common.sh
Normal file
107
usr.sbin/syslogd/tests/syslogd_format_test_common.sh
Normal file
@ -0,0 +1,107 @@
|
||||
#-
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# Copyright (c) 2024 Michal Scigocki <michal.os@hotmail.com>
|
||||
#
|
||||
|
||||
. $(atf_get_srcdir)/syslogd_test_common.sh
|
||||
|
||||
readonly SYSLOGD_UDP_PORT_1="5140"
|
||||
readonly SYSLOGD_UDP_PORT_2="5141"
|
||||
readonly SYSLOGD_UDP_PORT_3="5142"
|
||||
|
||||
# REGEX Components
|
||||
readonly PRI="<15>"
|
||||
readonly VERSION="1"
|
||||
readonly DATE_RFC3164="[A-Z][a-z]{2} [ 1-3][0-9]"
|
||||
readonly TIMESPEC_RFC5424="[:TZ0-9\.\+\-]{20,32}|\-" # Simplified TIMESPEC
|
||||
readonly TIME_RFC3164="([0-9]{2}:){2}[0-9]{2}"
|
||||
readonly HOSTNAME="example.test"
|
||||
readonly TAG="test_tag"
|
||||
readonly MSG="test_log_message"
|
||||
|
||||
# Test REGEX
|
||||
readonly REGEX_RFC3164="${DATE_RFC3164} ${TIME_RFC3164} ${HOSTNAME} ${TAG}: ${MSG}"
|
||||
readonly REGEX_RFC3164_LOGFILE="^${REGEX_RFC3164}$"
|
||||
readonly REGEX_RFC3164_PAYLOAD="${PRI}${REGEX_RFC3164}$"
|
||||
|
||||
readonly REGEX_RFC3164_LEGACY="${DATE_RFC3164} ${TIME_RFC3164} Forwarded from ${HOSTNAME}: ${TAG}: ${MSG}"
|
||||
readonly REGEX_RFC3164_LEGACY_LOGFILE="^${REGEX_RFC3164_LEGACY}$"
|
||||
readonly REGEX_RFC3164_LEGACY_PAYLOAD="${PRI}${REGEX_RFC3164_LEGACY}$"
|
||||
|
||||
readonly REGEX_RFC5424="${PRI}${VERSION} ${TIMESPEC_RFC5424} ${HOSTNAME} ${TAG} - - - ${MSG}"
|
||||
readonly REGEX_RFC5424_LOGFILE="^${REGEX_RFC5424}$"
|
||||
readonly REGEX_RFC5424_PAYLOAD="${REGEX_RFC5424}$"
|
||||
|
||||
# Filename helper functions
|
||||
config_filename()
|
||||
{ local ref="$1"; echo "${PWD}/syslog_${ref}.conf"; }
|
||||
|
||||
local_socket_filename()
|
||||
{ local ref="$1"; echo "${PWD}/log_${ref}.sock"; }
|
||||
|
||||
pid_filename()
|
||||
{ local ref="$1"; echo "${PWD}/syslogd_${ref}.pid"; }
|
||||
|
||||
local_privsocket_filename()
|
||||
{ local ref="$1"; echo "${PWD}/logpriv_${ref}.sock"; }
|
||||
|
||||
confirm_INET_support_or_skip()
|
||||
{
|
||||
if ! sysctl kern.conftxt | grep -qw INET; then
|
||||
atf_skip "Running kernel does not support INET"
|
||||
fi
|
||||
}
|
||||
|
||||
set_common_atf_metadata()
|
||||
{
|
||||
atf_set timeout 5
|
||||
atf_set require.user root
|
||||
atf_set require.progs "logger tcpdump"
|
||||
}
|
||||
|
||||
# Start a private syslogd instance on specified port.
|
||||
syslogd_start_on_port()
|
||||
{
|
||||
local port="$1"
|
||||
shift 1
|
||||
|
||||
syslogd \
|
||||
-b ":${port}" \
|
||||
-C \
|
||||
-d \
|
||||
-f "$(config_filename ${port})" \
|
||||
-H \
|
||||
-p "$(local_socket_filename ${port})" \
|
||||
-P "$(pid_filename ${port})" \
|
||||
-S "$(local_privsocket_filename ${port})" \
|
||||
$@ \
|
||||
&
|
||||
|
||||
# Give syslogd a bit of time to spin up.
|
||||
wait_for_syslogd_socket_or_fail "$(local_socket_filename ${port})"
|
||||
}
|
||||
|
||||
# Stop a private syslogd instance by named referenced.
|
||||
syslogd_stop_by_ref()
|
||||
{
|
||||
local ref="$1"
|
||||
|
||||
pid=$(cat "$(pid_filename ${ref})")
|
||||
if pkill -F "$(pid_filename ${ref})"; then
|
||||
wait "${pid}"
|
||||
rm -f "$(pid_filename ${ref})" \
|
||||
"$(local_socket_filename ${ref})" \
|
||||
"$(local_privsocket_filename ${ref})"
|
||||
fi
|
||||
}
|
||||
|
||||
# Wrapper with better semantic name for networking context
|
||||
syslogd_stop_on_ports()
|
||||
{
|
||||
local ports="$@"
|
||||
|
||||
for port in "${ports}"; do
|
||||
syslogd_stop_by_ref "${port}"
|
||||
done
|
||||
}
|
263
usr.sbin/syslogd/tests/syslogd_forwarded_format_test.sh
Normal file
263
usr.sbin/syslogd/tests/syslogd_forwarded_format_test.sh
Normal file
@ -0,0 +1,263 @@
|
||||
#-
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# Copyright (c) 2024 Michal Scigocki <michal.os@hotmail.com>
|
||||
#
|
||||
|
||||
. $(atf_get_srcdir)/syslogd_format_test_common.sh
|
||||
|
||||
# Forwarded Message Tests
|
||||
# Two servers, one sending syslog messages to the other over UDP
|
||||
setup_forwarded_format_test()
|
||||
{
|
||||
local format="$1"
|
||||
local logfile="$2"
|
||||
local pcapfile="$3"
|
||||
|
||||
confirm_INET_support_or_skip
|
||||
|
||||
# Begin packet capture for single packet
|
||||
tcpdump --immediate-mode -c 1 -i lo0 -w "${pcapfile}" dst port \
|
||||
"${SYSLOGD_UDP_PORT_1}" &
|
||||
tcpdump_pid="$!"
|
||||
|
||||
# Start first server: receive UDP, log to file
|
||||
printf "user.debug\t${logfile}\n" \
|
||||
> "$(config_filename ${SYSLOGD_UDP_PORT_1})"
|
||||
syslogd_start_on_port "${SYSLOGD_UDP_PORT_1}" -O "${format}"
|
||||
|
||||
# Start second server: send UDP, log to first server
|
||||
printf "user.debug\t@127.0.0.1:${SYSLOGD_UDP_PORT_1}\n" \
|
||||
> "$(config_filename ${SYSLOGD_UDP_PORT_2})"
|
||||
syslogd_start_on_port "${SYSLOGD_UDP_PORT_2}" -O "${format}"
|
||||
|
||||
# Send test syslog message
|
||||
syslogd_log -4 -p user.debug -t "${TAG}" -h 127.0.0.1 \
|
||||
-P "${SYSLOGD_UDP_PORT_2}" -H "${HOSTNAME}" "${MSG}"
|
||||
|
||||
wait "${tcpdump_pid}" # Wait for packet capture to finish
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_bsd_forwarded" "cleanup"
|
||||
O_flag_bsd_forwarded_head()
|
||||
{
|
||||
atf_set descr "bsd format test on a forwarded syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_bsd_forwarded_body()
|
||||
{
|
||||
local format="bsd"
|
||||
local logfile="${PWD}/${format}_forwarded.log"
|
||||
local pcapfile="${PWD}/${format}_forwarded.pcap"
|
||||
|
||||
setup_forwarded_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_expect_fail \
|
||||
"PR 220246 syslog -O bsd deviates from RFC 3164 recommendations"
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_bsd_forwarded_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc3164_forwarded" "cleanup"
|
||||
O_flag_rfc3164_forwarded_head()
|
||||
{
|
||||
atf_set descr "rfc3164 format test on a forwarded syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_rfc3164_forwarded_body()
|
||||
{
|
||||
local format="rfc3164"
|
||||
local logfile="${PWD}/${format}_forwarded.log"
|
||||
local pcapfile="${PWD}/${format}_forwarded.pcap"
|
||||
|
||||
setup_forwarded_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_expect_fail \
|
||||
"PR 220246 syslog -O rfc3164 deviates from RFC 3164 recommendations"
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_rfc3164_forwarded_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_strict_forwarded" "cleanup"
|
||||
O_flag_strict_forwarded_head()
|
||||
{
|
||||
atf_set descr "strict format test on a forwarded syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_strict_forwarded_body()
|
||||
{
|
||||
local format="strict"
|
||||
local logfile="${PWD}/${format}_forwarded.log"
|
||||
local pcapfile="${PWD}/${format}_forwarded.pcap"
|
||||
|
||||
setup_forwarded_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_strict_forwarded_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc3164strict_forwarded" "cleanup"
|
||||
O_flag_rfc3164strict_forwarded_head()
|
||||
{
|
||||
atf_set descr "rfc3164-strict format test on a forwarded syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_rfc3164strict_forwarded_body()
|
||||
{
|
||||
local format="rfc3164-strict"
|
||||
local logfile="${PWD}/${format}_forwarded.log"
|
||||
local pcapfile="${PWD}/${format}_forwarded.pcap"
|
||||
|
||||
setup_forwarded_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_rfc3164strict_forwarded_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_syslog_forwarded" "cleanup"
|
||||
O_flag_syslog_forwarded_head()
|
||||
{
|
||||
atf_set descr "syslog format test on a forwarded syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_syslog_forwarded_body()
|
||||
{
|
||||
local format="syslog"
|
||||
local logfile="${PWD}/${format}_forwarded.log"
|
||||
local pcapfile="${PWD}/${format}_forwarded.pcap"
|
||||
|
||||
setup_forwarded_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC5424_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_syslog_forwarded_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc5424_forwarded" "cleanup"
|
||||
O_flag_rfc5424_forwarded_head()
|
||||
{
|
||||
atf_set descr "rfc5424 format test on a forwarded syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_rfc5424_forwarded_body()
|
||||
{
|
||||
local format="rfc5424"
|
||||
local logfile="${PWD}/${format}_forwarded.log"
|
||||
local pcapfile="${PWD}/${format}_forwarded.pcap"
|
||||
|
||||
setup_forwarded_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC5424_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_rfc5424_forwarded_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}"
|
||||
}
|
||||
|
||||
# Legacy bsd/rfc3164 format tests
|
||||
# The legacy syntax was introduced in FreeBSD PR 7055, circa 1998
|
||||
atf_test_case "O_flag_bsd_forwarded_legacy" "cleanup"
|
||||
O_flag_bsd_forwarded_legacy_head()
|
||||
{
|
||||
atf_set descr "legacy bsd format test on a forwarded syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_bsd_forwarded_legacy_body()
|
||||
{
|
||||
local format="bsd"
|
||||
local logfile="${PWD}/${format}_forwarded_legacy.log"
|
||||
local pcapfile="${PWD}/${format}_forwarded.pcap"
|
||||
|
||||
setup_forwarded_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LEGACY_LOGFILE}" \
|
||||
cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore \
|
||||
-o match:"${REGEX_RFC3164_LEGACY_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_bsd_forwarded_legacy_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc3164_forwarded_legacy" "cleanup"
|
||||
O_flag_rfc3164_forwarded_legacy_head()
|
||||
{
|
||||
atf_set descr \
|
||||
"legacy rfc3164 format test on a forwarded syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_rfc3164_forwarded_legacy_body()
|
||||
{
|
||||
local format="rfc3164"
|
||||
local logfile="${PWD}/${format}_forwarded_legacy.log"
|
||||
local pcapfile="${PWD}/${format}_forwarded.pcap"
|
||||
|
||||
setup_forwarded_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LEGACY_LOGFILE}" \
|
||||
cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore \
|
||||
-o match:"${REGEX_RFC3164_LEGACY_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_rfc3164_forwarded_legacy_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}"
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case "O_flag_bsd_forwarded"
|
||||
atf_add_test_case "O_flag_rfc3164_forwarded"
|
||||
atf_add_test_case "O_flag_strict_forwarded"
|
||||
atf_add_test_case "O_flag_rfc3164strict_forwarded"
|
||||
atf_add_test_case "O_flag_syslog_forwarded"
|
||||
atf_add_test_case "O_flag_rfc5424_forwarded"
|
||||
|
||||
atf_add_test_case "O_flag_bsd_forwarded_legacy"
|
||||
atf_add_test_case "O_flag_rfc3164_forwarded_legacy"
|
||||
}
|
212
usr.sbin/syslogd/tests/syslogd_relayed_format_test.sh
Normal file
212
usr.sbin/syslogd/tests/syslogd_relayed_format_test.sh
Normal file
@ -0,0 +1,212 @@
|
||||
#-
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# Copyright (c) 2024 Michal Scigocki <michal.os@hotmail.com>
|
||||
#
|
||||
|
||||
. $(atf_get_srcdir)/syslogd_format_test_common.sh
|
||||
|
||||
# Relayed messages tests
|
||||
# [Host] ---UDP--> [Relay] ---UDP--> [Central]
|
||||
setup_relayed_format_test()
|
||||
{
|
||||
local format="$1"
|
||||
local logfile="$2"
|
||||
local pcapfile="$3"
|
||||
|
||||
confirm_INET_support_or_skip
|
||||
|
||||
# Begin packet capture for single packet
|
||||
tcpdump --immediate-mode -c 1 -i lo0 -w "${pcapfile}" dst port \
|
||||
"${SYSLOGD_UDP_PORT_1}" &
|
||||
tcpdump_pid="$!"
|
||||
|
||||
# Start first (central) server: receive UDP, log to file
|
||||
printf "user.debug\t${logfile}\n" \
|
||||
> "$(config_filename ${SYSLOGD_UDP_PORT_1})"
|
||||
syslogd_start_on_port "${SYSLOGD_UDP_PORT_1}" -O "${format}"
|
||||
|
||||
# Start second (relay) server: send UDP, log to central server
|
||||
printf "user.debug\t@127.0.0.1:${SYSLOGD_UDP_PORT_1}\n" \
|
||||
> "$(config_filename ${SYSLOGD_UDP_PORT_2})"
|
||||
syslogd_start_on_port "${SYSLOGD_UDP_PORT_2}" -O "${format}"
|
||||
|
||||
# Start third logging host: send UDP, log to relay server
|
||||
printf "user.debug\t@127.0.0.1:${SYSLOGD_UDP_PORT_2}\n" \
|
||||
> "$(config_filename ${SYSLOGD_UDP_PORT_3})"
|
||||
syslogd_start_on_port "${SYSLOGD_UDP_PORT_3}" -O "${format}"
|
||||
|
||||
# Send test syslog message
|
||||
syslogd_log -4 -p user.debug -t "${TAG}" -h 127.0.0.1 \
|
||||
-P "${SYSLOGD_UDP_PORT_3}" -H "${HOSTNAME}" "${MSG}"
|
||||
|
||||
wait "${tcpdump_pid}" # Wait for packet capture to finish
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_bsd_relayed" "cleanup"
|
||||
O_flag_bsd_relayed_head()
|
||||
{
|
||||
atf_set descr "bsd format test on a relayed syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_bsd_relayed_body()
|
||||
{
|
||||
local format="bsd"
|
||||
local logfile="${PWD}/${format}_relayed.log"
|
||||
local pcapfile="${PWD}/${format}_relayed.pcap"
|
||||
|
||||
setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_expect_fail "PR 220246 issue with the legacy bsd format"
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_bsd_relayed_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}" \
|
||||
"${SYSLOGD_UDP_PORT_3}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc3164_relayed" "cleanup"
|
||||
O_flag_rfc3164_relayed_head()
|
||||
{
|
||||
atf_set descr "rfc3164 format test on a relayed syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_rfc3164_relayed_body()
|
||||
{
|
||||
local format="rfc3164"
|
||||
local logfile="${PWD}/${format}_relayed.log"
|
||||
local pcapfile="${PWD}/${format}_relayed.pcap"
|
||||
|
||||
setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_expect_fail "PR 220246 issue with the legacy rfc3164 format"
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_rfc3164_relayed_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}" \
|
||||
"${SYSLOGD_UDP_PORT_3}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_strict_relayed" "cleanup"
|
||||
O_flag_strict_relayed_head()
|
||||
{
|
||||
atf_set descr "strict format test on a relayed syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_strict_relayed_body()
|
||||
{
|
||||
local format="strict"
|
||||
local logfile="${PWD}/${format}_relayed.log"
|
||||
local pcapfile="${PWD}/${format}_relayed.pcap"
|
||||
|
||||
setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_strict_relayed_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}" \
|
||||
"${SYSLOGD_UDP_PORT_3}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc3164strict_relayed" "cleanup"
|
||||
O_flag_rfc3164strict_relayed_head()
|
||||
{
|
||||
atf_set descr "rfc3164-strict format test on a relayed syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_rfc3164strict_relayed_body()
|
||||
{
|
||||
local format="rfc3164-strict"
|
||||
local logfile="${PWD}/${format}_relayed.log"
|
||||
local pcapfile="${PWD}/${format}_relayed.pcap"
|
||||
|
||||
setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC3164_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_rfc3164strict_relayed_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}" \
|
||||
"${SYSLOGD_UDP_PORT_3}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_syslog_relayed" "cleanup"
|
||||
O_flag_syslog_relayed_head()
|
||||
{
|
||||
atf_set descr "syslog format test on a relayed syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_syslog_relayed_body()
|
||||
{
|
||||
local format="syslog"
|
||||
local logfile="${PWD}/${format}_relayed.log"
|
||||
local pcapfile="${PWD}/${format}_relayed.pcap"
|
||||
|
||||
setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC5424_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_syslog_relayed_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}" \
|
||||
"${SYSLOGD_UDP_PORT_3}"
|
||||
}
|
||||
|
||||
atf_test_case "O_flag_rfc5424_relayed" "cleanup"
|
||||
O_flag_rfc5424_relayed_head()
|
||||
{
|
||||
atf_set descr "rfc5424 format test on a relayed syslog message"
|
||||
set_common_atf_metadata
|
||||
}
|
||||
O_flag_rfc5424_relayed_body()
|
||||
{
|
||||
local format="rfc5424"
|
||||
local logfile="${PWD}/${format}_relayed.log"
|
||||
local pcapfile="${PWD}/${format}_relayed.pcap"
|
||||
|
||||
setup_relayed_format_test "${format}" "${logfile}" "${pcapfile}"
|
||||
|
||||
atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}"
|
||||
atf_check -s exit:0 -e ignore -o match:"${REGEX_RFC5424_PAYLOAD}" \
|
||||
tcpdump -A -r "${pcapfile}"
|
||||
}
|
||||
O_flag_rfc5424_relayed_cleanup()
|
||||
{
|
||||
syslogd_stop_on_ports \
|
||||
"${SYSLOGD_UDP_PORT_1}" \
|
||||
"${SYSLOGD_UDP_PORT_2}" \
|
||||
"${SYSLOGD_UDP_PORT_3}"
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case "O_flag_bsd_relayed"
|
||||
atf_add_test_case "O_flag_rfc3164_relayed"
|
||||
atf_add_test_case "O_flag_strict_relayed"
|
||||
atf_add_test_case "O_flag_rfc3164strict_relayed"
|
||||
atf_add_test_case "O_flag_syslog_relayed"
|
||||
atf_add_test_case "O_flag_rfc5424_relayed"
|
||||
}
|
@ -13,6 +13,8 @@
|
||||
# Tests to-do:
|
||||
# actions: hostname, users
|
||||
|
||||
. $(atf_get_srcdir)/syslogd_test_common.sh
|
||||
|
||||
readonly SYSLOGD_UDP_PORT="5140"
|
||||
readonly SYSLOGD_CONFIG="${PWD}/syslog.conf"
|
||||
readonly SYSLOGD_LOCAL_SOCKET="${PWD}/log.sock"
|
||||
@ -41,17 +43,7 @@ syslogd_start()
|
||||
&
|
||||
|
||||
# Give syslogd a bit of time to spin up.
|
||||
while [ "$((i+=1))" -le 20 ]; do
|
||||
[ -S "${SYSLOGD_LOCAL_SOCKET}" ] && return
|
||||
sleep 0.1
|
||||
done
|
||||
atf_fail "timed out waiting for syslogd to start"
|
||||
}
|
||||
|
||||
# Simple logger(1) wrapper.
|
||||
syslogd_log()
|
||||
{
|
||||
atf_check -s exit:0 -o empty -e empty logger $*
|
||||
wait_for_syslogd_socket_or_fail "${SYSLOGD_LOCAL_SOCKET}"
|
||||
}
|
||||
|
||||
# Make syslogd reload its configuration file.
|
||||
|
28
usr.sbin/syslogd/tests/syslogd_test_common.sh
Normal file
28
usr.sbin/syslogd/tests/syslogd_test_common.sh
Normal file
@ -0,0 +1,28 @@
|
||||
#-
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# Copyright (c) 2021, 2023 The FreeBSD Foundation
|
||||
#
|
||||
# This software was developed by Mark Johnston under sponsorship from
|
||||
# the FreeBSD Foundation.
|
||||
#
|
||||
# This software was developed by Jake Freeland under sponsorship from
|
||||
# the FreeBSD Foundation.
|
||||
#
|
||||
|
||||
# Simple logger(1) wrapper.
|
||||
syslogd_log()
|
||||
{
|
||||
atf_check -s exit:0 -o empty -e empty logger $*
|
||||
}
|
||||
|
||||
wait_for_syslogd_socket_or_fail()
|
||||
{
|
||||
local socket_filename="$1"
|
||||
|
||||
while [ "$((i+=1))" -le 20 ]; do
|
||||
[ -S "${socket_filename}" ] && return
|
||||
sleep 0.1
|
||||
done
|
||||
atf_fail "timed out waiting for syslogd to start"
|
||||
}
|
Loading…
Reference in New Issue
Block a user