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