network: add DBus method to set DNS server with port number and SNI

This commit is contained in:
Yu Watanabe 2020-07-03 20:03:00 +09:00
parent 87d6489776
commit 4e11ddfdd3
3 changed files with 35 additions and 5 deletions

View File

@ -114,7 +114,7 @@ int bus_link_method_set_ntp_servers(sd_bus_message *message, void *userdata, sd_
return sd_bus_reply_method_return(message, NULL);
}
int bus_link_method_set_dns_servers(sd_bus_message *message, void *userdata, sd_bus_error *error) {
static int bus_link_method_set_dns_servers_internal(sd_bus_message *message, void *userdata, sd_bus_error *error, bool extended) {
struct in_addr_full **dns = NULL;
size_t allocated = 0, n = 0;
Link *l = userdata;
@ -127,19 +127,21 @@ int bus_link_method_set_dns_servers(sd_bus_message *message, void *userdata, sd_
if (r < 0)
return r;
r = sd_bus_message_enter_container(message, 'a', "(iay)");
r = sd_bus_message_enter_container(message, 'a', extended ? "(iayqs)" : "(iay)");
if (r < 0)
return r;
for (;;) {
const char *server_name = NULL;
union in_addr_union a;
uint16_t port = 0;
const void *d;
int family;
size_t sz;
const void *d;
assert_cc(sizeof(int) == sizeof(int32_t));
r = sd_bus_message_enter_container(message, 'r', "iay");
r = sd_bus_message_enter_container(message, 'r', extended ? "iayqs" : "iay");
if (r < 0)
goto finalize;
if (r == 0)
@ -167,6 +169,19 @@ int bus_link_method_set_dns_servers(sd_bus_message *message, void *userdata, sd_
goto finalize;
}
if (extended) {
r = sd_bus_message_read(message, "q", &port);
if (r < 0)
goto finalize;
if (IN_SET(port, 53, 853))
port = 0;
r = sd_bus_message_read(message, "s", &server_name);
if (r < 0)
goto finalize;
}
r = sd_bus_message_exit_container(message);
if (r < 0)
goto finalize;
@ -177,7 +192,7 @@ int bus_link_method_set_dns_servers(sd_bus_message *message, void *userdata, sd_
}
memcpy(&a, d, sz);
r = in_addr_full_new(family, &a, 0, 0, NULL, dns + n);
r = in_addr_full_new(family, &a, port, 0, server_name, dns + n);
if (r < 0)
goto finalize;
@ -218,6 +233,14 @@ finalize:
return r;
}
int bus_link_method_set_dns_servers(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return bus_link_method_set_dns_servers_internal(message, userdata, error, false);
}
int bus_link_method_set_dns_servers_ex(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return bus_link_method_set_dns_servers_internal(message, userdata, error, true);
}
int bus_link_method_set_domains(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_(ordered_set_freep) OrderedSet *search_domains = NULL, *route_domains = NULL;
Link *l = userdata;
@ -696,6 +719,7 @@ const sd_bus_vtable link_vtable[] = {
SD_BUS_METHOD("SetNTP", "as", NULL, bus_link_method_set_ntp_servers, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetDNS", "a(iay)", NULL, bus_link_method_set_dns_servers, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetDNSEx", "a(iayqs)", NULL, bus_link_method_set_dns_servers_ex, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetDomains", "a(sb)", NULL, bus_link_method_set_domains, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetDefaultRoute", "b", NULL, bus_link_method_set_default_route, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetLLMNR", "s", NULL, bus_link_method_set_llmnr, SD_BUS_VTABLE_UNPRIVILEGED),

View File

@ -21,6 +21,7 @@ int property_get_address_state(sd_bus *bus, const char *path, const char *interf
int bus_link_method_set_ntp_servers(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_link_method_set_dns_servers(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_link_method_set_dns_servers_ex(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_link_method_set_domains(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_link_method_set_default_route(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_link_method_set_llmnr(sd_bus_message *message, void *userdata, sd_bus_error *error);

View File

@ -151,6 +151,10 @@ static int bus_method_set_link_dns_servers(sd_bus_message *message, void *userda
return call_link_method(userdata, message, bus_link_method_set_dns_servers, error);
}
static int bus_method_set_link_dns_servers_ex(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return call_link_method(userdata, message, bus_link_method_set_dns_servers_ex, error);
}
static int bus_method_set_link_domains(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return call_link_method(userdata, message, bus_link_method_set_domains, error);
}
@ -243,6 +247,7 @@ const sd_bus_vtable manager_vtable[] = {
SD_BUS_METHOD("GetLinkByIndex", "i", "so", method_get_link_by_index, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetLinkNTP", "ias", NULL, bus_method_set_link_ntp_servers, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetLinkDNS", "ia(iay)", NULL, bus_method_set_link_dns_servers, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetLinkDNSEx", "ia(iayqs)", NULL, bus_method_set_link_dns_servers_ex, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetLinkDomains", "ia(sb)", NULL, bus_method_set_link_domains, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetLinkDefaultRoute", "ib", NULL, bus_method_set_link_default_route, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetLinkLLMNR", "is", NULL, bus_method_set_link_llmnr, SD_BUS_VTABLE_UNPRIVILEGED),