mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-06 22:10:25 +01:00
dhcp: store NetworkManager-specific dhclient leases in /var/lib/NetworkManager/
DHCP lease file names are built by NetworkManager and contain connection UUID which makes them NM-specific. Their new location belongs to NetworkManager and doesn't have to be guessed. With no guessing, we don't need distribution-specific conditionals. Note: This change may require modifications to the selinux policy. But after all these files actually belong to NetworkManager as well as the instance of dhclient that uses them.
This commit is contained in:
parent
ffb60cdba4
commit
20d4125cfc
8 changed files with 22 additions and 21 deletions
|
|
@ -28,7 +28,8 @@ libdhcp_dhclient_la_CPPFLAGS = \
|
|||
-DSYSCONFDIR=\"$(sysconfdir)\" \
|
||||
-DLIBEXECDIR=\"$(libexecdir)\" \
|
||||
-DLOCALSTATEDIR=\"$(localstatedir)\" \
|
||||
-DDHCLIENT_PATH=\"$(DHCLIENT_PATH)\"
|
||||
-DDHCLIENT_PATH=\"$(DHCLIENT_PATH)\" \
|
||||
-DNMSTATEDIR=\"$(nmstatedir)\"
|
||||
|
||||
libdhcp_dhclient_la_LIBADD = \
|
||||
$(top_builddir)/src/logging/libnm-logging.la \
|
||||
|
|
|
|||
|
|
@ -45,12 +45,6 @@ G_DEFINE_TYPE (NMDHCPDhclient, nm_dhcp_dhclient, NM_TYPE_DHCP_CLIENT)
|
|||
|
||||
#define NM_DHCP_DHCLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_DHCLIENT, NMDHCPDhclientPrivate))
|
||||
|
||||
#if defined(TARGET_DEBIAN) || defined(TARGET_SUSE) || defined(TARGET_MANDRIVA)
|
||||
#define NM_DHCLIENT_LEASE_DIR LOCALSTATEDIR "/lib/dhcp"
|
||||
#else
|
||||
#define NM_DHCLIENT_LEASE_DIR LOCALSTATEDIR "/lib/dhclient"
|
||||
#endif
|
||||
|
||||
#define ACTION_SCRIPT_PATH LIBEXECDIR "/nm-dhcp-client.action"
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -85,10 +79,9 @@ nm_dhcp_dhclient_get_path (const char *try_first)
|
|||
}
|
||||
|
||||
static char *
|
||||
get_leasefile_for_iface (const char * iface, const char *uuid, gboolean ipv6)
|
||||
get_dhclient_leasefile (const char * iface, const char *uuid, gboolean ipv6)
|
||||
{
|
||||
return g_strdup_printf ("%s/dhclient%s-%s-%s.lease",
|
||||
NM_DHCLIENT_LEASE_DIR,
|
||||
return g_strdup_printf (NMSTATEDIR "/dhclient%s-%s-%s.lease",
|
||||
ipv6 ? "6" : "",
|
||||
uuid,
|
||||
iface);
|
||||
|
|
@ -135,7 +128,7 @@ add_lease_option (GHashTable *hash, char *line)
|
|||
}
|
||||
|
||||
GSList *
|
||||
nm_dhcp_dhclient_get_lease_config (const char *iface, const char *uuid)
|
||||
nm_dhcp_dhclient_get_lease_config (const char *iface, const char *uuid, gboolean ipv6)
|
||||
{
|
||||
GSList *parsed = NULL, *iter, *leases = NULL;
|
||||
char *contents = NULL;
|
||||
|
|
@ -143,7 +136,11 @@ nm_dhcp_dhclient_get_lease_config (const char *iface, const char *uuid)
|
|||
char **line, **split = NULL;
|
||||
GHashTable *hash = NULL;
|
||||
|
||||
leasefile = get_leasefile_for_iface (iface, uuid, FALSE);
|
||||
/* IPv6 not supported */
|
||||
if (ipv6)
|
||||
return NULL;
|
||||
|
||||
leasefile = get_dhclient_leasefile (iface, uuid, FALSE);
|
||||
if (!leasefile)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -455,7 +452,7 @@ dhclient_start (NMDHCPClient *client,
|
|||
}
|
||||
|
||||
g_free (priv->lease_file);
|
||||
priv->lease_file = get_leasefile_for_iface (iface, uuid, ipv6);
|
||||
priv->lease_file = get_dhclient_leasefile (iface, uuid, ipv6);
|
||||
if (!priv->lease_file) {
|
||||
nm_log_warn (log_domain, "(%s): not enough memory for dhclient options.", iface);
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ typedef struct {
|
|||
|
||||
GType nm_dhcp_dhclient_get_type (void);
|
||||
|
||||
GSList *nm_dhcp_dhclient_get_lease_config (const char *iface, const char *uuid);
|
||||
GSList *nm_dhcp_dhclient_get_lease_config (const char *iface, const char *uuid, gboolean ipv6);
|
||||
|
||||
const char *nm_dhcp_dhclient_get_path (const char *try_first);
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ nm_dhcp_dhcpcd_get_path (const char *try_first)
|
|||
}
|
||||
|
||||
GSList *
|
||||
nm_dhcp_dhcpcd_get_lease_config (const char *iface, const char *uuid)
|
||||
nm_dhcp_dhcpcd_get_lease_config (const char *iface, const char *uuid, gboolean ipv6)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ typedef struct {
|
|||
|
||||
GType nm_dhcp_dhcpcd_get_type (void);
|
||||
|
||||
GSList *nm_dhcp_dhcpcd_get_lease_config (const char *iface, const char *uuid);
|
||||
GSList *nm_dhcp_dhcpcd_get_lease_config (const char *iface, const char *uuid, gboolean ipv6);
|
||||
|
||||
const char *nm_dhcp_dhcpcd_get_path (const char *try_first);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ nm_dhcp_manager_error_quark (void)
|
|||
|
||||
static NMDHCPManager *singleton = NULL;
|
||||
|
||||
typedef GSList * (*GetLeaseConfigFunc) (const char *iface, const char *uuid);
|
||||
typedef GSList * (*GetLeaseConfigFunc) (const char *iface, const char *uuid, gboolean ipv6);
|
||||
|
||||
typedef struct {
|
||||
GType client_type;
|
||||
|
|
@ -531,14 +531,15 @@ nm_dhcp_manager_set_hostname_provider (NMDHCPManager *manager,
|
|||
GSList *
|
||||
nm_dhcp_manager_get_lease_config (NMDHCPManager *self,
|
||||
const char *iface,
|
||||
const char *uuid)
|
||||
const char *uuid,
|
||||
gboolean ipv6)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
g_return_val_if_fail (uuid != NULL, NULL);
|
||||
|
||||
return NM_DHCP_MANAGER_GET_PRIVATE (self)->get_lease_config_func (iface, uuid);
|
||||
return NM_DHCP_MANAGER_GET_PRIVATE (self)->get_lease_config_func (iface, uuid, ipv6);
|
||||
}
|
||||
|
||||
NMIP4Config *
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ NMDHCPClient * nm_dhcp_manager_start_ip6 (NMDHCPManager *manager,
|
|||
|
||||
GSList * nm_dhcp_manager_get_lease_config (NMDHCPManager *self,
|
||||
const char *iface,
|
||||
const char *uuid);
|
||||
const char *uuid,
|
||||
gboolean ipv6);
|
||||
|
||||
/* For testing only */
|
||||
NMIP4Config *nm_dhcp_manager_test_ip4_options_to_config (const char *dhcp_client,
|
||||
|
|
|
|||
|
|
@ -4857,7 +4857,8 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
|
|||
dhcp_mgr = nm_dhcp_manager_get ();
|
||||
leases = nm_dhcp_manager_get_lease_config (dhcp_mgr,
|
||||
nm_device_get_iface (self),
|
||||
nm_connection_get_uuid (connection));
|
||||
nm_connection_get_uuid (connection),
|
||||
FALSE);
|
||||
g_object_unref (dhcp_mgr);
|
||||
|
||||
method = s_ip4 ? nm_setting_ip4_config_get_method (s_ip4) : NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue