blob: db607a33d0935da0d0b5175b249110002244d7d1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
#-
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2024 Michal Scigocki <michal.os@hotmail.com>
#
. $(atf_get_srcdir)/syslogd_format_test_common.sh
SERVER_1_PORT="5140"
SERVER_2_PORT="5141"
# Forwarded Message Tests
# Two servers, one sending syslog messages to the other over UDP
setup_forwarded_format_test()
{
local format="$1"
local pcapfile="$2"
confirm_INET_support_or_skip
# Begin packet capture for single packet
tcpdump --immediate-mode -c 1 -i lo0 -w "${pcapfile}" \
dst port "${SERVER_1_PORT}" &
tcpdump_pid="$!"
# Start first server: receive UDP, log to file
printf "user.debug\t${SYSLOGD_LOGFILE}\n" > "$(config_filename ${SERVER_1_PORT})"
syslogd_start_on_port "${SERVER_1_PORT}" -O "${format}"
# Start second server: send UDP, log to first server
printf "user.debug\t@127.0.0.1:${SERVER_1_PORT}\n" \
> "$(config_filename ${SERVER_2_PORT})"
syslogd_start_on_port "${SERVER_2_PORT}" -O "${format}"
# Send test syslog message
syslogd_log -4 -p user.debug -t "${TAG}" -h 127.0.0.1 \
-P "${SERVER_2_PORT}" -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 pcapfile="${PWD}/${format}_forwarded.pcap"
setup_forwarded_format_test "${format}" "${pcapfile}"
atf_expect_fail \
"PR 220246 syslog -O bsd deviates from RFC 3164 recommendations"
syslogd_check_log "${REGEX_RFC3164_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 \
"${SERVER_1_PORT}" \
"${SERVER_2_PORT}"
}
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 pcapfile="${PWD}/${format}_forwarded.pcap"
setup_forwarded_format_test "${format}" "${pcapfile}"
atf_expect_fail \
"PR 220246 syslog -O rfc3164 deviates from RFC 3164 recommendations"
syslogd_check_log "${REGEX_RFC3164_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 \
"${SERVER_1_PORT}" \
"${SERVER_2_PORT}"
}
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 pcapfile="${PWD}/${format}_forwarded.pcap"
setup_forwarded_format_test "${format}" "${pcapfile}"
syslogd_check_log "${REGEX_RFC3164_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 pcapfile="${PWD}/${format}_forwarded.pcap"
setup_forwarded_format_test "${format}" "${pcapfile}"
syslogd_check_log "${REGEX_RFC5424_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 \
"${SERVER_1_PORT}" \
"${SERVER_2_PORT}"
}
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 pcapfile="${PWD}/${format}_forwarded.pcap"
setup_forwarded_format_test "${format}" "${pcapfile}"
syslogd_check_log "${REGEX_RFC5424_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 \
"${SERVER_1_PORT}" \
"${SERVER_2_PORT}"
}
# 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 pcapfile="${PWD}/${format}_forwarded.pcap"
setup_forwarded_format_test "${format}" "${pcapfile}"
syslogd_check_log "${REGEX_RFC3164_LEGACY_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 \
"${SERVER_1_PORT}" \
"${SERVER_2_PORT}"
}
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 pcapfile="${PWD}/${format}_forwarded.pcap"
setup_forwarded_format_test "${format}" "${pcapfile}"
syslogd_check_log "${REGEX_RFC3164_LEGACY_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 \
"${SERVER_1_PORT}" \
"${SERVER_2_PORT}"
}
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_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"
}
|