In static route handling, one corner case is ignored. That is 2 machines
are directly connected while IPs configured are in the different subnet.
Say the IP of NIC1 on machine A is 192.168.10.1/24, the IP of NIC2 on
machine B is 192.168.20.1/24. Then on machine A, a route need be specified:
192.168.20.0/24 dev NIC1
On machine B:
192.168.10.0/24 dev NIC2
Without these routes connection from NIC1 to NIC2 can't be setup.
So if in machine A the dump target is set as machine B, route
"192.168.20.0/24 dev NIC1" has to be added in kdump kernel. But this is ignored
in previous handling since we use below patch to find all routes:
/sbin/ip route show | grep -v default | grep "^[[:digit:]].*via.* $_netdev "
Now in this patch use "/sbin/ip route get to $_target" to get the exact route
to the target.
sh> ip route get to 192.168.20.2
192.168.20.2 via 192.168.10.2 dev ens10 src 192.168.10.1
192.168.10.1 -> 192.168.20.2 -> 192.168.20.1 -> 192.168.20.2
or
sh> ip route get to 192.168.20.2
192.168.20.2 dev ens10 src 192.168.10.1
192.168.10.1 -> 192.168.20.2
And write the static route to config file only if static ip address configured
on this network interface.
---
dracut-module-setup.sh | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 8fa59ca..fda50cd 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -75,15 +75,24 @@ kdump_static_ip() {
local _ipaddr=$(ip addr show dev $_netdev permanent | \
awk "/ $_srcaddr\/.* $_netdev\$/{print \$2}")
if [ -n "$_ipaddr" ]; then
- _netmask=$(ipcalc -m $_ipaddr | cut -d'=' -f2)
- _gateway=$(ip route list dev $_netdev | awk '/^default /{print $3}')
- echo -n "${_srcaddr}::${_gateway}:${_netmask}::"
+ _netmask=$(ipcalc -m $_ipaddr | cut -d'=' -f2)
+ _gateway=$(ip route list dev $_netdev | awk '/^default /{print $3}')
+ echo -n "${_srcaddr}::${_gateway}:${_netmask}::"
+
+
+ local _route
+ _route=`/sbin/ip route get to $_target 2>&1`
+ if [ -n "`echo $_route | grep via`" ]
+ then
+ # route going to a different subnet via a router
+ echo $_route | awk '{printf("rd.route=%s:%s:%s\n", $1, $3, $5)}' \
+ >> ${initdir}/etc/cmdline.d/45route-static.conf
+ else
+ # route going to a different subnet though directly connected
+ echo $_route | awk '{printf("rd.route=%s:%s:%s\n", $1, $3)}' \
+ >> ${initdir}/etc/cmdline.d/45route-static.conf
+ fi
fi
-
- /sbin/ip route show | grep -v default | grep "^[[:digit:]].*via.* $_netdev " |\
- while read line; do
- echo $line | awk '{printf("rd.route=%s:%s:%s\n", $1, $3, $5)}'
- done >> ${initdir}/etc/cmdline.d/45route-static.conf
}
kdump_get_mac_addr() {
--
1.9.0