From 9a09c02012dd20edc052d5646b1044a0b137a3cd Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 14 Jul 2021 09:49:42 +0200 Subject: core: persist the bootfile from DHCP The bootfile location is needed by the anaconda dracut module; write it to the device state file. --- src/core/nm-config.c | 21 ++++++++++++++++----- src/core/nm-config.h | 3 ++- src/core/nm-manager.c | 15 ++++++++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/core/nm-config.c b/src/core/nm-config.c index fdc450a0e6..94ec7f381b 100644 --- a/src/core/nm-config.c +++ b/src/core/nm-config.c @@ -2343,8 +2343,9 @@ _nm_config_state_set(NMConfig *self, gboolean allow_persist, gboolean force_pers "route-metric-default-aspired" #define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_ROUTE_METRIC_DEFAULT_EFFECTIVE \ "route-metric-default-effective" -#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_ROOT_PATH "root-path" -#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NEXT_SERVER "next-server" +#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_ROOT_PATH "root-path" +#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NEXT_SERVER "next-server" +#define DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_DHCP_BOOTFILE "dhcp-bootfile" static NM_UTILS_LOOKUP_STR_DEFINE( _device_state_managed_type_to_str, @@ -2565,7 +2566,8 @@ nm_config_device_state_write(int ifindex, guint32 route_metric_default_aspired, guint32 route_metric_default_effective, const char * next_server, - const char * root_path) + const char * root_path, + const char * dhcp_bootfile) { char path[NM_STRLEN(NM_CONFIG_DEVICE_STATE_DIR "/") + DEVICE_STATE_FILENAME_LEN_MAX + 1]; GError *local = NULL; @@ -2632,6 +2634,12 @@ nm_config_device_state_write(int ifindex, DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_ROOT_PATH, root_path); } + if (dhcp_bootfile) { + g_key_file_set_string(kf, + DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE, + DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_DHCP_BOOTFILE, + dhcp_bootfile); + } if (!g_key_file_save_to_file(kf, path, &local)) { _LOGW("device-state: write #%d (%s) failed: %s", ifindex, path, local->message); @@ -2639,7 +2647,9 @@ nm_config_device_state_write(int ifindex, return FALSE; } _LOGT("device-state: write #%d (%s); managed=%s%s%s%s%s%s%s, " - "route-metric-default=%" G_GUINT32_FORMAT "-%" G_GUINT32_FORMAT "%s%s%s%s%s%s", + "route-metric-default=%" G_GUINT32_FORMAT "-%" G_GUINT32_FORMAT "%s%s%s" + "%s%s%s" + "%s%s%s", ifindex, path, _device_state_managed_type_to_str(managed), @@ -2648,7 +2658,8 @@ nm_config_device_state_write(int ifindex, route_metric_default_aspired, route_metric_default_effective, NM_PRINT_FMT_QUOTED(next_server, ", next-server=", next_server, "", ""), - NM_PRINT_FMT_QUOTED(root_path, ", root-path=", root_path, "", "")); + NM_PRINT_FMT_QUOTED(root_path, ", root-path=", root_path, "", ""), + NM_PRINT_FMT_QUOTED(dhcp_bootfile, ", dhcp-bootfile=", dhcp_bootfile, "", "")); return TRUE; } diff --git a/src/core/nm-config.h b/src/core/nm-config.h index 7f1c0c4c57..8279f4d264 100644 --- a/src/core/nm-config.h +++ b/src/core/nm-config.h @@ -185,7 +185,8 @@ gboolean nm_config_device_state_write(int guint32 route_metric_default_aspired, guint32 route_metric_default_effective, const char * next_server, - const char * root_path); + const char * root_path, + const char * dhcp_bootfile); void nm_config_device_state_prune_stale(GHashTable *preserve_ifindexes, NMPlatform *preserve_in_platform); diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index b66f7fbb37..c1c8034a77 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -6803,8 +6803,9 @@ nm_manager_write_device_state(NMManager *self, NMDevice *device, int *out_ifinde guint32 route_metric_default_effective; NMTernary nm_owned; NMDhcpConfig * dhcp_config; - const char * next_server = NULL; - const char * root_path = NULL; + const char * next_server = NULL; + const char * root_path = NULL; + const char * dhcp_bootfile = NULL; NM_SET_OUT(out_ifindex, 0); @@ -6848,8 +6849,11 @@ nm_manager_write_device_state(NMManager *self, NMDevice *device, int *out_ifinde dhcp_config = nm_device_get_dhcp_config(device, AF_INET); if (dhcp_config) { - root_path = nm_dhcp_config_get_option(dhcp_config, "root_path"); - next_server = nm_dhcp_config_get_option(dhcp_config, "next_server"); + root_path = nm_dhcp_config_get_option(dhcp_config, "root_path"); + next_server = nm_dhcp_config_get_option(dhcp_config, "next_server"); + dhcp_bootfile = nm_dhcp_config_get_option(dhcp_config, "filename"); + if (!dhcp_bootfile) + dhcp_bootfile = nm_dhcp_config_get_option(dhcp_config, "bootfile_name"); } if (!nm_config_device_state_write(ifindex, @@ -6860,7 +6864,8 @@ nm_manager_write_device_state(NMManager *self, NMDevice *device, int *out_ifinde route_metric_default_aspired, route_metric_default_effective, next_server, - root_path)) + root_path, + dhcp_bootfile)) return FALSE; NM_SET_OUT(out_ifindex, ifindex); -- cgit v1.2.1