]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/system/dhcp
Merge branch 'master' into kernel-4.9
[ipfire-2.x.git] / src / initscripts / system / dhcp
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
10
11 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
12 eval $(/usr/local/bin/readhash /var/ipfire/dhcp/settings)
13
14 function flush_chains() {
15 iptables -F DHCPGREENINPUT
16 iptables -F DHCPGREENOUTPUT
17 iptables -F DHCPBLUEINPUT
18 iptables -F DHCPBLUEOUTPUT
19 }
20
21 case "$1" in
22 start)
23 flush_chains
24
25 if [ -n "${GREEN_DEV}" -a -e "/var/ipfire/dhcp/enable_green" ]; then
26 devices="${GREEN_DEV}"
27
28 iptables -A DHCPGREENINPUT -i "${GREEN_DEV}" -j DHCPINPUT
29 iptables -A DHCPGREENOUTPUT -o "${GREEN_DEV}" -j DHCPOUTPUT
30 fi
31 if [ -n "${BLUE_DEV}" -a -e "/var/ipfire/dhcp/enable_blue" ]; then
32 devices+=" ${BLUE_DEV}"
33
34 iptables -A DHCPBLUEINPUT -i "${BLUE_DEV}" -j DHCPINPUT
35 iptables -A DHCPBLUEOUTPUT -o "${BLUE_DEV}" -j DHCPOUTPUT
36 fi
37
38 boot_mesg "Starting DHCP Server..."
39 loadproc /usr/sbin/dhcpd -q ${devices}
40
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
47 (sleep 5 && chmod 644 /var/run/dhcpd.pid) & # Fix because silly dhcpd creates its pid with mode 640
48 ;;
49
50 stop)
51 flush_chains
52
53 boot_mesg "Stopping DHCP Server..."
54 killproc -p /var/run/dhcpd.pid /usr/sbin/dhcpd
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;
61 fi
62
63 boot_mesg "Stopping Unbound DHCP Leases Bridge..."
64 killproc /usr/sbin/unbound-dhcp-leases-bridge
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
80 statusproc /usr/sbin/unbound-dhcp-leases-bridge
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