]>
Commit | Line | Data |
---|---|---|
6bdd769d MT |
1 | #!/bin/sh |
2 | # Begin $rc_base/init.d/dhcp | |
3 | ||
4 | # Based on sysklogd script from LFS-3.1 and earlier. | |
5 | # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org | |
6 | # Modified for IPFire by Michael Tremer - mitch@ipfire.org | |
7 | ||
8 | . /etc/sysconfig/rc | |
9 | . $rc_functions | |
6f5d8f0c | 10 | |
6bdd769d | 11 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) |
6f5d8f0c | 12 | eval $(/usr/local/bin/readhash /var/ipfire/dhcp/settings) |
6bdd769d | 13 | |
8490e496 MT |
14 | function flush_chains() { |
15 | iptables -F DHCPGREENINPUT | |
16 | iptables -F DHCPGREENOUTPUT | |
17 | iptables -F DHCPBLUEINPUT | |
18 | iptables -F DHCPBLUEOUTPUT | |
19 | } | |
20 | ||
6bdd769d MT |
21 | case "$1" in |
22 | start) | |
8490e496 MT |
23 | flush_chains |
24 | ||
838925a6 | 25 | if [ -n "${GREEN_DEV}" -a -e "/var/ipfire/dhcp/enable_green" ]; then |
6bdd769d | 26 | devices="${GREEN_DEV}" |
8490e496 MT |
27 | |
28 | iptables -A DHCPGREENINPUT -i "${GREEN_DEV}" -j DHCPINPUT | |
29 | iptables -A DHCPGREENOUTPUT -o "${GREEN_DEV}" -j DHCPOUTPUT | |
6bdd769d | 30 | fi |
838925a6 | 31 | if [ -n "${BLUE_DEV}" -a -e "/var/ipfire/dhcp/enable_blue" ]; then |
8e8bbd9d | 32 | devices+=" ${BLUE_DEV}" |
8490e496 MT |
33 | |
34 | iptables -A DHCPBLUEINPUT -i "${BLUE_DEV}" -j DHCPINPUT | |
35 | iptables -A DHCPBLUEOUTPUT -o "${BLUE_DEV}" -j DHCPOUTPUT | |
36 | fi | |
37 | ||
6bdd769d MT |
38 | boot_mesg "Starting DHCP Server..." |
39 | loadproc /usr/sbin/dhcpd -q ${devices} | |
838925a6 | 40 | |
6f5d8f0c MT |
41 | # Start Unbound DHCP Lease Bridge unless RFC2136 is used |
42 | if [ "${DNS_UPDATE_ENABLED}" != on ]; then | |
43 | boot_mesg "Starting Unbound DHCP Leases Bridge..." | |
44 | loadproc /usr/sbin/unbound-dhcp-leases-bridge -d | |
45 | fi | |
46 | ||
a2d5130f | 47 | (sleep 5 && chmod 644 /var/run/dhcpd.pid) & # Fix because silly dhcpd creates its pid with mode 640 |
6bdd769d MT |
48 | ;; |
49 | ||
50 | stop) | |
8490e496 MT |
51 | flush_chains |
52 | ||
6bdd769d | 53 | boot_mesg "Stopping DHCP Server..." |
e5ba3160 | 54 | killproc -p /var/run/dhcpd.pid /usr/sbin/dhcpd |
274a6064 AF |
55 | if [ "$(ps -A | grep " dhcpd")" != "" ] ; then |
56 | # if fail use the hard way ... | |
57 | boot_mesg "Killing DHCP Server..." | |
58 | killall -w -s KILL /usr/sbin/dhcpd > /dev/null 2>&1 | |
59 | rm -f /var/run/dhcpd.pid > /dev/null 2>&1 | |
60 | echo_ok; | |
274a6064 | 61 | fi |
6f5d8f0c MT |
62 | |
63 | boot_mesg "Stopping Unbound DHCP Leases Bridge..." | |
64 | killproc /usr/sbin/unbound-dhcp-leases-bridge | |
6bdd769d MT |
65 | ;; |
66 | ||
67 | reload) | |
68 | boot_mesg "Reloading DHCP Server..." | |
69 | reloadproc /usr/sbin/dhcpd | |
70 | ;; | |
71 | ||
72 | restart) | |
73 | $0 stop | |
74 | sleep 1 | |
75 | $0 start | |
76 | ;; | |
77 | ||
78 | status) | |
79 | statusproc /usr/sbin/dhcpd | |
6f5d8f0c | 80 | statusproc /usr/sbin/unbound-dhcp-leases-bridge |
6bdd769d MT |
81 | ;; |
82 | ||
83 | *) | |
84 | echo "Usage: $0 {start|stop|reload|restart|status}" | |
85 | exit 1 | |
86 | ;; | |
87 | esac | |
88 | ||
89 | # End $rc_base/init.d/dhcp |