Commit a8d60052 authored by Beniamino Galvani's avatar Beniamino Galvani

libnm: implement support for DNS manager properties

parent e3c67177
......@@ -696,6 +696,7 @@ libnm_lib_h_priv = \
libnm/nm-device-private.h \
libnm/nm-dhcp4-config.h \
libnm/nm-dhcp6-config.h \
libnm/nm-dns-manager.h \
libnm/nm-ip4-config.h \
libnm/nm-ip6-config.h \
libnm/nm-manager.h \
......@@ -728,6 +729,7 @@ libnm_lib_c_real = \
libnm/nm-dhcp-config.c \
libnm/nm-dhcp4-config.c \
libnm/nm-dhcp6-config.c \
libnm/nm-dns-manager.c \
libnm/nm-ip-config.c \
libnm/nm-ip4-config.c \
libnm/nm-ip6-config.c \
......
......@@ -42,6 +42,7 @@ IGNORE_HFILES= \
nm-device-private.h \
nm-dhcp4-config.h \
nm-dhcp6-config.h \
nm-dns-manager.h \
nm-ip4-config.h \
nm-ip6-config.h \
nm-manager.h \
......
......@@ -83,6 +83,9 @@
#define NM_DBUS_INTERFACE_SECRET_AGENT NM_DBUS_INTERFACE ".SecretAgent"
#define NM_DBUS_PATH_SECRET_AGENT "/org/freedesktop/NetworkManager/SecretAgent"
#define NM_DBUS_INTERFACE_DNS_MANAGER "org.freedesktop.NetworkManager.DnsManager"
#define NM_DBUS_PATH_DNS_MANAGER "/org/freedesktop/NetworkManager/DnsManager"
/**
* NMCapability:
* @NM_CAPABILITY_TEAM: Teams can be managed
......
......@@ -1087,7 +1087,17 @@ global:
libnm_1_6_0 {
global:
nm_capability_get_type;
nm_client_get_dns_configuration;
nm_client_get_dns_mode;
nm_client_get_dns_rc_manager;
nm_connection_get_setting_proxy;
nm_dns_entry_get_domains;
nm_dns_entry_get_interface;
nm_dns_entry_get_nameservers;
nm_dns_entry_get_priority;
nm_dns_entry_get_type;
nm_dns_entry_get_vpn;
nm_dns_entry_unref;
nm_setting_connection_get_autoconnect_retries;
nm_setting_proxy_get_type;
nm_setting_proxy_new;
......
......@@ -26,6 +26,7 @@
#include "nm-utils.h"
#include "nm-client.h"
#include "nm-manager.h"
#include "nm-dns-manager.h"
#include "nm-remote-settings.h"
#include "nm-device-ethernet.h"
#include "nm-device-wifi.h"
......@@ -40,6 +41,7 @@
#include "introspection/org.freedesktop.NetworkManager.h"
#include "introspection/org.freedesktop.NetworkManager.Device.Wireless.h"
#include "introspection/org.freedesktop.NetworkManager.Device.h"
#include "introspection/org.freedesktop.NetworkManager.DnsManager.h"
#include "introspection/org.freedesktop.NetworkManager.Settings.h"
#include "introspection/org.freedesktop.NetworkManager.Settings.Connection.h"
#include "introspection/org.freedesktop.NetworkManager.VPN.Connection.h"
......@@ -88,6 +90,7 @@ G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT,
typedef struct {
NMManager *manager;
NMRemoteSettings *settings;
NMDnsManager *dns_manager;
GDBusObjectManager *object_manager;
GCancellable *new_object_manager_cancellable;
} NMClientPrivate;
......@@ -115,6 +118,9 @@ enum {
PROP_HOSTNAME,
PROP_CAN_MODIFY,
PROP_METERED,
PROP_DNS_MODE,
PROP_DNS_RC_MANAGER,
PROP_DNS_CONFIGURATION,
LAST_PROP
};
......@@ -1716,6 +1722,85 @@ nm_client_reload_connections_finish (NMClient *client,
/*****************************************************************************/
/**
* nm_client_get_dns_mode:
* @client: the #NMClient
*
* Gets the current DNS processing mode.
*
* Return value: the DNS processing mode, or %NULL in case the
* value is not available.
*
* Since: 1.6
**/
const char *
nm_client_get_dns_mode (NMClient *client)
{
NMClientPrivate *priv;
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
priv = NM_CLIENT_GET_PRIVATE (client);
if (priv->dns_manager)
return nm_dns_manager_get_mode (priv->dns_manager);
else
return NULL;
}
/**
* nm_client_get_dns_rc_manager:
* @client: the #NMClient
*
* Gets the current DNS resolv.conf manager.
*
* Return value: the resolv.conf manager or %NULL in case the
* value is not available.
*
* Since: 1.6
**/
const char *
nm_client_get_dns_rc_manager (NMClient *client)
{
NMClientPrivate *priv;
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
priv = NM_CLIENT_GET_PRIVATE (client);
if (priv->dns_manager)
return nm_dns_manager_get_rc_manager (priv->dns_manager);
else
return NULL;
}
/**
* nm_client_get_dns_configuration:
* @client: a #NMClient
*
* Gets the current DNS configuration
*
* Returns: (transfer none) (element-type NMDnsEntry): a #GPtrArray
* containing #NMDnsEntry elements or %NULL in case the value is not
* available. The returned array is owned by the #NMClient object
* and should not be modified.
*
* Since: 1.6
**/
const GPtrArray *
nm_client_get_dns_configuration (NMClient *client)
{
NMClientPrivate *priv;
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
priv = NM_CLIENT_GET_PRIVATE (client);
if (priv->dns_manager)
return nm_dns_manager_get_configuration (priv->dns_manager);
else
return NULL;
}
/*****************************************************************************/
/**
* nm_client_new:
* @cancellable: a #GCancellable, or %NULL
......@@ -1881,6 +1966,22 @@ manager_active_connection_removed (NMManager *manager,
g_signal_emit (client, signals[ACTIVE_CONNECTION_REMOVED], 0, active_connection);
}
static void
dns_notify (GObject *object,
GParamSpec *pspec,
gpointer client)
{
char pname[128];
if (NM_IN_STRSET (pspec->name,
NM_DNS_MANAGER_MODE,
NM_DNS_MANAGER_RC_MANAGER,
NM_DNS_MANAGER_CONFIGURATION)) {
nm_sprintf_buf (pname, "dns-%s", pspec->name);
g_object_notify (client, pname);
}
}
/****************************************************************/
/* Object Initialization */
/****************************************************************/
......@@ -1909,6 +2010,8 @@ proxy_type (GDBusObjectManagerClient *manager,
return NMDBUS_TYPE_SETTINGS_CONNECTION_PROXY;
else if (strcmp (interface_name, NM_DBUS_INTERFACE_SETTINGS) == 0)
return NMDBUS_TYPE_SETTINGS_PROXY;
else if (strcmp (interface_name, NM_DBUS_INTERFACE_DNS_MANAGER) == 0)
return NMDBUS_TYPE_DNS_MANAGER_PROXY;
else if (strcmp (interface_name, NM_DBUS_INTERFACE_VPN_CONNECTION) == 0)
return NMDBUS_TYPE_VPN_CONNECTION_PROXY;
......@@ -1988,6 +2091,8 @@ obj_nm_for_gdbus_object (GDBusObject *object, GDBusObjectManager *object_manager
type = NM_TYPE_REMOTE_CONNECTION;
else if (strcmp (ifname, NM_DBUS_INTERFACE_SETTINGS) == 0)
type = NM_TYPE_REMOTE_SETTINGS;
else if (strcmp (ifname, NM_DBUS_INTERFACE_DNS_MANAGER) == 0)
type = NM_TYPE_DNS_MANAGER;
else if (strcmp (ifname, NM_DBUS_INTERFACE_VPN_CONNECTION) == 0)
type = NM_TYPE_VPN_CONNECTION;
else if (strcmp (ifname, NM_DBUS_INTERFACE_WIMAX_NSP) == 0)
......@@ -2046,6 +2151,7 @@ objects_created (NMClient *client, GDBusObjectManager *object_manager, GError **
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
gs_unref_object GDBusObject *manager = NULL;
gs_unref_object GDBusObject *settings = NULL;
gs_unref_object GDBusObject *dns_manager = NULL;
NMObject *obj_nm;
GList *objects, *iter;
......@@ -2119,6 +2225,23 @@ objects_created (NMClient *client, GDBusObjectManager *object_manager, GError **
g_signal_connect (priv->settings, "connection-removed",
G_CALLBACK (settings_connection_removed), client);
dns_manager = g_dbus_object_manager_get_object (object_manager, NM_DBUS_PATH_DNS_MANAGER);
if (dns_manager) {
obj_nm = g_object_get_qdata (G_OBJECT (dns_manager), _nm_object_obj_nm_quark ());
if (!obj_nm) {
g_set_error_literal (error,
NM_CLIENT_ERROR,
NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
"DNS manager object lacks the proper interface");
return FALSE;
}
priv->dns_manager = NM_DNS_MANAGER (g_object_ref (obj_nm));
g_signal_connect (priv->dns_manager, "notify",
G_CALLBACK (dns_notify), client);
}
/* The handlers don't really use the client instance. However
* it makes it convenient to unhook them by data. */
g_signal_connect (object_manager, "object-added",
......@@ -2257,6 +2380,10 @@ unhook_om (NMClient *self)
g_object_notify (G_OBJECT (self), NM_CLIENT_HOSTNAME);
g_object_notify (G_OBJECT (self), NM_CLIENT_CAN_MODIFY);
}
if (priv->dns_manager) {
g_signal_handlers_disconnect_by_data (priv->dns_manager, self);
g_clear_object (&priv->dns_manager);
}
objects = g_dbus_object_manager_get_objects (priv->object_manager);
for (iter = objects; iter; iter = iter->next)
......@@ -2415,6 +2542,11 @@ dispose (GObject *object)
g_clear_object (&priv->settings);
}
if (priv->dns_manager) {
g_signal_handlers_disconnect_by_data (priv->dns_manager, object);
g_clear_object (&priv->dns_manager);
}
if (priv->object_manager) {
GList *objects, *iter;
......@@ -2547,6 +2679,25 @@ get_property (GObject *object, guint prop_id,
else
g_value_set_boolean (value, FALSE);
break;
/* DNS properties */
case PROP_DNS_MODE:
case PROP_DNS_RC_MANAGER:
g_return_if_fail (pspec->name && strlen (pspec->name) > NM_STRLEN ("dns-"));
if (priv->dns_manager)
g_object_get_property (G_OBJECT (priv->dns_manager),
&pspec->name[NM_STRLEN ("dns-")], value);
else
g_value_set_string (value, NULL);
break;
case PROP_DNS_CONFIGURATION:
if (priv->dns_manager) {
g_object_get_property (G_OBJECT (priv->dns_manager),
NM_DNS_MANAGER_CONFIGURATION,
value);
} else
g_value_take_boxed (value, NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -2838,6 +2989,54 @@ nm_client_class_init (NMClientClass *client_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMClient:dns-mode:
*
* The current DNS processing mode.
*
* Since: 1.6
**/
g_object_class_install_property
(object_class, PROP_DNS_MODE,
g_param_spec_string (NM_CLIENT_DNS_MODE, "", "",
"",
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMClient:dns-rc-manager:
*
* The current resolv.conf management mode.
*
* Since: 1.6
**/
g_object_class_install_property
(object_class, PROP_DNS_RC_MANAGER,
g_param_spec_string (NM_CLIENT_DNS_RC_MANAGER, "", "",
"",
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMClient:dns-configuration:
*
* The current DNS configuration represented as an array of
* dictionaries. Each dictionary has the "nameservers",
* "priority" keys and, optionally, "interface" and "vpn".
* "nameservers" is the list of DNS servers, "priority" their
* relative priority, "interface" the interface on which these
* servers are contacted, "vpn" a boolean telling whether the
* configuration was obtained from a VPN connection.
*
* Since: 1.6
**/
g_object_class_install_property
(object_class, PROP_DNS_CONFIGURATION,
g_param_spec_boxed (NM_CLIENT_DNS_CONFIGURATION, "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/* signals */
/**
......
......@@ -58,6 +58,9 @@ G_BEGIN_DECLS
#define NM_CLIENT_HOSTNAME "hostname"
#define NM_CLIENT_CAN_MODIFY "can-modify"
#define NM_CLIENT_METERED "metered"
#define NM_CLIENT_DNS_MODE "dns-mode"
#define NM_CLIENT_DNS_RC_MANAGER "dns-rc-manager"
#define NM_CLIENT_DNS_CONFIGURATION "dns-configuration"
#define NM_CLIENT_DEVICE_ADDED "device-added"
#define NM_CLIENT_DEVICE_REMOVED "device-removed"
......@@ -169,6 +172,25 @@ typedef enum {
#define NM_CLIENT_ERROR nm_client_error_quark ()
GQuark nm_client_error_quark (void);
/* DNS stuff */
typedef struct NMDnsEntry NMDnsEntry;
NM_AVAILABLE_IN_1_6
GType nm_dns_entry_get_type (void);
NM_AVAILABLE_IN_1_6
void nm_dns_entry_unref (NMDnsEntry *entry);
NM_AVAILABLE_IN_1_6
const char * nm_dns_entry_get_interface (NMDnsEntry *entry);
NM_AVAILABLE_IN_1_6
const char * const *nm_dns_entry_get_nameservers (NMDnsEntry *entry);
NM_AVAILABLE_IN_1_6
const char * const *nm_dns_entry_get_domains (NMDnsEntry *entry);
NM_AVAILABLE_IN_1_6
int nm_dns_entry_get_priority (NMDnsEntry *entry);
NM_AVAILABLE_IN_1_6
gboolean nm_dns_entry_get_vpn (NMDnsEntry *entry);
/**
* NMClient:
*/
......@@ -359,6 +381,13 @@ gboolean nm_client_reload_connections_finish (NMClient *client,
GAsyncResult *result,
GError **error);
NM_AVAILABLE_IN_1_6
const char *nm_client_get_dns_mode (NMClient *client);
NM_AVAILABLE_IN_1_6
const char *nm_client_get_dns_rc_manager (NMClient *client);
NM_AVAILABLE_IN_1_6
const GPtrArray *nm_client_get_dns_configuration (NMClient *client);
G_END_DECLS
#endif /* __NM_CLIENT_H__ */
This diff is collapsed.
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2016 Red Hat, Inc.
*/
#ifndef __NM_DNS_MANAGER_H__
#define __NM_DNS_MANAGER_H__
#include <nm-object.h>
#include "nm-client.h"
G_BEGIN_DECLS
#define NM_TYPE_DNS_MANAGER (nm_dns_manager_get_type ())
#define NM_DNS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DNS_MANAGER, NMDnsManager))
#define NM_DNS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DNS_MANAGER, NMDnsManagerClass))
#define NM_IS_DNS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DNS_MANAGER))
#define NM_IS_DNS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DNS_MANAGER))
#define NM_DNS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DNS_MANAGER, NMDnsManagerClass))
#define NM_DNS_MANAGER_MODE "mode"
#define NM_DNS_MANAGER_RC_MANAGER "rc-manager"
#define NM_DNS_MANAGER_CONFIGURATION "configuration"
typedef struct _NMDnsManager NMDnsManager;
typedef struct _NMDnsManagerClass NMDnsManagerClass;
/**
* NMDnsManager:
*/
struct _NMDnsManager {
NMObject parent;
};
struct _NMDnsManagerClass {
NMObjectClass parent;
/*< private >*/
gpointer padding[8];
};
G_END_DECLS
GType nm_dns_manager_get_type (void);
const char *nm_dns_manager_get_mode (NMDnsManager *manager);
const char *nm_dns_manager_get_rc_manager (NMDnsManager *manager);
const GPtrArray *nm_dns_manager_get_configuration (NMDnsManager *manager);
NMDnsEntry * nm_dns_entry_new (const char *interface,
const char * const *nameservers,
const char * const *domains,
int priority,
gboolean vpn);
NMDnsEntry * nm_dns_entry_dup (NMDnsEntry *entry);
#endif /* __NM_DNS_MANAGER_H__ */
......@@ -1264,7 +1264,41 @@ class ObjectManager(dbus.service.Object):
pass
###################################################################
IFACE_DNS_MANAGER = 'org.freedesktop.NetworkManager.DnsManager'
class DnsManager(ExportedObj):
def __init__(self, bus, object_path):
self.props = {}
self.props['Mode'] = "dnsmasq"
self.props['RcManager'] = "symlink"
self.props['Configuration'] = dbus.Array([
dbus.Dictionary(
{ 'nameservers' : dbus.Array(['1.2.3.4', '5.6.7.8'], 's'),
'priority' : dbus.Int32(100) },
'sv') ],
'a{sv}')
self.add_dbus_interface(IFACE_DNS_MANAGER, self.__get_props, None)
ExportedObj.__init__(self, bus, object_path)
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
def GetAll(self, iface):
if iface != IFACE_DNS_MANAGER:
raise UnknownInterfaceException()
return self.props
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
def Get(self, iface, name):
if iface != IFACE_DNS_MANAGER:
raise UnknownInterfaceException()
if not name in self.props.keys():
raise UnknownPropertyException()
return self.props[name]
def __get_props(self):
return self.props
###################################################################
def stdin_cb(io, condition):
mainloop.quit()
......@@ -1276,13 +1310,14 @@ def main():
random.seed()
global manager, settings, agent_manager, object_manager, bus
global manager, settings, agent_manager, dns_manager, object_manager, bus
bus = dbus.SessionBus()
object_manager = ObjectManager(bus, "/org/freedesktop")
manager = NetworkManager(bus, "/org/freedesktop/NetworkManager")
settings = Settings(bus, "/org/freedesktop/NetworkManager/Settings")
agent_manager = AgentManager(bus, "/org/freedesktop/NetworkManager/AgentManager")
dns_manager = DnsManager(bus, "/org/freedesktop/NetworkManager/DnsManager")
if not bus.request_name("org.freedesktop.NetworkManager"):
sys.exit(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment