Clean up the related code to build up dracut cmdline parameter such
rd.route, ip and etc. And there is no need to to setup dns when
copying .nmconnection directly to initrd either.
Note the bootdev dracut command line parameter is only used by
dracut's 35network-legacy and network-manager doesn't use it, remove
related code as well.
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
dracut-module-setup.sh | 148 +----------------------------------------
1 file changed, 2 insertions(+), 146 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 3e2eb9f..b72a8e1 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -98,39 +98,6 @@ source_ifcfg_file() {
fi
}
-kdump_setup_dns() {
- local _netdev="$1"
- local _conpath="$2"
- local _nameserver _dns _tmp array
- local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf
-
- _tmp=$(get_nmcli_field_by_conpath "IP4.DNS" "$_conpath")
- # shellcheck disable=SC2206
- array=(${_tmp//|/ })
- if [[ ${array[*]} ]]; then
- for _dns in "${array[@]}"; do
- echo "nameserver=$_dns" >> "$_dnsfile"
- done
- else
- dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg
script"
- source_ifcfg_file "$_netdev"
- [[ -n $DNS1 ]] && echo "nameserver=$DNS1" >
"$_dnsfile"
- [[ -n $DNS2 ]] && echo "nameserver=$DNS2" >>
"$_dnsfile"
- fi
-
- while read -r content; do
- _nameserver=$(echo "$content" | grep ^nameserver)
- [[ -z $_nameserver ]] && continue
-
- _dns=$(echo "$_nameserver" | awk '{print $2}')
- [[ -z $_dns ]] && continue
-
- if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile";
then
- echo "nameserver=$_dns" >> "$_dnsfile"
- fi
- done < "/etc/resolv.conf"
-}
-
# $1: repeat times
# $2: string to be repeated
# $3: separator
@@ -241,89 +208,6 @@ cal_netmask_by_prefix() {
fi
}
-#$1: netdev name
-#$2: srcaddr
-#if it use static ip echo it, or echo null
-kdump_static_ip() {
- local _netdev="$1" _srcaddr="$2" kdumpnic="$3"
_ipv6_flag
- local _netmask _gateway _ipaddr _target _nexthop _prefix
-
- _ipaddr=$(ip addr show dev "$_netdev" permanent | awk "/ $_srcaddr\/.*
/{print \$2}")
-
- if is_ipv6_address "$_srcaddr"; then
- _ipv6_flag="-6"
- fi
-
- if [[ -n $_ipaddr ]]; then
- _gateway=$(ip $_ipv6_flag route list dev "$_netdev" \
- | awk '/^default /{print $3}' | head -n 1)
-
- if [[ "x" != "x"$_ipv6_flag ]]; then
- # _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after
"/"
- _netmask=${_ipaddr#*\/}
- _srcaddr="[$_srcaddr]"
- _gateway="[$_gateway]"
- else
- _prefix=$(cut -d'/' -f2 <<< "$_ipaddr")
- if ! _netmask=$(cal_netmask_by_prefix "$_prefix"
"$_ipv6_flag"); then
- derror "Failed to calculate netmask for $_ipaddr"
- exit 1
- fi
- fi
- echo -n "${_srcaddr}::${_gateway}:${_netmask}::"
- fi
-
- while read -r _route; do
- _target=$(echo "$_route" | awk '{print $1}')
- _nexthop=$(echo "$_route" | awk '{print $3}')
- if [[ "x" != "x"$_ipv6_flag ]]; then
- _target="[$_target]"
- _nexthop="[$_nexthop]"
- fi
- echo "rd.route=$_target:$_nexthop:$kdumpnic"
- done >> "${initdir}/etc/cmdline.d/45route-static.conf" \
- < <(/sbin/ip $_ipv6_flag route show | grep -v default \
- | grep ".*via.* $_netdev " | grep -v
"^[[:space:]]*nexthop")
-
- kdump_handle_mulitpath_route "$_netdev" "$_srcaddr"
"$kdumpnic"
-}
-
-kdump_handle_mulitpath_route() {
- local _netdev="$1" _srcaddr="$2" kdumpnic="$3"
_ipv6_flag
- local _target _nexthop _route _weight _max_weight _rule
-
- if is_ipv6_address "$_srcaddr"; then
- _ipv6_flag="-6"
- fi
-
- while IFS="" read -r _route; do
- if [[ $_route =~ [[:space:]]+nexthop ]]; then
- _route=${_route##[[: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]:$kdumpnic"
- else
- _rule="rd.route=$_target:$_nexthop:$kdumpnic"
- 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() {
cat "/sys/class/net/$1/address"
}
@@ -558,8 +442,7 @@ kdump_get_remote_ip() {
# initramfs accessing giving destination
# $1: destination host
kdump_install_net() {
- local _destaddr _srcaddr _route _netdev _conpath kdumpnic
- local _static _proto _ip_conf _ip_opts
+ local _destaddr _route _netdev kdumpnic
local _znet_netdev _znet_conpath
# each netowrk interface is managed by a NM connection profile
declare -A nmconnection_map
@@ -571,9 +454,7 @@ kdump_install_net() {
_destaddr=$(kdump_get_remote_ip "$1")
_route=$(kdump_get_ip_route "$_destaddr")
- _srcaddr=$(kdump_get_ip_route_field "$_route" "src")
_netdev=$(kdump_get_ip_route_field "$_route" "dev")
- _conpath=$(get_nmcli_connection_apath_by_ifname "$_netdev")
kdumpnic=$(kdump_setup_ifname "$_netdev")
_znet_netdev=$(find_online_znet_device)
@@ -585,27 +466,6 @@ kdump_install_net() {
fi
fi
- _static=$(kdump_static_ip "$_netdev" "$_srcaddr"
"$kdumpnic")
- if [[ -n $_static ]]; then
- _proto=none
- elif is_ipv6_address "$_srcaddr"; then
- _proto=auto6
- else
- _proto=dhcp
- fi
-
- _ip_conf="${initdir}/etc/cmdline.d/40ip.conf"
- _ip_opts=" ip=${_static}$kdumpnic:${_proto}"
-
- # dracut doesn't allow duplicated configuration for same NIC, even they're
exactly the same.
- # so we have to avoid adding duplicates
- # We should also check /proc/cmdline for existing ip=xx arg.
- # For example, iscsi boot will specify ip=xxx arg in cmdline.
- if [[ ! -f $_ip_conf ]] || ! grep -q "$_ip_opts" "$_ip_conf" \
- && ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then
- echo "$_ip_opts" >> "$_ip_conf"
- fi
-
if kdump_is_bridge "$_netdev"; then
kdump_setup_bridge "$_netdev"
elif kdump_is_bond "$_netdev"; then
@@ -617,8 +477,6 @@ kdump_install_net() {
fi
kdump_copy_nmconnection_file "$_netdev"
- kdump_setup_dns "$_netdev" "$_conpath"
-
if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then
# network-manager module needs this parameter
echo "rd.neednet" >>
"${initdir}/etc/cmdline.d/50neednet.conf"
@@ -636,10 +494,8 @@ kdump_install_net() {
# the default gate way for network dump, eth1 in the fence kdump path will
# call kdump_install_net again and we don't want eth1 to be the default
# gateway.
- if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] \
- && [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then
+ if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]]; then
echo "kdumpnic=$kdumpnic" >
"${initdir}/etc/cmdline.d/60kdumpnic.conf"
- echo "bootdev=$kdumpnic" >
"${initdir}/etc/cmdline.d/70bootdev.conf"
fi
}
--
2.37.1