]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/networking/red
ca0a8ae58b9705d986dade2faca65d37d14e1a2e
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 NETADDRESS
="${RED_NETADDRESS}"
55 NETMASK
="${RED_NETMASK}"
58 ADDRESS
="${GREEN_ADDRESS}"
59 NETADDRESS
="${GREEN_NETADDRESS}"
60 NETMASK
="${GREEN_NETMASK}"
63 GATEWAY
="${DEFAULT_GATEWAY}"
67 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
68 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
69 args
="${args} ${ADDRESS}/${PREFIX}"
71 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
79 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
80 boot_mesg
"Bringing up the ${DEVICE} interface..."
82 # Check if an interface is there...
83 if ip link show
${DEVICE} > /dev
/null
2>&1; then
84 link_status
=`ip link show ${DEVICE} 2> /dev/null`
85 if [ -n "${link_status}" ]; then
86 if ! echo "${link_status}" |
grep -q UP
; then
87 if [ -n "$MAC" ]; then
88 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
89 ip link
set dev
${DEVICE} address
${MAC}
92 ip link
set ${DEVICE} up
96 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
102 ## Create & Enable vnstat
103 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
105 if [ "${TYPE}" == "STATIC" ]; then
107 if [ -n "${MTU}" ]; then
108 if ! ip link
set dev
"${DEVICE}" mtu
"${MTU}" &>/dev
/null
; then
109 boot_mesg
"Could not set MTU of ${MTU} to ${DEVICE}..."
114 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
115 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
116 ip addr add
${args} dev
${DEVICE}
119 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
120 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
121 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
122 grep -v -E "\<gateway\>" /etc
/hosts
> /tmp
/hosts
123 echo "$GATEWAY gateway" >> /tmp
/hosts
124 mv /tmp
/hosts
/etc
/hosts
125 touch /var
/ipfire
/red
/active
127 # Create route to default gateway
128 ip route add
${GATEWAY} dev
${DEVICE}
130 boot_mesg
"Setting up default gateway ${GATEWAY}..."
131 ip route add default via
${GATEWAY} dev
${DEVICE}
134 if [ -d "/sys/class/net/${DEVICE}" ]; then
136 if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
137 boot_mesg
-n "Wait for carrier on ${DEVICE} "
138 for (( i
=30; i
>1; i--
)) do
139 if [ "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
146 if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
154 run_subdir
${rc_base}/init.d
/networking
/red.up
/
156 # Configure aliases only if red static
157 /usr
/local
/bin
/setaliases
159 elif [ "${TYPE}" == "DHCP" ]; then
160 # Add firewall rules to allow comunication with the dhcp server on red.
161 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
162 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
164 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
166 # Check if the wlan-client is used on red.
167 # To determine this we check if a wpa_supplicant is running.
168 pid
="$(pidof wpa_supplicant)"
170 if [ -z "${pid}" ]; then
171 # No wpa_supplicant is running. So it's save to start dhcpcd.
172 dhcpcd_start
"${DEVICE}"
175 ## Create & Enable vnstat
176 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
178 elif [ "$TYPE" == "PPPOE" ]; then
180 if ( ps ax |
grep -q [p
]ppd
); then
181 boot_mesg
"pppd is still running." ${FAILURE}
186 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
188 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
190 # We force the plugin method, anyway.
191 METHOD
="PPPOE_PLUGIN"
196 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
197 PPP_NIC
=nas
${ATM_DEV}
199 boot_mesg
"Creating ATM-Bridge as $PPP_NIC ..."
200 br2684ctl
-c${ATM_DEV} -e${ENCAP} -a${ATM_DEV}.${VPI}.${VCI} >/dev
/null
2>&1 &
203 # use user-defined or green mac address for nas0
204 if [ -n "$MAC" ]; then
205 ip link
set dev nas
${ATM_DEV} address
${MAC}
207 ip link
set dev nas
${ATM_DEV} address $
(cat /sys
/class
/net
/green
0/address
)
210 if [ "$TYPE" == "pppoeatm" ]; then
213 if [ "$TYPE" == "pptpatm" ]; then
218 if [ "$TYPE" == "vdsl" ]; then
219 boot_mesg
"Creating VLAN Interface ${DEVICE}.${INET_VLAN} ..."
221 vconfig add
${DEVICE} ${INET_VLAN}
222 if [ -n "$MAC1" ]; then
223 boot_mesg
"Setting mac address on ${DEVICE}.${INET_VLAN} to ${MAC1}"
224 ip link
set dev
${DEVICE}.${INET_VLAN} address ${MAC1}
227 PPP_NIC
=${DEVICE}.
${INET_VLAN}
229 ip link
set ${PPP_NIC} up
232 if [ "${IPTV}" == "enable" ]; then
233 PIDFILE
="/var/run/dhcpcd/${DEVICE}.${IPTV_VLAN}.pid"
234 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info"
235 # Test to see if there is a stale pid file
236 if [ -f "$PIDFILE" ]; then
237 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
239 rm -f /var
/run
/dhcpcd
/${DEVICE}.
${IPTV_VLAN}.pid
> /dev
/null
243 if [ ! -f "$PIDFILE" ]; then
244 boot_mesg
"Creating VLAN Interface ${DEVICE}.${IPTV_VLAN} ..."
246 vconfig add
${DEVICE} ${IPTV_VLAN}
247 if [ -n "$MAC2" ]; then
248 boot_mesg
"Setting mac address on ${DEVICE}.${IPTV_VLAN} to ${MAC2}"
249 ip link
set dev
${DEVICE}.${IPTV_VLAN} address ${MAC2}
252 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.${IPTV_VLAN} interface..."
253 /sbin
/dhcpcd
${DEVICE}.${IPTV_VLAN} ${DHCP_START} >/dev
/null
2>&1
256 if [ "$RET" = "0" ]; then
257 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.info
260 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.${IPTV_VLAN}:"
262 boot_mesg
" IP Address: $ip_address"
264 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
266 boot_mesg
" Subnet Mask: $subnet_mask"
268 boot_mesg
" Default Gateway: $routers"
270 boot_mesg
" DNS Server: $domain_name_servers"
280 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
281 if [ "$PPP_NIC" == "" ]; then
282 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
286 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
287 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
288 if [ "$TYPE" == "pptp" ]; then
289 if [ "$PPTP_NICCFG" == "dhcp" ]; then
290 # Test to see if there is a stale pid file
291 if [ -f "$PIDFILE" ]; then
292 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
294 rm -f /var
/run
/dhcpcd
/${DEVICE}.pid
> /dev
/null
298 if [ ! -f "$PIDFILE" ]; then
299 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
300 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
303 if [ "$RET" = "0" ]; then
304 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
307 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
309 boot_mesg
" IP Address: $ip_address"
311 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
313 boot_mesg
" Subnet Mask: $subnet_mask"
315 boot_mesg
" Default Gateway: $routers"
317 boot_mesg
" DNS Server: $domain_name_servers"
319 /sbin
/route add
$PPTP_PEER gw
$routers $PPP_NIC
327 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
330 ip link
set ${PPP_NIC} up
331 if [ -n "${PPTP_ROUTE}" ]; then
332 boot_mesg
"Set route ${PPTP_ROUTE} to pptp server..."
333 route add
${PPTP_ROUTE}
336 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
340 ### Configuring the pppd ###
345 if [ "$TYPE" == "pppoe" ]; then
346 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
347 PLUGOPTS
="plugin rp-pppoe.so"
355 ### Access Concentrator Name
357 if [ -n "${CONCENTRATORNAME}" ]; then
358 ACNAME
="-C ${CONCENTRATORNAME}"
363 if [ -n "${SERVICENAME}" ]; then
364 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
365 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
367 SERVICENAME
="-S ${SERVICENAME}"
371 ### Authentication Types
373 if [ "${AUTH}" == "pap" ]; then
375 elif [ "${AUTH}" == "chap" ]; then
383 if [ "${RECONNECTION}" != "persistent" ]; then
384 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
385 SECONDS
=$
[${TIMEOUT} * 60]
389 if [ "${RECONNECTION}" == "dialondemand" ]; then
390 touch /var
/ipfire
/red
/dial-on-demand
391 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
392 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
396 if [ "$TYPE" == "pppoe" ]; then
397 ### When using pppoe-plugin the device has to be the last option
399 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
402 if [ "$TYPE" == "modem" ]; then
403 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
404 METHOD
="PPPOE_PLUGIN"
405 elif [ "$TYPE" == "serial" ]; then
406 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
407 METHOD
="PPPOE_PLUGIN"
410 ### Standard PPP options we always use
412 PPP_STD_OPTIONS
="$PLUGOPTS usepeerdns defaultroute noipdefault noauth"
413 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach"
414 PPP_STD_OPTIONS
+=" noaccomp nodeflate nopcomp novj novjccomp"
415 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
416 PPP_STD_OPTIONS
+=" lcp-echo-failure 5 ${AUTH}"
418 if [ -n "${MTU}" ]; then
419 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mtu ${MTU}"
422 if [ -n "${MRU}" ]; then
423 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mru ${MRU}"
428 if [ "${DEBUG}" == "on" ]; then
436 if [ "$TYPE" == "pppoe" ]; then
437 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
438 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
443 if [ "$TYPE" == "pptp" ]; then
444 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
450 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
451 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
453 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
455 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
457 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
459 ## Create & Enable vnstat
460 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
461 /etc
/rc.d
/init.d
/connectd start
462 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
463 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
464 $
(date +%s
):: > /dev
/null
2>&1
470 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}
472 if [ "$TYPE" == "STATIC" ]; then
473 boot_mesg
"Stopping default gateway ${GATEWAY}..."
474 ip route del default via
${GATEWAY} >/dev
/null
2>&1
476 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
477 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
478 ip addr flush dev
${DEVICE}
481 run_subdir
${rc_base}/init.d
/networking
/red.down
/
483 elif [ "$TYPE" == "PPPOE" ]; then
484 boot_mesg
"Bringing down the PPP interface ..."
485 ## Disable vnstat collection
486 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
487 rm -f /var
/ipfire
/red
/keepconnected
488 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
490 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
491 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
492 $
(date +%s
):: > /dev
/null
2>&1
494 elif [ "$TYPE" == "DHCP" ]; then
495 # Check if the wlan-client is used on red.
496 # To determine this we check if a wpa_supplicant is running.
497 pid
="$(pidof wpa_supplicant)"
499 if [ -z "${pid}" ]; then
501 dhcpcd_stop
"${DEVICE}"
505 if [ -n "${PPTP_ROUTE}" ]; then
506 route del
${PPTP_ROUTE}
509 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
510 link_status
=`ip link show $DEVICE.${INET_VLAN} 2> /dev/null`
511 if [ -n "${link_status}" ]; then
512 if echo "${link_status}" |
grep -q UP
; then
513 boot_mesg
"Bringing down the ${DEVICE}.${INET_VLAN} interface..."
514 ip link
set ${DEVICE}.
${INET_VLAN} down
515 vconfig rem
${DEVICE}.
${INET_VLAN}
519 link_status
=`ip link show $DEVICE 2> /dev/null`
520 if [ -n "${link_status}" ]; then
521 if echo "${link_status}" |
grep -q UP
; then
522 boot_mesg
"Bringing down the ${DEVICE} interface..."
523 ip link
set ${DEVICE} down
529 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
530 killall
-w -s KILL pptp
>/dev
/null
2>&1
531 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
533 ## Disable vnstat collection
534 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1