From 08cec2e9bc0a9905ce26ce888d4c3d54ccecf3d5 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 29 Jan 2024 20:35:22 +0100 Subject: [PATCH] confd: add exception for hostname DHCP client option No need to guard the hostname option in quotes, it must not contain whitespace. If user configured more than one word, use first. Fixes #283 Signed-off-by: Joachim Wiberg --- src/confd/src/infix-dhcp.c | 3 +++ src/confd/yang/infix-dhcp-client@2023-05-22.yang | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/confd/src/infix-dhcp.c b/src/confd/src/infix-dhcp.c index 18ea16ef..6f3e8860 100644 --- a/src/confd/src/infix-dhcp.c +++ b/src/confd/src/infix-dhcp.c @@ -22,6 +22,7 @@ static const struct srx_module_requirement reqs[] = { { NULL } }; + static char *ip_cache(const char *ifname, char *str, size_t len) { const char *fn = "/var/lib/misc/%s.cache"; @@ -148,6 +149,8 @@ static char *compose_option(const char *ifname, const char *name, const char *va } else { if (!strcmp(name, "fqdn")) fqdn(value, option, len); + else if (!strcmp(name, "hostname")) + snprintf(option, len, "-x %s:%s ", name, value); else snprintf(option, len, "-x %s:'\"%s\"' ", name, value); } diff --git a/src/confd/yang/infix-dhcp-client@2023-05-22.yang b/src/confd/yang/infix-dhcp-client@2023-05-22.yang index a70c2199..ef6eb1d0 100644 --- a/src/confd/yang/infix-dhcp-client@2023-05-22.yang +++ b/src/confd/yang/infix-dhcp-client@2023-05-22.yang @@ -133,9 +133,10 @@ module infix-dhcp-client { leaf value { type string; description "Optional value, only used for non-flag request options. - Example: option:hostname, value:xyzzy - option:clientid, value:01:02:03:04:05:06:07:08:09:0a - option:0x51, value:xyzzy.example.com"; + Example: option:hostname, value:xyzzy + option:clientid, value:01:02:03:04:05:06:07:08:09:0a + option:0x51, value:xyzzy.example.com"; + must "../name != 'hostname' or re-match(., '[a-zA-Z0-9\\-_]{0,253}')"; } } leaf route-preference {