summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-11-20 15:53:45 +0100
committerGitHub <noreply@github.com>2023-11-20 15:53:45 +0100
commit391bd40f863b490241c6101e6333ba1327f32586 (patch)
treec8779bec9ea2cc50af26ef7ac2e66d964e30577e
parente92667504e0c503b7c0d125d89d8795d6b6d5876 (diff)
parent260645d0c6ff078cc89601f3a586195902f9c18e (diff)
downloadvyos-1x-391bd40f863b490241c6101e6333ba1327f32586.tar.gz
vyos-1x-391bd40f863b490241c6101e6333ba1327f32586.zip
Merge pull request #2506 from c-po/t5760-dhcp-user-class
dhcp-client: T5760: add CLI option to pass user-class parameter
-rw-r--r--data/templates/dhcp-client/ipv4.j224
-rw-r--r--interface-definitions/include/constraint/dhcp-client-string-option.xml.i4
-rw-r--r--interface-definitions/include/interface/dhcp-options.xml.i26
-rw-r--r--smoketest/scripts/cli/base_interfaces_test.py16
4 files changed, 64 insertions, 6 deletions
diff --git a/data/templates/dhcp-client/ipv4.j2 b/data/templates/dhcp-client/ipv4.j2
index cc5ddf09c..77905e054 100644
--- a/data/templates/dhcp-client/ipv4.j2
+++ b/data/templates/dhcp-client/ipv4.j2
@@ -9,14 +9,30 @@ interface "{{ ifname }}" {
send host-name "{{ dhcp_options.host_name }}";
{% if dhcp_options.client_id is vyos_defined %}
{% set client_id = dhcp_options.client_id %}
-{# Use HEX representation of client-id as it is send in MAC-address style using hex characters. If not HEX, use double quotes ASCII format #}
-{% if not dhcp_options.client_id.split(':') | length >= 5 %}
-{% set client_id = '"' + dhcp_options.client_id + '"' %}
+{# Use HEX representation of client-id as it is send in MAC-address style using hex characters. #}
+{# If not HEX, use double quotes ASCII format #}
+{% if not client_id.split(':') | length >= 3 %}
+{% set client_id = '"' ~ dhcp_options.client_id ~ '"' %}
{% endif %}
send dhcp-client-identifier {{ client_id }};
{% endif %}
{% if dhcp_options.vendor_class_id is vyos_defined %}
- send vendor-class-identifier "{{ dhcp_options.vendor_class_id }}";
+{% set vendor_class_id = dhcp_options.vendor_class_id %}
+{# Use HEX representation of client-id as it is send in MAC-address style using hex characters. #}
+{# If not HEX, use double quotes ASCII format #}
+{% if not vendor_class_id.split(':') | length >= 3 %}
+{% set vendor_class_id = '"' ~ dhcp_options.vendor_class_id ~ '"' %}
+{% endif %}
+ send vendor-class-identifier {{ vendor_class_id }};
+{% endif %}
+{% if dhcp_options.user_class is vyos_defined %}
+{% set user_class = dhcp_options.user_class %}
+{# Use HEX representation of client-id as it is send in MAC-address style using hex characters. #}
+{# If not HEX, use double quotes ASCII format #}
+{% if not user_class.split(':') | length >= 3 %}
+{% set user_class = '"' ~ dhcp_options.user_class ~ '"' %}
+{% endif %}
+ send user-class {{ user_class }};
{% endif %}
# The request statement causes the client to request that any server responding to the
# client send the client its values for the specified options.
diff --git a/interface-definitions/include/constraint/dhcp-client-string-option.xml.i b/interface-definitions/include/constraint/dhcp-client-string-option.xml.i
new file mode 100644
index 000000000..76e0e5466
--- /dev/null
+++ b/interface-definitions/include/constraint/dhcp-client-string-option.xml.i
@@ -0,0 +1,4 @@
+<!-- include start from include/constraint/dhcp-client-string-option.xml.i -->
+<regex>[-_a-zA-Z0-9\s]+</regex>
+<regex>([a-fA-F0-9][a-fA-F0-9]:){2,}[a-fA-F0-9][a-fA-F0-9]</regex>
+<!-- include end -->
diff --git a/interface-definitions/include/interface/dhcp-options.xml.i b/interface-definitions/include/interface/dhcp-options.xml.i
index 8027769ff..733512a98 100644
--- a/interface-definitions/include/interface/dhcp-options.xml.i
+++ b/interface-definitions/include/interface/dhcp-options.xml.i
@@ -7,6 +7,13 @@
<leafNode name="client-id">
<properties>
<help>Identifier used by client to identify itself to the DHCP server</help>
+ <valueHelp>
+ <format>txt</format>
+ <description>DHCP option string</description>
+ </valueHelp>
+ <constraint>
+ #include <include/constraint/dhcp-client-string-option.xml.i>
+ </constraint>
</properties>
</leafNode>
<leafNode name="host-name">
@@ -27,6 +34,25 @@
<leafNode name="vendor-class-id">
<properties>
<help>Identify the vendor client type to the DHCP server</help>
+ <valueHelp>
+ <format>txt</format>
+ <description>DHCP option string</description>
+ </valueHelp>
+ <constraint>
+ #include <include/constraint/dhcp-client-string-option.xml.i>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="user-class">
+ <properties>
+ <help>Identify to the DHCP server, user configurable option</help>
+ <valueHelp>
+ <format>txt</format>
+ <description>DHCP option string</description>
+ </valueHelp>
+ <constraint>
+ #include <include/constraint/dhcp-client-string-option.xml.i>
+ </constraint>
</properties>
</leafNode>
#include <include/interface/no-default-route.xml.i>
diff --git a/smoketest/scripts/cli/base_interfaces_test.py b/smoketest/scripts/cli/base_interfaces_test.py
index 73b4e9764..da196133a 100644
--- a/smoketest/scripts/cli/base_interfaces_test.py
+++ b/smoketest/scripts/cli/base_interfaces_test.py
@@ -158,14 +158,22 @@ class BasicInterfaceTest:
if not self._test_dhcp or not self._test_vrf:
self.skipTest('not supported')
+ client_id = 'VyOS-router'
distance = '100'
+ hostname = 'vyos'
+ vendor_class_id = 'vyos-vendor'
+ user_class = 'vyos'
for interface in self._interfaces:
for option in self._options.get(interface, []):
self.cli_set(self._base_path + [interface] + option.split())
self.cli_set(self._base_path + [interface, 'address', 'dhcp'])
+ self.cli_set(self._base_path + [interface, 'dhcp-options', 'client-id', client_id])
self.cli_set(self._base_path + [interface, 'dhcp-options', 'default-route-distance', distance])
+ self.cli_set(self._base_path + [interface, 'dhcp-options', 'host-name', hostname])
+ self.cli_set(self._base_path + [interface, 'dhcp-options', 'vendor-class-id', vendor_class_id])
+ self.cli_set(self._base_path + [interface, 'dhcp-options', 'user-class', user_class])
self.cli_commit()
@@ -175,8 +183,12 @@ class BasicInterfaceTest:
self.assertTrue(dhclient_pid)
dhclient_config = read_file(f'{dhclient_base_dir}/dhclient_{interface}.conf')
- self.assertIn('request subnet-mask, broadcast-address, routers, domain-name-servers', dhclient_config)
- self.assertIn('require subnet-mask;', dhclient_config)
+ self.assertIn(f'request subnet-mask, broadcast-address, routers, domain-name-servers', dhclient_config)
+ self.assertIn(f'require subnet-mask;', dhclient_config)
+ self.assertIn(f'send host-name "{hostname}";', dhclient_config)
+ self.assertIn(f'send dhcp-client-identifier "{client_id}";', dhclient_config)
+ self.assertIn(f'send vendor-class-identifier "{vendor_class_id}";', dhclient_config)
+ self.assertIn(f'send user-class "{user_class}";', dhclient_config)
# and the commandline has the appropriate options
cmdline = read_file(f'/proc/{dhclient_pid}/cmdline')