]>
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 ########################################################################
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 # Configure aliases only if red static
135 /usr
/local
/bin
/setaliases
137 elif [ "${TYPE}" == "DHCP" ]; then
139 if [ -e $LEASEINFO ]; then
140 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
142 if [ "$LEASETIME" = "4294967295" ]; then
143 # do nothing, just echo ok
147 if [ -n "$DHCP_STOP" ]; then
148 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
150 if [ "$RET" -eq 0 ]; then
153 elif [ "$RET" -eq 1 ]; then
154 boot_mesg
"dhcpcd not running!" ${WARNING}
167 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
168 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
170 ## Create & Enable vnstat
171 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
173 # Test to see if there is a stale pid file
174 if [ -f "$PIDFILE" ]; then
175 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
177 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
179 boot_mesg
"dhcpcd already running!" ${WARNING}
185 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
186 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
188 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
189 DHCP_START
+="-h ${RED_DHCP_HOSTNAME} "
192 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
195 if [ "$RET" = "0" ]; then
196 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
199 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
201 boot_mesg
" IP Address: $IPADDR"
203 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
204 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
207 boot_mesg
" Subnet Mask: $NETMASK"
209 boot_mesg
" Default Gateway: $GATEWAY"
211 boot_mesg
" DNS Server: $DNS"
214 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var
/ipfire
/red
/dns1
215 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var
/ipfire
/red
/dns2
217 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
218 echo "$IPADDR" > /var
/ipfire
/red
/local-ipaddress
219 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
220 echo "$GATEWAY gateway" >> /tmp
/hosts
221 mv /tmp
/hosts
/etc
/hosts
222 echo "$GATEWAY" > /var
/ipfire
/red
/remote-ipaddress
223 touch /var
/ipfire
/red
/active
230 elif [ "$TYPE" == "PPPOE" ]; then
232 if ( ps ax |
grep -q [p
]ppd
); then
233 boot_mesg
"pppd is still running." ${FAILURE}
238 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
240 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
244 if [ "$TYPE" == "vdsl" ]; then
245 boot_mesg
"Createing VLAN Interface ${DEVICE}.7 ..."
247 vconfig add
${DEVICE} 7
250 ip link
set ${PPP_NIC} up
254 PIDFILE
="/var/run/dhcpcd-${DEVICE}.8.pid"
255 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.8.info"
256 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
257 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
260 # Test to see if there is a stale pid file
261 if [ -f "$PIDFILE" ]; then
262 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
264 rm -f /var
/run
/dhcpcd-
${DEVICE}.8.pid
> /dev
/null
267 if [ ! -f "$PIDFILE" ]; then
269 boot_mesg
"Createing VLAN Interface ${DEVICE}.8 ..."
270 vconfig add
${DEVICE} 8
272 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.8 interface..."
274 /sbin
/dhcpcd
${DEVICE}.8 ${DHCP_START} >/dev
/null
2>&1
277 if [ "$RET" = "0" ]; then
278 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.8.info
281 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.8:"
283 boot_mesg
" IP Address: $IPADDR"
285 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
287 boot_mesg
" Subnet Mask: $NETMASK"
289 boot_mesg
" Default Gateway: $GATEWAY"
291 boot_mesg
" DNS Server: $DNS"
302 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
304 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
305 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
307 if [ "$TYPE" == "pppoeatm" ]; then
310 if [ "$TYPE" == "pptpatm" ]; then
314 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
315 if [ "$PPP_NIC" == "" ]; then
316 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
320 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
321 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
322 if [ "$TYPE" == "pptp" ]; then
323 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
325 ip link
set ${PPP_NIC} up
327 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
331 ### Configuring the pppd ###
336 if [ "$TYPE" == "pppoe" ]; then
337 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
338 PLUGOPTS
="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so"
346 ### Access Concentrator Name
348 if [ -n "${CONCENTRATORNAME}" ]; then
349 ACNAME
="-C ${CONCENTRATORNAME}"
354 if [ -n "${SERVICENAME}" ]; then
355 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
356 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
358 SERVICENAME
="-S ${SERVICENAME}"
362 ### Authentication Types
364 if [ "${AUTH}" == "pap" ]; then
366 elif [ "${AUTH}" == "chap" ]; then
374 if [ "${DNS}" == "Automatic" ]; then
378 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
379 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
384 if [ "${RECONNECTION}" != "persistent" ]; then
385 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
386 SECONDS
=$
[${TIMEOUT} * 60]
390 if [ "${RECONNECTION}" == "dialondemand" ]; then
391 touch /var
/ipfire
/red
/dial-on-demand
392 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
393 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
397 if [ "$TYPE" == "pppoe" ]; then
398 ### When using pppoe-plugin the device has to be the last option
400 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
403 if [ "$TYPE" == "modem" ]; then
404 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
405 METHOD
="PPPOE_PLUGIN"
406 elif [ "$TYPE" == "serial" ]; then
407 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
408 METHOD
="PPPOE_PLUGIN"
411 ### Standard PPP options we always use
413 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
414 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
415 PPP_STD_OPTIONS
+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
416 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
417 PPP_STD_OPTIONS
+=" lcp-echo-failure 3 ${AUTH}"
421 if [ "${DEBUG}" == "on" ]; then
429 if [ "$TYPE" == "pppoe" ]; then
430 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
431 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
436 if [ "$TYPE" == "pptp" ]; then
437 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
443 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
444 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
446 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
448 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
450 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
452 ## Create & Enable vnstat
453 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
454 /etc
/rc.d
/init.d
/connectd start
455 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
456 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
457 $
(date +%s
):: > /dev
/null
2>&1
463 if [ "$TYPE" == "STATIC" ]; then
464 boot_mesg
"Stopping default gateway ${GATEWAY}..."
465 ip route del default via
${GATEWAY} >/dev
/null
2>&1
467 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
468 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
469 ip addr flush dev
${DEVICE}
472 run_subdir
${rc_base}/init.d
/networking
/red.down
/
474 elif [ "$TYPE" == "DHCP" ]; then
475 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
476 if [ -e $LEASEINFO ]; then
478 if [ "$LEASETIME" = "4294967295" ]; then
479 # do nothing, just echo ok
483 if [ -n "$DHCP_STOP" ]; then
484 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
486 if [ "$RET" -eq 0 ]; then
489 elif [ "$RET" -eq 1 ]; then
490 boot_mesg
"dhcpcd not running!" ${WARNING}
502 boot_mesg
-n "LEASEINFO Test failed! - " ${WARNING}
503 boot_mesg
"dhcpcd is not running!" ${WARNING}
507 elif [ "$TYPE" == "PPPOE" ]; then
508 boot_mesg
"Bringing down the PPP interface ..."
509 ## Disable vnstat collection
510 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
511 rm -f /var
/ipfire
/red
/keepconnected
512 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
514 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
515 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
516 $
(date +%s
):: > /dev
/null
2>&1
519 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
520 link_status
=`ip link show $DEVICE.7 2> /dev/null`
521 if [ -n "${link_status}" ]; then
522 if echo "${link_status}" |
grep -q UP
; then
523 boot_mesg
"Bringing down the ${DEVICE}.7 interface..."
524 ip link
set ${DEVICE}.7 down
525 vconfig del
${DEVICE} 7
529 link_status
=`ip link show $DEVICE 2> /dev/null`
530 if [ -n "${link_status}" ]; then
531 if echo "${link_status}" |
grep -q UP
; then
532 boot_mesg
"Bringing down the ${DEVICE} interface..."
533 ip link
set ${DEVICE} down
539 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
540 killall
-w -s KILL pptp
>/dev
/null
2>&1
541 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
543 ## Disable vnstat collection
544 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
546 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}