From 278d2116e6426ca5960ca40cf973302d940fa3f5 Mon Sep 17 00:00:00 2001
From: Marius Tomaschewski <mt@suse.com>
Date: Mon, 15 Jul 2024 15:19:36 +0200
Subject: [PATCH 1/2] client: fix to set and use origin in loaded config

Request to update config origin from it's source while reading
to load the config with this origin to worker and send to nanny
on ifup/ifreload or using it in ifstatus/ifcheck.
Removed the "raw" parameter from the load function completely;
it's used to clear the origin and other attributes.
---
 client/ifcheck.c       |  2 +-
 client/ifreload.c      |  2 +-
 client/ifstatus.c      |  2 +-
 client/ifup.c          |  2 +-
 client/read-config.c   | 18 +++++++++++-------
 client/wicked-client.h |  3 +--
 6 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/client/ifcheck.c b/client/ifcheck.c
index f4e4c5b7..b71eb9b7 100644
--- a/client/ifcheck.c
+++ b/client/ifcheck.c
@@ -340,7 +340,7 @@ ni_do_ifcheck(int argc, char **argv)
 		}
 	}
 
-	if (!ni_ifconfig_load(fsm, opt_global_rootdir, &opt_ifconfig, TRUE, TRUE)) {
+	if (!ni_ifconfig_load(fsm, opt_global_rootdir, &opt_ifconfig, TRUE)) {
 		status = NI_WICKED_RC_NOT_CONFIGURED;
 		goto cleanup;
 	}
diff --git a/client/ifreload.c b/client/ifreload.c
index ab7dfe06..b5871173 100644
--- a/client/ifreload.c
+++ b/client/ifreload.c
@@ -308,7 +308,7 @@ usage:
 		}
 	}
 
-	if (!ni_ifconfig_load(fsm, opt_global_rootdir, &opt_ifconfig, TRUE, TRUE)) {
+	if (!ni_ifconfig_load(fsm, opt_global_rootdir, &opt_ifconfig, TRUE)) {
 		status = NI_WICKED_RC_NOT_CONFIGURED;
 		goto cleanup;
 	}
diff --git a/client/ifstatus.c b/client/ifstatus.c
index 568de17b..053fe8a6 100644
--- a/client/ifstatus.c
+++ b/client/ifstatus.c
@@ -844,7 +844,7 @@ ni_do_ifstatus(int argc, char **argv)
 			ni_string_array_copy(&opt_ifconfig, sources);
 	}
 
-	if (!ni_ifconfig_load(fsm, opt_global_rootdir, &opt_ifconfig, TRUE, TRUE)) {
+	if (!ni_ifconfig_load(fsm, opt_global_rootdir, &opt_ifconfig, TRUE)) {
 		status = NI_WICKED_ST_ERROR;
 		goto cleanup;
 	}
diff --git a/client/ifup.c b/client/ifup.c
index 0b843f18..f1a9c647 100644
--- a/client/ifup.c
+++ b/client/ifup.c
@@ -679,7 +679,7 @@ usage:
 		}
 	}
 
-	if (!ni_ifconfig_load(fsm, opt_global_rootdir, &opt_ifconfig, check_prio, TRUE)) {
+	if (!ni_ifconfig_load(fsm, opt_global_rootdir, &opt_ifconfig, check_prio)) {
 		status = NI_WICKED_RC_NOT_CONFIGURED;
 		goto cleanup;
 	}
diff --git a/client/read-config.c b/client/read-config.c
index 9c7ee285..da42d2cf 100644
--- a/client/read-config.c
+++ b/client/read-config.c
@@ -267,18 +267,22 @@ static const ni_ifconfig_type_t		ni_ifconfig_types[] = {
 };
 
 ni_bool_t
-ni_ifconfig_load(ni_fsm_t *fsm, const char *root, ni_string_array_t *opt_ifconfig, ni_bool_t check_prio, ni_bool_t raw)
+ni_ifconfig_load(ni_fsm_t *fsm, const char *root, ni_string_array_t *sources, ni_bool_t check_prio)
 {
 	xml_document_array_t docs = XML_DOCUMENT_ARRAY_INIT;
 	ni_ifconfig_kind_t kind = NI_IFCONFIG_KIND_CONFIG; /* load into fsm */
 	unsigned int i;
 
-	for (i = 0; i < opt_ifconfig->count; ++i) {
-		if (!ni_ifconfig_read(&docs, root, opt_ifconfig->data[i], kind, check_prio, raw)) {
-			xml_document_array_destroy(&docs);
-			return FALSE;
-		}
+	for (i = 0; i < sources->count; ++i) {
+		const char *source = sources->data[i];
+
+		if (ni_ifconfig_read(&docs, root, source, kind, check_prio, FALSE))
+			continue;
+
+		xml_document_array_destroy(&docs);
+		return FALSE;
 	}
+
 	if (ni_ifxml_migrate_docs(&docs))
 		ni_debug_readwrite("Migrated configuration to current schema");
 
@@ -287,7 +291,7 @@ ni_ifconfig_load(ni_fsm_t *fsm, const char *root, ni_string_array_t *opt_ifconfi
 		const char *origin;
 
 		root = xml_document_root(docs.data[i]);
-		origin = xml_node_location_filename(root);
+		origin = ni_ifconfig_get_origin(root);
 		/* We do not fail when unable to generate ifworker */
 		ni_fsm_workers_from_xml(fsm, root, origin);
 	}
diff --git a/client/wicked-client.h b/client/wicked-client.h
index 86fbf255..15e4cd16 100644
--- a/client/wicked-client.h
+++ b/client/wicked-client.h
@@ -149,8 +149,7 @@ extern unsigned int		ni_compat_generate_interfaces(xml_document_array_t *, ni_co
 extern unsigned int		ni_compat_generate_policies(xml_document_array_t *, ni_compat_ifconfig_t *, ni_bool_t, ni_bool_t);
 extern void			ni_compat_netdev_set_origin(ni_compat_netdev_t *, const char *, const char *);
 
-extern ni_bool_t		ni_ifconfig_load(ni_fsm_t *, const char *, ni_string_array_t *,
-						ni_bool_t, ni_bool_t);
+extern ni_bool_t		ni_ifconfig_load(ni_fsm_t *, const char *, ni_string_array_t *, ni_bool_t);
 
 extern const ni_string_array_t *ni_config_sources(const char *);
 
-- 
2.45.2

