commit 88c06f6d501fa66b482952bf1a5375c4f11697f0 Author: Gleb Smirnoff Date: Tue Jul 14 17:32:54 2026 -0700 inpcb: net.inet.ip.lport_dest_histgram diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 45cf963f9460..d86275597f9c 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -226,12 +226,19 @@ SYSCTL_COUNTER_U64(_net_inet_ip_rl, OID_AUTO, chgrl, CTLFLAG_RD, #endif /* INET */ +VNET_DEFINE_STATIC(counter_u64_t, lport_dest_histgram[16]); +#define V_lport_dest_histgram VNET(lport_dest_histgram) +SYSCTL_COUNTER_U64_ARRAY(_net_inet_ip, OID_AUTO, lport_dest_histgram, + CTLFLAG_RW | CTLFLAG_VNET, &VNET_NAME(lport_dest_histgram)[0], 16, ""); + VNET_DEFINE(uint32_t, in_pcbhashseed); static void in_pcbhashseed_init(void) { V_in_pcbhashseed = arc4random(); + + COUNTER_ARRAY_ALLOC(V_lport_dest_histgram, 16, M_WAITOK); } VNET_SYSINIT(in_pcbhashseed_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, in_pcbhashseed_init, NULL); @@ -741,6 +748,7 @@ in_pcb_lport_dest(struct inpcbinfo_ctx *ipictx, struct inpcb *inp, struct ucred *cred, int lookupflags, u_short *lportp) { u_int count, first, last, port, *lastport; + u_int cycles; int error; u_short lport; #ifdef INET @@ -811,12 +819,13 @@ in_pcb_lport_dest(struct inpcbinfo_ctx *ipictx, struct inpcb *inp, } } - for (count = last - first; count > 0; count--) { + for (count = last - first, cycles = 0; count > 0; count--) { struct inpcbinfo_ctx tmpctx = { .pcbinfo = ipictx->pcbinfo }; struct inpcb *tmpinp = NULL; + cycles++; lport = htons(port); if (fsa != NULL) { @@ -876,6 +885,8 @@ in_pcb_lport_dest(struct inpcbinfo_ctx *ipictx, struct inpcb *inp, *lportp = lport; + counter_u64_add(V_lport_dest_histgram[31 - __builtin_clz(cycles)], 1); + return (0); }