git: 4702a1166ae1 - stable/15 - nuageinit: config2_network support dns service cfg

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Wed, 14 Jan 2026 12:30:59 UTC
The branch stable/15 has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=4702a1166ae14394dcff07373b25a36071c3e26e

commit 4702a1166ae14394dcff07373b25a36071c3e26e
Author:     Gonéri Le Bouder <goneri@lebouder.net>
AuthorDate: 2026-01-03 02:11:55 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2026-01-14 12:30:43 +0000

    nuageinit: config2_network support dns service cfg
    
    This change enhances `config2_network()` to honor the DNS
    configuration, when it's defined through the `services` section.
    
    The `network_data.json` file can hold DNS configuration at two different
    places:
    - within a network configuration entry
    - or `dns` entry in the `services` section, in this case the configuration is global.
    
    An example of such configuration:
    
    {"links": [{"id": "interface0", "type": "phy",
    "ethernet_mac_address": "52:54:00:01:59:03"}], "networks": [{"id": "private-ipv4-0", "type": "ipv4", "link": "interface0",
    "ip_address": "192.168.123.5", "netmask": "255.255.255.0", "routes": [{"network": "0.0.0.0", "netmask": "0.0.0.0", "gateway":
    "192.168.123.1"}], "network_id": "9e5b1ed9-f5e6-4941-a90f-2e06bab858de", "dns_nameservers": ["192.168.123.1"], "services": [{"type":
     "dns", "address": "192.168.123.1"}]}], "services": [{"type": "dns", "address": "192.168.123.1"}]}
    
    See: https://docs.openstack.org/nova/latest/user/metadata.html
    
    MFC After:      1 week
    Signed-off-by: Gonéri Le Bouder <goneri@lebouder.net>
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1941
    (cherry picked from commit 7af8b75201b7af353fa74c8feb937b52f5ccf9bb)
---
 libexec/nuageinit/nuageinit   | 25 ++++++++++++++++++++++++-
 libexec/nuageinit/nuageinit.7 |  2 ++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit
index 0870d6570d0e..aa7d1e4981e6 100755
--- a/libexec/nuageinit/nuageinit
+++ b/libexec/nuageinit/nuageinit
@@ -235,9 +235,16 @@ local function nameservers(interface, obj)
 		resolv_conf_handler:close()
 	end
 
-	if not os.execute("resolvconf -a " .. interface .. " < " .. resolv_conf) then
+	-- Only call resolvconf with interface if interface is provided
+	if interface then
+		resolvconf_command = "resolvconf -a " .. interface .. " < " .. resolv_conf
+    else
+		resolvconf_command = "resolvconf -u"
+	end
+	if not os.execute(resolvconf_command) then
 		nuage.warn("Failed to execute resolvconf(8)")
 	end
+
 end
 
 local function install_packages(packages)
@@ -571,6 +578,22 @@ local function config2_network(p)
 			--end
 		end
 	end
+
+	-- Handle global nameservers from services section
+	if obj["services"] then
+		local dns_servers = {}
+		for _, service in pairs(obj["services"]) do
+			if service["type"] == "dns" then
+				table.insert(dns_servers, service["address"])
+			end
+		end
+		if #dns_servers > 0 then
+			-- Use nameservers() function for global services
+			local nameserver_config = {addresses = dns_servers}
+			nameservers(nil, nameserver_config)
+		end
+	end
+
 	if #ipv4 > 0 then
 		routing:write('static_routes="')
 		routing:write(table.concat(ipv4, " ") .. '"\n')
diff --git a/libexec/nuageinit/nuageinit.7 b/libexec/nuageinit/nuageinit.7
index bb646cf4a652..19f92873de51 100644
--- a/libexec/nuageinit/nuageinit.7
+++ b/libexec/nuageinit/nuageinit.7
@@ -117,6 +117,8 @@ file supports the following keys:
 Array of network interfaces to be configured.
 .It Ic networks
 Array of network configurations to be set.
+.It Ic services
+Array of service configurations to be set (e.g: DNS).
 .El
 .El
 .Pp