mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 10:32:33 +01:00
resolve: Add framework for resolution services
The framework enables the service specific implementations to provide its own variations for the DNS installation tasks. The selection of the address resolution service can be done through dns_resolve_method setting.
This commit is contained in:
parent
20466cd735
commit
01fe343825
@ -31,28 +31,89 @@
|
|||||||
#include "src/iwd.h"
|
#include "src/iwd.h"
|
||||||
#include "src/resolve.h"
|
#include "src/resolve.h"
|
||||||
|
|
||||||
|
struct resolve_method_ops {
|
||||||
|
void *(*init)(void);
|
||||||
|
void (*exit)(void *data);
|
||||||
|
void (*add_dns)(uint32_t ifindex, uint8_t type, char **dns_list,
|
||||||
|
void *data);
|
||||||
|
void (*remove)(uint32_t ifindex, void *data);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct resolve_method {
|
||||||
|
void *data;
|
||||||
|
const struct resolve_method_ops *ops;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct resolve_method method;
|
||||||
|
|
||||||
void resolve_add_dns(uint32_t ifindex, uint8_t type, char **dns_list)
|
void resolve_add_dns(uint32_t ifindex, uint8_t type, char **dns_list)
|
||||||
{
|
{
|
||||||
|
if (!dns_list || !*dns_list)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!method.ops || !method.ops->add_dns)
|
||||||
|
return;
|
||||||
|
|
||||||
|
method.ops->add_dns(ifindex, type, dns_list, method.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resolve_remove(uint32_t ifindex)
|
void resolve_remove(uint32_t ifindex)
|
||||||
{
|
{
|
||||||
|
if (!method.ops || !method.ops->remove)
|
||||||
|
return;
|
||||||
|
|
||||||
|
method.ops->remove(ifindex, method.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct {
|
||||||
|
const char *name;
|
||||||
|
const struct resolve_method_ops *method_ops;
|
||||||
|
} resolve_method_ops_list[] = {
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
static int resolve_init(void)
|
static int resolve_init(void)
|
||||||
{
|
{
|
||||||
|
const char *method_name;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
if (!l_settings_get_bool(iwd_get_config(), "General",
|
if (!l_settings_get_bool(iwd_get_config(), "General",
|
||||||
"enable_network_config", &enabled) ||
|
"enable_network_config", &enabled) ||
|
||||||
!enabled)
|
!enabled)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
method_name = l_settings_get_value(iwd_get_config(), "General",
|
||||||
|
"dns_resolve_method");
|
||||||
|
|
||||||
|
if (!method_name)
|
||||||
|
/* Default to systemd-resolved service. */
|
||||||
|
method_name = "systemd";
|
||||||
|
|
||||||
|
for (i = 0; resolve_method_ops_list[i].name; i++) {
|
||||||
|
if (strcmp(resolve_method_ops_list[i].name, method_name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
method.ops = resolve_method_ops_list[i].method_ops;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!method.ops)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (method.ops->init)
|
||||||
|
method.data = method.ops->init();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resolve_exit(void)
|
static void resolve_exit(void)
|
||||||
{
|
{
|
||||||
|
if (!method.ops->exit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
method.ops->exit(method.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
IWD_MODULE(resolve, resolve_init, resolve_exit)
|
IWD_MODULE(resolve, resolve_init, resolve_exit)
|
||||||
|
Loading…
Reference in New Issue
Block a user