]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/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 touch /var
/ipfire
/red
/active
125 # Create route to default gateway
126 ip route add
${GATEWAY} dev
${DEVICE}
128 boot_mesg
"Setting up default gateway ${GATEWAY}..."
129 ip route add default via
${GATEWAY} dev
${DEVICE}
132 if [ -d "/sys/class/net/${DEVICE}" ]; then
134 if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
135 boot_mesg
-n "Wait for carrier on ${DEVICE} "
136 for (( i
=30; i
>1; i--
)) do
137 if [ "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
144 if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
152 run_subdir
${rc_base}/init.d
/networking
/red.up
/
154 # Configure aliases only if red static
155 /usr
/local
/bin
/setaliases
157 elif [ "${TYPE}" == "DHCP" ]; then
158 # Add firewall rules to allow comunication with the dhcp server on red.
159 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
160 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
162 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
164 # Check if the wlan-client is used on red.
165 # To determine this we check if a wpa_supplicant is running.
166 pid
="$(pidof wpa_supplicant)"
168 if [ -z "${pid}" ]; then
169 # No wpa_supplicant is running. So it's save to start dhcpcd.
170 dhcpcd_start
"${DEVICE}"
173 ## Create & Enable vnstat
174 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
176 elif [ "$TYPE" == "PPPOE" ]; then
178 if ( ps ax |
grep -q [p
]ppd
); then
179 boot_mesg
"pppd is still running." ${FAILURE}
184 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
186 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
188 # We force the plugin method, anyway.
189 METHOD
="PPPOE_PLUGIN"
194 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
195 PPP_NIC
=nas
${ATM_DEV}
197 boot_mesg
"Creating ATM-Bridge as $PPP_NIC ..."
198 br2684ctl
-c${ATM_DEV} -e${ENCAP} -a${ATM_DEV}.${VPI}.${VCI} >/dev
/null
2>&1 &
201 # use user-defined or green mac address for nas0
202 if [ -n "$MAC" ]; then
203 ip link
set dev nas
${ATM_DEV} address
${MAC}
205 ip link
set dev nas
${ATM_DEV} address $
(cat /sys
/class
/net
/green
0/address
)
208 if [ "$TYPE" == "pppoeatm" ]; then
211 if [ "$TYPE" == "pptpatm" ]; then
216 if [ "$TYPE" == "vdsl" ]; then
217 boot_mesg
"Creating VLAN Interface ${DEVICE}.${INET_VLAN} ..."
219 vconfig add
${DEVICE} ${INET_VLAN}
220 if [ -n "$MAC1" ]; then
221 boot_mesg
"Setting mac address on ${DEVICE}.${INET_VLAN} to ${MAC1}"
222 ip link
set dev
${DEVICE}.${INET_VLAN} address ${MAC1}
225 PPP_NIC
=${DEVICE}.
${INET_VLAN}
227 ip link
set ${PPP_NIC} up
230 if [ "${IPTV}" == "enable" ]; then
231 PIDFILE
="/var/run/dhcpcd/${DEVICE}.${IPTV_VLAN}.pid"
232 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info"
233 # Test to see if there is a stale pid file
234 if [ -f "$PIDFILE" ]; then
235 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
237 rm -f /var
/run
/dhcpcd
/${DEVICE}.
${IPTV_VLAN}.pid
> /dev
/null
241 if [ ! -f "$PIDFILE" ]; then
242 boot_mesg
"Creating VLAN Interface ${DEVICE}.${IPTV_VLAN} ..."
244 vconfig add
${DEVICE} ${IPTV_VLAN}
245 if [ -n "$MAC2" ]; then
246 boot_mesg
"Setting mac address on ${DEVICE}.${IPTV_VLAN} to ${MAC2}"
247 ip link
set dev
${DEVICE}.${IPTV_VLAN} address ${MAC2}
250 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.${IPTV_VLAN} interface..."
251 /sbin
/dhcpcd
${DEVICE}.${IPTV_VLAN} ${DHCP_START} >/dev
/null
2>&1
254 if [ "$RET" = "0" ]; then
255 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.info
258 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.${IPTV_VLAN}:"
260 boot_mesg
" IP Address: $ip_address"
262 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
264 boot_mesg
" Subnet Mask: $subnet_mask"
266 boot_mesg
" Default Gateway: $routers"
268 boot_mesg
" DNS Server: $domain_name_servers"
278 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
279 if [ "$PPP_NIC" == "" ]; then
280 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
284 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
285 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
286 if [ "$TYPE" == "pptp" ]; then
287 if [ "$PPTP_NICCFG" == "dhcp" ]; then
288 # Test to see if there is a stale pid file
289 if [ -f "$PIDFILE" ]; then
290 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
292 rm -f /var
/run
/dhcpcd
/${DEVICE}.pid
> /dev
/null
296 if [ ! -f "$PIDFILE" ]; then
297 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
298 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
301 if [ "$RET" = "0" ]; then
302 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
305 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
307 boot_mesg
" IP Address: $ip_address"
309 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
311 boot_mesg
" Subnet Mask: $subnet_mask"
313 boot_mesg
" Default Gateway: $routers"
315 boot_mesg
" DNS Server: $domain_name_servers"
317 /sbin
/route add
$PPTP_PEER gw
$routers $PPP_NIC
325 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
328 ip link
set ${PPP_NIC} up
329 if [ -n "${PPTP_ROUTE}" ]; then
330 boot_mesg
"Set route ${PPTP_ROUTE} to pptp server..."
331 route add
${PPTP_ROUTE}
334 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
338 ### Configuring the pppd ###
343 if [ "$TYPE" == "pppoe" ]; then
344 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
345 PLUGOPTS
="plugin rp-pppoe.so"
353 ### Access Concentrator Name
355 if [ -n "${CONCENTRATORNAME}" ]; then
356 ACNAME
="-C ${CONCENTRATORNAME}"
361 if [ -n "${SERVICENAME}" ]; then
362 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
363 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
365 SERVICENAME
="-S ${SERVICENAME}"
369 ### Authentication Types
371 if [ "${AUTH}" == "pap" ]; then
373 elif [ "${AUTH}" == "chap" ]; then
381 if [ "${RECONNECTION}" != "persistent" ]; then
382 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
383 SECONDS
=$
[${TIMEOUT} * 60]
387 if [ "${RECONNECTION}" == "dialondemand" ]; then
388 touch /var
/ipfire
/red
/dial-on-demand
389 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
390 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
394 if [ "$TYPE" == "pppoe" ]; then
395 ### When using pppoe-plugin the device has to be the last option
397 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
400 if [ "$TYPE" == "modem" ]; then
401 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
402 METHOD
="PPPOE_PLUGIN"
403 elif [ "$TYPE" == "serial" ]; then
404 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
405 METHOD
="PPPOE_PLUGIN"
408 ### Standard PPP options we always use
410 PPP_STD_OPTIONS
="$PLUGOPTS usepeerdns defaultroute noipdefault noauth"
411 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach"
412 PPP_STD_OPTIONS
+=" noaccomp nodeflate nopcomp novj novjccomp"
413 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
414 PPP_STD_OPTIONS
+=" lcp-echo-failure 5 ${AUTH}"
416 if [ -n "${MTU}" ]; then
417 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mtu ${MTU}"
420 if [ -n "${MRU}" ]; then
421 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mru ${MRU}"
426 if [ "${DEBUG}" == "on" ]; then
434 if [ "$TYPE" == "pppoe" ]; then
435 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
436 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
441 if [ "$TYPE" == "pptp" ]; then
442 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
448 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
449 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
451 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
453 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
455 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
457 ## Create & Enable vnstat
458 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
459 /etc
/rc.d
/init.d
/connectd start
460 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
461 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
462 $
(date +%s
):: > /dev
/null
2>&1
468 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}
470 if [ "$TYPE" == "STATIC" ]; then
471 boot_mesg
"Stopping default gateway ${GATEWAY}..."
472 ip route del default via
${GATEWAY} >/dev
/null
2>&1
474 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
475 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
476 ip addr flush dev
${DEVICE}
479 run_subdir
${rc_base}/init.d
/networking
/red.down
/
481 elif [ "$TYPE" == "PPPOE" ]; then
482 boot_mesg
"Bringing down the PPP interface ..."
483 ## Disable vnstat collection
484 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
485 rm -f /var
/ipfire
/red
/keepconnected
486 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
488 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
489 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
490 $
(date +%s
):: > /dev
/null
2>&1
492 elif [ "$TYPE" == "DHCP" ]; then
493 # Check if the wlan-client is used on red.
494 # To determine this we check if a wpa_supplicant is running.
495 pid
="$(pidof wpa_supplicant)"
497 if [ -z "${pid}" ]; then
499 dhcpcd_stop
"${DEVICE}"
503 if [ -n "${PPTP_ROUTE}" ]; then
504 route del
${PPTP_ROUTE}
507 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
508 link_status
=`ip link show $DEVICE.${INET_VLAN} 2> /dev/null`
509 if [ -n "${link_status}" ]; then
510 if echo "${link_status}" |
grep -q UP
; then
511 boot_mesg
"Bringing down the ${DEVICE}.${INET_VLAN} interface..."
512 ip link
set ${DEVICE}.
${INET_VLAN} down
513 vconfig rem
${DEVICE}.
${INET_VLAN}
517 link_status
=`ip link show $DEVICE 2> /dev/null`
518 if [ -n "${link_status}" ]; then
519 if echo "${link_status}" |
grep -q UP
; then
520 boot_mesg
"Bringing down the ${DEVICE} interface..."
521 ip link
set ${DEVICE} down
527 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
528 killall
-w -s KILL pptp
>/dev
/null
2>&1
529 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
531 ## Disable vnstat collection
532 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1