xref: /freebsd/sys/netinet/sctp_structs.h (revision dd48af360fdbbb9552f9fc6de7abe50d68ad5331)
1 /*-
2  * Copyright (c) 2001-2008, by 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_structs.h,v 1.13 2005/03/06 16:04:18 itojun Exp $	 */
32 
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35 
36 #ifndef __sctp_structs_h__
37 #define __sctp_structs_h__
38 
39 #include <netinet/sctp_os.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctp_auth.h>
42 
43 struct sctp_timer {
44 	sctp_os_timer_t timer;
45 
46 	int type;
47 	/*
48 	 * Depending on the timer type these will be setup and cast with the
49 	 * appropriate entity.
50 	 */
51 	void *ep;
52 	void *tcb;
53 	void *net;
54 	void *vnet;
55 
56 	/* for sanity checking */
57 	void *self;
58 	uint32_t ticks;
59 	uint32_t stopped_from;
60 };
61 
62 
63 struct sctp_foo_stuff {
64 	struct sctp_inpcb *inp;
65 	uint32_t lineno;
66 	uint32_t ticks;
67 	int updown;
68 };
69 
70 
71 /*
72  * This is the information we track on each interface that we know about from
73  * the distant end.
74  */
75 TAILQ_HEAD(sctpnetlisthead, sctp_nets);
76 
77 struct sctp_stream_reset_list {
78 	TAILQ_ENTRY(sctp_stream_reset_list) next_resp;
79 	uint32_t tsn;
80 	int number_entries;
81 	struct sctp_stream_reset_out_request req;
82 };
83 
84 TAILQ_HEAD(sctp_resethead, sctp_stream_reset_list);
85 
86 /*
87  * Users of the iterator need to malloc a iterator with a call to
88  * sctp_initiate_iterator(inp_func, assoc_func, inp_func,  pcb_flags, pcb_features,
89  *     asoc_state, void-ptr-arg, uint32-arg, end_func, inp);
90  *
91  * Use the following two defines if you don't care what pcb flags are on the EP
92  * and/or you don't care what state the association is in.
93  *
94  * Note that if you specify an INP as the last argument then ONLY each
95  * association of that single INP will be executed upon. Note that the pcb
96  * flags STILL apply so if the inp you specify has different pcb_flags then
97  * what you put in pcb_flags nothing will happen. use SCTP_PCB_ANY_FLAGS to
98  * assure the inp you specify gets treated.
99  */
100 #define SCTP_PCB_ANY_FLAGS	0x00000000
101 #define SCTP_PCB_ANY_FEATURES	0x00000000
102 #define SCTP_ASOC_ANY_STATE	0x00000000
103 
104 typedef void (*asoc_func) (struct sctp_inpcb *, struct sctp_tcb *, void *ptr,
105          uint32_t val);
106 typedef int (*inp_func) (struct sctp_inpcb *, void *ptr, uint32_t val);
107 typedef void (*end_func) (void *ptr, uint32_t val);
108 
109 struct sctp_iterator {
110 	TAILQ_ENTRY(sctp_iterator) sctp_nxt_itr;
111 	struct sctp_timer tmr;
112 	struct sctp_inpcb *inp;	/* current endpoint */
113 	struct sctp_tcb *stcb;	/* current* assoc */
114 	asoc_func function_assoc;	/* per assoc function */
115 	inp_func function_inp;	/* per endpoint function */
116 	inp_func function_inp_end;	/* end INP function */
117 	end_func function_atend;/* iterator completion function */
118 	void *pointer;		/* pointer for apply func to use */
119 	uint32_t val;		/* value for apply func to use */
120 	uint32_t pcb_flags;	/* endpoint flags being checked */
121 	uint32_t pcb_features;	/* endpoint features being checked */
122 	uint32_t asoc_state;	/* assoc state being checked */
123 	uint32_t iterator_flags;
124 	uint8_t no_chunk_output;
125 	uint8_t done_current_ep;
126 };
127 
128 /* iterator_flags values */
129 #define SCTP_ITERATOR_DO_ALL_INP	0x00000001
130 #define SCTP_ITERATOR_DO_SINGLE_INP	0x00000002
131 
132 TAILQ_HEAD(sctpiterators, sctp_iterator);
133 
134 struct sctp_copy_all {
135 	struct sctp_inpcb *inp;	/* ep */
136 	struct mbuf *m;
137 	struct sctp_sndrcvinfo sndrcv;
138 	int sndlen;
139 	int cnt_sent;
140 	int cnt_failed;
141 };
142 
143 struct sctp_asconf_iterator {
144 	struct sctpladdr list_of_work;
145 	int cnt;
146 };
147 
148 struct sctp_net_route {
149 	sctp_rtentry_t *ro_rt;
150 	void *ro_lle;
151 	union sctp_sockstore _l_addr;	/* remote peer addr */
152 	struct sctp_ifa *_s_addr;	/* our selected src addr */
153 };
154 
155 struct htcp {
156 	uint16_t alpha;		/* Fixed point arith, << 7 */
157 	uint8_t beta;		/* Fixed point arith, << 7 */
158 	uint8_t modeswitch;	/* Delay modeswitch until we had at least one
159 				 * congestion event */
160 	uint32_t last_cong;	/* Time since last congestion event end */
161 	uint32_t undo_last_cong;
162 	uint16_t bytes_acked;
163 	uint32_t bytecount;
164 	uint32_t minRTT;
165 	uint32_t maxRTT;
166 
167 	uint32_t undo_maxRTT;
168 	uint32_t undo_old_maxB;
169 
170 	/* Bandwidth estimation */
171 	uint32_t minB;
172 	uint32_t maxB;
173 	uint32_t old_maxB;
174 	uint32_t Bi;
175 	uint32_t lasttime;
176 };
177 
178 
179 struct sctp_nets {
180 	TAILQ_ENTRY(sctp_nets) sctp_next;	/* next link */
181 
182 	/*
183 	 * Things on the top half may be able to be split into a common
184 	 * structure shared by all.
185 	 */
186 	struct sctp_timer pmtu_timer;
187 
188 	/*
189 	 * The following two in combination equate to a route entry for v6
190 	 * or v4.
191 	 */
192 	struct sctp_net_route ro;
193 
194 	/* mtu discovered so far */
195 	uint32_t mtu;
196 	uint32_t ssthresh;	/* not sure about this one for split */
197 
198 	/* smoothed average things for RTT and RTO itself */
199 	int lastsa;
200 	int lastsv;
201 	int rtt;		/* last measured rtt value in ms */
202 	unsigned int RTO;
203 
204 	/* This is used for SHUTDOWN/SHUTDOWN-ACK/SEND or INIT timers */
205 	struct sctp_timer rxt_timer;
206 	struct sctp_timer fr_timer;	/* for early fr */
207 
208 	/* last time in seconds I sent to it */
209 	struct timeval last_sent_time;
210 	int ref_count;
211 
212 	/* Congestion stats per destination */
213 	/*
214 	 * flight size variables and such, sorry Vern, I could not avoid
215 	 * this if I wanted performance :>
216 	 */
217 	uint32_t flight_size;
218 	uint32_t cwnd;		/* actual cwnd */
219 	uint32_t prev_cwnd;	/* cwnd before any processing */
220 	uint32_t partial_bytes_acked;	/* in CA tracks when to incr a MTU */
221 	uint32_t prev_rtt;
222 	/* tracking variables to avoid the aloc/free in sack processing */
223 	unsigned int net_ack;
224 	unsigned int net_ack2;
225 
226 	/*
227 	 * JRS - 5/8/07 - Variable to track last time a destination was
228 	 * active for CMT PF
229 	 */
230 	uint32_t last_active;
231 
232 	/*
233 	 * CMT variables (iyengar@cis.udel.edu)
234 	 */
235 	uint32_t this_sack_highest_newack;	/* tracks highest TSN newly
236 						 * acked for a given dest in
237 						 * the current SACK. Used in
238 						 * SFR and HTNA algos */
239 	uint32_t pseudo_cumack;	/* CMT CUC algorithm. Maintains next expected
240 				 * pseudo-cumack for this destination */
241 	uint32_t rtx_pseudo_cumack;	/* CMT CUC algorithm. Maintains next
242 					 * expected pseudo-cumack for this
243 					 * destination */
244 
245 	/* CMT fast recovery variables */
246 	uint32_t fast_recovery_tsn;
247 	uint32_t heartbeat_random1;
248 	uint32_t heartbeat_random2;
249 	uint32_t tos_flowlabel;
250 
251 	struct timeval start_time;	/* time when this net was created */
252 
253 	uint32_t marked_retrans;/* number or DATA chunks marked for timer
254 				 * based retransmissions */
255 	uint32_t marked_fastretrans;
256 
257 	/* if this guy is ok or not ... status */
258 	uint16_t dest_state;
259 	/* number of transmit failures to down this guy */
260 	uint16_t failure_threshold;
261 	/* error stats on destination */
262 	uint16_t error_count;
263 	/* UDP port number in case of UDP tunneling */
264 	uint16_t port;
265 
266 	uint8_t fast_retran_loss_recovery;
267 	uint8_t will_exit_fast_recovery;
268 	/* Flags that probably can be combined into dest_state */
269 	uint8_t fast_retran_ip;	/* fast retransmit in progress */
270 	uint8_t hb_responded;
271 	uint8_t saw_newack;	/* CMT's SFR algorithm flag */
272 	uint8_t src_addr_selected;	/* if we split we move */
273 	uint8_t indx_of_eligible_next_to_use;
274 	uint8_t addr_is_local;	/* its a local address (if known) could move
275 				 * in split */
276 
277 	/*
278 	 * CMT variables (iyengar@cis.udel.edu)
279 	 */
280 	uint8_t find_pseudo_cumack;	/* CMT CUC algorithm. Flag used to
281 					 * find a new pseudocumack. This flag
282 					 * is set after a new pseudo-cumack
283 					 * has been received and indicates
284 					 * that the sender should find the
285 					 * next pseudo-cumack expected for
286 					 * this destination */
287 	uint8_t find_rtx_pseudo_cumack;	/* CMT CUCv2 algorithm. Flag used to
288 					 * find a new rtx-pseudocumack. This
289 					 * flag is set after a new
290 					 * rtx-pseudo-cumack has been received
291 					 * and indicates that the sender
292 					 * should find the next
293 					 * rtx-pseudo-cumack expected for this
294 					 * destination */
295 	uint8_t new_pseudo_cumack;	/* CMT CUC algorithm. Flag used to
296 					 * indicate if a new pseudo-cumack or
297 					 * rtx-pseudo-cumack has been received */
298 	uint8_t window_probe;	/* Doing a window probe? */
299 	uint8_t RTO_measured;	/* Have we done the first measure */
300 	uint8_t last_hs_used;	/* index into the last HS table entry we used */
301 	/* JRS - struct used in HTCP algorithm */
302 	struct htcp htcp_ca;
303 };
304 
305 
306 struct sctp_data_chunkrec {
307 	uint32_t TSN_seq;	/* the TSN of this transmit */
308 	uint16_t stream_seq;	/* the stream sequence number of this transmit */
309 	uint16_t stream_number;	/* the stream number of this guy */
310 	uint32_t payloadtype;
311 	uint32_t context;	/* from send */
312 
313 	/* ECN Nonce: Nonce Value for this chunk */
314 	uint8_t ect_nonce;
315 	uint8_t fwd_tsn_cnt;
316 	/*
317 	 * part of the Highest sacked algorithm to be able to stroke counts
318 	 * on ones that are FR'd.
319 	 */
320 	uint32_t fast_retran_tsn;	/* sending_seq at the time of FR */
321 	struct timeval timetodrop;	/* time we drop it from queue */
322 	uint8_t doing_fast_retransmit;
323 	uint8_t rcv_flags;	/* flags pulled from data chunk on inbound for
324 				 * outbound holds sending flags for PR-SCTP. */
325 	uint8_t state_flags;
326 	uint8_t chunk_was_revoked;
327 };
328 
329 TAILQ_HEAD(sctpchunk_listhead, sctp_tmit_chunk);
330 
331 /* The lower byte is used to enumerate PR_SCTP policies */
332 #define CHUNK_FLAGS_PR_SCTP_TTL	        SCTP_PR_SCTP_TTL
333 #define CHUNK_FLAGS_PR_SCTP_BUF	        SCTP_PR_SCTP_BUF
334 #define CHUNK_FLAGS_PR_SCTP_RTX         SCTP_PR_SCTP_RTX
335 
336 /* The upper byte is used a a bit mask */
337 #define CHUNK_FLAGS_FRAGMENT_OK	        0x0100
338 
339 struct chk_id {
340 	uint16_t id;
341 	uint16_t can_take_data;
342 };
343 
344 
345 struct sctp_tmit_chunk {
346 	union {
347 		struct sctp_data_chunkrec data;
348 		struct chk_id chunk_id;
349 	}     rec;
350 	struct sctp_association *asoc;	/* bp to asoc this belongs to */
351 	struct timeval sent_rcv_time;	/* filled in if RTT being calculated */
352 	struct mbuf *data;	/* pointer to mbuf chain of data */
353 	struct mbuf *last_mbuf;	/* pointer to last mbuf in chain */
354 	struct sctp_nets *whoTo;
355 	          TAILQ_ENTRY(sctp_tmit_chunk) sctp_next;	/* next link */
356 	int32_t sent;		/* the send status */
357 	uint16_t snd_count;	/* number of times I sent */
358 	uint16_t flags;		/* flags, such as FRAGMENT_OK */
359 	uint16_t send_size;
360 	uint16_t book_size;
361 	uint16_t mbcnt;
362 	uint16_t auth_keyid;
363 	uint8_t holds_key_ref;	/* flag if auth keyid refcount is held */
364 	uint8_t pad_inplace;
365 	uint8_t do_rtt;
366 	uint8_t book_size_scale;
367 	uint8_t no_fr_allowed;
368 	uint8_t pr_sctp_on;
369 	uint8_t copy_by_ref;
370 	uint8_t window_probe;
371 };
372 
373 /*
374  * The first part of this structure MUST be the entire sinfo structure. Maybe
375  * I should have made it a sub structure... we can circle back later and do
376  * that if we want.
377  */
378 struct sctp_queued_to_read {	/* sinfo structure Pluse more */
379 	uint16_t sinfo_stream;	/* off the wire */
380 	uint16_t sinfo_ssn;	/* off the wire */
381 	uint16_t sinfo_flags;	/* SCTP_UNORDERED from wire use SCTP_EOF for
382 				 * EOR */
383 	uint32_t sinfo_ppid;	/* off the wire */
384 	uint32_t sinfo_context;	/* pick this up from assoc def context? */
385 	uint32_t sinfo_timetolive;	/* not used by kernel */
386 	uint32_t sinfo_tsn;	/* Use this in reassembly as first TSN */
387 	uint32_t sinfo_cumtsn;	/* Use this in reassembly as last TSN */
388 	sctp_assoc_t sinfo_assoc_id;	/* our assoc id */
389 	/* Non sinfo stuff */
390 	uint32_t length;	/* length of data */
391 	uint32_t held_length;	/* length held in sb */
392 	struct sctp_nets *whoFrom;	/* where it came from */
393 	struct mbuf *data;	/* front of the mbuf chain of data with
394 				 * PKT_HDR */
395 	struct mbuf *tail_mbuf;	/* used for multi-part data */
396 	struct mbuf *aux_data;	/* used to hold/cache  control if o/s does not
397 				 * take it from us */
398 	struct sctp_tcb *stcb;	/* assoc, used for window update */
399 	         TAILQ_ENTRY(sctp_queued_to_read) next;
400 	uint16_t port_from;
401 	uint16_t spec_flags;	/* Flags to hold the notification field */
402 	uint8_t do_not_ref_stcb;
403 	uint8_t end_added;
404 	uint8_t pdapi_aborted;
405 	uint8_t some_taken;
406 };
407 
408 /* This data structure will be on the outbound
409  * stream queues. Data will be pulled off from
410  * the front of the mbuf data and chunk-ified
411  * by the output routines. We will custom
412  * fit every chunk we pull to the send/sent
413  * queue to make up the next full packet
414  * if we can. An entry cannot be removed
415  * from the stream_out queue until
416  * the msg_is_complete flag is set. This
417  * means at times data/tail_mbuf MIGHT
418  * be NULL.. If that occurs it happens
419  * for one of two reasons. Either the user
420  * is blocked on a send() call and has not
421  * awoken to copy more data down... OR
422  * the user is in the explict MSG_EOR mode
423  * and wrote some data, but has not completed
424  * sending.
425  */
426 struct sctp_stream_queue_pending {
427 	struct mbuf *data;
428 	struct mbuf *tail_mbuf;
429 	struct timeval ts;
430 	struct sctp_nets *net;
431 	          TAILQ_ENTRY(sctp_stream_queue_pending) next;
432 	uint32_t length;
433 	uint32_t timetolive;
434 	uint32_t ppid;
435 	uint32_t context;
436 	uint16_t sinfo_flags;
437 	uint16_t stream;
438 	uint16_t strseq;
439 	uint16_t act_flags;
440 	uint16_t auth_keyid;
441 	uint8_t holds_key_ref;
442 	uint8_t msg_is_complete;
443 	uint8_t some_taken;
444 	uint8_t pr_sctp_on;
445 	uint8_t sender_all_done;
446 	uint8_t put_last_out;
447 	uint8_t discard_rest;
448 };
449 
450 /*
451  * this struct contains info that is used to track inbound stream data and
452  * help with ordering.
453  */
454 TAILQ_HEAD(sctpwheelunrel_listhead, sctp_stream_in);
455 struct sctp_stream_in {
456 	struct sctp_readhead inqueue;
457 	uint16_t stream_no;
458 	uint16_t last_sequence_delivered;	/* used for re-order */
459 	uint8_t delivery_started;
460 };
461 
462 /* This struct is used to track the traffic on outbound streams */
463 TAILQ_HEAD(sctpwheel_listhead, sctp_stream_out);
464 struct sctp_stream_out {
465 	struct sctp_streamhead outqueue;
466 	                TAILQ_ENTRY(sctp_stream_out) next_spoke;	/* next link in wheel */
467 	uint16_t stream_no;
468 	uint16_t next_sequence_sent;	/* next one I expect to send out */
469 	uint8_t last_msg_incomplete;
470 };
471 
472 /* used to keep track of the addresses yet to try to add/delete */
473 TAILQ_HEAD(sctp_asconf_addrhead, sctp_asconf_addr);
474 struct sctp_asconf_addr {
475 	TAILQ_ENTRY(sctp_asconf_addr) next;
476 	struct sctp_asconf_addr_param ap;
477 	struct sctp_ifa *ifa;	/* save the ifa for add/del ip */
478 	uint8_t sent;		/* has this been sent yet? */
479 	uint8_t special_del;	/* not to be used in lookup */
480 };
481 
482 struct sctp_scoping {
483 	uint8_t ipv4_addr_legal;
484 	uint8_t ipv6_addr_legal;
485 	uint8_t loopback_scope;
486 	uint8_t ipv4_local_scope;
487 	uint8_t local_scope;
488 	uint8_t site_scope;
489 };
490 
491 #define SCTP_TSN_LOG_SIZE 40
492 
493 struct sctp_tsn_log {
494 	void *stcb;
495 	uint32_t tsn;
496 	uint16_t strm;
497 	uint16_t seq;
498 	uint16_t sz;
499 	uint16_t flgs;
500 	uint16_t in_pos;
501 	uint16_t in_out;
502 };
503 
504 #define SCTP_FS_SPEC_LOG_SIZE 200
505 struct sctp_fs_spec_log {
506 	uint32_t sent;
507 	uint32_t total_flight;
508 	uint32_t tsn;
509 	uint16_t book;
510 	uint8_t incr;
511 	uint8_t decr;
512 };
513 
514 /* This struct is here to cut out the compatiabilty
515  * pad that bulks up both the inp and stcb. The non
516  * pad portion MUST stay in complete sync with
517  * sctp_sndrcvinfo... i.e. if sinfo_xxxx is added
518  * this must be done here too.
519  */
520 struct sctp_nonpad_sndrcvinfo {
521 	uint16_t sinfo_stream;
522 	uint16_t sinfo_ssn;
523 	uint16_t sinfo_flags;
524 	uint32_t sinfo_ppid;
525 	uint32_t sinfo_context;
526 	uint32_t sinfo_timetolive;
527 	uint32_t sinfo_tsn;
528 	uint32_t sinfo_cumtsn;
529 	sctp_assoc_t sinfo_assoc_id;
530 };
531 
532 /*
533  * JRS - Structure to hold function pointers to the functions responsible
534  * for congestion control.
535  */
536 
537 struct sctp_cc_functions {
538 	void (*sctp_set_initial_cc_param) (struct sctp_tcb *stcb, struct sctp_nets *net);
539 	void (*sctp_cwnd_update_after_sack) (struct sctp_tcb *stcb,
540 	         struct sctp_association *asoc,
541 	         int accum_moved, int reneged_all, int will_exit);
542 	void (*sctp_cwnd_update_after_fr) (struct sctp_tcb *stcb,
543 	         struct sctp_association *asoc);
544 	void (*sctp_cwnd_update_after_timeout) (struct sctp_tcb *stcb,
545 	         struct sctp_nets *net);
546 	void (*sctp_cwnd_update_after_ecn_echo) (struct sctp_tcb *stcb,
547 	         struct sctp_nets *net);
548 	void (*sctp_cwnd_update_after_packet_dropped) (struct sctp_tcb *stcb,
549 	         struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
550 	         uint32_t * bottle_bw, uint32_t * on_queue);
551 	void (*sctp_cwnd_update_after_output) (struct sctp_tcb *stcb,
552 	         struct sctp_nets *net, int burst_limit);
553 	void (*sctp_cwnd_update_after_fr_timer) (struct sctp_inpcb *inp,
554 	         struct sctp_tcb *stcb, struct sctp_nets *net);
555 };
556 
557 /* used to save ASCONF chunks for retransmission */
558 TAILQ_HEAD(sctp_asconf_head, sctp_asconf);
559 struct sctp_asconf {
560 	TAILQ_ENTRY(sctp_asconf) next;
561 	uint32_t serial_number;
562 	uint16_t snd_count;
563 	struct mbuf *data;
564 	uint16_t len;
565 };
566 
567 /* used to save ASCONF-ACK chunks for retransmission */
568 TAILQ_HEAD(sctp_asconf_ackhead, sctp_asconf_ack);
569 struct sctp_asconf_ack {
570 	TAILQ_ENTRY(sctp_asconf_ack) next;
571 	uint32_t serial_number;
572 	struct sctp_nets *last_sent_to;
573 	struct mbuf *data;
574 	uint16_t len;
575 };
576 
577 /*
578  * Here we have information about each individual association that we track.
579  * We probably in production would be more dynamic. But for ease of
580  * implementation we will have a fixed array that we hunt for in a linear
581  * fashion.
582  */
583 struct sctp_association {
584 	/* association state */
585 	int state;
586 
587 	/* queue of pending addrs to add/delete */
588 	struct sctp_asconf_addrhead asconf_queue;
589 
590 	struct timeval time_entered;	/* time we entered state */
591 	struct timeval time_last_rcvd;
592 	struct timeval time_last_sent;
593 	struct timeval time_last_sat_advance;
594 	struct sctp_nonpad_sndrcvinfo def_send;
595 
596 	/* timers and such */
597 	struct sctp_timer hb_timer;	/* hb timer */
598 	struct sctp_timer dack_timer;	/* Delayed ack timer */
599 	struct sctp_timer asconf_timer;	/* asconf */
600 	struct sctp_timer strreset_timer;	/* stream reset */
601 	struct sctp_timer shut_guard_timer;	/* shutdown guard */
602 	struct sctp_timer autoclose_timer;	/* automatic close timer */
603 	struct sctp_timer delayed_event_timer;	/* timer for delayed events */
604 	struct sctp_timer delete_prim_timer;	/* deleting primary dst */
605 
606 	/* list of restricted local addresses */
607 	struct sctpladdr sctp_restricted_addrs;
608 
609 	/* last local address pending deletion (waiting for an address add) */
610 	struct sctp_ifa *asconf_addr_del_pending;
611 	/* Deleted primary destination (used to stop timer) */
612 	struct sctp_nets *deleted_primary;
613 
614 	struct sctpnetlisthead nets;	/* remote address list */
615 
616 	/* Free chunk list */
617 	struct sctpchunk_listhead free_chunks;
618 
619 	/* Control chunk queue */
620 	struct sctpchunk_listhead control_send_queue;
621 
622 	/* ASCONF chunk queue */
623 	struct sctpchunk_listhead asconf_send_queue;
624 
625 	/*
626 	 * Once a TSN hits the wire it is moved to the sent_queue. We
627 	 * maintain two counts here (don't know if any but retran_cnt is
628 	 * needed). The idea is that the sent_queue_retran_cnt reflects how
629 	 * many chunks have been marked for retranmission by either T3-rxt
630 	 * or FR.
631 	 */
632 	struct sctpchunk_listhead sent_queue;
633 	struct sctpchunk_listhead send_queue;
634 
635 	/* re-assembly queue for fragmented chunks on the inbound path */
636 	struct sctpchunk_listhead reasmqueue;
637 
638 	/*
639 	 * this queue is used when we reach a condition that we can NOT put
640 	 * data into the socket buffer. We track the size of this queue and
641 	 * set our rwnd to the space in the socket minus also the
642 	 * size_on_delivery_queue.
643 	 */
644 	struct sctpwheel_listhead out_wheel;
645 
646 	/*
647 	 * This pointer will be set to NULL most of the time. But when we
648 	 * have a fragmented message, where we could not get out all of the
649 	 * message at the last send then this will point to the stream to go
650 	 * get data from.
651 	 */
652 	struct sctp_stream_out *locked_on_sending;
653 
654 	/* If an iterator is looking at me, this is it */
655 	struct sctp_iterator *stcb_starting_point_for_iterator;
656 
657 	/* ASCONF save the last ASCONF-ACK so we can resend it if necessary */
658 	struct sctp_asconf_ackhead asconf_ack_sent;
659 
660 	/*
661 	 * pointer to last stream reset queued to control queue by us with
662 	 * requests.
663 	 */
664 	struct sctp_tmit_chunk *str_reset;
665 	/*
666 	 * if Source Address Selection happening, this will rotate through
667 	 * the link list.
668 	 */
669 	struct sctp_laddr *last_used_address;
670 
671 	/* stream arrays */
672 	struct sctp_stream_in *strmin;
673 	struct sctp_stream_out *strmout;
674 	uint8_t *mapping_array;
675 	/* primary destination to use */
676 	struct sctp_nets *primary_destination;
677 	/* For CMT */
678 	struct sctp_nets *last_net_cmt_send_started;
679 	/* last place I got a data chunk from */
680 	struct sctp_nets *last_data_chunk_from;
681 	/* last place I got a control from */
682 	struct sctp_nets *last_control_chunk_from;
683 
684 	/* circular looking for output selection */
685 	struct sctp_stream_out *last_out_stream;
686 
687 	/*
688 	 * wait to the point the cum-ack passes req->send_reset_at_tsn for
689 	 * any req on the list.
690 	 */
691 	struct sctp_resethead resetHead;
692 
693 	/* queue of chunks waiting to be sent into the local stack */
694 	struct sctp_readhead pending_reply_queue;
695 
696 	/* JRS - the congestion control functions are in this struct */
697 	struct sctp_cc_functions cc_functions;
698 	/*
699 	 * JRS - value to store the currently loaded congestion control
700 	 * module
701 	 */
702 	uint32_t congestion_control_module;
703 
704 	uint32_t vrf_id;
705 
706 	uint32_t cookie_preserve_req;
707 	/* ASCONF next seq I am sending out, inits at init-tsn */
708 	uint32_t asconf_seq_out;
709 	uint32_t asconf_seq_out_acked;
710 	/* ASCONF last received ASCONF from peer, starts at peer's TSN-1 */
711 	uint32_t asconf_seq_in;
712 
713 	/* next seq I am sending in str reset messages */
714 	uint32_t str_reset_seq_out;
715 	/* next seq I am expecting in str reset messages */
716 	uint32_t str_reset_seq_in;
717 
718 	/* various verification tag information */
719 	uint32_t my_vtag;	/* The tag to be used. if assoc is re-initited
720 				 * by remote end, and I have unlocked this
721 				 * will be regenerated to a new random value. */
722 	uint32_t peer_vtag;	/* The peers last tag */
723 
724 	uint32_t my_vtag_nonce;
725 	uint32_t peer_vtag_nonce;
726 
727 	uint32_t assoc_id;
728 
729 	/* This is the SCTP fragmentation threshold */
730 	uint32_t smallest_mtu;
731 
732 	/*
733 	 * Special hook for Fast retransmit, allows us to track the highest
734 	 * TSN that is NEW in this SACK if gap ack blocks are present.
735 	 */
736 	uint32_t this_sack_highest_gap;
737 
738 	/*
739 	 * The highest consecutive TSN that has been acked by peer on my
740 	 * sends
741 	 */
742 	uint32_t last_acked_seq;
743 
744 	/* The next TSN that I will use in sending. */
745 	uint32_t sending_seq;
746 
747 	/* Original seq number I used ??questionable to keep?? */
748 	uint32_t init_seq_number;
749 
750 
751 	/* The Advanced Peer Ack Point, as required by the PR-SCTP */
752 	/* (A1 in Section 4.2) */
753 	uint32_t advanced_peer_ack_point;
754 
755 	/*
756 	 * The highest consequetive TSN at the bottom of the mapping array
757 	 * (for his sends).
758 	 */
759 	uint32_t cumulative_tsn;
760 	/*
761 	 * Used to track the mapping array and its offset bits. This MAY be
762 	 * lower then cumulative_tsn.
763 	 */
764 	uint32_t mapping_array_base_tsn;
765 	/*
766 	 * used to track highest TSN we have received and is listed in the
767 	 * mapping array.
768 	 */
769 	uint32_t highest_tsn_inside_map;
770 
771 	/* EY - new NR variables used for nr_sack based on mapping_array */
772 	uint8_t *nr_mapping_array;
773 	uint32_t highest_tsn_inside_nr_map;
774 
775 	uint32_t last_echo_tsn;
776 	uint32_t last_cwr_tsn;
777 	uint32_t fast_recovery_tsn;
778 	uint32_t sat_t3_recovery_tsn;
779 	uint32_t tsn_last_delivered;
780 	/*
781 	 * For the pd-api we should re-write this a bit more efficent. We
782 	 * could have multiple sctp_queued_to_read's that we are building at
783 	 * once. Now we only do this when we get ready to deliver to the
784 	 * socket buffer. Note that we depend on the fact that the struct is
785 	 * "stuck" on the read queue until we finish all the pd-api.
786 	 */
787 	struct sctp_queued_to_read *control_pdapi;
788 
789 	uint32_t tsn_of_pdapi_last_delivered;
790 	uint32_t pdapi_ppid;
791 	uint32_t context;
792 	uint32_t last_reset_action[SCTP_MAX_RESET_PARAMS];
793 	uint32_t last_sending_seq[SCTP_MAX_RESET_PARAMS];
794 	uint32_t last_base_tsnsent[SCTP_MAX_RESET_PARAMS];
795 #ifdef SCTP_ASOCLOG_OF_TSNS
796 	/*
797 	 * special log  - This adds considerable size to the asoc, but
798 	 * provides a log that you can use to detect problems via kgdb.
799 	 */
800 	struct sctp_tsn_log in_tsnlog[SCTP_TSN_LOG_SIZE];
801 	struct sctp_tsn_log out_tsnlog[SCTP_TSN_LOG_SIZE];
802 	uint32_t cumack_log[SCTP_TSN_LOG_SIZE];
803 	uint32_t cumack_logsnt[SCTP_TSN_LOG_SIZE];
804 	uint16_t tsn_in_at;
805 	uint16_t tsn_out_at;
806 	uint16_t tsn_in_wrapped;
807 	uint16_t tsn_out_wrapped;
808 	uint16_t cumack_log_at;
809 	uint16_t cumack_log_atsnt;
810 #endif				/* SCTP_ASOCLOG_OF_TSNS */
811 #ifdef SCTP_FS_SPEC_LOG
812 	struct sctp_fs_spec_log fslog[SCTP_FS_SPEC_LOG_SIZE];
813 	uint16_t fs_index;
814 #endif
815 
816 	/*
817 	 * window state information and smallest MTU that I use to bound
818 	 * segmentation
819 	 */
820 	uint32_t peers_rwnd;
821 	uint32_t my_rwnd;
822 	uint32_t my_last_reported_rwnd;
823 	uint32_t sctp_frag_point;
824 
825 	uint32_t total_output_queue_size;
826 
827 	uint32_t sb_cc;		/* shadow of sb_cc */
828 	uint32_t sb_send_resv;	/* amount reserved on a send */
829 	uint32_t my_rwnd_control_len;	/* shadow of sb_mbcnt used for rwnd
830 					 * control */
831 	/* 32 bit nonce stuff */
832 	uint32_t nonce_resync_tsn;
833 	uint32_t nonce_wait_tsn;
834 	uint32_t default_flowlabel;
835 	uint32_t pr_sctp_cnt;
836 	int ctrl_queue_cnt;	/* could be removed  REM */
837 	/*
838 	 * All outbound datagrams queue into this list from the individual
839 	 * stream queue. Here they get assigned a TSN and then await
840 	 * sending. The stream seq comes when it is first put in the
841 	 * individual str queue
842 	 */
843 	unsigned int stream_queue_cnt;
844 	unsigned int send_queue_cnt;
845 	unsigned int sent_queue_cnt;
846 	unsigned int sent_queue_cnt_removeable;
847 	/*
848 	 * Number on sent queue that are marked for retran until this value
849 	 * is 0 we only send one packet of retran'ed data.
850 	 */
851 	unsigned int sent_queue_retran_cnt;
852 
853 	unsigned int size_on_reasm_queue;
854 	unsigned int cnt_on_reasm_queue;
855 	/* amount of data (bytes) currently in flight (on all destinations) */
856 	unsigned int total_flight;
857 	/* Total book size in flight */
858 	unsigned int total_flight_count;	/* count of chunks used with
859 						 * book total */
860 	/* count of destinaton nets and list of destination nets */
861 	unsigned int numnets;
862 
863 	/* Total error count on this association */
864 	unsigned int overall_error_count;
865 
866 	unsigned int cnt_msg_on_sb;
867 
868 	/* All stream count of chunks for delivery */
869 	unsigned int size_on_all_streams;
870 	unsigned int cnt_on_all_streams;
871 
872 	/* Heart Beat delay in ticks */
873 	unsigned int heart_beat_delay;
874 
875 	/* autoclose */
876 	unsigned int sctp_autoclose_ticks;
877 
878 	/* how many preopen streams we have */
879 	unsigned int pre_open_streams;
880 
881 	/* How many streams I support coming into me */
882 	unsigned int max_inbound_streams;
883 
884 	/* the cookie life I award for any cookie, in seconds */
885 	unsigned int cookie_life;
886 	/* time to delay acks for */
887 	unsigned int delayed_ack;
888 	unsigned int old_delayed_ack;
889 	unsigned int sack_freq;
890 	unsigned int data_pkts_seen;
891 
892 	unsigned int numduptsns;
893 	int dup_tsns[SCTP_MAX_DUP_TSNS];
894 	unsigned int initial_init_rto_max;	/* initial RTO for INIT's */
895 	unsigned int initial_rto;	/* initial send RTO */
896 	unsigned int minrto;	/* per assoc RTO-MIN */
897 	unsigned int maxrto;	/* per assoc RTO-MAX */
898 
899 	/* authentication fields */
900 	sctp_auth_chklist_t *local_auth_chunks;
901 	sctp_auth_chklist_t *peer_auth_chunks;
902 	sctp_hmaclist_t *local_hmacs;	/* local HMACs supported */
903 	sctp_hmaclist_t *peer_hmacs;	/* peer HMACs supported */
904 	struct sctp_keyhead shared_keys;	/* assoc's shared keys */
905 	sctp_authinfo_t authinfo;	/* randoms, cached keys */
906 	/*
907 	 * refcnt to block freeing when a sender or receiver is off coping
908 	 * user data in.
909 	 */
910 	uint32_t refcnt;
911 	uint32_t chunks_on_out_queue;	/* total chunks floating around,
912 					 * locked by send socket buffer */
913 	uint32_t peers_adaptation;
914 	uint16_t peer_hmac_id;	/* peer HMAC id to send */
915 
916 	/*
917 	 * Being that we have no bag to collect stale cookies, and that we
918 	 * really would not want to anyway.. we will count them in this
919 	 * counter. We of course feed them to the pigeons right away (I have
920 	 * always thought of pigeons as flying rats).
921 	 */
922 	uint16_t stale_cookie_count;
923 
924 	/*
925 	 * For the partial delivery API, if up, invoked this is what last
926 	 * TSN I delivered
927 	 */
928 	uint16_t str_of_pdapi;
929 	uint16_t ssn_of_pdapi;
930 
931 	/* counts of actual built streams. Allocation may be more however */
932 	/* could re-arrange to optimize space here. */
933 	uint16_t streamincnt;
934 	uint16_t streamoutcnt;
935 	uint16_t strm_realoutsize;
936 	/* my maximum number of retrans of INIT and SEND */
937 	/* copied from SCTP but should be individually setable */
938 	uint16_t max_init_times;
939 	uint16_t max_send_times;
940 
941 	uint16_t def_net_failure;
942 
943 	/*
944 	 * lock flag: 0 is ok to send, 1+ (duals as a retran count) is
945 	 * awaiting ACK
946 	 */
947 	uint16_t mapping_array_size;
948 
949 	uint16_t last_strm_seq_delivered;
950 	uint16_t last_strm_no_delivered;
951 
952 	uint16_t last_revoke_count;
953 	int16_t num_send_timers_up;
954 
955 	uint16_t stream_locked_on;
956 	uint16_t ecn_echo_cnt_onq;
957 
958 	uint16_t free_chunk_cnt;
959 
960 	uint8_t stream_locked;
961 	uint8_t authenticated;	/* packet authenticated ok */
962 	/*
963 	 * This flag indicates that a SACK need to be sent. Initially this
964 	 * is 1 to send the first sACK immediately.
965 	 */
966 	uint8_t send_sack;
967 
968 	/* max burst after fast retransmit completes */
969 	uint8_t max_burst;
970 
971 	uint8_t sat_network;	/* RTT is in range of sat net or greater */
972 	uint8_t sat_network_lockout;	/* lockout code */
973 	uint8_t burst_limit_applied;	/* Burst limit in effect at last send? */
974 	/* flag goes on when we are doing a partial delivery api */
975 	uint8_t hb_random_values[4];
976 	uint8_t fragmented_delivery_inprogress;
977 	uint8_t fragment_flags;
978 	uint8_t last_flags_delivered;
979 	uint8_t hb_ect_randombit;
980 	uint8_t hb_random_idx;
981 	uint8_t hb_is_disabled;	/* is the hb disabled? */
982 	uint8_t default_tos;
983 	uint8_t asconf_del_pending;	/* asconf delete last addr pending */
984 
985 	/* ECN Nonce stuff */
986 	uint8_t receiver_nonce_sum;	/* nonce I sum and put in my sack */
987 	uint8_t ecn_nonce_allowed;	/* Tells us if ECN nonce is on */
988 	uint8_t nonce_sum_check;/* On off switch used during re-sync */
989 	uint8_t nonce_wait_for_ecne;	/* flag when we expect a ECN */
990 	uint8_t peer_supports_ecn_nonce;
991 
992 	/*
993 	 * This value, plus all other ack'd but above cum-ack is added
994 	 * together to cross check against the bit that we have yet to
995 	 * define (probably in the SACK). When the cum-ack is updated, this
996 	 * sum is updated as well.
997 	 */
998 	uint8_t nonce_sum_expect_base;
999 	/* Flag to tell if ECN is allowed */
1000 	uint8_t ecn_allowed;
1001 
1002 	/* flag to indicate if peer can do asconf */
1003 	uint8_t peer_supports_asconf;
1004 	/* EY - flag to indicate if peer can do nr_sack */
1005 	uint8_t peer_supports_nr_sack;
1006 	/* pr-sctp support flag */
1007 	uint8_t peer_supports_prsctp;
1008 	/* peer authentication support flag */
1009 	uint8_t peer_supports_auth;
1010 	/* stream resets are supported by the peer */
1011 	uint8_t peer_supports_strreset;
1012 
1013 	uint8_t peer_supports_nat;
1014 	/*
1015 	 * packet drop's are supported by the peer, we don't really care
1016 	 * about this but we bookkeep it anyway.
1017 	 */
1018 	uint8_t peer_supports_pktdrop;
1019 
1020 	/* Do we allow V6/V4? */
1021 	uint8_t ipv4_addr_legal;
1022 	uint8_t ipv6_addr_legal;
1023 	/* Address scoping flags */
1024 	/* scope value for IPv4 */
1025 	uint8_t ipv4_local_scope;
1026 	/* scope values for IPv6 */
1027 	uint8_t local_scope;
1028 	uint8_t site_scope;
1029 	/* loopback scope */
1030 	uint8_t loopback_scope;
1031 	/* flags to handle send alternate net tracking */
1032 	uint8_t used_alt_onsack;
1033 	uint8_t used_alt_asconfack;
1034 	uint8_t fast_retran_loss_recovery;
1035 	uint8_t sat_t3_loss_recovery;
1036 	uint8_t dropped_special_cnt;
1037 	uint8_t seen_a_sack_this_pkt;
1038 	uint8_t stream_reset_outstanding;
1039 	uint8_t stream_reset_out_is_outstanding;
1040 	uint8_t delayed_connection;
1041 	uint8_t ifp_had_enobuf;
1042 	uint8_t saw_sack_with_frags;
1043 	uint8_t in_asocid_hash;
1044 	uint8_t assoc_up_sent;
1045 	uint8_t adaptation_needed;
1046 	uint8_t adaptation_sent;
1047 	/* CMT variables */
1048 	uint8_t cmt_dac_pkts_rcvd;
1049 	uint8_t sctp_cmt_on_off;
1050 	uint8_t iam_blocking;
1051 	uint8_t cookie_how[8];
1052 	/* EY 05/05/08 - NR_SACK variable */
1053 	uint8_t sctp_nr_sack_on_off;
1054 	/* JRS 5/21/07 - CMT PF variable */
1055 	uint8_t sctp_cmt_pf;
1056 	/*
1057 	 * The mapping array is used to track out of order sequences above
1058 	 * last_acked_seq. 0 indicates packet missing 1 indicates packet
1059 	 * rec'd. We slide it up every time we raise last_acked_seq and 0
1060 	 * trailing locactions out.  If I get a TSN above the array
1061 	 * mappingArraySz, I discard the datagram and let retransmit happen.
1062 	 */
1063 	uint32_t marked_retrans;
1064 	uint32_t timoinit;
1065 	uint32_t timodata;
1066 	uint32_t timosack;
1067 	uint32_t timoshutdown;
1068 	uint32_t timoheartbeat;
1069 	uint32_t timocookie;
1070 	uint32_t timoshutdownack;
1071 	struct timeval start_time;
1072 	struct timeval discontinuity_time;
1073 };
1074 
1075 #endif
1076