MCPcopy Create free account
hub / github.com/F-Stack/f-stack / in_pcblookup_local

Function in_pcblookup_local

freebsd/netinet/in_pcb.c:2069–2184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2067 */
2068#define INP_LOOKUP_MAPPED_PCB_COST 3
2069struct inpcb *
2070in_pcblookup_local(struct inpcbinfo *pcbinfo, struct in_addr laddr,
2071 u_short lport, int lookupflags, struct ucred *cred)
2072{
2073 struct inpcb *inp;
2074#ifdef INET6
2075 int matchwild = 3 + INP_LOOKUP_MAPPED_PCB_COST;
2076#else
2077 int matchwild = 3;
2078#endif
2079 int wildcard;
2080
2081 KASSERT((lookupflags & ~(INPLOOKUP_WILDCARD)) == 0,
2082 ("%s: invalid lookup flags %d", __func__, lookupflags));
2083
2084 INP_HASH_LOCK_ASSERT(pcbinfo);
2085
2086 if ((lookupflags & INPLOOKUP_WILDCARD) == 0) {
2087 struct inpcbhead *head;
2088 /*
2089 * Look for an unconnected (wildcard foreign addr) PCB that
2090 * matches the local address and port we're looking for.
2091 */
2092 head = &pcbinfo->ipi_hashbase[INP_PCBHASH(INADDR_ANY, lport,
2093 0, pcbinfo->ipi_hashmask)];
2094 CK_LIST_FOREACH(inp, head, inp_hash) {
2095#ifdef INET6
2096 /* XXX inp locking */
2097 if ((inp->inp_vflag & INP_IPV4) == 0)
2098 continue;
2099#endif
2100 if (inp->inp_faddr.s_addr == INADDR_ANY &&
2101 inp->inp_laddr.s_addr == laddr.s_addr &&
2102 inp->inp_lport == lport) {
2103 /*
2104 * Found?
2105 */
2106 if (cred == NULL ||
2107 prison_equal_ip4(cred->cr_prison,
2108 inp->inp_cred->cr_prison))
2109 return (inp);
2110 }
2111 }
2112 /*
2113 * Not found.
2114 */
2115 return (NULL);
2116 } else {
2117 struct inpcbporthead *porthash;
2118 struct inpcbport *phd;
2119 struct inpcb *match = NULL;
2120 /*
2121 * Best fit PCB lookup.
2122 *
2123 * First see if this local port is in use by looking on the
2124 * port hash list.
2125 */
2126 porthash = &pcbinfo->ipi_porthashbase[INP_PCBPORTHASH(lport,

Callers 3

in_pcb.cFile · 0.85
in_pcbbind_setupFunction · 0.85
in6_pcbbindFunction · 0.85

Calls 1

prison_equal_ip4Function · 0.85

Tested by

no test coverage detected