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) {
#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);
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;
}
/*
* 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. */
* 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;
}
}
* @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.