1 /* $NetBSD: in_pcb.h,v 1.33 2003/06/15 02:49:33 matt Exp $ */ 2 3 /* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the project nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 /* 33 * Copyright (c) 1982, 1986, 1990, 1993 34 * The Regents of the University of California. All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. All advertising materials mentioning features or use of this software 45 * must display the following acknowledgement: 46 * This product includes software developed by the University of 47 * California, Berkeley and its contributors. 48 * 4. Neither the name of the University nor the names of its contributors 49 * may be used to endorse or promote products derived from this software 50 * without specific prior written permission. 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * SUCH DAMAGE. 63 * 64 * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 65 */ 66 67 #ifndef _NETINET_IN_PCB_H_ 68 #define _NETINET_IN_PCB_H_ 69 70 #include <sys/queue.h> 71 72 /* 73 * Common structure pcb for internet protocol implementation. 74 * Here are stored pointers to local and foreign host table 75 * entries, local and foreign socket numbers, and pointers 76 * up (to a socket structure) and down (to a protocol-specific) 77 * control block. 78 */ 79 struct inpcbpolicy; 80 81 struct inpcb { 82 LIST_ENTRY(inpcb) inp_hash; 83 CIRCLEQ_ENTRY(inpcb) inp_queue; 84 caddr_t inp_ppcb; /* pointer to per-protocol pcb */ 85 int inp_state; /* bind/connect state */ 86 u_int16_t inp_fport; /* foreign port */ 87 u_int16_t inp_lport; /* local port */ 88 struct socket *inp_socket; /* back pointer to socket */ 89 struct route inp_route; /* placeholder for routing entry */ 90 int inp_flags; /* generic IP/datagram flags */ 91 struct ip inp_ip; /* header prototype; should have more */ 92 struct mbuf *inp_options; /* IP options */ 93 struct ip_moptions *inp_moptions; /* IP multicast options */ 94 int inp_errormtu; /* MTU of last xmit status = EMSGSIZE */ 95 struct inpcbtable *inp_table; 96 #if 1 /*IPSEC*/ 97 struct inpcbpolicy *inp_sp; /* security policy. */ 98 #endif 99 LIST_ENTRY(inpcb) inp_ialink; 100 struct in_ifaddr *inp_ia; /* in_ifaddr which laddr is bound */ 101 }; 102 #define inp_faddr inp_ip.ip_dst 103 #define inp_laddr inp_ip.ip_src 104 105 LIST_HEAD(inpcbhead, inpcb); 106 107 struct inpcbtable { 108 CIRCLEQ_HEAD(, inpcb) inpt_queue; 109 struct inpcbhead *inpt_bindhashtbl; 110 struct inpcbhead *inpt_connecthashtbl; 111 u_long inpt_bindhash; 112 u_long inpt_connecthash; 113 u_int16_t inpt_lastport; 114 u_int16_t inpt_lastlow; 115 }; 116 #define inpt_lasthi inpt_lastport 117 118 /* states in inp_state: */ 119 #define INP_ATTACHED 0 120 #define INP_BOUND 1 121 #define INP_CONNECTED 2 122 123 /* flags in inp_flags: */ 124 #define INP_RECVOPTS 0x01 /* receive incoming IP options */ 125 #define INP_RECVRETOPTS 0x02 /* receive IP options for reply */ 126 #define INP_RECVDSTADDR 0x04 /* receive IP dst address */ 127 #define INP_HDRINCL 0x08 /* user supplies entire IP header */ 128 #define INP_HIGHPORT 0x10 /* (unused; FreeBSD compat) */ 129 #define INP_LOWPORT 0x20 /* user wants "low" port binding */ 130 #define INP_ANONPORT 0x40 /* port chosen for user */ 131 #define INP_RECVIF 0x80 /* receive incoming interface */ 132 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\ 133 INP_RECVIF) 134 135 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) 136 137 #ifdef _KERNEL 138 void in_losing __P((struct inpcb *)); 139 int in_pcballoc __P((struct socket *, void *)); 140 int in_pcbbind __P((void *, struct mbuf *, struct proc *)); 141 int in_pcbconnect __P((void *, struct mbuf *)); 142 void in_pcbdetach __P((void *)); 143 void in_pcbdisconnect __P((void *)); 144 void in_pcbinit __P((struct inpcbtable *, int, int)); 145 struct inpcb * 146 in_pcblookup_bind __P((struct inpcbtable *, 147 struct in_addr, u_int)); 148 struct inpcb * 149 in_pcblookup_connect __P((struct inpcbtable *, 150 struct in_addr, u_int, struct in_addr, u_int)); 151 int in_pcbnotify __P((struct inpcbtable *, struct in_addr, u_int, 152 struct in_addr, u_int, int, void (*)(struct inpcb *, int))); 153 void in_pcbnotifyall __P((struct inpcbtable *, struct in_addr, int, 154 void (*)(struct inpcb *, int))); 155 void in_pcbpurgeif0 __P((struct inpcbtable *, struct ifnet *)); 156 void in_pcbpurgeif __P((struct inpcbtable *, struct ifnet *)); 157 void in_pcbstate __P((struct inpcb *, int)); 158 void in_rtchange __P((struct inpcb *, int)); 159 void in_setpeeraddr __P((struct inpcb *, struct mbuf *)); 160 void in_setsockaddr __P((struct inpcb *, struct mbuf *)); 161 struct rtentry * 162 in_pcbrtentry __P((struct inpcb *)); 163 extern struct sockaddr_in *in_selectsrc __P((struct sockaddr_in *, 164 struct route *, int, struct ip_moptions *, int *)); 165 #endif 166 167 #endif /* _NETINET_IN_PCB_H_ */ 168