+
+ ads->nsortlist= 0;
+ while (nextword(&buf,&word,&l)) {
+ if (ads->nsortlist >= MAXSORTLIST) {
+ adns__diag(ads,-1,0,"too many sortlist entries,"
+ " ignoring %.*s onwards",l,word);
+ return;
+ }
+
+ if (l >= sizeof(tbuf)) {
+ configparseerr(ads,fn,lno,"sortlist entry `%.*s' too long",l,word);
+ continue;
+ }
+
+ memcpy(tbuf,word,l); tbuf[l]= 0;
+ slash= strchr(tbuf,'/');
+ if (slash) *slash++= 0;
+
+ sl= &ads->sortlist[ads->nsortlist];
+ if (!gen_pton(tbuf, AF_UNSPEC, &sl->base)) {
+ configparseerr(ads,fn,lno,"invalid address `%s' in sortlist",tbuf);
+ continue;
+ }
+
+ if (slash) {
+ if (slash[strspn(slash, "0123456789")]) {
+ maskwhat = "mask";
+ if (!gen_pton(slash, sl->base.sa.sa_family, &sl->mask)) {
+ configparseerr(ads,fn,lno,"invalid mask `%s' in sortlist",slash);
+ continue;
+ }
+ } else {
+ maskwhat = "prefix length";
+ initial= strtoul(slash,&ep,10);
+ if (*ep || initial>adns__addr_width(sl->base.sa.sa_family)) {
+ configparseerr(ads,fn,lno,"mask length `%s' invalid",slash);
+ continue;
+ }
+ sl->mask.sa.sa_family= sl->base.sa.sa_family;
+ adns__prefix_mask(&sl->mask, initial);
+ }
+ } else {
+ maskwhat = "implied prefix length";
+ initial= adns__guess_prefix_length(&sl->base);
+ if (initial < 0) {
+ configparseerr(ads,fn,lno, "network address `%s'"
+ " in sortlist is not in classed ranges,"
+ " must specify mask explicitly", tbuf);
+ continue;
+ }
+ sl->mask.sa.sa_family= sl->base.sa.sa_family;
+ adns__prefix_mask(&sl->mask, initial);
+ }
+
+ if (!adns__addr_matches(sl->base.sa.sa_family,
+ adns__sockaddr_addr(&sl->base.sa),
+ &sl->base,&sl->mask)) {
+ if (initial >= 0) {
+ configparseerr(ads,fn,lno, "%s %d in sortlist"
+ " overlaps address `%s'",maskwhat,initial,tbuf);
+ } else {
+ configparseerr(ads,fn,lno, "%s `%s' in sortlist"
+ " overlaps address `%s'",maskwhat,slash,tbuf);
+ }
+ continue;
+ }
+
+ ads->nsortlist++;
+ }
+}
+
+static void ccf_options(adns_state ads, const char *fn,
+ int lno, const char *buf) {
+ const char *opt, *word, *endword, *endopt;
+ char *ep;
+ unsigned long v;
+ int l;
+
+ if (!buf) return;
+
+#define OPTION__IS(s,op) ((endword-word) op (sizeof(s)-1) && \
+ !memcmp(word,s,(sizeof(s)-1)))
+#define OPTION_IS(s) (OPTION__IS(s,==))
+#define OPTION_STARTS(s) (OPTION__IS(s,>=) ? ((word+=sizeof(s)-1)) : 0)
+
+ while (nextword(&buf,&word,&l)) {
+ opt=word;
+ endopt=endword=word+l;
+ if (OPTION_IS("debug")) {
+ ads->iflags |= adns_if_debug;
+ continue;
+ }
+ if (OPTION_STARTS("ndots:")) {
+ v= strtoul(word,&ep,10);
+ if (ep==word || ep != endword || v > INT_MAX) {
+ configparseerr(ads,fn,lno,"option `%.*s' malformed"
+ " or has bad value",l,opt);
+ continue;
+ }
+ ads->searchndots= v;
+ continue;
+ }
+ if (OPTION_STARTS("adns_checkc:")) {
+ if (OPTION_IS("none")) {
+ ads->iflags &= ~adns_if_checkc_freq;
+ ads->iflags |= adns_if_checkc_entex;
+ } else if (OPTION_IS("entex")) {
+ ads->iflags &= ~adns_if_checkc_freq;
+ ads->iflags |= adns_if_checkc_entex;
+ } else if (OPTION_IS("freq")) {
+ ads->iflags |= adns_if_checkc_freq;
+ } else {
+ configparseerr(ads,fn,lno, "option adns_checkc has bad value `%s' "
+ "(must be none, entex or freq", word);
+ }
+ continue;
+ }
+ if (OPTION_STARTS("adns_af:")) {
+ ads->iflags &= ~adns_if_afmask;
+ if (!OPTION_IS("any")) for (;;) {
+ const char *comma= memchr(word,',',endopt-word);
+ endword=comma?comma:endopt;
+ if (OPTION_IS("ipv4"))
+ ads->iflags |= adns_if_permit_ipv4;
+ else if (OPTION_IS("ipv6"))
+ ads->iflags |= adns_if_permit_ipv6;
+ else {
+ configparseerr(ads,fn,lno, "option adns_af has bad value `%.*s' "
+ "(must be `any' or list {`ipv4',`ipv6'},...)",
+ (int)(endword-word), word);
+ break;
+ }
+ if (!comma) break;
+ word= comma+1;
+ }
+ continue;
+ }
+ if (OPTION_IS("adns_ignoreunkcfg")) {
+ ads->config_report_unknown=0;
+ continue;
+ }
+ if (/* adns's query strategy is not configurable */
+ OPTION_STARTS("timeout:") ||
+ OPTION_STARTS("attempts:") ||
+ OPTION_IS("rotate") ||
+ /* adns provides the application with knob for this */
+ OPTION_IS("no-check-names") ||
+ /* adns normally does IPv6 if the application wants it; control
+ * this with the adns_af: option if you like */
+ OPTION_IS("inet6") ||
+ /* adns does not do edns0 and this is not a problem */
+ OPTION_IS("edns0"))
+ continue;
+ if (ads->config_report_unknown)
+ adns__diag(ads,-1,0,"%s:%d: unknown option `%.*s'", fn,lno, l,opt);
+ }
+
+#undef OPTION__IS
+#undef OPTION_IS
+#undef OPTION_STARTS