netwerk/sctp/src/user_inpcb.h

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rwxr-xr-x

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 /*-
michael@0 2 * Copyright (c) 1982, 1986, 1990, 1993
michael@0 3 * The Regents of the University of California. All rights reserved.
michael@0 4 *
michael@0 5 * Redistribution and use in source and binary forms, with or without
michael@0 6 * modification, are permitted provided that the following conditions
michael@0 7 * are met:
michael@0 8 * 1. Redistributions of source code must retain the above copyright
michael@0 9 * notice, this list of conditions and the following disclaimer.
michael@0 10 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 11 * notice, this list of conditions and the following disclaimer in the
michael@0 12 * documentation and/or other materials provided with the distribution.
michael@0 13 * 4. Neither the name of the University nor the names of its contributors
michael@0 14 * may be used to endorse or promote products derived from this software
michael@0 15 * without specific prior written permission.
michael@0 16 *
michael@0 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
michael@0 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
michael@0 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
michael@0 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
michael@0 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
michael@0 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
michael@0 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
michael@0 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
michael@0 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@0 27 * SUCH DAMAGE.
michael@0 28 *
michael@0 29 * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
michael@0 30 * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.100.2.1 2007/12/07 05:46:08 kmacy Exp $
michael@0 31 */
michael@0 32
michael@0 33 #ifndef _USER_INPCB_H_
michael@0 34 #define _USER_INPCB_H_
michael@0 35
michael@0 36 #include <user_route.h> /* was <net/route.h> */
michael@0 37
michael@0 38 #define in6pcb inpcb /* for KAME src sync over BSD*'s */
michael@0 39 #define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
michael@0 40 struct inpcbpolicy;
michael@0 41
michael@0 42 /*
michael@0 43 * Struct inpcb is the ommon structure pcb for the Internet Protocol
michael@0 44 * implementation.
michael@0 45 *
michael@0 46 * Pointers to local and foreign host table entries, local and foreign socket
michael@0 47 * numbers, and pointers up (to a socket structure) and down (to a
michael@0 48 * protocol-specific control block) are stored here.
michael@0 49 */
michael@0 50 LIST_HEAD(inpcbhead, inpcb);
michael@0 51 LIST_HEAD(inpcbporthead, inpcbport);
michael@0 52
michael@0 53 /*
michael@0 54 * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
michael@0 55 * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
michael@0 56 * the following structure.
michael@0 57 */
michael@0 58 struct in_addr_4in6 {
michael@0 59 u_int32_t ia46_pad32[3];
michael@0 60 struct in_addr ia46_addr4;
michael@0 61 };
michael@0 62
michael@0 63 /*
michael@0 64 * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553. in_conninfo has
michael@0 65 * some extra padding to accomplish this.
michael@0 66 */
michael@0 67 struct in_endpoints {
michael@0 68 u_int16_t ie_fport; /* foreign port */
michael@0 69 u_int16_t ie_lport; /* local port */
michael@0 70 /* protocol dependent part, local and foreign addr */
michael@0 71 union {
michael@0 72 /* foreign host table entry */
michael@0 73 struct in_addr_4in6 ie46_foreign;
michael@0 74 struct in6_addr ie6_foreign;
michael@0 75 } ie_dependfaddr;
michael@0 76 union {
michael@0 77 /* local host table entry */
michael@0 78 struct in_addr_4in6 ie46_local;
michael@0 79 struct in6_addr ie6_local;
michael@0 80 } ie_dependladdr;
michael@0 81 #define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4
michael@0 82 #define ie_laddr ie_dependladdr.ie46_local.ia46_addr4
michael@0 83 #define ie6_faddr ie_dependfaddr.ie6_foreign
michael@0 84 #define ie6_laddr ie_dependladdr.ie6_local
michael@0 85 };
michael@0 86
michael@0 87 /*
michael@0 88 * XXX The defines for inc_* are hacks and should be changed to direct
michael@0 89 * references.
michael@0 90 */
michael@0 91 struct in_conninfo {
michael@0 92 u_int8_t inc_flags;
michael@0 93 u_int8_t inc_len;
michael@0 94 u_int16_t inc_pad; /* XXX alignment for in_endpoints */
michael@0 95 /* protocol dependent part */
michael@0 96 struct in_endpoints inc_ie;
michael@0 97 };
michael@0 98 #define inc_isipv6 inc_flags /* temp compatability */
michael@0 99 #define inc_fport inc_ie.ie_fport
michael@0 100 #define inc_lport inc_ie.ie_lport
michael@0 101 #define inc_faddr inc_ie.ie_faddr
michael@0 102 #define inc_laddr inc_ie.ie_laddr
michael@0 103 #define inc6_faddr inc_ie.ie6_faddr
michael@0 104 #define inc6_laddr inc_ie.ie6_laddr
michael@0 105
michael@0 106 struct icmp6_filter;
michael@0 107
michael@0 108 struct inpcb {
michael@0 109 LIST_ENTRY(inpcb) inp_hash; /* hash list */
michael@0 110 LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
michael@0 111 void *inp_ppcb; /* pointer to per-protocol pcb */
michael@0 112 struct inpcbinfo *inp_pcbinfo; /* PCB list info */
michael@0 113 struct socket *inp_socket; /* back pointer to socket */
michael@0 114
michael@0 115 u_int32_t inp_flow;
michael@0 116 int inp_flags; /* generic IP/datagram flags */
michael@0 117
michael@0 118 u_char inp_vflag; /* IP version flag (v4/v6) */
michael@0 119 #define INP_IPV4 0x1
michael@0 120 #define INP_IPV6 0x2
michael@0 121 #define INP_IPV6PROTO 0x4 /* opened under IPv6 protocol */
michael@0 122 #define INP_TIMEWAIT 0x8 /* .. probably doesn't go here */
michael@0 123 #define INP_ONESBCAST 0x10 /* send all-ones broadcast */
michael@0 124 #define INP_DROPPED 0x20 /* protocol drop flag */
michael@0 125 #define INP_SOCKREF 0x40 /* strong socket reference */
michael@0 126 #define INP_CONN 0x80
michael@0 127 u_char inp_ip_ttl; /* time to live proto */
michael@0 128 u_char inp_ip_p; /* protocol proto */
michael@0 129 u_char inp_ip_minttl; /* minimum TTL or drop */
michael@0 130 uint32_t inp_ispare1; /* connection id / queue id */
michael@0 131 void *inp_pspare[2]; /* rtentry / general use */
michael@0 132
michael@0 133 /* Local and foreign ports, local and foreign addr. */
michael@0 134 struct in_conninfo inp_inc;
michael@0 135
michael@0 136 /* list for this PCB's local port */
michael@0 137 struct label *inp_label; /* MAC label */
michael@0 138 struct inpcbpolicy *inp_sp; /* for IPSEC */
michael@0 139
michael@0 140 /* Protocol-dependent part; options. */
michael@0 141 struct {
michael@0 142 u_char inp4_ip_tos; /* type of service proto */
michael@0 143 struct mbuf *inp4_options; /* IP options */
michael@0 144 struct ip_moptions *inp4_moptions; /* IP multicast options */
michael@0 145 } inp_depend4;
michael@0 146 #define inp_fport inp_inc.inc_fport
michael@0 147 #define inp_lport inp_inc.inc_lport
michael@0 148 #define inp_faddr inp_inc.inc_faddr
michael@0 149 #define inp_laddr inp_inc.inc_laddr
michael@0 150 #define inp_ip_tos inp_depend4.inp4_ip_tos
michael@0 151 #define inp_options inp_depend4.inp4_options
michael@0 152 #define inp_moptions inp_depend4.inp4_moptions
michael@0 153 struct {
michael@0 154 /* IP options */
michael@0 155 struct mbuf *inp6_options;
michael@0 156 /* IP6 options for outgoing packets */
michael@0 157 struct ip6_pktopts *inp6_outputopts;
michael@0 158 /* IP multicast options */
michael@0 159 #if 0
michael@0 160 struct ip6_moptions *inp6_moptions;
michael@0 161 #endif
michael@0 162 /* ICMPv6 code type filter */
michael@0 163 struct icmp6_filter *inp6_icmp6filt;
michael@0 164 /* IPV6_CHECKSUM setsockopt */
michael@0 165 int inp6_cksum;
michael@0 166 short inp6_hops;
michael@0 167 } inp_depend6;
michael@0 168 LIST_ENTRY(inpcb) inp_portlist;
michael@0 169 struct inpcbport *inp_phd; /* head of this list */
michael@0 170 #define inp_zero_size offsetof(struct inpcb, inp_gencnt)
michael@0 171 struct mtx inp_mtx;
michael@0 172
michael@0 173 #define in6p_faddr inp_inc.inc6_faddr
michael@0 174 #define in6p_laddr inp_inc.inc6_laddr
michael@0 175 #define in6p_hops inp_depend6.inp6_hops /* default hop limit */
michael@0 176 #define in6p_ip6_nxt inp_ip_p
michael@0 177 #define in6p_flowinfo inp_flow
michael@0 178 #define in6p_vflag inp_vflag
michael@0 179 #define in6p_options inp_depend6.inp6_options
michael@0 180 #define in6p_outputopts inp_depend6.inp6_outputopts
michael@0 181 #if 0
michael@0 182 #define in6p_moptions inp_depend6.inp6_moptions
michael@0 183 #endif
michael@0 184 #define in6p_icmp6filt inp_depend6.inp6_icmp6filt
michael@0 185 #define in6p_cksum inp_depend6.inp6_cksum
michael@0 186 #define in6p_flags inp_flags /* for KAME src sync over BSD*'s */
michael@0 187 #define in6p_socket inp_socket /* for KAME src sync over BSD*'s */
michael@0 188 #define in6p_lport inp_lport /* for KAME src sync over BSD*'s */
michael@0 189 #define in6p_fport inp_fport /* for KAME src sync over BSD*'s */
michael@0 190 #define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */
michael@0 191 };
michael@0 192 /*
michael@0 193 * The range of the generation count, as used in this implementation, is 9e19.
michael@0 194 * We would have to create 300 billion connections per second for this number
michael@0 195 * to roll over in a year. This seems sufficiently unlikely that we simply
michael@0 196 * don't concern ourselves with that possibility.
michael@0 197 */
michael@0 198
michael@0 199 struct inpcbport {
michael@0 200 LIST_ENTRY(inpcbport) phd_hash;
michael@0 201 struct inpcbhead phd_pcblist;
michael@0 202 u_short phd_port;
michael@0 203 };
michael@0 204
michael@0 205 /*
michael@0 206 * Global data structure for each high-level protocol (UDP, TCP, ...) in both
michael@0 207 * IPv4 and IPv6. Holds inpcb lists and information for managing them.
michael@0 208 */
michael@0 209 struct inpcbinfo {
michael@0 210 /*
michael@0 211 * Global list of inpcbs on the protocol.
michael@0 212 */
michael@0 213 struct inpcbhead *ipi_listhead;
michael@0 214 u_int ipi_count;
michael@0 215
michael@0 216 /*
michael@0 217 * Global hash of inpcbs, hashed by local and foreign addresses and
michael@0 218 * port numbers.
michael@0 219 */
michael@0 220 struct inpcbhead *ipi_hashbase;
michael@0 221 u_long ipi_hashmask;
michael@0 222
michael@0 223 /*
michael@0 224 * Global hash of inpcbs, hashed by only local port number.
michael@0 225 */
michael@0 226 struct inpcbporthead *ipi_porthashbase;
michael@0 227 u_long ipi_porthashmask;
michael@0 228
michael@0 229 /*
michael@0 230 * Fields associated with port lookup and allocation.
michael@0 231 */
michael@0 232 u_short ipi_lastport;
michael@0 233 u_short ipi_lastlow;
michael@0 234 u_short ipi_lasthi;
michael@0 235
michael@0 236 /*
michael@0 237 * UMA zone from which inpcbs are allocated for this protocol.
michael@0 238 */
michael@0 239 struct uma_zone *ipi_zone;
michael@0 240
michael@0 241 /*
michael@0 242 * Generation count--incremented each time a connection is allocated
michael@0 243 * or freed.
michael@0 244 */
michael@0 245 struct mtx ipi_mtx;
michael@0 246
michael@0 247 /*
michael@0 248 * vimage 1
michael@0 249 * general use 1
michael@0 250 */
michael@0 251 void *ipi_pspare[2];
michael@0 252 };
michael@0 253
michael@0 254 #define INP_LOCK_INIT(inp, d, t) \
michael@0 255 mtx_init(&(inp)->inp_mtx, (d), (t), MTX_DEF | MTX_RECURSE | MTX_DUPOK)
michael@0 256 #define INP_LOCK_DESTROY(inp) mtx_destroy(&(inp)->inp_mtx)
michael@0 257 #define INP_LOCK(inp) mtx_lock(&(inp)->inp_mtx)
michael@0 258 #define INP_UNLOCK(inp) mtx_unlock(&(inp)->inp_mtx)
michael@0 259 #define INP_LOCK_ASSERT(inp) mtx_assert(&(inp)->inp_mtx, MA_OWNED)
michael@0 260 #define INP_UNLOCK_ASSERT(inp) mtx_assert(&(inp)->inp_mtx, MA_NOTOWNED)
michael@0 261
michael@0 262 #define INP_INFO_LOCK_INIT(ipi, d) \
michael@0 263 mtx_init(&(ipi)->ipi_mtx, (d), NULL, MTX_DEF | MTX_RECURSE)
michael@0 264 #define INP_INFO_LOCK_DESTROY(ipi) mtx_destroy(&(ipi)->ipi_mtx)
michael@0 265 #define INP_INFO_RLOCK(ipi) mtx_lock(&(ipi)->ipi_mtx)
michael@0 266 #define INP_INFO_WLOCK(ipi) mtx_lock(&(ipi)->ipi_mtx)
michael@0 267 #define INP_INFO_RUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_mtx)
michael@0 268 #define INP_INFO_WUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_mtx)
michael@0 269 #define INP_INFO_RLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_mtx, MA_OWNED)
michael@0 270 #define INP_INFO_WLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_mtx, MA_OWNED)
michael@0 271 #define INP_INFO_UNLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_mtx, MA_NOTOWNED)
michael@0 272
michael@0 273 #define INP_PCBHASH(faddr, lport, fport, mask) \
michael@0 274 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
michael@0 275 #define INP_PCBPORTHASH(lport, mask) \
michael@0 276 (ntohs((lport)) & (mask))
michael@0 277
michael@0 278 /* flags in inp_flags: */
michael@0 279 #define INP_RECVOPTS 0x01 /* receive incoming IP options */
michael@0 280 #define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
michael@0 281 #define INP_RECVDSTADDR 0x04 /* receive IP dst address */
michael@0 282 #define INP_HDRINCL 0x08 /* user supplies entire IP header */
michael@0 283 #define INP_HIGHPORT 0x10 /* user wants "high" port binding */
michael@0 284 #define INP_LOWPORT 0x20 /* user wants "low" port binding */
michael@0 285 #define INP_ANONPORT 0x40 /* port chosen for user */
michael@0 286 #define INP_RECVIF 0x80 /* receive incoming interface */
michael@0 287 #define INP_MTUDISC 0x100 /* user can do MTU discovery */
michael@0 288 #define INP_FAITH 0x200 /* accept FAITH'ed connections */
michael@0 289 #define INP_RECVTTL 0x400 /* receive incoming IP TTL */
michael@0 290 #define INP_DONTFRAG 0x800 /* don't fragment packet */
michael@0 291
michael@0 292 #define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
michael@0 293
michael@0 294 #define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */
michael@0 295 #define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */
michael@0 296 #define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */
michael@0 297 #define IN6P_DSTOPTS 0x080000 /* receive dst options after rthdr */
michael@0 298 #define IN6P_RTHDR 0x100000 /* receive routing header */
michael@0 299 #define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
michael@0 300 #define IN6P_TCLASS 0x400000 /* receive traffic class value */
michael@0 301 #define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
michael@0 302 #define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */
michael@0 303 #define IN6P_MTU 0x80000000 /* receive path MTU */
michael@0 304
michael@0 305 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
michael@0 306 INP_RECVIF|INP_RECVTTL|\
michael@0 307 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
michael@0 308 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
michael@0 309 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
michael@0 310 IN6P_MTU)
michael@0 311 #define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
michael@0 312 IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
michael@0 313
michael@0 314 /* for KAME src sync over BSD*'s */
michael@0 315 #define IN6P_HIGHPORT INP_HIGHPORT
michael@0 316 #define IN6P_LOWPORT INP_LOWPORT
michael@0 317 #define IN6P_ANONPORT INP_ANONPORT
michael@0 318 #define IN6P_RECVIF INP_RECVIF
michael@0 319 #define IN6P_MTUDISC INP_MTUDISC
michael@0 320 #define IN6P_FAITH INP_FAITH
michael@0 321 #define IN6P_CONTROLOPTS INP_CONTROLOPTS
michael@0 322 /*
michael@0 323 * socket AF version is {newer than,or include}
michael@0 324 * actual datagram AF version
michael@0 325 */
michael@0 326
michael@0 327 #define INPLOOKUP_WILDCARD 1
michael@0 328 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
michael@0 329 #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
michael@0 330
michael@0 331 #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
michael@0 332
michael@0 333 #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
michael@0 334
michael@0 335 /* #ifdef _KERNEL */
michael@0 336 extern int ipport_reservedhigh;
michael@0 337 extern int ipport_reservedlow;
michael@0 338 extern int ipport_lowfirstauto;
michael@0 339 extern int ipport_lowlastauto;
michael@0 340 extern int ipport_firstauto;
michael@0 341 extern int ipport_lastauto;
michael@0 342 extern int ipport_hifirstauto;
michael@0 343 extern int ipport_hilastauto;
michael@0 344 extern struct callout ipport_tick_callout;
michael@0 345
michael@0 346 void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
michael@0 347 int in_pcballoc(struct socket *, struct inpcbinfo *);
michael@0 348 int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
michael@0 349 int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
michael@0 350 void in_pcbdetach(struct inpcb *);
michael@0 351 void in_pcbdisconnect(struct inpcb *);
michael@0 352 void in_pcbdrop(struct inpcb *);
michael@0 353 void in_pcbfree(struct inpcb *);
michael@0 354 int in_pcbinshash(struct inpcb *);
michael@0 355 struct inpcb *
michael@0 356 in_pcblookup_local(struct inpcbinfo *,
michael@0 357 struct in_addr, u_int, int);
michael@0 358 struct inpcb *
michael@0 359 in_pcblookup_hash(struct inpcbinfo *, struct in_addr, u_int,
michael@0 360 struct in_addr, u_int, int, struct ifnet *);
michael@0 361 void in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr,
michael@0 362 int, struct inpcb *(*)(struct inpcb *, int));
michael@0 363 void in_pcbrehash(struct inpcb *);
michael@0 364 void in_pcbsetsolabel(struct socket *so);
michael@0 365 int in_getpeeraddr(struct socket *so, struct sockaddr **nam);
michael@0 366 int in_getsockaddr(struct socket *so, struct sockaddr **nam);
michael@0 367 void in_pcbsosetlabel(struct socket *so);
michael@0 368 void in_pcbremlists(struct inpcb *inp);
michael@0 369 void ipport_tick(void *xtp);
michael@0 370
michael@0 371 /*
michael@0 372 * Debugging routines compiled in when DDB is present.
michael@0 373 */
michael@0 374 void db_print_inpcb(struct inpcb *inp, const char *name, int indent);
michael@0 375
michael@0 376 /* #endif _KERNEL */
michael@0 377
michael@0 378 #endif /* !_NETINET_IN_PCB_H_ */

mercurial