File: network

package info (click to toggle)
hibernate 1.07-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 316 kB
  • ctags: 52
  • sloc: sh: 1,014; makefile: 33
file content (176 lines) | stat: -rw-r--r-- 4,076 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet

AddConfigHandler NetworkConfigOptions
AddConfigHelp "DownInterfaces auto|<ifname> [...]" "The names of network interfaces to bring down before suspending. If the parameter \"auto\" is given, all interfaces which are not lo are brought down."
AddConfigHelp "UpInterfaces auto|<ifname> [...]" "The names of network interfaces to bring up after suspending. If the parameter \"auto\" is given, the interfaces stoped before suspending will be started in reverse order."

NetworkStop() {
    # If the script stops networking altogether, there's not much we can do.
    if [ -n "$NETWORK_CALL_ONCE" ] ; then
	network_ifdown
	[ $? -eq 0 ] && return 0
	return 1
    fi

    local ret
    local int
    ret=0
    NETWORK_DOWNEDIFS="" # for saving the downed interfaces, for "auto"
    for int in $NETWORK_DOWNIFS ; do
	if [ "$int" = "auto" ] ; then
	    for int in `/sbin/ifconfig|sed -e 's/^\([^ \t]*\).*/\1/;/^$/d'` ; do
		[ "$int" = "lo" ] && continue
		vecho 2 "Bringing down interface $int (from auto)"
		network_ifdown $int
		[ $? -ne 0 ] && ret=1
		NETWORK_DOWNEDIFS="$int $NETWORK_DOWNEDIFS"
	    done
	    continue
	fi
	vecho 2 "Bringing down interface $int"
	network_ifdown $int
	[ $? -ne 0 ] && ret=1
	NETWORK_DOWNEDIFS="$int $NETWORK_DOWNEDIFS"
    done
    return $ret
}

NetworkStart() {
    # If the script starts networking altogether, there's not much we can do.
    if [ -n "$NETWORK_CALL_ONCE" ] ; then
	network_ifup
	[ $? -eq 0 ] && return 0
	return 1
    fi

    local ret
    local int
    ret=0
    for int in $NETWORK_UPIFS ; do
	if [ "$int" = "auto" ] ; then
	    for int in $NETWORK_DOWNEDIFS ; do
		vecho 2 "Bringing up interface $int (from auto)"
		network_ifup $int
		[ $? -ne 0 ] && ret=1
	    done
	    continue
	fi
	vecho 2 "Bringing up interface $int"
	network_ifup $int
	[ $? -ne 0 ] && ret=1
    done
    return 0
}

NetworkConfigOptions() {
    local opt
    opt="$1"
    shift
    case $opt in
	downinterfaces)
	    NETWORK_DOWNIFS="$NETWORK_DOWNIFS $* "
	    ;;
	upinterfaces)
	    NETWORK_UPIFS="$NETWORK_UPIFS $* "
	    ;;
	*)
	    return 1
    esac
    if [ -z "$NETWORK_HOOKED" ] ; then
	AddSuspendHook 60 NetworkStop
	AddResumeHook 60 NetworkStart
	NetworkDetectDistro
	NETWORK_HOOKED=1
    fi
    return 0
}

NetworkDetectDistro() {
    # Use either a given $DISTRIBUTION or autodetect one.
    case "$DISTRIBUTION" in
	gentoo)
	    network_ifup() {
	    	[ -x "/etc/init.d/net.$1" ] && /etc/init.d/net.$1 start
	    }
	    network_ifdown() {
	    	[ -x "/etc/init.d/net.$1" ] && /etc/init.d/net.$1 stop
	    }
	    ;;
	suse)
	    network_ifup() {
		/etc/init.d/network start
	    }
	    network_ifdown() {
		/etc/init.d/network stop
	    }
	    NETWORK_CALL_ONCE=1
	    ;;
	debian|mandrake|fedora|redhat)
	    network_ifup() {
		/sbin/ifup $*
	    }
	    network_ifdown() {
		/sbin/ifdown $*
	    }
	    ;;
	slackware)
	    network_ifup() {
		/etc/init.d/ifup $*
	    }
	    network_ifdown() {
		/etc/init.d/ifdown $*
	    }
	    ;;
    	*)
	    # Auto-detect
	    if [ -x "/sbin/ifup" ] ; then
		network_ifup() {
		    /sbin/ifup $*
		}
		network_ifdown() {
		    /sbin/ifdown $*
		}
	    elif [ -x "/etc/init.d/ifup" ] ; then
		network_ifup() {
		    /etc/init.d/ifup $*
		}
		network_ifdown() {
		    /etc/init.d/ifdown $*
		}
	    elif [ -x "/etc/sysconfig/network-scripts/ifup" ] ; then
		network_ifup() {
		    /etc/sysconfig/network-scripts/ifup $*
		}
		network_ifdown() {
		    /etc/sysconfig/network-scripts/ifdown $*
		}
	    elif [ -x "/etc/init.d/networking" ] ; then
		network_ifup() {
		    /etc/init.d/networking start
		}
		network_ifdown() {
		    /etc/init.d/networking stop
		}
		NETWORK_CALL_ONCE=1
	    elif [ -x "/etc/init.d/network" ] ; then
		network_ifup() {
		    /etc/init.d/network start
		}
		network_ifdown() {
		    /etc/init.d/network stop
		}
		NETWORK_CALL_ONCE=1
	    else
	    	network_ifup() {
		    /sbin/ifconfig $1 up
		}
		network_ifdown() {
		    /sbin/ifconfig $1 down
		}
	    fi
    esac
    return 0
}

# $Id: network 564 2004-11-17 15:31:06Z dagobah $