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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 266 - (show annotations) (download)
Mon Nov 18 13:07:02 2002 UTC (17 years ago) by azarah
File size: 3577 byte(s)
change license

1 #!/sbin/runscript
2 # Copyright 1999-2002 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 pcmcia
13 }
14
15 checkconfig() {
16 if [ -z "$(eval echo \$\{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 start() {
24 checkconfig || return 1
25 local iface_args="$(eval echo \$\{iface_${IFACE}\})"
26 local dhcp_args="$(eval echo \$\{dhcpcd_${IFACE}\})"
27 local retval=0
28 ebegin "Bringing ${IFACE} up"
29 if [ "$(eval echo \$\{iface_${IFACE}\})" != "dhcp" ]
30 then
31 /sbin/ifconfig ${IFACE} ${iface_args} >/dev/null || {
32 retval=$?
33 eend ${retval} "Failed to bring ${IFACE} up"
34 return ${retval}
35 }
36 else
37 /sbin/dhcpcd ${dhcp_args} ${IFACE} >/dev/null || {
38 retval=$?
39 eend ${retval} "Failed to bring ${IFACE} up"
40 return ${retval}
41 }
42 fi
43 eend 0
44
45 if [ -n "$(eval echo \$\{alias_${IFACE}\})" ]
46 then
47 local x=""
48 local num=0
49 local aliasbcast=""
50 local aliasnmask=""
51
52 ebegin " Adding aliases"
53 for x in $(eval echo \$\{alias_${IFACE}\})
54 do
55 aliasbcast="$(eval echo \$\{broadcast_${IFACE}\} \| awk \'\{ print \$$((num + 1)) \}\')"
56 if [ -n "${aliasbcast}" ]
57 then
58 aliasbcast="broadcast ${aliasbcast}"
59 fi
60
61 aliasnmask="$(eval echo \$\{netmask_${IFACE}\} \| awk \'\{ print \$$((num + 1)) \}\')"
62 if [ -n "${aliasnmask}" ]
63 then
64 aliasnmask="netmask ${aliasnmask}"
65 fi
66
67 ebegin " ${IFACE}:${num}"
68 /sbin/ifconfig ${IFACE}:${num} ${x} \
69 ${aliasbcast} ${aliasnmask} >/dev/null
70 num=$((num + 1))
71 eend 0
72 done
73 save_options "alias" "$(eval echo \$\{alias_${IFACE}\})"
74 fi
75
76 if [ -n "$(eval echo \$\{inet6_${IFACE}\})" ]
77 then
78 local x=""
79 ebegin " Adding inet6 addresses"
80 for x in $(eval echo \$\{inet6_${IFACE}\})
81 do
82 ebegin " ${IFACE} inet6 add ${x}"
83 /sbin/ifconfig ${IFACE} inet6 add ${x} >/dev/null
84 eend 0
85 done
86 save_options "inet6" "$(eval echo \$\{inet6_${IFACE}\})"
87 fi
88
89 if [ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ]
90 then
91 ebegin " Setting default gateway"
92 /sbin/route add default gw ${gateway#*/} dev ${gateway%/*} \
93 netmask 0.0.0.0 metric 1 >/dev/null || {
94
95 local error=$?
96 ifconfig ${IFACE} down &>/dev/null
97 eend ${error} "Failed to bring ${IFACE} up"
98 stop
99 return ${error}
100 }
101 eend 0
102 fi
103
104 # Enabling rp_filter causes wacky packets to be auto-dropped by
105 # the kernel
106 if [ -e /proc/sys/net/ipv4/conf/${IFACE}/rp_filter ]
107 then
108 echo 1 > /proc/sys/net/ipv4/conf/${IFACE}/rp_filter
109 fi
110 }
111
112 stop() {
113 local myalias="$(get_options alias)"
114 ebegin "Bringing ${IFACE} down"
115
116 # Also down the inet6 interfaces
117 local myinet6="$(get_options inet6)"
118 if [ -n "${myinet6}" ]
119 then
120 local x=""
121 for x in ${myinet6}
122 do
123 /sbin/ifconfig ${IFACE} inet6 del ${x} >/dev/null
124 done
125 fi
126
127 # Do some cleanup in case the amount of aliases change
128 if [ -n "${myalias}" ]
129 then
130 local x=""
131 local num=0
132 for x in ${myalias}
133 do
134 /sbin/ifconfig ${IFACE}:${num} down >/dev/null
135 num=$((num + 1))
136 done
137 fi
138
139 if [ "$(eval echo \$\{iface_${IFACE}\})" = "dhcp" ]
140 then
141 /sbin/dhcpcd -k ${IFACE} &>/dev/null
142
143 # Give dhcpcd time to properly shutdown
144 local count=0
145 einfon " Waiting for dhcpcd to shutdown"
146 while [ "${count}" -lt 5 ]
147 do
148 echo -n "."
149 sleep 1
150 count=$((count + 1))
151 done
152 echo "done"
153 else
154 /sbin/ifconfig ${IFACE} down >/dev/null
155 fi
156 eend 0
157 }
158
159
160 # 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