aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d
diff options
context:
space:
mode:
authorDavid Kaspar [Dee'Kej] <dkaspar@redhat.com>2017-03-21 17:10:49 +0100
committerDee'Kej <deekej@linuxmail.org>2017-03-22 14:42:25 +0100
commit1b3e55a2fb9e124eb64f0f3de3e0008b9caccbe5 (patch)
tree9f4d8a0758e47d02e40ba3c8b94f36891191a5e7 /rc.d
parentdfd251ac986ae6490522a6d2110c0ce6022f0a45 (diff)
downloadinitscripts-1b3e55a2fb9e124eb64f0f3de3e0008b9caccbe5.tar
initscripts-1b3e55a2fb9e124eb64f0f3de3e0008b9caccbe5.tar.gz
initscripts-1b3e55a2fb9e124eb64f0f3de3e0008b9caccbe5.tar.bz2
initscripts-1b3e55a2fb9e124eb64f0f3de3e0008b9caccbe5.tar.xz
initscripts-1b3e55a2fb9e124eb64f0f3de3e0008b9caccbe5.zip
9.70-sync: rc.d/init.d/netconsole updated
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