dns: add function to retrieve the systemd-resolved plugin instance

Now that we have nm_dns_systemd_resolved_resolve_address(), we also
need a way to obtain a reference to the plugin.

(cherry picked from commit 7285bc56a9)
This commit is contained in:
Beniamino Galvani 2021-05-28 11:30:42 +02:00
parent ffd6c5e3f4
commit 4f9ff47e2d
6 changed files with 17 additions and 10 deletions

View file

@ -7,6 +7,7 @@
#define __NETWORKMANAGER_DNS_DNSMASQ_H__
#include "nm-dns-plugin.h"
#include "nm-dns-manager.h"
#define NM_TYPE_DNS_DNSMASQ (nm_dns_dnsmasq_get_type())
#define NM_DNS_DNSMASQ(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_DNS_DNSMASQ, NMDnsDnsmasq))

View file

@ -378,11 +378,11 @@ _mgr_get_configs_lst_head(NMDnsManager *self)
/*****************************************************************************/
gboolean
nm_dns_manager_has_systemd_resolved(NMDnsManager *self)
NMDnsPlugin *
nm_dns_manager_get_systemd_resolved(NMDnsManager *self)
{
NMDnsManagerPrivate * priv;
NMDnsSystemdResolved *plugin = NULL;
NMDnsManagerPrivate *priv;
NMDnsPlugin * plugin = NULL;
g_return_val_if_fail(NM_IS_DNS_MANAGER(self), FALSE);
@ -390,11 +390,14 @@ nm_dns_manager_has_systemd_resolved(NMDnsManager *self)
if (priv->sd_resolve_plugin) {
nm_assert(!NM_IS_DNS_SYSTEMD_RESOLVED(priv->plugin));
plugin = NM_DNS_SYSTEMD_RESOLVED(priv->sd_resolve_plugin);
plugin = priv->sd_resolve_plugin;
} else if (NM_IS_DNS_SYSTEMD_RESOLVED(priv->plugin))
plugin = NM_DNS_SYSTEMD_RESOLVED(priv->plugin);
plugin = priv->plugin;
return plugin && nm_dns_systemd_resolved_is_running(plugin);
if (plugin && nm_dns_systemd_resolved_is_running(NM_DNS_SYSTEMD_RESOLVED(plugin)))
return plugin;
return NULL;
}
/*****************************************************************************/

View file

@ -11,6 +11,7 @@
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
#include "nm-setting-connection.h"
#include "nm-dns-plugin.h"
typedef enum {
NM_DNS_IP_CONFIG_TYPE_REMOVED = -1,
@ -148,7 +149,7 @@ typedef enum {
void nm_dns_manager_stop(NMDnsManager *self);
gboolean nm_dns_manager_has_systemd_resolved(NMDnsManager *self);
NMDnsPlugin *nm_dns_manager_get_systemd_resolved(NMDnsManager *self);
/*****************************************************************************/

View file

@ -6,7 +6,8 @@
#ifndef __NM_DNS_PLUGIN_H__
#define __NM_DNS_PLUGIN_H__
#include "nm-dns-manager.h"
#include "c-list/src/c-list.h"
#include "nm-config-data.h"
#define NM_TYPE_DNS_PLUGIN (nm_dns_plugin_get_type())

View file

@ -8,6 +8,7 @@
#define __NETWORKMANAGER_DNS_SYSTEMD_RESOLVED_H__
#include "nm-dns-plugin.h"
#include "nm-dns-manager.h"
#define NM_TYPE_DNS_SYSTEMD_RESOLVED (nm_dns_systemd_resolved_get_type())
#define NM_DNS_SYSTEMD_RESOLVED(obj) \

View file

@ -904,7 +904,7 @@ nm_connectivity_check_start(NMConnectivity * self,
* This is relatively cumbersome to avoid, because we would have to go through
* NMDnsSystemdResolved trying to asynchronously start the service, to ensure there
* is only one attempt to start the service. */
has_systemd_resolved = nm_dns_manager_has_systemd_resolved(nm_dns_manager_get());
has_systemd_resolved = !!nm_dns_manager_get_systemd_resolved(nm_dns_manager_get());
if (has_systemd_resolved) {
GDBusConnection *dbus_connection;