From 5799b89d9f5b7c9b8e00467392b72b751d2239d9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 1 Jun 2014 07:32:16 -0400 Subject: filter out dup CNAMES This happens when a docker host has an alias defined, because all docker hosts are added to the dns, same as other hosts. --- src/Propellor/Property/Dns.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/Propellor/Property') diff --git a/src/Propellor/Property/Dns.hs b/src/Propellor/Property/Dns.hs index 3e5c7828..50ce649e 100644 --- a/src/Propellor/Property/Dns.hs +++ b/src/Propellor/Property/Dns.hs @@ -339,7 +339,7 @@ genZone hosts zdomain soa = , map hostrecords inzdomain , map addcnames (M.elems m) ] - in (Zone zdomain soa (nub zhosts), warnings) + in (Zone zdomain soa (simplify zhosts), warnings) where m = hostMap hosts -- Known hosts with hostname located in the zone's domain. @@ -390,6 +390,17 @@ genZone hosts zdomain soa = l = zip (repeat $ AbsDomain $ hostName h) (S.toList $ S.filter (\r -> isNothing (getIPAddr r) && isNothing (getCNAME r)) (_dns attr)) + -- Simplifies the list of hosts. Remove duplicate entries. + -- Also, filter out any CHAMES where the same domain has an + -- IP address, since that's not legal. + simplify :: [(BindDomain, Record)] -> [(BindDomain, Record)] + simplify l = nub $ filter (not . dupcname ) l + where + dupcname (d, CNAME _) | any (matchingaddr d) l = True + dupcname _ = False + matchingaddr d (d', (Address _)) | d == d' = True + matchingaddr _ _ = False + inDomain :: Domain -> BindDomain -> Bool inDomain domain (AbsDomain d) = domain == d || ('.':domain) `isSuffixOf` d inDomain _ _ = False -- can't tell, so assume not -- cgit v1.2.3