Commit 7c3ceb4fb9667f34f1599a062efecf4cdc4a4ce5

Authored by Neil Horman
Committed by David S. Miller
1 parent 91ef5d2d6e

[SCTP]: Allow spillover of receive buffer to avoid deadlock.

This patch fixes a deadlock situation in the receive path by allowing
temporary spillover of the receive buffer.

- If the chunk we receive has a tsn that immediately follows the ctsn,
  accept it even if we run out of receive buffer space and renege data with
  higher TSNs.
- Once we accept one chunk in a packet, accept all the remaining chunks
  even if we run out of receive buffer space.

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Mark Butler <butlerm@middle.net>
Acked-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: Sridhar Samudrala <sri@us.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 3 changed files with 38 additions and 10 deletions Inline Diff

include/net/sctp/structs.h
1 /* SCTP kernel reference Implementation 1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004 2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc. 3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc. 4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001 Intel Corp. 5 * Copyright (c) 2001 Intel Corp.
6 * 6 *
7 * This file is part of the SCTP kernel reference Implementation 7 * This file is part of the SCTP kernel reference Implementation
8 * 8 *
9 * The SCTP reference implementation is free software; 9 * The SCTP reference implementation is free software;
10 * you can redistribute it and/or modify it under the terms of 10 * you can redistribute it and/or modify it under the terms of
11 * the GNU General Public License as published by 11 * the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option) 12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version. 13 * any later version.
14 * 14 *
15 * The SCTP reference implementation is distributed in the hope that it 15 * The SCTP reference implementation is distributed in the hope that it
16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied 16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * ************************ 17 * ************************
18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details. 19 * See the GNU General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU General Public License 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 22 * along with GNU CC; see the file COPYING. If not, write to
23 * the Free Software Foundation, 59 Temple Place - Suite 330, 23 * the Free Software Foundation, 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA. 24 * Boston, MA 02111-1307, USA.
25 * 25 *
26 * Please send any bug reports or fixes you make to the 26 * Please send any bug reports or fixes you make to the
27 * email addresses: 27 * email addresses:
28 * lksctp developers <lksctp-developers@lists.sourceforge.net> 28 * lksctp developers <lksctp-developers@lists.sourceforge.net>
29 * 29 *
30 * Or submit a bug report through the following website: 30 * Or submit a bug report through the following website:
31 * http://www.sf.net/projects/lksctp 31 * http://www.sf.net/projects/lksctp
32 * 32 *
33 * Written or modified by: 33 * Written or modified by:
34 * Randall Stewart <randall@sctp.chicago.il.us> 34 * Randall Stewart <randall@sctp.chicago.il.us>
35 * Ken Morneau <kmorneau@cisco.com> 35 * Ken Morneau <kmorneau@cisco.com>
36 * Qiaobing Xie <qxie1@email.mot.com> 36 * Qiaobing Xie <qxie1@email.mot.com>
37 * La Monte H.P. Yarroll <piggy@acm.org> 37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us> 38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Jon Grimm <jgrimm@us.ibm.com> 39 * Jon Grimm <jgrimm@us.ibm.com>
40 * Xingang Guo <xingang.guo@intel.com> 40 * Xingang Guo <xingang.guo@intel.com>
41 * Hui Huang <hui.huang@nokia.com> 41 * Hui Huang <hui.huang@nokia.com>
42 * Sridhar Samudrala <sri@us.ibm.com> 42 * Sridhar Samudrala <sri@us.ibm.com>
43 * Daisy Chang <daisyc@us.ibm.com> 43 * Daisy Chang <daisyc@us.ibm.com>
44 * Dajiang Zhang <dajiang.zhang@nokia.com> 44 * Dajiang Zhang <dajiang.zhang@nokia.com>
45 * Ardelle Fan <ardelle.fan@intel.com> 45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Ryan Layer <rmlayer@us.ibm.com> 46 * Ryan Layer <rmlayer@us.ibm.com>
47 * Anup Pemmaiah <pemmaiah@cc.usu.edu> 47 * Anup Pemmaiah <pemmaiah@cc.usu.edu>
48 * Kevin Gao <kevin.gao@intel.com> 48 * Kevin Gao <kevin.gao@intel.com>
49 * 49 *
50 * Any bugs reported given to us we will try to fix... any fixes shared will 50 * Any bugs reported given to us we will try to fix... any fixes shared will
51 * be incorporated into the next SCTP release. 51 * be incorporated into the next SCTP release.
52 */ 52 */
53 53
54 #ifndef __sctp_structs_h__ 54 #ifndef __sctp_structs_h__
55 #define __sctp_structs_h__ 55 #define __sctp_structs_h__
56 56
57 #include <linux/time.h> /* We get struct timespec. */ 57 #include <linux/time.h> /* We get struct timespec. */
58 #include <linux/socket.h> /* linux/in.h needs this!! */ 58 #include <linux/socket.h> /* linux/in.h needs this!! */
59 #include <linux/in.h> /* We get struct sockaddr_in. */ 59 #include <linux/in.h> /* We get struct sockaddr_in. */
60 #include <linux/in6.h> /* We get struct in6_addr */ 60 #include <linux/in6.h> /* We get struct in6_addr */
61 #include <linux/ipv6.h> 61 #include <linux/ipv6.h>
62 #include <asm/param.h> /* We get MAXHOSTNAMELEN. */ 62 #include <asm/param.h> /* We get MAXHOSTNAMELEN. */
63 #include <asm/atomic.h> /* This gets us atomic counters. */ 63 #include <asm/atomic.h> /* This gets us atomic counters. */
64 #include <linux/skbuff.h> /* We need sk_buff_head. */ 64 #include <linux/skbuff.h> /* We need sk_buff_head. */
65 #include <linux/workqueue.h> /* We need tq_struct. */ 65 #include <linux/workqueue.h> /* We need tq_struct. */
66 #include <linux/sctp.h> /* We need sctp* header structs. */ 66 #include <linux/sctp.h> /* We need sctp* header structs. */
67 67
68 /* A convenience structure for handling sockaddr structures. 68 /* A convenience structure for handling sockaddr structures.
69 * We should wean ourselves off this. 69 * We should wean ourselves off this.
70 */ 70 */
71 union sctp_addr { 71 union sctp_addr {
72 struct sockaddr_in v4; 72 struct sockaddr_in v4;
73 struct sockaddr_in6 v6; 73 struct sockaddr_in6 v6;
74 struct sockaddr sa; 74 struct sockaddr sa;
75 }; 75 };
76 76
77 /* Forward declarations for data structures. */ 77 /* Forward declarations for data structures. */
78 struct sctp_globals; 78 struct sctp_globals;
79 struct sctp_endpoint; 79 struct sctp_endpoint;
80 struct sctp_association; 80 struct sctp_association;
81 struct sctp_transport; 81 struct sctp_transport;
82 struct sctp_packet; 82 struct sctp_packet;
83 struct sctp_chunk; 83 struct sctp_chunk;
84 struct sctp_inq; 84 struct sctp_inq;
85 struct sctp_outq; 85 struct sctp_outq;
86 struct sctp_bind_addr; 86 struct sctp_bind_addr;
87 struct sctp_ulpq; 87 struct sctp_ulpq;
88 struct sctp_ep_common; 88 struct sctp_ep_common;
89 struct sctp_ssnmap; 89 struct sctp_ssnmap;
90 90
91 91
92 #include <net/sctp/tsnmap.h> 92 #include <net/sctp/tsnmap.h>
93 #include <net/sctp/ulpevent.h> 93 #include <net/sctp/ulpevent.h>
94 #include <net/sctp/ulpqueue.h> 94 #include <net/sctp/ulpqueue.h>
95 95
96 /* Structures useful for managing bind/connect. */ 96 /* Structures useful for managing bind/connect. */
97 97
98 struct sctp_bind_bucket { 98 struct sctp_bind_bucket {
99 unsigned short port; 99 unsigned short port;
100 unsigned short fastreuse; 100 unsigned short fastreuse;
101 struct sctp_bind_bucket *next; 101 struct sctp_bind_bucket *next;
102 struct sctp_bind_bucket **pprev; 102 struct sctp_bind_bucket **pprev;
103 struct hlist_head owner; 103 struct hlist_head owner;
104 }; 104 };
105 105
106 struct sctp_bind_hashbucket { 106 struct sctp_bind_hashbucket {
107 spinlock_t lock; 107 spinlock_t lock;
108 struct sctp_bind_bucket *chain; 108 struct sctp_bind_bucket *chain;
109 }; 109 };
110 110
111 /* Used for hashing all associations. */ 111 /* Used for hashing all associations. */
112 struct sctp_hashbucket { 112 struct sctp_hashbucket {
113 rwlock_t lock; 113 rwlock_t lock;
114 struct sctp_ep_common *chain; 114 struct sctp_ep_common *chain;
115 } __attribute__((__aligned__(8))); 115 } __attribute__((__aligned__(8)));
116 116
117 117
118 /* The SCTP globals structure. */ 118 /* The SCTP globals structure. */
119 extern struct sctp_globals { 119 extern struct sctp_globals {
120 /* RFC2960 Section 14. Suggested SCTP Protocol Parameter Values 120 /* RFC2960 Section 14. Suggested SCTP Protocol Parameter Values
121 * 121 *
122 * The following protocol parameters are RECOMMENDED: 122 * The following protocol parameters are RECOMMENDED:
123 * 123 *
124 * RTO.Initial - 3 seconds 124 * RTO.Initial - 3 seconds
125 * RTO.Min - 1 second 125 * RTO.Min - 1 second
126 * RTO.Max - 60 seconds 126 * RTO.Max - 60 seconds
127 * RTO.Alpha - 1/8 (3 when converted to right shifts.) 127 * RTO.Alpha - 1/8 (3 when converted to right shifts.)
128 * RTO.Beta - 1/4 (2 when converted to right shifts.) 128 * RTO.Beta - 1/4 (2 when converted to right shifts.)
129 */ 129 */
130 unsigned long rto_initial; 130 unsigned long rto_initial;
131 unsigned long rto_min; 131 unsigned long rto_min;
132 unsigned long rto_max; 132 unsigned long rto_max;
133 133
134 /* Note: rto_alpha and rto_beta are really defined as inverse 134 /* Note: rto_alpha and rto_beta are really defined as inverse
135 * powers of two to facilitate integer operations. 135 * powers of two to facilitate integer operations.
136 */ 136 */
137 int rto_alpha; 137 int rto_alpha;
138 int rto_beta; 138 int rto_beta;
139 139
140 /* Max.Burst - 4 */ 140 /* Max.Burst - 4 */
141 int max_burst; 141 int max_burst;
142 142
143 /* Whether Cookie Preservative is enabled(1) or not(0) */ 143 /* Whether Cookie Preservative is enabled(1) or not(0) */
144 int cookie_preserve_enable; 144 int cookie_preserve_enable;
145 145
146 /* Valid.Cookie.Life - 60 seconds */ 146 /* Valid.Cookie.Life - 60 seconds */
147 unsigned long valid_cookie_life; 147 unsigned long valid_cookie_life;
148 148
149 /* Delayed SACK timeout 200ms default*/ 149 /* Delayed SACK timeout 200ms default*/
150 unsigned long sack_timeout; 150 unsigned long sack_timeout;
151 151
152 /* HB.interval - 30 seconds */ 152 /* HB.interval - 30 seconds */
153 unsigned long hb_interval; 153 unsigned long hb_interval;
154 154
155 /* Association.Max.Retrans - 10 attempts 155 /* Association.Max.Retrans - 10 attempts
156 * Path.Max.Retrans - 5 attempts (per destination address) 156 * Path.Max.Retrans - 5 attempts (per destination address)
157 * Max.Init.Retransmits - 8 attempts 157 * Max.Init.Retransmits - 8 attempts
158 */ 158 */
159 int max_retrans_association; 159 int max_retrans_association;
160 int max_retrans_path; 160 int max_retrans_path;
161 int max_retrans_init; 161 int max_retrans_init;
162 162
163 /* 163 /*
164 * Policy for preforming sctp/socket accounting 164 * Policy for preforming sctp/socket accounting
165 * 0 - do socket level accounting, all assocs share sk_sndbuf 165 * 0 - do socket level accounting, all assocs share sk_sndbuf
166 * 1 - do sctp accounting, each asoc may use sk_sndbuf bytes 166 * 1 - do sctp accounting, each asoc may use sk_sndbuf bytes
167 */ 167 */
168 int sndbuf_policy; 168 int sndbuf_policy;
169 169
170 /* 170 /*
171 * Policy for preforming sctp/socket accounting 171 * Policy for preforming sctp/socket accounting
172 * 0 - do socket level accounting, all assocs share sk_rcvbuf 172 * 0 - do socket level accounting, all assocs share sk_rcvbuf
173 * 1 - do sctp accounting, each asoc may use sk_rcvbuf bytes 173 * 1 - do sctp accounting, each asoc may use sk_rcvbuf bytes
174 */ 174 */
175 int rcvbuf_policy; 175 int rcvbuf_policy;
176 176
177 /* The following variables are implementation specific. */ 177 /* The following variables are implementation specific. */
178 178
179 /* Default initialization values to be applied to new associations. */ 179 /* Default initialization values to be applied to new associations. */
180 __u16 max_instreams; 180 __u16 max_instreams;
181 __u16 max_outstreams; 181 __u16 max_outstreams;
182 182
183 /* This is a list of groups of functions for each address 183 /* This is a list of groups of functions for each address
184 * family that we support. 184 * family that we support.
185 */ 185 */
186 struct list_head address_families; 186 struct list_head address_families;
187 187
188 /* This is the hash of all endpoints. */ 188 /* This is the hash of all endpoints. */
189 int ep_hashsize; 189 int ep_hashsize;
190 struct sctp_hashbucket *ep_hashtable; 190 struct sctp_hashbucket *ep_hashtable;
191 191
192 /* This is the hash of all associations. */ 192 /* This is the hash of all associations. */
193 int assoc_hashsize; 193 int assoc_hashsize;
194 struct sctp_hashbucket *assoc_hashtable; 194 struct sctp_hashbucket *assoc_hashtable;
195 195
196 /* This is the sctp port control hash. */ 196 /* This is the sctp port control hash. */
197 int port_hashsize; 197 int port_hashsize;
198 int port_rover; 198 int port_rover;
199 spinlock_t port_alloc_lock; /* Protects port_rover. */ 199 spinlock_t port_alloc_lock; /* Protects port_rover. */
200 struct sctp_bind_hashbucket *port_hashtable; 200 struct sctp_bind_hashbucket *port_hashtable;
201 201
202 /* This is the global local address list. 202 /* This is the global local address list.
203 * We actively maintain this complete list of interfaces on 203 * We actively maintain this complete list of interfaces on
204 * the system by catching routing events. 204 * the system by catching routing events.
205 * 205 *
206 * It is a list of sctp_sockaddr_entry. 206 * It is a list of sctp_sockaddr_entry.
207 */ 207 */
208 struct list_head local_addr_list; 208 struct list_head local_addr_list;
209 spinlock_t local_addr_lock; 209 spinlock_t local_addr_lock;
210 210
211 /* Flag to indicate if addip is enabled. */ 211 /* Flag to indicate if addip is enabled. */
212 int addip_enable; 212 int addip_enable;
213 213
214 /* Flag to indicate if PR-SCTP is enabled. */ 214 /* Flag to indicate if PR-SCTP is enabled. */
215 int prsctp_enable; 215 int prsctp_enable;
216 } sctp_globals; 216 } sctp_globals;
217 217
218 #define sctp_rto_initial (sctp_globals.rto_initial) 218 #define sctp_rto_initial (sctp_globals.rto_initial)
219 #define sctp_rto_min (sctp_globals.rto_min) 219 #define sctp_rto_min (sctp_globals.rto_min)
220 #define sctp_rto_max (sctp_globals.rto_max) 220 #define sctp_rto_max (sctp_globals.rto_max)
221 #define sctp_rto_alpha (sctp_globals.rto_alpha) 221 #define sctp_rto_alpha (sctp_globals.rto_alpha)
222 #define sctp_rto_beta (sctp_globals.rto_beta) 222 #define sctp_rto_beta (sctp_globals.rto_beta)
223 #define sctp_max_burst (sctp_globals.max_burst) 223 #define sctp_max_burst (sctp_globals.max_burst)
224 #define sctp_valid_cookie_life (sctp_globals.valid_cookie_life) 224 #define sctp_valid_cookie_life (sctp_globals.valid_cookie_life)
225 #define sctp_cookie_preserve_enable (sctp_globals.cookie_preserve_enable) 225 #define sctp_cookie_preserve_enable (sctp_globals.cookie_preserve_enable)
226 #define sctp_max_retrans_association (sctp_globals.max_retrans_association) 226 #define sctp_max_retrans_association (sctp_globals.max_retrans_association)
227 #define sctp_sndbuf_policy (sctp_globals.sndbuf_policy) 227 #define sctp_sndbuf_policy (sctp_globals.sndbuf_policy)
228 #define sctp_rcvbuf_policy (sctp_globals.rcvbuf_policy) 228 #define sctp_rcvbuf_policy (sctp_globals.rcvbuf_policy)
229 #define sctp_max_retrans_path (sctp_globals.max_retrans_path) 229 #define sctp_max_retrans_path (sctp_globals.max_retrans_path)
230 #define sctp_max_retrans_init (sctp_globals.max_retrans_init) 230 #define sctp_max_retrans_init (sctp_globals.max_retrans_init)
231 #define sctp_sack_timeout (sctp_globals.sack_timeout) 231 #define sctp_sack_timeout (sctp_globals.sack_timeout)
232 #define sctp_hb_interval (sctp_globals.hb_interval) 232 #define sctp_hb_interval (sctp_globals.hb_interval)
233 #define sctp_max_instreams (sctp_globals.max_instreams) 233 #define sctp_max_instreams (sctp_globals.max_instreams)
234 #define sctp_max_outstreams (sctp_globals.max_outstreams) 234 #define sctp_max_outstreams (sctp_globals.max_outstreams)
235 #define sctp_address_families (sctp_globals.address_families) 235 #define sctp_address_families (sctp_globals.address_families)
236 #define sctp_ep_hashsize (sctp_globals.ep_hashsize) 236 #define sctp_ep_hashsize (sctp_globals.ep_hashsize)
237 #define sctp_ep_hashtable (sctp_globals.ep_hashtable) 237 #define sctp_ep_hashtable (sctp_globals.ep_hashtable)
238 #define sctp_assoc_hashsize (sctp_globals.assoc_hashsize) 238 #define sctp_assoc_hashsize (sctp_globals.assoc_hashsize)
239 #define sctp_assoc_hashtable (sctp_globals.assoc_hashtable) 239 #define sctp_assoc_hashtable (sctp_globals.assoc_hashtable)
240 #define sctp_port_hashsize (sctp_globals.port_hashsize) 240 #define sctp_port_hashsize (sctp_globals.port_hashsize)
241 #define sctp_port_rover (sctp_globals.port_rover) 241 #define sctp_port_rover (sctp_globals.port_rover)
242 #define sctp_port_alloc_lock (sctp_globals.port_alloc_lock) 242 #define sctp_port_alloc_lock (sctp_globals.port_alloc_lock)
243 #define sctp_port_hashtable (sctp_globals.port_hashtable) 243 #define sctp_port_hashtable (sctp_globals.port_hashtable)
244 #define sctp_local_addr_list (sctp_globals.local_addr_list) 244 #define sctp_local_addr_list (sctp_globals.local_addr_list)
245 #define sctp_local_addr_lock (sctp_globals.local_addr_lock) 245 #define sctp_local_addr_lock (sctp_globals.local_addr_lock)
246 #define sctp_addip_enable (sctp_globals.addip_enable) 246 #define sctp_addip_enable (sctp_globals.addip_enable)
247 #define sctp_prsctp_enable (sctp_globals.prsctp_enable) 247 #define sctp_prsctp_enable (sctp_globals.prsctp_enable)
248 248
249 /* SCTP Socket type: UDP or TCP style. */ 249 /* SCTP Socket type: UDP or TCP style. */
250 typedef enum { 250 typedef enum {
251 SCTP_SOCKET_UDP = 0, 251 SCTP_SOCKET_UDP = 0,
252 SCTP_SOCKET_UDP_HIGH_BANDWIDTH, 252 SCTP_SOCKET_UDP_HIGH_BANDWIDTH,
253 SCTP_SOCKET_TCP 253 SCTP_SOCKET_TCP
254 } sctp_socket_type_t; 254 } sctp_socket_type_t;
255 255
256 /* Per socket SCTP information. */ 256 /* Per socket SCTP information. */
257 struct sctp_sock { 257 struct sctp_sock {
258 /* inet_sock has to be the first member of sctp_sock */ 258 /* inet_sock has to be the first member of sctp_sock */
259 struct inet_sock inet; 259 struct inet_sock inet;
260 /* What kind of a socket is this? */ 260 /* What kind of a socket is this? */
261 sctp_socket_type_t type; 261 sctp_socket_type_t type;
262 262
263 /* PF_ family specific functions. */ 263 /* PF_ family specific functions. */
264 struct sctp_pf *pf; 264 struct sctp_pf *pf;
265 265
266 /* Access to HMAC transform. */ 266 /* Access to HMAC transform. */
267 struct crypto_tfm *hmac; 267 struct crypto_tfm *hmac;
268 268
269 /* What is our base endpointer? */ 269 /* What is our base endpointer? */
270 struct sctp_endpoint *ep; 270 struct sctp_endpoint *ep;
271 271
272 struct sctp_bind_bucket *bind_hash; 272 struct sctp_bind_bucket *bind_hash;
273 /* Various Socket Options. */ 273 /* Various Socket Options. */
274 __u16 default_stream; 274 __u16 default_stream;
275 __u32 default_ppid; 275 __u32 default_ppid;
276 __u16 default_flags; 276 __u16 default_flags;
277 __u32 default_context; 277 __u32 default_context;
278 __u32 default_timetolive; 278 __u32 default_timetolive;
279 279
280 /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to 280 /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
281 * the destination address every heartbeat interval. This value 281 * the destination address every heartbeat interval. This value
282 * will be inherited by all new associations. 282 * will be inherited by all new associations.
283 */ 283 */
284 __u32 hbinterval; 284 __u32 hbinterval;
285 285
286 /* This is the max_retrans value for new associations. */ 286 /* This is the max_retrans value for new associations. */
287 __u16 pathmaxrxt; 287 __u16 pathmaxrxt;
288 288
289 /* The initial Path MTU to use for new associations. */ 289 /* The initial Path MTU to use for new associations. */
290 __u32 pathmtu; 290 __u32 pathmtu;
291 291
292 /* The default SACK delay timeout for new associations. */ 292 /* The default SACK delay timeout for new associations. */
293 __u32 sackdelay; 293 __u32 sackdelay;
294 294
295 /* Flags controling Heartbeat, SACK delay, and Path MTU Discovery. */ 295 /* Flags controling Heartbeat, SACK delay, and Path MTU Discovery. */
296 __u32 param_flags; 296 __u32 param_flags;
297 297
298 struct sctp_initmsg initmsg; 298 struct sctp_initmsg initmsg;
299 struct sctp_rtoinfo rtoinfo; 299 struct sctp_rtoinfo rtoinfo;
300 struct sctp_paddrparams paddrparam; 300 struct sctp_paddrparams paddrparam;
301 struct sctp_event_subscribe subscribe; 301 struct sctp_event_subscribe subscribe;
302 struct sctp_assocparams assocparams; 302 struct sctp_assocparams assocparams;
303 int user_frag; 303 int user_frag;
304 __u32 autoclose; 304 __u32 autoclose;
305 __u8 nodelay; 305 __u8 nodelay;
306 __u8 disable_fragments; 306 __u8 disable_fragments;
307 __u8 pd_mode; 307 __u8 pd_mode;
308 __u8 v4mapped; 308 __u8 v4mapped;
309 __u32 adaption_ind; 309 __u32 adaption_ind;
310 310
311 /* Receive to here while partial delivery is in effect. */ 311 /* Receive to here while partial delivery is in effect. */
312 struct sk_buff_head pd_lobby; 312 struct sk_buff_head pd_lobby;
313 }; 313 };
314 314
315 static inline struct sctp_sock *sctp_sk(const struct sock *sk) 315 static inline struct sctp_sock *sctp_sk(const struct sock *sk)
316 { 316 {
317 return (struct sctp_sock *)sk; 317 return (struct sctp_sock *)sk;
318 } 318 }
319 319
320 static inline struct sock *sctp_opt2sk(const struct sctp_sock *sp) 320 static inline struct sock *sctp_opt2sk(const struct sctp_sock *sp)
321 { 321 {
322 return (struct sock *)sp; 322 return (struct sock *)sp;
323 } 323 }
324 324
325 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 325 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
326 struct sctp6_sock { 326 struct sctp6_sock {
327 struct sctp_sock sctp; 327 struct sctp_sock sctp;
328 struct ipv6_pinfo inet6; 328 struct ipv6_pinfo inet6;
329 }; 329 };
330 #endif /* CONFIG_IPV6 */ 330 #endif /* CONFIG_IPV6 */
331 331
332 332
333 /* This is our APPLICATION-SPECIFIC state cookie. 333 /* This is our APPLICATION-SPECIFIC state cookie.
334 * THIS IS NOT DICTATED BY THE SPECIFICATION. 334 * THIS IS NOT DICTATED BY THE SPECIFICATION.
335 */ 335 */
336 /* These are the parts of an association which we send in the cookie. 336 /* These are the parts of an association which we send in the cookie.
337 * Most of these are straight out of: 337 * Most of these are straight out of:
338 * RFC2960 12.2 Parameters necessary per association (i.e. the TCB) 338 * RFC2960 12.2 Parameters necessary per association (i.e. the TCB)
339 * 339 *
340 */ 340 */
341 341
342 struct sctp_cookie { 342 struct sctp_cookie {
343 343
344 /* My : Tag expected in every inbound packet and sent 344 /* My : Tag expected in every inbound packet and sent
345 * Verification: in the INIT or INIT ACK chunk. 345 * Verification: in the INIT or INIT ACK chunk.
346 * Tag : 346 * Tag :
347 */ 347 */
348 __u32 my_vtag; 348 __u32 my_vtag;
349 349
350 /* Peer's : Tag expected in every outbound packet except 350 /* Peer's : Tag expected in every outbound packet except
351 * Verification: in the INIT chunk. 351 * Verification: in the INIT chunk.
352 * Tag : 352 * Tag :
353 */ 353 */
354 __u32 peer_vtag; 354 __u32 peer_vtag;
355 355
356 /* The rest of these are not from the spec, but really need to 356 /* The rest of these are not from the spec, but really need to
357 * be in the cookie. 357 * be in the cookie.
358 */ 358 */
359 359
360 /* My Tie Tag : Assist in discovering a restarting association. */ 360 /* My Tie Tag : Assist in discovering a restarting association. */
361 __u32 my_ttag; 361 __u32 my_ttag;
362 362
363 /* Peer's Tie Tag: Assist in discovering a restarting association. */ 363 /* Peer's Tie Tag: Assist in discovering a restarting association. */
364 __u32 peer_ttag; 364 __u32 peer_ttag;
365 365
366 /* When does this cookie expire? */ 366 /* When does this cookie expire? */
367 struct timeval expiration; 367 struct timeval expiration;
368 368
369 /* Number of inbound/outbound streams which are set 369 /* Number of inbound/outbound streams which are set
370 * and negotiated during the INIT process. 370 * and negotiated during the INIT process.
371 */ 371 */
372 __u16 sinit_num_ostreams; 372 __u16 sinit_num_ostreams;
373 __u16 sinit_max_instreams; 373 __u16 sinit_max_instreams;
374 374
375 /* This is the first sequence number I used. */ 375 /* This is the first sequence number I used. */
376 __u32 initial_tsn; 376 __u32 initial_tsn;
377 377
378 /* This holds the originating address of the INIT packet. */ 378 /* This holds the originating address of the INIT packet. */
379 union sctp_addr peer_addr; 379 union sctp_addr peer_addr;
380 380
381 /* IG Section 2.35.3 381 /* IG Section 2.35.3
382 * Include the source port of the INIT-ACK 382 * Include the source port of the INIT-ACK
383 */ 383 */
384 __u16 my_port; 384 __u16 my_port;
385 385
386 __u8 prsctp_capable; 386 __u8 prsctp_capable;
387 387
388 /* Padding for future use */ 388 /* Padding for future use */
389 __u8 padding; 389 __u8 padding;
390 390
391 __u32 adaption_ind; 391 __u32 adaption_ind;
392 392
393 393
394 /* This is a shim for my peer's INIT packet, followed by 394 /* This is a shim for my peer's INIT packet, followed by
395 * a copy of the raw address list of the association. 395 * a copy of the raw address list of the association.
396 * The length of the raw address list is saved in the 396 * The length of the raw address list is saved in the
397 * raw_addr_list_len field, which will be used at the time when 397 * raw_addr_list_len field, which will be used at the time when
398 * the association TCB is re-constructed from the cookie. 398 * the association TCB is re-constructed from the cookie.
399 */ 399 */
400 __u32 raw_addr_list_len; 400 __u32 raw_addr_list_len;
401 struct sctp_init_chunk peer_init[0]; 401 struct sctp_init_chunk peer_init[0];
402 }; 402 };
403 403
404 404
405 /* The format of our cookie that we send to our peer. */ 405 /* The format of our cookie that we send to our peer. */
406 struct sctp_signed_cookie { 406 struct sctp_signed_cookie {
407 __u8 signature[SCTP_SECRET_SIZE]; 407 __u8 signature[SCTP_SECRET_SIZE];
408 __u32 __pad; /* force sctp_cookie alignment to 64 bits */ 408 __u32 __pad; /* force sctp_cookie alignment to 64 bits */
409 struct sctp_cookie c; 409 struct sctp_cookie c;
410 } __attribute__((packed)); 410 } __attribute__((packed));
411 411
412 /* This is another convenience type to allocate memory for address 412 /* This is another convenience type to allocate memory for address
413 * params for the maximum size and pass such structures around 413 * params for the maximum size and pass such structures around
414 * internally. 414 * internally.
415 */ 415 */
416 union sctp_addr_param { 416 union sctp_addr_param {
417 struct sctp_ipv4addr_param v4; 417 struct sctp_ipv4addr_param v4;
418 struct sctp_ipv6addr_param v6; 418 struct sctp_ipv6addr_param v6;
419 }; 419 };
420 420
421 /* A convenience type to allow walking through the various 421 /* A convenience type to allow walking through the various
422 * parameters and avoid casting all over the place. 422 * parameters and avoid casting all over the place.
423 */ 423 */
424 union sctp_params { 424 union sctp_params {
425 void *v; 425 void *v;
426 struct sctp_paramhdr *p; 426 struct sctp_paramhdr *p;
427 struct sctp_cookie_preserve_param *life; 427 struct sctp_cookie_preserve_param *life;
428 struct sctp_hostname_param *dns; 428 struct sctp_hostname_param *dns;
429 struct sctp_cookie_param *cookie; 429 struct sctp_cookie_param *cookie;
430 struct sctp_supported_addrs_param *sat; 430 struct sctp_supported_addrs_param *sat;
431 struct sctp_ipv4addr_param *v4; 431 struct sctp_ipv4addr_param *v4;
432 struct sctp_ipv6addr_param *v6; 432 struct sctp_ipv6addr_param *v6;
433 union sctp_addr_param *addr; 433 union sctp_addr_param *addr;
434 struct sctp_adaption_ind_param *aind; 434 struct sctp_adaption_ind_param *aind;
435 }; 435 };
436 436
437 /* RFC 2960. Section 3.3.5 Heartbeat. 437 /* RFC 2960. Section 3.3.5 Heartbeat.
438 * Heartbeat Information: variable length 438 * Heartbeat Information: variable length
439 * The Sender-specific Heartbeat Info field should normally include 439 * The Sender-specific Heartbeat Info field should normally include
440 * information about the sender's current time when this HEARTBEAT 440 * information about the sender's current time when this HEARTBEAT
441 * chunk is sent and the destination transport address to which this 441 * chunk is sent and the destination transport address to which this
442 * HEARTBEAT is sent (see Section 8.3). 442 * HEARTBEAT is sent (see Section 8.3).
443 */ 443 */
444 typedef struct sctp_sender_hb_info { 444 typedef struct sctp_sender_hb_info {
445 struct sctp_paramhdr param_hdr; 445 struct sctp_paramhdr param_hdr;
446 union sctp_addr daddr; 446 union sctp_addr daddr;
447 unsigned long sent_at; 447 unsigned long sent_at;
448 } __attribute__((packed)) sctp_sender_hb_info_t; 448 } __attribute__((packed)) sctp_sender_hb_info_t;
449 449
450 /* 450 /*
451 * RFC 2960 1.3.2 Sequenced Delivery within Streams 451 * RFC 2960 1.3.2 Sequenced Delivery within Streams
452 * 452 *
453 * The term "stream" is used in SCTP to refer to a sequence of user 453 * The term "stream" is used in SCTP to refer to a sequence of user
454 * messages that are to be delivered to the upper-layer protocol in 454 * messages that are to be delivered to the upper-layer protocol in
455 * order with respect to other messages within the same stream. This is 455 * order with respect to other messages within the same stream. This is
456 * in contrast to its usage in TCP, where it refers to a sequence of 456 * in contrast to its usage in TCP, where it refers to a sequence of
457 * bytes (in this document a byte is assumed to be eight bits). 457 * bytes (in this document a byte is assumed to be eight bits).
458 * ... 458 * ...
459 * 459 *
460 * This is the structure we use to track both our outbound and inbound 460 * This is the structure we use to track both our outbound and inbound
461 * SSN, or Stream Sequence Numbers. 461 * SSN, or Stream Sequence Numbers.
462 */ 462 */
463 463
464 struct sctp_stream { 464 struct sctp_stream {
465 __u16 *ssn; 465 __u16 *ssn;
466 unsigned int len; 466 unsigned int len;
467 }; 467 };
468 468
469 struct sctp_ssnmap { 469 struct sctp_ssnmap {
470 struct sctp_stream in; 470 struct sctp_stream in;
471 struct sctp_stream out; 471 struct sctp_stream out;
472 int malloced; 472 int malloced;
473 }; 473 };
474 474
475 struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out, 475 struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
476 gfp_t gfp); 476 gfp_t gfp);
477 void sctp_ssnmap_free(struct sctp_ssnmap *map); 477 void sctp_ssnmap_free(struct sctp_ssnmap *map);
478 void sctp_ssnmap_clear(struct sctp_ssnmap *map); 478 void sctp_ssnmap_clear(struct sctp_ssnmap *map);
479 479
480 /* What is the current SSN number for this stream? */ 480 /* What is the current SSN number for this stream? */
481 static inline __u16 sctp_ssn_peek(struct sctp_stream *stream, __u16 id) 481 static inline __u16 sctp_ssn_peek(struct sctp_stream *stream, __u16 id)
482 { 482 {
483 return stream->ssn[id]; 483 return stream->ssn[id];
484 } 484 }
485 485
486 /* Return the next SSN number for this stream. */ 486 /* Return the next SSN number for this stream. */
487 static inline __u16 sctp_ssn_next(struct sctp_stream *stream, __u16 id) 487 static inline __u16 sctp_ssn_next(struct sctp_stream *stream, __u16 id)
488 { 488 {
489 return stream->ssn[id]++; 489 return stream->ssn[id]++;
490 } 490 }
491 491
492 /* Skip over this ssn and all below. */ 492 /* Skip over this ssn and all below. */
493 static inline void sctp_ssn_skip(struct sctp_stream *stream, __u16 id, 493 static inline void sctp_ssn_skip(struct sctp_stream *stream, __u16 id,
494 __u16 ssn) 494 __u16 ssn)
495 { 495 {
496 stream->ssn[id] = ssn+1; 496 stream->ssn[id] = ssn+1;
497 } 497 }
498 498
499 /* 499 /*
500 * Pointers to address related SCTP functions. 500 * Pointers to address related SCTP functions.
501 * (i.e. things that depend on the address family.) 501 * (i.e. things that depend on the address family.)
502 */ 502 */
503 struct sctp_af { 503 struct sctp_af {
504 int (*sctp_xmit) (struct sk_buff *skb, 504 int (*sctp_xmit) (struct sk_buff *skb,
505 struct sctp_transport *, 505 struct sctp_transport *,
506 int ipfragok); 506 int ipfragok);
507 int (*setsockopt) (struct sock *sk, 507 int (*setsockopt) (struct sock *sk,
508 int level, 508 int level,
509 int optname, 509 int optname,
510 char __user *optval, 510 char __user *optval,
511 int optlen); 511 int optlen);
512 int (*getsockopt) (struct sock *sk, 512 int (*getsockopt) (struct sock *sk,
513 int level, 513 int level,
514 int optname, 514 int optname,
515 char __user *optval, 515 char __user *optval,
516 int __user *optlen); 516 int __user *optlen);
517 int (*compat_setsockopt) (struct sock *sk, 517 int (*compat_setsockopt) (struct sock *sk,
518 int level, 518 int level,
519 int optname, 519 int optname,
520 char __user *optval, 520 char __user *optval,
521 int optlen); 521 int optlen);
522 int (*compat_getsockopt) (struct sock *sk, 522 int (*compat_getsockopt) (struct sock *sk,
523 int level, 523 int level,
524 int optname, 524 int optname,
525 char __user *optval, 525 char __user *optval,
526 int __user *optlen); 526 int __user *optlen);
527 struct dst_entry *(*get_dst) (struct sctp_association *asoc, 527 struct dst_entry *(*get_dst) (struct sctp_association *asoc,
528 union sctp_addr *daddr, 528 union sctp_addr *daddr,
529 union sctp_addr *saddr); 529 union sctp_addr *saddr);
530 void (*get_saddr) (struct sctp_association *asoc, 530 void (*get_saddr) (struct sctp_association *asoc,
531 struct dst_entry *dst, 531 struct dst_entry *dst,
532 union sctp_addr *daddr, 532 union sctp_addr *daddr,
533 union sctp_addr *saddr); 533 union sctp_addr *saddr);
534 void (*copy_addrlist) (struct list_head *, 534 void (*copy_addrlist) (struct list_head *,
535 struct net_device *); 535 struct net_device *);
536 void (*dst_saddr) (union sctp_addr *saddr, 536 void (*dst_saddr) (union sctp_addr *saddr,
537 struct dst_entry *dst, 537 struct dst_entry *dst,
538 unsigned short port); 538 unsigned short port);
539 int (*cmp_addr) (const union sctp_addr *addr1, 539 int (*cmp_addr) (const union sctp_addr *addr1,
540 const union sctp_addr *addr2); 540 const union sctp_addr *addr2);
541 void (*addr_copy) (union sctp_addr *dst, 541 void (*addr_copy) (union sctp_addr *dst,
542 union sctp_addr *src); 542 union sctp_addr *src);
543 void (*from_skb) (union sctp_addr *, 543 void (*from_skb) (union sctp_addr *,
544 struct sk_buff *skb, 544 struct sk_buff *skb,
545 int saddr); 545 int saddr);
546 void (*from_sk) (union sctp_addr *, 546 void (*from_sk) (union sctp_addr *,
547 struct sock *sk); 547 struct sock *sk);
548 void (*to_sk_saddr) (union sctp_addr *, 548 void (*to_sk_saddr) (union sctp_addr *,
549 struct sock *sk); 549 struct sock *sk);
550 void (*to_sk_daddr) (union sctp_addr *, 550 void (*to_sk_daddr) (union sctp_addr *,
551 struct sock *sk); 551 struct sock *sk);
552 void (*from_addr_param) (union sctp_addr *, 552 void (*from_addr_param) (union sctp_addr *,
553 union sctp_addr_param *, 553 union sctp_addr_param *,
554 __u16 port, int iif); 554 __u16 port, int iif);
555 int (*to_addr_param) (const union sctp_addr *, 555 int (*to_addr_param) (const union sctp_addr *,
556 union sctp_addr_param *); 556 union sctp_addr_param *);
557 int (*addr_valid) (union sctp_addr *, 557 int (*addr_valid) (union sctp_addr *,
558 struct sctp_sock *); 558 struct sctp_sock *);
559 sctp_scope_t (*scope) (union sctp_addr *); 559 sctp_scope_t (*scope) (union sctp_addr *);
560 void (*inaddr_any) (union sctp_addr *, unsigned short); 560 void (*inaddr_any) (union sctp_addr *, unsigned short);
561 int (*is_any) (const union sctp_addr *); 561 int (*is_any) (const union sctp_addr *);
562 int (*available) (union sctp_addr *, 562 int (*available) (union sctp_addr *,
563 struct sctp_sock *); 563 struct sctp_sock *);
564 int (*skb_iif) (const struct sk_buff *sk); 564 int (*skb_iif) (const struct sk_buff *sk);
565 int (*is_ce) (const struct sk_buff *sk); 565 int (*is_ce) (const struct sk_buff *sk);
566 void (*seq_dump_addr)(struct seq_file *seq, 566 void (*seq_dump_addr)(struct seq_file *seq,
567 union sctp_addr *addr); 567 union sctp_addr *addr);
568 __u16 net_header_len; 568 __u16 net_header_len;
569 int sockaddr_len; 569 int sockaddr_len;
570 sa_family_t sa_family; 570 sa_family_t sa_family;
571 struct list_head list; 571 struct list_head list;
572 }; 572 };
573 573
574 struct sctp_af *sctp_get_af_specific(sa_family_t); 574 struct sctp_af *sctp_get_af_specific(sa_family_t);
575 int sctp_register_af(struct sctp_af *); 575 int sctp_register_af(struct sctp_af *);
576 576
577 /* Protocol family functions. */ 577 /* Protocol family functions. */
578 struct sctp_pf { 578 struct sctp_pf {
579 void (*event_msgname)(struct sctp_ulpevent *, char *, int *); 579 void (*event_msgname)(struct sctp_ulpevent *, char *, int *);
580 void (*skb_msgname) (struct sk_buff *, char *, int *); 580 void (*skb_msgname) (struct sk_buff *, char *, int *);
581 int (*af_supported) (sa_family_t, struct sctp_sock *); 581 int (*af_supported) (sa_family_t, struct sctp_sock *);
582 int (*cmp_addr) (const union sctp_addr *, 582 int (*cmp_addr) (const union sctp_addr *,
583 const union sctp_addr *, 583 const union sctp_addr *,
584 struct sctp_sock *); 584 struct sctp_sock *);
585 int (*bind_verify) (struct sctp_sock *, union sctp_addr *); 585 int (*bind_verify) (struct sctp_sock *, union sctp_addr *);
586 int (*send_verify) (struct sctp_sock *, union sctp_addr *); 586 int (*send_verify) (struct sctp_sock *, union sctp_addr *);
587 int (*supported_addrs)(const struct sctp_sock *, __u16 *); 587 int (*supported_addrs)(const struct sctp_sock *, __u16 *);
588 struct sock *(*create_accept_sk) (struct sock *sk, 588 struct sock *(*create_accept_sk) (struct sock *sk,
589 struct sctp_association *asoc); 589 struct sctp_association *asoc);
590 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *); 590 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
591 struct sctp_af *af; 591 struct sctp_af *af;
592 }; 592 };
593 593
594 594
595 /* Structure to track chunk fragments that have been acked, but peer 595 /* Structure to track chunk fragments that have been acked, but peer
596 * fragments of the same message have not. 596 * fragments of the same message have not.
597 */ 597 */
598 struct sctp_datamsg { 598 struct sctp_datamsg {
599 /* Chunks waiting to be submitted to lower layer. */ 599 /* Chunks waiting to be submitted to lower layer. */
600 struct list_head chunks; 600 struct list_head chunks;
601 /* Chunks that have been transmitted. */ 601 /* Chunks that have been transmitted. */
602 struct list_head track; 602 struct list_head track;
603 /* Reference counting. */ 603 /* Reference counting. */
604 atomic_t refcnt; 604 atomic_t refcnt;
605 /* When is this message no longer interesting to the peer? */ 605 /* When is this message no longer interesting to the peer? */
606 unsigned long expires_at; 606 unsigned long expires_at;
607 /* Did the messenge fail to send? */ 607 /* Did the messenge fail to send? */
608 int send_error; 608 int send_error;
609 char send_failed; 609 char send_failed;
610 /* Control whether chunks from this message can be abandoned. */ 610 /* Control whether chunks from this message can be abandoned. */
611 char can_abandon; 611 char can_abandon;
612 }; 612 };
613 613
614 struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *, 614 struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *,
615 struct sctp_sndrcvinfo *, 615 struct sctp_sndrcvinfo *,
616 struct msghdr *, int len); 616 struct msghdr *, int len);
617 void sctp_datamsg_put(struct sctp_datamsg *); 617 void sctp_datamsg_put(struct sctp_datamsg *);
618 void sctp_datamsg_free(struct sctp_datamsg *); 618 void sctp_datamsg_free(struct sctp_datamsg *);
619 void sctp_datamsg_track(struct sctp_chunk *); 619 void sctp_datamsg_track(struct sctp_chunk *);
620 void sctp_chunk_fail(struct sctp_chunk *, int error); 620 void sctp_chunk_fail(struct sctp_chunk *, int error);
621 int sctp_chunk_abandoned(struct sctp_chunk *); 621 int sctp_chunk_abandoned(struct sctp_chunk *);
622 622
623 /* RFC2960 1.4 Key Terms 623 /* RFC2960 1.4 Key Terms
624 * 624 *
625 * o Chunk: A unit of information within an SCTP packet, consisting of 625 * o Chunk: A unit of information within an SCTP packet, consisting of
626 * a chunk header and chunk-specific content. 626 * a chunk header and chunk-specific content.
627 * 627 *
628 * As a matter of convenience, we remember the SCTP common header for 628 * As a matter of convenience, we remember the SCTP common header for
629 * each chunk as well as a few other header pointers... 629 * each chunk as well as a few other header pointers...
630 */ 630 */
631 struct sctp_chunk { 631 struct sctp_chunk {
632 struct list_head list; 632 struct list_head list;
633 633
634 atomic_t refcnt; 634 atomic_t refcnt;
635 635
636 /* This is our link to the per-transport transmitted list. */ 636 /* This is our link to the per-transport transmitted list. */
637 struct list_head transmitted_list; 637 struct list_head transmitted_list;
638 638
639 /* This field is used by chunks that hold fragmented data. 639 /* This field is used by chunks that hold fragmented data.
640 * For the first fragment this is the list that holds the rest of 640 * For the first fragment this is the list that holds the rest of
641 * fragments. For the remaining fragments, this is the link to the 641 * fragments. For the remaining fragments, this is the link to the
642 * frag_list maintained in the first fragment. 642 * frag_list maintained in the first fragment.
643 */ 643 */
644 struct list_head frag_list; 644 struct list_head frag_list;
645 645
646 /* This points to the sk_buff containing the actual data. */ 646 /* This points to the sk_buff containing the actual data. */
647 struct sk_buff *skb; 647 struct sk_buff *skb;
648 648
649 /* These are the SCTP headers by reverse order in a packet. 649 /* These are the SCTP headers by reverse order in a packet.
650 * Note that some of these may happen more than once. In that 650 * Note that some of these may happen more than once. In that
651 * case, we point at the "current" one, whatever that means 651 * case, we point at the "current" one, whatever that means
652 * for that level of header. 652 * for that level of header.
653 */ 653 */
654 654
655 /* We point this at the FIRST TLV parameter to chunk_hdr. */ 655 /* We point this at the FIRST TLV parameter to chunk_hdr. */
656 union sctp_params param_hdr; 656 union sctp_params param_hdr;
657 union { 657 union {
658 __u8 *v; 658 __u8 *v;
659 struct sctp_datahdr *data_hdr; 659 struct sctp_datahdr *data_hdr;
660 struct sctp_inithdr *init_hdr; 660 struct sctp_inithdr *init_hdr;
661 struct sctp_sackhdr *sack_hdr; 661 struct sctp_sackhdr *sack_hdr;
662 struct sctp_heartbeathdr *hb_hdr; 662 struct sctp_heartbeathdr *hb_hdr;
663 struct sctp_sender_hb_info *hbs_hdr; 663 struct sctp_sender_hb_info *hbs_hdr;
664 struct sctp_shutdownhdr *shutdown_hdr; 664 struct sctp_shutdownhdr *shutdown_hdr;
665 struct sctp_signed_cookie *cookie_hdr; 665 struct sctp_signed_cookie *cookie_hdr;
666 struct sctp_ecnehdr *ecne_hdr; 666 struct sctp_ecnehdr *ecne_hdr;
667 struct sctp_cwrhdr *ecn_cwr_hdr; 667 struct sctp_cwrhdr *ecn_cwr_hdr;
668 struct sctp_errhdr *err_hdr; 668 struct sctp_errhdr *err_hdr;
669 struct sctp_addiphdr *addip_hdr; 669 struct sctp_addiphdr *addip_hdr;
670 struct sctp_fwdtsn_hdr *fwdtsn_hdr; 670 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
671 } subh; 671 } subh;
672 672
673 __u8 *chunk_end; 673 __u8 *chunk_end;
674 674
675 struct sctp_chunkhdr *chunk_hdr; 675 struct sctp_chunkhdr *chunk_hdr;
676 struct sctphdr *sctp_hdr; 676 struct sctphdr *sctp_hdr;
677 677
678 /* This needs to be recoverable for SCTP_SEND_FAILED events. */ 678 /* This needs to be recoverable for SCTP_SEND_FAILED events. */
679 struct sctp_sndrcvinfo sinfo; 679 struct sctp_sndrcvinfo sinfo;
680 680
681 /* Which association does this belong to? */ 681 /* Which association does this belong to? */
682 struct sctp_association *asoc; 682 struct sctp_association *asoc;
683 683
684 /* What endpoint received this chunk? */ 684 /* What endpoint received this chunk? */
685 struct sctp_ep_common *rcvr; 685 struct sctp_ep_common *rcvr;
686 686
687 /* We fill this in if we are calculating RTT. */ 687 /* We fill this in if we are calculating RTT. */
688 unsigned long sent_at; 688 unsigned long sent_at;
689 689
690 /* What is the origin IP address for this chunk? */ 690 /* What is the origin IP address for this chunk? */
691 union sctp_addr source; 691 union sctp_addr source;
692 /* Destination address for this chunk. */ 692 /* Destination address for this chunk. */
693 union sctp_addr dest; 693 union sctp_addr dest;
694 694
695 /* For outbound message, track all fragments for SEND_FAILED. */ 695 /* For outbound message, track all fragments for SEND_FAILED. */
696 struct sctp_datamsg *msg; 696 struct sctp_datamsg *msg;
697 697
698 /* For an inbound chunk, this tells us where it came from. 698 /* For an inbound chunk, this tells us where it came from.
699 * For an outbound chunk, it tells us where we'd like it to 699 * For an outbound chunk, it tells us where we'd like it to
700 * go. It is NULL if we have no preference. 700 * go. It is NULL if we have no preference.
701 */ 701 */
702 struct sctp_transport *transport; 702 struct sctp_transport *transport;
703 703
704 __u8 rtt_in_progress; /* Is this chunk used for RTT calculation? */ 704 __u8 rtt_in_progress; /* Is this chunk used for RTT calculation? */
705 __u8 resent; /* Has this chunk ever been retransmitted. */ 705 __u8 resent; /* Has this chunk ever been retransmitted. */
706 __u8 has_tsn; /* Does this chunk have a TSN yet? */ 706 __u8 has_tsn; /* Does this chunk have a TSN yet? */
707 __u8 has_ssn; /* Does this chunk have a SSN yet? */ 707 __u8 has_ssn; /* Does this chunk have a SSN yet? */
708 __u8 singleton; /* Was this the only chunk in the packet? */ 708 __u8 singleton; /* Was this the only chunk in the packet? */
709 __u8 end_of_packet; /* Was this the last chunk in the packet? */ 709 __u8 end_of_packet; /* Was this the last chunk in the packet? */
710 __u8 ecn_ce_done; /* Have we processed the ECN CE bit? */ 710 __u8 ecn_ce_done; /* Have we processed the ECN CE bit? */
711 __u8 pdiscard; /* Discard the whole packet now? */ 711 __u8 pdiscard; /* Discard the whole packet now? */
712 __u8 tsn_gap_acked; /* Is this chunk acked by a GAP ACK? */ 712 __u8 tsn_gap_acked; /* Is this chunk acked by a GAP ACK? */
713 __s8 fast_retransmit; /* Is this chunk fast retransmitted? */ 713 __s8 fast_retransmit; /* Is this chunk fast retransmitted? */
714 __u8 tsn_missing_report; /* Data chunk missing counter. */ 714 __u8 tsn_missing_report; /* Data chunk missing counter. */
715 __u8 data_accepted; /* At least 1 chunk in this packet accepted */
715 }; 716 };
716 717
717 void sctp_chunk_hold(struct sctp_chunk *); 718 void sctp_chunk_hold(struct sctp_chunk *);
718 void sctp_chunk_put(struct sctp_chunk *); 719 void sctp_chunk_put(struct sctp_chunk *);
719 int sctp_user_addto_chunk(struct sctp_chunk *chunk, int off, int len, 720 int sctp_user_addto_chunk(struct sctp_chunk *chunk, int off, int len,
720 struct iovec *data); 721 struct iovec *data);
721 void sctp_chunk_free(struct sctp_chunk *); 722 void sctp_chunk_free(struct sctp_chunk *);
722 void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data); 723 void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data);
723 struct sctp_chunk *sctp_chunkify(struct sk_buff *, 724 struct sctp_chunk *sctp_chunkify(struct sk_buff *,
724 const struct sctp_association *, 725 const struct sctp_association *,
725 struct sock *); 726 struct sock *);
726 void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *, 727 void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
727 union sctp_addr *); 728 union sctp_addr *);
728 const union sctp_addr *sctp_source(const struct sctp_chunk *chunk); 729 const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);
729 730
730 /* This is a structure for holding either an IPv6 or an IPv4 address. */ 731 /* This is a structure for holding either an IPv6 or an IPv4 address. */
731 /* sin_family -- AF_INET or AF_INET6 732 /* sin_family -- AF_INET or AF_INET6
732 * sin_port -- ordinary port number 733 * sin_port -- ordinary port number
733 * sin_addr -- cast to either (struct in_addr) or (struct in6_addr) 734 * sin_addr -- cast to either (struct in_addr) or (struct in6_addr)
734 */ 735 */
735 struct sctp_sockaddr_entry { 736 struct sctp_sockaddr_entry {
736 struct list_head list; 737 struct list_head list;
737 union sctp_addr a; 738 union sctp_addr a;
738 }; 739 };
739 740
740 typedef struct sctp_chunk *(sctp_packet_phandler_t)(struct sctp_association *); 741 typedef struct sctp_chunk *(sctp_packet_phandler_t)(struct sctp_association *);
741 742
742 /* This structure holds lists of chunks as we are assembling for 743 /* This structure holds lists of chunks as we are assembling for
743 * transmission. 744 * transmission.
744 */ 745 */
745 struct sctp_packet { 746 struct sctp_packet {
746 /* These are the SCTP header values (host order) for the packet. */ 747 /* These are the SCTP header values (host order) for the packet. */
747 __u16 source_port; 748 __u16 source_port;
748 __u16 destination_port; 749 __u16 destination_port;
749 __u32 vtag; 750 __u32 vtag;
750 751
751 /* This contains the payload chunks. */ 752 /* This contains the payload chunks. */
752 struct list_head chunk_list; 753 struct list_head chunk_list;
753 754
754 /* This is the overhead of the sctp and ip headers. */ 755 /* This is the overhead of the sctp and ip headers. */
755 size_t overhead; 756 size_t overhead;
756 /* This is the total size of all chunks INCLUDING padding. */ 757 /* This is the total size of all chunks INCLUDING padding. */
757 size_t size; 758 size_t size;
758 759
759 /* The packet is destined for this transport address. 760 /* The packet is destined for this transport address.
760 * The function we finally use to pass down to the next lower 761 * The function we finally use to pass down to the next lower
761 * layer lives in the transport structure. 762 * layer lives in the transport structure.
762 */ 763 */
763 struct sctp_transport *transport; 764 struct sctp_transport *transport;
764 765
765 /* This packet contains a COOKIE-ECHO chunk. */ 766 /* This packet contains a COOKIE-ECHO chunk. */
766 char has_cookie_echo; 767 char has_cookie_echo;
767 768
768 /* This packet containsa SACK chunk. */ 769 /* This packet containsa SACK chunk. */
769 char has_sack; 770 char has_sack;
770 771
771 /* SCTP cannot fragment this packet. So let ip fragment it. */ 772 /* SCTP cannot fragment this packet. So let ip fragment it. */
772 char ipfragok; 773 char ipfragok;
773 774
774 int malloced; 775 int malloced;
775 }; 776 };
776 777
777 struct sctp_packet *sctp_packet_init(struct sctp_packet *, 778 struct sctp_packet *sctp_packet_init(struct sctp_packet *,
778 struct sctp_transport *, 779 struct sctp_transport *,
779 __u16 sport, __u16 dport); 780 __u16 sport, __u16 dport);
780 struct sctp_packet *sctp_packet_config(struct sctp_packet *, __u32 vtag, int); 781 struct sctp_packet *sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
781 sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *, 782 sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *,
782 struct sctp_chunk *); 783 struct sctp_chunk *);
783 sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *, 784 sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *,
784 struct sctp_chunk *); 785 struct sctp_chunk *);
785 int sctp_packet_transmit(struct sctp_packet *); 786 int sctp_packet_transmit(struct sctp_packet *);
786 void sctp_packet_free(struct sctp_packet *); 787 void sctp_packet_free(struct sctp_packet *);
787 788
788 static inline int sctp_packet_empty(struct sctp_packet *packet) 789 static inline int sctp_packet_empty(struct sctp_packet *packet)
789 { 790 {
790 return (packet->size == packet->overhead); 791 return (packet->size == packet->overhead);
791 } 792 }
792 793
793 /* This represents a remote transport address. 794 /* This represents a remote transport address.
794 * For local transport addresses, we just use union sctp_addr. 795 * For local transport addresses, we just use union sctp_addr.
795 * 796 *
796 * RFC2960 Section 1.4 Key Terms 797 * RFC2960 Section 1.4 Key Terms
797 * 798 *
798 * o Transport address: A Transport Address is traditionally defined 799 * o Transport address: A Transport Address is traditionally defined
799 * by Network Layer address, Transport Layer protocol and Transport 800 * by Network Layer address, Transport Layer protocol and Transport
800 * Layer port number. In the case of SCTP running over IP, a 801 * Layer port number. In the case of SCTP running over IP, a
801 * transport address is defined by the combination of an IP address 802 * transport address is defined by the combination of an IP address
802 * and an SCTP port number (where SCTP is the Transport protocol). 803 * and an SCTP port number (where SCTP is the Transport protocol).
803 * 804 *
804 * RFC2960 Section 7.1 SCTP Differences from TCP Congestion control 805 * RFC2960 Section 7.1 SCTP Differences from TCP Congestion control
805 * 806 *
806 * o The sender keeps a separate congestion control parameter set for 807 * o The sender keeps a separate congestion control parameter set for
807 * each of the destination addresses it can send to (not each 808 * each of the destination addresses it can send to (not each
808 * source-destination pair but for each destination). The parameters 809 * source-destination pair but for each destination). The parameters
809 * should decay if the address is not used for a long enough time 810 * should decay if the address is not used for a long enough time
810 * period. 811 * period.
811 * 812 *
812 */ 813 */
813 struct sctp_transport { 814 struct sctp_transport {
814 /* A list of transports. */ 815 /* A list of transports. */
815 struct list_head transports; 816 struct list_head transports;
816 817
817 /* Reference counting. */ 818 /* Reference counting. */
818 atomic_t refcnt; 819 atomic_t refcnt;
819 int dead; 820 int dead;
820 821
821 /* This is the peer's IP address and port. */ 822 /* This is the peer's IP address and port. */
822 union sctp_addr ipaddr; 823 union sctp_addr ipaddr;
823 824
824 /* These are the functions we call to handle LLP stuff. */ 825 /* These are the functions we call to handle LLP stuff. */
825 struct sctp_af *af_specific; 826 struct sctp_af *af_specific;
826 827
827 /* Which association do we belong to? */ 828 /* Which association do we belong to? */
828 struct sctp_association *asoc; 829 struct sctp_association *asoc;
829 830
830 /* RFC2960 831 /* RFC2960
831 * 832 *
832 * 12.3 Per Transport Address Data 833 * 12.3 Per Transport Address Data
833 * 834 *
834 * For each destination transport address in the peer's 835 * For each destination transport address in the peer's
835 * address list derived from the INIT or INIT ACK chunk, a 836 * address list derived from the INIT or INIT ACK chunk, a
836 * number of data elements needs to be maintained including: 837 * number of data elements needs to be maintained including:
837 */ 838 */
838 __u32 rtt; /* This is the most recent RTT. */ 839 __u32 rtt; /* This is the most recent RTT. */
839 840
840 /* RTO : The current retransmission timeout value. */ 841 /* RTO : The current retransmission timeout value. */
841 unsigned long rto; 842 unsigned long rto;
842 843
843 /* RTTVAR : The current RTT variation. */ 844 /* RTTVAR : The current RTT variation. */
844 __u32 rttvar; 845 __u32 rttvar;
845 846
846 /* SRTT : The current smoothed round trip time. */ 847 /* SRTT : The current smoothed round trip time. */
847 __u32 srtt; 848 __u32 srtt;
848 849
849 /* RTO-Pending : A flag used to track if one of the DATA 850 /* RTO-Pending : A flag used to track if one of the DATA
850 * chunks sent to this address is currently being 851 * chunks sent to this address is currently being
851 * used to compute a RTT. If this flag is 0, 852 * used to compute a RTT. If this flag is 0,
852 * the next DATA chunk sent to this destination 853 * the next DATA chunk sent to this destination
853 * should be used to compute a RTT and this flag 854 * should be used to compute a RTT and this flag
854 * should be set. Every time the RTT 855 * should be set. Every time the RTT
855 * calculation completes (i.e. the DATA chunk 856 * calculation completes (i.e. the DATA chunk
856 * is SACK'd) clear this flag. 857 * is SACK'd) clear this flag.
857 */ 858 */
858 int rto_pending; 859 int rto_pending;
859 860
860 /* 861 /*
861 * These are the congestion stats. 862 * These are the congestion stats.
862 */ 863 */
863 /* cwnd : The current congestion window. */ 864 /* cwnd : The current congestion window. */
864 __u32 cwnd; /* This is the actual cwnd. */ 865 __u32 cwnd; /* This is the actual cwnd. */
865 866
866 /* ssthresh : The current slow start threshold value. */ 867 /* ssthresh : The current slow start threshold value. */
867 __u32 ssthresh; 868 __u32 ssthresh;
868 869
869 /* partial : The tracking method for increase of cwnd when in 870 /* partial : The tracking method for increase of cwnd when in
870 * bytes acked : congestion avoidance mode (see Section 6.2.2) 871 * bytes acked : congestion avoidance mode (see Section 6.2.2)
871 */ 872 */
872 __u32 partial_bytes_acked; 873 __u32 partial_bytes_acked;
873 874
874 /* Data that has been sent, but not acknowledged. */ 875 /* Data that has been sent, but not acknowledged. */
875 __u32 flight_size; 876 __u32 flight_size;
876 877
877 /* Destination */ 878 /* Destination */
878 struct dst_entry *dst; 879 struct dst_entry *dst;
879 /* Source address. */ 880 /* Source address. */
880 union sctp_addr saddr; 881 union sctp_addr saddr;
881 882
882 /* When was the last time(in jiffies) that a data packet was sent on 883 /* When was the last time(in jiffies) that a data packet was sent on
883 * this transport? This is used to adjust the cwnd when the transport 884 * this transport? This is used to adjust the cwnd when the transport
884 * becomes inactive. 885 * becomes inactive.
885 */ 886 */
886 unsigned long last_time_used; 887 unsigned long last_time_used;
887 888
888 /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to 889 /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
889 * the destination address every heartbeat interval. 890 * the destination address every heartbeat interval.
890 */ 891 */
891 unsigned long hbinterval; 892 unsigned long hbinterval;
892 893
893 /* SACK delay timeout */ 894 /* SACK delay timeout */
894 unsigned long sackdelay; 895 unsigned long sackdelay;
895 896
896 /* When was the last time (in jiffies) that we heard from this 897 /* When was the last time (in jiffies) that we heard from this
897 * transport? We use this to pick new active and retran paths. 898 * transport? We use this to pick new active and retran paths.
898 */ 899 */
899 unsigned long last_time_heard; 900 unsigned long last_time_heard;
900 901
901 /* Last time(in jiffies) when cwnd is reduced due to the congestion 902 /* Last time(in jiffies) when cwnd is reduced due to the congestion
902 * indication based on ECNE chunk. 903 * indication based on ECNE chunk.
903 */ 904 */
904 unsigned long last_time_ecne_reduced; 905 unsigned long last_time_ecne_reduced;
905 906
906 /* This is the max_retrans value for the transport and will 907 /* This is the max_retrans value for the transport and will
907 * be initialized from the assocs value. This can be changed 908 * be initialized from the assocs value. This can be changed
908 * using SCTP_SET_PEER_ADDR_PARAMS socket option. 909 * using SCTP_SET_PEER_ADDR_PARAMS socket option.
909 */ 910 */
910 __u16 pathmaxrxt; 911 __u16 pathmaxrxt;
911 912
912 /* PMTU : The current known path MTU. */ 913 /* PMTU : The current known path MTU. */
913 __u32 pathmtu; 914 __u32 pathmtu;
914 915
915 /* Flags controling Heartbeat, SACK delay, and Path MTU Discovery. */ 916 /* Flags controling Heartbeat, SACK delay, and Path MTU Discovery. */
916 __u32 param_flags; 917 __u32 param_flags;
917 918
918 /* The number of times INIT has been sent on this transport. */ 919 /* The number of times INIT has been sent on this transport. */
919 int init_sent_count; 920 int init_sent_count;
920 921
921 /* state : The current state of this destination, 922 /* state : The current state of this destination,
922 * : i.e. SCTP_ACTIVE, SCTP_INACTIVE, SCTP_UNKOWN. 923 * : i.e. SCTP_ACTIVE, SCTP_INACTIVE, SCTP_UNKOWN.
923 */ 924 */
924 int state; 925 int state;
925 926
926 /* These are the error stats for this destination. */ 927 /* These are the error stats for this destination. */
927 928
928 /* Error count : The current error count for this destination. */ 929 /* Error count : The current error count for this destination. */
929 unsigned short error_count; 930 unsigned short error_count;
930 931
931 /* Per : A timer used by each destination. 932 /* Per : A timer used by each destination.
932 * Destination : 933 * Destination :
933 * Timer : 934 * Timer :
934 * 935 *
935 * [Everywhere else in the text this is called T3-rtx. -ed] 936 * [Everywhere else in the text this is called T3-rtx. -ed]
936 */ 937 */
937 struct timer_list T3_rtx_timer; 938 struct timer_list T3_rtx_timer;
938 939
939 /* Heartbeat timer is per destination. */ 940 /* Heartbeat timer is per destination. */
940 struct timer_list hb_timer; 941 struct timer_list hb_timer;
941 942
942 /* Since we're using per-destination retransmission timers 943 /* Since we're using per-destination retransmission timers
943 * (see above), we're also using per-destination "transmitted" 944 * (see above), we're also using per-destination "transmitted"
944 * queues. This probably ought to be a private struct 945 * queues. This probably ought to be a private struct
945 * accessible only within the outqueue, but it's not, yet. 946 * accessible only within the outqueue, but it's not, yet.
946 */ 947 */
947 struct list_head transmitted; 948 struct list_head transmitted;
948 949
949 /* We build bundle-able packets for this transport here. */ 950 /* We build bundle-able packets for this transport here. */
950 struct sctp_packet packet; 951 struct sctp_packet packet;
951 952
952 /* This is the list of transports that have chunks to send. */ 953 /* This is the list of transports that have chunks to send. */
953 struct list_head send_ready; 954 struct list_head send_ready;
954 955
955 int malloced; /* Is this structure kfree()able? */ 956 int malloced; /* Is this structure kfree()able? */
956 957
957 /* State information saved for SFR_CACC algorithm. The key 958 /* State information saved for SFR_CACC algorithm. The key
958 * idea in SFR_CACC is to maintain state at the sender on a 959 * idea in SFR_CACC is to maintain state at the sender on a
959 * per-destination basis when a changeover happens. 960 * per-destination basis when a changeover happens.
960 * char changeover_active; 961 * char changeover_active;
961 * char cycling_changeover; 962 * char cycling_changeover;
962 * __u32 next_tsn_at_change; 963 * __u32 next_tsn_at_change;
963 * char cacc_saw_newack; 964 * char cacc_saw_newack;
964 */ 965 */
965 struct { 966 struct {
966 /* An unsigned integer, which stores the next TSN to be 967 /* An unsigned integer, which stores the next TSN to be
967 * used by the sender, at the moment of changeover. 968 * used by the sender, at the moment of changeover.
968 */ 969 */
969 __u32 next_tsn_at_change; 970 __u32 next_tsn_at_change;
970 971
971 /* A flag which indicates the occurrence of a changeover */ 972 /* A flag which indicates the occurrence of a changeover */
972 char changeover_active; 973 char changeover_active;
973 974
974 /* A flag which indicates whether the change of primary is 975 /* A flag which indicates whether the change of primary is
975 * the first switch to this destination address during an 976 * the first switch to this destination address during an
976 * active switch. 977 * active switch.
977 */ 978 */
978 char cycling_changeover; 979 char cycling_changeover;
979 980
980 /* A temporary flag, which is used during the processing of 981 /* A temporary flag, which is used during the processing of
981 * a SACK to estimate the causative TSN(s)'s group. 982 * a SACK to estimate the causative TSN(s)'s group.
982 */ 983 */
983 char cacc_saw_newack; 984 char cacc_saw_newack;
984 } cacc; 985 } cacc;
985 }; 986 };
986 987
987 struct sctp_transport *sctp_transport_new(const union sctp_addr *, 988 struct sctp_transport *sctp_transport_new(const union sctp_addr *,
988 gfp_t); 989 gfp_t);
989 void sctp_transport_set_owner(struct sctp_transport *, 990 void sctp_transport_set_owner(struct sctp_transport *,
990 struct sctp_association *); 991 struct sctp_association *);
991 void sctp_transport_route(struct sctp_transport *, union sctp_addr *, 992 void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
992 struct sctp_sock *); 993 struct sctp_sock *);
993 void sctp_transport_pmtu(struct sctp_transport *); 994 void sctp_transport_pmtu(struct sctp_transport *);
994 void sctp_transport_free(struct sctp_transport *); 995 void sctp_transport_free(struct sctp_transport *);
995 void sctp_transport_reset_timers(struct sctp_transport *); 996 void sctp_transport_reset_timers(struct sctp_transport *);
996 void sctp_transport_hold(struct sctp_transport *); 997 void sctp_transport_hold(struct sctp_transport *);
997 void sctp_transport_put(struct sctp_transport *); 998 void sctp_transport_put(struct sctp_transport *);
998 void sctp_transport_update_rto(struct sctp_transport *, __u32); 999 void sctp_transport_update_rto(struct sctp_transport *, __u32);
999 void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32); 1000 void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32);
1000 void sctp_transport_lower_cwnd(struct sctp_transport *, sctp_lower_cwnd_t); 1001 void sctp_transport_lower_cwnd(struct sctp_transport *, sctp_lower_cwnd_t);
1001 unsigned long sctp_transport_timeout(struct sctp_transport *); 1002 unsigned long sctp_transport_timeout(struct sctp_transport *);
1002 1003
1003 1004
1004 /* This is the structure we use to queue packets as they come into 1005 /* This is the structure we use to queue packets as they come into
1005 * SCTP. We write packets to it and read chunks from it. 1006 * SCTP. We write packets to it and read chunks from it.
1006 */ 1007 */
1007 struct sctp_inq { 1008 struct sctp_inq {
1008 /* This is actually a queue of sctp_chunk each 1009 /* This is actually a queue of sctp_chunk each
1009 * containing a partially decoded packet. 1010 * containing a partially decoded packet.
1010 */ 1011 */
1011 struct list_head in_chunk_list; 1012 struct list_head in_chunk_list;
1012 /* This is the packet which is currently off the in queue and is 1013 /* This is the packet which is currently off the in queue and is
1013 * being worked on through the inbound chunk processing. 1014 * being worked on through the inbound chunk processing.
1014 */ 1015 */
1015 struct sctp_chunk *in_progress; 1016 struct sctp_chunk *in_progress;
1016 1017
1017 /* This is the delayed task to finish delivering inbound 1018 /* This is the delayed task to finish delivering inbound
1018 * messages. 1019 * messages.
1019 */ 1020 */
1020 struct work_struct immediate; 1021 struct work_struct immediate;
1021 1022
1022 int malloced; /* Is this structure kfree()able? */ 1023 int malloced; /* Is this structure kfree()able? */
1023 }; 1024 };
1024 1025
1025 void sctp_inq_init(struct sctp_inq *); 1026 void sctp_inq_init(struct sctp_inq *);
1026 void sctp_inq_free(struct sctp_inq *); 1027 void sctp_inq_free(struct sctp_inq *);
1027 void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet); 1028 void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet);
1028 struct sctp_chunk *sctp_inq_pop(struct sctp_inq *); 1029 struct sctp_chunk *sctp_inq_pop(struct sctp_inq *);
1029 void sctp_inq_set_th_handler(struct sctp_inq *, void (*)(void *), void *); 1030 void sctp_inq_set_th_handler(struct sctp_inq *, void (*)(void *), void *);
1030 1031
1031 /* This is the structure we use to hold outbound chunks. You push 1032 /* This is the structure we use to hold outbound chunks. You push
1032 * chunks in and they automatically pop out the other end as bundled 1033 * chunks in and they automatically pop out the other end as bundled
1033 * packets (it calls (*output_handler)()). 1034 * packets (it calls (*output_handler)()).
1034 * 1035 *
1035 * This structure covers sections 6.3, 6.4, 6.7, 6.8, 6.10, 7., 8.1, 1036 * This structure covers sections 6.3, 6.4, 6.7, 6.8, 6.10, 7., 8.1,
1036 * and 8.2 of the v13 draft. 1037 * and 8.2 of the v13 draft.
1037 * 1038 *
1038 * It handles retransmissions. The connection to the timeout portion 1039 * It handles retransmissions. The connection to the timeout portion
1039 * of the state machine is through sctp_..._timeout() and timeout_handler. 1040 * of the state machine is through sctp_..._timeout() and timeout_handler.
1040 * 1041 *
1041 * If you feed it SACKs, it will eat them. 1042 * If you feed it SACKs, it will eat them.
1042 * 1043 *
1043 * If you give it big chunks, it will fragment them. 1044 * If you give it big chunks, it will fragment them.
1044 * 1045 *
1045 * It assigns TSN's to data chunks. This happens at the last possible 1046 * It assigns TSN's to data chunks. This happens at the last possible
1046 * instant before transmission. 1047 * instant before transmission.
1047 * 1048 *
1048 * When free()'d, it empties itself out via output_handler(). 1049 * When free()'d, it empties itself out via output_handler().
1049 */ 1050 */
1050 struct sctp_outq { 1051 struct sctp_outq {
1051 struct sctp_association *asoc; 1052 struct sctp_association *asoc;
1052 1053
1053 /* Data pending that has never been transmitted. */ 1054 /* Data pending that has never been transmitted. */
1054 struct list_head out_chunk_list; 1055 struct list_head out_chunk_list;
1055 1056
1056 unsigned out_qlen; /* Total length of queued data chunks. */ 1057 unsigned out_qlen; /* Total length of queued data chunks. */
1057 1058
1058 /* Error of send failed, may used in SCTP_SEND_FAILED event. */ 1059 /* Error of send failed, may used in SCTP_SEND_FAILED event. */
1059 unsigned error; 1060 unsigned error;
1060 1061
1061 /* These are control chunks we want to send. */ 1062 /* These are control chunks we want to send. */
1062 struct list_head control_chunk_list; 1063 struct list_head control_chunk_list;
1063 1064
1064 /* These are chunks that have been sacked but are above the 1065 /* These are chunks that have been sacked but are above the
1065 * CTSN, or cumulative tsn ack point. 1066 * CTSN, or cumulative tsn ack point.
1066 */ 1067 */
1067 struct list_head sacked; 1068 struct list_head sacked;
1068 1069
1069 /* Put chunks on this list to schedule them for 1070 /* Put chunks on this list to schedule them for
1070 * retransmission. 1071 * retransmission.
1071 */ 1072 */
1072 struct list_head retransmit; 1073 struct list_head retransmit;
1073 1074
1074 /* Put chunks on this list to save them for FWD TSN processing as 1075 /* Put chunks on this list to save them for FWD TSN processing as
1075 * they were abandoned. 1076 * they were abandoned.
1076 */ 1077 */
1077 struct list_head abandoned; 1078 struct list_head abandoned;
1078 1079
1079 /* How many unackd bytes do we have in-flight? */ 1080 /* How many unackd bytes do we have in-flight? */
1080 __u32 outstanding_bytes; 1081 __u32 outstanding_bytes;
1081 1082
1082 /* Corked? */ 1083 /* Corked? */
1083 char cork; 1084 char cork;
1084 1085
1085 /* Is this structure empty? */ 1086 /* Is this structure empty? */
1086 char empty; 1087 char empty;
1087 1088
1088 /* Are we kfree()able? */ 1089 /* Are we kfree()able? */
1089 char malloced; 1090 char malloced;
1090 }; 1091 };
1091 1092
1092 void sctp_outq_init(struct sctp_association *, struct sctp_outq *); 1093 void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
1093 void sctp_outq_teardown(struct sctp_outq *); 1094 void sctp_outq_teardown(struct sctp_outq *);
1094 void sctp_outq_free(struct sctp_outq*); 1095 void sctp_outq_free(struct sctp_outq*);
1095 int sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk); 1096 int sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk);
1096 int sctp_outq_flush(struct sctp_outq *, int); 1097 int sctp_outq_flush(struct sctp_outq *, int);
1097 int sctp_outq_sack(struct sctp_outq *, struct sctp_sackhdr *); 1098 int sctp_outq_sack(struct sctp_outq *, struct sctp_sackhdr *);
1098 int sctp_outq_is_empty(const struct sctp_outq *); 1099 int sctp_outq_is_empty(const struct sctp_outq *);
1099 void sctp_outq_restart(struct sctp_outq *); 1100 void sctp_outq_restart(struct sctp_outq *);
1100 1101
1101 void sctp_retransmit(struct sctp_outq *, struct sctp_transport *, 1102 void sctp_retransmit(struct sctp_outq *, struct sctp_transport *,
1102 sctp_retransmit_reason_t); 1103 sctp_retransmit_reason_t);
1103 void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8); 1104 void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
1104 int sctp_outq_uncork(struct sctp_outq *); 1105 int sctp_outq_uncork(struct sctp_outq *);
1105 /* Uncork and flush an outqueue. */ 1106 /* Uncork and flush an outqueue. */
1106 static inline void sctp_outq_cork(struct sctp_outq *q) 1107 static inline void sctp_outq_cork(struct sctp_outq *q)
1107 { 1108 {
1108 q->cork = 1; 1109 q->cork = 1;
1109 } 1110 }
1110 1111
1111 /* These bind address data fields common between endpoints and associations */ 1112 /* These bind address data fields common between endpoints and associations */
1112 struct sctp_bind_addr { 1113 struct sctp_bind_addr {
1113 1114
1114 /* RFC 2960 12.1 Parameters necessary for the SCTP instance 1115 /* RFC 2960 12.1 Parameters necessary for the SCTP instance
1115 * 1116 *
1116 * SCTP Port: The local SCTP port number the endpoint is 1117 * SCTP Port: The local SCTP port number the endpoint is
1117 * bound to. 1118 * bound to.
1118 */ 1119 */
1119 __u16 port; 1120 __u16 port;
1120 1121
1121 /* RFC 2960 12.1 Parameters necessary for the SCTP instance 1122 /* RFC 2960 12.1 Parameters necessary for the SCTP instance
1122 * 1123 *
1123 * Address List: The list of IP addresses that this instance 1124 * Address List: The list of IP addresses that this instance
1124 * has bound. This information is passed to one's 1125 * has bound. This information is passed to one's
1125 * peer(s) in INIT and INIT ACK chunks. 1126 * peer(s) in INIT and INIT ACK chunks.
1126 */ 1127 */
1127 struct list_head address_list; 1128 struct list_head address_list;
1128 1129
1129 int malloced; /* Are we kfree()able? */ 1130 int malloced; /* Are we kfree()able? */
1130 }; 1131 };
1131 1132
1132 void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port); 1133 void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
1133 void sctp_bind_addr_free(struct sctp_bind_addr *); 1134 void sctp_bind_addr_free(struct sctp_bind_addr *);
1134 int sctp_bind_addr_copy(struct sctp_bind_addr *dest, 1135 int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
1135 const struct sctp_bind_addr *src, 1136 const struct sctp_bind_addr *src,
1136 sctp_scope_t scope, gfp_t gfp, 1137 sctp_scope_t scope, gfp_t gfp,
1137 int flags); 1138 int flags);
1138 int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *, 1139 int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
1139 gfp_t gfp); 1140 gfp_t gfp);
1140 int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *); 1141 int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
1141 int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *, 1142 int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *,
1142 struct sctp_sock *); 1143 struct sctp_sock *);
1143 union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp, 1144 union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
1144 const union sctp_addr *addrs, 1145 const union sctp_addr *addrs,
1145 int addrcnt, 1146 int addrcnt,
1146 struct sctp_sock *opt); 1147 struct sctp_sock *opt);
1147 union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp, 1148 union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
1148 int *addrs_len, 1149 int *addrs_len,
1149 gfp_t gfp); 1150 gfp_t gfp);
1150 int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len, 1151 int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
1151 __u16 port, gfp_t gfp); 1152 __u16 port, gfp_t gfp);
1152 1153
1153 sctp_scope_t sctp_scope(const union sctp_addr *); 1154 sctp_scope_t sctp_scope(const union sctp_addr *);
1154 int sctp_in_scope(const union sctp_addr *addr, const sctp_scope_t scope); 1155 int sctp_in_scope(const union sctp_addr *addr, const sctp_scope_t scope);
1155 int sctp_is_any(const union sctp_addr *addr); 1156 int sctp_is_any(const union sctp_addr *addr);
1156 int sctp_addr_is_valid(const union sctp_addr *addr); 1157 int sctp_addr_is_valid(const union sctp_addr *addr);
1157 1158
1158 1159
1159 /* What type of endpoint? */ 1160 /* What type of endpoint? */
1160 typedef enum { 1161 typedef enum {
1161 SCTP_EP_TYPE_SOCKET, 1162 SCTP_EP_TYPE_SOCKET,
1162 SCTP_EP_TYPE_ASSOCIATION, 1163 SCTP_EP_TYPE_ASSOCIATION,
1163 } sctp_endpoint_type_t; 1164 } sctp_endpoint_type_t;
1164 1165
1165 /* 1166 /*
1166 * A common base class to bridge the implmentation view of a 1167 * A common base class to bridge the implmentation view of a
1167 * socket (usually listening) endpoint versus an association's 1168 * socket (usually listening) endpoint versus an association's
1168 * local endpoint. 1169 * local endpoint.
1169 * This common structure is useful for several purposes: 1170 * This common structure is useful for several purposes:
1170 * 1) Common interface for lookup routines. 1171 * 1) Common interface for lookup routines.
1171 * a) Subfunctions work for either endpoint or association 1172 * a) Subfunctions work for either endpoint or association
1172 * b) Single interface to lookup allows hiding the lookup lock rather 1173 * b) Single interface to lookup allows hiding the lookup lock rather
1173 * than acquiring it externally. 1174 * than acquiring it externally.
1174 * 2) Common interface for the inbound chunk handling/state machine. 1175 * 2) Common interface for the inbound chunk handling/state machine.
1175 * 3) Common object handling routines for reference counting, etc. 1176 * 3) Common object handling routines for reference counting, etc.
1176 * 4) Disentangle association lookup from endpoint lookup, where we 1177 * 4) Disentangle association lookup from endpoint lookup, where we
1177 * do not have to find our endpoint to find our association. 1178 * do not have to find our endpoint to find our association.
1178 * 1179 *
1179 */ 1180 */
1180 1181
1181 struct sctp_ep_common { 1182 struct sctp_ep_common {
1182 /* Fields to help us manage our entries in the hash tables. */ 1183 /* Fields to help us manage our entries in the hash tables. */
1183 struct sctp_ep_common *next; 1184 struct sctp_ep_common *next;
1184 struct sctp_ep_common **pprev; 1185 struct sctp_ep_common **pprev;
1185 int hashent; 1186 int hashent;
1186 1187
1187 /* Runtime type information. What kind of endpoint is this? */ 1188 /* Runtime type information. What kind of endpoint is this? */
1188 sctp_endpoint_type_t type; 1189 sctp_endpoint_type_t type;
1189 1190
1190 /* Some fields to help us manage this object. 1191 /* Some fields to help us manage this object.
1191 * refcnt - Reference count access to this object. 1192 * refcnt - Reference count access to this object.
1192 * dead - Do not attempt to use this object. 1193 * dead - Do not attempt to use this object.
1193 * malloced - Do we need to kfree this object? 1194 * malloced - Do we need to kfree this object?
1194 */ 1195 */
1195 atomic_t refcnt; 1196 atomic_t refcnt;
1196 char dead; 1197 char dead;
1197 char malloced; 1198 char malloced;
1198 1199
1199 /* What socket does this endpoint belong to? */ 1200 /* What socket does this endpoint belong to? */
1200 struct sock *sk; 1201 struct sock *sk;
1201 1202
1202 /* This is where we receive inbound chunks. */ 1203 /* This is where we receive inbound chunks. */
1203 struct sctp_inq inqueue; 1204 struct sctp_inq inqueue;
1204 1205
1205 /* This substructure includes the defining parameters of the 1206 /* This substructure includes the defining parameters of the
1206 * endpoint: 1207 * endpoint:
1207 * bind_addr.port is our shared port number. 1208 * bind_addr.port is our shared port number.
1208 * bind_addr.address_list is our set of local IP addresses. 1209 * bind_addr.address_list is our set of local IP addresses.
1209 */ 1210 */
1210 struct sctp_bind_addr bind_addr; 1211 struct sctp_bind_addr bind_addr;
1211 1212
1212 /* Protection during address list comparisons. */ 1213 /* Protection during address list comparisons. */
1213 rwlock_t addr_lock; 1214 rwlock_t addr_lock;
1214 }; 1215 };
1215 1216
1216 1217
1217 /* RFC Section 1.4 Key Terms 1218 /* RFC Section 1.4 Key Terms
1218 * 1219 *
1219 * o SCTP endpoint: The logical sender/receiver of SCTP packets. On a 1220 * o SCTP endpoint: The logical sender/receiver of SCTP packets. On a
1220 * multi-homed host, an SCTP endpoint is represented to its peers as a 1221 * multi-homed host, an SCTP endpoint is represented to its peers as a
1221 * combination of a set of eligible destination transport addresses to 1222 * combination of a set of eligible destination transport addresses to
1222 * which SCTP packets can be sent and a set of eligible source 1223 * which SCTP packets can be sent and a set of eligible source
1223 * transport addresses from which SCTP packets can be received. 1224 * transport addresses from which SCTP packets can be received.
1224 * All transport addresses used by an SCTP endpoint must use the 1225 * All transport addresses used by an SCTP endpoint must use the
1225 * same port number, but can use multiple IP addresses. A transport 1226 * same port number, but can use multiple IP addresses. A transport
1226 * address used by an SCTP endpoint must not be used by another 1227 * address used by an SCTP endpoint must not be used by another
1227 * SCTP endpoint. In other words, a transport address is unique 1228 * SCTP endpoint. In other words, a transport address is unique
1228 * to an SCTP endpoint. 1229 * to an SCTP endpoint.
1229 * 1230 *
1230 * From an implementation perspective, each socket has one of these. 1231 * From an implementation perspective, each socket has one of these.
1231 * A TCP-style socket will have exactly one association on one of 1232 * A TCP-style socket will have exactly one association on one of
1232 * these. An UDP-style socket will have multiple associations hanging 1233 * these. An UDP-style socket will have multiple associations hanging
1233 * off one of these. 1234 * off one of these.
1234 */ 1235 */
1235 1236
1236 struct sctp_endpoint { 1237 struct sctp_endpoint {
1237 /* Common substructure for endpoint and association. */ 1238 /* Common substructure for endpoint and association. */
1238 struct sctp_ep_common base; 1239 struct sctp_ep_common base;
1239 1240
1240 /* Associations: A list of current associations and mappings 1241 /* Associations: A list of current associations and mappings
1241 * to the data consumers for each association. This 1242 * to the data consumers for each association. This
1242 * may be in the form of a hash table or other 1243 * may be in the form of a hash table or other
1243 * implementation dependent structure. The data 1244 * implementation dependent structure. The data
1244 * consumers may be process identification 1245 * consumers may be process identification
1245 * information such as file descriptors, named pipe 1246 * information such as file descriptors, named pipe
1246 * pointer, or table pointers dependent on how SCTP 1247 * pointer, or table pointers dependent on how SCTP
1247 * is implemented. 1248 * is implemented.
1248 */ 1249 */
1249 /* This is really a list of struct sctp_association entries. */ 1250 /* This is really a list of struct sctp_association entries. */
1250 struct list_head asocs; 1251 struct list_head asocs;
1251 1252
1252 /* Secret Key: A secret key used by this endpoint to compute 1253 /* Secret Key: A secret key used by this endpoint to compute
1253 * the MAC. This SHOULD be a cryptographic quality 1254 * the MAC. This SHOULD be a cryptographic quality
1254 * random number with a sufficient length. 1255 * random number with a sufficient length.
1255 * Discussion in [RFC1750] can be helpful in 1256 * Discussion in [RFC1750] can be helpful in
1256 * selection of the key. 1257 * selection of the key.
1257 */ 1258 */
1258 __u8 secret_key[SCTP_HOW_MANY_SECRETS][SCTP_SECRET_SIZE]; 1259 __u8 secret_key[SCTP_HOW_MANY_SECRETS][SCTP_SECRET_SIZE];
1259 int current_key; 1260 int current_key;
1260 int last_key; 1261 int last_key;
1261 int key_changed_at; 1262 int key_changed_at;
1262 1263
1263 /* digest: This is a digest of the sctp cookie. This field is 1264 /* digest: This is a digest of the sctp cookie. This field is
1264 * only used on the receive path when we try to validate 1265 * only used on the receive path when we try to validate
1265 * that the cookie has not been tampered with. We put 1266 * that the cookie has not been tampered with. We put
1266 * this here so we pre-allocate this once and can re-use 1267 * this here so we pre-allocate this once and can re-use
1267 * on every receive. 1268 * on every receive.
1268 */ 1269 */
1269 __u8 digest[SCTP_SIGNATURE_SIZE]; 1270 __u8 digest[SCTP_SIGNATURE_SIZE];
1270 1271
1271 /* sendbuf acct. policy. */ 1272 /* sendbuf acct. policy. */
1272 __u32 sndbuf_policy; 1273 __u32 sndbuf_policy;
1273 1274
1274 /* rcvbuf acct. policy. */ 1275 /* rcvbuf acct. policy. */
1275 __u32 rcvbuf_policy; 1276 __u32 rcvbuf_policy;
1276 }; 1277 };
1277 1278
1278 /* Recover the outter endpoint structure. */ 1279 /* Recover the outter endpoint structure. */
1279 static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base) 1280 static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base)
1280 { 1281 {
1281 struct sctp_endpoint *ep; 1282 struct sctp_endpoint *ep;
1282 1283
1283 ep = container_of(base, struct sctp_endpoint, base); 1284 ep = container_of(base, struct sctp_endpoint, base);
1284 return ep; 1285 return ep;
1285 } 1286 }
1286 1287
1287 /* These are function signatures for manipulating endpoints. */ 1288 /* These are function signatures for manipulating endpoints. */
1288 struct sctp_endpoint *sctp_endpoint_new(struct sock *, gfp_t); 1289 struct sctp_endpoint *sctp_endpoint_new(struct sock *, gfp_t);
1289 void sctp_endpoint_free(struct sctp_endpoint *); 1290 void sctp_endpoint_free(struct sctp_endpoint *);
1290 void sctp_endpoint_put(struct sctp_endpoint *); 1291 void sctp_endpoint_put(struct sctp_endpoint *);
1291 void sctp_endpoint_hold(struct sctp_endpoint *); 1292 void sctp_endpoint_hold(struct sctp_endpoint *);
1292 void sctp_endpoint_add_asoc(struct sctp_endpoint *, struct sctp_association *); 1293 void sctp_endpoint_add_asoc(struct sctp_endpoint *, struct sctp_association *);
1293 struct sctp_association *sctp_endpoint_lookup_assoc( 1294 struct sctp_association *sctp_endpoint_lookup_assoc(
1294 const struct sctp_endpoint *ep, 1295 const struct sctp_endpoint *ep,
1295 const union sctp_addr *paddr, 1296 const union sctp_addr *paddr,
1296 struct sctp_transport **); 1297 struct sctp_transport **);
1297 int sctp_endpoint_is_peeled_off(struct sctp_endpoint *, 1298 int sctp_endpoint_is_peeled_off(struct sctp_endpoint *,
1298 const union sctp_addr *); 1299 const union sctp_addr *);
1299 struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *, 1300 struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *,
1300 const union sctp_addr *); 1301 const union sctp_addr *);
1301 int sctp_has_association(const union sctp_addr *laddr, 1302 int sctp_has_association(const union sctp_addr *laddr,
1302 const union sctp_addr *paddr); 1303 const union sctp_addr *paddr);
1303 1304
1304 int sctp_verify_init(const struct sctp_association *asoc, sctp_cid_t, 1305 int sctp_verify_init(const struct sctp_association *asoc, sctp_cid_t,
1305 sctp_init_chunk_t *peer_init, struct sctp_chunk *chunk, 1306 sctp_init_chunk_t *peer_init, struct sctp_chunk *chunk,
1306 struct sctp_chunk **err_chunk); 1307 struct sctp_chunk **err_chunk);
1307 int sctp_process_init(struct sctp_association *, sctp_cid_t cid, 1308 int sctp_process_init(struct sctp_association *, sctp_cid_t cid,
1308 const union sctp_addr *peer, 1309 const union sctp_addr *peer,
1309 sctp_init_chunk_t *init, gfp_t gfp); 1310 sctp_init_chunk_t *init, gfp_t gfp);
1310 __u32 sctp_generate_tag(const struct sctp_endpoint *); 1311 __u32 sctp_generate_tag(const struct sctp_endpoint *);
1311 __u32 sctp_generate_tsn(const struct sctp_endpoint *); 1312 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
1312 1313
1313 1314
1314 /* RFC2960 1315 /* RFC2960
1315 * 1316 *
1316 * 12. Recommended Transmission Control Block (TCB) Parameters 1317 * 12. Recommended Transmission Control Block (TCB) Parameters
1317 * 1318 *
1318 * This section details a recommended set of parameters that should 1319 * This section details a recommended set of parameters that should
1319 * be contained within the TCB for an implementation. This section is 1320 * be contained within the TCB for an implementation. This section is
1320 * for illustrative purposes and should not be deemed as requirements 1321 * for illustrative purposes and should not be deemed as requirements
1321 * on an implementation or as an exhaustive list of all parameters 1322 * on an implementation or as an exhaustive list of all parameters
1322 * inside an SCTP TCB. Each implementation may need its own additional 1323 * inside an SCTP TCB. Each implementation may need its own additional
1323 * parameters for optimization. 1324 * parameters for optimization.
1324 */ 1325 */
1325 1326
1326 1327
1327 /* Here we have information about each individual association. */ 1328 /* Here we have information about each individual association. */
1328 struct sctp_association { 1329 struct sctp_association {
1329 1330
1330 /* A base structure common to endpoint and association. 1331 /* A base structure common to endpoint and association.
1331 * In this context, it represents the associations's view 1332 * In this context, it represents the associations's view
1332 * of the local endpoint of the association. 1333 * of the local endpoint of the association.
1333 */ 1334 */
1334 struct sctp_ep_common base; 1335 struct sctp_ep_common base;
1335 1336
1336 /* Associations on the same socket. */ 1337 /* Associations on the same socket. */
1337 struct list_head asocs; 1338 struct list_head asocs;
1338 1339
1339 /* association id. */ 1340 /* association id. */
1340 sctp_assoc_t assoc_id; 1341 sctp_assoc_t assoc_id;
1341 1342
1342 /* This is our parent endpoint. */ 1343 /* This is our parent endpoint. */
1343 struct sctp_endpoint *ep; 1344 struct sctp_endpoint *ep;
1344 1345
1345 /* These are those association elements needed in the cookie. */ 1346 /* These are those association elements needed in the cookie. */
1346 struct sctp_cookie c; 1347 struct sctp_cookie c;
1347 1348
1348 /* This is all information about our peer. */ 1349 /* This is all information about our peer. */
1349 struct { 1350 struct {
1350 /* rwnd 1351 /* rwnd
1351 * 1352 *
1352 * Peer Rwnd : Current calculated value of the peer's rwnd. 1353 * Peer Rwnd : Current calculated value of the peer's rwnd.
1353 */ 1354 */
1354 __u32 rwnd; 1355 __u32 rwnd;
1355 1356
1356 /* transport_addr_list 1357 /* transport_addr_list
1357 * 1358 *
1358 * Peer : A list of SCTP transport addresses that the 1359 * Peer : A list of SCTP transport addresses that the
1359 * Transport : peer is bound to. This information is derived 1360 * Transport : peer is bound to. This information is derived
1360 * Address : from the INIT or INIT ACK and is used to 1361 * Address : from the INIT or INIT ACK and is used to
1361 * List : associate an inbound packet with a given 1362 * List : associate an inbound packet with a given
1362 * : association. Normally this information is 1363 * : association. Normally this information is
1363 * : hashed or keyed for quick lookup and access 1364 * : hashed or keyed for quick lookup and access
1364 * : of the TCB. 1365 * : of the TCB.
1365 * : The list is also initialized with the list 1366 * : The list is also initialized with the list
1366 * : of addresses passed with the sctp_connectx() 1367 * : of addresses passed with the sctp_connectx()
1367 * : call. 1368 * : call.
1368 * 1369 *
1369 * It is a list of SCTP_transport's. 1370 * It is a list of SCTP_transport's.
1370 */ 1371 */
1371 struct list_head transport_addr_list; 1372 struct list_head transport_addr_list;
1372 1373
1373 /* transport_count 1374 /* transport_count
1374 * 1375 *
1375 * Peer : A count of the number of peer addresses 1376 * Peer : A count of the number of peer addresses
1376 * Transport : in the Peer Transport Address List. 1377 * Transport : in the Peer Transport Address List.
1377 * Address : 1378 * Address :
1378 * Count : 1379 * Count :
1379 */ 1380 */
1380 __u16 transport_count; 1381 __u16 transport_count;
1381 1382
1382 /* port 1383 /* port
1383 * The transport layer port number. 1384 * The transport layer port number.
1384 */ 1385 */
1385 __u16 port; 1386 __u16 port;
1386 1387
1387 /* primary_path 1388 /* primary_path
1388 * 1389 *
1389 * Primary : This is the current primary destination 1390 * Primary : This is the current primary destination
1390 * Path : transport address of the peer endpoint. It 1391 * Path : transport address of the peer endpoint. It
1391 * : may also specify a source transport address 1392 * : may also specify a source transport address
1392 * : on this endpoint. 1393 * : on this endpoint.
1393 * 1394 *
1394 * All of these paths live on transport_addr_list. 1395 * All of these paths live on transport_addr_list.
1395 * 1396 *
1396 * At the bakeoffs, we discovered that the intent of 1397 * At the bakeoffs, we discovered that the intent of
1397 * primaryPath is that it only changes when the ULP 1398 * primaryPath is that it only changes when the ULP
1398 * asks to have it changed. We add the activePath to 1399 * asks to have it changed. We add the activePath to
1399 * designate the connection we are currently using to 1400 * designate the connection we are currently using to
1400 * transmit new data and most control chunks. 1401 * transmit new data and most control chunks.
1401 */ 1402 */
1402 struct sctp_transport *primary_path; 1403 struct sctp_transport *primary_path;
1403 1404
1404 /* Cache the primary path address here, when we 1405 /* Cache the primary path address here, when we
1405 * need a an address for msg_name. 1406 * need a an address for msg_name.
1406 */ 1407 */
1407 union sctp_addr primary_addr; 1408 union sctp_addr primary_addr;
1408 1409
1409 /* active_path 1410 /* active_path
1410 * The path that we are currently using to 1411 * The path that we are currently using to
1411 * transmit new data and most control chunks. 1412 * transmit new data and most control chunks.
1412 */ 1413 */
1413 struct sctp_transport *active_path; 1414 struct sctp_transport *active_path;
1414 1415
1415 /* retran_path 1416 /* retran_path
1416 * 1417 *
1417 * RFC2960 6.4 Multi-homed SCTP Endpoints 1418 * RFC2960 6.4 Multi-homed SCTP Endpoints
1418 * ... 1419 * ...
1419 * Furthermore, when its peer is multi-homed, an 1420 * Furthermore, when its peer is multi-homed, an
1420 * endpoint SHOULD try to retransmit a chunk to an 1421 * endpoint SHOULD try to retransmit a chunk to an
1421 * active destination transport address that is 1422 * active destination transport address that is
1422 * different from the last destination address to 1423 * different from the last destination address to
1423 * which the DATA chunk was sent. 1424 * which the DATA chunk was sent.
1424 */ 1425 */
1425 struct sctp_transport *retran_path; 1426 struct sctp_transport *retran_path;
1426 1427
1427 /* Pointer to last transport I have sent on. */ 1428 /* Pointer to last transport I have sent on. */
1428 struct sctp_transport *last_sent_to; 1429 struct sctp_transport *last_sent_to;
1429 1430
1430 /* This is the last transport I have received DATA on. */ 1431 /* This is the last transport I have received DATA on. */
1431 struct sctp_transport *last_data_from; 1432 struct sctp_transport *last_data_from;
1432 1433
1433 /* 1434 /*
1434 * Mapping An array of bits or bytes indicating which out of 1435 * Mapping An array of bits or bytes indicating which out of
1435 * Array order TSN's have been received (relative to the 1436 * Array order TSN's have been received (relative to the
1436 * Last Rcvd TSN). If no gaps exist, i.e. no out of 1437 * Last Rcvd TSN). If no gaps exist, i.e. no out of
1437 * order packets have been received, this array 1438 * order packets have been received, this array
1438 * will be set to all zero. This structure may be 1439 * will be set to all zero. This structure may be
1439 * in the form of a circular buffer or bit array. 1440 * in the form of a circular buffer or bit array.
1440 * 1441 *
1441 * Last Rcvd : This is the last TSN received in 1442 * Last Rcvd : This is the last TSN received in
1442 * TSN : sequence. This value is set initially by 1443 * TSN : sequence. This value is set initially by
1443 * : taking the peer's Initial TSN, received in 1444 * : taking the peer's Initial TSN, received in
1444 * : the INIT or INIT ACK chunk, and subtracting 1445 * : the INIT or INIT ACK chunk, and subtracting
1445 * : one from it. 1446 * : one from it.
1446 * 1447 *
1447 * Throughout most of the specification this is called the 1448 * Throughout most of the specification this is called the
1448 * "Cumulative TSN ACK Point". In this case, we 1449 * "Cumulative TSN ACK Point". In this case, we
1449 * ignore the advice in 12.2 in favour of the term 1450 * ignore the advice in 12.2 in favour of the term
1450 * used in the bulk of the text. This value is hidden 1451 * used in the bulk of the text. This value is hidden
1451 * in tsn_map--we get it by calling sctp_tsnmap_get_ctsn(). 1452 * in tsn_map--we get it by calling sctp_tsnmap_get_ctsn().
1452 */ 1453 */
1453 struct sctp_tsnmap tsn_map; 1454 struct sctp_tsnmap tsn_map;
1454 __u8 _map[sctp_tsnmap_storage_size(SCTP_TSN_MAP_SIZE)]; 1455 __u8 _map[sctp_tsnmap_storage_size(SCTP_TSN_MAP_SIZE)];
1455 1456
1456 /* Ack State : This flag indicates if the next received 1457 /* Ack State : This flag indicates if the next received
1457 * : packet is to be responded to with a 1458 * : packet is to be responded to with a
1458 * : SACK. This is initializedto 0. When a packet 1459 * : SACK. This is initializedto 0. When a packet
1459 * : is received it is incremented. If this value 1460 * : is received it is incremented. If this value
1460 * : reaches 2 or more, a SACK is sent and the 1461 * : reaches 2 or more, a SACK is sent and the
1461 * : value is reset to 0. Note: This is used only 1462 * : value is reset to 0. Note: This is used only
1462 * : when no DATA chunks are received out of 1463 * : when no DATA chunks are received out of
1463 * : order. When DATA chunks are out of order, 1464 * : order. When DATA chunks are out of order,
1464 * : SACK's are not delayed (see Section 6). 1465 * : SACK's are not delayed (see Section 6).
1465 */ 1466 */
1466 __u8 sack_needed; /* Do we need to sack the peer? */ 1467 __u8 sack_needed; /* Do we need to sack the peer? */
1467 1468
1468 /* These are capabilities which our peer advertised. */ 1469 /* These are capabilities which our peer advertised. */
1469 __u8 ecn_capable; /* Can peer do ECN? */ 1470 __u8 ecn_capable; /* Can peer do ECN? */
1470 __u8 ipv4_address; /* Peer understands IPv4 addresses? */ 1471 __u8 ipv4_address; /* Peer understands IPv4 addresses? */
1471 __u8 ipv6_address; /* Peer understands IPv6 addresses? */ 1472 __u8 ipv6_address; /* Peer understands IPv6 addresses? */
1472 __u8 hostname_address;/* Peer understands DNS addresses? */ 1473 __u8 hostname_address;/* Peer understands DNS addresses? */
1473 __u8 asconf_capable; /* Does peer support ADDIP? */ 1474 __u8 asconf_capable; /* Does peer support ADDIP? */
1474 __u8 prsctp_capable; /* Can peer do PR-SCTP? */ 1475 __u8 prsctp_capable; /* Can peer do PR-SCTP? */
1475 1476
1476 __u32 adaption_ind; /* Adaption Code point. */ 1477 __u32 adaption_ind; /* Adaption Code point. */
1477 1478
1478 /* This mask is used to disable sending the ASCONF chunk 1479 /* This mask is used to disable sending the ASCONF chunk
1479 * with specified parameter to peer. 1480 * with specified parameter to peer.
1480 */ 1481 */
1481 __u16 addip_disabled_mask; 1482 __u16 addip_disabled_mask;
1482 1483
1483 struct sctp_inithdr i; 1484 struct sctp_inithdr i;
1484 int cookie_len; 1485 int cookie_len;
1485 void *cookie; 1486 void *cookie;
1486 1487
1487 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. 1488 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
1488 * C1) ... "Peer-Serial-Number'. This value MUST be initialized to the 1489 * C1) ... "Peer-Serial-Number'. This value MUST be initialized to the
1489 * Initial TSN Value minus 1 1490 * Initial TSN Value minus 1
1490 */ 1491 */
1491 __u32 addip_serial; 1492 __u32 addip_serial;
1492 } peer; 1493 } peer;
1493 1494
1494 /* State : A state variable indicating what state the 1495 /* State : A state variable indicating what state the
1495 * : association is in, i.e. COOKIE-WAIT, 1496 * : association is in, i.e. COOKIE-WAIT,
1496 * : COOKIE-ECHOED, ESTABLISHED, SHUTDOWN-PENDING, 1497 * : COOKIE-ECHOED, ESTABLISHED, SHUTDOWN-PENDING,
1497 * : SHUTDOWN-SENT, SHUTDOWN-RECEIVED, SHUTDOWN-ACK-SENT. 1498 * : SHUTDOWN-SENT, SHUTDOWN-RECEIVED, SHUTDOWN-ACK-SENT.
1498 * 1499 *
1499 * Note: No "CLOSED" state is illustrated since if a 1500 * Note: No "CLOSED" state is illustrated since if a
1500 * association is "CLOSED" its TCB SHOULD be removed. 1501 * association is "CLOSED" its TCB SHOULD be removed.
1501 * 1502 *
1502 * In this implementation we DO have a CLOSED 1503 * In this implementation we DO have a CLOSED
1503 * state which is used during initiation and shutdown. 1504 * state which is used during initiation and shutdown.
1504 * 1505 *
1505 * State takes values from SCTP_STATE_*. 1506 * State takes values from SCTP_STATE_*.
1506 */ 1507 */
1507 sctp_state_t state; 1508 sctp_state_t state;
1508 1509
1509 /* The cookie life I award for any cookie. */ 1510 /* The cookie life I award for any cookie. */
1510 struct timeval cookie_life; 1511 struct timeval cookie_life;
1511 1512
1512 /* Overall : The overall association error count. 1513 /* Overall : The overall association error count.
1513 * Error Count : [Clear this any time I get something.] 1514 * Error Count : [Clear this any time I get something.]
1514 */ 1515 */
1515 int overall_error_count; 1516 int overall_error_count;
1516 1517
1517 /* These are the association's initial, max, and min RTO values. 1518 /* These are the association's initial, max, and min RTO values.
1518 * These values will be initialized by system defaults, but can 1519 * These values will be initialized by system defaults, but can
1519 * be modified via the SCTP_RTOINFO socket option. 1520 * be modified via the SCTP_RTOINFO socket option.
1520 */ 1521 */
1521 unsigned long rto_initial; 1522 unsigned long rto_initial;
1522 unsigned long rto_max; 1523 unsigned long rto_max;
1523 unsigned long rto_min; 1524 unsigned long rto_min;
1524 1525
1525 /* Maximum number of new data packets that can be sent in a burst. */ 1526 /* Maximum number of new data packets that can be sent in a burst. */
1526 int max_burst; 1527 int max_burst;
1527 1528
1528 /* This is the max_retrans value for the association. This value will 1529 /* This is the max_retrans value for the association. This value will
1529 * be initialized initialized from system defaults, but can be 1530 * be initialized initialized from system defaults, but can be
1530 * modified by the SCTP_ASSOCINFO socket option. 1531 * modified by the SCTP_ASSOCINFO socket option.
1531 */ 1532 */
1532 int max_retrans; 1533 int max_retrans;
1533 1534
1534 /* Maximum number of times the endpoint will retransmit INIT */ 1535 /* Maximum number of times the endpoint will retransmit INIT */
1535 __u16 max_init_attempts; 1536 __u16 max_init_attempts;
1536 1537
1537 /* How many times have we resent an INIT? */ 1538 /* How many times have we resent an INIT? */
1538 __u16 init_retries; 1539 __u16 init_retries;
1539 1540
1540 /* The largest timeout or RTO value to use in attempting an INIT */ 1541 /* The largest timeout or RTO value to use in attempting an INIT */
1541 unsigned long max_init_timeo; 1542 unsigned long max_init_timeo;
1542 1543
1543 /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to 1544 /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
1544 * the destination address every heartbeat interval. This value 1545 * the destination address every heartbeat interval. This value
1545 * will be inherited by all new transports. 1546 * will be inherited by all new transports.
1546 */ 1547 */
1547 unsigned long hbinterval; 1548 unsigned long hbinterval;
1548 1549
1549 /* This is the max_retrans value for new transports in the 1550 /* This is the max_retrans value for new transports in the
1550 * association. 1551 * association.
1551 */ 1552 */
1552 __u16 pathmaxrxt; 1553 __u16 pathmaxrxt;
1553 1554
1554 /* Association : The smallest PMTU discovered for all of the 1555 /* Association : The smallest PMTU discovered for all of the
1555 * PMTU : peer's transport addresses. 1556 * PMTU : peer's transport addresses.
1556 */ 1557 */
1557 __u32 pathmtu; 1558 __u32 pathmtu;
1558 1559
1559 /* Flags controling Heartbeat, SACK delay, and Path MTU Discovery. */ 1560 /* Flags controling Heartbeat, SACK delay, and Path MTU Discovery. */
1560 __u32 param_flags; 1561 __u32 param_flags;
1561 1562
1562 /* SACK delay timeout */ 1563 /* SACK delay timeout */
1563 unsigned long sackdelay; 1564 unsigned long sackdelay;
1564 1565
1565 1566
1566 unsigned long timeouts[SCTP_NUM_TIMEOUT_TYPES]; 1567 unsigned long timeouts[SCTP_NUM_TIMEOUT_TYPES];
1567 struct timer_list timers[SCTP_NUM_TIMEOUT_TYPES]; 1568 struct timer_list timers[SCTP_NUM_TIMEOUT_TYPES];
1568 1569
1569 /* Transport to which SHUTDOWN chunk was last sent. */ 1570 /* Transport to which SHUTDOWN chunk was last sent. */
1570 struct sctp_transport *shutdown_last_sent_to; 1571 struct sctp_transport *shutdown_last_sent_to;
1571 1572
1572 /* Transport to which INIT chunk was last sent. */ 1573 /* Transport to which INIT chunk was last sent. */
1573 struct sctp_transport *init_last_sent_to; 1574 struct sctp_transport *init_last_sent_to;
1574 1575
1575 /* Next TSN : The next TSN number to be assigned to a new 1576 /* Next TSN : The next TSN number to be assigned to a new
1576 * : DATA chunk. This is sent in the INIT or INIT 1577 * : DATA chunk. This is sent in the INIT or INIT
1577 * : ACK chunk to the peer and incremented each 1578 * : ACK chunk to the peer and incremented each
1578 * : time a DATA chunk is assigned a TSN 1579 * : time a DATA chunk is assigned a TSN
1579 * : (normally just prior to transmit or during 1580 * : (normally just prior to transmit or during
1580 * : fragmentation). 1581 * : fragmentation).
1581 */ 1582 */
1582 __u32 next_tsn; 1583 __u32 next_tsn;
1583 1584
1584 /* 1585 /*
1585 * Last Rcvd : This is the last TSN received in sequence. This value 1586 * Last Rcvd : This is the last TSN received in sequence. This value
1586 * TSN : is set initially by taking the peer's Initial TSN, 1587 * TSN : is set initially by taking the peer's Initial TSN,
1587 * : received in the INIT or INIT ACK chunk, and 1588 * : received in the INIT or INIT ACK chunk, and
1588 * : subtracting one from it. 1589 * : subtracting one from it.
1589 * 1590 *
1590 * Most of RFC 2960 refers to this as the Cumulative TSN Ack Point. 1591 * Most of RFC 2960 refers to this as the Cumulative TSN Ack Point.
1591 */ 1592 */
1592 1593
1593 __u32 ctsn_ack_point; 1594 __u32 ctsn_ack_point;
1594 1595
1595 /* PR-SCTP Advanced.Peer.Ack.Point */ 1596 /* PR-SCTP Advanced.Peer.Ack.Point */
1596 __u32 adv_peer_ack_point; 1597 __u32 adv_peer_ack_point;
1597 1598
1598 /* Highest TSN that is acknowledged by incoming SACKs. */ 1599 /* Highest TSN that is acknowledged by incoming SACKs. */
1599 __u32 highest_sacked; 1600 __u32 highest_sacked;
1600 1601
1601 /* The number of unacknowledged data chunks. Reported through 1602 /* The number of unacknowledged data chunks. Reported through
1602 * the SCTP_STATUS sockopt. 1603 * the SCTP_STATUS sockopt.
1603 */ 1604 */
1604 __u16 unack_data; 1605 __u16 unack_data;
1605 1606
1606 /* This is the association's receive buffer space. This value is used 1607 /* This is the association's receive buffer space. This value is used
1607 * to set a_rwnd field in an INIT or a SACK chunk. 1608 * to set a_rwnd field in an INIT or a SACK chunk.
1608 */ 1609 */
1609 __u32 rwnd; 1610 __u32 rwnd;
1610 1611
1611 /* This is the last advertised value of rwnd over a SACK chunk. */ 1612 /* This is the last advertised value of rwnd over a SACK chunk. */
1612 __u32 a_rwnd; 1613 __u32 a_rwnd;
1613 1614
1614 /* Number of bytes by which the rwnd has slopped. The rwnd is allowed 1615 /* Number of bytes by which the rwnd has slopped. The rwnd is allowed
1615 * to slop over a maximum of the association's frag_point. 1616 * to slop over a maximum of the association's frag_point.
1616 */ 1617 */
1617 __u32 rwnd_over; 1618 __u32 rwnd_over;
1618 1619
1619 /* This is the sndbuf size in use for the association. 1620 /* This is the sndbuf size in use for the association.
1620 * This corresponds to the sndbuf size for the association, 1621 * This corresponds to the sndbuf size for the association,
1621 * as specified in the sk->sndbuf. 1622 * as specified in the sk->sndbuf.
1622 */ 1623 */
1623 int sndbuf_used; 1624 int sndbuf_used;
1624 1625
1625 /* This is the amount of memory that this association has allocated 1626 /* This is the amount of memory that this association has allocated
1626 * in the receive path at any given time. 1627 * in the receive path at any given time.
1627 */ 1628 */
1628 atomic_t rmem_alloc; 1629 atomic_t rmem_alloc;
1629 1630
1630 /* This is the wait queue head for send requests waiting on 1631 /* This is the wait queue head for send requests waiting on
1631 * the association sndbuf space. 1632 * the association sndbuf space.
1632 */ 1633 */
1633 wait_queue_head_t wait; 1634 wait_queue_head_t wait;
1634 1635
1635 /* The message size at which SCTP fragmentation will occur. */ 1636 /* The message size at which SCTP fragmentation will occur. */
1636 __u32 frag_point; 1637 __u32 frag_point;
1637 1638
1638 /* Counter used to count INIT errors. */ 1639 /* Counter used to count INIT errors. */
1639 int init_err_counter; 1640 int init_err_counter;
1640 1641
1641 /* Count the number of INIT cycles (for doubling timeout). */ 1642 /* Count the number of INIT cycles (for doubling timeout). */
1642 int init_cycle; 1643 int init_cycle;
1643 1644
1644 /* Default send parameters. */ 1645 /* Default send parameters. */
1645 __u16 default_stream; 1646 __u16 default_stream;
1646 __u16 default_flags; 1647 __u16 default_flags;
1647 __u32 default_ppid; 1648 __u32 default_ppid;
1648 __u32 default_context; 1649 __u32 default_context;
1649 __u32 default_timetolive; 1650 __u32 default_timetolive;
1650 1651
1651 /* This tracks outbound ssn for a given stream. */ 1652 /* This tracks outbound ssn for a given stream. */
1652 struct sctp_ssnmap *ssnmap; 1653 struct sctp_ssnmap *ssnmap;
1653 1654
1654 /* All outbound chunks go through this structure. */ 1655 /* All outbound chunks go through this structure. */
1655 struct sctp_outq outqueue; 1656 struct sctp_outq outqueue;
1656 1657
1657 /* A smart pipe that will handle reordering and fragmentation, 1658 /* A smart pipe that will handle reordering and fragmentation,
1658 * as well as handle passing events up to the ULP. 1659 * as well as handle passing events up to the ULP.
1659 */ 1660 */
1660 struct sctp_ulpq ulpq; 1661 struct sctp_ulpq ulpq;
1661 1662
1662 /* Last TSN that caused an ECNE Chunk to be sent. */ 1663 /* Last TSN that caused an ECNE Chunk to be sent. */
1663 __u32 last_ecne_tsn; 1664 __u32 last_ecne_tsn;
1664 1665
1665 /* Last TSN that caused a CWR Chunk to be sent. */ 1666 /* Last TSN that caused a CWR Chunk to be sent. */
1666 __u32 last_cwr_tsn; 1667 __u32 last_cwr_tsn;
1667 1668
1668 /* How many duplicated TSNs have we seen? */ 1669 /* How many duplicated TSNs have we seen? */
1669 int numduptsns; 1670 int numduptsns;
1670 1671
1671 /* Number of seconds of idle time before an association is closed. 1672 /* Number of seconds of idle time before an association is closed.
1672 * In the association context, this is really used as a boolean 1673 * In the association context, this is really used as a boolean
1673 * since the real timeout is stored in the timeouts array 1674 * since the real timeout is stored in the timeouts array
1674 */ 1675 */
1675 __u32 autoclose; 1676 __u32 autoclose;
1676 1677
1677 /* These are to support 1678 /* These are to support
1678 * "SCTP Extensions for Dynamic Reconfiguration of IP Addresses 1679 * "SCTP Extensions for Dynamic Reconfiguration of IP Addresses
1679 * and Enforcement of Flow and Message Limits" 1680 * and Enforcement of Flow and Message Limits"
1680 * <draft-ietf-tsvwg-addip-sctp-02.txt> 1681 * <draft-ietf-tsvwg-addip-sctp-02.txt>
1681 * or "ADDIP" for short. 1682 * or "ADDIP" for short.
1682 */ 1683 */
1683 1684
1684 1685
1685 1686
1686 /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks 1687 /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
1687 * 1688 *
1688 * R1) One and only one ASCONF Chunk MAY be in transit and 1689 * R1) One and only one ASCONF Chunk MAY be in transit and
1689 * unacknowledged at any one time. If a sender, after sending 1690 * unacknowledged at any one time. If a sender, after sending
1690 * an ASCONF chunk, decides it needs to transfer another 1691 * an ASCONF chunk, decides it needs to transfer another
1691 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk 1692 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
1692 * returns from the previous ASCONF Chunk before sending a 1693 * returns from the previous ASCONF Chunk before sending a
1693 * subsequent ASCONF. Note this restriction binds each side, 1694 * subsequent ASCONF. Note this restriction binds each side,
1694 * so at any time two ASCONF may be in-transit on any given 1695 * so at any time two ASCONF may be in-transit on any given
1695 * association (one sent from each endpoint). 1696 * association (one sent from each endpoint).
1696 * 1697 *
1697 * [This is our one-and-only-one ASCONF in flight. If we do 1698 * [This is our one-and-only-one ASCONF in flight. If we do
1698 * not have an ASCONF in flight, this is NULL.] 1699 * not have an ASCONF in flight, this is NULL.]
1699 */ 1700 */
1700 struct sctp_chunk *addip_last_asconf; 1701 struct sctp_chunk *addip_last_asconf;
1701 1702
1702 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. 1703 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
1703 * 1704 *
1704 * IMPLEMENTATION NOTE: As an optimization a receiver may wish 1705 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
1705 * to save the last ASCONF-ACK for some predetermined period 1706 * to save the last ASCONF-ACK for some predetermined period
1706 * of time and instead of re-processing the ASCONF (with the 1707 * of time and instead of re-processing the ASCONF (with the
1707 * same serial number) it may just re-transmit the 1708 * same serial number) it may just re-transmit the
1708 * ASCONF-ACK. It may wish to use the arrival of a new serial 1709 * ASCONF-ACK. It may wish to use the arrival of a new serial
1709 * number to discard the previously saved ASCONF-ACK or any 1710 * number to discard the previously saved ASCONF-ACK or any
1710 * other means it may choose to expire the saved ASCONF-ACK. 1711 * other means it may choose to expire the saved ASCONF-ACK.
1711 * 1712 *
1712 * [This is our saved ASCONF-ACK. We invalidate it when a new 1713 * [This is our saved ASCONF-ACK. We invalidate it when a new
1713 * ASCONF serial number arrives.] 1714 * ASCONF serial number arrives.]
1714 */ 1715 */
1715 struct sctp_chunk *addip_last_asconf_ack; 1716 struct sctp_chunk *addip_last_asconf_ack;
1716 1717
1717 /* These ASCONF chunks are waiting to be sent. 1718 /* These ASCONF chunks are waiting to be sent.
1718 * 1719 *
1719 * These chunaks can't be pushed to outqueue until receiving 1720 * These chunaks can't be pushed to outqueue until receiving
1720 * ASCONF_ACK for the previous ASCONF indicated by 1721 * ASCONF_ACK for the previous ASCONF indicated by
1721 * addip_last_asconf, so as to guarantee that only one ASCONF 1722 * addip_last_asconf, so as to guarantee that only one ASCONF
1722 * is in flight at any time. 1723 * is in flight at any time.
1723 * 1724 *
1724 * ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks 1725 * ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
1725 * 1726 *
1726 * In defining the ASCONF Chunk transfer procedures, it is 1727 * In defining the ASCONF Chunk transfer procedures, it is
1727 * essential that these transfers MUST NOT cause congestion 1728 * essential that these transfers MUST NOT cause congestion
1728 * within the network. To achieve this, we place these 1729 * within the network. To achieve this, we place these
1729 * restrictions on the transfer of ASCONF Chunks: 1730 * restrictions on the transfer of ASCONF Chunks:
1730 * 1731 *
1731 * R1) One and only one ASCONF Chunk MAY be in transit and 1732 * R1) One and only one ASCONF Chunk MAY be in transit and
1732 * unacknowledged at any one time. If a sender, after sending 1733 * unacknowledged at any one time. If a sender, after sending
1733 * an ASCONF chunk, decides it needs to transfer another 1734 * an ASCONF chunk, decides it needs to transfer another
1734 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk 1735 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
1735 * returns from the previous ASCONF Chunk before sending a 1736 * returns from the previous ASCONF Chunk before sending a
1736 * subsequent ASCONF. Note this restriction binds each side, 1737 * subsequent ASCONF. Note this restriction binds each side,
1737 * so at any time two ASCONF may be in-transit on any given 1738 * so at any time two ASCONF may be in-transit on any given
1738 * association (one sent from each endpoint). 1739 * association (one sent from each endpoint).
1739 * 1740 *
1740 * 1741 *
1741 * [I really think this is EXACTLY the sort of intelligence 1742 * [I really think this is EXACTLY the sort of intelligence
1742 * which already resides in sctp_outq. Please move this 1743 * which already resides in sctp_outq. Please move this
1743 * queue and its supporting logic down there. --piggy] 1744 * queue and its supporting logic down there. --piggy]
1744 */ 1745 */
1745 struct list_head addip_chunk_list; 1746 struct list_head addip_chunk_list;
1746 1747
1747 /* ADDIP Section 4.1 ASCONF Chunk Procedures 1748 /* ADDIP Section 4.1 ASCONF Chunk Procedures
1748 * 1749 *
1749 * A2) A serial number should be assigned to the Chunk. The 1750 * A2) A serial number should be assigned to the Chunk. The
1750 * serial number SHOULD be a monotonically increasing 1751 * serial number SHOULD be a monotonically increasing
1751 * number. The serial number SHOULD be initialized at 1752 * number. The serial number SHOULD be initialized at
1752 * the start of the association to the same value as the 1753 * the start of the association to the same value as the
1753 * Initial TSN and every time a new ASCONF chunk is created 1754 * Initial TSN and every time a new ASCONF chunk is created
1754 * it is incremented by one after assigning the serial number 1755 * it is incremented by one after assigning the serial number
1755 * to the newly created chunk. 1756 * to the newly created chunk.
1756 * 1757 *
1757 * ADDIP 1758 * ADDIP
1758 * 3.1.1 Address/Stream Configuration Change Chunk (ASCONF) 1759 * 3.1.1 Address/Stream Configuration Change Chunk (ASCONF)
1759 * 1760 *
1760 * Serial Number : 32 bits (unsigned integer) 1761 * Serial Number : 32 bits (unsigned integer)
1761 * 1762 *
1762 * This value represents a Serial Number for the ASCONF 1763 * This value represents a Serial Number for the ASCONF
1763 * Chunk. The valid range of Serial Number is from 0 to 1764 * Chunk. The valid range of Serial Number is from 0 to
1764 * 4294967295 (2^32 - 1). Serial Numbers wrap back to 0 1765 * 4294967295 (2^32 - 1). Serial Numbers wrap back to 0
1765 * after reaching 4294967295. 1766 * after reaching 4294967295.
1766 */ 1767 */
1767 __u32 addip_serial; 1768 __u32 addip_serial;
1768 1769
1769 /* Need to send an ECNE Chunk? */ 1770 /* Need to send an ECNE Chunk? */
1770 char need_ecne; 1771 char need_ecne;
1771 1772
1772 /* Is it a temporary association? */ 1773 /* Is it a temporary association? */
1773 char temp; 1774 char temp;
1774 }; 1775 };
1775 1776
1776 1777
1777 /* An eyecatcher for determining if we are really looking at an 1778 /* An eyecatcher for determining if we are really looking at an
1778 * association data structure. 1779 * association data structure.
1779 */ 1780 */
1780 enum { 1781 enum {
1781 SCTP_ASSOC_EYECATCHER = 0xa550c123, 1782 SCTP_ASSOC_EYECATCHER = 0xa550c123,
1782 }; 1783 };
1783 1784
1784 /* Recover the outter association structure. */ 1785 /* Recover the outter association structure. */
1785 static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base) 1786 static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base)
1786 { 1787 {
1787 struct sctp_association *asoc; 1788 struct sctp_association *asoc;
1788 1789
1789 asoc = container_of(base, struct sctp_association, base); 1790 asoc = container_of(base, struct sctp_association, base);
1790 return asoc; 1791 return asoc;
1791 } 1792 }
1792 1793
1793 /* These are function signatures for manipulating associations. */ 1794 /* These are function signatures for manipulating associations. */
1794 1795
1795 1796
1796 struct sctp_association * 1797 struct sctp_association *
1797 sctp_association_new(const struct sctp_endpoint *, const struct sock *, 1798 sctp_association_new(const struct sctp_endpoint *, const struct sock *,
1798 sctp_scope_t scope, gfp_t gfp); 1799 sctp_scope_t scope, gfp_t gfp);
1799 void sctp_association_free(struct sctp_association *); 1800 void sctp_association_free(struct sctp_association *);
1800 void sctp_association_put(struct sctp_association *); 1801 void sctp_association_put(struct sctp_association *);
1801 void sctp_association_hold(struct sctp_association *); 1802 void sctp_association_hold(struct sctp_association *);
1802 1803
1803 struct sctp_transport *sctp_assoc_choose_init_transport( 1804 struct sctp_transport *sctp_assoc_choose_init_transport(
1804 struct sctp_association *); 1805 struct sctp_association *);
1805 struct sctp_transport *sctp_assoc_choose_shutdown_transport( 1806 struct sctp_transport *sctp_assoc_choose_shutdown_transport(
1806 struct sctp_association *); 1807 struct sctp_association *);
1807 void sctp_assoc_update_retran_path(struct sctp_association *); 1808 void sctp_assoc_update_retran_path(struct sctp_association *);
1808 struct sctp_transport *sctp_assoc_lookup_paddr(const struct sctp_association *, 1809 struct sctp_transport *sctp_assoc_lookup_paddr(const struct sctp_association *,
1809 const union sctp_addr *); 1810 const union sctp_addr *);
1810 int sctp_assoc_lookup_laddr(struct sctp_association *asoc, 1811 int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
1811 const union sctp_addr *laddr); 1812 const union sctp_addr *laddr);
1812 struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *, 1813 struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *,
1813 const union sctp_addr *address, 1814 const union sctp_addr *address,
1814 const gfp_t gfp, 1815 const gfp_t gfp,
1815 const int peer_state); 1816 const int peer_state);
1816 void sctp_assoc_del_peer(struct sctp_association *asoc, 1817 void sctp_assoc_del_peer(struct sctp_association *asoc,
1817 const union sctp_addr *addr); 1818 const union sctp_addr *addr);
1818 void sctp_assoc_rm_peer(struct sctp_association *asoc, 1819 void sctp_assoc_rm_peer(struct sctp_association *asoc,
1819 struct sctp_transport *peer); 1820 struct sctp_transport *peer);
1820 void sctp_assoc_control_transport(struct sctp_association *, 1821 void sctp_assoc_control_transport(struct sctp_association *,
1821 struct sctp_transport *, 1822 struct sctp_transport *,
1822 sctp_transport_cmd_t, sctp_sn_error_t); 1823 sctp_transport_cmd_t, sctp_sn_error_t);
1823 struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32); 1824 struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32);
1824 struct sctp_transport *sctp_assoc_is_match(struct sctp_association *, 1825 struct sctp_transport *sctp_assoc_is_match(struct sctp_association *,
1825 const union sctp_addr *, 1826 const union sctp_addr *,
1826 const union sctp_addr *); 1827 const union sctp_addr *);
1827 void sctp_assoc_migrate(struct sctp_association *, struct sock *); 1828 void sctp_assoc_migrate(struct sctp_association *, struct sock *);
1828 void sctp_assoc_update(struct sctp_association *old, 1829 void sctp_assoc_update(struct sctp_association *old,
1829 struct sctp_association *new); 1830 struct sctp_association *new);
1830 1831
1831 __u32 sctp_association_get_next_tsn(struct sctp_association *); 1832 __u32 sctp_association_get_next_tsn(struct sctp_association *);
1832 1833
1833 void sctp_assoc_sync_pmtu(struct sctp_association *); 1834 void sctp_assoc_sync_pmtu(struct sctp_association *);
1834 void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned); 1835 void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned);
1835 void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned); 1836 void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned);
1836 void sctp_assoc_set_primary(struct sctp_association *, 1837 void sctp_assoc_set_primary(struct sctp_association *,
1837 struct sctp_transport *); 1838 struct sctp_transport *);
1838 int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *, 1839 int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *,
1839 gfp_t); 1840 gfp_t);
1840 int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *, 1841 int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *,
1841 struct sctp_cookie*, 1842 struct sctp_cookie*,
1842 gfp_t gfp); 1843 gfp_t gfp);
1843 1844
1844 int sctp_cmp_addr_exact(const union sctp_addr *ss1, 1845 int sctp_cmp_addr_exact(const union sctp_addr *ss1,
1845 const union sctp_addr *ss2); 1846 const union sctp_addr *ss2);
1846 struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc); 1847 struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc);
1847 1848
1848 /* A convenience structure to parse out SCTP specific CMSGs. */ 1849 /* A convenience structure to parse out SCTP specific CMSGs. */
1849 typedef struct sctp_cmsgs { 1850 typedef struct sctp_cmsgs {
1850 struct sctp_initmsg *init; 1851 struct sctp_initmsg *init;
1851 struct sctp_sndrcvinfo *info; 1852 struct sctp_sndrcvinfo *info;
1852 } sctp_cmsgs_t; 1853 } sctp_cmsgs_t;
1853 1854
1854 /* Structure for tracking memory objects */ 1855 /* Structure for tracking memory objects */
1855 typedef struct { 1856 typedef struct {
1856 char *label; 1857 char *label;
1857 atomic_t *counter; 1858 atomic_t *counter;
1858 } sctp_dbg_objcnt_entry_t; 1859 } sctp_dbg_objcnt_entry_t;
1859 1860
1860 #endif /* __sctp_structs_h__ */ 1861 #endif /* __sctp_structs_h__ */
1861 1862
1 /* SCTP kernel reference Implementation 1 /* SCTP kernel reference Implementation
2 * Copyright (c) 1999-2000 Cisco, Inc. 2 * Copyright (c) 1999-2000 Cisco, Inc.
3 * Copyright (c) 1999-2001 Motorola, Inc. 3 * Copyright (c) 1999-2001 Motorola, Inc.
4 * Copyright (c) 2002 International Business Machines, Corp. 4 * Copyright (c) 2002 International Business Machines, Corp.
5 * 5 *
6 * This file is part of the SCTP kernel reference Implementation 6 * This file is part of the SCTP kernel reference Implementation
7 * 7 *
8 * These functions are the methods for accessing the SCTP inqueue. 8 * These functions are the methods for accessing the SCTP inqueue.
9 * 9 *
10 * An SCTP inqueue is a queue into which you push SCTP packets 10 * An SCTP inqueue is a queue into which you push SCTP packets
11 * (which might be bundles or fragments of chunks) and out of which you 11 * (which might be bundles or fragments of chunks) and out of which you
12 * pop SCTP whole chunks. 12 * pop SCTP whole chunks.
13 * 13 *
14 * The SCTP reference implementation is free software; 14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of 15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by 16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option) 17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version. 18 * any later version.
19 * 19 *
20 * The SCTP reference implementation is distributed in the hope that it 20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied 21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************ 22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details. 24 * See the GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to 27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330, 28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA. 29 * Boston, MA 02111-1307, USA.
30 * 30 *
31 * Please send any bug reports or fixes you make to the 31 * Please send any bug reports or fixes you make to the
32 * email address(es): 32 * email address(es):
33 * lksctp developers <lksctp-developers@lists.sourceforge.net> 33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
34 * 34 *
35 * Or submit a bug report through the following website: 35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp 36 * http://www.sf.net/projects/lksctp
37 * 37 *
38 * Written or modified by: 38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org> 39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us> 40 * Karl Knutson <karl@athena.chicago.il.us>
41 * 41 *
42 * Any bugs reported given to us we will try to fix... any fixes shared will 42 * Any bugs reported given to us we will try to fix... any fixes shared will
43 * be incorporated into the next SCTP release. 43 * be incorporated into the next SCTP release.
44 */ 44 */
45 45
46 #include <net/sctp/sctp.h> 46 #include <net/sctp/sctp.h>
47 #include <net/sctp/sm.h> 47 #include <net/sctp/sm.h>
48 #include <linux/interrupt.h> 48 #include <linux/interrupt.h>
49 49
50 /* Initialize an SCTP inqueue. */ 50 /* Initialize an SCTP inqueue. */
51 void sctp_inq_init(struct sctp_inq *queue) 51 void sctp_inq_init(struct sctp_inq *queue)
52 { 52 {
53 INIT_LIST_HEAD(&queue->in_chunk_list); 53 INIT_LIST_HEAD(&queue->in_chunk_list);
54 queue->in_progress = NULL; 54 queue->in_progress = NULL;
55 55
56 /* Create a task for delivering data. */ 56 /* Create a task for delivering data. */
57 INIT_WORK(&queue->immediate, NULL, NULL); 57 INIT_WORK(&queue->immediate, NULL, NULL);
58 58
59 queue->malloced = 0; 59 queue->malloced = 0;
60 } 60 }
61 61
62 /* Release the memory associated with an SCTP inqueue. */ 62 /* Release the memory associated with an SCTP inqueue. */
63 void sctp_inq_free(struct sctp_inq *queue) 63 void sctp_inq_free(struct sctp_inq *queue)
64 { 64 {
65 struct sctp_chunk *chunk, *tmp; 65 struct sctp_chunk *chunk, *tmp;
66 66
67 /* Empty the queue. */ 67 /* Empty the queue. */
68 list_for_each_entry_safe(chunk, tmp, &queue->in_chunk_list, list) { 68 list_for_each_entry_safe(chunk, tmp, &queue->in_chunk_list, list) {
69 list_del_init(&chunk->list); 69 list_del_init(&chunk->list);
70 sctp_chunk_free(chunk); 70 sctp_chunk_free(chunk);
71 } 71 }
72 72
73 /* If there is a packet which is currently being worked on, 73 /* If there is a packet which is currently being worked on,
74 * free it as well. 74 * free it as well.
75 */ 75 */
76 if (queue->in_progress) { 76 if (queue->in_progress) {
77 sctp_chunk_free(queue->in_progress); 77 sctp_chunk_free(queue->in_progress);
78 queue->in_progress = NULL; 78 queue->in_progress = NULL;
79 } 79 }
80 80
81 if (queue->malloced) { 81 if (queue->malloced) {
82 /* Dump the master memory segment. */ 82 /* Dump the master memory segment. */
83 kfree(queue); 83 kfree(queue);
84 } 84 }
85 } 85 }
86 86
87 /* Put a new packet in an SCTP inqueue. 87 /* Put a new packet in an SCTP inqueue.
88 * We assume that packet->sctp_hdr is set and in host byte order. 88 * We assume that packet->sctp_hdr is set and in host byte order.
89 */ 89 */
90 void sctp_inq_push(struct sctp_inq *q, struct sctp_chunk *packet) 90 void sctp_inq_push(struct sctp_inq *q, struct sctp_chunk *packet)
91 { 91 {
92 /* Directly call the packet handling routine. */ 92 /* Directly call the packet handling routine. */
93 93
94 /* We are now calling this either from the soft interrupt 94 /* We are now calling this either from the soft interrupt
95 * or from the backlog processing. 95 * or from the backlog processing.
96 * Eventually, we should clean up inqueue to not rely 96 * Eventually, we should clean up inqueue to not rely
97 * on the BH related data structures. 97 * on the BH related data structures.
98 */ 98 */
99 list_add_tail(&packet->list, &q->in_chunk_list); 99 list_add_tail(&packet->list, &q->in_chunk_list);
100 q->immediate.func(q->immediate.data); 100 q->immediate.func(q->immediate.data);
101 } 101 }
102 102
103 /* Extract a chunk from an SCTP inqueue. 103 /* Extract a chunk from an SCTP inqueue.
104 * 104 *
105 * WARNING: If you need to put the chunk on another queue, you need to 105 * WARNING: If you need to put the chunk on another queue, you need to
106 * make a shallow copy (clone) of it. 106 * make a shallow copy (clone) of it.
107 */ 107 */
108 struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue) 108 struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
109 { 109 {
110 struct sctp_chunk *chunk; 110 struct sctp_chunk *chunk;
111 sctp_chunkhdr_t *ch = NULL; 111 sctp_chunkhdr_t *ch = NULL;
112 112
113 /* The assumption is that we are safe to process the chunks 113 /* The assumption is that we are safe to process the chunks
114 * at this time. 114 * at this time.
115 */ 115 */
116 116
117 if ((chunk = queue->in_progress)) { 117 if ((chunk = queue->in_progress)) {
118 /* There is a packet that we have been working on. 118 /* There is a packet that we have been working on.
119 * Any post processing work to do before we move on? 119 * Any post processing work to do before we move on?
120 */ 120 */
121 if (chunk->singleton || 121 if (chunk->singleton ||
122 chunk->end_of_packet || 122 chunk->end_of_packet ||
123 chunk->pdiscard) { 123 chunk->pdiscard) {
124 sctp_chunk_free(chunk); 124 sctp_chunk_free(chunk);
125 chunk = queue->in_progress = NULL; 125 chunk = queue->in_progress = NULL;
126 } else { 126 } else {
127 /* Nothing to do. Next chunk in the packet, please. */ 127 /* Nothing to do. Next chunk in the packet, please. */
128 ch = (sctp_chunkhdr_t *) chunk->chunk_end; 128 ch = (sctp_chunkhdr_t *) chunk->chunk_end;
129 129
130 /* Force chunk->skb->data to chunk->chunk_end. */ 130 /* Force chunk->skb->data to chunk->chunk_end. */
131 skb_pull(chunk->skb, 131 skb_pull(chunk->skb,
132 chunk->chunk_end - chunk->skb->data); 132 chunk->chunk_end - chunk->skb->data);
133 } 133 }
134 } 134 }
135 135
136 /* Do we need to take the next packet out of the queue to process? */ 136 /* Do we need to take the next packet out of the queue to process? */
137 if (!chunk) { 137 if (!chunk) {
138 struct list_head *entry; 138 struct list_head *entry;
139 139
140 /* Is the queue empty? */ 140 /* Is the queue empty? */
141 if (list_empty(&queue->in_chunk_list)) 141 if (list_empty(&queue->in_chunk_list))
142 return NULL; 142 return NULL;
143 143
144 entry = queue->in_chunk_list.next; 144 entry = queue->in_chunk_list.next;
145 chunk = queue->in_progress = 145 chunk = queue->in_progress =
146 list_entry(entry, struct sctp_chunk, list); 146 list_entry(entry, struct sctp_chunk, list);
147 list_del_init(entry); 147 list_del_init(entry);
148 148
149 /* This is the first chunk in the packet. */ 149 /* This is the first chunk in the packet. */
150 chunk->singleton = 1; 150 chunk->singleton = 1;
151 ch = (sctp_chunkhdr_t *) chunk->skb->data; 151 ch = (sctp_chunkhdr_t *) chunk->skb->data;
152 chunk->data_accepted = 0;
152 } 153 }
153 154
154 chunk->chunk_hdr = ch; 155 chunk->chunk_hdr = ch;
155 chunk->chunk_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length)); 156 chunk->chunk_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
156 /* In the unlikely case of an IP reassembly, the skb could be 157 /* In the unlikely case of an IP reassembly, the skb could be
157 * non-linear. If so, update chunk_end so that it doesn't go past 158 * non-linear. If so, update chunk_end so that it doesn't go past
158 * the skb->tail. 159 * the skb->tail.
159 */ 160 */
160 if (unlikely(skb_is_nonlinear(chunk->skb))) { 161 if (unlikely(skb_is_nonlinear(chunk->skb))) {
161 if (chunk->chunk_end > chunk->skb->tail) 162 if (chunk->chunk_end > chunk->skb->tail)
162 chunk->chunk_end = chunk->skb->tail; 163 chunk->chunk_end = chunk->skb->tail;
163 } 164 }
164 skb_pull(chunk->skb, sizeof(sctp_chunkhdr_t)); 165 skb_pull(chunk->skb, sizeof(sctp_chunkhdr_t));
165 chunk->subh.v = NULL; /* Subheader is no longer valid. */ 166 chunk->subh.v = NULL; /* Subheader is no longer valid. */
166 167
167 if (chunk->chunk_end < chunk->skb->tail) { 168 if (chunk->chunk_end < chunk->skb->tail) {
168 /* This is not a singleton */ 169 /* This is not a singleton */
169 chunk->singleton = 0; 170 chunk->singleton = 0;
170 } else if (chunk->chunk_end > chunk->skb->tail) { 171 } else if (chunk->chunk_end > chunk->skb->tail) {
171 /* RFC 2960, Section 6.10 Bundling 172 /* RFC 2960, Section 6.10 Bundling
172 * 173 *
173 * Partial chunks MUST NOT be placed in an SCTP packet. 174 * Partial chunks MUST NOT be placed in an SCTP packet.
174 * If the receiver detects a partial chunk, it MUST drop 175 * If the receiver detects a partial chunk, it MUST drop
175 * the chunk. 176 * the chunk.
176 * 177 *
177 * Since the end of the chunk is past the end of our buffer 178 * Since the end of the chunk is past the end of our buffer
178 * (which contains the whole packet, we can freely discard 179 * (which contains the whole packet, we can freely discard
179 * the whole packet. 180 * the whole packet.
180 */ 181 */
181 sctp_chunk_free(chunk); 182 sctp_chunk_free(chunk);
182 chunk = queue->in_progress = NULL; 183 chunk = queue->in_progress = NULL;
183 184
184 return NULL; 185 return NULL;
185 } else { 186 } else {
186 /* We are at the end of the packet, so mark the chunk 187 /* We are at the end of the packet, so mark the chunk
187 * in case we need to send a SACK. 188 * in case we need to send a SACK.
188 */ 189 */
189 chunk->end_of_packet = 1; 190 chunk->end_of_packet = 1;
190 } 191 }
191 192
192 SCTP_DEBUG_PRINTK("+++sctp_inq_pop+++ chunk %p[%s]," 193 SCTP_DEBUG_PRINTK("+++sctp_inq_pop+++ chunk %p[%s],"
193 " length %d, skb->len %d\n",chunk, 194 " length %d, skb->len %d\n",chunk,
194 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)), 195 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)),
195 ntohs(chunk->chunk_hdr->length), chunk->skb->len); 196 ntohs(chunk->chunk_hdr->length), chunk->skb->len);
196 return chunk; 197 return chunk;
197 } 198 }
198 199
199 /* Set a top-half handler. 200 /* Set a top-half handler.
200 * 201 *
201 * Originally, we the top-half handler was scheduled as a BH. We now 202 * Originally, we the top-half handler was scheduled as a BH. We now
202 * call the handler directly in sctp_inq_push() at a time that 203 * call the handler directly in sctp_inq_push() at a time that
203 * we know we are lock safe. 204 * we know we are lock safe.
204 * The intent is that this routine will pull stuff out of the 205 * The intent is that this routine will pull stuff out of the
205 * inqueue and process it. 206 * inqueue and process it.
206 */ 207 */
207 void sctp_inq_set_th_handler(struct sctp_inq *q, 208 void sctp_inq_set_th_handler(struct sctp_inq *q,
208 void (*callback)(void *), void *arg) 209 void (*callback)(void *), void *arg)
209 { 210 {
210 INIT_WORK(&q->immediate, callback, arg); 211 INIT_WORK(&q->immediate, callback, arg);
211 } 212 }
212 213
213 214
net/sctp/sm_statefuns.c
1 /* SCTP kernel reference Implementation 1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004 2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc. 3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc. 4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp. 5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp. 6 * Copyright (c) 2002 Nokia Corp.
7 * 7 *
8 * This file is part of the SCTP kernel reference Implementation 8 * This file is part of the SCTP kernel reference Implementation
9 * 9 *
10 * This is part of the SCTP Linux Kernel Reference Implementation. 10 * This is part of the SCTP Linux Kernel Reference Implementation.
11 * 11 *
12 * These are the state functions for the state machine. 12 * These are the state functions for the state machine.
13 * 13 *
14 * The SCTP reference implementation is free software; 14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of 15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by 16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option) 17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version. 18 * any later version.
19 * 19 *
20 * The SCTP reference implementation is distributed in the hope that it 20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied 21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************ 22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details. 24 * See the GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to 27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330, 28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA. 29 * Boston, MA 02111-1307, USA.
30 * 30 *
31 * Please send any bug reports or fixes you make to the 31 * Please send any bug reports or fixes you make to the
32 * email address(es): 32 * email address(es):
33 * lksctp developers <lksctp-developers@lists.sourceforge.net> 33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
34 * 34 *
35 * Or submit a bug report through the following website: 35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp 36 * http://www.sf.net/projects/lksctp
37 * 37 *
38 * Written or modified by: 38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org> 39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us> 40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org> 41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com> 42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com> 43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com> 44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com> 45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com> 46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com> 47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com> 48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com> 49 * Kevin Gao <kevin.gao@intel.com>
50 * 50 *
51 * Any bugs reported given to us we will try to fix... any fixes shared will 51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release. 52 * be incorporated into the next SCTP release.
53 */ 53 */
54 54
55 #include <linux/types.h> 55 #include <linux/types.h>
56 #include <linux/kernel.h> 56 #include <linux/kernel.h>
57 #include <linux/ip.h> 57 #include <linux/ip.h>
58 #include <linux/ipv6.h> 58 #include <linux/ipv6.h>
59 #include <linux/net.h> 59 #include <linux/net.h>
60 #include <linux/inet.h> 60 #include <linux/inet.h>
61 #include <net/sock.h> 61 #include <net/sock.h>
62 #include <net/inet_ecn.h> 62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h> 63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h> 64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h> 65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h> 66 #include <net/sctp/structs.h>
67 67
68 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep, 68 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
69 const struct sctp_association *asoc, 69 const struct sctp_association *asoc,
70 struct sctp_chunk *chunk, 70 struct sctp_chunk *chunk,
71 const void *payload, 71 const void *payload,
72 size_t paylen); 72 size_t paylen);
73 static int sctp_eat_data(const struct sctp_association *asoc, 73 static int sctp_eat_data(const struct sctp_association *asoc,
74 struct sctp_chunk *chunk, 74 struct sctp_chunk *chunk,
75 sctp_cmd_seq_t *commands); 75 sctp_cmd_seq_t *commands);
76 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc, 76 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
77 const struct sctp_chunk *chunk); 77 const struct sctp_chunk *chunk);
78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep, 78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
79 const struct sctp_association *asoc, 79 const struct sctp_association *asoc,
80 const struct sctp_chunk *chunk, 80 const struct sctp_chunk *chunk,
81 sctp_cmd_seq_t *commands, 81 sctp_cmd_seq_t *commands,
82 struct sctp_chunk *err_chunk); 82 struct sctp_chunk *err_chunk);
83 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep, 83 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
84 const struct sctp_association *asoc, 84 const struct sctp_association *asoc,
85 const sctp_subtype_t type, 85 const sctp_subtype_t type,
86 void *arg, 86 void *arg,
87 sctp_cmd_seq_t *commands); 87 sctp_cmd_seq_t *commands);
88 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep, 88 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
89 const struct sctp_association *asoc, 89 const struct sctp_association *asoc,
90 const sctp_subtype_t type, 90 const sctp_subtype_t type,
91 void *arg, 91 void *arg,
92 sctp_cmd_seq_t *commands); 92 sctp_cmd_seq_t *commands);
93 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk); 93 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
94 94
95 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, 95 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
96 __u16 error, 96 __u16 error,
97 const struct sctp_association *asoc, 97 const struct sctp_association *asoc,
98 struct sctp_transport *transport); 98 struct sctp_transport *transport);
99 99
100 static sctp_disposition_t sctp_sf_violation_chunklen( 100 static sctp_disposition_t sctp_sf_violation_chunklen(
101 const struct sctp_endpoint *ep, 101 const struct sctp_endpoint *ep,
102 const struct sctp_association *asoc, 102 const struct sctp_association *asoc,
103 const sctp_subtype_t type, 103 const sctp_subtype_t type,
104 void *arg, 104 void *arg,
105 sctp_cmd_seq_t *commands); 105 sctp_cmd_seq_t *commands);
106 106
107 /* Small helper function that checks if the chunk length 107 /* Small helper function that checks if the chunk length
108 * is of the appropriate length. The 'required_length' argument 108 * is of the appropriate length. The 'required_length' argument
109 * is set to be the size of a specific chunk we are testing. 109 * is set to be the size of a specific chunk we are testing.
110 * Return Values: 1 = Valid length 110 * Return Values: 1 = Valid length
111 * 0 = Invalid length 111 * 0 = Invalid length
112 * 112 *
113 */ 113 */
114 static inline int 114 static inline int
115 sctp_chunk_length_valid(struct sctp_chunk *chunk, 115 sctp_chunk_length_valid(struct sctp_chunk *chunk,
116 __u16 required_length) 116 __u16 required_length)
117 { 117 {
118 __u16 chunk_length = ntohs(chunk->chunk_hdr->length); 118 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
119 119
120 if (unlikely(chunk_length < required_length)) 120 if (unlikely(chunk_length < required_length))
121 return 0; 121 return 0;
122 122
123 return 1; 123 return 1;
124 } 124 }
125 125
126 /********************************************************** 126 /**********************************************************
127 * These are the state functions for handling chunk events. 127 * These are the state functions for handling chunk events.
128 **********************************************************/ 128 **********************************************************/
129 129
130 /* 130 /*
131 * Process the final SHUTDOWN COMPLETE. 131 * Process the final SHUTDOWN COMPLETE.
132 * 132 *
133 * Section: 4 (C) (diagram), 9.2 133 * Section: 4 (C) (diagram), 9.2
134 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify 134 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
135 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be 135 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
136 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint 136 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
137 * should stop the T2-shutdown timer and remove all knowledge of the 137 * should stop the T2-shutdown timer and remove all knowledge of the
138 * association (and thus the association enters the CLOSED state). 138 * association (and thus the association enters the CLOSED state).
139 * 139 *
140 * Verification Tag: 8.5.1(C), sctpimpguide 2.41. 140 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
141 * C) Rules for packet carrying SHUTDOWN COMPLETE: 141 * C) Rules for packet carrying SHUTDOWN COMPLETE:
142 * ... 142 * ...
143 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet 143 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
144 * if the Verification Tag field of the packet matches its own tag and 144 * if the Verification Tag field of the packet matches its own tag and
145 * the T bit is not set 145 * the T bit is not set
146 * OR 146 * OR
147 * it is set to its peer's tag and the T bit is set in the Chunk 147 * it is set to its peer's tag and the T bit is set in the Chunk
148 * Flags. 148 * Flags.
149 * Otherwise, the receiver MUST silently discard the packet 149 * Otherwise, the receiver MUST silently discard the packet
150 * and take no further action. An endpoint MUST ignore the 150 * and take no further action. An endpoint MUST ignore the
151 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state. 151 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
152 * 152 *
153 * Inputs 153 * Inputs
154 * (endpoint, asoc, chunk) 154 * (endpoint, asoc, chunk)
155 * 155 *
156 * Outputs 156 * Outputs
157 * (asoc, reply_msg, msg_up, timers, counters) 157 * (asoc, reply_msg, msg_up, timers, counters)
158 * 158 *
159 * The return value is the disposition of the chunk. 159 * The return value is the disposition of the chunk.
160 */ 160 */
161 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep, 161 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
162 const struct sctp_association *asoc, 162 const struct sctp_association *asoc,
163 const sctp_subtype_t type, 163 const sctp_subtype_t type,
164 void *arg, 164 void *arg,
165 sctp_cmd_seq_t *commands) 165 sctp_cmd_seq_t *commands)
166 { 166 {
167 struct sctp_chunk *chunk = arg; 167 struct sctp_chunk *chunk = arg;
168 struct sctp_ulpevent *ev; 168 struct sctp_ulpevent *ev;
169 169
170 /* RFC 2960 6.10 Bundling 170 /* RFC 2960 6.10 Bundling
171 * 171 *
172 * An endpoint MUST NOT bundle INIT, INIT ACK or 172 * An endpoint MUST NOT bundle INIT, INIT ACK or
173 * SHUTDOWN COMPLETE with any other chunks. 173 * SHUTDOWN COMPLETE with any other chunks.
174 */ 174 */
175 if (!chunk->singleton) 175 if (!chunk->singleton)
176 return SCTP_DISPOSITION_VIOLATION; 176 return SCTP_DISPOSITION_VIOLATION;
177 177
178 if (!sctp_vtag_verify_either(chunk, asoc)) 178 if (!sctp_vtag_verify_either(chunk, asoc))
179 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 179 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
180 180
181 /* RFC 2960 10.2 SCTP-to-ULP 181 /* RFC 2960 10.2 SCTP-to-ULP
182 * 182 *
183 * H) SHUTDOWN COMPLETE notification 183 * H) SHUTDOWN COMPLETE notification
184 * 184 *
185 * When SCTP completes the shutdown procedures (section 9.2) this 185 * When SCTP completes the shutdown procedures (section 9.2) this
186 * notification is passed to the upper layer. 186 * notification is passed to the upper layer.
187 */ 187 */
188 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, 188 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
189 0, 0, 0, GFP_ATOMIC); 189 0, 0, 0, GFP_ATOMIC);
190 if (!ev) 190 if (!ev)
191 goto nomem; 191 goto nomem;
192 192
193 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); 193 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
194 194
195 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint 195 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
196 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is 196 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
197 * not the chunk should be discarded. If the endpoint is in 197 * not the chunk should be discarded. If the endpoint is in
198 * the SHUTDOWN-ACK-SENT state the endpoint should stop the 198 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
199 * T2-shutdown timer and remove all knowledge of the 199 * T2-shutdown timer and remove all knowledge of the
200 * association (and thus the association enters the CLOSED 200 * association (and thus the association enters the CLOSED
201 * state). 201 * state).
202 */ 202 */
203 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 203 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
204 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 204 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
205 205
206 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 206 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
207 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 207 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
208 208
209 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 209 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
210 SCTP_STATE(SCTP_STATE_CLOSED)); 210 SCTP_STATE(SCTP_STATE_CLOSED));
211 211
212 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); 212 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
213 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 213 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
214 214
215 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); 215 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
216 216
217 return SCTP_DISPOSITION_DELETE_TCB; 217 return SCTP_DISPOSITION_DELETE_TCB;
218 218
219 nomem: 219 nomem:
220 return SCTP_DISPOSITION_NOMEM; 220 return SCTP_DISPOSITION_NOMEM;
221 } 221 }
222 222
223 /* 223 /*
224 * Respond to a normal INIT chunk. 224 * Respond to a normal INIT chunk.
225 * We are the side that is being asked for an association. 225 * We are the side that is being asked for an association.
226 * 226 *
227 * Section: 5.1 Normal Establishment of an Association, B 227 * Section: 5.1 Normal Establishment of an Association, B
228 * B) "Z" shall respond immediately with an INIT ACK chunk. The 228 * B) "Z" shall respond immediately with an INIT ACK chunk. The
229 * destination IP address of the INIT ACK MUST be set to the source 229 * destination IP address of the INIT ACK MUST be set to the source
230 * IP address of the INIT to which this INIT ACK is responding. In 230 * IP address of the INIT to which this INIT ACK is responding. In
231 * the response, besides filling in other parameters, "Z" must set the 231 * the response, besides filling in other parameters, "Z" must set the
232 * Verification Tag field to Tag_A, and also provide its own 232 * Verification Tag field to Tag_A, and also provide its own
233 * Verification Tag (Tag_Z) in the Initiate Tag field. 233 * Verification Tag (Tag_Z) in the Initiate Tag field.
234 * 234 *
235 * Verification Tag: Must be 0. 235 * Verification Tag: Must be 0.
236 * 236 *
237 * Inputs 237 * Inputs
238 * (endpoint, asoc, chunk) 238 * (endpoint, asoc, chunk)
239 * 239 *
240 * Outputs 240 * Outputs
241 * (asoc, reply_msg, msg_up, timers, counters) 241 * (asoc, reply_msg, msg_up, timers, counters)
242 * 242 *
243 * The return value is the disposition of the chunk. 243 * The return value is the disposition of the chunk.
244 */ 244 */
245 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep, 245 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
246 const struct sctp_association *asoc, 246 const struct sctp_association *asoc,
247 const sctp_subtype_t type, 247 const sctp_subtype_t type,
248 void *arg, 248 void *arg,
249 sctp_cmd_seq_t *commands) 249 sctp_cmd_seq_t *commands)
250 { 250 {
251 struct sctp_chunk *chunk = arg; 251 struct sctp_chunk *chunk = arg;
252 struct sctp_chunk *repl; 252 struct sctp_chunk *repl;
253 struct sctp_association *new_asoc; 253 struct sctp_association *new_asoc;
254 struct sctp_chunk *err_chunk; 254 struct sctp_chunk *err_chunk;
255 struct sctp_packet *packet; 255 struct sctp_packet *packet;
256 sctp_unrecognized_param_t *unk_param; 256 sctp_unrecognized_param_t *unk_param;
257 struct sock *sk; 257 struct sock *sk;
258 int len; 258 int len;
259 259
260 /* 6.10 Bundling 260 /* 6.10 Bundling
261 * An endpoint MUST NOT bundle INIT, INIT ACK or 261 * An endpoint MUST NOT bundle INIT, INIT ACK or
262 * SHUTDOWN COMPLETE with any other chunks. 262 * SHUTDOWN COMPLETE with any other chunks.
263 * 263 *
264 * IG Section 2.11.2 264 * IG Section 2.11.2
265 * Furthermore, we require that the receiver of an INIT chunk MUST 265 * Furthermore, we require that the receiver of an INIT chunk MUST
266 * enforce these rules by silently discarding an arriving packet 266 * enforce these rules by silently discarding an arriving packet
267 * with an INIT chunk that is bundled with other chunks. 267 * with an INIT chunk that is bundled with other chunks.
268 */ 268 */
269 if (!chunk->singleton) 269 if (!chunk->singleton)
270 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 270 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
271 271
272 /* If the packet is an OOTB packet which is temporarily on the 272 /* If the packet is an OOTB packet which is temporarily on the
273 * control endpoint, respond with an ABORT. 273 * control endpoint, respond with an ABORT.
274 */ 274 */
275 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) 275 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
276 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); 276 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
277 277
278 sk = ep->base.sk; 278 sk = ep->base.sk;
279 /* If the endpoint is not listening or if the number of associations 279 /* If the endpoint is not listening or if the number of associations
280 * on the TCP-style socket exceed the max backlog, respond with an 280 * on the TCP-style socket exceed the max backlog, respond with an
281 * ABORT. 281 * ABORT.
282 */ 282 */
283 if (!sctp_sstate(sk, LISTENING) || 283 if (!sctp_sstate(sk, LISTENING) ||
284 (sctp_style(sk, TCP) && 284 (sctp_style(sk, TCP) &&
285 sk_acceptq_is_full(sk))) 285 sk_acceptq_is_full(sk)))
286 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); 286 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
287 287
288 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification 288 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
289 * Tag. 289 * Tag.
290 */ 290 */
291 if (chunk->sctp_hdr->vtag != 0) 291 if (chunk->sctp_hdr->vtag != 0)
292 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); 292 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
293 293
294 /* Make sure that the INIT chunk has a valid length. 294 /* Make sure that the INIT chunk has a valid length.
295 * Normally, this would cause an ABORT with a Protocol Violation 295 * Normally, this would cause an ABORT with a Protocol Violation
296 * error, but since we don't have an association, we'll 296 * error, but since we don't have an association, we'll
297 * just discard the packet. 297 * just discard the packet.
298 */ 298 */
299 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t))) 299 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
300 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 300 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
301 301
302 /* Verify the INIT chunk before processing it. */ 302 /* Verify the INIT chunk before processing it. */
303 err_chunk = NULL; 303 err_chunk = NULL;
304 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, 304 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
305 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, 305 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
306 &err_chunk)) { 306 &err_chunk)) {
307 /* This chunk contains fatal error. It is to be discarded. 307 /* This chunk contains fatal error. It is to be discarded.
308 * Send an ABORT, with causes if there is any. 308 * Send an ABORT, with causes if there is any.
309 */ 309 */
310 if (err_chunk) { 310 if (err_chunk) {
311 packet = sctp_abort_pkt_new(ep, asoc, arg, 311 packet = sctp_abort_pkt_new(ep, asoc, arg,
312 (__u8 *)(err_chunk->chunk_hdr) + 312 (__u8 *)(err_chunk->chunk_hdr) +
313 sizeof(sctp_chunkhdr_t), 313 sizeof(sctp_chunkhdr_t),
314 ntohs(err_chunk->chunk_hdr->length) - 314 ntohs(err_chunk->chunk_hdr->length) -
315 sizeof(sctp_chunkhdr_t)); 315 sizeof(sctp_chunkhdr_t));
316 316
317 sctp_chunk_free(err_chunk); 317 sctp_chunk_free(err_chunk);
318 318
319 if (packet) { 319 if (packet) {
320 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, 320 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
321 SCTP_PACKET(packet)); 321 SCTP_PACKET(packet));
322 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); 322 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
323 return SCTP_DISPOSITION_CONSUME; 323 return SCTP_DISPOSITION_CONSUME;
324 } else { 324 } else {
325 return SCTP_DISPOSITION_NOMEM; 325 return SCTP_DISPOSITION_NOMEM;
326 } 326 }
327 } else { 327 } else {
328 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, 328 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
329 commands); 329 commands);
330 } 330 }
331 } 331 }
332 332
333 /* Grab the INIT header. */ 333 /* Grab the INIT header. */
334 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data; 334 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
335 335
336 /* Tag the variable length parameters. */ 336 /* Tag the variable length parameters. */
337 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); 337 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
338 338
339 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); 339 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
340 if (!new_asoc) 340 if (!new_asoc)
341 goto nomem; 341 goto nomem;
342 342
343 /* The call, sctp_process_init(), can fail on memory allocation. */ 343 /* The call, sctp_process_init(), can fail on memory allocation. */
344 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, 344 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
345 sctp_source(chunk), 345 sctp_source(chunk),
346 (sctp_init_chunk_t *)chunk->chunk_hdr, 346 (sctp_init_chunk_t *)chunk->chunk_hdr,
347 GFP_ATOMIC)) 347 GFP_ATOMIC))
348 goto nomem_init; 348 goto nomem_init;
349 349
350 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); 350 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
351 351
352 /* B) "Z" shall respond immediately with an INIT ACK chunk. */ 352 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
353 353
354 /* If there are errors need to be reported for unknown parameters, 354 /* If there are errors need to be reported for unknown parameters,
355 * make sure to reserve enough room in the INIT ACK for them. 355 * make sure to reserve enough room in the INIT ACK for them.
356 */ 356 */
357 len = 0; 357 len = 0;
358 if (err_chunk) 358 if (err_chunk)
359 len = ntohs(err_chunk->chunk_hdr->length) - 359 len = ntohs(err_chunk->chunk_hdr->length) -
360 sizeof(sctp_chunkhdr_t); 360 sizeof(sctp_chunkhdr_t);
361 361
362 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0) 362 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
363 goto nomem_ack; 363 goto nomem_ack;
364 364
365 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); 365 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
366 if (!repl) 366 if (!repl)
367 goto nomem_ack; 367 goto nomem_ack;
368 368
369 /* If there are errors need to be reported for unknown parameters, 369 /* If there are errors need to be reported for unknown parameters,
370 * include them in the outgoing INIT ACK as "Unrecognized parameter" 370 * include them in the outgoing INIT ACK as "Unrecognized parameter"
371 * parameter. 371 * parameter.
372 */ 372 */
373 if (err_chunk) { 373 if (err_chunk) {
374 /* Get the "Unrecognized parameter" parameter(s) out of the 374 /* Get the "Unrecognized parameter" parameter(s) out of the
375 * ERROR chunk generated by sctp_verify_init(). Since the 375 * ERROR chunk generated by sctp_verify_init(). Since the
376 * error cause code for "unknown parameter" and the 376 * error cause code for "unknown parameter" and the
377 * "Unrecognized parameter" type is the same, we can 377 * "Unrecognized parameter" type is the same, we can
378 * construct the parameters in INIT ACK by copying the 378 * construct the parameters in INIT ACK by copying the
379 * ERROR causes over. 379 * ERROR causes over.
380 */ 380 */
381 unk_param = (sctp_unrecognized_param_t *) 381 unk_param = (sctp_unrecognized_param_t *)
382 ((__u8 *)(err_chunk->chunk_hdr) + 382 ((__u8 *)(err_chunk->chunk_hdr) +
383 sizeof(sctp_chunkhdr_t)); 383 sizeof(sctp_chunkhdr_t));
384 /* Replace the cause code with the "Unrecognized parameter" 384 /* Replace the cause code with the "Unrecognized parameter"
385 * parameter type. 385 * parameter type.
386 */ 386 */
387 sctp_addto_chunk(repl, len, unk_param); 387 sctp_addto_chunk(repl, len, unk_param);
388 sctp_chunk_free(err_chunk); 388 sctp_chunk_free(err_chunk);
389 } 389 }
390 390
391 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 391 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
392 392
393 /* 393 /*
394 * Note: After sending out INIT ACK with the State Cookie parameter, 394 * Note: After sending out INIT ACK with the State Cookie parameter,
395 * "Z" MUST NOT allocate any resources, nor keep any states for the 395 * "Z" MUST NOT allocate any resources, nor keep any states for the
396 * new association. Otherwise, "Z" will be vulnerable to resource 396 * new association. Otherwise, "Z" will be vulnerable to resource
397 * attacks. 397 * attacks.
398 */ 398 */
399 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); 399 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
400 400
401 return SCTP_DISPOSITION_DELETE_TCB; 401 return SCTP_DISPOSITION_DELETE_TCB;
402 402
403 nomem_ack: 403 nomem_ack:
404 if (err_chunk) 404 if (err_chunk)
405 sctp_chunk_free(err_chunk); 405 sctp_chunk_free(err_chunk);
406 nomem_init: 406 nomem_init:
407 sctp_association_free(new_asoc); 407 sctp_association_free(new_asoc);
408 nomem: 408 nomem:
409 return SCTP_DISPOSITION_NOMEM; 409 return SCTP_DISPOSITION_NOMEM;
410 } 410 }
411 411
412 /* 412 /*
413 * Respond to a normal INIT ACK chunk. 413 * Respond to a normal INIT ACK chunk.
414 * We are the side that is initiating the association. 414 * We are the side that is initiating the association.
415 * 415 *
416 * Section: 5.1 Normal Establishment of an Association, C 416 * Section: 5.1 Normal Establishment of an Association, C
417 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init 417 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
418 * timer and leave COOKIE-WAIT state. "A" shall then send the State 418 * timer and leave COOKIE-WAIT state. "A" shall then send the State
419 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start 419 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
420 * the T1-cookie timer, and enter the COOKIE-ECHOED state. 420 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
421 * 421 *
422 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound 422 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
423 * DATA chunks, but it MUST be the first chunk in the packet and 423 * DATA chunks, but it MUST be the first chunk in the packet and
424 * until the COOKIE ACK is returned the sender MUST NOT send any 424 * until the COOKIE ACK is returned the sender MUST NOT send any
425 * other packets to the peer. 425 * other packets to the peer.
426 * 426 *
427 * Verification Tag: 3.3.3 427 * Verification Tag: 3.3.3
428 * If the value of the Initiate Tag in a received INIT ACK chunk is 428 * If the value of the Initiate Tag in a received INIT ACK chunk is
429 * found to be 0, the receiver MUST treat it as an error and close the 429 * found to be 0, the receiver MUST treat it as an error and close the
430 * association by transmitting an ABORT. 430 * association by transmitting an ABORT.
431 * 431 *
432 * Inputs 432 * Inputs
433 * (endpoint, asoc, chunk) 433 * (endpoint, asoc, chunk)
434 * 434 *
435 * Outputs 435 * Outputs
436 * (asoc, reply_msg, msg_up, timers, counters) 436 * (asoc, reply_msg, msg_up, timers, counters)
437 * 437 *
438 * The return value is the disposition of the chunk. 438 * The return value is the disposition of the chunk.
439 */ 439 */
440 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep, 440 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
441 const struct sctp_association *asoc, 441 const struct sctp_association *asoc,
442 const sctp_subtype_t type, 442 const sctp_subtype_t type,
443 void *arg, 443 void *arg,
444 sctp_cmd_seq_t *commands) 444 sctp_cmd_seq_t *commands)
445 { 445 {
446 struct sctp_chunk *chunk = arg; 446 struct sctp_chunk *chunk = arg;
447 sctp_init_chunk_t *initchunk; 447 sctp_init_chunk_t *initchunk;
448 __u32 init_tag; 448 __u32 init_tag;
449 struct sctp_chunk *err_chunk; 449 struct sctp_chunk *err_chunk;
450 struct sctp_packet *packet; 450 struct sctp_packet *packet;
451 sctp_disposition_t ret; 451 sctp_disposition_t ret;
452 452
453 if (!sctp_vtag_verify(chunk, asoc)) 453 if (!sctp_vtag_verify(chunk, asoc))
454 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 454 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
455 455
456 /* Make sure that the INIT-ACK chunk has a valid length */ 456 /* Make sure that the INIT-ACK chunk has a valid length */
457 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t))) 457 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
458 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 458 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
459 commands); 459 commands);
460 /* 6.10 Bundling 460 /* 6.10 Bundling
461 * An endpoint MUST NOT bundle INIT, INIT ACK or 461 * An endpoint MUST NOT bundle INIT, INIT ACK or
462 * SHUTDOWN COMPLETE with any other chunks. 462 * SHUTDOWN COMPLETE with any other chunks.
463 */ 463 */
464 if (!chunk->singleton) 464 if (!chunk->singleton)
465 return SCTP_DISPOSITION_VIOLATION; 465 return SCTP_DISPOSITION_VIOLATION;
466 466
467 /* Grab the INIT header. */ 467 /* Grab the INIT header. */
468 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data; 468 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
469 469
470 init_tag = ntohl(chunk->subh.init_hdr->init_tag); 470 init_tag = ntohl(chunk->subh.init_hdr->init_tag);
471 471
472 /* Verification Tag: 3.3.3 472 /* Verification Tag: 3.3.3
473 * If the value of the Initiate Tag in a received INIT ACK 473 * If the value of the Initiate Tag in a received INIT ACK
474 * chunk is found to be 0, the receiver MUST treat it as an 474 * chunk is found to be 0, the receiver MUST treat it as an
475 * error and close the association by transmitting an ABORT. 475 * error and close the association by transmitting an ABORT.
476 */ 476 */
477 if (!init_tag) { 477 if (!init_tag) {
478 struct sctp_chunk *reply = sctp_make_abort(asoc, chunk, 0); 478 struct sctp_chunk *reply = sctp_make_abort(asoc, chunk, 0);
479 if (!reply) 479 if (!reply)
480 goto nomem; 480 goto nomem;
481 481
482 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 482 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
483 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 483 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
484 SCTP_STATE(SCTP_STATE_CLOSED)); 484 SCTP_STATE(SCTP_STATE_CLOSED));
485 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 485 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
486 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); 486 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
487 return SCTP_DISPOSITION_DELETE_TCB; 487 return SCTP_DISPOSITION_DELETE_TCB;
488 } 488 }
489 489
490 /* Verify the INIT chunk before processing it. */ 490 /* Verify the INIT chunk before processing it. */
491 err_chunk = NULL; 491 err_chunk = NULL;
492 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, 492 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
493 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, 493 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
494 &err_chunk)) { 494 &err_chunk)) {
495 495
496 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 496 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
497 497
498 /* This chunk contains fatal error. It is to be discarded. 498 /* This chunk contains fatal error. It is to be discarded.
499 * Send an ABORT, with causes if there is any. 499 * Send an ABORT, with causes if there is any.
500 */ 500 */
501 if (err_chunk) { 501 if (err_chunk) {
502 packet = sctp_abort_pkt_new(ep, asoc, arg, 502 packet = sctp_abort_pkt_new(ep, asoc, arg,
503 (__u8 *)(err_chunk->chunk_hdr) + 503 (__u8 *)(err_chunk->chunk_hdr) +
504 sizeof(sctp_chunkhdr_t), 504 sizeof(sctp_chunkhdr_t),
505 ntohs(err_chunk->chunk_hdr->length) - 505 ntohs(err_chunk->chunk_hdr->length) -
506 sizeof(sctp_chunkhdr_t)); 506 sizeof(sctp_chunkhdr_t));
507 507
508 sctp_chunk_free(err_chunk); 508 sctp_chunk_free(err_chunk);
509 509
510 if (packet) { 510 if (packet) {
511 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, 511 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
512 SCTP_PACKET(packet)); 512 SCTP_PACKET(packet));
513 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); 513 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
514 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 514 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
515 SCTP_STATE(SCTP_STATE_CLOSED)); 515 SCTP_STATE(SCTP_STATE_CLOSED));
516 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, 516 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
517 SCTP_NULL()); 517 SCTP_NULL());
518 return SCTP_DISPOSITION_CONSUME; 518 return SCTP_DISPOSITION_CONSUME;
519 } else { 519 } else {
520 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 520 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
521 SCTP_STATE(SCTP_STATE_CLOSED)); 521 SCTP_STATE(SCTP_STATE_CLOSED));
522 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, 522 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
523 SCTP_NULL()); 523 SCTP_NULL());
524 return SCTP_DISPOSITION_NOMEM; 524 return SCTP_DISPOSITION_NOMEM;
525 } 525 }
526 } else { 526 } else {
527 ret = sctp_sf_tabort_8_4_8(ep, asoc, type, arg, 527 ret = sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
528 commands); 528 commands);
529 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 529 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
530 SCTP_STATE(SCTP_STATE_CLOSED)); 530 SCTP_STATE(SCTP_STATE_CLOSED));
531 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, 531 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
532 SCTP_NULL()); 532 SCTP_NULL());
533 return ret; 533 return ret;
534 } 534 }
535 } 535 }
536 536
537 /* Tag the variable length parameters. Note that we never 537 /* Tag the variable length parameters. Note that we never
538 * convert the parameters in an INIT chunk. 538 * convert the parameters in an INIT chunk.
539 */ 539 */
540 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); 540 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
541 541
542 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr; 542 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
543 543
544 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT, 544 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
545 SCTP_PEER_INIT(initchunk)); 545 SCTP_PEER_INIT(initchunk));
546 546
547 /* Reset init error count upon receipt of INIT-ACK. */ 547 /* Reset init error count upon receipt of INIT-ACK. */
548 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); 548 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
549 549
550 /* 5.1 C) "A" shall stop the T1-init timer and leave 550 /* 5.1 C) "A" shall stop the T1-init timer and leave
551 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie 551 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
552 * timer, and enter the COOKIE-ECHOED state. 552 * timer, and enter the COOKIE-ECHOED state.
553 */ 553 */
554 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 554 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
555 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 555 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
556 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 556 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
557 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); 557 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
558 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 558 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
559 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED)); 559 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
560 560
561 /* 5.1 C) "A" shall then send the State Cookie received in the 561 /* 5.1 C) "A" shall then send the State Cookie received in the
562 * INIT ACK chunk in a COOKIE ECHO chunk, ... 562 * INIT ACK chunk in a COOKIE ECHO chunk, ...
563 */ 563 */
564 /* If there is any errors to report, send the ERROR chunk generated 564 /* If there is any errors to report, send the ERROR chunk generated
565 * for unknown parameters as well. 565 * for unknown parameters as well.
566 */ 566 */
567 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO, 567 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
568 SCTP_CHUNK(err_chunk)); 568 SCTP_CHUNK(err_chunk));
569 569
570 return SCTP_DISPOSITION_CONSUME; 570 return SCTP_DISPOSITION_CONSUME;
571 571
572 nomem: 572 nomem:
573 return SCTP_DISPOSITION_NOMEM; 573 return SCTP_DISPOSITION_NOMEM;
574 } 574 }
575 575
576 /* 576 /*
577 * Respond to a normal COOKIE ECHO chunk. 577 * Respond to a normal COOKIE ECHO chunk.
578 * We are the side that is being asked for an association. 578 * We are the side that is being asked for an association.
579 * 579 *
580 * Section: 5.1 Normal Establishment of an Association, D 580 * Section: 5.1 Normal Establishment of an Association, D
581 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply 581 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
582 * with a COOKIE ACK chunk after building a TCB and moving to 582 * with a COOKIE ACK chunk after building a TCB and moving to
583 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with 583 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
584 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK 584 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
585 * chunk MUST be the first chunk in the packet. 585 * chunk MUST be the first chunk in the packet.
586 * 586 *
587 * IMPLEMENTATION NOTE: An implementation may choose to send the 587 * IMPLEMENTATION NOTE: An implementation may choose to send the
588 * Communication Up notification to the SCTP user upon reception 588 * Communication Up notification to the SCTP user upon reception
589 * of a valid COOKIE ECHO chunk. 589 * of a valid COOKIE ECHO chunk.
590 * 590 *
591 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules 591 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
592 * D) Rules for packet carrying a COOKIE ECHO 592 * D) Rules for packet carrying a COOKIE ECHO
593 * 593 *
594 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the 594 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
595 * Initial Tag received in the INIT ACK. 595 * Initial Tag received in the INIT ACK.
596 * 596 *
597 * - The receiver of a COOKIE ECHO follows the procedures in Section 5. 597 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
598 * 598 *
599 * Inputs 599 * Inputs
600 * (endpoint, asoc, chunk) 600 * (endpoint, asoc, chunk)
601 * 601 *
602 * Outputs 602 * Outputs
603 * (asoc, reply_msg, msg_up, timers, counters) 603 * (asoc, reply_msg, msg_up, timers, counters)
604 * 604 *
605 * The return value is the disposition of the chunk. 605 * The return value is the disposition of the chunk.
606 */ 606 */
607 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep, 607 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
608 const struct sctp_association *asoc, 608 const struct sctp_association *asoc,
609 const sctp_subtype_t type, void *arg, 609 const sctp_subtype_t type, void *arg,
610 sctp_cmd_seq_t *commands) 610 sctp_cmd_seq_t *commands)
611 { 611 {
612 struct sctp_chunk *chunk = arg; 612 struct sctp_chunk *chunk = arg;
613 struct sctp_association *new_asoc; 613 struct sctp_association *new_asoc;
614 sctp_init_chunk_t *peer_init; 614 sctp_init_chunk_t *peer_init;
615 struct sctp_chunk *repl; 615 struct sctp_chunk *repl;
616 struct sctp_ulpevent *ev; 616 struct sctp_ulpevent *ev;
617 int error = 0; 617 int error = 0;
618 struct sctp_chunk *err_chk_p; 618 struct sctp_chunk *err_chk_p;
619 619
620 /* If the packet is an OOTB packet which is temporarily on the 620 /* If the packet is an OOTB packet which is temporarily on the
621 * control endpoint, respond with an ABORT. 621 * control endpoint, respond with an ABORT.
622 */ 622 */
623 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) 623 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
624 return sctp_sf_ootb(ep, asoc, type, arg, commands); 624 return sctp_sf_ootb(ep, asoc, type, arg, commands);
625 625
626 /* Make sure that the COOKIE_ECHO chunk has a valid length. 626 /* Make sure that the COOKIE_ECHO chunk has a valid length.
627 * In this case, we check that we have enough for at least a 627 * In this case, we check that we have enough for at least a
628 * chunk header. More detailed verification is done 628 * chunk header. More detailed verification is done
629 * in sctp_unpack_cookie(). 629 * in sctp_unpack_cookie().
630 */ 630 */
631 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) 631 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
632 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 632 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
633 633
634 /* "Decode" the chunk. We have no optional parameters so we 634 /* "Decode" the chunk. We have no optional parameters so we
635 * are in good shape. 635 * are in good shape.
636 */ 636 */
637 chunk->subh.cookie_hdr = 637 chunk->subh.cookie_hdr =
638 (struct sctp_signed_cookie *)chunk->skb->data; 638 (struct sctp_signed_cookie *)chunk->skb->data;
639 skb_pull(chunk->skb, 639 skb_pull(chunk->skb,
640 ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t)); 640 ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t));
641 641
642 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint 642 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
643 * "Z" will reply with a COOKIE ACK chunk after building a TCB 643 * "Z" will reply with a COOKIE ACK chunk after building a TCB
644 * and moving to the ESTABLISHED state. 644 * and moving to the ESTABLISHED state.
645 */ 645 */
646 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, 646 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
647 &err_chk_p); 647 &err_chk_p);
648 648
649 /* FIXME: 649 /* FIXME:
650 * If the re-build failed, what is the proper error path 650 * If the re-build failed, what is the proper error path
651 * from here? 651 * from here?
652 * 652 *
653 * [We should abort the association. --piggy] 653 * [We should abort the association. --piggy]
654 */ 654 */
655 if (!new_asoc) { 655 if (!new_asoc) {
656 /* FIXME: Several errors are possible. A bad cookie should 656 /* FIXME: Several errors are possible. A bad cookie should
657 * be silently discarded, but think about logging it too. 657 * be silently discarded, but think about logging it too.
658 */ 658 */
659 switch (error) { 659 switch (error) {
660 case -SCTP_IERROR_NOMEM: 660 case -SCTP_IERROR_NOMEM:
661 goto nomem; 661 goto nomem;
662 662
663 case -SCTP_IERROR_STALE_COOKIE: 663 case -SCTP_IERROR_STALE_COOKIE:
664 sctp_send_stale_cookie_err(ep, asoc, chunk, commands, 664 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
665 err_chk_p); 665 err_chk_p);
666 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 666 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
667 667
668 case -SCTP_IERROR_BAD_SIG: 668 case -SCTP_IERROR_BAD_SIG:
669 default: 669 default:
670 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 670 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
671 }; 671 };
672 } 672 }
673 673
674 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); 674 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
675 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 675 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
676 SCTP_STATE(SCTP_STATE_ESTABLISHED)); 676 SCTP_STATE(SCTP_STATE_ESTABLISHED));
677 SCTP_INC_STATS(SCTP_MIB_CURRESTAB); 677 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
678 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS); 678 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
679 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); 679 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
680 680
681 if (new_asoc->autoclose) 681 if (new_asoc->autoclose)
682 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 682 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
683 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 683 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
684 684
685 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); 685 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
686 686
687 /* Re-build the bind address for the association is done in 687 /* Re-build the bind address for the association is done in
688 * the sctp_unpack_cookie() already. 688 * the sctp_unpack_cookie() already.
689 */ 689 */
690 /* This is a brand-new association, so these are not yet side 690 /* This is a brand-new association, so these are not yet side
691 * effects--it is safe to run them here. 691 * effects--it is safe to run them here.
692 */ 692 */
693 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; 693 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
694 694
695 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, 695 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
696 &chunk->subh.cookie_hdr->c.peer_addr, 696 &chunk->subh.cookie_hdr->c.peer_addr,
697 peer_init, GFP_ATOMIC)) 697 peer_init, GFP_ATOMIC))
698 goto nomem_init; 698 goto nomem_init;
699 699
700 repl = sctp_make_cookie_ack(new_asoc, chunk); 700 repl = sctp_make_cookie_ack(new_asoc, chunk);
701 if (!repl) 701 if (!repl)
702 goto nomem_repl; 702 goto nomem_repl;
703 703
704 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 704 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
705 705
706 /* RFC 2960 5.1 Normal Establishment of an Association 706 /* RFC 2960 5.1 Normal Establishment of an Association
707 * 707 *
708 * D) IMPLEMENTATION NOTE: An implementation may choose to 708 * D) IMPLEMENTATION NOTE: An implementation may choose to
709 * send the Communication Up notification to the SCTP user 709 * send the Communication Up notification to the SCTP user
710 * upon reception of a valid COOKIE ECHO chunk. 710 * upon reception of a valid COOKIE ECHO chunk.
711 */ 711 */
712 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0, 712 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
713 new_asoc->c.sinit_num_ostreams, 713 new_asoc->c.sinit_num_ostreams,
714 new_asoc->c.sinit_max_instreams, 714 new_asoc->c.sinit_max_instreams,
715 GFP_ATOMIC); 715 GFP_ATOMIC);
716 if (!ev) 716 if (!ev)
717 goto nomem_ev; 717 goto nomem_ev;
718 718
719 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); 719 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
720 720
721 /* Sockets API Draft Section 5.3.1.6 721 /* Sockets API Draft Section 5.3.1.6
722 * When a peer sends a Adaption Layer Indication parameter , SCTP 722 * When a peer sends a Adaption Layer Indication parameter , SCTP
723 * delivers this notification to inform the application that of the 723 * delivers this notification to inform the application that of the
724 * peers requested adaption layer. 724 * peers requested adaption layer.
725 */ 725 */
726 if (new_asoc->peer.adaption_ind) { 726 if (new_asoc->peer.adaption_ind) {
727 ev = sctp_ulpevent_make_adaption_indication(new_asoc, 727 ev = sctp_ulpevent_make_adaption_indication(new_asoc,
728 GFP_ATOMIC); 728 GFP_ATOMIC);
729 if (!ev) 729 if (!ev)
730 goto nomem_ev; 730 goto nomem_ev;
731 731
732 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, 732 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
733 SCTP_ULPEVENT(ev)); 733 SCTP_ULPEVENT(ev));
734 } 734 }
735 735
736 return SCTP_DISPOSITION_CONSUME; 736 return SCTP_DISPOSITION_CONSUME;
737 737
738 nomem_ev: 738 nomem_ev:
739 sctp_chunk_free(repl); 739 sctp_chunk_free(repl);
740 nomem_repl: 740 nomem_repl:
741 nomem_init: 741 nomem_init:
742 sctp_association_free(new_asoc); 742 sctp_association_free(new_asoc);
743 nomem: 743 nomem:
744 return SCTP_DISPOSITION_NOMEM; 744 return SCTP_DISPOSITION_NOMEM;
745 } 745 }
746 746
747 /* 747 /*
748 * Respond to a normal COOKIE ACK chunk. 748 * Respond to a normal COOKIE ACK chunk.
749 * We are the side that is being asked for an association. 749 * We are the side that is being asked for an association.
750 * 750 *
751 * RFC 2960 5.1 Normal Establishment of an Association 751 * RFC 2960 5.1 Normal Establishment of an Association
752 * 752 *
753 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the 753 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
754 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie 754 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
755 * timer. It may also notify its ULP about the successful 755 * timer. It may also notify its ULP about the successful
756 * establishment of the association with a Communication Up 756 * establishment of the association with a Communication Up
757 * notification (see Section 10). 757 * notification (see Section 10).
758 * 758 *
759 * Verification Tag: 759 * Verification Tag:
760 * Inputs 760 * Inputs
761 * (endpoint, asoc, chunk) 761 * (endpoint, asoc, chunk)
762 * 762 *
763 * Outputs 763 * Outputs
764 * (asoc, reply_msg, msg_up, timers, counters) 764 * (asoc, reply_msg, msg_up, timers, counters)
765 * 765 *
766 * The return value is the disposition of the chunk. 766 * The return value is the disposition of the chunk.
767 */ 767 */
768 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep, 768 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
769 const struct sctp_association *asoc, 769 const struct sctp_association *asoc,
770 const sctp_subtype_t type, void *arg, 770 const sctp_subtype_t type, void *arg,
771 sctp_cmd_seq_t *commands) 771 sctp_cmd_seq_t *commands)
772 { 772 {
773 struct sctp_chunk *chunk = arg; 773 struct sctp_chunk *chunk = arg;
774 struct sctp_ulpevent *ev; 774 struct sctp_ulpevent *ev;
775 775
776 if (!sctp_vtag_verify(chunk, asoc)) 776 if (!sctp_vtag_verify(chunk, asoc))
777 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 777 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
778 778
779 /* Verify that the chunk length for the COOKIE-ACK is OK. 779 /* Verify that the chunk length for the COOKIE-ACK is OK.
780 * If we don't do this, any bundled chunks may be junked. 780 * If we don't do this, any bundled chunks may be junked.
781 */ 781 */
782 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) 782 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
783 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 783 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
784 commands); 784 commands);
785 785
786 /* Reset init error count upon receipt of COOKIE-ACK, 786 /* Reset init error count upon receipt of COOKIE-ACK,
787 * to avoid problems with the managemement of this 787 * to avoid problems with the managemement of this
788 * counter in stale cookie situations when a transition back 788 * counter in stale cookie situations when a transition back
789 * from the COOKIE-ECHOED state to the COOKIE-WAIT 789 * from the COOKIE-ECHOED state to the COOKIE-WAIT
790 * state is performed. 790 * state is performed.
791 */ 791 */
792 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); 792 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
793 793
794 /* RFC 2960 5.1 Normal Establishment of an Association 794 /* RFC 2960 5.1 Normal Establishment of an Association
795 * 795 *
796 * E) Upon reception of the COOKIE ACK, endpoint "A" will move 796 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
797 * from the COOKIE-ECHOED state to the ESTABLISHED state, 797 * from the COOKIE-ECHOED state to the ESTABLISHED state,
798 * stopping the T1-cookie timer. 798 * stopping the T1-cookie timer.
799 */ 799 */
800 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 800 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
801 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); 801 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
802 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 802 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
803 SCTP_STATE(SCTP_STATE_ESTABLISHED)); 803 SCTP_STATE(SCTP_STATE_ESTABLISHED));
804 SCTP_INC_STATS(SCTP_MIB_CURRESTAB); 804 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
805 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS); 805 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
806 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); 806 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
807 if (asoc->autoclose) 807 if (asoc->autoclose)
808 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 808 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
809 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 809 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
810 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); 810 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
811 811
812 /* It may also notify its ULP about the successful 812 /* It may also notify its ULP about the successful
813 * establishment of the association with a Communication Up 813 * establishment of the association with a Communication Up
814 * notification (see Section 10). 814 * notification (see Section 10).
815 */ 815 */
816 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 816 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
817 0, asoc->c.sinit_num_ostreams, 817 0, asoc->c.sinit_num_ostreams,
818 asoc->c.sinit_max_instreams, 818 asoc->c.sinit_max_instreams,
819 GFP_ATOMIC); 819 GFP_ATOMIC);
820 820
821 if (!ev) 821 if (!ev)
822 goto nomem; 822 goto nomem;
823 823
824 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); 824 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
825 825
826 /* Sockets API Draft Section 5.3.1.6 826 /* Sockets API Draft Section 5.3.1.6
827 * When a peer sends a Adaption Layer Indication parameter , SCTP 827 * When a peer sends a Adaption Layer Indication parameter , SCTP
828 * delivers this notification to inform the application that of the 828 * delivers this notification to inform the application that of the
829 * peers requested adaption layer. 829 * peers requested adaption layer.
830 */ 830 */
831 if (asoc->peer.adaption_ind) { 831 if (asoc->peer.adaption_ind) {
832 ev = sctp_ulpevent_make_adaption_indication(asoc, GFP_ATOMIC); 832 ev = sctp_ulpevent_make_adaption_indication(asoc, GFP_ATOMIC);
833 if (!ev) 833 if (!ev)
834 goto nomem; 834 goto nomem;
835 835
836 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, 836 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
837 SCTP_ULPEVENT(ev)); 837 SCTP_ULPEVENT(ev));
838 } 838 }
839 839
840 return SCTP_DISPOSITION_CONSUME; 840 return SCTP_DISPOSITION_CONSUME;
841 nomem: 841 nomem:
842 return SCTP_DISPOSITION_NOMEM; 842 return SCTP_DISPOSITION_NOMEM;
843 } 843 }
844 844
845 /* Generate and sendout a heartbeat packet. */ 845 /* Generate and sendout a heartbeat packet. */
846 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep, 846 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
847 const struct sctp_association *asoc, 847 const struct sctp_association *asoc,
848 const sctp_subtype_t type, 848 const sctp_subtype_t type,
849 void *arg, 849 void *arg,
850 sctp_cmd_seq_t *commands) 850 sctp_cmd_seq_t *commands)
851 { 851 {
852 struct sctp_transport *transport = (struct sctp_transport *) arg; 852 struct sctp_transport *transport = (struct sctp_transport *) arg;
853 struct sctp_chunk *reply; 853 struct sctp_chunk *reply;
854 sctp_sender_hb_info_t hbinfo; 854 sctp_sender_hb_info_t hbinfo;
855 size_t paylen = 0; 855 size_t paylen = 0;
856 856
857 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO; 857 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
858 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t)); 858 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
859 hbinfo.daddr = transport->ipaddr; 859 hbinfo.daddr = transport->ipaddr;
860 hbinfo.sent_at = jiffies; 860 hbinfo.sent_at = jiffies;
861 861
862 /* Send a heartbeat to our peer. */ 862 /* Send a heartbeat to our peer. */
863 paylen = sizeof(sctp_sender_hb_info_t); 863 paylen = sizeof(sctp_sender_hb_info_t);
864 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen); 864 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
865 if (!reply) 865 if (!reply)
866 return SCTP_DISPOSITION_NOMEM; 866 return SCTP_DISPOSITION_NOMEM;
867 867
868 /* Set rto_pending indicating that an RTT measurement 868 /* Set rto_pending indicating that an RTT measurement
869 * is started with this heartbeat chunk. 869 * is started with this heartbeat chunk.
870 */ 870 */
871 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING, 871 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
872 SCTP_TRANSPORT(transport)); 872 SCTP_TRANSPORT(transport));
873 873
874 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 874 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
875 return SCTP_DISPOSITION_CONSUME; 875 return SCTP_DISPOSITION_CONSUME;
876 } 876 }
877 877
878 /* Generate a HEARTBEAT packet on the given transport. */ 878 /* Generate a HEARTBEAT packet on the given transport. */
879 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep, 879 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
880 const struct sctp_association *asoc, 880 const struct sctp_association *asoc,
881 const sctp_subtype_t type, 881 const sctp_subtype_t type,
882 void *arg, 882 void *arg,
883 sctp_cmd_seq_t *commands) 883 sctp_cmd_seq_t *commands)
884 { 884 {
885 struct sctp_transport *transport = (struct sctp_transport *) arg; 885 struct sctp_transport *transport = (struct sctp_transport *) arg;
886 886
887 if (asoc->overall_error_count >= asoc->max_retrans) { 887 if (asoc->overall_error_count >= asoc->max_retrans) {
888 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ 888 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
889 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 889 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
890 SCTP_U32(SCTP_ERROR_NO_ERROR)); 890 SCTP_U32(SCTP_ERROR_NO_ERROR));
891 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 891 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
892 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 892 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
893 return SCTP_DISPOSITION_DELETE_TCB; 893 return SCTP_DISPOSITION_DELETE_TCB;
894 } 894 }
895 895
896 /* Section 3.3.5. 896 /* Section 3.3.5.
897 * The Sender-specific Heartbeat Info field should normally include 897 * The Sender-specific Heartbeat Info field should normally include
898 * information about the sender's current time when this HEARTBEAT 898 * information about the sender's current time when this HEARTBEAT
899 * chunk is sent and the destination transport address to which this 899 * chunk is sent and the destination transport address to which this
900 * HEARTBEAT is sent (see Section 8.3). 900 * HEARTBEAT is sent (see Section 8.3).
901 */ 901 */
902 902
903 if (transport->param_flags & SPP_HB_ENABLE) { 903 if (transport->param_flags & SPP_HB_ENABLE) {
904 if (SCTP_DISPOSITION_NOMEM == 904 if (SCTP_DISPOSITION_NOMEM ==
905 sctp_sf_heartbeat(ep, asoc, type, arg, 905 sctp_sf_heartbeat(ep, asoc, type, arg,
906 commands)) 906 commands))
907 return SCTP_DISPOSITION_NOMEM; 907 return SCTP_DISPOSITION_NOMEM;
908 /* Set transport error counter and association error counter 908 /* Set transport error counter and association error counter
909 * when sending heartbeat. 909 * when sending heartbeat.
910 */ 910 */
911 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET, 911 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
912 SCTP_TRANSPORT(transport)); 912 SCTP_TRANSPORT(transport));
913 } 913 }
914 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE, 914 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
915 SCTP_TRANSPORT(transport)); 915 SCTP_TRANSPORT(transport));
916 916
917 return SCTP_DISPOSITION_CONSUME; 917 return SCTP_DISPOSITION_CONSUME;
918 } 918 }
919 919
920 /* 920 /*
921 * Process an heartbeat request. 921 * Process an heartbeat request.
922 * 922 *
923 * Section: 8.3 Path Heartbeat 923 * Section: 8.3 Path Heartbeat
924 * The receiver of the HEARTBEAT should immediately respond with a 924 * The receiver of the HEARTBEAT should immediately respond with a
925 * HEARTBEAT ACK that contains the Heartbeat Information field copied 925 * HEARTBEAT ACK that contains the Heartbeat Information field copied
926 * from the received HEARTBEAT chunk. 926 * from the received HEARTBEAT chunk.
927 * 927 *
928 * Verification Tag: 8.5 Verification Tag [Normal verification] 928 * Verification Tag: 8.5 Verification Tag [Normal verification]
929 * When receiving an SCTP packet, the endpoint MUST ensure that the 929 * When receiving an SCTP packet, the endpoint MUST ensure that the
930 * value in the Verification Tag field of the received SCTP packet 930 * value in the Verification Tag field of the received SCTP packet
931 * matches its own Tag. If the received Verification Tag value does not 931 * matches its own Tag. If the received Verification Tag value does not
932 * match the receiver's own tag value, the receiver shall silently 932 * match the receiver's own tag value, the receiver shall silently
933 * discard the packet and shall not process it any further except for 933 * discard the packet and shall not process it any further except for
934 * those cases listed in Section 8.5.1 below. 934 * those cases listed in Section 8.5.1 below.
935 * 935 *
936 * Inputs 936 * Inputs
937 * (endpoint, asoc, chunk) 937 * (endpoint, asoc, chunk)
938 * 938 *
939 * Outputs 939 * Outputs
940 * (asoc, reply_msg, msg_up, timers, counters) 940 * (asoc, reply_msg, msg_up, timers, counters)
941 * 941 *
942 * The return value is the disposition of the chunk. 942 * The return value is the disposition of the chunk.
943 */ 943 */
944 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep, 944 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
945 const struct sctp_association *asoc, 945 const struct sctp_association *asoc,
946 const sctp_subtype_t type, 946 const sctp_subtype_t type,
947 void *arg, 947 void *arg,
948 sctp_cmd_seq_t *commands) 948 sctp_cmd_seq_t *commands)
949 { 949 {
950 struct sctp_chunk *chunk = arg; 950 struct sctp_chunk *chunk = arg;
951 struct sctp_chunk *reply; 951 struct sctp_chunk *reply;
952 size_t paylen = 0; 952 size_t paylen = 0;
953 953
954 if (!sctp_vtag_verify(chunk, asoc)) 954 if (!sctp_vtag_verify(chunk, asoc))
955 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 955 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
956 956
957 /* Make sure that the HEARTBEAT chunk has a valid length. */ 957 /* Make sure that the HEARTBEAT chunk has a valid length. */
958 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t))) 958 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
959 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 959 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
960 commands); 960 commands);
961 961
962 /* 8.3 The receiver of the HEARTBEAT should immediately 962 /* 8.3 The receiver of the HEARTBEAT should immediately
963 * respond with a HEARTBEAT ACK that contains the Heartbeat 963 * respond with a HEARTBEAT ACK that contains the Heartbeat
964 * Information field copied from the received HEARTBEAT chunk. 964 * Information field copied from the received HEARTBEAT chunk.
965 */ 965 */
966 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data; 966 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
967 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t); 967 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
968 skb_pull(chunk->skb, paylen); 968 skb_pull(chunk->skb, paylen);
969 969
970 reply = sctp_make_heartbeat_ack(asoc, chunk, 970 reply = sctp_make_heartbeat_ack(asoc, chunk,
971 chunk->subh.hb_hdr, paylen); 971 chunk->subh.hb_hdr, paylen);
972 if (!reply) 972 if (!reply)
973 goto nomem; 973 goto nomem;
974 974
975 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 975 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
976 return SCTP_DISPOSITION_CONSUME; 976 return SCTP_DISPOSITION_CONSUME;
977 977
978 nomem: 978 nomem:
979 return SCTP_DISPOSITION_NOMEM; 979 return SCTP_DISPOSITION_NOMEM;
980 } 980 }
981 981
982 /* 982 /*
983 * Process the returning HEARTBEAT ACK. 983 * Process the returning HEARTBEAT ACK.
984 * 984 *
985 * Section: 8.3 Path Heartbeat 985 * Section: 8.3 Path Heartbeat
986 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT 986 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
987 * should clear the error counter of the destination transport 987 * should clear the error counter of the destination transport
988 * address to which the HEARTBEAT was sent, and mark the destination 988 * address to which the HEARTBEAT was sent, and mark the destination
989 * transport address as active if it is not so marked. The endpoint may 989 * transport address as active if it is not so marked. The endpoint may
990 * optionally report to the upper layer when an inactive destination 990 * optionally report to the upper layer when an inactive destination
991 * address is marked as active due to the reception of the latest 991 * address is marked as active due to the reception of the latest
992 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also 992 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
993 * clear the association overall error count as well (as defined 993 * clear the association overall error count as well (as defined
994 * in section 8.1). 994 * in section 8.1).
995 * 995 *
996 * The receiver of the HEARTBEAT ACK should also perform an RTT 996 * The receiver of the HEARTBEAT ACK should also perform an RTT
997 * measurement for that destination transport address using the time 997 * measurement for that destination transport address using the time
998 * value carried in the HEARTBEAT ACK chunk. 998 * value carried in the HEARTBEAT ACK chunk.
999 * 999 *
1000 * Verification Tag: 8.5 Verification Tag [Normal verification] 1000 * Verification Tag: 8.5 Verification Tag [Normal verification]
1001 * 1001 *
1002 * Inputs 1002 * Inputs
1003 * (endpoint, asoc, chunk) 1003 * (endpoint, asoc, chunk)
1004 * 1004 *
1005 * Outputs 1005 * Outputs
1006 * (asoc, reply_msg, msg_up, timers, counters) 1006 * (asoc, reply_msg, msg_up, timers, counters)
1007 * 1007 *
1008 * The return value is the disposition of the chunk. 1008 * The return value is the disposition of the chunk.
1009 */ 1009 */
1010 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep, 1010 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1011 const struct sctp_association *asoc, 1011 const struct sctp_association *asoc,
1012 const sctp_subtype_t type, 1012 const sctp_subtype_t type,
1013 void *arg, 1013 void *arg,
1014 sctp_cmd_seq_t *commands) 1014 sctp_cmd_seq_t *commands)
1015 { 1015 {
1016 struct sctp_chunk *chunk = arg; 1016 struct sctp_chunk *chunk = arg;
1017 union sctp_addr from_addr; 1017 union sctp_addr from_addr;
1018 struct sctp_transport *link; 1018 struct sctp_transport *link;
1019 sctp_sender_hb_info_t *hbinfo; 1019 sctp_sender_hb_info_t *hbinfo;
1020 unsigned long max_interval; 1020 unsigned long max_interval;
1021 1021
1022 if (!sctp_vtag_verify(chunk, asoc)) 1022 if (!sctp_vtag_verify(chunk, asoc))
1023 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 1023 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1024 1024
1025 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */ 1025 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1026 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t))) 1026 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1027 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 1027 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1028 commands); 1028 commands);
1029 1029
1030 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data; 1030 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1031 from_addr = hbinfo->daddr; 1031 from_addr = hbinfo->daddr;
1032 link = sctp_assoc_lookup_paddr(asoc, &from_addr); 1032 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1033 1033
1034 /* This should never happen, but lets log it if so. */ 1034 /* This should never happen, but lets log it if so. */
1035 if (unlikely(!link)) { 1035 if (unlikely(!link)) {
1036 if (from_addr.sa.sa_family == AF_INET6) { 1036 if (from_addr.sa.sa_family == AF_INET6) {
1037 printk(KERN_WARNING 1037 printk(KERN_WARNING
1038 "%s association %p could not find address " 1038 "%s association %p could not find address "
1039 NIP6_FMT "\n", 1039 NIP6_FMT "\n",
1040 __FUNCTION__, 1040 __FUNCTION__,
1041 asoc, 1041 asoc,
1042 NIP6(from_addr.v6.sin6_addr)); 1042 NIP6(from_addr.v6.sin6_addr));
1043 } else { 1043 } else {
1044 printk(KERN_WARNING 1044 printk(KERN_WARNING
1045 "%s association %p could not find address " 1045 "%s association %p could not find address "
1046 NIPQUAD_FMT "\n", 1046 NIPQUAD_FMT "\n",
1047 __FUNCTION__, 1047 __FUNCTION__,
1048 asoc, 1048 asoc,
1049 NIPQUAD(from_addr.v4.sin_addr.s_addr)); 1049 NIPQUAD(from_addr.v4.sin_addr.s_addr));
1050 } 1050 }
1051 return SCTP_DISPOSITION_DISCARD; 1051 return SCTP_DISPOSITION_DISCARD;
1052 } 1052 }
1053 1053
1054 max_interval = link->hbinterval + link->rto; 1054 max_interval = link->hbinterval + link->rto;
1055 1055
1056 /* Check if the timestamp looks valid. */ 1056 /* Check if the timestamp looks valid. */
1057 if (time_after(hbinfo->sent_at, jiffies) || 1057 if (time_after(hbinfo->sent_at, jiffies) ||
1058 time_after(jiffies, hbinfo->sent_at + max_interval)) { 1058 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1059 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp" 1059 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
1060 "received for transport: %p\n", 1060 "received for transport: %p\n",
1061 __FUNCTION__, link); 1061 __FUNCTION__, link);
1062 return SCTP_DISPOSITION_DISCARD; 1062 return SCTP_DISPOSITION_DISCARD;
1063 } 1063 }
1064 1064
1065 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of 1065 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1066 * the HEARTBEAT should clear the error counter of the 1066 * the HEARTBEAT should clear the error counter of the
1067 * destination transport address to which the HEARTBEAT was 1067 * destination transport address to which the HEARTBEAT was
1068 * sent and mark the destination transport address as active if 1068 * sent and mark the destination transport address as active if
1069 * it is not so marked. 1069 * it is not so marked.
1070 */ 1070 */
1071 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link)); 1071 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1072 1072
1073 return SCTP_DISPOSITION_CONSUME; 1073 return SCTP_DISPOSITION_CONSUME;
1074 } 1074 }
1075 1075
1076 /* Helper function to send out an abort for the restart 1076 /* Helper function to send out an abort for the restart
1077 * condition. 1077 * condition.
1078 */ 1078 */
1079 static int sctp_sf_send_restart_abort(union sctp_addr *ssa, 1079 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1080 struct sctp_chunk *init, 1080 struct sctp_chunk *init,
1081 sctp_cmd_seq_t *commands) 1081 sctp_cmd_seq_t *commands)
1082 { 1082 {
1083 int len; 1083 int len;
1084 struct sctp_packet *pkt; 1084 struct sctp_packet *pkt;
1085 union sctp_addr_param *addrparm; 1085 union sctp_addr_param *addrparm;
1086 struct sctp_errhdr *errhdr; 1086 struct sctp_errhdr *errhdr;
1087 struct sctp_endpoint *ep; 1087 struct sctp_endpoint *ep;
1088 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)]; 1088 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1089 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family); 1089 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1090 1090
1091 /* Build the error on the stack. We are way to malloc crazy 1091 /* Build the error on the stack. We are way to malloc crazy
1092 * throughout the code today. 1092 * throughout the code today.
1093 */ 1093 */
1094 errhdr = (struct sctp_errhdr *)buffer; 1094 errhdr = (struct sctp_errhdr *)buffer;
1095 addrparm = (union sctp_addr_param *)errhdr->variable; 1095 addrparm = (union sctp_addr_param *)errhdr->variable;
1096 1096
1097 /* Copy into a parm format. */ 1097 /* Copy into a parm format. */
1098 len = af->to_addr_param(ssa, addrparm); 1098 len = af->to_addr_param(ssa, addrparm);
1099 len += sizeof(sctp_errhdr_t); 1099 len += sizeof(sctp_errhdr_t);
1100 1100
1101 errhdr->cause = SCTP_ERROR_RESTART; 1101 errhdr->cause = SCTP_ERROR_RESTART;
1102 errhdr->length = htons(len); 1102 errhdr->length = htons(len);
1103 1103
1104 /* Assign to the control socket. */ 1104 /* Assign to the control socket. */
1105 ep = sctp_sk((sctp_get_ctl_sock()))->ep; 1105 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1106 1106
1107 /* Association is NULL since this may be a restart attack and we 1107 /* Association is NULL since this may be a restart attack and we
1108 * want to send back the attacker's vtag. 1108 * want to send back the attacker's vtag.
1109 */ 1109 */
1110 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len); 1110 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1111 1111
1112 if (!pkt) 1112 if (!pkt)
1113 goto out; 1113 goto out;
1114 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt)); 1114 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1115 1115
1116 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); 1116 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1117 1117
1118 /* Discard the rest of the inbound packet. */ 1118 /* Discard the rest of the inbound packet. */
1119 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); 1119 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1120 1120
1121 out: 1121 out:
1122 /* Even if there is no memory, treat as a failure so 1122 /* Even if there is no memory, treat as a failure so
1123 * the packet will get dropped. 1123 * the packet will get dropped.
1124 */ 1124 */
1125 return 0; 1125 return 0;
1126 } 1126 }
1127 1127
1128 /* A restart is occurring, check to make sure no new addresses 1128 /* A restart is occurring, check to make sure no new addresses
1129 * are being added as we may be under a takeover attack. 1129 * are being added as we may be under a takeover attack.
1130 */ 1130 */
1131 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc, 1131 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1132 const struct sctp_association *asoc, 1132 const struct sctp_association *asoc,
1133 struct sctp_chunk *init, 1133 struct sctp_chunk *init,
1134 sctp_cmd_seq_t *commands) 1134 sctp_cmd_seq_t *commands)
1135 { 1135 {
1136 struct sctp_transport *new_addr, *addr; 1136 struct sctp_transport *new_addr, *addr;
1137 struct list_head *pos, *pos2; 1137 struct list_head *pos, *pos2;
1138 int found; 1138 int found;
1139 1139
1140 /* Implementor's Guide - Sectin 5.2.2 1140 /* Implementor's Guide - Sectin 5.2.2
1141 * ... 1141 * ...
1142 * Before responding the endpoint MUST check to see if the 1142 * Before responding the endpoint MUST check to see if the
1143 * unexpected INIT adds new addresses to the association. If new 1143 * unexpected INIT adds new addresses to the association. If new
1144 * addresses are added to the association, the endpoint MUST respond 1144 * addresses are added to the association, the endpoint MUST respond
1145 * with an ABORT.. 1145 * with an ABORT..
1146 */ 1146 */
1147 1147
1148 /* Search through all current addresses and make sure 1148 /* Search through all current addresses and make sure
1149 * we aren't adding any new ones. 1149 * we aren't adding any new ones.
1150 */ 1150 */
1151 new_addr = NULL; 1151 new_addr = NULL;
1152 found = 0; 1152 found = 0;
1153 1153
1154 list_for_each(pos, &new_asoc->peer.transport_addr_list) { 1154 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1155 new_addr = list_entry(pos, struct sctp_transport, transports); 1155 new_addr = list_entry(pos, struct sctp_transport, transports);
1156 found = 0; 1156 found = 0;
1157 list_for_each(pos2, &asoc->peer.transport_addr_list) { 1157 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1158 addr = list_entry(pos2, struct sctp_transport, 1158 addr = list_entry(pos2, struct sctp_transport,
1159 transports); 1159 transports);
1160 if (sctp_cmp_addr_exact(&new_addr->ipaddr, 1160 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1161 &addr->ipaddr)) { 1161 &addr->ipaddr)) {
1162 found = 1; 1162 found = 1;
1163 break; 1163 break;
1164 } 1164 }
1165 } 1165 }
1166 if (!found) 1166 if (!found)
1167 break; 1167 break;
1168 } 1168 }
1169 1169
1170 /* If a new address was added, ABORT the sender. */ 1170 /* If a new address was added, ABORT the sender. */
1171 if (!found && new_addr) { 1171 if (!found && new_addr) {
1172 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands); 1172 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1173 } 1173 }
1174 1174
1175 /* Return success if all addresses were found. */ 1175 /* Return success if all addresses were found. */
1176 return found; 1176 return found;
1177 } 1177 }
1178 1178
1179 /* Populate the verification/tie tags based on overlapping INIT 1179 /* Populate the verification/tie tags based on overlapping INIT
1180 * scenario. 1180 * scenario.
1181 * 1181 *
1182 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state. 1182 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1183 */ 1183 */
1184 static void sctp_tietags_populate(struct sctp_association *new_asoc, 1184 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1185 const struct sctp_association *asoc) 1185 const struct sctp_association *asoc)
1186 { 1186 {
1187 switch (asoc->state) { 1187 switch (asoc->state) {
1188 1188
1189 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */ 1189 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1190 1190
1191 case SCTP_STATE_COOKIE_WAIT: 1191 case SCTP_STATE_COOKIE_WAIT:
1192 new_asoc->c.my_vtag = asoc->c.my_vtag; 1192 new_asoc->c.my_vtag = asoc->c.my_vtag;
1193 new_asoc->c.my_ttag = asoc->c.my_vtag; 1193 new_asoc->c.my_ttag = asoc->c.my_vtag;
1194 new_asoc->c.peer_ttag = 0; 1194 new_asoc->c.peer_ttag = 0;
1195 break; 1195 break;
1196 1196
1197 case SCTP_STATE_COOKIE_ECHOED: 1197 case SCTP_STATE_COOKIE_ECHOED:
1198 new_asoc->c.my_vtag = asoc->c.my_vtag; 1198 new_asoc->c.my_vtag = asoc->c.my_vtag;
1199 new_asoc->c.my_ttag = asoc->c.my_vtag; 1199 new_asoc->c.my_ttag = asoc->c.my_vtag;
1200 new_asoc->c.peer_ttag = asoc->c.peer_vtag; 1200 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1201 break; 1201 break;
1202 1202
1203 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED, 1203 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1204 * COOKIE-WAIT and SHUTDOWN-ACK-SENT 1204 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1205 */ 1205 */
1206 default: 1206 default:
1207 new_asoc->c.my_ttag = asoc->c.my_vtag; 1207 new_asoc->c.my_ttag = asoc->c.my_vtag;
1208 new_asoc->c.peer_ttag = asoc->c.peer_vtag; 1208 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1209 break; 1209 break;
1210 }; 1210 };
1211 1211
1212 /* Other parameters for the endpoint SHOULD be copied from the 1212 /* Other parameters for the endpoint SHOULD be copied from the
1213 * existing parameters of the association (e.g. number of 1213 * existing parameters of the association (e.g. number of
1214 * outbound streams) into the INIT ACK and cookie. 1214 * outbound streams) into the INIT ACK and cookie.
1215 */ 1215 */
1216 new_asoc->rwnd = asoc->rwnd; 1216 new_asoc->rwnd = asoc->rwnd;
1217 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams; 1217 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1218 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams; 1218 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1219 new_asoc->c.initial_tsn = asoc->c.initial_tsn; 1219 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1220 } 1220 }
1221 1221
1222 /* 1222 /*
1223 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO 1223 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1224 * handling action. 1224 * handling action.
1225 * 1225 *
1226 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists. 1226 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1227 * 1227 *
1228 * Returns value representing action to be taken. These action values 1228 * Returns value representing action to be taken. These action values
1229 * correspond to Action/Description values in RFC 2960, Table 2. 1229 * correspond to Action/Description values in RFC 2960, Table 2.
1230 */ 1230 */
1231 static char sctp_tietags_compare(struct sctp_association *new_asoc, 1231 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1232 const struct sctp_association *asoc) 1232 const struct sctp_association *asoc)
1233 { 1233 {
1234 /* In this case, the peer may have restarted. */ 1234 /* In this case, the peer may have restarted. */
1235 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && 1235 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1236 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) && 1236 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1237 (asoc->c.my_vtag == new_asoc->c.my_ttag) && 1237 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1238 (asoc->c.peer_vtag == new_asoc->c.peer_ttag)) 1238 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1239 return 'A'; 1239 return 'A';
1240 1240
1241 /* Collision case B. */ 1241 /* Collision case B. */
1242 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && 1242 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1243 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) || 1243 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1244 (0 == asoc->c.peer_vtag))) { 1244 (0 == asoc->c.peer_vtag))) {
1245 return 'B'; 1245 return 'B';
1246 } 1246 }
1247 1247
1248 /* Collision case D. */ 1248 /* Collision case D. */
1249 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && 1249 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1250 (asoc->c.peer_vtag == new_asoc->c.peer_vtag)) 1250 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1251 return 'D'; 1251 return 'D';
1252 1252
1253 /* Collision case C. */ 1253 /* Collision case C. */
1254 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && 1254 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1255 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) && 1255 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1256 (0 == new_asoc->c.my_ttag) && 1256 (0 == new_asoc->c.my_ttag) &&
1257 (0 == new_asoc->c.peer_ttag)) 1257 (0 == new_asoc->c.peer_ttag))
1258 return 'C'; 1258 return 'C';
1259 1259
1260 /* No match to any of the special cases; discard this packet. */ 1260 /* No match to any of the special cases; discard this packet. */
1261 return 'E'; 1261 return 'E';
1262 } 1262 }
1263 1263
1264 /* Common helper routine for both duplicate and simulataneous INIT 1264 /* Common helper routine for both duplicate and simulataneous INIT
1265 * chunk handling. 1265 * chunk handling.
1266 */ 1266 */
1267 static sctp_disposition_t sctp_sf_do_unexpected_init( 1267 static sctp_disposition_t sctp_sf_do_unexpected_init(
1268 const struct sctp_endpoint *ep, 1268 const struct sctp_endpoint *ep,
1269 const struct sctp_association *asoc, 1269 const struct sctp_association *asoc,
1270 const sctp_subtype_t type, 1270 const sctp_subtype_t type,
1271 void *arg, sctp_cmd_seq_t *commands) 1271 void *arg, sctp_cmd_seq_t *commands)
1272 { 1272 {
1273 sctp_disposition_t retval; 1273 sctp_disposition_t retval;
1274 struct sctp_chunk *chunk = arg; 1274 struct sctp_chunk *chunk = arg;
1275 struct sctp_chunk *repl; 1275 struct sctp_chunk *repl;
1276 struct sctp_association *new_asoc; 1276 struct sctp_association *new_asoc;
1277 struct sctp_chunk *err_chunk; 1277 struct sctp_chunk *err_chunk;
1278 struct sctp_packet *packet; 1278 struct sctp_packet *packet;
1279 sctp_unrecognized_param_t *unk_param; 1279 sctp_unrecognized_param_t *unk_param;
1280 int len; 1280 int len;
1281 1281
1282 /* 6.10 Bundling 1282 /* 6.10 Bundling
1283 * An endpoint MUST NOT bundle INIT, INIT ACK or 1283 * An endpoint MUST NOT bundle INIT, INIT ACK or
1284 * SHUTDOWN COMPLETE with any other chunks. 1284 * SHUTDOWN COMPLETE with any other chunks.
1285 * 1285 *
1286 * IG Section 2.11.2 1286 * IG Section 2.11.2
1287 * Furthermore, we require that the receiver of an INIT chunk MUST 1287 * Furthermore, we require that the receiver of an INIT chunk MUST
1288 * enforce these rules by silently discarding an arriving packet 1288 * enforce these rules by silently discarding an arriving packet
1289 * with an INIT chunk that is bundled with other chunks. 1289 * with an INIT chunk that is bundled with other chunks.
1290 */ 1290 */
1291 if (!chunk->singleton) 1291 if (!chunk->singleton)
1292 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 1292 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1293 1293
1294 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification 1294 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1295 * Tag. 1295 * Tag.
1296 */ 1296 */
1297 if (chunk->sctp_hdr->vtag != 0) 1297 if (chunk->sctp_hdr->vtag != 0)
1298 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); 1298 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1299 1299
1300 /* Make sure that the INIT chunk has a valid length. 1300 /* Make sure that the INIT chunk has a valid length.
1301 * In this case, we generate a protocol violation since we have 1301 * In this case, we generate a protocol violation since we have
1302 * an association established. 1302 * an association established.
1303 */ 1303 */
1304 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t))) 1304 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1305 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 1305 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1306 commands); 1306 commands);
1307 /* Grab the INIT header. */ 1307 /* Grab the INIT header. */
1308 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data; 1308 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1309 1309
1310 /* Tag the variable length parameters. */ 1310 /* Tag the variable length parameters. */
1311 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); 1311 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1312 1312
1313 /* Verify the INIT chunk before processing it. */ 1313 /* Verify the INIT chunk before processing it. */
1314 err_chunk = NULL; 1314 err_chunk = NULL;
1315 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, 1315 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1316 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, 1316 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1317 &err_chunk)) { 1317 &err_chunk)) {
1318 /* This chunk contains fatal error. It is to be discarded. 1318 /* This chunk contains fatal error. It is to be discarded.
1319 * Send an ABORT, with causes if there is any. 1319 * Send an ABORT, with causes if there is any.
1320 */ 1320 */
1321 if (err_chunk) { 1321 if (err_chunk) {
1322 packet = sctp_abort_pkt_new(ep, asoc, arg, 1322 packet = sctp_abort_pkt_new(ep, asoc, arg,
1323 (__u8 *)(err_chunk->chunk_hdr) + 1323 (__u8 *)(err_chunk->chunk_hdr) +
1324 sizeof(sctp_chunkhdr_t), 1324 sizeof(sctp_chunkhdr_t),
1325 ntohs(err_chunk->chunk_hdr->length) - 1325 ntohs(err_chunk->chunk_hdr->length) -
1326 sizeof(sctp_chunkhdr_t)); 1326 sizeof(sctp_chunkhdr_t));
1327 1327
1328 if (packet) { 1328 if (packet) {
1329 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, 1329 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1330 SCTP_PACKET(packet)); 1330 SCTP_PACKET(packet));
1331 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); 1331 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1332 retval = SCTP_DISPOSITION_CONSUME; 1332 retval = SCTP_DISPOSITION_CONSUME;
1333 } else { 1333 } else {
1334 retval = SCTP_DISPOSITION_NOMEM; 1334 retval = SCTP_DISPOSITION_NOMEM;
1335 } 1335 }
1336 goto cleanup; 1336 goto cleanup;
1337 } else { 1337 } else {
1338 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, 1338 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1339 commands); 1339 commands);
1340 } 1340 }
1341 } 1341 }
1342 1342
1343 /* 1343 /*
1344 * Other parameters for the endpoint SHOULD be copied from the 1344 * Other parameters for the endpoint SHOULD be copied from the
1345 * existing parameters of the association (e.g. number of 1345 * existing parameters of the association (e.g. number of
1346 * outbound streams) into the INIT ACK and cookie. 1346 * outbound streams) into the INIT ACK and cookie.
1347 * FIXME: We are copying parameters from the endpoint not the 1347 * FIXME: We are copying parameters from the endpoint not the
1348 * association. 1348 * association.
1349 */ 1349 */
1350 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); 1350 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1351 if (!new_asoc) 1351 if (!new_asoc)
1352 goto nomem; 1352 goto nomem;
1353 1353
1354 /* In the outbound INIT ACK the endpoint MUST copy its current 1354 /* In the outbound INIT ACK the endpoint MUST copy its current
1355 * Verification Tag and Peers Verification tag into a reserved 1355 * Verification Tag and Peers Verification tag into a reserved
1356 * place (local tie-tag and per tie-tag) within the state cookie. 1356 * place (local tie-tag and per tie-tag) within the state cookie.
1357 */ 1357 */
1358 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, 1358 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1359 sctp_source(chunk), 1359 sctp_source(chunk),
1360 (sctp_init_chunk_t *)chunk->chunk_hdr, 1360 (sctp_init_chunk_t *)chunk->chunk_hdr,
1361 GFP_ATOMIC)) { 1361 GFP_ATOMIC)) {
1362 retval = SCTP_DISPOSITION_NOMEM; 1362 retval = SCTP_DISPOSITION_NOMEM;
1363 goto nomem_init; 1363 goto nomem_init;
1364 } 1364 }
1365 1365
1366 /* Make sure no new addresses are being added during the 1366 /* Make sure no new addresses are being added during the
1367 * restart. Do not do this check for COOKIE-WAIT state, 1367 * restart. Do not do this check for COOKIE-WAIT state,
1368 * since there are no peer addresses to check against. 1368 * since there are no peer addresses to check against.
1369 * Upon return an ABORT will have been sent if needed. 1369 * Upon return an ABORT will have been sent if needed.
1370 */ 1370 */
1371 if (!sctp_state(asoc, COOKIE_WAIT)) { 1371 if (!sctp_state(asoc, COOKIE_WAIT)) {
1372 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, 1372 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1373 commands)) { 1373 commands)) {
1374 retval = SCTP_DISPOSITION_CONSUME; 1374 retval = SCTP_DISPOSITION_CONSUME;
1375 goto cleanup_asoc; 1375 goto cleanup_asoc;
1376 } 1376 }
1377 } 1377 }
1378 1378
1379 sctp_tietags_populate(new_asoc, asoc); 1379 sctp_tietags_populate(new_asoc, asoc);
1380 1380
1381 /* B) "Z" shall respond immediately with an INIT ACK chunk. */ 1381 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1382 1382
1383 /* If there are errors need to be reported for unknown parameters, 1383 /* If there are errors need to be reported for unknown parameters,
1384 * make sure to reserve enough room in the INIT ACK for them. 1384 * make sure to reserve enough room in the INIT ACK for them.
1385 */ 1385 */
1386 len = 0; 1386 len = 0;
1387 if (err_chunk) { 1387 if (err_chunk) {
1388 len = ntohs(err_chunk->chunk_hdr->length) - 1388 len = ntohs(err_chunk->chunk_hdr->length) -
1389 sizeof(sctp_chunkhdr_t); 1389 sizeof(sctp_chunkhdr_t);
1390 } 1390 }
1391 1391
1392 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0) 1392 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1393 goto nomem; 1393 goto nomem;
1394 1394
1395 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); 1395 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1396 if (!repl) 1396 if (!repl)
1397 goto nomem; 1397 goto nomem;
1398 1398
1399 /* If there are errors need to be reported for unknown parameters, 1399 /* If there are errors need to be reported for unknown parameters,
1400 * include them in the outgoing INIT ACK as "Unrecognized parameter" 1400 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1401 * parameter. 1401 * parameter.
1402 */ 1402 */
1403 if (err_chunk) { 1403 if (err_chunk) {
1404 /* Get the "Unrecognized parameter" parameter(s) out of the 1404 /* Get the "Unrecognized parameter" parameter(s) out of the
1405 * ERROR chunk generated by sctp_verify_init(). Since the 1405 * ERROR chunk generated by sctp_verify_init(). Since the
1406 * error cause code for "unknown parameter" and the 1406 * error cause code for "unknown parameter" and the
1407 * "Unrecognized parameter" type is the same, we can 1407 * "Unrecognized parameter" type is the same, we can
1408 * construct the parameters in INIT ACK by copying the 1408 * construct the parameters in INIT ACK by copying the
1409 * ERROR causes over. 1409 * ERROR causes over.
1410 */ 1410 */
1411 unk_param = (sctp_unrecognized_param_t *) 1411 unk_param = (sctp_unrecognized_param_t *)
1412 ((__u8 *)(err_chunk->chunk_hdr) + 1412 ((__u8 *)(err_chunk->chunk_hdr) +
1413 sizeof(sctp_chunkhdr_t)); 1413 sizeof(sctp_chunkhdr_t));
1414 /* Replace the cause code with the "Unrecognized parameter" 1414 /* Replace the cause code with the "Unrecognized parameter"
1415 * parameter type. 1415 * parameter type.
1416 */ 1416 */
1417 sctp_addto_chunk(repl, len, unk_param); 1417 sctp_addto_chunk(repl, len, unk_param);
1418 } 1418 }
1419 1419
1420 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); 1420 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1421 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 1421 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1422 1422
1423 /* 1423 /*
1424 * Note: After sending out INIT ACK with the State Cookie parameter, 1424 * Note: After sending out INIT ACK with the State Cookie parameter,
1425 * "Z" MUST NOT allocate any resources for this new association. 1425 * "Z" MUST NOT allocate any resources for this new association.
1426 * Otherwise, "Z" will be vulnerable to resource attacks. 1426 * Otherwise, "Z" will be vulnerable to resource attacks.
1427 */ 1427 */
1428 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); 1428 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1429 retval = SCTP_DISPOSITION_CONSUME; 1429 retval = SCTP_DISPOSITION_CONSUME;
1430 1430
1431 cleanup: 1431 cleanup:
1432 if (err_chunk) 1432 if (err_chunk)
1433 sctp_chunk_free(err_chunk); 1433 sctp_chunk_free(err_chunk);
1434 return retval; 1434 return retval;
1435 nomem: 1435 nomem:
1436 retval = SCTP_DISPOSITION_NOMEM; 1436 retval = SCTP_DISPOSITION_NOMEM;
1437 goto cleanup; 1437 goto cleanup;
1438 nomem_init: 1438 nomem_init:
1439 cleanup_asoc: 1439 cleanup_asoc:
1440 sctp_association_free(new_asoc); 1440 sctp_association_free(new_asoc);
1441 goto cleanup; 1441 goto cleanup;
1442 } 1442 }
1443 1443
1444 /* 1444 /*
1445 * Handle simultanous INIT. 1445 * Handle simultanous INIT.
1446 * This means we started an INIT and then we got an INIT request from 1446 * This means we started an INIT and then we got an INIT request from
1447 * our peer. 1447 * our peer.
1448 * 1448 *
1449 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B) 1449 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1450 * This usually indicates an initialization collision, i.e., each 1450 * This usually indicates an initialization collision, i.e., each
1451 * endpoint is attempting, at about the same time, to establish an 1451 * endpoint is attempting, at about the same time, to establish an
1452 * association with the other endpoint. 1452 * association with the other endpoint.
1453 * 1453 *
1454 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an 1454 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1455 * endpoint MUST respond with an INIT ACK using the same parameters it 1455 * endpoint MUST respond with an INIT ACK using the same parameters it
1456 * sent in its original INIT chunk (including its Verification Tag, 1456 * sent in its original INIT chunk (including its Verification Tag,
1457 * unchanged). These original parameters are combined with those from the 1457 * unchanged). These original parameters are combined with those from the
1458 * newly received INIT chunk. The endpoint shall also generate a State 1458 * newly received INIT chunk. The endpoint shall also generate a State
1459 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its 1459 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1460 * INIT to calculate the State Cookie. 1460 * INIT to calculate the State Cookie.
1461 * 1461 *
1462 * After that, the endpoint MUST NOT change its state, the T1-init 1462 * After that, the endpoint MUST NOT change its state, the T1-init
1463 * timer shall be left running and the corresponding TCB MUST NOT be 1463 * timer shall be left running and the corresponding TCB MUST NOT be
1464 * destroyed. The normal procedures for handling State Cookies when 1464 * destroyed. The normal procedures for handling State Cookies when
1465 * a TCB exists will resolve the duplicate INITs to a single association. 1465 * a TCB exists will resolve the duplicate INITs to a single association.
1466 * 1466 *
1467 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate 1467 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1468 * its Tie-Tags with the Tag information of itself and its peer (see 1468 * its Tie-Tags with the Tag information of itself and its peer (see
1469 * section 5.2.2 for a description of the Tie-Tags). 1469 * section 5.2.2 for a description of the Tie-Tags).
1470 * 1470 *
1471 * Verification Tag: Not explicit, but an INIT can not have a valid 1471 * Verification Tag: Not explicit, but an INIT can not have a valid
1472 * verification tag, so we skip the check. 1472 * verification tag, so we skip the check.
1473 * 1473 *
1474 * Inputs 1474 * Inputs
1475 * (endpoint, asoc, chunk) 1475 * (endpoint, asoc, chunk)
1476 * 1476 *
1477 * Outputs 1477 * Outputs
1478 * (asoc, reply_msg, msg_up, timers, counters) 1478 * (asoc, reply_msg, msg_up, timers, counters)
1479 * 1479 *
1480 * The return value is the disposition of the chunk. 1480 * The return value is the disposition of the chunk.
1481 */ 1481 */
1482 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep, 1482 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1483 const struct sctp_association *asoc, 1483 const struct sctp_association *asoc,
1484 const sctp_subtype_t type, 1484 const sctp_subtype_t type,
1485 void *arg, 1485 void *arg,
1486 sctp_cmd_seq_t *commands) 1486 sctp_cmd_seq_t *commands)
1487 { 1487 {
1488 /* Call helper to do the real work for both simulataneous and 1488 /* Call helper to do the real work for both simulataneous and
1489 * duplicate INIT chunk handling. 1489 * duplicate INIT chunk handling.
1490 */ 1490 */
1491 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands); 1491 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1492 } 1492 }
1493 1493
1494 /* 1494 /*
1495 * Handle duplicated INIT messages. These are usually delayed 1495 * Handle duplicated INIT messages. These are usually delayed
1496 * restransmissions. 1496 * restransmissions.
1497 * 1497 *
1498 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED, 1498 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1499 * COOKIE-ECHOED and COOKIE-WAIT 1499 * COOKIE-ECHOED and COOKIE-WAIT
1500 * 1500 *
1501 * Unless otherwise stated, upon reception of an unexpected INIT for 1501 * Unless otherwise stated, upon reception of an unexpected INIT for
1502 * this association, the endpoint shall generate an INIT ACK with a 1502 * this association, the endpoint shall generate an INIT ACK with a
1503 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its 1503 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1504 * current Verification Tag and peer's Verification Tag into a reserved 1504 * current Verification Tag and peer's Verification Tag into a reserved
1505 * place within the state cookie. We shall refer to these locations as 1505 * place within the state cookie. We shall refer to these locations as
1506 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet 1506 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1507 * containing this INIT ACK MUST carry a Verification Tag value equal to 1507 * containing this INIT ACK MUST carry a Verification Tag value equal to
1508 * the Initiation Tag found in the unexpected INIT. And the INIT ACK 1508 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1509 * MUST contain a new Initiation Tag (randomly generated see Section 1509 * MUST contain a new Initiation Tag (randomly generated see Section
1510 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the 1510 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1511 * existing parameters of the association (e.g. number of outbound 1511 * existing parameters of the association (e.g. number of outbound
1512 * streams) into the INIT ACK and cookie. 1512 * streams) into the INIT ACK and cookie.
1513 * 1513 *
1514 * After sending out the INIT ACK, the endpoint shall take no further 1514 * After sending out the INIT ACK, the endpoint shall take no further
1515 * actions, i.e., the existing association, including its current state, 1515 * actions, i.e., the existing association, including its current state,
1516 * and the corresponding TCB MUST NOT be changed. 1516 * and the corresponding TCB MUST NOT be changed.
1517 * 1517 *
1518 * Note: Only when a TCB exists and the association is not in a COOKIE- 1518 * Note: Only when a TCB exists and the association is not in a COOKIE-
1519 * WAIT state are the Tie-Tags populated. For a normal association INIT 1519 * WAIT state are the Tie-Tags populated. For a normal association INIT
1520 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be 1520 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1521 * set to 0 (indicating that no previous TCB existed). The INIT ACK and 1521 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1522 * State Cookie are populated as specified in section 5.2.1. 1522 * State Cookie are populated as specified in section 5.2.1.
1523 * 1523 *
1524 * Verification Tag: Not specified, but an INIT has no way of knowing 1524 * Verification Tag: Not specified, but an INIT has no way of knowing
1525 * what the verification tag could be, so we ignore it. 1525 * what the verification tag could be, so we ignore it.
1526 * 1526 *
1527 * Inputs 1527 * Inputs
1528 * (endpoint, asoc, chunk) 1528 * (endpoint, asoc, chunk)
1529 * 1529 *
1530 * Outputs 1530 * Outputs
1531 * (asoc, reply_msg, msg_up, timers, counters) 1531 * (asoc, reply_msg, msg_up, timers, counters)
1532 * 1532 *
1533 * The return value is the disposition of the chunk. 1533 * The return value is the disposition of the chunk.
1534 */ 1534 */
1535 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep, 1535 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1536 const struct sctp_association *asoc, 1536 const struct sctp_association *asoc,
1537 const sctp_subtype_t type, 1537 const sctp_subtype_t type,
1538 void *arg, 1538 void *arg,
1539 sctp_cmd_seq_t *commands) 1539 sctp_cmd_seq_t *commands)
1540 { 1540 {
1541 /* Call helper to do the real work for both simulataneous and 1541 /* Call helper to do the real work for both simulataneous and
1542 * duplicate INIT chunk handling. 1542 * duplicate INIT chunk handling.
1543 */ 1543 */
1544 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands); 1544 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1545 } 1545 }
1546 1546
1547 1547
1548 1548
1549 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A') 1549 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1550 * 1550 *
1551 * Section 5.2.4 1551 * Section 5.2.4
1552 * A) In this case, the peer may have restarted. 1552 * A) In this case, the peer may have restarted.
1553 */ 1553 */
1554 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep, 1554 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1555 const struct sctp_association *asoc, 1555 const struct sctp_association *asoc,
1556 struct sctp_chunk *chunk, 1556 struct sctp_chunk *chunk,
1557 sctp_cmd_seq_t *commands, 1557 sctp_cmd_seq_t *commands,
1558 struct sctp_association *new_asoc) 1558 struct sctp_association *new_asoc)
1559 { 1559 {
1560 sctp_init_chunk_t *peer_init; 1560 sctp_init_chunk_t *peer_init;
1561 struct sctp_ulpevent *ev; 1561 struct sctp_ulpevent *ev;
1562 struct sctp_chunk *repl; 1562 struct sctp_chunk *repl;
1563 struct sctp_chunk *err; 1563 struct sctp_chunk *err;
1564 sctp_disposition_t disposition; 1564 sctp_disposition_t disposition;
1565 1565
1566 /* new_asoc is a brand-new association, so these are not yet 1566 /* new_asoc is a brand-new association, so these are not yet
1567 * side effects--it is safe to run them here. 1567 * side effects--it is safe to run them here.
1568 */ 1568 */
1569 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; 1569 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1570 1570
1571 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, 1571 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1572 sctp_source(chunk), peer_init, 1572 sctp_source(chunk), peer_init,
1573 GFP_ATOMIC)) 1573 GFP_ATOMIC))
1574 goto nomem; 1574 goto nomem;
1575 1575
1576 /* Make sure no new addresses are being added during the 1576 /* Make sure no new addresses are being added during the
1577 * restart. Though this is a pretty complicated attack 1577 * restart. Though this is a pretty complicated attack
1578 * since you'd have to get inside the cookie. 1578 * since you'd have to get inside the cookie.
1579 */ 1579 */
1580 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) { 1580 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1581 return SCTP_DISPOSITION_CONSUME; 1581 return SCTP_DISPOSITION_CONSUME;
1582 } 1582 }
1583 1583
1584 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes 1584 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1585 * the peer has restarted (Action A), it MUST NOT setup a new 1585 * the peer has restarted (Action A), it MUST NOT setup a new
1586 * association but instead resend the SHUTDOWN ACK and send an ERROR 1586 * association but instead resend the SHUTDOWN ACK and send an ERROR
1587 * chunk with a "Cookie Received while Shutting Down" error cause to 1587 * chunk with a "Cookie Received while Shutting Down" error cause to
1588 * its peer. 1588 * its peer.
1589 */ 1589 */
1590 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) { 1590 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1591 disposition = sctp_sf_do_9_2_reshutack(ep, asoc, 1591 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1592 SCTP_ST_CHUNK(chunk->chunk_hdr->type), 1592 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1593 chunk, commands); 1593 chunk, commands);
1594 if (SCTP_DISPOSITION_NOMEM == disposition) 1594 if (SCTP_DISPOSITION_NOMEM == disposition)
1595 goto nomem; 1595 goto nomem;
1596 1596
1597 err = sctp_make_op_error(asoc, chunk, 1597 err = sctp_make_op_error(asoc, chunk,
1598 SCTP_ERROR_COOKIE_IN_SHUTDOWN, 1598 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1599 NULL, 0); 1599 NULL, 0);
1600 if (err) 1600 if (err)
1601 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 1601 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1602 SCTP_CHUNK(err)); 1602 SCTP_CHUNK(err));
1603 1603
1604 return SCTP_DISPOSITION_CONSUME; 1604 return SCTP_DISPOSITION_CONSUME;
1605 } 1605 }
1606 1606
1607 /* For now, fail any unsent/unacked data. Consider the optional 1607 /* For now, fail any unsent/unacked data. Consider the optional
1608 * choice of resending of this data. 1608 * choice of resending of this data.
1609 */ 1609 */
1610 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL()); 1610 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1611 1611
1612 /* Update the content of current association. */ 1612 /* Update the content of current association. */
1613 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); 1613 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1614 1614
1615 repl = sctp_make_cookie_ack(new_asoc, chunk); 1615 repl = sctp_make_cookie_ack(new_asoc, chunk);
1616 if (!repl) 1616 if (!repl)
1617 goto nomem; 1617 goto nomem;
1618 1618
1619 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 1619 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1620 1620
1621 /* Report association restart to upper layer. */ 1621 /* Report association restart to upper layer. */
1622 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0, 1622 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1623 new_asoc->c.sinit_num_ostreams, 1623 new_asoc->c.sinit_num_ostreams,
1624 new_asoc->c.sinit_max_instreams, 1624 new_asoc->c.sinit_max_instreams,
1625 GFP_ATOMIC); 1625 GFP_ATOMIC);
1626 if (!ev) 1626 if (!ev)
1627 goto nomem_ev; 1627 goto nomem_ev;
1628 1628
1629 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); 1629 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1630 return SCTP_DISPOSITION_CONSUME; 1630 return SCTP_DISPOSITION_CONSUME;
1631 1631
1632 nomem_ev: 1632 nomem_ev:
1633 sctp_chunk_free(repl); 1633 sctp_chunk_free(repl);
1634 nomem: 1634 nomem:
1635 return SCTP_DISPOSITION_NOMEM; 1635 return SCTP_DISPOSITION_NOMEM;
1636 } 1636 }
1637 1637
1638 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B') 1638 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1639 * 1639 *
1640 * Section 5.2.4 1640 * Section 5.2.4
1641 * B) In this case, both sides may be attempting to start an association 1641 * B) In this case, both sides may be attempting to start an association
1642 * at about the same time but the peer endpoint started its INIT 1642 * at about the same time but the peer endpoint started its INIT
1643 * after responding to the local endpoint's INIT 1643 * after responding to the local endpoint's INIT
1644 */ 1644 */
1645 /* This case represents an initialization collision. */ 1645 /* This case represents an initialization collision. */
1646 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep, 1646 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1647 const struct sctp_association *asoc, 1647 const struct sctp_association *asoc,
1648 struct sctp_chunk *chunk, 1648 struct sctp_chunk *chunk,
1649 sctp_cmd_seq_t *commands, 1649 sctp_cmd_seq_t *commands,
1650 struct sctp_association *new_asoc) 1650 struct sctp_association *new_asoc)
1651 { 1651 {
1652 sctp_init_chunk_t *peer_init; 1652 sctp_init_chunk_t *peer_init;
1653 struct sctp_ulpevent *ev; 1653 struct sctp_ulpevent *ev;
1654 struct sctp_chunk *repl; 1654 struct sctp_chunk *repl;
1655 1655
1656 /* new_asoc is a brand-new association, so these are not yet 1656 /* new_asoc is a brand-new association, so these are not yet
1657 * side effects--it is safe to run them here. 1657 * side effects--it is safe to run them here.
1658 */ 1658 */
1659 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; 1659 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1660 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, 1660 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1661 sctp_source(chunk), peer_init, 1661 sctp_source(chunk), peer_init,
1662 GFP_ATOMIC)) 1662 GFP_ATOMIC))
1663 goto nomem; 1663 goto nomem;
1664 1664
1665 /* Update the content of current association. */ 1665 /* Update the content of current association. */
1666 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); 1666 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1667 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 1667 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1668 SCTP_STATE(SCTP_STATE_ESTABLISHED)); 1668 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1669 SCTP_INC_STATS(SCTP_MIB_CURRESTAB); 1669 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1670 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); 1670 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1671 1671
1672 repl = sctp_make_cookie_ack(new_asoc, chunk); 1672 repl = sctp_make_cookie_ack(new_asoc, chunk);
1673 if (!repl) 1673 if (!repl)
1674 goto nomem; 1674 goto nomem;
1675 1675
1676 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 1676 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1677 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); 1677 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1678 1678
1679 /* RFC 2960 5.1 Normal Establishment of an Association 1679 /* RFC 2960 5.1 Normal Establishment of an Association
1680 * 1680 *
1681 * D) IMPLEMENTATION NOTE: An implementation may choose to 1681 * D) IMPLEMENTATION NOTE: An implementation may choose to
1682 * send the Communication Up notification to the SCTP user 1682 * send the Communication Up notification to the SCTP user
1683 * upon reception of a valid COOKIE ECHO chunk. 1683 * upon reception of a valid COOKIE ECHO chunk.
1684 */ 1684 */
1685 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0, 1685 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0,
1686 new_asoc->c.sinit_num_ostreams, 1686 new_asoc->c.sinit_num_ostreams,
1687 new_asoc->c.sinit_max_instreams, 1687 new_asoc->c.sinit_max_instreams,
1688 GFP_ATOMIC); 1688 GFP_ATOMIC);
1689 if (!ev) 1689 if (!ev)
1690 goto nomem_ev; 1690 goto nomem_ev;
1691 1691
1692 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); 1692 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1693 1693
1694 /* Sockets API Draft Section 5.3.1.6 1694 /* Sockets API Draft Section 5.3.1.6
1695 * When a peer sends a Adaption Layer Indication parameter , SCTP 1695 * When a peer sends a Adaption Layer Indication parameter , SCTP
1696 * delivers this notification to inform the application that of the 1696 * delivers this notification to inform the application that of the
1697 * peers requested adaption layer. 1697 * peers requested adaption layer.
1698 */ 1698 */
1699 if (asoc->peer.adaption_ind) { 1699 if (asoc->peer.adaption_ind) {
1700 ev = sctp_ulpevent_make_adaption_indication(asoc, GFP_ATOMIC); 1700 ev = sctp_ulpevent_make_adaption_indication(asoc, GFP_ATOMIC);
1701 if (!ev) 1701 if (!ev)
1702 goto nomem_ev; 1702 goto nomem_ev;
1703 1703
1704 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, 1704 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1705 SCTP_ULPEVENT(ev)); 1705 SCTP_ULPEVENT(ev));
1706 } 1706 }
1707 1707
1708 return SCTP_DISPOSITION_CONSUME; 1708 return SCTP_DISPOSITION_CONSUME;
1709 1709
1710 nomem_ev: 1710 nomem_ev:
1711 sctp_chunk_free(repl); 1711 sctp_chunk_free(repl);
1712 nomem: 1712 nomem:
1713 return SCTP_DISPOSITION_NOMEM; 1713 return SCTP_DISPOSITION_NOMEM;
1714 } 1714 }
1715 1715
1716 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C') 1716 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1717 * 1717 *
1718 * Section 5.2.4 1718 * Section 5.2.4
1719 * C) In this case, the local endpoint's cookie has arrived late. 1719 * C) In this case, the local endpoint's cookie has arrived late.
1720 * Before it arrived, the local endpoint sent an INIT and received an 1720 * Before it arrived, the local endpoint sent an INIT and received an
1721 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag 1721 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1722 * but a new tag of its own. 1722 * but a new tag of its own.
1723 */ 1723 */
1724 /* This case represents an initialization collision. */ 1724 /* This case represents an initialization collision. */
1725 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep, 1725 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1726 const struct sctp_association *asoc, 1726 const struct sctp_association *asoc,
1727 struct sctp_chunk *chunk, 1727 struct sctp_chunk *chunk,
1728 sctp_cmd_seq_t *commands, 1728 sctp_cmd_seq_t *commands,
1729 struct sctp_association *new_asoc) 1729 struct sctp_association *new_asoc)
1730 { 1730 {
1731 /* The cookie should be silently discarded. 1731 /* The cookie should be silently discarded.
1732 * The endpoint SHOULD NOT change states and should leave 1732 * The endpoint SHOULD NOT change states and should leave
1733 * any timers running. 1733 * any timers running.
1734 */ 1734 */
1735 return SCTP_DISPOSITION_DISCARD; 1735 return SCTP_DISPOSITION_DISCARD;
1736 } 1736 }
1737 1737
1738 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D') 1738 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1739 * 1739 *
1740 * Section 5.2.4 1740 * Section 5.2.4
1741 * 1741 *
1742 * D) When both local and remote tags match the endpoint should always 1742 * D) When both local and remote tags match the endpoint should always
1743 * enter the ESTABLISHED state, if it has not already done so. 1743 * enter the ESTABLISHED state, if it has not already done so.
1744 */ 1744 */
1745 /* This case represents an initialization collision. */ 1745 /* This case represents an initialization collision. */
1746 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep, 1746 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1747 const struct sctp_association *asoc, 1747 const struct sctp_association *asoc,
1748 struct sctp_chunk *chunk, 1748 struct sctp_chunk *chunk,
1749 sctp_cmd_seq_t *commands, 1749 sctp_cmd_seq_t *commands,
1750 struct sctp_association *new_asoc) 1750 struct sctp_association *new_asoc)
1751 { 1751 {
1752 struct sctp_ulpevent *ev = NULL; 1752 struct sctp_ulpevent *ev = NULL;
1753 struct sctp_chunk *repl; 1753 struct sctp_chunk *repl;
1754 1754
1755 /* Clarification from Implementor's Guide: 1755 /* Clarification from Implementor's Guide:
1756 * D) When both local and remote tags match the endpoint should 1756 * D) When both local and remote tags match the endpoint should
1757 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state. 1757 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1758 * It should stop any cookie timer that may be running and send 1758 * It should stop any cookie timer that may be running and send
1759 * a COOKIE ACK. 1759 * a COOKIE ACK.
1760 */ 1760 */
1761 1761
1762 /* Don't accidentally move back into established state. */ 1762 /* Don't accidentally move back into established state. */
1763 if (asoc->state < SCTP_STATE_ESTABLISHED) { 1763 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1764 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 1764 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1765 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); 1765 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1766 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 1766 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1767 SCTP_STATE(SCTP_STATE_ESTABLISHED)); 1767 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1768 SCTP_INC_STATS(SCTP_MIB_CURRESTAB); 1768 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1769 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, 1769 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1770 SCTP_NULL()); 1770 SCTP_NULL());
1771 1771
1772 /* RFC 2960 5.1 Normal Establishment of an Association 1772 /* RFC 2960 5.1 Normal Establishment of an Association
1773 * 1773 *
1774 * D) IMPLEMENTATION NOTE: An implementation may choose 1774 * D) IMPLEMENTATION NOTE: An implementation may choose
1775 * to send the Communication Up notification to the 1775 * to send the Communication Up notification to the
1776 * SCTP user upon reception of a valid COOKIE 1776 * SCTP user upon reception of a valid COOKIE
1777 * ECHO chunk. 1777 * ECHO chunk.
1778 */ 1778 */
1779 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, 1779 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0,
1780 SCTP_COMM_UP, 0, 1780 SCTP_COMM_UP, 0,
1781 new_asoc->c.sinit_num_ostreams, 1781 new_asoc->c.sinit_num_ostreams,
1782 new_asoc->c.sinit_max_instreams, 1782 new_asoc->c.sinit_max_instreams,
1783 GFP_ATOMIC); 1783 GFP_ATOMIC);
1784 if (!ev) 1784 if (!ev)
1785 goto nomem; 1785 goto nomem;
1786 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, 1786 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1787 SCTP_ULPEVENT(ev)); 1787 SCTP_ULPEVENT(ev));
1788 1788
1789 /* Sockets API Draft Section 5.3.1.6 1789 /* Sockets API Draft Section 5.3.1.6
1790 * When a peer sends a Adaption Layer Indication parameter, 1790 * When a peer sends a Adaption Layer Indication parameter,
1791 * SCTP delivers this notification to inform the application 1791 * SCTP delivers this notification to inform the application
1792 * that of the peers requested adaption layer. 1792 * that of the peers requested adaption layer.
1793 */ 1793 */
1794 if (new_asoc->peer.adaption_ind) { 1794 if (new_asoc->peer.adaption_ind) {
1795 ev = sctp_ulpevent_make_adaption_indication(new_asoc, 1795 ev = sctp_ulpevent_make_adaption_indication(new_asoc,
1796 GFP_ATOMIC); 1796 GFP_ATOMIC);
1797 if (!ev) 1797 if (!ev)
1798 goto nomem; 1798 goto nomem;
1799 1799
1800 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, 1800 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1801 SCTP_ULPEVENT(ev)); 1801 SCTP_ULPEVENT(ev));
1802 } 1802 }
1803 } 1803 }
1804 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); 1804 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1805 1805
1806 repl = sctp_make_cookie_ack(new_asoc, chunk); 1806 repl = sctp_make_cookie_ack(new_asoc, chunk);
1807 if (!repl) 1807 if (!repl)
1808 goto nomem; 1808 goto nomem;
1809 1809
1810 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 1810 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1811 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); 1811 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1812 1812
1813 return SCTP_DISPOSITION_CONSUME; 1813 return SCTP_DISPOSITION_CONSUME;
1814 1814
1815 nomem: 1815 nomem:
1816 if (ev) 1816 if (ev)
1817 sctp_ulpevent_free(ev); 1817 sctp_ulpevent_free(ev);
1818 return SCTP_DISPOSITION_NOMEM; 1818 return SCTP_DISPOSITION_NOMEM;
1819 } 1819 }
1820 1820
1821 /* 1821 /*
1822 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying 1822 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1823 * chunk was retransmitted and then delayed in the network. 1823 * chunk was retransmitted and then delayed in the network.
1824 * 1824 *
1825 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists 1825 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1826 * 1826 *
1827 * Verification Tag: None. Do cookie validation. 1827 * Verification Tag: None. Do cookie validation.
1828 * 1828 *
1829 * Inputs 1829 * Inputs
1830 * (endpoint, asoc, chunk) 1830 * (endpoint, asoc, chunk)
1831 * 1831 *
1832 * Outputs 1832 * Outputs
1833 * (asoc, reply_msg, msg_up, timers, counters) 1833 * (asoc, reply_msg, msg_up, timers, counters)
1834 * 1834 *
1835 * The return value is the disposition of the chunk. 1835 * The return value is the disposition of the chunk.
1836 */ 1836 */
1837 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep, 1837 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1838 const struct sctp_association *asoc, 1838 const struct sctp_association *asoc,
1839 const sctp_subtype_t type, 1839 const sctp_subtype_t type,
1840 void *arg, 1840 void *arg,
1841 sctp_cmd_seq_t *commands) 1841 sctp_cmd_seq_t *commands)
1842 { 1842 {
1843 sctp_disposition_t retval; 1843 sctp_disposition_t retval;
1844 struct sctp_chunk *chunk = arg; 1844 struct sctp_chunk *chunk = arg;
1845 struct sctp_association *new_asoc; 1845 struct sctp_association *new_asoc;
1846 int error = 0; 1846 int error = 0;
1847 char action; 1847 char action;
1848 struct sctp_chunk *err_chk_p; 1848 struct sctp_chunk *err_chk_p;
1849 1849
1850 /* Make sure that the chunk has a valid length from the protocol 1850 /* Make sure that the chunk has a valid length from the protocol
1851 * perspective. In this case check to make sure we have at least 1851 * perspective. In this case check to make sure we have at least
1852 * enough for the chunk header. Cookie length verification is 1852 * enough for the chunk header. Cookie length verification is
1853 * done later. 1853 * done later.
1854 */ 1854 */
1855 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) 1855 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1856 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 1856 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1857 commands); 1857 commands);
1858 1858
1859 /* "Decode" the chunk. We have no optional parameters so we 1859 /* "Decode" the chunk. We have no optional parameters so we
1860 * are in good shape. 1860 * are in good shape.
1861 */ 1861 */
1862 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data; 1862 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1863 skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - 1863 skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1864 sizeof(sctp_chunkhdr_t)); 1864 sizeof(sctp_chunkhdr_t));
1865 1865
1866 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie 1866 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1867 * of a duplicate COOKIE ECHO match the Verification Tags of the 1867 * of a duplicate COOKIE ECHO match the Verification Tags of the
1868 * current association, consider the State Cookie valid even if 1868 * current association, consider the State Cookie valid even if
1869 * the lifespan is exceeded. 1869 * the lifespan is exceeded.
1870 */ 1870 */
1871 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, 1871 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1872 &err_chk_p); 1872 &err_chk_p);
1873 1873
1874 /* FIXME: 1874 /* FIXME:
1875 * If the re-build failed, what is the proper error path 1875 * If the re-build failed, what is the proper error path
1876 * from here? 1876 * from here?
1877 * 1877 *
1878 * [We should abort the association. --piggy] 1878 * [We should abort the association. --piggy]
1879 */ 1879 */
1880 if (!new_asoc) { 1880 if (!new_asoc) {
1881 /* FIXME: Several errors are possible. A bad cookie should 1881 /* FIXME: Several errors are possible. A bad cookie should
1882 * be silently discarded, but think about logging it too. 1882 * be silently discarded, but think about logging it too.
1883 */ 1883 */
1884 switch (error) { 1884 switch (error) {
1885 case -SCTP_IERROR_NOMEM: 1885 case -SCTP_IERROR_NOMEM:
1886 goto nomem; 1886 goto nomem;
1887 1887
1888 case -SCTP_IERROR_STALE_COOKIE: 1888 case -SCTP_IERROR_STALE_COOKIE:
1889 sctp_send_stale_cookie_err(ep, asoc, chunk, commands, 1889 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1890 err_chk_p); 1890 err_chk_p);
1891 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 1891 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1892 case -SCTP_IERROR_BAD_SIG: 1892 case -SCTP_IERROR_BAD_SIG:
1893 default: 1893 default:
1894 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 1894 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1895 }; 1895 };
1896 } 1896 }
1897 1897
1898 /* Compare the tie_tag in cookie with the verification tag of 1898 /* Compare the tie_tag in cookie with the verification tag of
1899 * current association. 1899 * current association.
1900 */ 1900 */
1901 action = sctp_tietags_compare(new_asoc, asoc); 1901 action = sctp_tietags_compare(new_asoc, asoc);
1902 1902
1903 switch (action) { 1903 switch (action) {
1904 case 'A': /* Association restart. */ 1904 case 'A': /* Association restart. */
1905 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands, 1905 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1906 new_asoc); 1906 new_asoc);
1907 break; 1907 break;
1908 1908
1909 case 'B': /* Collision case B. */ 1909 case 'B': /* Collision case B. */
1910 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands, 1910 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1911 new_asoc); 1911 new_asoc);
1912 break; 1912 break;
1913 1913
1914 case 'C': /* Collision case C. */ 1914 case 'C': /* Collision case C. */
1915 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands, 1915 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1916 new_asoc); 1916 new_asoc);
1917 break; 1917 break;
1918 1918
1919 case 'D': /* Collision case D. */ 1919 case 'D': /* Collision case D. */
1920 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands, 1920 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
1921 new_asoc); 1921 new_asoc);
1922 break; 1922 break;
1923 1923
1924 default: /* Discard packet for all others. */ 1924 default: /* Discard packet for all others. */
1925 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands); 1925 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1926 break; 1926 break;
1927 }; 1927 };
1928 1928
1929 /* Delete the tempory new association. */ 1929 /* Delete the tempory new association. */
1930 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); 1930 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1931 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); 1931 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1932 1932
1933 return retval; 1933 return retval;
1934 1934
1935 nomem: 1935 nomem:
1936 return SCTP_DISPOSITION_NOMEM; 1936 return SCTP_DISPOSITION_NOMEM;
1937 } 1937 }
1938 1938
1939 /* 1939 /*
1940 * Process an ABORT. (SHUTDOWN-PENDING state) 1940 * Process an ABORT. (SHUTDOWN-PENDING state)
1941 * 1941 *
1942 * See sctp_sf_do_9_1_abort(). 1942 * See sctp_sf_do_9_1_abort().
1943 */ 1943 */
1944 sctp_disposition_t sctp_sf_shutdown_pending_abort( 1944 sctp_disposition_t sctp_sf_shutdown_pending_abort(
1945 const struct sctp_endpoint *ep, 1945 const struct sctp_endpoint *ep,
1946 const struct sctp_association *asoc, 1946 const struct sctp_association *asoc,
1947 const sctp_subtype_t type, 1947 const sctp_subtype_t type,
1948 void *arg, 1948 void *arg,
1949 sctp_cmd_seq_t *commands) 1949 sctp_cmd_seq_t *commands)
1950 { 1950 {
1951 struct sctp_chunk *chunk = arg; 1951 struct sctp_chunk *chunk = arg;
1952 1952
1953 if (!sctp_vtag_verify_either(chunk, asoc)) 1953 if (!sctp_vtag_verify_either(chunk, asoc))
1954 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 1954 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1955 1955
1956 /* Make sure that the ABORT chunk has a valid length. 1956 /* Make sure that the ABORT chunk has a valid length.
1957 * Since this is an ABORT chunk, we have to discard it 1957 * Since this is an ABORT chunk, we have to discard it
1958 * because of the following text: 1958 * because of the following text:
1959 * RFC 2960, Section 3.3.7 1959 * RFC 2960, Section 3.3.7
1960 * If an endpoint receives an ABORT with a format error or for an 1960 * If an endpoint receives an ABORT with a format error or for an
1961 * association that doesn't exist, it MUST silently discard it. 1961 * association that doesn't exist, it MUST silently discard it.
1962 * Becasue the length is "invalid", we can't really discard just 1962 * Becasue the length is "invalid", we can't really discard just
1963 * as we do not know its true length. So, to be safe, discard the 1963 * as we do not know its true length. So, to be safe, discard the
1964 * packet. 1964 * packet.
1965 */ 1965 */
1966 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) 1966 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
1967 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 1967 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1968 1968
1969 /* Stop the T5-shutdown guard timer. */ 1969 /* Stop the T5-shutdown guard timer. */
1970 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 1970 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1971 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 1971 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1972 1972
1973 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands); 1973 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1974 } 1974 }
1975 1975
1976 /* 1976 /*
1977 * Process an ABORT. (SHUTDOWN-SENT state) 1977 * Process an ABORT. (SHUTDOWN-SENT state)
1978 * 1978 *
1979 * See sctp_sf_do_9_1_abort(). 1979 * See sctp_sf_do_9_1_abort().
1980 */ 1980 */
1981 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep, 1981 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
1982 const struct sctp_association *asoc, 1982 const struct sctp_association *asoc,
1983 const sctp_subtype_t type, 1983 const sctp_subtype_t type,
1984 void *arg, 1984 void *arg,
1985 sctp_cmd_seq_t *commands) 1985 sctp_cmd_seq_t *commands)
1986 { 1986 {
1987 struct sctp_chunk *chunk = arg; 1987 struct sctp_chunk *chunk = arg;
1988 1988
1989 if (!sctp_vtag_verify_either(chunk, asoc)) 1989 if (!sctp_vtag_verify_either(chunk, asoc))
1990 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 1990 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1991 1991
1992 /* Make sure that the ABORT chunk has a valid length. 1992 /* Make sure that the ABORT chunk has a valid length.
1993 * Since this is an ABORT chunk, we have to discard it 1993 * Since this is an ABORT chunk, we have to discard it
1994 * because of the following text: 1994 * because of the following text:
1995 * RFC 2960, Section 3.3.7 1995 * RFC 2960, Section 3.3.7
1996 * If an endpoint receives an ABORT with a format error or for an 1996 * If an endpoint receives an ABORT with a format error or for an
1997 * association that doesn't exist, it MUST silently discard it. 1997 * association that doesn't exist, it MUST silently discard it.
1998 * Becasue the length is "invalid", we can't really discard just 1998 * Becasue the length is "invalid", we can't really discard just
1999 * as we do not know its true length. So, to be safe, discard the 1999 * as we do not know its true length. So, to be safe, discard the
2000 * packet. 2000 * packet.
2001 */ 2001 */
2002 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) 2002 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2003 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2003 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2004 2004
2005 /* Stop the T2-shutdown timer. */ 2005 /* Stop the T2-shutdown timer. */
2006 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 2006 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2007 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 2007 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2008 2008
2009 /* Stop the T5-shutdown guard timer. */ 2009 /* Stop the T5-shutdown guard timer. */
2010 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 2010 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2011 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 2011 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2012 2012
2013 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands); 2013 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2014 } 2014 }
2015 2015
2016 /* 2016 /*
2017 * Process an ABORT. (SHUTDOWN-ACK-SENT state) 2017 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2018 * 2018 *
2019 * See sctp_sf_do_9_1_abort(). 2019 * See sctp_sf_do_9_1_abort().
2020 */ 2020 */
2021 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort( 2021 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2022 const struct sctp_endpoint *ep, 2022 const struct sctp_endpoint *ep,
2023 const struct sctp_association *asoc, 2023 const struct sctp_association *asoc,
2024 const sctp_subtype_t type, 2024 const sctp_subtype_t type,
2025 void *arg, 2025 void *arg,
2026 sctp_cmd_seq_t *commands) 2026 sctp_cmd_seq_t *commands)
2027 { 2027 {
2028 /* The same T2 timer, so we should be able to use 2028 /* The same T2 timer, so we should be able to use
2029 * common function with the SHUTDOWN-SENT state. 2029 * common function with the SHUTDOWN-SENT state.
2030 */ 2030 */
2031 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands); 2031 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2032 } 2032 }
2033 2033
2034 /* 2034 /*
2035 * Handle an Error received in COOKIE_ECHOED state. 2035 * Handle an Error received in COOKIE_ECHOED state.
2036 * 2036 *
2037 * Only handle the error type of stale COOKIE Error, the other errors will 2037 * Only handle the error type of stale COOKIE Error, the other errors will
2038 * be ignored. 2038 * be ignored.
2039 * 2039 *
2040 * Inputs 2040 * Inputs
2041 * (endpoint, asoc, chunk) 2041 * (endpoint, asoc, chunk)
2042 * 2042 *
2043 * Outputs 2043 * Outputs
2044 * (asoc, reply_msg, msg_up, timers, counters) 2044 * (asoc, reply_msg, msg_up, timers, counters)
2045 * 2045 *
2046 * The return value is the disposition of the chunk. 2046 * The return value is the disposition of the chunk.
2047 */ 2047 */
2048 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep, 2048 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2049 const struct sctp_association *asoc, 2049 const struct sctp_association *asoc,
2050 const sctp_subtype_t type, 2050 const sctp_subtype_t type,
2051 void *arg, 2051 void *arg,
2052 sctp_cmd_seq_t *commands) 2052 sctp_cmd_seq_t *commands)
2053 { 2053 {
2054 struct sctp_chunk *chunk = arg; 2054 struct sctp_chunk *chunk = arg;
2055 sctp_errhdr_t *err; 2055 sctp_errhdr_t *err;
2056 2056
2057 if (!sctp_vtag_verify(chunk, asoc)) 2057 if (!sctp_vtag_verify(chunk, asoc))
2058 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2058 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2059 2059
2060 /* Make sure that the ERROR chunk has a valid length. 2060 /* Make sure that the ERROR chunk has a valid length.
2061 * The parameter walking depends on this as well. 2061 * The parameter walking depends on this as well.
2062 */ 2062 */
2063 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t))) 2063 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2064 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 2064 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2065 commands); 2065 commands);
2066 2066
2067 /* Process the error here */ 2067 /* Process the error here */
2068 /* FUTURE FIXME: When PR-SCTP related and other optional 2068 /* FUTURE FIXME: When PR-SCTP related and other optional
2069 * parms are emitted, this will have to change to handle multiple 2069 * parms are emitted, this will have to change to handle multiple
2070 * errors. 2070 * errors.
2071 */ 2071 */
2072 sctp_walk_errors(err, chunk->chunk_hdr) { 2072 sctp_walk_errors(err, chunk->chunk_hdr) {
2073 if (SCTP_ERROR_STALE_COOKIE == err->cause) 2073 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2074 return sctp_sf_do_5_2_6_stale(ep, asoc, type, 2074 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2075 arg, commands); 2075 arg, commands);
2076 } 2076 }
2077 2077
2078 /* It is possible to have malformed error causes, and that 2078 /* It is possible to have malformed error causes, and that
2079 * will cause us to end the walk early. However, since 2079 * will cause us to end the walk early. However, since
2080 * we are discarding the packet, there should be no adverse 2080 * we are discarding the packet, there should be no adverse
2081 * affects. 2081 * affects.
2082 */ 2082 */
2083 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2083 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2084 } 2084 }
2085 2085
2086 /* 2086 /*
2087 * Handle a Stale COOKIE Error 2087 * Handle a Stale COOKIE Error
2088 * 2088 *
2089 * Section: 5.2.6 Handle Stale COOKIE Error 2089 * Section: 5.2.6 Handle Stale COOKIE Error
2090 * If the association is in the COOKIE-ECHOED state, the endpoint may elect 2090 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2091 * one of the following three alternatives. 2091 * one of the following three alternatives.
2092 * ... 2092 * ...
2093 * 3) Send a new INIT chunk to the endpoint, adding a Cookie 2093 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2094 * Preservative parameter requesting an extension to the lifetime of 2094 * Preservative parameter requesting an extension to the lifetime of
2095 * the State Cookie. When calculating the time extension, an 2095 * the State Cookie. When calculating the time extension, an
2096 * implementation SHOULD use the RTT information measured based on the 2096 * implementation SHOULD use the RTT information measured based on the
2097 * previous COOKIE ECHO / ERROR exchange, and should add no more 2097 * previous COOKIE ECHO / ERROR exchange, and should add no more
2098 * than 1 second beyond the measured RTT, due to long State Cookie 2098 * than 1 second beyond the measured RTT, due to long State Cookie
2099 * lifetimes making the endpoint more subject to a replay attack. 2099 * lifetimes making the endpoint more subject to a replay attack.
2100 * 2100 *
2101 * Verification Tag: Not explicit, but safe to ignore. 2101 * Verification Tag: Not explicit, but safe to ignore.
2102 * 2102 *
2103 * Inputs 2103 * Inputs
2104 * (endpoint, asoc, chunk) 2104 * (endpoint, asoc, chunk)
2105 * 2105 *
2106 * Outputs 2106 * Outputs
2107 * (asoc, reply_msg, msg_up, timers, counters) 2107 * (asoc, reply_msg, msg_up, timers, counters)
2108 * 2108 *
2109 * The return value is the disposition of the chunk. 2109 * The return value is the disposition of the chunk.
2110 */ 2110 */
2111 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep, 2111 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2112 const struct sctp_association *asoc, 2112 const struct sctp_association *asoc,
2113 const sctp_subtype_t type, 2113 const sctp_subtype_t type,
2114 void *arg, 2114 void *arg,
2115 sctp_cmd_seq_t *commands) 2115 sctp_cmd_seq_t *commands)
2116 { 2116 {
2117 struct sctp_chunk *chunk = arg; 2117 struct sctp_chunk *chunk = arg;
2118 time_t stale; 2118 time_t stale;
2119 sctp_cookie_preserve_param_t bht; 2119 sctp_cookie_preserve_param_t bht;
2120 sctp_errhdr_t *err; 2120 sctp_errhdr_t *err;
2121 struct sctp_chunk *reply; 2121 struct sctp_chunk *reply;
2122 struct sctp_bind_addr *bp; 2122 struct sctp_bind_addr *bp;
2123 int attempts = asoc->init_err_counter + 1; 2123 int attempts = asoc->init_err_counter + 1;
2124 2124
2125 if (attempts > asoc->max_init_attempts) { 2125 if (attempts > asoc->max_init_attempts) {
2126 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, 2126 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2127 SCTP_U32(SCTP_ERROR_STALE_COOKIE)); 2127 SCTP_U32(SCTP_ERROR_STALE_COOKIE));
2128 return SCTP_DISPOSITION_DELETE_TCB; 2128 return SCTP_DISPOSITION_DELETE_TCB;
2129 } 2129 }
2130 2130
2131 err = (sctp_errhdr_t *)(chunk->skb->data); 2131 err = (sctp_errhdr_t *)(chunk->skb->data);
2132 2132
2133 /* When calculating the time extension, an implementation 2133 /* When calculating the time extension, an implementation
2134 * SHOULD use the RTT information measured based on the 2134 * SHOULD use the RTT information measured based on the
2135 * previous COOKIE ECHO / ERROR exchange, and should add no 2135 * previous COOKIE ECHO / ERROR exchange, and should add no
2136 * more than 1 second beyond the measured RTT, due to long 2136 * more than 1 second beyond the measured RTT, due to long
2137 * State Cookie lifetimes making the endpoint more subject to 2137 * State Cookie lifetimes making the endpoint more subject to
2138 * a replay attack. 2138 * a replay attack.
2139 * Measure of Staleness's unit is usec. (1/1000000 sec) 2139 * Measure of Staleness's unit is usec. (1/1000000 sec)
2140 * Suggested Cookie Life-span Increment's unit is msec. 2140 * Suggested Cookie Life-span Increment's unit is msec.
2141 * (1/1000 sec) 2141 * (1/1000 sec)
2142 * In general, if you use the suggested cookie life, the value 2142 * In general, if you use the suggested cookie life, the value
2143 * found in the field of measure of staleness should be doubled 2143 * found in the field of measure of staleness should be doubled
2144 * to give ample time to retransmit the new cookie and thus 2144 * to give ample time to retransmit the new cookie and thus
2145 * yield a higher probability of success on the reattempt. 2145 * yield a higher probability of success on the reattempt.
2146 */ 2146 */
2147 stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t))); 2147 stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t)));
2148 stale = (stale * 2) / 1000; 2148 stale = (stale * 2) / 1000;
2149 2149
2150 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE; 2150 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2151 bht.param_hdr.length = htons(sizeof(bht)); 2151 bht.param_hdr.length = htons(sizeof(bht));
2152 bht.lifespan_increment = htonl(stale); 2152 bht.lifespan_increment = htonl(stale);
2153 2153
2154 /* Build that new INIT chunk. */ 2154 /* Build that new INIT chunk. */
2155 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; 2155 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2156 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht)); 2156 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2157 if (!reply) 2157 if (!reply)
2158 goto nomem; 2158 goto nomem;
2159 2159
2160 sctp_addto_chunk(reply, sizeof(bht), &bht); 2160 sctp_addto_chunk(reply, sizeof(bht), &bht);
2161 2161
2162 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */ 2162 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2163 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL()); 2163 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2164 2164
2165 /* Stop pending T3-rtx and heartbeat timers */ 2165 /* Stop pending T3-rtx and heartbeat timers */
2166 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL()); 2166 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2167 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); 2167 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2168 2168
2169 /* Delete non-primary peer ip addresses since we are transitioning 2169 /* Delete non-primary peer ip addresses since we are transitioning
2170 * back to the COOKIE-WAIT state 2170 * back to the COOKIE-WAIT state
2171 */ 2171 */
2172 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL()); 2172 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2173 2173
2174 /* If we've sent any data bundled with COOKIE-ECHO we will need to 2174 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2175 * resend 2175 * resend
2176 */ 2176 */
2177 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, 2177 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN,
2178 SCTP_TRANSPORT(asoc->peer.primary_path)); 2178 SCTP_TRANSPORT(asoc->peer.primary_path));
2179 2179
2180 /* Cast away the const modifier, as we want to just 2180 /* Cast away the const modifier, as we want to just
2181 * rerun it through as a sideffect. 2181 * rerun it through as a sideffect.
2182 */ 2182 */
2183 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL()); 2183 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2184 2184
2185 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 2185 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2186 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); 2186 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2187 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 2187 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2188 SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); 2188 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2189 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 2189 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2190 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 2190 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2191 2191
2192 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 2192 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2193 2193
2194 return SCTP_DISPOSITION_CONSUME; 2194 return SCTP_DISPOSITION_CONSUME;
2195 2195
2196 nomem: 2196 nomem:
2197 return SCTP_DISPOSITION_NOMEM; 2197 return SCTP_DISPOSITION_NOMEM;
2198 } 2198 }
2199 2199
2200 /* 2200 /*
2201 * Process an ABORT. 2201 * Process an ABORT.
2202 * 2202 *
2203 * Section: 9.1 2203 * Section: 9.1
2204 * After checking the Verification Tag, the receiving endpoint shall 2204 * After checking the Verification Tag, the receiving endpoint shall
2205 * remove the association from its record, and shall report the 2205 * remove the association from its record, and shall report the
2206 * termination to its upper layer. 2206 * termination to its upper layer.
2207 * 2207 *
2208 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules 2208 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2209 * B) Rules for packet carrying ABORT: 2209 * B) Rules for packet carrying ABORT:
2210 * 2210 *
2211 * - The endpoint shall always fill in the Verification Tag field of the 2211 * - The endpoint shall always fill in the Verification Tag field of the
2212 * outbound packet with the destination endpoint's tag value if it 2212 * outbound packet with the destination endpoint's tag value if it
2213 * is known. 2213 * is known.
2214 * 2214 *
2215 * - If the ABORT is sent in response to an OOTB packet, the endpoint 2215 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2216 * MUST follow the procedure described in Section 8.4. 2216 * MUST follow the procedure described in Section 8.4.
2217 * 2217 *
2218 * - The receiver MUST accept the packet if the Verification Tag 2218 * - The receiver MUST accept the packet if the Verification Tag
2219 * matches either its own tag, OR the tag of its peer. Otherwise, the 2219 * matches either its own tag, OR the tag of its peer. Otherwise, the
2220 * receiver MUST silently discard the packet and take no further 2220 * receiver MUST silently discard the packet and take no further
2221 * action. 2221 * action.
2222 * 2222 *
2223 * Inputs 2223 * Inputs
2224 * (endpoint, asoc, chunk) 2224 * (endpoint, asoc, chunk)
2225 * 2225 *
2226 * Outputs 2226 * Outputs
2227 * (asoc, reply_msg, msg_up, timers, counters) 2227 * (asoc, reply_msg, msg_up, timers, counters)
2228 * 2228 *
2229 * The return value is the disposition of the chunk. 2229 * The return value is the disposition of the chunk.
2230 */ 2230 */
2231 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep, 2231 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2232 const struct sctp_association *asoc, 2232 const struct sctp_association *asoc,
2233 const sctp_subtype_t type, 2233 const sctp_subtype_t type,
2234 void *arg, 2234 void *arg,
2235 sctp_cmd_seq_t *commands) 2235 sctp_cmd_seq_t *commands)
2236 { 2236 {
2237 struct sctp_chunk *chunk = arg; 2237 struct sctp_chunk *chunk = arg;
2238 unsigned len; 2238 unsigned len;
2239 __u16 error = SCTP_ERROR_NO_ERROR; 2239 __u16 error = SCTP_ERROR_NO_ERROR;
2240 2240
2241 if (!sctp_vtag_verify_either(chunk, asoc)) 2241 if (!sctp_vtag_verify_either(chunk, asoc))
2242 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2242 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2243 2243
2244 /* Make sure that the ABORT chunk has a valid length. 2244 /* Make sure that the ABORT chunk has a valid length.
2245 * Since this is an ABORT chunk, we have to discard it 2245 * Since this is an ABORT chunk, we have to discard it
2246 * because of the following text: 2246 * because of the following text:
2247 * RFC 2960, Section 3.3.7 2247 * RFC 2960, Section 3.3.7
2248 * If an endpoint receives an ABORT with a format error or for an 2248 * If an endpoint receives an ABORT with a format error or for an
2249 * association that doesn't exist, it MUST silently discard it. 2249 * association that doesn't exist, it MUST silently discard it.
2250 * Becasue the length is "invalid", we can't really discard just 2250 * Becasue the length is "invalid", we can't really discard just
2251 * as we do not know its true length. So, to be safe, discard the 2251 * as we do not know its true length. So, to be safe, discard the
2252 * packet. 2252 * packet.
2253 */ 2253 */
2254 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) 2254 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2255 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2255 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2256 2256
2257 /* See if we have an error cause code in the chunk. */ 2257 /* See if we have an error cause code in the chunk. */
2258 len = ntohs(chunk->chunk_hdr->length); 2258 len = ntohs(chunk->chunk_hdr->length);
2259 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) 2259 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2260 error = ((sctp_errhdr_t *)chunk->skb->data)->cause; 2260 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2261 2261
2262 /* ASSOC_FAILED will DELETE_TCB. */ 2262 /* ASSOC_FAILED will DELETE_TCB. */
2263 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_U32(error)); 2263 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_U32(error));
2264 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 2264 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2265 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 2265 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2266 2266
2267 return SCTP_DISPOSITION_ABORT; 2267 return SCTP_DISPOSITION_ABORT;
2268 } 2268 }
2269 2269
2270 /* 2270 /*
2271 * Process an ABORT. (COOKIE-WAIT state) 2271 * Process an ABORT. (COOKIE-WAIT state)
2272 * 2272 *
2273 * See sctp_sf_do_9_1_abort() above. 2273 * See sctp_sf_do_9_1_abort() above.
2274 */ 2274 */
2275 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep, 2275 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2276 const struct sctp_association *asoc, 2276 const struct sctp_association *asoc,
2277 const sctp_subtype_t type, 2277 const sctp_subtype_t type,
2278 void *arg, 2278 void *arg,
2279 sctp_cmd_seq_t *commands) 2279 sctp_cmd_seq_t *commands)
2280 { 2280 {
2281 struct sctp_chunk *chunk = arg; 2281 struct sctp_chunk *chunk = arg;
2282 unsigned len; 2282 unsigned len;
2283 __u16 error = SCTP_ERROR_NO_ERROR; 2283 __u16 error = SCTP_ERROR_NO_ERROR;
2284 2284
2285 if (!sctp_vtag_verify_either(chunk, asoc)) 2285 if (!sctp_vtag_verify_either(chunk, asoc))
2286 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2286 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2287 2287
2288 /* Make sure that the ABORT chunk has a valid length. 2288 /* Make sure that the ABORT chunk has a valid length.
2289 * Since this is an ABORT chunk, we have to discard it 2289 * Since this is an ABORT chunk, we have to discard it
2290 * because of the following text: 2290 * because of the following text:
2291 * RFC 2960, Section 3.3.7 2291 * RFC 2960, Section 3.3.7
2292 * If an endpoint receives an ABORT with a format error or for an 2292 * If an endpoint receives an ABORT with a format error or for an
2293 * association that doesn't exist, it MUST silently discard it. 2293 * association that doesn't exist, it MUST silently discard it.
2294 * Becasue the length is "invalid", we can't really discard just 2294 * Becasue the length is "invalid", we can't really discard just
2295 * as we do not know its true length. So, to be safe, discard the 2295 * as we do not know its true length. So, to be safe, discard the
2296 * packet. 2296 * packet.
2297 */ 2297 */
2298 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) 2298 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2299 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2299 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2300 2300
2301 /* See if we have an error cause code in the chunk. */ 2301 /* See if we have an error cause code in the chunk. */
2302 len = ntohs(chunk->chunk_hdr->length); 2302 len = ntohs(chunk->chunk_hdr->length);
2303 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) 2303 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2304 error = ((sctp_errhdr_t *)chunk->skb->data)->cause; 2304 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2305 2305
2306 return sctp_stop_t1_and_abort(commands, error, asoc, chunk->transport); 2306 return sctp_stop_t1_and_abort(commands, error, asoc, chunk->transport);
2307 } 2307 }
2308 2308
2309 /* 2309 /*
2310 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state) 2310 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2311 */ 2311 */
2312 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep, 2312 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2313 const struct sctp_association *asoc, 2313 const struct sctp_association *asoc,
2314 const sctp_subtype_t type, 2314 const sctp_subtype_t type,
2315 void *arg, 2315 void *arg,
2316 sctp_cmd_seq_t *commands) 2316 sctp_cmd_seq_t *commands)
2317 { 2317 {
2318 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR, asoc, 2318 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR, asoc,
2319 (struct sctp_transport *)arg); 2319 (struct sctp_transport *)arg);
2320 } 2320 }
2321 2321
2322 /* 2322 /*
2323 * Process an ABORT. (COOKIE-ECHOED state) 2323 * Process an ABORT. (COOKIE-ECHOED state)
2324 */ 2324 */
2325 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep, 2325 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2326 const struct sctp_association *asoc, 2326 const struct sctp_association *asoc,
2327 const sctp_subtype_t type, 2327 const sctp_subtype_t type,
2328 void *arg, 2328 void *arg,
2329 sctp_cmd_seq_t *commands) 2329 sctp_cmd_seq_t *commands)
2330 { 2330 {
2331 /* There is a single T1 timer, so we should be able to use 2331 /* There is a single T1 timer, so we should be able to use
2332 * common function with the COOKIE-WAIT state. 2332 * common function with the COOKIE-WAIT state.
2333 */ 2333 */
2334 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands); 2334 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2335 } 2335 }
2336 2336
2337 /* 2337 /*
2338 * Stop T1 timer and abort association with "INIT failed". 2338 * Stop T1 timer and abort association with "INIT failed".
2339 * 2339 *
2340 * This is common code called by several sctp_sf_*_abort() functions above. 2340 * This is common code called by several sctp_sf_*_abort() functions above.
2341 */ 2341 */
2342 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, 2342 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2343 __u16 error, 2343 __u16 error,
2344 const struct sctp_association *asoc, 2344 const struct sctp_association *asoc,
2345 struct sctp_transport *transport) 2345 struct sctp_transport *transport)
2346 { 2346 {
2347 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n"); 2347 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2348 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 2348 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2349 SCTP_STATE(SCTP_STATE_CLOSED)); 2349 SCTP_STATE(SCTP_STATE_CLOSED));
2350 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 2350 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2351 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 2351 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2352 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 2352 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2353 /* CMD_INIT_FAILED will DELETE_TCB. */ 2353 /* CMD_INIT_FAILED will DELETE_TCB. */
2354 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, 2354 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2355 SCTP_U32(error)); 2355 SCTP_U32(error));
2356 return SCTP_DISPOSITION_ABORT; 2356 return SCTP_DISPOSITION_ABORT;
2357 } 2357 }
2358 2358
2359 /* 2359 /*
2360 * sctp_sf_do_9_2_shut 2360 * sctp_sf_do_9_2_shut
2361 * 2361 *
2362 * Section: 9.2 2362 * Section: 9.2
2363 * Upon the reception of the SHUTDOWN, the peer endpoint shall 2363 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2364 * - enter the SHUTDOWN-RECEIVED state, 2364 * - enter the SHUTDOWN-RECEIVED state,
2365 * 2365 *
2366 * - stop accepting new data from its SCTP user 2366 * - stop accepting new data from its SCTP user
2367 * 2367 *
2368 * - verify, by checking the Cumulative TSN Ack field of the chunk, 2368 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2369 * that all its outstanding DATA chunks have been received by the 2369 * that all its outstanding DATA chunks have been received by the
2370 * SHUTDOWN sender. 2370 * SHUTDOWN sender.
2371 * 2371 *
2372 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT 2372 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2373 * send a SHUTDOWN in response to a ULP request. And should discard 2373 * send a SHUTDOWN in response to a ULP request. And should discard
2374 * subsequent SHUTDOWN chunks. 2374 * subsequent SHUTDOWN chunks.
2375 * 2375 *
2376 * If there are still outstanding DATA chunks left, the SHUTDOWN 2376 * If there are still outstanding DATA chunks left, the SHUTDOWN
2377 * receiver shall continue to follow normal data transmission 2377 * receiver shall continue to follow normal data transmission
2378 * procedures defined in Section 6 until all outstanding DATA chunks 2378 * procedures defined in Section 6 until all outstanding DATA chunks
2379 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept 2379 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2380 * new data from its SCTP user. 2380 * new data from its SCTP user.
2381 * 2381 *
2382 * Verification Tag: 8.5 Verification Tag [Normal verification] 2382 * Verification Tag: 8.5 Verification Tag [Normal verification]
2383 * 2383 *
2384 * Inputs 2384 * Inputs
2385 * (endpoint, asoc, chunk) 2385 * (endpoint, asoc, chunk)
2386 * 2386 *
2387 * Outputs 2387 * Outputs
2388 * (asoc, reply_msg, msg_up, timers, counters) 2388 * (asoc, reply_msg, msg_up, timers, counters)
2389 * 2389 *
2390 * The return value is the disposition of the chunk. 2390 * The return value is the disposition of the chunk.
2391 */ 2391 */
2392 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep, 2392 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2393 const struct sctp_association *asoc, 2393 const struct sctp_association *asoc,
2394 const sctp_subtype_t type, 2394 const sctp_subtype_t type,
2395 void *arg, 2395 void *arg,
2396 sctp_cmd_seq_t *commands) 2396 sctp_cmd_seq_t *commands)
2397 { 2397 {
2398 struct sctp_chunk *chunk = arg; 2398 struct sctp_chunk *chunk = arg;
2399 sctp_shutdownhdr_t *sdh; 2399 sctp_shutdownhdr_t *sdh;
2400 sctp_disposition_t disposition; 2400 sctp_disposition_t disposition;
2401 struct sctp_ulpevent *ev; 2401 struct sctp_ulpevent *ev;
2402 2402
2403 if (!sctp_vtag_verify(chunk, asoc)) 2403 if (!sctp_vtag_verify(chunk, asoc))
2404 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2404 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2405 2405
2406 /* Make sure that the SHUTDOWN chunk has a valid length. */ 2406 /* Make sure that the SHUTDOWN chunk has a valid length. */
2407 if (!sctp_chunk_length_valid(chunk, 2407 if (!sctp_chunk_length_valid(chunk,
2408 sizeof(struct sctp_shutdown_chunk_t))) 2408 sizeof(struct sctp_shutdown_chunk_t)))
2409 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 2409 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2410 commands); 2410 commands);
2411 2411
2412 /* Convert the elaborate header. */ 2412 /* Convert the elaborate header. */
2413 sdh = (sctp_shutdownhdr_t *)chunk->skb->data; 2413 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2414 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t)); 2414 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2415 chunk->subh.shutdown_hdr = sdh; 2415 chunk->subh.shutdown_hdr = sdh;
2416 2416
2417 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT 2417 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2418 * When a peer sends a SHUTDOWN, SCTP delivers this notification to 2418 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2419 * inform the application that it should cease sending data. 2419 * inform the application that it should cease sending data.
2420 */ 2420 */
2421 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC); 2421 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2422 if (!ev) { 2422 if (!ev) {
2423 disposition = SCTP_DISPOSITION_NOMEM; 2423 disposition = SCTP_DISPOSITION_NOMEM;
2424 goto out; 2424 goto out;
2425 } 2425 }
2426 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); 2426 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2427 2427
2428 /* Upon the reception of the SHUTDOWN, the peer endpoint shall 2428 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2429 * - enter the SHUTDOWN-RECEIVED state, 2429 * - enter the SHUTDOWN-RECEIVED state,
2430 * - stop accepting new data from its SCTP user 2430 * - stop accepting new data from its SCTP user
2431 * 2431 *
2432 * [This is implicit in the new state.] 2432 * [This is implicit in the new state.]
2433 */ 2433 */
2434 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 2434 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2435 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED)); 2435 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2436 disposition = SCTP_DISPOSITION_CONSUME; 2436 disposition = SCTP_DISPOSITION_CONSUME;
2437 2437
2438 if (sctp_outq_is_empty(&asoc->outqueue)) { 2438 if (sctp_outq_is_empty(&asoc->outqueue)) {
2439 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type, 2439 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2440 arg, commands); 2440 arg, commands);
2441 } 2441 }
2442 2442
2443 if (SCTP_DISPOSITION_NOMEM == disposition) 2443 if (SCTP_DISPOSITION_NOMEM == disposition)
2444 goto out; 2444 goto out;
2445 2445
2446 /* - verify, by checking the Cumulative TSN Ack field of the 2446 /* - verify, by checking the Cumulative TSN Ack field of the
2447 * chunk, that all its outstanding DATA chunks have been 2447 * chunk, that all its outstanding DATA chunks have been
2448 * received by the SHUTDOWN sender. 2448 * received by the SHUTDOWN sender.
2449 */ 2449 */
2450 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN, 2450 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2451 SCTP_U32(chunk->subh.shutdown_hdr->cum_tsn_ack)); 2451 SCTP_U32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2452 2452
2453 out: 2453 out:
2454 return disposition; 2454 return disposition;
2455 } 2455 }
2456 2456
2457 /* RFC 2960 9.2 2457 /* RFC 2960 9.2
2458 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk 2458 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2459 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination 2459 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2460 * transport addresses (either in the IP addresses or in the INIT chunk) 2460 * transport addresses (either in the IP addresses or in the INIT chunk)
2461 * that belong to this association, it should discard the INIT chunk and 2461 * that belong to this association, it should discard the INIT chunk and
2462 * retransmit the SHUTDOWN ACK chunk. 2462 * retransmit the SHUTDOWN ACK chunk.
2463 */ 2463 */
2464 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep, 2464 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2465 const struct sctp_association *asoc, 2465 const struct sctp_association *asoc,
2466 const sctp_subtype_t type, 2466 const sctp_subtype_t type,
2467 void *arg, 2467 void *arg,
2468 sctp_cmd_seq_t *commands) 2468 sctp_cmd_seq_t *commands)
2469 { 2469 {
2470 struct sctp_chunk *chunk = (struct sctp_chunk *) arg; 2470 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2471 struct sctp_chunk *reply; 2471 struct sctp_chunk *reply;
2472 2472
2473 /* Since we are not going to really process this INIT, there 2473 /* Since we are not going to really process this INIT, there
2474 * is no point in verifying chunk boundries. Just generate 2474 * is no point in verifying chunk boundries. Just generate
2475 * the SHUTDOWN ACK. 2475 * the SHUTDOWN ACK.
2476 */ 2476 */
2477 reply = sctp_make_shutdown_ack(asoc, chunk); 2477 reply = sctp_make_shutdown_ack(asoc, chunk);
2478 if (NULL == reply) 2478 if (NULL == reply)
2479 goto nomem; 2479 goto nomem;
2480 2480
2481 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for 2481 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2482 * the T2-SHUTDOWN timer. 2482 * the T2-SHUTDOWN timer.
2483 */ 2483 */
2484 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); 2484 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2485 2485
2486 /* and restart the T2-shutdown timer. */ 2486 /* and restart the T2-shutdown timer. */
2487 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 2487 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2488 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 2488 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2489 2489
2490 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 2490 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2491 2491
2492 return SCTP_DISPOSITION_CONSUME; 2492 return SCTP_DISPOSITION_CONSUME;
2493 nomem: 2493 nomem:
2494 return SCTP_DISPOSITION_NOMEM; 2494 return SCTP_DISPOSITION_NOMEM;
2495 } 2495 }
2496 2496
2497 /* 2497 /*
2498 * sctp_sf_do_ecn_cwr 2498 * sctp_sf_do_ecn_cwr
2499 * 2499 *
2500 * Section: Appendix A: Explicit Congestion Notification 2500 * Section: Appendix A: Explicit Congestion Notification
2501 * 2501 *
2502 * CWR: 2502 * CWR:
2503 * 2503 *
2504 * RFC 2481 details a specific bit for a sender to send in the header of 2504 * RFC 2481 details a specific bit for a sender to send in the header of
2505 * its next outbound TCP segment to indicate to its peer that it has 2505 * its next outbound TCP segment to indicate to its peer that it has
2506 * reduced its congestion window. This is termed the CWR bit. For 2506 * reduced its congestion window. This is termed the CWR bit. For
2507 * SCTP the same indication is made by including the CWR chunk. 2507 * SCTP the same indication is made by including the CWR chunk.
2508 * This chunk contains one data element, i.e. the TSN number that 2508 * This chunk contains one data element, i.e. the TSN number that
2509 * was sent in the ECNE chunk. This element represents the lowest 2509 * was sent in the ECNE chunk. This element represents the lowest
2510 * TSN number in the datagram that was originally marked with the 2510 * TSN number in the datagram that was originally marked with the
2511 * CE bit. 2511 * CE bit.
2512 * 2512 *
2513 * Verification Tag: 8.5 Verification Tag [Normal verification] 2513 * Verification Tag: 8.5 Verification Tag [Normal verification]
2514 * Inputs 2514 * Inputs
2515 * (endpoint, asoc, chunk) 2515 * (endpoint, asoc, chunk)
2516 * 2516 *
2517 * Outputs 2517 * Outputs
2518 * (asoc, reply_msg, msg_up, timers, counters) 2518 * (asoc, reply_msg, msg_up, timers, counters)
2519 * 2519 *
2520 * The return value is the disposition of the chunk. 2520 * The return value is the disposition of the chunk.
2521 */ 2521 */
2522 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep, 2522 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2523 const struct sctp_association *asoc, 2523 const struct sctp_association *asoc,
2524 const sctp_subtype_t type, 2524 const sctp_subtype_t type,
2525 void *arg, 2525 void *arg,
2526 sctp_cmd_seq_t *commands) 2526 sctp_cmd_seq_t *commands)
2527 { 2527 {
2528 sctp_cwrhdr_t *cwr; 2528 sctp_cwrhdr_t *cwr;
2529 struct sctp_chunk *chunk = arg; 2529 struct sctp_chunk *chunk = arg;
2530 2530
2531 if (!sctp_vtag_verify(chunk, asoc)) 2531 if (!sctp_vtag_verify(chunk, asoc))
2532 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2532 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2533 2533
2534 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t))) 2534 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2535 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 2535 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2536 commands); 2536 commands);
2537 2537
2538 cwr = (sctp_cwrhdr_t *) chunk->skb->data; 2538 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2539 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t)); 2539 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2540 2540
2541 cwr->lowest_tsn = ntohl(cwr->lowest_tsn); 2541 cwr->lowest_tsn = ntohl(cwr->lowest_tsn);
2542 2542
2543 /* Does this CWR ack the last sent congestion notification? */ 2543 /* Does this CWR ack the last sent congestion notification? */
2544 if (TSN_lte(asoc->last_ecne_tsn, cwr->lowest_tsn)) { 2544 if (TSN_lte(asoc->last_ecne_tsn, cwr->lowest_tsn)) {
2545 /* Stop sending ECNE. */ 2545 /* Stop sending ECNE. */
2546 sctp_add_cmd_sf(commands, 2546 sctp_add_cmd_sf(commands,
2547 SCTP_CMD_ECN_CWR, 2547 SCTP_CMD_ECN_CWR,
2548 SCTP_U32(cwr->lowest_tsn)); 2548 SCTP_U32(cwr->lowest_tsn));
2549 } 2549 }
2550 return SCTP_DISPOSITION_CONSUME; 2550 return SCTP_DISPOSITION_CONSUME;
2551 } 2551 }
2552 2552
2553 /* 2553 /*
2554 * sctp_sf_do_ecne 2554 * sctp_sf_do_ecne
2555 * 2555 *
2556 * Section: Appendix A: Explicit Congestion Notification 2556 * Section: Appendix A: Explicit Congestion Notification
2557 * 2557 *
2558 * ECN-Echo 2558 * ECN-Echo
2559 * 2559 *
2560 * RFC 2481 details a specific bit for a receiver to send back in its 2560 * RFC 2481 details a specific bit for a receiver to send back in its
2561 * TCP acknowledgements to notify the sender of the Congestion 2561 * TCP acknowledgements to notify the sender of the Congestion
2562 * Experienced (CE) bit having arrived from the network. For SCTP this 2562 * Experienced (CE) bit having arrived from the network. For SCTP this
2563 * same indication is made by including the ECNE chunk. This chunk 2563 * same indication is made by including the ECNE chunk. This chunk
2564 * contains one data element, i.e. the lowest TSN associated with the IP 2564 * contains one data element, i.e. the lowest TSN associated with the IP
2565 * datagram marked with the CE bit..... 2565 * datagram marked with the CE bit.....
2566 * 2566 *
2567 * Verification Tag: 8.5 Verification Tag [Normal verification] 2567 * Verification Tag: 8.5 Verification Tag [Normal verification]
2568 * Inputs 2568 * Inputs
2569 * (endpoint, asoc, chunk) 2569 * (endpoint, asoc, chunk)
2570 * 2570 *
2571 * Outputs 2571 * Outputs
2572 * (asoc, reply_msg, msg_up, timers, counters) 2572 * (asoc, reply_msg, msg_up, timers, counters)
2573 * 2573 *
2574 * The return value is the disposition of the chunk. 2574 * The return value is the disposition of the chunk.
2575 */ 2575 */
2576 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep, 2576 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2577 const struct sctp_association *asoc, 2577 const struct sctp_association *asoc,
2578 const sctp_subtype_t type, 2578 const sctp_subtype_t type,
2579 void *arg, 2579 void *arg,
2580 sctp_cmd_seq_t *commands) 2580 sctp_cmd_seq_t *commands)
2581 { 2581 {
2582 sctp_ecnehdr_t *ecne; 2582 sctp_ecnehdr_t *ecne;
2583 struct sctp_chunk *chunk = arg; 2583 struct sctp_chunk *chunk = arg;
2584 2584
2585 if (!sctp_vtag_verify(chunk, asoc)) 2585 if (!sctp_vtag_verify(chunk, asoc))
2586 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2586 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2587 2587
2588 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t))) 2588 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2589 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 2589 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2590 commands); 2590 commands);
2591 2591
2592 ecne = (sctp_ecnehdr_t *) chunk->skb->data; 2592 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2593 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t)); 2593 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2594 2594
2595 /* If this is a newer ECNE than the last CWR packet we sent out */ 2595 /* If this is a newer ECNE than the last CWR packet we sent out */
2596 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE, 2596 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2597 SCTP_U32(ntohl(ecne->lowest_tsn))); 2597 SCTP_U32(ntohl(ecne->lowest_tsn)));
2598 2598
2599 return SCTP_DISPOSITION_CONSUME; 2599 return SCTP_DISPOSITION_CONSUME;
2600 } 2600 }
2601 2601
2602 /* 2602 /*
2603 * Section: 6.2 Acknowledgement on Reception of DATA Chunks 2603 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2604 * 2604 *
2605 * The SCTP endpoint MUST always acknowledge the reception of each valid 2605 * The SCTP endpoint MUST always acknowledge the reception of each valid
2606 * DATA chunk. 2606 * DATA chunk.
2607 * 2607 *
2608 * The guidelines on delayed acknowledgement algorithm specified in 2608 * The guidelines on delayed acknowledgement algorithm specified in
2609 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an 2609 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2610 * acknowledgement SHOULD be generated for at least every second packet 2610 * acknowledgement SHOULD be generated for at least every second packet
2611 * (not every second DATA chunk) received, and SHOULD be generated within 2611 * (not every second DATA chunk) received, and SHOULD be generated within
2612 * 200 ms of the arrival of any unacknowledged DATA chunk. In some 2612 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2613 * situations it may be beneficial for an SCTP transmitter to be more 2613 * situations it may be beneficial for an SCTP transmitter to be more
2614 * conservative than the algorithms detailed in this document allow. 2614 * conservative than the algorithms detailed in this document allow.
2615 * However, an SCTP transmitter MUST NOT be more aggressive than the 2615 * However, an SCTP transmitter MUST NOT be more aggressive than the
2616 * following algorithms allow. 2616 * following algorithms allow.
2617 * 2617 *
2618 * A SCTP receiver MUST NOT generate more than one SACK for every 2618 * A SCTP receiver MUST NOT generate more than one SACK for every
2619 * incoming packet, other than to update the offered window as the 2619 * incoming packet, other than to update the offered window as the
2620 * receiving application consumes new data. 2620 * receiving application consumes new data.
2621 * 2621 *
2622 * Verification Tag: 8.5 Verification Tag [Normal verification] 2622 * Verification Tag: 8.5 Verification Tag [Normal verification]
2623 * 2623 *
2624 * Inputs 2624 * Inputs
2625 * (endpoint, asoc, chunk) 2625 * (endpoint, asoc, chunk)
2626 * 2626 *
2627 * Outputs 2627 * Outputs
2628 * (asoc, reply_msg, msg_up, timers, counters) 2628 * (asoc, reply_msg, msg_up, timers, counters)
2629 * 2629 *
2630 * The return value is the disposition of the chunk. 2630 * The return value is the disposition of the chunk.
2631 */ 2631 */
2632 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep, 2632 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2633 const struct sctp_association *asoc, 2633 const struct sctp_association *asoc,
2634 const sctp_subtype_t type, 2634 const sctp_subtype_t type,
2635 void *arg, 2635 void *arg,
2636 sctp_cmd_seq_t *commands) 2636 sctp_cmd_seq_t *commands)
2637 { 2637 {
2638 struct sctp_chunk *chunk = arg; 2638 struct sctp_chunk *chunk = arg;
2639 int error; 2639 int error;
2640 2640
2641 if (!sctp_vtag_verify(chunk, asoc)) { 2641 if (!sctp_vtag_verify(chunk, asoc)) {
2642 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, 2642 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2643 SCTP_NULL()); 2643 SCTP_NULL());
2644 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2644 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2645 } 2645 }
2646 2646
2647 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t))) 2647 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2648 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 2648 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2649 commands); 2649 commands);
2650 2650
2651 error = sctp_eat_data(asoc, chunk, commands ); 2651 error = sctp_eat_data(asoc, chunk, commands );
2652 switch (error) { 2652 switch (error) {
2653 case SCTP_IERROR_NO_ERROR: 2653 case SCTP_IERROR_NO_ERROR:
2654 break; 2654 break;
2655 case SCTP_IERROR_HIGH_TSN: 2655 case SCTP_IERROR_HIGH_TSN:
2656 case SCTP_IERROR_BAD_STREAM: 2656 case SCTP_IERROR_BAD_STREAM:
2657 goto discard_noforce; 2657 goto discard_noforce;
2658 case SCTP_IERROR_DUP_TSN: 2658 case SCTP_IERROR_DUP_TSN:
2659 case SCTP_IERROR_IGNORE_TSN: 2659 case SCTP_IERROR_IGNORE_TSN:
2660 goto discard_force; 2660 goto discard_force;
2661 case SCTP_IERROR_NO_DATA: 2661 case SCTP_IERROR_NO_DATA:
2662 goto consume; 2662 goto consume;
2663 default: 2663 default:
2664 BUG(); 2664 BUG();
2665 } 2665 }
2666 2666
2667 if (asoc->autoclose) { 2667 if (asoc->autoclose) {
2668 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 2668 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2669 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 2669 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2670 } 2670 }
2671 2671
2672 /* If this is the last chunk in a packet, we need to count it 2672 /* If this is the last chunk in a packet, we need to count it
2673 * toward sack generation. Note that we need to SACK every 2673 * toward sack generation. Note that we need to SACK every
2674 * OTHER packet containing data chunks, EVEN IF WE DISCARD 2674 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2675 * THEM. We elect to NOT generate SACK's if the chunk fails 2675 * THEM. We elect to NOT generate SACK's if the chunk fails
2676 * the verification tag test. 2676 * the verification tag test.
2677 * 2677 *
2678 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks 2678 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2679 * 2679 *
2680 * The SCTP endpoint MUST always acknowledge the reception of 2680 * The SCTP endpoint MUST always acknowledge the reception of
2681 * each valid DATA chunk. 2681 * each valid DATA chunk.
2682 * 2682 *
2683 * The guidelines on delayed acknowledgement algorithm 2683 * The guidelines on delayed acknowledgement algorithm
2684 * specified in Section 4.2 of [RFC2581] SHOULD be followed. 2684 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2685 * Specifically, an acknowledgement SHOULD be generated for at 2685 * Specifically, an acknowledgement SHOULD be generated for at
2686 * least every second packet (not every second DATA chunk) 2686 * least every second packet (not every second DATA chunk)
2687 * received, and SHOULD be generated within 200 ms of the 2687 * received, and SHOULD be generated within 200 ms of the
2688 * arrival of any unacknowledged DATA chunk. In some 2688 * arrival of any unacknowledged DATA chunk. In some
2689 * situations it may be beneficial for an SCTP transmitter to 2689 * situations it may be beneficial for an SCTP transmitter to
2690 * be more conservative than the algorithms detailed in this 2690 * be more conservative than the algorithms detailed in this
2691 * document allow. However, an SCTP transmitter MUST NOT be 2691 * document allow. However, an SCTP transmitter MUST NOT be
2692 * more aggressive than the following algorithms allow. 2692 * more aggressive than the following algorithms allow.
2693 */ 2693 */
2694 if (chunk->end_of_packet) 2694 if (chunk->end_of_packet)
2695 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); 2695 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2696 2696
2697 return SCTP_DISPOSITION_CONSUME; 2697 return SCTP_DISPOSITION_CONSUME;
2698 2698
2699 discard_force: 2699 discard_force:
2700 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks 2700 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2701 * 2701 *
2702 * When a packet arrives with duplicate DATA chunk(s) and with 2702 * When a packet arrives with duplicate DATA chunk(s) and with
2703 * no new DATA chunk(s), the endpoint MUST immediately send a 2703 * no new DATA chunk(s), the endpoint MUST immediately send a
2704 * SACK with no delay. If a packet arrives with duplicate 2704 * SACK with no delay. If a packet arrives with duplicate
2705 * DATA chunk(s) bundled with new DATA chunks, the endpoint 2705 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2706 * MAY immediately send a SACK. Normally receipt of duplicate 2706 * MAY immediately send a SACK. Normally receipt of duplicate
2707 * DATA chunks will occur when the original SACK chunk was lost 2707 * DATA chunks will occur when the original SACK chunk was lost
2708 * and the peer's RTO has expired. The duplicate TSN number(s) 2708 * and the peer's RTO has expired. The duplicate TSN number(s)
2709 * SHOULD be reported in the SACK as duplicate. 2709 * SHOULD be reported in the SACK as duplicate.
2710 */ 2710 */
2711 /* In our case, we split the MAY SACK advice up whether or not 2711 /* In our case, we split the MAY SACK advice up whether or not
2712 * the last chunk is a duplicate.' 2712 * the last chunk is a duplicate.'
2713 */ 2713 */
2714 if (chunk->end_of_packet) 2714 if (chunk->end_of_packet)
2715 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); 2715 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2716 return SCTP_DISPOSITION_DISCARD; 2716 return SCTP_DISPOSITION_DISCARD;
2717 2717
2718 discard_noforce: 2718 discard_noforce:
2719 if (chunk->end_of_packet) 2719 if (chunk->end_of_packet)
2720 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); 2720 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2721 2721
2722 return SCTP_DISPOSITION_DISCARD; 2722 return SCTP_DISPOSITION_DISCARD;
2723 consume: 2723 consume:
2724 return SCTP_DISPOSITION_CONSUME; 2724 return SCTP_DISPOSITION_CONSUME;
2725 2725
2726 } 2726 }
2727 2727
2728 /* 2728 /*
2729 * sctp_sf_eat_data_fast_4_4 2729 * sctp_sf_eat_data_fast_4_4
2730 * 2730 *
2731 * Section: 4 (4) 2731 * Section: 4 (4)
2732 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received 2732 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2733 * DATA chunks without delay. 2733 * DATA chunks without delay.
2734 * 2734 *
2735 * Verification Tag: 8.5 Verification Tag [Normal verification] 2735 * Verification Tag: 8.5 Verification Tag [Normal verification]
2736 * Inputs 2736 * Inputs
2737 * (endpoint, asoc, chunk) 2737 * (endpoint, asoc, chunk)
2738 * 2738 *
2739 * Outputs 2739 * Outputs
2740 * (asoc, reply_msg, msg_up, timers, counters) 2740 * (asoc, reply_msg, msg_up, timers, counters)
2741 * 2741 *
2742 * The return value is the disposition of the chunk. 2742 * The return value is the disposition of the chunk.
2743 */ 2743 */
2744 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep, 2744 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2745 const struct sctp_association *asoc, 2745 const struct sctp_association *asoc,
2746 const sctp_subtype_t type, 2746 const sctp_subtype_t type,
2747 void *arg, 2747 void *arg,
2748 sctp_cmd_seq_t *commands) 2748 sctp_cmd_seq_t *commands)
2749 { 2749 {
2750 struct sctp_chunk *chunk = arg; 2750 struct sctp_chunk *chunk = arg;
2751 int error; 2751 int error;
2752 2752
2753 if (!sctp_vtag_verify(chunk, asoc)) { 2753 if (!sctp_vtag_verify(chunk, asoc)) {
2754 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, 2754 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2755 SCTP_NULL()); 2755 SCTP_NULL());
2756 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2756 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2757 } 2757 }
2758 2758
2759 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t))) 2759 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2760 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 2760 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2761 commands); 2761 commands);
2762 2762
2763 error = sctp_eat_data(asoc, chunk, commands ); 2763 error = sctp_eat_data(asoc, chunk, commands );
2764 switch (error) { 2764 switch (error) {
2765 case SCTP_IERROR_NO_ERROR: 2765 case SCTP_IERROR_NO_ERROR:
2766 case SCTP_IERROR_HIGH_TSN: 2766 case SCTP_IERROR_HIGH_TSN:
2767 case SCTP_IERROR_DUP_TSN: 2767 case SCTP_IERROR_DUP_TSN:
2768 case SCTP_IERROR_IGNORE_TSN: 2768 case SCTP_IERROR_IGNORE_TSN:
2769 case SCTP_IERROR_BAD_STREAM: 2769 case SCTP_IERROR_BAD_STREAM:
2770 break; 2770 break;
2771 case SCTP_IERROR_NO_DATA: 2771 case SCTP_IERROR_NO_DATA:
2772 goto consume; 2772 goto consume;
2773 default: 2773 default:
2774 BUG(); 2774 BUG();
2775 } 2775 }
2776 2776
2777 /* Go a head and force a SACK, since we are shutting down. */ 2777 /* Go a head and force a SACK, since we are shutting down. */
2778 2778
2779 /* Implementor's Guide. 2779 /* Implementor's Guide.
2780 * 2780 *
2781 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately 2781 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2782 * respond to each received packet containing one or more DATA chunk(s) 2782 * respond to each received packet containing one or more DATA chunk(s)
2783 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer 2783 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2784 */ 2784 */
2785 if (chunk->end_of_packet) { 2785 if (chunk->end_of_packet) {
2786 /* We must delay the chunk creation since the cumulative 2786 /* We must delay the chunk creation since the cumulative
2787 * TSN has not been updated yet. 2787 * TSN has not been updated yet.
2788 */ 2788 */
2789 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); 2789 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2790 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); 2790 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2791 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 2791 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2792 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 2792 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2793 } 2793 }
2794 2794
2795 consume: 2795 consume:
2796 return SCTP_DISPOSITION_CONSUME; 2796 return SCTP_DISPOSITION_CONSUME;
2797 } 2797 }
2798 2798
2799 /* 2799 /*
2800 * Section: 6.2 Processing a Received SACK 2800 * Section: 6.2 Processing a Received SACK
2801 * D) Any time a SACK arrives, the endpoint performs the following: 2801 * D) Any time a SACK arrives, the endpoint performs the following:
2802 * 2802 *
2803 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point, 2803 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2804 * then drop the SACK. Since Cumulative TSN Ack is monotonically 2804 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2805 * increasing, a SACK whose Cumulative TSN Ack is less than the 2805 * increasing, a SACK whose Cumulative TSN Ack is less than the
2806 * Cumulative TSN Ack Point indicates an out-of-order SACK. 2806 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2807 * 2807 *
2808 * ii) Set rwnd equal to the newly received a_rwnd minus the number 2808 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2809 * of bytes still outstanding after processing the Cumulative TSN Ack 2809 * of bytes still outstanding after processing the Cumulative TSN Ack
2810 * and the Gap Ack Blocks. 2810 * and the Gap Ack Blocks.
2811 * 2811 *
2812 * iii) If the SACK is missing a TSN that was previously 2812 * iii) If the SACK is missing a TSN that was previously
2813 * acknowledged via a Gap Ack Block (e.g., the data receiver 2813 * acknowledged via a Gap Ack Block (e.g., the data receiver
2814 * reneged on the data), then mark the corresponding DATA chunk 2814 * reneged on the data), then mark the corresponding DATA chunk
2815 * as available for retransmit: Mark it as missing for fast 2815 * as available for retransmit: Mark it as missing for fast
2816 * retransmit as described in Section 7.2.4 and if no retransmit 2816 * retransmit as described in Section 7.2.4 and if no retransmit
2817 * timer is running for the destination address to which the DATA 2817 * timer is running for the destination address to which the DATA
2818 * chunk was originally transmitted, then T3-rtx is started for 2818 * chunk was originally transmitted, then T3-rtx is started for
2819 * that destination address. 2819 * that destination address.
2820 * 2820 *
2821 * Verification Tag: 8.5 Verification Tag [Normal verification] 2821 * Verification Tag: 8.5 Verification Tag [Normal verification]
2822 * 2822 *
2823 * Inputs 2823 * Inputs
2824 * (endpoint, asoc, chunk) 2824 * (endpoint, asoc, chunk)
2825 * 2825 *
2826 * Outputs 2826 * Outputs
2827 * (asoc, reply_msg, msg_up, timers, counters) 2827 * (asoc, reply_msg, msg_up, timers, counters)
2828 * 2828 *
2829 * The return value is the disposition of the chunk. 2829 * The return value is the disposition of the chunk.
2830 */ 2830 */
2831 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep, 2831 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2832 const struct sctp_association *asoc, 2832 const struct sctp_association *asoc,
2833 const sctp_subtype_t type, 2833 const sctp_subtype_t type,
2834 void *arg, 2834 void *arg,
2835 sctp_cmd_seq_t *commands) 2835 sctp_cmd_seq_t *commands)
2836 { 2836 {
2837 struct sctp_chunk *chunk = arg; 2837 struct sctp_chunk *chunk = arg;
2838 sctp_sackhdr_t *sackh; 2838 sctp_sackhdr_t *sackh;
2839 __u32 ctsn; 2839 __u32 ctsn;
2840 2840
2841 if (!sctp_vtag_verify(chunk, asoc)) 2841 if (!sctp_vtag_verify(chunk, asoc))
2842 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2842 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2843 2843
2844 /* Make sure that the SACK chunk has a valid length. */ 2844 /* Make sure that the SACK chunk has a valid length. */
2845 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t))) 2845 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
2846 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 2846 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2847 commands); 2847 commands);
2848 2848
2849 /* Pull the SACK chunk from the data buffer */ 2849 /* Pull the SACK chunk from the data buffer */
2850 sackh = sctp_sm_pull_sack(chunk); 2850 sackh = sctp_sm_pull_sack(chunk);
2851 /* Was this a bogus SACK? */ 2851 /* Was this a bogus SACK? */
2852 if (!sackh) 2852 if (!sackh)
2853 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2853 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2854 chunk->subh.sack_hdr = sackh; 2854 chunk->subh.sack_hdr = sackh;
2855 ctsn = ntohl(sackh->cum_tsn_ack); 2855 ctsn = ntohl(sackh->cum_tsn_ack);
2856 2856
2857 /* i) If Cumulative TSN Ack is less than the Cumulative TSN 2857 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2858 * Ack Point, then drop the SACK. Since Cumulative TSN 2858 * Ack Point, then drop the SACK. Since Cumulative TSN
2859 * Ack is monotonically increasing, a SACK whose 2859 * Ack is monotonically increasing, a SACK whose
2860 * Cumulative TSN Ack is less than the Cumulative TSN Ack 2860 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2861 * Point indicates an out-of-order SACK. 2861 * Point indicates an out-of-order SACK.
2862 */ 2862 */
2863 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { 2863 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2864 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn); 2864 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2865 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point); 2865 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2866 return SCTP_DISPOSITION_DISCARD; 2866 return SCTP_DISPOSITION_DISCARD;
2867 } 2867 }
2868 2868
2869 /* Return this SACK for further processing. */ 2869 /* Return this SACK for further processing. */
2870 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh)); 2870 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2871 2871
2872 /* Note: We do the rest of the work on the PROCESS_SACK 2872 /* Note: We do the rest of the work on the PROCESS_SACK
2873 * sideeffect. 2873 * sideeffect.
2874 */ 2874 */
2875 return SCTP_DISPOSITION_CONSUME; 2875 return SCTP_DISPOSITION_CONSUME;
2876 } 2876 }
2877 2877
2878 /* 2878 /*
2879 * Generate an ABORT in response to a packet. 2879 * Generate an ABORT in response to a packet.
2880 * 2880 *
2881 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41 2881 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
2882 * 2882 *
2883 * 8) The receiver should respond to the sender of the OOTB packet with 2883 * 8) The receiver should respond to the sender of the OOTB packet with
2884 * an ABORT. When sending the ABORT, the receiver of the OOTB packet 2884 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2885 * MUST fill in the Verification Tag field of the outbound packet 2885 * MUST fill in the Verification Tag field of the outbound packet
2886 * with the value found in the Verification Tag field of the OOTB 2886 * with the value found in the Verification Tag field of the OOTB
2887 * packet and set the T-bit in the Chunk Flags to indicate that the 2887 * packet and set the T-bit in the Chunk Flags to indicate that the
2888 * Verification Tag is reflected. After sending this ABORT, the 2888 * Verification Tag is reflected. After sending this ABORT, the
2889 * receiver of the OOTB packet shall discard the OOTB packet and take 2889 * receiver of the OOTB packet shall discard the OOTB packet and take
2890 * no further action. 2890 * no further action.
2891 * 2891 *
2892 * Verification Tag: 2892 * Verification Tag:
2893 * 2893 *
2894 * The return value is the disposition of the chunk. 2894 * The return value is the disposition of the chunk.
2895 */ 2895 */
2896 sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep, 2896 sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
2897 const struct sctp_association *asoc, 2897 const struct sctp_association *asoc,
2898 const sctp_subtype_t type, 2898 const sctp_subtype_t type,
2899 void *arg, 2899 void *arg,
2900 sctp_cmd_seq_t *commands) 2900 sctp_cmd_seq_t *commands)
2901 { 2901 {
2902 struct sctp_packet *packet = NULL; 2902 struct sctp_packet *packet = NULL;
2903 struct sctp_chunk *chunk = arg; 2903 struct sctp_chunk *chunk = arg;
2904 struct sctp_chunk *abort; 2904 struct sctp_chunk *abort;
2905 2905
2906 packet = sctp_ootb_pkt_new(asoc, chunk); 2906 packet = sctp_ootb_pkt_new(asoc, chunk);
2907 2907
2908 if (packet) { 2908 if (packet) {
2909 /* Make an ABORT. The T bit will be set if the asoc 2909 /* Make an ABORT. The T bit will be set if the asoc
2910 * is NULL. 2910 * is NULL.
2911 */ 2911 */
2912 abort = sctp_make_abort(asoc, chunk, 0); 2912 abort = sctp_make_abort(asoc, chunk, 0);
2913 if (!abort) { 2913 if (!abort) {
2914 sctp_ootb_pkt_free(packet); 2914 sctp_ootb_pkt_free(packet);
2915 return SCTP_DISPOSITION_NOMEM; 2915 return SCTP_DISPOSITION_NOMEM;
2916 } 2916 }
2917 2917
2918 /* Reflect vtag if T-Bit is set */ 2918 /* Reflect vtag if T-Bit is set */
2919 if (sctp_test_T_bit(abort)) 2919 if (sctp_test_T_bit(abort))
2920 packet->vtag = ntohl(chunk->sctp_hdr->vtag); 2920 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
2921 2921
2922 /* Set the skb to the belonging sock for accounting. */ 2922 /* Set the skb to the belonging sock for accounting. */
2923 abort->skb->sk = ep->base.sk; 2923 abort->skb->sk = ep->base.sk;
2924 2924
2925 sctp_packet_append_chunk(packet, abort); 2925 sctp_packet_append_chunk(packet, abort);
2926 2926
2927 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, 2927 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2928 SCTP_PACKET(packet)); 2928 SCTP_PACKET(packet));
2929 2929
2930 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); 2930 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
2931 2931
2932 return SCTP_DISPOSITION_CONSUME; 2932 return SCTP_DISPOSITION_CONSUME;
2933 } 2933 }
2934 2934
2935 return SCTP_DISPOSITION_NOMEM; 2935 return SCTP_DISPOSITION_NOMEM;
2936 } 2936 }
2937 2937
2938 /* 2938 /*
2939 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR 2939 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2940 * event as ULP notification for each cause included in the chunk. 2940 * event as ULP notification for each cause included in the chunk.
2941 * 2941 *
2942 * API 5.3.1.3 - SCTP_REMOTE_ERROR 2942 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2943 * 2943 *
2944 * The return value is the disposition of the chunk. 2944 * The return value is the disposition of the chunk.
2945 */ 2945 */
2946 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep, 2946 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
2947 const struct sctp_association *asoc, 2947 const struct sctp_association *asoc,
2948 const sctp_subtype_t type, 2948 const sctp_subtype_t type,
2949 void *arg, 2949 void *arg,
2950 sctp_cmd_seq_t *commands) 2950 sctp_cmd_seq_t *commands)
2951 { 2951 {
2952 struct sctp_chunk *chunk = arg; 2952 struct sctp_chunk *chunk = arg;
2953 struct sctp_ulpevent *ev; 2953 struct sctp_ulpevent *ev;
2954 2954
2955 if (!sctp_vtag_verify(chunk, asoc)) 2955 if (!sctp_vtag_verify(chunk, asoc))
2956 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 2956 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2957 2957
2958 /* Make sure that the ERROR chunk has a valid length. */ 2958 /* Make sure that the ERROR chunk has a valid length. */
2959 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t))) 2959 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2960 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 2960 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2961 commands); 2961 commands);
2962 2962
2963 while (chunk->chunk_end > chunk->skb->data) { 2963 while (chunk->chunk_end > chunk->skb->data) {
2964 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0, 2964 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
2965 GFP_ATOMIC); 2965 GFP_ATOMIC);
2966 if (!ev) 2966 if (!ev)
2967 goto nomem; 2967 goto nomem;
2968 2968
2969 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP, 2969 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
2970 SCTP_ULPEVENT(ev))) { 2970 SCTP_ULPEVENT(ev))) {
2971 sctp_ulpevent_free(ev); 2971 sctp_ulpevent_free(ev);
2972 goto nomem; 2972 goto nomem;
2973 } 2973 }
2974 2974
2975 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR, 2975 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
2976 SCTP_CHUNK(chunk)); 2976 SCTP_CHUNK(chunk));
2977 } 2977 }
2978 return SCTP_DISPOSITION_CONSUME; 2978 return SCTP_DISPOSITION_CONSUME;
2979 2979
2980 nomem: 2980 nomem:
2981 return SCTP_DISPOSITION_NOMEM; 2981 return SCTP_DISPOSITION_NOMEM;
2982 } 2982 }
2983 2983
2984 /* 2984 /*
2985 * Process an inbound SHUTDOWN ACK. 2985 * Process an inbound SHUTDOWN ACK.
2986 * 2986 *
2987 * From Section 9.2: 2987 * From Section 9.2:
2988 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall 2988 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2989 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its 2989 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
2990 * peer, and remove all record of the association. 2990 * peer, and remove all record of the association.
2991 * 2991 *
2992 * The return value is the disposition. 2992 * The return value is the disposition.
2993 */ 2993 */
2994 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep, 2994 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
2995 const struct sctp_association *asoc, 2995 const struct sctp_association *asoc,
2996 const sctp_subtype_t type, 2996 const sctp_subtype_t type,
2997 void *arg, 2997 void *arg,
2998 sctp_cmd_seq_t *commands) 2998 sctp_cmd_seq_t *commands)
2999 { 2999 {
3000 struct sctp_chunk *chunk = arg; 3000 struct sctp_chunk *chunk = arg;
3001 struct sctp_chunk *reply; 3001 struct sctp_chunk *reply;
3002 struct sctp_ulpevent *ev; 3002 struct sctp_ulpevent *ev;
3003 3003
3004 if (!sctp_vtag_verify(chunk, asoc)) 3004 if (!sctp_vtag_verify(chunk, asoc))
3005 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3005 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3006 3006
3007 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */ 3007 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3008 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) 3008 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3009 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 3009 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3010 commands); 3010 commands);
3011 3011
3012 /* 10.2 H) SHUTDOWN COMPLETE notification 3012 /* 10.2 H) SHUTDOWN COMPLETE notification
3013 * 3013 *
3014 * When SCTP completes the shutdown procedures (section 9.2) this 3014 * When SCTP completes the shutdown procedures (section 9.2) this
3015 * notification is passed to the upper layer. 3015 * notification is passed to the upper layer.
3016 */ 3016 */
3017 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, 3017 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3018 0, 0, 0, GFP_ATOMIC); 3018 0, 0, 0, GFP_ATOMIC);
3019 if (!ev) 3019 if (!ev)
3020 goto nomem; 3020 goto nomem;
3021 3021
3022 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); 3022 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3023 3023
3024 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall 3024 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3025 * stop the T2-shutdown timer, 3025 * stop the T2-shutdown timer,
3026 */ 3026 */
3027 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 3027 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3028 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 3028 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3029 3029
3030 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 3030 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3031 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 3031 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3032 3032
3033 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */ 3033 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3034 reply = sctp_make_shutdown_complete(asoc, chunk); 3034 reply = sctp_make_shutdown_complete(asoc, chunk);
3035 if (!reply) 3035 if (!reply)
3036 goto nomem; 3036 goto nomem;
3037 3037
3038 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 3038 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3039 SCTP_STATE(SCTP_STATE_CLOSED)); 3039 SCTP_STATE(SCTP_STATE_CLOSED));
3040 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); 3040 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3041 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 3041 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3042 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 3042 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3043 3043
3044 /* ...and remove all record of the association. */ 3044 /* ...and remove all record of the association. */
3045 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); 3045 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3046 return SCTP_DISPOSITION_DELETE_TCB; 3046 return SCTP_DISPOSITION_DELETE_TCB;
3047 3047
3048 nomem: 3048 nomem:
3049 return SCTP_DISPOSITION_NOMEM; 3049 return SCTP_DISPOSITION_NOMEM;
3050 } 3050 }
3051 3051
3052 /* 3052 /*
3053 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41. 3053 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3054 * 3054 *
3055 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should 3055 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3056 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. 3056 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3057 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB 3057 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3058 * packet must fill in the Verification Tag field of the outbound 3058 * packet must fill in the Verification Tag field of the outbound
3059 * packet with the Verification Tag received in the SHUTDOWN ACK and 3059 * packet with the Verification Tag received in the SHUTDOWN ACK and
3060 * set the T-bit in the Chunk Flags to indicate that the Verification 3060 * set the T-bit in the Chunk Flags to indicate that the Verification
3061 * Tag is reflected. 3061 * Tag is reflected.
3062 * 3062 *
3063 * 8) The receiver should respond to the sender of the OOTB packet with 3063 * 8) The receiver should respond to the sender of the OOTB packet with
3064 * an ABORT. When sending the ABORT, the receiver of the OOTB packet 3064 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3065 * MUST fill in the Verification Tag field of the outbound packet 3065 * MUST fill in the Verification Tag field of the outbound packet
3066 * with the value found in the Verification Tag field of the OOTB 3066 * with the value found in the Verification Tag field of the OOTB
3067 * packet and set the T-bit in the Chunk Flags to indicate that the 3067 * packet and set the T-bit in the Chunk Flags to indicate that the
3068 * Verification Tag is reflected. After sending this ABORT, the 3068 * Verification Tag is reflected. After sending this ABORT, the
3069 * receiver of the OOTB packet shall discard the OOTB packet and take 3069 * receiver of the OOTB packet shall discard the OOTB packet and take
3070 * no further action. 3070 * no further action.
3071 */ 3071 */
3072 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep, 3072 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3073 const struct sctp_association *asoc, 3073 const struct sctp_association *asoc,
3074 const sctp_subtype_t type, 3074 const sctp_subtype_t type,
3075 void *arg, 3075 void *arg,
3076 sctp_cmd_seq_t *commands) 3076 sctp_cmd_seq_t *commands)
3077 { 3077 {
3078 struct sctp_chunk *chunk = arg; 3078 struct sctp_chunk *chunk = arg;
3079 struct sk_buff *skb = chunk->skb; 3079 struct sk_buff *skb = chunk->skb;
3080 sctp_chunkhdr_t *ch; 3080 sctp_chunkhdr_t *ch;
3081 __u8 *ch_end; 3081 __u8 *ch_end;
3082 int ootb_shut_ack = 0; 3082 int ootb_shut_ack = 0;
3083 3083
3084 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES); 3084 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3085 3085
3086 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr; 3086 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
3087 do { 3087 do {
3088 /* Break out if chunk length is less then minimal. */ 3088 /* Break out if chunk length is less then minimal. */
3089 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t)) 3089 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
3090 break; 3090 break;
3091 3091
3092 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length)); 3092 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3093 if (ch_end > skb->tail) 3093 if (ch_end > skb->tail)
3094 break; 3094 break;
3095 3095
3096 if (SCTP_CID_SHUTDOWN_ACK == ch->type) 3096 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3097 ootb_shut_ack = 1; 3097 ootb_shut_ack = 1;
3098 3098
3099 /* RFC 2960, Section 3.3.7 3099 /* RFC 2960, Section 3.3.7
3100 * Moreover, under any circumstances, an endpoint that 3100 * Moreover, under any circumstances, an endpoint that
3101 * receives an ABORT MUST NOT respond to that ABORT by 3101 * receives an ABORT MUST NOT respond to that ABORT by
3102 * sending an ABORT of its own. 3102 * sending an ABORT of its own.
3103 */ 3103 */
3104 if (SCTP_CID_ABORT == ch->type) 3104 if (SCTP_CID_ABORT == ch->type)
3105 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3105 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3106 3106
3107 ch = (sctp_chunkhdr_t *) ch_end; 3107 ch = (sctp_chunkhdr_t *) ch_end;
3108 } while (ch_end < skb->tail); 3108 } while (ch_end < skb->tail);
3109 3109
3110 if (ootb_shut_ack) 3110 if (ootb_shut_ack)
3111 sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands); 3111 sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
3112 else 3112 else
3113 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); 3113 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
3114 3114
3115 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3115 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3116 } 3116 }
3117 3117
3118 /* 3118 /*
3119 * Handle an "Out of the blue" SHUTDOWN ACK. 3119 * Handle an "Out of the blue" SHUTDOWN ACK.
3120 * 3120 *
3121 * Section: 8.4 5, sctpimpguide 2.41. 3121 * Section: 8.4 5, sctpimpguide 2.41.
3122 * 3122 *
3123 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should 3123 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3124 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. 3124 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3125 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB 3125 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3126 * packet must fill in the Verification Tag field of the outbound 3126 * packet must fill in the Verification Tag field of the outbound
3127 * packet with the Verification Tag received in the SHUTDOWN ACK and 3127 * packet with the Verification Tag received in the SHUTDOWN ACK and
3128 * set the T-bit in the Chunk Flags to indicate that the Verification 3128 * set the T-bit in the Chunk Flags to indicate that the Verification
3129 * Tag is reflected. 3129 * Tag is reflected.
3130 * 3130 *
3131 * Inputs 3131 * Inputs
3132 * (endpoint, asoc, type, arg, commands) 3132 * (endpoint, asoc, type, arg, commands)
3133 * 3133 *
3134 * Outputs 3134 * Outputs
3135 * (sctp_disposition_t) 3135 * (sctp_disposition_t)
3136 * 3136 *
3137 * The return value is the disposition of the chunk. 3137 * The return value is the disposition of the chunk.
3138 */ 3138 */
3139 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep, 3139 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3140 const struct sctp_association *asoc, 3140 const struct sctp_association *asoc,
3141 const sctp_subtype_t type, 3141 const sctp_subtype_t type,
3142 void *arg, 3142 void *arg,
3143 sctp_cmd_seq_t *commands) 3143 sctp_cmd_seq_t *commands)
3144 { 3144 {
3145 struct sctp_packet *packet = NULL; 3145 struct sctp_packet *packet = NULL;
3146 struct sctp_chunk *chunk = arg; 3146 struct sctp_chunk *chunk = arg;
3147 struct sctp_chunk *shut; 3147 struct sctp_chunk *shut;
3148 3148
3149 packet = sctp_ootb_pkt_new(asoc, chunk); 3149 packet = sctp_ootb_pkt_new(asoc, chunk);
3150 3150
3151 if (packet) { 3151 if (packet) {
3152 /* Make an SHUTDOWN_COMPLETE. 3152 /* Make an SHUTDOWN_COMPLETE.
3153 * The T bit will be set if the asoc is NULL. 3153 * The T bit will be set if the asoc is NULL.
3154 */ 3154 */
3155 shut = sctp_make_shutdown_complete(asoc, chunk); 3155 shut = sctp_make_shutdown_complete(asoc, chunk);
3156 if (!shut) { 3156 if (!shut) {
3157 sctp_ootb_pkt_free(packet); 3157 sctp_ootb_pkt_free(packet);
3158 return SCTP_DISPOSITION_NOMEM; 3158 return SCTP_DISPOSITION_NOMEM;
3159 } 3159 }
3160 3160
3161 /* Reflect vtag if T-Bit is set */ 3161 /* Reflect vtag if T-Bit is set */
3162 if (sctp_test_T_bit(shut)) 3162 if (sctp_test_T_bit(shut))
3163 packet->vtag = ntohl(chunk->sctp_hdr->vtag); 3163 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3164 3164
3165 /* Set the skb to the belonging sock for accounting. */ 3165 /* Set the skb to the belonging sock for accounting. */
3166 shut->skb->sk = ep->base.sk; 3166 shut->skb->sk = ep->base.sk;
3167 3167
3168 sctp_packet_append_chunk(packet, shut); 3168 sctp_packet_append_chunk(packet, shut);
3169 3169
3170 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, 3170 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3171 SCTP_PACKET(packet)); 3171 SCTP_PACKET(packet));
3172 3172
3173 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); 3173 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3174 3174
3175 /* If the chunk length is invalid, we don't want to process 3175 /* If the chunk length is invalid, we don't want to process
3176 * the reset of the packet. 3176 * the reset of the packet.
3177 */ 3177 */
3178 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) 3178 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3179 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3179 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3180 3180
3181 return SCTP_DISPOSITION_CONSUME; 3181 return SCTP_DISPOSITION_CONSUME;
3182 } 3182 }
3183 3183
3184 return SCTP_DISPOSITION_NOMEM; 3184 return SCTP_DISPOSITION_NOMEM;
3185 } 3185 }
3186 3186
3187 /* 3187 /*
3188 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state. 3188 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3189 * 3189 *
3190 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK 3190 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3191 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the 3191 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3192 * procedures in section 8.4 SHOULD be followed, in other words it 3192 * procedures in section 8.4 SHOULD be followed, in other words it
3193 * should be treated as an Out Of The Blue packet. 3193 * should be treated as an Out Of The Blue packet.
3194 * [This means that we do NOT check the Verification Tag on these 3194 * [This means that we do NOT check the Verification Tag on these
3195 * chunks. --piggy ] 3195 * chunks. --piggy ]
3196 * 3196 *
3197 */ 3197 */
3198 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep, 3198 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3199 const struct sctp_association *asoc, 3199 const struct sctp_association *asoc,
3200 const sctp_subtype_t type, 3200 const sctp_subtype_t type,
3201 void *arg, 3201 void *arg,
3202 sctp_cmd_seq_t *commands) 3202 sctp_cmd_seq_t *commands)
3203 { 3203 {
3204 /* Although we do have an association in this case, it corresponds 3204 /* Although we do have an association in this case, it corresponds
3205 * to a restarted association. So the packet is treated as an OOTB 3205 * to a restarted association. So the packet is treated as an OOTB
3206 * packet and the state function that handles OOTB SHUTDOWN_ACK is 3206 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3207 * called with a NULL association. 3207 * called with a NULL association.
3208 */ 3208 */
3209 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands); 3209 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3210 } 3210 }
3211 3211
3212 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */ 3212 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3213 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep, 3213 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3214 const struct sctp_association *asoc, 3214 const struct sctp_association *asoc,
3215 const sctp_subtype_t type, void *arg, 3215 const sctp_subtype_t type, void *arg,
3216 sctp_cmd_seq_t *commands) 3216 sctp_cmd_seq_t *commands)
3217 { 3217 {
3218 struct sctp_chunk *chunk = arg; 3218 struct sctp_chunk *chunk = arg;
3219 struct sctp_chunk *asconf_ack = NULL; 3219 struct sctp_chunk *asconf_ack = NULL;
3220 sctp_addiphdr_t *hdr; 3220 sctp_addiphdr_t *hdr;
3221 __u32 serial; 3221 __u32 serial;
3222 3222
3223 if (!sctp_vtag_verify(chunk, asoc)) { 3223 if (!sctp_vtag_verify(chunk, asoc)) {
3224 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, 3224 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3225 SCTP_NULL()); 3225 SCTP_NULL());
3226 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3226 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3227 } 3227 }
3228 3228
3229 /* Make sure that the ASCONF ADDIP chunk has a valid length. */ 3229 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3230 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t))) 3230 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t)))
3231 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 3231 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3232 commands); 3232 commands);
3233 3233
3234 hdr = (sctp_addiphdr_t *)chunk->skb->data; 3234 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3235 serial = ntohl(hdr->serial); 3235 serial = ntohl(hdr->serial);
3236 3236
3237 /* ADDIP 4.2 C1) Compare the value of the serial number to the value 3237 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3238 * the endpoint stored in a new association variable 3238 * the endpoint stored in a new association variable
3239 * 'Peer-Serial-Number'. 3239 * 'Peer-Serial-Number'.
3240 */ 3240 */
3241 if (serial == asoc->peer.addip_serial + 1) { 3241 if (serial == asoc->peer.addip_serial + 1) {
3242 /* ADDIP 4.2 C2) If the value found in the serial number is 3242 /* ADDIP 4.2 C2) If the value found in the serial number is
3243 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST 3243 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3244 * do V1-V5. 3244 * do V1-V5.
3245 */ 3245 */
3246 asconf_ack = sctp_process_asconf((struct sctp_association *) 3246 asconf_ack = sctp_process_asconf((struct sctp_association *)
3247 asoc, chunk); 3247 asoc, chunk);
3248 if (!asconf_ack) 3248 if (!asconf_ack)
3249 return SCTP_DISPOSITION_NOMEM; 3249 return SCTP_DISPOSITION_NOMEM;
3250 } else if (serial == asoc->peer.addip_serial) { 3250 } else if (serial == asoc->peer.addip_serial) {
3251 /* ADDIP 4.2 C3) If the value found in the serial number is 3251 /* ADDIP 4.2 C3) If the value found in the serial number is
3252 * equal to the value stored in the 'Peer-Serial-Number' 3252 * equal to the value stored in the 'Peer-Serial-Number'
3253 * IMPLEMENTATION NOTE: As an optimization a receiver may wish 3253 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3254 * to save the last ASCONF-ACK for some predetermined period of 3254 * to save the last ASCONF-ACK for some predetermined period of
3255 * time and instead of re-processing the ASCONF (with the same 3255 * time and instead of re-processing the ASCONF (with the same
3256 * serial number) it may just re-transmit the ASCONF-ACK. 3256 * serial number) it may just re-transmit the ASCONF-ACK.
3257 */ 3257 */
3258 if (asoc->addip_last_asconf_ack) 3258 if (asoc->addip_last_asconf_ack)
3259 asconf_ack = asoc->addip_last_asconf_ack; 3259 asconf_ack = asoc->addip_last_asconf_ack;
3260 else 3260 else
3261 return SCTP_DISPOSITION_DISCARD; 3261 return SCTP_DISPOSITION_DISCARD;
3262 } else { 3262 } else {
3263 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since 3263 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3264 * it must be either a stale packet or from an attacker. 3264 * it must be either a stale packet or from an attacker.
3265 */ 3265 */
3266 return SCTP_DISPOSITION_DISCARD; 3266 return SCTP_DISPOSITION_DISCARD;
3267 } 3267 }
3268 3268
3269 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent 3269 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3270 * back to the source address contained in the IP header of the ASCONF 3270 * back to the source address contained in the IP header of the ASCONF
3271 * being responded to. 3271 * being responded to.
3272 */ 3272 */
3273 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack)); 3273 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3274 3274
3275 return SCTP_DISPOSITION_CONSUME; 3275 return SCTP_DISPOSITION_CONSUME;
3276 } 3276 }
3277 3277
3278 /* 3278 /*
3279 * ADDIP Section 4.3 General rules for address manipulation 3279 * ADDIP Section 4.3 General rules for address manipulation
3280 * When building TLV parameters for the ASCONF Chunk that will add or 3280 * When building TLV parameters for the ASCONF Chunk that will add or
3281 * delete IP addresses the D0 to D13 rules should be applied: 3281 * delete IP addresses the D0 to D13 rules should be applied:
3282 */ 3282 */
3283 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep, 3283 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3284 const struct sctp_association *asoc, 3284 const struct sctp_association *asoc,
3285 const sctp_subtype_t type, void *arg, 3285 const sctp_subtype_t type, void *arg,
3286 sctp_cmd_seq_t *commands) 3286 sctp_cmd_seq_t *commands)
3287 { 3287 {
3288 struct sctp_chunk *asconf_ack = arg; 3288 struct sctp_chunk *asconf_ack = arg;
3289 struct sctp_chunk *last_asconf = asoc->addip_last_asconf; 3289 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3290 struct sctp_chunk *abort; 3290 struct sctp_chunk *abort;
3291 sctp_addiphdr_t *addip_hdr; 3291 sctp_addiphdr_t *addip_hdr;
3292 __u32 sent_serial, rcvd_serial; 3292 __u32 sent_serial, rcvd_serial;
3293 3293
3294 if (!sctp_vtag_verify(asconf_ack, asoc)) { 3294 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3295 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, 3295 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3296 SCTP_NULL()); 3296 SCTP_NULL());
3297 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3297 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3298 } 3298 }
3299 3299
3300 /* Make sure that the ADDIP chunk has a valid length. */ 3300 /* Make sure that the ADDIP chunk has a valid length. */
3301 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t))) 3301 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t)))
3302 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 3302 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3303 commands); 3303 commands);
3304 3304
3305 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data; 3305 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3306 rcvd_serial = ntohl(addip_hdr->serial); 3306 rcvd_serial = ntohl(addip_hdr->serial);
3307 3307
3308 if (last_asconf) { 3308 if (last_asconf) {
3309 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr; 3309 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3310 sent_serial = ntohl(addip_hdr->serial); 3310 sent_serial = ntohl(addip_hdr->serial);
3311 } else { 3311 } else {
3312 sent_serial = asoc->addip_serial - 1; 3312 sent_serial = asoc->addip_serial - 1;
3313 } 3313 }
3314 3314
3315 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or 3315 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3316 * equal to the next serial number to be used but no ASCONF chunk is 3316 * equal to the next serial number to be used but no ASCONF chunk is
3317 * outstanding the endpoint MUST ABORT the association. Note that a 3317 * outstanding the endpoint MUST ABORT the association. Note that a
3318 * sequence number is greater than if it is no more than 2^^31-1 3318 * sequence number is greater than if it is no more than 2^^31-1
3319 * larger than the current sequence number (using serial arithmetic). 3319 * larger than the current sequence number (using serial arithmetic).
3320 */ 3320 */
3321 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) && 3321 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3322 !(asoc->addip_last_asconf)) { 3322 !(asoc->addip_last_asconf)) {
3323 abort = sctp_make_abort(asoc, asconf_ack, 3323 abort = sctp_make_abort(asoc, asconf_ack,
3324 sizeof(sctp_errhdr_t)); 3324 sizeof(sctp_errhdr_t));
3325 if (abort) { 3325 if (abort) {
3326 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0); 3326 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0);
3327 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 3327 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3328 SCTP_CHUNK(abort)); 3328 SCTP_CHUNK(abort));
3329 } 3329 }
3330 /* We are going to ABORT, so we might as well stop 3330 /* We are going to ABORT, so we might as well stop
3331 * processing the rest of the chunks in the packet. 3331 * processing the rest of the chunks in the packet.
3332 */ 3332 */
3333 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 3333 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3334 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); 3334 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3335 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); 3335 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3336 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 3336 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3337 SCTP_U32(SCTP_ERROR_ASCONF_ACK)); 3337 SCTP_U32(SCTP_ERROR_ASCONF_ACK));
3338 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 3338 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3339 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 3339 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3340 return SCTP_DISPOSITION_ABORT; 3340 return SCTP_DISPOSITION_ABORT;
3341 } 3341 }
3342 3342
3343 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) { 3343 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3344 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 3344 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3345 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); 3345 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3346 3346
3347 if (!sctp_process_asconf_ack((struct sctp_association *)asoc, 3347 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3348 asconf_ack)) 3348 asconf_ack))
3349 return SCTP_DISPOSITION_CONSUME; 3349 return SCTP_DISPOSITION_CONSUME;
3350 3350
3351 abort = sctp_make_abort(asoc, asconf_ack, 3351 abort = sctp_make_abort(asoc, asconf_ack,
3352 sizeof(sctp_errhdr_t)); 3352 sizeof(sctp_errhdr_t));
3353 if (abort) { 3353 if (abort) {
3354 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0); 3354 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0);
3355 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 3355 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3356 SCTP_CHUNK(abort)); 3356 SCTP_CHUNK(abort));
3357 } 3357 }
3358 /* We are going to ABORT, so we might as well stop 3358 /* We are going to ABORT, so we might as well stop
3359 * processing the rest of the chunks in the packet. 3359 * processing the rest of the chunks in the packet.
3360 */ 3360 */
3361 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); 3361 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3362 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 3362 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3363 SCTP_U32(SCTP_ERROR_ASCONF_ACK)); 3363 SCTP_U32(SCTP_ERROR_ASCONF_ACK));
3364 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 3364 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3365 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 3365 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3366 return SCTP_DISPOSITION_ABORT; 3366 return SCTP_DISPOSITION_ABORT;
3367 } 3367 }
3368 3368
3369 return SCTP_DISPOSITION_DISCARD; 3369 return SCTP_DISPOSITION_DISCARD;
3370 } 3370 }
3371 3371
3372 /* 3372 /*
3373 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP 3373 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3374 * 3374 *
3375 * When a FORWARD TSN chunk arrives, the data receiver MUST first update 3375 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3376 * its cumulative TSN point to the value carried in the FORWARD TSN 3376 * its cumulative TSN point to the value carried in the FORWARD TSN
3377 * chunk, and then MUST further advance its cumulative TSN point locally 3377 * chunk, and then MUST further advance its cumulative TSN point locally
3378 * if possible. 3378 * if possible.
3379 * After the above processing, the data receiver MUST stop reporting any 3379 * After the above processing, the data receiver MUST stop reporting any
3380 * missing TSNs earlier than or equal to the new cumulative TSN point. 3380 * missing TSNs earlier than or equal to the new cumulative TSN point.
3381 * 3381 *
3382 * Verification Tag: 8.5 Verification Tag [Normal verification] 3382 * Verification Tag: 8.5 Verification Tag [Normal verification]
3383 * 3383 *
3384 * The return value is the disposition of the chunk. 3384 * The return value is the disposition of the chunk.
3385 */ 3385 */
3386 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep, 3386 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3387 const struct sctp_association *asoc, 3387 const struct sctp_association *asoc,
3388 const sctp_subtype_t type, 3388 const sctp_subtype_t type,
3389 void *arg, 3389 void *arg,
3390 sctp_cmd_seq_t *commands) 3390 sctp_cmd_seq_t *commands)
3391 { 3391 {
3392 struct sctp_chunk *chunk = arg; 3392 struct sctp_chunk *chunk = arg;
3393 struct sctp_fwdtsn_hdr *fwdtsn_hdr; 3393 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3394 __u16 len; 3394 __u16 len;
3395 __u32 tsn; 3395 __u32 tsn;
3396 3396
3397 if (!sctp_vtag_verify(chunk, asoc)) { 3397 if (!sctp_vtag_verify(chunk, asoc)) {
3398 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, 3398 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3399 SCTP_NULL()); 3399 SCTP_NULL());
3400 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3400 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3401 } 3401 }
3402 3402
3403 /* Make sure that the FORWARD_TSN chunk has valid length. */ 3403 /* Make sure that the FORWARD_TSN chunk has valid length. */
3404 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk))) 3404 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3405 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 3405 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3406 commands); 3406 commands);
3407 3407
3408 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; 3408 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3409 chunk->subh.fwdtsn_hdr = fwdtsn_hdr; 3409 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3410 len = ntohs(chunk->chunk_hdr->length); 3410 len = ntohs(chunk->chunk_hdr->length);
3411 len -= sizeof(struct sctp_chunkhdr); 3411 len -= sizeof(struct sctp_chunkhdr);
3412 skb_pull(chunk->skb, len); 3412 skb_pull(chunk->skb, len);
3413 3413
3414 tsn = ntohl(fwdtsn_hdr->new_cum_tsn); 3414 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3415 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn); 3415 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3416 3416
3417 /* The TSN is too high--silently discard the chunk and count on it 3417 /* The TSN is too high--silently discard the chunk and count on it
3418 * getting retransmitted later. 3418 * getting retransmitted later.
3419 */ 3419 */
3420 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) 3420 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3421 goto discard_noforce; 3421 goto discard_noforce;
3422 3422
3423 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); 3423 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3424 if (len > sizeof(struct sctp_fwdtsn_hdr)) 3424 if (len > sizeof(struct sctp_fwdtsn_hdr))
3425 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, 3425 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3426 SCTP_CHUNK(chunk)); 3426 SCTP_CHUNK(chunk));
3427 3427
3428 /* Count this as receiving DATA. */ 3428 /* Count this as receiving DATA. */
3429 if (asoc->autoclose) { 3429 if (asoc->autoclose) {
3430 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 3430 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3431 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 3431 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3432 } 3432 }
3433 3433
3434 /* FIXME: For now send a SACK, but DATA processing may 3434 /* FIXME: For now send a SACK, but DATA processing may
3435 * send another. 3435 * send another.
3436 */ 3436 */
3437 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); 3437 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3438 3438
3439 return SCTP_DISPOSITION_CONSUME; 3439 return SCTP_DISPOSITION_CONSUME;
3440 3440
3441 discard_noforce: 3441 discard_noforce:
3442 return SCTP_DISPOSITION_DISCARD; 3442 return SCTP_DISPOSITION_DISCARD;
3443 } 3443 }
3444 3444
3445 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast( 3445 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3446 const struct sctp_endpoint *ep, 3446 const struct sctp_endpoint *ep,
3447 const struct sctp_association *asoc, 3447 const struct sctp_association *asoc,
3448 const sctp_subtype_t type, 3448 const sctp_subtype_t type,
3449 void *arg, 3449 void *arg,
3450 sctp_cmd_seq_t *commands) 3450 sctp_cmd_seq_t *commands)
3451 { 3451 {
3452 struct sctp_chunk *chunk = arg; 3452 struct sctp_chunk *chunk = arg;
3453 struct sctp_fwdtsn_hdr *fwdtsn_hdr; 3453 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3454 __u16 len; 3454 __u16 len;
3455 __u32 tsn; 3455 __u32 tsn;
3456 3456
3457 if (!sctp_vtag_verify(chunk, asoc)) { 3457 if (!sctp_vtag_verify(chunk, asoc)) {
3458 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, 3458 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3459 SCTP_NULL()); 3459 SCTP_NULL());
3460 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3460 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3461 } 3461 }
3462 3462
3463 /* Make sure that the FORWARD_TSN chunk has a valid length. */ 3463 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3464 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk))) 3464 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3465 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 3465 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3466 commands); 3466 commands);
3467 3467
3468 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; 3468 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3469 chunk->subh.fwdtsn_hdr = fwdtsn_hdr; 3469 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3470 len = ntohs(chunk->chunk_hdr->length); 3470 len = ntohs(chunk->chunk_hdr->length);
3471 len -= sizeof(struct sctp_chunkhdr); 3471 len -= sizeof(struct sctp_chunkhdr);
3472 skb_pull(chunk->skb, len); 3472 skb_pull(chunk->skb, len);
3473 3473
3474 tsn = ntohl(fwdtsn_hdr->new_cum_tsn); 3474 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3475 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn); 3475 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3476 3476
3477 /* The TSN is too high--silently discard the chunk and count on it 3477 /* The TSN is too high--silently discard the chunk and count on it
3478 * getting retransmitted later. 3478 * getting retransmitted later.
3479 */ 3479 */
3480 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) 3480 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3481 goto gen_shutdown; 3481 goto gen_shutdown;
3482 3482
3483 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); 3483 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3484 if (len > sizeof(struct sctp_fwdtsn_hdr)) 3484 if (len > sizeof(struct sctp_fwdtsn_hdr))
3485 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, 3485 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3486 SCTP_CHUNK(chunk)); 3486 SCTP_CHUNK(chunk));
3487 3487
3488 /* Go a head and force a SACK, since we are shutting down. */ 3488 /* Go a head and force a SACK, since we are shutting down. */
3489 gen_shutdown: 3489 gen_shutdown:
3490 /* Implementor's Guide. 3490 /* Implementor's Guide.
3491 * 3491 *
3492 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately 3492 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3493 * respond to each received packet containing one or more DATA chunk(s) 3493 * respond to each received packet containing one or more DATA chunk(s)
3494 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer 3494 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3495 */ 3495 */
3496 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); 3496 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3497 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); 3497 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3498 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 3498 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3499 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 3499 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3500 3500
3501 return SCTP_DISPOSITION_CONSUME; 3501 return SCTP_DISPOSITION_CONSUME;
3502 } 3502 }
3503 3503
3504 /* 3504 /*
3505 * Process an unknown chunk. 3505 * Process an unknown chunk.
3506 * 3506 *
3507 * Section: 3.2. Also, 2.1 in the implementor's guide. 3507 * Section: 3.2. Also, 2.1 in the implementor's guide.
3508 * 3508 *
3509 * Chunk Types are encoded such that the highest-order two bits specify 3509 * Chunk Types are encoded such that the highest-order two bits specify
3510 * the action that must be taken if the processing endpoint does not 3510 * the action that must be taken if the processing endpoint does not
3511 * recognize the Chunk Type. 3511 * recognize the Chunk Type.
3512 * 3512 *
3513 * 00 - Stop processing this SCTP packet and discard it, do not process 3513 * 00 - Stop processing this SCTP packet and discard it, do not process
3514 * any further chunks within it. 3514 * any further chunks within it.
3515 * 3515 *
3516 * 01 - Stop processing this SCTP packet and discard it, do not process 3516 * 01 - Stop processing this SCTP packet and discard it, do not process
3517 * any further chunks within it, and report the unrecognized 3517 * any further chunks within it, and report the unrecognized
3518 * chunk in an 'Unrecognized Chunk Type'. 3518 * chunk in an 'Unrecognized Chunk Type'.
3519 * 3519 *
3520 * 10 - Skip this chunk and continue processing. 3520 * 10 - Skip this chunk and continue processing.
3521 * 3521 *
3522 * 11 - Skip this chunk and continue processing, but report in an ERROR 3522 * 11 - Skip this chunk and continue processing, but report in an ERROR
3523 * Chunk using the 'Unrecognized Chunk Type' cause of error. 3523 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3524 * 3524 *
3525 * The return value is the disposition of the chunk. 3525 * The return value is the disposition of the chunk.
3526 */ 3526 */
3527 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep, 3527 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3528 const struct sctp_association *asoc, 3528 const struct sctp_association *asoc,
3529 const sctp_subtype_t type, 3529 const sctp_subtype_t type,
3530 void *arg, 3530 void *arg,
3531 sctp_cmd_seq_t *commands) 3531 sctp_cmd_seq_t *commands)
3532 { 3532 {
3533 struct sctp_chunk *unk_chunk = arg; 3533 struct sctp_chunk *unk_chunk = arg;
3534 struct sctp_chunk *err_chunk; 3534 struct sctp_chunk *err_chunk;
3535 sctp_chunkhdr_t *hdr; 3535 sctp_chunkhdr_t *hdr;
3536 3536
3537 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk); 3537 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3538 3538
3539 if (!sctp_vtag_verify(unk_chunk, asoc)) 3539 if (!sctp_vtag_verify(unk_chunk, asoc))
3540 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3540 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3541 3541
3542 /* Make sure that the chunk has a valid length. 3542 /* Make sure that the chunk has a valid length.
3543 * Since we don't know the chunk type, we use a general 3543 * Since we don't know the chunk type, we use a general
3544 * chunkhdr structure to make a comparison. 3544 * chunkhdr structure to make a comparison.
3545 */ 3545 */
3546 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t))) 3546 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t)))
3547 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 3547 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3548 commands); 3548 commands);
3549 3549
3550 switch (type.chunk & SCTP_CID_ACTION_MASK) { 3550 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3551 case SCTP_CID_ACTION_DISCARD: 3551 case SCTP_CID_ACTION_DISCARD:
3552 /* Discard the packet. */ 3552 /* Discard the packet. */
3553 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3553 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3554 break; 3554 break;
3555 case SCTP_CID_ACTION_DISCARD_ERR: 3555 case SCTP_CID_ACTION_DISCARD_ERR:
3556 /* Discard the packet. */ 3556 /* Discard the packet. */
3557 sctp_sf_pdiscard(ep, asoc, type, arg, commands); 3557 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3558 3558
3559 /* Generate an ERROR chunk as response. */ 3559 /* Generate an ERROR chunk as response. */
3560 hdr = unk_chunk->chunk_hdr; 3560 hdr = unk_chunk->chunk_hdr;
3561 err_chunk = sctp_make_op_error(asoc, unk_chunk, 3561 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3562 SCTP_ERROR_UNKNOWN_CHUNK, hdr, 3562 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3563 WORD_ROUND(ntohs(hdr->length))); 3563 WORD_ROUND(ntohs(hdr->length)));
3564 if (err_chunk) { 3564 if (err_chunk) {
3565 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 3565 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3566 SCTP_CHUNK(err_chunk)); 3566 SCTP_CHUNK(err_chunk));
3567 } 3567 }
3568 return SCTP_DISPOSITION_CONSUME; 3568 return SCTP_DISPOSITION_CONSUME;
3569 break; 3569 break;
3570 case SCTP_CID_ACTION_SKIP: 3570 case SCTP_CID_ACTION_SKIP:
3571 /* Skip the chunk. */ 3571 /* Skip the chunk. */
3572 return SCTP_DISPOSITION_DISCARD; 3572 return SCTP_DISPOSITION_DISCARD;
3573 break; 3573 break;
3574 case SCTP_CID_ACTION_SKIP_ERR: 3574 case SCTP_CID_ACTION_SKIP_ERR:
3575 /* Generate an ERROR chunk as response. */ 3575 /* Generate an ERROR chunk as response. */
3576 hdr = unk_chunk->chunk_hdr; 3576 hdr = unk_chunk->chunk_hdr;
3577 err_chunk = sctp_make_op_error(asoc, unk_chunk, 3577 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3578 SCTP_ERROR_UNKNOWN_CHUNK, hdr, 3578 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3579 WORD_ROUND(ntohs(hdr->length))); 3579 WORD_ROUND(ntohs(hdr->length)));
3580 if (err_chunk) { 3580 if (err_chunk) {
3581 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 3581 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3582 SCTP_CHUNK(err_chunk)); 3582 SCTP_CHUNK(err_chunk));
3583 } 3583 }
3584 /* Skip the chunk. */ 3584 /* Skip the chunk. */
3585 return SCTP_DISPOSITION_CONSUME; 3585 return SCTP_DISPOSITION_CONSUME;
3586 break; 3586 break;
3587 default: 3587 default:
3588 break; 3588 break;
3589 } 3589 }
3590 3590
3591 return SCTP_DISPOSITION_DISCARD; 3591 return SCTP_DISPOSITION_DISCARD;
3592 } 3592 }
3593 3593
3594 /* 3594 /*
3595 * Discard the chunk. 3595 * Discard the chunk.
3596 * 3596 *
3597 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2 3597 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3598 * [Too numerous to mention...] 3598 * [Too numerous to mention...]
3599 * Verification Tag: No verification needed. 3599 * Verification Tag: No verification needed.
3600 * Inputs 3600 * Inputs
3601 * (endpoint, asoc, chunk) 3601 * (endpoint, asoc, chunk)
3602 * 3602 *
3603 * Outputs 3603 * Outputs
3604 * (asoc, reply_msg, msg_up, timers, counters) 3604 * (asoc, reply_msg, msg_up, timers, counters)
3605 * 3605 *
3606 * The return value is the disposition of the chunk. 3606 * The return value is the disposition of the chunk.
3607 */ 3607 */
3608 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep, 3608 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
3609 const struct sctp_association *asoc, 3609 const struct sctp_association *asoc,
3610 const sctp_subtype_t type, 3610 const sctp_subtype_t type,
3611 void *arg, 3611 void *arg,
3612 sctp_cmd_seq_t *commands) 3612 sctp_cmd_seq_t *commands)
3613 { 3613 {
3614 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk); 3614 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3615 return SCTP_DISPOSITION_DISCARD; 3615 return SCTP_DISPOSITION_DISCARD;
3616 } 3616 }
3617 3617
3618 /* 3618 /*
3619 * Discard the whole packet. 3619 * Discard the whole packet.
3620 * 3620 *
3621 * Section: 8.4 2) 3621 * Section: 8.4 2)
3622 * 3622 *
3623 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST 3623 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3624 * silently discard the OOTB packet and take no further action. 3624 * silently discard the OOTB packet and take no further action.
3625 * 3625 *
3626 * Verification Tag: No verification necessary 3626 * Verification Tag: No verification necessary
3627 * 3627 *
3628 * Inputs 3628 * Inputs
3629 * (endpoint, asoc, chunk) 3629 * (endpoint, asoc, chunk)
3630 * 3630 *
3631 * Outputs 3631 * Outputs
3632 * (asoc, reply_msg, msg_up, timers, counters) 3632 * (asoc, reply_msg, msg_up, timers, counters)
3633 * 3633 *
3634 * The return value is the disposition of the chunk. 3634 * The return value is the disposition of the chunk.
3635 */ 3635 */
3636 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep, 3636 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
3637 const struct sctp_association *asoc, 3637 const struct sctp_association *asoc,
3638 const sctp_subtype_t type, 3638 const sctp_subtype_t type,
3639 void *arg, 3639 void *arg,
3640 sctp_cmd_seq_t *commands) 3640 sctp_cmd_seq_t *commands)
3641 { 3641 {
3642 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); 3642 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3643 3643
3644 return SCTP_DISPOSITION_CONSUME; 3644 return SCTP_DISPOSITION_CONSUME;
3645 } 3645 }
3646 3646
3647 3647
3648 /* 3648 /*
3649 * The other end is violating protocol. 3649 * The other end is violating protocol.
3650 * 3650 *
3651 * Section: Not specified 3651 * Section: Not specified
3652 * Verification Tag: Not specified 3652 * Verification Tag: Not specified
3653 * Inputs 3653 * Inputs
3654 * (endpoint, asoc, chunk) 3654 * (endpoint, asoc, chunk)
3655 * 3655 *
3656 * Outputs 3656 * Outputs
3657 * (asoc, reply_msg, msg_up, timers, counters) 3657 * (asoc, reply_msg, msg_up, timers, counters)
3658 * 3658 *
3659 * We simply tag the chunk as a violation. The state machine will log 3659 * We simply tag the chunk as a violation. The state machine will log
3660 * the violation and continue. 3660 * the violation and continue.
3661 */ 3661 */
3662 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep, 3662 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
3663 const struct sctp_association *asoc, 3663 const struct sctp_association *asoc,
3664 const sctp_subtype_t type, 3664 const sctp_subtype_t type,
3665 void *arg, 3665 void *arg,
3666 sctp_cmd_seq_t *commands) 3666 sctp_cmd_seq_t *commands)
3667 { 3667 {
3668 return SCTP_DISPOSITION_VIOLATION; 3668 return SCTP_DISPOSITION_VIOLATION;
3669 } 3669 }
3670 3670
3671 3671
3672 /* 3672 /*
3673 * Handle a protocol violation when the chunk length is invalid. 3673 * Handle a protocol violation when the chunk length is invalid.
3674 * "Invalid" length is identified as smaller then the minimal length a 3674 * "Invalid" length is identified as smaller then the minimal length a
3675 * given chunk can be. For example, a SACK chunk has invalid length 3675 * given chunk can be. For example, a SACK chunk has invalid length
3676 * if it's length is set to be smaller then the size of sctp_sack_chunk_t. 3676 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
3677 * 3677 *
3678 * We inform the other end by sending an ABORT with a Protocol Violation 3678 * We inform the other end by sending an ABORT with a Protocol Violation
3679 * error code. 3679 * error code.
3680 * 3680 *
3681 * Section: Not specified 3681 * Section: Not specified
3682 * Verification Tag: Nothing to do 3682 * Verification Tag: Nothing to do
3683 * Inputs 3683 * Inputs
3684 * (endpoint, asoc, chunk) 3684 * (endpoint, asoc, chunk)
3685 * 3685 *
3686 * Outputs 3686 * Outputs
3687 * (reply_msg, msg_up, counters) 3687 * (reply_msg, msg_up, counters)
3688 * 3688 *
3689 * Generate an ABORT chunk and terminate the association. 3689 * Generate an ABORT chunk and terminate the association.
3690 */ 3690 */
3691 static sctp_disposition_t sctp_sf_violation_chunklen( 3691 static sctp_disposition_t sctp_sf_violation_chunklen(
3692 const struct sctp_endpoint *ep, 3692 const struct sctp_endpoint *ep,
3693 const struct sctp_association *asoc, 3693 const struct sctp_association *asoc,
3694 const sctp_subtype_t type, 3694 const sctp_subtype_t type,
3695 void *arg, 3695 void *arg,
3696 sctp_cmd_seq_t *commands) 3696 sctp_cmd_seq_t *commands)
3697 { 3697 {
3698 struct sctp_chunk *chunk = arg; 3698 struct sctp_chunk *chunk = arg;
3699 struct sctp_chunk *abort = NULL; 3699 struct sctp_chunk *abort = NULL;
3700 char err_str[]="The following chunk had invalid length:"; 3700 char err_str[]="The following chunk had invalid length:";
3701 3701
3702 /* Make the abort chunk. */ 3702 /* Make the abort chunk. */
3703 abort = sctp_make_abort_violation(asoc, chunk, err_str, 3703 abort = sctp_make_abort_violation(asoc, chunk, err_str,
3704 sizeof(err_str)); 3704 sizeof(err_str));
3705 if (!abort) 3705 if (!abort)
3706 goto nomem; 3706 goto nomem;
3707 3707
3708 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); 3708 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3709 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); 3709 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3710 3710
3711 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) { 3711 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
3712 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 3712 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3713 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 3713 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3714 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, 3714 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
3715 SCTP_U32(SCTP_ERROR_PROTO_VIOLATION)); 3715 SCTP_U32(SCTP_ERROR_PROTO_VIOLATION));
3716 } else { 3716 } else {
3717 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 3717 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3718 SCTP_U32(SCTP_ERROR_PROTO_VIOLATION)); 3718 SCTP_U32(SCTP_ERROR_PROTO_VIOLATION));
3719 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 3719 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3720 } 3720 }
3721 3721
3722 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); 3722 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3723 3723
3724 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 3724 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3725 3725
3726 return SCTP_DISPOSITION_ABORT; 3726 return SCTP_DISPOSITION_ABORT;
3727 3727
3728 nomem: 3728 nomem:
3729 return SCTP_DISPOSITION_NOMEM; 3729 return SCTP_DISPOSITION_NOMEM;
3730 } 3730 }
3731 3731
3732 /*************************************************************************** 3732 /***************************************************************************
3733 * These are the state functions for handling primitive (Section 10) events. 3733 * These are the state functions for handling primitive (Section 10) events.
3734 ***************************************************************************/ 3734 ***************************************************************************/
3735 /* 3735 /*
3736 * sctp_sf_do_prm_asoc 3736 * sctp_sf_do_prm_asoc
3737 * 3737 *
3738 * Section: 10.1 ULP-to-SCTP 3738 * Section: 10.1 ULP-to-SCTP
3739 * B) Associate 3739 * B) Associate
3740 * 3740 *
3741 * Format: ASSOCIATE(local SCTP instance name, destination transport addr, 3741 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3742 * outbound stream count) 3742 * outbound stream count)
3743 * -> association id [,destination transport addr list] [,outbound stream 3743 * -> association id [,destination transport addr list] [,outbound stream
3744 * count] 3744 * count]
3745 * 3745 *
3746 * This primitive allows the upper layer to initiate an association to a 3746 * This primitive allows the upper layer to initiate an association to a
3747 * specific peer endpoint. 3747 * specific peer endpoint.
3748 * 3748 *
3749 * The peer endpoint shall be specified by one of the transport addresses 3749 * The peer endpoint shall be specified by one of the transport addresses
3750 * which defines the endpoint (see Section 1.4). If the local SCTP 3750 * which defines the endpoint (see Section 1.4). If the local SCTP
3751 * instance has not been initialized, the ASSOCIATE is considered an 3751 * instance has not been initialized, the ASSOCIATE is considered an
3752 * error. 3752 * error.
3753 * [This is not relevant for the kernel implementation since we do all 3753 * [This is not relevant for the kernel implementation since we do all
3754 * initialization at boot time. It we hadn't initialized we wouldn't 3754 * initialization at boot time. It we hadn't initialized we wouldn't
3755 * get anywhere near this code.] 3755 * get anywhere near this code.]
3756 * 3756 *
3757 * An association id, which is a local handle to the SCTP association, 3757 * An association id, which is a local handle to the SCTP association,
3758 * will be returned on successful establishment of the association. If 3758 * will be returned on successful establishment of the association. If
3759 * SCTP is not able to open an SCTP association with the peer endpoint, 3759 * SCTP is not able to open an SCTP association with the peer endpoint,
3760 * an error is returned. 3760 * an error is returned.
3761 * [In the kernel implementation, the struct sctp_association needs to 3761 * [In the kernel implementation, the struct sctp_association needs to
3762 * be created BEFORE causing this primitive to run.] 3762 * be created BEFORE causing this primitive to run.]
3763 * 3763 *
3764 * Other association parameters may be returned, including the 3764 * Other association parameters may be returned, including the
3765 * complete destination transport addresses of the peer as well as the 3765 * complete destination transport addresses of the peer as well as the
3766 * outbound stream count of the local endpoint. One of the transport 3766 * outbound stream count of the local endpoint. One of the transport
3767 * address from the returned destination addresses will be selected by 3767 * address from the returned destination addresses will be selected by
3768 * the local endpoint as default primary path for sending SCTP packets 3768 * the local endpoint as default primary path for sending SCTP packets
3769 * to this peer. The returned "destination transport addr list" can 3769 * to this peer. The returned "destination transport addr list" can
3770 * be used by the ULP to change the default primary path or to force 3770 * be used by the ULP to change the default primary path or to force
3771 * sending a packet to a specific transport address. [All of this 3771 * sending a packet to a specific transport address. [All of this
3772 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING 3772 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3773 * function.] 3773 * function.]
3774 * 3774 *
3775 * Mandatory attributes: 3775 * Mandatory attributes:
3776 * 3776 *
3777 * o local SCTP instance name - obtained from the INITIALIZE operation. 3777 * o local SCTP instance name - obtained from the INITIALIZE operation.
3778 * [This is the argument asoc.] 3778 * [This is the argument asoc.]
3779 * o destination transport addr - specified as one of the transport 3779 * o destination transport addr - specified as one of the transport
3780 * addresses of the peer endpoint with which the association is to be 3780 * addresses of the peer endpoint with which the association is to be
3781 * established. 3781 * established.
3782 * [This is asoc->peer.active_path.] 3782 * [This is asoc->peer.active_path.]
3783 * o outbound stream count - the number of outbound streams the ULP 3783 * o outbound stream count - the number of outbound streams the ULP
3784 * would like to open towards this peer endpoint. 3784 * would like to open towards this peer endpoint.
3785 * [BUG: This is not currently implemented.] 3785 * [BUG: This is not currently implemented.]
3786 * Optional attributes: 3786 * Optional attributes:
3787 * 3787 *
3788 * None. 3788 * None.
3789 * 3789 *
3790 * The return value is a disposition. 3790 * The return value is a disposition.
3791 */ 3791 */
3792 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep, 3792 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
3793 const struct sctp_association *asoc, 3793 const struct sctp_association *asoc,
3794 const sctp_subtype_t type, 3794 const sctp_subtype_t type,
3795 void *arg, 3795 void *arg,
3796 sctp_cmd_seq_t *commands) 3796 sctp_cmd_seq_t *commands)
3797 { 3797 {
3798 struct sctp_chunk *repl; 3798 struct sctp_chunk *repl;
3799 3799
3800 /* The comment below says that we enter COOKIE-WAIT AFTER 3800 /* The comment below says that we enter COOKIE-WAIT AFTER
3801 * sending the INIT, but that doesn't actually work in our 3801 * sending the INIT, but that doesn't actually work in our
3802 * implementation... 3802 * implementation...
3803 */ 3803 */
3804 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 3804 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3805 SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); 3805 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
3806 3806
3807 /* RFC 2960 5.1 Normal Establishment of an Association 3807 /* RFC 2960 5.1 Normal Establishment of an Association
3808 * 3808 *
3809 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A" 3809 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3810 * must provide its Verification Tag (Tag_A) in the Initiate 3810 * must provide its Verification Tag (Tag_A) in the Initiate
3811 * Tag field. Tag_A SHOULD be a random number in the range of 3811 * Tag field. Tag_A SHOULD be a random number in the range of
3812 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ... 3812 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3813 */ 3813 */
3814 3814
3815 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0); 3815 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
3816 if (!repl) 3816 if (!repl)
3817 goto nomem; 3817 goto nomem;
3818 3818
3819 /* Cast away the const modifier, as we want to just 3819 /* Cast away the const modifier, as we want to just
3820 * rerun it through as a sideffect. 3820 * rerun it through as a sideffect.
3821 */ 3821 */
3822 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, 3822 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
3823 SCTP_ASOC((struct sctp_association *) asoc)); 3823 SCTP_ASOC((struct sctp_association *) asoc));
3824 3824
3825 /* Choose transport for INIT. */ 3825 /* Choose transport for INIT. */
3826 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, 3826 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
3827 SCTP_CHUNK(repl)); 3827 SCTP_CHUNK(repl));
3828 3828
3829 /* After sending the INIT, "A" starts the T1-init timer and 3829 /* After sending the INIT, "A" starts the T1-init timer and
3830 * enters the COOKIE-WAIT state. 3830 * enters the COOKIE-WAIT state.
3831 */ 3831 */
3832 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 3832 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3833 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 3833 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3834 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 3834 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
3835 return SCTP_DISPOSITION_CONSUME; 3835 return SCTP_DISPOSITION_CONSUME;
3836 3836
3837 nomem: 3837 nomem:
3838 return SCTP_DISPOSITION_NOMEM; 3838 return SCTP_DISPOSITION_NOMEM;
3839 } 3839 }
3840 3840
3841 /* 3841 /*
3842 * Process the SEND primitive. 3842 * Process the SEND primitive.
3843 * 3843 *
3844 * Section: 10.1 ULP-to-SCTP 3844 * Section: 10.1 ULP-to-SCTP
3845 * E) Send 3845 * E) Send
3846 * 3846 *
3847 * Format: SEND(association id, buffer address, byte count [,context] 3847 * Format: SEND(association id, buffer address, byte count [,context]
3848 * [,stream id] [,life time] [,destination transport address] 3848 * [,stream id] [,life time] [,destination transport address]
3849 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] ) 3849 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3850 * -> result 3850 * -> result
3851 * 3851 *
3852 * This is the main method to send user data via SCTP. 3852 * This is the main method to send user data via SCTP.
3853 * 3853 *
3854 * Mandatory attributes: 3854 * Mandatory attributes:
3855 * 3855 *
3856 * o association id - local handle to the SCTP association 3856 * o association id - local handle to the SCTP association
3857 * 3857 *
3858 * o buffer address - the location where the user message to be 3858 * o buffer address - the location where the user message to be
3859 * transmitted is stored; 3859 * transmitted is stored;
3860 * 3860 *
3861 * o byte count - The size of the user data in number of bytes; 3861 * o byte count - The size of the user data in number of bytes;
3862 * 3862 *
3863 * Optional attributes: 3863 * Optional attributes:
3864 * 3864 *
3865 * o context - an optional 32 bit integer that will be carried in the 3865 * o context - an optional 32 bit integer that will be carried in the
3866 * sending failure notification to the ULP if the transportation of 3866 * sending failure notification to the ULP if the transportation of
3867 * this User Message fails. 3867 * this User Message fails.
3868 * 3868 *
3869 * o stream id - to indicate which stream to send the data on. If not 3869 * o stream id - to indicate which stream to send the data on. If not
3870 * specified, stream 0 will be used. 3870 * specified, stream 0 will be used.
3871 * 3871 *
3872 * o life time - specifies the life time of the user data. The user data 3872 * o life time - specifies the life time of the user data. The user data
3873 * will not be sent by SCTP after the life time expires. This 3873 * will not be sent by SCTP after the life time expires. This
3874 * parameter can be used to avoid efforts to transmit stale 3874 * parameter can be used to avoid efforts to transmit stale
3875 * user messages. SCTP notifies the ULP if the data cannot be 3875 * user messages. SCTP notifies the ULP if the data cannot be
3876 * initiated to transport (i.e. sent to the destination via SCTP's 3876 * initiated to transport (i.e. sent to the destination via SCTP's
3877 * send primitive) within the life time variable. However, the 3877 * send primitive) within the life time variable. However, the
3878 * user data will be transmitted if SCTP has attempted to transmit a 3878 * user data will be transmitted if SCTP has attempted to transmit a
3879 * chunk before the life time expired. 3879 * chunk before the life time expired.
3880 * 3880 *
3881 * o destination transport address - specified as one of the destination 3881 * o destination transport address - specified as one of the destination
3882 * transport addresses of the peer endpoint to which this packet 3882 * transport addresses of the peer endpoint to which this packet
3883 * should be sent. Whenever possible, SCTP should use this destination 3883 * should be sent. Whenever possible, SCTP should use this destination
3884 * transport address for sending the packets, instead of the current 3884 * transport address for sending the packets, instead of the current
3885 * primary path. 3885 * primary path.
3886 * 3886 *
3887 * o unorder flag - this flag, if present, indicates that the user 3887 * o unorder flag - this flag, if present, indicates that the user
3888 * would like the data delivered in an unordered fashion to the peer 3888 * would like the data delivered in an unordered fashion to the peer
3889 * (i.e., the U flag is set to 1 on all DATA chunks carrying this 3889 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3890 * message). 3890 * message).
3891 * 3891 *
3892 * o no-bundle flag - instructs SCTP not to bundle this user data with 3892 * o no-bundle flag - instructs SCTP not to bundle this user data with
3893 * other outbound DATA chunks. SCTP MAY still bundle even when 3893 * other outbound DATA chunks. SCTP MAY still bundle even when
3894 * this flag is present, when faced with network congestion. 3894 * this flag is present, when faced with network congestion.
3895 * 3895 *
3896 * o payload protocol-id - A 32 bit unsigned integer that is to be 3896 * o payload protocol-id - A 32 bit unsigned integer that is to be
3897 * passed to the peer indicating the type of payload protocol data 3897 * passed to the peer indicating the type of payload protocol data
3898 * being transmitted. This value is passed as opaque data by SCTP. 3898 * being transmitted. This value is passed as opaque data by SCTP.
3899 * 3899 *
3900 * The return value is the disposition. 3900 * The return value is the disposition.
3901 */ 3901 */
3902 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep, 3902 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
3903 const struct sctp_association *asoc, 3903 const struct sctp_association *asoc,
3904 const sctp_subtype_t type, 3904 const sctp_subtype_t type,
3905 void *arg, 3905 void *arg,
3906 sctp_cmd_seq_t *commands) 3906 sctp_cmd_seq_t *commands)
3907 { 3907 {
3908 struct sctp_chunk *chunk = arg; 3908 struct sctp_chunk *chunk = arg;
3909 3909
3910 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); 3910 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
3911 return SCTP_DISPOSITION_CONSUME; 3911 return SCTP_DISPOSITION_CONSUME;
3912 } 3912 }
3913 3913
3914 /* 3914 /*
3915 * Process the SHUTDOWN primitive. 3915 * Process the SHUTDOWN primitive.
3916 * 3916 *
3917 * Section: 10.1: 3917 * Section: 10.1:
3918 * C) Shutdown 3918 * C) Shutdown
3919 * 3919 *
3920 * Format: SHUTDOWN(association id) 3920 * Format: SHUTDOWN(association id)
3921 * -> result 3921 * -> result
3922 * 3922 *
3923 * Gracefully closes an association. Any locally queued user data 3923 * Gracefully closes an association. Any locally queued user data
3924 * will be delivered to the peer. The association will be terminated only 3924 * will be delivered to the peer. The association will be terminated only
3925 * after the peer acknowledges all the SCTP packets sent. A success code 3925 * after the peer acknowledges all the SCTP packets sent. A success code
3926 * will be returned on successful termination of the association. If 3926 * will be returned on successful termination of the association. If
3927 * attempting to terminate the association results in a failure, an error 3927 * attempting to terminate the association results in a failure, an error
3928 * code shall be returned. 3928 * code shall be returned.
3929 * 3929 *
3930 * Mandatory attributes: 3930 * Mandatory attributes:
3931 * 3931 *
3932 * o association id - local handle to the SCTP association 3932 * o association id - local handle to the SCTP association
3933 * 3933 *
3934 * Optional attributes: 3934 * Optional attributes:
3935 * 3935 *
3936 * None. 3936 * None.
3937 * 3937 *
3938 * The return value is the disposition. 3938 * The return value is the disposition.
3939 */ 3939 */
3940 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown( 3940 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
3941 const struct sctp_endpoint *ep, 3941 const struct sctp_endpoint *ep,
3942 const struct sctp_association *asoc, 3942 const struct sctp_association *asoc,
3943 const sctp_subtype_t type, 3943 const sctp_subtype_t type,
3944 void *arg, 3944 void *arg,
3945 sctp_cmd_seq_t *commands) 3945 sctp_cmd_seq_t *commands)
3946 { 3946 {
3947 int disposition; 3947 int disposition;
3948 3948
3949 /* From 9.2 Shutdown of an Association 3949 /* From 9.2 Shutdown of an Association
3950 * Upon receipt of the SHUTDOWN primitive from its upper 3950 * Upon receipt of the SHUTDOWN primitive from its upper
3951 * layer, the endpoint enters SHUTDOWN-PENDING state and 3951 * layer, the endpoint enters SHUTDOWN-PENDING state and
3952 * remains there until all outstanding data has been 3952 * remains there until all outstanding data has been
3953 * acknowledged by its peer. The endpoint accepts no new data 3953 * acknowledged by its peer. The endpoint accepts no new data
3954 * from its upper layer, but retransmits data to the far end 3954 * from its upper layer, but retransmits data to the far end
3955 * if necessary to fill gaps. 3955 * if necessary to fill gaps.
3956 */ 3956 */
3957 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 3957 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3958 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); 3958 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
3959 3959
3960 /* sctpimpguide-05 Section 2.12.2 3960 /* sctpimpguide-05 Section 2.12.2
3961 * The sender of the SHUTDOWN MAY also start an overall guard timer 3961 * The sender of the SHUTDOWN MAY also start an overall guard timer
3962 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. 3962 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
3963 */ 3963 */
3964 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 3964 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3965 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 3965 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3966 3966
3967 disposition = SCTP_DISPOSITION_CONSUME; 3967 disposition = SCTP_DISPOSITION_CONSUME;
3968 if (sctp_outq_is_empty(&asoc->outqueue)) { 3968 if (sctp_outq_is_empty(&asoc->outqueue)) {
3969 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type, 3969 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
3970 arg, commands); 3970 arg, commands);
3971 } 3971 }
3972 return disposition; 3972 return disposition;
3973 } 3973 }
3974 3974
3975 /* 3975 /*
3976 * Process the ABORT primitive. 3976 * Process the ABORT primitive.
3977 * 3977 *
3978 * Section: 10.1: 3978 * Section: 10.1:
3979 * C) Abort 3979 * C) Abort
3980 * 3980 *
3981 * Format: Abort(association id [, cause code]) 3981 * Format: Abort(association id [, cause code])
3982 * -> result 3982 * -> result
3983 * 3983 *
3984 * Ungracefully closes an association. Any locally queued user data 3984 * Ungracefully closes an association. Any locally queued user data
3985 * will be discarded and an ABORT chunk is sent to the peer. A success code 3985 * will be discarded and an ABORT chunk is sent to the peer. A success code
3986 * will be returned on successful abortion of the association. If 3986 * will be returned on successful abortion of the association. If
3987 * attempting to abort the association results in a failure, an error 3987 * attempting to abort the association results in a failure, an error
3988 * code shall be returned. 3988 * code shall be returned.
3989 * 3989 *
3990 * Mandatory attributes: 3990 * Mandatory attributes:
3991 * 3991 *
3992 * o association id - local handle to the SCTP association 3992 * o association id - local handle to the SCTP association
3993 * 3993 *
3994 * Optional attributes: 3994 * Optional attributes:
3995 * 3995 *
3996 * o cause code - reason of the abort to be passed to the peer 3996 * o cause code - reason of the abort to be passed to the peer
3997 * 3997 *
3998 * None. 3998 * None.
3999 * 3999 *
4000 * The return value is the disposition. 4000 * The return value is the disposition.
4001 */ 4001 */
4002 sctp_disposition_t sctp_sf_do_9_1_prm_abort( 4002 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
4003 const struct sctp_endpoint *ep, 4003 const struct sctp_endpoint *ep,
4004 const struct sctp_association *asoc, 4004 const struct sctp_association *asoc,
4005 const sctp_subtype_t type, 4005 const sctp_subtype_t type,
4006 void *arg, 4006 void *arg,
4007 sctp_cmd_seq_t *commands) 4007 sctp_cmd_seq_t *commands)
4008 { 4008 {
4009 /* From 9.1 Abort of an Association 4009 /* From 9.1 Abort of an Association
4010 * Upon receipt of the ABORT primitive from its upper 4010 * Upon receipt of the ABORT primitive from its upper
4011 * layer, the endpoint enters CLOSED state and 4011 * layer, the endpoint enters CLOSED state and
4012 * discard all outstanding data has been 4012 * discard all outstanding data has been
4013 * acknowledged by its peer. The endpoint accepts no new data 4013 * acknowledged by its peer. The endpoint accepts no new data
4014 * from its upper layer, but retransmits data to the far end 4014 * from its upper layer, but retransmits data to the far end
4015 * if necessary to fill gaps. 4015 * if necessary to fill gaps.
4016 */ 4016 */
4017 struct msghdr *msg = arg; 4017 struct msghdr *msg = arg;
4018 struct sctp_chunk *abort; 4018 struct sctp_chunk *abort;
4019 sctp_disposition_t retval; 4019 sctp_disposition_t retval;
4020 4020
4021 retval = SCTP_DISPOSITION_CONSUME; 4021 retval = SCTP_DISPOSITION_CONSUME;
4022 4022
4023 /* Generate ABORT chunk to send the peer. */ 4023 /* Generate ABORT chunk to send the peer. */
4024 abort = sctp_make_abort_user(asoc, NULL, msg); 4024 abort = sctp_make_abort_user(asoc, NULL, msg);
4025 if (!abort) 4025 if (!abort)
4026 retval = SCTP_DISPOSITION_NOMEM; 4026 retval = SCTP_DISPOSITION_NOMEM;
4027 else 4027 else
4028 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); 4028 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4029 4029
4030 /* Even if we can't send the ABORT due to low memory delete the 4030 /* Even if we can't send the ABORT due to low memory delete the
4031 * TCB. This is a departure from our typical NOMEM handling. 4031 * TCB. This is a departure from our typical NOMEM handling.
4032 */ 4032 */
4033 4033
4034 /* Delete the established association. */ 4034 /* Delete the established association. */
4035 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 4035 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4036 SCTP_U32(SCTP_ERROR_USER_ABORT)); 4036 SCTP_U32(SCTP_ERROR_USER_ABORT));
4037 4037
4038 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 4038 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4039 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 4039 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4040 4040
4041 return retval; 4041 return retval;
4042 } 4042 }
4043 4043
4044 /* We tried an illegal operation on an association which is closed. */ 4044 /* We tried an illegal operation on an association which is closed. */
4045 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep, 4045 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
4046 const struct sctp_association *asoc, 4046 const struct sctp_association *asoc,
4047 const sctp_subtype_t type, 4047 const sctp_subtype_t type,
4048 void *arg, 4048 void *arg,
4049 sctp_cmd_seq_t *commands) 4049 sctp_cmd_seq_t *commands)
4050 { 4050 {
4051 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL)); 4051 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
4052 return SCTP_DISPOSITION_CONSUME; 4052 return SCTP_DISPOSITION_CONSUME;
4053 } 4053 }
4054 4054
4055 /* We tried an illegal operation on an association which is shutting 4055 /* We tried an illegal operation on an association which is shutting
4056 * down. 4056 * down.
4057 */ 4057 */
4058 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep, 4058 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
4059 const struct sctp_association *asoc, 4059 const struct sctp_association *asoc,
4060 const sctp_subtype_t type, 4060 const sctp_subtype_t type,
4061 void *arg, 4061 void *arg,
4062 sctp_cmd_seq_t *commands) 4062 sctp_cmd_seq_t *commands)
4063 { 4063 {
4064 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, 4064 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
4065 SCTP_ERROR(-ESHUTDOWN)); 4065 SCTP_ERROR(-ESHUTDOWN));
4066 return SCTP_DISPOSITION_CONSUME; 4066 return SCTP_DISPOSITION_CONSUME;
4067 } 4067 }
4068 4068
4069 /* 4069 /*
4070 * sctp_cookie_wait_prm_shutdown 4070 * sctp_cookie_wait_prm_shutdown
4071 * 4071 *
4072 * Section: 4 Note: 2 4072 * Section: 4 Note: 2
4073 * Verification Tag: 4073 * Verification Tag:
4074 * Inputs 4074 * Inputs
4075 * (endpoint, asoc) 4075 * (endpoint, asoc)
4076 * 4076 *
4077 * The RFC does not explicitly address this issue, but is the route through the 4077 * The RFC does not explicitly address this issue, but is the route through the
4078 * state table when someone issues a shutdown while in COOKIE_WAIT state. 4078 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4079 * 4079 *
4080 * Outputs 4080 * Outputs
4081 * (timers) 4081 * (timers)
4082 */ 4082 */
4083 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown( 4083 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
4084 const struct sctp_endpoint *ep, 4084 const struct sctp_endpoint *ep,
4085 const struct sctp_association *asoc, 4085 const struct sctp_association *asoc,
4086 const sctp_subtype_t type, 4086 const sctp_subtype_t type,
4087 void *arg, 4087 void *arg,
4088 sctp_cmd_seq_t *commands) 4088 sctp_cmd_seq_t *commands)
4089 { 4089 {
4090 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 4090 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4091 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 4091 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4092 4092
4093 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 4093 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4094 SCTP_STATE(SCTP_STATE_CLOSED)); 4094 SCTP_STATE(SCTP_STATE_CLOSED));
4095 4095
4096 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); 4096 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
4097 4097
4098 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); 4098 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
4099 4099
4100 return SCTP_DISPOSITION_DELETE_TCB; 4100 return SCTP_DISPOSITION_DELETE_TCB;
4101 } 4101 }
4102 4102
4103 /* 4103 /*
4104 * sctp_cookie_echoed_prm_shutdown 4104 * sctp_cookie_echoed_prm_shutdown
4105 * 4105 *
4106 * Section: 4 Note: 2 4106 * Section: 4 Note: 2
4107 * Verification Tag: 4107 * Verification Tag:
4108 * Inputs 4108 * Inputs
4109 * (endpoint, asoc) 4109 * (endpoint, asoc)
4110 * 4110 *
4111 * The RFC does not explcitly address this issue, but is the route through the 4111 * The RFC does not explcitly address this issue, but is the route through the
4112 * state table when someone issues a shutdown while in COOKIE_ECHOED state. 4112 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4113 * 4113 *
4114 * Outputs 4114 * Outputs
4115 * (timers) 4115 * (timers)
4116 */ 4116 */
4117 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown( 4117 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
4118 const struct sctp_endpoint *ep, 4118 const struct sctp_endpoint *ep,
4119 const struct sctp_association *asoc, 4119 const struct sctp_association *asoc,
4120 const sctp_subtype_t type, 4120 const sctp_subtype_t type,
4121 void *arg, sctp_cmd_seq_t *commands) 4121 void *arg, sctp_cmd_seq_t *commands)
4122 { 4122 {
4123 /* There is a single T1 timer, so we should be able to use 4123 /* There is a single T1 timer, so we should be able to use
4124 * common function with the COOKIE-WAIT state. 4124 * common function with the COOKIE-WAIT state.
4125 */ 4125 */
4126 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands); 4126 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
4127 } 4127 }
4128 4128
4129 /* 4129 /*
4130 * sctp_sf_cookie_wait_prm_abort 4130 * sctp_sf_cookie_wait_prm_abort
4131 * 4131 *
4132 * Section: 4 Note: 2 4132 * Section: 4 Note: 2
4133 * Verification Tag: 4133 * Verification Tag:
4134 * Inputs 4134 * Inputs
4135 * (endpoint, asoc) 4135 * (endpoint, asoc)
4136 * 4136 *
4137 * The RFC does not explicitly address this issue, but is the route through the 4137 * The RFC does not explicitly address this issue, but is the route through the
4138 * state table when someone issues an abort while in COOKIE_WAIT state. 4138 * state table when someone issues an abort while in COOKIE_WAIT state.
4139 * 4139 *
4140 * Outputs 4140 * Outputs
4141 * (timers) 4141 * (timers)
4142 */ 4142 */
4143 sctp_disposition_t sctp_sf_cookie_wait_prm_abort( 4143 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
4144 const struct sctp_endpoint *ep, 4144 const struct sctp_endpoint *ep,
4145 const struct sctp_association *asoc, 4145 const struct sctp_association *asoc,
4146 const sctp_subtype_t type, 4146 const sctp_subtype_t type,
4147 void *arg, 4147 void *arg,
4148 sctp_cmd_seq_t *commands) 4148 sctp_cmd_seq_t *commands)
4149 { 4149 {
4150 struct msghdr *msg = arg; 4150 struct msghdr *msg = arg;
4151 struct sctp_chunk *abort; 4151 struct sctp_chunk *abort;
4152 sctp_disposition_t retval; 4152 sctp_disposition_t retval;
4153 4153
4154 /* Stop T1-init timer */ 4154 /* Stop T1-init timer */
4155 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 4155 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4156 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 4156 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4157 retval = SCTP_DISPOSITION_CONSUME; 4157 retval = SCTP_DISPOSITION_CONSUME;
4158 4158
4159 /* Generate ABORT chunk to send the peer */ 4159 /* Generate ABORT chunk to send the peer */
4160 abort = sctp_make_abort_user(asoc, NULL, msg); 4160 abort = sctp_make_abort_user(asoc, NULL, msg);
4161 if (!abort) 4161 if (!abort)
4162 retval = SCTP_DISPOSITION_NOMEM; 4162 retval = SCTP_DISPOSITION_NOMEM;
4163 else 4163 else
4164 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); 4164 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4165 4165
4166 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 4166 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4167 SCTP_STATE(SCTP_STATE_CLOSED)); 4167 SCTP_STATE(SCTP_STATE_CLOSED));
4168 4168
4169 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 4169 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4170 4170
4171 /* Even if we can't send the ABORT due to low memory delete the 4171 /* Even if we can't send the ABORT due to low memory delete the
4172 * TCB. This is a departure from our typical NOMEM handling. 4172 * TCB. This is a departure from our typical NOMEM handling.
4173 */ 4173 */
4174 4174
4175 /* Delete the established association. */ 4175 /* Delete the established association. */
4176 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, 4176 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4177 SCTP_U32(SCTP_ERROR_USER_ABORT)); 4177 SCTP_U32(SCTP_ERROR_USER_ABORT));
4178 4178
4179 return retval; 4179 return retval;
4180 } 4180 }
4181 4181
4182 /* 4182 /*
4183 * sctp_sf_cookie_echoed_prm_abort 4183 * sctp_sf_cookie_echoed_prm_abort
4184 * 4184 *
4185 * Section: 4 Note: 3 4185 * Section: 4 Note: 3
4186 * Verification Tag: 4186 * Verification Tag:
4187 * Inputs 4187 * Inputs
4188 * (endpoint, asoc) 4188 * (endpoint, asoc)
4189 * 4189 *
4190 * The RFC does not explcitly address this issue, but is the route through the 4190 * The RFC does not explcitly address this issue, but is the route through the
4191 * state table when someone issues an abort while in COOKIE_ECHOED state. 4191 * state table when someone issues an abort while in COOKIE_ECHOED state.
4192 * 4192 *
4193 * Outputs 4193 * Outputs
4194 * (timers) 4194 * (timers)
4195 */ 4195 */
4196 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort( 4196 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
4197 const struct sctp_endpoint *ep, 4197 const struct sctp_endpoint *ep,
4198 const struct sctp_association *asoc, 4198 const struct sctp_association *asoc,
4199 const sctp_subtype_t type, 4199 const sctp_subtype_t type,
4200 void *arg, 4200 void *arg,
4201 sctp_cmd_seq_t *commands) 4201 sctp_cmd_seq_t *commands)
4202 { 4202 {
4203 /* There is a single T1 timer, so we should be able to use 4203 /* There is a single T1 timer, so we should be able to use
4204 * common function with the COOKIE-WAIT state. 4204 * common function with the COOKIE-WAIT state.
4205 */ 4205 */
4206 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands); 4206 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
4207 } 4207 }
4208 4208
4209 /* 4209 /*
4210 * sctp_sf_shutdown_pending_prm_abort 4210 * sctp_sf_shutdown_pending_prm_abort
4211 * 4211 *
4212 * Inputs 4212 * Inputs
4213 * (endpoint, asoc) 4213 * (endpoint, asoc)
4214 * 4214 *
4215 * The RFC does not explicitly address this issue, but is the route through the 4215 * The RFC does not explicitly address this issue, but is the route through the
4216 * state table when someone issues an abort while in SHUTDOWN-PENDING state. 4216 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4217 * 4217 *
4218 * Outputs 4218 * Outputs
4219 * (timers) 4219 * (timers)
4220 */ 4220 */
4221 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort( 4221 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
4222 const struct sctp_endpoint *ep, 4222 const struct sctp_endpoint *ep,
4223 const struct sctp_association *asoc, 4223 const struct sctp_association *asoc,
4224 const sctp_subtype_t type, 4224 const sctp_subtype_t type,
4225 void *arg, 4225 void *arg,
4226 sctp_cmd_seq_t *commands) 4226 sctp_cmd_seq_t *commands)
4227 { 4227 {
4228 /* Stop the T5-shutdown guard timer. */ 4228 /* Stop the T5-shutdown guard timer. */
4229 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 4229 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4230 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 4230 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4231 4231
4232 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands); 4232 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4233 } 4233 }
4234 4234
4235 /* 4235 /*
4236 * sctp_sf_shutdown_sent_prm_abort 4236 * sctp_sf_shutdown_sent_prm_abort
4237 * 4237 *
4238 * Inputs 4238 * Inputs
4239 * (endpoint, asoc) 4239 * (endpoint, asoc)
4240 * 4240 *
4241 * The RFC does not explicitly address this issue, but is the route through the 4241 * The RFC does not explicitly address this issue, but is the route through the
4242 * state table when someone issues an abort while in SHUTDOWN-SENT state. 4242 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4243 * 4243 *
4244 * Outputs 4244 * Outputs
4245 * (timers) 4245 * (timers)
4246 */ 4246 */
4247 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort( 4247 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4248 const struct sctp_endpoint *ep, 4248 const struct sctp_endpoint *ep,
4249 const struct sctp_association *asoc, 4249 const struct sctp_association *asoc,
4250 const sctp_subtype_t type, 4250 const sctp_subtype_t type,
4251 void *arg, 4251 void *arg,
4252 sctp_cmd_seq_t *commands) 4252 sctp_cmd_seq_t *commands)
4253 { 4253 {
4254 /* Stop the T2-shutdown timer. */ 4254 /* Stop the T2-shutdown timer. */
4255 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 4255 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4256 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 4256 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4257 4257
4258 /* Stop the T5-shutdown guard timer. */ 4258 /* Stop the T5-shutdown guard timer. */
4259 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 4259 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4260 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 4260 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4261 4261
4262 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands); 4262 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4263 } 4263 }
4264 4264
4265 /* 4265 /*
4266 * sctp_sf_cookie_echoed_prm_abort 4266 * sctp_sf_cookie_echoed_prm_abort
4267 * 4267 *
4268 * Inputs 4268 * Inputs
4269 * (endpoint, asoc) 4269 * (endpoint, asoc)
4270 * 4270 *
4271 * The RFC does not explcitly address this issue, but is the route through the 4271 * The RFC does not explcitly address this issue, but is the route through the
4272 * state table when someone issues an abort while in COOKIE_ECHOED state. 4272 * state table when someone issues an abort while in COOKIE_ECHOED state.
4273 * 4273 *
4274 * Outputs 4274 * Outputs
4275 * (timers) 4275 * (timers)
4276 */ 4276 */
4277 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort( 4277 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4278 const struct sctp_endpoint *ep, 4278 const struct sctp_endpoint *ep,
4279 const struct sctp_association *asoc, 4279 const struct sctp_association *asoc,
4280 const sctp_subtype_t type, 4280 const sctp_subtype_t type,
4281 void *arg, 4281 void *arg,
4282 sctp_cmd_seq_t *commands) 4282 sctp_cmd_seq_t *commands)
4283 { 4283 {
4284 /* The same T2 timer, so we should be able to use 4284 /* The same T2 timer, so we should be able to use
4285 * common function with the SHUTDOWN-SENT state. 4285 * common function with the SHUTDOWN-SENT state.
4286 */ 4286 */
4287 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands); 4287 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4288 } 4288 }
4289 4289
4290 /* 4290 /*
4291 * Process the REQUESTHEARTBEAT primitive 4291 * Process the REQUESTHEARTBEAT primitive
4292 * 4292 *
4293 * 10.1 ULP-to-SCTP 4293 * 10.1 ULP-to-SCTP
4294 * J) Request Heartbeat 4294 * J) Request Heartbeat
4295 * 4295 *
4296 * Format: REQUESTHEARTBEAT(association id, destination transport address) 4296 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4297 * 4297 *
4298 * -> result 4298 * -> result
4299 * 4299 *
4300 * Instructs the local endpoint to perform a HeartBeat on the specified 4300 * Instructs the local endpoint to perform a HeartBeat on the specified
4301 * destination transport address of the given association. The returned 4301 * destination transport address of the given association. The returned
4302 * result should indicate whether the transmission of the HEARTBEAT 4302 * result should indicate whether the transmission of the HEARTBEAT
4303 * chunk to the destination address is successful. 4303 * chunk to the destination address is successful.
4304 * 4304 *
4305 * Mandatory attributes: 4305 * Mandatory attributes:
4306 * 4306 *
4307 * o association id - local handle to the SCTP association 4307 * o association id - local handle to the SCTP association
4308 * 4308 *
4309 * o destination transport address - the transport address of the 4309 * o destination transport address - the transport address of the
4310 * association on which a heartbeat should be issued. 4310 * association on which a heartbeat should be issued.
4311 */ 4311 */
4312 sctp_disposition_t sctp_sf_do_prm_requestheartbeat( 4312 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4313 const struct sctp_endpoint *ep, 4313 const struct sctp_endpoint *ep,
4314 const struct sctp_association *asoc, 4314 const struct sctp_association *asoc,
4315 const sctp_subtype_t type, 4315 const sctp_subtype_t type,
4316 void *arg, 4316 void *arg,
4317 sctp_cmd_seq_t *commands) 4317 sctp_cmd_seq_t *commands)
4318 { 4318 {
4319 return sctp_sf_heartbeat(ep, asoc, type, (struct sctp_transport *)arg, 4319 return sctp_sf_heartbeat(ep, asoc, type, (struct sctp_transport *)arg,
4320 commands); 4320 commands);
4321 } 4321 }
4322 4322
4323 /* 4323 /*
4324 * ADDIP Section 4.1 ASCONF Chunk Procedures 4324 * ADDIP Section 4.1 ASCONF Chunk Procedures
4325 * When an endpoint has an ASCONF signaled change to be sent to the 4325 * When an endpoint has an ASCONF signaled change to be sent to the
4326 * remote endpoint it should do A1 to A9 4326 * remote endpoint it should do A1 to A9
4327 */ 4327 */
4328 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep, 4328 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4329 const struct sctp_association *asoc, 4329 const struct sctp_association *asoc,
4330 const sctp_subtype_t type, 4330 const sctp_subtype_t type,
4331 void *arg, 4331 void *arg,
4332 sctp_cmd_seq_t *commands) 4332 sctp_cmd_seq_t *commands)
4333 { 4333 {
4334 struct sctp_chunk *chunk = arg; 4334 struct sctp_chunk *chunk = arg;
4335 4335
4336 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); 4336 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4337 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 4337 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4338 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); 4338 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4339 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); 4339 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4340 return SCTP_DISPOSITION_CONSUME; 4340 return SCTP_DISPOSITION_CONSUME;
4341 } 4341 }
4342 4342
4343 /* 4343 /*
4344 * Ignore the primitive event 4344 * Ignore the primitive event
4345 * 4345 *
4346 * The return value is the disposition of the primitive. 4346 * The return value is the disposition of the primitive.
4347 */ 4347 */
4348 sctp_disposition_t sctp_sf_ignore_primitive( 4348 sctp_disposition_t sctp_sf_ignore_primitive(
4349 const struct sctp_endpoint *ep, 4349 const struct sctp_endpoint *ep,
4350 const struct sctp_association *asoc, 4350 const struct sctp_association *asoc,
4351 const sctp_subtype_t type, 4351 const sctp_subtype_t type,
4352 void *arg, 4352 void *arg,
4353 sctp_cmd_seq_t *commands) 4353 sctp_cmd_seq_t *commands)
4354 { 4354 {
4355 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive); 4355 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4356 return SCTP_DISPOSITION_DISCARD; 4356 return SCTP_DISPOSITION_DISCARD;
4357 } 4357 }
4358 4358
4359 /*************************************************************************** 4359 /***************************************************************************
4360 * These are the state functions for the OTHER events. 4360 * These are the state functions for the OTHER events.
4361 ***************************************************************************/ 4361 ***************************************************************************/
4362 4362
4363 /* 4363 /*
4364 * Start the shutdown negotiation. 4364 * Start the shutdown negotiation.
4365 * 4365 *
4366 * From Section 9.2: 4366 * From Section 9.2:
4367 * Once all its outstanding data has been acknowledged, the endpoint 4367 * Once all its outstanding data has been acknowledged, the endpoint
4368 * shall send a SHUTDOWN chunk to its peer including in the Cumulative 4368 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4369 * TSN Ack field the last sequential TSN it has received from the peer. 4369 * TSN Ack field the last sequential TSN it has received from the peer.
4370 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT 4370 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4371 * state. If the timer expires, the endpoint must re-send the SHUTDOWN 4371 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4372 * with the updated last sequential TSN received from its peer. 4372 * with the updated last sequential TSN received from its peer.
4373 * 4373 *
4374 * The return value is the disposition. 4374 * The return value is the disposition.
4375 */ 4375 */
4376 sctp_disposition_t sctp_sf_do_9_2_start_shutdown( 4376 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4377 const struct sctp_endpoint *ep, 4377 const struct sctp_endpoint *ep,
4378 const struct sctp_association *asoc, 4378 const struct sctp_association *asoc,
4379 const sctp_subtype_t type, 4379 const sctp_subtype_t type,
4380 void *arg, 4380 void *arg,
4381 sctp_cmd_seq_t *commands) 4381 sctp_cmd_seq_t *commands)
4382 { 4382 {
4383 struct sctp_chunk *reply; 4383 struct sctp_chunk *reply;
4384 4384
4385 /* Once all its outstanding data has been acknowledged, the 4385 /* Once all its outstanding data has been acknowledged, the
4386 * endpoint shall send a SHUTDOWN chunk to its peer including 4386 * endpoint shall send a SHUTDOWN chunk to its peer including
4387 * in the Cumulative TSN Ack field the last sequential TSN it 4387 * in the Cumulative TSN Ack field the last sequential TSN it
4388 * has received from the peer. 4388 * has received from the peer.
4389 */ 4389 */
4390 reply = sctp_make_shutdown(asoc, NULL); 4390 reply = sctp_make_shutdown(asoc, NULL);
4391 if (!reply) 4391 if (!reply)
4392 goto nomem; 4392 goto nomem;
4393 4393
4394 /* Set the transport for the SHUTDOWN chunk and the timeout for the 4394 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4395 * T2-shutdown timer. 4395 * T2-shutdown timer.
4396 */ 4396 */
4397 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); 4397 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4398 4398
4399 /* It shall then start the T2-shutdown timer */ 4399 /* It shall then start the T2-shutdown timer */
4400 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 4400 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4401 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 4401 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4402 4402
4403 if (asoc->autoclose) 4403 if (asoc->autoclose)
4404 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 4404 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4405 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 4405 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4406 4406
4407 /* and enter the SHUTDOWN-SENT state. */ 4407 /* and enter the SHUTDOWN-SENT state. */
4408 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 4408 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4409 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT)); 4409 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4410 4410
4411 /* sctp-implguide 2.10 Issues with Heartbeating and failover 4411 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4412 * 4412 *
4413 * HEARTBEAT ... is discontinued after sending either SHUTDOWN 4413 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4414 * or SHUTDOWN-ACK. 4414 * or SHUTDOWN-ACK.
4415 */ 4415 */
4416 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); 4416 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4417 4417
4418 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 4418 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4419 4419
4420 return SCTP_DISPOSITION_CONSUME; 4420 return SCTP_DISPOSITION_CONSUME;
4421 4421
4422 nomem: 4422 nomem:
4423 return SCTP_DISPOSITION_NOMEM; 4423 return SCTP_DISPOSITION_NOMEM;
4424 } 4424 }
4425 4425
4426 /* 4426 /*
4427 * Generate a SHUTDOWN ACK now that everything is SACK'd. 4427 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4428 * 4428 *
4429 * From Section 9.2: 4429 * From Section 9.2:
4430 * 4430 *
4431 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver 4431 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4432 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own, 4432 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4433 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the 4433 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4434 * endpoint must re-send the SHUTDOWN ACK. 4434 * endpoint must re-send the SHUTDOWN ACK.
4435 * 4435 *
4436 * The return value is the disposition. 4436 * The return value is the disposition.
4437 */ 4437 */
4438 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack( 4438 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4439 const struct sctp_endpoint *ep, 4439 const struct sctp_endpoint *ep,
4440 const struct sctp_association *asoc, 4440 const struct sctp_association *asoc,
4441 const sctp_subtype_t type, 4441 const sctp_subtype_t type,
4442 void *arg, 4442 void *arg,
4443 sctp_cmd_seq_t *commands) 4443 sctp_cmd_seq_t *commands)
4444 { 4444 {
4445 struct sctp_chunk *chunk = (struct sctp_chunk *) arg; 4445 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
4446 struct sctp_chunk *reply; 4446 struct sctp_chunk *reply;
4447 4447
4448 /* There are 2 ways of getting here: 4448 /* There are 2 ways of getting here:
4449 * 1) called in response to a SHUTDOWN chunk 4449 * 1) called in response to a SHUTDOWN chunk
4450 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued. 4450 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
4451 * 4451 *
4452 * For the case (2), the arg parameter is set to NULL. We need 4452 * For the case (2), the arg parameter is set to NULL. We need
4453 * to check that we have a chunk before accessing it's fields. 4453 * to check that we have a chunk before accessing it's fields.
4454 */ 4454 */
4455 if (chunk) { 4455 if (chunk) {
4456 if (!sctp_vtag_verify(chunk, asoc)) 4456 if (!sctp_vtag_verify(chunk, asoc))
4457 return sctp_sf_pdiscard(ep, asoc, type, arg, commands); 4457 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
4458 4458
4459 /* Make sure that the SHUTDOWN chunk has a valid length. */ 4459 /* Make sure that the SHUTDOWN chunk has a valid length. */
4460 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t))) 4460 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t)))
4461 return sctp_sf_violation_chunklen(ep, asoc, type, arg, 4461 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4462 commands); 4462 commands);
4463 } 4463 }
4464 4464
4465 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver 4465 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4466 * shall send a SHUTDOWN ACK ... 4466 * shall send a SHUTDOWN ACK ...
4467 */ 4467 */
4468 reply = sctp_make_shutdown_ack(asoc, chunk); 4468 reply = sctp_make_shutdown_ack(asoc, chunk);
4469 if (!reply) 4469 if (!reply)
4470 goto nomem; 4470 goto nomem;
4471 4471
4472 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for 4472 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4473 * the T2-shutdown timer. 4473 * the T2-shutdown timer.
4474 */ 4474 */
4475 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); 4475 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4476 4476
4477 /* and start/restart a T2-shutdown timer of its own, */ 4477 /* and start/restart a T2-shutdown timer of its own, */
4478 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 4478 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4479 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 4479 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4480 4480
4481 if (asoc->autoclose) 4481 if (asoc->autoclose)
4482 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 4482 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4483 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 4483 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4484 4484
4485 /* Enter the SHUTDOWN-ACK-SENT state. */ 4485 /* Enter the SHUTDOWN-ACK-SENT state. */
4486 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 4486 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4487 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT)); 4487 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
4488 4488
4489 /* sctp-implguide 2.10 Issues with Heartbeating and failover 4489 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4490 * 4490 *
4491 * HEARTBEAT ... is discontinued after sending either SHUTDOWN 4491 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4492 * or SHUTDOWN-ACK. 4492 * or SHUTDOWN-ACK.
4493 */ 4493 */
4494 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); 4494 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4495 4495
4496 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 4496 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4497 4497
4498 return SCTP_DISPOSITION_CONSUME; 4498 return SCTP_DISPOSITION_CONSUME;
4499 4499
4500 nomem: 4500 nomem:
4501 return SCTP_DISPOSITION_NOMEM; 4501 return SCTP_DISPOSITION_NOMEM;
4502 } 4502 }
4503 4503
4504 /* 4504 /*
4505 * Ignore the event defined as other 4505 * Ignore the event defined as other
4506 * 4506 *
4507 * The return value is the disposition of the event. 4507 * The return value is the disposition of the event.
4508 */ 4508 */
4509 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep, 4509 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
4510 const struct sctp_association *asoc, 4510 const struct sctp_association *asoc,
4511 const sctp_subtype_t type, 4511 const sctp_subtype_t type,
4512 void *arg, 4512 void *arg,
4513 sctp_cmd_seq_t *commands) 4513 sctp_cmd_seq_t *commands)
4514 { 4514 {
4515 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other); 4515 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
4516 return SCTP_DISPOSITION_DISCARD; 4516 return SCTP_DISPOSITION_DISCARD;
4517 } 4517 }
4518 4518
4519 /************************************************************ 4519 /************************************************************
4520 * These are the state functions for handling timeout events. 4520 * These are the state functions for handling timeout events.
4521 ************************************************************/ 4521 ************************************************************/
4522 4522
4523 /* 4523 /*
4524 * RTX Timeout 4524 * RTX Timeout
4525 * 4525 *
4526 * Section: 6.3.3 Handle T3-rtx Expiration 4526 * Section: 6.3.3 Handle T3-rtx Expiration
4527 * 4527 *
4528 * Whenever the retransmission timer T3-rtx expires for a destination 4528 * Whenever the retransmission timer T3-rtx expires for a destination
4529 * address, do the following: 4529 * address, do the following:
4530 * [See below] 4530 * [See below]
4531 * 4531 *
4532 * The return value is the disposition of the chunk. 4532 * The return value is the disposition of the chunk.
4533 */ 4533 */
4534 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep, 4534 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
4535 const struct sctp_association *asoc, 4535 const struct sctp_association *asoc,
4536 const sctp_subtype_t type, 4536 const sctp_subtype_t type,
4537 void *arg, 4537 void *arg,
4538 sctp_cmd_seq_t *commands) 4538 sctp_cmd_seq_t *commands)
4539 { 4539 {
4540 struct sctp_transport *transport = arg; 4540 struct sctp_transport *transport = arg;
4541 4541
4542 if (asoc->overall_error_count >= asoc->max_retrans) { 4542 if (asoc->overall_error_count >= asoc->max_retrans) {
4543 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ 4543 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4544 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 4544 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4545 SCTP_U32(SCTP_ERROR_NO_ERROR)); 4545 SCTP_U32(SCTP_ERROR_NO_ERROR));
4546 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 4546 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4547 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 4547 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4548 return SCTP_DISPOSITION_DELETE_TCB; 4548 return SCTP_DISPOSITION_DELETE_TCB;
4549 } 4549 }
4550 4550
4551 /* E1) For the destination address for which the timer 4551 /* E1) For the destination address for which the timer
4552 * expires, adjust its ssthresh with rules defined in Section 4552 * expires, adjust its ssthresh with rules defined in Section
4553 * 7.2.3 and set the cwnd <- MTU. 4553 * 7.2.3 and set the cwnd <- MTU.
4554 */ 4554 */
4555 4555
4556 /* E2) For the destination address for which the timer 4556 /* E2) For the destination address for which the timer
4557 * expires, set RTO <- RTO * 2 ("back off the timer"). The 4557 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4558 * maximum value discussed in rule C7 above (RTO.max) may be 4558 * maximum value discussed in rule C7 above (RTO.max) may be
4559 * used to provide an upper bound to this doubling operation. 4559 * used to provide an upper bound to this doubling operation.
4560 */ 4560 */
4561 4561
4562 /* E3) Determine how many of the earliest (i.e., lowest TSN) 4562 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4563 * outstanding DATA chunks for the address for which the 4563 * outstanding DATA chunks for the address for which the
4564 * T3-rtx has expired will fit into a single packet, subject 4564 * T3-rtx has expired will fit into a single packet, subject
4565 * to the MTU constraint for the path corresponding to the 4565 * to the MTU constraint for the path corresponding to the
4566 * destination transport address to which the retransmission 4566 * destination transport address to which the retransmission
4567 * is being sent (this may be different from the address for 4567 * is being sent (this may be different from the address for
4568 * which the timer expires [see Section 6.4]). Call this 4568 * which the timer expires [see Section 6.4]). Call this
4569 * value K. Bundle and retransmit those K DATA chunks in a 4569 * value K. Bundle and retransmit those K DATA chunks in a
4570 * single packet to the destination endpoint. 4570 * single packet to the destination endpoint.
4571 * 4571 *
4572 * Note: Any DATA chunks that were sent to the address for 4572 * Note: Any DATA chunks that were sent to the address for
4573 * which the T3-rtx timer expired but did not fit in one MTU 4573 * which the T3-rtx timer expired but did not fit in one MTU
4574 * (rule E3 above), should be marked for retransmission and 4574 * (rule E3 above), should be marked for retransmission and
4575 * sent as soon as cwnd allows (normally when a SACK arrives). 4575 * sent as soon as cwnd allows (normally when a SACK arrives).
4576 */ 4576 */
4577 4577
4578 /* NB: Rules E4 and F1 are implicit in R1. */ 4578 /* NB: Rules E4 and F1 are implicit in R1. */
4579 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport)); 4579 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
4580 4580
4581 /* Do some failure management (Section 8.2). */ 4581 /* Do some failure management (Section 8.2). */
4582 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); 4582 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4583 4583
4584 return SCTP_DISPOSITION_CONSUME; 4584 return SCTP_DISPOSITION_CONSUME;
4585 } 4585 }
4586 4586
4587 /* 4587 /*
4588 * Generate delayed SACK on timeout 4588 * Generate delayed SACK on timeout
4589 * 4589 *
4590 * Section: 6.2 Acknowledgement on Reception of DATA Chunks 4590 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4591 * 4591 *
4592 * The guidelines on delayed acknowledgement algorithm specified in 4592 * The guidelines on delayed acknowledgement algorithm specified in
4593 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an 4593 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4594 * acknowledgement SHOULD be generated for at least every second packet 4594 * acknowledgement SHOULD be generated for at least every second packet
4595 * (not every second DATA chunk) received, and SHOULD be generated 4595 * (not every second DATA chunk) received, and SHOULD be generated
4596 * within 200 ms of the arrival of any unacknowledged DATA chunk. In 4596 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4597 * some situations it may be beneficial for an SCTP transmitter to be 4597 * some situations it may be beneficial for an SCTP transmitter to be
4598 * more conservative than the algorithms detailed in this document 4598 * more conservative than the algorithms detailed in this document
4599 * allow. However, an SCTP transmitter MUST NOT be more aggressive than 4599 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4600 * the following algorithms allow. 4600 * the following algorithms allow.
4601 */ 4601 */
4602 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep, 4602 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
4603 const struct sctp_association *asoc, 4603 const struct sctp_association *asoc,
4604 const sctp_subtype_t type, 4604 const sctp_subtype_t type,
4605 void *arg, 4605 void *arg,
4606 sctp_cmd_seq_t *commands) 4606 sctp_cmd_seq_t *commands)
4607 { 4607 {
4608 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); 4608 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4609 return SCTP_DISPOSITION_CONSUME; 4609 return SCTP_DISPOSITION_CONSUME;
4610 } 4610 }
4611 4611
4612 /* 4612 /*
4613 * sctp_sf_t1_init_timer_expire 4613 * sctp_sf_t1_init_timer_expire
4614 * 4614 *
4615 * Section: 4 Note: 2 4615 * Section: 4 Note: 2
4616 * Verification Tag: 4616 * Verification Tag:
4617 * Inputs 4617 * Inputs
4618 * (endpoint, asoc) 4618 * (endpoint, asoc)
4619 * 4619 *
4620 * RFC 2960 Section 4 Notes 4620 * RFC 2960 Section 4 Notes
4621 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT 4621 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4622 * and re-start the T1-init timer without changing state. This MUST 4622 * and re-start the T1-init timer without changing state. This MUST
4623 * be repeated up to 'Max.Init.Retransmits' times. After that, the 4623 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4624 * endpoint MUST abort the initialization process and report the 4624 * endpoint MUST abort the initialization process and report the
4625 * error to SCTP user. 4625 * error to SCTP user.
4626 * 4626 *
4627 * Outputs 4627 * Outputs
4628 * (timers, events) 4628 * (timers, events)
4629 * 4629 *
4630 */ 4630 */
4631 sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep, 4631 sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep,
4632 const struct sctp_association *asoc, 4632 const struct sctp_association *asoc,
4633 const sctp_subtype_t type, 4633 const sctp_subtype_t type,
4634 void *arg, 4634 void *arg,
4635 sctp_cmd_seq_t *commands) 4635 sctp_cmd_seq_t *commands)
4636 { 4636 {
4637 struct sctp_chunk *repl = NULL; 4637 struct sctp_chunk *repl = NULL;
4638 struct sctp_bind_addr *bp; 4638 struct sctp_bind_addr *bp;
4639 int attempts = asoc->init_err_counter + 1; 4639 int attempts = asoc->init_err_counter + 1;
4640 4640
4641 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n"); 4641 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
4642 4642
4643 if (attempts <= asoc->max_init_attempts) { 4643 if (attempts <= asoc->max_init_attempts) {
4644 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; 4644 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
4645 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0); 4645 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
4646 if (!repl) 4646 if (!repl)
4647 return SCTP_DISPOSITION_NOMEM; 4647 return SCTP_DISPOSITION_NOMEM;
4648 4648
4649 /* Choose transport for INIT. */ 4649 /* Choose transport for INIT. */
4650 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, 4650 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4651 SCTP_CHUNK(repl)); 4651 SCTP_CHUNK(repl));
4652 4652
4653 /* Issue a sideeffect to do the needed accounting. */ 4653 /* Issue a sideeffect to do the needed accounting. */
4654 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART, 4654 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
4655 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 4655 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4656 4656
4657 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 4657 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4658 } else { 4658 } else {
4659 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d" 4659 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
4660 " max_init_attempts: %d\n", 4660 " max_init_attempts: %d\n",
4661 attempts, asoc->max_init_attempts); 4661 attempts, asoc->max_init_attempts);
4662 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, 4662 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4663 SCTP_U32(SCTP_ERROR_NO_ERROR)); 4663 SCTP_U32(SCTP_ERROR_NO_ERROR));
4664 return SCTP_DISPOSITION_DELETE_TCB; 4664 return SCTP_DISPOSITION_DELETE_TCB;
4665 } 4665 }
4666 4666
4667 return SCTP_DISPOSITION_CONSUME; 4667 return SCTP_DISPOSITION_CONSUME;
4668 } 4668 }
4669 4669
4670 /* 4670 /*
4671 * sctp_sf_t1_cookie_timer_expire 4671 * sctp_sf_t1_cookie_timer_expire
4672 * 4672 *
4673 * Section: 4 Note: 2 4673 * Section: 4 Note: 2
4674 * Verification Tag: 4674 * Verification Tag:
4675 * Inputs 4675 * Inputs
4676 * (endpoint, asoc) 4676 * (endpoint, asoc)
4677 * 4677 *
4678 * RFC 2960 Section 4 Notes 4678 * RFC 2960 Section 4 Notes
4679 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit 4679 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4680 * COOKIE ECHO and re-start the T1-cookie timer without changing 4680 * COOKIE ECHO and re-start the T1-cookie timer without changing
4681 * state. This MUST be repeated up to 'Max.Init.Retransmits' times. 4681 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4682 * After that, the endpoint MUST abort the initialization process and 4682 * After that, the endpoint MUST abort the initialization process and
4683 * report the error to SCTP user. 4683 * report the error to SCTP user.
4684 * 4684 *
4685 * Outputs 4685 * Outputs
4686 * (timers, events) 4686 * (timers, events)
4687 * 4687 *
4688 */ 4688 */
4689 sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep, 4689 sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep,
4690 const struct sctp_association *asoc, 4690 const struct sctp_association *asoc,
4691 const sctp_subtype_t type, 4691 const sctp_subtype_t type,
4692 void *arg, 4692 void *arg,
4693 sctp_cmd_seq_t *commands) 4693 sctp_cmd_seq_t *commands)
4694 { 4694 {
4695 struct sctp_chunk *repl = NULL; 4695 struct sctp_chunk *repl = NULL;
4696 int attempts = asoc->init_err_counter + 1; 4696 int attempts = asoc->init_err_counter + 1;
4697 4697
4698 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n"); 4698 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
4699 4699
4700 if (attempts <= asoc->max_init_attempts) { 4700 if (attempts <= asoc->max_init_attempts) {
4701 repl = sctp_make_cookie_echo(asoc, NULL); 4701 repl = sctp_make_cookie_echo(asoc, NULL);
4702 if (!repl) 4702 if (!repl)
4703 return SCTP_DISPOSITION_NOMEM; 4703 return SCTP_DISPOSITION_NOMEM;
4704 4704
4705 /* Issue a sideeffect to do the needed accounting. */ 4705 /* Issue a sideeffect to do the needed accounting. */
4706 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART, 4706 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
4707 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); 4707 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
4708 4708
4709 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 4709 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4710 } else { 4710 } else {
4711 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, 4711 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4712 SCTP_U32(SCTP_ERROR_NO_ERROR)); 4712 SCTP_U32(SCTP_ERROR_NO_ERROR));
4713 return SCTP_DISPOSITION_DELETE_TCB; 4713 return SCTP_DISPOSITION_DELETE_TCB;
4714 } 4714 }
4715 4715
4716 return SCTP_DISPOSITION_CONSUME; 4716 return SCTP_DISPOSITION_CONSUME;
4717 } 4717 }
4718 4718
4719 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN 4719 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4720 * with the updated last sequential TSN received from its peer. 4720 * with the updated last sequential TSN received from its peer.
4721 * 4721 *
4722 * An endpoint should limit the number of retransmissions of the 4722 * An endpoint should limit the number of retransmissions of the
4723 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'. 4723 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4724 * If this threshold is exceeded the endpoint should destroy the TCB and 4724 * If this threshold is exceeded the endpoint should destroy the TCB and
4725 * MUST report the peer endpoint unreachable to the upper layer (and 4725 * MUST report the peer endpoint unreachable to the upper layer (and
4726 * thus the association enters the CLOSED state). The reception of any 4726 * thus the association enters the CLOSED state). The reception of any
4727 * packet from its peer (i.e. as the peer sends all of its queued DATA 4727 * packet from its peer (i.e. as the peer sends all of its queued DATA
4728 * chunks) should clear the endpoint's retransmission count and restart 4728 * chunks) should clear the endpoint's retransmission count and restart
4729 * the T2-Shutdown timer, giving its peer ample opportunity to transmit 4729 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4730 * all of its queued DATA chunks that have not yet been sent. 4730 * all of its queued DATA chunks that have not yet been sent.
4731 */ 4731 */
4732 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep, 4732 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
4733 const struct sctp_association *asoc, 4733 const struct sctp_association *asoc,
4734 const sctp_subtype_t type, 4734 const sctp_subtype_t type,
4735 void *arg, 4735 void *arg,
4736 sctp_cmd_seq_t *commands) 4736 sctp_cmd_seq_t *commands)
4737 { 4737 {
4738 struct sctp_chunk *reply = NULL; 4738 struct sctp_chunk *reply = NULL;
4739 4739
4740 SCTP_DEBUG_PRINTK("Timer T2 expired.\n"); 4740 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4741 if (asoc->overall_error_count >= asoc->max_retrans) { 4741 if (asoc->overall_error_count >= asoc->max_retrans) {
4742 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ 4742 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4743 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 4743 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4744 SCTP_U32(SCTP_ERROR_NO_ERROR)); 4744 SCTP_U32(SCTP_ERROR_NO_ERROR));
4745 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 4745 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4746 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 4746 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4747 return SCTP_DISPOSITION_DELETE_TCB; 4747 return SCTP_DISPOSITION_DELETE_TCB;
4748 } 4748 }
4749 4749
4750 switch (asoc->state) { 4750 switch (asoc->state) {
4751 case SCTP_STATE_SHUTDOWN_SENT: 4751 case SCTP_STATE_SHUTDOWN_SENT:
4752 reply = sctp_make_shutdown(asoc, NULL); 4752 reply = sctp_make_shutdown(asoc, NULL);
4753 break; 4753 break;
4754 4754
4755 case SCTP_STATE_SHUTDOWN_ACK_SENT: 4755 case SCTP_STATE_SHUTDOWN_ACK_SENT:
4756 reply = sctp_make_shutdown_ack(asoc, NULL); 4756 reply = sctp_make_shutdown_ack(asoc, NULL);
4757 break; 4757 break;
4758 4758
4759 default: 4759 default:
4760 BUG(); 4760 BUG();
4761 break; 4761 break;
4762 }; 4762 };
4763 4763
4764 if (!reply) 4764 if (!reply)
4765 goto nomem; 4765 goto nomem;
4766 4766
4767 /* Do some failure management (Section 8.2). */ 4767 /* Do some failure management (Section 8.2). */
4768 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, 4768 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
4769 SCTP_TRANSPORT(asoc->shutdown_last_sent_to)); 4769 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
4770 4770
4771 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for 4771 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4772 * the T2-shutdown timer. 4772 * the T2-shutdown timer.
4773 */ 4773 */
4774 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); 4774 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4775 4775
4776 /* Restart the T2-shutdown timer. */ 4776 /* Restart the T2-shutdown timer. */
4777 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 4777 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4778 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 4778 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4779 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 4779 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4780 return SCTP_DISPOSITION_CONSUME; 4780 return SCTP_DISPOSITION_CONSUME;
4781 4781
4782 nomem: 4782 nomem:
4783 return SCTP_DISPOSITION_NOMEM; 4783 return SCTP_DISPOSITION_NOMEM;
4784 } 4784 }
4785 4785
4786 /* 4786 /*
4787 * ADDIP Section 4.1 ASCONF CHunk Procedures 4787 * ADDIP Section 4.1 ASCONF CHunk Procedures
4788 * If the T4 RTO timer expires the endpoint should do B1 to B5 4788 * If the T4 RTO timer expires the endpoint should do B1 to B5
4789 */ 4789 */
4790 sctp_disposition_t sctp_sf_t4_timer_expire( 4790 sctp_disposition_t sctp_sf_t4_timer_expire(
4791 const struct sctp_endpoint *ep, 4791 const struct sctp_endpoint *ep,
4792 const struct sctp_association *asoc, 4792 const struct sctp_association *asoc,
4793 const sctp_subtype_t type, 4793 const sctp_subtype_t type,
4794 void *arg, 4794 void *arg,
4795 sctp_cmd_seq_t *commands) 4795 sctp_cmd_seq_t *commands)
4796 { 4796 {
4797 struct sctp_chunk *chunk = asoc->addip_last_asconf; 4797 struct sctp_chunk *chunk = asoc->addip_last_asconf;
4798 struct sctp_transport *transport = chunk->transport; 4798 struct sctp_transport *transport = chunk->transport;
4799 4799
4800 /* ADDIP 4.1 B1) Increment the error counters and perform path failure 4800 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
4801 * detection on the appropriate destination address as defined in 4801 * detection on the appropriate destination address as defined in
4802 * RFC2960 [5] section 8.1 and 8.2. 4802 * RFC2960 [5] section 8.1 and 8.2.
4803 */ 4803 */
4804 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); 4804 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4805 4805
4806 /* Reconfig T4 timer and transport. */ 4806 /* Reconfig T4 timer and transport. */
4807 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); 4807 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4808 4808
4809 /* ADDIP 4.1 B2) Increment the association error counters and perform 4809 /* ADDIP 4.1 B2) Increment the association error counters and perform
4810 * endpoint failure detection on the association as defined in 4810 * endpoint failure detection on the association as defined in
4811 * RFC2960 [5] section 8.1 and 8.2. 4811 * RFC2960 [5] section 8.1 and 8.2.
4812 * association error counter is incremented in SCTP_CMD_STRIKE. 4812 * association error counter is incremented in SCTP_CMD_STRIKE.
4813 */ 4813 */
4814 if (asoc->overall_error_count >= asoc->max_retrans) { 4814 if (asoc->overall_error_count >= asoc->max_retrans) {
4815 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 4815 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4816 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); 4816 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4817 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 4817 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4818 SCTP_U32(SCTP_ERROR_NO_ERROR)); 4818 SCTP_U32(SCTP_ERROR_NO_ERROR));
4819 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 4819 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4820 SCTP_INC_STATS(SCTP_MIB_CURRESTAB); 4820 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
4821 return SCTP_DISPOSITION_ABORT; 4821 return SCTP_DISPOSITION_ABORT;
4822 } 4822 }
4823 4823
4824 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which 4824 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
4825 * the ASCONF chunk was sent by doubling the RTO timer value. 4825 * the ASCONF chunk was sent by doubling the RTO timer value.
4826 * This is done in SCTP_CMD_STRIKE. 4826 * This is done in SCTP_CMD_STRIKE.
4827 */ 4827 */
4828 4828
4829 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible 4829 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
4830 * choose an alternate destination address (please refer to RFC2960 4830 * choose an alternate destination address (please refer to RFC2960
4831 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this 4831 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
4832 * chunk, it MUST be the same (including its serial number) as the last 4832 * chunk, it MUST be the same (including its serial number) as the last
4833 * ASCONF sent. 4833 * ASCONF sent.
4834 */ 4834 */
4835 sctp_chunk_hold(asoc->addip_last_asconf); 4835 sctp_chunk_hold(asoc->addip_last_asconf);
4836 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 4836 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4837 SCTP_CHUNK(asoc->addip_last_asconf)); 4837 SCTP_CHUNK(asoc->addip_last_asconf));
4838 4838
4839 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different 4839 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
4840 * destination is selected, then the RTO used will be that of the new 4840 * destination is selected, then the RTO used will be that of the new
4841 * destination address. 4841 * destination address.
4842 */ 4842 */
4843 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 4843 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4844 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); 4844 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4845 4845
4846 return SCTP_DISPOSITION_CONSUME; 4846 return SCTP_DISPOSITION_CONSUME;
4847 } 4847 }
4848 4848
4849 /* sctpimpguide-05 Section 2.12.2 4849 /* sctpimpguide-05 Section 2.12.2
4850 * The sender of the SHUTDOWN MAY also start an overall guard timer 4850 * The sender of the SHUTDOWN MAY also start an overall guard timer
4851 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. 4851 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4852 * At the expiration of this timer the sender SHOULD abort the association 4852 * At the expiration of this timer the sender SHOULD abort the association
4853 * by sending an ABORT chunk. 4853 * by sending an ABORT chunk.
4854 */ 4854 */
4855 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep, 4855 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
4856 const struct sctp_association *asoc, 4856 const struct sctp_association *asoc,
4857 const sctp_subtype_t type, 4857 const sctp_subtype_t type,
4858 void *arg, 4858 void *arg,
4859 sctp_cmd_seq_t *commands) 4859 sctp_cmd_seq_t *commands)
4860 { 4860 {
4861 struct sctp_chunk *reply = NULL; 4861 struct sctp_chunk *reply = NULL;
4862 4862
4863 SCTP_DEBUG_PRINTK("Timer T5 expired.\n"); 4863 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4864 4864
4865 reply = sctp_make_abort(asoc, NULL, 0); 4865 reply = sctp_make_abort(asoc, NULL, 0);
4866 if (!reply) 4866 if (!reply)
4867 goto nomem; 4867 goto nomem;
4868 4868
4869 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); 4869 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4870 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 4870 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4871 SCTP_U32(SCTP_ERROR_NO_ERROR)); 4871 SCTP_U32(SCTP_ERROR_NO_ERROR));
4872 4872
4873 return SCTP_DISPOSITION_DELETE_TCB; 4873 return SCTP_DISPOSITION_DELETE_TCB;
4874 nomem: 4874 nomem:
4875 return SCTP_DISPOSITION_NOMEM; 4875 return SCTP_DISPOSITION_NOMEM;
4876 } 4876 }
4877 4877
4878 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires, 4878 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4879 * the association is automatically closed by starting the shutdown process. 4879 * the association is automatically closed by starting the shutdown process.
4880 * The work that needs to be done is same as when SHUTDOWN is initiated by 4880 * The work that needs to be done is same as when SHUTDOWN is initiated by
4881 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown(). 4881 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4882 */ 4882 */
4883 sctp_disposition_t sctp_sf_autoclose_timer_expire( 4883 sctp_disposition_t sctp_sf_autoclose_timer_expire(
4884 const struct sctp_endpoint *ep, 4884 const struct sctp_endpoint *ep,
4885 const struct sctp_association *asoc, 4885 const struct sctp_association *asoc,
4886 const sctp_subtype_t type, 4886 const sctp_subtype_t type,
4887 void *arg, 4887 void *arg,
4888 sctp_cmd_seq_t *commands) 4888 sctp_cmd_seq_t *commands)
4889 { 4889 {
4890 int disposition; 4890 int disposition;
4891 4891
4892 /* From 9.2 Shutdown of an Association 4892 /* From 9.2 Shutdown of an Association
4893 * Upon receipt of the SHUTDOWN primitive from its upper 4893 * Upon receipt of the SHUTDOWN primitive from its upper
4894 * layer, the endpoint enters SHUTDOWN-PENDING state and 4894 * layer, the endpoint enters SHUTDOWN-PENDING state and
4895 * remains there until all outstanding data has been 4895 * remains there until all outstanding data has been
4896 * acknowledged by its peer. The endpoint accepts no new data 4896 * acknowledged by its peer. The endpoint accepts no new data
4897 * from its upper layer, but retransmits data to the far end 4897 * from its upper layer, but retransmits data to the far end
4898 * if necessary to fill gaps. 4898 * if necessary to fill gaps.
4899 */ 4899 */
4900 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 4900 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4901 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); 4901 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4902 4902
4903 /* sctpimpguide-05 Section 2.12.2 4903 /* sctpimpguide-05 Section 2.12.2
4904 * The sender of the SHUTDOWN MAY also start an overall guard timer 4904 * The sender of the SHUTDOWN MAY also start an overall guard timer
4905 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. 4905 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4906 */ 4906 */
4907 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 4907 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4908 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 4908 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4909 disposition = SCTP_DISPOSITION_CONSUME; 4909 disposition = SCTP_DISPOSITION_CONSUME;
4910 if (sctp_outq_is_empty(&asoc->outqueue)) { 4910 if (sctp_outq_is_empty(&asoc->outqueue)) {
4911 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type, 4911 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4912 arg, commands); 4912 arg, commands);
4913 } 4913 }
4914 return disposition; 4914 return disposition;
4915 } 4915 }
4916 4916
4917 /***************************************************************************** 4917 /*****************************************************************************
4918 * These are sa state functions which could apply to all types of events. 4918 * These are sa state functions which could apply to all types of events.
4919 ****************************************************************************/ 4919 ****************************************************************************/
4920 4920
4921 /* 4921 /*
4922 * This table entry is not implemented. 4922 * This table entry is not implemented.
4923 * 4923 *
4924 * Inputs 4924 * Inputs
4925 * (endpoint, asoc, chunk) 4925 * (endpoint, asoc, chunk)
4926 * 4926 *
4927 * The return value is the disposition of the chunk. 4927 * The return value is the disposition of the chunk.
4928 */ 4928 */
4929 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep, 4929 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
4930 const struct sctp_association *asoc, 4930 const struct sctp_association *asoc,
4931 const sctp_subtype_t type, 4931 const sctp_subtype_t type,
4932 void *arg, 4932 void *arg,
4933 sctp_cmd_seq_t *commands) 4933 sctp_cmd_seq_t *commands)
4934 { 4934 {
4935 return SCTP_DISPOSITION_NOT_IMPL; 4935 return SCTP_DISPOSITION_NOT_IMPL;
4936 } 4936 }
4937 4937
4938 /* 4938 /*
4939 * This table entry represents a bug. 4939 * This table entry represents a bug.
4940 * 4940 *
4941 * Inputs 4941 * Inputs
4942 * (endpoint, asoc, chunk) 4942 * (endpoint, asoc, chunk)
4943 * 4943 *
4944 * The return value is the disposition of the chunk. 4944 * The return value is the disposition of the chunk.
4945 */ 4945 */
4946 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep, 4946 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
4947 const struct sctp_association *asoc, 4947 const struct sctp_association *asoc,
4948 const sctp_subtype_t type, 4948 const sctp_subtype_t type,
4949 void *arg, 4949 void *arg,
4950 sctp_cmd_seq_t *commands) 4950 sctp_cmd_seq_t *commands)
4951 { 4951 {
4952 return SCTP_DISPOSITION_BUG; 4952 return SCTP_DISPOSITION_BUG;
4953 } 4953 }
4954 4954
4955 /* 4955 /*
4956 * This table entry represents the firing of a timer in the wrong state. 4956 * This table entry represents the firing of a timer in the wrong state.
4957 * Since timer deletion cannot be guaranteed a timer 'may' end up firing 4957 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
4958 * when the association is in the wrong state. This event should 4958 * when the association is in the wrong state. This event should
4959 * be ignored, so as to prevent any rearming of the timer. 4959 * be ignored, so as to prevent any rearming of the timer.
4960 * 4960 *
4961 * Inputs 4961 * Inputs
4962 * (endpoint, asoc, chunk) 4962 * (endpoint, asoc, chunk)
4963 * 4963 *
4964 * The return value is the disposition of the chunk. 4964 * The return value is the disposition of the chunk.
4965 */ 4965 */
4966 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep, 4966 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
4967 const struct sctp_association *asoc, 4967 const struct sctp_association *asoc,
4968 const sctp_subtype_t type, 4968 const sctp_subtype_t type,
4969 void *arg, 4969 void *arg,
4970 sctp_cmd_seq_t *commands) 4970 sctp_cmd_seq_t *commands)
4971 { 4971 {
4972 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk); 4972 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
4973 return SCTP_DISPOSITION_CONSUME; 4973 return SCTP_DISPOSITION_CONSUME;
4974 } 4974 }
4975 4975
4976 /******************************************************************** 4976 /********************************************************************
4977 * 2nd Level Abstractions 4977 * 2nd Level Abstractions
4978 ********************************************************************/ 4978 ********************************************************************/
4979 4979
4980 /* Pull the SACK chunk based on the SACK header. */ 4980 /* Pull the SACK chunk based on the SACK header. */
4981 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk) 4981 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
4982 { 4982 {
4983 struct sctp_sackhdr *sack; 4983 struct sctp_sackhdr *sack;
4984 unsigned int len; 4984 unsigned int len;
4985 __u16 num_blocks; 4985 __u16 num_blocks;
4986 __u16 num_dup_tsns; 4986 __u16 num_dup_tsns;
4987 4987
4988 /* Protect ourselves from reading too far into 4988 /* Protect ourselves from reading too far into
4989 * the skb from a bogus sender. 4989 * the skb from a bogus sender.
4990 */ 4990 */
4991 sack = (struct sctp_sackhdr *) chunk->skb->data; 4991 sack = (struct sctp_sackhdr *) chunk->skb->data;
4992 4992
4993 num_blocks = ntohs(sack->num_gap_ack_blocks); 4993 num_blocks = ntohs(sack->num_gap_ack_blocks);
4994 num_dup_tsns = ntohs(sack->num_dup_tsns); 4994 num_dup_tsns = ntohs(sack->num_dup_tsns);
4995 len = sizeof(struct sctp_sackhdr); 4995 len = sizeof(struct sctp_sackhdr);
4996 len += (num_blocks + num_dup_tsns) * sizeof(__u32); 4996 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
4997 if (len > chunk->skb->len) 4997 if (len > chunk->skb->len)
4998 return NULL; 4998 return NULL;
4999 4999
5000 skb_pull(chunk->skb, len); 5000 skb_pull(chunk->skb, len);
5001 5001
5002 return sack; 5002 return sack;
5003 } 5003 }
5004 5004
5005 /* Create an ABORT packet to be sent as a response, with the specified 5005 /* Create an ABORT packet to be sent as a response, with the specified
5006 * error causes. 5006 * error causes.
5007 */ 5007 */
5008 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep, 5008 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
5009 const struct sctp_association *asoc, 5009 const struct sctp_association *asoc,
5010 struct sctp_chunk *chunk, 5010 struct sctp_chunk *chunk,
5011 const void *payload, 5011 const void *payload,
5012 size_t paylen) 5012 size_t paylen)
5013 { 5013 {
5014 struct sctp_packet *packet; 5014 struct sctp_packet *packet;
5015 struct sctp_chunk *abort; 5015 struct sctp_chunk *abort;
5016 5016
5017 packet = sctp_ootb_pkt_new(asoc, chunk); 5017 packet = sctp_ootb_pkt_new(asoc, chunk);
5018 5018
5019 if (packet) { 5019 if (packet) {
5020 /* Make an ABORT. 5020 /* Make an ABORT.
5021 * The T bit will be set if the asoc is NULL. 5021 * The T bit will be set if the asoc is NULL.
5022 */ 5022 */
5023 abort = sctp_make_abort(asoc, chunk, paylen); 5023 abort = sctp_make_abort(asoc, chunk, paylen);
5024 if (!abort) { 5024 if (!abort) {
5025 sctp_ootb_pkt_free(packet); 5025 sctp_ootb_pkt_free(packet);
5026 return NULL; 5026 return NULL;
5027 } 5027 }
5028 5028
5029 /* Reflect vtag if T-Bit is set */ 5029 /* Reflect vtag if T-Bit is set */
5030 if (sctp_test_T_bit(abort)) 5030 if (sctp_test_T_bit(abort))
5031 packet->vtag = ntohl(chunk->sctp_hdr->vtag); 5031 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
5032 5032
5033 /* Add specified error causes, i.e., payload, to the 5033 /* Add specified error causes, i.e., payload, to the
5034 * end of the chunk. 5034 * end of the chunk.
5035 */ 5035 */
5036 sctp_addto_chunk(abort, paylen, payload); 5036 sctp_addto_chunk(abort, paylen, payload);
5037 5037
5038 /* Set the skb to the belonging sock for accounting. */ 5038 /* Set the skb to the belonging sock for accounting. */
5039 abort->skb->sk = ep->base.sk; 5039 abort->skb->sk = ep->base.sk;
5040 5040
5041 sctp_packet_append_chunk(packet, abort); 5041 sctp_packet_append_chunk(packet, abort);
5042 5042
5043 } 5043 }
5044 5044
5045 return packet; 5045 return packet;
5046 } 5046 }
5047 5047
5048 /* Allocate a packet for responding in the OOTB conditions. */ 5048 /* Allocate a packet for responding in the OOTB conditions. */
5049 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc, 5049 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
5050 const struct sctp_chunk *chunk) 5050 const struct sctp_chunk *chunk)
5051 { 5051 {
5052 struct sctp_packet *packet; 5052 struct sctp_packet *packet;
5053 struct sctp_transport *transport; 5053 struct sctp_transport *transport;
5054 __u16 sport; 5054 __u16 sport;
5055 __u16 dport; 5055 __u16 dport;
5056 __u32 vtag; 5056 __u32 vtag;
5057 5057
5058 /* Get the source and destination port from the inbound packet. */ 5058 /* Get the source and destination port from the inbound packet. */
5059 sport = ntohs(chunk->sctp_hdr->dest); 5059 sport = ntohs(chunk->sctp_hdr->dest);
5060 dport = ntohs(chunk->sctp_hdr->source); 5060 dport = ntohs(chunk->sctp_hdr->source);
5061 5061
5062 /* The V-tag is going to be the same as the inbound packet if no 5062 /* The V-tag is going to be the same as the inbound packet if no
5063 * association exists, otherwise, use the peer's vtag. 5063 * association exists, otherwise, use the peer's vtag.
5064 */ 5064 */
5065 if (asoc) { 5065 if (asoc) {
5066 vtag = asoc->peer.i.init_tag; 5066 vtag = asoc->peer.i.init_tag;
5067 } else { 5067 } else {
5068 /* Special case the INIT and stale COOKIE_ECHO as there is no 5068 /* Special case the INIT and stale COOKIE_ECHO as there is no
5069 * vtag yet. 5069 * vtag yet.
5070 */ 5070 */
5071 switch(chunk->chunk_hdr->type) { 5071 switch(chunk->chunk_hdr->type) {
5072 case SCTP_CID_INIT: 5072 case SCTP_CID_INIT:
5073 { 5073 {
5074 sctp_init_chunk_t *init; 5074 sctp_init_chunk_t *init;
5075 5075
5076 init = (sctp_init_chunk_t *)chunk->chunk_hdr; 5076 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
5077 vtag = ntohl(init->init_hdr.init_tag); 5077 vtag = ntohl(init->init_hdr.init_tag);
5078 break; 5078 break;
5079 } 5079 }
5080 default: 5080 default:
5081 vtag = ntohl(chunk->sctp_hdr->vtag); 5081 vtag = ntohl(chunk->sctp_hdr->vtag);
5082 break; 5082 break;
5083 } 5083 }
5084 } 5084 }
5085 5085
5086 /* Make a transport for the bucket, Eliza... */ 5086 /* Make a transport for the bucket, Eliza... */
5087 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC); 5087 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
5088 if (!transport) 5088 if (!transport)
5089 goto nomem; 5089 goto nomem;
5090 5090
5091 /* Cache a route for the transport with the chunk's destination as 5091 /* Cache a route for the transport with the chunk's destination as
5092 * the source address. 5092 * the source address.
5093 */ 5093 */
5094 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest, 5094 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
5095 sctp_sk(sctp_get_ctl_sock())); 5095 sctp_sk(sctp_get_ctl_sock()));
5096 5096
5097 packet = sctp_packet_init(&transport->packet, transport, sport, dport); 5097 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
5098 packet = sctp_packet_config(packet, vtag, 0); 5098 packet = sctp_packet_config(packet, vtag, 0);
5099 5099
5100 return packet; 5100 return packet;
5101 5101
5102 nomem: 5102 nomem:
5103 return NULL; 5103 return NULL;
5104 } 5104 }
5105 5105
5106 /* Free the packet allocated earlier for responding in the OOTB condition. */ 5106 /* Free the packet allocated earlier for responding in the OOTB condition. */
5107 void sctp_ootb_pkt_free(struct sctp_packet *packet) 5107 void sctp_ootb_pkt_free(struct sctp_packet *packet)
5108 { 5108 {
5109 sctp_transport_free(packet->transport); 5109 sctp_transport_free(packet->transport);
5110 } 5110 }
5111 5111
5112 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */ 5112 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5113 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep, 5113 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
5114 const struct sctp_association *asoc, 5114 const struct sctp_association *asoc,
5115 const struct sctp_chunk *chunk, 5115 const struct sctp_chunk *chunk,
5116 sctp_cmd_seq_t *commands, 5116 sctp_cmd_seq_t *commands,
5117 struct sctp_chunk *err_chunk) 5117 struct sctp_chunk *err_chunk)
5118 { 5118 {
5119 struct sctp_packet *packet; 5119 struct sctp_packet *packet;
5120 5120
5121 if (err_chunk) { 5121 if (err_chunk) {
5122 packet = sctp_ootb_pkt_new(asoc, chunk); 5122 packet = sctp_ootb_pkt_new(asoc, chunk);
5123 if (packet) { 5123 if (packet) {
5124 struct sctp_signed_cookie *cookie; 5124 struct sctp_signed_cookie *cookie;
5125 5125
5126 /* Override the OOTB vtag from the cookie. */ 5126 /* Override the OOTB vtag from the cookie. */
5127 cookie = chunk->subh.cookie_hdr; 5127 cookie = chunk->subh.cookie_hdr;
5128 packet->vtag = cookie->c.peer_vtag; 5128 packet->vtag = cookie->c.peer_vtag;
5129 5129
5130 /* Set the skb to the belonging sock for accounting. */ 5130 /* Set the skb to the belonging sock for accounting. */
5131 err_chunk->skb->sk = ep->base.sk; 5131 err_chunk->skb->sk = ep->base.sk;
5132 sctp_packet_append_chunk(packet, err_chunk); 5132 sctp_packet_append_chunk(packet, err_chunk);
5133 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, 5133 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
5134 SCTP_PACKET(packet)); 5134 SCTP_PACKET(packet));
5135 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); 5135 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
5136 } else 5136 } else
5137 sctp_chunk_free (err_chunk); 5137 sctp_chunk_free (err_chunk);
5138 } 5138 }
5139 } 5139 }
5140 5140
5141 5141
5142 /* Process a data chunk */ 5142 /* Process a data chunk */
5143 static int sctp_eat_data(const struct sctp_association *asoc, 5143 static int sctp_eat_data(const struct sctp_association *asoc,
5144 struct sctp_chunk *chunk, 5144 struct sctp_chunk *chunk,
5145 sctp_cmd_seq_t *commands) 5145 sctp_cmd_seq_t *commands)
5146 { 5146 {
5147 sctp_datahdr_t *data_hdr; 5147 sctp_datahdr_t *data_hdr;
5148 struct sctp_chunk *err; 5148 struct sctp_chunk *err;
5149 size_t datalen; 5149 size_t datalen;
5150 sctp_verb_t deliver; 5150 sctp_verb_t deliver;
5151 int tmp; 5151 int tmp;
5152 __u32 tsn; 5152 __u32 tsn;
5153 int account_value; 5153 int account_value;
5154 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
5154 struct sock *sk = asoc->base.sk; 5155 struct sock *sk = asoc->base.sk;
5156 int rcvbuf_over = 0;
5155 5157
5156 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data; 5158 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
5157 skb_pull(chunk->skb, sizeof(sctp_datahdr_t)); 5159 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
5158 5160
5159 tsn = ntohl(data_hdr->tsn); 5161 tsn = ntohl(data_hdr->tsn);
5160 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn); 5162 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
5161 5163
5162 /* ASSERT: Now skb->data is really the user data. */ 5164 /* ASSERT: Now skb->data is really the user data. */
5163 5165
5164 /* 5166 /*
5165 * if we are established, and we have used up our receive 5167 * If we are established, and we have used up our receive buffer
5166 * buffer memory, drop the frame 5168 * memory, think about droping the frame.
5169 * Note that we have an opportunity to improve performance here.
5170 * If we accept one chunk from an skbuff, we have to keep all the
5171 * memory of that skbuff around until the chunk is read into user
5172 * space. Therefore, once we accept 1 chunk we may as well accept all
5173 * remaining chunks in the skbuff. The data_accepted flag helps us do
5174 * that.
5167 */ 5175 */
5168 if (asoc->state == SCTP_STATE_ESTABLISHED) { 5176 if ((asoc->state == SCTP_STATE_ESTABLISHED) && (!chunk->data_accepted)) {
5169 /* 5177 /*
5170 * If the receive buffer policy is 1, then each 5178 * If the receive buffer policy is 1, then each
5171 * association can allocate up to sk_rcvbuf bytes 5179 * association can allocate up to sk_rcvbuf bytes
5172 * otherwise, all the associations in aggregate 5180 * otherwise, all the associations in aggregate
5173 * may allocate up to sk_rcvbuf bytes 5181 * may allocate up to sk_rcvbuf bytes
5174 */ 5182 */
5175 if (asoc->ep->rcvbuf_policy) 5183 if (asoc->ep->rcvbuf_policy)
5176 account_value = atomic_read(&asoc->rmem_alloc); 5184 account_value = atomic_read(&asoc->rmem_alloc);
5177 else 5185 else
5178 account_value = atomic_read(&sk->sk_rmem_alloc); 5186 account_value = atomic_read(&sk->sk_rmem_alloc);
5187 if (account_value > sk->sk_rcvbuf) {
5188 /*
5189 * We need to make forward progress, even when we are
5190 * under memory pressure, so we always allow the
5191 * next tsn after the ctsn ack point to be accepted.
5192 * This lets us avoid deadlocks in which we have to
5193 * drop frames that would otherwise let us drain the
5194 * receive queue.
5195 */
5196 if ((sctp_tsnmap_get_ctsn(map) + 1) != tsn)
5197 return SCTP_IERROR_IGNORE_TSN;
5179 5198
5180 if (account_value > sk->sk_rcvbuf) 5199 /*
5181 return SCTP_IERROR_IGNORE_TSN; 5200 * We're going to accept the frame but we should renege
5201 * to make space for it. This will send us down that
5202 * path later in this function.
5203 */
5204 rcvbuf_over = 1;
5205 }
5182 } 5206 }
5183 5207
5184 /* Process ECN based congestion. 5208 /* Process ECN based congestion.
5185 * 5209 *
5186 * Since the chunk structure is reused for all chunks within 5210 * Since the chunk structure is reused for all chunks within
5187 * a packet, we use ecn_ce_done to track if we've already 5211 * a packet, we use ecn_ce_done to track if we've already
5188 * done CE processing for this packet. 5212 * done CE processing for this packet.
5189 * 5213 *
5190 * We need to do ECN processing even if we plan to discard the 5214 * We need to do ECN processing even if we plan to discard the
5191 * chunk later. 5215 * chunk later.
5192 */ 5216 */
5193 5217
5194 if (!chunk->ecn_ce_done) { 5218 if (!chunk->ecn_ce_done) {
5195 struct sctp_af *af; 5219 struct sctp_af *af;
5196 chunk->ecn_ce_done = 1; 5220 chunk->ecn_ce_done = 1;
5197 5221
5198 af = sctp_get_af_specific( 5222 af = sctp_get_af_specific(
5199 ipver2af(chunk->skb->nh.iph->version)); 5223 ipver2af(chunk->skb->nh.iph->version));
5200 5224
5201 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) { 5225 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
5202 /* Do real work as sideffect. */ 5226 /* Do real work as sideffect. */
5203 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE, 5227 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
5204 SCTP_U32(tsn)); 5228 SCTP_U32(tsn));
5205 } 5229 }
5206 } 5230 }
5207 5231
5208 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn); 5232 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
5209 if (tmp < 0) { 5233 if (tmp < 0) {
5210 /* The TSN is too high--silently discard the chunk and 5234 /* The TSN is too high--silently discard the chunk and
5211 * count on it getting retransmitted later. 5235 * count on it getting retransmitted later.
5212 */ 5236 */
5213 return SCTP_IERROR_HIGH_TSN; 5237 return SCTP_IERROR_HIGH_TSN;
5214 } else if (tmp > 0) { 5238 } else if (tmp > 0) {
5215 /* This is a duplicate. Record it. */ 5239 /* This is a duplicate. Record it. */
5216 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn)); 5240 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
5217 return SCTP_IERROR_DUP_TSN; 5241 return SCTP_IERROR_DUP_TSN;
5218 } 5242 }
5219 5243
5220 /* This is a new TSN. */ 5244 /* This is a new TSN. */
5221 5245
5222 /* Discard if there is no room in the receive window. 5246 /* Discard if there is no room in the receive window.
5223 * Actually, allow a little bit of overflow (up to a MTU). 5247 * Actually, allow a little bit of overflow (up to a MTU).
5224 */ 5248 */
5225 datalen = ntohs(chunk->chunk_hdr->length); 5249 datalen = ntohs(chunk->chunk_hdr->length);
5226 datalen -= sizeof(sctp_data_chunk_t); 5250 datalen -= sizeof(sctp_data_chunk_t);
5227 5251
5228 deliver = SCTP_CMD_CHUNK_ULP; 5252 deliver = SCTP_CMD_CHUNK_ULP;
5253 chunk->data_accepted = 1;
5229 5254
5230 /* Think about partial delivery. */ 5255 /* Think about partial delivery. */
5231 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) { 5256 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
5232 5257
5233 /* Even if we don't accept this chunk there is 5258 /* Even if we don't accept this chunk there is
5234 * memory pressure. 5259 * memory pressure.
5235 */ 5260 */
5236 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL()); 5261 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
5237 } 5262 }
5238 5263
5239 /* Spill over rwnd a little bit. Note: While allowed, this spill over 5264 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5240 * seems a bit troublesome in that frag_point varies based on 5265 * seems a bit troublesome in that frag_point varies based on
5241 * PMTU. In cases, such as loopback, this might be a rather 5266 * PMTU. In cases, such as loopback, this might be a rather
5242 * large spill over. 5267 * large spill over.
5243 */ 5268 */
5244 if (!asoc->rwnd || asoc->rwnd_over || 5269 if (!asoc->rwnd || asoc->rwnd_over ||
5245 (datalen > asoc->rwnd + asoc->frag_point)) { 5270 (datalen > asoc->rwnd + asoc->frag_point) ||
5271 rcvbuf_over) {
5246 5272
5247 /* If this is the next TSN, consider reneging to make 5273 /* If this is the next TSN, consider reneging to make
5248 * room. Note: Playing nice with a confused sender. A 5274 * room. Note: Playing nice with a confused sender. A
5249 * malicious sender can still eat up all our buffer 5275 * malicious sender can still eat up all our buffer
5250 * space and in the future we may want to detect and 5276 * space and in the future we may want to detect and
5251 * do more drastic reneging. 5277 * do more drastic reneging.
5252 */ 5278 */
5253 if (sctp_tsnmap_has_gap(&asoc->peer.tsn_map) && 5279 if (sctp_tsnmap_has_gap(map) &&
5254 (sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1) == tsn) { 5280 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5255 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn); 5281 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
5256 deliver = SCTP_CMD_RENEGE; 5282 deliver = SCTP_CMD_RENEGE;
5257 } else { 5283 } else {
5258 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, " 5284 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5259 "rwnd: %d\n", tsn, datalen, 5285 "rwnd: %d\n", tsn, datalen,
5260 asoc->rwnd); 5286 asoc->rwnd);
5261 return SCTP_IERROR_IGNORE_TSN; 5287 return SCTP_IERROR_IGNORE_TSN;
5262 } 5288 }
5263 } 5289 }
5264 5290
5265 /* 5291 /*
5266 * Section 3.3.10.9 No User Data (9) 5292 * Section 3.3.10.9 No User Data (9)
5267 * 5293 *
5268 * Cause of error 5294 * Cause of error
5269 * --------------- 5295 * ---------------
5270 * No User Data: This error cause is returned to the originator of a 5296 * No User Data: This error cause is returned to the originator of a
5271 * DATA chunk if a received DATA chunk has no user data. 5297 * DATA chunk if a received DATA chunk has no user data.
5272 */ 5298 */
5273 if (unlikely(0 == datalen)) { 5299 if (unlikely(0 == datalen)) {
5274 err = sctp_make_abort_no_data(asoc, chunk, tsn); 5300 err = sctp_make_abort_no_data(asoc, chunk, tsn);
5275 if (err) { 5301 if (err) {
5276 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 5302 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5277 SCTP_CHUNK(err)); 5303 SCTP_CHUNK(err));
5278 } 5304 }
5279 /* We are going to ABORT, so we might as well stop 5305 /* We are going to ABORT, so we might as well stop
5280 * processing the rest of the chunks in the packet. 5306 * processing the rest of the chunks in the packet.
5281 */ 5307 */
5282 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); 5308 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
5283 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 5309 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5284 SCTP_U32(SCTP_ERROR_NO_DATA)); 5310 SCTP_U32(SCTP_ERROR_NO_DATA));
5285 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); 5311 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5286 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); 5312 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5287 return SCTP_IERROR_NO_DATA; 5313 return SCTP_IERROR_NO_DATA;
5288 } 5314 }
5289 5315
5290 /* If definately accepting the DATA chunk, record its TSN, otherwise 5316 /* If definately accepting the DATA chunk, record its TSN, otherwise
5291 * wait for renege processing. 5317 * wait for renege processing.
5292 */ 5318 */
5293 if (SCTP_CMD_CHUNK_ULP == deliver) 5319 if (SCTP_CMD_CHUNK_ULP == deliver)
5294 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn)); 5320 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
5295 5321
5296 /* Note: Some chunks may get overcounted (if we drop) or overcounted 5322 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5297 * if we renege and the chunk arrives again. 5323 * if we renege and the chunk arrives again.
5298 */ 5324 */
5299 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) 5325 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
5300 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS); 5326 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS);
5301 else 5327 else
5302 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS); 5328 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS);
5303 5329
5304 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number 5330 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5305 * 5331 *
5306 * If an endpoint receive a DATA chunk with an invalid stream 5332 * If an endpoint receive a DATA chunk with an invalid stream
5307 * identifier, it shall acknowledge the reception of the DATA chunk 5333 * identifier, it shall acknowledge the reception of the DATA chunk
5308 * following the normal procedure, immediately send an ERROR chunk 5334 * following the normal procedure, immediately send an ERROR chunk
5309 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10) 5335 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5310 * and discard the DATA chunk. 5336 * and discard the DATA chunk.
5311 */ 5337 */
5312 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) { 5338 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
5313 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM, 5339 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
5314 &data_hdr->stream, 5340 &data_hdr->stream,
5315 sizeof(data_hdr->stream)); 5341 sizeof(data_hdr->stream));
5316 if (err) 5342 if (err)
5317 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 5343 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5318 SCTP_CHUNK(err)); 5344 SCTP_CHUNK(err));
5319 return SCTP_IERROR_BAD_STREAM; 5345 return SCTP_IERROR_BAD_STREAM;
5320 } 5346 }
5321 5347
5322 /* Send the data up to the user. Note: Schedule the 5348 /* Send the data up to the user. Note: Schedule the
5323 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK 5349 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5324 * chunk needs the updated rwnd. 5350 * chunk needs the updated rwnd.
5325 */ 5351 */
5326 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk)); 5352 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
5327 5353
5328 return SCTP_IERROR_NO_ERROR; 5354 return SCTP_IERROR_NO_ERROR;
5329 } 5355 }
5330 5356