1 /* $KAME: sctp_structs.h,v 1.12 2004/08/17 04:06:19 itojun Exp $ */
2 /* $DragonFly: src/sys/netinet/sctp_structs.h,v 1.1 2005/07/15 14:46:17 eirikn Exp $ */
4 #ifndef __sctp_structs_h__
5 #define __sctp_structs_h__
8 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Cisco Systems, Inc.
22 * 4. Neither the name of the project nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/queue.h>
40 #if defined(__APPLE__)
41 #include <netinet/sctp_callout.h>
42 #elif defined(__OpenBSD__)
43 #include <sys/timeout.h>
45 #include <sys/callout.h>
50 #include <netinet6/ipsec.h>
51 #include <netkey/key.h>
55 #include <netinet/sctp_header.h>
56 #include <netinet/sctp_uio.h>
59 #if defined(__OpenBSD__)
66 * Depending on the timer type these will be setup and cast with
67 * the appropriate entity.
75 * This is the information we track on each interface that we know about * from the distant end.
77 TAILQ_HEAD(sctpnetlisthead, sctp_nets);
80 * Users of the iterator need to malloc a iterator with a call to
81 * sctp_initiate_iterator(func, pcb_flags, asoc_state, void-ptr-arg, u_int32_t,
82 * u_int32-arg, end_func, inp);
84 * Use the following two defines if you don't care what pcb flags are on the
85 * EP and/or you don't care what state the association is in.
87 * Note that if you specify an INP as the last argument then ONLY each
88 * association of that single INP will be executed upon. Note that the
89 * pcb flags STILL apply so if the inp you specify has different pcb_flags
90 * then what you put in pcb_flags nothing will happen. use SCTP_PCB_ANY_FLAGS
91 * to assure the inp you specify gets treated.
93 #define SCTP_PCB_ANY_FLAGS 0x00000000
94 #define SCTP_ASOC_ANY_STATE 0x00000000
96 typedef void (*asoc_func)(struct sctp_inpcb *, struct sctp_tcb *, void *ptr,
98 typedef void (*end_func)(void *ptr, u_int32_t val);
100 #define SCTP_ITERATOR_DO_ALL_INP 0x00000001
101 #define SCTP_ITERATOR_DO_SINGLE_INP 0x00000002
103 struct sctp_iterator {
104 LIST_ENTRY(sctp_iterator) sctp_nxt_itr;
105 struct sctp_timer tmr;
106 struct sctp_inpcb *inp; /* ep */
107 struct sctp_tcb *stcb; /* assoc */
108 asoc_func function_toapply;
109 end_func function_atend;
110 void *pointer; /* pointer for apply func to use */
111 u_int32_t val; /* value for apply func to use */
113 u_int32_t asoc_state;
114 u_int32_t iterator_flags;
117 LIST_HEAD(sctpiterators, sctp_iterator);
119 struct sctp_copy_all {
120 struct sctp_inpcb *inp; /* ep */
122 struct sctp_sndrcvinfo sndrcv;
128 union sctp_sockstore {
130 struct sockaddr_in sin;
133 struct sockaddr_in6 sin6;
139 TAILQ_ENTRY(sctp_nets) sctp_next; /* next link */
141 /* Things on the top half may be able to be split
142 * into a common structure shared by all.
144 struct sctp_timer pmtu_timer;
147 * The following two in combination equate to a route entry for
151 struct rtentry *ro_rt;
152 union sctp_sockstore _l_addr; /* remote peer addr */
153 union sctp_sockstore _s_addr; /* our selected src addr */
155 /* mtu discovered so far */
157 u_int32_t ssthresh; /* not sure about this one for split */
159 /* smoothed average things for RTT and RTO itself */
164 /* This is used for SHUTDOWN/SHUTDOWN-ACK/SEND or INIT timers */
165 struct sctp_timer rxt_timer;
167 /* last time in seconds I sent to it */
168 struct timeval last_sent_time;
171 /* Congestion stats per destination */
173 * flight size variables and such, sorry Vern, I could not avoid
174 * this if I wanted performance :>
176 u_int32_t flight_size;
177 u_int32_t cwnd; /* actual cwnd */
178 u_int32_t prev_cwnd; /* cwnd before any processing */
179 u_int32_t partial_bytes_acked; /* in CA tracks when to incr a MTU */
181 /* tracking variables to avoid the aloc/free in sack processing */
182 unsigned int net_ack;
183 unsigned int net_ack2;
185 * These only are valid if the primary dest_sstate holds the
186 * SCTP_ADDR_SWITCH_PRIMARY flag
188 u_int32_t next_tsn_at_change;
189 u_int32_t heartbeat_random1;
190 u_int32_t heartbeat_random2;
192 /* if this guy is ok or not ... status */
193 u_int16_t dest_state;
194 /* number of transmit failures to down this guy */
195 u_int16_t failure_threshold;
196 /* error stats on destination */
197 u_int16_t error_count;
199 /* Flags that probably can be combined into dest_state */
200 u_int8_t rto_pending; /* is segment marked for RTO update ** if we split?*/
201 u_int8_t fast_retran_ip; /* fast retransmit in progress */
202 u_int8_t hb_responded;
203 u_int8_t cacc_saw_newack; /* CACC algorithm flag */
204 u_int8_t src_addr_selected; /* if we split we move */
205 u_int8_t indx_of_eligible_next_to_use;
206 u_int8_t addr_is_local; /* its a local address (if known) could move in split */
207 #ifdef SCTP_HIGH_SPEED
208 u_int8_t last_hs_used; /* index into the last HS table entry we used */
213 struct sctp_data_chunkrec {
214 u_int32_t TSN_seq; /* the TSN of this transmit */
215 u_int16_t stream_seq; /* the stream sequence number of this transmit */
216 u_int16_t stream_number; /* the stream number of this guy */
217 u_int32_t payloadtype;
218 u_int32_t context; /* from send */
220 /* ECN Nonce: Nonce Value for this chunk */
223 /* part of the Highest sacked algorithm to be able to
224 * stroke counts on ones that are FR'd.
226 u_int32_t fast_retran_tsn; /* sending_seq at the time of FR */
227 struct timeval timetodrop; /* time we drop it from queue */
228 u_int8_t doing_fast_retransmit;
229 u_int8_t rcv_flags; /* flags pulled from data chunk on inbound
230 * for outbound holds sending flags.
232 u_int8_t state_flags;
235 TAILQ_HEAD(sctpchunk_listhead, sctp_tmit_chunk);
237 #define CHUNK_FLAGS_FRAGMENT_OK 0x0001
239 struct sctp_tmit_chunk {
241 struct sctp_data_chunkrec data;
244 int32_t sent; /* the send status */
245 int32_t snd_count; /* number of times I sent */
246 u_int32_t flags; /* flags, such as FRAGMENT_OK */
250 struct sctp_association *asoc; /* bp to asoc this belongs to */
251 struct timeval sent_rcv_time; /* filled in if RTT being calculated */
252 struct mbuf *data; /* pointer to mbuf chain of data */
253 struct sctp_nets *whoTo;
254 TAILQ_ENTRY(sctp_tmit_chunk) sctp_next; /* next link */
260 * this struct contains info that is used to track inbound stream data
261 * and help with ordering.
263 TAILQ_HEAD(sctpwheelunrel_listhead, sctp_stream_in);
264 struct sctp_stream_in {
265 struct sctpchunk_listhead inqueue;
266 TAILQ_ENTRY(sctp_stream_in) next_spoke;
268 uint16_t last_sequence_delivered; /* used for re-order */
271 /* This struct is used to track the traffic on outbound streams */
272 TAILQ_HEAD(sctpwheel_listhead, sctp_stream_out);
273 struct sctp_stream_out {
274 struct sctpchunk_listhead outqueue;
275 TAILQ_ENTRY(sctp_stream_out) next_spoke; /* next link in wheel */
277 uint16_t next_sequence_sent; /* next one I expect to send out */
280 /* used to keep track of the addresses yet to try to add/delete */
281 TAILQ_HEAD(sctp_asconf_addrhead, sctp_asconf_addr);
282 struct sctp_asconf_addr {
283 TAILQ_ENTRY(sctp_asconf_addr) next;
284 struct sctp_asconf_addr_param ap;
285 struct ifaddr *ifa; /* save the ifa for add/del ip */
286 uint8_t sent; /* has this been sent yet? */
291 * Here we have information about each individual association that we
292 * track. We probably in production would be more dynamic. But for ease
293 * of implementation we will have a fixed array that we hunt for in a
296 struct sctp_association {
297 /* association state */
299 /* queue of pending addrs to add/delete */
300 struct sctp_asconf_addrhead asconf_queue;
301 struct timeval time_entered; /* time we entered state */
302 struct timeval time_last_rcvd;
303 struct timeval time_last_sent;
304 struct timeval time_last_sat_advance;
305 struct sctp_sndrcvinfo def_send; /* default send parameters */
307 /* timers and such */
308 struct sctp_timer hb_timer; /* hb timer */
309 struct sctp_timer dack_timer; /* Delayed ack timer */
310 struct sctp_timer asconf_timer; /* Asconf */
311 struct sctp_timer strreset_timer; /* stream reset */
312 struct sctp_timer shut_guard_timer; /* guard */
313 struct sctp_timer autoclose_timer; /* automatic close timer */
314 struct sctp_timer delayed_event_timer; /* timer for delayed events */
316 /* list of local addresses when add/del in progress */
317 struct sctpladdr sctp_local_addr_list;
318 struct sctpnetlisthead nets;
320 /* Control chunk queue */
321 struct sctpchunk_listhead control_send_queue;
323 /* Once a TSN hits the wire it is moved to the sent_queue. We
324 * maintain two counts here (don't know if any but retran_cnt
325 * is needed). The idea is that the sent_queue_retran_cnt
326 * reflects how many chunks have been marked for retranmission
327 * by either T3-rxt or FR.
329 struct sctpchunk_listhead sent_queue;
330 struct sctpchunk_listhead send_queue;
333 /* re-assembly queue for fragmented chunks on the inbound path */
334 struct sctpchunk_listhead reasmqueue;
337 * this queue is used when we reach a condition that we can NOT
338 * put data into the socket buffer. We track the size of this
339 * queue and set our rwnd to the space in the socket minus also
340 * the size_on_delivery_queue.
342 struct sctpchunk_listhead delivery_queue;
344 struct sctpwheel_listhead out_wheel;
346 /* If an iterator is looking at me, this is it */
347 struct sctp_iterator *stcb_starting_point_for_iterator;
349 /* ASCONF destination address last sent to */
350 struct sctp_nets *asconf_last_sent_to;
352 /* ASCONF save the last ASCONF-ACK so we can resend it if necessary */
353 struct mbuf *last_asconf_ack_sent;
356 * if Source Address Selection happening, this will rotate through
359 struct sctp_laddr *last_used_address;
362 struct sctp_stream_in *strmin;
363 struct sctp_stream_out *strmout;
364 u_int8_t *mapping_array;
365 /* primary destination to use */
366 struct sctp_nets *primary_destination;
368 /* last place I got a data chunk from */
369 struct sctp_nets *last_data_chunk_from;
370 /* last place I got a control from */
371 struct sctp_nets *last_control_chunk_from;
373 /* circular looking for output selection */
374 struct sctp_stream_out *last_out_stream;
376 /* wait to the point the cum-ack passes
377 * pending_reply->sr_resp.reset_at_tsn.
379 struct sctp_stream_reset_response *pending_reply;
380 struct sctpchunk_listhead pending_reply_queue;
382 u_int32_t cookie_preserve_req;
383 /* ASCONF next seq I am sending out, inits at init-tsn */
384 uint32_t asconf_seq_out;
385 /* ASCONF last received ASCONF from peer, starts at peer's TSN-1 */
386 uint32_t asconf_seq_in;
388 /* next seq I am sending in str reset messages */
389 uint32_t str_reset_seq_out;
391 /* next seq I am expecting in str reset messages */
392 uint32_t str_reset_seq_in;
393 u_int32_t str_reset_sending_seq;
395 /* various verification tag information */
396 u_int32_t my_vtag; /*
397 * The tag to be used. if assoc is
398 * re-initited by remote end, and
399 * I have unlocked this will be
400 * regenrated to a new random value.
402 u_int32_t peer_vtag; /* The peers last tag */
404 u_int32_t my_vtag_nonce;
405 u_int32_t peer_vtag_nonce;
408 /* This is the SCTP fragmentation threshold */
409 u_int32_t smallest_mtu;
412 * Special hook for Fast retransmit, allows us to track the highest
413 * TSN that is NEW in this SACK if gap ack blocks are present.
415 u_int32_t this_sack_highest_gap;
418 * The highest consecutive TSN that has been acked by peer on my
421 u_int32_t last_acked_seq;
423 /* The next TSN that I will use in sending. */
424 u_int32_t sending_seq;
426 /* Original seq number I used ??questionable to keep?? */
427 u_int32_t init_seq_number;
430 * We use this value to know if FR's are allowed, i.e. did the
431 * cum-ack pass this point or equal it so FR's are now allowed.
433 u_int32_t t3timeout_highest_marked;
435 /* The Advanced Peer Ack Point, as required by the PR-SCTP */
436 /* (A1 in Section 4.2) */
437 u_int32_t advanced_peer_ack_point;
440 * The highest consequetive TSN at the bottom of the mapping
441 * array (for his sends).
443 u_int32_t cumulative_tsn;
445 * Used to track the mapping array and its offset bits. This
446 * MAY be lower then cumulative_tsn.
448 u_int32_t mapping_array_base_tsn;
450 * used to track highest TSN we have received and is listed in
453 u_int32_t highest_tsn_inside_map;
455 u_int32_t last_echo_tsn;
456 u_int32_t last_cwr_tsn;
457 u_int32_t fast_recovery_tsn;
458 u_int32_t sat_t3_recovery_tsn;
460 u_int32_t tsn_last_delivered;
463 * window state information and smallest MTU that I use to bound
466 u_int32_t peers_rwnd;
468 u_int32_t my_last_reported_rwnd;
469 u_int32_t my_rwnd_control_len;
471 u_int32_t total_output_queue_size;
472 u_int32_t total_output_mbuf_queue_size;
474 /* 32 bit nonce stuff */
475 u_int32_t nonce_resync_tsn;
476 u_int32_t nonce_wait_tsn;
478 int ctrl_queue_cnt; /* could be removed REM */
480 * All outbound datagrams queue into this list from the
481 * individual stream queue. Here they get assigned a TSN
482 * and then await sending. The stream seq comes when it
483 * is first put in the individual str queue
485 unsigned int stream_queue_cnt;
486 unsigned int send_queue_cnt;
487 unsigned int sent_queue_cnt;
488 unsigned int sent_queue_cnt_removeable;
490 * Number on sent queue that are marked for retran until this
491 * value is 0 we only send one packet of retran'ed data.
493 unsigned int sent_queue_retran_cnt;
495 unsigned int size_on_reasm_queue;
496 unsigned int cnt_on_reasm_queue;
497 /* amount of data (bytes) currently in flight (on all destinations) */
498 unsigned int total_flight;
499 /* Total book size in flight */
500 unsigned int total_flight_count; /* count of chunks used with book total */
501 /* count of destinaton nets and list of destination nets */
502 unsigned int numnets;
504 /* Total error count on this association */
505 unsigned int overall_error_count;
507 unsigned int size_on_delivery_queue;
508 unsigned int cnt_on_delivery_queue;
510 unsigned int cnt_msg_on_sb;
512 /* All stream count of chunks for delivery */
513 unsigned int size_on_all_streams;
514 unsigned int cnt_on_all_streams;
516 /* Heart Beat delay in ticks */
517 unsigned int heart_beat_delay;
520 unsigned int sctp_autoclose_ticks;
522 /* how many preopen streams we have */
523 unsigned int pre_open_streams;
525 /* How many streams I support coming into me */
526 unsigned int max_inbound_streams;
528 /* the cookie life I award for any cookie, in seconds */
529 unsigned int cookie_life;
531 unsigned int numduptsns;
532 int dup_tsns[SCTP_MAX_DUP_TSNS];
533 unsigned int initial_init_rto_max; /* initial RTO for INIT's */
534 unsigned int initial_rto; /* initial send RTO */
535 unsigned int minrto; /* per assoc RTO-MIN */
536 unsigned int maxrto; /* per assoc RTO-MAX */
537 /* Being that we have no bag to collect stale cookies, and
538 * that we really would not want to anyway.. we will count
539 * them in this counter. We of course feed them to the
540 * pigeons right away (I have always thought of pigeons
543 u_int16_t stale_cookie_count;
545 /* For the partial delivery API, if up, invoked
546 * this is what last TSN I delivered
548 u_int16_t str_of_pdapi;
549 u_int16_t ssn_of_pdapi;
552 /* counts of actual built streams. Allocation may be more however */
553 /* could re-arrange to optimize space here. */
554 u_int16_t streamincnt;
555 u_int16_t streamoutcnt;
557 /* my maximum number of retrans of INIT and SEND */
558 /* copied from SCTP but should be individually setable */
559 u_int16_t max_init_times;
560 u_int16_t max_send_times;
562 u_int16_t def_net_failure;
565 * lock flag: 0 is ok to send, 1+ (duals as a retran count) is
568 u_int16_t asconf_sent; /* possibly removable REM */
569 u_int16_t mapping_array_size;
571 u_int16_t chunks_on_out_queue; /* total chunks floating around */
572 int16_t num_send_timers_up;
574 * This flag indicates that we need to send the first SACK. If
575 * in place it says we have NOT yet sent a SACK and need to.
577 u_int8_t first_ack_sent;
579 /* max burst after fast retransmit completes */
582 u_int8_t sat_network; /* RTT is in range of sat net or greater */
583 u_int8_t sat_network_lockout;/* lockout code */
584 u_int8_t burst_limit_applied; /* Burst limit in effect at last send? */
585 /* flag goes on when we are doing a partial delivery api */
586 u_int8_t hb_random_values[4];
587 u_int8_t fragmented_delivery_inprogress;
588 u_int8_t fragment_flags;
589 u_int8_t hb_ect_randombit;
590 u_int8_t hb_random_idx;
592 /* ECN Nonce stuff */
593 u_int8_t receiver_nonce_sum; /* nonce I sum and put in my sack */
594 u_int8_t ecn_nonce_allowed; /* Tells us if ECN nonce is on */
595 u_int8_t nonce_sum_check; /* On off switch used during re-sync */
596 u_int8_t nonce_wait_for_ecne;/* flag when we expect a ECN */
597 u_int8_t peer_supports_ecn_nonce;
600 * This value, plus all other ack'd but above cum-ack is added
601 * together to cross check against the bit that we have yet to
602 * define (probably in the SACK).
603 * When the cum-ack is updated, this sum is updated as well.
605 u_int8_t nonce_sum_expect_base;
606 /* Flag to tell if ECN is allowed */
607 u_int8_t ecn_allowed;
609 /* flag to indicate if peer can do asconf */
610 uint8_t peer_supports_asconf;
611 uint8_t peer_supports_asconf_setprim; /* possibly removable REM */
612 /* pr-sctp support flag */
613 uint8_t peer_supports_prsctp;
615 /* stream resets are supported by the peer */
616 uint8_t peer_supports_strreset;
619 * packet drop's are supported by the peer, we don't really care
620 * about this but we bookkeep it anyway.
622 uint8_t peer_supports_pktdrop;
624 /* Do we allow V6/V4? */
625 u_int8_t ipv4_addr_legal;
626 u_int8_t ipv6_addr_legal;
627 /* Address scoping flags */
628 /* scope value for IPv4 */
629 u_int8_t ipv4_local_scope;
630 /* scope values for IPv6 */
631 u_int8_t local_scope;
634 u_int8_t loopback_scope;
635 /* flags to handle send alternate net tracking */
636 u_int8_t used_alt_onsack;
637 u_int8_t used_alt_asconfack;
638 u_int8_t fast_retran_loss_recovery;
639 u_int8_t sat_t3_loss_recovery;
640 u_int8_t dropped_special_cnt;
641 u_int8_t seen_a_sack_this_pkt;
642 u_int8_t stream_reset_outstanding;
643 u_int8_t delayed_connection;
644 u_int8_t ifp_had_enobuf;
645 u_int8_t saw_sack_with_frags;
647 * The mapping array is used to track out of order sequences above
648 * last_acked_seq. 0 indicates packet missing 1 indicates packet
649 * rec'd. We slide it up every time we raise last_acked_seq and 0
650 * trailing locactions out. If I get a TSN above the array
651 * mappingArraySz, I discard the datagram and let retransmit happen.