]>
Commit | Line | Data |
---|---|---|
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} | |
20 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
21 | ||
22 | TYPE="${RED_TYPE}" | |
23 | DEVICE="${RED_DEV}" | |
24 | ||
0dde24fa MT |
25 | if [ "$TYPE" == "STATIC" ] || [ "$TYPE" == "DHCP" ]; then |
26 | if [ "$DEVICE" == "" ]; then | |
27 | boot_mesg "No device for red network. Please run setup." ${FAILURE} | |
28 | echo_failure | |
29 | [ "${1}" == "start" ] && exit 0 | |
30 | fi | |
31 | fi | |
32 | ||
33 | if [ "${TYPE}" == "STATIC" ]; then | |
34 | if [ "${DEVICE}" != "${GREEN_DEV}" ]; then | |
35 | ADDRESS="${RED_ADDRESS}" | |
36 | BROADCAST="${RED_BROADCAST}" | |
37 | NETADDRESS="${RED_NETADDRESS}" | |
38 | NETMASK="${RED_NETMASK}" | |
39 | else | |
40 | ADDRESS="${GREEN_ADDRESS}" | |
41 | BROADCAST="${GREEN_BROADCAST}" | |
42 | NETADDRESS="${GREEN_NETADDRESS}" | |
43 | NETMASK="${GREEN_NETMASK}" | |
44 | fi | |
d1e90efc | 45 | GATEWAY="${DEFAULT_GATEWAY}" |
0db33b56 MT |
46 | # DNS1 |
47 | # DNS2 | |
d1e90efc MT |
48 | |
49 | if [ -z "${BROADCAST}" ]; then | |
0dde24fa | 50 | boot_mesg "BROADCAST variable missing, cannot continue." ${FAILURE} |
d1e90efc MT |
51 | echo_failure |
52 | exit 1 | |
53 | fi | |
54 | if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then | |
55 | PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-` | |
56 | args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}" | |
57 | else | |
58 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
59 | echo_failure | |
60 | exit 1 | |
61 | fi | |
62 | ||
63 | elif [ "${TYPE}" == "DHCP" ]; then | |
64 | ||
65 | PIDFILE="/var/run/dhcpcd-${DEVICE}.pid" | |
66 | LEASEINFO="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info" | |
67 | DHCP_START="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe " | |
68 | DHCP_STOP="-k -c /var/ipfire/dhcpc/dhcpcd.exe " | |
69 | ||
70 | fi | |
71 | ||
72 | case "${1}" in | |
73 | start) | |
0dde24fa MT |
74 | if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then |
75 | boot_mesg "Bringing up the ${DEVICE} interface..." | |
76 | boot_mesg_flush | |
77 | # Check if an interface is there... | |
78 | if ip link show ${DEVICE} > /dev/null 2>&1; then | |
79 | link_status=`ip link show ${DEVICE} 2> /dev/null` | |
80 | if [ -n "${link_status}" ]; then | |
81 | if ! echo "${link_status}" | grep -q UP; then | |
82 | ip link set ${DEVICE} up | |
83 | fi | |
d1e90efc | 84 | fi |
0dde24fa MT |
85 | else |
86 | boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE} | |
87 | echo_failure | |
88 | exit 1 | |
d1e90efc | 89 | fi |
d1e90efc MT |
90 | fi |
91 | ||
92 | if [ "${TYPE}" == "STATIC" ]; then | |
0dde24fa MT |
93 | |
94 | if [ "$DEVICE" != "${GREEN_DEV}" ]; then | |
95 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..." | |
96 | ip addr add ${args} dev ${DEVICE} | |
97 | evaluate_retval | |
98 | fi | |
0db33b56 MT |
99 | echo -n "${DEVICE}" > /var/ipfire/red/iface |
100 | echo -n "${ADDRESS}" > /var/ipfire/red/local-ipaddress | |
101 | echo -n "${GATEWAY}" > /var/ipfire/red/remote-ipaddress | |
102 | echo -n "${DNS1}" > /var/ipfire/red/dns1 | |
103 | echo -n "${DNS2}" > /var/ipfire/red/dns2 | |
bcdde652 | 104 | touch /var/ipfire/red/active |
d1e90efc | 105 | |
040e5040 MT |
106 | boot_mesg "Setting up default gateway ${GATEWAY}..." |
107 | ip route add default via ${GATEWAY} dev ${DEVICE} | |
108 | evaluate_retval | |
109 | ||
0e42072a MT |
110 | run_subdir ${rc_base}/init.d/networking/red.up/ |
111 | ||
d1e90efc MT |
112 | elif [ "${TYPE}" == "DHCP" ]; then |
113 | boot_mesg -n "Starting dhcpcd on the ${DEVICE} interface..." | |
114 | echo -n "${DEVICE}" > /var/ipfire/red/iface | |
115 | ||
116 | # Test to see if there is a stale pid file | |
117 | if [ -f "$PIDFILE" ]; then | |
118 | ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null | |
119 | if [ $? != 0 ]; then | |
120 | rm -f /var/run/dhcpcd-${DEVICE}.pid > /dev/null | |
121 | else | |
122 | boot_mesg "dhcpcd already running!" ${WARNING} | |
123 | echo_warning | |
124 | exit 2 | |
125 | fi | |
126 | fi | |
127 | ||
128 | iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT | |
129 | iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT | |
130 | ||
7f5fdd04 MT |
131 | if [ -n "${RED_DHCP_HOSTNAME}" ]; then |
132 | DHCP_START+="-h ${RED_DHCP_HOSTNAME} " | |
d1e90efc MT |
133 | fi |
134 | ||
135 | /sbin/dhcpcd ${DEVICE} ${DHCP_START} >/dev/null 2>&1 | |
136 | RET="$?" | |
137 | ||
138 | if [ "$RET" = "0" ]; then | |
139 | . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info | |
140 | echo "" | |
141 | echo_ok | |
142 | boot_mesg " DHCP Assigned Settings for ${DEVICE}:" | |
143 | boot_mesg_flush | |
144 | boot_mesg " IP Address: $IPADDR" | |
145 | boot_mesg_flush | |
7f5fdd04 MT |
146 | if [ -n "${RED_DHCP_HOSTNAME}" ]; then |
147 | boot_mesg " Hostname: $RED_DHCP_HOSTNAME" | |
d1e90efc MT |
148 | boot_mesg_flush |
149 | fi | |
150 | boot_mesg " Subnet Mask: $NETMASK" | |
151 | boot_mesg_flush | |
152 | boot_mesg " Default Gateway: $GATEWAY" | |
153 | boot_mesg_flush | |
154 | boot_mesg " DNS Server: $DNS" | |
155 | boot_mesg_flush | |
156 | ||
157 | echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1 | |
158 | echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2 | |
159 | ||
160 | . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info | |
161 | echo "$IPADDR" > /var/ipfire/red/local-ipaddress | |
a332b303 CS |
162 | grep -v "gateway" /etc/hosts > /tmp/hosts |
163 | echo "$GATEWAY gateway" >> /tmp/hosts | |
164 | mv /tmp/hosts /etc/hosts | |
d1e90efc MT |
165 | echo "$GATEWAY" > /var/ipfire/red/remote-ipaddress |
166 | else | |
167 | echo "" | |
168 | $(exit "$RET") | |
169 | evaluate_retval | |
170 | fi | |
171 | ||
172 | elif [ "$TYPE" == "PPPOE" ]; then | |
a89770fa MT |
173 | |
174 | if ( ps ax | grep -q [p]ppd ); then | |
0dde24fa MT |
175 | boot_mesg "pppd is still running." ${FAILURE} |
176 | echo_failure | |
177 | exit 1 | |
a89770fa | 178 | fi |
0dde24fa | 179 | |
d1e90efc MT |
180 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) |
181 | ||
905fbf3e | 182 | [ -c "/dev/ppp" ] || mknod /dev/ppp c 108 0 |
d1e90efc | 183 | |
a89770fa MT |
184 | PPP_NIC=${DEVICE} |
185 | ||
186 | if [ "$TYPE" == "pppoeatm" ]; then | |
187 | PPP_NIC=nas0 | |
0dde24fa | 188 | boot_mesg "Createing ATM-Bridge as $PPP_NIC ..." |
a89770fa MT |
189 | br2684ctl -c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev/null 2>&1 & |
190 | sleep 1 | |
191 | ifconfig $PPP_NIC up | |
192 | TYPE="pppoe" | |
193 | fi | |
194 | if [ "$TYPE" == "pppoe" ]; then | |
4cd4876a | 195 | if [ "$PPP_NIC" == "" ]; then |
0dde24fa MT |
196 | boot_mesg "No device for red interface given. Check netsetup or dialprofile!" ${FAILURE} |
197 | echo_failure | |
cb1fb691 | 198 | exit 0 |
0dde24fa | 199 | fi |
a89770fa MT |
200 | boot_mesg "Bringing up the PPPoE interface on $PPP_NIC ..." |
201 | ip addr add 1.1.1.1/24 broadcast 1.1.1.255 dev $PPP_NIC | |
27b8cc24 MT |
202 | else |
203 | boot_mesg "Bringing up the PPP via ${TYPE} on ${COMPORT}..." | |
204 | fi | |
0dde24fa | 205 | |
905fbf3e MT |
206 | ### ### |
207 | ### Configuring the pppd ### | |
208 | ### ### | |
209 | ||
210 | ### Plugin Options | |
211 | # | |
212 | [ "${METHOD}" == "PPPOE_PLUGIN" ] && \ | |
a89770fa MT |
213 | PLUGOPTS="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so" |
214 | ||
215 | # PLUGOPTS="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so nic-$PPP_NIC" | |
d1e90efc | 216 | |
905fbf3e MT |
217 | ### Synchronous Mode |
218 | # | |
219 | #PPPOE_SYNC=-s | |
a89770fa MT |
220 | #PPPD_SYNC=sync |
221 | ||
222 | ### Access Concentrator Name | |
223 | # | |
905fbf3e MT |
224 | if [ -n "${CONCENTRATORNAME}" ]; then |
225 | ACNAME="-C ${CONCENTRATORNAME}" | |
d1e90efc | 226 | fi |
905fbf3e MT |
227 | |
228 | ### Service Name | |
229 | # | |
230 | if [ -n "${SERVICENAME}" ]; then | |
231 | if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then | |
232 | PLUGOPTS+=" rp_pppoe_service ${SERVICENAME}" | |
233 | else | |
234 | SERVICENAME="-S ${SERVICENAME}" | |
235 | fi | |
d1e90efc | 236 | fi |
a89770fa | 237 | |
905fbf3e MT |
238 | ### Authentication Types |
239 | # | |
d1e90efc | 240 | if [ "${AUTH}" == "pap" ]; then |
905fbf3e | 241 | AUTH="-chap" |
d1e90efc | 242 | elif [ "${AUTH}" == "chap" ]; then |
905fbf3e | 243 | AUTH="-pap" |
57cb9775 CS |
244 | else |
245 | AUTH="" | |
d1e90efc | 246 | fi |
a89770fa MT |
247 | |
248 | ### DNS Config | |
249 | # | |
250 | if [ "${DNS}" == "Automatic" ]; then | |
251 | DNS="usepeerdns" | |
252 | else | |
253 | DNS="" | |
254 | echo nameserver=$DNS1 > /etc/ppp/resolv.conf | |
255 | echo nameserver=$DNS2 >> /etc/ppp/resolv.conf | |
256 | ||
257 | fi | |
258 | ||
905fbf3e MT |
259 | ### Dial On Demand |
260 | # | |
d1e90efc MT |
261 | if [ "${RECONNECTION}" != "persistent" ]; then |
262 | if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then | |
263 | SECONDS=$[${TIMEOUT} * 60] | |
905fbf3e MT |
264 | else |
265 | SECONDS=300 | |
d1e90efc MT |
266 | fi |
267 | if [ "${RECONNECTION}" == "dialondemand" ]; then | |
268 | touch /var/ipfire/red/dial-on-demand | |
905fbf3e | 269 | DEMAND="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113" |
a89770fa | 270 | DEMAND+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune" |
d1e90efc | 271 | fi |
905fbf3e MT |
272 | fi |
273 | ||
27b8cc24 | 274 | ### When using pppoe-plugin the device has to be the last option |
905fbf3e | 275 | # |
a89770fa | 276 | [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS+=" $PPP_NIC" |
27b8cc24 MT |
277 | |
278 | if [ "$TYPE" == "modem" ]; then | |
a89770fa | 279 | PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts" |
27b8cc24 | 280 | elif [ "$TYPE" == "serial" ]; then |
a89770fa | 281 | PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts" |
27b8cc24 | 282 | fi |
905fbf3e MT |
283 | |
284 | ### Standard PPP options we always use | |
285 | # | |
a89770fa | 286 | PPP_STD_OPTIONS="$PLUGOPTS $DNS defaultroute noipdefault noauth" |
905fbf3e MT |
287 | PPP_STD_OPTIONS+=" default-asyncmap hide-password nodetach mtu ${MTU}" |
288 | PPP_STD_OPTIONS+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp" | |
289 | PPP_STD_OPTIONS+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20" | |
290 | PPP_STD_OPTIONS+=" lcp-echo-failure 3 ${AUTH}" | |
a89770fa | 291 | |
905fbf3e MT |
292 | ### Debugging |
293 | # | |
294 | if [ "${DEBUG}" == "on" ]; then | |
295 | DEBUG="debug" | |
d1e90efc | 296 | else |
905fbf3e | 297 | DEBUG="" |
d1e90efc MT |
298 | fi |
299 | ||
905fbf3e MT |
300 | ### PPPoE invocation |
301 | # | |
a89770fa MT |
302 | if [ "$TYPE" == "pppoe" ]; then |
303 | PPPOE_CMD="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC" | |
27b8cc24 MT |
304 | PPPOE_CMD+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT" |
305 | fi | |
d1e90efc | 306 | |
905fbf3e MT |
307 | ### Run everything |
308 | # | |
309 | if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then | |
310 | /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND >/dev/null 2>&1 & | |
311 | evaluate_retval | |
a89770fa | 312 | # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND |
905fbf3e MT |
313 | else |
314 | /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev/null 2>&1 & | |
315 | evaluate_retval | |
a89770fa | 316 | # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC |
905fbf3e MT |
317 | fi |
318 | ||
319 | /etc/rc.d/init.d/connectd start | |
320 | ||
d1e90efc | 321 | fi |
d1e90efc MT |
322 | ;; |
323 | ||
324 | stop) | |
325 | if [ "$TYPE" == "STATIC" ]; then | |
0dde24fa MT |
326 | boot_mesg "Stopping default gateway ${GATEWAY}..." |
327 | ip route del default via ${GATEWAY} >/dev/null 2>&1 | |
328 | echo_ok | |
329 | if [ "$DEVICE" != "${GREEN_DEV}" ]; then | |
330 | boot_mesg "Removing IPv4 address ${ADDRESS} from the ${DEVICE} interface..." | |
331 | ip addr del ${args} dev ${DEVICE} | |
332 | evaluate_retval | |
333 | fi | |
0e42072a MT |
334 | run_subdir ${rc_base}/init.d/networking/red.down/ |
335 | ||
d1e90efc MT |
336 | elif [ "$TYPE" == "DHCP" ]; then |
337 | boot_mesg -n "Stopping dhcpcd on the ${DEVICE} interface..." | |
338 | if [ -e $LEASEINFO ]; then | |
339 | . $LEASEINFO | |
340 | if [ "$LEASETIME" = "4294967295" ]; then | |
341 | # do nothing, just echo ok | |
342 | echo "" | |
343 | echo_ok | |
344 | else | |
345 | if [ -n "$DHCP_STOP" ]; then | |
346 | /sbin/dhcpcd ${DEVICE} $DHCP_STOP &> /dev/null | |
347 | RET="$?" | |
348 | if [ "$RET" -eq 0 ]; then | |
349 | echo "" | |
350 | echo_ok | |
351 | elif [ "$RET" -eq 1 ]; then | |
352 | boot_mesg "dhcpcd not running!" ${WARNING} | |
353 | echo_warning | |
354 | else | |
355 | echo "" | |
356 | echo_failure | |
357 | fi | |
358 | else | |
359 | echo "" | |
360 | killproc dhcpcd | |
361 | fi | |
362 | fi | |
363 | else | |
364 | boot_mesg -n "LEASEINFO Test failed! - " ${WARNING} | |
365 | boot_mesg "dhcpcd is not running!" ${WARNING} | |
366 | echo_warning | |
367 | exit 1 | |
368 | fi | |
369 | ||
370 | elif [ "$TYPE" == "PPPOE" ]; then | |
a89770fa | 371 | boot_mesg "Bringing down the PPP interface ..." |
93b34528 | 372 | rm -f /var/ipfire/red/keepconnected |
a89770fa | 373 | killall -w -s TERM /usr/sbin/pppd 2>/dev/null |
352e626f | 374 | evaluate_retval |
0dde24fa | 375 | ip addr del 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE} >/dev/null 2>&1 |
d1e90efc | 376 | fi |
0dde24fa MT |
377 | |
378 | if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then | |
379 | link_status=`ip link show $DEVICE 2> /dev/null` | |
380 | if [ -n "${link_status}" ]; then | |
381 | if echo "${link_status}" | grep -q UP; then | |
382 | boot_mesg "Bringing down the ${DEVICE} interface..." | |
383 | ip link set ${DEVICE} down | |
384 | evaluate_retval | |
385 | fi | |
d1e90efc MT |
386 | fi |
387 | fi | |
cb1fb691 MT |
388 | killall -w -s KILL /usr/sbin/pppd >/dev/null 2>&1 |
389 | killall -w -s KILL br2684ctl >/dev/null 2>&1 | |
f480386f | 390 | rm -f /var/ipfire/red/{active,device,dial-on-demand,dns1,dns2,local-ipaddress,remote-ipaddress,resolv.conf} |
d1e90efc MT |
391 | ;; |
392 | ||
393 | esac | |
394 | ||
395 | # End |