]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
Merge branch 'master' into 'rrl-wip'
authorOto Šťáva <oto.stava@nic.cz>
Tue, 4 Jun 2024 15:38:58 +0000 (17:38 +0200)
committerOto Šťáva <oto.stava@nic.cz>
Tue, 4 Jun 2024 15:38:58 +0000 (17:38 +0200)
1  2 
.gitlab-ci.yml
daemon/main.c
daemon/proxyv2.c
daemon/proxyv2.h
daemon/session2.c
daemon/worker.c
lib/utils.c
lib/utils.h
meson.build

diff --cc .gitlab-ci.yml
Simple merge
diff --cc daemon/main.c
Simple merge
Simple merge
index a21f14b1eb69f0c023b2c32c2d0e423f911359bf,6a6bc1794905bdbf0617980442848acc652f5514..9bba34762ce96946ef4f05a1c3ad8356b157c315
@@@ -35,19 -31,5 +31,9 @@@ struct proxy_result 
        bool has_tls : 1;
  };
  
- /** Checks for a PROXY protocol version 2 signature in the specified buffer. */
- static inline bool proxy_header_present(const void* buf, const ssize_t nread)
- {
-       return nread >= PROXY2_MIN_SIZE &&
-               memcmp(buf, PROXY2_SIGNATURE, sizeof(PROXY2_SIGNATURE)) == 0;
- }
 +/** Checks whether the use of PROXYv2 protocol is allowed for the specified
 + * address. */
 +bool proxy_allowed(const struct sockaddr *saddr);
 +
- /** Parses the PROXYv2 header from buf of size nread and writes the result into
-  * out. The function assumes that the PROXYv2 signature is present
-  * and has been already checked by the caller (like `udp_recv` or `tcp_recv`). */
- ssize_t proxy_process_header(struct proxy_result *out,
-                              const void *buf, ssize_t nread);
+ /** Initializes the protocol layers managed by the PROXYv2 "module". */
+ void proxy_protolayers_init(void);
index a2c519a0789c9a2dc1b975a6cc9782fe7dc7326c,19ea42dc3de0632c24d65718516da0c717fea406..5f6f7d005d0f852e7322259f1fffa25187a82fab
@@@ -554,37 -575,25 +577,37 @@@ static int session2_submit
                struct protolayer_payload payload, const struct comm_info *comm,
                protolayer_finished_cb cb, void *baton)
  {
-       struct protolayer_manager *manager = s->layers;
-       if (!comm)
-               comm = &manager->session->comm;
+       if (session->closing)
+               return kr_error(ECANCELED);
 -
+       if (kr_fails_assert(session->proto < KR_PROTO_COUNT))
+               return kr_error(EFAULT);
+       bool had_comm_param = (comm != NULL);
+       if (!had_comm_param)
+               comm = &session->comm_storage;
  
-               if (!s->outgoing && s->secure && !proxy_allowed(comm->comm_addr))
 +      // RRL: at this point we might start doing nontrivial work,
 +      // but we may not know the client's IP yet.
 +      // Note two cases: incoming session (new request)
 +      // vs. outgoing session (resuming work on some request)
 +      if (direction == PROTOLAYER_UNWRAP) {
 +              kr_rrl_sample_start();
 +              // In particular we don't want to miss en/decryption work
 +              // for regular connections from clients.
-       if (manager->session->closing) {
-               ret = kr_error(ECANCELED);
-               goto finish_ret;
-       }
-       struct protolayer_iter_ctx *ctx = malloc(manager->cb_ctx_size);
++              if (!session->outgoing && session->secure && !proxy_allowed(comm->comm_addr))
 +                      kr_rrl_sample_addr((const union kr_sockaddr *)comm->comm_addr);
 +      }
 +      int ret;
 +
+       struct protolayer_iter_ctx *ctx = malloc(session->iter_ctx_size);
        kr_require(ctx);
  
-       VERBOSE_LOG(manager->session,
+       VERBOSE_LOG(session,
                        "%s submitted to grp '%s' in %s direction (%zu: %s)\n",
                        protolayer_payload_name(payload.type),
-                       protolayer_grp_name(manager->grp),
+                       kr_proto_name(session->proto),
                        (direction == PROTOLAYER_UNWRAP) ? "unwrap" : "wrap",
-                       layer_ix, layer_name(manager->grp, layer_ix));
+                       layer_ix, layer_name(session->proto, layer_ix));
  
        *ctx = (struct protolayer_iter_ctx) {
                .payload = payload,
                }
  
                if (globals->iter_init)
-                       globals->iter_init(manager, ctx, iter_data);
+                       globals->iter_init(ctx, iter_data);
        }
  
 -      return protolayer_step(ctx);
 +      ret = protolayer_step(ctx);
- finish_ret:
 +      if (direction == PROTOLAYER_UNWRAP)
 +              kr_rrl_sample_stop();
 +      return ret;
  }
  
- static void *get_init_param(enum protolayer_protocol p,
+ static void *get_init_param(enum protolayer_type p,
                              struct protolayer_data_param *layer_param,
                              size_t layer_param_count)
  {
diff --cc daemon/worker.c
Simple merge
diff --cc lib/utils.c
Simple merge
diff --cc lib/utils.h
Simple merge
diff --cc meson.build
Simple merge