summaryrefslogtreecommitdiff
path: root/sys/netinet/ip_ipsp.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2021-11-16 13:53:15 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2021-11-16 13:53:15 +0000
commit8b9d25de60073f9c62e61d873c3c57045f58f5c4 (patch)
tree9f646d0ec8c40934e7845dbfec5bb68c71d96b98 /sys/netinet/ip_ipsp.c
parent5ae2c6a6fb0014f5c4d0d0131fea6b4c1927e0ff (diff)
To debug IPsec and tdb refcounting it is useful to have "show tdb"
and "show all tdbs" in ddb. tested by Hrvoje Popovski; OK mvs@
Diffstat (limited to 'sys/netinet/ip_ipsp.c')
-rw-r--r--sys/netinet/ip_ipsp.c85
1 files changed, 82 insertions, 3 deletions
diff --git a/sys/netinet/ip_ipsp.c b/sys/netinet/ip_ipsp.c
index 05b3987ee39..c516964f429 100644
--- a/sys/netinet/ip_ipsp.c
+++ b/sys/netinet/ip_ipsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_ipsp.c,v 1.249 2021/10/27 16:58:44 bluhm Exp $ */
+/* $OpenBSD: ip_ipsp.c,v 1.250 2021/11/16 13:53:14 bluhm Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr),
@@ -532,6 +532,85 @@ tdb_hashstats(void)
db_printf("%d%s\t\t%d\n", i, i == NBUCKETS - 1 ?
"+" : "", buckets[i]);
}
+
+#define DUMP(m, f) pr("%18s: " f "\n", #m, tdb->tdb_##m)
+void
+tdb_printit(void *addr, int full, int (*pr)(const char *, ...))
+{
+ struct tdb *tdb = addr;
+ char buf[INET6_ADDRSTRLEN];
+
+ if (full) {
+ pr("tdb at %p\n", tdb);
+ DUMP(hnext, "%p");
+ DUMP(dnext, "%p");
+ DUMP(snext, "%p");
+ DUMP(inext, "%p");
+ DUMP(onext, "%p");
+ DUMP(xform, "%p");
+ DUMP(encalgxform, "%p");
+ DUMP(authalgxform, "%p");
+ DUMP(compalgxform, "%p");
+ pr("%18s: %b\n", "flags", tdb->tdb_flags, TDBF_BITS);
+ /* tdb_XXX_tmo */
+ DUMP(seq, "%d");
+ DUMP(exp_allocations, "%d");
+ DUMP(soft_allocations, "%d");
+ DUMP(cur_allocations, "%d");
+ DUMP(exp_bytes, "%lld");
+ DUMP(soft_bytes, "%lld");
+ DUMP(cur_bytes, "%lld");
+ DUMP(exp_timeout, "%lld");
+ DUMP(soft_timeout, "%lld");
+ DUMP(established, "%lld");
+ DUMP(first_use, "%lld");
+ DUMP(soft_first_use, "%lld");
+ DUMP(exp_first_use, "%lld");
+ DUMP(last_used, "%lld");
+ DUMP(last_marked, "%lld");
+ /* tdb_data */
+ DUMP(cryptoid, "%lld");
+ pr("%18s: %08x\n", "tdb_spi", ntohl(tdb->tdb_spi));
+ DUMP(amxkeylen, "%d");
+ DUMP(emxkeylen, "%d");
+ DUMP(ivlen, "%d");
+ DUMP(sproto, "%d");
+ DUMP(wnd, "%d");
+ DUMP(satype, "%d");
+ DUMP(updates, "%d");
+ pr("%18s: %s\n", "dst",
+ ipsp_address(&tdb->tdb_dst, buf, sizeof(buf)));
+ pr("%18s: %s\n", "src",
+ ipsp_address(&tdb->tdb_src, buf, sizeof(buf)));
+ DUMP(amxkey, "%p");
+ DUMP(emxkey, "%p");
+ DUMP(rpl, "%lld");
+ /* tdb_seen */
+ /* tdb_iv */
+ DUMP(ids, "%p");
+ DUMP(ids_swapped, "%d");
+ DUMP(mtu, "%d");
+ DUMP(mtutimeout, "%lld");
+ pr("%18s: %08x\n", "udpencap_port",
+ ntohl(tdb->tdb_udpencap_port));
+ DUMP(tag, "%d");
+ DUMP(tap, "%d");
+ DUMP(rdomain, "%d");
+ DUMP(rdomain_post, "%d");
+ /* tdb_filter */
+ /* tdb_filtermask */
+ /* tdb_policy_head */
+ /* tdb_sync_entry */
+ } else {
+ pr("%p:", tdb);
+ pr(" %08x", ntohl(tdb->tdb_spi));
+ pr(" %s", ipsp_address(&tdb->tdb_src, buf, sizeof(buf)));
+ pr("->%s", ipsp_address(&tdb->tdb_dst, buf, sizeof(buf)));
+ pr(":%d", tdb->tdb_sproto);
+ pr(" %08x\n", tdb->tdb_flags);
+ }
+}
+#undef DUMP
#endif /* DDB */
int
@@ -939,7 +1018,7 @@ tdb_init(struct tdb *tdbp, u_int16_t alg, struct ipsecinit *ii)
return EINVAL;
}
-#ifdef ENCDEBUG
+#if defined(DDB) || defined(ENCDEBUG)
/* Return a printable string for the address. */
const char *
ipsp_address(union sockaddr_union *sa, char *buf, socklen_t size)
@@ -959,7 +1038,7 @@ ipsp_address(union sockaddr_union *sa, char *buf, socklen_t size)
return "(unknown address family)";
}
}
-#endif /* ENCDEBUG */
+#endif /* DDB || ENCDEBUG */
/* Check whether an IP{4,6} address is unspecified. */
int