From a0dc92f46cc5a95cb7b13bb7fcfc0a095275fd40 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 12 Nov 2018 20:27:18 +0800 Subject: [PATCH] dracut-module-setup: Fix routing failure on multipath route Currently we still don't support multipath route, when parsing multipath route kdumpctl will wrongly consider 'nexthop' as the destination address, and raise errors in second kernel. When multipath route is in use, ip route output should be like this: $ /sbin/ip route show default via 192.168.122.1 dev ens1 proto dhcp metric 100 192.168.122.0/24 dev ens1 proto kernel scope link src 192.168.122.161 metric 100 192.168.122.8 nexthop via 192.168.122.1 dev ens1 weight 50 nexthop via 192.168.122.2 dev ens1 weight 5 As we don't care about HA/performance, simply use the rule with highest weight and ignore the rest. Signed-off-by: Kairui Song Acked-by: Baoquan He --- dracut-module-setup.sh | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 2f9d762..7499678 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -126,7 +126,8 @@ kdump_static_ip() { echo -n "${_srcaddr}::${_gateway}:${_netmask}::" fi - /sbin/ip $_ipv6_flag route show | grep -v default | grep ".*via.* $_netdev " |\ + /sbin/ip $_ipv6_flag route show | grep -v default |\ + grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\ while read _route; do _target=`echo $_route | cut -d ' ' -f1` _nexthop=`echo $_route | cut -d ' ' -f3` @@ -136,6 +137,44 @@ kdump_static_ip() { fi echo "rd.route=$_target:$_nexthop:$_netdev" done >> ${initdir}/etc/cmdline.d/45route-static.conf + + kdump_handle_mulitpath_route $_netdev $_srcaddr +} + +kdump_handle_mulitpath_route() { + local _netdev="$1" _srcaddr="$2" _ipv6_flag + local _target _nexthop _route _weight _max_weight _rule + + if is_ipv6_address $_srcaddr; then + _ipv6_flag="-6" + fi + + while IFS="" read _route; do + if [[ "$_route" =~ [[:space:]]+nexthop ]]; then + _route=$(echo "$_route" | sed -e 's/^[[:space:]]*//') + # Parse multipath route, using previous _target + [[ "$_target" == 'default' ]] && continue + [[ "$_route" =~ .*via.*\ $_netdev ]] || continue + + _weight=`echo "$_route" | cut -d ' ' -f7` + if [[ "$_weight" -gt "$_max_weight" ]]; then + _nexthop=`echo "$_route" | cut -d ' ' -f3` + _max_weight=$_weight + if [ "x" != "x"$_ipv6_flag ]; then + _rule="rd.route=[$_target]:[$_nexthop]:$_netdev" + else + _rule="rd.route=$_target:$_nexthop:$_netdev" + fi + fi + else + [[ -n "$_rule" ]] && echo "$_rule" + _target=`echo "$_route" | cut -d ' ' -f1` + _rule="" _max_weight=0 _weight=0 + fi + done >> ${initdir}/etc/cmdline.d/45route-static.conf\ + < <(/sbin/ip $_ipv6_flag route show) + + [[ -n $_rule ]] && echo $_rule >> ${initdir}/etc/cmdline.d/45route-static.conf } kdump_get_mac_addr() {