]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/netinet/sctp_pcb.h
This commit was generated by cvs2svn to compensate for changes in r166124,
[FreeBSD/FreeBSD.git] / sys / netinet / sctp_pcb.h
1 /*-
2  * Copyright (c) 2001-2007, Cisco Systems, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * a) Redistributions of source code must retain the above copyright notice,
8  *   this list of conditions and the following disclaimer.
9  *
10  * b) Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *   the documentation and/or other materials provided with the distribution.
13  *
14  * c) Neither the name of Cisco Systems, Inc. nor the names of its
15  *    contributors may be used to endorse or promote products derived
16  *    from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 /* $KAME: sctp_pcb.h,v 1.21 2005/07/16 01:18:47 suz Exp $        */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #ifndef __sctp_pcb_h__
37 #define __sctp_pcb_h__
38
39 #include <netinet/sctp_os.h>
40 #include <netinet/sctp.h>
41 #include <netinet/sctp_constants.h>
42
43 LIST_HEAD(sctppcbhead, sctp_inpcb);
44 LIST_HEAD(sctpasochead, sctp_tcb);
45 LIST_HEAD(sctpladdr, sctp_laddr);
46 LIST_HEAD(sctpvtaghead, sctp_tagblock);
47 TAILQ_HEAD(sctp_readhead, sctp_queued_to_read);
48 TAILQ_HEAD(sctp_streamhead, sctp_stream_queue_pending);
49
50 #include <netinet/sctp_structs.h>
51 #include <netinet/sctp_uio.h>
52 #include <netinet/sctp_auth.h>
53
54 /*
55  * PCB flags (in sctp_flags bitmask)
56  */
57 #define SCTP_PCB_FLAGS_UDPTYPE          0x00000001
58 #define SCTP_PCB_FLAGS_TCPTYPE          0x00000002
59 #define SCTP_PCB_FLAGS_BOUNDALL         0x00000004
60 #define SCTP_PCB_FLAGS_ACCEPTING        0x00000008
61 #define SCTP_PCB_FLAGS_UNBOUND          0x00000010
62 #define SCTP_PCB_FLAGS_CLOSE_IP         0x00040000
63 #define SCTP_PCB_FLAGS_WAS_CONNECTED    0x00080000
64 #define SCTP_PCB_FLAGS_WAS_ABORTED      0x00100000
65 /* TCP model support */
66
67 #define SCTP_PCB_FLAGS_CONNECTED        0x00200000
68 #define SCTP_PCB_FLAGS_IN_TCPPOOL       0x00400000
69 #define SCTP_PCB_FLAGS_DONT_WAKE        0x00800000
70 #define SCTP_PCB_FLAGS_WAKEOUTPUT       0x01000000
71 #define SCTP_PCB_FLAGS_WAKEINPUT        0x02000000
72 #define SCTP_PCB_FLAGS_BOUND_V6         0x04000000
73 #define SCTP_PCB_FLAGS_NEEDS_MAPPED_V4  0x08000000
74 #define SCTP_PCB_FLAGS_BLOCKING_IO      0x10000000
75 #define SCTP_PCB_FLAGS_SOCKET_GONE      0x20000000
76 #define SCTP_PCB_FLAGS_SOCKET_ALLGONE   0x40000000
77 /* flags to copy to new PCB */
78 #define SCTP_PCB_COPY_FLAGS             0x0e000004
79
80
81 /*
82  * PCB Features (in sctp_features bitmask)
83  */
84 #define SCTP_PCB_FLAGS_EXT_RCVINFO      0x00000004
85 #define SCTP_PCB_FLAGS_DONOT_HEARTBEAT  0x00000008
86 #define SCTP_PCB_FLAGS_FRAG_INTERLEAVE  0x00000010
87 #define SCTP_PCB_FLAGS_DO_ASCONF        0x00000020
88 #define SCTP_PCB_FLAGS_AUTO_ASCONF      0x00000040
89 /* socket options */
90 #define SCTP_PCB_FLAGS_NODELAY          0x00000100
91 #define SCTP_PCB_FLAGS_AUTOCLOSE        0x00000200
92 #define SCTP_PCB_FLAGS_RECVDATAIOEVNT   0x00000400
93 #define SCTP_PCB_FLAGS_RECVASSOCEVNT    0x00000800
94 #define SCTP_PCB_FLAGS_RECVPADDREVNT    0x00001000
95 #define SCTP_PCB_FLAGS_RECVPEERERR      0x00002000
96 #define SCTP_PCB_FLAGS_RECVSENDFAILEVNT 0x00004000
97 #define SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT 0x00008000
98 #define SCTP_PCB_FLAGS_ADAPTATIONEVNT   0x00010000
99 #define SCTP_PCB_FLAGS_PDAPIEVNT        0x00020000
100 #define SCTP_PCB_FLAGS_AUTHEVNT         0x00040000
101 #define SCTP_PCB_FLAGS_STREAM_RESETEVNT 0x00080000
102 #define SCTP_PCB_FLAGS_NO_FRAGMENT      0x00100000
103 #define SCTP_PCB_FLAGS_EXPLICIT_EOR     0x00200000
104
105
106 #define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask)
107 #define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask)
108
109 struct sctp_laddr {
110         LIST_ENTRY(sctp_laddr) sctp_nxt_addr;   /* next in list */
111         struct ifaddr *ifa;
112         int action;             /* Only used in delayed asconf stuff */
113 };
114
115 struct sctp_block_entry {
116         int error;
117 };
118
119 struct sctp_timewait {
120         uint32_t tv_sec_at_expire;      /* the seconds from boot to expire */
121         uint32_t v_tag;         /* the vtag that can not be reused */
122 };
123
124 struct sctp_tagblock {
125         LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock;
126         struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
127 };
128
129
130 struct sctp_epinfo {
131         struct sctpasochead *sctp_asochash;
132         u_long hashasocmark;
133
134         struct sctppcbhead *sctp_ephash;
135         u_long hashmark;
136
137         struct sctpasochead *sctp_restarthash;
138         u_long hashrestartmark;
139         /*
140          * The TCP model represents a substantial overhead in that we get an
141          * additional hash table to keep explicit connections in. The
142          * listening TCP endpoint will exist in the usual ephash above and
143          * accept only INIT's. It will be incapable of sending off an INIT.
144          * When a dg arrives we must look in the normal ephash. If we find a
145          * TCP endpoint that will tell us to go to the specific endpoint
146          * hash and re-hash to find the right assoc/socket. If we find a UDP
147          * model socket we then must complete the lookup. If this fails,
148          * i.e. no association can be found then we must continue to see if
149          * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket
150          * acts like a TCP model connected socket).
151          */
152         struct sctppcbhead *sctp_tcpephash;
153         u_long hashtcpmark;
154         uint32_t hashtblsize;
155
156         struct sctppcbhead listhead;
157         struct sctpladdr addr_wq;
158
159         struct sctpiterators iteratorhead;
160
161         /* ep zone info */
162         sctp_zone_t ipi_zone_ep;
163         sctp_zone_t ipi_zone_asoc;
164         sctp_zone_t ipi_zone_laddr;
165         sctp_zone_t ipi_zone_net;
166         sctp_zone_t ipi_zone_chunk;
167         sctp_zone_t ipi_zone_readq;
168         sctp_zone_t ipi_zone_strmoq;
169
170         struct mtx ipi_ep_mtx;
171         struct mtx it_mtx;
172         struct mtx ipi_addr_mtx;
173         struct mtx timer_mtx;
174         uint32_t ipi_count_ep;
175
176         /* assoc/tcb zone info */
177         uint32_t ipi_count_asoc;
178
179         /* local addrlist zone info */
180         uint32_t ipi_count_laddr;
181
182         /* remote addrlist zone info */
183         uint32_t ipi_count_raddr;
184
185         /* chunk structure list for output */
186         uint32_t ipi_count_chunk;
187
188         /* socket queue zone info */
189         uint32_t ipi_count_readq;
190
191         /* socket queue zone info */
192         uint32_t ipi_count_strmoq;
193
194         /* system wide number of free chunks hanging around */
195         uint32_t ipi_free_chunks;
196         uint32_t ipi_free_strmoq;
197
198         struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
199
200         struct sctp_timer addr_wq_timer;
201
202 };
203
204 extern struct sctpstat sctpstat;
205
206 /*
207  * Here we have all the relevant information for each SCTP entity created. We
208  * will need to modify this as approprate. We also need to figure out how to
209  * access /dev/random.
210  */
211 struct sctp_pcb {
212         unsigned int time_of_secret_change;     /* number of seconds from
213                                                  * timeval.tv_sec */
214         uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
215         unsigned int size_of_a_cookie;
216
217         unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
218         unsigned int sctp_minrto;
219         unsigned int sctp_maxrto;
220         unsigned int initial_rto;
221
222         int initial_init_rto_max;
223
224         uint32_t sctp_sws_sender;
225         uint32_t sctp_sws_receiver;
226
227         /* authentication related fields */
228         struct sctp_keyhead shared_keys;
229         sctp_auth_chklist_t *local_auth_chunks;
230         sctp_hmaclist_t *local_hmacs;
231         uint16_t default_keyid;
232
233         /* various thresholds */
234         /* Max times I will init at a guy */
235         uint16_t max_init_times;
236
237         /* Max times I will send before we consider someone dead */
238         uint16_t max_send_times;
239
240         uint16_t def_net_failure;
241
242         /* number of streams to pre-open on a association */
243         uint16_t pre_open_stream_count;
244         uint16_t max_open_streams_intome;
245
246         /* random number generator */
247         uint32_t random_counter;
248         uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
249         uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
250
251         /*
252          * This timer is kept running per endpoint.  When it fires it will
253          * change the secret key.  The default is once a hour
254          */
255         struct sctp_timer signature_change;
256         int def_cookie_life;
257         /* defaults to 0 */
258         int auto_close_time;
259         uint32_t initial_sequence_debug;
260         uint32_t adaptation_layer_indicator;
261         char store_at;
262         uint8_t max_burst;
263         char current_secret_number;
264         char last_secret_number;
265 };
266
267 #ifndef SCTP_ALIGNMENT
268 #define SCTP_ALIGNMENT 32
269 #endif
270
271 #ifndef SCTP_ALIGNM1
272 #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
273 #endif
274
275 #define sctp_lport ip_inp.inp.inp_lport
276
277 struct sctp_inpcb {
278         /*
279          * put an inpcb in front of it all, kind of a waste but we need to
280          * for compatability with all the other stuff.
281          */
282         union {
283                 struct inpcb inp;
284                 char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) &
285                         ~SCTP_ALIGNM1];
286         }     ip_inp;
287
288
289         /* Socket buffer lock protects read_queue and of course sb_cc */
290         struct sctp_readhead read_queue;
291
292                       LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */
293         /* hash of all endpoints for model */
294                       LIST_ENTRY(sctp_inpcb) sctp_hash;
295         /* count of local addresses bound, 0 if bound all */
296         int laddr_count;
297         /* list of addrs in use by the EP */
298         struct sctpladdr sctp_addr_list;
299         /* used for source address selection rotation */
300         struct sctp_laddr *next_addr_touse;
301         struct ifnet *next_ifn_touse;
302         /* back pointer to our socket */
303         struct socket *sctp_socket;
304         uint32_t sctp_flags;    /* INP state flag set */
305         uint32_t sctp_features; /* Feature flags */
306         struct sctp_pcb sctp_ep;/* SCTP ep data */
307         /* head of the hash of all associations */
308         struct sctpasochead *sctp_tcbhash;
309         u_long sctp_hashmark;
310         /* head of the list of all associations */
311         struct sctpasochead sctp_asoc_list;
312 #ifdef SCTP_TRACK_FREED_ASOCS
313         struct sctpasochead sctp_asoc_free_list;
314 #endif
315         struct sctp_iterator *inp_starting_point_for_iterator;
316         uint32_t sctp_frag_point;
317         uint32_t partial_delivery_point;
318         uint32_t sctp_context;
319         struct sctp_sndrcvinfo def_send;
320         /*
321          * These three are here for the sosend_dgram (pkt, pkt_last and
322          * control). routine. However, I don't think anyone in the current
323          * FreeBSD kernel calls this. So they are candidates with sctp_sendm
324          * for de-supporting.
325          */
326         struct mbuf *pkt, *pkt_last;
327         struct mbuf *control;
328         struct mtx inp_mtx;
329         struct mtx inp_create_mtx;
330         struct mtx inp_rdata_mtx;
331         int32_t refcount;
332         uint32_t total_sends;
333         uint32_t total_recvs;
334         uint32_t last_abort_code;
335         uint32_t total_nospaces;
336 };
337
338 struct sctp_tcb {
339         struct socket *sctp_socket;     /* back pointer to socket */
340         struct sctp_inpcb *sctp_ep;     /* back pointer to ep */
341                    LIST_ENTRY(sctp_tcb) sctp_tcbhash;   /* next link in hash
342                                                          * table */
343                    LIST_ENTRY(sctp_tcb) sctp_tcblist;   /* list of all of the
344                                                          * TCB's */
345                    LIST_ENTRY(sctp_tcb) sctp_tcbrestarhash;     /* next link in restart
346                                                                  * hash table */
347                    LIST_ENTRY(sctp_tcb) sctp_asocs;     /* vtag hash list */
348         struct sctp_block_entry *block_entry;   /* pointer locked by  socket
349                                                  * send buffer */
350         struct sctp_association asoc;
351         /*
352          * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the
353          * tcb_lock. Its special in this way to help avoid extra mutex calls
354          * in the reading of data.
355          */
356         uint32_t freed_by_sorcv_sincelast;
357         uint32_t total_sends;
358         uint32_t total_recvs;
359         int freed_from_where;
360         uint16_t rport;         /* remote port in network format */
361         uint16_t resv;
362         struct mtx tcb_mtx;
363         struct mtx tcb_send_mtx;
364 };
365
366
367
368 #include <netinet/sctp_lock_bsd.h>
369
370
371 #if defined(_KERNEL)
372
373 extern struct sctp_epinfo sctppcbinfo;
374 extern int sctp_auto_asconf;
375
376 int SCTP6_ARE_ADDR_EQUAL(struct in6_addr *a, struct in6_addr *b);
377
378 void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
379
380 struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
381
382 struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int);
383
384 int sctp_inpcb_bind(struct socket *, struct sockaddr *, struct thread *);
385
386
387 struct sctp_tcb *
388 sctp_findassociation_addr(struct mbuf *, int, int,
389     struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
390     struct sctp_nets **);
391
392 struct sctp_tcb *
393 sctp_findassociation_addr_sa(struct sockaddr *,
394     struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int);
395
396 void
397 sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
398     struct sctp_tcb *);
399
400 /*
401  * For this call ep_addr, the to is the destination endpoint address of the
402  * peer (relative to outbound). The from field is only used if the TCP model
403  * is enabled and helps distingush amongst the subset bound (non-boundall).
404  * The TCP model MAY change the actual ep field, this is why it is passed.
405  */
406 struct sctp_tcb *
407 sctp_findassociation_ep_addr(struct sctp_inpcb **,
408     struct sockaddr *, struct sctp_nets **, struct sockaddr *,
409     struct sctp_tcb *);
410
411 struct sctp_tcb *
412 sctp_findassociation_ep_asocid(struct sctp_inpcb *,
413     sctp_assoc_t, int);
414
415 struct sctp_tcb *
416 sctp_findassociation_ep_asconf(struct mbuf *, int, int,
417     struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **);
418
419 int sctp_inpcb_alloc(struct socket *);
420
421 int sctp_is_address_on_local_host(struct sockaddr *addr);
422
423 void sctp_inpcb_free(struct sctp_inpcb *, int, int);
424
425 struct sctp_tcb *
426 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
427     int, int *, uint32_t);
428
429 int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
430
431 void
432      sctp_add_vtag_to_timewait(struct sctp_inpcb *, uint32_t, uint32_t);
433
434 int sctp_add_local_addr_ep(struct sctp_inpcb *, struct ifaddr *);
435
436 int sctp_insert_laddr(struct sctpladdr *, struct ifaddr *);
437
438 void sctp_remove_laddr(struct sctp_laddr *);
439
440 int sctp_del_local_addr_ep(struct sctp_inpcb *, struct ifaddr *);
441
442 int sctp_del_local_addr_ep_sa(struct sctp_inpcb *, struct sockaddr *);
443
444 int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, int, int);
445
446 void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
447
448 int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
449
450 void sctp_pcb_init(void);
451
452 int sctp_add_local_addr_assoc(struct sctp_tcb *, struct ifaddr *);
453
454 int sctp_del_local_addr_assoc(struct sctp_tcb *, struct ifaddr *);
455
456 int sctp_del_local_addr_assoc_sa(struct sctp_tcb *, struct sockaddr *);
457
458 int
459 sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
460     int, struct sctphdr *, struct sockaddr *);
461
462 int
463 sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
464     struct sctp_nets *);
465
466 int sctp_is_vtag_good(struct sctp_inpcb *, uint32_t, struct timeval *);
467
468 /* void sctp_drain(void); */
469
470 int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *);
471
472 /*
473  * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg
474  * indicates run on ONLY assoc's of the specified endpoint.
475  */
476 int
477 sctp_initiate_iterator(inp_func inpf, asoc_func af, uint32_t, uint32_t,
478     uint32_t, void *, uint32_t, end_func ef, struct sctp_inpcb *, uint8_t co_off);
479
480
481 #endif                          /* _KERNEL */
482 #endif                          /* !__sctp_pcb_h__ */