--- netinet/in_pcb.c.orig Fri Oct 24 10:57:51 2003 +++ netinet/in_pcb.c Fri Oct 24 15:45:10 2003 @@ -266,6 +266,11 @@ if (ntohs(lport) < IPPORT_RESERVED && (error = suser(p, 0))) return (EACCES); + /* + * XXX we could speed this up by returning the first + * match -- even if not the best -- should not affect + * the euid check. + */ if (so->so_euid) { t = in_pcblookup(table, &zeroin_addr, 0, &sin->sin_addr, lport, INPLOOKUP_WILDCARD); @@ -332,7 +337,7 @@ lport = htons(*lastport); } while (in_baddynamic(*lastport, so->so_proto->pr_protocol) || in_pcblookup(table, &zeroin_addr, 0, - &inp->inp_laddr, lport, wild)); + &inp->inp_laddr, lport, wild | INPLOOKUP_ANYMATCH)); } else { /* * counting up @@ -359,7 +364,7 @@ lport = htons(*lastport); } while (in_baddynamic(*lastport, so->so_proto->pr_protocol) || in_pcblookup(table, &zeroin_addr, 0, - &inp->inp_laddr, lport, wild)); + &inp->inp_laddr, lport, wild | INPLOOKUP_ANYMATCH)); } } inp->inp_lport = lport; @@ -787,7 +792,8 @@ if ((!wildcard || (flags & INPLOOKUP_WILDCARD)) && wildcard < matchwild) { match = inp; - if ((matchwild = wildcard) == 0) + if ((matchwild = wildcard) == 0 || + (flags & INPLOOKUP_ANYMATCH)) break; } } --- netinet/in_pcb.h.orig Fri Oct 24 10:57:57 2003 +++ netinet/in_pcb.h Fri Oct 24 15:46:12 2003 @@ -206,6 +206,13 @@ #define INPLOOKUP_WILDCARD 1 #define INPLOOKUP_SETLOCAL 2 #define INPLOOKUP_IPV6 4 +/* + * INPLOOKUP_ANYMATCH is used only toghether with INPLOOKUP_WILDCARD to + * indicate that any match will do it -- acctually won't do it. + * This will speedup in_pcblookup on long port lists because we can short + * circuit the search loop. + */ +#define INPLOOKUP_ANYMATCH 8 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)