Commit bf4db95b authored by Daniel Salzman's avatar Daniel Salzman

refresh: unify similar code

parent ce1a69aa
......@@ -810,13 +810,14 @@ static int soa_query_produce(knot_layer_t *layer, knot_pkt_t *pkt)
query_init_pkt(pkt);
int r = knot_pkt_put_question(pkt, data->zone->name, KNOT_CLASS_IN, KNOT_RRTYPE_SOA);
if (r != KNOT_EOK) {
int ret = knot_pkt_put_question(pkt, data->zone->name, KNOT_CLASS_IN,
KNOT_RRTYPE_SOA);
if (ret != KNOT_EOK) {
return KNOT_STATE_FAIL;
}
r = query_put_edns(pkt, &data->edns);
if (r != KNOT_EOK) {
ret = query_put_edns(pkt, &data->edns);
if (ret != KNOT_EOK) {
return KNOT_STATE_FAIL;
}
......@@ -870,17 +871,21 @@ static int transfer_produce(knot_layer_t *layer, knot_pkt_t *pkt)
{
struct refresh_data *data = layer->data;
query_init_pkt(pkt);
bool ixfr = (data->xfr_type == XFR_TYPE_IXFR);
query_init_pkt(pkt);
knot_pkt_put_question(pkt, data->zone->name, KNOT_CLASS_IN,
ixfr ? KNOT_RRTYPE_IXFR : KNOT_RRTYPE_AXFR);
int ret = knot_pkt_put_question(pkt, data->zone->name, KNOT_CLASS_IN,
ixfr ? KNOT_RRTYPE_IXFR : KNOT_RRTYPE_AXFR);
if (ret != KNOT_EOK) {
return KNOT_STATE_FAIL;
}
if (ixfr) {
assert(data->soa);
knot_rrset_t *sending_soa = knot_rrset_copy(data->soa, data->mm);
uint32_t master_serial;
int ret = zone_get_master_serial(data->zone, &master_serial);
ret = zone_get_master_serial(data->zone, &master_serial);
if (ret != KNOT_EOK) {
log_zone_error(data->zone->name, "Failed reading master's serial"
"from KASP DB (%s)", knot_strerror(ret));
......@@ -895,7 +900,10 @@ static int transfer_produce(knot_layer_t *layer, knot_pkt_t *pkt)
knot_rrset_free(sending_soa, data->mm);
}
query_put_edns(pkt, &data->edns);
ret = query_put_edns(pkt, &data->edns);
if (ret != KNOT_EOK) {
return KNOT_STATE_FAIL;
}
return KNOT_STATE_CONSUME;
}
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -24,16 +24,14 @@
#include "libknot/yparser/yptrafo.h"
#include "libknot/rrset.h"
int query_init_pkt(knot_pkt_t *pkt)
void query_init_pkt(knot_pkt_t *pkt)
{
if (!pkt) {
return KNOT_EINVAL;
if (pkt == NULL) {
return;
}
knot_pkt_clear(pkt);
knot_wire_set_id(pkt->wire, dnssec_random_uint16_t());
return KNOT_EOK;
}
int query_edns_data_init(struct query_edns_data *edns_ptr, conf_t *conf,
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -38,10 +38,8 @@ struct query_edns_data {
* Clear the packet and generate random transaction ID.
*
* \param pkt Packet to initialize.
*
* \return Always KNOT_EOK if valid parameters supplied.
*/
int query_init_pkt(knot_pkt_t *pkt);
void query_init_pkt(knot_pkt_t *pkt);
/*!
* \brief Initialize EDNS parameters from server configuration.
......
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