199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1982, 1986, 1990, 1993
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The Regents of the University of California.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2010-2011 Juniper Networks, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Portions of this software were developed by Robert N. M. Watson under
199767f8919635c4928607450d9e0abb932109ceToomas Soome * contract to Juniper Networks, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4. Neither the name of the University nor the names of its contributors
199767f8919635c4928607450d9e0abb932109ceToomas Soome * may be used to endorse or promote products derived from this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _NETINET_IN_PCB_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _NETINET_IN_PCB_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/queue.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/_lock.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/_mutex.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/_rwlock.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/lock.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/rwlock.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <net/vnet.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <vm/uma.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6pcb inpcb /* for KAME src sync over BSD*'s */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcbpolicy;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * struct inpcb is the common protocol control block structure used in most
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IP transport protocols.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Pointers to local and foreign host table entries, local and foreign socket
199767f8919635c4928607450d9e0abb932109ceToomas Soome * numbers, and pointers up (to a socket structure) and down (to a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * protocol-specific control block) are stored here.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeLIST_HEAD(inpcbhead, inpcb);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeLIST_HEAD(inpcbporthead, inpcbport);
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef u_quad_t inp_gen_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the following structure.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct in_addr_4in6 {
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int32_t ia46_pad32[3];
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_addr ia46_addr4;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553. in_conninfo has
199767f8919635c4928607450d9e0abb932109ceToomas Soome * some extra padding to accomplish this.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * NOTE 2: tcp_syncache.c uses first 5 32-bit words, which identify fport,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * lport, faddr to generate hash, so these fields shouldn't be moved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct in_endpoints {
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int16_t ie_fport; /* foreign port */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int16_t ie_lport; /* local port */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* protocol dependent part, local and foreign addr */
199767f8919635c4928607450d9e0abb932109ceToomas Soome union {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* foreign host table entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_addr_4in6 ie46_foreign;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in6_addr ie6_foreign;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } ie_dependfaddr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome union {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* local host table entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_addr_4in6 ie46_local;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in6_addr ie6_local;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } ie_dependladdr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int32_t ie6_zoneid; /* scope zone id */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ie_laddr ie_dependladdr.ie46_local.ia46_addr4
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ie6_faddr ie_dependfaddr.ie6_foreign
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ie6_laddr ie_dependladdr.ie6_local
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * XXX The defines for inc_* are hacks and should be changed to direct
199767f8919635c4928607450d9e0abb932109ceToomas Soome * references.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct in_conninfo {
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int8_t inc_flags;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int8_t inc_len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int16_t inc_fibnum; /* XXX was pad, 16 bits is plenty */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* protocol dependent part */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_endpoints inc_ie;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags for inc_flags.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INC_ISIPV6 0x01
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inc_isipv6 inc_flags /* temp compatability */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inc_fport inc_ie.ie_fport
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inc_lport inc_ie.ie_lport
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inc_faddr inc_ie.ie_faddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inc_laddr inc_ie.ie_laddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inc6_faddr inc_ie.ie6_faddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inc6_laddr inc_ie.ie6_laddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inc6_zoneid inc_ie.ie6_zoneid
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct icmp6_filter;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * struct inpcb captures the network layer state for TCP, UDP, and raw IPv4 and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IPv6 sockets. In the case of TCP and UDP, further per-connection state is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * hung off of inp_ppcb most of the time. Almost all fields of struct inpcb
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are static after creation or protected by a per-inpcb rwlock, inp_lock. A
199767f8919635c4928607450d9e0abb932109ceToomas Soome * few fields are protected by multiple locks as indicated in the locking notes
199767f8919635c4928607450d9e0abb932109ceToomas Soome * below. For these fields, all of the listed locks must be write-locked for
199767f8919635c4928607450d9e0abb932109ceToomas Soome * any modifications. However, these fields can be safely read while any one of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the listed locks are read-locked. This model can permit greater concurrency
199767f8919635c4928607450d9e0abb932109ceToomas Soome * for read operations. For example, connections can be looked up while only
199767f8919635c4928607450d9e0abb932109ceToomas Soome * holding a read lock on the global pcblist lock. This is important for
199767f8919635c4928607450d9e0abb932109ceToomas Soome * performance when attempting to find the connection for a packet given its IP
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and port tuple.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * One noteworthy exception is that the global pcbinfo lock follows a different
199767f8919635c4928607450d9e0abb932109ceToomas Soome * set of rules in relation to the inp_list field. Rather than being
199767f8919635c4928607450d9e0abb932109ceToomas Soome * write-locked for modifications and read-locked for list iterations, it must
199767f8919635c4928607450d9e0abb932109ceToomas Soome * be read-locked during modifications and write-locked during list iterations.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This ensures that the relatively rare global list iterations safely walk a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * stable snapshot of connections while allowing more common list modifications
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to safely grab the pcblist lock just while adding or removing a connection
199767f8919635c4928607450d9e0abb932109ceToomas Soome * from the global list.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Key:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (c) - Constant after initialization
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (g) - Protected by the pcbgroup lock
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (i) - Protected by the inpcb lock
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (p) - Protected by the pcbinfo lock for the inpcb
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (l) - Protected by the pcblist lock for the inpcb
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (h) - Protected by the pcbhash lock for the inpcb
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (s) - Protected by another subsystem's locks
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (x) - Undefined locking
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * A few other notes:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When a read lock is held, stability of the field is guaranteed; to write
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to a field, a write lock must generally be held.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * netinet/netinet6-layer code should not assume that the inp_socket pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is safe to dereference without inp_lock being held, even for protocols
199767f8919635c4928607450d9e0abb932109ceToomas Soome * other than TCP (where the inpcb persists during TIMEWAIT even after the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * socket has been freed), or there may be close(2)-related races.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The inp_vflag field is overloaded, and would otherwise ideally be (c).
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * TODO: Currently only the TCP stack is leveraging the global pcbinfo lock
199767f8919635c4928607450d9e0abb932109ceToomas Soome * read-lock usage during modification, this model can be applied to other
199767f8919635c4928607450d9e0abb932109ceToomas Soome * protocols (especially SCTP).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcb {
199767f8919635c4928607450d9e0abb932109ceToomas Soome LIST_ENTRY(inpcb) inp_hash; /* (h/i) hash list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome LIST_ENTRY(inpcb) inp_pcbgrouphash; /* (g/i) hash list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome LIST_ENTRY(inpcb) inp_list; /* (p/l) list for all PCBs for proto */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* (p[w]) for list iteration */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* (p[r]/l) for addition/removal */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *inp_ppcb; /* (i) pointer to per-protocol pcb */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbinfo *inp_pcbinfo; /* (c) PCB list info */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbgroup *inp_pcbgroup; /* (g/i) PCB group list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome LIST_ENTRY(inpcb) inp_pcbgroup_wild; /* (g/i/h) group wildcard entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct socket *inp_socket; /* (i) back pointer to socket */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct ucred *inp_cred; /* (c) cache of socket cred */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int32_t inp_flow; /* (i) IPv6 flow information */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int inp_flags; /* (i) generic IP/datagram flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int inp_flags2; /* (i) generic IP/datagram flags #2*/
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char inp_vflag; /* (i) IP version flag (v4/v6) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char inp_ip_ttl; /* (i) time to live proto */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char inp_ip_p; /* (c) protocol proto */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char inp_ip_minttl; /* (i) minimum TTL or drop */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t inp_flowid; /* (x) flow id / queue id */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int inp_refcount; /* (i) refcount */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *inp_pspare[5]; /* (x) route caching / general use */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t inp_flowtype; /* (x) M_HASHTYPE value */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t inp_rss_listen_bucket; /* (x) overridden RSS listen bucket */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int inp_ispare[4]; /* (x) route caching / user cookie /
199767f8919635c4928607450d9e0abb932109ceToomas Soome * general use */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Local and foreign ports, local and foreign addr. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_conninfo inp_inc; /* (i) list for PCB's local port */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* MAC and IPSEC policy information. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct label *inp_label; /* (i) MAC label */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbpolicy *inp_sp; /* (s) for IPSEC */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Protocol-dependent part; options. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char inp4_ip_tos; /* (i) type of service proto */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct mbuf *inp4_options; /* (i) IP options */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct ip_moptions *inp4_moptions; /* (i) IP mcast options */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } inp_depend4;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* (i) IP options */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct mbuf *inp6_options;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* (i) IP6 options for outgoing packets */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct ip6_pktopts *inp6_outputopts;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* (i) IP multicast options */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct ip6_moptions *inp6_moptions;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* (i) ICMPv6 code type filter */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct icmp6_filter *inp6_icmp6filt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* (i) IPV6_CHECKSUM setsockopt */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int inp6_cksum;
199767f8919635c4928607450d9e0abb932109ceToomas Soome short inp6_hops;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } inp_depend6;
199767f8919635c4928607450d9e0abb932109ceToomas Soome LIST_ENTRY(inpcb) inp_portlist; /* (i/h) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbport *inp_phd; /* (i/h) head of this list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_zero_size offsetof(struct inpcb, inp_gencnt)
199767f8919635c4928607450d9e0abb932109ceToomas Soome inp_gen_t inp_gencnt; /* (c) generation count */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct llentry *inp_lle; /* cached L2 information */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct rtentry *inp_rt; /* cached L3 information */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct rwlock inp_lock;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_fport inp_inc.inc_fport
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_lport inp_inc.inc_lport
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_faddr inp_inc.inc_faddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_laddr inp_inc.inc_laddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_ip_tos inp_depend4.inp4_ip_tos
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_options inp_depend4.inp4_options
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_moptions inp_depend4.inp4_moptions
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_faddr inp_inc.inc6_faddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_laddr inp_inc.inc6_laddr
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_zoneid inp_inc.inc6_zoneid
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_hops inp_depend6.inp6_hops /* default hop limit */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_flowinfo inp_flow
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_options inp_depend6.inp6_options
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_outputopts inp_depend6.inp6_outputopts
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_moptions inp_depend6.inp6_moptions
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_icmp6filt inp_depend6.inp6_icmp6filt
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define in6p_cksum inp_depend6.inp6_cksum
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inp_vnet inp_pcbinfo->ipi_vnet
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The range of the generation count, as used in this implementation, is 9e19.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We would have to create 300 billion connections per second for this number
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to roll over in a year. This seems sufficiently unlikely that we simply
199767f8919635c4928607450d9e0abb932109ceToomas Soome * don't concern ourselves with that possibility.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Interface exported to userland by various protocols which use inpcbs. Hack
199767f8919635c4928607450d9e0abb932109ceToomas Soome * alert -- only define if struct xsocket is in scope.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _SYS_SOCKETVAR_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct xinpcb {
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t xi_len; /* length of this structure */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcb xi_inp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct xsocket xi_socket;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_quad_t xi_alignment_hack;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct xinpgen {
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t xig_len; /* length of this structure */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int xig_count; /* number of PCBs at this time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome inp_gen_t xig_gen; /* generation count at this time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome so_gen_t xig_sogen; /* socket generation count at this time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _SYS_SOCKETVAR_H_ */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcbport {
199767f8919635c4928607450d9e0abb932109ceToomas Soome LIST_ENTRY(inpcbport) phd_hash;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbhead phd_pcblist;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_short phd_port;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global data structure for each high-level protocol (UDP, TCP, ...) in both
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IPv4 and IPv6. Holds inpcb lists and information for managing them.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Each pcbinfo is protected by three locks: ipi_lock, ipi_hash_lock and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ipi_list_lock:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * - ipi_lock covering the global pcb list stability during loop iteration,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * - ipi_hash_lock covering the hashed lookup tables,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * - ipi_list_lock covering mutable global fields (such as the global
199767f8919635c4928607450d9e0abb932109ceToomas Soome * pcb list)
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The lock order is:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ipi_lock (before)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * inpcb locks (before)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ipi_list locks (before)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * {ipi_hash_lock, pcbgroup locks}
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Locking key:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (c) Constant or nearly constant after initialisation
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (g) Locked by ipi_lock
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (l) Locked by ipi_list_lock
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (h) Read using either ipi_hash_lock or inpcb lock; write requires both
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (p) Protected by one or more pcbgroup locks
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (x) Synchronisation properties poorly defined
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcbinfo {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global lock protecting full inpcb list traversal
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct rwlock ipi_lock;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global list of inpcbs on the protocol.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbhead *ipi_listhead; /* (g/l) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int ipi_count; /* (l) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Generation count -- incremented each time a connection is allocated
199767f8919635c4928607450d9e0abb932109ceToomas Soome * or freed.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_quad_t ipi_gencnt; /* (l) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Fields associated with port lookup and allocation.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_short ipi_lastport; /* (x) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_short ipi_lastlow; /* (x) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_short ipi_lasthi; /* (x) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * UMA zone from which inpcbs are allocated for this protocol.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct uma_zone *ipi_zone; /* (c) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Connection groups associated with this protocol. These fields are
199767f8919635c4928607450d9e0abb932109ceToomas Soome * constant, but pcbgroup structures themselves are protected by
199767f8919635c4928607450d9e0abb932109ceToomas Soome * per-pcbgroup locks.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbgroup *ipi_pcbgroups; /* (c) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int ipi_npcbgroups; /* (c) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int ipi_hashfields; /* (c) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global lock protecting non-pcbgroup hash lookup tables.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct rwlock ipi_hash_lock;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global hash of inpcbs, hashed by local and foreign addresses and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * port numbers.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbhead *ipi_hashbase; /* (h) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long ipi_hashmask; /* (h) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global hash of inpcbs, hashed by only local port number.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbporthead *ipi_porthashbase; /* (h) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long ipi_porthashmask; /* (h) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List of wildcard inpcbs for use with pcbgroups. In the past, was
199767f8919635c4928607450d9e0abb932109ceToomas Soome * per-pcbgroup but is now global. All pcbgroup locks must be held
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to modify the list, so any is sufficient to read it.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbhead *ipi_wildbase; /* (p) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long ipi_wildmask; /* (p) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Pointer to network stack instance
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct vnet *ipi_vnet; /* (c) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * general use 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *ipi_pspare[2];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global lock protecting global inpcb list, inpcb count, etc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct rwlock ipi_list_lock;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Connection groups hold sets of connections that have similar CPU/thread
199767f8919635c4928607450d9e0abb932109ceToomas Soome * affinity. Each connection belongs to exactly one connection group.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcbgroup {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Per-connection group hash of inpcbs, hashed by local and foreign
199767f8919635c4928607450d9e0abb932109ceToomas Soome * addresses and port numbers.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct inpcbhead *ipg_hashbase; /* (c) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long ipg_hashmask; /* (c) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Notional affinity of this pcbgroup.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int ipg_cpu; /* (p) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Per-connection group lock, not to be confused with ipi_lock.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Protects the hash table hung off the group, but also the global
199767f8919635c4928607450d9e0abb932109ceToomas Soome * wildcard list in inpcbinfo.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct mtx ipg_lock;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} __aligned(CACHE_LINE_SIZE);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LOCK_INIT(inp, d, t) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome rw_init_flags(&(inp)->inp_lock, (t), RW_RECURSE | RW_DUPOK)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LOCK_DESTROY(inp) rw_destroy(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RLOCK(inp) rw_rlock(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_WLOCK(inp) rw_wlock(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_TRY_RLOCK(inp) rw_try_rlock(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_TRY_WLOCK(inp) rw_try_wlock(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RUNLOCK(inp) rw_runlock(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_WUNLOCK(inp) rw_wunlock(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_TRY_UPGRADE(inp) rw_try_upgrade(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_DOWNGRADE(inp) rw_downgrade(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_WLOCKED(inp) rw_wowned(&(inp)->inp_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_LOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_RLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_WLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_WLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_UNLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_UNLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * These locking functions are for inpcb consumers outside of sys/netinet,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * more specifically, they were added for the benefit of TOE drivers. The
199767f8919635c4928607450d9e0abb932109ceToomas Soome * macros are reserved for use by the stack.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_wlock(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_wunlock(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_rlock(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_runlock(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef INVARIANTS
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_lock_assert(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_unlock_assert(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic __inline void
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinp_lock_assert(struct inpcb *inp __unused)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic __inline void
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinp_unlock_assert(struct inpcb *inp __unused)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_apply_all(void (*func)(struct inpcb *, void *), void *arg);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint inp_ip_tos_get(const struct inpcb *inp);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_ip_tos_set(struct inpcb *inp, int val);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct socket *
199767f8919635c4928607450d9e0abb932109ceToomas Soome inp_inpcbtosocket(struct inpcb *inp);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct tcpcb *
199767f8919635c4928607450d9e0abb932109ceToomas Soome inp_inpcbtotcpcb(struct inpcb *inp);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp,
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t *faddr, uint16_t *fp);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeshort inp_so_options(const struct inpcb *inp);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _KERNEL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_LOCK_INIT(ipi, d) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome rw_init_flags(&(ipi)->ipi_lock, (d), RW_RECURSE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_RLOCK(ipi) rw_rlock(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_WLOCK(ipi) rw_wlock(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_TRY_RLOCK(ipi) rw_try_rlock(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_TRY_WLOCK(ipi) rw_try_wlock(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_TRY_UPGRADE(ipi) rw_try_upgrade(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_WLOCKED(ipi) rw_wowned(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_LOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_LOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_RLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_RLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_WLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_WLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INFO_UNLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_UNLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_LOCK_INIT(ipi, d) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome rw_init_flags(&(ipi)->ipi_list_lock, (d), 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_list_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_RLOCK(ipi) rw_rlock(&(ipi)->ipi_list_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_WLOCK(ipi) rw_wlock(&(ipi)->ipi_list_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_TRY_RLOCK(ipi) rw_try_rlock(&(ipi)->ipi_list_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_TRY_WLOCK(ipi) rw_try_wlock(&(ipi)->ipi_list_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_TRY_UPGRADE(ipi) rw_try_upgrade(&(ipi)->ipi_list_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_list_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_list_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_LOCK_ASSERT(ipi) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome rw_assert(&(ipi)->ipi_list_lock, RA_LOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_RLOCK_ASSERT(ipi) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome rw_assert(&(ipi)->ipi_list_lock, RA_RLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_WLOCK_ASSERT(ipi) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome rw_assert(&(ipi)->ipi_list_lock, RA_WLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LIST_UNLOCK_ASSERT(ipi) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome rw_assert(&(ipi)->ipi_list_lock, RA_UNLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HASH_LOCK_INIT(ipi, d) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome rw_init_flags(&(ipi)->ipi_hash_lock, (d), 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HASH_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_hash_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HASH_RLOCK(ipi) rw_rlock(&(ipi)->ipi_hash_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HASH_WLOCK(ipi) rw_wlock(&(ipi)->ipi_hash_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HASH_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_hash_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HASH_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_hash_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HASH_LOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_hash_lock, \
199767f8919635c4928607450d9e0abb932109ceToomas Soome RA_LOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HASH_WLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_hash_lock, \
199767f8919635c4928607450d9e0abb932109ceToomas Soome RA_WLOCKED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_GROUP_LOCK_INIT(ipg, d) mtx_init(&(ipg)->ipg_lock, (d), NULL, \
199767f8919635c4928607450d9e0abb932109ceToomas Soome MTX_DEF | MTX_DUPOK)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_GROUP_LOCK_DESTROY(ipg) mtx_destroy(&(ipg)->ipg_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_GROUP_LOCK(ipg) mtx_lock(&(ipg)->ipg_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_GROUP_LOCK_ASSERT(ipg) mtx_assert(&(ipg)->ipg_lock, MA_OWNED)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_GROUP_UNLOCK(ipg) mtx_unlock(&(ipg)->ipg_lock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_PCBHASH(faddr, lport, fport, mask) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_PCBPORTHASH(lport, mask) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (ntohs((lport)) & (mask))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP6_PCBHASHKEY(faddr) ((faddr)->s6_addr32[3])
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags for inp_vflags -- historically version flags only
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_IPV4 0x1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_IPV6 0x2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_IPV6PROTO 0x4 /* opened under IPv6 protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags for inp_flags.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RECVOPTS 0x00000001 /* receive incoming IP options */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RECVRETOPTS 0x00000002 /* receive IP options for reply */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RECVDSTADDR 0x00000004 /* receive IP dst address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HDRINCL 0x00000008 /* user supplies entire IP header */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_HIGHPORT 0x00000010 /* user wants "high" port binding */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LOWPORT 0x00000020 /* user wants "low" port binding */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_ANONPORT 0x00000040 /* port chosen for user */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RECVIF 0x00000080 /* receive incoming interface */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_MTUDISC 0x00000100 /* user can do MTU discovery */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* 0x000200 unused: was INP_FAITH */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RECVTTL 0x00000400 /* receive incoming IP TTL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_DONTFRAG 0x00000800 /* don't fragment packet */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_BINDANY 0x00001000 /* allow bind to any address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_INHASHLIST 0x00002000 /* in_pcbinshash() has been called */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RECVTOS 0x00004000 /* receive incoming IP TOS */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_HOPOPTS 0x00040000 /* receive hop-by-hop options */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_DSTOPTS 0x00080000 /* receive dst options after rthdr */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_RTHDR 0x00100000 /* receive routing header */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_RTHDRDSTOPTS 0x00200000 /* receive dstoptions before rthdr */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_TCLASS 0x00400000 /* receive traffic class value */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_AUTOFLOWLABEL 0x00800000 /* attach flowlabel automatically */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_TIMEWAIT 0x01000000 /* in TIMEWAIT, ppcb is tcptw */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_ONESBCAST 0x02000000 /* send all-ones broadcast */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_DROPPED 0x04000000 /* protocol drop flag */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_SOCKREF 0x08000000 /* strong socket reference */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RESERVED_0 0x10000000 /* reserved field */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RESERVED_1 0x20000000 /* reserved field */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IN6P_MTU 0x80000000 /* receive path MTU */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
199767f8919635c4928607450d9e0abb932109ceToomas Soome INP_RECVIF|INP_RECVTTL|INP_RECVTOS|\
199767f8919635c4928607450d9e0abb932109ceToomas Soome IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
199767f8919635c4928607450d9e0abb932109ceToomas Soome IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
199767f8919635c4928607450d9e0abb932109ceToomas Soome IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
199767f8919635c4928607450d9e0abb932109ceToomas Soome IN6P_MTU)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags for inp_flags2.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_LLE_VALID 0x00000001 /* cached lle is valid */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RT_VALID 0x00000002 /* cached rtentry is valid */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_PCBGROUPWILD 0x00000004 /* in pcbgroup wildcard list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_REUSEPORT 0x00000008 /* SO_REUSEPORT option is set */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_FREED 0x00000010 /* inp itself is not valid */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_REUSEADDR 0x00000020 /* SO_REUSEADDR option is set */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_BINDMULTI 0x00000040 /* IP_BINDMULTI option is set */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RSS_BUCKET_SET 0x00000080 /* IP_RSS_LISTEN_BUCKET is set */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RECVFLOWID 0x00000100 /* populate recv datagram with flow info */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_RECVRSSBUCKETID 0x00000200 /* populate recv datagram with bucket id */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags passed to in_pcblookup*() functions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INPLOOKUP_WILDCARD 0x00000001 /* Allow wildcard sockets. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INPLOOKUP_RLOCKPCB 0x00000002 /* Return inpcb read-locked. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INPLOOKUP_WLOCKPCB 0x00000004 /* Return inpcb write-locked. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INPLOOKUP_MASK (INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome INPLOOKUP_WLOCKPCB)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Constants for pcbinfo.ipi_hashfields.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IPI_HASHFIELDS_NONE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IPI_HASHFIELDS_2TUPLE 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IPI_HASHFIELDS_4TUPLE 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_reservedhigh);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_reservedlow);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_lowfirstauto);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_lowlastauto);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_firstauto);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_lastauto);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_hifirstauto);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_hilastauto);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_randomized);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_randomcps);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_randomtime);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_stoprandom);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeVNET_DECLARE(int, ipport_tcpallocs);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_reservedhigh VNET(ipport_reservedhigh)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_reservedlow VNET(ipport_reservedlow)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_lowfirstauto VNET(ipport_lowfirstauto)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_lowlastauto VNET(ipport_lowlastauto)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_firstauto VNET(ipport_firstauto)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_lastauto VNET(ipport_lastauto)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_hifirstauto VNET(ipport_hifirstauto)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_hilastauto VNET(ipport_hilastauto)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_randomized VNET(ipport_randomized)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_randomcps VNET(ipport_randomcps)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_randomtime VNET(ipport_randomtime)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_stoprandom VNET(ipport_stoprandom)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define V_ipport_tcpallocs VNET(ipport_tcpallocs)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbinfo_destroy(struct inpcbinfo *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbinfo_init(struct inpcbinfo *, const char *, struct inpcbhead *,
199767f8919635c4928607450d9e0abb932109ceToomas Soome int, int, char *, uma_init, uma_fini, uint32_t, u_int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbbind_check_bindmulti(const struct inpcb *ni,
199767f8919635c4928607450d9e0abb932109ceToomas Soome const struct inpcb *oi);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcbgroup *
199767f8919635c4928607450d9e0abb932109ceToomas Soome in_pcbgroup_byhash(struct inpcbinfo *, u_int, uint32_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcbgroup *
199767f8919635c4928607450d9e0abb932109ceToomas Soome in_pcbgroup_byinpcb(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcbgroup *
199767f8919635c4928607450d9e0abb932109ceToomas Soome in_pcbgroup_bytuple(struct inpcbinfo *, struct in_addr, u_short,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_addr, u_short);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbgroup_destroy(struct inpcbinfo *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbgroup_enabled(struct inpcbinfo *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbgroup_init(struct inpcbinfo *, u_int, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbgroup_remove(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbgroup_update(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbgroup_update_mbuf(struct inpcb *, struct mbuf *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcballoc(struct socket *, struct inpcbinfo *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcb_lport(struct inpcb *, struct in_addr *, u_short *,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct ucred *, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_short *, struct ucred *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbconnect_mbuf(struct inpcb *, struct sockaddr *, struct ucred *,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct mbuf *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_short *, in_addr_t *, u_short *, struct inpcb **,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct ucred *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbdetach(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbdisconnect(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbdrop(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbfree(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbinshash(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbinshash_nopcbgroup(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbladdr(struct inpcb *, struct in_addr *, struct in_addr *,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct ucred *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcb *
199767f8919635c4928607450d9e0abb932109ceToomas Soome in_pcblookup_local(struct inpcbinfo *,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_addr, u_short, int, struct ucred *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcb *
199767f8919635c4928607450d9e0abb932109ceToomas Soome in_pcblookup(struct inpcbinfo *, struct in_addr, u_int,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_addr, u_int, int, struct ifnet *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcb *
199767f8919635c4928607450d9e0abb932109ceToomas Soome in_pcblookup_mbuf(struct inpcbinfo *, struct in_addr, u_int,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct in_addr, u_int, int, struct ifnet *, struct mbuf *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr,
199767f8919635c4928607450d9e0abb932109ceToomas Soome int, struct inpcb *(*)(struct inpcb *, int));
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbref(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbrehash(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbrehash_mbuf(struct inpcb *, struct mbuf *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbrele(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbrele_rlocked(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_pcbrele_wlocked(struct inpcb *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbsetsolabel(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_getpeeraddr(struct socket *so, struct sockaddr **nam);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint in_getsockaddr(struct socket *so, struct sockaddr **nam);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct sockaddr *
199767f8919635c4928607450d9e0abb932109ceToomas Soome in_sockaddr(in_port_t port, struct in_addr *addr);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid in_pcbsosetlabel(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _KERNEL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_NETINET_IN_PCB_H_ */