]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/worker: rework worker_request_*_source_session()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 19 Apr 2021 16:22:14 +0000 (18:22 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 19 Apr 2021 16:55:07 +0000 (18:55 +0200)
I see no potential use for `set`; it's not a suitable abstraction.
And for `get` we want to use a pointer to the public type
instead of the private one.

Overall, worker.h has way too many stuff, but this branch is
not a good place to clean it up.

daemon/worker.c
daemon/worker.h

index d3e06a03499c3c1dd90f40ef35cd86687ffc5f6b..6710fa66988cf47196d219cf5c98b60d16f06740 100644 (file)
@@ -2056,14 +2056,11 @@ struct request_ctx *worker_task_get_request(struct qr_task *task)
        return task->ctx;
 }
 
-struct session *worker_request_get_source_session(struct request_ctx *ctx)
+struct session *worker_request_get_source_session(const struct kr_request *req)
 {
-       return ctx->source.session;
-}
-
-void worker_request_set_source_session(struct request_ctx *ctx, struct session *session)
-{
-       ctx->source.session = session;
+       static_assert(offsetof(struct request_ctx, req) == 0,
+                       "Bad struct request_ctx definition.");
+       return ((struct request_ctx *)req)->source.session;
 }
 
 uint16_t worker_task_pkt_get_msgid(struct qr_task *task)
index 5f7be5b43ba301342bc5bfae2ff72d06a961be85..51c9099cc11f6ec84f49b4fa9d5e89217fda3fa3 100644 (file)
@@ -107,9 +107,8 @@ knot_pkt_t *worker_task_get_pktbuf(const struct qr_task *task);
 
 struct request_ctx *worker_task_get_request(struct qr_task *task);
 
-struct session *worker_request_get_source_session(struct request_ctx *);
-
-void worker_request_set_source_session(struct request_ctx *, struct session *session);
+/** Note: source session is NULL in case the request hasn't come over network. */
+KR_EXPORT struct session *worker_request_get_source_session(const struct kr_request *req);
 
 uint16_t worker_task_pkt_get_msgid(struct qr_task *task);
 void worker_task_pkt_set_msgid(struct qr_task *task, uint16_t msgid);