aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d
diff options
context:
space:
mode:
authorDavid Kaspar [Dee'Kej] <dkaspar@redhat.com>2016-10-28 10:59:13 +0200
committerLukáš Nykrýn <lnykryn@redhat.com>2016-11-01 10:14:31 +0100
commit78ebd68cd40a229313ff3130d7dd335e88bb4d44 (patch)
treea186f51105a4830a8790ee2c9dbb7a5789cbcd55 /rc.d
parentb6a3a1dd5d783229a2bb6e42993fe6b09e0583d2 (diff)
downloadinitscripts-78ebd68cd40a229313ff3130d7dd335e88bb4d44.tar
initscripts-78ebd68cd40a229313ff3130d7dd335e88bb4d44.tar.gz
initscripts-78ebd68cd40a229313ff3130d7dd335e88bb4d44.tar.bz2
initscripts-78ebd68cd40a229313ff3130d7dd335e88bb4d44.tar.xz
initscripts-78ebd68cd40a229313ff3130d7dd335e88bb4d44.zip
netconsole: resolve domain name via 'getent' instead of 'hosts'
Diffstat (limited to 'rc.d')
-rw-r--r--rc.d/init.d/netconsole23
1 files changed, 20 insertions, 3 deletions
diff --git a/rc.d/init.d/netconsole b/rc.d/init.d/netconsole
index 1b10af2d..ad51bd22 100644
--- a/rc.d/init.d/netconsole
+++ b/rc.d/init.d/netconsole
@@ -67,9 +67,26 @@ start ()
SYSLOGOPTS=
# syslogd server, if any
if [ -n "$SYSLOGADDR" ]; then
- MATCH="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
- if ! [[ "$SYSLOGADDR" =~ $MATCH ]]; then
- SYSLOGADDR=$(LANG=C host $SYSLOGADDR 2>/dev/null | awk '/has address / { print $NF }')
+ # IPv6 regex also covers 4to6, zero-compressed, and link-local addresses with zone-index addresses.
+ # It should also cover IPv4-embedded, IPv4-mapped, and IPv4-translated IPv6 addresses.
+ # Taken from: http://stackoverflow.com/a/17871737/3481531
+ IPv4_regex="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
+ IPv6_regex="^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$"
+ if ! [[ "$SYSLOGADDR" =~ $IPv4_regex ]] && ! [[ "$SYSLOGADDR" =~ $IPv6_regex ]]; then
+ # Use IPv4 by default:
+ SYSLOGADDR="$(LANG=C getent ahostsv4 $SYSLOGADDR 2> /dev/null)"
+
+ # Try IPv6 in case IPv4 resolution has failed:
+ if [[ $? -eq 2 ]]; then
+ SYSLOGADDR="$(LANG=C getent ahostsv6 $SYSLOGADDR 2> /dev/null)"
+ fi
+
+ if [[ $? -ne 0 ]]; then
+ echo $"Unable to resolve IP address specified in /etc/sysconfig/netconsole" 1>&2
+ exit 6
+ fi
+
+ SYSLOGADDR="$(echo "$SYSLOGADDR" | head -1 | cut --delimiter=' ' --fields=1)"
fi
fi
if [ -z "$SYSLOGADDR" ] ; then