]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
Added src parameter in kr_resolve_query_finalize().
authorKarel Slany <karel.slany@nic.cz>
Mon, 25 Jul 2016 11:24:52 +0000 (13:24 +0200)
committerOndřej Surý <ondrej@sury.org>
Thu, 11 Aug 2016 12:06:45 +0000 (14:06 +0200)
daemon/worker.c
lib/resolve.c
lib/resolve.h

index b4ce214c8480a007aeebff8f1d7df10c425e6fb2..c27084a67a0345c33d7aaf039ac54479e8a6c5b9 100644 (file)
@@ -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) {
index ace257e2edf52a7066472fe7c8812542d08ff4cd..7a61695b4c5fdb17383d9d14c23ec3e8653505c7 100644 (file)
@@ -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;
                }
        }
index d39da76f118c654a555435a1de32c716bc4c7411..312de6e705a3dd7e9ad52deaf3649d9a8b7853c4 100644 (file)
@@ -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.