]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - lib/functions.network
If an iface type is specified NEVER override it
[projects/rc-scripts.git] / lib / functions.network
index 5a90b723077dce37d0c1c5524dcd6e25f33c2625..0543059fcbd06594d4389fd4f0fc3c6900dfe1f4 100644 (file)
@@ -1,6 +1,5 @@
 #!/bin/sh - keep it for file(1) to get bourne shell script result
 #
-# $Id$
 #
 # This is not a shell script; it provides functions to network scripts
 # that source it.
@@ -73,7 +72,7 @@ set_hostname()
        if [ "$domain" ]; then
                # XXX umask and possible /etc/resolv.conf symlink breakage
                > /etc/resolv.conf.new
-               if ! grep -q "search $domain" /etc/resolv.conf; then
+               if ! grep -Fq "search $domain" /etc/resolv.conf; then
                        echo "search $domain" >> /etc/resolv.conf.new
                fi
                echo "domain $domain" >> /etc/resolv.conf.new
@@ -183,13 +182,14 @@ setup_ip_param ()
 {
        # detect network device type (ie. dummy, eth for dummy0, eth0 ..)
        if [ -z "$DEVICETYPE" ]; then
-               DEVICETYPE=$(echo $DEVICE | awk ' { gsub(/[\.:]?[0-9]*[\.:]?[0-9]*$/,NUL); print $0 } ')
+               # If there's a dot, it's a vlan
+               if echo ${DEVICE} | LC_ALL=C grep -qE '^[a-z0-9]+\.[0-9]+$'; then
+                       DEVICETYPE=vlan
+               else
+                       DEVICETYPE=$(echo $DEVICE | awk ' { gsub(/[\.:]?[0-9]*[\.:]?[0-9]*$/,NUL); print $0 } ')
+               fi
        fi
 
-       # Setup DEVICETYPE for special cases.
-       if echo ${DEVICE} | LC_ALL=C grep -qE '^[a-z0-9]+\.[0-9]+$'; then
-               DEVICETYPE=vlan
-       fi
 
        # real name of device (ie. is eth0 for eth0,eth0:1,eth0:alias)
        SUBDEVICE=$(echo "$DEVICE" | grep -E "([0-9]+:[0-9]+)")
@@ -257,7 +257,7 @@ setup_ip_param ()
 
 check_device_down ()
 {
-       if LC_ALL=C ip link show dev ${DEVICE} 2> /dev/null | grep -q UP; then
+       if LC_ALL=C ip link show dev ${DEVICE} 2> /dev/null | grep -Fq UP; then
                return 1
        else
                return 0
@@ -469,12 +469,19 @@ get_ppp_device_and_pid ()
 # Olgierd Pieczul <wojrus@pld-linux.org>
 setup_ip_rules ()
 {
-       local args prio from src
+       local args prio from src i prio
 
        if [ -f /etc/sysconfig/static-routes ]; then
                if is_yes "$1"; then
+                       i=10000
                        grep -E "^(from|to|iif|tos|fwmark|dev|pref|priority|prio)[[:blank:]]" /etc/sysconfig/static-routes | while read args; do
-                               /sbin/ip rule add $args
+                               prio=""
+                               if [ "${args##* prio }" = "$args" ]; then
+                                       # no "prio" used in rule, use own prio
+                                       prio="prio $i"
+                                       i=$((i + 5))
+                               fi
+                               /sbin/ip rule add $args $prio
                        done
                elif is_no "$1"; then
                        LC_ALL=C /sbin/ip rule show | grep -vE -e "from all lookup (main|default|local|253|254|255) \$" -e " map-to " | while read prio from src args; do
@@ -485,8 +492,15 @@ setup_ip_rules ()
        is_no "$IPV6_NETWORKING" && return
        if [ -f /etc/sysconfig/static-routes6 ]; then
                if is_yes "$1"; then
+                       i=10000
                        grep -E "^(from|to|iif|tos|fwmark|dev|pref|priority|prio)[[:blank:]]" /etc/sysconfig/static-routes6 | while read args; do
-                               /sbin/ip -6 rule add $args
+                               prio=""
+                               if [ "${args##* prio }" = "$args" ]; then
+                                       # no "prio" used in rule, use own prio
+                                       prio="prio $i"
+                                       i=$((i + 5))
+                               fi
+                               /sbin/ip -6 rule add $args $prio
                        done
                elif is_no "$1"; then
                        LC_ALL=C /sbin/ip -6 rule show | grep -vE -e "from all lookup (main|default|local|253|254|255) \$" -e " map-to " | while read prio from src args; do
@@ -499,7 +513,7 @@ setup_ip_rules ()
 is_wireless_device ()
 {
        if [ -x /sbin/iwconfig ]; then
-               LC_ALL=C iwconfig "${1}" 2>&1 | grep -q "no wireless extensions" || return 0
+               LC_ALL=C iwconfig "${1}" 2>&1 | grep -Fq "no wireless extensions" || return 0
        fi
        return 1
 }
@@ -592,8 +606,8 @@ check_mii_tool ()
 {
        [ -x /sbin/mii-tool ] || return 2
        local output=$(LC_ALL=C mii-tool $1 2>&1)
-       echo $output | grep -q "link ok" && return 1
-       echo $output | grep -q "no link" && return 0
+       echo $output | grep -Fq "link ok" && return 1
+       echo $output | grep -Fq "no link" && return 0
        return 2
 }
 
@@ -605,8 +619,8 @@ check_ethtool ()
 {
        [ -x /sbin/ethtool ] || return 2
        local output=$(LC_ALL=C ethtool $1 2>&1)
-       echo $output | grep -q "Link detected: yes" && return 1
-       echo $output | grep -q "Link detected: no" && return 0
+       echo $output | grep -Fq "Link detected: yes" && return 1
+       echo $output | grep -Fq "Link detected: no" && return 0
        return 2
 }
 
@@ -625,7 +639,7 @@ check_iwconfig ()
        [ -x /sbin/iwconfig ] || return 2
        output=$(LC_ALL=C iwconfig "$1" 2>&1)
        # "radio off" is ipwxxx only "feature" (and there is no "radio on")
-       echo "$output" | grep -q "radio off" && return 0
+       echo "$output" | grep -Fq "radio off" && return 0
        # XXX: need more generic checks for wifi
        return 2
 }
@@ -644,9 +658,9 @@ check_link_down ()
                return 2
        fi
 
-       [ -z "$max_timeout" ] && max_timeout=6
+       [ -z "$max_timeout" ] && max_timeout=10
 
-       if ! LC_ALL=C ip link show dev $device 2>/dev/null | grep -q UP; then
+       if ! LC_ALL=C ip link show dev $device 2>/dev/null | grep -Fq UP; then
                ip link set dev $device up >/dev/null 2>&1
                emit net-device-up IFACE=$device
        fi
This page took 0.034179 seconds and 4 git commands to generate.