On 08/18/14 at 04:34pm, Baoquan He wrote:
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(a)redhat.com>
I think we can clean up a bit for the part of determing subnet. See
my inline comment below. Because this patch has been sitting in the mail
list for quite long, I'll merge this patch and leave the cleanup part
for Bao or someone else to address later.
Acked-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-module-setup.sh | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 02a0557..9da1a41 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -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
The logic of determining subnet is used twice in dracut-module-setup.sh,
the other instance is in kdump_install_net(). We can extract a function
for both places to use.
Thanks
WANG Chao