1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2003
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001 Intel Corp.
6 *
7 * This file is part of the SCTP kernel reference Implementation
8 *
9 * The SCTP reference implementation is free software;
10 * you can redistribute it and/or modify it under the terms of
11 * the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * The SCTP reference implementation is distributed in the hope that it
16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * ************************
18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with GNU CC; see the file COPYING. If not, write to
23 * the Free Software Foundation, 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
25 *
26 * Please send any bug reports or fixes you make to the
27 * email addresses:
28 * lksctp developers <lksctp-developers@lists.sourceforge.net>
29 *
30 * Or submit a bug report through the following website:
31 * http://www.sf.net/projects/lksctp
32 *
33 * Written or modified by:
34 * Randall Stewart <randall@sctp.chicago.il.us>
35 * Ken Morneau <kmorneau@cisco.com>
36 * Qiaobing Xie <qxie1@email.mot.com>
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Jon Grimm <jgrimm@us.ibm.com>
40 * Xingang Guo <xingang.guo@intel.com>
41 * Hui Huang <hui.huang@nokia.com>
42 * Sridhar Samudrala <sri@us.ibm.com>
43 * Daisy Chang <daisyc@us.ibm.com>
44 * Dajiang Zhang <dajiang.zhang@nokia.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Ryan Layer <rmlayer@us.ibm.com>
47 * Anup Pemmaiah <pemmaiah@cc.usu.edu>
48 * Kevin Gao <kevin.gao@intel.com>
49 *
50 * Any bugs reported given to us we will try to fix... any fixes shared will
51 * be incorporated into the next SCTP release.
52 */
53
54 #ifndef __sctp_structs_h__
55 #define __sctp_structs_h__
56
57 #include <linux/time.h> /* We get struct timespec. */
58 #include <linux/socket.h> /* linux/in.h needs this!! */
59 #include <linux/in.h> /* We get struct sockaddr_in. */
60 #include <linux/in6.h> /* We get struct in6_addr */
61 #include <asm/param.h> /* We get MAXHOSTNAMELEN. */
62 #include <asm/atomic.h> /* This gets us atomic counters. */
63 #include <linux/skbuff.h> /* We need sk_buff_head. */
64 #include <linux/tqueue.h> /* We need tq_struct. */
65 #include <linux/sctp.h> /* We need sctp* header structs. */
66
67 /* A convenience structure for handling sockaddr structures.
68 * We should wean ourselves off this.
69 */
70 union sctp_addr {
71 struct sockaddr_in v4;
72 struct sockaddr_in6 v6;
73 struct sockaddr sa;
74 };
75
76 /* Forward declarations for data structures. */
77 struct sctp_globals;
78 struct sctp_endpoint;
79 struct sctp_association;
80 struct sctp_transport;
81 struct sctp_packet;
82 struct sctp_chunk;
83 struct sctp_inq;
84 struct sctp_outq;
85 struct sctp_bind_addr;
86 struct sctp_ulpq;
87 struct sctp_opt;
88 struct sctp_ep_common;
89 struct sctp_ssnmap;
90
91
92 #include <net/sctp/compat.h>
93 #include <net/sctp/tsnmap.h>
94 #include <net/sctp/ulpevent.h>
95 #include <net/sctp/ulpqueue.h>
96
97 /* Structures useful for managing bind/connect. */
98
99 struct sctp_bind_bucket {
100 unsigned short port;
101 unsigned short fastreuse;
102 struct sctp_bind_bucket *next;
103 struct sctp_bind_bucket **pprev;
104 struct sock *sk;
105 };
106
107 struct sctp_bind_hashbucket {
108 spinlock_t lock;
109 struct sctp_bind_bucket *chain;
110 };
111
112 /* Used for hashing all associations. */
113 struct sctp_hashbucket {
114 rwlock_t lock;
115 struct sctp_ep_common *chain;
116 } __attribute__((__aligned__(8)));
117
118
119 /* The SCTP globals structure. */
120 extern struct sctp_globals {
121 /* RFC2960 Section 14. Suggested SCTP Protocol Parameter Values
122 *
123 * The following protocol parameters are RECOMMENDED:
124 *
125 * RTO.Initial - 3 seconds
126 * RTO.Min - 1 second
127 * RTO.Max - 60 seconds
128 * RTO.Alpha - 1/8 (3 when converted to right shifts.)
129 * RTO.Beta - 1/4 (2 when converted to right shifts.)
130 */
131 __u32 rto_initial;
132 __u32 rto_min;
133 __u32 rto_max;
134
135 /* Note: rto_alpha and rto_beta are really defined as inverse
136 * powers of two to facilitate integer operations.
137 */
138 int rto_alpha;
139 int rto_beta;
140
141 /* Max.Burst - 4 */
142 int max_burst;
143
144 /* Valid.Cookie.Life - 60 seconds */
145 int valid_cookie_life;
146
147 /* Whether Cookie Preservative is enabled(1) or not(0) */
148 int cookie_preserve_enable;
149
150 /* Association.Max.Retrans - 10 attempts
151 * Path.Max.Retrans - 5 attempts (per destination address)
152 * Max.Init.Retransmits - 8 attempts
153 */
154 int max_retrans_association;
155 int max_retrans_path;
156 int max_retrans_init;
157
158 /* HB.interval - 30 seconds */
159 int hb_interval;
160
161 /* The following variables are implementation specific. */
162
163 /* Default initialization values to be applied to new associations. */
164 __u16 max_instreams;
165 __u16 max_outstreams;
166
167 /* This is a list of groups of functions for each address
168 * family that we support.
169 */
170 struct list_head address_families;
171
172 /* This is the hash of all endpoints. */
173 int ep_hashsize;
174 struct sctp_hashbucket *ep_hashtable;
175
176 /* This is the hash of all associations. */
177 int assoc_hashsize;
178 struct sctp_hashbucket *assoc_hashtable;
179
180 /* This is the sctp port control hash. */
181 int port_hashsize;
182 int port_rover;
183 spinlock_t port_alloc_lock; /* Protects port_rover. */
184 struct sctp_bind_hashbucket *port_hashtable;
185
186 /* This is the global local address list.
187 * We actively maintain this complete list of interfaces on
188 * the system by catching routing events.
189 *
190 * It is a list of sctp_sockaddr_entry.
191 */
192 struct list_head local_addr_list;
193 spinlock_t local_addr_lock;
194
195 /* Flag to indicate if addip is enabled. */
196 int addip_enable;
197
198 /* Flag to indicate if PR-SCTP is enabled. */
199 int prsctp_enable;
200 } sctp_globals;
201
202 #define sctp_rto_initial (sctp_globals.rto_initial)
203 #define sctp_rto_min (sctp_globals.rto_min)
204 #define sctp_rto_max (sctp_globals.rto_max)
205 #define sctp_rto_alpha (sctp_globals.rto_alpha)
206 #define sctp_rto_beta (sctp_globals.rto_beta)
207 #define sctp_max_burst (sctp_globals.max_burst)
208 #define sctp_valid_cookie_life (sctp_globals.valid_cookie_life)
209 #define sctp_cookie_preserve_enable (sctp_globals.cookie_preserve_enable)
210 #define sctp_max_retrans_association (sctp_globals.max_retrans_association)
211 #define sctp_max_retrans_path (sctp_globals.max_retrans_path)
212 #define sctp_max_retrans_init (sctp_globals.max_retrans_init)
213 #define sctp_hb_interval (sctp_globals.hb_interval)
214 #define sctp_max_instreams (sctp_globals.max_instreams)
215 #define sctp_max_outstreams (sctp_globals.max_outstreams)
216 #define sctp_address_families (sctp_globals.address_families)
217 #define sctp_ep_hashsize (sctp_globals.ep_hashsize)
218 #define sctp_ep_hashtable (sctp_globals.ep_hashtable)
219 #define sctp_assoc_hashsize (sctp_globals.assoc_hashsize)
220 #define sctp_assoc_hashtable (sctp_globals.assoc_hashtable)
221 #define sctp_port_hashsize (sctp_globals.port_hashsize)
222 #define sctp_port_rover (sctp_globals.port_rover)
223 #define sctp_port_alloc_lock (sctp_globals.port_alloc_lock)
224 #define sctp_port_hashtable (sctp_globals.port_hashtable)
225 #define sctp_local_addr_list (sctp_globals.local_addr_list)
226 #define sctp_local_addr_lock (sctp_globals.local_addr_lock)
227 #define sctp_addip_enable (sctp_globals.addip_enable)
228 #define sctp_prsctp_enable (sctp_globals.prsctp_enable)
229
230 /* SCTP Socket type: UDP or TCP style. */
231 typedef enum {
232 SCTP_SOCKET_UDP = 0,
233 SCTP_SOCKET_UDP_HIGH_BANDWIDTH,
234 SCTP_SOCKET_TCP
235 } sctp_socket_type_t;
236
237 /* Per socket SCTP information. */
238 struct sctp_opt {
239 /* What kind of a socket is this? */
240 sctp_socket_type_t type;
241
242 /* PF_ family specific functions. */
243 struct sctp_pf *pf;
244
245 /* Access to HMAC transform. */
246 struct crypto_tfm *hmac;
247
248 /* What is our base endpointer? */
249 struct sctp_endpoint *ep;
250
251 /* Various Socket Options. */
252 __u16 default_stream;
253 __u32 default_ppid;
254 __u16 default_flags;
255 __u32 default_context;
256 __u32 default_timetolive;
257
258 struct sctp_initmsg initmsg;
259 struct sctp_rtoinfo rtoinfo;
260 struct sctp_paddrparams paddrparam;
261 struct sctp_event_subscribe subscribe;
262 struct sctp_assocparams assocparams;
263 int user_frag;
264 __u32 autoclose;
265 __u8 nodelay;
266 __u8 disable_fragments;
267 __u8 pd_mode;
268 __u8 v4mapped;
269 __u32 adaption_ind;
270
271 /* Receive to here while partial delivery is in effect. */
272 struct sk_buff_head pd_lobby;
273 };
274
275
276
277 /* This is our APPLICATION-SPECIFIC state cookie.
278 * THIS IS NOT DICTATED BY THE SPECIFICATION.
279 */
280 /* These are the parts of an association which we send in the cookie.
281 * Most of these are straight out of:
282 * RFC2960 12.2 Parameters necessary per association (i.e. the TCB)
283 *
284 */
285
286 struct sctp_cookie {
287
288 /* My : Tag expected in every inbound packet and sent
289 * Verification: in the INIT or INIT ACK chunk.
290 * Tag :
291 */
292 __u32 my_vtag;
293
294 /* Peer's : Tag expected in every outbound packet except
295 * Verification: in the INIT chunk.
296 * Tag :
297 */
298 __u32 peer_vtag;
299
300 /* The rest of these are not from the spec, but really need to
301 * be in the cookie.
302 */
303
304 /* My Tie Tag : Assist in discovering a restarting association. */
305 __u32 my_ttag;
306
307 /* Peer's Tie Tag: Assist in discovering a restarting association. */
308 __u32 peer_ttag;
309
310 /* When does this cookie expire? */
311 struct timeval expiration;
312
313 /* Number of inbound/outbound streams which are set
314 * and negotiated during the INIT process.
315 */
316 __u16 sinit_num_ostreams;
317 __u16 sinit_max_instreams;
318
319 /* This is the first sequence number I used. */
320 __u32 initial_tsn;
321
322 /* This holds the originating address of the INIT packet. */
323 union sctp_addr peer_addr;
324
325 /* IG Section 2.35.3
326 * Include the source port of the INIT-ACK
327 */
328 __u16 my_port;
329
330 __u8 prsctp_capable;
331
332 /* Padding for future use */
333 __u8 padding;
334
335 __u32 adaption_ind;
336
337
338 /* This is a shim for my peer's INIT packet, followed by
339 * a copy of the raw address list of the association.
340 * The length of the raw address list is saved in the
341 * raw_addr_list_len field, which will be used at the time when
342 * the association TCB is re-constructed from the cookie.
343 */
344 __u32 raw_addr_list_len;
345 struct sctp_init_chunk peer_init[0];
346 };
347
348
349 /* The format of our cookie that we send to our peer. */
350 struct sctp_signed_cookie {
351 __u8 signature[SCTP_SECRET_SIZE];
352 struct sctp_cookie c;
353 };
354
355 /* This is another convenience type to allocate memory for address
356 * params for the maximum size and pass such structures around
357 * internally.
358 */
359 union sctp_addr_param {
360 struct sctp_ipv4addr_param v4;
361 struct sctp_ipv6addr_param v6;
362 };
363
364 /* A convenience type to allow walking through the various
365 * parameters and avoid casting all over the place.
366 */
367 union sctp_params {
368 void *v;
369 struct sctp_paramhdr *p;
370 struct sctp_cookie_preserve_param *life;
371 struct sctp_hostname_param *dns;
372 struct sctp_cookie_param *cookie;
373 struct sctp_supported_addrs_param *sat;
374 struct sctp_ipv4addr_param *v4;
375 struct sctp_ipv6addr_param *v6;
376 union sctp_addr_param *addr;
377 struct sctp_adaption_ind_param *aind;
378 };
379
380 /* RFC 2960. Section 3.3.5 Heartbeat.
381 * Heartbeat Information: variable length
382 * The Sender-specific Heartbeat Info field should normally include
383 * information about the sender's current time when this HEARTBEAT
384 * chunk is sent and the destination transport address to which this
385 * HEARTBEAT is sent (see Section 8.3).
386 */
387 typedef struct sctp_sender_hb_info {
388 struct sctp_paramhdr param_hdr;
389 union sctp_addr daddr;
390 unsigned long sent_at;
391 } __attribute__((packed)) sctp_sender_hb_info_t;
392
393 /*
394 * RFC 2960 1.3.2 Sequenced Delivery within Streams
395 *
396 * The term "stream" is used in SCTP to refer to a sequence of user
397 * messages that are to be delivered to the upper-layer protocol in
398 * order with respect to other messages within the same stream. This is
399 * in contrast to its usage in TCP, where it refers to a sequence of
400 * bytes (in this document a byte is assumed to be eight bits).
401 * ...
402 *
403 * This is the structure we use to track both our outbound and inbound
404 * SSN, or Stream Sequence Numbers.
405 */
406
407 struct sctp_stream {
408 __u16 *ssn;
409 unsigned int len;
410 };
411
412 struct sctp_ssnmap {
413 struct sctp_stream in;
414 struct sctp_stream out;
415 int malloced;
416 };
417
418 struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out, int gfp);
419 void sctp_ssnmap_free(struct sctp_ssnmap *map);
420 void sctp_ssnmap_clear(struct sctp_ssnmap *map);
421
422 /* What is the current SSN number for this stream? */
sctp_ssn_peek(struct sctp_stream * stream,__u16 id)423 static inline __u16 sctp_ssn_peek(struct sctp_stream *stream, __u16 id)
424 {
425 return stream->ssn[id];
426 }
427
428 /* Return the next SSN number for this stream. */
sctp_ssn_next(struct sctp_stream * stream,__u16 id)429 static inline __u16 sctp_ssn_next(struct sctp_stream *stream, __u16 id)
430 {
431 return stream->ssn[id]++;
432 }
433
434 /* Skip over this ssn and all below. */
sctp_ssn_skip(struct sctp_stream * stream,__u16 id,__u16 ssn)435 static inline void sctp_ssn_skip(struct sctp_stream *stream, __u16 id,
436 __u16 ssn)
437 {
438 stream->ssn[id] = ssn+1;
439 }
440
441 /*
442 * Pointers to address related SCTP functions.
443 * (i.e. things that depend on the address family.)
444 */
445 struct sctp_af {
446 int (*sctp_xmit) (struct sk_buff *skb,
447 struct sctp_transport *,
448 int ipfragok);
449 int (*setsockopt) (struct sock *sk,
450 int level,
451 int optname,
452 char *optval,
453 int optlen);
454 int (*getsockopt) (struct sock *sk,
455 int level,
456 int optname,
457 char *optval,
458 int *optlen);
459 struct dst_entry *(*get_dst) (struct sctp_association *asoc,
460 union sctp_addr *daddr,
461 union sctp_addr *saddr);
462 void (*get_saddr) (struct sctp_association *asoc,
463 struct dst_entry *dst,
464 union sctp_addr *daddr,
465 union sctp_addr *saddr);
466 void (*copy_addrlist) (struct list_head *,
467 struct net_device *);
468 void (*dst_saddr) (union sctp_addr *saddr,
469 struct dst_entry *dst,
470 unsigned short port);
471 int (*cmp_addr) (const union sctp_addr *addr1,
472 const union sctp_addr *addr2);
473 void (*addr_copy) (union sctp_addr *dst,
474 union sctp_addr *src);
475 void (*from_skb) (union sctp_addr *,
476 struct sk_buff *skb,
477 int saddr);
478 void (*from_sk) (union sctp_addr *,
479 struct sock *sk);
480 void (*to_sk_saddr) (union sctp_addr *,
481 struct sock *sk);
482 void (*to_sk_daddr) (union sctp_addr *,
483 struct sock *sk);
484 void (*from_addr_param) (union sctp_addr *,
485 union sctp_addr_param *,
486 __u16 port, int iif);
487 int (*to_addr_param) (const union sctp_addr *,
488 union sctp_addr_param *);
489 int (*addr_valid) (union sctp_addr *,
490 struct sctp_opt *);
491 sctp_scope_t (*scope) (union sctp_addr *);
492 void (*inaddr_any) (union sctp_addr *, unsigned short);
493 int (*is_any) (const union sctp_addr *);
494 int (*available) (union sctp_addr *,
495 struct sctp_opt *);
496 int (*skb_iif) (const struct sk_buff *sk);
497 int (*is_ce) (const struct sk_buff *sk);
498 void (*seq_dump_addr)(struct seq_file *seq,
499 union sctp_addr *addr);
500 __u16 net_header_len;
501 int sockaddr_len;
502 sa_family_t sa_family;
503 struct list_head list;
504 };
505
506 struct sctp_af *sctp_get_af_specific(sa_family_t);
507 int sctp_register_af(struct sctp_af *);
508
509 /* Protocol family functions. */
510 struct sctp_pf {
511 void (*event_msgname)(struct sctp_ulpevent *, char *, int *);
512 void (*skb_msgname) (struct sk_buff *, char *, int *);
513 int (*af_supported) (sa_family_t, struct sctp_opt *);
514 int (*cmp_addr) (const union sctp_addr *,
515 const union sctp_addr *,
516 struct sctp_opt *);
517 int (*bind_verify) (struct sctp_opt *, union sctp_addr *);
518 int (*send_verify) (struct sctp_opt *, union sctp_addr *);
519 int (*supported_addrs)(const struct sctp_opt *, __u16 *);
520 struct sock *(*create_accept_sk) (struct sock *sk,
521 struct sctp_association *asoc);
522 void (*addr_v4map) (struct sctp_opt *, union sctp_addr *);
523 struct sctp_af *af;
524 };
525
526
527 /* Structure to track chunk fragments that have been acked, but peer
528 * fragments of the same message have not.
529 */
530 struct sctp_datamsg {
531 /* Chunks waiting to be submitted to lower layer. */
532 struct list_head chunks;
533 /* Chunks that have been transmitted. */
534 struct list_head track;
535 /* Reference counting. */
536 atomic_t refcnt;
537 /* When is this message no longer interesting to the peer? */
538 unsigned long expires_at;
539 /* Did the messenge fail to send? */
540 int send_error;
541 char send_failed;
542 /* Control whether chunks from this message can be abandoned. */
543 char can_abandon;
544 };
545
546 struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *,
547 struct sctp_sndrcvinfo *,
548 struct msghdr *, int len);
549 void sctp_datamsg_put(struct sctp_datamsg *);
550 void sctp_datamsg_free(struct sctp_datamsg *);
551 void sctp_datamsg_track(struct sctp_chunk *);
552 void sctp_chunk_fail(struct sctp_chunk *, int error);
553 int sctp_chunk_abandoned(struct sctp_chunk *);
554
555
556 /* RFC2960 1.4 Key Terms
557 *
558 * o Chunk: A unit of information within an SCTP packet, consisting of
559 * a chunk header and chunk-specific content.
560 *
561 * As a matter of convenience, we remember the SCTP common header for
562 * each chunk as well as a few other header pointers...
563 */
564 struct sctp_chunk {
565 /* These first three elements MUST PRECISELY match the first
566 * three elements of struct sk_buff. This allows us to reuse
567 * all the skb_* queue management functions.
568 */
569 struct sctp_chunk *next;
570 struct sctp_chunk *prev;
571 struct sk_buff_head *list;
572 atomic_t refcnt;
573
574 /* This is our link to the per-transport transmitted list. */
575 struct list_head transmitted_list;
576
577 /* This field is used by chunks that hold fragmented data.
578 * For the first fragment this is the list that holds the rest of
579 * fragments. For the remaining fragments, this is the link to the
580 * frag_list maintained in the first fragment.
581 */
582 struct list_head frag_list;
583
584 /* This points to the sk_buff containing the actual data. */
585 struct sk_buff *skb;
586
587 /* These are the SCTP headers by reverse order in a packet.
588 * Note that some of these may happen more than once. In that
589 * case, we point at the "current" one, whatever that means
590 * for that level of header.
591 */
592
593 /* We point this at the FIRST TLV parameter to chunk_hdr. */
594 union sctp_params param_hdr;
595 union {
596 __u8 *v;
597 struct sctp_datahdr *data_hdr;
598 struct sctp_inithdr *init_hdr;
599 struct sctp_sackhdr *sack_hdr;
600 struct sctp_heartbeathdr *hb_hdr;
601 struct sctp_sender_hb_info *hbs_hdr;
602 struct sctp_shutdownhdr *shutdown_hdr;
603 struct sctp_signed_cookie *cookie_hdr;
604 struct sctp_ecnehdr *ecne_hdr;
605 struct sctp_cwrhdr *ecn_cwr_hdr;
606 struct sctp_errhdr *err_hdr;
607 struct sctp_addiphdr *addip_hdr;
608 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
609 } subh;
610
611 __u8 *chunk_end;
612
613 struct sctp_chunkhdr *chunk_hdr;
614 struct sctphdr *sctp_hdr;
615
616 /* This needs to be recoverable for SCTP_SEND_FAILED events. */
617 struct sctp_sndrcvinfo sinfo;
618
619 /* Which association does this belong to? */
620 struct sctp_association *asoc;
621
622 /* What endpoint received this chunk? */
623 struct sctp_ep_common *rcvr;
624
625 /* We fill this in if we are calculating RTT. */
626 unsigned long sent_at;
627
628 /* What is the origin IP address for this chunk? */
629 union sctp_addr source;
630 /* Destination address for this chunk. */
631 union sctp_addr dest;
632
633 /* For outbound message, track all fragments for SEND_FAILED. */
634 struct sctp_datamsg *msg;
635
636 /* For an inbound chunk, this tells us where it came from.
637 * For an outbound chunk, it tells us where we'd like it to
638 * go. It is NULL if we have no preference.
639 */
640 struct sctp_transport *transport;
641
642 __u8 rtt_in_progress; /* Is this chunk used for RTT calculation? */
643 __u8 resent; /* Has this chunk ever been retransmitted. */
644 __u8 has_tsn; /* Does this chunk have a TSN yet? */
645 __u8 has_ssn; /* Does this chunk have a SSN yet? */
646 __u8 singleton; /* Was this the only chunk in the packet? */
647 __u8 end_of_packet; /* Was this the last chunk in the packet? */
648 __u8 ecn_ce_done; /* Have we processed the ECN CE bit? */
649 __u8 pdiscard; /* Discard the whole packet now? */
650 __u8 tsn_gap_acked; /* Is this chunk acked by a GAP ACK? */
651 __u8 fast_retransmit; /* Is this chunk fast retransmitted? */
652 __u8 tsn_missing_report; /* Data chunk missing counter. */
653 };
654
655 void sctp_chunk_hold(struct sctp_chunk *);
656 void sctp_chunk_put(struct sctp_chunk *);
657 int sctp_user_addto_chunk(struct sctp_chunk *chunk, int off, int len,
658 struct iovec *data);
659 void sctp_chunk_free(struct sctp_chunk *);
660 void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data);
661 struct sctp_chunk *sctp_chunkify(struct sk_buff *,
662 const struct sctp_association *,
663 struct sock *);
664 void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
665 union sctp_addr *);
666 const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);
667
668 /* This is a structure for holding either an IPv6 or an IPv4 address. */
669 /* sin_family -- AF_INET or AF_INET6
670 * sin_port -- ordinary port number
671 * sin_addr -- cast to either (struct in_addr) or (struct in6_addr)
672 */
673 struct sctp_sockaddr_entry {
674 struct list_head list;
675 union sctp_addr a;
676 };
677
678 typedef struct sctp_chunk *(sctp_packet_phandler_t)(struct sctp_association *);
679
680 /* This structure holds lists of chunks as we are assembling for
681 * transmission.
682 */
683 struct sctp_packet {
684 /* These are the SCTP header values (host order) for the packet. */
685 __u16 source_port;
686 __u16 destination_port;
687 __u32 vtag;
688
689 /* This contains the payload chunks. */
690 struct sk_buff_head chunks;
691
692 /* This is the overhead of the sctp and ip headers. */
693 size_t overhead;
694 /* This is the total size of all chunks INCLUDING padding. */
695 size_t size;
696
697 /* The packet is destined for this transport address.
698 * The function we finally use to pass down to the next lower
699 * layer lives in the transport structure.
700 */
701 struct sctp_transport *transport;
702
703 /* This packet contains a COOKIE-ECHO chunk. */
704 char has_cookie_echo;
705
706 /* This packet containsa SACK chunk. */
707 char has_sack;
708
709 /* SCTP cannot fragment this packet. So let ip fragment it. */
710 char ipfragok;
711
712 int malloced;
713 };
714
715 struct sctp_packet *sctp_packet_init(struct sctp_packet *,
716 struct sctp_transport *,
717 __u16 sport, __u16 dport);
718 struct sctp_packet *sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
719 sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *,
720 struct sctp_chunk *);
721 sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *,
722 struct sctp_chunk *);
723 int sctp_packet_transmit(struct sctp_packet *);
724 void sctp_packet_free(struct sctp_packet *);
725
sctp_packet_empty(struct sctp_packet * packet)726 static inline int sctp_packet_empty(struct sctp_packet *packet)
727 {
728 return (packet->size == packet->overhead);
729 }
730
731 /* This represents a remote transport address.
732 * For local transport addresses, we just use union sctp_addr.
733 *
734 * RFC2960 Section 1.4 Key Terms
735 *
736 * o Transport address: A Transport Address is traditionally defined
737 * by Network Layer address, Transport Layer protocol and Transport
738 * Layer port number. In the case of SCTP running over IP, a
739 * transport address is defined by the combination of an IP address
740 * and an SCTP port number (where SCTP is the Transport protocol).
741 *
742 * RFC2960 Section 7.1 SCTP Differences from TCP Congestion control
743 *
744 * o The sender keeps a separate congestion control parameter set for
745 * each of the destination addresses it can send to (not each
746 * source-destination pair but for each destination). The parameters
747 * should decay if the address is not used for a long enough time
748 * period.
749 *
750 */
751 struct sctp_transport {
752 /* A list of transports. */
753 struct list_head transports;
754
755 /* Reference counting. */
756 atomic_t refcnt;
757 int dead;
758
759 /* This is the peer's IP address and port. */
760 union sctp_addr ipaddr;
761
762 /* These are the functions we call to handle LLP stuff. */
763 struct sctp_af *af_specific;
764
765 /* Which association do we belong to? */
766 struct sctp_association *asoc;
767
768 /* RFC2960
769 *
770 * 12.3 Per Transport Address Data
771 *
772 * For each destination transport address in the peer's
773 * address list derived from the INIT or INIT ACK chunk, a
774 * number of data elements needs to be maintained including:
775 */
776 __u32 rtt; /* This is the most recent RTT. */
777
778 /* RTO : The current retransmission timeout value. */
779 __u32 rto;
780
781 /* RTTVAR : The current RTT variation. */
782 __u32 rttvar;
783
784 /* SRTT : The current smoothed round trip time. */
785 __u32 srtt;
786
787 /* RTO-Pending : A flag used to track if one of the DATA
788 * chunks sent to this address is currently being
789 * used to compute a RTT. If this flag is 0,
790 * the next DATA chunk sent to this destination
791 * should be used to compute a RTT and this flag
792 * should be set. Every time the RTT
793 * calculation completes (i.e. the DATA chunk
794 * is SACK'd) clear this flag.
795 */
796 int rto_pending;
797
798 /*
799 * These are the congestion stats.
800 */
801 /* cwnd : The current congestion window. */
802 __u32 cwnd; /* This is the actual cwnd. */
803
804 /* ssthresh : The current slow start threshold value. */
805 __u32 ssthresh;
806
807 /* partial : The tracking method for increase of cwnd when in
808 * bytes acked : congestion avoidance mode (see Section 6.2.2)
809 */
810 __u32 partial_bytes_acked;
811
812 /* Data that has been sent, but not acknowledged. */
813 __u32 flight_size;
814
815 /* PMTU : The current known path MTU. */
816 __u32 pmtu;
817
818 /* Destination */
819 struct dst_entry *dst;
820 /* Source address. */
821 union sctp_addr saddr;
822
823 /* When was the last time(in jiffies) that a data packet was sent on
824 * this transport? This is used to adjust the cwnd when the transport
825 * becomes inactive.
826 */
827 unsigned long last_time_used;
828
829 /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
830 * the destination address every heartbeat interval.
831 */
832 int hb_interval;
833
834 /* When was the last time (in jiffies) that we heard from this
835 * transport? We use this to pick new active and retran paths.
836 */
837 unsigned long last_time_heard;
838
839 /* Last time(in jiffies) when cwnd is reduced due to the congestion
840 * indication based on ECNE chunk.
841 */
842 unsigned long last_time_ecne_reduced;
843
844 /* active : The current active state of this destination,
845 * : i.e. DOWN, UP, etc.
846 */
847 int active;
848
849 /* hb_allowed : The current heartbeat state of this destination,
850 * : i.e. ALLOW-HB, NO-HEARTBEAT, etc.
851 */
852 int hb_allowed;
853
854 /* These are the error stats for this destination. */
855
856 /* Error count : The current error count for this destination. */
857 unsigned short error_count;
858
859 /* This is the max_retrans value for the transport and will
860 * be initialized to proto.max_retrans.path. This can be changed
861 * using SCTP_SET_PEER_ADDR_PARAMS socket option.
862 */
863 int max_retrans;
864
865 /* Per : A timer used by each destination.
866 * Destination :
867 * Timer :
868 *
869 * [Everywhere else in the text this is called T3-rtx. -ed]
870 */
871 struct timer_list T3_rtx_timer;
872
873 /* Heartbeat timer is per destination. */
874 struct timer_list hb_timer;
875
876 /* Since we're using per-destination retransmission timers
877 * (see above), we're also using per-destination "transmitted"
878 * queues. This probably ought to be a private struct
879 * accessible only within the outqueue, but it's not, yet.
880 */
881 struct list_head transmitted;
882
883 /* We build bundle-able packets for this transport here. */
884 struct sctp_packet packet;
885
886 /* This is the list of transports that have chunks to send. */
887 struct list_head send_ready;
888
889 int malloced; /* Is this structure kfree()able? */
890
891 /* State information saved for SFR_CACC algorithm. The key
892 * idea in SFR_CACC is to maintain state at the sender on a
893 * per-destination basis when a changeover happens.
894 * char changeover_active;
895 * char cycling_changeover;
896 * __u32 next_tsn_at_change;
897 * char cacc_saw_newack;
898 */
899 struct {
900 /* An unsigned integer, which stores the next TSN to be
901 * used by the sender, at the moment of changeover.
902 */
903 __u32 next_tsn_at_change;
904
905 /* A flag which indicates the occurrence of a changeover */
906 char changeover_active;
907
908 /* A flag which indicates whether the change of primary is
909 * the first switch to this destination address during an
910 * active switch.
911 */
912 char cycling_changeover;
913
914 /* A temporary flag, which is used during the processing of
915 * a SACK to estimate the causative TSN(s)'s group.
916 */
917 char cacc_saw_newack;
918 } cacc;
919 };
920
921 struct sctp_transport *sctp_transport_new(const union sctp_addr *, int);
922 void sctp_transport_set_owner(struct sctp_transport *,
923 struct sctp_association *);
924 void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
925 struct sctp_opt *);
926 void sctp_transport_pmtu(struct sctp_transport *);
927 void sctp_transport_free(struct sctp_transport *);
928 void sctp_transport_reset_timers(struct sctp_transport *);
929 void sctp_transport_hold(struct sctp_transport *);
930 void sctp_transport_put(struct sctp_transport *);
931 void sctp_transport_update_rto(struct sctp_transport *, __u32);
932 void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32);
933 void sctp_transport_lower_cwnd(struct sctp_transport *, sctp_lower_cwnd_t);
934 unsigned long sctp_transport_timeout(struct sctp_transport *);
935
936
937 /* This is the structure we use to queue packets as they come into
938 * SCTP. We write packets to it and read chunks from it.
939 */
940 struct sctp_inq {
941 /* This is actually a queue of sctp_chunk each
942 * containing a partially decoded packet.
943 */
944 struct sk_buff_head in;
945 /* This is the packet which is currently off the in queue and is
946 * being worked on through the inbound chunk processing.
947 */
948 struct sctp_chunk *in_progress;
949
950 /* This is the delayed task to finish delivering inbound
951 * messages.
952 */
953 struct tq_struct immediate;
954
955 int malloced; /* Is this structure kfree()able? */
956 };
957
958 void sctp_inq_init(struct sctp_inq *);
959 void sctp_inq_free(struct sctp_inq *);
960 void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet);
961 struct sctp_chunk *sctp_inq_pop(struct sctp_inq *);
962 void sctp_inq_set_th_handler(struct sctp_inq *, void (*)(void *), void *);
963
964 /* This is the structure we use to hold outbound chunks. You push
965 * chunks in and they automatically pop out the other end as bundled
966 * packets (it calls (*output_handler)()).
967 *
968 * This structure covers sections 6.3, 6.4, 6.7, 6.8, 6.10, 7., 8.1,
969 * and 8.2 of the v13 draft.
970 *
971 * It handles retransmissions. The connection to the timeout portion
972 * of the state machine is through sctp_..._timeout() and timeout_handler.
973 *
974 * If you feed it SACKs, it will eat them.
975 *
976 * If you give it big chunks, it will fragment them.
977 *
978 * It assigns TSN's to data chunks. This happens at the last possible
979 * instant before transmission.
980 *
981 * When free()'d, it empties itself out via output_handler().
982 */
983 struct sctp_outq {
984 struct sctp_association *asoc;
985
986 /* Data pending that has never been transmitted. */
987 struct sk_buff_head out;
988
989 unsigned out_qlen; /* Total length of queued data chunks. */
990
991 /* Error of send failed, may used in SCTP_SEND_FAILED event. */
992 unsigned error;
993
994 /* These are control chunks we want to send. */
995 struct sk_buff_head control;
996
997 /* These are chunks that have been sacked but are above the
998 * CTSN, or cumulative tsn ack point.
999 */
1000 struct list_head sacked;
1001
1002 /* Put chunks on this list to schedule them for
1003 * retransmission.
1004 */
1005 struct list_head retransmit;
1006
1007 /* Put chunks on this list to save them for FWD TSN processing as
1008 * they were abandoned.
1009 */
1010 struct list_head abandoned;
1011
1012 /* How many unackd bytes do we have in-flight? */
1013 __u32 outstanding_bytes;
1014
1015 /* Corked? */
1016 char cork;
1017
1018 /* Is this structure empty? */
1019 char empty;
1020
1021 /* Are we kfree()able? */
1022 char malloced;
1023 };
1024
1025 void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
1026 void sctp_outq_teardown(struct sctp_outq *);
1027 void sctp_outq_free(struct sctp_outq*);
1028 int sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk);
1029 int sctp_outq_flush(struct sctp_outq *, int);
1030 int sctp_outq_sack(struct sctp_outq *, struct sctp_sackhdr *);
1031 int sctp_outq_is_empty(const struct sctp_outq *);
1032 void sctp_outq_restart(struct sctp_outq *);
1033
1034 void sctp_retransmit(struct sctp_outq *, struct sctp_transport *,
1035 sctp_retransmit_reason_t);
1036 void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
1037 int sctp_outq_uncork(struct sctp_outq *);
1038 /* Uncork and flush an outqueue. */
sctp_outq_cork(struct sctp_outq * q)1039 static inline void sctp_outq_cork(struct sctp_outq *q)
1040 {
1041 q->cork = 1;
1042 }
1043
1044 /* These bind address data fields common between endpoints and associations */
1045 struct sctp_bind_addr {
1046
1047 /* RFC 2960 12.1 Parameters necessary for the SCTP instance
1048 *
1049 * SCTP Port: The local SCTP port number the endpoint is
1050 * bound to.
1051 */
1052 __u16 port;
1053
1054 /* RFC 2960 12.1 Parameters necessary for the SCTP instance
1055 *
1056 * Address List: The list of IP addresses that this instance
1057 * has bound. This information is passed to one's
1058 * peer(s) in INIT and INIT ACK chunks.
1059 */
1060 struct list_head address_list;
1061
1062 int malloced; /* Are we kfree()able? */
1063 };
1064
1065 void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
1066 void sctp_bind_addr_free(struct sctp_bind_addr *);
1067 int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
1068 const struct sctp_bind_addr *src,
1069 sctp_scope_t scope, int gfp,int flags);
1070 int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
1071 int gfp);
1072 int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
1073 int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *,
1074 struct sctp_opt *);
1075 union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
1076 const union sctp_addr *addrs,
1077 int addrcnt,
1078 struct sctp_opt *opt);
1079 union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
1080 int *addrs_len, int gfp);
1081 int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
1082 __u16 port, int gfp);
1083
1084 sctp_scope_t sctp_scope(const union sctp_addr *);
1085 int sctp_in_scope(const union sctp_addr *addr, const sctp_scope_t scope);
1086 int sctp_is_any(const union sctp_addr *addr);
1087 int sctp_addr_is_valid(const union sctp_addr *addr);
1088
1089
1090 /* What type of endpoint? */
1091 typedef enum {
1092 SCTP_EP_TYPE_SOCKET,
1093 SCTP_EP_TYPE_ASSOCIATION,
1094 } sctp_endpoint_type_t;
1095
1096 /*
1097 * A common base class to bridge the implmentation view of a
1098 * socket (usually listening) endpoint versus an association's
1099 * local endpoint.
1100 * This common structure is useful for several purposes:
1101 * 1) Common interface for lookup routines.
1102 * a) Subfunctions work for either endpoint or association
1103 * b) Single interface to lookup allows hiding the lookup lock rather
1104 * than acquiring it externally.
1105 * 2) Common interface for the inbound chunk handling/state machine.
1106 * 3) Common object handling routines for reference counting, etc.
1107 * 4) Disentangle association lookup from endpoint lookup, where we
1108 * do not have to find our endpoint to find our association.
1109 *
1110 */
1111
1112 struct sctp_ep_common {
1113 /* Fields to help us manage our entries in the hash tables. */
1114 struct sctp_ep_common *next;
1115 struct sctp_ep_common **pprev;
1116 int hashent;
1117
1118 /* Runtime type information. What kind of endpoint is this? */
1119 sctp_endpoint_type_t type;
1120
1121 /* Some fields to help us manage this object.
1122 * refcnt - Reference count access to this object.
1123 * dead - Do not attempt to use this object.
1124 * malloced - Do we need to kfree this object?
1125 */
1126 atomic_t refcnt;
1127 char dead;
1128 char malloced;
1129
1130 /* What socket does this endpoint belong to? */
1131 struct sock *sk;
1132
1133 /* This is where we receive inbound chunks. */
1134 struct sctp_inq inqueue;
1135
1136 /* This substructure includes the defining parameters of the
1137 * endpoint:
1138 * bind_addr.port is our shared port number.
1139 * bind_addr.address_list is our set of local IP addresses.
1140 */
1141 struct sctp_bind_addr bind_addr;
1142
1143 /* Protection during address list comparisons. */
1144 rwlock_t addr_lock;
1145 };
1146
1147
1148 /* RFC Section 1.4 Key Terms
1149 *
1150 * o SCTP endpoint: The logical sender/receiver of SCTP packets. On a
1151 * multi-homed host, an SCTP endpoint is represented to its peers as a
1152 * combination of a set of eligible destination transport addresses to
1153 * which SCTP packets can be sent and a set of eligible source
1154 * transport addresses from which SCTP packets can be received.
1155 * All transport addresses used by an SCTP endpoint must use the
1156 * same port number, but can use multiple IP addresses. A transport
1157 * address used by an SCTP endpoint must not be used by another
1158 * SCTP endpoint. In other words, a transport address is unique
1159 * to an SCTP endpoint.
1160 *
1161 * From an implementation perspective, each socket has one of these.
1162 * A TCP-style socket will have exactly one association on one of
1163 * these. An UDP-style socket will have multiple associations hanging
1164 * off one of these.
1165 */
1166
1167 struct sctp_endpoint {
1168 /* Common substructure for endpoint and association. */
1169 struct sctp_ep_common base;
1170
1171 /* Associations: A list of current associations and mappings
1172 * to the data consumers for each association. This
1173 * may be in the form of a hash table or other
1174 * implementation dependent structure. The data
1175 * consumers may be process identification
1176 * information such as file descriptors, named pipe
1177 * pointer, or table pointers dependent on how SCTP
1178 * is implemented.
1179 */
1180 /* This is really a list of struct sctp_association entries. */
1181 struct list_head asocs;
1182
1183 /* Secret Key: A secret key used by this endpoint to compute
1184 * the MAC. This SHOULD be a cryptographic quality
1185 * random number with a sufficient length.
1186 * Discussion in [RFC1750] can be helpful in
1187 * selection of the key.
1188 */
1189 __u8 secret_key[SCTP_HOW_MANY_SECRETS][SCTP_SECRET_SIZE];
1190 int current_key;
1191 int last_key;
1192 int key_changed_at;
1193
1194 /* Default timeouts. */
1195 int timeouts[SCTP_NUM_TIMEOUT_TYPES];
1196
1197 /* Various thresholds. */
1198
1199 /* Name for debugging output... */
1200 char *debug_name;
1201 };
1202
1203 /* Recover the outter endpoint structure. */
sctp_ep(struct sctp_ep_common * base)1204 static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base)
1205 {
1206 struct sctp_endpoint *ep;
1207
1208 ep = container_of(base, struct sctp_endpoint, base);
1209 return ep;
1210 }
1211
1212 /* These are function signatures for manipulating endpoints. */
1213 struct sctp_endpoint *sctp_endpoint_new(struct sock *, int);
1214 void sctp_endpoint_free(struct sctp_endpoint *);
1215 void sctp_endpoint_put(struct sctp_endpoint *);
1216 void sctp_endpoint_hold(struct sctp_endpoint *);
1217 void sctp_endpoint_add_asoc(struct sctp_endpoint *, struct sctp_association *);
1218 struct sctp_association *sctp_endpoint_lookup_assoc(
1219 const struct sctp_endpoint *ep,
1220 const union sctp_addr *paddr,
1221 struct sctp_transport **);
1222 int sctp_endpoint_is_peeled_off(struct sctp_endpoint *,
1223 const union sctp_addr *);
1224 struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *,
1225 const union sctp_addr *);
1226 int sctp_has_association(const union sctp_addr *laddr,
1227 const union sctp_addr *paddr);
1228
1229 int sctp_verify_init(const struct sctp_association *asoc, sctp_cid_t,
1230 sctp_init_chunk_t *peer_init, struct sctp_chunk *chunk,
1231 struct sctp_chunk **err_chunk);
1232 int sctp_process_init(struct sctp_association *, sctp_cid_t cid,
1233 const union sctp_addr *peer,
1234 sctp_init_chunk_t *init, int gfp);
1235 __u32 sctp_generate_tag(const struct sctp_endpoint *);
1236 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
1237
1238
1239 /* RFC2960
1240 *
1241 * 12. Recommended Transmission Control Block (TCB) Parameters
1242 *
1243 * This section details a recommended set of parameters that should
1244 * be contained within the TCB for an implementation. This section is
1245 * for illustrative purposes and should not be deemed as requirements
1246 * on an implementation or as an exhaustive list of all parameters
1247 * inside an SCTP TCB. Each implementation may need its own additional
1248 * parameters for optimization.
1249 */
1250
1251
1252 /* Here we have information about each individual association. */
1253 struct sctp_association {
1254
1255 /* A base structure common to endpoint and association.
1256 * In this context, it represents the associations's view
1257 * of the local endpoint of the association.
1258 */
1259 struct sctp_ep_common base;
1260
1261 /* Associations on the same socket. */
1262 struct list_head asocs;
1263
1264 /* This is a signature that lets us know that this is a
1265 * struct sctp_association data structure. Used for mapping an
1266 * association id to an association.
1267 */
1268 __u32 eyecatcher;
1269
1270 /* This is our parent endpoint. */
1271 struct sctp_endpoint *ep;
1272
1273 /* These are those association elements needed in the cookie. */
1274 struct sctp_cookie c;
1275
1276 /* This is all information about our peer. */
1277 struct {
1278 /* rwnd
1279 *
1280 * Peer Rwnd : Current calculated value of the peer's rwnd.
1281 */
1282 __u32 rwnd;
1283
1284 /* transport_addr_list
1285 *
1286 * Peer : A list of SCTP transport addresses that the
1287 * Transport : peer is bound to. This information is derived
1288 * Address : from the INIT or INIT ACK and is used to
1289 * List : associate an inbound packet with a given
1290 * : association. Normally this information is
1291 * : hashed or keyed for quick lookup and access
1292 * : of the TCB.
1293 *
1294 * It is a list of SCTP_transport's.
1295 */
1296 struct list_head transport_addr_list;
1297
1298 /* port
1299 * The transport layer port number.
1300 */
1301 __u16 port;
1302
1303 /* primary_path
1304 *
1305 * Primary : This is the current primary destination
1306 * Path : transport address of the peer endpoint. It
1307 * : may also specify a source transport address
1308 * : on this endpoint.
1309 *
1310 * All of these paths live on transport_addr_list.
1311 *
1312 * At the bakeoffs, we discovered that the intent of
1313 * primaryPath is that it only changes when the ULP
1314 * asks to have it changed. We add the activePath to
1315 * designate the connection we are currently using to
1316 * transmit new data and most control chunks.
1317 */
1318 struct sctp_transport *primary_path;
1319
1320 /* Cache the primary path address here, when we
1321 * need a an address for msg_name.
1322 */
1323 union sctp_addr primary_addr;
1324
1325 /* active_path
1326 * The path that we are currently using to
1327 * transmit new data and most control chunks.
1328 */
1329 struct sctp_transport *active_path;
1330
1331 /* retran_path
1332 *
1333 * RFC2960 6.4 Multi-homed SCTP Endpoints
1334 * ...
1335 * Furthermore, when its peer is multi-homed, an
1336 * endpoint SHOULD try to retransmit a chunk to an
1337 * active destination transport address that is
1338 * different from the last destination address to
1339 * which the DATA chunk was sent.
1340 */
1341 struct sctp_transport *retran_path;
1342
1343 /* Pointer to last transport I have sent on. */
1344 struct sctp_transport *last_sent_to;
1345
1346 /* This is the last transport I have received DATA on. */
1347 struct sctp_transport *last_data_from;
1348
1349 /*
1350 * Mapping An array of bits or bytes indicating which out of
1351 * Array order TSN's have been received (relative to the
1352 * Last Rcvd TSN). If no gaps exist, i.e. no out of
1353 * order packets have been received, this array
1354 * will be set to all zero. This structure may be
1355 * in the form of a circular buffer or bit array.
1356 *
1357 * Last Rcvd : This is the last TSN received in
1358 * TSN : sequence. This value is set initially by
1359 * : taking the peer's Initial TSN, received in
1360 * : the INIT or INIT ACK chunk, and subtracting
1361 * : one from it.
1362 *
1363 * Throughout most of the specification this is called the
1364 * "Cumulative TSN ACK Point". In this case, we
1365 * ignore the advice in 12.2 in favour of the term
1366 * used in the bulk of the text. This value is hidden
1367 * in tsn_map--we get it by calling sctp_tsnmap_get_ctsn().
1368 */
1369 struct sctp_tsnmap tsn_map;
1370 __u8 _map[sctp_tsnmap_storage_size(SCTP_TSN_MAP_SIZE)];
1371
1372 /* Ack State : This flag indicates if the next received
1373 * : packet is to be responded to with a
1374 * : SACK. This is initializedto 0. When a packet
1375 * : is received it is incremented. If this value
1376 * : reaches 2 or more, a SACK is sent and the
1377 * : value is reset to 0. Note: This is used only
1378 * : when no DATA chunks are received out of
1379 * : order. When DATA chunks are out of order,
1380 * : SACK's are not delayed (see Section 6).
1381 */
1382 __u8 sack_needed; /* Do we need to sack the peer? */
1383
1384 /* These are capabilities which our peer advertised. */
1385 __u8 ecn_capable; /* Can peer do ECN? */
1386 __u8 ipv4_address; /* Peer understands IPv4 addresses? */
1387 __u8 ipv6_address; /* Peer understands IPv6 addresses? */
1388 __u8 hostname_address;/* Peer understands DNS addresses? */
1389 __u8 asconf_capable; /* Does peer support ADDIP? */
1390 __u8 prsctp_capable; /* Can peer do PR-SCTP? */
1391
1392 __u32 adaption_ind; /* Adaption Code point. */
1393
1394 /* This mask is used to disable sending the ASCONF chunk
1395 * with specified parameter to peer.
1396 */
1397 __u16 addip_disabled_mask;
1398
1399 struct sctp_inithdr i;
1400 int cookie_len;
1401 void *cookie;
1402
1403 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
1404 * C1) ... "Peer-Serial-Number'. This value MUST be initialized to the
1405 * Initial TSN Value minus 1
1406 */
1407 __u32 addip_serial;
1408 } peer;
1409
1410 /* State : A state variable indicating what state the
1411 * : association is in, i.e. COOKIE-WAIT,
1412 * : COOKIE-ECHOED, ESTABLISHED, SHUTDOWN-PENDING,
1413 * : SHUTDOWN-SENT, SHUTDOWN-RECEIVED, SHUTDOWN-ACK-SENT.
1414 *
1415 * Note: No "CLOSED" state is illustrated since if a
1416 * association is "CLOSED" its TCB SHOULD be removed.
1417 *
1418 * In this implementation we DO have a CLOSED
1419 * state which is used during initiation and shutdown.
1420 *
1421 * State takes values from SCTP_STATE_*.
1422 */
1423 sctp_state_t state;
1424
1425 /* The cookie life I award for any cookie. */
1426 struct timeval cookie_life;
1427
1428 /* Overall : The overall association error count.
1429 * Error Count : [Clear this any time I get something.]
1430 */
1431 int overall_error_count;
1432
1433 /* These are the association's initial, max, and min RTO values.
1434 * These values will be initialized by system defaults, but can
1435 * be modified via the SCTP_RTOINFO socket option.
1436 */
1437 __u32 rto_initial;
1438 __u32 rto_max;
1439 __u32 rto_min;
1440
1441 /* Maximum number of new data packets that can be sent in a burst. */
1442 int max_burst;
1443
1444 /* This is the max_retrans value for the association. This value will
1445 * be initialized initialized from system defaults, but can be
1446 * modified by the SCTP_ASSOCINFO socket option.
1447 */
1448 int max_retrans;
1449
1450 /* Maximum number of times the endpoint will retransmit INIT */
1451 __u16 max_init_attempts;
1452
1453 /* How many times have we resent an INIT? */
1454 __u16 init_retries;
1455
1456 /* The largest timeout or RTO value to use in attempting an INIT */
1457 __u16 max_init_timeo;
1458
1459 int timeouts[SCTP_NUM_TIMEOUT_TYPES];
1460 struct timer_list timers[SCTP_NUM_TIMEOUT_TYPES];
1461
1462 /* Transport to which SHUTDOWN chunk was last sent. */
1463 struct sctp_transport *shutdown_last_sent_to;
1464
1465 /* Next TSN : The next TSN number to be assigned to a new
1466 * : DATA chunk. This is sent in the INIT or INIT
1467 * : ACK chunk to the peer and incremented each
1468 * : time a DATA chunk is assigned a TSN
1469 * : (normally just prior to transmit or during
1470 * : fragmentation).
1471 */
1472 __u32 next_tsn;
1473
1474 /*
1475 * Last Rcvd : This is the last TSN received in sequence. This value
1476 * TSN : is set initially by taking the peer's Initial TSN,
1477 * : received in the INIT or INIT ACK chunk, and
1478 * : subtracting one from it.
1479 *
1480 * Most of RFC 2960 refers to this as the Cumulative TSN Ack Point.
1481 */
1482
1483 __u32 ctsn_ack_point;
1484
1485 /* PR-SCTP Advanced.Peer.Ack.Point */
1486 __u32 adv_peer_ack_point;
1487
1488 /* Highest TSN that is acknowledged by incoming SACKs. */
1489 __u32 highest_sacked;
1490
1491 /* The number of unacknowledged data chunks. Reported through
1492 * the SCTP_STATUS sockopt.
1493 */
1494 __u16 unack_data;
1495
1496 /* This is the association's receive buffer space. This value is used
1497 * to set a_rwnd field in an INIT or a SACK chunk.
1498 */
1499 __u32 rwnd;
1500
1501 /* This is the last advertised value of rwnd over a SACK chunk. */
1502 __u32 a_rwnd;
1503
1504 /* Number of bytes by which the rwnd has slopped. The rwnd is allowed
1505 * to slop over a maximum of the association's frag_point.
1506 */
1507 __u32 rwnd_over;
1508
1509 /* This is the sndbuf size in use for the association.
1510 * This corresponds to the sndbuf size for the association,
1511 * as specified in the sk->sndbuf.
1512 */
1513 int sndbuf_used;
1514
1515 /* This is the wait queue head for send requests waiting on
1516 * the association sndbuf space.
1517 */
1518 wait_queue_head_t wait;
1519
1520 /* Association : The smallest PMTU discovered for all of the
1521 * PMTU : peer's transport addresses.
1522 */
1523 __u32 pmtu;
1524
1525 /* The message size at which SCTP fragmentation will occur. */
1526 __u32 frag_point;
1527
1528 /* Currently only one counter is used to count INIT errors. */
1529 int counters[SCTP_NUMBER_COUNTERS];
1530
1531 /* Default send parameters. */
1532 __u16 default_stream;
1533 __u16 default_flags;
1534 __u32 default_ppid;
1535 __u32 default_context;
1536 __u32 default_timetolive;
1537
1538 /* This tracks outbound ssn for a given stream. */
1539 struct sctp_ssnmap *ssnmap;
1540
1541 /* All outbound chunks go through this structure. */
1542 struct sctp_outq outqueue;
1543
1544 /* A smart pipe that will handle reordering and fragmentation,
1545 * as well as handle passing events up to the ULP.
1546 */
1547 struct sctp_ulpq ulpq;
1548
1549 /* Last TSN that caused an ECNE Chunk to be sent. */
1550 __u32 last_ecne_tsn;
1551
1552 /* Last TSN that caused a CWR Chunk to be sent. */
1553 __u32 last_cwr_tsn;
1554
1555 /* How many duplicated TSNs have we seen? */
1556 int numduptsns;
1557
1558 /* Number of seconds of idle time before an association is closed. */
1559 __u32 autoclose;
1560
1561 /* These are to support
1562 * "SCTP Extensions for Dynamic Reconfiguration of IP Addresses
1563 * and Enforcement of Flow and Message Limits"
1564 * <draft-ietf-tsvwg-addip-sctp-02.txt>
1565 * or "ADDIP" for short.
1566 */
1567
1568
1569
1570 /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
1571 *
1572 * R1) One and only one ASCONF Chunk MAY be in transit and
1573 * unacknowledged at any one time. If a sender, after sending
1574 * an ASCONF chunk, decides it needs to transfer another
1575 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
1576 * returns from the previous ASCONF Chunk before sending a
1577 * subsequent ASCONF. Note this restriction binds each side,
1578 * so at any time two ASCONF may be in-transit on any given
1579 * association (one sent from each endpoint).
1580 *
1581 * [This is our one-and-only-one ASCONF in flight. If we do
1582 * not have an ASCONF in flight, this is NULL.]
1583 */
1584 struct sctp_chunk *addip_last_asconf;
1585
1586 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
1587 *
1588 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
1589 * to save the last ASCONF-ACK for some predetermined period
1590 * of time and instead of re-processing the ASCONF (with the
1591 * same serial number) it may just re-transmit the
1592 * ASCONF-ACK. It may wish to use the arrival of a new serial
1593 * number to discard the previously saved ASCONF-ACK or any
1594 * other means it may choose to expire the saved ASCONF-ACK.
1595 *
1596 * [This is our saved ASCONF-ACK. We invalidate it when a new
1597 * ASCONF serial number arrives.]
1598 */
1599 struct sctp_chunk *addip_last_asconf_ack;
1600
1601 /* These ASCONF chunks are waiting to be sent.
1602 *
1603 * These chunaks can't be pushed to outqueue until receiving
1604 * ASCONF_ACK for the previous ASCONF indicated by
1605 * addip_last_asconf, so as to guarantee that only one ASCONF
1606 * is in flight at any time.
1607 *
1608 * ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
1609 *
1610 * In defining the ASCONF Chunk transfer procedures, it is
1611 * essential that these transfers MUST NOT cause congestion
1612 * within the network. To achieve this, we place these
1613 * restrictions on the transfer of ASCONF Chunks:
1614 *
1615 * R1) One and only one ASCONF Chunk MAY be in transit and
1616 * unacknowledged at any one time. If a sender, after sending
1617 * an ASCONF chunk, decides it needs to transfer another
1618 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
1619 * returns from the previous ASCONF Chunk before sending a
1620 * subsequent ASCONF. Note this restriction binds each side,
1621 * so at any time two ASCONF may be in-transit on any given
1622 * association (one sent from each endpoint).
1623 *
1624 *
1625 * [I really think this is EXACTLY the sort of intelligence
1626 * which already resides in sctp_outq. Please move this
1627 * queue and its supporting logic down there. --piggy]
1628 */
1629 struct sk_buff_head addip_chunks;
1630
1631 /* ADDIP Section 4.1 ASCONF Chunk Procedures
1632 *
1633 * A2) A serial number should be assigned to the Chunk. The
1634 * serial number SHOULD be a monotonically increasing
1635 * number. The serial number SHOULD be initialized at
1636 * the start of the association to the same value as the
1637 * Initial TSN and every time a new ASCONF chunk is created
1638 * it is incremented by one after assigning the serial number
1639 * to the newly created chunk.
1640 *
1641 * ADDIP
1642 * 3.1.1 Address/Stream Configuration Change Chunk (ASCONF)
1643 *
1644 * Serial Number : 32 bits (unsigned integer)
1645 *
1646 * This value represents a Serial Number for the ASCONF
1647 * Chunk. The valid range of Serial Number is from 0 to
1648 * 4294967295 (2^32 - 1). Serial Numbers wrap back to 0
1649 * after reaching 4294967295.
1650 */
1651 __u32 addip_serial;
1652
1653 /* Need to send an ECNE Chunk? */
1654 char need_ecne;
1655
1656 /* Is it a temporary association? */
1657 char temp;
1658 };
1659
1660
1661 /* An eyecatcher for determining if we are really looking at an
1662 * association data structure.
1663 */
1664 enum {
1665 SCTP_ASSOC_EYECATCHER = 0xa550c123,
1666 };
1667
1668 /* Recover the outter association structure. */
sctp_assoc(struct sctp_ep_common * base)1669 static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base)
1670 {
1671 struct sctp_association *asoc;
1672
1673 asoc = container_of(base, struct sctp_association, base);
1674 return asoc;
1675 }
1676
1677 /* These are function signatures for manipulating associations. */
1678
1679
1680 struct sctp_association *
1681 sctp_association_new(const struct sctp_endpoint *, const struct sock *,
1682 sctp_scope_t scope, int gfp);
1683 void sctp_association_free(struct sctp_association *);
1684 void sctp_association_put(struct sctp_association *);
1685 void sctp_association_hold(struct sctp_association *);
1686
1687 struct sctp_transport *sctp_assoc_choose_shutdown_transport(
1688 struct sctp_association *);
1689 void sctp_assoc_update_retran_path(struct sctp_association *);
1690 struct sctp_transport *sctp_assoc_lookup_paddr(const struct sctp_association *,
1691 const union sctp_addr *);
1692 int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
1693 const union sctp_addr *laddr);
1694 struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *,
1695 const union sctp_addr *address,
1696 const int gfp);
1697 void sctp_assoc_del_peer(struct sctp_association *asoc,
1698 const union sctp_addr *addr);
1699 void sctp_assoc_control_transport(struct sctp_association *,
1700 struct sctp_transport *,
1701 sctp_transport_cmd_t, sctp_sn_error_t);
1702 struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32);
1703 struct sctp_transport *sctp_assoc_is_match(struct sctp_association *,
1704 const union sctp_addr *,
1705 const union sctp_addr *);
1706 void sctp_assoc_migrate(struct sctp_association *, struct sock *);
1707 void sctp_assoc_update(struct sctp_association *old,
1708 struct sctp_association *new);
1709
1710 __u32 sctp_association_get_next_tsn(struct sctp_association *);
1711
1712 void sctp_assoc_sync_pmtu(struct sctp_association *);
1713 void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned);
1714 void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned);
1715 void sctp_assoc_set_primary(struct sctp_association *,
1716 struct sctp_transport *);
1717 int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *, int);
1718 int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *,
1719 struct sctp_cookie*, int gfp);
1720
1721 int sctp_cmp_addr_exact(const union sctp_addr *ss1,
1722 const union sctp_addr *ss2);
1723 struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc);
1724
1725 /* A convenience structure to parse out SCTP specific CMSGs. */
1726 typedef struct sctp_cmsgs {
1727 struct sctp_initmsg *init;
1728 struct sctp_sndrcvinfo *info;
1729 } sctp_cmsgs_t;
1730
1731 /* Structure for tracking memory objects */
1732 typedef struct {
1733 char *label;
1734 atomic_t *counter;
1735 } sctp_dbg_objcnt_entry_t;
1736
1737 #endif /* __sctp_structs_h__ */
1738