]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/networking/red
44e0daa68e986ef533ff2854f5169a34f08fb2ba
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}"
59 ADDRESS
="${GREEN_ADDRESS}"
60 BROADCAST
="${GREEN_BROADCAST}"
61 NETADDRESS
="${GREEN_NETADDRESS}"
62 NETMASK
="${GREEN_NETMASK}"
65 GATEWAY
="${DEFAULT_GATEWAY}"
69 if [ -z "${BROADCAST}" ]; then
70 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
74 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
75 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
76 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
78 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
86 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
87 boot_mesg
"Bringing up the ${DEVICE} interface..."
89 # Check if an interface is there...
90 if ip link show
${DEVICE} > /dev
/null
2>&1; then
91 link_status
=`ip link show ${DEVICE} 2> /dev/null`
92 if [ -n "${link_status}" ]; then
93 if ! echo "${link_status}" |
grep -q UP
; then
94 if [ -n "$MAC" ]; then
95 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
96 ip link
set dev
${DEVICE} address
${MAC}
99 ip link
set ${DEVICE} up
103 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
109 ## Create & Enable vnstat
110 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
112 if [ "${TYPE}" == "STATIC" ]; then
114 if [ -n "${MTU}" ]; then
115 if ! ip link
set dev
"${DEVICE}" mtu
"${MTU}" &>/dev
/null
; then
116 boot_mesg
"Could not set MTU of ${MTU} to ${DEVICE}..."
121 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
122 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
123 ip addr add
${args} dev
${DEVICE}
126 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
127 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
128 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
129 grep -v -E "\<gateway\>" /etc
/hosts
> /tmp
/hosts
130 echo "$GATEWAY gateway" >> /tmp
/hosts
131 mv /tmp
/hosts
/etc
/hosts
132 touch /var
/ipfire
/red
/active
134 # Create route to default gateway
135 ip route add
${GATEWAY} dev
${DEVICE}
137 boot_mesg
"Setting up default gateway ${GATEWAY}..."
138 ip route add default via
${GATEWAY} dev
${DEVICE}
141 if [ -d "/sys/class/net/${DEVICE}" ]; then
143 if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
144 boot_mesg
-n "Wait for carrier on ${DEVICE} "
145 for (( i
=30; i
>1; i--
)) do
146 if [ "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
153 if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then
161 run_subdir
${rc_base}/init.d
/networking
/red.up
/
163 # Configure aliases only if red static
164 /usr
/local
/bin
/setaliases
166 elif [ "${TYPE}" == "DHCP" ]; then
167 # Add firewall rules to allow comunication with the dhcp server on red.
168 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
169 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
171 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
173 # Check if the wlan-client is used on red.
174 # To determine this we check if a wpa_supplicant is running.
175 pid
="$(pidof wpa_supplicant)"
177 if [ -z "${pid}" ]; then
178 # No wpa_supplicant is running. So it's save to start dhcpcd.
179 dhcpcd_start
"${DEVICE}"
182 ## Create & Enable vnstat
183 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
185 elif [ "$TYPE" == "PPPOE" ]; then
187 if ( ps ax |
grep -q [p
]ppd
); then
188 boot_mesg
"pppd is still running." ${FAILURE}
193 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
195 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
197 # We force the plugin method, anyway.
198 METHOD
="PPPOE_PLUGIN"
203 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
204 PPP_NIC
=nas
${ATM_DEV}
206 boot_mesg
"Creating ATM-Bridge as $PPP_NIC ..."
207 br2684ctl
-c${ATM_DEV} -e${ENCAP} -a${ATM_DEV}.${VPI}.${VCI} >/dev
/null
2>&1 &
210 # use user-defined or green mac address for nas0
211 if [ -n "$MAC" ]; then
212 ip link
set dev nas
${ATM_DEV} address
${MAC}
214 ip link
set dev nas
${ATM_DEV} address $
(cat /sys
/class
/net
/green
0/address
)
217 if [ "$TYPE" == "pppoeatm" ]; then
220 if [ "$TYPE" == "pptpatm" ]; then
225 if [ "$TYPE" == "vdsl" ]; then
226 boot_mesg
"Creating VLAN Interface ${DEVICE}.${INET_VLAN} ..."
228 vconfig add
${DEVICE} ${INET_VLAN}
229 if [ -n "$MAC1" ]; then
230 boot_mesg
"Setting mac address on ${DEVICE}.${INET_VLAN} to ${MAC1}"
231 ip link
set dev
${DEVICE}.${INET_VLAN} address ${MAC1}
234 PPP_NIC
=${DEVICE}.
${INET_VLAN}
236 ip link
set ${PPP_NIC} up
239 if [ "${IPTV}" == "enable" ]; then
240 PIDFILE
="/var/run/dhcpcd/${DEVICE}.${IPTV_VLAN}.pid"
241 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info"
242 # Test to see if there is a stale pid file
243 if [ -f "$PIDFILE" ]; then
244 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
246 rm -f /var
/run
/dhcpcd
/${DEVICE}.
${IPTV_VLAN}.pid
> /dev
/null
250 if [ ! -f "$PIDFILE" ]; then
251 boot_mesg
"Creating VLAN Interface ${DEVICE}.${IPTV_VLAN} ..."
253 vconfig add
${DEVICE} ${IPTV_VLAN}
254 if [ -n "$MAC2" ]; then
255 boot_mesg
"Setting mac address on ${DEVICE}.${IPTV_VLAN} to ${MAC2}"
256 ip link
set dev
${DEVICE}.${IPTV_VLAN} address ${MAC2}
259 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.${IPTV_VLAN} interface..."
260 /sbin
/dhcpcd
${DEVICE}.${IPTV_VLAN} ${DHCP_START} >/dev
/null
2>&1
263 if [ "$RET" = "0" ]; then
264 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.
${IPTV_VLAN}.info
267 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.${IPTV_VLAN}:"
269 boot_mesg
" IP Address: $ip_address"
271 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
273 boot_mesg
" Subnet Mask: $subnet_mask"
275 boot_mesg
" Default Gateway: $routers"
277 boot_mesg
" DNS Server: $domain_name_servers"
287 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
288 if [ "$PPP_NIC" == "" ]; then
289 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
293 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
294 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
295 if [ "$TYPE" == "pptp" ]; then
296 if [ "$PPTP_NICCFG" == "dhcp" ]; then
297 # Test to see if there is a stale pid file
298 if [ -f "$PIDFILE" ]; then
299 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
301 rm -f /var
/run
/dhcpcd
/${DEVICE}.pid
> /dev
/null
305 if [ ! -f "$PIDFILE" ]; then
306 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
307 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
310 if [ "$RET" = "0" ]; then
311 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
314 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
316 boot_mesg
" IP Address: $ip_address"
318 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
320 boot_mesg
" Subnet Mask: $subnet_mask"
322 boot_mesg
" Default Gateway: $routers"
324 boot_mesg
" DNS Server: $domain_name_servers"
326 /sbin
/route add
$PPTP_PEER gw
$routers $PPP_NIC
334 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
337 ip link
set ${PPP_NIC} up
338 if [ -n "${PPTP_ROUTE}" ]; then
339 boot_mesg
"Set route ${PPTP_ROUTE} to pptp server..."
340 route add
${PPTP_ROUTE}
343 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
347 ### Configuring the pppd ###
352 if [ "$TYPE" == "pppoe" ]; then
353 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
354 PLUGOPTS
="plugin rp-pppoe.so"
362 ### Access Concentrator Name
364 if [ -n "${CONCENTRATORNAME}" ]; then
365 ACNAME
="-C ${CONCENTRATORNAME}"
370 if [ -n "${SERVICENAME}" ]; then
371 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
372 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
374 SERVICENAME
="-S ${SERVICENAME}"
378 ### Authentication Types
380 if [ "${AUTH}" == "pap" ]; then
382 elif [ "${AUTH}" == "chap" ]; then
390 if [ "${RECONNECTION}" != "persistent" ]; then
391 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
392 SECONDS
=$
[${TIMEOUT} * 60]
396 if [ "${RECONNECTION}" == "dialondemand" ]; then
397 touch /var
/ipfire
/red
/dial-on-demand
398 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
399 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
403 if [ "$TYPE" == "pppoe" ]; then
404 ### When using pppoe-plugin the device has to be the last option
406 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
409 if [ "$TYPE" == "modem" ]; then
410 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
411 METHOD
="PPPOE_PLUGIN"
412 elif [ "$TYPE" == "serial" ]; then
413 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
414 METHOD
="PPPOE_PLUGIN"
417 ### Standard PPP options we always use
419 PPP_STD_OPTIONS
="$PLUGOPTS usepeerdns defaultroute noipdefault noauth"
420 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach"
421 PPP_STD_OPTIONS
+=" noaccomp nodeflate nopcomp novj novjccomp"
422 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
423 PPP_STD_OPTIONS
+=" lcp-echo-failure 5 ${AUTH}"
425 if [ -n "${MTU}" ]; then
426 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mtu ${MTU}"
429 if [ -n "${MRU}" ]; then
430 PPP_STD_OPTIONS
="${PPP_STD_OPTIONS} mru ${MRU}"
435 if [ "${DEBUG}" == "on" ]; then
443 if [ "$TYPE" == "pppoe" ]; then
444 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
445 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
450 if [ "$TYPE" == "pptp" ]; then
451 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
457 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
458 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
460 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
462 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
464 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
466 ## Create & Enable vnstat
467 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
468 /etc
/rc.d
/init.d
/connectd start
469 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
470 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
471 $
(date +%s
):: > /dev
/null
2>&1
477 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}
479 if [ "$TYPE" == "STATIC" ]; then
480 boot_mesg
"Stopping default gateway ${GATEWAY}..."
481 ip route del default via
${GATEWAY} >/dev
/null
2>&1
483 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
484 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
485 ip addr flush dev
${DEVICE}
488 run_subdir
${rc_base}/init.d
/networking
/red.down
/
490 elif [ "$TYPE" == "PPPOE" ]; then
491 boot_mesg
"Bringing down the PPP interface ..."
492 ## Disable vnstat collection
493 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
494 rm -f /var
/ipfire
/red
/keepconnected
495 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
497 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
498 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
499 $
(date +%s
):: > /dev
/null
2>&1
501 elif [ "$TYPE" == "DHCP" ]; then
502 # Check if the wlan-client is used on red.
503 # To determine this we check if a wpa_supplicant is running.
504 pid
="$(pidof wpa_supplicant)"
506 if [ -z "${pid}" ]; then
508 dhcpcd_stop
"${DEVICE}"
512 if [ -n "${PPTP_ROUTE}" ]; then
513 route del
${PPTP_ROUTE}
516 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
517 link_status
=`ip link show $DEVICE.${INET_VLAN} 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}.${INET_VLAN} interface..."
521 ip link
set ${DEVICE}.
${INET_VLAN} down
522 vconfig rem
${DEVICE}.
${INET_VLAN}
526 link_status
=`ip link show $DEVICE 2> /dev/null`
527 if [ -n "${link_status}" ]; then
528 if echo "${link_status}" |
grep -q UP
; then
529 boot_mesg
"Bringing down the ${DEVICE} interface..."
530 ip link
set ${DEVICE} down
536 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
537 killall
-w -s KILL pptp
>/dev
/null
2>&1
538 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
540 ## Disable vnstat collection
541 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1