Skip to content

Commit 1450e1e

Browse files
AlphixNoltari
authored andcommitted
odhcpd: remove fallback DNS search domain
This might require some explanation :) First, res_init() is marked as deprecated in the Linux man-pages (read: in glibc), and has been so for a while. Second, we use musl on OpenWrt, and what does res_init() look like in musl? musl/src/network/res_init.c: int res_init() { return 0; } musl/include/resolv.h (commit date 2011-02-12): /* unused; purely for broken apps */ typedef struct __res_state { OpenWrt switched to musl sometime in 2015 (from a quick search, don't quote me on that), and res_init() hasn't worked since then. Ok, so first I thought I might reimplement res_init(), using the glibc implementation as inspiration. glibc's res_init() basically has three sources of domain search data: 1. The LOCALDOMAIN environment variable 2. /etc/resolv.conf 3. gethostname() followed by checking if there's at least one dot in the name 1. The environment variable won't help us, we don't have it on OpenWrt and it would just be confusing. 2. resolv.conf seems reasonable, but note that it is typically a symlink: /etc/resolv.conf -> /tmp/resolv.conf -> /tmp/resolv.conf.d/resolv.conf.auto The latter is created by netifd. Where do we get iface->dns_search from? From netifd via ubus. In addition, the resolv.conf.auto that netifd generates includes all dns search domain and we might end up picking a random one (so if the user has set a domain on the guest network, but not on the main network, the former might end up being the fallback for the latter, not good). 3. gethostname() will return the hostname, which on OpenWrt is typically set to exactly that - the hostname and not a FQDN (and this is what the UIs tell the users to do). In summary, all these calls to res_init() are pointless right now, and there is no reasonable fallback once we've failed to get the info we want from netifd. So, remove the DNS search domain fallback logic if one isn't set. It's not like DHCPv[46] clients or hosts listening to RAs have any expectation that the domain search list MUST be defined. Signed-off-by: David Härdeman <david@hardeman.nu> Link: #358 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
1 parent 5b0e5c4 commit 1450e1e

File tree

4 files changed

+18
-64
lines changed

4 files changed

+18
-64
lines changed

src/dhcpv4.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <unistd.h>
2020
#include <stddef.h>
2121
#include <stdlib.h>
22-
#include <resolv.h>
2322
#include <limits.h>
2423
#include <alloca.h>
2524
#include <net/if.h>
@@ -1211,21 +1210,6 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len,
12111210
iov[IOV_SRCH_DOMAIN].iov_len = sizeof(reply_srch_domain);
12121211
iov[IOV_SRCH_DOMAIN_NAME].iov_base = iface->dns_search;
12131212
iov[IOV_SRCH_DOMAIN_NAME].iov_len = iface->dns_search_len;
1214-
} else if (!res_init() && _res.dnsrch[0] && _res.dnsrch[0][0]) {
1215-
int dds_len;
1216-
1217-
if (!iov[IOV_SRCH_DOMAIN_NAME].iov_base)
1218-
iov[IOV_SRCH_DOMAIN_NAME].iov_base = alloca(DNS_MAX_NAME_LEN);
1219-
1220-
dds_len = dn_comp(_res.dnsrch[0],
1221-
iov[IOV_SRCH_DOMAIN_NAME].iov_base,
1222-
DNS_MAX_NAME_LEN, NULL, NULL);
1223-
if (dds_len < 0)
1224-
break;
1225-
1226-
reply_srch_domain.len = dds_len;
1227-
iov[IOV_SRCH_DOMAIN].iov_len = sizeof(reply_srch_domain);
1228-
iov[IOV_SRCH_DOMAIN_NAME].iov_len = dds_len;
12291213
}
12301214
break;
12311215

src/dhcpv6.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include <errno.h>
1717
#include <unistd.h>
1818
#include <stddef.h>
19-
#include <resolv.h>
20-
#include <sys/timerfd.h>
2119
#include <arpa/inet.h>
2220

2321
#include <libubox/utils.h>
@@ -615,23 +613,10 @@ static void handle_client_request(void *addr, void *data, size_t len,
615613
}
616614

617615
/* DNS Search options */
618-
uint8_t dns_search_buf[DNS_MAX_NAME_LEN];
619-
uint8_t *dns_search = iface->dns_search;
620-
size_t dns_search_len = iface->dns_search_len;
621-
622-
if (!dns_search && !res_init() && _res.dnsrch[0] && _res.dnsrch[0][0]) {
623-
int ds_len = dn_comp(_res.dnsrch[0], dns_search_buf,
624-
sizeof(dns_search_buf), NULL, NULL);
625-
if (ds_len > 0) {
626-
dns_search = dns_search_buf;
627-
dns_search_len = ds_len;
628-
}
629-
}
630-
631616
struct {
632617
uint16_t type;
633618
uint16_t len;
634-
} dns_search_hdr = { htons(DHCPV6_OPT_DNS_DOMAIN), htons(dns_search_len) };
619+
} dns_search_hdr = { htons(DHCPV6_OPT_DNS_DOMAIN), htons(iface->dns_search_len) };
635620

636621

637622
struct _o_packed dhcpv4o6_server {
@@ -650,8 +635,8 @@ static void handle_client_request(void *addr, void *data, size_t len,
650635
[IOV_RAPID_COMMIT] = {&rapid_commit, 0},
651636
[IOV_DNS] = { &dns_hdr, (dns_addrs6_cnt) ? sizeof(dns_hdr) : 0},
652637
[IOV_DNS_ADDR] = { dns_addrs6, dns_addrs6_cnt * sizeof(*dns_addrs6) },
653-
[IOV_SEARCH] = { &dns_search_hdr, (dns_search_len) ? sizeof(dns_search_hdr) : 0 },
654-
[IOV_SEARCH_DOMAIN] = { dns_search, dns_search_len },
638+
[IOV_SEARCH] = { &dns_search_hdr, iface->dns_search_len ? sizeof(dns_search_hdr) : 0 },
639+
[IOV_SEARCH_DOMAIN] = { iface->dns_search, iface->dns_search_len },
655640
[IOV_PDBUF] = {pdbuf, 0},
656641
[IOV_DHCPV6_RAW] = {iface->dhcpv6_raw, iface->dhcpv6_raw_len},
657642
[IOV_NTP] = {&ntp, (ntp_cnt) ? sizeof(ntp) : 0},

src/odhcpd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <errno.h>
1717
#include <fcntl.h>
1818
#include <stdio.h>
19-
#include <resolv.h>
2019
#include <getopt.h>
2120
#include <stddef.h>
2221
#include <stdlib.h>

src/router.c

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <errno.h>
1717
#include <fcntl.h>
1818
#include <signal.h>
19-
#include <resolv.h>
2019
#include <stdio.h>
2120
#include <stdlib.h>
2221
#include <unistd.h>
@@ -881,14 +880,11 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
881880

882881
debug("Using a RA lifetime of %d seconds on %s", ntohs(adv.h.nd_ra_router_lifetime), iface->name);
883882

884-
/* DNS options */
883+
/* Recursive DNS Server aka RDNSS; RFC8106, §5.1 */
885884
if (iface->ra_dns) {
886885
struct in6_addr *dns_addrs6 = NULL, dns_addr6;
887-
size_t dns_addrs6_cnt = 0, dns_search_len = iface->dns_search_len;
888-
uint8_t *dns_search = iface->dns_search;
889-
uint8_t dns_search_buf[DNS_MAX_NAME_LEN];
886+
size_t dns_addrs6_cnt = 0;
890887

891-
/* DNS Recursive DNS aka RDNSS Type 25; RFC8106 */
892888
if (iface->dns_addrs6_cnt > 0) {
893889
dns_addrs6 = iface->dns_addrs6;
894890
dns_addrs6_cnt = iface->dns_addrs6_cnt;
@@ -907,32 +903,22 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
907903
dns->lifetime = htonl(highest_found_lifetime);
908904
memcpy(dns->addr, dns_addrs6, dns_addrs6_cnt * sizeof(*dns_addrs6));
909905
}
910-
911-
/* DNS Search List option aka DNSSL Type 31; RFC8106, §5.2 */
912-
if (!dns_search && !res_init() && _res.dnsrch[0] && _res.dnsrch[0][0]) {
913-
int len = dn_comp(_res.dnsrch[0], dns_search_buf,
914-
sizeof(dns_search_buf), NULL, NULL);
915-
if (len > 0) {
916-
dns_search = dns_search_buf;
917-
dns_search_len = len;
918-
}
919-
}
920-
921-
if (dns_search_len > 0) {
922-
search_sz = sizeof(*search) + ((dns_search_len + 7) & (~7));
923-
search = alloca(search_sz);
924-
*search = (struct nd_opt_search_list) {
925-
.type = ND_OPT_DNS_SEARCH,
926-
.len = search_sz / 8,
927-
.reserved = 0,
928-
.lifetime = htonl(highest_found_lifetime),
929-
};
930-
memcpy(search->name, dns_search, dns_search_len);
931-
}
932906
}
933-
934907
iov[IOV_RA_DNS].iov_base = dns;
935908
iov[IOV_RA_DNS].iov_len = dns_sz;
909+
910+
/* DNS Search List aka DNSSL; RFC8106, §5.2 */
911+
if (iface->ra_dns && iface->dns_search_len > 0) {
912+
search_sz = sizeof(*search) + ((iface->dns_search_len + 7) & ~7);
913+
search = alloca(search_sz);
914+
*search = (struct nd_opt_search_list) {
915+
.type = ND_OPT_DNS_SEARCH,
916+
.len = search_sz / 8,
917+
.reserved = 0,
918+
.lifetime = htonl(highest_found_lifetime),
919+
};
920+
memcpy(search->name, iface->dns_search, iface->dns_search_len);
921+
}
936922
iov[IOV_RA_SEARCH].iov_base = search;
937923
iov[IOV_RA_SEARCH].iov_len = search_sz;
938924

0 commit comments

Comments
 (0)