summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dhcp/nm-dhcp-utils.c53
-rw-r--r--src/dhcp/nm-dhcp-utils.h8
2 files changed, 60 insertions, 1 deletions
diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c
index 3f9368f2dd..4723b129d5 100644
--- a/src/dhcp/nm-dhcp-utils.c
+++ b/src/dhcp/nm-dhcp-utils.c
@@ -25,6 +25,7 @@
#include "nm-dhcp-utils.h"
#include "nm-utils.h"
+#include "nm-config.h"
#include "NetworkManagerUtils.h"
#include "platform/nm-platform.h"
#include "nm-dhcp-client-logging.h"
@@ -762,3 +763,55 @@ nm_dhcp_utils_client_id_string_to_bytes (const char *client_id)
return bytes;
}
+/**
+ * nm_dhcp_utils_get_leasefile_path:
+ * @addr_family: the IP address family
+ * @plugin_name: the name of the plugin part of the lease file name
+ * @iface: the interface name to which the lease relates to
+ * @uuid: uuid of the connection to which the lease relates to
+ * @out_leasefile_path: will store the computed lease file path
+ *
+ * Constructs the lease file name on the basis of the calling plugin,
+ * interface name and connection uuid. Then returns in @out_leasefile_path
+ * the full path of the lease filename.
+ *
+ * Returns: TRUE if the lease file already exists, FALSE otherwise.
+ */
+gboolean
+nm_dhcp_utils_get_leasefile_path (int addr_family,
+ const char *plugin_name,
+ const char *iface,
+ const char *uuid,
+ char **out_leasefile_path)
+{
+ gs_free char *rundir_path = NULL;
+ gs_free char *statedir_path = NULL;
+
+ rundir_path = g_strdup_printf (NMRUNDIR "/%s%s-%s-%s.lease",
+ plugin_name,
+ addr_family == AF_INET6 ? "6" : "",
+ uuid,
+ iface);
+
+ if (g_file_test (rundir_path, G_FILE_TEST_EXISTS)) {
+ *out_leasefile_path = g_steal_pointer (&rundir_path);
+ return TRUE;
+ }
+
+ statedir_path = g_strdup_printf (NMSTATEDIR "/%s%s-%s-%s.lease",
+ plugin_name,
+ addr_family == AF_INET6 ? "6" : "",
+ uuid,
+ iface);
+
+ if (g_file_test (statedir_path, G_FILE_TEST_EXISTS)) {
+ *out_leasefile_path = g_steal_pointer (&statedir_path);
+ return TRUE;
+ }
+
+ if (nm_config_get_configure_and_quit (nm_config_get ()) == NM_CONFIG_CONFIGURE_AND_QUIT_INITRD)
+ *out_leasefile_path = g_steal_pointer (&rundir_path);
+ else
+ *out_leasefile_path = g_steal_pointer (&statedir_path);
+ return FALSE;
+}
diff --git a/src/dhcp/nm-dhcp-utils.h b/src/dhcp/nm-dhcp-utils.h
index 39ae76932b..36099b5f8f 100644
--- a/src/dhcp/nm-dhcp-utils.h
+++ b/src/dhcp/nm-dhcp-utils.h
@@ -40,7 +40,13 @@ NMPlatformIP6Address nm_dhcp_utils_ip6_prefix_from_options (GHashTable *options)
char *nm_dhcp_utils_duid_to_string (GBytes *duid);
-GBytes * nm_dhcp_utils_client_id_string_to_bytes (const char *client_id);
+GBytes *nm_dhcp_utils_client_id_string_to_bytes (const char *client_id);
+
+gboolean nm_dhcp_utils_get_leasefile_path (int addr_family,
+ const char *plugin_name,
+ const char *iface,
+ const char *uuid,
+ char **out_leasefile_path);
#endif /* __NETWORKMANAGER_DHCP_UTILS_H__ */