diff --git a/Knot.files b/Knot.files index f394d0eac..cca246480 100644 --- a/Knot.files +++ b/Knot.files @@ -541,6 +541,8 @@ src/libzscanner/functions.h src/libzscanner/scanner.h src/libzscanner/scanner.rl src/libzscanner/scanner_body.rl +src/knot/common/dbg_signal.c +src/knot/common/dbg_signal.h src/utils/common/exec.c src/utils/common/exec.h src/utils/common/hex.c diff --git a/src/knot/Makefile.inc b/src/knot/Makefile.inc index 3a20ec129..4bed7e68e 100644 --- a/src/knot/Makefile.inc +++ b/src/knot/Makefile.inc @@ -125,6 +125,8 @@ libknotd_la_SOURCES = \ knot/query/query.h \ knot/query/requestor.c \ knot/query/requestor.h \ + knot/common/dbg_signal.c \ + knot/common/dbg_signal.h \ knot/common/evsched.c \ knot/common/evsched.h \ knot/common/fdset.c \ diff --git a/src/knot/common/dbg_signal.c b/src/knot/common/dbg_signal.c new file mode 100644 index 000000000..c9ee5c050 --- /dev/null +++ b/src/knot/common/dbg_signal.c @@ -0,0 +1,54 @@ +/* Copyright (C) 2023 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include +#include +#include +#include + +#include "knot/common/dbg_signal.h" + +#include "knot/common/log.h" +#include "libknot/libknot.h" + +/*! \brief Temporary debug helper - signal handler. */ +static void dbg_signal_handler(int signum) +{ + printf("%s\n", strsignal(signum)); + + extern dbg_data_t dbg_data; + if (dbg_data.valid) { + knot_dname_txt_storage_t name_str; + (void)knot_dname_to_str(name_str, knot_pkt_qname(dbg_data.qdata->query), + sizeof(name_str)); + + char rrtype_str[32]; + int len = knot_rrtype_to_string(knot_pkt_qtype(dbg_data.qdata->query), + rrtype_str, sizeof(rrtype_str)); + + log_fatal("corrupted glue: name=%s, type=%s", + name_str, (len > 0) ? rrtype_str : ""); + } + + abort(); +} + +/*! \brief Temporary debug helper - signal handler setup. */ +void dbg_signal_setup(void) +{ + struct sigaction action = { .sa_handler = dbg_signal_handler }; + sigaction(SIGSEGV, &action, NULL); +} diff --git a/src/knot/common/dbg_signal.h b/src/knot/common/dbg_signal.h new file mode 100644 index 000000000..39955173a --- /dev/null +++ b/src/knot/common/dbg_signal.h @@ -0,0 +1,27 @@ +/* Copyright (C) 2023 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#pragma once + +#include "knot/nameserver/internet.h" + +typedef struct dbg_data_struct { + bool valid; + knotd_qdata_t *qdata; +} dbg_data_t; + +/*! \brief Temporary debug helper - signal handler setup. */ +void dbg_signal_setup(void); diff --git a/src/knot/nameserver/internet.c b/src/knot/nameserver/internet.c index 51bde9757..1b882d3d0 100644 --- a/src/knot/nameserver/internet.c +++ b/src/knot/nameserver/internet.c @@ -21,8 +21,11 @@ #include "knot/nameserver/nsec_proofs.h" #include "knot/nameserver/query_module.h" #include "knot/zone/serial.h" +#include "knot/common/dbg_signal.h" // Temporary debug helper. #include "contrib/mempattern.h" +dbg_data_t dbg_data = { 0 }; // Temporary debug helper. + /*! \brief Check if given node was already visited. */ static int wildcard_has_visited(knotd_qdata_t *qdata, const zone_node_t *node) { @@ -247,7 +250,9 @@ static int put_additional(knot_pkt_t *pkt, const knot_rrset_t *rr, uint16_t hint = knot_compr_hint(info, KNOT_COMPR_HINT_RDATA + glue->ns_pos); const zone_node_t *gluenode = glue_node(glue, qdata->extra->node); + dbg_data = (dbg_data_t){ .qdata = qdata, .valid = true }; // Temporary debug helper. knot_rrset_t rrsigs = node_rrset(gluenode, KNOT_RRTYPE_RRSIG); + dbg_data.valid = false; // Temporary debug helper. for (int k = 0; k < ar_type_count; ++k) { knot_rrset_t rrset = node_rrset(gluenode, ar_type_list[k]); if (knot_rrset_empty(&rrset)) { diff --git a/src/utils/knotd/main.c b/src/utils/knotd/main.c index d5abc825d..a846c7774 100644 --- a/src/utils/knotd/main.c +++ b/src/utils/knotd/main.c @@ -38,6 +38,7 @@ #include "knot/conf/conf.h" #include "knot/conf/migration.h" #include "knot/conf/module.h" +#include "knot/common/dbg_signal.h" /* Temporary debug helper. */ #include "knot/common/log.h" #include "knot/common/process.h" #include "knot/common/stats.h" @@ -507,6 +508,9 @@ int main(int argc, char **argv) /* Setup base signal handling. */ setup_signals(); + /* Temporary debug helper - signal handler setup. */ + dbg_signal_setup(); + /* Initialize cryptographic backend. */ dnssec_crypto_init();