save exact route to remote target

Previously for solving static route issues, all routes which go
through a specific dev will be saved in 1st kernel, and then added
in 2nd kernel. Because we use below search pattern, an exception
will happen:
/sbin/ip route show | grep -v default | grep "^[[:digit:]].*via.* $_netdev"

That exception is a corner case which happened when 2 machines connected
directly by cable and the 2 network interfaces are configured in
different network subnets. E.g there are 2 machines A and B:

A:ens10 < ------ > B:ens9

A:ens10  inet 192.168.100.111/24 scope global ens10
route need be added in A:
192.168.110.0/24 dev ens10

B:ens9   inet 192.168.110.222/24 scope global ens9
route need be added in B
192.168.100.0/24 dev ens9

Now if A want to dump to B, the route "192.168.110.0/24 dev ens10"
has to be saved and added in 2nd kernel.

So in this patch "ip route get to $target" command is executed, then
an exact route can be got for going to that target. By this, static
route works and the corner case can be fixed too.

Signed-off-by: Baoquan He <bhe@redhat.com>
Acked-by: Marc Milgram <mmilgram@redhat.com>
Acked-by: WANG Chao <chaowang@redhat.com>
This commit is contained in:
Baoquan He 2014-08-18 16:34:53 +08:00 committed by WANG Chao
parent d1483f9b28
commit a68bb200f8
1 changed files with 23 additions and 8 deletions

View File

@ -79,11 +79,6 @@ kdump_static_ip() {
_gateway=$(ip route list dev $_netdev | awk '/^default /{print $3}')
echo -n "${_srcaddr}::${_gateway}:${_netmask}::"
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() {
@ -212,9 +207,27 @@ kdump_setup_znet() {
echo rd.znet=${NETTYPE},${SUBCHANNELS}${_options} > ${initdir}/etc/cmdline.d/30znet.conf
}
get_routes() {
local _netdev="$1" _target="$2"
local _route
_route=`/sbin/ip route get to $_target 2>&1`
if /sbin/ip route get to $_target | 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\n", $1, $3)}' \
>> ${initdir}/etc/cmdline.d/45route-static.conf
fi
}
# Setup dracut to bringup a given network interface
kdump_setup_netdev() {
local _netdev=$1 _srcaddr=$2
local _netdev=$1 _srcaddr=$2 _target=$3
local _static _proto _ip_conf _ip_opts _ifname_opts
if [ "$(uname -m)" = "s390x" ]; then
@ -229,6 +242,8 @@ kdump_setup_netdev() {
_proto=dhcp
fi
get_routes $_netdev $_target
_ip_conf="${initdir}/etc/cmdline.d/40ip.conf"
_ip_opts=" ip=${_static}$(kdump_setup_ifname $_netdev):${_proto}"
@ -284,7 +299,7 @@ kdump_install_net() {
_netdev=`echo $_netdev|awk '{print $3}'|head -n 1`
fi
kdump_setup_netdev "${_netdev}" "${_srcaddr}"
kdump_setup_netdev "${_netdev}" "${_srcaddr}" "${_server}"
#save netdev used for kdump as cmdline
# Whoever calling kdump_install_net() is setting up the default gateway,
@ -442,7 +457,7 @@ kdump_setup_iscsi_device() {
srcaddr=$(echo $netdev | awk '{ print $3; exit }')
netdev=$(echo $netdev | awk '{ print $1; exit }')
kdump_setup_netdev $netdev $srcaddr
kdump_setup_netdev $netdev $srcaddr $tgt_ipaddr
# prepare netroot= command line
# FIXME: IPV6 addresses require explicit [] around $tgt_ipaddr