Lines Matching +full:pkt +full:- +full:size
2 * util/data/msgparse.c - parse wireformat DNS messages.
58 smart_compare(sldns_buffer* pkt, uint8_t* dnow, in smart_compare() argument
65 >= sldns_buffer_limit(pkt)) in smart_compare()
66 return -1; in smart_compare()
67 p = sldns_buffer_at(pkt, PTR_OFFSET(dnow[0], dnow[1])); in smart_compare()
75 return dname_pkt_compare(pkt, dnow, dprlast); in smart_compare()
89 p->rrset_bucket_next = msg->hashtable[hash & (PARSE_TABLE_SIZE-1)]; in new_rrset()
90 msg->hashtable[hash & (PARSE_TABLE_SIZE-1)] = p; in new_rrset()
91 p->rrset_all_next = 0; in new_rrset()
92 if(msg->rrset_last) in new_rrset()
93 msg->rrset_last->rrset_all_next = p; in new_rrset()
94 else msg->rrset_first = p; in new_rrset()
95 msg->rrset_last = p; in new_rrset()
96 p->hash = hash; in new_rrset()
97 p->section = section; in new_rrset()
98 p->dname = dname; in new_rrset()
99 p->dname_len = dnamelen; in new_rrset()
100 p->type = type; in new_rrset()
101 p->rrset_class = dclass; in new_rrset()
102 p->flags = rrset_flags; in new_rrset()
103 p->rr_count = 0; in new_rrset()
104 p->size = 0; in new_rrset()
105 p->rr_first = 0; in new_rrset()
106 p->rr_last = 0; in new_rrset()
107 p->rrsig_count = 0; in new_rrset()
108 p->rrsig_first = 0; in new_rrset()
109 p->rrsig_last = 0; in new_rrset()
115 nsec_at_apex(sldns_buffer* pkt) in nsec_at_apex() argument
118 size_t pos = sldns_buffer_position(pkt); in nsec_at_apex()
120 if(sldns_buffer_remaining(pkt) < 7) /* ttl+len+root */ in nsec_at_apex()
122 sldns_buffer_skip(pkt, 4); /* ttl */; in nsec_at_apex()
123 rdatalen = sldns_buffer_read_u16(pkt); in nsec_at_apex()
124 if(sldns_buffer_remaining(pkt) < rdatalen) { in nsec_at_apex()
125 sldns_buffer_set_position(pkt, pos); in nsec_at_apex()
129 if(pkt_dname_len(pkt) == 0) { in nsec_at_apex()
130 sldns_buffer_set_position(pkt, pos); in nsec_at_apex()
135 if(sldns_buffer_position(pkt) < pos+4+rdatalen) { in nsec_at_apex()
139 if(sldns_buffer_position(pkt)+3 > pos+4+rdatalen) { in nsec_at_apex()
140 sldns_buffer_set_position(pkt, pos); in nsec_at_apex()
143 win = sldns_buffer_read_u8(pkt); in nsec_at_apex()
144 blen = sldns_buffer_read_u8(pkt); in nsec_at_apex()
145 bits = sldns_buffer_read_u8(pkt); in nsec_at_apex()
149 sldns_buffer_set_position(pkt, pos); in nsec_at_apex()
154 sldns_buffer_set_position(pkt, pos); in nsec_at_apex()
160 pkt_rrset_flags(sldns_buffer* pkt, uint16_t type, sldns_pkt_section sec) in pkt_rrset_flags() argument
163 if(type == LDNS_RR_TYPE_NSEC && nsec_at_apex(pkt)) { in pkt_rrset_flags()
172 pkt_hash_rrset(sldns_buffer* pkt, uint8_t* dname, uint16_t type, in pkt_hash_rrset() argument
178 h = dname_pkt_hash(pkt, dname, h); in pkt_hash_rrset()
187 pkt_hash_rrset_first(sldns_buffer* pkt, uint8_t* dname) in pkt_hash_rrset_first() argument
193 h = dname_pkt_hash(pkt, dname, h); in pkt_hash_rrset_first()
213 rrset_parse_equals(struct rrset_parse* p, sldns_buffer* pkt, hashvalue_type h, in rrset_parse_equals() argument
217 if(p->hash == h && p->dname_len == dnamelen && p->type == type && in rrset_parse_equals()
218 p->rrset_class == dclass && p->flags == rrset_flags && in rrset_parse_equals()
219 dname_pkt_compare(pkt, dname, p->dname) == 0) in rrset_parse_equals()
226 msgparse_hashtable_lookup(struct msg_parse* msg, sldns_buffer* pkt, in msgparse_hashtable_lookup() argument
230 struct rrset_parse* p = msg->hashtable[h & (PARSE_TABLE_SIZE-1)]; in msgparse_hashtable_lookup()
232 if(rrset_parse_equals(p, pkt, h, rrset_flags, dname, dnamelen, in msgparse_hashtable_lookup()
235 p = p->rrset_bucket_next; in msgparse_hashtable_lookup()
242 pkt_rrsig_covered(sldns_buffer* pkt, uint8_t* here, uint16_t* type) in pkt_rrsig_covered() argument
244 size_t pos = sldns_buffer_position(pkt); in pkt_rrsig_covered()
245 sldns_buffer_set_position(pkt, (size_t)(here-sldns_buffer_begin(pkt))); in pkt_rrsig_covered()
246 /* ttl + len + size of small rrsig(rootlabel, no signature) */ in pkt_rrsig_covered()
247 if(sldns_buffer_remaining(pkt) < 4+2+19) in pkt_rrsig_covered()
249 sldns_buffer_skip(pkt, 4); /* ttl */ in pkt_rrsig_covered()
250 if(sldns_buffer_read_u16(pkt) < 19) /* too short */ { in pkt_rrsig_covered()
251 sldns_buffer_set_position(pkt, pos); in pkt_rrsig_covered()
254 *type = sldns_buffer_read_u16(pkt); in pkt_rrsig_covered()
255 sldns_buffer_set_position(pkt, pos); in pkt_rrsig_covered()
261 pkt_rrsig_covered_equals(sldns_buffer* pkt, uint8_t* here, uint16_t type) in pkt_rrsig_covered_equals() argument
264 if(pkt_rrsig_covered(pkt, here, &t) && t == type) in pkt_rrsig_covered_equals()
273 p = &msg->hashtable[ rrset->hash & (PARSE_TABLE_SIZE-1) ]; in msgparse_bucket_remove()
276 *p = rrset->rrset_bucket_next; in msgparse_bucket_remove()
279 p = &( (*p)->rrset_bucket_next ); in msgparse_bucket_remove()
290 if(section == rrset->section) in change_section()
292 p = msg->rrset_first; in change_section()
296 if(prev) prev->rrset_all_next = p->rrset_all_next; in change_section()
297 else msg->rrset_first = p->rrset_all_next; in change_section()
298 if(msg->rrset_last == rrset) in change_section()
299 msg->rrset_last = prev; in change_section()
303 p = p->rrset_all_next; in change_section()
306 switch(rrset->section) { in change_section()
307 case LDNS_SECTION_ANSWER: msg->an_rrsets--; break; in change_section()
308 case LDNS_SECTION_AUTHORITY: msg->ns_rrsets--; break; in change_section()
309 case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets--; break; in change_section()
313 rrset->rrset_all_next = 0; in change_section()
314 if(msg->rrset_last) in change_section()
315 msg->rrset_last->rrset_all_next = rrset; in change_section()
316 else msg->rrset_first = rrset; in change_section()
317 msg->rrset_last = rrset; in change_section()
320 case LDNS_SECTION_AUTHORITY: msg->ns_rrsets++; break; in change_section()
321 case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets++; break; in change_section()
324 rrset->section = section; in change_section()
329 rrset_has_sigover(sldns_buffer* pkt, struct rrset_parse* rrset, uint16_t type, in rrset_has_sigover() argument
333 struct rr_parse* rr = rrset->rr_first; in rrset_has_sigover()
334 log_assert( rrset->type == LDNS_RR_TYPE_RRSIG ); in rrset_has_sigover()
336 if(pkt_rrsig_covered_equals(pkt, rr->ttl_data, type)) in rrset_has_sigover()
339 rr = rr->next; in rrset_has_sigover()
346 moveover_rrsigs(sldns_buffer* pkt, struct regional* region, in moveover_rrsigs() argument
349 struct rr_parse* sig = sigset->rr_first; in moveover_rrsigs()
354 nextsig = sig->next; in moveover_rrsigs()
355 if(pkt_rrsig_covered_equals(pkt, sig->ttl_data, in moveover_rrsigs()
356 dataset->type)) { in moveover_rrsigs()
362 insert->outside_packet = 0; in moveover_rrsigs()
363 insert->ttl_data = sig->ttl_data; in moveover_rrsigs()
364 insert->size = sig->size; in moveover_rrsigs()
368 if(prev) prev->next = sig->next; in moveover_rrsigs()
369 else sigset->rr_first = sig->next; in moveover_rrsigs()
370 if(sigset->rr_last == sig) in moveover_rrsigs()
371 sigset->rr_last = prev; in moveover_rrsigs()
372 sigset->rr_count--; in moveover_rrsigs()
373 sigset->size -= sig->size; in moveover_rrsigs()
378 dataset->rrsig_count++; in moveover_rrsigs()
379 insert->next = 0; in moveover_rrsigs()
380 if(dataset->rrsig_last) in moveover_rrsigs()
381 dataset->rrsig_last->next = insert; in moveover_rrsigs()
382 else dataset->rrsig_first = insert; in moveover_rrsigs()
383 dataset->rrsig_last = insert; in moveover_rrsigs()
384 dataset->size += insert->size; in moveover_rrsigs()
396 sldns_buffer* pkt, uint16_t datatype, uint32_t rrset_flags, in change_rrsig_rrset() argument
400 hashvalue_type hash = pkt_hash_rrset(pkt, sigset->dname, datatype, in change_rrsig_rrset()
401 sigset->rrset_class, rrset_flags); in change_rrsig_rrset()
402 log_assert( sigset->type == LDNS_RR_TYPE_RRSIG ); in change_rrsig_rrset()
406 dataset = new_rrset(msg, sigset->dname, sigset->dname_len, in change_rrsig_rrset()
407 datatype, sigset->rrset_class, hash, rrset_flags, in change_rrsig_rrset()
412 case LDNS_SECTION_ANSWER: msg->an_rrsets++; break; in change_rrsig_rrset()
413 case LDNS_SECTION_AUTHORITY: msg->ns_rrsets++; break; in change_rrsig_rrset()
414 case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets++; break; in change_rrsig_rrset()
417 if(!moveover_rrsigs(pkt, region, sigset, dataset, in change_rrsig_rrset()
418 msg->qtype == LDNS_RR_TYPE_RRSIG || in change_rrsig_rrset()
419 (msg->qtype == LDNS_RR_TYPE_ANY && in change_rrsig_rrset()
427 dataset->rrset_bucket_next = msg->hashtable[hash&(PARSE_TABLE_SIZE-1)]; in change_rrsig_rrset()
428 msg->hashtable[hash&(PARSE_TABLE_SIZE-1)] = dataset; in change_rrsig_rrset()
429 dataset->hash = hash; in change_rrsig_rrset()
432 dataset->type = datatype; in change_rrsig_rrset()
433 dataset->flags = rrset_flags; in change_rrsig_rrset()
434 dataset->rrsig_count += dataset->rr_count; in change_rrsig_rrset()
435 dataset->rr_count = 0; in change_rrsig_rrset()
437 if(dataset->rrsig_last) in change_rrsig_rrset()
438 dataset->rrsig_last->next = dataset->rr_first; in change_rrsig_rrset()
439 else dataset->rrsig_first = dataset->rr_first; in change_rrsig_rrset()
440 dataset->rrsig_last = dataset->rr_last; in change_rrsig_rrset()
441 dataset->rr_first = 0; in change_rrsig_rrset()
442 dataset->rr_last = 0; in change_rrsig_rrset()
448 * @param pkt: the packet in wireformat (needed for compression ptrs).
466 find_rrset(struct msg_parse* msg, sldns_buffer* pkt, uint8_t* dname, in find_rrset() argument
474 hashvalue_type dname_h = pkt_hash_rrset_first(pkt, dname); in find_rrset()
480 smart_compare(pkt, dname, *prev_dname_first, in find_rrset()
489 pkt_rrsig_covered_equals(pkt, sldns_buffer_current(pkt), in find_rrset()
491 smart_compare(pkt, dname, *prev_dname_first, in find_rrset()
499 *rrset_flags = pkt_rrset_flags(pkt, type, section); in find_rrset()
501 /* if rrsig - try to lookup matching data set first */ in find_rrset()
502 if(type == LDNS_RR_TYPE_RRSIG && pkt_rrsig_covered(pkt, in find_rrset()
503 sldns_buffer_current(pkt), &covtype)) { in find_rrset()
506 *rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, in find_rrset()
513 *rrset_prev = msgparse_hashtable_lookup(msg, pkt, in find_rrset()
524 *rrset_prev = msgparse_hashtable_lookup(msg, pkt, in find_rrset()
531 *prev_dname_first = (*rrset_prev)->dname; in find_rrset()
544 *rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, in find_rrset()
547 if(*rrset_prev && rrset_has_sigover(pkt, *rrset_prev, type, in find_rrset()
550 *prev_dname_first = (*rrset_prev)->dname; in find_rrset()
556 pkt, type, *rrset_flags, hasother, section, in find_rrset()
564 *rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, *rrset_flags, in find_rrset()
567 *prev_dname_first = (*rrset_prev)->dname; in find_rrset()
578 * @param pkt: packet, position at call must be at start of query section.
584 parse_query_section(sldns_buffer* pkt, struct msg_parse* msg) in parse_query_section() argument
586 if(msg->qdcount == 0) in parse_query_section()
588 if(msg->qdcount > 1) in parse_query_section()
590 log_assert(msg->qdcount == 1); in parse_query_section()
591 if(sldns_buffer_remaining(pkt) <= 0) in parse_query_section()
593 msg->qname = sldns_buffer_current(pkt); in parse_query_section()
594 if((msg->qname_len = pkt_dname_len(pkt)) == 0) in parse_query_section()
596 if(sldns_buffer_remaining(pkt) < sizeof(uint16_t)*2) in parse_query_section()
598 msg->qtype = sldns_buffer_read_u16(pkt); in parse_query_section()
599 msg->qclass = sldns_buffer_read_u16(pkt); in parse_query_section()
637 /** calculate the size of one rr */
639 calc_size(sldns_buffer* pkt, uint16_t type, struct rr_parse* rr) in calc_size() argument
643 rr->size = sizeof(uint16_t); /* the rdatalen */ in calc_size()
644 sldns_buffer_skip(pkt, 4); /* skip ttl */ in calc_size()
645 pkt_len = sldns_buffer_read_u16(pkt); in calc_size()
646 if(sldns_buffer_remaining(pkt) < pkt_len) in calc_size()
649 if(pkt_len > 0 && desc && desc->_dname_count > 0) { in calc_size()
650 int count = (int)desc->_dname_count; in calc_size()
656 switch(desc->_wireformat[rdf]) { in calc_size()
659 oldpos = sldns_buffer_position(pkt); in calc_size()
660 if((len = pkt_dname_len(pkt)) == 0) in calc_size()
662 if(sldns_buffer_position(pkt)-oldpos > pkt_len) in calc_size()
664 pkt_len -= sldns_buffer_position(pkt)-oldpos; in calc_size()
665 rr->size += len; in calc_size()
666 count--; in calc_size()
674 len = sldns_buffer_current(pkt)[0] + 1; in calc_size()
677 len = get_rdf_size(desc->_wireformat[rdf]); in calc_size()
682 pkt_len -= len; in calc_size()
683 sldns_buffer_skip(pkt, (ssize_t)len); in calc_size()
684 rr->size += len; in calc_size()
690 rr->size += pkt_len; in calc_size()
691 sldns_buffer_skip(pkt, (ssize_t)pkt_len); in calc_size()
697 skip_ttl_rdata(sldns_buffer* pkt) in skip_ttl_rdata() argument
700 if(sldns_buffer_remaining(pkt) < 6) /* ttl + rdatalen */ in skip_ttl_rdata()
702 sldns_buffer_skip(pkt, 4); /* ttl */ in skip_ttl_rdata()
703 rdatalen = sldns_buffer_read_u16(pkt); in skip_ttl_rdata()
704 if(sldns_buffer_remaining(pkt) < rdatalen) in skip_ttl_rdata()
706 sldns_buffer_skip(pkt, (ssize_t)rdatalen); in skip_ttl_rdata()
712 sig_is_double(sldns_buffer* pkt, struct rrset_parse* rrset, uint8_t* ttldata) in sig_is_double() argument
715 size_t pos = sldns_buffer_position(pkt); in sig_is_double()
717 if(sldns_buffer_remaining(pkt) < 6) in sig_is_double()
719 sldns_buffer_skip(pkt, 4); /* ttl */ in sig_is_double()
720 rlen = sldns_buffer_read_u16(pkt); in sig_is_double()
721 if(sldns_buffer_remaining(pkt) < rlen) { in sig_is_double()
722 sldns_buffer_set_position(pkt, pos); in sig_is_double()
725 sldns_buffer_set_position(pkt, pos); in sig_is_double()
727 sig = rrset->rrsig_first; in sig_is_double()
730 memmove(&siglen, sig->ttl_data+4, sizeof(siglen)); in sig_is_double()
737 * Cannot use sig->size because size of the other one is not in sig_is_double()
741 if(siglen>0 && memcmp(sig->ttl_data+6, ttldata+6, in sig_is_double()
747 sig = sig->next; in sig_is_double()
754 add_rr_to_rrset(struct rrset_parse* rrset, sldns_buffer* pkt, in add_rr_to_rrset() argument
760 if(rrset->section != section && type != LDNS_RR_TYPE_RRSIG && in add_rr_to_rrset()
761 rrset->type != LDNS_RR_TYPE_RRSIG) { in add_rr_to_rrset()
762 /* silently drop it - we drop the last part, since in add_rr_to_rrset()
770 log_buf(VERB_QUERY, "packet was", pkt); in add_rr_to_rrset()
773 if(!skip_ttl_rdata(pkt)) in add_rr_to_rrset()
778 if( (msg->qtype == LDNS_RR_TYPE_RRSIG || in add_rr_to_rrset()
779 msg->qtype == LDNS_RR_TYPE_ANY) in add_rr_to_rrset()
780 && sig_is_double(pkt, rrset, sldns_buffer_current(pkt))) { in add_rr_to_rrset()
781 if(!skip_ttl_rdata(pkt)) in add_rr_to_rrset()
789 rr->outside_packet = 0; in add_rr_to_rrset()
790 rr->ttl_data = sldns_buffer_current(pkt); in add_rr_to_rrset()
791 rr->next = 0; in add_rr_to_rrset()
792 if(type == LDNS_RR_TYPE_RRSIG && rrset->type != LDNS_RR_TYPE_RRSIG) { in add_rr_to_rrset()
793 if(rrset->rrsig_last) in add_rr_to_rrset()
794 rrset->rrsig_last->next = rr; in add_rr_to_rrset()
795 else rrset->rrsig_first = rr; in add_rr_to_rrset()
796 rrset->rrsig_last = rr; in add_rr_to_rrset()
797 rrset->rrsig_count++; in add_rr_to_rrset()
799 if(rrset->rr_last) in add_rr_to_rrset()
800 rrset->rr_last->next = rr; in add_rr_to_rrset()
801 else rrset->rr_first = rr; in add_rr_to_rrset()
802 rrset->rr_last = rr; in add_rr_to_rrset()
803 rrset->rr_count++; in add_rr_to_rrset()
806 /* calc decompressed size */ in add_rr_to_rrset()
807 if(!calc_size(pkt, type, rr)) in add_rr_to_rrset()
809 rrset->size += rr->size; in add_rr_to_rrset()
816 * @param pkt: packet, position at call must be at start of section.
826 parse_section(sldns_buffer* pkt, struct msg_parse* msg, in parse_section() argument
842 if(sldns_buffer_remaining(pkt) <= 0) in parse_section()
846 dname = sldns_buffer_current(pkt); in parse_section()
847 if((dnamelen = pkt_dname_len(pkt)) == 0) in parse_section()
849 if(sldns_buffer_remaining(pkt) < 10) /* type, class, ttl, len */ in parse_section()
851 type = sldns_buffer_read_u16(pkt); in parse_section()
852 sldns_buffer_read(pkt, &dclass, sizeof(dclass)); in parse_section()
857 if(pkt_rrsig_covered(pkt, in parse_section()
858 sldns_buffer_current(pkt), &t)) in parse_section()
861 sldns_rr_descript(type)->_name: "??", in parse_section()
864 sldns_rr_descript(t)->_name: "??", in parse_section()
869 sldns_rr_descript(type)->_name: "??", in parse_section()
874 sldns_rr_classes, (int)ntohs(dclass))->name: in parse_section()
876 dname_print(stderr, pkt, dname); in parse_section()
881 if(!find_rrset(msg, pkt, dname, dnamelen, type, dclass, &hash, in parse_section()
896 dname_print(stderr, pkt, rrset->dname); in parse_section()
898 sldns_rr_descript(rrset->type)? in parse_section()
899 sldns_rr_descript(rrset->type)->_name: "??", in parse_section()
900 (int)rrset->type); in parse_section()
903 if((r=add_rr_to_rrset(rrset, pkt, msg, region, section, in parse_section()
911 parse_packet(sldns_buffer* pkt, struct msg_parse* msg, struct regional* region) in parse_packet() argument
914 if(sldns_buffer_remaining(pkt) < LDNS_HEADER_SIZE) in parse_packet()
917 sldns_buffer_read(pkt, &msg->id, sizeof(uint16_t)); in parse_packet()
918 msg->flags = sldns_buffer_read_u16(pkt); in parse_packet()
919 msg->qdcount = sldns_buffer_read_u16(pkt); in parse_packet()
920 msg->ancount = sldns_buffer_read_u16(pkt); in parse_packet()
921 msg->nscount = sldns_buffer_read_u16(pkt); in parse_packet()
922 msg->arcount = sldns_buffer_read_u16(pkt); in parse_packet()
923 if(msg->qdcount > 1) in parse_packet()
925 if((ret = parse_query_section(pkt, msg)) != 0) in parse_packet()
927 if((ret = parse_section(pkt, msg, region, LDNS_SECTION_ANSWER, in parse_packet()
928 msg->ancount, &msg->an_rrsets)) != 0) in parse_packet()
930 if((ret = parse_section(pkt, msg, region, LDNS_SECTION_AUTHORITY, in parse_packet()
931 msg->nscount, &msg->ns_rrsets)) != 0) in parse_packet()
933 if(sldns_buffer_remaining(pkt) == 0 && msg->arcount == 1) { in parse_packet()
936 } else if((ret = parse_section(pkt, msg, region, in parse_packet()
937 LDNS_SECTION_ADDITIONAL, msg->arcount, &msg->ar_rrsets)) != 0) in parse_packet()
939 /* if(sldns_buffer_remaining(pkt) > 0) { */ in parse_packet()
942 msg->rrset_count = msg->an_rrsets + msg->ns_rrsets + msg->ar_rrsets; in parse_packet()
958 * In the if-statement below, the option is added unsolicited. This in parse_edns_options_from_query()
960 * here this is true, because c->tcp_keepalive is set. in parse_edns_options_from_query()
962 if (cfg && cfg->do_tcp_keepalive && c && c->type != comm_udp && c->tcp_keepalive) { in parse_edns_options_from_query()
963 if(!edns_opt_list_append_keepalive(&edns->opt_list_out, in parse_edns_options_from_query()
964 c->tcp_timeout_msec / 100, region)) { in parse_edns_options_from_query()
980 rdata_len -= 4; in parse_edns_options_from_query()
987 if (!cfg || !cfg->nsid) in parse_edns_options_from_query()
989 if(!edns_opt_list_append(&edns->opt_list_out, in parse_edns_options_from_query()
990 LDNS_EDNS_NSID, cfg->nsid_len, in parse_edns_options_from_query()
991 cfg->nsid, region)) { in parse_edns_options_from_query()
1005 * option, so c->tcp_keepalive is not set. in parse_edns_options_from_query()
1007 * c->tcp_keepalive will be set so that the in parse_edns_options_from_query()
1009 * responses (see the comment above the if-statement in parse_edns_options_from_query()
1012 if (!cfg || !cfg->do_tcp_keepalive || !c || in parse_edns_options_from_query()
1013 c->type == comm_udp || c->tcp_keepalive) in parse_edns_options_from_query()
1019 if(!edns_opt_list_append_keepalive(&edns->opt_list_out, in parse_edns_options_from_query()
1020 c->tcp_timeout_msec / 100, in parse_edns_options_from_query()
1025 c->tcp_keepalive = 1; in parse_edns_options_from_query()
1029 if(!cfg || !cfg->pad_responses || in parse_edns_options_from_query()
1030 !c || c->type != comm_tcp ||!c->ssl) in parse_edns_options_from_query()
1032 if(!edns_opt_list_append(&edns->opt_list_out, in parse_edns_options_from_query()
1038 edns->padding_block_size = cfg->pad_responses_block_size; in parse_edns_options_from_query()
1042 if(!cfg || !cfg->do_answer_cookie || !repinfo) in parse_edns_options_from_query()
1049 edns->cookie_present = 1; in parse_edns_options_from_query()
1065 if(repinfo->remote_addr.ss_family == AF_INET) { in parse_edns_options_from_query()
1067 &((struct sockaddr_in*)&repinfo->remote_addr)->sin_addr, 4); in parse_edns_options_from_query()
1071 &((struct sockaddr_in6*)&repinfo->remote_addr)->sin6_addr, 16); in parse_edns_options_from_query()
1074 if(cfg->cookie_secret_file && in parse_edns_options_from_query()
1075 cfg->cookie_secret_file[0]) { in parse_edns_options_from_query()
1084 rdata_ptr, opt_len, cfg->cookie_secret, in parse_edns_options_from_query()
1085 cfg->cookie_secret_len, cookie_is_v4, in parse_edns_options_from_query()
1089 edns->cookie_valid = 1; in parse_edns_options_from_query()
1092 edns->cookie_valid = 1; in parse_edns_options_from_query()
1095 &edns->opt_list_out, LDNS_EDNS_COOKIE, in parse_edns_options_from_query()
1105 edns->cookie_client = 1; in parse_edns_options_from_query()
1113 if(cfg->cookie_secret_file && in parse_edns_options_from_query()
1114 cfg->cookie_secret_file[0]) { in parse_edns_options_from_query()
1117 lock_basic_lock(&cookie_secrets->lock); in parse_edns_options_from_query()
1118 if(cookie_secrets->cookie_count < 1) { in parse_edns_options_from_query()
1119 lock_basic_unlock(&cookie_secrets->lock); in parse_edns_options_from_query()
1123 cookie_secrets->cookie_secrets[0].cookie_secret, in parse_edns_options_from_query()
1125 lock_basic_unlock(&cookie_secrets->lock); in parse_edns_options_from_query()
1128 cfg->cookie_secret, cookie_is_v4, now); in parse_edns_options_from_query()
1130 if(!edns_opt_list_append(&edns->opt_list_out, in parse_edns_options_from_query()
1142 if(!edns_opt_list_append(&edns->opt_list_in, in parse_edns_options_from_query()
1148 rdata_len -= opt_len; in parse_edns_options_from_query()
1157 struct rrset_parse* rrset = msg->rrset_first; in parse_extract_edns_from_response_msg()
1163 /* since the class encodes the UDP size, we cannot use hash table to in parse_extract_edns_from_response_msg()
1166 if(rrset->type == LDNS_RR_TYPE_OPT) { in parse_extract_edns_from_response_msg()
1174 rrset = rrset->rrset_all_next; in parse_extract_edns_from_response_msg()
1178 edns->udp_size = 512; in parse_extract_edns_from_response_msg()
1183 if(found->section != LDNS_SECTION_ADDITIONAL) in parse_extract_edns_from_response_msg()
1185 if(found->rr_count == 0) in parse_extract_edns_from_response_msg()
1188 if(found->dname_len != 1 || !found->dname in parse_extract_edns_from_response_msg()
1189 || found->dname[0] != 0) return LDNS_RCODE_FORMERR; in parse_extract_edns_from_response_msg()
1190 if(found->rr_count != 1) return LDNS_RCODE_FORMERR; in parse_extract_edns_from_response_msg()
1192 log_assert(found->rr_first && found->rr_last); in parse_extract_edns_from_response_msg()
1195 if(found_prev) found_prev->rrset_all_next = found->rrset_all_next; in parse_extract_edns_from_response_msg()
1196 else msg->rrset_first = found->rrset_all_next; in parse_extract_edns_from_response_msg()
1197 if(found == msg->rrset_last) in parse_extract_edns_from_response_msg()
1198 msg->rrset_last = found_prev; in parse_extract_edns_from_response_msg()
1199 msg->arcount --; in parse_extract_edns_from_response_msg()
1200 msg->ar_rrsets --; in parse_extract_edns_from_response_msg()
1201 msg->rrset_count --; in parse_extract_edns_from_response_msg()
1204 edns->edns_present = 1; in parse_extract_edns_from_response_msg()
1205 edns->ext_rcode = found->rr_last->ttl_data[0]; in parse_extract_edns_from_response_msg()
1206 edns->edns_version = found->rr_last->ttl_data[1]; in parse_extract_edns_from_response_msg()
1207 edns->bits = sldns_read_uint16(&found->rr_last->ttl_data[2]); in parse_extract_edns_from_response_msg()
1208 edns->udp_size = ntohs(found->rrset_class); in parse_extract_edns_from_response_msg()
1209 edns->opt_list_in = NULL; in parse_extract_edns_from_response_msg()
1210 edns->opt_list_out = NULL; in parse_extract_edns_from_response_msg()
1211 edns->opt_list_inplace_cb_out = NULL; in parse_extract_edns_from_response_msg()
1212 edns->padding_block_size = 0; in parse_extract_edns_from_response_msg()
1213 edns->cookie_present = 0; in parse_extract_edns_from_response_msg()
1214 edns->cookie_valid = 0; in parse_extract_edns_from_response_msg()
1217 rdata_len = found->rr_first->size-2; in parse_extract_edns_from_response_msg()
1218 rdata_ptr = found->rr_first->ttl_data+6; in parse_extract_edns_from_response_msg()
1226 rdata_len -= 4; in parse_extract_edns_from_response_msg()
1230 if(!edns_opt_list_append(&edns->opt_list_in, in parse_extract_edns_from_response_msg()
1236 rdata_len -= opt_len; in parse_extract_edns_from_response_msg()
1244 skip_pkt_rr(sldns_buffer* pkt) in skip_pkt_rr() argument
1246 if(sldns_buffer_remaining(pkt) < 1) return 0; in skip_pkt_rr()
1247 if(!pkt_dname_len(pkt)) in skip_pkt_rr()
1249 if(sldns_buffer_remaining(pkt) < 4) return 0; in skip_pkt_rr()
1250 sldns_buffer_skip(pkt, 4); /* type and class */ in skip_pkt_rr()
1251 if(!skip_ttl_rdata(pkt)) in skip_pkt_rr()
1258 skip_pkt_rrs(sldns_buffer* pkt, int num) in skip_pkt_rrs() argument
1262 if(!skip_pkt_rr(pkt)) in skip_pkt_rrs()
1269 parse_edns_from_query_pkt(sldns_buffer* pkt, struct edns_data* edns, in parse_edns_from_query_pkt() argument
1276 log_assert(LDNS_QDCOUNT(sldns_buffer_begin(pkt)) == 1); in parse_edns_from_query_pkt()
1278 if(LDNS_ANCOUNT(sldns_buffer_begin(pkt)) != 0 || in parse_edns_from_query_pkt()
1279 LDNS_NSCOUNT(sldns_buffer_begin(pkt)) != 0) { in parse_edns_from_query_pkt()
1280 if(!skip_pkt_rrs(pkt, ((int)LDNS_ANCOUNT(sldns_buffer_begin(pkt)))+ in parse_edns_from_query_pkt()
1281 ((int)LDNS_NSCOUNT(sldns_buffer_begin(pkt))))) in parse_edns_from_query_pkt()
1285 if(LDNS_ARCOUNT(sldns_buffer_begin(pkt)) > 1) { in parse_edns_from_query_pkt()
1288 if(LDNS_ARCOUNT(sldns_buffer_begin(pkt)) == 0) { in parse_edns_from_query_pkt()
1289 edns->udp_size = 512; in parse_edns_from_query_pkt()
1293 if(pkt_dname_len(pkt) != 1) in parse_edns_from_query_pkt()
1295 if(sldns_buffer_remaining(pkt) < 10) /* type, class, ttl, rdatalen */ in parse_edns_from_query_pkt()
1297 if(sldns_buffer_read_u16(pkt) != LDNS_RR_TYPE_OPT) in parse_edns_from_query_pkt()
1299 edns->edns_present = 1; in parse_edns_from_query_pkt()
1300 edns->udp_size = sldns_buffer_read_u16(pkt); /* class is udp size */ in parse_edns_from_query_pkt()
1301 edns->ext_rcode = sldns_buffer_read_u8(pkt); /* ttl used for bits */ in parse_edns_from_query_pkt()
1302 edns->edns_version = sldns_buffer_read_u8(pkt); in parse_edns_from_query_pkt()
1303 edns->bits = sldns_buffer_read_u16(pkt); in parse_edns_from_query_pkt()
1304 edns->opt_list_in = NULL; in parse_edns_from_query_pkt()
1305 edns->opt_list_out = NULL; in parse_edns_from_query_pkt()
1306 edns->opt_list_inplace_cb_out = NULL; in parse_edns_from_query_pkt()
1307 edns->padding_block_size = 0; in parse_edns_from_query_pkt()
1308 edns->cookie_present = 0; in parse_edns_from_query_pkt()
1309 edns->cookie_valid = 0; in parse_edns_from_query_pkt()
1312 rdata_len = sldns_buffer_read_u16(pkt); in parse_edns_from_query_pkt()
1313 if(sldns_buffer_remaining(pkt) < rdata_len) in parse_edns_from_query_pkt()
1315 rdata_ptr = sldns_buffer_current(pkt); in parse_edns_from_query_pkt()
1332 (void)sldns_wire2str_edns_option_print(&s, &slen, list->opt_code, in log_edns_opt_list()
1333 list->opt_data, list->opt_len); in log_edns_opt_list()
1335 list = list->next; in log_edns_opt_list()
1342 msgparse_rrset_remove_rr(const char* str, sldns_buffer* pkt, struct rrset_parse* rrset, in msgparse_rrset_remove_rr() argument
1345 if(verbosity >= VERB_QUERY && rrset->dname_len <= LDNS_MAX_DOMAINLEN && str) { in msgparse_rrset_remove_rr()
1347 dname_pkt_copy(pkt, buf, rrset->dname); in msgparse_rrset_remove_rr()
1351 rrset->type, ntohs(rrset->rrset_class)); in msgparse_rrset_remove_rr()
1354 prev->next = rr->next; in msgparse_rrset_remove_rr()
1355 else rrset->rr_first = rr->next; in msgparse_rrset_remove_rr()
1356 if(rrset->rr_last == rr) in msgparse_rrset_remove_rr()
1357 rrset->rr_last = prev; in msgparse_rrset_remove_rr()
1358 rrset->rr_count --; in msgparse_rrset_remove_rr()
1359 rrset->size -= rr->size; in msgparse_rrset_remove_rr()
1361 * the rr->next works fine to continue. */ in msgparse_rrset_remove_rr()
1362 return rrset->rr_count == 0; in msgparse_rrset_remove_rr()