]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/init.d/networking/red
b33c03f136f67168490f6001c42f82256338dca0
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 ########################################################################
20 .
/etc
/init.d
/networking
/functions.network
26 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/main
/settings
)
27 if [ "$RRDLOG" == "" ]; then
31 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
32 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/dns
/settings
)
33 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/mac
/settings
)
36 MAC1
=$
(tr - : <<<$MAC1)
37 MAC2
=$
(tr - : <<<$MAC2)
42 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
43 if [ "$DEVICE" == "" ]; then
44 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
46 [ "${1}" == "start" ] && exit 0
50 if [ "${TYPE}" == "STATIC" ]; then
51 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
52 ADDRESS
="${RED_ADDRESS}"
53 BROADCAST
="${RED_BROADCAST}"
54 NETADDRESS
="${RED_NETADDRESS}"
55 NETMASK
="${RED_NETMASK}"
57 ADDRESS
="${GREEN_ADDRESS}"
58 BROADCAST
="${GREEN_BROADCAST}"
59 NETADDRESS
="${GREEN_NETADDRESS}"
60 NETMASK
="${GREEN_NETMASK}"
62 GATEWAY
="${DEFAULT_GATEWAY}"
66 if [ -z "${BROADCAST}" ]; then
67 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
71 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
72 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
73 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
75 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
83 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
84 boot_mesg
"Bringing up the ${DEVICE} interface..."
86 # Check if an interface is there...
87 if ip link show
${DEVICE} > /dev
/null
2>&1; then
88 link_status
=`ip link show ${DEVICE} 2> /dev/null`
89 if [ -n "${link_status}" ]; then
90 if ! echo "${link_status}" |
grep -q UP
; then
91 if [ -n "$MAC" ]; then
92 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
93 ip link
set dev
${DEVICE} address
${MAC}
96 ip link
set ${DEVICE} up
100 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
106 ## Create & Enable vnstat
107 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
109 if [ "${TYPE}" == "STATIC" ]; then
111 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
112 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
113 ip addr add
${args} dev
${DEVICE}
116 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
117 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
118 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
119 grep -v -E "\<gateway\>" /etc
/hosts
> /tmp
/hosts
120 echo "$GATEWAY gateway" >> /tmp
/hosts
121 mv /tmp
/hosts
/etc
/hosts
122 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
123 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
124 touch /var
/ipfire
/red
/active
126 boot_mesg
"Setting up default gateway ${GATEWAY}..."
127 ip route add default via
${GATEWAY} dev
${DEVICE}
130 run_subdir
${rc_base}/init.d
/networking
/red.up
/
132 # Configure aliases only if red static
133 /usr
/local
/bin
/setaliases
135 elif [ "${TYPE}" == "DHCP" ]; then
136 # Add firewall rules to allow comunication with the dhcp server on red.
137 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
138 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
140 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
142 # Check if the wlan-client is used on red.
143 # To determine this we check if a wpa_supplicant is running.
144 pid
="$(pidof wpa_supplicant)"
146 if [ -z "${pid}" ]; then
147 # No wpa_supplicant is running. So it's save to start dhcpcd.
148 dhcpcd_start
"${DEVICE}"
151 ## Create & Enable vnstat
152 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
154 elif [ "$TYPE" == "PPPOE" ]; then
156 if ( ps ax |
grep -q [p
]ppd
); then
157 boot_mesg
"pppd is still running." ${FAILURE}
162 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
164 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
166 # We force the plugin method, anyway.
167 METHOD
="PPPOE_PLUGIN"
172 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
175 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
176 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
178 if [ "$TYPE" == "pppoeatm" ]; then
181 if [ "$TYPE" == "pptpatm" ]; then
186 if [ "$TYPE" == "vdsl" ]; then
187 boot_mesg
"Createing VLAN Interface ${DEVICE}.${INET_VLAN} ..."
189 vconfig add
${DEVICE} ${INET_VLAN}
190 if [ -n "$MAC1" ]; then
191 boot_mesg
"Setting mac address on ${DEVICE}.${INET_VLAN} to ${MAC1}"
192 ip link
set dev
${DEVICE}.${INET_VLAN} address ${MAC1}
195 PPP_NIC
=${DEVICE}.
${INET_VLAN}
197 ip link
set ${PPP_NIC} up
200 if [ "${IPTV}" == "enable" ]; then
201 PIDFILE
="/var/run/dhcpcd-${DEVICE}.${IPTV_VLAN}.pid"
202 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info"
203 # Test to see if there is a stale pid file
204 if [ -f "$PIDFILE" ]; then
205 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
207 rm -f /var
/run
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.pid
> /dev
/null
211 if [ ! -f "$PIDFILE" ]; then
212 boot_mesg
"Createing VLAN Interface ${DEVICE}.${IPTV_VLAN} ..."
214 vconfig add
${DEVICE} ${IPTV_VLAN}
215 if [ -n "$MAC2" ]; then
216 boot_mesg
"Setting mac address on ${DEVICE}.${IPTV_VLAN} to ${MAC2}"
217 ip link
set dev
${DEVICE}.${IPTV_VLAN} address ${MAC2}
220 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.${IPTV_VLAN} interface..."
221 /sbin
/dhcpcd
${DEVICE}.${IPTV_VLAN} ${DHCP_START} >/dev
/null
2>&1
224 if [ "$RET" = "0" ]; then
225 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.info
228 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.${IPTV_VLAN}:"
230 boot_mesg
" IP Address: $ip_address"
232 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
234 boot_mesg
" Subnet Mask: $subnet_mask"
236 boot_mesg
" Default Gateway: $routers"
238 boot_mesg
" DNS Server: $domain_name_servers"
248 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
249 if [ "$PPP_NIC" == "" ]; then
250 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
254 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
255 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
256 if [ "$TYPE" == "pptp" ]; then
257 if [ "$PPTP_NICCFG" == "dhcp" ]; then
258 # Test to see if there is a stale pid file
259 if [ -f "$PIDFILE" ]; then
260 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
262 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
266 if [ ! -f "$PIDFILE" ]; then
267 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
268 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
271 if [ "$RET" = "0" ]; then
272 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
275 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
277 boot_mesg
" IP Address: $ip_address"
279 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
281 boot_mesg
" Subnet Mask: $subnet_mask"
283 boot_mesg
" Default Gateway: $routers"
285 boot_mesg
" DNS Server: $domain_name_servers"
287 /sbin
/route add
$PPTP_PEER gw
$routers $PPP_NIC
295 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
298 ip link
set ${PPP_NIC} up
299 if [ -n "${PPTP_ROUTE}" ]; then
300 boot_mesg
"Set route ${PPTP_ROUTE} to pptp server..."
301 route add
${PPTP_ROUTE}
304 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
308 ### Configuring the pppd ###
313 if [ "$TYPE" == "pppoe" ]; then
314 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
315 PLUGOPTS
="plugin rp-pppoe.so"
323 ### Access Concentrator Name
325 if [ -n "${CONCENTRATORNAME}" ]; then
326 ACNAME
="-C ${CONCENTRATORNAME}"
331 if [ -n "${SERVICENAME}" ]; then
332 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
333 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
335 SERVICENAME
="-S ${SERVICENAME}"
339 ### Authentication Types
341 if [ "${AUTH}" == "pap" ]; then
343 elif [ "${AUTH}" == "chap" ]; then
351 if [ "${DNS}" == "Automatic" ]; then
355 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
356 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
361 if [ "${RECONNECTION}" != "persistent" ]; then
362 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
363 SECONDS
=$
[${TIMEOUT} * 60]
367 if [ "${RECONNECTION}" == "dialondemand" ]; then
368 touch /var
/ipfire
/red
/dial-on-demand
369 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
370 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
374 if [ "$TYPE" == "pppoe" ]; then
375 ### When using pppoe-plugin the device has to be the last option
377 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
380 if [ "$TYPE" == "modem" ]; then
381 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
382 METHOD
="PPPOE_PLUGIN"
383 elif [ "$TYPE" == "serial" ]; then
384 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
385 METHOD
="PPPOE_PLUGIN"
388 ### Standard PPP options we always use
390 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
391 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach"
392 PPP_STD_OPTIONS
+=" mru ${MRU} noaccomp nodeflate nopcomp novj novjccomp"
393 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
394 PPP_STD_OPTIONS
+=" lcp-echo-failure 5 ${AUTH}"
396 if [ -n "${MTU}" ]; then
397 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mtu ${MTU}"
400 if [ -n "${MRU}" ]; then
401 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mru ${MRU}"
406 if [ "${DEBUG}" == "on" ]; then
414 if [ "$TYPE" == "pppoe" ]; then
415 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
416 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
421 if [ "$TYPE" == "pptp" ]; then
422 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
428 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
429 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
431 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
433 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
435 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
437 ## Create & Enable vnstat
438 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
439 /etc
/rc.d
/init.d
/connectd start
440 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
441 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
442 $
(date +%s
):: > /dev
/null
2>&1
448 if [ "$TYPE" == "STATIC" ]; then
449 boot_mesg
"Stopping default gateway ${GATEWAY}..."
450 ip route del default via
${GATEWAY} >/dev
/null
2>&1
452 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
453 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
454 ip addr flush dev
${DEVICE}
457 run_subdir
${rc_base}/init.d
/networking
/red.down
/
459 elif [ "$TYPE" == "PPPOE" ]; then
460 boot_mesg
"Bringing down the PPP interface ..."
461 ## Disable vnstat collection
462 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
463 rm -f /var
/ipfire
/red
/keepconnected
464 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
466 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
467 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
468 $
(date +%s
):: > /dev
/null
2>&1
470 elif [ "$TYPE" == "DHCP" ]; then
471 # Check if the wlan-client is used on red.
472 # To determine this we check if a wpa_supplicant is running.
473 pid
="$(pidof wpa_supplicant)"
475 if [ -z "${pid}" ]; then
477 dhcpcd_stop
"${DEVICE}"
481 if [ -n "${PPTP_ROUTE}" ]; then
482 route del
${PPTP_ROUTE}
485 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
486 link_status
=`ip link show $DEVICE.${INET_VLAN} 2> /dev/null`
487 if [ -n "${link_status}" ]; then
488 if echo "${link_status}" |
grep -q UP
; then
489 boot_mesg
"Bringing down the ${DEVICE}.${INET_VLAN} interface..."
490 ip link
set ${DEVICE}.
${INET_VLAN} down
491 vconfig rem
${DEVICE}.
${INET_VLAN}
495 link_status
=`ip link show $DEVICE 2> /dev/null`
496 if [ -n "${link_status}" ]; then
497 if echo "${link_status}" |
grep -q UP
; then
498 boot_mesg
"Bringing down the ${DEVICE} interface..."
499 ip link
set ${DEVICE} down
505 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
506 killall
-w -s KILL pptp
>/dev
/null
2>&1
507 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
509 ## Disable vnstat collection
510 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
512 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}