resolved: read the per-interface LLMNR setting from networkd and act on it

This commit is contained in:
Lennart Poettering 2014-08-04 23:08:03 +02:00
parent b3df0b34c1
commit 19b50b5ba7
3 changed files with 46 additions and 10 deletions

View File

@ -42,6 +42,7 @@ int link_new(Manager *m, Link **ret, int ifindex) {
return -ENOMEM;
l->ifindex = ifindex;
l->llmnr_support = SUPPORT_YES;
r = hashmap_put(m->links, INT_TO_PTR(ifindex), l);
if (r < 0)
@ -92,7 +93,7 @@ static void link_allocate_scopes(Link *l) {
} else
l->unicast_scope = dns_scope_free(l->unicast_scope);
if (link_relevant(l, AF_INET) && l->manager->llmnr_support != SUPPORT_NO) {
if (link_relevant(l, AF_INET) && l->llmnr_support != SUPPORT_NO && l->manager->llmnr_support != SUPPORT_NO) {
if (!l->llmnr_ipv4_scope) {
r = dns_scope_new(l->manager, &l->llmnr_ipv4_scope, l, DNS_PROTOCOL_LLMNR, AF_INET);
if (r < 0)
@ -101,7 +102,7 @@ static void link_allocate_scopes(Link *l) {
} else
l->llmnr_ipv4_scope = dns_scope_free(l->llmnr_ipv4_scope);
if (link_relevant(l, AF_INET6) && l->manager->llmnr_support != SUPPORT_NO) {
if (link_relevant(l, AF_INET6) && l->llmnr_support != SUPPORT_NO && l->manager->llmnr_support != SUPPORT_NO) {
if (!l->llmnr_ipv6_scope) {
r = dns_scope_new(l->manager, &l->llmnr_ipv6_scope, l, DNS_PROTOCOL_LLMNR, AF_INET6);
if (r < 0)
@ -188,10 +189,40 @@ clear:
return r;
}
static int link_update_llmnr_support(Link *l) {
_cleanup_free_ char *b = NULL;
int r;
assert(l);
r = sd_network_get_llmnr(l->ifindex, &b);
if (r < 0)
goto clear;
r = parse_boolean(b);
if (r < 0) {
if (streq(b, "resolve"))
l->llmnr_support = SUPPORT_RESOLVE;
else
goto clear;
} else if (r > 0)
l->llmnr_support = SUPPORT_YES;
else
l->llmnr_support = SUPPORT_NO;
return 0;
clear:
l->llmnr_support = SUPPORT_YES;
return r;
}
int link_update_monitor(Link *l) {
assert(l);
link_update_dns_servers(l);
link_update_llmnr_support(l);
link_allocate_scopes(l);
link_add_rrs(l, false);
@ -353,6 +384,7 @@ void link_address_add_rrs(LinkAddress *a, bool force_remove) {
if (!force_remove &&
link_address_relevant(a) &&
a->link->llmnr_ipv4_scope &&
a->link->llmnr_support == SUPPORT_YES &&
a->link->manager->llmnr_support == SUPPORT_YES) {
if (!a->link->manager->host_ipv4_key) {
@ -409,6 +441,7 @@ void link_address_add_rrs(LinkAddress *a, bool force_remove) {
if (!force_remove &&
link_address_relevant(a) &&
a->link->llmnr_ipv6_scope &&
a->link->llmnr_support == SUPPORT_YES &&
a->link->manager->llmnr_support == SUPPORT_YES) {
if (!a->link->manager->host_ipv6_key) {

View File

@ -59,6 +59,8 @@ struct Link {
LIST_HEAD(DnsServer, dns_servers);
DnsServer *current_dns_server;
Support llmnr_support;
DnsScope *unicast_scope;
DnsScope *llmnr_ipv4_scope;
DnsScope *llmnr_ipv6_scope;

View File

@ -30,6 +30,15 @@
#include "hashmap.h"
typedef struct Manager Manager;
typedef enum Support Support;
enum Support {
SUPPORT_NO,
SUPPORT_YES,
SUPPORT_RESOLVE,
_SUPPORT_MAX,
_SUPPORT_INVALID = -1
};
#include "resolved-dns-query.h"
#include "resolved-dns-server.h"
@ -37,14 +46,6 @@ typedef struct Manager Manager;
#include "resolved-dns-stream.h"
#include "resolved-link.h"
typedef enum Support {
SUPPORT_NO,
SUPPORT_YES,
SUPPORT_RESOLVE,
_SUPPORT_MAX,
_SUPPORT_INVALID = -1
} Support;
struct Manager {
sd_event *event;