]>
Commit | Line | Data |
---|---|---|
d1e90efc MT |
1 | #!/bin/sh |
2 | ######################################################################## | |
3 | # Begin | |
4 | # | |
5 | # Description : RED Device Script | |
6 | # | |
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 | |
11 | # | |
12 | # Version : 01.00 | |
13 | # | |
14 | # Notes : | |
15 | # | |
16 | ######################################################################## | |
17 | ||
18 | . /etc/sysconfig/rc | |
19 | . ${rc_functions} | |
20 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
21 | ||
22 | TYPE="${RED_TYPE}" | |
23 | DEVICE="${RED_DEV}" | |
24 | ||
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}" | |
0db33b56 MT |
31 | # DNS1 |
32 | # DNS2 | |
d1e90efc MT |
33 | |
34 | if [ -z "${BROADCAST}" ]; then | |
35 | boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE} | |
36 | echo_failure | |
37 | exit 1 | |
38 | fi | |
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}" | |
42 | else | |
43 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
44 | echo_failure | |
45 | exit 1 | |
46 | fi | |
47 | ||
48 | elif [ "${TYPE}" == "DHCP" ]; then | |
49 | ||
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 " | |
54 | ||
55 | fi | |
56 | ||
57 | case "${1}" in | |
58 | start) | |
59 | boot_mesg "Bringing up the ${DEVICE} interface..." | |
60 | boot_mesg_flush | |
61 | ||
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 | |
68 | fi | |
69 | fi | |
70 | else | |
71 | boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE} | |
72 | echo_failure | |
73 | exit 1 | |
74 | fi | |
75 | ||
76 | if [ "${TYPE}" == "STATIC" ]; then | |
77 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..." | |
78 | ip addr add ${args} dev ${DEVICE} | |
79 | evaluate_retval | |
0db33b56 MT |
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 | |
d1e90efc | 85 | |
0e42072a MT |
86 | run_subdir ${rc_base}/init.d/networking/red.up/ |
87 | ||
d1e90efc MT |
88 | elif [ "${TYPE}" == "DHCP" ]; then |
89 | boot_mesg -n "Starting dhcpcd on the ${DEVICE} interface..." | |
90 | echo -n "${DEVICE}" > /var/ipfire/red/iface | |
91 | ||
92 | # Test to see if there is a stale pid file | |
93 | if [ -f "$PIDFILE" ]; then | |
94 | ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null | |
95 | if [ $? != 0 ]; then | |
96 | rm -f /var/run/dhcpcd-${DEVICE}.pid > /dev/null | |
97 | else | |
98 | boot_mesg "dhcpcd already running!" ${WARNING} | |
99 | echo_warning | |
100 | exit 2 | |
101 | fi | |
102 | fi | |
103 | ||
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 | |
106 | ||
107 | if [ -n "${DHCP_HOSTNAME}" ]; then | |
108 | DHCP_START+="-h ${DHCP_HOSTNAME} " | |
109 | fi | |
110 | ||
111 | /sbin/dhcpcd ${DEVICE} ${DHCP_START} >/dev/null 2>&1 | |
112 | RET="$?" | |
113 | ||
114 | if [ "$RET" = "0" ]; then | |
115 | . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info | |
116 | echo "" | |
117 | echo_ok | |
118 | boot_mesg " DHCP Assigned Settings for ${DEVICE}:" | |
119 | boot_mesg_flush | |
120 | boot_mesg " IP Address: $IPADDR" | |
121 | boot_mesg_flush | |
122 | if [ -n "${DHCP_HOSTNAME}" ]; then | |
123 | boot_mesg " Hostname: $DHCP_HOSTNAME" | |
124 | boot_mesg_flush | |
125 | fi | |
126 | boot_mesg " Subnet Mask: $NETMASK" | |
127 | boot_mesg_flush | |
128 | boot_mesg " Default Gateway: $GATEWAY" | |
129 | boot_mesg_flush | |
130 | boot_mesg " DNS Server: $DNS" | |
131 | boot_mesg_flush | |
132 | ||
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 | |
135 | ||
136 | . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info | |
137 | echo "$IPADDR" > /var/ipfire/red/local-ipaddress | |
138 | echo "$GATEWAY" > /var/ipfire/red/remote-ipaddress | |
139 | else | |
140 | echo "" | |
141 | $(exit "$RET") | |
142 | evaluate_retval | |
143 | fi | |
144 | ||
145 | elif [ "$TYPE" == "PPPOE" ]; then | |
905fbf3e | 146 | |
d1e90efc MT |
147 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) |
148 | ||
149 | boot_mesg "Bringing up the PPPoE interface on ${DEVICE}..." | |
150 | ip addr add 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE} | |
151 | ||
905fbf3e | 152 | [ -c "/dev/ppp" ] || mknod /dev/ppp c 108 0 |
d1e90efc | 153 | |
905fbf3e MT |
154 | ### ### |
155 | ### Configuring the pppd ### | |
156 | ### ### | |
157 | ||
158 | ### Plugin Options | |
159 | # | |
160 | [ "${METHOD}" == "PPPOE_PLUGIN" ] && \ | |
161 | PLUGOPTS="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so nic-${DEVICE}" | |
d1e90efc | 162 | |
905fbf3e MT |
163 | ### Synchronous Mode |
164 | # | |
165 | #PPPOE_SYNC=-s | |
166 | #PPPD_SYNC=sync | |
167 | ||
168 | ### Access Concentrator Name | |
169 | # | |
170 | if [ -n "${CONCENTRATORNAME}" ]; then | |
171 | ACNAME="-C ${CONCENTRATORNAME}" | |
d1e90efc | 172 | fi |
905fbf3e MT |
173 | |
174 | ### Service Name | |
175 | # | |
176 | if [ -n "${SERVICENAME}" ]; then | |
177 | if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then | |
178 | PLUGOPTS+=" rp_pppoe_service ${SERVICENAME}" | |
179 | else | |
180 | SERVICENAME="-S ${SERVICENAME}" | |
181 | fi | |
d1e90efc | 182 | fi |
905fbf3e MT |
183 | |
184 | ### Authentication Types | |
185 | # | |
d1e90efc | 186 | if [ "${AUTH}" == "pap" ]; then |
905fbf3e | 187 | AUTH="-chap" |
d1e90efc | 188 | elif [ "${AUTH}" == "chap" ]; then |
905fbf3e | 189 | AUTH="-pap" |
d1e90efc | 190 | fi |
905fbf3e MT |
191 | |
192 | ### Dial On Demand | |
193 | # | |
d1e90efc MT |
194 | if [ "${RECONNECTION}" != "persistent" ]; then |
195 | if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then | |
196 | SECONDS=$[${TIMEOUT} * 60] | |
905fbf3e MT |
197 | else |
198 | SECONDS=300 | |
d1e90efc MT |
199 | fi |
200 | if [ "${RECONNECTION}" == "dialondemand" ]; then | |
201 | touch /var/ipfire/red/dial-on-demand | |
905fbf3e MT |
202 | DEMAND="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113" |
203 | DEMAND+=" ipcp-accept-remote ipcp-accept-local connect true noipdefault ktune" | |
d1e90efc | 204 | fi |
905fbf3e MT |
205 | fi |
206 | ||
207 | ### When using plugin the device has to be the last option | |
208 | # | |
209 | [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS+=" ${DEVICE}" | |
210 | ||
211 | ### Standard PPP options we always use | |
212 | # | |
213 | PPP_STD_OPTIONS="$PLUGOPTS usepeerdns defaultroute noipdefault noauth" | |
214 | PPP_STD_OPTIONS+=" default-asyncmap hide-password nodetach mtu ${MTU}" | |
215 | PPP_STD_OPTIONS+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp" | |
216 | PPP_STD_OPTIONS+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20" | |
217 | PPP_STD_OPTIONS+=" lcp-echo-failure 3 ${AUTH}" | |
218 | ||
219 | ### Debugging | |
220 | # | |
221 | if [ "${DEBUG}" == "on" ]; then | |
222 | DEBUG="debug" | |
d1e90efc | 223 | else |
905fbf3e | 224 | DEBUG="" |
d1e90efc MT |
225 | fi |
226 | ||
905fbf3e MT |
227 | ### PPPoE invocation |
228 | # | |
229 | PPPOE_CMD="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I ${DEVICE}" | |
230 | PPPOE_CMD+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT" | |
d1e90efc | 231 | |
905fbf3e MT |
232 | ### Run everything |
233 | # | |
234 | if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then | |
235 | /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND >/dev/null 2>&1 & | |
236 | evaluate_retval | |
237 | else | |
238 | /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev/null 2>&1 & | |
239 | evaluate_retval | |
240 | fi | |
241 | ||
242 | /etc/rc.d/init.d/connectd start | |
243 | ||
d1e90efc | 244 | fi |
d1e90efc MT |
245 | ;; |
246 | ||
247 | stop) | |
248 | if [ "$TYPE" == "STATIC" ]; then | |
249 | boot_mesg "Removing IPv4 address ${ADDRESS} from the ${DEVICE} interface..." | |
250 | ip addr del ${args} dev ${DEVICE} | |
251 | evaluate_retval | |
252 | ||
0e42072a MT |
253 | run_subdir ${rc_base}/init.d/networking/red.down/ |
254 | ||
d1e90efc MT |
255 | elif [ "$TYPE" == "DHCP" ]; then |
256 | boot_mesg -n "Stopping dhcpcd on the ${DEVICE} interface..." | |
257 | if [ -e $LEASEINFO ]; then | |
258 | . $LEASEINFO | |
259 | if [ "$LEASETIME" = "4294967295" ]; then | |
260 | # do nothing, just echo ok | |
261 | echo "" | |
262 | echo_ok | |
263 | else | |
264 | if [ -n "$DHCP_STOP" ]; then | |
265 | /sbin/dhcpcd ${DEVICE} $DHCP_STOP &> /dev/null | |
266 | RET="$?" | |
267 | if [ "$RET" -eq 0 ]; then | |
268 | echo "" | |
269 | echo_ok | |
270 | elif [ "$RET" -eq 1 ]; then | |
271 | boot_mesg "dhcpcd not running!" ${WARNING} | |
272 | echo_warning | |
273 | else | |
274 | echo "" | |
275 | echo_failure | |
276 | fi | |
277 | else | |
278 | echo "" | |
279 | killproc dhcpcd | |
280 | fi | |
281 | fi | |
282 | else | |
283 | boot_mesg -n "LEASEINFO Test failed! - " ${WARNING} | |
284 | boot_mesg "dhcpcd is not running!" ${WARNING} | |
285 | echo_warning | |
286 | exit 1 | |
287 | fi | |
288 | ||
289 | elif [ "$TYPE" == "PPPOE" ]; then | |
290 | boot_mesg "Bringing down the PPPoE interface on ${DEVICE}..." | |
905fbf3e MT |
291 | killproc /usr/sbin/pppd |
292 | ||
d1e90efc MT |
293 | ip addr del 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE} |
294 | ||
295 | fi | |
296 | ||
297 | link_status=`ip link show $DEVICE 2> /dev/null` | |
298 | if [ -n "${link_status}" ]; then | |
299 | if echo "${link_status}" | grep -q UP; then | |
300 | boot_mesg "Bringing down the ${DEVICE} interface..." | |
301 | ip link set ${DEVICE} down | |
302 | evaluate_retval | |
303 | fi | |
304 | fi | |
305 | ||
f480386f | 306 | rm -f /var/ipfire/red/{active,device,dial-on-demand,dns1,dns2,local-ipaddress,remote-ipaddress,resolv.conf} |
d1e90efc MT |
307 | ;; |
308 | ||
309 | esac | |
310 | ||
311 | # End |