Lines Matching refs:inp

131 static void	in_pcbremlists(struct inpcb *inp);
267 struct inpcb *inp;
272 inp = uma_zalloc(pcbinfo->ipi_zone, M_NOWAIT);
273 if (inp == NULL)
275 bzero(inp, inp_zero_size);
276 inp->inp_pcbinfo = pcbinfo;
277 inp->inp_socket = so;
278 inp->inp_cred = crhold(so->so_cred);
279 inp->inp_inc.inc_fibnum = so->so_fibnum;
281 error = mac_inpcb_init(inp, M_NOWAIT);
284 mac_inpcb_create(so, inp);
287 error = ipsec_init_policy(so, &inp->inp_sp);
290 mac_inpcb_destroy(inp);
297 inp->inp_vflag |= INP_IPV6PROTO;
299 inp->inp_flags |= IN6P_IPV6_V6ONLY;
302 LIST_INSERT_HEAD(pcbinfo->ipi_listhead, inp, inp_list);
304 so->so_pcb = (caddr_t)inp;
307 inp->inp_flags |= IN6P_AUTOFLOWLABEL;
309 INP_WLOCK(inp);
310 inp->inp_gencnt = ++pcbinfo->ipi_gencnt;
311 refcount_init(&inp->inp_refcount, 1); /* Reference from inpcbinfo */
315 crfree(inp->inp_cred);
316 uma_zfree(pcbinfo->ipi_zone, inp);
324 in_pcbbind(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred)
328 INP_WLOCK_ASSERT(inp);
329 INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
331 if (inp->inp_lport != 0 || inp->inp_laddr.s_addr != INADDR_ANY)
334 error = in_pcbbind_setup(inp, nam, &inp->inp_laddr.s_addr,
335 &inp->inp_lport, cred);
338 if (in_pcbinshash(inp) != 0) {
339 inp->inp_laddr.s_addr = INADDR_ANY;
340 inp->inp_lport = 0;
344 inp->inp_flags |= INP_ANONPORT;
351 in_pcb_lport(struct inpcb *inp, struct in_addr *laddrp, u_short *lportp,
363 pcbinfo = inp->inp_pcbinfo;
369 INP_LOCK_ASSERT(inp);
372 if (inp->inp_flags & INP_HIGHPORT) {
376 } else if (inp->inp_flags & INP_LOWPORT) {
423 if ((inp->inp_vflag & (INP_IPV4|INP_IPV6)) == INP_IPV4) {
424 KASSERT(laddrp != NULL, ("%s: laddrp NULL for v4 inp %p",
425 __func__, inp));
446 if ((inp->inp_vflag & INP_IPV6) != 0)
448 &inp->in6p_laddr, lport, lookupflags, cred);
460 if ((inp->inp_vflag & (INP_IPV4|INP_IPV6)) == INP_IPV4)
472 inp_so_options(const struct inpcb *inp)
478 if ((inp->inp_flags2 & INP_REUSEPORT) != 0)
480 if ((inp->inp_flags2 & INP_REUSEADDR) != 0)
497 in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp,
500 struct socket *so = inp->inp_socket;
502 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
511 INP_LOCK_ASSERT(inp);
564 if ((inp->inp_flags & INP_BINDANY) == 0 &&
580 priv_check_cred(inp->inp_cred,
595 (inp->inp_cred->cr_uid !=
618 (inp->inp_vflag & INP_IPV6PROTO) == 0 ||
628 error = in_pcb_lport(inp, &laddr, &lport, cred, lookupflags);
645 in_pcbconnect_mbuf(struct inpcb *inp, struct sockaddr *nam,
652 INP_WLOCK_ASSERT(inp);
653 INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
655 lport = inp->inp_lport;
656 laddr = inp->inp_laddr.s_addr;
658 error = in_pcbconnect_setup(inp, nam, &laddr, &lport, &faddr, &fport,
664 if (inp->inp_laddr.s_addr == INADDR_ANY && inp->inp_lport == 0) {
665 inp->inp_lport = lport;
666 inp->inp_laddr.s_addr = laddr;
667 if (in_pcbinshash(inp) != 0) {
668 inp->inp_laddr.s_addr = INADDR_ANY;
669 inp->inp_lport = 0;
675 inp->inp_lport = lport;
676 inp->inp_laddr.s_addr = laddr;
677 inp->inp_faddr.s_addr = faddr;
678 inp->inp_fport = fport;
679 in_pcbrehash_mbuf(inp, m);
682 inp->inp_flags |= INP_ANONPORT;
687 in_pcbconnect(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred)
690 return (in_pcbconnect_mbuf(inp, nam, cred, NULL));
698 in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr,
730 if ((inp->inp_socket->so_options & SO_DONTROUTE) == 0)
731 in_rtalloc_ign(&sro, 0, inp->inp_inc.inc_fibnum);
933 in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam,
948 INP_LOCK_ASSERT(inp);
949 INP_HASH_LOCK_ASSERT(inp->inp_pcbinfo);
990 error = in_pcbladdr(inp, &faddr, &laddr, cred);
997 inp->inp_moptions != NULL) {
1001 imo = inp->inp_moptions;
1024 oinp = in_pcblookup_hash_locked(inp->inp_pcbinfo, faddr, fport,
1032 error = in_pcbbind_setup(inp, NULL, &laddr.s_addr, &lport,
1045 in_pcbdisconnect(struct inpcb *inp)
1048 INP_WLOCK_ASSERT(inp);
1049 INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
1051 inp->inp_faddr.s_addr = INADDR_ANY;
1052 inp->inp_fport = 0;
1053 in_pcbrehash(inp);
1064 in_pcbdetach(struct inpcb *inp)
1067 KASSERT(inp->inp_socket != NULL, ("%s: inp_socket == NULL", __func__));
1069 inp->inp_socket->so_pcb = NULL;
1070 inp->inp_socket = NULL;
1093 in_pcbref(struct inpcb *inp)
1096 KASSERT(inp->inp_refcount > 0, ("%s: refcount 0", __func__));
1098 refcount_acquire(&inp->inp_refcount);
1114 in_pcbrele_rlocked(struct inpcb *inp)
1118 KASSERT(inp->inp_refcount > 0, ("%s: refcount 0", __func__));
1120 INP_RLOCK_ASSERT(inp);
1122 if (refcount_release(&inp->inp_refcount) == 0) {
1127 if (inp->inp_flags2 & INP_FREED) {
1128 INP_RUNLOCK(inp);
1134 KASSERT(inp->inp_socket == NULL, ("%s: inp_socket != NULL", __func__));
1136 INP_RUNLOCK(inp);
1137 pcbinfo = inp->inp_pcbinfo;
1138 uma_zfree(pcbinfo->ipi_zone, inp);
1143 in_pcbrele_wlocked(struct inpcb *inp)
1147 KASSERT(inp->inp_refcount > 0, ("%s: refcount 0", __func__));
1149 INP_WLOCK_ASSERT(inp);
1151 if (refcount_release(&inp->inp_refcount) == 0)
1154 KASSERT(inp->inp_socket == NULL, ("%s: inp_socket != NULL", __func__));
1156 INP_WUNLOCK(inp);
1157 pcbinfo = inp->inp_pcbinfo;
1158 uma_zfree(pcbinfo->ipi_zone, inp);
1166 in_pcbrele(struct inpcb *inp)
1169 return (in_pcbrele_wlocked(inp));
1182 in_pcbfree(struct inpcb *inp)
1184 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
1186 KASSERT(inp->inp_socket == NULL, ("%s: inp_socket != NULL", __func__));
1189 INP_WLOCK_ASSERT(inp);
1193 if (inp->inp_sp != NULL)
1194 ipsec_delete_pcbpolicy(inp);
1196 inp->inp_gencnt = ++pcbinfo->ipi_gencnt;
1197 in_pcbremlists(inp);
1199 if (inp->inp_vflag & INP_IPV6PROTO) {
1200 ip6_freepcbopts(inp->in6p_outputopts);
1201 if (inp->in6p_moptions != NULL)
1202 ip6_freemoptions(inp->in6p_moptions);
1205 if (inp->inp_options)
1206 (void)m_free(inp->inp_options);
1208 if (inp->inp_moptions != NULL)
1209 inp_freemoptions(inp->inp_moptions);
1211 inp->inp_vflag = 0;
1212 inp->inp_flags2 |= INP_FREED;
1213 crfree(inp->inp_cred);
1215 mac_inpcb_destroy(inp);
1217 if (!in_pcbrele_wlocked(inp))
1218 INP_WUNLOCK(inp);
1236 in_pcbdrop(struct inpcb *inp)
1239 INP_WLOCK_ASSERT(inp);
1245 inp->inp_flags |= INP_DROPPED;
1246 if (inp->inp_flags & INP_INHASHLIST) {
1247 struct inpcbport *phd = inp->inp_phd;
1249 INP_HASH_WLOCK(inp->inp_pcbinfo);
1250 LIST_REMOVE(inp, inp_hash);
1251 LIST_REMOVE(inp, inp_portlist);
1256 INP_HASH_WUNLOCK(inp->inp_pcbinfo);
1257 inp->inp_flags &= ~INP_INHASHLIST;
1259 in_pcbgroup_remove(inp);
1286 struct inpcb *inp;
1290 inp = sotoinpcb(so);
1291 KASSERT(inp != NULL, ("in_getsockaddr: inp == NULL"));
1293 INP_RLOCK(inp);
1294 port = inp->inp_lport;
1295 addr = inp->inp_laddr;
1296 INP_RUNLOCK(inp);
1305 struct inpcb *inp;
1309 inp = sotoinpcb(so);
1310 KASSERT(inp != NULL, ("in_getpeeraddr: inp == NULL"));
1312 INP_RLOCK(inp);
1313 port = inp->inp_fport;
1314 addr = inp->inp_faddr;
1315 INP_RUNLOCK(inp);
1325 struct inpcb *inp, *inp_temp;
1328 LIST_FOREACH_SAFE(inp, pcbinfo->ipi_listhead, inp_list, inp_temp) {
1329 INP_WLOCK(inp);
1331 if ((inp->inp_vflag & INP_IPV4) == 0) {
1332 INP_WUNLOCK(inp);
1336 if (inp->inp_faddr.s_addr != faddr.s_addr ||
1337 inp->inp_socket == NULL) {
1338 INP_WUNLOCK(inp);
1341 if ((*notify)(inp, errno))
1342 INP_WUNLOCK(inp);
1350 struct inpcb *inp;
1355 LIST_FOREACH(inp, pcbinfo->ipi_listhead, inp_list) {
1356 INP_WLOCK(inp);
1357 imo = inp->inp_moptions;
1358 if ((inp->inp_vflag & INP_IPV4) &&
1382 INP_WUNLOCK(inp);
1396 struct inpcb *inp;
1417 LIST_FOREACH(inp, head, inp_hash) {
1419 /* XXX inp locking */
1420 if ((inp->inp_vflag & INP_IPV4) == 0)
1423 if (inp->inp_faddr.s_addr == INADDR_ANY &&
1424 inp->inp_laddr.s_addr == laddr.s_addr &&
1425 inp->inp_lport == lport) {
1431 inp->inp_cred->cr_prison))
1432 return (inp);
1460 LIST_FOREACH(inp, &phd->phd_pcblist, inp_portlist) {
1463 !prison_equal_ip4(inp->inp_cred->cr_prison,
1467 /* XXX inp locking */
1468 if ((inp->inp_vflag & INP_IPV4) == 0)
1483 if ((inp->inp_vflag & INP_IPV6) != 0)
1486 if (inp->inp_faddr.s_addr != INADDR_ANY)
1488 if (inp->inp_laddr.s_addr != INADDR_ANY) {
1491 else if (inp->inp_laddr.s_addr != laddr.s_addr)
1498 match = inp;
1520 struct inpcb *inp, *tmpinp;
1530 LIST_FOREACH(inp, head, inp_pcbgrouphash) {
1532 /* XXX inp locking */
1533 if ((inp->inp_vflag & INP_IPV4) == 0)
1536 if (inp->inp_faddr.s_addr == faddr.s_addr &&
1537 inp->inp_laddr.s_addr == laddr.s_addr &&
1538 inp->inp_fport == fport &&
1539 inp->inp_lport == lport) {
1542 * the inp here, without any checks.
1545 if (prison_flag(inp->inp_cred, PR_IP4))
1548 tmpinp = inp;
1552 inp = tmpinp;
1577 LIST_FOREACH(inp, head, inp_pcbgroup_wild) {
1579 /* XXX inp locking */
1580 if ((inp->inp_vflag & INP_IPV4) == 0)
1583 if (inp->inp_faddr.s_addr != INADDR_ANY ||
1584 inp->inp_lport != lport)
1587 /* XXX inp locking */
1589 (inp->inp_flags & INP_FAITH) == 0)
1592 injail = prison_flag(inp->inp_cred, PR_IP4);
1594 if (prison_check_ip4(inp->inp_cred,
1602 if (inp->inp_laddr.s_addr == laddr.s_addr) {
1606 local_exact = inp;
1607 } else if (inp->inp_laddr.s_addr == INADDR_ANY) {
1609 /* XXX inp locking, NULL check */
1610 if (inp->inp_vflag & INP_IPV6PROTO)
1611 local_wild_mapped = inp;
1615 jail_wild = inp;
1617 local_wild = inp;
1620 inp = jail_wild;
1621 if (inp == NULL)
1622 inp = local_exact;
1623 if (inp == NULL)
1624 inp = local_wild;
1626 if (inp == NULL)
1627 inp = local_wild_mapped;
1629 if (inp != NULL)
1636 in_pcbref(inp);
1639 INP_WLOCK(inp);
1640 if (in_pcbrele_wlocked(inp))
1643 INP_RLOCK(inp);
1644 if (in_pcbrele_rlocked(inp))
1648 return (inp);
1663 struct inpcb *inp, *tmpinp;
1677 LIST_FOREACH(inp, head, inp_hash) {
1679 /* XXX inp locking */
1680 if ((inp->inp_vflag & INP_IPV4) == 0)
1683 if (inp->inp_faddr.s_addr == faddr.s_addr &&
1684 inp->inp_laddr.s_addr == laddr.s_addr &&
1685 inp->inp_fport == fport &&
1686 inp->inp_lport == lport) {
1689 * the inp here, without any checks.
1692 if (prison_flag(inp->inp_cred, PR_IP4))
1693 return (inp);
1695 tmpinp = inp;
1722 LIST_FOREACH(inp, head, inp_hash) {
1724 /* XXX inp locking */
1725 if ((inp->inp_vflag & INP_IPV4) == 0)
1728 if (inp->inp_faddr.s_addr != INADDR_ANY ||
1729 inp->inp_lport != lport)
1732 /* XXX inp locking */
1734 (inp->inp_flags & INP_FAITH) == 0)
1737 injail = prison_flag(inp->inp_cred, PR_IP4);
1739 if (prison_check_ip4(inp->inp_cred,
1747 if (inp->inp_laddr.s_addr == laddr.s_addr) {
1749 return (inp);
1751 local_exact = inp;
1752 } else if (inp->inp_laddr.s_addr == INADDR_ANY) {
1754 /* XXX inp locking, NULL check */
1755 if (inp->inp_vflag & INP_IPV6PROTO)
1756 local_wild_mapped = inp;
1760 jail_wild = inp;
1762 local_wild = inp;
1790 struct inpcb *inp;
1793 inp = in_pcblookup_hash_locked(pcbinfo, faddr, fport, laddr, lport,
1795 if (inp != NULL) {
1796 in_pcbref(inp);
1799 INP_WLOCK(inp);
1800 if (in_pcbrele_wlocked(inp))
1803 INP_RLOCK(inp);
1804 if (in_pcbrele_rlocked(inp))
1810 return (inp);
1880 in_pcbinshash_internal(struct inpcb *inp, int do_pcbgroup_update)
1884 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
1888 INP_WLOCK_ASSERT(inp);
1891 KASSERT((inp->inp_flags & INP_INHASHLIST) == 0,
1895 if (inp->inp_vflag & INP_IPV6)
1896 hashkey_faddr = inp->in6p_faddr.s6_addr32[3] /* XXX */;
1899 hashkey_faddr = inp->inp_faddr.s_addr;
1902 inp->inp_lport, inp->inp_fport, pcbinfo->ipi_hashmask)];
1905 INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_porthashmask)];
1911 if (phd->phd_port == inp->inp_lport)
1922 phd->phd_port = inp->inp_lport;
1926 inp->inp_phd = phd;
1927 LIST_INSERT_HEAD(&phd->phd_pcblist, inp, inp_portlist);
1928 LIST_INSERT_HEAD(pcbhash, inp, inp_hash);
1929 inp->inp_flags |= INP_INHASHLIST;
1932 in_pcbgroup_update(inp);
1949 in_pcbinshash(struct inpcb *inp)
1952 return (in_pcbinshash_internal(inp, 1));
1956 in_pcbinshash_nopcbgroup(struct inpcb *inp)
1959 return (in_pcbinshash_internal(inp, 0));
1969 in_pcbrehash_mbuf(struct inpcb *inp, struct mbuf *m)
1971 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
1975 INP_WLOCK_ASSERT(inp);
1978 KASSERT(inp->inp_flags & INP_INHASHLIST,
1982 if (inp->inp_vflag & INP_IPV6)
1983 hashkey_faddr = inp->in6p_faddr.s6_addr32[3] /* XXX */;
1986 hashkey_faddr = inp->inp_faddr.s_addr;
1989 inp->inp_lport, inp->inp_fport, pcbinfo->ipi_hashmask)];
1991 LIST_REMOVE(inp, inp_hash);
1992 LIST_INSERT_HEAD(head, inp, inp_hash);
1996 in_pcbgroup_update_mbuf(inp, m);
1998 in_pcbgroup_update(inp);
2003 in_pcbrehash(struct inpcb *inp)
2006 in_pcbrehash_mbuf(inp, NULL);
2013 in_pcbremlists(struct inpcb *inp)
2015 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
2018 INP_WLOCK_ASSERT(inp);
2020 inp->inp_gencnt = ++pcbinfo->ipi_gencnt;
2021 if (inp->inp_flags & INP_INHASHLIST) {
2022 struct inpcbport *phd = inp->inp_phd;
2025 LIST_REMOVE(inp, inp_hash);
2026 LIST_REMOVE(inp, inp_portlist);
2032 inp->inp_flags &= ~INP_INHASHLIST;
2034 LIST_REMOVE(inp, inp_list);
2037 in_pcbgroup_remove(inp);
2049 struct inpcb *inp;
2051 inp = sotoinpcb(so);
2052 KASSERT(inp != NULL, ("in_pcbsosetlabel: so->so_pcb == NULL"));
2054 INP_WLOCK(inp);
2056 mac_inpcb_sosetlabel(so, inp);
2058 INP_WUNLOCK(inp);
2115 inp_wlock(struct inpcb *inp)
2118 INP_WLOCK(inp);
2122 inp_wunlock(struct inpcb *inp)
2125 INP_WUNLOCK(inp);
2129 inp_rlock(struct inpcb *inp)
2132 INP_RLOCK(inp);
2136 inp_runlock(struct inpcb *inp)
2139 INP_RUNLOCK(inp);
2144 inp_lock_assert(struct inpcb *inp)
2147 INP_WLOCK_ASSERT(inp);
2151 inp_unlock_assert(struct inpcb *inp)
2154 INP_UNLOCK_ASSERT(inp);
2161 struct inpcb *inp;
2164 LIST_FOREACH(inp, V_tcbinfo.ipi_listhead, inp_list) {
2165 INP_WLOCK(inp);
2166 func(inp, arg);
2167 INP_WUNLOCK(inp);
2173 inp_inpcbtosocket(struct inpcb *inp)
2176 INP_WLOCK_ASSERT(inp);
2177 return (inp->inp_socket);
2181 inp_inpcbtotcpcb(struct inpcb *inp)
2184 INP_WLOCK_ASSERT(inp);
2185 return ((struct tcpcb *)inp->inp_ppcb);
2189 inp_ip_tos_get(const struct inpcb *inp)
2192 return (inp->inp_ip_tos);
2196 inp_ip_tos_set(struct inpcb *inp, int val)
2199 inp->inp_ip_tos = val;
2203 inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp,
2207 INP_LOCK_ASSERT(inp);
2208 *laddr = inp->inp_laddr.s_addr;
2209 *faddr = inp->inp_faddr.s_addr;
2210 *lp = inp->inp_lport;
2211 *fp = inp->inp_fport;
2409 db_print_inpcb(struct inpcb *inp, const char *name, int indent)
2413 db_printf("%s at %p\n", name, inp);
2418 db_printf("inp_flow: 0x%x\n", inp->inp_flow);
2420 db_print_inconninfo(&inp->inp_inc, "inp_conninfo", indent);
2424 inp->inp_ppcb, inp->inp_pcbinfo, inp->inp_socket);
2428 inp->inp_label, inp->inp_flags);
2429 db_print_inpflags(inp->inp_flags);
2433 db_printf("inp_sp: %p inp_vflag: 0x%x (", inp->inp_sp,
2434 inp->inp_vflag);
2435 db_print_inpvflag(inp->inp_vflag);
2440 inp->inp_ip_ttl, inp->inp_ip_p, inp->inp_ip_minttl);
2444 if (inp->inp_vflag & INP_IPV6) {
2446 "in6p_moptions: %p\n", inp->in6p_options,
2447 inp->in6p_outputopts, inp->in6p_moptions);
2449 "in6p_hops %u\n", inp->in6p_icmp6filt, inp->in6p_cksum,
2450 inp->in6p_hops);
2455 "inp_ip_moptions: %p\n", inp->inp_ip_tos,
2456 inp->inp_options, inp->inp_moptions);
2460 db_printf("inp_phd: %p inp_gencnt: %ju\n", inp->inp_phd,
2461 (uintmax_t)inp->inp_gencnt);
2466 struct inpcb *inp;
2472 inp = (struct inpcb *)addr;
2474 db_print_inpcb(inp, "inpcb", 0);