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