Lines Matching refs:b
164 resolv_response_init (struct resolv_response_builder *b, in resolv_response_init() argument
167 if (b->offset > 0) in resolv_response_init()
168 FAIL_EXIT1 ("response_init: called at offset %zu", b->offset); in resolv_response_init()
169 if (b->query_length < 12) in resolv_response_init()
171 b->query_length); in resolv_response_init()
176 b->buffer[0] = b->query_buffer[0]; in resolv_response_init()
177 b->buffer[1] = b->query_buffer[1]; in resolv_response_init()
180 b->buffer[2] = 0x80; /* Mark as response. */ in resolv_response_init()
181 b->buffer[2] |= b->query_buffer[2] & 0x01; /* Copy the RD bit. */ in resolv_response_init()
183 b->buffer[2] |= 0x02; in resolv_response_init()
184 b->buffer[3] = flags.rcode; in resolv_response_init()
186 b->buffer[3] |= 0x80; in resolv_response_init()
188 b->buffer[3] |= 0x20; in resolv_response_init()
191 b->buffer[4] = flags.qdcount >> 8; in resolv_response_init()
192 b->buffer[5] = flags.qdcount; in resolv_response_init()
193 b->buffer[6] = flags.ancount >> 8; in resolv_response_init()
194 b->buffer[7] = flags.ancount; in resolv_response_init()
195 b->buffer[8] = flags.nscount >> 8; in resolv_response_init()
196 b->buffer[9] = flags.nscount; in resolv_response_init()
197 b->buffer[10] = flags.adcount >> 8; in resolv_response_init()
198 b->buffer[11] = flags.adcount; in resolv_response_init()
200 b->offset = 12; in resolv_response_init()
204 resolv_response_section (struct resolv_response_builder *b, ns_sect section) in resolv_response_section() argument
206 if (b->offset == 0) in resolv_response_section()
208 if (section < b->section) in resolv_response_section()
210 b->section = section; in resolv_response_section()
215 response_add_byte (struct resolv_response_builder *b, unsigned char ch) in response_add_byte() argument
217 if (b->offset == max_response_length) in response_add_byte()
219 b->buffer[b->offset] = ch; in response_add_byte()
220 ++b->offset; in response_add_byte()
225 response_add_16 (struct resolv_response_builder *b, uint16_t val) in response_add_16() argument
227 response_add_byte (b, val >> 8); in response_add_16()
228 response_add_byte (b, val); in response_add_16()
233 response_count_increment (struct resolv_response_builder *b) in response_count_increment() argument
235 unsigned int offset = b->section; in response_count_increment()
237 ++b->buffer[offset + 1]; in response_count_increment()
238 if (b->buffer[offset + 1] == 0) in response_count_increment()
241 ++b->buffer[offset]; in response_count_increment()
242 if (b->buffer[offset] == 0) in response_count_increment()
249 resolv_response_add_question (struct resolv_response_builder *b, in resolv_response_add_question() argument
252 if (b->offset == 0) in resolv_response_add_question()
255 if (b->section != ns_s_qd) in resolv_response_add_question()
259 resolv_response_add_name (b, name); in resolv_response_add_question()
260 response_add_16 (b, type); in resolv_response_add_question()
261 response_add_16 (b, class); in resolv_response_add_question()
263 response_count_increment (b); in resolv_response_add_question()
267 resolv_response_add_name (struct resolv_response_builder *b, in resolv_response_add_name() argument
282 response_add_byte (b, '\0'); in resolv_response_add_name()
297 = allocate_compressed_name (name, b->offset); in resolv_response_add_name()
299 if (b->offset < compression_limit) in resolv_response_add_name()
303 void **ptr = tsearch (crname, &b->compression_offsets, in resolv_response_add_name()
323 void **ptr = tfind (crname, &b->compression_offsets, in resolv_response_add_name()
340 response_add_byte (b, 0xC0 | (old_offset >> 8)); in resolv_response_add_name()
341 response_add_byte (b, old_offset); in resolv_response_add_name()
348 resolv_response_add_data (b, name, len); in resolv_response_add_name()
355 resolv_response_open_record (struct resolv_response_builder *b, in resolv_response_open_record() argument
359 if (b->section == ns_s_qd) in resolv_response_open_record()
361 if (b->current_rdata_offset != 0) in resolv_response_open_record()
364 resolv_response_add_name (b, name); in resolv_response_open_record()
365 response_add_16 (b, type); in resolv_response_open_record()
366 response_add_16 (b, class); in resolv_response_open_record()
367 response_add_16 (b, ttl >> 16); in resolv_response_open_record()
368 response_add_16 (b, ttl); in resolv_response_open_record()
370 b->current_rdata_offset = b->offset; in resolv_response_open_record()
372 response_add_16 (b, 0); in resolv_response_open_record()
377 resolv_response_close_record (struct resolv_response_builder *b) in resolv_response_close_record() argument
379 size_t rdata_offset = b->current_rdata_offset; in resolv_response_close_record()
382 size_t rdata_length = b->offset - rdata_offset - 2; in resolv_response_close_record()
385 b->buffer[rdata_offset] = rdata_length >> 8; in resolv_response_close_record()
386 b->buffer[rdata_offset + 1] = rdata_length; in resolv_response_close_record()
387 response_count_increment (b); in resolv_response_close_record()
388 b->current_rdata_offset = 0; in resolv_response_close_record()
392 resolv_response_add_data (struct resolv_response_builder *b, in resolv_response_add_data() argument
395 size_t remaining = max_response_length - b->offset; in resolv_response_add_data()
399 memcpy (b->buffer + b->offset, data, length); in resolv_response_add_data()
400 b->offset += length; in resolv_response_add_data()
404 resolv_response_drop (struct resolv_response_builder *b) in resolv_response_drop() argument
406 b->drop = true; in resolv_response_drop()
410 resolv_response_close (struct resolv_response_builder *b) in resolv_response_close() argument
412 b->close = true; in resolv_response_close()
416 resolv_response_truncate_data (struct resolv_response_builder *b, size_t count) in resolv_response_truncate_data() argument
421 b->truncate_bytes = count; in resolv_response_truncate_data()
426 resolv_response_length (const struct resolv_response_builder *b) in resolv_response_length() argument
428 return b->offset; in resolv_response_length()
432 resolv_response_buffer (const struct resolv_response_builder *b) in resolv_response_buffer() argument
434 unsigned char *result = xmalloc (b->offset); in resolv_response_buffer()
435 memcpy (result, b->buffer, b->offset); in resolv_response_buffer()
443 struct resolv_response_builder *b = xmalloc (sizeof (*b)); in resolv_response_builder_allocate() local
444 memset (b, 0, offsetof (struct resolv_response_builder, buffer)); in resolv_response_builder_allocate()
445 b->query_buffer = query_buffer; in resolv_response_builder_allocate()
446 b->query_length = query_length; in resolv_response_builder_allocate()
447 return b; in resolv_response_builder_allocate()
451 resolv_response_builder_free (struct resolv_response_builder *b) in resolv_response_builder_free() argument
453 tdestroy (b->compression_offsets, free); in resolv_response_builder_free()
454 free (b); in resolv_response_builder_free()
675 struct resolv_response_builder *b in server_thread_udp_process_one() local
678 (&ctx, b, qinfo.qname, qinfo.qclass, qinfo.qtype); in server_thread_udp_process_one()
680 if (b->drop) in server_thread_udp_process_one()
690 if (b->offset >= 12) in server_thread_udp_process_one()
693 ctx.server_index, b->offset, b->buffer[3] & 0x0f, in server_thread_udp_process_one()
698 server_index, b->offset, in server_thread_udp_process_one()
700 if (b->truncate_bytes > 0) in server_thread_udp_process_one()
701 printf ("info: truncated by %u bytes\n", b->truncate_bytes); in server_thread_udp_process_one()
703 resolv_response_send_udp (&ctx, b); in server_thread_udp_process_one()
705 resolv_response_builder_free (b); in server_thread_udp_process_one()
711 struct resolv_response_builder *b) in resolv_response_send_udp() argument
714 size_t to_send = b->offset; in resolv_response_send_udp()
715 if (to_send < b->truncate_bytes) in resolv_response_send_udp()
718 to_send -= b->truncate_bytes; in resolv_response_send_udp()
723 b->buffer, to_send, 0, in resolv_response_send_udp()
921 struct resolv_response_builder *b in server_thread_tcp_client() local
924 (&ctx, b, qinfo.qname, qinfo.qclass, qinfo.qtype); in server_thread_tcp_client()
926 if (b->drop) in server_thread_tcp_client()
938 closure->server_index, b->offset, in server_thread_tcp_client()
940 uint16_t length = htons (b->offset); in server_thread_tcp_client()
941 size_t to_send = b->offset; in server_thread_tcp_client()
942 if (to_send < b->truncate_bytes) in server_thread_tcp_client()
945 to_send -= b->truncate_bytes; in server_thread_tcp_client()
949 {b->buffer, to_send} in server_thread_tcp_client()
953 bool close_flag = b->close; in server_thread_tcp_client()
954 resolv_response_builder_free (b); in server_thread_tcp_client()