Browse Source

[trac553] Cancel wildcard on existing subdomain

Michal 'vorner' Vaner 14 years ago
parent
commit
d619eab67a
1 changed files with 27 additions and 0 deletions
  1. 27 0
      src/lib/datasrc/memory_datasrc.cc

+ 27 - 0
src/lib/datasrc/memory_datasrc.cc

@@ -434,6 +434,33 @@ struct MemoryZone::MemoryZoneImpl {
                  * is known to exist).
                  * is known to exist).
                  */
                  */
                 if (node->getFlag(DOMAINFLAG_WILD)) {
                 if (node->getFlag(DOMAINFLAG_WILD)) {
+                    /* Should we cancel this match?
+                     *
+                     * If we compare with some node and get a common ancestor,
+                     * it might mean we are comparing with a non-wildcard node.
+                     * In that case, we check which part is common. If we have
+                     * something in common that lives below the node we got
+                     * (the one above *), then we should cancel the match
+                     * according to section 4.3.3 of RFC 1034 (as the name
+                     * between the wildcard domain and the query name is known
+                     * to exist).
+                     *
+                     * Because the way the tree stores relative names, we will
+                     * have exactly one common label (the ".") in case we have
+                     * nothing common under the node we got and we will get
+                     * more common labels otherwise (yes, this relies on the
+                     * internal RBTree structure, which leaks out trough this
+                     * little bit).
+                     *
+                     * If the empty non-terminal node actually exists in the
+                     * tree, then this cancellation is not needed, because we
+                     * will not get here at all.
+                     */
+                    if (node_path.getLastComparisonResult().getRelation() ==
+                        NameComparisonResult::COMMONANCESTOR && node_path.
+                        getLastComparisonResult().getCommonLabels() > 1) {
+                        return (FindResult(NXDOMAIN, ConstRRsetPtr()));
+                    }
                     Name wildcard(Name("*").concatenate(
                     Name wildcard(Name("*").concatenate(
                         node_path.getAbsoluteName()));
                         node_path.getAbsoluteName()));
                     DomainTree::Result result(domains_.find(wildcard, &node));
                     DomainTree::Result result(domains_.find(wildcard, &node));