3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 02:19:26 +01:00

resolve: systemd set DNS names

This commit is contained in:
Tim Kourt 2019-07-02 16:14:53 -07:00 committed by Denis Kenzior
parent c1a1828872
commit 25ec69b358

View File

@ -25,6 +25,7 @@
#endif
#include <errno.h>
#include <arpa/inet.h>
#include <ell/ell.h>
@ -48,16 +49,68 @@ struct resolve_method {
static struct resolve_method method;
#define SYSTEMD_RESOLVED_SERVICE "org.freedesktop.resolve1"
#define SYSTEMD_RESOLVED_MANAGER_PATH "/org/freedesktop/resolve1"
#define SYSTEMD_RESOLVED_MANAGER_INTERFACE "org.freedesktop.resolve1.Manager"
struct systemd_state {
uint32_t service_watch;
bool is_ready:1;
};
static void resolve_systemd_add_dns(uint32_t ifindex, char **dns_list,
void *data)
static void systemd_link_dns_reply(struct l_dbus_message *message,
void *user_data)
{
const char *name;
const char *text;
if (!l_dbus_message_is_error(message))
return;
l_dbus_message_get_error(message, &name, &text);
l_error("resolve-systemd: Failed to modify the DNS entries. %s: %s",
name, text);
}
static bool systemd_builder_add_dns(struct l_dbus_message_builder *builder,
uint8_t type, const char *dns)
{
uint8_t buf[16];
uint8_t buf_size;
uint8_t i;
int t = (int) type;
l_debug("installing DNS: %s %u", dns, type);
l_dbus_message_builder_append_basic(builder, 'i', &t);
l_dbus_message_builder_enter_array(builder, "y");
switch (type) {
case AF_INET:
if (inet_pton(AF_INET, dns, buf) < 1)
return false;
buf_size = 4;
break;
default:
return false;
}
for (i = 0; i < buf_size; i++)
l_dbus_message_builder_append_basic(builder, 'y', &buf[i]);
l_dbus_message_builder_leave_array(builder);
return true;
}
static void resolve_systemd_add_dns(uint32_t ifindex, uint8_t type,
char **dns_list, void *data)
{
struct systemd_state *state = data;
struct l_dbus_message_builder *builder;
struct l_dbus_message *message;
l_debug("ifindex: %u", ifindex);
@ -68,7 +121,48 @@ static void resolve_systemd_add_dns(uint32_t ifindex, char **dns_list,
return;
}
/* TODO */
message =
l_dbus_message_new_method_call(dbus_get_bus(),
SYSTEMD_RESOLVED_SERVICE,
SYSTEMD_RESOLVED_MANAGER_PATH,
SYSTEMD_RESOLVED_MANAGER_INTERFACE,
"SetLinkDNS");
if (!message)
return;
builder = l_dbus_message_builder_new(message);
if (!builder) {
l_dbus_message_unref(message);
return;
}
l_dbus_message_builder_append_basic(builder, 'i', &ifindex);
l_dbus_message_builder_enter_array(builder, "(iay)");
for (; *dns_list; dns_list++) {
l_dbus_message_builder_enter_struct(builder, "iay");
if (systemd_builder_add_dns(builder, type, *dns_list)) {
l_dbus_message_builder_leave_struct(builder);
continue;
}
l_dbus_message_builder_destroy(builder);
l_dbus_message_unref(message);
return;
}
l_dbus_message_builder_leave_array(builder);
l_dbus_message_builder_finalize(builder);
l_dbus_message_builder_destroy(builder);
l_dbus_send_with_reply(dbus_get_bus(), message, systemd_link_dns_reply,
state, NULL);
}
static void resolve_systemd_remove(uint32_t ifindex, void *data)