]>
git.ipfire.org Git - 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 ########################################################################
20 .
/etc
/init.d
/networking
/functions.network
27 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/main
/settings
)
28 if [ "$RRDLOG" == "" ]; then
32 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
33 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/dns
/settings
)
34 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/mac
/settings
)
37 MAC1
=$
(tr - : <<<$MAC1)
38 MAC2
=$
(tr - : <<<$MAC2)
43 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
44 if [ "$DEVICE" == "" ]; then
45 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
47 [ "${1}" == "start" ] && exit 0
51 if [ "${TYPE}" == "STATIC" ]; then
52 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
53 ADDRESS
="${RED_ADDRESS}"
54 BROADCAST
="${RED_BROADCAST}"
55 NETADDRESS
="${RED_NETADDRESS}"
56 NETMASK
="${RED_NETMASK}"
58 ADDRESS
="${GREEN_ADDRESS}"
59 BROADCAST
="${GREEN_BROADCAST}"
60 NETADDRESS
="${GREEN_NETADDRESS}"
61 NETMASK
="${GREEN_NETMASK}"
63 GATEWAY
="${DEFAULT_GATEWAY}"
67 if [ -z "${BROADCAST}" ]; then
68 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
72 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
73 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
74 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
76 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
84 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
85 boot_mesg
"Bringing up the ${DEVICE} interface..."
87 # Check if an interface is there...
88 if ip link show
${DEVICE} > /dev
/null
2>&1; then
89 link_status
=`ip link show ${DEVICE} 2> /dev/null`
90 if [ -n "${link_status}" ]; then
91 if ! echo "${link_status}" |
grep -q UP
; then
92 if [ -n "$MAC" ]; then
93 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
94 ip link
set dev
${DEVICE} address
${MAC}
97 ip link
set ${DEVICE} up
101 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
107 ## Create & Enable vnstat
108 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
110 if [ "${TYPE}" == "STATIC" ]; then
112 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
113 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
114 ip addr add
${args} dev
${DEVICE}
117 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
118 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
119 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
120 grep -v -E "\<gateway\>" /etc
/hosts
> /tmp
/hosts
121 echo "$GATEWAY gateway" >> /tmp
/hosts
122 mv /tmp
/hosts
/etc
/hosts
123 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
124 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
125 touch /var
/ipfire
/red
/active
127 boot_mesg
"Setting up default gateway ${GATEWAY}..."
128 ip route add default via
${GATEWAY} dev
${DEVICE}
131 run_subdir
${rc_base}/init.d
/networking
/red.up
/
133 # Configure aliases only if red static
134 /usr
/local
/bin
/setaliases
136 elif [ "${TYPE}" == "DHCP" ]; then
137 # Add firewall rules to allow comunication with the dhcp server on red.
138 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
139 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
141 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
143 # Check if the wlan-client is used on red.
144 # To determine this we check if a wpa_supplicant is running.
145 pid
="$(pidof wpa_supplicant)"
147 if [ -z "${pid}" ]; then
148 # No wpa_supplicant is running. So it's save to start dhcpcd.
149 dhcpcd_start
"${DEVICE}"
152 ## Create & Enable vnstat
153 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
155 elif [ "$TYPE" == "PPPOE" ]; then
157 if ( ps ax |
grep -q [p
]ppd
); then
158 boot_mesg
"pppd is still running." ${FAILURE}
163 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
165 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
167 # We force the plugin method, anyway.
168 METHOD
="PPPOE_PLUGIN"
173 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
174 PPP_NIC
=nas
${ATM_DEV}
176 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
177 br2684ctl
-c${ATM_DEV} -e${ENCAP} -a${ATM_DEV}.${VPI}.${VCI} >/dev
/null
2>&1 &
180 # use user-defined or green mac address for nas0
181 if [ -n "$MAC" ]; then
182 ip link
set dev nas
${ATM_DEV} address
${MAC}
184 ip link
set dev nas
${ATM_DEV} address $
(cat /sys
/class
/net
/green
0/address
)
187 if [ "$TYPE" == "pppoeatm" ]; then
190 if [ "$TYPE" == "pptpatm" ]; then
195 if [ "$TYPE" == "vdsl" ]; then
196 boot_mesg
"Createing VLAN Interface ${DEVICE}.${INET_VLAN} ..."
198 vconfig add
${DEVICE} ${INET_VLAN}
199 if [ -n "$MAC1" ]; then
200 boot_mesg
"Setting mac address on ${DEVICE}.${INET_VLAN} to ${MAC1}"
201 ip link
set dev
${DEVICE}.${INET_VLAN} address ${MAC1}
204 PPP_NIC
=${DEVICE}.
${INET_VLAN}
206 ip link
set ${PPP_NIC} up
209 if [ "${IPTV}" == "enable" ]; then
210 PIDFILE
="/var/run/dhcpcd-${DEVICE}.${IPTV_VLAN}.pid"
211 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info"
212 # Test to see if there is a stale pid file
213 if [ -f "$PIDFILE" ]; then
214 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
216 rm -f /var
/run
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.pid
> /dev
/null
220 if [ ! -f "$PIDFILE" ]; then
221 boot_mesg
"Createing VLAN Interface ${DEVICE}.${IPTV_VLAN} ..."
223 vconfig add
${DEVICE} ${IPTV_VLAN}
224 if [ -n "$MAC2" ]; then
225 boot_mesg
"Setting mac address on ${DEVICE}.${IPTV_VLAN} to ${MAC2}"
226 ip link
set dev
${DEVICE}.${IPTV_VLAN} address ${MAC2}
229 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.${IPTV_VLAN} interface..."
230 /sbin
/dhcpcd
${DEVICE}.${IPTV_VLAN} ${DHCP_START} >/dev
/null
2>&1
233 if [ "$RET" = "0" ]; then
234 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.info
237 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.${IPTV_VLAN}:"
239 boot_mesg
" IP Address: $ip_address"
241 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
243 boot_mesg
" Subnet Mask: $subnet_mask"
245 boot_mesg
" Default Gateway: $routers"
247 boot_mesg
" DNS Server: $domain_name_servers"
257 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
258 if [ "$PPP_NIC" == "" ]; then
259 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
263 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
264 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
265 if [ "$TYPE" == "pptp" ]; then
266 if [ "$PPTP_NICCFG" == "dhcp" ]; then
267 # Test to see if there is a stale pid file
268 if [ -f "$PIDFILE" ]; then
269 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
271 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
275 if [ ! -f "$PIDFILE" ]; then
276 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
277 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
280 if [ "$RET" = "0" ]; then
281 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
284 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
286 boot_mesg
" IP Address: $ip_address"
288 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
290 boot_mesg
" Subnet Mask: $subnet_mask"
292 boot_mesg
" Default Gateway: $routers"
294 boot_mesg
" DNS Server: $domain_name_servers"
296 /sbin
/route add
$PPTP_PEER gw
$routers $PPP_NIC
304 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
307 ip link
set ${PPP_NIC} up
308 if [ -n "${PPTP_ROUTE}" ]; then
309 boot_mesg
"Set route ${PPTP_ROUTE} to pptp server..."
310 route add
${PPTP_ROUTE}
313 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
317 ### Configuring the pppd ###
322 if [ "$TYPE" == "pppoe" ]; then
323 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
324 PLUGOPTS
="plugin rp-pppoe.so"
332 ### Access Concentrator Name
334 if [ -n "${CONCENTRATORNAME}" ]; then
335 ACNAME
="-C ${CONCENTRATORNAME}"
340 if [ -n "${SERVICENAME}" ]; then
341 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
342 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
344 SERVICENAME
="-S ${SERVICENAME}"
348 ### Authentication Types
350 if [ "${AUTH}" == "pap" ]; then
352 elif [ "${AUTH}" == "chap" ]; then
360 if [ "${DNS}" == "Automatic" ]; then
364 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
365 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
370 if [ "${RECONNECTION}" != "persistent" ]; then
371 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
372 SECONDS
=$
[${TIMEOUT} * 60]
376 if [ "${RECONNECTION}" == "dialondemand" ]; then
377 touch /var
/ipfire
/red
/dial-on-demand
378 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
379 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
383 if [ "$TYPE" == "pppoe" ]; then
384 ### When using pppoe-plugin the device has to be the last option
386 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
389 if [ "$TYPE" == "modem" ]; then
390 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
391 METHOD
="PPPOE_PLUGIN"
392 elif [ "$TYPE" == "serial" ]; then
393 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
394 METHOD
="PPPOE_PLUGIN"
397 ### Standard PPP options we always use
399 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
400 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach"
401 PPP_STD_OPTIONS
+=" noaccomp nodeflate nopcomp novj novjccomp"
402 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
403 PPP_STD_OPTIONS
+=" lcp-echo-failure 5 ${AUTH}"
405 if [ -n "${MTU}" ]; then
406 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mtu ${MTU}"
409 if [ -n "${MRU}" ]; then
410 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mru ${MRU}"
415 if [ "${DEBUG}" == "on" ]; then
423 if [ "$TYPE" == "pppoe" ]; then
424 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
425 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
430 if [ "$TYPE" == "pptp" ]; then
431 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
437 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
438 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
440 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
442 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
444 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
446 ## Create & Enable vnstat
447 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
448 /etc
/rc.d
/init.d
/connectd start
449 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
450 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
451 $
(date +%s
):: > /dev
/null
2>&1
457 if [ "$TYPE" == "STATIC" ]; then
458 boot_mesg
"Stopping default gateway ${GATEWAY}..."
459 ip route del default via
${GATEWAY} >/dev
/null
2>&1
461 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
462 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
463 ip addr flush dev
${DEVICE}
466 run_subdir
${rc_base}/init.d
/networking
/red.down
/
468 elif [ "$TYPE" == "PPPOE" ]; then
469 boot_mesg
"Bringing down the PPP interface ..."
470 ## Disable vnstat collection
471 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
472 rm -f /var
/ipfire
/red
/keepconnected
473 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
475 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
476 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
477 $
(date +%s
):: > /dev
/null
2>&1
479 elif [ "$TYPE" == "DHCP" ]; then
480 # Check if the wlan-client is used on red.
481 # To determine this we check if a wpa_supplicant is running.
482 pid
="$(pidof wpa_supplicant)"
484 if [ -z "${pid}" ]; then
486 dhcpcd_stop
"${DEVICE}"
490 if [ -n "${PPTP_ROUTE}" ]; then
491 route del
${PPTP_ROUTE}
494 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
495 link_status
=`ip link show $DEVICE.${INET_VLAN} 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}.${INET_VLAN} interface..."
499 ip link
set ${DEVICE}.
${INET_VLAN} down
500 vconfig rem
${DEVICE}.
${INET_VLAN}
504 link_status
=`ip link show $DEVICE 2> /dev/null`
505 if [ -n "${link_status}" ]; then
506 if echo "${link_status}" |
grep -q UP
; then
507 boot_mesg
"Bringing down the ${DEVICE} interface..."
508 ip link
set ${DEVICE} down
514 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
515 killall
-w -s KILL pptp
>/dev
/null
2>&1
516 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
518 ## Disable vnstat collection
519 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
521 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}