router: make announcing DNS info configurable (FS#2020)
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 31 Dec 2018 16:06:40 +0000 (17:06 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Tue, 1 Jan 2019 12:53:34 +0000 (13:53 +0100)
Make announcing options Recursive DNS server and DNS search list
configurable via the ra_dns config option.
This allows to disable sending RA based DNS info if such info is
already provided by DHCPv6.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
README
src/config.c
src/odhcpd.h
src/router.c

diff --git a/README b/README
index 0c562e6faed472dadf8170a9e4e83f214cb054a8..158b5b8a30bee5511781983f977717d3b411ce05 100644 (file)
--- a/README
+++ b/README
@@ -132,6 +132,8 @@ ra_hoplimit         integer 0                       Current hoplimit to be advertised
                                                        in RA messages
 ra_mtu                 integer 0                       MTU to be advertised in
                                                        RA messages
+ra_dns                 bool    1                       Announce DNS configuration in
+                                                       RA messages (RFC8106)
 ndproxy_routing                bool    1                       Learn routes from NDP
 ndproxy_slave          bool    0                       NDProxy external slave
 prefix_filter          string  ::/0                    Only advertise on-link prefixes within
index 9ffe1ac14123b2c0d64882d2fa61ea4093676d50..29d71813828c585f17555a0c813851eab16113c2 100644 (file)
@@ -58,6 +58,7 @@ enum {
        IFACE_ATTR_RA_RETRANSTIME,
        IFACE_ATTR_RA_HOPLIMIT,
        IFACE_ATTR_RA_MTU,
+       IFACE_ATTR_RA_DNS,
        IFACE_ATTR_PD_MANAGER,
        IFACE_ATTR_PD_CER,
        IFACE_ATTR_NDPROXY_ROUTING,
@@ -103,6 +104,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_RA_RETRANSTIME] = { .name = "ra_retranstime", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_RA_HOPLIMIT] = { .name = "ra_hoplimit", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_RA_MTU] = { .name = "ra_mtu", .type = BLOBMSG_TYPE_INT32 },
+       [IFACE_ATTR_RA_DNS] = { .name = "ra_dns", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_NDPROXY_ROUTING] = { .name = "ndproxy_routing", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_NDPROXY_SLAVE] = { .name = "ndproxy_slave", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_PREFIX_FILTER] = { .name = "prefix_filter", .type = BLOBMSG_TYPE_STRING },
@@ -218,6 +220,7 @@ static void set_interface_defaults(struct interface *iface)
        iface->ra_maxinterval = 600;
        iface->ra_mininterval = iface->ra_maxinterval/3;
        iface->ra_lifetime = -1;
+       iface->ra_dns = true;
 }
 
 static void clean_interface(struct interface *iface)
@@ -704,6 +707,9 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        if ((c = tb[IFACE_ATTR_RA_USELEASETIME]))
                iface->ra_useleasetime = blobmsg_get_bool(c);
 
+       if ((c = tb[IFACE_ATTR_RA_DNS]))
+               iface->ra_dns = blobmsg_get_bool(c);
+
        if ((c = tb[IFACE_ATTR_RA_PREFERENCE])) {
                const char *prio = blobmsg_get_string(c);
 
index 80dbb40f3463bbc8ed4e4484fc377075f2557a7a..10f26b1a925cdf0c604b704f2d7d2bca3af55177 100644 (file)
@@ -193,6 +193,7 @@ struct interface {
        bool ra_not_onlink;
        bool ra_advrouter;
        bool ra_useleasetime;
+       bool ra_dns;
        bool no_dynamic_dhcp;
        uint8_t pio_filter_length;
        struct in6_addr pio_filter_addr;
index f45ecab67fbfdbc8605ceeb1dabd1e6476d1cdb3..f8a83a6437d0ddb3d58a32160bb9b17007a6d52a 100644 (file)
@@ -428,12 +428,14 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
        struct in6_addr dns_pref, *dns_addr = NULL;
        size_t dns_cnt = 0;
 
-       if (iface->dns_cnt > 0) {
-               dns_addr = iface->dns;
-               dns_cnt = iface->dns_cnt;
-       } else if (!odhcpd_get_interface_dns_addr(iface, &dns_pref)) {
-               dns_addr = &dns_pref;
-               dns_cnt = 1;
+       if (iface->ra_dns) {
+               if (iface->dns_cnt > 0) {
+                       dns_addr = iface->dns;
+                       dns_cnt = iface->dns_cnt;
+               } else if (!odhcpd_get_interface_dns_addr(iface, &dns_pref)) {
+                       dns_addr = &dns_pref;
+                       dns_cnt = 1;
+               }
        }
 
        /* Construct Prefix Information options */
@@ -541,15 +543,22 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
        } dns = {ND_OPT_RECURSIVE_DNS, (1 + (2 * dns_cnt)), 0, 0, 0};
 
        /* DNS Search options */
-       uint8_t search_buf[256], *search_domain = iface->search;
-       size_t search_len = iface->search_len, search_padded = 0;
-
-       if (!search_domain && !res_init() && _res.dnsrch[0] && _res.dnsrch[0][0]) {
-               int len = dn_comp(_res.dnsrch[0], search_buf,
-                               sizeof(search_buf), NULL, NULL);
-               if (len > 0) {
-                       search_domain = search_buf;
-                       search_len = len;
+       uint8_t *search_domain = NULL;
+       size_t search_len = 0, search_padded = 0;
+
+       if (iface->ra_dns) {
+               search_len = iface->search_len;
+               search_domain = iface->search;
+
+               if (!search_domain && !res_init() && _res.dnsrch[0] && _res.dnsrch[0][0]) {
+                       uint8_t search_buf[256];
+
+                       int len = dn_comp(_res.dnsrch[0], search_buf,
+                                       sizeof(search_buf), NULL, NULL);
+                       if (len > 0) {
+                               search_domain = search_buf;
+                               search_len = len;
+                       }
                }
        }