mirror of
https://github.com/EndPositive/slipstream.git
synced 2025-10-08 12:25:04 +00:00
Implement edns0
This commit is contained in:
parent
2038af95e8
commit
dbf3190c4f
2 changed files with 28 additions and 14 deletions
|
|
@ -27,9 +27,6 @@ char* client_domain_name = NULL;
|
|||
size_t client_domain_name_len = 0;
|
||||
|
||||
ssize_t client_encode_segment(picoquic_quic_t* quic, dns_packet_t* packet, size_t* packet_len, const unsigned char* src_buf, size_t src_buf_len) {
|
||||
edns0_opt_t opt;
|
||||
dns_answer_t edns;
|
||||
|
||||
char name[255];
|
||||
const size_t len = b32_encode(&name[0], (const char*) src_buf, src_buf_len, true, false);
|
||||
const size_t encoded_len = slipstream_inline_dotify(name, 255, len);
|
||||
|
|
@ -39,10 +36,17 @@ ssize_t client_encode_segment(picoquic_quic_t* quic, dns_packet_t* packet, size_
|
|||
name[encoded_len + 1 + client_domain_name_len] = '.';
|
||||
name[encoded_len + 1 + client_domain_name_len + 1] = '\0';
|
||||
|
||||
dns_question_t domain;
|
||||
domain.name = name;
|
||||
domain.type = RR_TXT;
|
||||
domain.class = CLASS_IN;
|
||||
dns_question_t question;
|
||||
question.name = name;
|
||||
question.type = RR_TXT;
|
||||
question.class = CLASS_IN;
|
||||
|
||||
dns_answer_t edns = {0};
|
||||
edns.opt.name = ".";
|
||||
edns.opt.type = RR_OPT;
|
||||
edns.opt.class = CLASS_UNKNOWN;
|
||||
edns.opt.ttl = 0;
|
||||
edns.opt.udp_payload = 4096;
|
||||
|
||||
dns_query_t query = {0};
|
||||
query.id = rand() % UINT16_MAX;
|
||||
|
|
@ -51,11 +55,9 @@ ssize_t client_encode_segment(picoquic_quic_t* quic, dns_packet_t* packet, size_
|
|||
query.rd = true;
|
||||
query.rcode = RCODE_OKAY;
|
||||
query.qdcount = 1;
|
||||
query.questions = &domain;
|
||||
query.arcount = 0; // TODO: set to 1 for EDNS0
|
||||
query.additional = NULL;
|
||||
|
||||
// TODO: add EDNS0
|
||||
query.questions = &question;
|
||||
query.arcount = 1;
|
||||
query.additional = &edns;
|
||||
|
||||
const dns_rcode_t rc = dns_encode(packet, packet_len, &query);
|
||||
if (rc != RCODE_OKAY) {
|
||||
|
|
@ -135,6 +137,11 @@ ssize_t client_decode(picoquic_quic_t* quic, unsigned char** dest_buf, const uns
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (query->rcode != RCODE_OKAY) {
|
||||
fprintf(stderr, "dns record rcode not okay: %d\n", query->rcode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (query->ancount != 1) {
|
||||
fprintf(stderr, "dns record should contain exactly one answer\n");
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,13 @@ ssize_t server_encode(picoquic_quic_t* quic, picoquic_cnx_t* cnx, unsigned char*
|
|||
answer_txt.text = (char *)src_buf;
|
||||
answer_txt.len = src_buf_len;
|
||||
|
||||
dns_answer_t edns = {0};
|
||||
edns.opt.name = ".";
|
||||
edns.opt.type = RR_OPT;
|
||||
edns.opt.class = CLASS_UNKNOWN;
|
||||
edns.opt.ttl = 0;
|
||||
edns.opt.udp_payload = 4096;
|
||||
|
||||
dns_query_t response = {0};
|
||||
response.id = query->id;
|
||||
response.query = false;
|
||||
|
|
@ -74,8 +81,8 @@ ssize_t server_encode(picoquic_quic_t* quic, picoquic_cnx_t* cnx, unsigned char*
|
|||
response.questions = query->questions;
|
||||
response.ancount = 1;
|
||||
response.answers = (dns_answer_t *)&answer_txt;
|
||||
response.arcount = 0; // TODO: set to 1 for EDNS0
|
||||
response.additional = NULL;
|
||||
response.arcount = 1;
|
||||
response.additional = &edns;
|
||||
|
||||
dns_packet_t* packet = malloc(MAX_UDP_PACKET_SIZE);
|
||||
size_t packet_len = MAX_UDP_PACKET_SIZE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue