Commit b2be1bd4 authored by Karel Slaný's avatar Karel Slaný Committed by Ondřej Surý
Browse files

Added src parameter in kr_resolve_query_finalize().

parent d8787137
......@@ -463,8 +463,19 @@ static int qr_task_send(struct qr_task *task, uv_handle_t *handle, struct sockad
return qr_task_on_send(task, handle, kr_error(ENOMEM));
}
if (knot_wire_get_qr(pkt->wire) == 0) {
/* Query must be finalised using destination address before sending. */
ret = kr_resolve_query_finalize(&task->req, addr,
/*
* Query must be finalised using destination address before
* sending.
*
* Libuv does not offer a convenient way how to obtain a source
* IP address from a UDP handle that has been initialised using
* uv_udp_init(). The uv_udp_getsockname() fails because of the
* lazy socket initialisation.
*
* @note -- A solution might be opening a separate socket and
* trying to obtain the IP address from it.
*/
ret = kr_resolve_query_finalize(&task->req, NULL, addr,
handle->type == UV_UDP ? SOCK_DGRAM : SOCK_STREAM,
pkt);
if (ret == KNOT_STATE_FAIL) {
......
......@@ -780,6 +780,7 @@ ns_election:
#if defined(ENABLE_COOKIES)
/** Update DNS cookie data in packet. */
static bool outbound_request_update_cookies(struct kr_request *req,
const struct sockaddr *src,
const struct sockaddr *dst)
{
assert(req);
......@@ -791,7 +792,7 @@ static bool outbound_request_update_cookies(struct kr_request *req,
struct kr_cookie_settings *clnt_sett = &req->ctx->cookie_ctx.clnt;
/* Cookies disabled or packet has no ENDS section. */
/* Cookies disabled or packet has no EDNS section. */
if (!clnt_sett->enabled) {
return true;
}
......@@ -799,24 +800,17 @@ static bool outbound_request_update_cookies(struct kr_request *req,
/*
* RFC7873 4.1 recommends using also the client address. The matter is
* also discussed in section 6.
*
* Libuv does not offer a convenient way how to obtain a source IP
* address from a UDP handle that has been initialised using
* uv_udp_init(). The uv_udp_getsockname() fails because of the lazy
* socket initialisation.
*
* @note -- A solution might be opening a separate socket and trying
* to obtain the IP address from it.
*/
kr_request_put_cookie(&clnt_sett->current, req->ctx->cache_cookie,
NULL, dst, req);
src, dst, req);
return true;
}
#endif /* defined(ENABLE_COOKIES) */
int kr_resolve_query_finalize(struct kr_request *request, struct sockaddr *dst, int type, knot_pkt_t *packet)
int kr_resolve_query_finalize(struct kr_request *request, struct sockaddr *src,
struct sockaddr *dst, int type, knot_pkt_t *packet)
{
/* @todo: Update documentation if this function becomes approved. */
......@@ -848,7 +842,7 @@ int kr_resolve_query_finalize(struct kr_request *request, struct sockaddr *dst,
* Also the resolver somehow mangles the query packets before
* building the query i.e. the space needed for the cookie
* cannot be allocated in the cookie layer. */
if (!outbound_request_update_cookies(request, dst)) {
if (!outbound_request_update_cookies(request, src, dst)) {
return KNOT_STATE_FAIL;
}
}
......
......@@ -183,13 +183,15 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
* @note The function must be called before actual sending of the request packet.
*
* @param request request state (in PRODUCE state)
* @param src address from which the query is going to be sent
* @param dst address of the name server
* @param type used socket type (SOCK_STREAM, SOCK_DGRAM)
* @param packet [in,out] query packet to be finalised
* @return any state
*/
KR_EXPORT
int kr_resolve_query_finalize(struct kr_request *request, struct sockaddr *dst, int type, knot_pkt_t *packet);
int kr_resolve_query_finalize(struct kr_request *request, struct sockaddr *src,
struct sockaddr *dst, int type, knot_pkt_t *packet);
/**
* Finish resolution and commit results if the state is DONE.
......
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