]>
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 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
25 if [ "$TYPE" == "STATIC" ]; then
26 ADDRESS
="${RED_ADDRESS}"
27 BROADCAST
="${RED_BROADCAST}"
28 NETADDRESS
="${RED_NETADDRESS}"
29 NETMASK
="${RED_NETMASK}"
30 GATEWAY
="${DEFAULT_GATEWAY}"
34 if [ -z "${BROADCAST}" ]; then
35 boot_mesg
"BROADCAST variable missing from input, cannot continue." ${FAILURE}
39 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
40 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
41 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
43 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
48 elif [ "${TYPE}" == "DHCP" ]; then
50 PIDFILE
="/var/run/dhcpcd-${DEVICE}.pid"
51 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
52 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
53 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
59 boot_mesg
"Bringing up the ${DEVICE} interface..."
62 # Check if an interface is there...
63 if ip link show
${DEVICE} > /dev
/null
2>&1; then
64 link_status
=`ip link show ${DEVICE} 2> /dev/null`
65 if [ -n "${link_status}" ]; then
66 if ! echo "${link_status}" |
grep -q UP
; then
67 ip link
set ${DEVICE} up
71 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
76 if [ "${TYPE}" == "STATIC" ]; then
77 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
78 ip addr add
${args} dev
${DEVICE}
80 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
81 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
82 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
83 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
84 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
86 boot_mesg
"Setting up default gateway ${GATEWAY}..."
87 ip route add default via
${GATEWAY} dev
${DEVICE}
90 run_subdir
${rc_base}/init.d
/networking
/red.up
/
92 elif [ "${TYPE}" == "DHCP" ]; then
93 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
94 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
96 # Test to see if there is a stale pid file
97 if [ -f "$PIDFILE" ]; then
98 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
100 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
102 boot_mesg
"dhcpcd already running!" ${WARNING}
108 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
109 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
111 if [ -n "${DHCP_HOSTNAME}" ]; then
112 DHCP_START
+="-h ${DHCP_HOSTNAME} "
115 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
118 if [ "$RET" = "0" ]; then
119 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
122 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
124 boot_mesg
" IP Address: $IPADDR"
126 if [ -n "${DHCP_HOSTNAME}" ]; then
127 boot_mesg
" Hostname: $DHCP_HOSTNAME"
130 boot_mesg
" Subnet Mask: $NETMASK"
132 boot_mesg
" Default Gateway: $GATEWAY"
134 boot_mesg
" DNS Server: $DNS"
137 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var
/ipfire
/red
/dns1
138 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var
/ipfire
/red
/dns2
140 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
141 echo "$IPADDR" > /var
/ipfire
/red
/local-ipaddress
142 echo "$GATEWAY" > /var
/ipfire
/red
/remote-ipaddress
149 elif [ "$TYPE" == "PPPOE" ]; then
151 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
153 boot_mesg
"Bringing up the PPPoE interface on ${DEVICE}..."
154 ip addr add
1.1.1.1/24 broadcast
1.1.1.255 dev
${DEVICE}
156 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
159 ### Configuring the pppd ###
164 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
165 PLUGOPTS
="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so nic-${DEVICE}"
172 ### Access Concentrator Name
174 if [ -n "${CONCENTRATORNAME}" ]; then
175 ACNAME
="-C ${CONCENTRATORNAME}"
180 if [ -n "${SERVICENAME}" ]; then
181 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
182 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
184 SERVICENAME
="-S ${SERVICENAME}"
188 ### Authentication Types
190 if [ "${AUTH}" == "pap" ]; then
192 elif [ "${AUTH}" == "chap" ]; then
200 if [ "${RECONNECTION}" != "persistent" ]; then
201 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
202 SECONDS
=$
[${TIMEOUT} * 60]
206 if [ "${RECONNECTION}" == "dialondemand" ]; then
207 touch /var
/ipfire
/red
/dial-on-demand
208 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
209 DEMAND
+=" ipcp-accept-remote ipcp-accept-local connect true noipdefault ktune"
213 ### When using plugin the device has to be the last option
215 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" ${DEVICE}"
217 ### Standard PPP options we always use
219 PPP_STD_OPTIONS
="$PLUGOPTS usepeerdns defaultroute noipdefault noauth"
220 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
221 PPP_STD_OPTIONS
+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
222 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
223 PPP_STD_OPTIONS
+=" lcp-echo-failure 3 ${AUTH}"
227 if [ "${DEBUG}" == "on" ]; then
235 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I ${DEVICE}"
236 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
240 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
241 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
244 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
248 /etc
/rc.d
/init.d
/connectd start
254 if [ "$TYPE" == "STATIC" ]; then
255 boot_mesg
"Removing IPv4 address ${ADDRESS} from the ${DEVICE} interface..."
256 ip addr del
${args} dev
${DEVICE}
259 run_subdir
${rc_base}/init.d
/networking
/red.down
/
261 elif [ "$TYPE" == "DHCP" ]; then
262 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
263 if [ -e $LEASEINFO ]; then
265 if [ "$LEASETIME" = "4294967295" ]; then
266 # do nothing, just echo ok
270 if [ -n "$DHCP_STOP" ]; then
271 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
273 if [ "$RET" -eq 0 ]; then
276 elif [ "$RET" -eq 1 ]; then
277 boot_mesg
"dhcpcd not running!" ${WARNING}
289 boot_mesg
-n "LEASEINFO Test failed! - " ${WARNING}
290 boot_mesg
"dhcpcd is not running!" ${WARNING}
295 elif [ "$TYPE" == "PPPOE" ]; then
296 boot_mesg
"Bringing down the PPPoE interface on ${DEVICE}..."
297 rm -f /var
/ipfire
/red
/keepconnected
298 kill -TERM /usr
/sbin
/pppd
2>/dev
/null
302 ip addr del
1.1.1.1/24 broadcast
1.1.1.255 dev
${DEVICE}
306 link_status
=`ip link show $DEVICE 2> /dev/null`
307 if [ -n "${link_status}" ]; then
308 if echo "${link_status}" |
grep -q UP
; then
309 boot_mesg
"Bringing down the ${DEVICE} interface..."
310 ip link
set ${DEVICE} down
315 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}