Skip to content
Snippets Groups Projects
Commit a8a062ec authored by Lubos Slovak's avatar Lubos Slovak
Browse files

AXFR handling function stub.

refs #754
parent b10f883b
No related branches found
No related tags found
No related merge requests found
......@@ -1973,6 +1973,47 @@ int ns_answer_request(ns_nameserver_t *nameserver, const uint8_t *query_wire,
/*----------------------------------------------------------------------------*/
int ns_answer_axfr(ns_nameserver_t *nameserver, dnslib_response_t *resp,
axfr_callback_t send_packet, int session)
{
if (nameserver == NULL || resp == NULL || send_packet == NULL) {
return KNOT_EINVAL;
}
dnslib_response_set_rcode(resp, DNSLIB_RCODE_NOTIMPL);
debug_ns("Created response packet.\n");
dnslib_response_dump(resp);
// TODO: this is ugly, either remove, or add getter for max size
uint8_t *response_wire = (uint8_t *)malloc(resp->max_size);
if (response_wire == NULL) {
return KNOT_ENOMEM;
}
size_t rsize;
// 4) Transform the packet into wire format
if (ns_response_to_wire(resp, response_wire, &rsize) != 0) {
// send back SERVFAIL (as this is our problem)
// TODO: change API to get query ID, not the whole wire format
// This is uber-ugly, to pass wire format of the response there
ns_error_response(nameserver, resp->wireformat,
DNSLIB_RCODE_SERVFAIL, response_wire, &rsize);
}
int ret = send_packet(session, response_wire, rsize);
if (ret != KNOT_EOK) {
// there was some error but there is not much to do about it
return KNOT_ERROR;
}
return KNOT_EOK;
}
/*----------------------------------------------------------------------------*/
void ns_destroy(ns_nameserver_t **nameserver)
{
synchronize_rcu();
......
......@@ -125,6 +125,36 @@ int ns_answer_request(ns_nameserver_t *nameserver,
uint8_t *response_wire,
size_t *rsize);
/*! \brief Callback for sending one packet back through a TCP connection. */
typedef int (*axfr_callback_t)(int session, uint8_t *packet, size_t size);
/*!
* \brief Processes an AXFR query.
*
* This function sequentially creates DNS packets to be sent as a response
* to the AXFR query and sends each packet using the given callback (\a
* send_packet).
*
* \param namserver Name server structure to provide the data for answering.
* \param resp Response structure with parsed query.
* \param send_packet Callback to function for sending one packet.
* \param session Opaque TCP session identifier.
*
* \note Currently only a stub which sends one error response using the given
* callback.
*
* \retval KNOT_EOK
* \retval KNOT_EINVAL
* \retval KNOT_ENOMEM
* \retval KNOT_ERROR
*
* \todo Implement.
* \todo Maybe the place for the wire format should be passed in as in
* the ns_answer_request() function...?
*/
int ns_answer_axfr(ns_nameserver_t *nameserver, dnslib_response_t *resp,
axfr_callback_t send_packet, int session);
/*!
* \brief Properly destroys the name server structure.
*
......
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