Skip to content
Snippets Groups Projects
Commit 4cb8eddb authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Add ixfr_serial item to query_t structure

refs #2137
parent fa77b77f
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@
#define IPV4_REVERSE_DOMAIN "in-addr.arpa."
#define IPV6_REVERSE_DOMAIN "ip6.arpa."
query_t* create_query(const char *name, const uint16_t type)
query_t* query_create(const char *name, const uint16_t type)
{
// Create output structure.
query_t *query = calloc(1, sizeof(query_t));
......@@ -39,10 +39,16 @@ query_t* create_query(const char *name, const uint16_t type)
// Fill output.
query->name = strdup(name);
query->type = type;
query->ixfr_serial = -1;
return query;
}
void query_set_serial(query_t *query, const uint32_t serial)
{
query->ixfr_serial = serial;
}
void query_free(query_t *query)
{
if (query == NULL) {
......
......@@ -45,6 +45,8 @@ typedef struct {
char *name;
/*!< Type number to query on. */
uint16_t type;
/*!< SOA serial for IXFR. */
int64_t ixfr_serial;
} query_t;
typedef enum {
......@@ -89,7 +91,7 @@ typedef struct {
list qfiles;
/*!< Operation mode. */
operation_t mode;
operation_t operation;
/*!< Version of ip protocol to use. */
ip_version_t ip;
/*!< Type (TCP, UDP) protocol to use. */
......@@ -98,7 +100,7 @@ typedef struct {
uint16_t class_num;
/*!< Default type number (16unsigned + -1 uninitialized). */
int32_t type_num;
/*!< SOA serial for IXFR query (32unsigned + -1 uninitialized). */
/*!< Default SOA serial for IXFR (32unsigned + -1 uninitialized). */
int64_t ixfr_serial;
/*!< Use recursion. */
bool recursion;
......@@ -118,10 +120,13 @@ typedef struct {
const char* addr;
} params_t;
query_t* create_query(const char *name, const uint16_t type);
query_t* query_create(const char *name, const uint16_t type);
void query_free(query_t *query);
void query_set_serial(query_t *query, const uint32_t serial);
int parse_class(const char *rclass, uint16_t *class_num);
int parse_type(const char *rtype, int32_t *type_num, int64_t *ixfr_serial);
......
......@@ -105,7 +105,7 @@ static knot_packet_t* create_query_packet(const params_t *params,
// SOA rdata in wireformat.
uint8_t wire[22] = { 0x0 };
// Set SOA serial.
uint32_t serial = htonl(params->ixfr_serial);
uint32_t serial = htonl(query->ixfr_serial);
memcpy(wire + 2, &serial, sizeof(serial));
// Create SOA rdata.
......@@ -191,26 +191,29 @@ static int process_query(const params_t *params, const query_t *query)
continue;
}
int x = receive_msg(params, query, sockfd, out, out_len);
int x;
/* knot_packet_t *pkt_in =
while (x = receive_msg(params, query, sockfd, out, out_len), x) {
knot_packet_t *pkt_in =
knot_packet_new(KNOT_PACKET_PREALLOC_RESPONSE);
char y[70000];
int ret = knot_packet_parse_from_wire(pkt_in, out, x, 0, KNOT_PACKET_DUPL_NO_MERGE);
if (ret != KNOT_EOK) {
printf("ggr");
printf("ggr\n");
}
// knot_rrset_t *rr = NULL;
// knot_packet_parse_next_rr_answer(pkt_in, &rr);
char y[70000];
for (int i = 0; i < pkt_in->an_rrsets; i++) {
rrset_write_mem(y, 70000, (pkt_in->answer)[i]);
printf("%s", y);
}
*/
knot_packet_free(&pkt_in);
}
shutdown(sockfd, SHUT_RDWR);
// If successfully processed, stop quering nameservers.
......@@ -231,7 +234,7 @@ int host_exec(const params_t *params)
return KNOT_EINVAL;
}
switch (params->mode) {
switch (params->operation) {
case OPERATION_QUERY:
WALK_LIST(query, params->queries) {
process_query(params, (query_t *)query);
......
......@@ -42,7 +42,7 @@ static void host_params_init(params_t *params)
init_list(&params->queries);
// Default values.
params->mode = OPERATION_QUERY;
params->operation = OPERATION_QUERY;
params->ip = IP_ALL;
params->protocol = PROTO_ALL;
params->udp_size = DEFAULT_UDP_SIZE;
......@@ -87,7 +87,7 @@ static void host_params_flag_all(params_t *params)
static void host_params_flag_soa(params_t *params)
{
params->type_num = KNOT_RRTYPE_SOA;
params->mode = OPERATION_LIST_SOA;
params->operation = OPERATION_LIST_SOA;
}
static void host_params_flag_axfr(params_t *params)
......@@ -135,7 +135,7 @@ static int host_params_parse_name(params_t *params, const char *name)
}
// Add reverse query for address.
query = create_query(reverse, params->type_num);
query = query_create(reverse, params->type_num);
if (query == NULL) {
free(reverse);
return KNOT_ENOMEM;
......@@ -143,39 +143,43 @@ static int host_params_parse_name(params_t *params, const char *name)
add_tail(&params->queries, (node *)query);
} else {
// Add query for name and specified type.
query = create_query(name, params->type_num);
query = query_create(name, params->type_num);
if (query == NULL) {
free(reverse);
return KNOT_ENOMEM;
}
// Set SOA serial for IXFR query.
if (params->type_num == KNOT_RRTYPE_IXFR) {
query_set_serial(query, params->ixfr_serial);
}
add_tail(&params->queries, (node *)query);
}
// RR type is unknown, use defaults.
} else {
if (reverse == NULL) {
// Add query for name and type A.
query = create_query(name, KNOT_RRTYPE_A);
query = query_create(name, KNOT_RRTYPE_A);
if (query == NULL) {
return KNOT_ENOMEM;
}
add_tail(&params->queries, (node *)query);
// Add query for name and type AAAA.
query = create_query(name, KNOT_RRTYPE_AAAA);
query = query_create(name, KNOT_RRTYPE_AAAA);
if (query == NULL) {
return KNOT_ENOMEM;
}
add_tail(&params->queries, (node *)query);
// Add query for name and type MX.
query = create_query(name, KNOT_RRTYPE_MX);
query = query_create(name, KNOT_RRTYPE_MX);
if (query == NULL) {
return KNOT_ENOMEM;
}
add_tail(&params->queries, (node *)query);
} else {
// Add reverse query for address.
query = create_query(reverse, KNOT_RRTYPE_PTR);
query = query_create(reverse, KNOT_RRTYPE_PTR);
if (query == NULL) {
free(reverse);
return KNOT_ENOMEM;
......
......@@ -34,7 +34,7 @@ static void nsupdate_params_init(params_t *params)
init_list(&params->qfiles);
// Default values.
params->mode = OPERATION_UPDATE;
params->operation = OPERATION_UPDATE;
params->port = DEFAULT_PORT;
params->protocol = PROTO_ALL;
params->udp_size = DEFAULT_UDP_SIZE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment