smtpd: allow arguments on NOOP

2023-06-23 Thread Omar Polo
another diff from the -portable repo:

https://github.com/OpenSMTPD/OpenSMTPD/pull/1150

per rfc-5321 § 4.1.1.9 the NOOP command allows optionally one argument
that we SHOULD ignore.

The original diff set the check function in the commands table to NULL
because NOOP is not a phase that can have filters.  However, I prefer
to stay on the safe side and add a smtp_check_noop() function.
Alternatively, we could allow a NULL check function in
smtp_session_imsg().

the rfc specifies only one optional string, while here for semplicity
it's relaxed to allow anything.


diff /usr/src
commit - 8def1c1c2777f0b5175283f8116e1eaab1f1962a
path + /usr/src
blob - 1686f03e96deeb5e6ea8b065456e04c27c752c8c
file + usr.sbin/smtpd/smtp_session.c
--- usr.sbin/smtpd/smtp_session.c
+++ usr.sbin/smtpd/smtp_session.c
@@ -212,6 +212,7 @@ static int  smtp_check_noparam(struct smtp_session *, 
 static int  smtp_check_mail_from(struct smtp_session *, const char *);
 static int  smtp_check_rcpt_to(struct smtp_session *, const char *);
 static int  smtp_check_data(struct smtp_session *, const char *);
+static int  smtp_check_noop(struct smtp_session *, const char *);
 static int  smtp_check_noparam(struct smtp_session *, const char *);
 
 static void smtp_filter_phase(enum filter_phase, struct smtp_session *, const 
char *);
@@ -276,7 +277,7 @@ static struct {
{ CMD_DATA, FILTER_DATA,"DATA", 
smtp_check_data,smtp_proceed_data },
{ CMD_RSET, FILTER_RSET,"RSET", 
smtp_check_rset,smtp_proceed_rset },
{ CMD_QUIT, FILTER_QUIT,"QUIT", 
smtp_check_noparam, smtp_proceed_quit },
-   { CMD_NOOP, FILTER_NOOP,"NOOP", 
smtp_check_noparam, smtp_proceed_noop },
+   { CMD_NOOP, FILTER_NOOP,"NOOP", 
smtp_check_noop,smtp_proceed_noop },
{ CMD_HELP, FILTER_HELP,"HELP", 
smtp_check_noparam, smtp_proceed_help },
{ CMD_WIZ,  FILTER_WIZ, "WIZ",  
smtp_check_noparam, smtp_proceed_wiz },
{ CMD_COMMIT,   FILTER_COMMIT,  ".",
smtp_check_noparam, smtp_proceed_commit },
@@ -1343,8 +1344,8 @@ smtp_command(struct smtp_session *s, char *line)
break;
 
case CMD_NOOP:
-   if (!smtp_check_noparam(s, args))
-   break;  
+   if (!smtp_check_noop(s, args))
+   break;
smtp_filter_phase(FILTER_NOOP, s, NULL);
break;
 
@@ -1631,6 +1632,12 @@ smtp_check_noparam(struct smtp_session *s, const char 
 }
 
 static int
+smtp_check_noop(struct smtp_session *s, const char *args)
+{
+   return 1;
+}
+
+static int
 smtp_check_noparam(struct smtp_session *s, const char *args)
 {
if (args != NULL) {



Re: smtpd: allow arguments on NOOP

2023-06-23 Thread gilles
June 23, 2023 11:58 AM, "Omar Polo"  wrote:

> another diff from the -portable repo:
> 
> https://github.com/OpenSMTPD/OpenSMTPD/pull/1150
> 
> per rfc-5321 § 4.1.1.9 the NOOP command allows optionally one argument
> that we SHOULD ignore.
> 
> The original diff set the check function in the commands table to NULL
> because NOOP is not a phase that can have filters. However, I prefer
> to stay on the safe side and add a smtp_check_noop() function.
> Alternatively, we could allow a NULL check function in
> smtp_session_imsg().
> 
> the rfc specifies only one optional string, while here for semplicity
> it's relaxed to allow anything.
> 
> diff /usr/src
> commit - 8def1c1c2777f0b5175283f8116e1eaab1f1962a
> path + /usr/src
> blob - 1686f03e96deeb5e6ea8b065456e04c27c752c8c
> file + usr.sbin/smtpd/smtp_session.c
> --- usr.sbin/smtpd/smtp_session.c
> +++ usr.sbin/smtpd/smtp_session.c
> @@ -212,6 +212,7 @@ static int smtp_check_noparam(struct smtp_session *, 
> static int smtp_check_mail_from(struct smtp_session *, const char *);
> static int smtp_check_rcpt_to(struct smtp_session *, const char *);
> static int smtp_check_data(struct smtp_session *, const char *);
> +static int smtp_check_noop(struct smtp_session *, const char *);
> static int smtp_check_noparam(struct smtp_session *, const char *);
> 
> static void smtp_filter_phase(enum filter_phase, struct smtp_session *, const 
> char *);
> @@ -276,7 +277,7 @@ static struct {
> { CMD_DATA, FILTER_DATA, "DATA", smtp_check_data, smtp_proceed_data },
> { CMD_RSET, FILTER_RSET, "RSET", smtp_check_rset, smtp_proceed_rset },
> { CMD_QUIT, FILTER_QUIT, "QUIT", smtp_check_noparam, smtp_proceed_quit },
> - { CMD_NOOP, FILTER_NOOP, "NOOP", smtp_check_noparam, smtp_proceed_noop },
> + { CMD_NOOP, FILTER_NOOP, "NOOP", smtp_check_noop, smtp_proceed_noop },
> { CMD_HELP, FILTER_HELP, "HELP", smtp_check_noparam, smtp_proceed_help },
> { CMD_WIZ, FILTER_WIZ, "WIZ", smtp_check_noparam, smtp_proceed_wiz },
> { CMD_COMMIT, FILTER_COMMIT, ".", smtp_check_noparam, smtp_proceed_commit },
> @@ -1343,8 +1344,8 @@ smtp_command(struct smtp_session *s, char *line)
> break;
> 
> case CMD_NOOP:
> - if (!smtp_check_noparam(s, args))
> - break; 
> + if (!smtp_check_noop(s, args))
> + break;
> smtp_filter_phase(FILTER_NOOP, s, NULL);
> break;
> 
> @@ -1631,6 +1632,12 @@ smtp_check_noparam(struct smtp_session *s, const char 
> }
> 
> static int
> +smtp_check_noop(struct smtp_session *s, const char *args)
> +{
> + return 1;
> +}
> +
> +static int
> smtp_check_noparam(struct smtp_session *s, const char *args)
> {
> if (args != NULL) {


This reads fine and you did well adding an smtp_check_noop() because it leaves 
room
for hooking this command in filters which is something OpenSMTPD could benefit 
from
as it would allow a filter to detect people doing NOOP loops and kick them.

Just my 2cents



Re: Error in ex(1) s command when using c option and numbering on

2023-06-23 Thread Omar Polo
On 2023/06/22 13:18:43 -0600, Todd C. Miller  wrote:
> On Tue, 07 Feb 2023 20:35:10 -0700, Todd C. Miller wrote:
> 
> > On Tue, 07 Feb 2023 17:17:02 -0700, Todd C. Miller wrote:
> >
> > > Yes, the bug is that the number is not displayed.  The following
> > > diff fixes that but there is still a bug because the resulting line
> > > also lacks a line number.  In other words, instead of:
> > >
> > > :s/men/MEN/c
> > >  1  Five women came to the party.
> > >^^^[ynq]y
> > > Five woMEN came to the party.
> > >
> > > it should look like this:
> > >
> > > :s/men/MEN/c
> > >  1  Five women came to the party.
> > >^^^[ynq]y
> > >  1  Five woMEN came to the party.
> >
> > Here's an updated diff that prints line numbers when autoprint is
> > set too.  This seems to match historic ex behavior and POSIX, but
> > I'd appreciate other eyes on it.
> 
> Moving this from busg@ to tech@.  I noticed today I still have this
> diff from Feb rotting in my tree.  The original thread is:
> https://marc.info/?l=openbsd-bugs&m=167580085421828&w=2
> 
> OK?

not really using ex, but the diff reads fine and fixes the issue.
ok op@

(midly surprised by LF_INIT, wich is just a long way to set a local
variable :/)

> Index: usr.bin/vi/ex/ex.c
> ===
> RCS file: /cvs/src/usr.bin/vi/ex/ex.c,v
> retrieving revision 1.22
> diff -u -p -u -r1.22 ex.c
> --- usr.bin/vi/ex/ex.c20 Feb 2022 19:45:51 -  1.22
> +++ usr.bin/vi/ex/ex.c8 Feb 2023 03:28:32 -
> @@ -1454,8 +1454,14 @@ addr_verify:
>   LF_INIT(FL_ISSET(ecp->iflags, E_C_HASH | E_C_LIST | E_C_PRINT));
>   if (!LF_ISSET(E_C_HASH | E_C_LIST | E_C_PRINT | E_NOAUTO) &&
>   !F_ISSET(sp, SC_EX_GLOBAL) &&
> - O_ISSET(sp, O_AUTOPRINT) && F_ISSET(ecp, E_AUTOPRINT))
> - LF_INIT(E_C_PRINT);
> + O_ISSET(sp, O_AUTOPRINT) && F_ISSET(ecp, E_AUTOPRINT)) {
> +
> + /* Honor the number option if autoprint is set. */
> + if (F_ISSET(ecp, E_OPTNUM))
> + LF_INIT(E_C_HASH);
> + else
> + LF_INIT(E_C_PRINT);
> + }
>  
>   if (LF_ISSET(E_C_HASH | E_C_LIST | E_C_PRINT)) {
>   cur.lno = sp->lno;
> Index: usr.bin/vi/ex/ex_subst.c
> ===
> RCS file: /cvs/src/usr.bin/vi/ex/ex_subst.c,v
> retrieving revision 1.30
> diff -u -p -u -r1.30 ex_subst.c
> --- usr.bin/vi/ex/ex_subst.c  18 Apr 2017 01:45:35 -  1.30
> +++ usr.bin/vi/ex/ex_subst.c  8 Feb 2023 03:23:27 -
> @@ -633,7 +633,9 @@ nextmatch:match[0].rm_so = offset;
>   goto lquit;
>   }
>   } else {
> - if (ex_print(sp, cmdp, &from, &to, 0) ||
> + const int flags =
> + O_ISSET(sp, O_NUMBER) ? E_C_HASH : 0;
> + if (ex_print(sp, cmdp, &from, &to, flags) ||
>   ex_scprint(sp, &from, &to))
>   goto lquit;
>   if (ex_txt(sp, &tiq, 0, TXT_CR))




lo(4) loopback LRO and TSO

2023-06-23 Thread Alexander Bluhm
Hi,

Claudio@ mentioned the idea to use TSO and LRO on the loopback
interface to transfer TCP faster.

I see a performance effect with this diff, but more importantly it
gives us more test coverage.  Currently LRO on lo(4) is default
off.

Future plan is:
- Fix some corner cases for LRO/TSO with TCP path-MTU discovery
  and IP forwarding when LRO is enabled.
- Enable LRO/TSO for lo(4) and ix(4) per default.
- Jan@ commits his ixl(4) TSO diff.

ok for lo(4) LRO/TSO with default off?

bluhm

Index: sys/net/if.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if.c,v
retrieving revision 1.700
diff -u -p -r1.700 if.c
--- sys/net/if.c12 Jun 2023 21:19:54 -  1.700
+++ sys/net/if.c23 Jun 2023 15:48:27 -
@@ -106,6 +106,9 @@
 #ifdef MROUTING
 #include 
 #endif
+#include 
+#include 
+#include 
 
 #ifdef INET6
 #include 
@@ -802,12 +805,29 @@ if_input_local(struct ifnet *ifp, struct
 * is now incorrect, will be calculated before sending.
 */
keepcksum = m->m_pkthdr.csum_flags & (M_IPV4_CSUM_OUT |
-   M_TCP_CSUM_OUT | M_UDP_CSUM_OUT | M_ICMP_CSUM_OUT);
+   M_TCP_CSUM_OUT | M_UDP_CSUM_OUT | M_ICMP_CSUM_OUT |
+   M_TCP_TSO);
m_resethdr(m);
m->m_flags |= M_LOOP | keepflags;
m->m_pkthdr.csum_flags = keepcksum;
m->m_pkthdr.ph_ifidx = ifp->if_index;
m->m_pkthdr.ph_rtableid = ifp->if_rdomain;
+
+   if (ISSET(keepcksum, M_TCP_TSO) && m->m_pkthdr.len > ifp->if_mtu) {
+   if (ifp->if_mtu > 0 &&
+   ((af == AF_INET &&
+   ISSET(ifp->if_capabilities, IFCAP_TSOv4)) ||
+   (af == AF_INET6 &&
+   ISSET(ifp->if_capabilities, IFCAP_TSOv6 {
+   tcpstat_inc(tcps_inswlro);
+   tcpstat_add(tcps_inpktlro,
+   (m->m_pkthdr.len + ifp->if_mtu - 1) / ifp->if_mtu);
+   } else {
+   tcpstat_inc(tcps_inbadlro);
+   m_freem(m);
+   return (EPROTONOSUPPORT);
+   }
+   }
 
if (ISSET(keepcksum, M_TCP_CSUM_OUT))
m->m_pkthdr.csum_flags |= M_TCP_CSUM_IN_OK;
Index: sys/net/if_loop.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_loop.c,v
retrieving revision 1.94
diff -u -p -r1.94 if_loop.c
--- sys/net/if_loop.c   5 Jun 2023 11:35:46 -   1.94
+++ sys/net/if_loop.c   23 Jun 2023 15:48:27 -
@@ -175,7 +175,8 @@ loop_clone_create(struct if_clone *ifc, 
ifp->if_xflags = IFXF_CLONED;
ifp->if_capabilities = IFCAP_CSUM_IPv4 |
IFCAP_CSUM_TCPv4 | IFCAP_CSUM_UDPv4 |
-   IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6;
+   IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6 |
+   IFCAP_LRO;
ifp->if_rtrequest = lortrequest;
ifp->if_ioctl = loioctl;
ifp->if_input = loinput;
@@ -281,6 +282,10 @@ loioctl(struct ifnet *ifp, u_long cmd, c
 
switch (cmd) {
case SIOCSIFFLAGS:
+   if (ISSET(ifp->if_xflags, IFXF_LRO))
+   SET(ifp->if_capabilities, IFCAP_TSOv4 | IFCAP_TSOv6);
+   else
+   CLR(ifp->if_capabilities, IFCAP_TSOv4 | IFCAP_TSOv6);
break;
 
case SIOCSIFADDR:
Index: sys/netinet/tcp_usrreq.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_usrreq.c,v
retrieving revision 1.219
diff -u -p -r1.219 tcp_usrreq.c
--- sys/netinet/tcp_usrreq.c23 May 2023 09:16:16 -  1.219
+++ sys/netinet/tcp_usrreq.c23 Jun 2023 15:48:27 -
@@ -1340,6 +1340,7 @@ tcp_sysctl_tcpstat(void *oldp, size_t *o
ASSIGN(tcps_outhwtso);
ASSIGN(tcps_outpkttso);
ASSIGN(tcps_outbadtso);
+   ASSIGN(tcps_inswlro);
ASSIGN(tcps_inhwlro);
ASSIGN(tcps_inpktlro);
ASSIGN(tcps_inbadlro);
Index: sys/netinet/tcp_var.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_var.h,v
retrieving revision 1.167
diff -u -p -r1.167 tcp_var.h
--- sys/netinet/tcp_var.h   23 May 2023 09:16:16 -  1.167
+++ sys/netinet/tcp_var.h   23 Jun 2023 15:48:27 -
@@ -447,6 +447,7 @@ struct  tcpstat {
u_int32_t tcps_outhwtso;/* output tso processed by hardware */
u_int32_t tcps_outpkttso;   /* packets generated by tso */
u_int32_t tcps_outbadtso;   /* output tso failed, packet dropped */
+   u_int32_t tcps_inswlro; /* input lro on pseudo device */
u_int32_t tcps_inhwlro; /* input lro from hardware */
u_int32_t tcps_inpktlro;/* packets coalesced by hardware lro */
u_int32_t tcps_inbadlro;/* input bad lro packets */
@@ -628,6 +629,7 @@ enum tcpstat_cou

Re: smtpd: allow arguments on NOOP

2023-06-23 Thread Todd C . Miller
On Fri, 23 Jun 2023 11:58:47 +0200, Omar Polo wrote:

> another diff from the -portable repo:
>
>   https://github.com/OpenSMTPD/OpenSMTPD/pull/1150
>
> per rfc-5321 § 4.1.1.9 the NOOP command allows optionally one argument
> that we SHOULD ignore.
>
> The original diff set the check function in the commands table to NULL
> because NOOP is not a phase that can have filters.  However, I prefer
> to stay on the safe side and add a smtp_check_noop() function.
> Alternatively, we could allow a NULL check function in
> smtp_session_imsg().
>
> the rfc specifies only one optional string, while here for semplicity
> it's relaxed to allow anything.

This is a case where being liberal in what you accept seems fine.
OK millert@

 - todd



Re: profclock, gmonclock: new callbacks for profil(2)/GPROF statclock() code

2023-06-23 Thread Scott Cheloha
On Tue, Jun 20, 2023 at 08:35:11AM -0600, Theo de Raadt wrote:
> Claudio Jeker  wrote:
> 
> > On Mon, Jun 19, 2023 at 06:41:14PM -0500, Scott Cheloha wrote:
> > > > On Jun 19, 2023, at 18:07, Theo de Raadt  wrote:
> > > > 
> > > > ???Make sure to STOP all kernel profiling before attempting to
> > > >suspend or hibernate your machine.  Otherwise I expect it
> > > >will hang.
> > > > 
> > > > It is completely acceptable if it produces wrong results, but it must
> > > > not hang the system.
> > > 
> > > The hang is present in -current, with or
> > > without this patch.
> > > 
> > > I am working to figure it out.
> > 
> > I don't think the suspend or hibernate code has any code to disable
> > kernel profiling. This is bad since these code paths are extremly
> > sensitive and try not to do side-effects.
> > 
> > So in the suspend/hibernate code path we should disable profiling early
> > on. It makes no sense to try to run gprof collection in those code paths.
> 
> Yes, that's right.
> 
> It will be somewhere in kern/subr_suspend.c
> 
> Be careful that the "stop profiling" and "restart profiling" are at the
> correct places.  The sleep_state() function has a bunch of unrolling
> goto's which are not 100% reflexive, so be careful.

Judging from the blinking light on my laptop, the crash is in the
resume path.

This patch appears to fix the problem on amd64:

- Add a new guard variable, gmon_suspended,
- Toggle gmon_suspended off at the top of sleep_state(), and
- Toggle gmon_suspended back on at the bottom of sleep_state().

With this applied, I can suspend/resume and hibernate/unhibernate a an
amd64/GENERIC.MP kernel w/ GPROF without issue, even if kgmon(8) has
enabled kernel profiling and increased the effective statclock
frequency.

Index: sys/kern/subr_prof.c
===
RCS file: /cvs/src/sys/kern/subr_prof.c,v
retrieving revision 1.35
diff -u -p -r1.35 subr_prof.c
--- sys/kern/subr_prof.c2 Jun 2023 17:44:29 -   1.35
+++ sys/kern/subr_prof.c23 Jun 2023 21:25:51 -
@@ -34,6 +34,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -59,6 +60,31 @@ int gmoninit = 0;
 u_int gmon_cpu_count;  /* [K] number of CPUs with profiling enabled */
 
 extern char etext[];
+
+/*
+ * The suspend and hibernate paths need to be free
+ * of side effects.  Keep all CPUs out of _mcount()
+ * while a suspend/resume is ongoing.
+ */
+#ifdef SUSPEND
+volatile int gmon_suspended;
+
+void
+prof_resume(void)
+{
+   KASSERT(CPU_IS_PRIMARY(curcpu()));
+   gmon_suspended = 0;
+   membar_producer();
+}
+
+void
+prof_suspend(void)
+{
+   KASSERT(CPU_IS_PRIMARY(curcpu()));
+   gmon_suspended = 1;
+   membar_producer();
+}
+#endif /* SUSPEND */
 
 void
 prof_init(void)
Index: sys/kern/subr_suspend.c
===
RCS file: /cvs/src/sys/kern/subr_suspend.c,v
retrieving revision 1.14
diff -u -p -r1.14 subr_suspend.c
--- sys/kern/subr_suspend.c 10 Nov 2022 10:37:40 -  1.14
+++ sys/kern/subr_suspend.c 23 Jun 2023 21:25:51 -
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -63,6 +64,11 @@ top:
 
if (sleep_showstate(v, sleepmode))
return EOPNOTSUPP;
+
+#if defined(GPROF) || defined(DDBPROF)
+   prof_suspend();
+#endif
+
 #if NWSDISPLAY > 0
wsdisplay_suspend();
 #endif
@@ -193,6 +199,9 @@ fail_hiballoc:
start_periodic_resettodr();
 #if NWSDISPLAY > 0
wsdisplay_resume();
+#endif
+#if defined(GPROF) || defined(DDBPROF)
+   prof_resume();
 #endif
sys_sync(curproc, NULL, NULL);
if (cpu_setperf != NULL)
Index: sys/sys/gmon.h
===
RCS file: /cvs/src/sys/sys/gmon.h,v
retrieving revision 1.9
diff -u -p -r1.9 gmon.h
--- sys/sys/gmon.h  11 Jan 2022 23:59:55 -  1.9
+++ sys/sys/gmon.h  23 Jun 2023 21:25:51 -
@@ -158,6 +158,13 @@ struct gmonparam {
 #ifdef _KERNEL
 extern int gmoninit;   /* Is the kernel ready for being profiled? */
 
+#ifdef SUSPEND
+extern volatile int gmon_suspended;/* Ongoing suspend/resume? */
+
+void prof_resume(void);
+void prof_suspend(void);
+#endif
+
 #else /* !_KERNEL */
 
 #include 
Index: sys/lib/libkern/mcount.c
===
RCS file: /cvs/src/sys/lib/libkern/mcount.c,v
retrieving revision 1.14
diff -u -p -r1.14 mcount.c
--- sys/lib/libkern/mcount.c11 Jan 2022 09:21:34 -  1.14
+++ sys/lib/libkern/mcount.c23 Jun 2023 21:25:51 -
@@ -64,6 +64,10 @@ _MCOUNT_DECL(u_long frompc, u_long selfp
if (gmoninit == 0)
return;
 
+   /* Don't profile execution during suspend/resume. */
+   if (gmon_suspended)
+   return;
+
if ((p = curcpu()->ci_gmon) == NULL)
retur

Re: inpcb sip hash mutex contention

2023-06-23 Thread David Gwynne
makes sense to me, ok.

maybe it's time to re-evaluate siphash?

> On 23 Jun 2023, at 05:50, Alexander Bluhm  wrote:
> 
> Hi,
> 
> I am working on a diff to run UDP input in parallel.  Btrace kstack
> analysis shows that SIP hash for PCB lookup is quite expensive.
> When running in parallel we get lock contention on the PCB table
> mutex.
> 
> So it results in better performance to calculate the hash value
> before taking the mutex.  Code gets a bit more complicated as I
> have to pass the value around.
> 
> The hash secret has to be constant as hash calculation must not
> depend on values protected by the table mutex.  I see no security
> benefit in reseeding when the hash table gets resized.
> 
> Analysis also shows that asserting a rw_lock while holding a
> mutex is a bit expensive.  Just remove the netlock assert.
> 
> ok?
> 
> bluhm
> 
> Index: netinet/in_pcb.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
> retrieving revision 1.276
> diff -u -p -r1.276 in_pcb.c
> --- netinet/in_pcb.c 3 Oct 2022 16:43:52 - 1.276
> +++ netinet/in_pcb.c 22 Jun 2023 06:26:14 -
> @@ -121,15 +121,15 @@ struct baddynamicports rootonlyports;
> struct pool inpcb_pool;
> 
> void in_pcbhash_insert(struct inpcb *);
> -struct inpcb *in_pcbhash_lookup(struct inpcbtable *, u_int,
> +struct inpcb *in_pcbhash_lookup(struct inpcbtable *, uint64_t, u_int,
> const struct in_addr *, u_short, const struct in_addr *, u_short);
> int in_pcbresize(struct inpcbtable *, int);
> 
> #define INPCBHASH_LOADFACTOR(_x) (((_x) * 3) / 4)
> 
> -struct inpcbhead *in_pcbhash(struct inpcbtable *, u_int,
> +uint64_t in_pcbhash(struct inpcbtable *, u_int,
> const struct in_addr *, u_short, const struct in_addr *, u_short);
> -struct inpcbhead *in_pcblhash(struct inpcbtable *, u_int, u_short);
> +uint64_t in_pcblhash(struct inpcbtable *, u_int, u_short);
> 
> /*
>  * in_pcb is used for inet and inet6.  in6_pcb only contains special
> @@ -142,7 +142,7 @@ in_init(void)
>IPL_SOFTNET, 0, "inpcb", NULL);
> }
> 
> -struct inpcbhead *
> +uint64_t
> in_pcbhash(struct inpcbtable *table, u_int rdomain,
> const struct in_addr *faddr, u_short fport,
> const struct in_addr *laddr, u_short lport)
> @@ -156,11 +156,10 @@ in_pcbhash(struct inpcbtable *table, u_i
> SipHash24_Update(&ctx, &fport, sizeof(fport));
> SipHash24_Update(&ctx, laddr, sizeof(*laddr));
> SipHash24_Update(&ctx, &lport, sizeof(lport));
> -
> - return (&table->inpt_hashtbl[SipHash24_End(&ctx) & table->inpt_mask]);
> + return SipHash24_End(&ctx);
> }
> 
> -struct inpcbhead *
> +uint64_t
> in_pcblhash(struct inpcbtable *table, u_int rdomain, u_short lport)
> {
> SIPHASH_CTX ctx;
> @@ -169,8 +168,7 @@ in_pcblhash(struct inpcbtable *table, u_
> SipHash24_Init(&ctx, &table->inpt_lkey);
> SipHash24_Update(&ctx, &nrdom, sizeof(nrdom));
> SipHash24_Update(&ctx, &lport, sizeof(lport));
> -
> - return (&table->inpt_lhashtbl[SipHash24_End(&ctx) & table->inpt_lmask]);
> + return SipHash24_End(&ctx);
> }
> 
> void
> @@ -816,11 +814,14 @@ in_pcblookup_local(struct inpcbtable *ta
> struct in6_addr *laddr6 = (struct in6_addr *)laddrp;
> #endif
> struct inpcbhead *head;
> + uint64_t lhash;
> u_int rdomain;
> 
> rdomain = rtable_l2(rtable);
> + lhash = in_pcblhash(table, rdomain, lport);
> +
> mtx_enter(&table->inpt_mtx);
> - head = in_pcblhash(table, rdomain, lport);
> + head = &table->inpt_lhashtbl[lhash & table->inpt_lmask];
> LIST_FOREACH(inp, head, inp_lhash) {
> if (rtable_l2(inp->inp_rtableid) != rdomain)
> continue;
> @@ -1056,37 +1057,38 @@ in_pcbhash_insert(struct inpcb *inp)
> {
> struct inpcbtable *table = inp->inp_table;
> struct inpcbhead *head;
> + uint64_t hash, lhash;
> 
> - NET_ASSERT_LOCKED();
> MUTEX_ASSERT_LOCKED(&table->inpt_mtx);
> 
> - head = in_pcblhash(table, inp->inp_rtableid, inp->inp_lport);
> + lhash = in_pcblhash(table, inp->inp_rtableid, inp->inp_lport);
> + head = &table->inpt_lhashtbl[lhash & table->inpt_lmask];
> LIST_INSERT_HEAD(head, inp, inp_lhash);
> #ifdef INET6
> if (inp->inp_flags & INP_IPV6)
> - head = in6_pcbhash(table, rtable_l2(inp->inp_rtableid),
> + hash = in6_pcbhash(table, rtable_l2(inp->inp_rtableid),
>&inp->inp_faddr6, inp->inp_fport,
>&inp->inp_laddr6, inp->inp_lport);
> else
> #endif /* INET6 */
> - head = in_pcbhash(table, rtable_l2(inp->inp_rtableid),
> + hash = in_pcbhash(table, rtable_l2(inp->inp_rtableid),
>&inp->inp_faddr, inp->inp_fport,
>&inp->inp_laddr, inp->inp_lport);
> + head = &table->inpt_hashtbl[hash & table->inpt_mask];
> LIST_INSERT_HEAD(head, inp, inp_hash);
> }
> 
> struct inpcb *
> -in_pcbhash_lookup(struct inpcbtable *table, u_int rdomain,
> +in_pcbhash_lookup(struct inpcbtable *table, uint64_t hash, u_int rdomain,
> const struct in_addr *faddr, u_short fport,
> const struct in_addr *laddr, u_short lport)
> {
> struct inpcbhead *head;
> struct inpcb *inp;
> 
> - NET_ASSERT_LOCKED();
> MUTEX_ASSERT_LOCKED(&tabl