core: remove the HostnameProvider interface

It's only used to keep the DHCPManager up-to-date with hostname changes,
and that can be accomplished in much less code by just having NMManager
set a hostname on the DHCPManager itself.
This commit is contained in:
Dan Williams 2014-04-02 15:52:04 -05:00
parent d336a78a0e
commit b732240026
7 changed files with 29 additions and 181 deletions

View file

@ -220,8 +220,6 @@ nm_sources = \
nm-dispatcher.h \
nm-enum-types.c \
nm-enum-types.h \
nm-hostname-provider.c \
nm-hostname-provider.h \
nm-ip4-config.c \
nm-ip4-config.h \
nm-ip6-config.c \

View file

@ -39,7 +39,6 @@
#include "nm-dhcp-dhcpcd.h"
#include "nm-logging.h"
#include "nm-dbus-manager.h"
#include "nm-hostname-provider.h"
#include "nm-config.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
@ -79,7 +78,7 @@ typedef struct {
GHashTable * clients;
DBusGProxy * proxy;
NMHostnameProvider *hostname_provider;
char * default_hostname;
} NMDHCPManagerPrivate;
@ -438,6 +437,15 @@ client_start (NMDHCPManager *self,
return client;
}
static const char *
get_send_hostname (NMDHCPManager *self, const char *setting_hostname)
{
NMDHCPManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
/* Always prefer the explicit dhcp-send-hostname if given */
return setting_hostname ? setting_hostname : priv->default_hostname;
}
/* Caller owns a reference to the NMDHCPClient on return */
NMDHCPClient *
nm_dhcp_manager_start_ip4 (NMDHCPManager *self,
@ -448,36 +456,18 @@ nm_dhcp_manager_start_ip4 (NMDHCPManager *self,
guint32 timeout,
GByteArray *dhcp_anycast_addr)
{
NMDHCPManagerPrivate *priv;
const char *hostname, *method;
const char *hostname = NULL, *method;
gboolean send_hostname;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
method = nm_setting_ip4_config_get_method (s_ip4);
g_return_val_if_fail (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, NULL);
send_hostname = nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4);
if (send_hostname) {
hostname = nm_setting_ip4_config_get_dhcp_hostname (s_ip4);
/* If we're supposed to send the hostname to the DHCP server but
* the user didn't specify one, then use the hostname from the
* hostname provider if there is one, otherwise use the persistent
* hostname.
*/
if (!hostname && priv->hostname_provider) {
hostname = nm_hostname_provider_get_hostname (priv->hostname_provider);
if ( hostname
&& (!strcmp (hostname, "localhost.localdomain") ||
!strcmp (hostname, "localhost6.localdomain6")))
hostname = NULL;
}
} else
hostname = NULL;
if (send_hostname)
hostname = get_send_hostname (self, nm_setting_ip4_config_get_dhcp_hostname (s_ip4));
return client_start (self, iface, hwaddr, uuid, FALSE, nm_setting_ip4_config_get_dhcp_client_id (s_ip4), timeout, dhcp_anycast_addr, hostname, FALSE);
}
@ -493,50 +483,28 @@ nm_dhcp_manager_start_ip6 (NMDHCPManager *self,
GByteArray *dhcp_anycast_addr,
gboolean info_only)
{
NMDHCPManagerPrivate *priv;
const char *hostname;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
hostname = nm_setting_ip6_config_get_dhcp_hostname (s_ip6);
if (!hostname && priv->hostname_provider) {
hostname = nm_hostname_provider_get_hostname (priv->hostname_provider);
if ( g_strcmp0 (hostname, "localhost.localdomain") == 0
|| g_strcmp0 (hostname, "localhost6.localdomain6") == 0)
hostname = NULL;
}
hostname = get_send_hostname (self, nm_setting_ip6_config_get_dhcp_hostname (s_ip6));
return client_start (self, iface, hwaddr, uuid, TRUE, NULL, timeout, dhcp_anycast_addr, hostname, info_only);
}
static void
hostname_provider_destroyed (gpointer data, GObject *destroyed_object)
{
NM_DHCP_MANAGER_GET_PRIVATE (data)->hostname_provider = NULL;
}
void
nm_dhcp_manager_set_hostname_provider (NMDHCPManager *manager,
NMHostnameProvider *provider)
nm_dhcp_manager_set_default_hostname (NMDHCPManager *manager, const char *hostname)
{
NMDHCPManagerPrivate *priv;
NMDHCPManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (manager);
g_return_if_fail (NM_IS_DHCP_MANAGER (manager));
g_clear_pointer (&priv->default_hostname, g_free);
priv = NM_DHCP_MANAGER_GET_PRIVATE (manager);
/* Never send 'localhost'-type names to the DHCP server */
if (g_strcmp0 (hostname, "localhost.localdomain") == 0 ||
g_strcmp0 (hostname, "localhost6.localdomain6") == 0)
return;
if (priv->hostname_provider) {
g_object_weak_unref (G_OBJECT (priv->hostname_provider), hostname_provider_destroyed, manager);
priv->hostname_provider = NULL;
}
if (provider) {
priv->hostname_provider = provider;
g_object_weak_ref (G_OBJECT (provider), hostname_provider_destroyed, manager);
}
priv->default_hostname = g_strdup (hostname);
}
GSList *
@ -696,10 +664,7 @@ finalize (GObject *object)
{
NMDHCPManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (object);
if (priv->hostname_provider) {
g_object_weak_unref (G_OBJECT (priv->hostname_provider), hostname_provider_destroyed, object);
priv->hostname_provider = NULL;
}
g_free (priv->default_hostname);
if (priv->clients)
g_hash_table_destroy (priv->clients);

View file

@ -31,7 +31,6 @@
#include "nm-dhcp-client.h"
#include "nm-ip4-config.h"
#include "nm-dhcp4-config.h"
#include "nm-hostname-provider.h"
typedef enum {
NM_DHCP_MANAGER_ERROR_BAD_CLIENT = 0, /*< nick=BadClient >*/
@ -62,8 +61,8 @@ GType nm_dhcp_manager_get_type (void);
NMDHCPManager *nm_dhcp_manager_get (void);
void nm_dhcp_manager_set_hostname_provider(NMDHCPManager *manager,
NMHostnameProvider *provider);
void nm_dhcp_manager_set_default_hostname (NMDHCPManager *manager,
const char *hostname);
NMDHCPClient * nm_dhcp_manager_start_ip4 (NMDHCPManager *manager,
const char *iface,

View file

@ -49,7 +49,6 @@
#include "nm-supplicant-manager.h"
#include "nm-dhcp-manager.h"
#include "nm-firewall-manager.h"
#include "nm-hostname-provider.h"
#include "nm-vpn-manager.h"
#include "nm-logging.h"
#include "nm-config.h"
@ -601,7 +600,6 @@ main (int argc, char *argv[])
/* Initialize DHCP manager */
dhcp_mgr = nm_dhcp_manager_get ();
g_assert (dhcp_mgr != NULL);
nm_dhcp_manager_set_hostname_provider (dhcp_mgr, NM_HOSTNAME_PROVIDER (manager));
settings = nm_settings_new (&error);
if (!settings) {

View file

@ -1,54 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2009 Novell, Inc.
*/
#include "nm-hostname-provider.h"
const char *
nm_hostname_provider_get_hostname (NMHostnameProvider *self)
{
g_return_val_if_fail (NM_IS_HOSTNAME_PROVIDER (self), NULL);
return NM_HOSTNAME_PROVIDER_GET_INTERFACE (self)->get_hostname (self);
}
GType
nm_hostname_provider_get_type (void)
{
static GType type = 0;
if (!G_UNLIKELY (type)) {
const GTypeInfo type_info = {
sizeof (NMHostnameProvider), /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
type = g_type_register_static (G_TYPE_INTERFACE, "NMHostnameProvider", &type_info, 0);
g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
}
return type;
}

View file

@ -1,44 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2009 Novell, Inc.
*/
#ifndef NM_HOSTNAME_PROVIDER_H
#define NM_HOSTNAME_PROVIDER_H
#include <glib-object.h>
#define NM_TYPE_HOSTNAME_PROVIDER (nm_hostname_provider_get_type ())
#define NM_HOSTNAME_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_HOSTNAME_PROVIDER, NMHostnameProvider))
#define NM_IS_HOSTNAME_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_HOSTNAME_PROVIDER))
#define NM_HOSTNAME_PROVIDER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_HOSTNAME_PROVIDER, NMHostnameProvider))
typedef struct _NMHostnameProvider NMHostnameProvider;
struct _NMHostnameProvider {
GTypeInterface g_iface;
/* Methods */
const char *(*get_hostname) (NMHostnameProvider *self);
};
GType nm_hostname_provider_get_type (void);
const char *nm_hostname_provider_get_hostname (NMHostnameProvider *self);
#endif /* NM_HOSTNAME_PROVIDER_H */

View file

@ -60,7 +60,7 @@
#include "nm-dbus-glib-types.h"
#include "nm-platform.h"
#include "nm-rfkill-manager.h"
#include "nm-hostname-provider.h"
#include "nm-dhcp-manager.h"
#include "nm-settings.h"
#include "nm-settings-connection.h"
#include "nm-manager-auth.h"
@ -133,8 +133,6 @@ static void impl_manager_check_connectivity (NMManager *manager,
static void add_device (NMManager *self, NMDevice *device, gboolean generate_con);
static void remove_device (NMManager *self, NMDevice *device, gboolean quitting);
static void hostname_provider_init (NMHostnameProvider *provider_class);
static NMActiveConnection *_new_active_connection (NMManager *self,
NMConnection *connection,
const char *specific_object,
@ -221,9 +219,7 @@ typedef struct {
#define NM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MANAGER, NMManagerPrivate))
G_DEFINE_TYPE_EXTENDED (NMManager, nm_manager, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_HOSTNAME_PROVIDER,
hostname_provider_init))
G_DEFINE_TYPE (NMManager, nm_manager, G_TYPE_OBJECT)
enum {
DEVICE_ADDED,
@ -810,18 +806,6 @@ aipd_handle_event (DBusGProxy *proxy,
nm_log_warn (LOGD_AUTOIP4, "(%s): unhandled avahi-autoipd event", iface);
}
static const char *
hostname_provider_get_hostname (NMHostnameProvider *provider)
{
return NM_MANAGER_GET_PRIVATE (provider)->hostname;
}
static void
hostname_provider_init (NMHostnameProvider *provider_class)
{
provider_class->get_hostname = hostname_provider_get_hostname;
}
NMState
nm_manager_get_state (NMManager *manager)
{
@ -1219,6 +1203,8 @@ system_hostname_changed_cb (NMSettings *settings,
priv->hostname = (hostname && strlen (hostname)) ? g_strdup (hostname) : NULL;
g_object_notify (G_OBJECT (self), NM_MANAGER_HOSTNAME);
nm_dhcp_manager_set_default_hostname (nm_dhcp_manager_get (), priv->hostname);
g_free (hostname);
}