]>
git.ipfire.org Git - people/teissler/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 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
25 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
26 if [ "$DEVICE" == "" ]; then
27 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
29 [ "${1}" == "start" ] && exit 0
33 if [ "${TYPE}" == "STATIC" ]; then
34 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
35 ADDRESS
="${RED_ADDRESS}"
36 BROADCAST
="${RED_BROADCAST}"
37 NETADDRESS
="${RED_NETADDRESS}"
38 NETMASK
="${RED_NETMASK}"
40 ADDRESS
="${GREEN_ADDRESS}"
41 BROADCAST
="${GREEN_BROADCAST}"
42 NETADDRESS
="${GREEN_NETADDRESS}"
43 NETMASK
="${GREEN_NETMASK}"
45 GATEWAY
="${DEFAULT_GATEWAY}"
49 if [ -z "${BROADCAST}" ]; then
50 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
54 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
55 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
56 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
58 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
63 elif [ "${TYPE}" == "DHCP" ]; then
65 PIDFILE
="/var/run/dhcpcd-${DEVICE}.pid"
66 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
67 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
68 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
74 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
75 boot_mesg
"Bringing up the ${DEVICE} interface..."
77 # Check if an interface is there...
78 if ip link show
${DEVICE} > /dev
/null
2>&1; then
79 link_status
=`ip link show ${DEVICE} 2> /dev/null`
80 if [ -n "${link_status}" ]; then
81 if ! echo "${link_status}" |
grep -q UP
; then
82 ip link
set ${DEVICE} up
86 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
92 ## Create & Enable vnstat
93 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
95 if [ "${TYPE}" == "STATIC" ]; then
97 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
98 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
99 ip addr add
${args} dev
${DEVICE}
102 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
103 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
104 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
105 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
106 echo "$GATEWAY gateway" >> /tmp
/hosts
107 mv /tmp
/hosts
/etc
/hosts
108 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
109 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
110 touch /var
/ipfire
/red
/active
112 boot_mesg
"Setting up default gateway ${GATEWAY}..."
113 ip route add default via
${GATEWAY} dev
${DEVICE}
116 run_subdir
${rc_base}/init.d
/networking
/red.up
/
118 elif [ "${TYPE}" == "DHCP" ]; then
119 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
120 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
122 ## Create & Enable vnstat
123 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
125 # Test to see if there is a stale pid file
126 if [ -f "$PIDFILE" ]; then
127 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
129 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
131 boot_mesg
"dhcpcd already running!" ${WARNING}
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 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
141 DHCP_START
+="-h ${RED_DHCP_HOSTNAME} "
144 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
147 if [ "$RET" = "0" ]; then
148 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
151 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
153 boot_mesg
" IP Address: $IPADDR"
155 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
156 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
159 boot_mesg
" Subnet Mask: $NETMASK"
161 boot_mesg
" Default Gateway: $GATEWAY"
163 boot_mesg
" DNS Server: $DNS"
166 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var
/ipfire
/red
/dns1
167 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var
/ipfire
/red
/dns2
169 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
170 echo "$IPADDR" > /var
/ipfire
/red
/local-ipaddress
171 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
172 echo "$GATEWAY gateway" >> /tmp
/hosts
173 mv /tmp
/hosts
/etc
/hosts
174 echo "$GATEWAY" > /var
/ipfire
/red
/remote-ipaddress
181 elif [ "$TYPE" == "PPPOE" ]; then
183 if ( ps ax |
grep -q [p
]ppd
); then
184 boot_mesg
"pppd is still running." ${FAILURE}
189 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
191 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
195 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
197 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
198 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
200 if [ "$TYPE" == "pppoeatm" ]; then
203 if [ "$TYPE" == "pptpatm" ]; then
207 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
208 if [ "$PPP_NIC" == "" ]; then
209 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
213 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
214 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
215 if [ "$TYPE" == "pptp" ]; then
216 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
218 ip link
set ${PPP_NIC} up
220 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
224 ### Configuring the pppd ###
229 if [ "$TYPE" == "pppoe" ]; then
230 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
231 PLUGOPTS
="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so"
239 ### Access Concentrator Name
241 if [ -n "${CONCENTRATORNAME}" ]; then
242 ACNAME
="-C ${CONCENTRATORNAME}"
247 if [ -n "${SERVICENAME}" ]; then
248 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
249 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
251 SERVICENAME
="-S ${SERVICENAME}"
255 ### Authentication Types
257 if [ "${AUTH}" == "pap" ]; then
259 elif [ "${AUTH}" == "chap" ]; then
267 if [ "${DNS}" == "Automatic" ]; then
271 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
272 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
277 if [ "${RECONNECTION}" != "persistent" ]; then
278 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
279 SECONDS
=$
[${TIMEOUT} * 60]
283 if [ "${RECONNECTION}" == "dialondemand" ]; then
284 touch /var
/ipfire
/red
/dial-on-demand
285 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
286 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
290 if [ "$TYPE" == "pppoe" ]; then
291 ### When using pppoe-plugin the device has to be the last option
293 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
296 if [ "$TYPE" == "modem" ]; then
297 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
298 METHOD
="PPPOE_PLUGIN"
299 elif [ "$TYPE" == "serial" ]; then
300 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
301 METHOD
="PPPOE_PLUGIN"
304 ### Standard PPP options we always use
306 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
307 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
308 PPP_STD_OPTIONS
+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
309 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
310 PPP_STD_OPTIONS
+=" lcp-echo-failure 3 ${AUTH}"
314 if [ "${DEBUG}" == "on" ]; then
322 if [ "$TYPE" == "pppoe" ]; then
323 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
324 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
329 if [ "$TYPE" == "pptp" ]; then
330 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
336 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
337 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
339 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
341 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
343 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
345 ## Create & Enable vnstat
346 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
347 /etc
/rc.d
/init.d
/connectd start
353 if [ "$TYPE" == "STATIC" ]; then
354 boot_mesg
"Stopping default gateway ${GATEWAY}..."
355 ip route del default via
${GATEWAY} >/dev
/null
2>&1
357 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
358 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
359 ip addr flush dev
${DEVICE}
362 run_subdir
${rc_base}/init.d
/networking
/red.down
/
364 elif [ "$TYPE" == "DHCP" ]; then
365 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
366 if [ -e $LEASEINFO ]; then
368 if [ "$LEASETIME" = "4294967295" ]; then
369 # do nothing, just echo ok
373 if [ -n "$DHCP_STOP" ]; then
374 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
376 if [ "$RET" -eq 0 ]; then
379 elif [ "$RET" -eq 1 ]; then
380 boot_mesg
"dhcpcd not running!" ${WARNING}
392 boot_mesg
-n "LEASEINFO Test failed! - " ${WARNING}
393 boot_mesg
"dhcpcd is not running!" ${WARNING}
397 elif [ "$TYPE" == "PPPOE" ]; then
398 boot_mesg
"Bringing down the PPP interface ..."
399 ## Disable vnstat collection
400 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
401 rm -f /var
/ipfire
/red
/keepconnected
402 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
406 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
407 link_status
=`ip link show $DEVICE 2> /dev/null`
408 if [ -n "${link_status}" ]; then
409 if echo "${link_status}" |
grep -q UP
; then
410 boot_mesg
"Bringing down the ${DEVICE} interface..."
411 ip link
set ${DEVICE} down
416 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
417 killall
-w -s KILL pptp
>/dev
/null
2>&1
418 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
420 ## Disable vnstat collection
421 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
423 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}