Lines Matching refs:pkt
53 smart_compare(sldns_buffer* pkt, uint8_t* dnow,
60 >= sldns_buffer_limit(pkt))
62 p = sldns_buffer_at(pkt, PTR_OFFSET(dnow[0], dnow[1]));
70 return dname_pkt_compare(pkt, dnow, dprlast);
110 nsec_at_apex(sldns_buffer* pkt)
113 size_t pos = sldns_buffer_position(pkt);
115 if(sldns_buffer_remaining(pkt) < 7) /* ttl+len+root */
117 sldns_buffer_skip(pkt, 4); /* ttl */;
118 rdatalen = sldns_buffer_read_u16(pkt);
119 if(sldns_buffer_remaining(pkt) < rdatalen) {
120 sldns_buffer_set_position(pkt, pos);
124 if(pkt_dname_len(pkt) == 0) {
125 sldns_buffer_set_position(pkt, pos);
130 if(sldns_buffer_position(pkt) < pos+4+rdatalen) {
134 if(sldns_buffer_position(pkt)+3 > pos+4+rdatalen) {
135 sldns_buffer_set_position(pkt, pos);
138 win = sldns_buffer_read_u8(pkt);
139 blen = sldns_buffer_read_u8(pkt);
140 bits = sldns_buffer_read_u8(pkt);
144 sldns_buffer_set_position(pkt, pos);
149 sldns_buffer_set_position(pkt, pos);
155 pkt_rrset_flags(sldns_buffer* pkt, uint16_t type, sldns_pkt_section sec)
158 if(type == LDNS_RR_TYPE_NSEC && nsec_at_apex(pkt)) {
167 pkt_hash_rrset(sldns_buffer* pkt, uint8_t* dname, uint16_t type,
173 h = dname_pkt_hash(pkt, dname, h);
182 pkt_hash_rrset_first(sldns_buffer* pkt, uint8_t* dname)
188 h = dname_pkt_hash(pkt, dname, h);
208 rrset_parse_equals(struct rrset_parse* p, sldns_buffer* pkt, hashvalue_type h,
214 dname_pkt_compare(pkt, dname, p->dname) == 0)
221 msgparse_hashtable_lookup(struct msg_parse* msg, sldns_buffer* pkt,
227 if(rrset_parse_equals(p, pkt, h, rrset_flags, dname, dnamelen,
237 pkt_rrsig_covered(sldns_buffer* pkt, uint8_t* here, uint16_t* type)
239 size_t pos = sldns_buffer_position(pkt);
240 sldns_buffer_set_position(pkt, (size_t)(here-sldns_buffer_begin(pkt)));
242 if(sldns_buffer_remaining(pkt) < 4+2+19)
244 sldns_buffer_skip(pkt, 4); /* ttl */
245 if(sldns_buffer_read_u16(pkt) < 19) /* too short */ {
246 sldns_buffer_set_position(pkt, pos);
249 *type = sldns_buffer_read_u16(pkt);
250 sldns_buffer_set_position(pkt, pos);
256 pkt_rrsig_covered_equals(sldns_buffer* pkt, uint8_t* here, uint16_t type)
259 if(pkt_rrsig_covered(pkt, here, &t) && t == type)
324 rrset_has_sigover(sldns_buffer* pkt, struct rrset_parse* rrset, uint16_t type,
331 if(pkt_rrsig_covered_equals(pkt, rr->ttl_data, type))
341 moveover_rrsigs(sldns_buffer* pkt, struct regional* region,
350 if(pkt_rrsig_covered_equals(pkt, sig->ttl_data,
391 sldns_buffer* pkt, uint16_t datatype, uint32_t rrset_flags,
395 hashvalue_type hash = pkt_hash_rrset(pkt, sigset->dname, datatype,
412 if(!moveover_rrsigs(pkt, region, sigset, dataset,
443 * @param pkt: the packet in wireformat (needed for compression ptrs).
461 find_rrset(struct msg_parse* msg, sldns_buffer* pkt, uint8_t* dname,
469 hashvalue_type dname_h = pkt_hash_rrset_first(pkt, dname);
475 smart_compare(pkt, dname, *prev_dname_first,
484 pkt_rrsig_covered_equals(pkt, sldns_buffer_current(pkt),
486 smart_compare(pkt, dname, *prev_dname_first,
494 *rrset_flags = pkt_rrset_flags(pkt, type, section);
497 if(type == LDNS_RR_TYPE_RRSIG && pkt_rrsig_covered(pkt,
498 sldns_buffer_current(pkt), &covtype)) {
501 *rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash,
508 *rrset_prev = msgparse_hashtable_lookup(msg, pkt,
519 *rrset_prev = msgparse_hashtable_lookup(msg, pkt,
539 *rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash,
542 if(*rrset_prev && rrset_has_sigover(pkt, *rrset_prev, type,
551 pkt, type, *rrset_flags, hasother, section,
559 *rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, *rrset_flags,
573 * @param pkt: packet, position at call must be at start of query section.
579 parse_query_section(sldns_buffer* pkt, struct msg_parse* msg)
586 if(sldns_buffer_remaining(pkt) <= 0)
588 msg->qname = sldns_buffer_current(pkt);
589 if((msg->qname_len = pkt_dname_len(pkt)) == 0)
591 if(sldns_buffer_remaining(pkt) < sizeof(uint16_t)*2)
593 msg->qtype = sldns_buffer_read_u16(pkt);
594 msg->qclass = sldns_buffer_read_u16(pkt);
634 calc_size(sldns_buffer* pkt, uint16_t type, struct rr_parse* rr)
639 sldns_buffer_skip(pkt, 4); /* skip ttl */
640 pkt_len = sldns_buffer_read_u16(pkt);
641 if(sldns_buffer_remaining(pkt) < pkt_len)
654 oldpos = sldns_buffer_position(pkt);
655 if((len = pkt_dname_len(pkt)) == 0)
657 if(sldns_buffer_position(pkt)-oldpos > pkt_len)
659 pkt_len -= sldns_buffer_position(pkt)-oldpos;
669 len = sldns_buffer_current(pkt)[0] + 1;
678 sldns_buffer_skip(pkt, (ssize_t)len);
686 sldns_buffer_skip(pkt, (ssize_t)pkt_len);
692 skip_ttl_rdata(sldns_buffer* pkt)
695 if(sldns_buffer_remaining(pkt) < 6) /* ttl + rdatalen */
697 sldns_buffer_skip(pkt, 4); /* ttl */
698 rdatalen = sldns_buffer_read_u16(pkt);
699 if(sldns_buffer_remaining(pkt) < rdatalen)
701 sldns_buffer_skip(pkt, (ssize_t)rdatalen);
707 sig_is_double(sldns_buffer* pkt, struct rrset_parse* rrset, uint8_t* ttldata)
710 size_t pos = sldns_buffer_position(pkt);
712 if(sldns_buffer_remaining(pkt) < 6)
714 sldns_buffer_skip(pkt, 4); /* ttl */
715 rlen = sldns_buffer_read_u16(pkt);
716 if(sldns_buffer_remaining(pkt) < rlen) {
717 sldns_buffer_set_position(pkt, pos);
720 sldns_buffer_set_position(pkt, pos);
749 add_rr_to_rrset(struct rrset_parse* rrset, sldns_buffer* pkt,
765 log_buf(VERB_QUERY, "packet was", pkt);
768 if(!skip_ttl_rdata(pkt))
775 && sig_is_double(pkt, rrset, sldns_buffer_current(pkt))) {
776 if(!skip_ttl_rdata(pkt))
785 rr->ttl_data = sldns_buffer_current(pkt);
802 if(!calc_size(pkt, type, rr))
811 * @param pkt: packet, position at call must be at start of section.
821 parse_section(sldns_buffer* pkt, struct msg_parse* msg,
837 if(sldns_buffer_remaining(pkt) <= 0)
841 dname = sldns_buffer_current(pkt);
842 if((dnamelen = pkt_dname_len(pkt)) == 0)
844 if(sldns_buffer_remaining(pkt) < 10) /* type, class, ttl, len */
846 type = sldns_buffer_read_u16(pkt);
847 sldns_buffer_read(pkt, &dclass, sizeof(dclass));
852 if(pkt_rrsig_covered(pkt,
853 sldns_buffer_current(pkt), &t))
871 dname_print(stderr, pkt, dname);
876 if(!find_rrset(msg, pkt, dname, dnamelen, type, dclass, &hash,
891 dname_print(stderr, pkt, rrset->dname);
898 if((r=add_rr_to_rrset(rrset, pkt, msg, region, section,
906 parse_packet(sldns_buffer* pkt, struct msg_parse* msg, struct regional* region)
909 if(sldns_buffer_remaining(pkt) < LDNS_HEADER_SIZE)
912 sldns_buffer_read(pkt, &msg->id, sizeof(uint16_t));
913 msg->flags = sldns_buffer_read_u16(pkt);
914 msg->qdcount = sldns_buffer_read_u16(pkt);
915 msg->ancount = sldns_buffer_read_u16(pkt);
916 msg->nscount = sldns_buffer_read_u16(pkt);
917 msg->arcount = sldns_buffer_read_u16(pkt);
920 if((ret = parse_query_section(pkt, msg)) != 0)
922 if((ret = parse_section(pkt, msg, region, LDNS_SECTION_ANSWER,
925 if((ret = parse_section(pkt, msg, region, LDNS_SECTION_AUTHORITY,
928 if(sldns_buffer_remaining(pkt) == 0 && msg->arcount == 1) {
931 } else if((ret = parse_section(pkt, msg, region,
934 /* if(sldns_buffer_remaining(pkt) > 0) { */
1038 skip_pkt_rr(sldns_buffer* pkt)
1040 if(sldns_buffer_remaining(pkt) < 1) return 0;
1041 if(!pkt_dname_len(pkt))
1043 if(sldns_buffer_remaining(pkt) < 4) return 0;
1044 sldns_buffer_skip(pkt, 4); /* type and class */
1045 if(!skip_ttl_rdata(pkt))
1052 skip_pkt_rrs(sldns_buffer* pkt, int num)
1056 if(!skip_pkt_rr(pkt))
1063 parse_edns_from_pkt(sldns_buffer* pkt, struct edns_data* edns,
1068 log_assert(LDNS_QDCOUNT(sldns_buffer_begin(pkt)) == 1);
1070 if(LDNS_ANCOUNT(sldns_buffer_begin(pkt)) != 0 ||
1071 LDNS_NSCOUNT(sldns_buffer_begin(pkt)) != 0) {
1072 if(!skip_pkt_rrs(pkt, ((int)LDNS_ANCOUNT(sldns_buffer_begin(pkt)))+
1073 ((int)LDNS_NSCOUNT(sldns_buffer_begin(pkt)))))
1077 if(LDNS_ARCOUNT(sldns_buffer_begin(pkt)) > 1) {
1080 if(LDNS_ARCOUNT(sldns_buffer_begin(pkt)) == 0) {
1085 if(pkt_dname_len(pkt) != 1)
1087 if(sldns_buffer_remaining(pkt) < 10) /* type, class, ttl, rdatalen */
1089 if(sldns_buffer_read_u16(pkt) != LDNS_RR_TYPE_OPT)
1092 edns->udp_size = sldns_buffer_read_u16(pkt); /* class is udp size */
1093 edns->ext_rcode = sldns_buffer_read_u8(pkt); /* ttl used for bits */
1094 edns->edns_version = sldns_buffer_read_u8(pkt);
1095 edns->bits = sldns_buffer_read_u16(pkt);
1100 rdata_len = sldns_buffer_read_u16(pkt);
1101 if(sldns_buffer_remaining(pkt) < rdata_len)
1103 rdata_ptr = sldns_buffer_current(pkt);