network: code optimization for speed and removal/cornering of obsolete functions

This commit is contained in:
Silvan Calarco 2013-09-18 20:10:00 +02:00
parent 57701f3c38
commit 94b6db3676

View File

@ -15,9 +15,6 @@ me="network"
. /etc/postplug/postplug.defs . /etc/postplug/postplug.defs
postplugnew_file=$postplugnewdir/network
rm -f $postplugnew_file
[ -r /etc/sysconfig/postplug ] && . /etc/sysconfig/postplug [ -r /etc/sysconfig/postplug ] && . /etc/sysconfig/postplug
[ -r /etc/sysconfig/rc ] && . /etc/sysconfig/rc [ -r /etc/sysconfig/rc ] && . /etc/sysconfig/rc
@ -66,7 +63,7 @@ function cdc_usb() {
ifconfig usb0 &>/dev/null && { ifconfig usb0 &>/dev/null && {
[ "$NETWORK_CDC_NETMASK" ] && CDC_NETMASK=$NETWORK_CDC_NETMASK [ "$NETWORK_CDC_NETMASK" ] && CDC_NETMASK=$NETWORK_CDC_NETMASK
[ -e $network_devices/ifcng-usb0 ] || { [ -e $network_devices/ifcfg-usb0 ] || {
[ "$NETWORK_CDC_IPADDR" ] && CDC_IPADDR=$NETWORK_CDC_IPADDR [ "$NETWORK_CDC_IPADDR" ] && CDC_IPADDR=$NETWORK_CDC_IPADDR
cat > $network_devices/ifcfg-usb0 << _EOF cat > $network_devices/ifcfg-usb0 << _EOF
DEVICE=usb0 DEVICE=usb0
@ -144,62 +141,72 @@ _EOF
[ "$NETWORK_CDC_DISABLE" = "1" ] || cdc_usb [ "$NETWORK_CDC_DISABLE" = "1" ] || cdc_usb
[ "$NETWORK_ANDROID_DISABLE" = "1" ] || android_usb [ "$NETWORK_ANDROID_DISABLE" = "1" ] || android_usb
wlan_ints=() # Disable p2p interface managed by NetworkManager
for wlan_int in $(cat /proc/net/wireless 2>/dev/null | sed -n '/[a-z]*[0-9]*:/{s,:.*,,;p}'); do for net_int in $(cat /proc/net/dev | sed -n '/p2p[0-9]*:/{s,:.*,,;p}'); do
# checks for existing physical interfaces
/sbin/ifconfig $wlan_int >/dev/null 2>&1 || continue
# found interface already configured # found interface already configured
[ -e $network_devices/ifcfg-$wlan_int ] && continue [ -e $network_devices/ifcfg-${net_int} ] && continue
wlan_ints[${#wlan_ints[*]}]="$wlan_int" if [ "${net_int:0:3}" = "p2p" ]; then
echo "$wlan_int" >> $postplugnew_file 2>/dev/null P2P_HWADDR=`ifconfig $net_int | grep HWaddr | sed "s|.* HWaddr ||"`
cat > $network_devices/ifcfg-${net_int} << _EOF
DEVICE=$net_int
HWADDR=$P2P_HWADDR
ONBOOT=no
NM_CONTROLLED=no
_EOF
fi
done done
eth_ints=() # INFO: the following code is going obsolete
for eth_int in $(cat /proc/net/dev | sed -n '/eth[0-9]*:/{s,:.*,,;p}'); do if [ "$NETWORK_NEWDEVICE" -a "$NETWORK_NEWDEVICE" != "off" ]; then
# checks for existing physical interfaces
/sbin/ifconfig $eth_int >/dev/null 2>&1 || continue
# found interface already configured wlan_ints=()
[ -e $network_devices/ifcfg-$eth_int ] && continue for wlan_int in $(cat /proc/net/wireless 2>/dev/null | sed -n '/[a-z]*[0-9]*:/{s,:.*,,;p}'); do
# found interface already configured
[ -e $network_devices/ifcfg-$wlan_int ] && continue
wlan_ints[${#wlan_ints[*]}]="$wlan_int"
done
eth_ints[${#eth_ints[*]}]="$eth_int" eth_ints=()
echo "$eth_int" >> $postplugnew_file 2>/dev/null for eth_int in $(cat /proc/net/dev | sed -n '/eth[0-9]*:/{s,:.*,,;p}'); do
done # found interface already configured
[ -e $network_devices/ifcfg-$eth_int ] && continue
eth_ints[${#eth_ints[*]}]="$eth_int"
done
# how many interface have been configured? # how many interface have been configured?
let "int_newconf = 0" let "int_newconf = 0"
if [ ${#eth_ints[*]} -gt 0 ]; then if [ ${#eth_ints[*]} -gt 0 ]; then
case "$NETWORK_NEWDEVICE" in case "$NETWORK_NEWDEVICE" in
"auto") "auto")
for eth_int in ${eth_ints[*]}; do for eth_int in ${eth_ints[*]}; do
eth_config_auto $eth_int eth_config_auto $eth_int
let "int_newconf += 1" let "int_newconf += 1"
done done
exit exit
;; ;;
"off"|"") "off"|"")
exit exit
;; ;;
*) logmsg "$me" "error: "$"\ *) logmsg "$me" "error: "$"\
illegal value for NETWORK_NEWDEVICE ($NETWORK_NEWDEVICE)" illegal value for NETWORK_NEWDEVICE ($NETWORK_NEWDEVICE)"
exit 1 exit 1
;; ;;
esac esac
fi fi
if [ ${#wlan_ints[*]} -gt 0 ]; then if [ ${#wlan_ints[*]} -gt 0 ]; then
case "$NETWORK_NEWDEVICE" in case "$NETWORK_NEWDEVICE" in
"auto") "auto")
for wlan_int in ${wlan_ints[*]}; do for wlan_int in ${wlan_ints[*]}; do
wlan_config_auto $wlan_int wlan_config_auto $wlan_int
let "int_newconf += 1" let "int_newconf += 1"
done done
exit exit
;; ;;
esac esac
fi
fi fi
exit 0 exit 0