summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2018-12-31 16:00:12 +0100
committerHans Dedecker <dedeckeh@gmail.com>2018-12-31 16:05:09 +0100
commit1fe77f3f40cbe9227ade848e7c95f6354b2ff409 (patch)
tree2e3ab882b258c4cb167012634143bede08f759b1
parent8f498044938e6ae48a49bc441a21195dd889e632 (diff)
router: check return code of odhcpd_get_interface_dns_addr()
Check if odhcpd_get_interface_dns_addr() returns a valid DNS address. While at it restructure the DNS RA code to make it more readable Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--src/router.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/router.c b/src/router.c
index c02d675..f45ecab 100644
--- a/src/router.c
+++ b/src/router.c
@@ -424,11 +424,17 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
default_route = true;
}
+ /* DNS Recursive DNS */
+ struct in6_addr dns_pref, *dns_addr = NULL;
+ size_t dns_cnt = 0;
- struct in6_addr dns_pref, *dns_addr = &dns_pref;
- size_t dns_cnt = 1;
-
- odhcpd_get_interface_dns_addr(iface, &dns_pref);
+ 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 */
size_t pfxs_cnt = 0;
@@ -526,15 +532,6 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
syslog(LOG_INFO, "Using a RA lifetime of %d seconds on %s", ntohs(adv.h.nd_ra_router_lifetime), iface->ifname);
- /* DNS Recursive DNS */
- if (iface->dns_cnt > 0) {
- dns_addr = iface->dns;
- dns_cnt = iface->dns_cnt;
- }
-
- if (!dns_addr || IN6_IS_ADDR_UNSPECIFIED(dns_addr))
- dns_cnt = 0;
-
struct {
uint8_t type;
uint8_t len;