]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/networking/red
554ff4b1b8e7331750b50cb8ff90720e0ba931e9
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
/dns
/settings
)
30 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/mac
/settings
)
37 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
38 if [ "$DEVICE" == "" ]; then
39 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
41 [ "${1}" == "start" ] && exit 0
45 if [ "${TYPE}" == "STATIC" ]; then
46 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
47 ADDRESS
="${RED_ADDRESS}"
48 BROADCAST
="${RED_BROADCAST}"
49 NETADDRESS
="${RED_NETADDRESS}"
50 NETMASK
="${RED_NETMASK}"
52 ADDRESS
="${GREEN_ADDRESS}"
53 BROADCAST
="${GREEN_BROADCAST}"
54 NETADDRESS
="${GREEN_NETADDRESS}"
55 NETMASK
="${GREEN_NETMASK}"
57 GATEWAY
="${DEFAULT_GATEWAY}"
61 if [ -z "${BROADCAST}" ]; then
62 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
66 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
67 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
68 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
70 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
75 elif [ "${TYPE}" == "DHCP" ]; then
77 PIDFILE
="/var/run/dhcpcd-${DEVICE}.pid"
78 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
79 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
80 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
86 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
87 boot_mesg
"Bringing up the ${DEVICE} interface..."
89 # Check if an interface is there...
90 if ip link show
${DEVICE} > /dev
/null
2>&1; then
91 link_status
=`ip link show ${DEVICE} 2> /dev/null`
92 if [ -n "${link_status}" ]; then
93 if ! echo "${link_status}" |
grep -q UP
; then
94 if [ -n "$MAC" ]; then
95 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
96 ip link
set dev
${DEVICE} address
${MAC}
100 ip link
set ${DEVICE} up
104 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
110 ## Create & Enable vnstat
111 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
113 if [ "${TYPE}" == "STATIC" ]; then
115 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
116 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
117 ip addr add
${args} dev
${DEVICE}
120 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
121 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
122 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
123 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
124 echo "$GATEWAY gateway" >> /tmp
/hosts
125 mv /tmp
/hosts
/etc
/hosts
126 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
127 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
128 touch /var
/ipfire
/red
/active
130 boot_mesg
"Setting up default gateway ${GATEWAY}..."
131 ip route add default via
${GATEWAY} dev
${DEVICE}
134 run_subdir
${rc_base}/init.d
/networking
/red.up
/
136 # Configure aliases only if red static
137 /usr
/local
/bin
/setaliases
139 elif [ "${TYPE}" == "DHCP" ]; then
141 if [ -e $LEASEINFO ]; then
142 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
144 if [ "$LEASETIME" = "4294967295" ]; then
145 # do nothing, just echo ok
149 if [ -n "$DHCP_STOP" ]; then
150 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
152 if [ "$RET" -eq 0 ]; then
155 elif [ "$RET" -eq 1 ]; then
156 boot_mesg
"dhcpcd not running!" ${WARNING}
169 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
170 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
172 ## Create & Enable vnstat
173 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
175 # Test to see if there is a stale pid file
176 if [ -f "$PIDFILE" ]; then
177 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
179 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
181 boot_mesg
"dhcpcd already running!" ${WARNING}
187 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
188 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
190 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
191 DHCP_START
+="-h ${RED_DHCP_HOSTNAME} "
194 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
197 if [ "$RET" = "0" ]; then
198 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
201 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
203 boot_mesg
" IP Address: $IPADDR"
205 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
206 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
209 boot_mesg
" Subnet Mask: $NETMASK"
211 boot_mesg
" Default Gateway: $GATEWAY"
213 boot_mesg
" DNS Server: $DNS"
215 if [ -n "$DNS0" ] && [ -n "$DNS1" ]; then
216 boot_mesg
"Overwritting DNS-Server addresses with ${DNS0},${DNS1}"
217 echo -n ${DNS0} > /var
/ipfire
/red
/dns1
218 echo -n ${DNS1} > /var
/ipfire
/red
/dns2
221 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var
/ipfire
/red
/dns1
222 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var
/ipfire
/red
/dns2
225 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
226 echo "$IPADDR" > /var
/ipfire
/red
/local-ipaddress
227 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
228 echo "$GATEWAY gateway" >> /tmp
/hosts
229 mv /tmp
/hosts
/etc
/hosts
230 echo "$GATEWAY" > /var
/ipfire
/red
/remote-ipaddress
231 touch /var
/ipfire
/red
/active
238 elif [ "$TYPE" == "PPPOE" ]; then
240 if ( ps ax |
grep -q [p
]ppd
); then
241 boot_mesg
"pppd is still running." ${FAILURE}
246 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
248 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
252 if [ "$TYPE" == "vdsl" ]; then
253 boot_mesg
"Createing VLAN Interface ${DEVICE}.7 ..."
255 vconfig add
${DEVICE} 7
258 ip link
set ${PPP_NIC} up
262 PIDFILE
="/var/run/dhcpcd-${DEVICE}.8.pid"
263 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.8.info"
264 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
265 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
268 # Test to see if there is a stale pid file
269 if [ -f "$PIDFILE" ]; then
270 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
272 rm -f /var
/run
/dhcpcd-
${DEVICE}.8.pid
> /dev
/null
275 if [ ! -f "$PIDFILE" ]; then
277 boot_mesg
"Createing VLAN Interface ${DEVICE}.8 ..."
278 vconfig add
${DEVICE} 8
280 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.8 interface..."
282 /sbin
/dhcpcd
${DEVICE}.8 ${DHCP_START} >/dev
/null
2>&1
285 if [ "$RET" = "0" ]; then
286 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.8.info
289 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.8:"
291 boot_mesg
" IP Address: $IPADDR"
293 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
295 boot_mesg
" Subnet Mask: $NETMASK"
297 boot_mesg
" Default Gateway: $GATEWAY"
299 boot_mesg
" DNS Server: $DNS"
310 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
312 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
313 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
315 if [ "$TYPE" == "pppoeatm" ]; then
318 if [ "$TYPE" == "pptpatm" ]; then
322 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
323 if [ "$PPP_NIC" == "" ]; then
324 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
328 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
329 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
330 if [ "$TYPE" == "pptp" ]; then
331 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
333 ip link
set ${PPP_NIC} up
335 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
339 ### Configuring the pppd ###
344 if [ "$TYPE" == "pppoe" ]; then
345 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
346 PLUGOPTS
="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so"
354 ### Access Concentrator Name
356 if [ -n "${CONCENTRATORNAME}" ]; then
357 ACNAME
="-C ${CONCENTRATORNAME}"
362 if [ -n "${SERVICENAME}" ]; then
363 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
364 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
366 SERVICENAME
="-S ${SERVICENAME}"
370 ### Authentication Types
372 if [ "${AUTH}" == "pap" ]; then
374 elif [ "${AUTH}" == "chap" ]; then
382 if [ "${DNS}" == "Automatic" ]; then
386 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
387 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
392 if [ "${RECONNECTION}" != "persistent" ]; then
393 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
394 SECONDS
=$
[${TIMEOUT} * 60]
398 if [ "${RECONNECTION}" == "dialondemand" ]; then
399 touch /var
/ipfire
/red
/dial-on-demand
400 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
401 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
405 if [ "$TYPE" == "pppoe" ]; then
406 ### When using pppoe-plugin the device has to be the last option
408 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
411 if [ "$TYPE" == "modem" ]; then
412 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
413 METHOD
="PPPOE_PLUGIN"
414 elif [ "$TYPE" == "serial" ]; then
415 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
416 METHOD
="PPPOE_PLUGIN"
419 ### Standard PPP options we always use
421 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
422 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
423 PPP_STD_OPTIONS
+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
424 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
425 PPP_STD_OPTIONS
+=" lcp-echo-failure 3 ${AUTH}"
429 if [ "${DEBUG}" == "on" ]; then
437 if [ "$TYPE" == "pppoe" ]; then
438 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
439 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
444 if [ "$TYPE" == "pptp" ]; then
445 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
451 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
452 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
454 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
456 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
458 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
460 ## Create & Enable vnstat
461 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
462 /etc
/rc.d
/init.d
/connectd start
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
471 if [ "$TYPE" == "STATIC" ]; then
472 boot_mesg
"Stopping default gateway ${GATEWAY}..."
473 ip route del default via
${GATEWAY} >/dev
/null
2>&1
475 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
476 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
477 ip addr flush dev
${DEVICE}
480 run_subdir
${rc_base}/init.d
/networking
/red.down
/
482 elif [ "$TYPE" == "DHCP" ]; then
483 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
484 if [ -e $LEASEINFO ]; then
486 if [ "$LEASETIME" = "4294967295" ]; then
487 # do nothing, just echo ok
491 if [ -n "$DHCP_STOP" ]; then
492 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
494 if [ "$RET" -eq 0 ]; then
497 elif [ "$RET" -eq 1 ]; then
498 boot_mesg
"dhcpcd not running!" ${WARNING}
510 boot_mesg
-n "LEASEINFO Test failed! - " ${WARNING}
511 boot_mesg
"dhcpcd is not running!" ${WARNING}
515 elif [ "$TYPE" == "PPPOE" ]; then
516 boot_mesg
"Bringing down the PPP interface ..."
517 ## Disable vnstat collection
518 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
519 rm -f /var
/ipfire
/red
/keepconnected
520 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
522 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
523 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
524 $
(date +%s
):: > /dev
/null
2>&1
527 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
528 link_status
=`ip link show $DEVICE.7 2> /dev/null`
529 if [ -n "${link_status}" ]; then
530 if echo "${link_status}" |
grep -q UP
; then
531 boot_mesg
"Bringing down the ${DEVICE}.7 interface..."
532 ip link
set ${DEVICE}.7 down
533 vconfig del
${DEVICE} 7
537 link_status
=`ip link show $DEVICE 2> /dev/null`
538 if [ -n "${link_status}" ]; then
539 if echo "${link_status}" |
grep -q UP
; then
540 boot_mesg
"Bringing down the ${DEVICE} interface..."
541 ip link
set ${DEVICE} down
547 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
548 killall
-w -s KILL pptp
>/dev
/null
2>&1
549 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
551 ## Disable vnstat collection
552 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
554 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}