]>
git.ipfire.org Git - people/teissler/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 ########################################################################
25 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/main
/settings
)
26 if [ "$RRDLOG" == "" ]; then
30 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
31 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/dns
/settings
)
32 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/mac
/settings
)
35 MAC1
=$
(tr - : <<<$MAC1)
36 MAC2
=$
(tr - : <<<$MAC2)
41 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
42 if [ "$DEVICE" == "" ]; then
43 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
45 [ "${1}" == "start" ] && exit 0
49 if [ "${TYPE}" == "STATIC" ]; then
50 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
51 ADDRESS
="${RED_ADDRESS}"
52 BROADCAST
="${RED_BROADCAST}"
53 NETADDRESS
="${RED_NETADDRESS}"
54 NETMASK
="${RED_NETMASK}"
56 ADDRESS
="${GREEN_ADDRESS}"
57 BROADCAST
="${GREEN_BROADCAST}"
58 NETADDRESS
="${GREEN_NETADDRESS}"
59 NETMASK
="${GREEN_NETMASK}"
61 GATEWAY
="${DEFAULT_GATEWAY}"
65 if [ -z "${BROADCAST}" ]; then
66 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
70 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
71 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
72 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
74 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
80 PIDFILE
="/var/run/dhcpcd-${DEVICE}.pid"
81 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
87 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
88 boot_mesg
"Bringing up the ${DEVICE} interface..."
90 # Check if an interface is there...
91 if ip link show
${DEVICE} > /dev
/null
2>&1; then
92 link_status
=`ip link show ${DEVICE} 2> /dev/null`
93 if [ -n "${link_status}" ]; then
94 if ! echo "${link_status}" |
grep -q UP
; then
95 if [ -n "$MAC" ]; then
96 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
97 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 [ "$dhcp_lease_time" = "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: $ip_address"
205 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
206 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
209 boot_mesg
" Subnet Mask: $subnet_mask"
211 boot_mesg
" Default Gateway: $routers"
213 boot_mesg
" DNS Server: $domain_name_servers"
221 elif [ "$TYPE" == "PPPOE" ]; then
223 if ( ps ax |
grep -q [p
]ppd
); then
224 boot_mesg
"pppd is still running." ${FAILURE}
229 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
231 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
233 # We force the plugin method, anyway.
234 METHOD
="PPPOE_PLUGIN"
239 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
242 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
243 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
245 if [ "$TYPE" == "pppoeatm" ]; then
248 if [ "$TYPE" == "pptpatm" ]; then
253 if [ "$TYPE" == "vdsl" ]; then
254 boot_mesg
"Createing VLAN Interface ${DEVICE}.${INET_VLAN} ..."
256 vconfig add
${DEVICE} ${INET_VLAN}
257 if [ -n "$MAC1" ]; then
258 boot_mesg
"Setting mac address on ${DEVICE}.${INET_VLAN} to ${MAC1}"
259 ip link
set dev
${DEVICE}.${INET_VLAN} address ${MAC1}
262 PPP_NIC
=${DEVICE}.
${INET_VLAN}
264 ip link
set ${PPP_NIC} up
267 if [ "${IPTV}" == "enable" ]; then
268 PIDFILE
="/var/run/dhcpcd-${DEVICE}.${IPTV_VLAN}.pid"
269 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info"
270 # Test to see if there is a stale pid file
271 if [ -f "$PIDFILE" ]; then
272 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
274 rm -f /var
/run
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.pid
> /dev
/null
278 if [ ! -f "$PIDFILE" ]; then
279 boot_mesg
"Createing VLAN Interface ${DEVICE}.${IPTV_VLAN} ..."
281 vconfig add
${DEVICE} ${IPTV_VLAN}
282 if [ -n "$MAC2" ]; then
283 boot_mesg
"Setting mac address on ${DEVICE}.${IPTV_VLAN} to ${MAC2}"
284 ip link
set dev
${DEVICE}.${IPTV_VLAN} address ${MAC2}
287 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.${IPTV_VLAN} interface..."
288 /sbin
/dhcpcd
${DEVICE}.${IPTV_VLAN} ${DHCP_START} >/dev
/null
2>&1
291 if [ "$RET" = "0" ]; then
292 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.info
295 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.${IPTV_VLAN}:"
297 boot_mesg
" IP Address: $ip_address"
299 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
301 boot_mesg
" Subnet Mask: $subnet_mask"
303 boot_mesg
" Default Gateway: $routers"
305 boot_mesg
" DNS Server: $domain_name_servers"
315 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
316 if [ "$PPP_NIC" == "" ]; then
317 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
321 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
322 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
323 if [ "$TYPE" == "pptp" ]; then
324 if [ "$PPTP_NICCFG" == "dhcp" ]; then
325 # Test to see if there is a stale pid file
326 if [ -f "$PIDFILE" ]; then
327 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
329 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
333 if [ ! -f "$PIDFILE" ]; then
334 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
335 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
338 if [ "$RET" = "0" ]; then
339 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
342 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
344 boot_mesg
" IP Address: $ip_address"
346 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
348 boot_mesg
" Subnet Mask: $subnet_mask"
350 boot_mesg
" Default Gateway: $routers"
352 boot_mesg
" DNS Server: $domain_name_servers"
354 /sbin
/route add
$PPTP_PEER gw
$routers $PPP_NIC
362 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
365 ip link
set ${PPP_NIC} up
366 if [ -n "${PPTP_ROUTE}" ]; then
367 boot_mesg
"Set route ${PPTP_ROUTE} to pptp server..."
368 route add
${PPTP_ROUTE}
371 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
375 ### Configuring the pppd ###
380 if [ "$TYPE" == "pppoe" ]; then
381 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
382 PLUGOPTS
="plugin rp-pppoe.so"
390 ### Access Concentrator Name
392 if [ -n "${CONCENTRATORNAME}" ]; then
393 ACNAME
="-C ${CONCENTRATORNAME}"
398 if [ -n "${SERVICENAME}" ]; then
399 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
400 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
402 SERVICENAME
="-S ${SERVICENAME}"
406 ### Authentication Types
408 if [ "${AUTH}" == "pap" ]; then
410 elif [ "${AUTH}" == "chap" ]; then
418 if [ "${DNS}" == "Automatic" ]; then
422 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
423 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
428 if [ "${RECONNECTION}" != "persistent" ]; then
429 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
430 SECONDS
=$
[${TIMEOUT} * 60]
434 if [ "${RECONNECTION}" == "dialondemand" ]; then
435 touch /var
/ipfire
/red
/dial-on-demand
436 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
437 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
441 if [ "$TYPE" == "pppoe" ]; then
442 ### When using pppoe-plugin the device has to be the last option
444 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
447 if [ "$TYPE" == "modem" ]; then
448 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
449 METHOD
="PPPOE_PLUGIN"
450 elif [ "$TYPE" == "serial" ]; then
451 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
452 METHOD
="PPPOE_PLUGIN"
455 ### Standard PPP options we always use
457 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
458 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
459 PPP_STD_OPTIONS
+=" mru ${MRU} noaccomp nodeflate nopcomp novj novjccomp"
460 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
461 PPP_STD_OPTIONS
+=" lcp-echo-failure 5 ${AUTH}"
465 if [ "${DEBUG}" == "on" ]; then
473 if [ "$TYPE" == "pppoe" ]; then
474 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
475 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
480 if [ "$TYPE" == "pptp" ]; then
481 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
487 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
488 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
490 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
492 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
494 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
496 ## Create & Enable vnstat
497 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
498 /etc
/rc.d
/init.d
/connectd start
499 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
500 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
501 $
(date +%s
):: > /dev
/null
2>&1
507 if [ "$TYPE" == "STATIC" ]; then
508 boot_mesg
"Stopping default gateway ${GATEWAY}..."
509 ip route del default via
${GATEWAY} >/dev
/null
2>&1
511 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
512 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
513 ip addr flush dev
${DEVICE}
516 run_subdir
${rc_base}/init.d
/networking
/red.down
/
518 elif [ "$TYPE" == "PPPOE" ]; then
519 boot_mesg
"Bringing down the PPP interface ..."
520 ## Disable vnstat collection
521 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
522 rm -f /var
/ipfire
/red
/keepconnected
523 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
525 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
526 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
527 $
(date +%s
):: > /dev
/null
2>&1
530 if [ -e $LEASEINFO ]; then
531 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
533 if [ "$dchp_lease_time" = "4294967295" ]; then
534 # do nothing, just echo ok
538 if [ -n "$DHCP_STOP" ]; then
539 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
541 if [ "$RET" -eq 0 ]; then
544 elif [ "$RET" -eq 1 ]; then
545 boot_mesg
"dhcpcd not running!" ${WARNING}
558 if [ -n "${PPTP_ROUTE}" ]; then
559 route del
${PPTP_ROUTE}
562 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
563 link_status
=`ip link show $DEVICE.${INET_VLAN} 2> /dev/null`
564 if [ -n "${link_status}" ]; then
565 if echo "${link_status}" |
grep -q UP
; then
566 boot_mesg
"Bringing down the ${DEVICE}.${INET_VLAN} interface..."
567 ip link
set ${DEVICE}.
${INET_VLAN} down
568 vconfig rem
${DEVICE}.
${INET_VLAN}
572 link_status
=`ip link show $DEVICE 2> /dev/null`
573 if [ -n "${link_status}" ]; then
574 if echo "${link_status}" |
grep -q UP
; then
575 boot_mesg
"Bringing down the ${DEVICE} interface..."
576 ip link
set ${DEVICE} down
582 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
583 killall
-w -s KILL pptp
>/dev
/null
2>&1
584 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
586 ## Disable vnstat collection
587 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
589 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}