Page MenuHomeVyOS Platform

Add support to DHCP server include an extended config
Closed, WontfixPublicFEATURE 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

Version
-
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Feature (new functionality)

Event Timeline

Unknown Object (User) created this task.Oct 16 2020, 6:46 PM

@Dmitry Is it works if you include config as "global parameter" without patching?

set service dhcp-server global-parameters "include "/config/extended_dhcp.conf";"
erkin renamed this task from Adds support to DHCP server include an extended config to Add support to DHCP server include an extended config.Aug 29 2021, 12:38 PM
erkin set Issue type to Feature (new functionality).
erkin removed a subscriber: Global Notifications.
Viacheslav claimed this task.

We agree not to use RAW options for service configuration anymore.