From 04681a8b0a99beaef088be9a210359c0626f33bf Mon Sep 17 00:00:00 2001 From: Danilo Egea Gondolfo Date: Mon, 26 Jun 2023 18:17:39 +0100 Subject: [PATCH] parse: handle redefinition of a place holder netdef If we find an interface with the same name of a place holder created earlier, we just change the place holder type to the type of the new interface and use it to store the configuration. Without this logic the parser would fail if it finds an interface with the same name of the place holder but of a different type. --- src/parse.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/parse.c b/src/parse.c index 85ceeaf67..977b623fa 100644 --- a/src/parse.c +++ b/src/parse.c @@ -3071,8 +3071,13 @@ handle_network_type(NetplanParser* npp, yaml_node_t* node, const char* key_prefi npp->current.netdef = npp->parsed_defs ? g_hash_table_lookup(npp->parsed_defs, scalar(key)) : NULL; if (npp->current.netdef) { /* already exists, overriding/amending previous definition */ - if (npp->current.netdef->type != GPOINTER_TO_UINT(data)) - return yaml_error(npp, key, error, "Updated definition '%s' changes device type", scalar(key)); + if (npp->current.netdef->type != GPOINTER_TO_UINT(data)) { + /* If the existing netdef is a place holder, we just repurpose it */ + if (npp->current.netdef->type == NETPLAN_DEF_TYPE_NM_PLACEHOLDER_) + npp->current.netdef->type = GPOINTER_TO_UINT(data); + else + return yaml_error(npp, key, error, "Updated definition '%s' changes device type", scalar(key)); + } } else { npp->current.netdef = netplan_netdef_new(npp, scalar(key), GPOINTER_TO_UINT(data), npp->current.backend); }