From b2be1bd43c1fd86712b6b308bdac715fd12da798 Mon Sep 17 00:00:00 2001 From: Karel Slany <karel.slany@nic.cz> Date: Mon, 25 Jul 2016 13:24:52 +0200 Subject: [PATCH] Added src parameter in kr_resolve_query_finalize(). --- daemon/worker.c | 15 +++++++++++++-- lib/resolve.c | 18 ++++++------------ lib/resolve.h | 4 +++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/daemon/worker.c b/daemon/worker.c index b4ce214c8..c27084a67 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -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) { diff --git a/lib/resolve.c b/lib/resolve.c index ace257e2e..7a61695b4 100644 --- a/lib/resolve.c +++ b/lib/resolve.c @@ -780,6 +780,7 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t #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; } } diff --git a/lib/resolve.h b/lib/resolve.h index d39da76f1..312de6e70 100644 --- a/lib/resolve.h +++ b/lib/resolve.h @@ -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. -- GitLab