From 7f6964b636fb980e83c7b84c1b46c319d4dca780 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Tue, 16 Feb 2010 13:53:15 -0500 Subject: Add get_config_by_device, adjust caller. --- sysconfig/network-scripts/network-functions | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index 89baeb45..bef3606c 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -20,6 +20,13 @@ get_hwaddr () fi } +get_config_by_device () +{ + LANG=C grep -l "^[[:space:]]*DEVICE=${1}\([[:space:]#]\|$\)" \ + /etc/sysconfig/network-scripts/ifcfg-* \ + | LC_ALL=C sed -e "$__sed_discard_ignored_files" +} + get_config_by_hwaddr () { LANG=C grep -il "^[[:space:]]*HWADDR=${1}\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-* \ @@ -34,6 +41,7 @@ get_config_by_subchannel () | LC_ALL=C sed -e "$__sed_discard_ignored_files" } + get_device_by_hwaddr () { LANG=C ip -o link | grep -v link/ieee802.11 | awk -F ': ' -vIGNORECASE=1 "/$1/ { print \$2 }" @@ -55,9 +63,7 @@ need_config () [ -f "${CONFIG}" ] && return fi fi - nconfig=$(LANG=C grep -l "^[[:space:]]*DEVICE=${1}\([[:space:]#]\|$\)" \ - /etc/sysconfig/network-scripts/ifcfg-* \ - | LC_ALL=C sed -e "$__sed_discard_ignored_files") + nconfig=$(get_config_by_device ${1}) if [ -n "$nconfig" ] && [ -f "$nconfig" ]; then CONFIG=${nconfig##*/} return -- cgit v1.2.1 From 9c4b5b4c2f2105e99377719b78631b357dfc2e3d Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Tue, 16 Feb 2010 14:05:03 -0500 Subject: Add get_config_by_name, use it. --- sysconfig/network-scripts/network-functions | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index bef3606c..96df715b 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -41,6 +41,13 @@ get_config_by_subchannel () | LC_ALL=C sed -e "$__sed_discard_ignored_files" } +get_config_by_name () +{ + LANG=C grep -E -i -l \ + "^[[:space:]]*NAME=\"(Auto |System )?${1}\"" \ + /etc/sysconfig/network-scripts/ifcfg-* \ + | LC_ALL=C sed -e "$__sed_discard_ignored_files" +} get_device_by_hwaddr () { @@ -55,6 +62,11 @@ need_config () [ -f "${CONFIG}" ] && return CONFIG="${1##*/}" [ -f "${CONFIG}" ] && return + nconfig=$(get_config_by_name ${1}) + if [ -n "$nconfig" ] && [ -f "$nconfig" ]; then + CONFIG=${nconfig##*/} + return + fi local addr=$(get_hwaddr ${1}) if [ -n "$addr" ]; then nconfig=$(get_config_by_hwaddr ${addr}) -- cgit v1.2.1 From 7623065694b1b84bf99f2425ff91cf5655e4d981 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Tue, 16 Feb 2010 14:06:16 -0500 Subject: Add a function that determines the status of NetworkManager; use it. --- sysconfig/network-scripts/network-functions | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index 96df715b..313e42fd 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -138,6 +138,7 @@ source_config () else ISALIAS=no fi + is_nm_running && USE_NM=true } @@ -190,6 +191,11 @@ do_netreport () ) } +is_nm_running () +{ + LANG=C nmcli nm status | grep -Eq "NM running:[[:space:]]+running" +} + # Sets $alias to the device module if $? != 0 is_available () { -- cgit v1.2.1 From c43e3361caca18a78e58fca3db57ce513d18d694 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Tue, 16 Feb 2010 15:17:03 -0500 Subject: Use NM if it's running and we have a configuration for the device. --- sysconfig/network-scripts/ifdown | 9 +++++++++ sysconfig/network-scripts/ifup | 9 +++++++++ sysconfig/network-scripts/network-functions | 4 ++++ 3 files changed, 22 insertions(+) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/ifdown b/sysconfig/network-scripts/ifdown index a0cc0c9e..9c9112cb 100755 --- a/sysconfig/network-scripts/ifdown +++ b/sysconfig/network-scripts/ifdown @@ -41,6 +41,15 @@ then exit 0 fi +if [ "$USE_NM" = "true" -a -n "$NAME" -o -n "$UUID" ]; then + if [ -n "$UUID" ]; then + nmcli con down uuid "$UUID" + elif [ -n "$NAME" ]; then + nmcli con down id "$NAME" + fi + exit $? +fi + if [ -x /sbin/ifdown-pre-local ]; then /sbin/ifdown-pre-local ${DEVICE} fi diff --git a/sysconfig/network-scripts/ifup b/sysconfig/network-scripts/ifup index e3b01478..5d50cbfc 100755 --- a/sysconfig/network-scripts/ifup +++ b/sysconfig/network-scripts/ifup @@ -65,6 +65,15 @@ then exit 0 fi +if [ "$USE_NM" = "true" -a -n "$NAME" -o -n "$UUID" ]; then + if [ -n "$UUID" ]; then + nmcli con up uuid "$UUID" + elif [ -n "$NAME" ]; then + nmcli con up id "$NAME" + fi + exit $? +fi + # Ethernet 802.1Q VLAN support if [ "${VLAN}" = "yes" ] && [ "$ISALIAS" = "no" ] && [ -x /sbin/vconfig ]; then VID="" diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index 313e42fd..0eaf8e10 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -139,6 +139,10 @@ source_config () ISALIAS=no fi is_nm_running && USE_NM=true + if [ -z "$NAME" -a "$USE_NM" = "true" ]; then + UUID=$(nmcli -t con list id "System ${DEVICE}" 2>/dev/null| awk '/uuid :/ { print $3 }') + [ -n "$UUID" ] && NAME="System ${DEVICE}" + fi } -- cgit v1.2.1 From 1733f15b20d44fe195550d81e98dd3c68b0c8d3b Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Tue, 16 Feb 2010 16:25:55 -0500 Subject: Remove quotes from uuid. --- sysconfig/network-scripts/network-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index 0eaf8e10..8ae752ba 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -140,7 +140,7 @@ source_config () fi is_nm_running && USE_NM=true if [ -z "$NAME" -a "$USE_NM" = "true" ]; then - UUID=$(nmcli -t con list id "System ${DEVICE}" 2>/dev/null| awk '/uuid :/ { print $3 }') + UUID=$(nmcli -t con list id "System ${DEVICE}" 2>/dev/null| awk '/uuid :/ { print gensub("\"","","g",$3) }') [ -n "$UUID" ] && NAME="System ${DEVICE}" fi } -- cgit v1.2.1 From ec7c088ad300e79a4bed6310c3a19e6c9bc03c4e Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Wed, 17 Feb 2010 15:32:22 -0500 Subject: When bringing devices down, disconnect the device, don't down the connection. --- sysconfig/network-scripts/ifdown | 8 ++------ sysconfig/network-scripts/network-functions | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/ifdown b/sysconfig/network-scripts/ifdown index 9c9112cb..31d3f716 100755 --- a/sysconfig/network-scripts/ifdown +++ b/sysconfig/network-scripts/ifdown @@ -41,12 +41,8 @@ then exit 0 fi -if [ "$USE_NM" = "true" -a -n "$NAME" -o -n "$UUID" ]; then - if [ -n "$UUID" ]; then - nmcli con down uuid "$UUID" - elif [ -n "$NAME" ]; then - nmcli con down id "$NAME" - fi +if [ "$USE_NM" = "true" ]] && is_nm_active "$DEVICE" ; then + nmcli dev disconnect iface "$DEVICE" exit $? fi diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index 8ae752ba..a29c9764 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -200,6 +200,11 @@ is_nm_running () LANG=C nmcli nm status | grep -Eq "NM running:[[:space:]]+running" } +is_nm_active () +{ + LANG=C nmcli -t dev status | grep -Eq "^${1}[[:space:]]*.*[[:space:]]*connected$" +} + # Sets $alias to the device module if $? != 0 is_available () { -- cgit v1.2.1 From fca418e42dd0291a5ea7a6490a14dab90a0e5511 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Wed, 17 Feb 2010 16:07:27 -0500 Subject: Fix is_nm_active Some versions of nmcli have trailing whitespace. --- sysconfig/network-scripts/network-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index a29c9764..43f37af2 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -202,7 +202,7 @@ is_nm_running () is_nm_active () { - LANG=C nmcli -t dev status | grep -Eq "^${1}[[:space:]]*.*[[:space:]]*connected$" + LANG=C nmcli -t dev status | grep -Eq "^${1}[[:space:]]*.*[[:space:]]*connected" } # Sets $alias to the device module if $? != 0 -- cgit v1.2.1 From 23e879f6ff48a792095e6bdbbe74dfda2b1c74f2 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Wed, 17 Feb 2010 16:30:18 -0500 Subject: Quote need_config; needed when identifying configuration by NM's 'name'. --- sysconfig/network-scripts/ifdown | 2 +- sysconfig/network-scripts/ifup | 2 +- sysconfig/network-scripts/ifup-eth | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/ifdown b/sysconfig/network-scripts/ifdown index 31d3f716..fd766427 100755 --- a/sysconfig/network-scripts/ifdown +++ b/sysconfig/network-scripts/ifdown @@ -16,7 +16,7 @@ CONFIG=$1 exit 1 } -need_config $CONFIG +need_config "${CONFIG}" [ -f "$CONFIG" ] || { echo $"usage: ifdown " >&2 diff --git a/sysconfig/network-scripts/ifup b/sysconfig/network-scripts/ifup index 5d50cbfc..d9095dc7 100755 --- a/sysconfig/network-scripts/ifup +++ b/sysconfig/network-scripts/ifup @@ -31,7 +31,7 @@ CONFIG=${1} exit 1 } -need_config ${CONFIG} +need_config "${CONFIG}" [ -f "${CONFIG}" ] || { echo $"$0: configuration for ${1} not found." >&2 diff --git a/sysconfig/network-scripts/ifup-eth b/sysconfig/network-scripts/ifup-eth index 17312863..51d1ae4f 100755 --- a/sysconfig/network-scripts/ifup-eth +++ b/sysconfig/network-scripts/ifup-eth @@ -24,7 +24,7 @@ cd /etc/sysconfig/network-scripts CONFIG=${1} -need_config ${CONFIG} +need_config "${CONFIG}" source_config -- cgit v1.2.1 From 9909d11f0a40b093a2b40e241215436fe71c5fa4 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Wed, 17 Feb 2010 16:31:05 -0500 Subject: Quote 'name' when passing to get_config_by_name. --- sysconfig/network-scripts/network-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index 43f37af2..de884ec3 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -62,7 +62,7 @@ need_config () [ -f "${CONFIG}" ] && return CONFIG="${1##*/}" [ -f "${CONFIG}" ] && return - nconfig=$(get_config_by_name ${1}) + nconfig=$(get_config_by_name "${1}") if [ -n "$nconfig" ] && [ -f "$nconfig" ]; then CONFIG=${nconfig##*/} return -- cgit v1.2.1 From b3180a743f5a80c97ea86d4ae3076920aef1c027 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Mon, 1 Mar 2010 16:12:29 -0500 Subject: Only use UUID to bring connections up/down; ensure we have a UUID by asking NM for it. --- sysconfig/network-scripts/ifup | 8 ++------ sysconfig/network-scripts/network-functions | 10 +++++++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/ifup b/sysconfig/network-scripts/ifup index d9095dc7..cc5efc97 100755 --- a/sysconfig/network-scripts/ifup +++ b/sysconfig/network-scripts/ifup @@ -65,12 +65,8 @@ then exit 0 fi -if [ "$USE_NM" = "true" -a -n "$NAME" -o -n "$UUID" ]; then - if [ -n "$UUID" ]; then - nmcli con up uuid "$UUID" - elif [ -n "$NAME" ]; then - nmcli con up id "$NAME" - fi +if [ "$USE_NM" = "true" -a -n "$UUID" ]; then + nmcli con up uuid "$UUID" exit $? fi diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index de884ec3..e498553b 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -54,6 +54,11 @@ get_device_by_hwaddr () LANG=C ip -o link | grep -v link/ieee802.11 | awk -F ': ' -vIGNORECASE=1 "/$1/ { print \$2 }" } +get_uuid_by_config () +{ + dbus-send --system --print-reply --dest=com.redhat.ifcfgrh1 /com/redhat/ifcfgrh1 com.redhat.ifcfgrh1.GetIfcfgDetails string:"/etc/sysconfig/network-scripts/$1" | awk -F '"' '/string / { print $2 }' +} + need_config () { local nconfig @@ -139,9 +144,8 @@ source_config () ISALIAS=no fi is_nm_running && USE_NM=true - if [ -z "$NAME" -a "$USE_NM" = "true" ]; then - UUID=$(nmcli -t con list id "System ${DEVICE}" 2>/dev/null| awk '/uuid :/ { print gensub("\"","","g",$3) }') - [ -n "$UUID" ] && NAME="System ${DEVICE}" + if [ -z "$UUID" -a "$USE_NM" = "true" ]; then + UUID=$(get_uuid_by_config $CONFIG) fi } -- cgit v1.2.1