40#ifndef _NETINET_IN_PCB_H_
41#define _NETINET_IN_PCB_H_
46#include <sys/_mutex.h>
47#include <sys/_rwlock.h>
53#include <sys/rwlock.h>
55#include <sys/sysctl.h>
102#define ie_faddr ie_dependfaddr.id46_addr.ia46_addr4
103#define ie_laddr ie_dependladdr.id46_addr.ia46_addr4
104#define ie6_faddr ie_dependfaddr.id6_addr
105#define ie6_laddr ie_dependladdr.id6_addr
124#define INC_ISIPV6 0x01
125#define INC_IPV6MINMTU 0x02
127#define inc_fport inc_ie.ie_fport
128#define inc_lport inc_ie.ie_lport
129#define inc_faddr inc_ie.ie_faddr
130#define inc_laddr inc_ie.ie_laddr
131#define inc6_faddr inc_ie.ie6_faddr
132#define inc6_laddr inc_ie.ie6_laddr
133#define inc6_zoneid inc_ie.ie6_zoneid
135#if defined(_KERNEL) || defined(_WANT_INPCB)
222#define inp_start_zero inp_hpts
223#define inp_zero_size (sizeof(struct inpcb) - \
224 offsetof(struct inpcb, inp_start_zero))
238#if defined(__amd64__) || defined(__i386__)
308#define inp_fport inp_inc.inc_fport
309#define inp_lport inp_inc.inc_lport
310#define inp_faddr inp_inc.inc_faddr
311#define inp_laddr inp_inc.inc_laddr
313#define in6p_faddr inp_inc.inc6_faddr
314#define in6p_laddr inp_inc.inc6_laddr
315#define in6p_zoneid inp_inc.inc6_zoneid
317#define inp_vnet inp_pcbinfo->ipi_vnet
338#ifdef _SYS_SOCKETVAR_H_
341 struct xsocket xi_socket;
345 int64_t inp_spare64[4];
351 int32_t inp_rss_listen_bucket;
353 int32_t inp_spare32[4];
361 int8_t inp_spare8[4];
370 uint64_t _xig_spare64[4];
373struct sockopt_parameters {
383 int (*ctloutput_set)(
struct inpcb *,
struct sockopt *));
474#define INPCBSTORAGE_DEFINE(prot, lname, zname, iname, hname) \
476prot##_inpcb_init(void *mem, int size __unused, int flags __unused) \
478 struct inpcb *inp = mem; \
480 rw_init_flags(&inp->inp_lock, lname, RW_RECURSE | RW_DUPOK); \
483static struct inpcbstorage prot = { \
484 .ips_pcbinit = prot##_inpcb_init, \
485 .ips_zone_name = zname, \
486 .ips_portzone_name = zname " ports", \
487 .ips_infolock_name = iname, \
488 .ips_hashlock_name = hname, \
490SYSINIT(prot##_inpcbstorage_init, SI_SUB_PROTO_DOMAIN, \
491 SI_ORDER_SECOND, in_pcbstorage_init, &prot); \
492SYSUNINIT(prot##_inpcbstorage_uninit, SI_SUB_PROTO_DOMAIN, \
493 SI_ORDER_SECOND, in_pcbstorage_destroy, &prot)
509#define il_laddr il_dependladdr.id46_addr.ia46_addr4
510#define il6_laddr il_dependladdr.id6_addr
516#define INP_LOCK_DESTROY(inp) rw_destroy(&(inp)->inp_lock)
517#define INP_RLOCK(inp) rw_rlock(&(inp)->inp_lock)
518#define INP_WLOCK(inp) rw_wlock(&(inp)->inp_lock)
519#define INP_TRY_RLOCK(inp) rw_try_rlock(&(inp)->inp_lock)
520#define INP_TRY_WLOCK(inp) rw_try_wlock(&(inp)->inp_lock)
521#define INP_RUNLOCK(inp) rw_runlock(&(inp)->inp_lock)
522#define INP_WUNLOCK(inp) rw_wunlock(&(inp)->inp_lock)
523#define INP_UNLOCK(inp) rw_unlock(&(inp)->inp_lock)
524#define INP_TRY_UPGRADE(inp) rw_try_upgrade(&(inp)->inp_lock)
525#define INP_DOWNGRADE(inp) rw_downgrade(&(inp)->inp_lock)
526#define INP_WLOCKED(inp) rw_wowned(&(inp)->inp_lock)
527#define INP_LOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_LOCKED)
528#define INP_RLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_RLOCKED)
529#define INP_WLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_WLOCKED)
530#define INP_UNLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_UNLOCKED)
542#ifdef INVARIANT_SUPPORT
546#define inp_lock_assert(inp) do {} while (0)
547#define inp_unlock_assert(inp) do {} while (0)
563#define INP_INFO_WLOCK(ipi) mtx_lock(&(ipi)->ipi_lock)
564#define INP_INFO_WLOCKED(ipi) mtx_owned(&(ipi)->ipi_lock)
565#define INP_INFO_WUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_lock)
566#define INP_INFO_LOCK_ASSERT(ipi) MPASS(SMR_ENTERED((ipi)->ipi_smr) || \
567 mtx_owned(&(ipi)->ipi_lock))
568#define INP_INFO_WLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_lock, MA_OWNED)
569#define INP_INFO_WUNLOCK_ASSERT(ipi) \
570 mtx_assert(&(ipi)->ipi_lock, MA_NOTOWNED)
572#define INP_HASH_WLOCK(ipi) mtx_lock(&(ipi)->ipi_hash_lock)
573#define INP_HASH_WUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_hash_lock)
574#define INP_HASH_LOCK_ASSERT(ipi) MPASS(SMR_ENTERED((ipi)->ipi_smr) || \
575 mtx_owned(&(ipi)->ipi_hash_lock))
576#define INP_HASH_WLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_hash_lock, \
586#define IN_ADDR_JHASH32(addr) \
587 ((addr)->s_addr == INADDR_ANY ? V_in_pcbhashseed : \
588 jenkins_hash32((&(addr)->s_addr), 1, V_in_pcbhashseed))
589#define IN6_ADDR_JHASH32(addr) \
590 (memcmp((addr), &in6addr_any, sizeof(in6addr_any)) == 0 ? \
592 jenkins_hash32((addr)->__u6_addr.__u6_addr32, \
593 nitems((addr)->__u6_addr.__u6_addr32), V_in_pcbhashseed))
595#define INP_PCBHASH(faddr, lport, fport, mask) \
596 ((IN_ADDR_JHASH32(faddr) ^ ntohs((lport) ^ (fport))) & (mask))
597#define INP6_PCBHASH(faddr, lport, fport, mask) \
598 ((IN6_ADDR_JHASH32(faddr) ^ ntohs((lport) ^ (fport))) & (mask))
600#define INP_PCBHASH_WILD(lport, mask) \
601 ((V_in_pcbhashseed ^ ntohs(lport)) & (mask))
603#define INP_PCBLBGROUP_PKTHASH(faddr, lport, fport) \
604 (IN_ADDR_JHASH32(faddr) ^ ntohs((lport) ^ (fport)))
605#define INP6_PCBLBGROUP_PKTHASH(faddr, lport, fport) \
606 (IN6_ADDR_JHASH32(faddr) ^ ntohs((lport) ^ (fport)))
608#define INP_PCBPORTHASH(lport, mask) (ntohs((lport)) & (mask))
615#define INP_IPV6PROTO 0x4
620#define INP_RECVOPTS 0x00000001
621#define INP_RECVRETOPTS 0x00000002
622#define INP_RECVDSTADDR 0x00000004
623#define INP_HDRINCL 0x00000008
624#define INP_HIGHPORT 0x00000010
625#define INP_LOWPORT 0x00000020
626#define INP_ANONPORT 0x00000040
627#define INP_RECVIF 0x00000080
628#define INP_MTUDISC 0x00000100
630#define INP_RECVTTL 0x00000400
631#define INP_DONTFRAG 0x00000800
632#define INP_BINDANY 0x00001000
633#define INP_INHASHLIST 0x00002000
634#define INP_RECVTOS 0x00004000
635#define IN6P_IPV6_V6ONLY 0x00008000
636#define IN6P_PKTINFO 0x00010000
637#define IN6P_HOPLIMIT 0x00020000
638#define IN6P_HOPOPTS 0x00040000
639#define IN6P_DSTOPTS 0x00080000
640#define IN6P_RTHDR 0x00100000
641#define IN6P_RTHDRDSTOPTS 0x00200000
642#define IN6P_TCLASS 0x00400000
643#define IN6P_AUTOFLOWLABEL 0x00800000
644#define INP_TIMEWAIT 0x01000000
645#define INP_ONESBCAST 0x02000000
646#define INP_DROPPED 0x04000000
647#define INP_SOCKREF 0x08000000
648#define INP_RESERVED_0 0x10000000
649#define INP_RESERVED_1 0x20000000
650#define IN6P_RFC2292 0x40000000
651#define IN6P_MTU 0x80000000
653#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
654 INP_RECVIF|INP_RECVTTL|INP_RECVTOS|\
655 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
656 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
657 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
663#define INP_MBUF_L_ACKS 0x00000001
664#define INP_MBUF_ACKCMP 0x00000002
666#define INP_REUSEPORT 0x00000008
668#define INP_REUSEADDR 0x00000020
669#define INP_BINDMULTI 0x00000040
670#define INP_RSS_BUCKET_SET 0x00000080
671#define INP_RECVFLOWID 0x00000100
672#define INP_RECVRSSBUCKETID 0x00000200
673#define INP_RATE_LIMIT_CHANGED 0x00000400
674#define INP_ORIGDSTADDR 0x00000800
675#define INP_CANNOT_DO_ECN 0x00001000
676#define INP_REUSEPORT_LB 0x00002000
677#define INP_SUPPORTS_MBUFQ 0x00004000
678#define INP_MBUF_QUEUE_READY 0x00008000
679#define INP_DONT_SACK_QUEUE 0x00010000
680#define INP_2PCP_SET 0x00020000
681#define INP_2PCP_BIT0 0x00040000
682#define INP_2PCP_BIT1 0x00080000
683#define INP_2PCP_BIT2 0x00100000
684#define INP_2PCP_BASE INP_2PCP_BIT0
685#define INP_2PCP_MASK (INP_2PCP_BIT0 | INP_2PCP_BIT1 | INP_2PCP_BIT2)
686#define INP_2PCP_SHIFT 18
697#define INPLOOKUP_MASK (INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB | \
699#define INPLOOKUP_LOCKMASK (INPLOOKUP_RLOCKPCB | INPLOOKUP_WLOCKPCB)
701#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
703#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
705#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
722#define V_ipport_reservedhigh VNET(ipport_reservedhigh)
723#define V_ipport_reservedlow VNET(ipport_reservedlow)
724#define V_ipport_lowfirstauto VNET(ipport_lowfirstauto)
725#define V_ipport_lowlastauto VNET(ipport_lowlastauto)
726#define V_ipport_firstauto VNET(ipport_firstauto)
727#define V_ipport_lastauto VNET(ipport_lastauto)
728#define V_ipport_hifirstauto VNET(ipport_hifirstauto)
729#define V_ipport_hilastauto VNET(ipport_hilastauto)
730#define V_ipport_randomized VNET(ipport_randomized)
731#define V_ipport_randomcps VNET(ipport_randomcps)
732#define V_ipport_randomtime VNET(ipport_randomtime)
733#define V_ipport_stoprandom VNET(ipport_stoprandom)
734#define V_ipport_tcpallocs VNET(ipport_tcpallocs)
743 const struct inpcb *oi);
749 u_short *,
struct ucred *);
764 struct in_addr, u_int,
int,
struct ifnet *);
767 struct in_addr, u_int,
int,
struct ifnet *,
struct mbuf *);
782#define INP_ALL_LIST -1
787#define INP_ITERATOR(_ipi, _lock, _match, _ctx) \
791 .hash = INP_ALL_LIST, \
795#define INP_ALL_ITERATOR(_ipi, _lock) \
799 .hash = INP_ALL_LIST, \
812in_pcboutput_txrtlmt_locked(
struct inpcb *,
struct ifnet *,
816void in_pcbdetach_txrtlmt(
struct inpcb *);
817void in_pcbdetach_tag(
struct m_snd_tag *);
821void in_pcboutput_txrtlmt(
struct inpcb *,
struct ifnet *,
struct mbuf *);
822void in_pcboutput_eagain(
struct inpcb *);
void in_pcbtoxinpcb(const struct inpcb *inp, struct xinpcb *xi)
int sysctl_setsockopt(SYSCTL_HANDLER_ARGS, struct inpcbinfo *pcbinfo, int(*ctloutput_set)(struct inpcb *, struct sockopt *))
struct inpcb * inp_next(struct inpcb_iterator *)
void in_pcbdetach(struct inpcb *)
void inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp, uint32_t *faddr, uint16_t *fp)
void in_pcbsetsolabel(struct socket *so)
void in_pcbfree(struct inpcb *)
struct tcpcb * inp_inpcbtotcpcb(struct inpcb *inp)
void inp_ip_tos_set(struct inpcb *inp, int val)
void inp_rlock(struct inpcb *)
void in_pcbdisconnect(struct inpcb *)
VNET_DECLARE(int, ipport_reservedhigh)
void in_pcbinfo_init(struct inpcbinfo *, struct inpcbstorage *, u_int, u_int)
struct inpcb * in_pcblookup(struct inpcbinfo *, struct in_addr, u_int, struct in_addr, u_int, int, struct ifnet *)
bool in_pcbrele_rlocked(struct inpcb *)
struct socket * inp_inpcbtosocket(struct inpcb *inp)
int in_getsockaddr(struct socket *so, struct sockaddr **nam)
void inp_apply_all(void(*func)(struct inpcb *, void *), void *arg)
CK_LIST_HEAD(inpcbhead, inpcb)
void in_pcbsosetlabel(struct socket *so)
int in_pcbladdr(struct inpcb *, struct in_addr *, struct in_addr *, struct ucred *)
int in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *, u_short *, in_addr_t *, u_short *, struct inpcb **, struct ucred *)
#define inp_lock_assert(inp)
int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *)
#define inp_unlock_assert(inp)
bool in_pcbrele_wlocked(struct inpcb *)
int in_pcblbgroup_numa(struct inpcb *, int arg)
int in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *, u_short *, struct ucred *)
void in_pcbref(struct inpcb *)
int in_getpeeraddr(struct socket *so, struct sockaddr **nam)
void in_pcbinfo_destroy(struct inpcbinfo *)
int in_pcballoc(struct socket *, struct inpcbinfo *)
void inp_runlock(struct inpcb *)
void inp_wlock(struct inpcb *)
bool inp_match_t(const struct inpcb *, void *)
int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *, bool)
void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *)
int in_pcbinshash(struct inpcb *)
void inp_wunlock(struct inpcb *)
struct inpcb * in_pcblookup_mbuf(struct inpcbinfo *, struct in_addr, u_int, struct in_addr, u_int, int, struct ifnet *, struct mbuf *)
void in_pcbstorage_init(void *)
int inp_so_options(const struct inpcb *inp)
void in_pcbrehash(struct inpcb *)
void in_losing(struct inpcb *)
int inp_ip_tos_get(const struct inpcb *inp)
void in_pcbstorage_destroy(void *)
void in_pcbdrop(struct inpcb *)
struct sockaddr * in_sockaddr(in_port_t port, struct in_addr *addr)
void in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr, int, struct inpcb *(*)(struct inpcb *, int))
int in_pcbbind_check_bindmulti(const struct inpcb *ni, const struct inpcb *oi)
struct ip_timestamp __aligned
struct in_addr ia46_addr4
struct in_endpoints inc_ie
union in_dependaddr ie_dependladdr
union in_dependaddr ie_dependfaddr
const struct inpcbinfo * ipi
uint32_t inp_rss_listen_bucket
CK_LIST_ENTRY(inpcb) inp_list
struct socket * inp_socket
struct inpcbport * inp_phd
struct icmp6_filter * in6p_icmp6filt
struct ip6_pktopts * in6p_outputopts
volatile uint16_t inp_hpts_cpu
struct route_in6 inp_route6
struct inpcbpolicy * inp_sp
struct mbuf * inp_options
struct m_snd_tag * inp_snd_tag
struct ip6_moptions * in6p_moptions
TAILQ_ENTRY(inpcb) inp_hpts
struct ip_moptions * inp_moptions
CK_LIST_ENTRY(inpcb) inp_hash
uint32_t inp_hpts_request
uint32_t inp_hpts_drop_reas
struct inpcbinfo * inp_pcbinfo
CK_LIST_ENTRY(inpcb) inp_portlist
struct mbuf * in6p_options
volatile uint16_t inp_irq_cpu
struct in_conninfo inp_inc
struct inpcbhead * ipi_hashbase
struct inpcblbgrouphead * ipi_lbgrouphashbase
u_long ipi_lbgrouphashmask
struct inpcbporthead * ipi_porthashbase
struct inpcbhead ipi_listhead
CK_LIST_ENTRY(inpcblbgroup) il_list
union in_dependaddr il_dependladdr
struct epoch_context il_epoch_ctx
const char * ips_zone_name
const char * ips_portzone_name
const char * ips_hashlock_name
const char * ips_infolock_name
struct in_addr_4in6 id46_addr