summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2018-08-29 21:03:16 +0200
committerChristian Poessinger <christian@poessinger.com>2018-08-29 21:03:25 +0200
commitc2351f4dc49c96b70c060edfe7657da5ac423f5d (patch)
tree87f4b7161876a32135fb3dedbf735c9ab3928aa7 /src
parenta0406e87389ad9ff9a045383d50d2bce49179382 (diff)
downloadvyos-1x-c2351f4dc49c96b70c060edfe7657da5ac423f5d.tar.gz
vyos-1x-c2351f4dc49c96b70c060edfe7657da5ac423f5d.zip
dhcp_server.py: improve handling of 'dhcpd.leases' file
If there was yet no lease file present, dhcpd refused to start. Lease file is created if required. Ususally this is handeled by the isc-dhcp-server init script but we use our own path (for persistance) of that file.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/dhcp_server.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/conf_mode/dhcp_server.py b/src/conf_mode/dhcp_server.py
index e03a04a4d..3a095b618 100755
--- a/src/conf_mode/dhcp_server.py
+++ b/src/conf_mode/dhcp_server.py
@@ -28,12 +28,16 @@ from vyos.config import Config
from vyos import ConfigError
config_file = r'/etc/dhcp/dhcpd.conf'
+lease_file = r'/config/dhcpd.leases'
daemon_config_file = r'/etc/default/isc-dhcp-server'
# Please be careful if you edit the template.
config_tmpl = """
### Autogenerated by dhcp_server.py ###
+# For options please consult the following website:
+# https://www.isc.org/wp-content/uploads/2017/08/dhcp43options.html
+
log-facility local7;
{% if hostfile_update %}
@@ -103,7 +107,7 @@ failover peer "{{ subnet.failover_name }}" {
{% endif -%}
{% endfor %}
-# Shared network configrations
+# Shared network configration(s)
{% for network in shared_network %}
{%- if not network.disabled -%}
shared-network {{ network.name }} {
@@ -206,22 +210,14 @@ daemon_tmpl = """
# sourced by /etc/init.d/isc-dhcp-server
-# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
DHCPD_CONF=/etc/dhcp/dhcpd.conf
-
-# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
DHCPD_PID=/var/run/dhcpd.pid
-
-# Additional options to start dhcpd with.
-# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
-OPTIONS="-lf /config/dhcpd.leases"
-
-# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
-# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
+OPTIONS="-4 -lf {{ lease_file }}"
INTERFACES=""
"""
default_config_data = {
+ 'lease_file': lease_file,
'disabled': False,
'ddns_enable': False,
'global_parameters': [],
@@ -764,6 +760,10 @@ def apply(dhcp):
if os.path.exists(daemon_config_file):
os.unlink(daemon_config_file)
else:
+ # If our file holding DHCP leases does yet not exist - create it
+ if not os.path.exists(lease_file):
+ os.mknod(lease_file)
+
os.system('sudo systemctl restart isc-dhcp-server.service')
return None