1 /* 2 * Copyright (c) 1982, 1986, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 34 * $Id: in_pcb.h,v 1.25 1998/03/28 10:18:22 bde Exp $ 35 */ 36 37 #ifndef _NETINET_IN_PCB_H_ 38 #define _NETINET_IN_PCB_H_ 39 40 #include <sys/queue.h> 41 42 /* 43 * Common structure pcb for internet protocol implementation. 44 * Here are stored pointers to local and foreign host table 45 * entries, local and foreign socket numbers, and pointers 46 * up (to a socket structure) and down (to a protocol-specific) 47 * control block. 48 */ 49 LIST_HEAD(inpcbhead, inpcb); 50 LIST_HEAD(inpcbporthead, inpcbport); 51 typedef u_quad_t inp_gen_t; 52 53 /* 54 * NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS 55 * of the structure. Therefore, it is important that the members in 56 * that position not contain any information which is required to be 57 * stable. 58 */ 59 struct inpcb { 60 LIST_ENTRY(inpcb) inp_hash; /* hash list */ 61 struct in_addr inp_faddr; /* foreign host table entry */ 62 struct in_addr inp_laddr; /* local host table entry */ 63 u_short inp_fport; /* foreign port */ 64 u_short inp_lport; /* local port */ 65 LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */ 66 caddr_t inp_ppcb; /* pointer to per-protocol pcb */ 67 struct inpcbinfo *inp_pcbinfo; /* PCB list info */ 68 struct socket *inp_socket; /* back pointer to socket */ 69 struct mbuf *inp_options; /* IP options */ 70 struct route inp_route; /* placeholder for routing entry */ 71 int inp_flags; /* generic IP/datagram flags */ 72 u_char inp_ip_tos; /* type of service proto */ 73 u_char inp_ip_ttl; /* time to live proto */ 74 u_char inp_ip_p; /* protocol proto */ 75 u_char pad[1]; /* alignment */ 76 struct ip_moptions *inp_moptions; /* IP multicast options */ 77 LIST_ENTRY(inpcb) inp_portlist; /* list for this PCB's local port */ 78 struct inpcbport *inp_phd; /* head of this list */ 79 inp_gen_t inp_gencnt; /* generation count of this instance */ 80 }; 81 /* 82 * The range of the generation count, as used in this implementation, 83 * is 9e19. We would have to create 300 billion connections per 84 * second for this number to roll over in a year. This seems sufficiently 85 * unlikely that we simply don't concern ourselves with that possibility. 86 */ 87 88 /* 89 * Interface exported to userland by various protocols which use 90 * inpcbs. Hack alert -- only define if struct xsocket is in scope. 91 */ 92 #ifdef _SYS_SOCKETVAR_H_ 93 struct xinpcb { 94 size_t xi_len; /* length of this structure */ 95 struct inpcb xi_inp; 96 struct xsocket xi_socket; 97 u_quad_t xi_alignment_hack; 98 }; 99 100 struct xinpgen { 101 size_t xig_len; /* length of this structure */ 102 u_int xig_count; /* number of PCBs at this time */ 103 inp_gen_t xig_gen; /* generation count at this time */ 104 so_gen_t xig_sogen; /* socket generation count at this time */ 105 }; 106 #endif /* _SYS_SOCKETVAR_H_ */ 107 108 struct inpcbport { 109 LIST_ENTRY(inpcbport) phd_hash; 110 struct inpcbhead phd_pcblist; 111 u_short phd_port; 112 }; 113 114 struct inpcbinfo { /* XXX documentation, prefixes */ 115 struct inpcbhead *hashbase; 116 u_long hashmask; 117 struct inpcbporthead *porthashbase; 118 u_long porthashmask; 119 struct inpcbhead *listhead; 120 u_short lastport; 121 u_short lastlow; 122 u_short lasthi; 123 struct vm_zone *ipi_zone; /* zone to allocate pcbs from */ 124 u_int ipi_count; /* number of pcbs in this list */ 125 u_quad_t ipi_gencnt; /* current generation count */ 126 }; 127 128 #define INP_PCBHASH(faddr, lport, fport, mask) \ 129 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask)) 130 #define INP_PCBPORTHASH(lport, mask) \ 131 (ntohs((lport)) & (mask)) 132 133 /* flags in inp_flags: */ 134 #define INP_RECVOPTS 0x01 /* receive incoming IP options */ 135 #define INP_RECVRETOPTS 0x02 /* receive IP options for reply */ 136 #define INP_RECVDSTADDR 0x04 /* receive IP dst address */ 137 #define INP_HDRINCL 0x08 /* user supplies entire IP header */ 138 #define INP_HIGHPORT 0x10 /* user wants "high" port binding */ 139 #define INP_LOWPORT 0x20 /* user wants "low" port binding */ 140 #define INP_ANONPORT 0x40 /* port chosen for user */ 141 #define INP_RECVIF 0x80 /* receive incoming interface */ 142 #define INP_MTUDISC 0x100 /* user can do MTU discovery */ 143 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\ 144 INP_RECVIF) 145 146 #define INPLOOKUP_WILDCARD 1 147 148 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) 149 150 #ifdef KERNEL 151 void in_losing __P((struct inpcb *)); 152 int in_pcballoc __P((struct socket *, struct inpcbinfo *, struct proc *)); 153 int in_pcbbind __P((struct inpcb *, struct sockaddr *, struct proc *)); 154 int in_pcbconnect __P((struct inpcb *, struct sockaddr *, struct proc *)); 155 void in_pcbdetach __P((struct inpcb *)); 156 void in_pcbdisconnect __P((struct inpcb *)); 157 int in_pcbinshash __P((struct inpcb *)); 158 int in_pcbladdr __P((struct inpcb *, struct sockaddr *, 159 struct sockaddr_in **)); 160 struct inpcb * 161 in_pcblookup_local __P((struct inpcbinfo *, 162 struct in_addr, u_int, int)); 163 struct inpcb * 164 in_pcblookup_hash __P((struct inpcbinfo *, 165 struct in_addr, u_int, struct in_addr, u_int, int)); 166 void in_pcbnotify __P((struct inpcbhead *, struct sockaddr *, 167 u_int, struct in_addr, u_int, int, void (*)(struct inpcb *, int))); 168 void in_pcbrehash __P((struct inpcb *)); 169 int in_setpeeraddr __P((struct socket *so, struct sockaddr **nam)); 170 int in_setsockaddr __P((struct socket *so, struct sockaddr **nam)); 171 #endif /* KERNEL */ 172 173 #endif /* !_NETINET_IN_PCB_H_ */ 174