aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiloslav Trmac <mitr@volny.cz>2006-02-10 01:45:34 +0000
committerMiloslav Trmac <mitr@volny.cz>2006-02-10 01:45:34 +0000
commit858506a7cab3cfc3cc98072ef75ec80ada55bcc2 (patch)
tree9852ef2ad79e783d1af2c5e58c34bebca786e25e
parent24d9e8bb5fbc56104873174b5c13095954fc6eb1 (diff)
downloadinitscripts-858506a7cab3cfc3cc98072ef75ec80ada55bcc2.tar
initscripts-858506a7cab3cfc3cc98072ef75ec80ada55bcc2.tar.gz
initscripts-858506a7cab3cfc3cc98072ef75ec80ada55bcc2.tar.bz2
initscripts-858506a7cab3cfc3cc98072ef75ec80ada55bcc2.tar.xz
initscripts-858506a7cab3cfc3cc98072ef75ec80ada55bcc2.zip
ifup-aliases:
- Revert the previous commit - Reformat the eval of doom, add comments - Add support for non-numeric IP aliases ifdown-aliases: - Copy the updated eval of doom
-rwxr-xr-xsysconfig/network-scripts/ifdown-aliases24
-rwxr-xr-xsysconfig/network-scripts/ifup-aliases42
2 files changed, 56 insertions, 10 deletions
diff --git a/sysconfig/network-scripts/ifdown-aliases b/sysconfig/network-scripts/ifdown-aliases
index 34d70f1f..6a310cc7 100755
--- a/sysconfig/network-scripts/ifdown-aliases
+++ b/sysconfig/network-scripts/ifdown-aliases
@@ -15,7 +15,29 @@ cd /etc/sysconfig/network-scripts
. network-functions
# This is the same messy sed script as in the ifup-aliases script.
-eval `LC_ALL= LANG= ifconfig | sed -e ' /^[^[:space:]]*:[0-9]*/ { s|^\([^:]*\):\([0-9]*\).*$|X=x; TMP="\2"; [ "$device" != "\1" ] \|\| |g; b; }; /^[^[:space:]]/ { s|.*|X=x; [ 0 = 0 ] \|\| |g; b; }; /inet addr:[0-9]*\.[0-9]*\.[0-9]*\.[0-9]* *Bcast:[0-9.]* *Mask:[0-9.]*/ { s|^.*inet addr:\(\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\) *Bcast:\([0-9.]*\) *Mask:\([0-9.]*\).*$|eval " rdev_${TMP}_addr=\1; rdev_${TMP}_mb=\7_\6; rdevip_\2_\3_\4_\5=${TMP}; rdev_LIST=\\\\"\\\\$rdev_LIST \\\\${TMP}\\\\"; " \|\| |g; b; }; s|^.*$||g; ' ` X=x;
+# Update also ifup-aliases!
+eval $(LC_ALL= LANG= /sbin/ifconfig | LC_ALL=C sed -n '
+# Alias name: store the number in TMP, ignore the following address if the
+# device name does not match. This may leave a hanging ||, so dummy X=x
+# comands are used to ignore a possible previous condition.
+/^[^[:space:]]*:[0-9A-Za-z_]*/ {
+ s|^\([^:]*\):\([0-9A-Za-z_]*\).*$|X=x; TMP="\2"; [ "$device" != "\1" ] \|\| |p
+ b
+}
+# Non-alias device: always ignore the following address
+/^[^[:space:]]/ {
+ s|^.*$|X=x; true \|\| |p
+ b
+}
+# Address: Preceded by a device name, which was converted into
+# condition ||
+# So this triggers only for $device.
+# Add a trailing || (which will be swallowed by X=x) to keep the syntax
+# correct.
+/inet addr:[0-9]*\.[0-9]*\.[0-9]*\.[0-9]* *Bcast:[0-9.]* *Mask:[0-9.]*/ {
+ s|^.*inet addr:\(\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\) *Bcast:\([0-9.]*\) *Mask:\([0-9.]*\).*$|eval "rdev_${TMP}_addr=\1; rdev_${TMP}_mb=\7_\6; rdevip_\2_\3_\4_\5=${TMP}; rdev_LIST=\\"\\$rdev_LIST \\${TMP}\\"; " \|\| |p
+ b
+}') X=x
for DEVNUM in $rdev_LIST ; do
ifconfig $parent_device:$DEVNUM down
diff --git a/sysconfig/network-scripts/ifup-aliases b/sysconfig/network-scripts/ifup-aliases
index d02c71c8..6ac5d9a0 100755
--- a/sysconfig/network-scripts/ifup-aliases
+++ b/sysconfig/network-scripts/ifup-aliases
@@ -74,14 +74,33 @@ parent_device=$device
cd /etc/sysconfig/network-scripts
. network-functions
- #
- # Grab the current configuration of any running aliases device info is placed into
- # variables in the form: rdev_$DEVICE_addr, dev_$DEVICE_mb and rdevip_$IPGLOP.
- # A list of all the devices is created in rdev_LIST.
- #
-
-# sorry this is all one line -- it didn't work on multiple lines for me
-eval `LC_ALL= LANG= /sbin/ifconfig | sed -e ' /^[^[:space:]]*:[0-9]*/ { s|^\([^:]*\):\([0-9]*\).*$|X=x; TMP="\2"; [ "$device" != "\1" ] \|\| |g; b; }; /^[^[:space:]]/ { s|.*|X=x; [ 0 = 0 ] \|\| |g; b; }; /inet addr:[0-9]*\.[0-9]*\.[0-9]*\.[0-9]* *Bcast:[0-9.]* *Mask:[0-9.]*/ { s|^.*inet addr:\(\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\) *Bcast:\([0-9.]*\) *Mask:\([0-9.]*\).*$|eval " rdev_${TMP}_addr=\1; rdev_${TMP}_mb=\7_\6; rdevip_\2_\3_\4_\5=${TMP}; rdev_LIST=\\\\"\\\\$rdev_LIST \\\\${TMP}\\\\"; " \|\| |g; b; }; s|^.*$||g; ' ` X=x;
+# Grab the current configuration of any running aliases device info is placed
+# into variables in the form: rdev_$DEVICE_addr, dev_$DEVICE_mb and
+# rdevip_$IPGLOP. A list of all the devices is created in rdev_LIST.
+
+# Update also ifdown-aliases!
+eval $(LC_ALL= LANG= /sbin/ifconfig | LC_ALL=C sed -n '
+# Alias name: store the number in TMP, ignore the following address if the
+# device name does not match. This may leave a hanging ||, so dummy X=x
+# comands are used to ignore a possible previous condition.
+/^[^[:space:]]*:[0-9A-Za-z_]*/ {
+ s|^\([^:]*\):\([0-9A-Za-z_]*\).*$|X=x; TMP="\2"; [ "$device" != "\1" ] \|\| |p
+ b
+}
+# Non-alias device: always ignore the following address
+/^[^[:space:]]/ {
+ s|^.*$|X=x; true \|\| |p
+ b
+}
+# Address: Preceded by a device name, which was converted into
+# condition ||
+# So this triggers only for $device.
+# Add a trailing || (which will be swallowed by X=x) to keep the syntax
+# correct.
+/inet addr:[0-9]*\.[0-9]*\.[0-9]*\.[0-9]* *Bcast:[0-9.]* *Mask:[0-9.]*/ {
+ s|^.*inet addr:\(\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\) *Bcast:\([0-9.]*\) *Mask:\([0-9.]*\).*$|eval "rdev_${TMP}_addr=\1; rdev_${TMP}_mb=\7_\6; rdevip_\2_\3_\4_\5=${TMP}; rdev_LIST=\\"\\$rdev_LIST \\${TMP}\\"; " \|\| |p
+ b
+}') X=x
if [ -z "$rdev_LIST" ]; then
no_devices_are_up=yes
@@ -149,6 +168,11 @@ function new_interface ()
IPGLOP="${ipa%%.*}_${ipb%%.*}_${ipc%%.*}_${ipc#*.}";
DEVNUM=${DEVICE#*:}
+ if (LC_ALL=C; [[ ! "$DEVNUM" =~ '^[0-9A-Za-z_]*$' ]]); then
+ echo $"error in $FILE: invalid alias number" >&2
+ return 1
+ fi
+
eval "
ipseen=\$ipseen_${IPGLOP}; devseen=\$devseen_${DEVNUM};
ipseen_${IPGLOP}=$FILE; devseen_${DEVNUM}=$FILE;
@@ -297,7 +321,7 @@ for FILE in ifcfg-${parent_device}:*[^~] ; do
ini_env;
. $FILE;
[ -z "$DEVICE" ] && DEVICE=${FILE##ifcfg-}
- [[ ! "$ONPARENT" =~ "NO|no" ]] && [ "$DEVICE" == "${FILE##ifcfg-}" ] && new_interface;
+ [ "$ONPARENT" != "no" -a "$ONPARENT" != "NO" ] && new_interface;
unset DEVICE
done