in_pcb.h revision 53541
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1982, 1986, 1990, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by the University of 161541Srgrimes * California, Berkeley and its contributors. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 331541Srgrimes * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 3450477Speter * $FreeBSD: head/sys/netinet/in_pcb.h 53541 1999-11-22 02:45:11Z shin $ 351541Srgrimes */ 361541Srgrimes 372169Spaul#ifndef _NETINET_IN_PCB_H_ 382169Spaul#define _NETINET_IN_PCB_H_ 392169Spaul 4012644Sbde#include <sys/queue.h> 4112644Sbde 4253541Sshin 4353541Sshin#include <netinet6/ipsec.h> /* for IPSEC */ 4453541Sshin 4553541Sshin#define in6pcb inpcb /* for KAME src sync over BSD*'s */ 4653541Sshin#define in6p_sp inp_sp /* for KAME src sync over BSD*'s */ 4753541Sshin 481541Srgrimes/* 491541Srgrimes * Common structure pcb for internet protocol implementation. 501541Srgrimes * Here are stored pointers to local and foreign host table 511541Srgrimes * entries, local and foreign socket numbers, and pointers 521541Srgrimes * up (to a socket structure) and down (to a protocol-specific) 531541Srgrimes * control block. 541541Srgrimes */ 557684SdgLIST_HEAD(inpcbhead, inpcb); 5632821SdgLIST_HEAD(inpcbporthead, inpcbport); 5736079Swollmantypedef u_quad_t inp_gen_t; 587684Sdg 5934881Swollman/* 6053541Sshin * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet. 6153541Sshin * So, AF_INET6 null laddr is also used as AF_INET null laddr, 6253541Sshin * by utilize following structure. (At last, same as INRIA) 6353541Sshin */ 6453541Sshinstruct in_addr_4in6 { 6553541Sshin u_int32_t ia46_pad32[3]; 6653541Sshin struct in_addr ia46_addr4; 6753541Sshin}; 6853541Sshin 6953541Sshin/* 7034881Swollman * NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS 7134881Swollman * of the structure. Therefore, it is important that the members in 7234881Swollman * that position not contain any information which is required to be 7334881Swollman * stable. 7434881Swollman */ 7553541Sshinstruct icmp6_filter; 7653541Sshin 771541Srgrimesstruct inpcb { 7853541Sshin LIST_ENTRY(inpcb) inp_hash; /* hash list */ 791541Srgrimes u_short inp_fport; /* foreign port */ 801541Srgrimes u_short inp_lport; /* local port */ 8153541Sshin LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */ 8253541Sshin u_int32_t inp_flow; 8353541Sshin 8453541Sshin /* protocol dependent part, local and foreign addr */ 8553541Sshin union { 8653541Sshin /* foreign host table entry */ 8753541Sshin struct in_addr_4in6 inp46_foreign; 8853541Sshin struct in6_addr inp6_foreign; 8953541Sshin } inp_dependfaddr; 9053541Sshin union { 9153541Sshin /* local host table entry */ 9253541Sshin struct in_addr_4in6 inp46_local; 9353541Sshin struct in6_addr inp6_local; 9453541Sshin } inp_dependladdr; 9553541Sshin 9624570Sdg caddr_t inp_ppcb; /* pointer to per-protocol pcb */ 9732821Sdg struct inpcbinfo *inp_pcbinfo; /* PCB list info */ 981541Srgrimes struct socket *inp_socket; /* back pointer to socket */ 9953541Sshin /* list for this PCB's local port */ 1001541Srgrimes int inp_flags; /* generic IP/datagram flags */ 10153541Sshin 10253541Sshin /* protocol dependent part; cached route */ 10353541Sshin union { 10453541Sshin /* placeholder for routing entry */ 10553541Sshin struct route inp4_route; 10653541Sshin struct route_in6 inp6_route; 10753541Sshin } inp_dependroute; 10853541Sshin 10953541Sshin struct inpcbpolicy *inp_sp; /* for IPSEC */ 11053541Sshin u_char inp_vflag; 11153541Sshin#define INP_IPV4 0x1 11253541Sshin#define INP_IPV6 0x2 11324570Sdg u_char inp_ip_ttl; /* time to live proto */ 11424570Sdg u_char inp_ip_p; /* protocol proto */ 11553541Sshin 11653541Sshin /* protocol dependent part; options */ 11753541Sshin struct { 11853541Sshin u_char inp4_ip_tos; /* type of service proto */ 11953541Sshin struct mbuf *inp4_options; /* IP options */ 12053541Sshin struct ip_moptions *inp4_moptions; /* IP multicast options */ 12153541Sshin } inp_depend4; 12253541Sshin#define inp_faddr inp_dependfaddr.inp46_foreign.ia46_addr4 12353541Sshin#define inp_laddr inp_dependladdr.inp46_local.ia46_addr4 12453541Sshin#define inp_route inp_dependroute.inp4_route 12553541Sshin#define inp_ip_tos inp_depend4.inp4_ip_tos 12653541Sshin#define inp_options inp_depend4.inp4_options 12753541Sshin#define inp_moptions inp_depend4.inp4_moptions 12853541Sshin struct { 12953541Sshin /* IP options */ 13053541Sshin struct mbuf *inp6_options; 13153541Sshin /* IP6 options for outgoing packets */ 13253541Sshin struct ip6_pktopts *inp6_outputopts; 13353541Sshin /* IP multicast options */ 13453541Sshin struct ip6_moptions *inp6_moptions; 13553541Sshin /* ICMPv6 code type filter */ 13653541Sshin struct icmp6_filter *inp6_icmp6filt; 13753541Sshin /* IPV6_CHECKSUM setsockopt */ 13853541Sshin int inp6_cksum; 13953541Sshin u_short inp6_ifindex; 14053541Sshin short inp6_hops; 14153541Sshin u_int8_t inp6_hlim; 14253541Sshin } inp_depend6; 14353541Sshin LIST_ENTRY(inpcb) inp_portlist; 14434923Sbde struct inpcbport *inp_phd; /* head of this list */ 14553541Sshin inp_gen_t inp_gencnt; /* generation count of this instance */ 14653541Sshin#define in6p_faddr inp_dependfaddr.inp6_foreign 14753541Sshin#define in6p_laddr inp_dependladdr.inp6_local 14853541Sshin#define in6p_route inp_dependroute.inp6_route 14953541Sshin#define in6p_ip6_hlim inp_depend6.inp6_hlim 15053541Sshin#define in6p_hops inp_depend6.inp6_hops /* default hop limit */ 15153541Sshin#define in6p_ip6_nxt inp_ip_p 15253541Sshin#define in6p_flowinfo inp_flow 15353541Sshin#define in6p_vflag inp_vflag 15453541Sshin#define in6p_options inp_depend6.inp6_options 15553541Sshin#define in6p_outputopts inp_depend6.inp6_outputopts 15653541Sshin#define in6p_moptions inp_depend6.inp6_moptions 15753541Sshin#define in6p_icmp6filt inp_depend6.inp6_icmp6filt 15853541Sshin#define in6p_cksum inp_depend6.inp6_cksum 15953541Sshin#define inp6_ifindex inp_depend6.inp6_ifindex 16053541Sshin#define in6p_flags inp_flags /* for KAME src sync over BSD*'s */ 16153541Sshin#define in6p_socket inp_socket /* for KAME src sync over BSD*'s */ 16253541Sshin#define in6p_lport inp_lport /* for KAME src sync over BSD*'s */ 16353541Sshin#define in6p_fport inp_fport /* for KAME src sync over BSD*'s */ 16453541Sshin#define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */ 1651541Srgrimes}; 16634881Swollman/* 16734881Swollman * The range of the generation count, as used in this implementation, 16834881Swollman * is 9e19. We would have to create 300 billion connections per 16934881Swollman * second for this number to roll over in a year. This seems sufficiently 17034881Swollman * unlikely that we simply don't concern ourselves with that possibility. 17134881Swollman */ 1721541Srgrimes 17336079Swollman/* 17436079Swollman * Interface exported to userland by various protocols which use 17536079Swollman * inpcbs. Hack alert -- only define if struct xsocket is in scope. 17636079Swollman */ 17736079Swollman#ifdef _SYS_SOCKETVAR_H_ 17836079Swollmanstruct xinpcb { 17936079Swollman size_t xi_len; /* length of this structure */ 18036079Swollman struct inpcb xi_inp; 18136079Swollman struct xsocket xi_socket; 18236079Swollman u_quad_t xi_alignment_hack; 18336079Swollman}; 18436079Swollman 18536079Swollmanstruct xinpgen { 18636079Swollman size_t xig_len; /* length of this structure */ 18736079Swollman u_int xig_count; /* number of PCBs at this time */ 18836079Swollman inp_gen_t xig_gen; /* generation count at this time */ 18936079Swollman so_gen_t xig_sogen; /* socket generation count at this time */ 19036079Swollman}; 19136079Swollman#endif /* _SYS_SOCKETVAR_H_ */ 19236079Swollman 19332821Sdgstruct inpcbport { 19432821Sdg LIST_ENTRY(inpcbport) phd_hash; 19532821Sdg struct inpcbhead phd_pcblist; 19632821Sdg u_short phd_port; 19732821Sdg}; 19832821Sdg 19934881Swollmanstruct inpcbinfo { /* XXX documentation, prefixes */ 20034881Swollman struct inpcbhead *hashbase; 20134881Swollman u_long hashmask; 20234881Swollman struct inpcbporthead *porthashbase; 20334881Swollman u_long porthashmask; 20434881Swollman struct inpcbhead *listhead; 20534881Swollman u_short lastport; 20634881Swollman u_short lastlow; 20734881Swollman u_short lasthi; 20834881Swollman struct vm_zone *ipi_zone; /* zone to allocate pcbs from */ 20934881Swollman u_int ipi_count; /* number of pcbs in this list */ 21034881Swollman u_quad_t ipi_gencnt; /* current generation count */ 2117684Sdg}; 2127684Sdg 21323324Sdg#define INP_PCBHASH(faddr, lport, fport, mask) \ 21432821Sdg (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask)) 21532821Sdg#define INP_PCBPORTHASH(lport, mask) \ 21632821Sdg (ntohs((lport)) & (mask)) 21723324Sdg 2181541Srgrimes/* flags in inp_flags: */ 2191541Srgrimes#define INP_RECVOPTS 0x01 /* receive incoming IP options */ 2201541Srgrimes#define INP_RECVRETOPTS 0x02 /* receive IP options for reply */ 2211541Srgrimes#define INP_RECVDSTADDR 0x04 /* receive IP dst address */ 2221541Srgrimes#define INP_HDRINCL 0x08 /* user supplies entire IP header */ 22314195Speter#define INP_HIGHPORT 0x10 /* user wants "high" port binding */ 22414195Speter#define INP_LOWPORT 0x20 /* user wants "low" port binding */ 22517795Sphk#define INP_ANONPORT 0x40 /* port chosen for user */ 22619622Sfenner#define INP_RECVIF 0x80 /* receive incoming interface */ 22728270Swollman#define INP_MTUDISC 0x100 /* user can do MTU discovery */ 22853541Sshin#define INP_FAITH 0x200 /* accept FAITH'ed connections */ 22953541Sshin#define IN6P_PKTINFO 0x010000 23053541Sshin#define IN6P_HOPLIMIT 0x020000 23153541Sshin#define IN6P_NEXTHOP 0x040000 23253541Sshin#define IN6P_HOPOPTS 0x080000 23353541Sshin#define IN6P_DSTOPTS 0x100000 23453541Sshin#define IN6P_RTHDR 0x200000 23553541Sshin#define IN6P_BINDV6ONLY 0x400000 23619622Sfenner#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\ 23753541Sshin INP_RECVIF|\ 23853541Sshin IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_NEXTHOP|\ 23953541Sshin IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR) 2401541Srgrimes 24153541Sshin#define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR) 24253541Sshin 24353541Sshin /* for KAME src sync over BSD*'s */ 24453541Sshin#define IN6P_RECVOPTS INP_RECVOPTS 24553541Sshin#define IN6P_RECVRETOPTS INP_RECVRETOPTS 24653541Sshin#define IN6P_RECVDSTADDR INP_RECVDSTADDR 24753541Sshin#define IN6P_HDRINCL INP_HDRINCL 24853541Sshin#define IN6P_HIGHPORT INP_HIGHPORT 24953541Sshin#define IN6P_LOWPORT INP_LOWPORT 25053541Sshin#define IN6P_ANONPORT INP_ANONPORT 25153541Sshin#define IN6P_RECVIF INP_RECVIF 25253541Sshin#define IN6P_MTUDISC INP_MTUDISC 25353541Sshin#define IN6P_FAITH INP_FAITH 25453541Sshin#define IN6P_CONTROLOPTS INP_CONTROLOPTS 25553541Sshin /* 25653541Sshin * socket AF version is {newer than,or include} 25753541Sshin * actual datagram AF version 25853541Sshin */ 25953541Sshin 2601541Srgrimes#define INPLOOKUP_WILDCARD 1 2611541Srgrimes#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) 26253541Sshin#define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */ 2631541Srgrimes 26453541Sshin#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family 26553541Sshin 26653541Sshin#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af) 26753541Sshin 2681541Srgrimes#ifdef KERNEL 26953541Sshinextern int ipport_lowfirstauto; 27053541Sshinextern int ipport_lowlastauto; 27153541Sshinextern int ipport_firstauto; 27253541Sshinextern int ipport_lastauto; 27353541Sshinextern int ipport_hifirstauto; 27453541Sshinextern int ipport_hilastauto; 27553541Sshin 27632821Sdgvoid in_losing __P((struct inpcb *)); 27732821Sdgint in_pcballoc __P((struct socket *, struct inpcbinfo *, struct proc *)); 27832821Sdgint in_pcbbind __P((struct inpcb *, struct sockaddr *, struct proc *)); 27932821Sdgint in_pcbconnect __P((struct inpcb *, struct sockaddr *, struct proc *)); 28032821Sdgvoid in_pcbdetach __P((struct inpcb *)); 28132821Sdgvoid in_pcbdisconnect __P((struct inpcb *)); 28232821Sdgint in_pcbinshash __P((struct inpcb *)); 28332821Sdgint in_pcbladdr __P((struct inpcb *, struct sockaddr *, 2847090Sbde struct sockaddr_in **)); 2851541Srgrimesstruct inpcb * 28632821Sdg in_pcblookup_local __P((struct inpcbinfo *, 28732821Sdg struct in_addr, u_int, int)); 2887684Sdgstruct inpcb * 28932821Sdg in_pcblookup_hash __P((struct inpcbinfo *, 29018795Sdg struct in_addr, u_int, struct in_addr, u_int, int)); 29132821Sdgvoid in_pcbnotify __P((struct inpcbhead *, struct sockaddr *, 2921541Srgrimes u_int, struct in_addr, u_int, int, void (*)(struct inpcb *, int))); 29332821Sdgvoid in_pcbrehash __P((struct inpcb *)); 29432821Sdgint in_setpeeraddr __P((struct socket *so, struct sockaddr **nam)); 29532821Sdgint in_setsockaddr __P((struct socket *so, struct sockaddr **nam)); 29652904Sshinvoid in_pcbremlists __P((struct inpcb *inp)); 29746155Sphkint prison_xinpcb __P((struct proc *p, struct inpcb *inp)); 29834923Sbde#endif /* KERNEL */ 29934881Swollman 30034923Sbde#endif /* !_NETINET_IN_PCB_H_ */ 301