]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/networking/red
2 ########################################################################
5 # Description : RED Device Script
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
16 ########################################################################
22 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
27 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
28 if [ "$DEVICE" == "" ]; then
29 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
31 [ "${1}" == "start" ] && exit 0
35 if [ "${TYPE}" == "STATIC" ]; then
36 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
37 ADDRESS
="${RED_ADDRESS}"
38 BROADCAST
="${RED_BROADCAST}"
39 NETADDRESS
="${RED_NETADDRESS}"
40 NETMASK
="${RED_NETMASK}"
42 ADDRESS
="${GREEN_ADDRESS}"
43 BROADCAST
="${GREEN_BROADCAST}"
44 NETADDRESS
="${GREEN_NETADDRESS}"
45 NETMASK
="${GREEN_NETMASK}"
47 GATEWAY
="${DEFAULT_GATEWAY}"
51 if [ -z "${BROADCAST}" ]; then
52 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
56 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
57 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
58 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
60 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
65 elif [ "${TYPE}" == "DHCP" ]; then
67 PIDFILE
="/var/run/dhcpcd-${DEVICE}.pid"
68 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
69 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
70 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
76 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
77 boot_mesg
"Bringing up the ${DEVICE} interface..."
79 # Check if an interface is there...
80 if ip link show
${DEVICE} > /dev
/null
2>&1; then
81 link_status
=`ip link show ${DEVICE} 2> /dev/null`
82 if [ -n "${link_status}" ]; then
83 if ! echo "${link_status}" |
grep -q UP
; then
84 ip link
set ${DEVICE} up
88 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
94 ## Create & Enable vnstat
95 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
97 if [ "${TYPE}" == "STATIC" ]; then
99 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
100 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
101 ip addr add
${args} dev
${DEVICE}
104 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
105 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
106 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
107 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
108 echo "$GATEWAY gateway" >> /tmp
/hosts
109 mv /tmp
/hosts
/etc
/hosts
110 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
111 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
112 touch /var
/ipfire
/red
/active
114 boot_mesg
"Setting up default gateway ${GATEWAY}..."
115 ip route add default via
${GATEWAY} dev
${DEVICE}
118 run_subdir
${rc_base}/init.d
/networking
/red.up
/
120 elif [ "${TYPE}" == "DHCP" ]; then
121 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
122 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
124 ## Create & Enable vnstat
125 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
127 # Test to see if there is a stale pid file
128 if [ -f "$PIDFILE" ]; then
129 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
131 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
133 boot_mesg
"dhcpcd already running!" ${WARNING}
139 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
140 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
142 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
143 DHCP_START
+="-h ${RED_DHCP_HOSTNAME} "
146 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
149 if [ "$RET" = "0" ]; then
150 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
153 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
155 boot_mesg
" IP Address: $IPADDR"
157 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
158 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
161 boot_mesg
" Subnet Mask: $NETMASK"
163 boot_mesg
" Default Gateway: $GATEWAY"
165 boot_mesg
" DNS Server: $DNS"
168 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var
/ipfire
/red
/dns1
169 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var
/ipfire
/red
/dns2
171 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
172 echo "$IPADDR" > /var
/ipfire
/red
/local-ipaddress
173 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
174 echo "$GATEWAY gateway" >> /tmp
/hosts
175 mv /tmp
/hosts
/etc
/hosts
176 echo "$GATEWAY" > /var
/ipfire
/red
/remote-ipaddress
183 elif [ "$TYPE" == "PPPOE" ]; then
185 if ( ps ax |
grep -q [p
]ppd
); then
186 boot_mesg
"pppd is still running." ${FAILURE}
191 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
193 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
197 if [ "$TYPE" == "vdsl" ]; then
198 boot_mesg
"Createing VLAN Interface ${DEVICE}.7 ..."
200 vconfig add
${DEVICE} 7
203 ip link
set ${PPP_NIC} up
207 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
209 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
210 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
212 if [ "$TYPE" == "pppoeatm" ]; then
215 if [ "$TYPE" == "pptpatm" ]; then
219 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
220 if [ "$PPP_NIC" == "" ]; then
221 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
225 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
226 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
227 if [ "$TYPE" == "pptp" ]; then
228 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
230 ip link
set ${PPP_NIC} up
232 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
236 ### Configuring the pppd ###
241 if [ "$TYPE" == "pppoe" ]; then
242 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
243 PLUGOPTS
="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so"
251 ### Access Concentrator Name
253 if [ -n "${CONCENTRATORNAME}" ]; then
254 ACNAME
="-C ${CONCENTRATORNAME}"
259 if [ -n "${SERVICENAME}" ]; then
260 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
261 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
263 SERVICENAME
="-S ${SERVICENAME}"
267 ### Authentication Types
269 if [ "${AUTH}" == "pap" ]; then
271 elif [ "${AUTH}" == "chap" ]; then
279 if [ "${DNS}" == "Automatic" ]; then
283 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
284 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
289 if [ "${RECONNECTION}" != "persistent" ]; then
290 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
291 SECONDS
=$
[${TIMEOUT} * 60]
295 if [ "${RECONNECTION}" == "dialondemand" ]; then
296 touch /var
/ipfire
/red
/dial-on-demand
297 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
298 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
302 if [ "$TYPE" == "pppoe" ]; then
303 ### When using pppoe-plugin the device has to be the last option
305 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
308 if [ "$TYPE" == "modem" ]; then
309 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
310 METHOD
="PPPOE_PLUGIN"
311 elif [ "$TYPE" == "serial" ]; then
312 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
313 METHOD
="PPPOE_PLUGIN"
316 ### Standard PPP options we always use
318 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
319 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
320 PPP_STD_OPTIONS
+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
321 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
322 PPP_STD_OPTIONS
+=" lcp-echo-failure 3 ${AUTH}"
326 if [ "${DEBUG}" == "on" ]; then
334 if [ "$TYPE" == "pppoe" ]; then
335 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
336 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
341 if [ "$TYPE" == "pptp" ]; then
342 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
348 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
349 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
351 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
353 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
355 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
357 ## Create & Enable vnstat
358 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
359 /etc
/rc.d
/init.d
/connectd start
365 if [ "$TYPE" == "STATIC" ]; then
366 boot_mesg
"Stopping default gateway ${GATEWAY}..."
367 ip route del default via
${GATEWAY} >/dev
/null
2>&1
369 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
370 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
371 ip addr flush dev
${DEVICE}
374 run_subdir
${rc_base}/init.d
/networking
/red.down
/
376 elif [ "$TYPE" == "DHCP" ]; then
377 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
378 if [ -e $LEASEINFO ]; then
380 if [ "$LEASETIME" = "4294967295" ]; then
381 # do nothing, just echo ok
385 if [ -n "$DHCP_STOP" ]; then
386 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
388 if [ "$RET" -eq 0 ]; then
391 elif [ "$RET" -eq 1 ]; then
392 boot_mesg
"dhcpcd not running!" ${WARNING}
404 boot_mesg
-n "LEASEINFO Test failed! - " ${WARNING}
405 boot_mesg
"dhcpcd is not running!" ${WARNING}
409 elif [ "$TYPE" == "PPPOE" ]; then
410 boot_mesg
"Bringing down the PPP interface ..."
411 ## Disable vnstat collection
412 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
413 rm -f /var
/ipfire
/red
/keepconnected
414 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
418 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
419 link_status
=`ip link show $DEVICE.7 2> /dev/null`
420 if [ -n "${link_status}" ]; then
421 if echo "${link_status}" |
grep -q UP
; then
422 boot_mesg
"Bringing down the ${DEVICE}.7 interface..."
423 ip link
set ${DEVICE}.7 down
424 vconfig del
${DEVICE} 7
428 link_status
=`ip link show $DEVICE 2> /dev/null`
429 if [ -n "${link_status}" ]; then
430 if echo "${link_status}" |
grep -q UP
; then
431 boot_mesg
"Bringing down the ${DEVICE} interface..."
432 ip link
set ${DEVICE} down
437 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
438 killall
-w -s KILL pptp
>/dev
/null
2>&1
439 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
441 ## Disable vnstat collection
442 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
444 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}