]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: use init_request in more places; docs
authorOto Šťáva <oto.stava@nic.cz>
Thu, 29 Sep 2022 11:24:07 +0000 (13:24 +0200)
committerOto Šťáva <oto.stava@nic.cz>
Thu, 26 Jan 2023 11:56:08 +0000 (12:56 +0100)
daemon/session2.h
daemon/tls.c
daemon/worker.c

index f9d9685e03e0d870c12a9c18c6bf36593d6f1b41..f381774134a416a00e68500b0254c90d8ba0ba14 100644 (file)
@@ -537,7 +537,8 @@ struct protolayer_globals {
         * Optional - iteration continues automatically if this is NULL. */
        protolayer_event_cb event_wrap;
 
-       /** Modifies the provided request for use with the layer. */
+       /** Modifies the provided request for use with the layer. Mostly for
+        * setting `struct kr_request::qsource.comm_flags`. */
        protolayer_request_cb request_init;
 };
 
@@ -929,6 +930,8 @@ void session2_event(struct session2 *s, enum protolayer_event_type event, void *
 void session2_event_after(struct session2 *s, enum protolayer_protocol protocol,
                           enum protolayer_event_type event, void *baton);
 
+/** Performs initial setup of the specified `req`, using the session's protocol
+ * layers. Layers are processed in the `_UNWRAP` direction. */
 void session2_init_request(struct session2 *s, struct kr_request *req);
 
 /** Removes the specified request task from the session's tasklist. The session
index 63836fccd5c0e9c0263e13ecf135ef66691cdd1c..96d5988747b4c8094c20ed05b36ac63170a852ff 100644 (file)
@@ -1315,6 +1315,13 @@ static bool pl_tls_event_wrap(enum protolayer_event_type event,
        return true;
 }
 
+static void pl_tls_request_init(struct protolayer_manager *manager,
+                                struct kr_request *req,
+                                void *sess_data)
+{
+       req->qsource.comm_flags.tls = true;
+}
+
 void tls_protolayers_init(void)
 {
        protolayer_globals[PROTOLAYER_TLS] = (struct protolayer_globals){
@@ -1325,6 +1332,7 @@ void tls_protolayers_init(void)
                .wrap = pl_tls_wrap,
                .event_unwrap = pl_tls_event_unwrap,
                .event_wrap = pl_tls_event_wrap,
+               .request_init = pl_tls_request_init
        };
 }
 
index f15576480d84460893abe3f951874f84001a1b19..8ce4b185f8bc53d43e55f74da1321e3fd26261a9 100644 (file)
@@ -348,8 +348,8 @@ static struct request_ctx *request_create(struct session2 *session,
                const struct sockaddr *dst_addr = comm->dst_addr;
                const struct proxy_result *proxy = comm->proxy;
 
-               req->qsource.comm_flags.tcp = session->stream;
-               req->qsource.comm_flags.tls = session->secure;
+               req->qsource.stream_id = -1;
+               session2_init_request(session, req);
 
                req->qsource.flags = req->qsource.comm_flags;
                if (proxy) {
@@ -357,10 +357,6 @@ static struct request_ctx *request_create(struct session2 *session,
                        req->qsource.flags.tls = proxy->has_tls;
                }
 
-               req->qsource.stream_id = -1;
-
-               session2_init_request(session, req);
-
                /* We need to store a copy of peer address. */
                memcpy(&ctx->source.addr.ip, src_addr, kr_sockaddr_len(src_addr));
                req->qsource.addr = &ctx->source.addr.ip;
@@ -2289,6 +2285,12 @@ static enum protolayer_iter_cb_result pl_dns_stream_wrap(
        }
 }
 
+static void pl_dns_stream_request_init(struct protolayer_manager *manager,
+                                       struct kr_request *req,
+                                       void *sess_data)
+{
+       req->qsource.comm_flags.tcp = true;
+}
 
 int worker_init(void)
 {
@@ -2304,7 +2306,8 @@ int worker_init(void)
        protolayer_globals[PROTOLAYER_DNS_UNSIZED_STREAM] = (struct protolayer_globals){
                .sess_init = pl_dns_stream_sess_init,
                .unwrap = pl_dns_dgram_unwrap,
-               .event_unwrap = pl_dns_stream_event_unwrap
+               .event_unwrap = pl_dns_stream_event_unwrap,
+               .request_init = pl_dns_stream_request_init
        };
        const struct protolayer_globals stream_common = {
                .sess_size = sizeof(struct pl_dns_stream_sess_data),
@@ -2313,7 +2316,8 @@ int worker_init(void)
                .iter_deinit = pl_dns_stream_iter_deinit,
                .unwrap = pl_dns_stream_unwrap,
                .wrap = pl_dns_stream_wrap,
-               .event_unwrap = pl_dns_stream_event_unwrap
+               .event_unwrap = pl_dns_stream_event_unwrap,
+               .request_init = pl_dns_stream_request_init
        };
        protolayer_globals[PROTOLAYER_DNS_MULTI_STREAM] = stream_common;
        protolayer_globals[PROTOLAYER_DNS_MULTI_STREAM].sess_init = pl_dns_stream_sess_init;