networkmanager: ifupdown: add a setting to disable this feature

The 'ifupdown' script does not allow to disconnect a network interface on
purpose. Once it is down, the script will reconnect it again.

This commit adds a configuration section inside 'NetworkManager.conf' to be able
to manage this behavior. By default, it is disabled.

https://onedigi.atlassian.net/browse/DEL-8342

Signed-off-by: Tatiana Leon <Tatiana.Leon@digi.com>
This commit is contained in:
Tatiana Leon 2023-02-07 14:05:27 +01:00
parent 0f1dfc3823
commit 5eb0f07906
2 changed files with 17 additions and 4 deletions

View File

@ -12,3 +12,6 @@ unmanaged-devices=interface-name:p2p*;interface-name:wlan1
[device]
wifi.scan-rand-mac-address=no
[digi-recovery]
ifdownup=false

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2019, Digi International Inc.
# Copyright 2019-2023, Digi International Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
@ -26,6 +26,16 @@ log() {
fi
}
log info "device-connectivity-change detected on interface ${DEVICE_IP_IFACE}"
nmcli device disconnect "${DEVICE_IP_IFACE}"
nmcli connection up "${CONNECTION_ID}"
# $1 = file, $2 = section, $3 = parameter
get_cfg_param() {
sed -nr "/^\[${2}\]/ { :l /^${3}[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" "${1}" | tr '[:upper:]' '[:lower:]'
}
ifdownup=$(get_cfg_param /etc/NetworkManager/NetworkManager.conf digi-recovery ifdownup)
[ -z "${ifdownup}" ] && ifdownup="false"
if [ "${ifdownup}" = "true" ] || [ "${ifdownup}" = "yes" ]; then
log info "device-connectivity-change detected on interface ${DEVICE_IP_IFACE}"
nmcli device disconnect "${DEVICE_IP_IFACE}"
nmcli connection up "${CONNECTION_ID}"
fi