Page MenuHomeVyOS Platform

Adds support to DHCP server include an extended config
Open, Requires assessmentPublicFEATURE REQUEST

Description

In some cases require to add additional DHCP global params and we can do it via CLI, but these params should not be repeated. As an example, create classes:

set service dhcp-server global-parameters "class "XX1" {"
set service dhcp-server global-parameters " match if substring (option vendor-class-identifier, 0, 18) = "xxx";"
set service dhcp-server global-parameters " option xxx.image-file-name "xxx.tgz";"
set service dhcp-server global-parameters "}"
set service dhcp-server global-parameters "class "YY1" {"
set service dhcp-server global-parameters " match if substring (option vendor-class-identifier, 0, 18) = "yyy";"
set service dhcp-server global-parameters " option xxx.image-file-name "xxx.tgz";"
set service dhcp-server global-parameters " option xxx.config-file-name "yyy.conf";"
set service dhcp-server global-parameters "}"

Lines set service dhcp-server global-parameters " option xxx.image-file-name "xxx.tgz";" repeated twice.

As for me, this looks a bit ugly. I propose to use native dhcpd.conf function include
Algorithm: dhcp_server.py check if /config/extended_dhcp.conf file exists, then add string include "/config/extended_dhcp.conf"; to /etc/dhcp/dhcpd.conf
Patch already tested on 1.2.6 CRUX

diff --git a/src/conf_mode/dhcp_server.py b/src/conf_mode/dhcp_server.py
index 8dc0856..4d931ce 100755
--- a/src/conf_mode/dhcp_server.py
+++ b/src/conf_mode/dhcp_server.py
@@ -29,6 +29,7 @@ from vyos.config import Config
 from vyos import ConfigError
 
 config_file = r'/etc/dhcp/dhcpd.conf'
+ext_config_file = r'/config/extended_dhcp.conf'
 lease_file = r'/config/dhcpd.leases'
 daemon_config_file = r'/etc/default/isc-dhcp-server'
 
@@ -70,6 +71,9 @@ option windows-static-route code 249 = array of integer 8;
 option wpad-url code 252 = text;
 {% endif %}
 
+{%- if ext_config_file %}
+include "{{ext_config_file}}";
+{%- endif %}
 {%- if global_parameters %}
 # The following {{ global_parameters | length }} line(s) were added as global-parameters in the CLI and have not been validated
 {%- for param in global_parameters %}
@@ -649,6 +653,10 @@ def get_config():
             # append shared network configuration to config dictionary
             dhcp['shared_network'].append(config)
 
+            # Include extended configuration file if exists
+            if os.path.exists(ext_config_file):
+                dhcp['ext_config_file'] = ext_config_file
+
     return dhcp
 
 def verify(dhcp):

Details

Difficulty level
Unknown (require assessment)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)

Event Timeline

Dmitry created this task.Fri, Oct 16, 6:46 PM
pasik added a subscriber: pasik.Sat, Oct 17, 9:44 AM