From 694148a87fa5a0c964286fdaac1fa490a2fb530b Mon Sep 17 00:00:00 2001 From: icpz Date: Sat, 21 Nov 2020 00:55:25 +0800 Subject: config: add option to indicate dns service presence Adds the config option to set if ipv6 dns service is availiable on the interface. In some cases the dns service may not be listening on the ipv6 address of the interface, and thus should not be announced to clients. Signed-off-by: Paizhuo Chen --- src/config.c | 6 ++++++ src/dhcpv4.c | 7 ++++--- src/odhcpd.c | 3 +++ src/odhcpd.h | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index 3d41e13..8a6f573 100644 --- a/src/config.c +++ b/src/config.c @@ -53,6 +53,7 @@ enum { IFACE_ATTR_NDP, IFACE_ATTR_ROUTER, IFACE_ATTR_DNS, + IFACE_ATTR_DNS_SERVICE, IFACE_ATTR_DOMAIN, IFACE_ATTR_FILTER_CLASS, IFACE_ATTR_DHCPV4_FORCERECONF, @@ -100,6 +101,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_NDP] = { .name = "ndp", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_ROUTER] = { .name = "router", .type = BLOBMSG_TYPE_ARRAY }, [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY }, + [IFACE_ATTR_DNS_SERVICE] = { .name = "dns_service", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_DOMAIN] = { .name = "domain", .type = BLOBMSG_TYPE_ARRAY }, [IFACE_ATTR_FILTER_CLASS] = { .name = "filter_class", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_DHCPV4_FORCERECONF] = { .name = "dhcpv4_forcereconf", .type = BLOBMSG_TYPE_BOOL }, @@ -235,6 +237,7 @@ static void set_interface_defaults(struct interface *iface) iface->dhcpv6_assignall = true; iface->dhcpv6_pd = true; iface->dhcpv6_na = true; + iface->dns_service = true; iface->ra_flags = ND_RA_FLAG_OTHER; iface->ra_slaac = true; iface->ra_maxinterval = 600; @@ -685,6 +688,9 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr } } + if ((c = tb[IFACE_ATTR_DNS_SERVICE])) + iface->dns_service = blobmsg_get_bool(c); + if ((c = tb[IFACE_ATTR_DOMAIN])) { struct blob_attr *cur; unsigned rem; diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 25a4c77..c3d16f5 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -842,9 +842,10 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, 4 * iface->dhcpv4_router_cnt, iface->dhcpv4_router); - if (iface->dhcpv4_dns_cnt == 0) - dhcpv4_put(&reply, &cookie, DHCPV4_OPT_DNSSERVER, 4, &iface->dhcpv4_local); - else + if (iface->dhcpv4_dns_cnt == 0) { + if (iface->dns_service) + dhcpv4_put(&reply, &cookie, DHCPV4_OPT_DNSSERVER, 4, &iface->dhcpv4_local); + } else dhcpv4_put(&reply, &cookie, DHCPV4_OPT_DNSSERVER, 4 * iface->dhcpv4_dns_cnt, iface->dhcpv4_dns); diff --git a/src/odhcpd.c b/src/odhcpd.c index 39e0e51..04a8054 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -253,6 +253,9 @@ int odhcpd_get_interface_dns_addr(const struct interface *iface, struct in6_addr time_t now = odhcpd_time(); ssize_t m = -1; + if (!iface->dns_service) + return -1; + for (size_t i = 0; i < iface->addr6_len; ++i) { if (iface->addr6[i].valid <= (uint32_t)now) continue; diff --git a/src/odhcpd.h b/src/odhcpd.h index 787be1f..0108af1 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -253,6 +253,7 @@ struct interface { bool master; bool ignore; bool always_rewrite_dns; + bool dns_service; // NDP int learn_routes; -- cgit v1.2.3