diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2026-02-09 11:25:57 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2026-02-09 11:25:57 +0000 |
| commit | d4ef901e6eed5946d414727cad3f4d7446794c88 (patch) | |
| tree | e4e183139a3efbbb51ca798594d6a8fe652635a8 | |
| parent | ed02e1a94b532911e1d20364e1f396cefd5a0f7a (diff) | |
| download | smtpd-starttls-proxy-d4ef901e6eed5946d414727cad3f4d7446794c88.tar.gz | |
Add some debug instructions
| -rw-r--r-- | src/qmail-remote/dns.c | 37 | ||||
| -rw-r--r-- | src/qmail-remote/qmail-remote.c | 9 |
2 files changed, 45 insertions, 1 deletions
diff --git a/src/qmail-remote/dns.c b/src/qmail-remote/dns.c index 7344cf6..4f087f6 100644 --- a/src/qmail-remote/dns.c +++ b/src/qmail-remote/dns.c @@ -12,6 +12,8 @@ #include <skalibs/iopause.h> #include <skalibs/ip46.h> #include <skalibs/random.h> +#include <skalibs/prog.h> +#include <skalibs/lolstdio.h> #include <s6-dns/s6dns.h> #include <s6-dns/skadns.h> @@ -54,10 +56,12 @@ static unsigned int use_host_as_mx (skadns_t *a, char const *host, genalloc *mxi qmailr_tempusys("DNS-encode host domain") ; if (!skadns_send_g(a, &info.id4, &q, S6DNS_T_A, deadline, deadline)) qmailr_tempusys("send ", "A", " DNS query") ; + LOLDEBUG("sending A for %s, id %hu", host, info.id4) ; newreqs++ ; #ifdef SKALIBS_IPV6_ENABLED if (!skadns_send_g(a, &info.id6, &q, S6DNS_T_AAAA, deadline, deadline)) qmailr_tempusys("send ", "AAAA", " DNS query") ; + LOLDEBUG("sending AAAA for %s, id %hu", host, info.id6) ; newreqs++ ; #endif if (!genalloc_catb(mxipinfo, mxip, &info, 1)) dienomem() ; @@ -111,6 +115,7 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int qmailr_tempusys("DNS-encode recipient domain") ; if (!skadns_send_g(&a, &cnames[i].id, &q, S6DNS_T_CNAME, &deadline, &deadline)) qmailr_tempusys("send ", "CNAME", " DNS query") ; + LOLDEBUG("sending CNAME for %s, id %hu", at+1, cnames[i].id) ; cnames[i].count = 1 ; pending++ ; } @@ -129,6 +134,7 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int qmailr_tempusys("DNS-encode host domain") ; if (!skadns_send_g(&a, &mxid, &q, S6DNS_T_MX, &deadline, &deadline)) qmailr_tempusys("send ", "MX", " DNS query") ; + LOLDEBUG("sending MX for %s, id %hu", host, mxid) ; pending++ ; } else @@ -144,6 +150,7 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int int r = iopause_g(&x, 1, &deadline) ; if (r == -1) qmailr_tempusys("iopause") ; if (!r) qmailr_tempsys("Timed out waiting for DNS") ; + LOLDEBUG("looping, pending = %u", pending) ; r = skadns_update(&a) ; if (r == -1) qmailr_tempusys("read DNS answers") ; ids = genalloc_s(uint16_t, &a.list) ; @@ -157,6 +164,8 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int { s6dns_message_header_t h ; genalloc mxes = GENALLOC_ZERO ; /* s6dns_message_rr_mx_t */ + + LOLDEBUG("received id %hu (MX)", mxid) ; r = s6dns_message_parse(&h, packet, packetlen, &s6dns_message_parse_answer_mx, &mxes) ; if (r == -1) qmailr_tempsys("DNS packet parsing error") ; if (!r) @@ -175,14 +184,24 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int qsort(mxs, mxn, sizeof(s6dns_message_rr_mx_t), &mx_cmp) ; for (unsigned int i = 0 ; i < mxn ; i++) { +#ifdef DEBUG + char exch[256] ; + { + s6dns_domain_t dexch = mxs[i].exchange ; + s6dns_domain_decode(&dexch) ; + s6dns_domain_tostring(exch, 256, &dexch) ; + } +#endif mxipinfo *p = genalloc_s(mxipinfo, &mxipi) + i ; p->ip4 = p->ip6 = stralloc_zero ; if (!skadns_send_g(&a, &p->id4, &mxs[i].exchange, S6DNS_T_A, &deadline, &deadline)) qmailr_tempusys("send ", "A", " DNS query") ; + LOLDEBUG("sending A for %s, id %hu", exch, p->id4) ; pending++ ; #ifdef SKALIBS_IPV6_ENABLED if (!skadns_send_g(&a, &p->id6, &mxs[i].exchange, S6DNS_T_AAAA, &deadline, &deadline)) qmailr_tempusys("send ", "AAAA", " DNS query") ; + LOLDEBUG("sending AAAA for %s, id %hu", exch, p->id6) ; pending++ ; #endif } @@ -200,6 +219,7 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int { s6dns_message_header_t h ; s6dns_dpag_t dlist = { .ds = GENALLOC_ZERO, .rtype = S6DNS_T_CNAME } ; + LOLDEBUG("received id %hu (CNAME)", ids[j]) ; r = s6dns_message_parse(&h, packet, packetlen, &s6dns_message_parse_answer_domain, &dlist) ; if (r == -1) qmailr_tempsys("DNS packet parsing error") ; if (!r) @@ -215,13 +235,26 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int if (cnames[i].count++ >= 100) qmailr_perm("DNS CNAME loop") ; if (!skadns_send_g(&a, &cnames[i].id, domain, S6DNS_T_CNAME, &deadline, &deadline)) qmailr_tempusys("send ", "CNAME", " DNS query") ; +#ifdef DEBUG + { + char s[256] ; + s6dns_domain_t dom = *domain ; + s6dns_domain_decode(&dom) ; + s6dns_domain_tostring(s, &dom) ; + LOLDEBUG("sending CNAME for %s, id %hu", s, cnames[i].id) ; + } +#endif pending++ ; if (!stralloc_ready(&cnames[i].sa, 256)) dienomem() ; s6dns_domain_decode(domain) ; cnames[i].sa.len = s6dns_domain_tostring(cnames[i].sa.s, 256, domain) ; genalloc_free(s6dns_domain_t, &dlist.ds) ; } - else cnames[i].id = UINT16_MAX ; /* we have the canonical host in cnames[i].sa */ + else + { + cnames[i].id = UINT16_MAX ; /* we have the canonical host in cnames[i].sa */ + LOLDEBUG("%.*s is not a CNAME", (int)cnames[i].sa.len, cnames[i].sa.s) ; + } continue ; } @@ -231,6 +264,7 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int if (ids[j] == p->id4) { s6dns_message_header_t h ; + LOLDEBUG("received id %hu (A)", ids[j]) ; r = s6dns_message_parse(&h, packet, packetlen, &s6dns_message_parse_answer_a, &p->ip4) ; if (r == -1) qmailr_tempsys("DNS packet parsing error") ; if (!r) @@ -255,6 +289,7 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int else if (ids[j] == p->id6) { s6dns_message_header_t h ; + LOLDEBUG("received id %hu (A)", ids[j]) ; r = s6dns_message_parse(&h, packet, packetlen, &s6dns_message_parse_answer_aaaa, &p->ip6) ; if (r == -1) qmailr_tempsys("DNS packet parsing error") ; if (!r) diff --git a/src/qmail-remote/qmail-remote.c b/src/qmail-remote/qmail-remote.c index a9fdd13..7c7f5f7 100644 --- a/src/qmail-remote/qmail-remote.c +++ b/src/qmail-remote/qmail-remote.c @@ -20,6 +20,9 @@ #include <skalibs/socket.h> #include <skalibs/ip46.h> #include <skalibs/unix-timed.h> +#ifdef DEBUG +# include <skalibs/prog.h> +#endif #include <s6-networking/config.h> #include <smtpd-starttls-proxy/config.h> @@ -201,6 +204,12 @@ int main (int argc, char const *const *argv) uint16_t port = 25 ; int r ; +#ifdef DEBUG + char progstr[18 + PID_FMT] = "qmail-remote: pid " ; + progstr[18 + pid_fmt(progstr + 18, getpid())] = 0 ; + PROG = progstr ; +#endif + if (argc-- < 4) dieusage() ; argv++ ; if (chdir(SMTPD_STARTTLS_PROXY_QMAIL_HOME) == -1) qmailr_tempusys("chdir to ", SMTPD_STARTTLS_PROXY_QMAIL_HOME) ; |
