dracut/backport-fix-dracut-functions.sh-ip-route-parsing.patch
hongjinghao 9d9fb131b3 backport patchs from upstream
(cherry picked from commit 74c55dc789a3aacb444c42ab40cd308bd213f5e3)
2024-02-22 16:48:54 +08:00

64 lines
1.6 KiB
Diff

From d754e1c6f081a6501cb7fdcb5caaa6c4977235af Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Fri, 21 Jan 2022 21:25:54 +0100
Subject: [PATCH] fix(dracut-functions.sh): ip route parsing
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: ceca74cc ("dracut-functions: add ip_params_for_remote_addr() helper")
Reference:https://github.com/dracutdevs/dracut/commit/d754e1c6f081a6501cb7fdcb5caaa6c4977235af
Conflict:NA
---
dracut-functions.sh | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/dracut-functions.sh b/dracut-functions.sh
index 63b6c892..8503c22f 100755
--- a/dracut-functions.sh
+++ b/dracut-functions.sh
@@ -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() {
--
2.23.0