Commit 027b14cb authored by Jan Kadlec's avatar Jan Kadlec

Added new test data. Added separate loading of queries. Changed python script...

Added new test data. Added separate loading of queries. Changed python script to contain query flag.
parent dce9257f
......@@ -106,6 +106,9 @@ def chop_and_write_packet(packet):
fp.write(pack('H', packet.ancount))
fp.write(pack('H', packet.nscount))
fp.write(pack('H', packet.arcount))
#write query flag
fp.write(pack('H', packet.qr))
chop_and_write_section_query(packet.qd)
chop_and_write_section_response(packet.an)
......@@ -122,6 +125,7 @@ fp.write(pack('L', total_length))
for packet in packets:
try:
data = a2b_hex(str(packet['DNS']).encode('hex'))
fr.write(pack('H', packet.qr))
fr.write(pack('H', len(data)))
fr.write(data)
chop_and_write_packet(packet['DNS'])
......
......@@ -28,6 +28,7 @@ static int mem_read(void *dst, size_t n, const char **src,
static int load_raw_packets(test_data_t *data, uint32_t *count,
const char *src, unsigned src_size)
{
uint16_t tmp_size = 0;
/* Packets are stored like this: [size][packet_data]+ */
......@@ -37,6 +38,11 @@ static int load_raw_packets(test_data_t *data, uint32_t *count,
}
for (int i = 0; i < *count; i++) {
uint16_t query = 0;
if (!mem_read(&query, sizeof(query), &src, &src_size)) {
return -1;
}
if(!mem_read(&tmp_size, sizeof(uint16_t), &src, &src_size)) {
return -1;
}
......@@ -50,7 +56,14 @@ static int load_raw_packets(test_data_t *data, uint32_t *count,
sizeof(uint8_t) * tmp_size, &src, &src_size)) {
return -1;
}
add_tail(&data->raw_response_list, (void *)packet);
if (query) {
add_tail(&data->raw_query_list, (void *)packet);
} else {
add_tail(&data->raw_response_list, (void *)packet);
}
add_tail(&data->raw_packet_list, (void *)packet);
}
return 0;
......@@ -676,6 +689,11 @@ static test_response_t *load_parsed_response(const char **src,
fprintf(stderr, "arcount: %d\n", resp->arcount);
#endif
if (!mem_read(&resp->query, sizeof(resp->query), src, src_size)) {
free(resp);
return NULL;
}
test_rrset_t **question_rrsets;
question_rrsets = malloc(sizeof(test_rrset_t *) * resp->qdcount);
......@@ -1026,7 +1044,6 @@ static void get_and_save_data_from_response(const test_response_t *response,
static int load_parsed_responses(test_data_t *data, uint32_t *count,
const char* src, unsigned src_size)
{
if (!mem_read(count, sizeof(*count), &src, &src_size)) {
fprintf(stderr, "Wrong read\n");
return -1;
......@@ -1045,7 +1062,13 @@ static int load_parsed_responses(test_data_t *data, uint32_t *count,
return -1;
}
add_tail(&data->response_list,
if (tmp_response->query) {
add_tail(&data->query_list, (node *)tmp_response);
} else {
add_tail(&data->response_list, (node *)tmp_response);
}
add_tail(&data->packet_list,
(node *)tmp_response);
}
......@@ -1084,6 +1107,10 @@ static int init_data(test_data_t *data)
init_list(&data->rrset_list);
init_list(&data->item_list);
init_list(&data->raw_response_list);
init_list(&data->raw_query_list);
init_list(&data->raw_packet_list);
init_list(&data->query_list);
init_list(&data->packet_list);
data->node_tree = malloc(sizeof(avl_tree_test_t));
CHECK_ALLOC_LOG(data->node_tree, 0);
......@@ -1096,8 +1123,9 @@ static int init_data(test_data_t *data)
static void print_stats(test_data_t *data)
{
uint resp_count = 0, dname_count = 0, edns_count = 0, node_count = 0,
rdata_count = 0, rrset_count = 0, item_count = 0,
raw_response_count = 0;
rdata_count = 0, rrset_count = 0, item_count = 0, query_count = 0,
raw_query_count = 0, response_count = 0, packet_count = 0,
raw_packet_count = 0, raw_response_count = 0;
node *n = NULL; /* Will not be used */
......@@ -1135,6 +1163,29 @@ static void print_stats(test_data_t *data)
raw_response_count++;
}
WALK_LIST(n, data->query_list) {
query_count++;
}
WALK_LIST(n, data->response_list) {
response_count++;
}
WALK_LIST(n, data->raw_query_list) {
raw_query_count++;
}
WALK_LIST(n, data->packet_list) {
packet_count++;
}
WALK_LIST(n, data->raw_packet_list) {
raw_packet_count++;
}
printf("Loaded: Responses: %d RRSets: %d RDATAs: %d Dnames: %d Nodes: %d Items: %d Raw_responses: %d\n", resp_count, rrset_count,
rdata_count, dname_count, node_count, item_count,
raw_response_count);
......
......@@ -106,6 +106,7 @@ typedef struct test_rrset test_rrset_t;
struct test_response {
struct node *next, *prev;
/* This is basically same thing as actual response structure */
uint16_t query;
test_dname_t *qname;
uint16_t qclass;
uint16_t qtype;
......@@ -141,10 +142,13 @@ struct test_data {
list node_list;
list rrset_list;
list response_list;
list query_list;
list item_list;
list raw_response_list;
list query_list;
list raw_query_list;
list item_list;
/* responses and queries together */
list packet_list;
list raw_packet_list;
avl_tree_test_t *node_tree;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment