Home | History | Annotate | Line # | Download | only in netinet
sctp_pcb.h revision 1.6
      1  1.1       rjs /*	$KAME: sctp_pcb.h,v 1.21 2005/07/16 01:18:47 suz Exp $	*/
      2  1.6     ozaki /*	$NetBSD: sctp_pcb.h,v 1.6 2022/10/28 05:20:08 ozaki-r Exp $ */
      3  1.1       rjs 
      4  1.1       rjs #ifndef __SCTP_PCB_H__
      5  1.1       rjs #define __SCTP_PCB_H__
      6  1.1       rjs 
      7  1.1       rjs /*
      8  1.1       rjs  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
      9  1.1       rjs  * All rights reserved.
     10  1.1       rjs  *
     11  1.1       rjs  * Redistribution and use in source and binary forms, with or without
     12  1.1       rjs  * modification, are permitted provided that the following conditions
     13  1.1       rjs  * are met:
     14  1.1       rjs  * 1. Redistributions of source code must retain the above copyright
     15  1.1       rjs  *    notice, this list of conditions and the following disclaimer.
     16  1.1       rjs  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1       rjs  *    notice, this list of conditions and the following disclaimer in the
     18  1.1       rjs  *    documentation and/or other materials provided with the distribution.
     19  1.1       rjs  * 3. All advertising materials mentioning features or use of this software
     20  1.1       rjs  *    must display the following acknowledgement:
     21  1.1       rjs  *      This product includes software developed by Cisco Systems, Inc.
     22  1.1       rjs  * 4. Neither the name of the project nor the names of its contributors
     23  1.1       rjs  *    may be used to endorse or promote products derived from this software
     24  1.1       rjs  *    without specific prior written permission.
     25  1.1       rjs  *
     26  1.1       rjs  * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1       rjs  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1       rjs  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1       rjs  * ARE DISCLAIMED.  IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
     30  1.1       rjs  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1       rjs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1       rjs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1       rjs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1       rjs  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1       rjs  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1       rjs  * SUCH DAMAGE.
     37  1.1       rjs  */
     38  1.1       rjs 
     39  1.1       rjs /*
     40  1.1       rjs  * We must have V6 so the size of the proto can be calculated. Otherwise
     41  1.1       rjs  * we would not allocate enough for Net/Open BSD :-<
     42  1.1       rjs  */
     43  1.1       rjs #include <net/if.h>
     44  1.6     ozaki #include <netinet/in_pcb.h>
     45  1.1       rjs #include <netinet/ip6.h>
     46  1.1       rjs #include <netinet6/ip6_var.h>
     47  1.1       rjs #include <netinet6/ip6protosw.h>
     48  1.1       rjs #include <netinet6/in6_var.h>
     49  1.1       rjs #include <netinet6/in6_pcb.h>
     50  1.1       rjs 
     51  1.1       rjs #include <netinet/sctp.h>
     52  1.1       rjs #include <netinet/sctp_constants.h>
     53  1.1       rjs 
     54  1.1       rjs LIST_HEAD(sctppcbhead, sctp_inpcb);
     55  1.1       rjs LIST_HEAD(sctpasochead, sctp_tcb);
     56  1.1       rjs TAILQ_HEAD(sctpsocketq, sctp_socket_q_list);
     57  1.1       rjs LIST_HEAD(sctpladdr, sctp_laddr);
     58  1.1       rjs LIST_HEAD(sctpvtaghead, sctp_tagblock);
     59  1.1       rjs 
     60  1.1       rjs #include <netinet/sctp_structs.h>
     61  1.1       rjs #include <netinet/sctp_uio.h>
     62  1.1       rjs 
     63  1.1       rjs /*
     64  1.1       rjs  * PCB flags
     65  1.1       rjs  */
     66  1.1       rjs #define SCTP_PCB_FLAGS_UDPTYPE		0x00000001
     67  1.1       rjs #define SCTP_PCB_FLAGS_TCPTYPE		0x00000002
     68  1.1       rjs #define SCTP_PCB_FLAGS_BOUNDALL		0x00000004
     69  1.1       rjs #define SCTP_PCB_FLAGS_ACCEPTING	0x00000008
     70  1.1       rjs #define SCTP_PCB_FLAGS_UNBOUND		0x00000010
     71  1.1       rjs #define SCTP_PCB_FLAGS_DO_ASCONF	0x00000020
     72  1.1       rjs #define SCTP_PCB_FLAGS_AUTO_ASCONF	0x00000040
     73  1.1       rjs /* socket options */
     74  1.1       rjs #define SCTP_PCB_FLAGS_NODELAY		0x00000100
     75  1.1       rjs #define SCTP_PCB_FLAGS_AUTOCLOSE	0x00000200
     76  1.1       rjs #define SCTP_PCB_FLAGS_RECVDATAIOEVNT	0x00000400
     77  1.1       rjs #define SCTP_PCB_FLAGS_RECVASSOCEVNT	0x00000800
     78  1.1       rjs #define SCTP_PCB_FLAGS_RECVPADDREVNT	0x00001000
     79  1.1       rjs #define SCTP_PCB_FLAGS_RECVPEERERR	0x00002000
     80  1.1       rjs #define SCTP_PCB_FLAGS_RECVSENDFAILEVNT	0x00004000
     81  1.1       rjs #define SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT	0x00008000
     82  1.1       rjs #define SCTP_PCB_FLAGS_ADAPTIONEVNT	0x00010000
     83  1.1       rjs #define SCTP_PCB_FLAGS_PDAPIEVNT	0x00020000
     84  1.1       rjs #define SCTP_PCB_FLAGS_STREAM_RESETEVNT 0x00040000
     85  1.1       rjs #define SCTP_PCB_FLAGS_NO_FRAGMENT	0x00080000
     86  1.1       rjs /* TCP model support */
     87  1.1       rjs #define SCTP_PCB_FLAGS_CONNECTED	0x00100000
     88  1.1       rjs #define SCTP_PCB_FLAGS_IN_TCPPOOL	0x00200000
     89  1.1       rjs #define SCTP_PCB_FLAGS_DONT_WAKE	0x00400000
     90  1.1       rjs #define SCTP_PCB_FLAGS_WAKEOUTPUT	0x00800000
     91  1.1       rjs #define SCTP_PCB_FLAGS_WAKEINPUT	0x01000000
     92  1.1       rjs #define SCTP_PCB_FLAGS_BOUND_V6		0x02000000
     93  1.1       rjs #define SCTP_PCB_FLAGS_NEEDS_MAPPED_V4	0x04000000
     94  1.1       rjs #define SCTP_PCB_FLAGS_BLOCKING_IO	0x08000000
     95  1.1       rjs #define SCTP_PCB_FLAGS_SOCKET_GONE	0x10000000
     96  1.1       rjs #define SCTP_PCB_FLAGS_SOCKET_ALLGONE	0x20000000
     97  1.1       rjs 
     98  1.1       rjs /* flags to copy to new PCB */
     99  1.1       rjs #define SCTP_PCB_COPY_FLAGS		0x0707ff64
    100  1.1       rjs 
    101  1.1       rjs #define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask)
    102  1.1       rjs #define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask)
    103  1.1       rjs 
    104  1.1       rjs struct sctp_laddr {
    105  1.1       rjs 	LIST_ENTRY(sctp_laddr) sctp_nxt_addr;	/* next in list */
    106  1.1       rjs 	struct ifaddr *ifa;
    107  1.1       rjs };
    108  1.1       rjs 
    109  1.1       rjs struct sctp_timewait {
    110  1.1       rjs 	uint32_t tv_sec_at_expire;	/* the seconds from boot to expire */
    111  1.1       rjs 	uint32_t v_tag;		/* the vtag that can not be reused */
    112  1.1       rjs };
    113  1.1       rjs 
    114  1.1       rjs struct sctp_tagblock {
    115  1.1       rjs         LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock;
    116  1.1       rjs 	struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
    117  1.1       rjs };
    118  1.1       rjs 
    119  1.1       rjs struct sctp_epinfo {
    120  1.1       rjs 	struct sctpasochead *sctp_asochash;
    121  1.1       rjs 	u_long hashasocmark;
    122  1.1       rjs 
    123  1.1       rjs 	struct sctppcbhead *sctp_ephash;
    124  1.1       rjs 	u_long hashmark;
    125  1.1       rjs 
    126  1.1       rjs 	/*
    127  1.1       rjs 	 * The TCP model represents a substantial overhead in that we get
    128  1.1       rjs 	 * an additional hash table to keep explicit connections in. The
    129  1.1       rjs 	 * listening TCP endpoint will exist in the usual ephash above and
    130  1.1       rjs 	 * accept only INIT's. It will be incapable of sending off an INIT.
    131  1.1       rjs 	 * When a dg arrives we must look in the normal ephash. If we find
    132  1.1       rjs 	 * a TCP endpoint that will tell us to go to the specific endpoint
    133  1.1       rjs 	 * hash and re-hash to find the right assoc/socket. If we find a
    134  1.1       rjs 	 * UDP model socket we then must complete the lookup. If this fails,
    135  1.1       rjs 	 * i.e. no association can be found then we must continue to see if
    136  1.1       rjs 	 * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket
    137  1.1       rjs 	 * acts like a TCP model connected socket).
    138  1.1       rjs 	 */
    139  1.1       rjs 	struct sctppcbhead *sctp_tcpephash;
    140  1.1       rjs 	u_long hashtcpmark;
    141  1.1       rjs 	uint32_t hashtblsize;
    142  1.1       rjs 
    143  1.1       rjs 	struct sctppcbhead listhead;
    144  1.1       rjs 
    145  1.1       rjs 	struct sctpiterators iteratorhead;
    146  1.1       rjs 
    147  1.1       rjs 	/* ep zone info */
    148  1.1       rjs #if defined(__FreeBSD__) || defined(__APPLE__)
    149  1.1       rjs #if __FreeBSD_version >= 500000
    150  1.1       rjs 	struct uma_zone *ipi_zone_ep;
    151  1.1       rjs 	struct uma_zone *ipi_zone_asoc;
    152  1.1       rjs 	struct uma_zone *ipi_zone_laddr;
    153  1.1       rjs 	struct uma_zone *ipi_zone_net;
    154  1.1       rjs 	struct uma_zone *ipi_zone_chunk;
    155  1.1       rjs 	struct uma_zone *ipi_zone_sockq;
    156  1.1       rjs #else
    157  1.1       rjs 	struct vm_zone *ipi_zone_ep;
    158  1.1       rjs 	struct vm_zone *ipi_zone_asoc;
    159  1.1       rjs 	struct vm_zone *ipi_zone_laddr;
    160  1.1       rjs 	struct vm_zone *ipi_zone_net;
    161  1.1       rjs 	struct vm_zone *ipi_zone_chunk;
    162  1.1       rjs 	struct vm_zone *ipi_zone_sockq;
    163  1.1       rjs #endif
    164  1.1       rjs #endif
    165  1.1       rjs #if defined(__NetBSD__) || defined(__OpenBSD__)
    166  1.1       rjs 	struct pool ipi_zone_ep;
    167  1.1       rjs 	struct pool ipi_zone_asoc;
    168  1.1       rjs 	struct pool ipi_zone_laddr;
    169  1.1       rjs 	struct pool ipi_zone_net;
    170  1.1       rjs 	struct pool ipi_zone_chunk;
    171  1.1       rjs 	struct pool ipi_zone_sockq;
    172  1.1       rjs 	struct pool ipi_zone_hash;
    173  1.1       rjs #endif
    174  1.1       rjs 
    175  1.1       rjs #if defined(__FreeBSD__) && __FreeBSD_version >= 503000
    176  1.1       rjs 	struct mtx ipi_ep_mtx;
    177  1.1       rjs 	struct mtx it_mtx;
    178  1.1       rjs #elif 0 /* defined(__NetBSD__) */
    179  1.1       rjs 	krwlock_t ipi_ep_mtx;
    180  1.1       rjs 	kmutex_t it_mtx;
    181  1.1       rjs #endif
    182  1.1       rjs 	u_int ipi_count_ep;
    183  1.1       rjs 	u_quad_t ipi_gencnt_ep;
    184  1.1       rjs 
    185  1.1       rjs 	/* assoc/tcb zone info */
    186  1.1       rjs 	u_int ipi_count_asoc;
    187  1.1       rjs 	u_quad_t ipi_gencnt_asoc;
    188  1.1       rjs 
    189  1.1       rjs 	/* local addrlist zone info */
    190  1.1       rjs 	u_int ipi_count_laddr;
    191  1.1       rjs 	u_quad_t ipi_gencnt_laddr;
    192  1.1       rjs 
    193  1.1       rjs 	/* remote addrlist zone info */
    194  1.1       rjs 	u_int ipi_count_raddr;
    195  1.1       rjs 	u_quad_t ipi_gencnt_raddr;
    196  1.1       rjs 
    197  1.1       rjs 	/* chunk structure list for output */
    198  1.1       rjs 	u_int ipi_count_chunk;
    199  1.1       rjs 	u_quad_t ipi_gencnt_chunk;
    200  1.1       rjs 
    201  1.1       rjs 	/* socket queue zone info */
    202  1.1       rjs 	u_int ipi_count_sockq;
    203  1.1       rjs 	u_quad_t ipi_gencnt_sockq;
    204  1.1       rjs 
    205  1.1       rjs 	struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
    206  1.1       rjs 
    207  1.1       rjs #ifdef _SCTP_NEEDS_CALLOUT_
    208  1.1       rjs 	struct calloutlist callqueue;
    209  1.1       rjs #endif /* _SCTP_NEEDS_CALLOUT_ */
    210  1.1       rjs 
    211  1.1       rjs 	uint32_t mbuf_track;
    212  1.1       rjs 
    213  1.1       rjs 	/* for port allocations */
    214  1.1       rjs 	uint16_t lastport;
    215  1.1       rjs 	uint16_t lastlow;
    216  1.1       rjs 	uint16_t lasthi;
    217  1.1       rjs 
    218  1.1       rjs };
    219  1.1       rjs 
    220  1.1       rjs extern uint32_t sctp_pegs[SCTP_NUMBER_OF_PEGS];
    221  1.1       rjs /*
    222  1.1       rjs  * Here we have all the relevant information for each SCTP entity created.
    223  1.1       rjs  * We will need to modify this as approprate. We also need to figure out
    224  1.1       rjs  * how to access /dev/random.
    225  1.1       rjs  */
    226  1.1       rjs struct sctp_pcb {
    227  1.1       rjs 	unsigned int time_of_secret_change; /* number of seconds from timeval.tv_sec */
    228  1.1       rjs 	uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
    229  1.1       rjs 	unsigned int size_of_a_cookie;
    230  1.1       rjs 
    231  1.1       rjs 	unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
    232  1.1       rjs 	unsigned int sctp_minrto;
    233  1.1       rjs 	unsigned int sctp_maxrto;
    234  1.1       rjs 	unsigned int initial_rto;
    235  1.1       rjs 
    236  1.1       rjs 	int initial_init_rto_max;
    237  1.1       rjs 
    238  1.1       rjs 	uint32_t sctp_sws_sender;
    239  1.1       rjs 	uint32_t sctp_sws_receiver;
    240  1.1       rjs 
    241  1.1       rjs 	/* various thresholds */
    242  1.1       rjs 	/* Max times I will init at a guy */
    243  1.1       rjs 	uint16_t max_init_times;
    244  1.1       rjs 
    245  1.1       rjs 	/* Max times I will send before we consider someone dead */
    246  1.1       rjs 	uint16_t max_send_times;
    247  1.1       rjs 
    248  1.1       rjs 	uint16_t def_net_failure;
    249  1.1       rjs 
    250  1.1       rjs 	/* number of streams to pre-open on a association */
    251  1.1       rjs 	uint16_t pre_open_stream_count;
    252  1.1       rjs 	uint16_t max_open_streams_intome;
    253  1.1       rjs 
    254  1.1       rjs 	/*
    255  1.1       rjs 	 * This timer is kept running per endpoint.  When it fires it
    256  1.1       rjs 	 * will change the secret key.  The default is once a hour
    257  1.1       rjs 	 */
    258  1.1       rjs 	struct sctp_timer signature_change;
    259  1.1       rjs 	int def_cookie_life;
    260  1.1       rjs 	/* defaults to 0 */
    261  1.1       rjs 	int auto_close_time;
    262  1.1       rjs 	uint32_t initial_sequence_debug;
    263  1.1       rjs 	uint32_t adaption_layer_indicator;
    264  1.1       rjs 	uint8_t max_burst;
    265  1.1       rjs 	char current_secret_number;
    266  1.1       rjs 	char last_secret_number;
    267  1.1       rjs };
    268  1.1       rjs 
    269  1.1       rjs #ifndef SCTP_ALIGNMENT
    270  1.1       rjs #define SCTP_ALIGNMENT 32
    271  1.1       rjs #endif
    272  1.1       rjs 
    273  1.1       rjs #ifndef SCTP_ALIGNM1
    274  1.1       rjs #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
    275  1.1       rjs #endif
    276  1.1       rjs 
    277  1.1       rjs #define sctp_lport ip_inp.inp.inp_lport
    278  1.1       rjs 
    279  1.1       rjs struct sctp_socket_q_list {
    280  1.1       rjs 	struct sctp_tcb *tcb;
    281  1.1       rjs 	TAILQ_ENTRY(sctp_socket_q_list) next_sq;
    282  1.1       rjs };
    283  1.1       rjs 
    284  1.1       rjs struct sctp_inpcb {
    285  1.1       rjs 	/*
    286  1.1       rjs 	 * put an inpcb in front of it all, kind of a waste but we need
    287  1.4    andvar 	 * to for compatibility with all the other stuff.
    288  1.1       rjs 	 */
    289  1.1       rjs 	union {
    290  1.1       rjs 		struct inpcb inp;
    291  1.6     ozaki 		char align[(sizeof(struct inpcb) + SCTP_ALIGNM1) &
    292  1.1       rjs 			  ~SCTP_ALIGNM1];
    293  1.1       rjs 	} ip_inp;
    294  1.1       rjs 	LIST_ENTRY(sctp_inpcb) sctp_list;	/* lists all endpoints */
    295  1.1       rjs 	/* hash of all endpoints for model */
    296  1.1       rjs 	LIST_ENTRY(sctp_inpcb) sctp_hash;
    297  1.1       rjs 
    298  1.1       rjs 	/* count of local addresses bound, 0 if bound all */
    299  1.1       rjs 	int laddr_count;
    300  1.1       rjs 	/* list of addrs in use by the EP */
    301  1.1       rjs 	struct sctpladdr sctp_addr_list;
    302  1.1       rjs 	/* used for source address selection rotation */
    303  1.1       rjs 	struct sctp_laddr *next_addr_touse;
    304  1.1       rjs 	struct ifnet *next_ifn_touse;
    305  1.1       rjs 	/* back pointer to our socket */
    306  1.1       rjs 	struct socket *sctp_socket;
    307  1.1       rjs 	uint32_t sctp_flags;			/* flag set */
    308  1.1       rjs 	struct sctp_pcb sctp_ep;		/* SCTP ep data */
    309  1.1       rjs 	/* head of the hash of all associations */
    310  1.1       rjs 	struct sctpasochead *sctp_tcbhash;
    311  1.1       rjs 	u_long sctp_hashmark;
    312  1.1       rjs 	/* head of the list of all associations */
    313  1.1       rjs 	struct sctpasochead sctp_asoc_list;
    314  1.1       rjs 	/* queue of TCB's waiting to stuff data up the socket */
    315  1.1       rjs 	struct sctpsocketq sctp_queue_list;
    316  1.1       rjs 	void *sctp_tcb_at_block;
    317  1.1       rjs 	struct sctp_iterator *inp_starting_point_for_iterator;
    318  1.1       rjs 	int  error_on_block;
    319  1.1       rjs 	uint32_t sctp_frag_point;
    320  1.1       rjs 	uint32_t sctp_vtag_first;
    321  1.1       rjs 	struct mbuf *pkt, *pkt_last, *sb_last_mpkt;
    322  1.1       rjs 	struct mbuf *control;
    323  1.1       rjs #if !(defined(__FreeBSD__) || defined(__APPLE__))
    324  1.1       rjs #ifndef INP_IPV6
    325  1.1       rjs #define INP_IPV6	0x1
    326  1.1       rjs #endif
    327  1.1       rjs #ifndef INP_IPV4
    328  1.1       rjs #define INP_IPV4	0x2
    329  1.1       rjs #endif
    330  1.1       rjs 	u_char inp_vflag;
    331  1.1       rjs 	u_char inp_ip_ttl;
    332  1.1       rjs 	u_char inp_ip_tos;
    333  1.1       rjs 	u_char inp_ip_resv;
    334  1.1       rjs #endif
    335  1.1       rjs #if defined(__FreeBSD__) && __FreeBSD_version >= 503000
    336  1.1       rjs 	struct mtx inp_mtx;
    337  1.1       rjs 	struct mtx inp_create_mtx;
    338  1.1       rjs 	u_int32_t refcount;
    339  1.1       rjs #elif defined(__NetBSD__)
    340  1.1       rjs 	kmutex_t inp_mtx;
    341  1.1       rjs 	kmutex_t inp_create_mtx;
    342  1.1       rjs 	u_int32_t refcount;
    343  1.1       rjs #endif
    344  1.1       rjs };
    345  1.1       rjs 
    346  1.1       rjs struct sctp_tcb {
    347  1.1       rjs 	struct socket *sctp_socket;		/* back pointer to socket */
    348  1.1       rjs 	struct sctp_inpcb *sctp_ep;		/* back pointer to ep */
    349  1.1       rjs 	LIST_ENTRY(sctp_tcb) sctp_tcbhash;	/* next link in hash table */
    350  1.1       rjs 	LIST_ENTRY(sctp_tcb) sctp_tcblist;	/* list of all of the TCB's */
    351  1.1       rjs 	LIST_ENTRY(sctp_tcb) sctp_asocs;
    352  1.1       rjs 	struct sctp_association asoc;
    353  1.1       rjs 	uint16_t rport;			/* remote port in network format */
    354  1.1       rjs 	uint16_t resv;
    355  1.1       rjs #if defined(__FreeBSD__) && __FreeBSD_version >= 503000
    356  1.1       rjs 	struct mtx tcb_mtx;
    357  1.1       rjs #elif defined(__NetBSD__)
    358  1.1       rjs 	kmutex_t tcb_mtx;
    359  1.1       rjs #endif
    360  1.1       rjs };
    361  1.1       rjs 
    362  1.1       rjs #if defined(__FreeBSD__) && __FreeBSD_version >= 503000
    363  1.1       rjs 
    364  1.1       rjs /* General locking concepts:
    365  1.1       rjs  * The goal of our locking is to of course provide
    366  1.1       rjs  * consistency and yet minimize overhead. We will
    367  1.1       rjs  * attempt to use non-recursive locks which are supposed
    368  1.1       rjs  * to be quite inexpensive. Now in order to do this the goal
    369  1.1       rjs  * is that most functions are not aware of locking. Once we
    370  1.1       rjs  * have a TCB we lock it and unlock when we are through. This
    371  1.1       rjs  * means that the TCB lock is kind-of a "global" lock when
    372  1.1       rjs  * working on an association. Caution must be used when
    373  1.1       rjs  * asserting a TCB_LOCK since if we recurse we deadlock.
    374  1.1       rjs  *
    375  1.1       rjs  * Most other locks (INP and INFO) attempt to localize
    376  1.1       rjs  * the locking i.e. we try to contain the lock and
    377  1.1       rjs  * unlock within the function that needs to lock it. This
    378  1.1       rjs  * sometimes mean we do extra locks and unlocks and loose
    379  1.5    andvar  * a bit of efficiency, but if the performance statements about
    380  1.1       rjs  * non-recursive locks are true this should not be a problem.
    381  1.1       rjs  * One issue that arises with this only lock when needed
    382  1.1       rjs  * is that if an implicit association setup is done we
    383  1.1       rjs  * have a problem. If at the time I lookup an association
    384  1.1       rjs  * I have NULL in the tcb return, by the time I call to
    385  1.1       rjs  * create the association some other processor could
    386  1.1       rjs  * have created it. This is what the CREATE lock on
    387  1.1       rjs  * the endpoint. Places where we will be implicitly
    388  1.1       rjs  * creating the association OR just creating an association
    389  1.1       rjs  * (the connect call) will assert the CREATE_INP lock. This
    390  1.1       rjs  * will assure us that during all the lookup of INP and INFO
    391  1.1       rjs  * if another creator is also locking/looking up we can
    392  1.1       rjs  * gate the two to synchronize. So the CREATE_INP lock is
    393  1.1       rjs  * also another one we must use extreme caution in locking
    394  1.1       rjs  * to make sure we don't hit a re-entrancy issue.
    395  1.1       rjs  *
    396  1.1       rjs  * For non FreeBSD 5.x and above we provide a bunch
    397  1.1       rjs  * of EMPTY lock macro's so we can blatantly put locks
    398  1.1       rjs  * everywhere and they reduce to nothing on NetBSD/OpenBSD
    399  1.1       rjs  * and FreeBSD 4.x
    400  1.1       rjs  *
    401  1.1       rjs  */
    402  1.1       rjs 
    403  1.1       rjs 
    404  1.1       rjs /* When working with the global SCTP lists we lock and unlock
    405  1.1       rjs  * the INP_INFO lock. So when we go to lookup an association
    406  1.1       rjs  * we will want to do a SCTP_INP_INFO_RLOCK() and then when
    407  1.1       rjs  * we want to add a new association to the sctppcbinfo list's
    408  1.1       rjs  * we will do a SCTP_INP_INFO_WLOCK().
    409  1.1       rjs  */
    410  1.1       rjs 
    411  1.1       rjs /*
    412  1.1       rjs  * FIX ME, all locks right now have a
    413  1.1       rjs  * recursive check/panic to validate that I
    414  1.1       rjs  * don't have any lock recursion going on.
    415  1.1       rjs  */
    416  1.1       rjs 
    417  1.1       rjs #define SCTP_INP_INFO_LOCK_INIT() \
    418  1.1       rjs         mtx_init(&sctppcbinfo.ipi_ep_mtx, "sctp", "inp_info", MTX_DEF)
    419  1.1       rjs 
    420  1.1       rjs #ifdef xyzzy
    421  1.1       rjs #define SCTP_INP_INFO_RLOCK()	do { 					\
    422  1.1       rjs              if (mtx_owned(&sctppcbinfo.ipi_ep_mtx))                     \
    423  1.1       rjs 		panic("INP INFO Recursive Lock-R");                     \
    424  1.1       rjs              mtx_lock(&sctppcbinfo.ipi_ep_mtx);                         \
    425  1.1       rjs } while (0)
    426  1.1       rjs 
    427  1.1       rjs #define SCTP_INP_INFO_WLOCK()	do { 					\
    428  1.1       rjs              if (mtx_owned(&sctppcbinfo.ipi_ep_mtx))                     \
    429  1.1       rjs 		panic("INP INFO Recursive Lock-W");                     \
    430  1.1       rjs              mtx_lock(&sctppcbinfo.ipi_ep_mtx);                         \
    431  1.1       rjs } while (0)
    432  1.1       rjs 
    433  1.1       rjs #else
    434  1.1       rjs 
    435  1.1       rjs void SCTP_INP_INFO_RLOCK(void);
    436  1.1       rjs void SCTP_INP_INFO_WLOCK(void);
    437  1.1       rjs 
    438  1.1       rjs #endif
    439  1.1       rjs 
    440  1.1       rjs #define SCTP_INP_INFO_RUNLOCK()		mtx_unlock(&sctppcbinfo.ipi_ep_mtx)
    441  1.1       rjs #define SCTP_INP_INFO_WUNLOCK()		mtx_unlock(&sctppcbinfo.ipi_ep_mtx)
    442  1.1       rjs 
    443  1.1       rjs /* The INP locks we will use for locking an SCTP endpoint, so for
    444  1.1       rjs  * example if we want to change something at the endpoint level for
    445  1.3  riastrad  * example cookie secrets we lock the INP level.
    446  1.1       rjs  */
    447  1.1       rjs #define SCTP_INP_LOCK_INIT(_inp) \
    448  1.1       rjs 	mtx_init(&(_inp)->inp_mtx, "sctp", "inp", MTX_DEF | MTX_DUPOK)
    449  1.1       rjs 
    450  1.1       rjs #define SCTP_ASOC_CREATE_LOCK_INIT(_inp) \
    451  1.1       rjs 	mtx_init(&(_inp)->inp_create_mtx, "sctp", "inp_create", \
    452  1.1       rjs 		 MTX_DEF | MTX_DUPOK)
    453  1.1       rjs 
    454  1.1       rjs #define SCTP_INP_LOCK_DESTROY(_inp)	mtx_destroy(&(_inp)->inp_mtx)
    455  1.1       rjs #define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp)	mtx_destroy(&(_inp)->inp_create_mtx)
    456  1.1       rjs 
    457  1.1       rjs #ifdef xyzzy
    458  1.1       rjs #define SCTP_INP_RLOCK(_inp)	do { 					\
    459  1.1       rjs         struct sctp_tcb *xx_stcb;					\
    460  1.1       rjs         xx_stcb = LIST_FIRST(&_inp->sctp_asoc_list);                    \
    461  1.1       rjs         if (xx_stcb)                                                     \
    462  1.1       rjs               if (mtx_owned(&(xx_stcb)->tcb_mtx))                        \
    463  1.1       rjs                      panic("I own TCB lock?");                          \
    464  1.1       rjs         if (mtx_owned(&(_inp)->inp_mtx))                                 \
    465  1.1       rjs 		panic("INP Recursive Lock-R");                          \
    466  1.1       rjs         mtx_lock(&(_inp)->inp_mtx);                                     \
    467  1.1       rjs } while (0)
    468  1.1       rjs 
    469  1.1       rjs #define SCTP_INP_WLOCK(_inp)	do { 					\
    470  1.1       rjs         struct sctp_tcb *xx_stcb;					\
    471  1.1       rjs         xx_stcb = LIST_FIRST(&_inp->sctp_asoc_list);                    \
    472  1.1       rjs         if (xx_stcb)                                                     \
    473  1.1       rjs               if (mtx_owned(&(xx_stcb)->tcb_mtx))                        \
    474  1.1       rjs                      panic("I own TCB lock?");                          \
    475  1.1       rjs         if (mtx_owned(&(_inp)->inp_mtx))                                 \
    476  1.1       rjs 		panic("INP Recursive Lock-W");                          \
    477  1.1       rjs         mtx_lock(&(_inp)->inp_mtx);                                     \
    478  1.1       rjs } while (0)
    479  1.1       rjs 
    480  1.1       rjs #else
    481  1.1       rjs void SCTP_INP_RLOCK(struct sctp_inpcb *);
    482  1.1       rjs void SCTP_INP_WLOCK(struct sctp_inpcb *);
    483  1.1       rjs 
    484  1.1       rjs #endif
    485  1.1       rjs 
    486  1.1       rjs 
    487  1.1       rjs #define SCTP_INP_INCR_REF(_inp)        _inp->refcount++
    488  1.1       rjs 
    489  1.1       rjs #define SCTP_INP_DECR_REF(_inp)         do {                                 \
    490  1.1       rjs                                              if (_inp->refcount > 0)          \
    491  1.1       rjs                                                   _inp->refcount--;          \
    492  1.1       rjs                                              else                            \
    493  1.1       rjs                                                   panic("bad inp refcount"); \
    494  1.1       rjs }while (0)
    495  1.1       rjs 
    496  1.1       rjs #define SCTP_ASOC_CREATE_LOCK(_inp)  do {				\
    497  1.1       rjs         if (mtx_owned(&(_inp)->inp_create_mtx))                          \
    498  1.1       rjs 		panic("INP Recursive CREATE");                          \
    499  1.1       rjs         mtx_lock(&(_inp)->inp_create_mtx);                              \
    500  1.1       rjs } while (0)
    501  1.1       rjs 
    502  1.1       rjs #define SCTP_INP_RUNLOCK(_inp)		mtx_unlock(&(_inp)->inp_mtx)
    503  1.1       rjs #define SCTP_INP_WUNLOCK(_inp)		mtx_unlock(&(_inp)->inp_mtx)
    504  1.1       rjs #define SCTP_ASOC_CREATE_UNLOCK(_inp)	mtx_unlock(&(_inp)->inp_create_mtx)
    505  1.1       rjs 
    506  1.1       rjs /* For the majority of things (once we have found the association) we
    507  1.1       rjs  * will lock the actual association mutex. This will protect all
    508  1.1       rjs  * the assoiciation level queues and streams and such. We will
    509  1.1       rjs  * need to lock the socket layer when we stuff data up into
    510  1.1       rjs  * the receiving sb_mb. I.e. we will need to do an extra
    511  1.1       rjs  * SOCKBUF_LOCK(&so->so_rcv) even though the association is
    512  1.1       rjs  * locked.
    513  1.1       rjs  */
    514  1.1       rjs 
    515  1.1       rjs #define SCTP_TCB_LOCK_INIT(_tcb) \
    516  1.1       rjs 	mutex_init(&(_tcb)->tcb_mtx, MUTEX_DEFAULT, IPL_NET)
    517  1.1       rjs #define SCTP_TCB_LOCK_DESTROY(_tcb)	mtx_destroy(&(_tcb)->tcb_mtx)
    518  1.1       rjs #define SCTP_TCB_LOCK(_tcb)  do {					\
    519  1.1       rjs         if (!mtx_owned(&(_tcb->sctp_ep->inp_mtx)))                       \
    520  1.1       rjs 		panic("TCB locking and no INP lock");                   \
    521  1.1       rjs         if (mtx_owned(&(_tcb)->tcb_mtx))                                 \
    522  1.1       rjs 		panic("TCB Lock-recursive");                            \
    523  1.1       rjs 	mtx_lock(&(_tcb)->tcb_mtx);                                     \
    524  1.1       rjs } while (0)
    525  1.1       rjs #define SCTP_TCB_UNLOCK(_tcb)		mtx_unlock(&(_tcb)->tcb_mtx)
    526  1.1       rjs 
    527  1.1       rjs #define SCTP_ITERATOR_LOCK_INIT() \
    528  1.1       rjs         mtx_init(&sctppcbinfo.it_mtx, "sctp", "iterator", MTX_DEF)
    529  1.1       rjs #define SCTP_ITERATOR_LOCK()  do {					\
    530  1.1       rjs         if (mtx_owned(&sctppcbinfo.it_mtx))                              \
    531  1.1       rjs 		panic("Iterator Lock");                                 \
    532  1.1       rjs 	mtx_lock(&sctppcbinfo.it_mtx);                                  \
    533  1.1       rjs } while (0)
    534  1.1       rjs 
    535  1.1       rjs #define SCTP_ITERATOR_UNLOCK()	        mtx_unlock(&sctppcbinfo.it_mtx)
    536  1.1       rjs #define SCTP_ITERATOR_LOCK_DESTROY()	mtx_destroy(&sctppcbinfo.it_mtx)
    537  1.1       rjs #elif 0 /* defined(__NetBSD__) */
    538  1.1       rjs #define SCTP_INP_INFO_LOCK_INIT() \
    539  1.1       rjs 	rw_init(&sctppcbinfo.ipi_ep_mtx)
    540  1.1       rjs 
    541  1.1       rjs #define SCTP_INP_INFO_RLOCK()	do { 					\
    542  1.1       rjs 		rw_enter(&sctppcbinfo.ipi_ep_mtx, RW_READER);           \
    543  1.1       rjs } while (0)
    544  1.1       rjs 
    545  1.1       rjs #define SCTP_INP_INFO_WLOCK()	do { 					\
    546  1.1       rjs              rw_enter(&sctppcbinfo.ipi_ep_mtx, RW_WRITER);              \
    547  1.1       rjs } while (0)
    548  1.1       rjs 
    549  1.1       rjs #define SCTP_INP_INFO_RUNLOCK()		rw_exit(&sctppcbinfo.ipi_ep_mtx)
    550  1.1       rjs #define SCTP_INP_INFO_WUNLOCK()		rw_exit(&sctppcbinfo.ipi_ep_mtx)
    551  1.1       rjs 
    552  1.1       rjs /* The INP locks we will use for locking an SCTP endpoint, so for
    553  1.1       rjs  * example if we want to change something at the endpoint level for
    554  1.3  riastrad  * example cookie secrets we lock the INP level.
    555  1.1       rjs  */
    556  1.1       rjs #define SCTP_INP_LOCK_INIT(_inp) \
    557  1.1       rjs 	mutex_init(&(_inp)->inp_mtx, MUTEX_DEFAULT, IPL_NET)
    558  1.1       rjs 
    559  1.1       rjs #define SCTP_ASOC_CREATE_LOCK_INIT(_inp) \
    560  1.1       rjs 	mutex_init(&(_inp)->inp_create_mtx, MUTEX_DEFAULT, IPL_NET)
    561  1.1       rjs 
    562  1.1       rjs #define SCTP_INP_LOCK_DESTROY(_inp)	mutex_destroy(&(_inp)->inp_mtx)
    563  1.1       rjs #define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp)	mutex_destroy(&(_inp)->inp_create_mtx)
    564  1.1       rjs 
    565  1.1       rjs #define SCTP_INP_RLOCK(_inp)	do { 					\
    566  1.1       rjs 	mutex_enter(&(_inp)->inp_mtx);                                  \
    567  1.1       rjs } while (0)
    568  1.1       rjs 
    569  1.1       rjs #define SCTP_INP_WLOCK(_inp)	do { 					\
    570  1.1       rjs 	mutex_enter(&(_inp)->inp_mtx);                                  \
    571  1.1       rjs } while (0)
    572  1.1       rjs 
    573  1.1       rjs 
    574  1.1       rjs #define SCTP_INP_INCR_REF(_inp) atomic_add_int(&((_inp)->refcount), 1)
    575  1.1       rjs 
    576  1.1       rjs #define SCTP_INP_DECR_REF(_inp) atomic_add_int(&((_inp)->refcount), -1)
    577  1.1       rjs 
    578  1.1       rjs #define SCTP_ASOC_CREATE_LOCK(_inp)  do {				\
    579  1.1       rjs         mutex_enter(&(_inp)->inp_create_mtx);                              \
    580  1.1       rjs } while (0)
    581  1.1       rjs 
    582  1.1       rjs #define SCTP_INP_RUNLOCK(_inp)		mutex_exit(&(_inp)->inp_mtx)
    583  1.1       rjs #define SCTP_INP_WUNLOCK(_inp)		mutex_exit(&(_inp)->inp_mtx)
    584  1.1       rjs #define SCTP_ASOC_CREATE_UNLOCK(_inp)	mutex_exit(&(_inp)->inp_create_mtx)
    585  1.1       rjs 
    586  1.1       rjs /* For the majority of things (once we have found the association) we
    587  1.1       rjs  * will lock the actual association mutex. This will protect all
    588  1.1       rjs  * the assoiciation level queues and streams and such. We will
    589  1.1       rjs  * need to lock the socket layer when we stuff data up into
    590  1.1       rjs  * the receiving sb_mb. I.e. we will need to do an extra
    591  1.1       rjs  * SOCKBUF_LOCK(&so->so_rcv) even though the association is
    592  1.1       rjs  * locked.
    593  1.1       rjs  */
    594  1.1       rjs 
    595  1.1       rjs #define SCTP_TCB_LOCK_INIT(_tcb) \
    596  1.1       rjs 	mutex_init(&(_tcb)->tcb_mtx, MUTEX_DEFAULT, IPL_NET)
    597  1.1       rjs #define SCTP_TCB_LOCK_DESTROY(_tcb)	mutex_destroy(&(_tcb)->tcb_mtx)
    598  1.1       rjs #define SCTP_TCB_LOCK(_tcb)  do {					\
    599  1.1       rjs 	mutex_enter(&(_tcb)->tcb_mtx);                                     \
    600  1.1       rjs } while (0)
    601  1.1       rjs #define SCTP_TCB_UNLOCK(_tcb)		mutex_exit(&(_tcb)->tcb_mtx)
    602  1.1       rjs 
    603  1.1       rjs #define SCTP_ITERATOR_LOCK_INIT() \
    604  1.1       rjs         mutex_init(&sctppcbinfo.it_mtx, MUTEX_DEFAULT, IPL_NET)
    605  1.1       rjs #define SCTP_ITERATOR_LOCK()  do {					\
    606  1.1       rjs         if (mutex_owned(&sctppcbinfo.it_mtx))                           \
    607  1.1       rjs 		panic("Iterator Lock");                                 \
    608  1.1       rjs 	mutex_enter(&sctppcbinfo.it_mtx);                               \
    609  1.1       rjs } while (0)
    610  1.1       rjs 
    611  1.1       rjs #define SCTP_ITERATOR_UNLOCK()	        mutex_exit(&sctppcbinfo.it_mtx)
    612  1.1       rjs #define SCTP_ITERATOR_LOCK_DESTROY()	mutex_destroy(&sctppcbinfo.it_mtx)
    613  1.1       rjs #else
    614  1.1       rjs 
    615  1.1       rjs /* Empty Lock declarations for all other
    616  1.1       rjs  * platforms pre-process away to nothing.
    617  1.1       rjs  */
    618  1.1       rjs 
    619  1.1       rjs /* Lock for INFO stuff */
    620  1.1       rjs #define SCTP_INP_INFO_LOCK_INIT()
    621  1.1       rjs #define SCTP_INP_INFO_RLOCK()
    622  1.1       rjs #define SCTP_INP_INFO_RLOCK()
    623  1.1       rjs #define SCTP_INP_INFO_WLOCK()
    624  1.1       rjs 
    625  1.1       rjs #define SCTP_INP_INFO_RUNLOCK()
    626  1.1       rjs #define SCTP_INP_INFO_WUNLOCK()
    627  1.1       rjs /* Lock for INP */
    628  1.1       rjs #define SCTP_INP_LOCK_INIT(_inp)
    629  1.1       rjs #define SCTP_INP_LOCK_DESTROY(_inp)
    630  1.1       rjs #define SCTP_INP_RLOCK(_inp)
    631  1.1       rjs #define SCTP_INP_RUNLOCK(_inp)
    632  1.1       rjs #define SCTP_INP_WLOCK(_inp)
    633  1.1       rjs #define SCTP_INP_INCR_REF(_inp)
    634  1.1       rjs #define SCTP_INP_DECR_REF(_inp)
    635  1.1       rjs #define SCTP_INP_WUNLOCK(_inp)
    636  1.1       rjs #define SCTP_ASOC_CREATE_LOCK_INIT(_inp)
    637  1.1       rjs #define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp)
    638  1.1       rjs #define SCTP_ASOC_CREATE_LOCK(_inp)
    639  1.1       rjs #define SCTP_ASOC_CREATE_UNLOCK(_inp)
    640  1.1       rjs /* Lock for TCB */
    641  1.1       rjs #define SCTP_TCB_LOCK_INIT(_tcb)
    642  1.1       rjs #define SCTP_TCB_LOCK_DESTROY(_tcb)
    643  1.1       rjs #define SCTP_TCB_LOCK(_tcb)
    644  1.1       rjs #define SCTP_TCB_UNLOCK(_tcb)
    645  1.1       rjs /* iterator locks */
    646  1.1       rjs #define SCTP_ITERATOR_LOCK_INIT()
    647  1.1       rjs #define SCTP_ITERATOR_LOCK()
    648  1.1       rjs #define SCTP_ITERATOR_UNLOCK()
    649  1.1       rjs #define SCTP_ITERATOR_LOCK_DESTROY()
    650  1.1       rjs #endif
    651  1.1       rjs 
    652  1.1       rjs #if defined(_KERNEL)
    653  1.1       rjs 
    654  1.1       rjs extern struct sctp_epinfo sctppcbinfo;
    655  1.1       rjs extern int sctp_auto_asconf;
    656  1.1       rjs 
    657  1.1       rjs int SCTP6_ARE_ADDR_EQUAL(const struct in6_addr *a, const struct in6_addr *b);
    658  1.1       rjs 
    659  1.1       rjs void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
    660  1.1       rjs 
    661  1.1       rjs struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
    662  1.1       rjs 
    663  1.1       rjs struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int);
    664  1.1       rjs 
    665  1.1       rjs int sctp_inpcb_bind(struct socket *, struct sockaddr *, struct lwp *);
    666  1.1       rjs 
    667  1.1       rjs struct sctp_tcb *sctp_findassociation_addr(struct mbuf *, int, int,
    668  1.1       rjs     struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
    669  1.1       rjs     struct sctp_nets **);
    670  1.1       rjs 
    671  1.1       rjs struct sctp_tcb *sctp_findassociation_addr_sa(struct sockaddr *,
    672  1.1       rjs 	struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int);
    673  1.1       rjs 
    674  1.1       rjs void sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
    675  1.1       rjs 	struct sctp_tcb *);
    676  1.1       rjs 
    677  1.1       rjs /*
    678  1.1       rjs  * For this call ep_addr, the to is the destination endpoint address
    679  1.1       rjs  * of the peer (relative to outbound). The from field is only used if
    680  1.1       rjs  * the TCP model is enabled and helps distingush amongst the subset
    681  1.1       rjs  * bound (non-boundall). The TCP model MAY change the actual ep field,
    682  1.1       rjs  * this is why it is passed.
    683  1.1       rjs  */
    684  1.1       rjs struct sctp_tcb *sctp_findassociation_ep_addr(struct sctp_inpcb **,
    685  1.1       rjs 	struct sockaddr *, struct sctp_nets **, struct sockaddr *, struct sctp_tcb *);
    686  1.1       rjs 
    687  1.1       rjs struct sctp_tcb *sctp_findassociation_ep_asocid(struct sctp_inpcb *, vaddr_t);
    688  1.1       rjs 
    689  1.1       rjs struct sctp_tcb *sctp_findassociation_ep_asconf(struct mbuf *, int, int,
    690  1.1       rjs     struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **);
    691  1.1       rjs 
    692  1.1       rjs int sctp_inpcb_alloc(struct socket *);
    693  1.1       rjs 
    694  1.1       rjs 
    695  1.1       rjs int sctp_is_address_on_local_host(struct sockaddr *addr);
    696  1.1       rjs 
    697  1.1       rjs void sctp_inpcb_free(struct sctp_inpcb *, int);
    698  1.1       rjs 
    699  1.1       rjs struct sctp_tcb *sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
    700  1.1       rjs 	int, int *, uint32_t);
    701  1.1       rjs 
    702  1.1       rjs void sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *);
    703  1.1       rjs 
    704  1.1       rjs int sctp_add_local_addr_ep(struct sctp_inpcb *, struct ifaddr *);
    705  1.1       rjs 
    706  1.1       rjs int sctp_insert_laddr(struct sctpladdr *, struct ifaddr *);
    707  1.1       rjs 
    708  1.1       rjs void sctp_remove_laddr(struct sctp_laddr *);
    709  1.1       rjs 
    710  1.1       rjs int sctp_del_local_addr_ep(struct sctp_inpcb *, struct ifaddr *);
    711  1.1       rjs 
    712  1.1       rjs int sctp_del_local_addr_ep_sa(struct sctp_inpcb *, struct sockaddr *);
    713  1.1       rjs 
    714  1.1       rjs int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, int, int);
    715  1.1       rjs 
    716  1.1       rjs int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
    717  1.1       rjs 
    718  1.1       rjs void sctp_pcb_init(void);
    719  1.1       rjs 
    720  1.1       rjs void sctp_free_remote_addr(struct sctp_nets *);
    721  1.1       rjs 
    722  1.1       rjs int sctp_add_local_addr_assoc(struct sctp_tcb *, struct ifaddr *);
    723  1.1       rjs 
    724  1.1       rjs int sctp_del_local_addr_assoc(struct sctp_tcb *, struct ifaddr *);
    725  1.1       rjs 
    726  1.1       rjs int sctp_del_local_addr_assoc_sa(struct sctp_tcb *, struct sockaddr *);
    727  1.1       rjs 
    728  1.1       rjs int sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
    729  1.1       rjs     int, struct sctphdr *, struct sockaddr *);
    730  1.1       rjs 
    731  1.1       rjs int sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *, struct sctp_nets *);
    732  1.1       rjs 
    733  1.1       rjs int sctp_is_vtag_good(struct sctp_inpcb *, uint32_t, struct timeval *);
    734  1.1       rjs 
    735  1.1       rjs /*void sctp_drain(void);*/
    736  1.1       rjs 
    737  1.1       rjs int sctp_destination_is_reachable(struct sctp_tcb *, const struct sockaddr *);
    738  1.1       rjs 
    739  1.1       rjs int sctp_add_to_socket_q(struct sctp_inpcb *, struct sctp_tcb *);
    740  1.1       rjs 
    741  1.1       rjs struct sctp_tcb *sctp_remove_from_socket_q(struct sctp_inpcb *);
    742  1.1       rjs 
    743  1.1       rjs 
    744  1.1       rjs /* Null in last arg inpcb indicate run on ALL ep's. Specific
    745  1.1       rjs  * inp in last arg indicates run on ONLY assoc's of the
    746  1.1       rjs  * specified endpoint.
    747  1.1       rjs  */
    748  1.1       rjs int
    749  1.1       rjs sctp_initiate_iterator(asoc_func af, uint32_t, uint32_t, void *, uint32_t,
    750  1.1       rjs 		       end_func ef, struct sctp_inpcb *);
    751  1.1       rjs 
    752  1.2       rjs void in6_sin6_2_sin (struct sockaddr_in *,
    753  1.1       rjs                             struct sockaddr_in6 *sin6);
    754  1.1       rjs 
    755  1.6     ozaki #ifdef __NetBSD__
    756  1.6     ozaki #ifndef in6pcb
    757  1.6     ozaki #define in6pcb		inpcb
    758  1.6     ozaki #endif
    759  1.6     ozaki #ifndef sotoin6pcb
    760  1.6     ozaki #define sotoin6pcb      sotoinpcb
    761  1.6     ozaki #endif
    762  1.6     ozaki #ifndef in6p_flags
    763  1.6     ozaki #define in6p_flags	inp_flags
    764  1.6     ozaki #endif
    765  1.6     ozaki #ifndef in6p_af
    766  1.6     ozaki #define in6p_af		inp_af
    767  1.6     ozaki #endif
    768  1.6     ozaki #ifndef in6p_cksum
    769  1.6     ozaki #define in6p_cksum	inp_cksum6
    770  1.6     ozaki #endif
    771  1.6     ozaki #ifndef in6p_hops
    772  1.6     ozaki #define in6p_hops	inp_hops6
    773  1.6     ozaki #endif
    774  1.6     ozaki #ifndef in6p_flowinfo
    775  1.6     ozaki #define in6p_flowinfo	inp_flowinfo
    776  1.6     ozaki #endif
    777  1.6     ozaki #ifndef in6p_outputopts
    778  1.6     ozaki #define in6p_outputopts	inp_outputopts6
    779  1.6     ozaki #endif
    780  1.6     ozaki #ifndef in6p_moptions
    781  1.6     ozaki #define in6p_moptions	inp_moptions6
    782  1.6     ozaki #endif
    783  1.6     ozaki #ifndef inpcb_hdr
    784  1.6     ozaki #define inpcb_hdr	inpcb
    785  1.6     ozaki #endif
    786  1.6     ozaki #ifndef sp_inph
    787  1.6     ozaki #define sp_inph		sp_inp
    788  1.6     ozaki #endif
    789  1.6     ozaki #endif
    790  1.6     ozaki 
    791  1.1       rjs #endif /* _KERNEL */
    792  1.1       rjs #endif /* !__SCTP_PCB_H__ */
    793