git: 8e813d07c680 - main - netstat: fix printing of TCP pcbs with -A
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 20 Apr 2023 19:42:51 UTC
The branch main has been updated by glebius:
URL: https://cgit.FreeBSD.org/src/commit/?id=8e813d07c6804f80e1380b54f6e5fa6d34a3be52
commit 8e813d07c6804f80e1380b54f6e5fa6d34a3be52
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2023-04-20 19:41:03 +0000
Commit: Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2023-04-20 19:42:42 +0000
netstat: fix printing of TCP pcbs with -A
This change touches both kernel and netstat(1), but either of the changes
will fix printing pcb addresses with -A.
The thing is that historically netstat(1) treated TCP differently, and
printed tcpcb address instead of inpcb address. This is not documented
anywhere! With e68b3792440 these two addresses became the same. It is
highly likely they will be the same for a long time, but it might be they
will start to differ again in a far future. My proposal is to stop
treating TCP differently with netstat(1) and right now is a good opportunity
to do that, since there will be no behavior change at all. The kernel
change to tcp_inptoxtp() will go into stable/14 to make it compatible with
netstat(1) binary from stable/13. We can drop it later, probably together
with in_ppcb pointer from inpcb. The in_ppcb in xinpcb will stay for size
compatibility.
Reviewed by: tuexen, rrs
Differential Revision: https://reviews.freebsd.org/D39736
---
sys/netinet/tcp_subr.c | 7 +++++++
usr.bin/netstat/inet.c | 13 +++----------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index db0c71fdbfff..d7ca44e8a581 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -3968,6 +3968,13 @@ tcp_inptoxtp(const struct inpcb *inp, struct xtcpcb *xt)
xt->xt_len = sizeof(struct xtcpcb);
in_pcbtoxinpcb(inp, &xt->xt_inp);
+ /*
+ * TCP doesn't use inp_ppcb pointer, we embed inpcb into tcpcb.
+ * Fixup the pointer that in_pcbtoxinpcb() has set. When printing
+ * TCP netstat(1) used to use this pointer, so this fixup needs to
+ * stay for stable/14.
+ */
+ xt->xt_inp.inp_ppcb = (uintptr_t)tp;
}
void
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index a16f09d391fb..fd1a6ff20e42 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -383,16 +383,9 @@ protopr(u_long off, const char *name, int af1, int proto)
if (Lflag && so->so_qlimit == 0)
continue;
xo_open_instance("socket");
- if (Aflag) {
- if (istcp)
- xo_emit("{q:address/%*lx} ",
- 2 * (int)sizeof(void *),
- (u_long)inp->inp_ppcb);
- else
- xo_emit("{q:address/%*lx} ",
- 2 * (int)sizeof(void *),
- (u_long)so->so_pcb);
- }
+ if (Aflag)
+ xo_emit("{q:address/%*lx} ", 2 * (int)sizeof(void *),
+ (u_long)so->so_pcb);
#ifdef INET6
if ((inp->inp_vflag & INP_IPV6) != 0)
vchar = ((inp->inp_vflag & INP_IPV4) != 0) ?