]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/init.d/networking/red
5c96c06911797cd610f7f8b53b8bb265e96d0909
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 ########################################################################
23 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/main
/settings
)
24 if [ "$RRDLOG" == "" ]; then
28 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
29 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/mac
/settings
)
36 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
37 if [ "$DEVICE" == "" ]; then
38 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
40 [ "${1}" == "start" ] && exit 0
44 if [ "${TYPE}" == "STATIC" ]; then
45 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
46 ADDRESS
="${RED_ADDRESS}"
47 BROADCAST
="${RED_BROADCAST}"
48 NETADDRESS
="${RED_NETADDRESS}"
49 NETMASK
="${RED_NETMASK}"
51 ADDRESS
="${GREEN_ADDRESS}"
52 BROADCAST
="${GREEN_BROADCAST}"
53 NETADDRESS
="${GREEN_NETADDRESS}"
54 NETMASK
="${GREEN_NETMASK}"
56 GATEWAY
="${DEFAULT_GATEWAY}"
60 if [ -z "${BROADCAST}" ]; then
61 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
65 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
66 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
67 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
69 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
74 elif [ "${TYPE}" == "DHCP" ]; then
76 PIDFILE
="/var/run/dhcpcd-${DEVICE}.pid"
77 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
78 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
79 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
85 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
86 boot_mesg
"Bringing up the ${DEVICE} interface..."
88 # Check if an interface is there...
89 if ip link show
${DEVICE} > /dev
/null
2>&1; then
90 link_status
=`ip link show ${DEVICE} 2> /dev/null`
91 if [ -n "${link_status}" ]; then
92 if ! echo "${link_status}" |
grep -q UP
; then
93 if [ -n "$MAC" ]; then
94 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
95 ip link
set dev
${DEVICE} address
${MAC}
98 ip link
set ${DEVICE} up
102 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
108 ## Create & Enable vnstat
109 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
111 if [ "${TYPE}" == "STATIC" ]; then
113 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
114 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
115 ip addr add
${args} dev
${DEVICE}
118 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
119 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
120 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
121 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
122 echo "$GATEWAY gateway" >> /tmp
/hosts
123 mv /tmp
/hosts
/etc
/hosts
124 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
125 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
126 touch /var
/ipfire
/red
/active
128 boot_mesg
"Setting up default gateway ${GATEWAY}..."
129 ip route add default via
${GATEWAY} dev
${DEVICE}
132 run_subdir
${rc_base}/init.d
/networking
/red.up
/
134 elif [ "${TYPE}" == "DHCP" ]; then
136 if [ -e $LEASEINFO ]; then
137 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
139 if [ "$LEASETIME" = "4294967295" ]; then
140 # do nothing, just echo ok
144 if [ -n "$DHCP_STOP" ]; then
145 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
147 if [ "$RET" -eq 0 ]; then
150 elif [ "$RET" -eq 1 ]; then
151 boot_mesg
"dhcpcd not running!" ${WARNING}
164 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
165 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
167 ## Create & Enable vnstat
168 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
170 # Test to see if there is a stale pid file
171 if [ -f "$PIDFILE" ]; then
172 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
174 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
176 boot_mesg
"dhcpcd already running!" ${WARNING}
182 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
183 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
185 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
186 DHCP_START
+="-h ${RED_DHCP_HOSTNAME} "
189 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
192 if [ "$RET" = "0" ]; then
193 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
196 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
198 boot_mesg
" IP Address: $IPADDR"
200 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
201 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
204 boot_mesg
" Subnet Mask: $NETMASK"
206 boot_mesg
" Default Gateway: $GATEWAY"
208 boot_mesg
" DNS Server: $DNS"
211 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var
/ipfire
/red
/dns1
212 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var
/ipfire
/red
/dns2
214 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
215 echo "$IPADDR" > /var
/ipfire
/red
/local-ipaddress
216 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
217 echo "$GATEWAY gateway" >> /tmp
/hosts
218 mv /tmp
/hosts
/etc
/hosts
219 echo "$GATEWAY" > /var
/ipfire
/red
/remote-ipaddress
220 touch /var
/ipfire
/red
/active
227 elif [ "$TYPE" == "PPPOE" ]; then
229 if ( ps ax |
grep -q [p
]ppd
); then
230 boot_mesg
"pppd is still running." ${FAILURE}
235 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
237 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
241 if [ "$TYPE" == "vdsl" ]; then
242 boot_mesg
"Createing VLAN Interface ${DEVICE}.7 ..."
244 vconfig add
${DEVICE} 7
247 ip link
set ${PPP_NIC} up
251 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
253 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
254 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
256 if [ "$TYPE" == "pppoeatm" ]; then
259 if [ "$TYPE" == "pptpatm" ]; then
263 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
264 if [ "$PPP_NIC" == "" ]; then
265 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
269 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
270 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
271 if [ "$TYPE" == "pptp" ]; then
272 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
274 ip link
set ${PPP_NIC} up
276 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
280 ### Configuring the pppd ###
285 if [ "$TYPE" == "pppoe" ]; then
286 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
287 PLUGOPTS
="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so"
295 ### Access Concentrator Name
297 if [ -n "${CONCENTRATORNAME}" ]; then
298 ACNAME
="-C ${CONCENTRATORNAME}"
303 if [ -n "${SERVICENAME}" ]; then
304 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
305 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
307 SERVICENAME
="-S ${SERVICENAME}"
311 ### Authentication Types
313 if [ "${AUTH}" == "pap" ]; then
315 elif [ "${AUTH}" == "chap" ]; then
323 if [ "${DNS}" == "Automatic" ]; then
327 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
328 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
333 if [ "${RECONNECTION}" != "persistent" ]; then
334 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
335 SECONDS
=$
[${TIMEOUT} * 60]
339 if [ "${RECONNECTION}" == "dialondemand" ]; then
340 touch /var
/ipfire
/red
/dial-on-demand
341 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
342 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
346 if [ "$TYPE" == "pppoe" ]; then
347 ### When using pppoe-plugin the device has to be the last option
349 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
352 if [ "$TYPE" == "modem" ]; then
353 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
354 METHOD
="PPPOE_PLUGIN"
355 elif [ "$TYPE" == "serial" ]; then
356 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
357 METHOD
="PPPOE_PLUGIN"
360 ### Standard PPP options we always use
362 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
363 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
364 PPP_STD_OPTIONS
+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
365 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
366 PPP_STD_OPTIONS
+=" lcp-echo-failure 3 ${AUTH}"
370 if [ "${DEBUG}" == "on" ]; then
378 if [ "$TYPE" == "pppoe" ]; then
379 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
380 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
385 if [ "$TYPE" == "pptp" ]; then
386 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
392 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
393 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
395 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
397 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
399 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
401 ## Create & Enable vnstat
402 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
403 /etc
/rc.d
/init.d
/connectd start
404 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
405 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
406 $
(date +%s
):: > /dev
/null
2>&1
412 if [ "$TYPE" == "STATIC" ]; then
413 boot_mesg
"Stopping default gateway ${GATEWAY}..."
414 ip route del default via
${GATEWAY} >/dev
/null
2>&1
416 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
417 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
418 ip addr flush dev
${DEVICE}
421 run_subdir
${rc_base}/init.d
/networking
/red.down
/
423 elif [ "$TYPE" == "DHCP" ]; then
424 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
425 if [ -e $LEASEINFO ]; then
427 if [ "$LEASETIME" = "4294967295" ]; then
428 # do nothing, just echo ok
432 if [ -n "$DHCP_STOP" ]; then
433 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
435 if [ "$RET" -eq 0 ]; then
438 elif [ "$RET" -eq 1 ]; then
439 boot_mesg
"dhcpcd not running!" ${WARNING}
451 boot_mesg
-n "LEASEINFO Test failed! - " ${WARNING}
452 boot_mesg
"dhcpcd is not running!" ${WARNING}
456 elif [ "$TYPE" == "PPPOE" ]; then
457 boot_mesg
"Bringing down the PPP interface ..."
458 ## Disable vnstat collection
459 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
460 rm -f /var
/ipfire
/red
/keepconnected
461 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
463 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
464 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
465 $
(date +%s
):: > /dev
/null
2>&1
468 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
469 link_status
=`ip link show $DEVICE.7 2> /dev/null`
470 if [ -n "${link_status}" ]; then
471 if echo "${link_status}" |
grep -q UP
; then
472 boot_mesg
"Bringing down the ${DEVICE}.7 interface..."
473 ip link
set ${DEVICE}.7 down
474 vconfig del
${DEVICE} 7
478 link_status
=`ip link show $DEVICE 2> /dev/null`
479 if [ -n "${link_status}" ]; then
480 if echo "${link_status}" |
grep -q UP
; then
481 boot_mesg
"Bringing down the ${DEVICE} interface..."
482 ip link
set ${DEVICE} down
487 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
488 killall
-w -s KILL pptp
>/dev
/null
2>&1
489 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
491 ## Disable vnstat collection
492 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
494 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}