]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/worker: minor refactoring around knot_pkt_parse()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 1 Dec 2022 18:25:57 +0000 (19:25 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 6 Dec 2022 11:58:14 +0000 (12:58 +0100)
The separate function wasn't really doing anything.
Also add a debug log.

daemon/worker.c

index a50be16fac4ac37e7ab5f16844e214d436b5c981..ed35cb03d16b8cabf239029f1478242010e2a487 100644 (file)
@@ -1691,27 +1691,6 @@ static int qr_task_step(struct qr_task *task,
        }
 }
 
-static int parse_packet(knot_pkt_t *query)
-{
-       if (!query){
-               return kr_error(EINVAL);
-       }
-
-       /* Parse query packet. */
-       int ret = knot_pkt_parse(query, 0);
-       if (ret == KNOT_ETRAIL) {
-               /* Extra data after message end. */
-               ret = kr_error(EMSGSIZE);
-       } else if (ret != KNOT_EOK) {
-               /* Malformed query. */
-               ret = kr_error(EPROTO);
-       } else {
-               ret = kr_ok();
-       }
-
-       return ret;
-}
-
 int worker_submit(struct session *session, struct io_comm_data *comm,
                   const uint8_t *eth_from, const uint8_t *eth_to, knot_pkt_t *pkt)
 {
@@ -1722,11 +1701,13 @@ int worker_submit(struct session *session, struct io_comm_data *comm,
        if (!handle || !handle->loop->data)
                return kr_error(EINVAL);
 
-       int ret = parse_packet(pkt);
-
        const bool is_query = (knot_wire_get_qr(pkt->wire) == 0);
        const bool is_outgoing = session_flags(session)->outgoing;
 
+       int ret = knot_pkt_parse(pkt, 0);
+       if (ret == KNOT_ETRAIL && is_outgoing && !kr_fails_assert(pkt->parsed < pkt->size))
+               ret = KNOT_EOK; // we deal with this later, so that `selection` applies
+
        struct http_ctx *http_ctx = NULL;
 #if ENABLE_DOH2
        http_ctx = session_http_get_server_ctx(session);
@@ -1734,7 +1715,7 @@ int worker_submit(struct session *session, struct io_comm_data *comm,
        /* Badly formed query when using DoH leads to a Bad Request */
        if (http_ctx && !is_outgoing && ret) {
                http_send_status(session, HTTP_STATUS_BAD_REQUEST);
-               return ret;
+               return kr_error(ret);
        }
 #endif
 
@@ -1742,11 +1723,13 @@ int worker_submit(struct session *session, struct io_comm_data *comm,
                return kr_error(ENOENT);
 
        /* Ignore badly formed queries. */
-       if ((ret != kr_ok() && ret != kr_error(EMSGSIZE)) ||
-           (is_query == is_outgoing)) {
-               if (!is_outgoing) {
+       if (ret && kr_log_is_debug(WORKER, NULL)) {
+               VERBOSE_MSG(NULL, "=> incoming packet failed to parse, %s\n",
+                               knot_strerror(ret));
+       }
+       if (ret || is_query == is_outgoing) {
+               if (!is_outgoing)
                        the_worker->stats.dropped += 1;
-               }
                return kr_error(EILSEQ);
        }