<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I do some research from the source code. And find some interesting.</div><div class=""><br class=""></div><div class="">The forward zones will be build into a Red-Black tree. And the compare function is: int dname_lab_cmp(uint8_t* d1, int labs1, uint8_t* d2, int labs2, int* mlabs)(source code attached last).</div><div class=""><br class=""></div><div class="">In my option, the compare function is about this rules:</div><div class=""><br class=""></div><div class="">1. Compare same No. label from left to right.</div><div class="">2. For Same No. label, longer is bigger</div><div class="">3. Else If label has same length, later<span style="background-color: rgb(255, 255, 255);" class=""> </span><span style="background-color: rgb(255, 255, 255);" class="">character is bigger</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class="">4. Else, have more labels is bigger</span></div><div class=""><br class=""></div><div class="">e.g.</div><div class="">1. <a href="http://www.example.com" class="">www.example.com</a></div><div class="">2. <a href="http://example.com" class="">example.com</a></div><div class="">3. <a href="http://ab.example.com" class="">ab.example.com</a></div><div class="">4. <a href="http://www.zxample.com" class="">www.zxample.com</a></div><div class="">5. <a href="http://zxample.com" class="">zxample.com</a></div><div class="">6. <a href="http://longexample.com" class="">longexample.com</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">the sorted order muse be: 6 > 4 > 5 > 1 > 3 > 2.</div><div class=""><br class=""></div><div class="">Now suppose we build the Red-Black tree without 1. the right order is: 6 > 4 > 5 > 3 > 2.</div><div class=""><br class=""></div><div class="">And Let’s lookup <a href="http://www.example.com" class="">www.example.com</a> from the tree. The Search function is below:</div><div class=""><br class=""></div><div class=""><div class="">int</div><div class="">rbtree_find_less_equal(rbtree_type *rbtree, const void *key,</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>rbnode_type **result)</div><div class="">{</div><div class=""><span class="Apple-tab-span" style="white-space:pre">  </span>int r;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>rbnode_type *node;</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>log_assert(result);</div><div class=""><span class="Apple-tab-span" style="white-space:pre">       </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">  </span>/* We start at root... */</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>node = rbtree->root;</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>*result = NULL;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">   </span>fptr_ok(fptr_whitelist_rbtree_cmp(rbtree->cmp));</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/* While there are children... */</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>while (node != RBTREE_NULL) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">             </span>r = rbtree->cmp(key, node->key);</div><div class=""><span class="Apple-tab-span" style="white-space:pre">            </span>if (r == 0) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                     </span>/* Exact match */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                 </span>*result = node;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                   </span>return 1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">         </span>} </div><div class=""><span class="Apple-tab-span" style="white-space:pre">           </span>if (r < 0) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                   </span>node = node->left;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">             </span>} else {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                  </span>/* Temporary match */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                     </span>*result = node;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                   </span>node = node->right;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">            </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>return 0;</div><div class="">}</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">It’s clear, It will find the exact or closest but bigger result. according our original order, the result must be 3: <a href="http://ab.example.com" class="">ab.example.com</a></div><div class=""><br class=""></div><div class="">What does it mean?</div><div class=""><br class=""></div><div class="">I want to find NS for <a href="http://www.example.com" class="">www.example.com</a>, It it result to <a href="http://ab.example.com" class="">ab.example.com</a> instead of <a href="http://example.com" class="">example.com</a>.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Am I make mistakes or it’s designed to?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">int </div><div class="">dname_lab_cmp(uint8_t* d1, int labs1, uint8_t* d2, int labs2, int* mlabs)</div><div class="">{</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>uint8_t len1, len2;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">       </span>int atlabel = labs1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">      </span>int lastmlabs;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>int lastdiff = 0;</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>/* first skip so that we compare same label. */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">   </span>if(labs1 > labs2) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">            </span>while(atlabel > labs2) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                       </span>len1 = *d1++;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                     </span>d1 += len1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                       </span>atlabel--;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">         </span>log_assert(atlabel == labs2);</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>} else if(labs1 < labs2) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">             </span>atlabel = labs2;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">          </span>while(atlabel > labs1) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                       </span>len2 = *d2++;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                     </span>d2 += len2;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                       </span>atlabel--;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">         </span>log_assert(atlabel == labs1);</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>lastmlabs = atlabel+1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>/* now at same label in d1 and d2, atlabel */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>/* <a href="http://www.example.com" class="">www.example.com</a>.                  */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/* 4   3       2  1   atlabel number */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>/* repeat until at root label (which is always the same) */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">       </span>while(atlabel > 1) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">           </span>len1 = *d1++;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">             </span>len2 = *d2++;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">             </span>if(len1 != len2) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>log_assert(len1 != 0 && len2 != 0);</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                       </span>if(len1<len2)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                          </span>lastdiff = -1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                    </span>else<span class="Apple-tab-span" style="white-space:pre">        </span>lastdiff = 1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                     </span>lastmlabs = atlabel;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                      </span>d1 += len1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                       </span>d2 += len2;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">               </span>} else {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                  </span>/* memlowercmp is inlined here; or just like</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                      </span> * if((c=memlowercmp(d1, d2, len1)) != 0) { </div><div class=""><span class="Apple-tab-span" style="white-space:pre">                 </span> *<span class="Apple-tab-span" style="white-space:pre">  </span>lastdiff = c;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                     </span> *<span class="Apple-tab-span" style="white-space:pre">  </span>lastmlabs = atlabel; } apart from d1++,d2++ */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                    </span>while(len1) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                             </span>if(*d1 != *d2 && tolower((unsigned char)*d1) </div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                        </span>!= tolower((unsigned char)*d2)) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                 </span>if(tolower((unsigned char)*d1) < </div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                         </span>tolower((unsigned char)*d2)) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                            </span>lastdiff = -1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                            </span>lastmlabs = atlabel;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                              </span>d1 += len1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                               </span>d2 += len1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                               </span>break;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                    </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                 </span>lastdiff = 1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                     </span>lastmlabs = atlabel;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                      </span>d1 += len1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                       </span>d2 += len1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                       </span>break; /* out of memlowercmp */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                           </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                         </span>d1++;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                             </span>d2++;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                             </span>len1--;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                   </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">         </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">         </span>atlabel--;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>/* last difference atlabel number, so number of labels matching,</div><div class=""><span class="Apple-tab-span" style="white-space:pre">  </span> * at the right side, is one less. */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>*mlabs = lastmlabs-1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>if(lastdiff == 0) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">               </span>/* all labels compared were equal, check if one has more</div><div class=""><span class="Apple-tab-span" style="white-space:pre">          </span> * labels, so that <a href="http://example.com" class="">example.com</a>. > com. */</div><div class=""><span class="Apple-tab-span" style="white-space:pre">            </span>if(labs1 > labs2)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                      </span>return 1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">         </span>else if(labs1 < labs2)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                 </span>return -1;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>return lastdiff;</div><div class="">}</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(153, 153, 153); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13.1999998092651px; line-height: 19.7999992370605px; widows: 1; background-color: rgb(255, 255, 255);" class="">Thanks</div><div style="font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(153, 153, 153); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13.1999998092651px; line-height: 19.7999992370605px; widows: 1; background-color: rgb(255, 255, 255);" class=""><br class="Apple-interchange-newline">-- </div><div style="font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(153, 153, 153); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13.1999998092651px; line-height: 19.7999992370605px; widows: 1; background-color: rgb(255, 255, 255);" class="">Newell Zhu</div><div style="font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(153, 153, 153); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13.1999998092651px; line-height: 19.7999992370605px; widows: 1; background-color: rgb(255, 255, 255);" class="">Blog: <a href="http://blog.zlxstar.me/" class="">http://zlxstar.me/</a></div><div style="font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(153, 153, 153); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13.1999998092651px; line-height: 19.7999992370605px; widows: 1; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 13.1999998092651px;" class="">Github: </span><a href="http://github.com/zlx" class="">http://github.com/zlx<br class=""></a></div></div></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 8 Sep 2017, at 22:12, Newell Zhu <<a href="mailto:zlx.star@gmail.com" class="">zlx.star@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello<div class=""><br class=""></div><div class="">System is windows 7 and unbound 1.6.5.</div><div class=""><br class=""></div><div class="">I have below forward zone in server.conf</div><div class=""><br class=""></div><div class=""><div class="">forward-zone:</div><div class="">      name: '<a href="http://taobao.com/" class="">taobao.com</a>.'</div><div class="">      forward-addr: 114.114.114.114</div></div><div class=""><br class=""></div><div class="">to forward all domain like *.<a href="http://taobao.com/" class="">taobao.com</a> to 114 dns server.</div><div class=""><br class=""></div><div class="">But it seems except <a href="http://taobao.com/" class="">taobao.com</a>, other subdomains, e.g..<a href="http://www.taobao.com/" class="">www.taobao.com</a> do not forward to 114.114.114.114</div><div class=""><br class=""></div><div class="">I test it on ubuntu, and it’s OK.</div><div class=""><br class=""></div><div class="">So am I missing something in my config?</div><div class=""><br class=""></div><div class="">My whole server.conf:</div><div class=""><br class=""></div><div class=""><div class="">server:</div><div class="">   access-control: 127.0.0.0/8 allow</div><div class="">   access-control: 192.168.0.0/16 allow</div><div class="">   cache-max-ttl: 14400</div><div class="">   cache-min-ttl: 900</div><div class="">   hide-identity: yes</div><div class="">   hide-version: yes</div><div class="">   interface: 0.0.0.0</div><div class="">   minimal-responses: yes</div><div class="">   prefetch: yes</div><div class="">   qname-minimisation: yes</div><div class="">   rrset-roundrobin: yes</div><div class="">   use-caps-for-id: yes</div><div class="">   verbosity: 4</div><div class="">   use-syslog: yes</div><div class="">   log-time-ascii: yes</div><div class=""><br class=""></div><div class="">forward-zone:</div><div class="">      name: '<a href="http://taobao.com/" class="">taobao.com</a>.'</div><div class="">      forward-addr: 114.114.114.114</div><div class=""><br class=""></div><div class="">forward-zone:</div><div class="">      name: '<a href="http://qq.com/" class="">qq.com</a>'</div><div class="">      forward-addr: 114.114.114.114</div><div class=""><br class=""></div><div class="">forward-zone:</div><div class="">      name: '<a href="http://baidu.com/" class="">baidu.com</a>'</div><div class="">      forward-addr: 114.114.114.114</div><div class=""><br class=""></div><div class="">forward-zone:</div><div class="">      name: 'cn.'</div><div class="">      forward-addr: 114.114.114.114</div><div class=""><br class=""></div><div class="">forward-zone:</div><div class="">      name: "."</div><div class="">      forward-addr: 8.8.4.4        # Google</div><div class="">      forward-addr: 8.8.8.8        # Google</div><div class="">      forward-addr: 37.235.1.174   # FreeDNS</div><div class="">      forward-addr: 37.235.1.177   # FreeDNS</div><div class="">      forward-addr: 50.116.23.211  # OpenNIC</div><div class="">      forward-addr: 64.6.64.6      # Verisign</div><div class="">      forward-addr: 64.6.65.6      # Verisign</div><div class="">      forward-addr: 74.82.42.42    # Hurricane Electric</div><div class="">      forward-addr: 84.200.69.80   # DNS Watch</div><div class="">      forward-addr: 84.200.70.40   # DNS Watch</div><div class="">      forward-addr: 91.239.100.100 # <a href="http://censurfridns.dk/" class="">censurfridns.dk</a></div><div class="">      forward-addr: 109.69.8.51    # puntCAT</div><div class="">      forward-addr: 208.67.222.220 # OpenDNS</div><div class="">      forward-addr: 208.67.222.222 # OpenDNS</div><div class="">      forward-addr: 216.146.35.35  # Dyn Public</div><div class="">      forward-addr: 216.146.36.36  # Dyn Public   </div></div></div></div></blockquote></div><br class=""></body></html>