config: add option to indicate dns service presence
authoricpz <cc@icpz.dev>
Fri, 20 Nov 2020 16:55:25 +0000 (00:55 +0800)
committerHans Dedecker <dedeckeh@gmail.com>
Tue, 24 Nov 2020 20:24:33 +0000 (21:24 +0100)
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 <cc@icpz.dev>
README
src/config.c
src/dhcpv4.c
src/odhcpd.c
src/odhcpd.h

diff --git a/README b/README
index a5ed3199cf1b43f0f2909b11b6dca2b965895ebb..a34a93c1ae08747b4a87c31f85273b374d6b60f4 100644 (file)
--- a/README
+++ b/README
@@ -103,6 +103,8 @@ router                      list    <local address>         Routers to announce
                                                        accepts IPv4 only
 dns                    list    <local address>         DNS servers to announce
                                                        accepts IPv4 and IPv6
+dns_service            bool    1                       Announce the address of interface as DNS service
+                                                       if the list of dns is empty
 domain                 list    <local search domain>   Search domains to announce
 
 leasetime              string  12h                     DHCPv4 address leasetime
index 3d41e130f50b7308dc545e01b6104c7c1cc25eb0..8a6f573399493d980312b3942e51c7683432a526 100644 (file)
@@ -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;
index 25a4c773b09cd981fcd0b296463eb9c76bb0cb66..c3d16f56bb6262022c9f4984a4481bbb0e9e5af2 100644 (file)
@@ -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);
 
index 39e0e5137cf5514555f0ea98420d45bfe284b47d..04a8054264f66eab9ab07ef6709efe22f144d359 100644 (file)
@@ -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;
index 787be1f3423ce208d114516b20f4aec1f2e3fe32..0108af1d93c01c63ecd8e66f1ce854a3a6922a92 100644 (file)
@@ -253,6 +253,7 @@ struct interface {
        bool master;
        bool ignore;
        bool always_rewrite_dns;
+       bool dns_service;
 
        // NDP
        int learn_routes;