]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/init.d/networking/red
Postfix-Konfiguration funktioniert.
[ipfire-2.x.git] / src / initscripts / init.d / networking / red
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}"
31 # DNS1
32 # DNS2
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
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
85
86 boot_mesg "Setting up default gateway ${GATEWAY}..."
87 ip route add default via ${GATEWAY} dev ${DEVICE}
88 evaluate_retval
89
90 run_subdir ${rc_base}/init.d/networking/red.up/
91
92 elif [ "${TYPE}" == "DHCP" ]; then
93 boot_mesg -n "Starting dhcpcd on the ${DEVICE} interface..."
94 echo -n "${DEVICE}" > /var/ipfire/red/iface
95
96 # Test to see if there is a stale pid file
97 if [ -f "$PIDFILE" ]; then
98 ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null
99 if [ $? != 0 ]; then
100 rm -f /var/run/dhcpcd-${DEVICE}.pid > /dev/null
101 else
102 boot_mesg "dhcpcd already running!" ${WARNING}
103 echo_warning
104 exit 2
105 fi
106 fi
107
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
110
111 if [ -n "${DHCP_HOSTNAME}" ]; then
112 DHCP_START+="-h ${DHCP_HOSTNAME} "
113 fi
114
115 /sbin/dhcpcd ${DEVICE} ${DHCP_START} >/dev/null 2>&1
116 RET="$?"
117
118 if [ "$RET" = "0" ]; then
119 . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info
120 echo ""
121 echo_ok
122 boot_mesg " DHCP Assigned Settings for ${DEVICE}:"
123 boot_mesg_flush
124 boot_mesg " IP Address: $IPADDR"
125 boot_mesg_flush
126 if [ -n "${DHCP_HOSTNAME}" ]; then
127 boot_mesg " Hostname: $DHCP_HOSTNAME"
128 boot_mesg_flush
129 fi
130 boot_mesg " Subnet Mask: $NETMASK"
131 boot_mesg_flush
132 boot_mesg " Default Gateway: $GATEWAY"
133 boot_mesg_flush
134 boot_mesg " DNS Server: $DNS"
135 boot_mesg_flush
136
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
139
140 . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info
141 echo "$IPADDR" > /var/ipfire/red/local-ipaddress
142 echo "$GATEWAY" > /var/ipfire/red/remote-ipaddress
143 else
144 echo ""
145 $(exit "$RET")
146 evaluate_retval
147 fi
148
149 elif [ "$TYPE" == "PPPOE" ]; then
150
151 eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
152
153 [ -c "/dev/ppp" ] || mknod /dev/ppp c 108 0
154
155 if [ "$TYPE" == "pppoe" ]; then
156 boot_mesg "Bringing up the PPPoE interface on ${DEVICE}..."
157 ip addr add 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE}
158 else
159 boot_mesg "Bringing up the PPP via ${TYPE} on ${COMPORT}..."
160 fi
161
162 ### ###
163 ### Configuring the pppd ###
164 ### ###
165
166 ### Plugin Options
167 #
168 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
169 PLUGOPTS="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so nic-${DEVICE}"
170
171 ### Synchronous Mode
172 #
173 #PPPOE_SYNC=-s
174 #PPPD_SYNC=sync
175
176 ### Access Concentrator Name
177 #
178 if [ -n "${CONCENTRATORNAME}" ]; then
179 ACNAME="-C ${CONCENTRATORNAME}"
180 fi
181
182 ### Service Name
183 #
184 if [ -n "${SERVICENAME}" ]; then
185 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
186 PLUGOPTS+=" rp_pppoe_service ${SERVICENAME}"
187 else
188 SERVICENAME="-S ${SERVICENAME}"
189 fi
190 fi
191
192 ### Authentication Types
193 #
194 if [ "${AUTH}" == "pap" ]; then
195 AUTH="-chap"
196 elif [ "${AUTH}" == "chap" ]; then
197 AUTH="-pap"
198 else
199 AUTH=""
200 fi
201
202 ### Dial On Demand
203 #
204 if [ "${RECONNECTION}" != "persistent" ]; then
205 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
206 SECONDS=$[${TIMEOUT} * 60]
207 else
208 SECONDS=300
209 fi
210 if [ "${RECONNECTION}" == "dialondemand" ]; then
211 touch /var/ipfire/red/dial-on-demand
212 DEMAND="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
213 DEMAND+=" ipcp-accept-remote ipcp-accept-local connect true noipdefault ktune"
214 fi
215 fi
216
217 ### When using pppoe-plugin the device has to be the last option
218 #
219 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS+=" ${DEVICE}"
220
221 if [ "$TYPE" == "modem" ]; then
222 PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer"
223 elif [ "$TYPE" == "serial" ]; then
224 PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /bin/true"
225 fi
226
227 ### Standard PPP options we always use
228 #
229 PPP_STD_OPTIONS="$PLUGOPTS usepeerdns defaultroute noipdefault noauth"
230 PPP_STD_OPTIONS+=" default-asyncmap hide-password nodetach mtu ${MTU}"
231 PPP_STD_OPTIONS+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
232 PPP_STD_OPTIONS+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
233 PPP_STD_OPTIONS+=" lcp-echo-failure 3 ${AUTH}"
234 [ "${TYPE}" eq "pppoe" ] || PPP_STD_OPTIONS+=" lock modem crtscts user ${USERNAME}"
235
236 ### Debugging
237 #
238 if [ "${DEBUG}" == "on" ]; then
239 DEBUG="debug"
240 else
241 DEBUG=""
242 fi
243
244 ### PPPoE invocation
245 #
246 if [ "${TYPE}" == "pppoe" ]; then
247 PPPOE_CMD="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I ${DEVICE}"
248 PPPOE_CMD+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
249 fi
250
251 ### Run everything
252 #
253 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
254 /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND >/dev/null 2>&1 &
255 evaluate_retval
256 else
257 /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev/null 2>&1 &
258 evaluate_retval
259 fi
260
261 /etc/rc.d/init.d/connectd start
262
263 fi
264 ;;
265
266 stop)
267 if [ "$TYPE" == "STATIC" ]; then
268 boot_mesg "Removing IPv4 address ${ADDRESS} from the ${DEVICE} interface..."
269 ip addr del ${args} dev ${DEVICE}
270 evaluate_retval
271
272 run_subdir ${rc_base}/init.d/networking/red.down/
273
274 elif [ "$TYPE" == "DHCP" ]; then
275 boot_mesg -n "Stopping dhcpcd on the ${DEVICE} interface..."
276 if [ -e $LEASEINFO ]; then
277 . $LEASEINFO
278 if [ "$LEASETIME" = "4294967295" ]; then
279 # do nothing, just echo ok
280 echo ""
281 echo_ok
282 else
283 if [ -n "$DHCP_STOP" ]; then
284 /sbin/dhcpcd ${DEVICE} $DHCP_STOP &> /dev/null
285 RET="$?"
286 if [ "$RET" -eq 0 ]; then
287 echo ""
288 echo_ok
289 elif [ "$RET" -eq 1 ]; then
290 boot_mesg "dhcpcd not running!" ${WARNING}
291 echo_warning
292 else
293 echo ""
294 echo_failure
295 fi
296 else
297 echo ""
298 killproc dhcpcd
299 fi
300 fi
301 else
302 boot_mesg -n "LEASEINFO Test failed! - " ${WARNING}
303 boot_mesg "dhcpcd is not running!" ${WARNING}
304 echo_warning
305 exit 1
306 fi
307
308 elif [ "$TYPE" == "PPPOE" ]; then
309 boot_mesg "Bringing down the PPPoE interface on ${DEVICE}..."
310 rm -f /var/ipfire/red/keepconnected
311 kill -TERM /usr/sbin/pppd 2>/dev/null
312 evaluate_retval
313 sleep 5
314
315 ip addr del 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE}
316
317 fi
318
319 link_status=`ip link show $DEVICE 2> /dev/null`
320 if [ -n "${link_status}" ]; then
321 if echo "${link_status}" | grep -q UP; then
322 boot_mesg "Bringing down the ${DEVICE} interface..."
323 ip link set ${DEVICE} down
324 evaluate_retval
325 fi
326 fi
327
328 rm -f /var/ipfire/red/{active,device,dial-on-demand,dns1,dns2,local-ipaddress,remote-ipaddress,resolv.conf}
329 ;;
330
331 esac
332
333 # End