2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-28 05:12:14 +00:00

fix(xcat-core): a syslog target with a port is bracketed as if it were an IPv6 literal

site.master may carry a port. format_syslog_forward_target in
xCAT/postscripts/syslog bracketed any value containing a colon, so
MASTER=127.0.0.1:1515 rendered the rsyslog line as @[127.0.0.1:1515], which
rsyslog does not accept, and syslog_ng_udp_driver chose udp6 for an IPv4 peer.
format_syslog_server in the dracut_105 rsyslogd-start.sh carries its own copy of
the rule and had the same defect; it runs inside the initramfs and cannot source
the postscript, so the rule is held down twice on purpose.

An IPv4 address or a hostname with a port has exactly one colon and an IPv6
literal has at least two, so the test is now on two colons rather than one. A
value already starting with "[" is left alone whether or not a port follows it,
which the old pattern missed: it required a trailing "]" and so double-bracketed
[2001:db8::1]:514.

ipv6_syslog_forwarding.bats gains four cases. Without the fix, "a target with a
port is not mistaken for an IPv6 literal", "an already-bracketed target with a
port is left alone" and "the initrd launcher does not mistake a port for an IPv6
literal" all fail; the compressed-literal case passes either way and is there to
show the bracketing of ::1 did not regress.

Also: grub2_ipv6.t could not load grub2.pm once xcat-core/#7980 made it use
xCAT::DHCP::BootPolicy, which lives in perl-xCAT. The file died at compile time
and reported no plan at all, which in a prove summary reads as a count
discrepancy rather than a failure. It now puts perl-xCAT and the server perl
directory on @INC, as every other plugin test does.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-23 10:38:37 -03:00
parent 0fb17cab83
commit 2371e2a98e
4 changed files with 67 additions and 6 deletions
@@ -6,10 +6,14 @@
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
# A COLON DOES NOT MEAN IPv6. An IPv4 address or a hostname with a port has one
# colon; an IPv6 literal has at least two. This is a second copy of the rule in
# xCAT/postscripts/syslog, because this script runs inside the dracut initramfs
# and cannot source the postscript.
format_syslog_server() {
case "$1" in
\[*\]) printf '%s\n' "$1" ;;
*:*) printf '[%s]\n' "$1" ;;
\[*) printf '%s\n' "$1" ;;
*:*:*) printf '[%s]\n' "$1" ;;
*) printf '%s\n' "$1" ;;
esac
}
@@ -29,6 +29,31 @@ load_syslog_helpers()
[ "$(format_syslog_forward_target 'mn01')" = 'mn01' ]
}
# A COLON DOES NOT MEAN IPv6. site.master may carry a port -- xcat-core/#7975 sets
# MASTER=127.0.0.1:1515 for its own forwarding case -- and an IPv4 or hostname target with a port
# has exactly one colon, while an IPv6 literal has at least two. Bracketing on any colon rendered
# @[127.0.0.1:1515], which rsyslog does not accept, and sent syslog-ng to udp6 for an IPv4 peer.
@test "a target with a port is not mistaken for an IPv6 literal" {
load_syslog_helpers
[ "$(format_syslog_forward_target '127.0.0.1:1515')" = '127.0.0.1:1515' ]
[ "$(format_syslog_forward_target '192.0.2.10:514')" = '192.0.2.10:514' ]
[ "$(format_syslog_forward_target 'mn01:514')" = 'mn01:514' ]
[ "$(syslog_ng_udp_driver '127.0.0.1:1515')" = 'udp' ]
[ "$(syslog_ng_udp_driver 'mn01:514')" = 'udp' ]
}
@test "a compressed IPv6 literal is still bracketed and still udp6" {
load_syslog_helpers
[ "$(format_syslog_forward_target '::1')" = '[::1]' ]
[ "$(syslog_ng_udp_driver '::1')" = 'udp6' ]
[ "$(syslog_ng_udp_driver '2001:db8::1')" = 'udp6' ]
}
@test "an already-bracketed target with a port is left alone" {
load_syslog_helpers
[ "$(format_syslog_forward_target '[2001:db8::1]:514')" = '[2001:db8::1]:514' ]
}
@test "an already-bracketed target is not bracketed twice" {
load_syslog_helpers
[ "$(format_syslog_forward_target '[2001:db8::1]')" = '[2001:db8::1]' ]
@@ -62,6 +87,29 @@ load_syslog_helpers()
[ "${lines[${#lines[@]}-1]}" = 'kern.* @192.0.2.10' ]
}
# The initrd launcher carries its OWN copy of the rule -- it runs inside the dracut initramfs and
# cannot source the postscript -- so the port case has to be held down twice.
@test "the initrd launcher does not mistake a port for an IPv6 literal" {
local file lib template
file="$(require_repo_file 'xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh')"
lib="${BATS_TEST_TMPDIR}/rsyslogd.sh"
{ extract_shell_function "$file" 'format_syslog_server'
extract_shell_function "$file" 'rsyslog_config'; } >"$lib"
# shellcheck disable=SC1090
. "$lib"
template="${BATS_TEST_TMPDIR}/rsyslog.conf"
printf '# template\n' >"$template"
run rsyslog_config '127.0.0.1:1515' "$template" 'kern.*'
[ "$status" -eq 0 ]
[ "${lines[${#lines[@]}-1]}" = 'kern.* @127.0.0.1:1515' ]
run rsyslog_config '::1' "$template" 'kern.*'
[ "$status" -eq 0 ]
[ "${lines[${#lines[@]}-1]}" = 'kern.* @[::1]' ]
}
@test "the initrd launcher logs locally when no server is given" {
local file lib template
file="$(require_repo_file 'xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh')"
+4
View File
@@ -5,6 +5,10 @@ no warnings 'once';
use Cwd qw(getcwd);
use FindBin;
# grub2.pm loads xCAT::DHCP::BootPolicy, which lives in perl-xCAT. xcat-core/#7980 added that
# use, and without this the require below dies at compile time: the file then reports NO PLAN
# at all, which in a prove summary reads as a count discrepancy rather than a failure.
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use Test::More;
+9 -4
View File
@@ -36,11 +36,15 @@ master=$MASTER
# The legacy rsyslog forwarding syntax treats a colon after the target as the
# port separator. Bracket IPv6 literals so the complete address is passed to
# the resolver, while preserving the existing output for hostnames and IPv4.
# A COLON DOES NOT MEAN IPv6. site.master may carry a port, and an IPv4 address
# or a hostname with one has exactly one colon, while an IPv6 literal has at
# least two. Bracketing on any colon rendered @[127.0.0.1:1515], which rsyslog
# does not accept.
format_syslog_forward_target()
{
case "$1" in
\[*\]) printf '%s\n' "$1" ;;
*:*) printf '[%s]\n' "$1" ;;
\[*) printf '%s\n' "$1" ;;
*:*:*) printf '[%s]\n' "$1" ;;
*) printf '%s\n' "$1" ;;
esac
}
@@ -50,8 +54,9 @@ format_syslog_forward_target()
syslog_ng_udp_driver()
{
case "$1" in
*:*) printf '%s\n' 'udp6' ;;
*) printf '%s\n' 'udp' ;;
\[*:*:*\]*) printf '%s\n' 'udp6' ;;
*:*:*) printf '%s\n' 'udp6' ;;
*) printf '%s\n' 'udp' ;;
esac
}