michael@0: /*- michael@0: * Copyright (c) 1982, 1986, 1990, 1993 michael@0: * The Regents of the University of California. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * 4. Neither the name of the University nor the names of its contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND michael@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE michael@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL michael@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS michael@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT michael@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY michael@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@0: * SUCH DAMAGE. michael@0: * michael@0: * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 michael@0: * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.100.2.1 2007/12/07 05:46:08 kmacy Exp $ michael@0: */ michael@0: michael@0: #ifndef _USER_INPCB_H_ michael@0: #define _USER_INPCB_H_ michael@0: michael@0: #include /* was */ michael@0: michael@0: #define in6pcb inpcb /* for KAME src sync over BSD*'s */ michael@0: #define in6p_sp inp_sp /* for KAME src sync over BSD*'s */ michael@0: struct inpcbpolicy; michael@0: michael@0: /* michael@0: * Struct inpcb is the ommon structure pcb for the Internet Protocol michael@0: * implementation. michael@0: * michael@0: * Pointers to local and foreign host table entries, local and foreign socket michael@0: * numbers, and pointers up (to a socket structure) and down (to a michael@0: * protocol-specific control block) are stored here. michael@0: */ michael@0: LIST_HEAD(inpcbhead, inpcb); michael@0: LIST_HEAD(inpcbporthead, inpcbport); michael@0: michael@0: /* michael@0: * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet. michael@0: * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing michael@0: * the following structure. michael@0: */ michael@0: struct in_addr_4in6 { michael@0: u_int32_t ia46_pad32[3]; michael@0: struct in_addr ia46_addr4; michael@0: }; michael@0: michael@0: /* michael@0: * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553. in_conninfo has michael@0: * some extra padding to accomplish this. michael@0: */ michael@0: struct in_endpoints { michael@0: u_int16_t ie_fport; /* foreign port */ michael@0: u_int16_t ie_lport; /* local port */ michael@0: /* protocol dependent part, local and foreign addr */ michael@0: union { michael@0: /* foreign host table entry */ michael@0: struct in_addr_4in6 ie46_foreign; michael@0: struct in6_addr ie6_foreign; michael@0: } ie_dependfaddr; michael@0: union { michael@0: /* local host table entry */ michael@0: struct in_addr_4in6 ie46_local; michael@0: struct in6_addr ie6_local; michael@0: } ie_dependladdr; michael@0: #define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4 michael@0: #define ie_laddr ie_dependladdr.ie46_local.ia46_addr4 michael@0: #define ie6_faddr ie_dependfaddr.ie6_foreign michael@0: #define ie6_laddr ie_dependladdr.ie6_local michael@0: }; michael@0: michael@0: /* michael@0: * XXX The defines for inc_* are hacks and should be changed to direct michael@0: * references. michael@0: */ michael@0: struct in_conninfo { michael@0: u_int8_t inc_flags; michael@0: u_int8_t inc_len; michael@0: u_int16_t inc_pad; /* XXX alignment for in_endpoints */ michael@0: /* protocol dependent part */ michael@0: struct in_endpoints inc_ie; michael@0: }; michael@0: #define inc_isipv6 inc_flags /* temp compatability */ michael@0: #define inc_fport inc_ie.ie_fport michael@0: #define inc_lport inc_ie.ie_lport michael@0: #define inc_faddr inc_ie.ie_faddr michael@0: #define inc_laddr inc_ie.ie_laddr michael@0: #define inc6_faddr inc_ie.ie6_faddr michael@0: #define inc6_laddr inc_ie.ie6_laddr michael@0: michael@0: struct icmp6_filter; michael@0: michael@0: struct inpcb { michael@0: LIST_ENTRY(inpcb) inp_hash; /* hash list */ michael@0: LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */ michael@0: void *inp_ppcb; /* pointer to per-protocol pcb */ michael@0: struct inpcbinfo *inp_pcbinfo; /* PCB list info */ michael@0: struct socket *inp_socket; /* back pointer to socket */ michael@0: michael@0: u_int32_t inp_flow; michael@0: int inp_flags; /* generic IP/datagram flags */ michael@0: michael@0: u_char inp_vflag; /* IP version flag (v4/v6) */ michael@0: #define INP_IPV4 0x1 michael@0: #define INP_IPV6 0x2 michael@0: #define INP_IPV6PROTO 0x4 /* opened under IPv6 protocol */ michael@0: #define INP_TIMEWAIT 0x8 /* .. probably doesn't go here */ michael@0: #define INP_ONESBCAST 0x10 /* send all-ones broadcast */ michael@0: #define INP_DROPPED 0x20 /* protocol drop flag */ michael@0: #define INP_SOCKREF 0x40 /* strong socket reference */ michael@0: #define INP_CONN 0x80 michael@0: u_char inp_ip_ttl; /* time to live proto */ michael@0: u_char inp_ip_p; /* protocol proto */ michael@0: u_char inp_ip_minttl; /* minimum TTL or drop */ michael@0: uint32_t inp_ispare1; /* connection id / queue id */ michael@0: void *inp_pspare[2]; /* rtentry / general use */ michael@0: michael@0: /* Local and foreign ports, local and foreign addr. */ michael@0: struct in_conninfo inp_inc; michael@0: michael@0: /* list for this PCB's local port */ michael@0: struct label *inp_label; /* MAC label */ michael@0: struct inpcbpolicy *inp_sp; /* for IPSEC */ michael@0: michael@0: /* Protocol-dependent part; options. */ michael@0: struct { michael@0: u_char inp4_ip_tos; /* type of service proto */ michael@0: struct mbuf *inp4_options; /* IP options */ michael@0: struct ip_moptions *inp4_moptions; /* IP multicast options */ michael@0: } inp_depend4; michael@0: #define inp_fport inp_inc.inc_fport michael@0: #define inp_lport inp_inc.inc_lport michael@0: #define inp_faddr inp_inc.inc_faddr michael@0: #define inp_laddr inp_inc.inc_laddr michael@0: #define inp_ip_tos inp_depend4.inp4_ip_tos michael@0: #define inp_options inp_depend4.inp4_options michael@0: #define inp_moptions inp_depend4.inp4_moptions michael@0: struct { michael@0: /* IP options */ michael@0: struct mbuf *inp6_options; michael@0: /* IP6 options for outgoing packets */ michael@0: struct ip6_pktopts *inp6_outputopts; michael@0: /* IP multicast options */ michael@0: #if 0 michael@0: struct ip6_moptions *inp6_moptions; michael@0: #endif michael@0: /* ICMPv6 code type filter */ michael@0: struct icmp6_filter *inp6_icmp6filt; michael@0: /* IPV6_CHECKSUM setsockopt */ michael@0: int inp6_cksum; michael@0: short inp6_hops; michael@0: } inp_depend6; michael@0: LIST_ENTRY(inpcb) inp_portlist; michael@0: struct inpcbport *inp_phd; /* head of this list */ michael@0: #define inp_zero_size offsetof(struct inpcb, inp_gencnt) michael@0: struct mtx inp_mtx; michael@0: michael@0: #define in6p_faddr inp_inc.inc6_faddr michael@0: #define in6p_laddr inp_inc.inc6_laddr michael@0: #define in6p_hops inp_depend6.inp6_hops /* default hop limit */ michael@0: #define in6p_ip6_nxt inp_ip_p michael@0: #define in6p_flowinfo inp_flow michael@0: #define in6p_vflag inp_vflag michael@0: #define in6p_options inp_depend6.inp6_options michael@0: #define in6p_outputopts inp_depend6.inp6_outputopts michael@0: #if 0 michael@0: #define in6p_moptions inp_depend6.inp6_moptions michael@0: #endif michael@0: #define in6p_icmp6filt inp_depend6.inp6_icmp6filt michael@0: #define in6p_cksum inp_depend6.inp6_cksum michael@0: #define in6p_flags inp_flags /* for KAME src sync over BSD*'s */ michael@0: #define in6p_socket inp_socket /* for KAME src sync over BSD*'s */ michael@0: #define in6p_lport inp_lport /* for KAME src sync over BSD*'s */ michael@0: #define in6p_fport inp_fport /* for KAME src sync over BSD*'s */ michael@0: #define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */ michael@0: }; michael@0: /* michael@0: * The range of the generation count, as used in this implementation, is 9e19. michael@0: * We would have to create 300 billion connections per second for this number michael@0: * to roll over in a year. This seems sufficiently unlikely that we simply michael@0: * don't concern ourselves with that possibility. michael@0: */ michael@0: michael@0: struct inpcbport { michael@0: LIST_ENTRY(inpcbport) phd_hash; michael@0: struct inpcbhead phd_pcblist; michael@0: u_short phd_port; michael@0: }; michael@0: michael@0: /* michael@0: * Global data structure for each high-level protocol (UDP, TCP, ...) in both michael@0: * IPv4 and IPv6. Holds inpcb lists and information for managing them. michael@0: */ michael@0: struct inpcbinfo { michael@0: /* michael@0: * Global list of inpcbs on the protocol. michael@0: */ michael@0: struct inpcbhead *ipi_listhead; michael@0: u_int ipi_count; michael@0: michael@0: /* michael@0: * Global hash of inpcbs, hashed by local and foreign addresses and michael@0: * port numbers. michael@0: */ michael@0: struct inpcbhead *ipi_hashbase; michael@0: u_long ipi_hashmask; michael@0: michael@0: /* michael@0: * Global hash of inpcbs, hashed by only local port number. michael@0: */ michael@0: struct inpcbporthead *ipi_porthashbase; michael@0: u_long ipi_porthashmask; michael@0: michael@0: /* michael@0: * Fields associated with port lookup and allocation. michael@0: */ michael@0: u_short ipi_lastport; michael@0: u_short ipi_lastlow; michael@0: u_short ipi_lasthi; michael@0: michael@0: /* michael@0: * UMA zone from which inpcbs are allocated for this protocol. michael@0: */ michael@0: struct uma_zone *ipi_zone; michael@0: michael@0: /* michael@0: * Generation count--incremented each time a connection is allocated michael@0: * or freed. michael@0: */ michael@0: struct mtx ipi_mtx; michael@0: michael@0: /* michael@0: * vimage 1 michael@0: * general use 1 michael@0: */ michael@0: void *ipi_pspare[2]; michael@0: }; michael@0: michael@0: #define INP_LOCK_INIT(inp, d, t) \ michael@0: mtx_init(&(inp)->inp_mtx, (d), (t), MTX_DEF | MTX_RECURSE | MTX_DUPOK) michael@0: #define INP_LOCK_DESTROY(inp) mtx_destroy(&(inp)->inp_mtx) michael@0: #define INP_LOCK(inp) mtx_lock(&(inp)->inp_mtx) michael@0: #define INP_UNLOCK(inp) mtx_unlock(&(inp)->inp_mtx) michael@0: #define INP_LOCK_ASSERT(inp) mtx_assert(&(inp)->inp_mtx, MA_OWNED) michael@0: #define INP_UNLOCK_ASSERT(inp) mtx_assert(&(inp)->inp_mtx, MA_NOTOWNED) michael@0: michael@0: #define INP_INFO_LOCK_INIT(ipi, d) \ michael@0: mtx_init(&(ipi)->ipi_mtx, (d), NULL, MTX_DEF | MTX_RECURSE) michael@0: #define INP_INFO_LOCK_DESTROY(ipi) mtx_destroy(&(ipi)->ipi_mtx) michael@0: #define INP_INFO_RLOCK(ipi) mtx_lock(&(ipi)->ipi_mtx) michael@0: #define INP_INFO_WLOCK(ipi) mtx_lock(&(ipi)->ipi_mtx) michael@0: #define INP_INFO_RUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_mtx) michael@0: #define INP_INFO_WUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_mtx) michael@0: #define INP_INFO_RLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_mtx, MA_OWNED) michael@0: #define INP_INFO_WLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_mtx, MA_OWNED) michael@0: #define INP_INFO_UNLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_mtx, MA_NOTOWNED) michael@0: michael@0: #define INP_PCBHASH(faddr, lport, fport, mask) \ michael@0: (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask)) michael@0: #define INP_PCBPORTHASH(lport, mask) \ michael@0: (ntohs((lport)) & (mask)) michael@0: michael@0: /* flags in inp_flags: */ michael@0: #define INP_RECVOPTS 0x01 /* receive incoming IP options */ michael@0: #define INP_RECVRETOPTS 0x02 /* receive IP options for reply */ michael@0: #define INP_RECVDSTADDR 0x04 /* receive IP dst address */ michael@0: #define INP_HDRINCL 0x08 /* user supplies entire IP header */ michael@0: #define INP_HIGHPORT 0x10 /* user wants "high" port binding */ michael@0: #define INP_LOWPORT 0x20 /* user wants "low" port binding */ michael@0: #define INP_ANONPORT 0x40 /* port chosen for user */ michael@0: #define INP_RECVIF 0x80 /* receive incoming interface */ michael@0: #define INP_MTUDISC 0x100 /* user can do MTU discovery */ michael@0: #define INP_FAITH 0x200 /* accept FAITH'ed connections */ michael@0: #define INP_RECVTTL 0x400 /* receive incoming IP TTL */ michael@0: #define INP_DONTFRAG 0x800 /* don't fragment packet */ michael@0: michael@0: #define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */ michael@0: michael@0: #define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */ michael@0: #define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */ michael@0: #define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */ michael@0: #define IN6P_DSTOPTS 0x080000 /* receive dst options after rthdr */ michael@0: #define IN6P_RTHDR 0x100000 /* receive routing header */ michael@0: #define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */ michael@0: #define IN6P_TCLASS 0x400000 /* receive traffic class value */ michael@0: #define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */ michael@0: #define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */ michael@0: #define IN6P_MTU 0x80000000 /* receive path MTU */ michael@0: michael@0: #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\ michael@0: INP_RECVIF|INP_RECVTTL|\ michael@0: IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ michael@0: IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\ michael@0: IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\ michael@0: IN6P_MTU) michael@0: #define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\ michael@0: IN6P_TCLASS|IN6P_AUTOFLOWLABEL) michael@0: michael@0: /* for KAME src sync over BSD*'s */ michael@0: #define IN6P_HIGHPORT INP_HIGHPORT michael@0: #define IN6P_LOWPORT INP_LOWPORT michael@0: #define IN6P_ANONPORT INP_ANONPORT michael@0: #define IN6P_RECVIF INP_RECVIF michael@0: #define IN6P_MTUDISC INP_MTUDISC michael@0: #define IN6P_FAITH INP_FAITH michael@0: #define IN6P_CONTROLOPTS INP_CONTROLOPTS michael@0: /* michael@0: * socket AF version is {newer than,or include} michael@0: * actual datagram AF version michael@0: */ michael@0: michael@0: #define INPLOOKUP_WILDCARD 1 michael@0: #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) michael@0: #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */ michael@0: michael@0: #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family michael@0: michael@0: #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af) michael@0: michael@0: /* #ifdef _KERNEL */ michael@0: extern int ipport_reservedhigh; michael@0: extern int ipport_reservedlow; michael@0: extern int ipport_lowfirstauto; michael@0: extern int ipport_lowlastauto; michael@0: extern int ipport_firstauto; michael@0: extern int ipport_lastauto; michael@0: extern int ipport_hifirstauto; michael@0: extern int ipport_hilastauto; michael@0: extern struct callout ipport_tick_callout; michael@0: michael@0: void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *); michael@0: int in_pcballoc(struct socket *, struct inpcbinfo *); michael@0: int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *); michael@0: int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *); michael@0: void in_pcbdetach(struct inpcb *); michael@0: void in_pcbdisconnect(struct inpcb *); michael@0: void in_pcbdrop(struct inpcb *); michael@0: void in_pcbfree(struct inpcb *); michael@0: int in_pcbinshash(struct inpcb *); michael@0: struct inpcb * michael@0: in_pcblookup_local(struct inpcbinfo *, michael@0: struct in_addr, u_int, int); michael@0: struct inpcb * michael@0: in_pcblookup_hash(struct inpcbinfo *, struct in_addr, u_int, michael@0: struct in_addr, u_int, int, struct ifnet *); michael@0: void in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr, michael@0: int, struct inpcb *(*)(struct inpcb *, int)); michael@0: void in_pcbrehash(struct inpcb *); michael@0: void in_pcbsetsolabel(struct socket *so); michael@0: int in_getpeeraddr(struct socket *so, struct sockaddr **nam); michael@0: int in_getsockaddr(struct socket *so, struct sockaddr **nam); michael@0: void in_pcbsosetlabel(struct socket *so); michael@0: void in_pcbremlists(struct inpcb *inp); michael@0: void ipport_tick(void *xtp); michael@0: michael@0: /* michael@0: * Debugging routines compiled in when DDB is present. michael@0: */ michael@0: void db_print_inpcb(struct inpcb *inp, const char *name, int indent); michael@0: michael@0: /* #endif _KERNEL */ michael@0: michael@0: #endif /* !_NETINET_IN_PCB_H_ */