Lines Matching refs:p

32 #define REWINDER_INIT(p) {                              \  argument
33 .packet = (p), \
34 .saved_rindex = (p)->rindex, \
44 DnsPacket *p; in dns_packet_new() local
77 p = malloc0(ALIGN(sizeof(DnsPacket)) + a); in dns_packet_new()
78 if (!p) in dns_packet_new()
81 *p = (DnsPacket) { in dns_packet_new()
92 *ret = p; in dns_packet_new()
97 void dns_packet_set_flags(DnsPacket *p, bool dnssec_checking_disabled, bool truncated) { in dns_packet_set_flags() argument
101 assert(p); in dns_packet_set_flags()
103 h = DNS_PACKET_HEADER(p); in dns_packet_set_flags()
105 switch (p->protocol) { in dns_packet_set_flags()
148 DnsPacket *p; in dns_packet_new_query() local
153 r = dns_packet_new(&p, protocol, min_alloc_dsize, DNS_PACKET_SIZE_MAX); in dns_packet_new_query()
160 dns_packet_set_flags(p, dnssec_checking_disabled, false); in dns_packet_new_query()
162 *ret = p; in dns_packet_new_query()
166 int dns_packet_dup(DnsPacket **ret, DnsPacket *p) { in dns_packet_dup() argument
171 assert(p); in dns_packet_dup()
173 r = dns_packet_validate(p); in dns_packet_dup()
177 c = malloc(ALIGN(sizeof(DnsPacket)) + p->size); in dns_packet_dup()
183 .protocol = p->protocol, in dns_packet_dup()
184 .size = p->size, in dns_packet_dup()
186 .allocated = p->size, in dns_packet_dup()
187 .max_size = p->max_size, in dns_packet_dup()
192 memcpy(DNS_PACKET_DATA(c), DNS_PACKET_DATA(p), p->size); in dns_packet_dup()
198 DnsPacket *dns_packet_ref(DnsPacket *p) { in dns_packet_ref() argument
200 if (!p) in dns_packet_ref()
203 assert(!p->on_stack); in dns_packet_ref()
205 assert(p->n_ref > 0); in dns_packet_ref()
206 p->n_ref++; in dns_packet_ref()
207 return p; in dns_packet_ref()
210 static void dns_packet_free(DnsPacket *p) { in dns_packet_free() argument
213 assert(p); in dns_packet_free()
215 dns_question_unref(p->question); in dns_packet_free()
216 dns_answer_unref(p->answer); in dns_packet_free()
217 dns_resource_record_unref(p->opt); in dns_packet_free()
219 while ((s = hashmap_steal_first_key(p->names))) in dns_packet_free()
221 hashmap_free(p->names); in dns_packet_free()
223 free(p->_data); in dns_packet_free()
225 if (!p->on_stack) in dns_packet_free()
226 free(p); in dns_packet_free()
229 DnsPacket *dns_packet_unref(DnsPacket *p) { in dns_packet_unref() argument
230 if (!p) in dns_packet_unref()
233 assert(p->n_ref > 0); in dns_packet_unref()
235 dns_packet_unref(p->more); in dns_packet_unref()
237 if (p->n_ref == 1) in dns_packet_unref()
238 dns_packet_free(p); in dns_packet_unref()
240 p->n_ref--; in dns_packet_unref()
245 int dns_packet_validate(DnsPacket *p) { in dns_packet_validate() argument
246 assert(p); in dns_packet_validate()
248 if (p->size < DNS_PACKET_HEADER_SIZE) in dns_packet_validate()
251 if (p->size > DNS_PACKET_SIZE_MAX) in dns_packet_validate()
257 int dns_packet_validate_reply(DnsPacket *p) { in dns_packet_validate_reply() argument
260 assert(p); in dns_packet_validate_reply()
262 r = dns_packet_validate(p); in dns_packet_validate_reply()
266 if (DNS_PACKET_QR(p) != 1) in dns_packet_validate_reply()
269 if (DNS_PACKET_OPCODE(p) != 0) in dns_packet_validate_reply()
272 switch (p->protocol) { in dns_packet_validate_reply()
276 if (DNS_PACKET_QDCOUNT(p) != 1) in dns_packet_validate_reply()
283 if (DNS_PACKET_RCODE(p) != 0) in dns_packet_validate_reply()
295 int dns_packet_validate_query(DnsPacket *p) { in dns_packet_validate_query() argument
298 assert(p); in dns_packet_validate_query()
300 r = dns_packet_validate(p); in dns_packet_validate_query()
304 if (DNS_PACKET_QR(p) != 0) in dns_packet_validate_query()
307 if (DNS_PACKET_OPCODE(p) != 0) in dns_packet_validate_query()
310 if (DNS_PACKET_TC(p)) in dns_packet_validate_query()
313 switch (p->protocol) { in dns_packet_validate_query()
318 if (DNS_PACKET_QDCOUNT(p) != 1) in dns_packet_validate_query()
322 if (DNS_PACKET_ANCOUNT(p) > 0) in dns_packet_validate_query()
326 if (DNS_PACKET_NSCOUNT(p) > 0) in dns_packet_validate_query()
335 if (DNS_PACKET_RCODE(p) != 0) in dns_packet_validate_query()
347 static int dns_packet_extend(DnsPacket *p, size_t add, void **ret, size_t *start) { in dns_packet_extend() argument
348 assert(p); in dns_packet_extend()
350 if (p->size + add > p->allocated) { in dns_packet_extend()
353 a = PAGE_ALIGN((p->size + add) * 2); in dns_packet_extend()
355 ms = dns_packet_size_max(p); in dns_packet_extend()
359 if (p->size + add > a) in dns_packet_extend()
362 if (p->_data) { in dns_packet_extend()
365 d = realloc(p->_data, a); in dns_packet_extend()
369 p->_data = d; in dns_packet_extend()
371 p->_data = malloc(a); in dns_packet_extend()
372 if (!p->_data) in dns_packet_extend()
375 memcpy(p->_data, (uint8_t*) p + ALIGN(sizeof(DnsPacket)), p->size); in dns_packet_extend()
376 memzero((uint8_t*) p->_data + p->size, a - p->size); in dns_packet_extend()
379 p->allocated = a; in dns_packet_extend()
383 *start = p->size; in dns_packet_extend()
386 *ret = (uint8_t*) DNS_PACKET_DATA(p) + p->size; in dns_packet_extend()
388 p->size += add; in dns_packet_extend()
392 void dns_packet_truncate(DnsPacket *p, size_t sz) { in dns_packet_truncate() argument
396 assert(p); in dns_packet_truncate()
398 if (p->size <= sz) in dns_packet_truncate()
401 HASHMAP_FOREACH_KEY(n, s, p->names) { in dns_packet_truncate()
406 hashmap_remove(p->names, s); in dns_packet_truncate()
410 p->size = sz; in dns_packet_truncate()
413 int dns_packet_append_blob(DnsPacket *p, const void *d, size_t l, size_t *start) { in dns_packet_append_blob() argument
417 assert(p); in dns_packet_append_blob()
419 r = dns_packet_extend(p, l, &q, start); in dns_packet_append_blob()
427 int dns_packet_append_uint8(DnsPacket *p, uint8_t v, size_t *start) { in dns_packet_append_uint8() argument
431 assert(p); in dns_packet_append_uint8()
433 r = dns_packet_extend(p, sizeof(uint8_t), &d, start); in dns_packet_append_uint8()
442 int dns_packet_append_uint16(DnsPacket *p, uint16_t v, size_t *start) { in dns_packet_append_uint16() argument
446 assert(p); in dns_packet_append_uint16()
448 r = dns_packet_extend(p, sizeof(uint16_t), &d, start); in dns_packet_append_uint16()
457 int dns_packet_append_uint32(DnsPacket *p, uint32_t v, size_t *start) { in dns_packet_append_uint32() argument
461 assert(p); in dns_packet_append_uint32()
463 r = dns_packet_extend(p, sizeof(uint32_t), &d, start); in dns_packet_append_uint32()
472 int dns_packet_append_string(DnsPacket *p, const char *s, size_t *start) { in dns_packet_append_string() argument
473 assert(p); in dns_packet_append_string()
476 return dns_packet_append_raw_string(p, s, strlen(s), start); in dns_packet_append_string()
479 int dns_packet_append_raw_string(DnsPacket *p, const void *s, size_t size, size_t *start) { in dns_packet_append_raw_string() argument
483 assert(p); in dns_packet_append_raw_string()
489 r = dns_packet_extend(p, 1 + size, &d, start); in dns_packet_append_raw_string()
500 int dns_packet_append_label(DnsPacket *p, const char *d, size_t l, bool canonical_candidate, size_t… in dns_packet_append_label() argument
509 assert(p); in dns_packet_append_label()
515 r = dns_packet_extend(p, 1 + l, (void**) &w, start); in dns_packet_append_label()
521 if (p->canonical_form && canonical_candidate) in dns_packet_append_label()
536 DnsPacket *p, in dns_packet_append_name() argument
545 assert(p); in dns_packet_append_name()
548 if (p->refuse_compression) in dns_packet_append_name()
551 saved_size = p->size; in dns_packet_append_name()
559 n = PTR_TO_SIZE(hashmap_get(p->names, name)); in dns_packet_append_name()
561 assert(n < p->size); in dns_packet_append_name()
564 r = dns_packet_append_uint16(p, 0xC000 | n, NULL); in dns_packet_append_name()
576 r = dns_packet_append_label(p, label, r, canonical_candidate, &n); in dns_packet_append_name()
589 r = hashmap_ensure_put(&p->names, &dns_name_hash_ops, s, SIZE_TO_PTR(n)); in dns_packet_append_name()
597 r = dns_packet_append_uint8(p, 0, NULL); in dns_packet_append_name()
608 dns_packet_truncate(p, saved_size); in dns_packet_append_name()
612 int dns_packet_append_key(DnsPacket *p, const DnsResourceKey *k, const DnsAnswerFlags flags, size_t… in dns_packet_append_key() argument
617 assert(p); in dns_packet_append_key()
620 saved_size = p->size; in dns_packet_append_key()
622 r = dns_packet_append_name(p, dns_resource_key_name(k), true, true, NULL); in dns_packet_append_key()
626 r = dns_packet_append_uint16(p, k->type, NULL); in dns_packet_append_key()
631 r = dns_packet_append_uint16(p, class, NULL); in dns_packet_append_key()
641 dns_packet_truncate(p, saved_size); in dns_packet_append_key()
645 static int dns_packet_append_type_window(DnsPacket *p, uint8_t window, uint8_t length, const uint8_… in dns_packet_append_type_window() argument
649 assert(p); in dns_packet_append_type_window()
653 saved_size = p->size; in dns_packet_append_type_window()
655 r = dns_packet_append_uint8(p, window, NULL); in dns_packet_append_type_window()
659 r = dns_packet_append_uint8(p, length, NULL); in dns_packet_append_type_window()
663 r = dns_packet_append_blob(p, types, length, NULL); in dns_packet_append_type_window()
672 dns_packet_truncate(p, saved_size); in dns_packet_append_type_window()
676 static int dns_packet_append_types(DnsPacket *p, Bitmap *types, size_t *start) { in dns_packet_append_types() argument
684 assert(p); in dns_packet_append_types()
686 saved_size = p->size; in dns_packet_append_types()
692 r = dns_packet_append_type_window(p, window, entry / 8 + 1, bitmaps, NULL); in dns_packet_append_types()
706 r = dns_packet_append_type_window(p, window, entry / 8 + 1, bitmaps, NULL); in dns_packet_append_types()
716 dns_packet_truncate(p, saved_size); in dns_packet_append_types()
722 DnsPacket *p, in dns_packet_append_opt() argument
733 assert(p); in dns_packet_append_opt()
739 if (p->opt_start != SIZE_MAX) in dns_packet_append_opt()
742 assert(p->opt_size == SIZE_MAX); in dns_packet_append_opt()
744 saved_size = p->size; in dns_packet_append_opt()
747 r = dns_packet_append_uint8(p, 0, NULL); in dns_packet_append_opt()
752 r = dns_packet_append_uint16(p, DNS_TYPE_OPT, NULL); in dns_packet_append_opt()
757 r = dns_packet_append_uint16(p, max_udp_size, NULL); in dns_packet_append_opt()
762 r = dns_packet_append_uint16(p, ((uint16_t) rcode & 0x0FF0) << 4, NULL); in dns_packet_append_opt()
767 r = dns_packet_append_uint16(p, edns0_do ? EDNS0_OPT_DO : 0, NULL); in dns_packet_append_opt()
805 r = dns_packet_append_uint16(p, sizeof(rfc6975), NULL); /* RDLENGTH */ in dns_packet_append_opt()
809 … r = dns_packet_append_blob(p, rfc6975, sizeof(rfc6975), NULL); /* the payload, as defined above */ in dns_packet_append_opt()
818 r = dns_packet_append_uint16(p, 4 + strlen(nsid), NULL); /* RDLENGTH */ in dns_packet_append_opt()
822 r = dns_packet_append_uint16(p, 3, NULL); /* OPTION-CODE: NSID */ in dns_packet_append_opt()
826 r = dns_packet_append_uint16(p, strlen(nsid), NULL); /* OPTION-LENGTH */ in dns_packet_append_opt()
830 r = dns_packet_append_blob(p, nsid, strlen(nsid), NULL); in dns_packet_append_opt()
832 r = dns_packet_append_uint16(p, 0, NULL); in dns_packet_append_opt()
836 DNS_PACKET_HEADER(p)->arcount = htobe16(DNS_PACKET_ARCOUNT(p) + 1); in dns_packet_append_opt()
838 p->opt_start = saved_size; in dns_packet_append_opt()
839 p->opt_size = p->size - saved_size; in dns_packet_append_opt()
847 dns_packet_truncate(p, saved_size); in dns_packet_append_opt()
851 int dns_packet_truncate_opt(DnsPacket *p) { in dns_packet_truncate_opt() argument
852 assert(p); in dns_packet_truncate_opt()
854 if (p->opt_start == SIZE_MAX) { in dns_packet_truncate_opt()
855 assert(p->opt_size == SIZE_MAX); in dns_packet_truncate_opt()
859 assert(p->opt_size != SIZE_MAX); in dns_packet_truncate_opt()
860 assert(DNS_PACKET_ARCOUNT(p) > 0); in dns_packet_truncate_opt()
862 if (p->opt_start + p->opt_size != p->size) in dns_packet_truncate_opt()
865 dns_packet_truncate(p, p->opt_start); in dns_packet_truncate_opt()
866 DNS_PACKET_HEADER(p)->arcount = htobe16(DNS_PACKET_ARCOUNT(p) - 1); in dns_packet_truncate_opt()
867 p->opt_start = p->opt_size = SIZE_MAX; in dns_packet_truncate_opt()
872 int dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, const DnsAnswerFlags flags, siz… in dns_packet_append_rr() argument
878 assert(p); in dns_packet_append_rr()
881 saved_size = p->size; in dns_packet_append_rr()
883 r = dns_packet_append_key(p, rr->key, flags, NULL); in dns_packet_append_rr()
888 r = dns_packet_append_uint32(p, ttl, NULL); in dns_packet_append_rr()
893 r = dns_packet_append_uint16(p, 0, &rdlength_offset); in dns_packet_append_rr()
897 rds = p->size - saved_size; in dns_packet_append_rr()
902 r = dns_packet_append_uint16(p, rr->srv.priority, NULL); in dns_packet_append_rr()
906 r = dns_packet_append_uint16(p, rr->srv.weight, NULL); in dns_packet_append_rr()
910 r = dns_packet_append_uint16(p, rr->srv.port, NULL); in dns_packet_append_rr()
916 r = dns_packet_append_name(p, rr->srv.name, false, true, NULL); in dns_packet_append_rr()
923 r = dns_packet_append_name(p, rr->ptr.name, true, true, NULL); in dns_packet_append_rr()
927 r = dns_packet_append_string(p, rr->hinfo.cpu, NULL); in dns_packet_append_rr()
931 r = dns_packet_append_string(p, rr->hinfo.os, NULL); in dns_packet_append_rr()
941 r = dns_packet_append_raw_string(p, NULL, 0, NULL); in dns_packet_append_rr()
946 r = dns_packet_append_raw_string(p, i->data, i->length, NULL); in dns_packet_append_rr()
955 r = dns_packet_append_blob(p, &rr->a.in_addr, sizeof(struct in_addr), NULL); in dns_packet_append_rr()
959 r = dns_packet_append_blob(p, &rr->aaaa.in6_addr, sizeof(struct in6_addr), NULL); in dns_packet_append_rr()
963 r = dns_packet_append_name(p, rr->soa.mname, true, true, NULL); in dns_packet_append_rr()
967 r = dns_packet_append_name(p, rr->soa.rname, true, true, NULL); in dns_packet_append_rr()
971 r = dns_packet_append_uint32(p, rr->soa.serial, NULL); in dns_packet_append_rr()
975 r = dns_packet_append_uint32(p, rr->soa.refresh, NULL); in dns_packet_append_rr()
979 r = dns_packet_append_uint32(p, rr->soa.retry, NULL); in dns_packet_append_rr()
983 r = dns_packet_append_uint32(p, rr->soa.expire, NULL); in dns_packet_append_rr()
987 r = dns_packet_append_uint32(p, rr->soa.minimum, NULL); in dns_packet_append_rr()
991 r = dns_packet_append_uint16(p, rr->mx.priority, NULL); in dns_packet_append_rr()
995 r = dns_packet_append_name(p, rr->mx.exchange, true, true, NULL); in dns_packet_append_rr()
999 r = dns_packet_append_uint8(p, rr->loc.version, NULL); in dns_packet_append_rr()
1003 r = dns_packet_append_uint8(p, rr->loc.size, NULL); in dns_packet_append_rr()
1007 r = dns_packet_append_uint8(p, rr->loc.horiz_pre, NULL); in dns_packet_append_rr()
1011 r = dns_packet_append_uint8(p, rr->loc.vert_pre, NULL); in dns_packet_append_rr()
1015 r = dns_packet_append_uint32(p, rr->loc.latitude, NULL); in dns_packet_append_rr()
1019 r = dns_packet_append_uint32(p, rr->loc.longitude, NULL); in dns_packet_append_rr()
1023 r = dns_packet_append_uint32(p, rr->loc.altitude, NULL); in dns_packet_append_rr()
1027 r = dns_packet_append_uint16(p, rr->ds.key_tag, NULL); in dns_packet_append_rr()
1031 r = dns_packet_append_uint8(p, rr->ds.algorithm, NULL); in dns_packet_append_rr()
1035 r = dns_packet_append_uint8(p, rr->ds.digest_type, NULL); in dns_packet_append_rr()
1039 r = dns_packet_append_blob(p, rr->ds.digest, rr->ds.digest_size, NULL); in dns_packet_append_rr()
1043 r = dns_packet_append_uint8(p, rr->sshfp.algorithm, NULL); in dns_packet_append_rr()
1047 r = dns_packet_append_uint8(p, rr->sshfp.fptype, NULL); in dns_packet_append_rr()
1051 … r = dns_packet_append_blob(p, rr->sshfp.fingerprint, rr->sshfp.fingerprint_size, NULL); in dns_packet_append_rr()
1055 r = dns_packet_append_uint16(p, rr->dnskey.flags, NULL); in dns_packet_append_rr()
1059 r = dns_packet_append_uint8(p, rr->dnskey.protocol, NULL); in dns_packet_append_rr()
1063 r = dns_packet_append_uint8(p, rr->dnskey.algorithm, NULL); in dns_packet_append_rr()
1067 r = dns_packet_append_blob(p, rr->dnskey.key, rr->dnskey.key_size, NULL); in dns_packet_append_rr()
1071 r = dns_packet_append_uint16(p, rr->rrsig.type_covered, NULL); in dns_packet_append_rr()
1075 r = dns_packet_append_uint8(p, rr->rrsig.algorithm, NULL); in dns_packet_append_rr()
1079 r = dns_packet_append_uint8(p, rr->rrsig.labels, NULL); in dns_packet_append_rr()
1083 r = dns_packet_append_uint32(p, rr->rrsig.original_ttl, NULL); in dns_packet_append_rr()
1087 r = dns_packet_append_uint32(p, rr->rrsig.expiration, NULL); in dns_packet_append_rr()
1091 r = dns_packet_append_uint32(p, rr->rrsig.inception, NULL); in dns_packet_append_rr()
1095 r = dns_packet_append_uint16(p, rr->rrsig.key_tag, NULL); in dns_packet_append_rr()
1099 r = dns_packet_append_name(p, rr->rrsig.signer, false, true, NULL); in dns_packet_append_rr()
1103 r = dns_packet_append_blob(p, rr->rrsig.signature, rr->rrsig.signature_size, NULL); in dns_packet_append_rr()
1107 r = dns_packet_append_name(p, rr->nsec.next_domain_name, false, false, NULL); in dns_packet_append_rr()
1111 r = dns_packet_append_types(p, rr->nsec.types, NULL); in dns_packet_append_rr()
1118 r = dns_packet_append_uint8(p, rr->nsec3.algorithm, NULL); in dns_packet_append_rr()
1122 r = dns_packet_append_uint8(p, rr->nsec3.flags, NULL); in dns_packet_append_rr()
1126 r = dns_packet_append_uint16(p, rr->nsec3.iterations, NULL); in dns_packet_append_rr()
1130 r = dns_packet_append_uint8(p, rr->nsec3.salt_size, NULL); in dns_packet_append_rr()
1134 r = dns_packet_append_blob(p, rr->nsec3.salt, rr->nsec3.salt_size, NULL); in dns_packet_append_rr()
1138 r = dns_packet_append_uint8(p, rr->nsec3.next_hashed_name_size, NULL); in dns_packet_append_rr()
1142 … r = dns_packet_append_blob(p, rr->nsec3.next_hashed_name, rr->nsec3.next_hashed_name_size, NULL); in dns_packet_append_rr()
1146 r = dns_packet_append_types(p, rr->nsec3.types, NULL); in dns_packet_append_rr()
1153 r = dns_packet_append_uint8(p, rr->tlsa.cert_usage, NULL); in dns_packet_append_rr()
1157 r = dns_packet_append_uint8(p, rr->tlsa.selector, NULL); in dns_packet_append_rr()
1161 r = dns_packet_append_uint8(p, rr->tlsa.matching_type, NULL); in dns_packet_append_rr()
1165 r = dns_packet_append_blob(p, rr->tlsa.data, rr->tlsa.data_size, NULL); in dns_packet_append_rr()
1169 r = dns_packet_append_uint8(p, rr->caa.flags, NULL); in dns_packet_append_rr()
1173 r = dns_packet_append_string(p, rr->caa.tag, NULL); in dns_packet_append_rr()
1177 r = dns_packet_append_blob(p, rr->caa.value, rr->caa.value_size, NULL); in dns_packet_append_rr()
1185 r = dns_packet_append_blob(p, rr->generic.data, rr->generic.data_size, NULL); in dns_packet_append_rr()
1192 rdlength = p->size - rdlength_offset - sizeof(uint16_t); in dns_packet_append_rr()
1198 end = p->size; in dns_packet_append_rr()
1199 p->size = rdlength_offset; in dns_packet_append_rr()
1200 r = dns_packet_append_uint16(p, rdlength, NULL); in dns_packet_append_rr()
1203 p->size = end; in dns_packet_append_rr()
1214 dns_packet_truncate(p, saved_size); in dns_packet_append_rr()
1218 int dns_packet_append_question(DnsPacket *p, DnsQuestion *q) { in dns_packet_append_question() argument
1222 assert(p); in dns_packet_append_question()
1225 r = dns_packet_append_key(p, key, 0, NULL); in dns_packet_append_question()
1233 int dns_packet_append_answer(DnsPacket *p, DnsAnswer *a, unsigned *completed) { in dns_packet_append_answer() argument
1238 assert(p); in dns_packet_append_answer()
1241 r = dns_packet_append_rr(p, rr, flags, NULL, NULL); in dns_packet_append_answer()
1252 int dns_packet_read(DnsPacket *p, size_t sz, const void **ret, size_t *start) { in dns_packet_read() argument
1253 assert(p); in dns_packet_read()
1255 if (p->rindex + sz > p->size) in dns_packet_read()
1259 *ret = (uint8_t*) DNS_PACKET_DATA(p) + p->rindex; in dns_packet_read()
1262 *start = p->rindex; in dns_packet_read()
1264 p->rindex += sz; in dns_packet_read()
1268 void dns_packet_rewind(DnsPacket *p, size_t idx) { in dns_packet_rewind() argument
1269 assert(p); in dns_packet_rewind()
1270 assert(idx <= p->size); in dns_packet_rewind()
1273 p->rindex = idx; in dns_packet_rewind()
1276 int dns_packet_read_blob(DnsPacket *p, void *d, size_t sz, size_t *start) { in dns_packet_read_blob() argument
1280 assert(p); in dns_packet_read_blob()
1283 r = dns_packet_read(p, sz, &q, start); in dns_packet_read_blob()
1292 DnsPacket *p, size_t size, in dns_packet_read_memdup() argument
1300 assert(p); in dns_packet_read_memdup()
1303 r = dns_packet_read(p, size, &src, &start); in dns_packet_read_memdup()
1327 int dns_packet_read_uint8(DnsPacket *p, uint8_t *ret, size_t *start) { in dns_packet_read_uint8() argument
1331 assert(p); in dns_packet_read_uint8()
1333 r = dns_packet_read(p, sizeof(uint8_t), &d, start); in dns_packet_read_uint8()
1341 int dns_packet_read_uint16(DnsPacket *p, uint16_t *ret, size_t *start) { in dns_packet_read_uint16() argument
1345 assert(p); in dns_packet_read_uint16()
1347 r = dns_packet_read(p, sizeof(uint16_t), &d, start); in dns_packet_read_uint16()
1357 int dns_packet_read_uint32(DnsPacket *p, uint32_t *ret, size_t *start) { in dns_packet_read_uint32() argument
1361 assert(p); in dns_packet_read_uint32()
1363 r = dns_packet_read(p, sizeof(uint32_t), &d, start); in dns_packet_read_uint32()
1372 int dns_packet_read_string(DnsPacket *p, char **ret, size_t *start) { in dns_packet_read_string() argument
1373 assert(p); in dns_packet_read_string()
1375 _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_read_string()
1381 r = dns_packet_read_uint8(p, &c, NULL); in dns_packet_read_string()
1385 r = dns_packet_read(p, c, &d, NULL); in dns_packet_read_string()
1410 int dns_packet_read_raw_string(DnsPacket *p, const void **ret, size_t *size, size_t *start) { in dns_packet_read_raw_string() argument
1411 assert(p); in dns_packet_read_raw_string()
1413 _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_read_raw_string()
1417 r = dns_packet_read_uint8(p, &c, NULL); in dns_packet_read_raw_string()
1421 r = dns_packet_read(p, c, ret, NULL); in dns_packet_read_raw_string()
1435 DnsPacket *p, in dns_packet_read_name() argument
1440 assert(p); in dns_packet_read_name()
1442 _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_read_name()
1443 size_t after_rindex = 0, jump_barrier = p->rindex; in dns_packet_read_name()
1449 if (p->refuse_compression) in dns_packet_read_name()
1455 r = dns_packet_read_uint8(p, &c, NULL); in dns_packet_read_name()
1466 r = dns_packet_read(p, c, (const void**) &label, NULL); in dns_packet_read_name()
1488 r = dns_packet_read_uint8(p, &d, NULL); in dns_packet_read_name()
1497 after_rindex = p->rindex; in dns_packet_read_name()
1501 p->rindex = ptr; in dns_packet_read_name()
1512 p->rindex= after_rindex; in dns_packet_read_name()
1524 static int dns_packet_read_type_window(DnsPacket *p, Bitmap **types, size_t *start) { in dns_packet_read_type_window() argument
1525 assert(p); in dns_packet_read_type_window()
1528 _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_read_type_window()
1539 r = dns_packet_read_uint8(p, &window, NULL); in dns_packet_read_type_window()
1543 r = dns_packet_read_uint8(p, &length, NULL); in dns_packet_read_type_window()
1550 r = dns_packet_read(p, length, (const void **)&bitmap, NULL); in dns_packet_read_type_window()
1591 static int dns_packet_read_type_windows(DnsPacket *p, Bitmap **types, size_t size, size_t *start) { in dns_packet_read_type_windows() argument
1592 _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_read_type_windows()
1595 while (p->rindex < rewinder.saved_rindex + size) { in dns_packet_read_type_windows()
1596 r = dns_packet_read_type_window(p, types, NULL); in dns_packet_read_type_windows()
1601 if (p->rindex > rewinder.saved_rindex + size) in dns_packet_read_type_windows()
1605 if (p->rindex != rewinder.saved_rindex + size) in dns_packet_read_type_windows()
1616 DnsPacket *p, in dns_packet_read_key() argument
1621 assert(p); in dns_packet_read_key()
1623 _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_read_key()
1629 r = dns_packet_read_name(p, &name, true, NULL); in dns_packet_read_key()
1633 r = dns_packet_read_uint16(p, &type, NULL); in dns_packet_read_key()
1637 r = dns_packet_read_uint16(p, &class, NULL); in dns_packet_read_key()
1641 if (p->protocol == DNS_PROTOCOL_MDNS) { in dns_packet_read_key()
1677 DnsPacket *p, in dns_packet_read_rr() argument
1682 assert(p); in dns_packet_read_rr()
1684 _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_read_rr()
1692 r = dns_packet_read_key(p, &key, &cache_flush, NULL); in dns_packet_read_rr()
1703 r = dns_packet_read_uint32(p, &rr->ttl, NULL); in dns_packet_read_rr()
1712 r = dns_packet_read_uint16(p, &rdlength, NULL); in dns_packet_read_rr()
1716 if (p->rindex + rdlength > p->size) in dns_packet_read_rr()
1719 offset = p->rindex; in dns_packet_read_rr()
1724 r = dns_packet_read_uint16(p, &rr->srv.priority, NULL); in dns_packet_read_rr()
1727 r = dns_packet_read_uint16(p, &rr->srv.weight, NULL); in dns_packet_read_rr()
1730 r = dns_packet_read_uint16(p, &rr->srv.port, NULL); in dns_packet_read_rr()
1733 r = dns_packet_read_name(p, &rr->srv.name, true, NULL); in dns_packet_read_rr()
1740 r = dns_packet_read_name(p, &rr->ptr.name, true, NULL); in dns_packet_read_rr()
1744 r = dns_packet_read_string(p, &rr->hinfo.cpu, NULL); in dns_packet_read_rr()
1748 r = dns_packet_read_string(p, &rr->hinfo.os, NULL); in dns_packet_read_rr()
1760 while (p->rindex < offset + rdlength) { in dns_packet_read_rr()
1765 r = dns_packet_read_raw_string(p, &data, &sz, NULL); in dns_packet_read_rr()
1785 r = dns_packet_read_blob(p, &rr->a.in_addr, sizeof(struct in_addr), NULL); in dns_packet_read_rr()
1789 r = dns_packet_read_blob(p, &rr->aaaa.in6_addr, sizeof(struct in6_addr), NULL); in dns_packet_read_rr()
1793 r = dns_packet_read_name(p, &rr->soa.mname, true, NULL); in dns_packet_read_rr()
1797 r = dns_packet_read_name(p, &rr->soa.rname, true, NULL); in dns_packet_read_rr()
1801 r = dns_packet_read_uint32(p, &rr->soa.serial, NULL); in dns_packet_read_rr()
1805 r = dns_packet_read_uint32(p, &rr->soa.refresh, NULL); in dns_packet_read_rr()
1809 r = dns_packet_read_uint32(p, &rr->soa.retry, NULL); in dns_packet_read_rr()
1813 r = dns_packet_read_uint32(p, &rr->soa.expire, NULL); in dns_packet_read_rr()
1817 r = dns_packet_read_uint32(p, &rr->soa.minimum, NULL); in dns_packet_read_rr()
1821 r = dns_packet_read_uint16(p, &rr->mx.priority, NULL); in dns_packet_read_rr()
1825 r = dns_packet_read_name(p, &rr->mx.exchange, true, NULL); in dns_packet_read_rr()
1832 r = dns_packet_read_uint8(p, &t, &pos); in dns_packet_read_rr()
1839 r = dns_packet_read_uint8(p, &rr->loc.size, NULL); in dns_packet_read_rr()
1846 r = dns_packet_read_uint8(p, &rr->loc.horiz_pre, NULL); in dns_packet_read_rr()
1853 r = dns_packet_read_uint8(p, &rr->loc.vert_pre, NULL); in dns_packet_read_rr()
1860 r = dns_packet_read_uint32(p, &rr->loc.latitude, NULL); in dns_packet_read_rr()
1864 r = dns_packet_read_uint32(p, &rr->loc.longitude, NULL); in dns_packet_read_rr()
1868 r = dns_packet_read_uint32(p, &rr->loc.altitude, NULL); in dns_packet_read_rr()
1874 dns_packet_rewind(p, pos); in dns_packet_read_rr()
1881 r = dns_packet_read_uint16(p, &rr->ds.key_tag, NULL); in dns_packet_read_rr()
1885 r = dns_packet_read_uint8(p, &rr->ds.algorithm, NULL); in dns_packet_read_rr()
1889 r = dns_packet_read_uint8(p, &rr->ds.digest_type, NULL); in dns_packet_read_rr()
1896 r = dns_packet_read_memdup(p, rdlength - 4, in dns_packet_read_rr()
1910 r = dns_packet_read_uint8(p, &rr->sshfp.algorithm, NULL); in dns_packet_read_rr()
1914 r = dns_packet_read_uint8(p, &rr->sshfp.fptype, NULL); in dns_packet_read_rr()
1921 r = dns_packet_read_memdup(p, rdlength - 2, in dns_packet_read_rr()
1933 r = dns_packet_read_uint16(p, &rr->dnskey.flags, NULL); in dns_packet_read_rr()
1937 r = dns_packet_read_uint8(p, &rr->dnskey.protocol, NULL); in dns_packet_read_rr()
1941 r = dns_packet_read_uint8(p, &rr->dnskey.algorithm, NULL); in dns_packet_read_rr()
1948 r = dns_packet_read_memdup(p, rdlength - 4, in dns_packet_read_rr()
1960 r = dns_packet_read_uint16(p, &rr->rrsig.type_covered, NULL); in dns_packet_read_rr()
1964 r = dns_packet_read_uint8(p, &rr->rrsig.algorithm, NULL); in dns_packet_read_rr()
1968 r = dns_packet_read_uint8(p, &rr->rrsig.labels, NULL); in dns_packet_read_rr()
1972 r = dns_packet_read_uint32(p, &rr->rrsig.original_ttl, NULL); in dns_packet_read_rr()
1976 r = dns_packet_read_uint32(p, &rr->rrsig.expiration, NULL); in dns_packet_read_rr()
1980 r = dns_packet_read_uint32(p, &rr->rrsig.inception, NULL); in dns_packet_read_rr()
1984 r = dns_packet_read_uint16(p, &rr->rrsig.key_tag, NULL); in dns_packet_read_rr()
1988 r = dns_packet_read_name(p, &rr->rrsig.signer, false, NULL); in dns_packet_read_rr()
1992 if (rdlength + offset < p->rindex) in dns_packet_read_rr()
1995 r = dns_packet_read_memdup(p, offset + rdlength - p->rindex, in dns_packet_read_rr()
2013 bool allow_compressed = p->protocol == DNS_PROTOCOL_MDNS; in dns_packet_read_rr()
2015 r = dns_packet_read_name(p, &rr->nsec.next_domain_name, allow_compressed, NULL); in dns_packet_read_rr()
2019 … r = dns_packet_read_type_windows(p, &rr->nsec.types, offset + rdlength - p->rindex, NULL); in dns_packet_read_rr()
2030 r = dns_packet_read_uint8(p, &rr->nsec3.algorithm, NULL); in dns_packet_read_rr()
2034 r = dns_packet_read_uint8(p, &rr->nsec3.flags, NULL); in dns_packet_read_rr()
2038 r = dns_packet_read_uint16(p, &rr->nsec3.iterations, NULL); in dns_packet_read_rr()
2043 r = dns_packet_read_uint8(p, &size, NULL); in dns_packet_read_rr()
2047 r = dns_packet_read_memdup(p, size, &rr->nsec3.salt, &rr->nsec3.salt_size, NULL); in dns_packet_read_rr()
2051 r = dns_packet_read_uint8(p, &size, NULL); in dns_packet_read_rr()
2058 r = dns_packet_read_memdup(p, size, in dns_packet_read_rr()
2064 … r = dns_packet_read_type_windows(p, &rr->nsec3.types, offset + rdlength - p->rindex, NULL); in dns_packet_read_rr()
2072 r = dns_packet_read_uint8(p, &rr->tlsa.cert_usage, NULL); in dns_packet_read_rr()
2076 r = dns_packet_read_uint8(p, &rr->tlsa.selector, NULL); in dns_packet_read_rr()
2080 r = dns_packet_read_uint8(p, &rr->tlsa.matching_type, NULL); in dns_packet_read_rr()
2087 r = dns_packet_read_memdup(p, rdlength - 3, in dns_packet_read_rr()
2099 r = dns_packet_read_uint8(p, &rr->caa.flags, NULL); in dns_packet_read_rr()
2103 r = dns_packet_read_string(p, &rr->caa.tag, NULL); in dns_packet_read_rr()
2107 if (rdlength + offset < p->rindex) in dns_packet_read_rr()
2110 r = dns_packet_read_memdup(p, in dns_packet_read_rr()
2111 rdlength + offset - p->rindex, in dns_packet_read_rr()
2120 … r = dns_packet_read_memdup(p, rdlength, &rr->generic.data, &rr->generic.data_size, NULL); in dns_packet_read_rr()
2126 if (p->rindex != offset + rdlength) in dns_packet_read_rr()
2141 const uint8_t* p; in opt_is_good() local
2157 p = rr->opt.data; in opt_is_good()
2166 option_code = unaligned_read_be16(p); in opt_is_good()
2167 option_length = unaligned_read_be16(p + 2); in opt_is_good()
2176 p += option_length + 4U; in opt_is_good()
2184 static int dns_packet_extract_question(DnsPacket *p, DnsQuestion **ret_question) { in dns_packet_extract_question() argument
2189 n = DNS_PACKET_QDCOUNT(p); in dns_packet_extract_question()
2210 r = dns_packet_read_key(p, &key, &qu, NULL); in dns_packet_extract_question()
2235 static int dns_packet_extract_answer(DnsPacket *p, DnsAnswer **ret_answer) { in dns_packet_extract_answer() argument
2242 n = DNS_PACKET_RRCOUNT(p); in dns_packet_extract_answer()
2255 if (p->rindex == p->size && p->opt) { in dns_packet_extract_answer()
2267 r = dns_packet_read_rr(p, &rr, &cache_flush, &start); in dns_packet_extract_answer()
2278 if (p->opt || bad_opt) { in dns_packet_extract_answer()
2295 if (i < DNS_PACKET_ANCOUNT(p) + DNS_PACKET_NSCOUNT(p)) { in dns_packet_extract_answer()
2310 if (DNS_PACKET_QR(p)) { in dns_packet_extract_answer()
2334 p->opt = dns_resource_record_ref(rr); in dns_packet_extract_answer()
2335 p->opt_start = start; in dns_packet_extract_answer()
2336 assert(p->rindex >= start); in dns_packet_extract_answer()
2337 p->opt_size = p->rindex - start; in dns_packet_extract_answer()
2341 if (p->protocol == DNS_PROTOCOL_MDNS && !cache_flush) in dns_packet_extract_answer()
2347 if (i < DNS_PACKET_ANCOUNT(p)) in dns_packet_extract_answer()
2349 else if (i < DNS_PACKET_ANCOUNT(p) + DNS_PACKET_NSCOUNT(p)) in dns_packet_extract_answer()
2354 r = dns_answer_add(answer, rr, p->ifindex, flags, NULL); in dns_packet_extract_answer()
2366 p->opt = dns_resource_record_unref(p->opt); in dns_packet_extract_answer()
2367 p->opt_start = p->opt_size = SIZE_MAX; in dns_packet_extract_answer()
2375 int dns_packet_extract(DnsPacket *p) { in dns_packet_extract() argument
2376 assert(p); in dns_packet_extract()
2378 if (p->extracted) in dns_packet_extract()
2383 _unused_ _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_extract()
2386 dns_packet_rewind(p, DNS_PACKET_HEADER_SIZE); in dns_packet_extract()
2388 r = dns_packet_extract_question(p, &question); in dns_packet_extract()
2392 r = dns_packet_extract_answer(p, &answer); in dns_packet_extract()
2396 if (p->rindex < p->size) { in dns_packet_extract()
2398 p->opt = dns_resource_record_unref(p->opt); in dns_packet_extract()
2399 p->opt_start = p->opt_size = SIZE_MAX; in dns_packet_extract()
2402 p->question = TAKE_PTR(question); in dns_packet_extract()
2403 p->answer = TAKE_PTR(answer); in dns_packet_extract()
2404 p->extracted = true; in dns_packet_extract()
2410 int dns_packet_is_reply_for(DnsPacket *p, const DnsResourceKey *key) { in dns_packet_is_reply_for() argument
2413 assert(p); in dns_packet_is_reply_for()
2420 if (DNS_PACKET_QR(p) != 1) in dns_packet_is_reply_for()
2424 r = dns_packet_extract(p); in dns_packet_is_reply_for()
2428 if (!p->question) in dns_packet_is_reply_for()
2431 if (p->question->n_keys != 1) in dns_packet_is_reply_for()
2434 return dns_resource_key_equal(dns_question_first_key(p->question), key); in dns_packet_is_reply_for()
2437 int dns_packet_patch_max_udp_size(DnsPacket *p, uint16_t max_udp_size) { in dns_packet_patch_max_udp_size() argument
2438 assert(p); in dns_packet_patch_max_udp_size()
2441 if (p->opt_start == SIZE_MAX) /* No OPT section, nothing to patch */ in dns_packet_patch_max_udp_size()
2444 assert(p->opt_size != SIZE_MAX); in dns_packet_patch_max_udp_size()
2445 assert(p->opt_size >= 5); in dns_packet_patch_max_udp_size()
2447 unaligned_write_be16(DNS_PACKET_DATA(p) + p->opt_start + 3, max_udp_size); in dns_packet_patch_max_udp_size()
2451 static int patch_rr(DnsPacket *p, usec_t age) { in patch_rr() argument
2452 _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in patch_rr()
2460 r = dns_packet_read_name(p, NULL, true, NULL); in patch_rr()
2464 r = dns_packet_read_uint16(p, &type, NULL); in patch_rr()
2468 r = dns_packet_read_uint16(p, NULL, NULL); in patch_rr()
2472 r = dns_packet_read_uint32(p, &ttl, &ttl_index); in patch_rr()
2478 unaligned_write_be32(DNS_PACKET_DATA(p) + ttl_index, ttl); in patch_rr()
2481 r = dns_packet_read_uint16(p, &rdlength, NULL); in patch_rr()
2485 r = dns_packet_read(p, rdlength, NULL, NULL); in patch_rr()
2493 int dns_packet_patch_ttls(DnsPacket *p, usec_t timestamp) { in dns_packet_patch_ttls() argument
2494 assert(p); in dns_packet_patch_ttls()
2499 _unused_ _cleanup_(rewind_dns_packet) DnsPacketRewinder rewinder = REWINDER_INIT(p); in dns_packet_patch_ttls()
2508 dns_packet_rewind(p, DNS_PACKET_HEADER_SIZE); in dns_packet_patch_ttls()
2510 n = DNS_PACKET_QDCOUNT(p); in dns_packet_patch_ttls()
2512 r = dns_packet_read_key(p, NULL, NULL, NULL); in dns_packet_patch_ttls()
2517 n = DNS_PACKET_RRCOUNT(p); in dns_packet_patch_ttls()
2522 if (p->rindex == p->size) in dns_packet_patch_ttls()
2525 r = patch_rr(p, k); in dns_packet_patch_ttls()
2556 int dns_packet_has_nsid_request(DnsPacket *p) { in dns_packet_has_nsid_request() argument
2561 assert(p); in dns_packet_has_nsid_request()
2563 if (!p->opt) in dns_packet_has_nsid_request()
2566 d = p->opt->opt.data; in dns_packet_has_nsid_request()
2567 l = p->opt->opt.data_size; in dns_packet_has_nsid_request()
2602 size_t dns_packet_size_unfragmented(DnsPacket *p) { in dns_packet_size_unfragmented() argument
2603 assert(p); in dns_packet_size_unfragmented()
2605 if (p->fragsize == 0) /* Wasn't fragmented */ in dns_packet_size_unfragmented()
2606 return p->size; in dns_packet_size_unfragmented()
2613 return LESS_BY(p->fragsize, udp_header_size(p->family)); in dns_packet_size_unfragmented()