Neue und hoffentlich bessere Scripte fuer die Verwaltung der vielen Netzwerkschnittst...
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / networking / red
CommitLineData
d1e90efc
MT
1#!/bin/sh
2########################################################################
3# Begin
4#
5# Description : RED Device Script
6#
7# Authors : Michael Tremer - mitch@ipfire.org
8# Maniacikarus - maniacikarus@ipfire.org
9# Inspired by : Nathan Coulson - nathan@linuxfromscratch.org
10# Kevin P. Fleming - kpfleming@linuxfromscratch.org
11#
12# Version : 01.00
13#
14# Notes :
15#
16########################################################################
17
18. /etc/sysconfig/rc
19. ${rc_functions}
20eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
21
22TYPE="${RED_TYPE}"
23DEVICE="${RED_DEV}"
24
25if [ "$TYPE" == "STATIC" ]; then
26 ADDRESS="${RED_ADDRESS}"
27 BROADCAST="${RED_BROADCAST}"
28 NETADDRESS="${RED_NETADDRESS}"
29 NETMASK="${RED_NETMASK}"
30 GATEWAY="${DEFAULT_GATEWAY}"
31 DNS1="${DNS1}"
32 DNS2="${DNS2}"
33
34 if [ -z "${BROADCAST}" ]; then
35 boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE}
36 echo_failure
37 exit 1
38 fi
39 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
40 PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
41 args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
42 else
43 boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
44 echo_failure
45 exit 1
46 fi
47
48elif [ "${TYPE}" == "DHCP" ]; then
49
50 PIDFILE="/var/run/dhcpcd-${DEVICE}.pid"
51 LEASEINFO="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
52 DHCP_START="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
53 DHCP_STOP="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
54
55fi
56
57case "${1}" in
58 start)
59 boot_mesg "Bringing up the ${DEVICE} interface..."
60 boot_mesg_flush
61
62 # Check if an interface is there...
63 if ip link show ${DEVICE} > /dev/null 2>&1; then
64 link_status=`ip link show ${DEVICE} 2> /dev/null`
65 if [ -n "${link_status}" ]; then
66 if ! echo "${link_status}" | grep -q UP; then
67 ip link set ${DEVICE} up
68 fi
69 fi
70 else
71 boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE}
72 echo_failure
73 exit 1
74 fi
75
76 if [ "${TYPE}" == "STATIC" ]; then
77 boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
78 ip addr add ${args} dev ${DEVICE}
79 evaluate_retval
80
81 elif [ "${TYPE}" == "DHCP" ]; then
82 boot_mesg -n "Starting dhcpcd on the ${DEVICE} interface..."
83 echo -n "${DEVICE}" > /var/ipfire/red/iface
84
85 # Test to see if there is a stale pid file
86 if [ -f "$PIDFILE" ]; then
87 ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null
88 if [ $? != 0 ]; then
89 rm -f /var/run/dhcpcd-${DEVICE}.pid > /dev/null
90 else
91 boot_mesg "dhcpcd already running!" ${WARNING}
92 echo_warning
93 exit 2
94 fi
95 fi
96
97 iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
98 iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
99
100 if [ -n "${DHCP_HOSTNAME}" ]; then
101 DHCP_START+="-h ${DHCP_HOSTNAME} "
102 fi
103
104 /sbin/dhcpcd ${DEVICE} ${DHCP_START} >/dev/null 2>&1
105 RET="$?"
106
107 if [ "$RET" = "0" ]; then
108 . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info
109 echo ""
110 echo_ok
111 boot_mesg " DHCP Assigned Settings for ${DEVICE}:"
112 boot_mesg_flush
113 boot_mesg " IP Address: $IPADDR"
114 boot_mesg_flush
115 if [ -n "${DHCP_HOSTNAME}" ]; then
116 boot_mesg " Hostname: $DHCP_HOSTNAME"
117 boot_mesg_flush
118 fi
119 boot_mesg " Subnet Mask: $NETMASK"
120 boot_mesg_flush
121 boot_mesg " Default Gateway: $GATEWAY"
122 boot_mesg_flush
123 boot_mesg " DNS Server: $DNS"
124 boot_mesg_flush
125
126 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1
127 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2
128
129 . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info
130 echo "$IPADDR" > /var/ipfire/red/local-ipaddress
131 echo "$GATEWAY" > /var/ipfire/red/remote-ipaddress
132 else
133 echo ""
134 $(exit "$RET")
135 evaluate_retval
136 fi
137
138 elif [ "$TYPE" == "PPPOE" ]; then
139 eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
140
141 boot_mesg "Bringing up the PPPoE interface on ${DEVICE}..."
142 ip addr add 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE}
143
144 PPPOECONF=/etc/ppp/pppoe.conf
145 echo > $PPPOECONF #clear
146
147 if [ "${METHOD}" != "PPPOE_PLUGIN" ]; then
148 echo "LINUX_PLUGIN=" >> $PPPOECONF
149 else
150 echo "LINUX_PLUGIN=/usr/lib/pppd/2.4.4/rp-pppoe.so" >> $PPPOECONF
151 fi
152
153 echo "ETH=${DEVICE}" >> $PPPOECONF
154 echo "USER=${USERNAME}" >> $PPPOECONF
155
156 echo "PPPOE_TIMEOUT=80" >> $PPPOECONF
157
158 #echo "PPPD_EXTRA=\"-U\"" >> $PPPOECONF
159 #echo "PPPOE_EXTRA=\"-m ${MTU}\"" >> $PPPOECONF
160
161 if [ -n ${SERVICENAME} ]; then
162 echo "SERVICENAME=${SERVICENAME}" >> $PPPOECONF
163 fi
164 if [ -n ${CONCENTRATORNAME} ]; then
165 echo "ACNAME=${CONCENTRATORNAME}" >> $PPPOECONF
166 fi
167
168 if [ "${DNS}" == "Automatic" ]; then
169 echo "PEERDNS=yes" >> $PPPOECONF
170 echo "DNSTYPE=NOCHANGE" >> $PPPOECONF
171 fi
172
173 if [ "${AUTH}" == "pap" ]; then
174 PPPD_EXTRA+="-chap "
175 elif [ "${AUTH}" == "chap" ]; then
176 PPPD_EXTRA+="-pap "
177 fi
178
179 echo "FIREWALL=NONE" >> $PPPOECONF
180
181 if [ "${RECONNECTION}" != "persistent" ]; then
182 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
183 SECONDS=$[${TIMEOUT} * 60]
184 fi
185 if [ "${RECONNECTION}" == "dialondemand" ]; then
186 touch /var/ipfire/red/dial-on-demand
187 echo "DEMAND=${SECONDS}" >> $PPPOECONF
188 fi
189 else
190 echo "DEMAND=no" >> $PPPOECONF
191 fi
192
193 echo "LCP_INTERVAL=20" >> $PPPOECONF
194 echo "LCP_FAILURE=3" >> $PPPOECONF
195
196 echo "PIDFILE=/var/run/ppp-ipfire.pid" >> $PPPOECONF
197
198 #ARGS+=" maxfail ${MAXRETRIES}"
199
200 [ "${METHOD}" != "PPPOE_PLUGIN" ] && [ "${DEBUG}" == "on" ] && export DEBUG=1
201 /usr/sbin/pppoe-start
202 evaluate_retval
203 fi
204
205 for i in $( ls -v ${rc_base}/init.d/networking/red.up/* 2> /dev/null); do
206 check_script_status
207 OUT=$(echo $(basename ${i}) | awk -F- '{ print $2 }')
208 case "$OUT" in
209 S) ${i} start ;;
210 K) ${i} stop ;;
211 RS) ${i} restart ;;
212 RL) ${i} reload ;;
213 *) ${i} ;;
214 esac
215 done
216 ;;
217
218 stop)
219 if [ "$TYPE" == "STATIC" ]; then
220 boot_mesg "Removing IPv4 address ${ADDRESS} from the ${DEVICE} interface..."
221 ip addr del ${args} dev ${DEVICE}
222 evaluate_retval
223
224 elif [ "$TYPE" == "DHCP" ]; then
225 boot_mesg -n "Stopping dhcpcd on the ${DEVICE} interface..."
226 if [ -e $LEASEINFO ]; then
227 . $LEASEINFO
228 if [ "$LEASETIME" = "4294967295" ]; then
229 # do nothing, just echo ok
230 echo ""
231 echo_ok
232 else
233 if [ -n "$DHCP_STOP" ]; then
234 /sbin/dhcpcd ${DEVICE} $DHCP_STOP &> /dev/null
235 RET="$?"
236 if [ "$RET" -eq 0 ]; then
237 echo ""
238 echo_ok
239 elif [ "$RET" -eq 1 ]; then
240 boot_mesg "dhcpcd not running!" ${WARNING}
241 echo_warning
242 else
243 echo ""
244 echo_failure
245 fi
246 else
247 echo ""
248 killproc dhcpcd
249 fi
250 fi
251 else
252 boot_mesg -n "LEASEINFO Test failed! - " ${WARNING}
253 boot_mesg "dhcpcd is not running!" ${WARNING}
254 echo_warning
255 exit 1
256 fi
257
258 elif [ "$TYPE" == "PPPOE" ]; then
259 boot_mesg "Bringing down the PPPoE interface on ${DEVICE}..."
260
261 /usr/sbin/pppoe-stop
262 evaluate_retval
263 ip addr del 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE}
264
265 fi
266
267 link_status=`ip link show $DEVICE 2> /dev/null`
268 if [ -n "${link_status}" ]; then
269 if echo "${link_status}" | grep -q UP; then
270 boot_mesg "Bringing down the ${DEVICE} interface..."
271 ip link set ${DEVICE} down
272 evaluate_retval
273 fi
274 fi
275
276 for i in $( ls -v ${rc_base}/init.d/networking/red.down/* 2> /dev/null); do
277 check_script_status
278 OUT=$(echo $(basename ${i}) | awk -F- '{ print $2 }')
279 case "$OUT" in
280 S) ${i} start ;;
281 K) ${i} stop ;;
282 RS) ${i} restart ;;
283 RL) ${i} reload ;;
284 *) ${i} ;;
285 esac
286 done
287 ;;
288
289esac
290
291# End