]>
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" ]; 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 run_subdir
${rc_base}/init.d
/networking
/red.up
/
88 elif [ "${TYPE}" == "DHCP" ]; then
89 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
90 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
92 # Test to see if there is a stale pid file
93 if [ -f "$PIDFILE" ]; then
94 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
96 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
98 boot_mesg
"dhcpcd already running!" ${WARNING}
104 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
105 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
107 if [ -n "${DHCP_HOSTNAME}" ]; then
108 DHCP_START
+="-h ${DHCP_HOSTNAME} "
111 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
114 if [ "$RET" = "0" ]; then
115 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
118 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
120 boot_mesg
" IP Address: $IPADDR"
122 if [ -n "${DHCP_HOSTNAME}" ]; then
123 boot_mesg
" Hostname: $DHCP_HOSTNAME"
126 boot_mesg
" Subnet Mask: $NETMASK"
128 boot_mesg
" Default Gateway: $GATEWAY"
130 boot_mesg
" DNS Server: $DNS"
133 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var
/ipfire
/red
/dns1
134 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var
/ipfire
/red
/dns2
136 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
137 echo "$IPADDR" > /var
/ipfire
/red
/local-ipaddress
138 echo "$GATEWAY" > /var
/ipfire
/red
/remote-ipaddress
145 elif [ "$TYPE" == "PPPOE" ]; then
146 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
148 boot_mesg
"Bringing up the PPPoE interface on ${DEVICE}..."
149 ip addr add
1.1.1.1/24 broadcast
1.1.1.255 dev
${DEVICE}
151 PPPOECONF
=/etc
/ppp
/pppoe.conf
152 echo > $PPPOECONF #clear
154 if [ "${METHOD}" != "PPPOE_PLUGIN" ]; then
155 echo "LINUX_PLUGIN=" >> $PPPOECONF
157 echo "LINUX_PLUGIN=/usr/lib/pppd/2.4.4/rp-pppoe.so" >> $PPPOECONF
160 echo "ETH=${DEVICE}" >> $PPPOECONF
161 echo "USER=${USERNAME}" >> $PPPOECONF
163 echo "PPPOE_TIMEOUT=80" >> $PPPOECONF
165 #echo "PPPD_EXTRA=\"-U\"" >> $PPPOECONF
166 #echo "PPPOE_EXTRA=\"-m ${MTU}\"" >> $PPPOECONF
168 if [ -n ${SERVICENAME} ]; then
169 echo "SERVICENAME=${SERVICENAME}" >> $PPPOECONF
171 if [ -n ${CONCENTRATORNAME} ]; then
172 echo "ACNAME=${CONCENTRATORNAME}" >> $PPPOECONF
175 if [ "${DNS}" == "Automatic" ]; then
176 echo "PEERDNS=yes" >> $PPPOECONF
177 echo "DNSTYPE=NOCHANGE" >> $PPPOECONF
180 if [ "${AUTH}" == "pap" ]; then
182 elif [ "${AUTH}" == "chap" ]; then
186 echo "FIREWALL=NONE" >> $PPPOECONF
188 if [ "${RECONNECTION}" != "persistent" ]; then
189 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
190 SECONDS
=$
[${TIMEOUT} * 60]
192 if [ "${RECONNECTION}" == "dialondemand" ]; then
193 touch /var
/ipfire
/red
/dial-on-demand
194 echo "DEMAND=${SECONDS}" >> $PPPOECONF
197 echo "DEMAND=no" >> $PPPOECONF
200 echo "LCP_INTERVAL=20" >> $PPPOECONF
201 echo "LCP_FAILURE=3" >> $PPPOECONF
203 echo "PIDFILE=/var/run/ppp-ipfire.pid" >> $PPPOECONF
205 #ARGS+=" maxfail ${MAXRETRIES}"
207 [ "${METHOD}" != "PPPOE_PLUGIN" ] && [ "${DEBUG}" == "on" ] && export DEBUG
=1
208 /usr
/sbin
/pppoe-start
214 if [ "$TYPE" == "STATIC" ]; then
215 boot_mesg
"Removing IPv4 address ${ADDRESS} from the ${DEVICE} interface..."
216 ip addr del
${args} dev
${DEVICE}
219 run_subdir
${rc_base}/init.d
/networking
/red.down
/
221 elif [ "$TYPE" == "DHCP" ]; then
222 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
223 if [ -e $LEASEINFO ]; then
225 if [ "$LEASETIME" = "4294967295" ]; then
226 # do nothing, just echo ok
230 if [ -n "$DHCP_STOP" ]; then
231 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
233 if [ "$RET" -eq 0 ]; then
236 elif [ "$RET" -eq 1 ]; then
237 boot_mesg
"dhcpcd not running!" ${WARNING}
249 boot_mesg
-n "LEASEINFO Test failed! - " ${WARNING}
250 boot_mesg
"dhcpcd is not running!" ${WARNING}
255 elif [ "$TYPE" == "PPPOE" ]; then
256 boot_mesg
"Bringing down the PPPoE interface on ${DEVICE}..."
260 ip addr del
1.1.1.1/24 broadcast
1.1.1.255 dev
${DEVICE}
264 link_status
=`ip link show $DEVICE 2> /dev/null`
265 if [ -n "${link_status}" ]; then
266 if echo "${link_status}" |
grep -q UP
; then
267 boot_mesg
"Bringing down the ${DEVICE} interface..."
268 ip link
set ${DEVICE} down
273 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}