wok-6.x view open-vm-tools/stuff/network @ rev 25445
itaka: fix wget_url
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Sep 06 07:38:52 2022 +0000 (2022-09-06) |
parents | 995a8662f5ad |
children |
line source
1 #!/bin/sh
2 ##########################################################
3 # Copyright (C) 2001-2010 VMware, Inc. All rights reserved.
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published
7 # by the Free Software Foundation version 2.1 and no later version.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
12 # License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 #
18 ##########################################################
20 exit 0
23 #
24 # network (Linux)
25 #
26 # Using a combination of a system networking script, ifconfig, and ifup,
27 # attempt to release and renew DHCP leases upon receipt of suspend and resume
28 # events, respectively.
29 #
32 echo `date` ": Executing '$0'"
33 echo
35 . `dirname "$0"`/../../statechange.subr
38 #
39 # find_networking_script --
40 #
41 # Searches common Linux distro init/rc paths to find a singular network
42 # services script.
43 #
44 # Result:
45 # Returns a valid networking script path on success or "error" on failure.
46 #
47 # Side effects:
48 # None.
49 #
51 find_networking_script() {
52 echo "network.sh"
53 }
56 #
57 # run_network_script --
58 #
59 # Finds out how to run the system's script used to control networking, and
60 # runs it with the given argument (which should be one of the usual SysV
61 # init script arguments).
62 #
63 run_network_script()
64 {
65 script=`find_networking_script`
66 [ "$script" != "error" ] || Panic "Cannot find system networking script."
68 "$script" "$1"
69 }
72 #
73 # save_active_NIC_list --
74 #
75 # Records a list of every active NIC to /var/run/vmware-active-nics.
76 #
77 # XXX What's the story on aliases? Should they still be included, or will
78 # they be recreated automatically upon resume?
79 #
80 # Results:
81 # $activeList has, one per line, a list of all active NICs.
82 #
83 # Side effects:
84 # None.
85 #
87 save_active_NIC_list() {
88 >$activeList
90 for nic in `ifconfig | awk '/^eth/ { print $1 }'`; do
91 ifconfig $nic | egrep -q '\bUP\b' && echo $nic >> $activeList
92 exitCode=`expr $exitCode \| $?`
93 done
94 }
97 #
98 # rescue_NIC --
99 #
100 # For each NIC recorded in $activeList that is not currently "up", run
101 # "INTERFACE=$nic network.sh start".
102 #
103 # Results:
104 # All downed NICs should be active.
105 #
107 rescue_NIC() {
108 if [ -f "$activeList" ]; then
109 while read nic; do
110 if ifconfig $nic | egrep -q '\bUP\b'; then
111 echo `date` "[rescue_nic] $nic is already active."
112 else
113 echo `date` "[rescue_nic] activating $nic ..."
115 INTERFACE=$nic /etc/init.d/network.sh start
116 exitCode=`expr $exitCode \| $?`
117 fi
118 done < $activeList
120 rm -f $activeList
121 fi
122 }
125 #
126 # main --
127 #
128 # Main entry point. Perform some sanity checking, then map state change
129 # events to relevant networking operations.
130 #
131 # Results:
132 # See comment at top of file.
133 #
135 main() {
136 exitCode=0
137 activeList=/var/run/vmware-active-nics
139 # XXX Are these really necessary? If so, we should have seen customer
140 # complaints by now.
141 which ifconfig >/dev/null 2>&1 || Panic "ifconfig not in search path."
143 case "$1" in
144 poweron-vm)
145 rm -f $activeList
146 ;;
147 suspend-vm)
148 exitCode=$?
149 if [ $exitCode != 0 ]; then
150 save_active_NIC_list
151 run_network_script stop
152 exitCode=$?
153 fi
154 ;;
155 resume-vm)
156 WakeNetworkManager
157 exitCode=$?
158 if [ $exitCode != 0 ]; then
159 # According to hfu, "/etc/init.d/networking restart" on Debian 5.0
160 # may bring down ethernet interfaces tagged as "allow-hotplug" without
161 # bringing them back up.
162 #
163 # This is especially a problem when reverting to a live, running
164 # VM snapshot where an active NIC list hadn't yet been generated,
165 # resulting in sudden loss of an otherwise operational NIC.
166 #
167 # So, if the active list doesn't exist, assume we're coming back to
168 # a live snapshot and capture the current active list now for
169 # rescue later.
170 if [ ! -s $activeList ]; then
171 save_active_NIC_list
172 fi
174 # We shall use start not restart here. Otherwise we may not be able
175 # to bring back active list on distros like sles11sp2
176 # -- PR 816791
177 run_network_script start
178 rescue_NIC
179 exitCode=$?
180 fi
181 ;;
182 *) ;;
183 esac
185 return $exitCode
186 }
188 main "$@"