/[baselayout]/trunk/init.d/net.eth0
Gentoo

Contents of /trunk/init.d/net.eth0

Parent Directory Parent Directory | Revision Log Revision Log


Revision 340 - (show annotations) (download)
Sun Mar 16 08:03:19 2003 UTC (16 years, 3 months ago) by azarah
File size: 4116 byte(s)
some fixes and new release

1 #!/sbin/runscript
2 # Copyright 1999-2003 Gentoo Technologies, Inc.
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header$
5
6 #NB: Config is in /etc/conf.d/net
7
8
9 # For pcmcia users. note that pcmcia must be added to the same
10 # runlevel as the net.* script that needs it.
11 depend() {
12 use hotplug pcmcia
13 }
14
15 checkconfig() {
16 if [ -z "${iface_IFACE}" ]
17 then
18 eerror "Please make sure that /etc/conf.d/net has \$iface_$IFACE set"
19 return 1
20 fi
21 }
22
23 setup_env() {
24 # No reason to check these multiple times in the file
25 iface_IFACE="$(eval echo \$\{iface_${IFACE}\})"
26 dhcpcd_IFACE="$(eval echo \$\{dhcpcd_${IFACE}\})"
27 inet6_IFACE="$(eval echo \$\{inet6_${IFACE}\})"
28 alias_IFACE="$(eval echo \$\{alias_${IFACE}\})"
29 status_IFACE="$(ifconfig | gawk -v IFACE="${IFACE}" '/Link/ { if ($1 == IFACE) print "up" }')"
30 }
31
32 start() {
33 local retval=0
34
35 setup_env
36 checkconfig || return 1
37
38 ebegin "Bringing ${IFACE} up"
39 if [ "${iface_IFACE}" != "dhcp" ]
40 then
41 /sbin/ifconfig ${IFACE} ${iface_IFACE} >/dev/null || {
42 retval=$?
43 eend ${retval} "Failed to bring ${IFACE} up"
44 return ${retval}
45 }
46 # ifconfig do not always return failure ..
47 /sbin/ifconfig ${IFACE} &> /dev/null || {
48 retval=$?
49 eend ${retval} "Failed to bring ${IFACE} up"
50 return ${retval}
51 }
52 else
53 # Check that eth0 was not brough up by the kernel ...
54 if [ "${status_IFACE}" != "up" ]
55 then
56 /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} >/dev/null || {
57 retval=$?
58 eend ${retval} "Failed to bring ${IFACE} up"
59 return ${retval}
60 }
61 fi
62 fi
63 eend 0
64
65 if [ -n "${alias_IFACE}" ]
66 then
67 local x=""
68 local num=0
69 local aliasbcast=""
70 local aliasnmask=""
71
72 ebegin " Adding aliases"
73 for x in ${alias_IFACE}
74 do
75 aliasbcast="$(eval echo \$\{broadcast_${IFACE}\} \| awk \'\{ print \$$((num + 1)) \}\')"
76 if [ -n "${aliasbcast}" ]
77 then
78 aliasbcast="broadcast ${aliasbcast}"
79 fi
80
81 aliasnmask="$(eval echo \$\{netmask_${IFACE}\} \| awk \'\{ print \$$((num + 1)) \}\')"
82 if [ -n "${aliasnmask}" ]
83 then
84 aliasnmask="netmask ${aliasnmask}"
85 fi
86
87 ebegin " ${IFACE}:${num}"
88 /sbin/ifconfig ${IFACE}:${num} ${x} \
89 ${aliasbcast} ${aliasnmask} >/dev/null
90 num=$((num + 1))
91 eend 0
92 done
93 save_options "alias" "${alias_IFACE}"
94 fi
95
96 if [ -n "${inet6_IFACE}" ]
97 then
98 local x=""
99 ebegin " Adding inet6 addresses"
100 for x in ${inet6_IFACE}
101 do
102 ebegin " ${IFACE} inet6 add ${x}"
103 /sbin/ifconfig ${IFACE} inet6 add ${x} >/dev/null
104 eend 0
105 done
106 save_options "inet6" "${inet6_IFACE}"
107 fi
108
109 if [ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ]
110 then
111 ebegin " Setting default gateway"
112 # First delete any existing routes if it was setup by kernel ..
113 /sbin/route del default dev ${gateway%/*} &>/dev/null
114 /sbin/route add default gw ${gateway#*/} dev ${gateway%/*} \
115 netmask 0.0.0.0 metric 1 >/dev/null || {
116
117 local error=$?
118 ifconfig ${IFACE} down &>/dev/null
119 eend ${error} "Failed to bring ${IFACE} up"
120 stop
121 return ${error}
122 }
123 eend 0
124 fi
125
126 # Enabling rp_filter causes wacky packets to be auto-dropped by
127 # the kernel
128 if [ -e /proc/sys/net/ipv4/conf/${IFACE}/rp_filter ]
129 then
130 echo 1 > /proc/sys/net/ipv4/conf/${IFACE}/rp_filter
131 fi
132 }
133
134 stop() {
135 local myalias="$(get_options alias)"
136 local myinet6="$(get_options inet6)"
137
138 setup_env
139
140 ebegin "Bringing ${IFACE} down"
141
142 # Also down the inet6 interfaces
143 if [ -n "${myinet6}" ]
144 then
145 local x=""
146 for x in ${myinet6}
147 do
148 /sbin/ifconfig ${IFACE} inet6 del ${x} >/dev/null
149 done
150 fi
151
152 # Do some cleanup in case the amount of aliases change
153 if [ -n "${myalias}" ]
154 then
155 local x=""
156 local num=0
157 for x in ${myalias}
158 do
159 /sbin/ifconfig ${IFACE}:${num} down >/dev/null
160 num=$((num + 1))
161 done
162 fi
163
164 if [ "${iface_IFACE}" = "dhcp" ]
165 then
166 local count=0
167 while /sbin/dhcpcd -k ${IFACE} &>/dev/null && [ "${count}" -lt 9 ]
168 do
169 # Give dhcpcd time to properly shutdown
170 sleep 1
171 count=$((count + 1))
172 done
173 if [ "${count}" -ge 9 ]
174 then
175 eerror "Timed out trying to stop dhcpcd"
176 fi
177 else
178 /sbin/ifconfig ${IFACE} down >/dev/null
179 fi
180 eend 0
181 }
182
183
184 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20