Skip to content

Commit

Permalink
fix(dracut-functions.sh): ip route parsing
Browse files Browse the repository at this point in the history
The code for determining local interface and address works
only for peers that are reachable in a single hop.

This is parsed correctly:
192.168.110.1 dev br0 src 192.168.110.160 uid 0 \    cache

But this isn't:
192.168.1.4 via 192.168.110.1 dev br0 src 192.168.110.160 uid 0 \    cache

Fix it.

Fixes: ceca74c ("dracut-functions: add ip_params_for_remote_addr() helper")
  • Loading branch information
mwilck authored and johannbg committed Feb 4, 2022
1 parent 9371dca commit d754e1c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions dracut-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,29 @@ btrfs_devs() {
iface_for_remote_addr() {
# shellcheck disable=SC2046
set -- $(ip -o route get to "$1")
echo "$3"
while [ $# -gt 0 ]; do
case $1 in
dev)
echo "$2"
return
;;
esac
shift
done
}
local_addr_for_remote_addr() {
# shellcheck disable=SC2046
set -- $(ip -o route get to "$1")
echo "$5"
while [ $# -gt 0 ]; do
case $1 in
src)
echo "$2"
return
;;
esac
shift
done
}
peer_for_addr() {
Expand Down

0 comments on commit d754e1c

Please sign in to comment.