Lines Matching refs:txn
126 dns_name_to_wire_(dns_name_pointer_t *NULLABLE r_pointer, dns_towire_state_t *NONNULL txn,
133 if (!txn->error) {
135 np.message_start = (uint8_t *)txn->message;
136 np.name_start = txn->p;
140 // Note that nothing is stored through txn->p until dns_name_parse has verified that
142 status = dns_parse_label(cur, &next, txn->p, txn->p + 1, txn->lim - txn->p - 1);
145 txn->truncated = true;
147 txn->error = (unsigned)status;
148 txn->line = line;
153 if (*txn->p != 0) {
155 np.length += 1 + *txn->p;
156 txn->p = txn->p + *txn->p + 1;
162 txn->error = ENAMETOOLONG;
163 txn->line = line;
174 dns_full_name_to_wire_(dns_name_pointer_t *NULLABLE r_pointer, dns_towire_state_t *NONNULL txn,
178 if (!txn->error) {
180 dns_name_to_wire(&np, txn, name);
181 if (!txn->error) {
182 if (txn->p + 1 >= txn->lim) {
183 txn->error = ENOBUFS;
184 txn->truncated = true;
185 txn->line = line;
188 *txn->p++ = 0;
192 txn->error = ENAMETOOLONG;
193 txn->line = line;
205 dns_pointer_to_wire_(dns_name_pointer_t *NULLABLE r_pointer, dns_towire_state_t *NONNULL txn,
208 if (!txn->error) {
211 txn->error = ETOOMANYREFS;
212 txn->line = line;
215 if (txn->p + 2 >= txn->lim) {
216 txn->error = ENOBUFS;
217 txn->truncated = true;
218 txn->line = line;
221 *txn->p++ = 0xc0 | (offset >> 8);
222 *txn->p++ = offset & 0xff;
227 txn->error = ENAMETOOLONG;
228 txn->line = line;
236 dns_u8_to_wire_(dns_towire_state_t *NONNULL txn, uint8_t val, int line)
238 if (!txn->error) {
239 if (txn->p + 1 >= txn->lim) {
240 txn->error = ENOBUFS;
241 txn->truncated = true;
242 txn->line = line;
245 *txn->p++ = val;
251 dns_u16_to_wire_(dns_towire_state_t *NONNULL txn, uint16_t val, int line)
253 if (!txn->error) {
254 if (txn->p + 2 >= txn->lim) {
255 txn->error = ENOBUFS;
256 txn->truncated = true;
257 txn->line = line;
260 *txn->p++ = val >> 8;
261 *txn->p++ = val & 0xff;
266 dns_u32_to_wire_(dns_towire_state_t *NONNULL txn, uint32_t val, int line)
268 if (!txn->error) {
269 if (txn->p + 4 >= txn->lim) {
270 txn->error = ENOBUFS;
271 txn->truncated = true;
272 txn->line = line;
275 *txn->p++ = val >> 24;
276 *txn->p++ = (val >> 16) & 0xff;
277 *txn->p++ = (val >> 8) & 0xff;
278 *txn->p++ = val & 0xff;
283 dns_u64_to_wire_(dns_towire_state_t *NONNULL txn, uint64_t val, int line)
285 if (!txn->error) {
286 if (txn->p + 8 >= txn->lim) {
287 txn->error = ENOBUFS;
288 txn->truncated = true;
289 txn->line = line;
292 *txn->p++ = val >> 56;
293 *txn->p++ = (val >> 48) & 0xff;
294 *txn->p++ = (val >> 40) & 0xff;
295 *txn->p++ = (val >> 32) & 0xff;
296 *txn->p++ = (val >> 24) & 0xff;
297 *txn->p++ = (val >> 16) & 0xff;
298 *txn->p++ = (val >> 8) & 0xff;
299 *txn->p++ = val & 0xff;
304 dns_ttl_to_wire_(dns_towire_state_t *NONNULL txn, int32_t val, int line)
306 if (!txn->error) {
307 dns_u32_to_wire_(txn, (uint32_t)val, line);
312 dns_rdlength_begin_(dns_towire_state_t *NONNULL txn, int line)
314 if (!txn->error) {
315 if (txn->p + 2 >= txn->lim) {
316 txn->error = ENOBUFS;
317 txn->truncated = true;
318 txn->line = line;
321 if (txn->p_rdlength != NULL) {
322 txn->error = EINVAL;
323 txn->line = line;
326 txn->p_rdlength = txn->p;
327 txn->p += 2;
332 dns_rdlength_end_(dns_towire_state_t *NONNULL txn, int line)
335 if (!txn->error) {
336 if (txn->p_rdlength == NULL) {
337 txn->error = EINVAL;
338 txn->line = line;
341 rdlength = txn->p - txn->p_rdlength - 2;
342 txn->p_rdlength[0] = (uint8_t)(rdlength >> 8);
343 txn->p_rdlength[1] = (uint8_t)(rdlength & 0xff);
344 txn->p_rdlength = NULL;
350 dns_rdata_a_to_wire_(dns_towire_state_t *NONNULL txn, const char *NONNULL ip_address, int line)
352 if (!txn->error) {
353 if (txn->p + 4 >= txn->lim) {
354 txn->error = ENOBUFS;
355 txn->truncated = true;
356 txn->line = line;
359 if (!inet_pton(AF_INET, ip_address, txn->p)) {
360 txn->error = EINVAL;
361 txn->line = line;
364 txn->p += 4;
369 dns_rdata_aaaa_to_wire_(dns_towire_state_t *NONNULL txn, const char *NONNULL ip_address, int line)
371 if (!txn->error) {
372 if (txn->p + 16 >= txn->lim) {
373 txn->error = ENOBUFS;
374 txn->truncated = true;
375 txn->line = line;
378 if (!inet_pton(AF_INET6, ip_address, txn->p)) {
379 txn->error = EINVAL;
380 txn->line = line;
383 txn->p += 16;
389 dns_rdata_key_to_wire_(dns_towire_state_t *NONNULL txn, unsigned key_type, unsigned name_type,
393 uint8_t *rdata = txn->p;
398 if (!txn->error) {
400 txn->error = EINVAL;
401 txn->line = line;
404 if (txn->p + key_len + 4 >= txn->lim) {
405 txn->error = ENOBUFS;
406 txn->truncated = true;
407 txn->line = line;
410 *txn->p++ = (uint8_t)((key_type << 6) | name_type);
411 *txn->p++ = signatory;
412 *txn->p++ = 3; // protocol type is always 3
413 *txn->p++ = srp_key_algorithm(key);
414 copied_len = srp_pubkey_copy(txn->p, key_len, key);
416 txn->error = EINVAL;
417 txn->line = line;
420 txn->p += key_len;
422 rdlen = txn->p - rdata;
434 dns_rdata_txt_to_wire_(dns_towire_state_t *NONNULL txn, const char *NONNULL txt_record, int line)
436 if (!txn->error) {
438 if (txn->p + len + 1 >= txn->lim) {
439 txn->error = ENOBUFS;
440 txn->truncated = true;
441 txn->line = line;
445 txn->error = ENAMETOOLONG;
446 txn->line = line;
449 *txn->p++ = (uint8_t)len;
450 memcpy(txn->p, txt_record, len);
451 txn->p += len;
456 dns_rdata_raw_data_to_wire_(dns_towire_state_t *NONNULL txn, const void *NONNULL raw_data, size_t length, int line)
458 if (!txn->error) {
459 if (txn->p + length > txn->lim) {
460 txn->error = ENOBUFS;
461 txn->truncated = true;
462 txn->line = line;
465 memcpy(txn->p, raw_data, length);
466 txn->p += length;
471 dns_edns0_header_to_wire_(dns_towire_state_t *NONNULL txn, uint16_t mtu, uint8_t xrcode, uint8_t version, bool DO, int line)
473 if (!txn->error) {
474 if (txn->p + 9 >= txn->lim) {
475 txn->error = ENOBUFS;
476 txn->truncated = true;
477 txn->line = line;
480 *txn->p++ = 0; // root label
481 dns_u16_to_wire(txn, dns_rrtype_opt);
482 dns_u16_to_wire(txn, mtu);
483 *txn->p++ = xrcode;
484 *txn->p++ = version;
485 *txn->p++ = DO ? 1 << 7 : 0; // flags (usb)
486 *txn->p++ = 0; // flags (lsb, mbz)
491 dns_edns0_option_begin_(dns_towire_state_t *NONNULL txn, int line)
493 if (!txn->error) {
494 if (txn->p + 2 >= txn->lim) {
495 txn->error = ENOBUFS;
496 txn->truncated = true;
497 txn->line = line;
500 if (txn->p_opt != NULL) {
501 txn->error = EINVAL;
502 txn->line = line;
505 txn->p_opt = txn->p;
506 txn->p += 2;
511 dns_edns0_option_end_(dns_towire_state_t *NONNULL txn, int line)
514 if (!txn->error) {
515 if (txn->p_opt == NULL) {
516 txn->error = EINVAL;
517 txn->line = line;
520 opt_length = txn->p - txn->p_opt - 2;
521 txn->p_opt[0] = (uint8_t)(opt_length >> 8);
522 txn->p_opt[1] = opt_length & 0xff;
523 txn->p_opt = NULL;
528 dns_sig0_signature_to_wire_(dns_towire_state_t *NONNULL txn, srp_key_t *key, uint16_t key_tag,
533 uint8_t *start, *p_signer, *p_signature, *rrstart = txn->p;
545 if (!txn->error) {
546 dns_u8_to_wire(txn, 0); // root label
547 dns_u16_to_wire(txn, dns_rrtype_sig);
548 dns_u16_to_wire(txn, dns_qclass_any); // class
549 dns_ttl_to_wire(txn, 0); // SIG RR TTL
550 dns_rdlength_begin(txn);
551 start = txn->p;
552 dns_u16_to_wire(txn, 0); // type = 0 for transaction signature
553 dns_u8_to_wire(txn, srp_key_algorithm(key));
554 dns_u8_to_wire(txn, 0); // labels field doesn't apply for transaction signature
555 dns_ttl_to_wire(txn, 0); // original ttl doesn't apply
558 dns_u32_to_wire(txn, 0); // Indicate that we have no clock: set expiry and inception times to zero
559 dns_u32_to_wire(txn, 0);
561 dns_u32_to_wire(txn, timenow + 300); // signature expiration time is five minutes from now
562 dns_u32_to_wire(txn, timenow - 300); // signature inception time, five minutes in the past
564 dns_u16_to_wire(txn, key_tag);
566 p_signer = txn->p;
569 dns_name_to_wire(NULL, txn, signer_hostname);
571 dns_full_name_to_wire(NULL, txn
573 p_signature = txn->p;
576 if (!srp_sign(txn->p, siglen, (uint8_t *)txn->message, (size_t)(rrstart - (uint8_t *)txn->message),
577 start, (size_t)(txn->p - start), key)) {
578 txn->error = true;
579 txn->line = __LINE__;
583 txn->p = p_signer;
584 dns_pointer_to_wire(NULL, txn, signer); // Pointer to the owner name the key is attached to
586 memmove(txn->p, p_signature, siglen);
588 txn->p += siglen;
589 dns_rdlength_end(txn);
592 if (txn->error) {
593 txn->outer_line = line;