ifcfg scripts are deprecated. kexec-tools still set up network based on ifcfg scripts which lead to the issues like [1] [2].
We can get network configuration including dns, bond and znet by parsing nmcli output instead. Another benefit is we could potentially avoid subtle bugs caused by namespace pollution because of sourcing ifcfg scripts.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1919052 [2] https://bugzilla.redhat.com/show_bug.cgi?id=1933679
v1 -> v2: - Use "nmcli --get-values" to extract the value by filed directly [Kairui] - Keep compatibility with network scripts [Kairui] - kdumpctl will exit when failing to set up znet or bond cmdline - Warn the user when network scripts are used
dracut-module-setup.sh | 105 +++++++++++++++++++++++++++++++---------- kdump-lib.sh | 48 +++++++++++++++++++ 2 files changed, 128 insertions(+), 25 deletions(-)
nmcli --get-values <field> connection show /org/freedesktop/NetworkManager/ActiveConnection/1 returns the following value for the corresponding field respectively, Field Value IP4.DNS "10.19.42.41 | 10.11.5.19 | 10.5.30.160" 802-3-ethernet.s390-subchannels "" bond.options "mode=balance-rr"
Signed-off-by: Coiby Xu coxu@redhat.com --- kdump-lib.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/kdump-lib.sh b/kdump-lib.sh index 21271cf..88c0855 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -372,6 +372,26 @@ get_hwaddr() fi }
+ +# Get value by a field using "nmcli -g" +# +# "nmcli --get-values" allows us to retrive value(s) by field, for example, +# nmcli --get-values <field> connection show /org/freedesktop/NetworkManager/ActiveConnection/1 +# returns the following value for the corresponding field respectively, +# Field Value +# IP4.DNS "10.19.42.41 | 10.11.5.19 | 10.5.30.160" +# 802-3-ethernet.s390-subchannels "" +# bond.options "mode=balance-rr" +get_nmcli_value_by_field() +{ + local _nm_show_cmd=$1 + local _field=$2 + + local val=$(LANG=C nmcli --get-values $_field $_nm_show_cmd) + + echo -n "$val" +} + get_ifcfg_by_device() { grep -E -i -l "^[[:space:]]*DEVICE="*${1}"*[[:space:]]*$" \
apath (a D-Bus active connection path) is used for nmcli connection operations, e.g. $ nmcli connection show $apath
Signed-off-by: Coiby Xu coxu@redhat.com --- kdump-lib.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/kdump-lib.sh b/kdump-lib.sh index 88c0855..b05e779 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -392,6 +392,20 @@ get_nmcli_value_by_field() echo -n "$val" }
+# Get nmcli connection apath (a D-Bus active connection path ) by ifname +# +# apath is used for nmcli connection operations, e.g. +# $ nmcli connection show $apath +get_nmcli_connection_apath_by_ifname() +{ + local _ifname=$1 + local _nm_show_cmd="device show $_ifname" + + local _apath=$(get_nmcli_value_by_field "$_nm_show_cmd" "GENERAL.CON-PATH") + + echo -n "$_apath" +} + get_ifcfg_by_device() { grep -E -i -l "^[[:space:]]*DEVICE="*${1}"*[[:space:]]*$" \
Signed-off-by: Coiby Xu coxu@redhat.com --- kdump-lib.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/kdump-lib.sh b/kdump-lib.sh index b05e779..89f354b 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -406,6 +406,20 @@ get_nmcli_connection_apath_by_ifname() echo -n "$_apath" }
+# Get nmcli connection show cmd by ifname +# +# "$_apath" is supposed to not contain any chracter that +# need to be escapded, e.g. space. Otherwise get_nmcli_value_by_field +# would fail. +get_nmcli_connection_show_cmd_by_ifname() +{ + local _ifname="$1" + local _apath=$(get_nmcli_connection_apath_by_ifname "$_ifname") + local _nm_show_cmd="connection show $_apath" + + echo -n "$_nm_show_cmd" +} + get_ifcfg_by_device() { grep -E -i -l "^[[:space:]]*DEVICE="*${1}"*[[:space:]]*$" \
Now kdumpctl will abort when failing to set up znet.
Signed-off-by: Coiby Xu coxu@redhat.com --- dracut-module-setup.sh | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 21143b4..0ea343a 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -318,17 +318,33 @@ kdump_setup_vlan() { }
# setup s390 znet cmdline -# $1: netdev name +# $1: netdev (ifname) +# $2: nmcli connection show output kdump_setup_znet() { + local _netdev="$1" + local _nmcli_cmd="$2" + local s390_prefix="802-3-ethernet.s390-" local _options="" - local _netdev=$1 + local NETTYPE + local SUBCHANNELS + + NETTYPE=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}nettype") + SUBCHANNELS=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}subchannels") + _options=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}options") + + if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then + dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script." + source_ifcfg_file $_netdev + for i in $OPTIONS; do + _options=${_options},$i + done + fi
- source_ifcfg_file $_netdev + if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then + exit 1 + fi
- for i in $OPTIONS; do - _options=${_options},$i - done - echo rd.znet=${NETTYPE},${SUBCHANNELS}${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf + echo rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf }
kdump_get_ip_route() @@ -362,17 +378,22 @@ kdump_get_remote_ip() # initramfs accessing giving destination # $1: destination host kdump_install_net() { - local _destaddr _srcaddr _route _netdev + local _destaddr _srcaddr _route _netdev _nm_show_cmd local _static _proto _ip_conf _ip_opts _ifname_opts
_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") + _nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev") _netmac=$(kdump_get_mac_addr $_netdev)
if [ "$(uname -m)" = "s390x" ]; then - kdump_setup_znet $_netdev + $(kdump_setup_znet "$_netdev" "$_nm_show_cmd") + if [[ $? != 0 ]]; then + derror "Failed to set up znet" + exit 1 + fi fi
_static=$(kdump_static_ip $_netdev $_srcaddr)
Signed-off-by: Coiby Xu coxu@redhat.com --- dracut-module-setup.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 0ea343a..3bd15b7 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -97,15 +97,26 @@ source_ifcfg_file() { fi }
-# $1: netdev name +# $1: nmcli connection show output kdump_setup_dns() { - local _nameserver _dns + local _netdev="$1" + local _nm_show_cmd="$2" + local _nameserver _dns _tmp array local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf
- source_ifcfg_file $1 - - [ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile" - [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile" + _tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS") + 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 content; do @@ -430,7 +441,7 @@ kdump_install_net() { echo "$_ifname_opts" >> $_ip_conf fi
- kdump_setup_dns "$_netdev" + kdump_setup_dns "$_netdev" "$_nm_show_cmd"
if [ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]; then # network-manager module needs this parameter
Now kdumpctl will exit if failing to set up bond cmdline.
Signed-off-by: Coiby Xu coxu@redhat.com --- dracut-module-setup.sh | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 3bd15b7..e81be9b 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -253,7 +253,10 @@ kdump_setup_bridge() { for _dev in `ls /sys/class/net/$_netdev/brif/`; do _kdumpdev=$_dev if kdump_is_bond "$_dev"; then - kdump_setup_bond "$_dev" + $(kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") + if [[ $? != 0 ]]; then + exit 1 + fi elif kdump_is_team "$_dev"; then kdump_setup_team "$_dev" elif kdump_is_vlan "$_dev"; then @@ -268,9 +271,13 @@ kdump_setup_bridge() { echo " bridge=$_netdev:$(echo $_brif | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/41bridge.conf }
+# drauct takes bond=<bondname>[:<bondslaves>:[:<options>]] syntax to parse +# bond. For example: +# bond=bond0:eth0,eth1:mode=balance-rr kdump_setup_bond() { - local _netdev=$1 - local _dev _mac _slaves _kdumpdev + local _netdev="$1" + local _nm_show_cmd="$2" + local _dev _mac _slaves _kdumpdev _bondoptions for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do _mac=$(kdump_get_perm_addr $_dev) _kdumpdev=$(kdump_setup_ifname $_dev) @@ -278,12 +285,21 @@ kdump_setup_bond() { _slaves+="$_kdumpdev," done echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf - # Get bond options specified in ifcfg
- source_ifcfg_file $_netdev + _bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options")
- bondoptions=":$(echo $BONDING_OPTS | xargs echo | tr " " ",")" - echo "$bondoptions" >> ${initdir}/etc/cmdline.d/42bond.conf + if [[ -z "_bondoptions" ]]; then + dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script." + source_ifcfg_file $_netdev + _bondoptions="$(echo $BONDING_OPTS | xargs echo | tr " " ",")" + fi + + if [[ -z "_bondoptions" ]]; then + derror "Get empty bond options" + exit 1 + fi + + echo ":$_bondoptions" >> ${initdir}/etc/cmdline.d/42bond.conf }
kdump_setup_team() { @@ -320,7 +336,10 @@ kdump_setup_vlan() { derror "Vlan over bridge is not supported!" exit 1 elif kdump_is_bond "$_phydev"; then - kdump_setup_bond "$_phydev" + $(kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") + if [[ $? != 0 ]]; then + exit 1 + fi echo " vlan=$(kdump_setup_ifname $_netdev):$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf else _kdumpdev="$(kdump_setup_ifname $_phydev)" @@ -431,7 +450,10 @@ kdump_install_net() { if kdump_is_bridge "$_netdev"; then kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then - kdump_setup_bond "$_netdev" + $(kdump_setup_bond "$_netdev" "$_nm_show_cmd") + if [[ $? != 0 ]]; then + exit 1 + fi elif kdump_is_team "$_netdev"; then kdump_setup_team "$_netdev" elif kdump_is_vlan "$_netdev"; then
Signed-off-by: Coiby Xu coxu@redhat.com --- dracut-module-setup.sh | 1 + 1 file changed, 1 insertion(+)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index e81be9b..54aa5b7 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -89,6 +89,7 @@ kdump_is_vlan() { source_ifcfg_file() { local ifcfg_file
+ dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager." ifcfg_file=$(get_ifcfg_filename $1) if [ -f "${ifcfg_file}" ]; then . ${ifcfg_file}
On Thu, Apr 1, 2021 at 3:38 PM Coiby Xu coxu@redhat.com wrote:
Now kdumpctl will abort when failing to set up znet.
Signed-off-by: Coiby Xu coxu@redhat.com
dracut-module-setup.sh | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 21143b4..0ea343a 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -318,17 +318,33 @@ kdump_setup_vlan() { }
# setup s390 znet cmdline -# $1: netdev name +# $1: netdev (ifname) +# $2: nmcli connection show output kdump_setup_znet() {
- local _netdev="$1"
- local _nmcli_cmd="$2"
- local s390_prefix="802-3-ethernet.s390-" local _options=""
- local _netdev=$1
- local NETTYPE
- local SUBCHANNELS
- NETTYPE=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}nettype")
- SUBCHANNELS=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}subchannels")
- _options=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}options")
- if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script."
source_ifcfg_file $_netdev
for i in $OPTIONS; do
_options=${_options},$i
done
- fi
- source_ifcfg_file $_netdev
- if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
exit 1
- fi
- for i in $OPTIONS; do
_options=${_options},$i
- done
- echo rd.znet=${NETTYPE},${SUBCHANNELS}${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf
- echo rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf
}
kdump_get_ip_route() @@ -362,17 +378,22 @@ kdump_get_remote_ip() # initramfs accessing giving destination # $1: destination host kdump_install_net() {
- local _destaddr _srcaddr _route _netdev
local _destaddr _srcaddr _route _netdev _nm_show_cmd local _static _proto _ip_conf _ip_opts _ifname_opts
_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")
_nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev") _netmac=$(kdump_get_mac_addr $_netdev)
if [ "$(uname -m)" = "s390x" ]; then
kdump_setup_znet $_netdev
$(kdump_setup_znet "$_netdev" "$_nm_show_cmd")
Any reason why we invoke the function via a subshell here?
if [[ $? != 0 ]]; then
derror "Failed to set up znet"
exit 1
fi
fi
_static=$(kdump_static_ip $_netdev $_srcaddr)
-- 2.31.0 _______________________________________________ kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
On Fri, Apr 16, 2021 at 07:24:38PM +0800, Kairui Song wrote:
On Thu, Apr 1, 2021 at 3:38 PM Coiby Xu coxu@redhat.com wrote:
Now kdumpctl will abort when failing to set up znet.
Signed-off-by: Coiby Xu coxu@redhat.com
dracut-module-setup.sh | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 21143b4..0ea343a 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -318,17 +318,33 @@ kdump_setup_vlan() { }
# setup s390 znet cmdline -# $1: netdev name +# $1: netdev (ifname) +# $2: nmcli connection show output kdump_setup_znet() {
- local _netdev="$1"
- local _nmcli_cmd="$2"
- local s390_prefix="802-3-ethernet.s390-" local _options=""
- local _netdev=$1
- local NETTYPE
- local SUBCHANNELS
- NETTYPE=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}nettype")
- SUBCHANNELS=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}subchannels")
- _options=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}options")
- if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script."
source_ifcfg_file $_netdev
for i in $OPTIONS; do
_options=${_options},$i
done
- fi
- source_ifcfg_file $_netdev
- if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
exit 1
- fi
- for i in $OPTIONS; do
_options=${_options},$i
- done
- echo rd.znet=${NETTYPE},${SUBCHANNELS}${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf
- echo rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf
}
kdump_get_ip_route() @@ -362,17 +378,22 @@ kdump_get_remote_ip() # initramfs accessing giving destination # $1: destination host kdump_install_net() {
- local _destaddr _srcaddr _route _netdev
local _destaddr _srcaddr _route _netdev _nm_show_cmd local _static _proto _ip_conf _ip_opts _ifname_opts
_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")
_nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev") _netmac=$(kdump_get_mac_addr $_netdev)
if [ "$(uname -m)" = "s390x" ]; then
kdump_setup_znet $_netdev
$(kdump_setup_znet "$_netdev" "$_nm_show_cmd")
Any reason why we invoke the function via a subshell here?
Calling the function via a subshell makes the function more like a pure function thus no unexpected side effect. So I think it's better.
if [[ $? != 0 ]]; then
derror "Failed to set up znet"
exit 1
fi
fi
_static=$(kdump_static_ip $_netdev $_srcaddr)
-- 2.31.0 _______________________________________________ kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
-- Best Regards, Kairui Song
On Thu, Apr 1, 2021 at 3:38 PM Coiby Xu coxu@redhat.com wrote:
ifcfg scripts are deprecated. kexec-tools still set up network based on ifcfg scripts which lead to the issues like [1] [2].
We can get network configuration including dns, bond and znet by parsing nmcli output instead. Another benefit is we could potentially avoid subtle bugs caused by namespace pollution because of sourcing ifcfg scripts.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1919052 [2] https://bugzilla.redhat.com/show_bug.cgi?id=1933679
v1 -> v2:
- Use "nmcli --get-values" to extract the value by filed directly [Kairui]
- Keep compatibility with network scripts [Kairui]
- kdumpctl will exit when failing to set up znet or bond cmdline
- Warn the user when network scripts are used
dracut-module-setup.sh | 105 +++++++++++++++++++++++++++++++---------- kdump-lib.sh | 48 +++++++++++++++++++ 2 files changed, 128 insertions(+), 25 deletions(-)
-- 2.31.0 _______________________________________________ kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
Looks good to me. Acked-by: Kairui Song kasong@redhat.com