int dmaddr_index;
} qcontext;
+typedef struct {
+ adns_query qu;
+ const byte *dgram;
+ int serv, dglen, max, nsstart;
+} parseinfo;
+
typedef struct {
adns_rrtype type;
const char *rrtname;
* and will not be null-terminated by convstring.
*/
- adns_status (*parse)(adns_query qu, int serv,
- const byte *dgram, int dglen, int cbyte, int max,
- int nsstart, int *arstart_io, void *store_r);
+ adns_status (*parse)(const struct parseinfo *pai, int cbyte, void *store_r);
/* Parse one RR, in dgram of length dglen, starting at cbyte and
* extending until at most max.
*
* If there is an overrun which might indicate truncation, it should set
* *rdstart to -1; otherwise it may set it to anything else positive.
*
- * nsstart is the offset of the authority section; *arstart_io is
- * -1 or the offset of the additional section; if it is -1 then
- * parse may set it to the correct offset.
+ * nsstart is the offset of the authority section.
*/
int (*diff_needswap)(const void *datap_a, const void *datap_b);
const byte *dgram, int dglen, int *cbyte_io,
int *type_r, int *class_r, int *rdlen_r, int *rdstart_r,
int *ownermatchedquery_r);
- /* Finds the extent and some of the contents of an RR in a datagram
- * and does some checks. The datagram is *dgram, length dglen, and
- * the RR starts at *cbyte_io (which is updated afterwards to point
- * to the end of the RR).
- *
- * The type, class and RRdata length and start are returned iff
- * the corresponding pointer variables are not null. type_r and
- * class_r may not be null.
- *
- * If ownermatchedquery_r != 0 then the owner domain of this
- * RR will be compared with that in the query (or, if the query
- * has gone to a CNAME lookup, with the canonical name).
- * In this case, *ownermatchedquery_r will be set to 0 or 1.
- * The query datagram (or CNAME datagram) MUST be valid and not truncated.
- *
- * If there is truncation then *type_r will be set to -1 and
- * *cbyte_io, *class_r, *rdlen_r, *rdstart_r and *eo_matched_r will be
- * undefined.
- *
- * qu must obviously be non-null.
- *
- * If an error is returned then *type_r will be undefined too.
- */
+/* Finds the extent and some of the contents of an RR in a datagram
+ * and does some checks. The datagram is *dgram, length dglen, and
+ * the RR starts at *cbyte_io (which is updated afterwards to point
+ * to the end of the RR).
+ *
+ * The type, class and RRdata length and start are returned iff
+ * the corresponding pointer variables are not null. type_r and
+ * class_r may not be null.
+ *
+ * If ownermatchedquery_r != 0 then the owner domain of this
+ * RR will be compared with that in the query (or, if the query
+ * has gone to a CNAME lookup, with the canonical name).
+ * In this case, *ownermatchedquery_r will be set to 0 or 1.
+ * The query datagram (or CNAME datagram) MUST be valid and not truncated.
+ *
+ * If there is truncation then *type_r will be set to -1 and
+ * *cbyte_io, *class_r, *rdlen_r, *rdstart_r and *eo_matched_r will be
+ * undefined.
+ *
+ * qu must obviously be non-null.
+ *
+ * If an error is returned then *type_r will be undefined too.
+ */
+
+static adns_status findrr_anychk(adns_query qu, int serv,
+ const byte *dgram, int dglen, int *cbyte_io,
+ int *type_r, int *class_r, int *rdlen_r, int *rdstart_r,
+ const byte *eo_dgram, int eo_dglen, int eo_cbyte,
+ int *eo_matched_r);
+/* Like adns__findrr_checked, except that the datagram and
+ * owner to compare with can be specified explicitly.
+ *
+ * If the caller thinks they know what the owner of the RR ought to
+ * be they can pass in details in eo_*: this is another (or perhaps
+ * the same datagram), and a pointer to where the putative owner
+ * starts in that datagram. In this case *eo_matched_r will be set
+ * to 1 if the datagram matched or 0 if it did not. Either
+ * both eo_dgram and eo_matched_r must both be non-null, or they
+ * must both be null (in which case eo_dglen and eo_cbyte will be ignored).
+ * The eo datagram and contained owner domain MUST be valid and
+ * untruncated.
+ */
int vbuf__append_quoted1035(vbuf *vb, const byte *buf, int len);
return adns_s_ok;
}
-static adns_status findrr_intern(adns_query qu, int serv,
+static adns_status findrr_anychk(adns_query qu, int serv,
const byte *dgram, int dglen, int *cbyte_io,
int *type_r, int *class_r, int *rdlen_r, int *rdstart_r,
const byte *eo_dgram, int eo_dglen, int eo_cbyte,
int *eo_matched_r) {
- /* Like adns__findrr_checked, except that the datagram to compare
- * with can be specified explicitly.
- *
- * If the caller thinks they know what the owner of the RR ought to
- * be they can pass in details in eo_*: this is another (or perhaps
- * the same datagram), and a pointer to where the putative owner
- * starts in that datagram. In this case *eo_matched_r will be set
- * to 1 if the datagram matched or 0 if it did not. Either
- * both eo_dgram and eo_matched_r must both be non-null, or they
- * must both be null (in which case eo_dglen and eo_cbyte will be ignored).
- * The eo datagram and contained owner domain MUST be valid and
- * untruncated.
- */
findlabel_state fls, eo_fls;
int cbyte;
int *type_r, int *class_r, int *rdlen_r, int *rdstart_r,
int *ownermatchedquery_r) {
if (!ownermatchedquery_r) {
- return findrr_intern(qu,serv,
+ return findrr_anychk(qu,serv,
dgram,dglen,cbyte_io,
type_r,class_r,rdlen_r,rdstart_r,
0,0,0, 0);
} else if (!qu->cname_dgram) {
- return findrr_intern(qu,serv,
+ return findrr_anychk(qu,serv,
dgram,dglen,cbyte_io,
type_r,class_r,rdlen_r,rdstart_r,
qu->query_dgram,qu->query_dglen,DNS_HDRSIZE,
ownermatchedquery_r);
} else {
- return findrr_intern(qu,serv,
+ return findrr_anychk(qu,serv,
dgram,dglen,cbyte_io,
type_r,class_r,rdlen_r,rdstart_r,
qu->cname_dgram,qu->cname_dglen,qu->cname_begin,
static adns_status pa_addr(adns_query qu, int serv,
const byte *dgram, int dglen, int cbyte, int max,
- int nsstart, int *arstart_io, void *datap) {
+ void *datap) {
adns_addr *storeto= datap;
-
+
if (max-cbyte != 4) return adns_s_invaliddata;
storeto->len= sizeof(storeto->addr.inet);
memset(&storeto->addr,0,sizeof(storeto->addr.inet));
return adns_s_ok;
}
+
+static adns_status pap_findaddrs(adns_query qu, int serv, adns_rr_hostaddr *ha,
+ const byte *dgram, int dglen, int *cbyte_io,
+ int dmstart, int count) {
+ int rri, nrrs;
+ int type, class, rdlen, rdstart, ownermatched;
+
+ for (rri=0, nrrs=-1; rri<count; rri++) {
+ st= adns__findrr_anychk(qu,serv,dgram,dglen,cbyte_io,
+ &type,&class,&rdlen,&rdstart,
+ dgram,dglen,dmstart,
+ &ownermatched);
+ if (st) return st;
+ if (class != DNS_CLASS_IN) continue;
+ if (type != adns_r_a) continue;
+ if (nrrs == -1) {
+ qu->vb.used= 0;
+ nrrs= 0;
+ }
+ if (!adns__vbuf_ensure(&qu->vb,qu->vb.used+sizeof(adns_addr)))
+ return adns_s_nolocalmem;
+ st= pa_addr(qu,serv, dgram,dglen, rdstart,rdstart+rdlen,
+ qu->vb.buf + qu->vb.used);
+ if (st) return st;
+ qu->vb.used += sizeof(adns_addr);
+ nrrs++;
+ }
+ if (nrrs >= 0) {
+ ha->rrs= adns__alloc_interim(qu,qu->vb.used);
+ if (!ha->rrs) return adns_s_nolocalmem;
+ ha->nrrs= nrrs;
+ ha->astatus= adns_s_ok;
+ }
+ return adns_s_ok;
+}
+
+static adns_status pap_hostaddr(adns_query qu, int serv,
+ const byte *dgram, int dglen, int *cbyte_io, int max,
+ int nsstart, int nscount, int arcount, void *datap) {
+ adns_rr_hostaddr **rrp= datap;
+ adns_status st;
+ int dmstart, cbyte;
+
+ dmstart= cbyte= *cbyte_io;
+ st= pap_domain(qu,serv,
+ qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0,
+ dgram,dglen,&cbyte,max,&rrp->dm);
+ if (st) return st;
+ *cbyte_io= cbyte;
+
+ rrp->astatus= adns_s_ok;
+ rrp->naddrs= -1;
+ rrp->addrs= 0;
+
+ cbyte= nsstart;
+
+ st= pap_findaddrs(qu, rrp, dgram,dglen,&cbyte, dmstart);
+ if (st) return st;
+ if (rrp->naddrs != -1) return adns_s_ok;
+
+ st= pap_findaddrs(qu, rrp, dgram,dglen,&cbyte, dmstart);
+ if (st) return st;
+ if (rrp->naddrs != -1) return adns_s_ok;
+}
+
+static adns_status pa_hostaddr(adns_query qu, int serv,
+ const byte *dgram, int dglen, int cbyte, int max,
+ int nsstart, void *datap) {
+ adns_rr_hostaddr **rrp= datap;
+ adns_status st;
+ int dmstart;
+
+ dmstart= cbyte;
+ st= pap_domain(qu,serv,
+ qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0,
+ dgram,dglen,&cbyte,max,&rrp->dm);
+ if (st) return st;
+ if (cbyte != max) return adns_s_invaliddata;
+
+ rrp->astatus= adns_s_ok;
+ rrp->naddrs= -1;
+ rrp->addrs= 0;
+
+ cbyte= nsstart;
+
+ st= pap_findaddrs(qu, rrp, dgram,dglen, dmstart,&cbyte);
+ if (st) return st;
+ if (rrp->naddrs != -1) return adns_s_ok;
+
+ st= pap_findaddrs(qu, rrp, dgram,dglen, dmstart,&cbyte);
+ if (st) return st;
+ if (rrp->naddrs != -1) return adns_s_ok;
+
+ assert(!"additional section didn't have required data");
+}
+
static int di_mx_raw(const void *datap_a, const void *datap_b) {
const adns_rr_intstr *ap= datap_a, *bp= datap_b;
/* Must be in ascending order of rrtype ! */
/* rr type code rrt fmt mem.mgmt member parser comparer */
- { adns_r_a, "A", 0, FLAT_MEMB(inaddr), pa_inaddr, di_inaddr },
- { adns_r_ns_raw, "NS", "raw", DEEP_MEMB(str), pa_host_raw, 0 },
- { adns_r_cname, "CNAME", 0, DEEP_MEMB(str), pa_host_raw, 0 },
-#if 0 /*fixme*/
- { adns_r_soa_raw, "SOA", "raw", DEEP_MEMB(soa), pa_soa, 0 },
-#endif
- { adns_r_ptr_raw, "PTR", "raw", DEEP_MEMB(str), pa_host_raw, 0 },
-#if 0 /*fixme*/
- { adns_r_hinfo, "HINFO", 0, DEEP_MEMB(strpair), pa_hinfo, 0 },
-#endif
- { adns_r_mx_raw, "MX", "raw", DEEP_MEMB(intstr), pa_mx_raw, di_mx_raw },
- { adns_r_txt, "TXT", 0, DEEP_MEMB(manyistr), pa_txt, 0 },
-#if 0 /*fixme*/
- { adns_r_rp_raw, "RP", "raw", DEEP_MEMB(strpair), pa_rp, 0 },
-#endif
-
- { adns_r_addr, "A", "addr", FLAT_MEMB(addr), pa_addr, di_addr },
-#if 0 /*fixme*/
- { adns_r_ns, "NS", "+addr", DEEP_MEMB(dmaddr), pa_dmaddr, di_dmaddr },
- { adns_r_ptr, "PTR","checked", DEEP_MEMB(str), pa_ptr, 0 },
- { adns_r_mx, "MX", "+addr", DEEP_MEMB(intdmaddr), pa_mx, di_mx },
+ { adns_r_a, "A", 0, FLAT_MEMB(inaddr), pa_inaddr, di_inaddr },
+ { adns_r_ns_raw, "NS", "raw", DEEP_MEMB(str), pa_host_raw, 0 },
+ { adns_r_cname, "CNAME", 0, DEEP_MEMB(str), pa_host_raw, 0 },
+#if 0 /*fixme*/
+ { adns_r_soa_raw, "SOA", "raw", DEEP_MEMB(soa), pa_soa, 0 },
+#endif
+ { adns_r_ptr_raw, "PTR", "raw", DEEP_MEMB(str), pa_host_raw, 0 },
+#if 0 /*fixme*/
+ { adns_r_hinfo, "HINFO", 0, DEEP_MEMB(strpair), pa_hinfo, 0 },
+#endif
+ { adns_r_mx_raw, "MX", "raw", DEEP_MEMB(intstr), pa_mx_raw, di_mx_raw },
+ { adns_r_txt, "TXT", 0, DEEP_MEMB(manyistr), pa_txt, 0 },
+#if 0 /*fixme*/
+ { adns_r_rp_raw, "RP", "raw", DEEP_MEMB(strpair), pa_rp, 0 },
+#endif
+
+ { adns_r_addr, "A", "addr", FLAT_MEMB(addr), pa_addr, di_addr },
+ { adns_r_ns, "NS", "+addr", DEEP_MEMB(dmaddr), pa_hostaddr, di_hostaddr },
+#if 0 /*fixme*/
+ { adns_r_ptr, "PTR","checked", DEEP_MEMB(str), pa_ptr, 0 },
+ { adns_r_mx, "MX", "+addr", DEEP_MEMB(intdmaddr), pa_mx, di_mx },
#endif
#if 0 /*fixme*/