Instroduce lib function get_remote_host to be used to strip the
characters around the ip address or hostname.
Instroduce lib function is_hostname to identify the specified string is
ip address(ipv4/ipv6) or hostname. If the specified string is hostname,
we can use command "getent hosts" to parse it and get the ip
address(ipv4/ipv6).
In order to setup the network in 2nd kernel, we need the network device
and target ip address. we use the command "ip route" to get the route
info.
Signed-off-by: Minfei Huang <mhuang(a)redhat.com>
---
dracut-module-setup.sh | 22 ++++++----------------
kdump-lib.sh | 28 ++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 75737fd..f47e57e 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -300,28 +300,18 @@ kdump_setup_netdev() {
#$1: config values of net line in kdump.conf
#$2: srcaddr of network device
kdump_install_net() {
- local _server _netdev _srcaddr
+ local _server _netdev _srcaddr _route
local config_val="$1"
- _server=`echo $config_val | sed 's/.*@//' | cut -d':' -f1`
+ _server=$(get_remote_host $config_val)
- _need_dns=`echo $_server|grep "[a-zA-Z]"`
- [ -n "$_need_dns" ] && _server=`getent hosts $_server|cut -d'
' -f1`
+ is_hostname $_server && _server=`getent hosts $_server | head -n 1 | cut
-d' ' -f1`
- _netdev=`/sbin/ip route get to $_server 2>&1`
+ _route=`/sbin/ip -o route get to $_server 2>&1`
[ $? != 0 ] && echo "Bad kdump location: $config_val" &&
exit 1
- #the field in the ip output changes if we go to another subnet
- if [ -n "`echo $_netdev | grep via`" ]
- then
- # we are going to a different subnet
- _srcaddr=`echo $_netdev|awk '{print $7}'|head -n 1`
- _netdev=`echo $_netdev|awk '{print $5;}'|head -n 1`
- else
- # we are on the same subnet
- _srcaddr=`echo $_netdev|awk '{print $5}'|head -n 1`
- _netdev=`echo $_netdev|awk '{print $3}'|head -n 1`
- fi
+ _srcaddr=$(get_ip_route_field "$_route" "src")
+ _netdev=$(get_ip_route_field "$_route" "dev")
kdump_setup_netdev "${_netdev}" "${_srcaddr}"
"${_server}"
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 1b98a6f..b83516b 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -206,3 +206,31 @@ is_ipv6_address()
{
echo $1 | grep -q ":"
}
+
+# get ip address or hostname from nfs/ssh config value
+get_remote_host()
+{
+ local _config_val=$1
+
+ # in ipv6, the _config_val format is [xxxx:xxxx::xxxx%eth0]:/mnt/nfs or
+ # username at xxxx:xxxx::xxxx%eth0. what we need is just xxxx:xxxx::xxxx
+ _config_val=${_config_val#*@}
+ _config_val=${_config_val%:/*}
+ _config_val=${_config_val#[}
+ _config_val=${_config_val%]}
+ _config_val=${_config_val%\%*}
+ echo $_config_val
+}
+
+# if the passed parameter is hostname/domain, it will be satisfied with
+# condition which it is without colon ":", and contains the [a-zA-Z]
+# $1: hostname/ip address
+is_hostname()
+{
+ local _hostname=`echo $1 | grep ":"`
+
+ if [ -n "$_hostname" ]; then
+ return 1
+ fi
+ echo $1 | grep -q "[a-zA-Z]"
+}
--
2.1.0