1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
7 * This file is part of the SCTP kernel reference Implementation
9 * These functions work with the state functions in sctp_sm_statefuns.c
10 * to implement the state operations. These functions implement the
11 * steps which require modifying existing data structures.
13 * The SCTP reference implementation is free software;
14 * you can redistribute it and/or modify it under the terms of
15 * the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * The SCTP reference implementation is distributed in the hope that it
20 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
21 * ************************
22 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * See the GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, write to
27 * the Free Software Foundation, 59 Temple Place - Suite 330,
28 * Boston, MA 02111-1307, USA.
30 * Please send any bug reports or fixes you make to the
32 * lksctp developers <lksctp-developers@lists.sourceforge.net>
34 * Or submit a bug report through the following website:
35 * http://www.sf.net/projects/lksctp
37 * Written or modified by:
38 * La Monte H.P. Yarroll <piggy@acm.org>
39 * Karl Knutson <karl@athena.chicago.il.us>
40 * C. Robin <chris@hundredacre.ac.uk>
41 * Jon Grimm <jgrimm@us.ibm.com>
42 * Xingang Guo <xingang.guo@intel.com>
43 * Dajiang Zhang <dajiang.zhang@nokia.com>
44 * Sridhar Samudrala <sri@us.ibm.com>
45 * Daisy Chang <daisyc@us.ibm.com>
46 * Ardelle Fan <ardelle.fan@intel.com>
47 * Kevin Gao <kevin.gao@intel.com>
49 * Any bugs reported given to us we will try to fix... any fixes shared will
50 * be incorporated into the next SCTP release.
53 #include <linux/types.h>
54 #include <linux/kernel.h>
56 #include <linux/ipv6.h>
57 #include <linux/net.h>
58 #include <linux/inet.h>
59 #include <asm/scatterlist.h>
60 #include <linux/crypto.h>
63 #include <linux/skbuff.h>
64 #include <linux/random.h> /* for get_random_bytes */
65 #include <net/sctp/sctp.h>
66 #include <net/sctp/sm.h>
69 struct sctp_chunk
*sctp_make_chunk(const struct sctp_association
*asoc
,
70 __u8 type
, __u8 flags
, int paylen
);
71 static sctp_cookie_param_t
*sctp_pack_cookie(const struct sctp_endpoint
*ep
,
72 const struct sctp_association
*asoc
,
73 const struct sctp_chunk
*init_chunk
,
75 const __u8
*raw_addrs
, int addrs_len
);
76 static int sctp_process_param(struct sctp_association
*asoc
,
77 union sctp_params param
,
78 const union sctp_addr
*peer_addr
,
81 /* What was the inbound interface for this chunk? */
82 int sctp_chunk_iif(const struct sctp_chunk
*chunk
)
87 af
= sctp_get_af_specific(ipver2af(ip_hdr(chunk
->skb
)->version
));
89 iif
= af
->skb_iif(chunk
->skb
);
94 /* RFC 2960 3.3.2 Initiation (INIT) (1)
96 * Note 2: The ECN capable field is reserved for future use of
97 * Explicit Congestion Notification.
99 static const struct sctp_paramhdr ecap_param
= {
100 SCTP_PARAM_ECN_CAPABLE
,
101 __constant_htons(sizeof(struct sctp_paramhdr
)),
103 static const struct sctp_paramhdr prsctp_param
= {
104 SCTP_PARAM_FWD_TSN_SUPPORT
,
105 __constant_htons(sizeof(struct sctp_paramhdr
)),
108 /* A helper to initialize to initialize an op error inside a
109 * provided chunk, as most cause codes will be embedded inside an
112 void sctp_init_cause(struct sctp_chunk
*chunk
, __be16 cause_code
,
113 const void *payload
, size_t paylen
)
119 /* Cause code constants are now defined in network order. */
120 err
.cause
= cause_code
;
121 len
= sizeof(sctp_errhdr_t
) + paylen
;
123 err
.length
= htons(len
);
125 chunk
->subh
.err_hdr
= sctp_addto_chunk(chunk
, sizeof(sctp_errhdr_t
), &err
);
126 sctp_addto_chunk(chunk
, paylen
, payload
);
129 /* 3.3.2 Initiation (INIT) (1)
131 * This chunk is used to initiate a SCTP association between two
132 * endpoints. The format of the INIT chunk is shown below:
135 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
136 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
137 * | Type = 1 | Chunk Flags | Chunk Length |
138 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141 * | Advertised Receiver Window Credit (a_rwnd) |
142 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 * | Number of Outbound Streams | Number of Inbound Streams |
144 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
146 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148 * / Optional/Variable-Length Parameters /
150 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 * The INIT chunk contains the following parameters. Unless otherwise
154 * noted, each parameter MUST only be included once in the INIT chunk.
156 * Fixed Parameters Status
157 * ----------------------------------------------
158 * Initiate Tag Mandatory
159 * Advertised Receiver Window Credit Mandatory
160 * Number of Outbound Streams Mandatory
161 * Number of Inbound Streams Mandatory
162 * Initial TSN Mandatory
164 * Variable Parameters Status Type Value
165 * -------------------------------------------------------------
166 * IPv4 Address (Note 1) Optional 5
167 * IPv6 Address (Note 1) Optional 6
168 * Cookie Preservative Optional 9
169 * Reserved for ECN Capable (Note 2) Optional 32768 (0x8000)
170 * Host Name Address (Note 3) Optional 11
171 * Supported Address Types (Note 4) Optional 12
173 struct sctp_chunk
*sctp_make_init(const struct sctp_association
*asoc
,
174 const struct sctp_bind_addr
*bp
,
175 gfp_t gfp
, int vparam_len
)
178 union sctp_params addrs
;
180 struct sctp_chunk
*retval
= NULL
;
181 int num_types
, addrs_len
= 0;
182 struct sctp_sock
*sp
;
183 sctp_supported_addrs_param_t sat
;
185 sctp_adaptation_ind_param_t aiparam
;
187 /* RFC 2960 3.3.2 Initiation (INIT) (1)
189 * Note 1: The INIT chunks can contain multiple addresses that
190 * can be IPv4 and/or IPv6 in any combination.
194 /* Convert the provided bind address list to raw format. */
195 addrs
= sctp_bind_addrs_to_raw(bp
, &addrs_len
, gfp
);
197 init
.init_tag
= htonl(asoc
->c
.my_vtag
);
198 init
.a_rwnd
= htonl(asoc
->rwnd
);
199 init
.num_outbound_streams
= htons(asoc
->c
.sinit_num_ostreams
);
200 init
.num_inbound_streams
= htons(asoc
->c
.sinit_max_instreams
);
201 init
.initial_tsn
= htonl(asoc
->c
.initial_tsn
);
203 /* How many address types are needed? */
204 sp
= sctp_sk(asoc
->base
.sk
);
205 num_types
= sp
->pf
->supported_addrs(sp
, types
);
207 chunksize
= sizeof(init
) + addrs_len
+ SCTP_SAT_LEN(num_types
);
208 chunksize
+= sizeof(ecap_param
);
209 if (sctp_prsctp_enable
)
210 chunksize
+= sizeof(prsctp_param
);
211 chunksize
+= sizeof(aiparam
);
212 chunksize
+= vparam_len
;
214 /* RFC 2960 3.3.2 Initiation (INIT) (1)
216 * Note 3: An INIT chunk MUST NOT contain more than one Host
217 * Name address parameter. Moreover, the sender of the INIT
218 * MUST NOT combine any other address types with the Host Name
219 * address in the INIT. The receiver of INIT MUST ignore any
220 * other address types if the Host Name address parameter is
221 * present in the received INIT chunk.
223 * PLEASE DO NOT FIXME [This version does not support Host Name.]
226 retval
= sctp_make_chunk(asoc
, SCTP_CID_INIT
, 0, chunksize
);
230 retval
->subh
.init_hdr
=
231 sctp_addto_chunk(retval
, sizeof(init
), &init
);
232 retval
->param_hdr
.v
=
233 sctp_addto_chunk(retval
, addrs_len
, addrs
.v
);
235 /* RFC 2960 3.3.2 Initiation (INIT) (1)
237 * Note 4: This parameter, when present, specifies all the
238 * address types the sending endpoint can support. The absence
239 * of this parameter indicates that the sending endpoint can
240 * support any address type.
242 sat
.param_hdr
.type
= SCTP_PARAM_SUPPORTED_ADDRESS_TYPES
;
243 sat
.param_hdr
.length
= htons(SCTP_SAT_LEN(num_types
));
244 sctp_addto_chunk(retval
, sizeof(sat
), &sat
);
245 sctp_addto_chunk(retval
, num_types
* sizeof(__u16
), &types
);
247 sctp_addto_chunk(retval
, sizeof(ecap_param
), &ecap_param
);
248 if (sctp_prsctp_enable
)
249 sctp_addto_chunk(retval
, sizeof(prsctp_param
), &prsctp_param
);
250 aiparam
.param_hdr
.type
= SCTP_PARAM_ADAPTATION_LAYER_IND
;
251 aiparam
.param_hdr
.length
= htons(sizeof(aiparam
));
252 aiparam
.adaptation_ind
= htonl(sp
->adaptation_ind
);
253 sctp_addto_chunk(retval
, sizeof(aiparam
), &aiparam
);
259 struct sctp_chunk
*sctp_make_init_ack(const struct sctp_association
*asoc
,
260 const struct sctp_chunk
*chunk
,
261 gfp_t gfp
, int unkparam_len
)
263 sctp_inithdr_t initack
;
264 struct sctp_chunk
*retval
;
265 union sctp_params addrs
;
267 sctp_cookie_param_t
*cookie
;
270 sctp_adaptation_ind_param_t aiparam
;
274 /* Note: there may be no addresses to embed. */
275 addrs
= sctp_bind_addrs_to_raw(&asoc
->base
.bind_addr
, &addrs_len
, gfp
);
277 initack
.init_tag
= htonl(asoc
->c
.my_vtag
);
278 initack
.a_rwnd
= htonl(asoc
->rwnd
);
279 initack
.num_outbound_streams
= htons(asoc
->c
.sinit_num_ostreams
);
280 initack
.num_inbound_streams
= htons(asoc
->c
.sinit_max_instreams
);
281 initack
.initial_tsn
= htonl(asoc
->c
.initial_tsn
);
283 /* FIXME: We really ought to build the cookie right
284 * into the packet instead of allocating more fresh memory.
286 cookie
= sctp_pack_cookie(asoc
->ep
, asoc
, chunk
, &cookie_len
,
291 /* Calculate the total size of allocation, include the reserved
292 * space for reporting unknown parameters if it is specified.
294 chunksize
= sizeof(initack
) + addrs_len
+ cookie_len
+ unkparam_len
;
296 /* Tell peer that we'll do ECN only if peer advertised such cap. */
297 if (asoc
->peer
.ecn_capable
)
298 chunksize
+= sizeof(ecap_param
);
300 /* Tell peer that we'll do PR-SCTP only if peer advertised. */
301 if (asoc
->peer
.prsctp_capable
)
302 chunksize
+= sizeof(prsctp_param
);
304 chunksize
+= sizeof(aiparam
);
306 /* Now allocate and fill out the chunk. */
307 retval
= sctp_make_chunk(asoc
, SCTP_CID_INIT_ACK
, 0, chunksize
);
311 /* Per the advice in RFC 2960 6.4, send this reply to
312 * the source of the INIT packet.
314 retval
->transport
= chunk
->transport
;
315 retval
->subh
.init_hdr
=
316 sctp_addto_chunk(retval
, sizeof(initack
), &initack
);
317 retval
->param_hdr
.v
= sctp_addto_chunk(retval
, addrs_len
, addrs
.v
);
318 sctp_addto_chunk(retval
, cookie_len
, cookie
);
319 if (asoc
->peer
.ecn_capable
)
320 sctp_addto_chunk(retval
, sizeof(ecap_param
), &ecap_param
);
321 if (asoc
->peer
.prsctp_capable
)
322 sctp_addto_chunk(retval
, sizeof(prsctp_param
), &prsctp_param
);
324 aiparam
.param_hdr
.type
= SCTP_PARAM_ADAPTATION_LAYER_IND
;
325 aiparam
.param_hdr
.length
= htons(sizeof(aiparam
));
326 aiparam
.adaptation_ind
= htonl(sctp_sk(asoc
->base
.sk
)->adaptation_ind
);
327 sctp_addto_chunk(retval
, sizeof(aiparam
), &aiparam
);
329 /* We need to remove the const qualifier at this point. */
330 retval
->asoc
= (struct sctp_association
*) asoc
;
332 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
334 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
335 * HEARTBEAT ACK, * etc.) to the same destination transport
336 * address from which it received the DATA or control chunk
337 * to which it is replying.
339 * [INIT ACK back to where the INIT came from.]
342 retval
->transport
= chunk
->transport
;
351 /* 3.3.11 Cookie Echo (COOKIE ECHO) (10):
353 * This chunk is used only during the initialization of an association.
354 * It is sent by the initiator of an association to its peer to complete
355 * the initialization process. This chunk MUST precede any DATA chunk
356 * sent within the association, but MAY be bundled with one or more DATA
357 * chunks in the same packet.
360 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
361 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
362 * | Type = 10 |Chunk Flags | Length |
363 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
366 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
370 * Set to zero on transmit and ignored on receipt.
372 * Length: 16 bits (unsigned integer)
374 * Set to the size of the chunk in bytes, including the 4 bytes of
375 * the chunk header and the size of the Cookie.
377 * Cookie: variable size
379 * This field must contain the exact cookie received in the
380 * State Cookie parameter from the previous INIT ACK.
382 * An implementation SHOULD make the cookie as small as possible
383 * to insure interoperability.
385 struct sctp_chunk
*sctp_make_cookie_echo(const struct sctp_association
*asoc
,
386 const struct sctp_chunk
*chunk
)
388 struct sctp_chunk
*retval
;
392 cookie
= asoc
->peer
.cookie
;
393 cookie_len
= asoc
->peer
.cookie_len
;
395 /* Build a cookie echo chunk. */
396 retval
= sctp_make_chunk(asoc
, SCTP_CID_COOKIE_ECHO
, 0, cookie_len
);
399 retval
->subh
.cookie_hdr
=
400 sctp_addto_chunk(retval
, cookie_len
, cookie
);
402 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
404 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
405 * HEARTBEAT ACK, * etc.) to the same destination transport
406 * address from which it * received the DATA or control chunk
407 * to which it is replying.
409 * [COOKIE ECHO back to where the INIT ACK came from.]
412 retval
->transport
= chunk
->transport
;
418 /* 3.3.12 Cookie Acknowledgement (COOKIE ACK) (11):
420 * This chunk is used only during the initialization of an
421 * association. It is used to acknowledge the receipt of a COOKIE
422 * ECHO chunk. This chunk MUST precede any DATA or SACK chunk sent
423 * within the association, but MAY be bundled with one or more DATA
424 * chunks or SACK chunk in the same SCTP packet.
427 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
428 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
429 * | Type = 11 |Chunk Flags | Length = 4 |
430 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
432 * Chunk Flags: 8 bits
434 * Set to zero on transmit and ignored on receipt.
436 struct sctp_chunk
*sctp_make_cookie_ack(const struct sctp_association
*asoc
,
437 const struct sctp_chunk
*chunk
)
439 struct sctp_chunk
*retval
;
441 retval
= sctp_make_chunk(asoc
, SCTP_CID_COOKIE_ACK
, 0, 0);
443 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
445 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
446 * HEARTBEAT ACK, * etc.) to the same destination transport
447 * address from which it * received the DATA or control chunk
448 * to which it is replying.
450 * [COOKIE ACK back to where the COOKIE ECHO came from.]
453 retval
->transport
= chunk
->transport
;
459 * Appendix A: Explicit Congestion Notification:
462 * RFC 2481 details a specific bit for a sender to send in the header of
463 * its next outbound TCP segment to indicate to its peer that it has
464 * reduced its congestion window. This is termed the CWR bit. For
465 * SCTP the same indication is made by including the CWR chunk.
466 * This chunk contains one data element, i.e. the TSN number that
467 * was sent in the ECNE chunk. This element represents the lowest
468 * TSN number in the datagram that was originally marked with the
472 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
473 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
474 * | Chunk Type=13 | Flags=00000000| Chunk Length = 8 |
475 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
476 * | Lowest TSN Number |
477 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
479 * Note: The CWR is considered a Control chunk.
481 struct sctp_chunk
*sctp_make_cwr(const struct sctp_association
*asoc
,
482 const __u32 lowest_tsn
,
483 const struct sctp_chunk
*chunk
)
485 struct sctp_chunk
*retval
;
488 cwr
.lowest_tsn
= htonl(lowest_tsn
);
489 retval
= sctp_make_chunk(asoc
, SCTP_CID_ECN_CWR
, 0,
490 sizeof(sctp_cwrhdr_t
));
495 retval
->subh
.ecn_cwr_hdr
=
496 sctp_addto_chunk(retval
, sizeof(cwr
), &cwr
);
498 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
500 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
501 * HEARTBEAT ACK, * etc.) to the same destination transport
502 * address from which it * received the DATA or control chunk
503 * to which it is replying.
505 * [Report a reduced congestion window back to where the ECNE
509 retval
->transport
= chunk
->transport
;
515 /* Make an ECNE chunk. This is a congestion experienced report. */
516 struct sctp_chunk
*sctp_make_ecne(const struct sctp_association
*asoc
,
517 const __u32 lowest_tsn
)
519 struct sctp_chunk
*retval
;
522 ecne
.lowest_tsn
= htonl(lowest_tsn
);
523 retval
= sctp_make_chunk(asoc
, SCTP_CID_ECN_ECNE
, 0,
524 sizeof(sctp_ecnehdr_t
));
527 retval
->subh
.ecne_hdr
=
528 sctp_addto_chunk(retval
, sizeof(ecne
), &ecne
);
534 /* Make a DATA chunk for the given association from the provided
535 * parameters. However, do not populate the data payload.
537 struct sctp_chunk
*sctp_make_datafrag_empty(struct sctp_association
*asoc
,
538 const struct sctp_sndrcvinfo
*sinfo
,
539 int data_len
, __u8 flags
, __u16 ssn
)
541 struct sctp_chunk
*retval
;
542 struct sctp_datahdr dp
;
545 /* We assign the TSN as LATE as possible, not here when
546 * creating the chunk.
549 dp
.stream
= htons(sinfo
->sinfo_stream
);
550 dp
.ppid
= sinfo
->sinfo_ppid
;
552 /* Set the flags for an unordered send. */
553 if (sinfo
->sinfo_flags
& SCTP_UNORDERED
) {
554 flags
|= SCTP_DATA_UNORDERED
;
559 chunk_len
= sizeof(dp
) + data_len
;
560 retval
= sctp_make_chunk(asoc
, SCTP_CID_DATA
, flags
, chunk_len
);
564 retval
->subh
.data_hdr
= sctp_addto_chunk(retval
, sizeof(dp
), &dp
);
565 memcpy(&retval
->sinfo
, sinfo
, sizeof(struct sctp_sndrcvinfo
));
571 /* Create a selective ackowledgement (SACK) for the given
572 * association. This reports on which TSN's we've seen to date,
573 * including duplicates and gaps.
575 struct sctp_chunk
*sctp_make_sack(const struct sctp_association
*asoc
)
577 struct sctp_chunk
*retval
;
578 struct sctp_sackhdr sack
;
581 __u16 num_gabs
, num_dup_tsns
;
582 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
584 ctsn
= sctp_tsnmap_get_ctsn(map
);
585 SCTP_DEBUG_PRINTK("sackCTSNAck sent: 0x%x.\n", ctsn
);
587 /* How much room is needed in the chunk? */
588 num_gabs
= sctp_tsnmap_num_gabs(map
);
589 num_dup_tsns
= sctp_tsnmap_num_dups(map
);
591 /* Initialize the SACK header. */
592 sack
.cum_tsn_ack
= htonl(ctsn
);
593 sack
.a_rwnd
= htonl(asoc
->a_rwnd
);
594 sack
.num_gap_ack_blocks
= htons(num_gabs
);
595 sack
.num_dup_tsns
= htons(num_dup_tsns
);
598 + sizeof(struct sctp_gap_ack_block
) * num_gabs
599 + sizeof(__u32
) * num_dup_tsns
;
601 /* Create the chunk. */
602 retval
= sctp_make_chunk(asoc
, SCTP_CID_SACK
, 0, len
);
606 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
608 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
609 * HEARTBEAT ACK, etc.) to the same destination transport
610 * address from which it received the DATA or control chunk to
611 * which it is replying. This rule should also be followed if
612 * the endpoint is bundling DATA chunks together with the
615 * However, when acknowledging multiple DATA chunks received
616 * in packets from different source addresses in a single
617 * SACK, the SACK chunk may be transmitted to one of the
618 * destination transport addresses from which the DATA or
619 * control chunks being acknowledged were received.
621 * [BUG: We do not implement the following paragraph.
622 * Perhaps we should remember the last transport we used for a
623 * SACK and avoid that (if possible) if we have seen any
624 * duplicates. --piggy]
626 * When a receiver of a duplicate DATA chunk sends a SACK to a
627 * multi- homed endpoint it MAY be beneficial to vary the
628 * destination address and not use the source address of the
629 * DATA chunk. The reason being that receiving a duplicate
630 * from a multi-homed endpoint might indicate that the return
631 * path (as specified in the source address of the DATA chunk)
632 * for the SACK is broken.
634 * [Send to the address from which we last received a DATA chunk.]
636 retval
->transport
= asoc
->peer
.last_data_from
;
638 retval
->subh
.sack_hdr
=
639 sctp_addto_chunk(retval
, sizeof(sack
), &sack
);
641 /* Add the gap ack block information. */
643 sctp_addto_chunk(retval
, sizeof(__u32
) * num_gabs
,
644 sctp_tsnmap_get_gabs(map
));
646 /* Add the duplicate TSN information. */
648 sctp_addto_chunk(retval
, sizeof(__u32
) * num_dup_tsns
,
649 sctp_tsnmap_get_dups(map
));
655 /* Make a SHUTDOWN chunk. */
656 struct sctp_chunk
*sctp_make_shutdown(const struct sctp_association
*asoc
,
657 const struct sctp_chunk
*chunk
)
659 struct sctp_chunk
*retval
;
660 sctp_shutdownhdr_t shut
;
663 ctsn
= sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
);
664 shut
.cum_tsn_ack
= htonl(ctsn
);
666 retval
= sctp_make_chunk(asoc
, SCTP_CID_SHUTDOWN
, 0,
667 sizeof(sctp_shutdownhdr_t
));
671 retval
->subh
.shutdown_hdr
=
672 sctp_addto_chunk(retval
, sizeof(shut
), &shut
);
675 retval
->transport
= chunk
->transport
;
680 struct sctp_chunk
*sctp_make_shutdown_ack(const struct sctp_association
*asoc
,
681 const struct sctp_chunk
*chunk
)
683 struct sctp_chunk
*retval
;
685 retval
= sctp_make_chunk(asoc
, SCTP_CID_SHUTDOWN_ACK
, 0, 0);
687 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
689 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
690 * HEARTBEAT ACK, * etc.) to the same destination transport
691 * address from which it * received the DATA or control chunk
692 * to which it is replying.
694 * [ACK back to where the SHUTDOWN came from.]
697 retval
->transport
= chunk
->transport
;
702 struct sctp_chunk
*sctp_make_shutdown_complete(
703 const struct sctp_association
*asoc
,
704 const struct sctp_chunk
*chunk
)
706 struct sctp_chunk
*retval
;
709 /* Set the T-bit if we have no association (vtag will be
712 flags
|= asoc
? 0 : SCTP_CHUNK_FLAG_T
;
714 retval
= sctp_make_chunk(asoc
, SCTP_CID_SHUTDOWN_COMPLETE
, flags
, 0);
716 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
718 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
719 * HEARTBEAT ACK, * etc.) to the same destination transport
720 * address from which it * received the DATA or control chunk
721 * to which it is replying.
723 * [Report SHUTDOWN COMPLETE back to where the SHUTDOWN ACK
727 retval
->transport
= chunk
->transport
;
732 /* Create an ABORT. Note that we set the T bit if we have no
733 * association, except when responding to an INIT (sctpimpguide 2.41).
735 struct sctp_chunk
*sctp_make_abort(const struct sctp_association
*asoc
,
736 const struct sctp_chunk
*chunk
,
739 struct sctp_chunk
*retval
;
742 /* Set the T-bit if we have no association and 'chunk' is not
743 * an INIT (vtag will be reflected).
746 if (chunk
&& chunk
->chunk_hdr
&&
747 chunk
->chunk_hdr
->type
== SCTP_CID_INIT
)
750 flags
= SCTP_CHUNK_FLAG_T
;
753 retval
= sctp_make_chunk(asoc
, SCTP_CID_ABORT
, flags
, hint
);
755 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
757 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
758 * HEARTBEAT ACK, * etc.) to the same destination transport
759 * address from which it * received the DATA or control chunk
760 * to which it is replying.
762 * [ABORT back to where the offender came from.]
765 retval
->transport
= chunk
->transport
;
770 /* Helper to create ABORT with a NO_USER_DATA error. */
771 struct sctp_chunk
*sctp_make_abort_no_data(
772 const struct sctp_association
*asoc
,
773 const struct sctp_chunk
*chunk
, __u32 tsn
)
775 struct sctp_chunk
*retval
;
778 retval
= sctp_make_abort(asoc
, chunk
, sizeof(sctp_errhdr_t
)
784 /* Put the tsn back into network byte order. */
785 payload
= htonl(tsn
);
786 sctp_init_cause(retval
, SCTP_ERROR_NO_DATA
, (const void *)&payload
,
789 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
791 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
792 * HEARTBEAT ACK, * etc.) to the same destination transport
793 * address from which it * received the DATA or control chunk
794 * to which it is replying.
796 * [ABORT back to where the offender came from.]
799 retval
->transport
= chunk
->transport
;
805 /* Helper to create ABORT with a SCTP_ERROR_USER_ABORT error. */
806 struct sctp_chunk
*sctp_make_abort_user(const struct sctp_association
*asoc
,
807 const struct msghdr
*msg
,
810 struct sctp_chunk
*retval
;
811 void *payload
= NULL
;
814 retval
= sctp_make_abort(asoc
, NULL
, sizeof(sctp_errhdr_t
) + paylen
);
819 /* Put the msg_iov together into payload. */
820 payload
= kmalloc(paylen
, GFP_KERNEL
);
824 err
= memcpy_fromiovec(payload
, msg
->msg_iov
, paylen
);
829 sctp_init_cause(retval
, SCTP_ERROR_USER_ABORT
, payload
, paylen
);
839 sctp_chunk_free(retval
);
845 /* Make an ABORT chunk with a PROTOCOL VIOLATION cause code. */
846 struct sctp_chunk
*sctp_make_abort_violation(
847 const struct sctp_association
*asoc
,
848 const struct sctp_chunk
*chunk
,
852 struct sctp_chunk
*retval
;
853 struct sctp_paramhdr phdr
;
855 retval
= sctp_make_abort(asoc
, chunk
, sizeof(sctp_errhdr_t
) + paylen
856 + sizeof(sctp_chunkhdr_t
));
860 sctp_init_cause(retval
, SCTP_ERROR_PROTO_VIOLATION
, payload
, paylen
);
862 phdr
.type
= htons(chunk
->chunk_hdr
->type
);
863 phdr
.length
= chunk
->chunk_hdr
->length
;
864 sctp_addto_chunk(retval
, sizeof(sctp_paramhdr_t
), &phdr
);
870 /* Make a HEARTBEAT chunk. */
871 struct sctp_chunk
*sctp_make_heartbeat(const struct sctp_association
*asoc
,
872 const struct sctp_transport
*transport
,
873 const void *payload
, const size_t paylen
)
875 struct sctp_chunk
*retval
= sctp_make_chunk(asoc
, SCTP_CID_HEARTBEAT
,
881 /* Cast away the 'const', as this is just telling the chunk
882 * what transport it belongs to.
884 retval
->transport
= (struct sctp_transport
*) transport
;
885 retval
->subh
.hbs_hdr
= sctp_addto_chunk(retval
, paylen
, payload
);
891 struct sctp_chunk
*sctp_make_heartbeat_ack(const struct sctp_association
*asoc
,
892 const struct sctp_chunk
*chunk
,
893 const void *payload
, const size_t paylen
)
895 struct sctp_chunk
*retval
;
897 retval
= sctp_make_chunk(asoc
, SCTP_CID_HEARTBEAT_ACK
, 0, paylen
);
901 retval
->subh
.hbs_hdr
= sctp_addto_chunk(retval
, paylen
, payload
);
903 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
905 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
906 * HEARTBEAT ACK, * etc.) to the same destination transport
907 * address from which it * received the DATA or control chunk
908 * to which it is replying.
910 * [HBACK back to where the HEARTBEAT came from.]
913 retval
->transport
= chunk
->transport
;
919 /* Create an Operation Error chunk with the specified space reserved.
920 * This routine can be used for containing multiple causes in the chunk.
922 static struct sctp_chunk
*sctp_make_op_error_space(
923 const struct sctp_association
*asoc
,
924 const struct sctp_chunk
*chunk
,
927 struct sctp_chunk
*retval
;
929 retval
= sctp_make_chunk(asoc
, SCTP_CID_ERROR
, 0,
930 sizeof(sctp_errhdr_t
) + size
);
934 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
936 * An endpoint SHOULD transmit reply chunks (e.g., SACK,
937 * HEARTBEAT ACK, etc.) to the same destination transport
938 * address from which it received the DATA or control chunk
939 * to which it is replying.
943 retval
->transport
= chunk
->transport
;
949 /* Create an Operation Error chunk. */
950 struct sctp_chunk
*sctp_make_op_error(const struct sctp_association
*asoc
,
951 const struct sctp_chunk
*chunk
,
952 __be16 cause_code
, const void *payload
,
955 struct sctp_chunk
*retval
;
957 retval
= sctp_make_op_error_space(asoc
, chunk
, paylen
);
961 sctp_init_cause(retval
, cause_code
, payload
, paylen
);
967 /********************************************************************
968 * 2nd Level Abstractions
969 ********************************************************************/
971 /* Turn an skb into a chunk.
972 * FIXME: Eventually move the structure directly inside the skb->cb[].
974 struct sctp_chunk
*sctp_chunkify(struct sk_buff
*skb
,
975 const struct sctp_association
*asoc
,
978 struct sctp_chunk
*retval
;
980 retval
= kmem_cache_zalloc(sctp_chunk_cachep
, GFP_ATOMIC
);
986 SCTP_DEBUG_PRINTK("chunkifying skb %p w/o an sk\n", skb
);
989 INIT_LIST_HEAD(&retval
->list
);
991 retval
->asoc
= (struct sctp_association
*)asoc
;
995 retval
->rtt_in_progress
= 0;
997 retval
->singleton
= 1;
998 retval
->end_of_packet
= 0;
999 retval
->ecn_ce_done
= 0;
1000 retval
->pdiscard
= 0;
1002 /* sctpimpguide-05.txt Section 2.8.2
1003 * M1) Each time a new DATA chunk is transmitted
1004 * set the 'TSN.Missing.Report' count for that TSN to 0. The
1005 * 'TSN.Missing.Report' count will be used to determine missing chunks
1006 * and when to fast retransmit.
1008 retval
->tsn_missing_report
= 0;
1009 retval
->tsn_gap_acked
= 0;
1010 retval
->fast_retransmit
= 0;
1012 /* If this is a fragmented message, track all fragments
1013 * of the message (for SEND_FAILED).
1017 /* Polish the bead hole. */
1018 INIT_LIST_HEAD(&retval
->transmitted_list
);
1019 INIT_LIST_HEAD(&retval
->frag_list
);
1020 SCTP_DBG_OBJCNT_INC(chunk
);
1021 atomic_set(&retval
->refcnt
, 1);
1027 /* Set chunk->source and dest based on the IP header in chunk->skb. */
1028 void sctp_init_addrs(struct sctp_chunk
*chunk
, union sctp_addr
*src
,
1029 union sctp_addr
*dest
)
1031 memcpy(&chunk
->source
, src
, sizeof(union sctp_addr
));
1032 memcpy(&chunk
->dest
, dest
, sizeof(union sctp_addr
));
1035 /* Extract the source address from a chunk. */
1036 const union sctp_addr
*sctp_source(const struct sctp_chunk
*chunk
)
1038 /* If we have a known transport, use that. */
1039 if (chunk
->transport
) {
1040 return &chunk
->transport
->ipaddr
;
1042 /* Otherwise, extract it from the IP header. */
1043 return &chunk
->source
;
1047 /* Create a new chunk, setting the type and flags headers from the
1048 * arguments, reserving enough space for a 'paylen' byte payload.
1051 struct sctp_chunk
*sctp_make_chunk(const struct sctp_association
*asoc
,
1052 __u8 type
, __u8 flags
, int paylen
)
1054 struct sctp_chunk
*retval
;
1055 sctp_chunkhdr_t
*chunk_hdr
;
1056 struct sk_buff
*skb
;
1059 /* No need to allocate LL here, as this is only a chunk. */
1060 skb
= alloc_skb(WORD_ROUND(sizeof(sctp_chunkhdr_t
) + paylen
),
1065 /* Make room for the chunk header. */
1066 chunk_hdr
= (sctp_chunkhdr_t
*)skb_put(skb
, sizeof(sctp_chunkhdr_t
));
1067 chunk_hdr
->type
= type
;
1068 chunk_hdr
->flags
= flags
;
1069 chunk_hdr
->length
= htons(sizeof(sctp_chunkhdr_t
));
1071 sk
= asoc
? asoc
->base
.sk
: NULL
;
1072 retval
= sctp_chunkify(skb
, asoc
, sk
);
1078 retval
->chunk_hdr
= chunk_hdr
;
1079 retval
->chunk_end
= ((__u8
*)chunk_hdr
) + sizeof(struct sctp_chunkhdr
);
1081 /* Set the skb to the belonging sock for accounting. */
1090 /* Release the memory occupied by a chunk. */
1091 static void sctp_chunk_destroy(struct sctp_chunk
*chunk
)
1093 /* Free the chunk skb data and the SCTP_chunk stub itself. */
1094 dev_kfree_skb(chunk
->skb
);
1096 SCTP_DBG_OBJCNT_DEC(chunk
);
1097 kmem_cache_free(sctp_chunk_cachep
, chunk
);
1100 /* Possibly, free the chunk. */
1101 void sctp_chunk_free(struct sctp_chunk
*chunk
)
1103 BUG_ON(!list_empty(&chunk
->list
));
1104 list_del_init(&chunk
->transmitted_list
);
1106 /* Release our reference on the message tracker. */
1108 sctp_datamsg_put(chunk
->msg
);
1110 sctp_chunk_put(chunk
);
1113 /* Grab a reference to the chunk. */
1114 void sctp_chunk_hold(struct sctp_chunk
*ch
)
1116 atomic_inc(&ch
->refcnt
);
1119 /* Release a reference to the chunk. */
1120 void sctp_chunk_put(struct sctp_chunk
*ch
)
1122 if (atomic_dec_and_test(&ch
->refcnt
))
1123 sctp_chunk_destroy(ch
);
1126 /* Append bytes to the end of a chunk. Will panic if chunk is not big
1129 void *sctp_addto_chunk(struct sctp_chunk
*chunk
, int len
, const void *data
)
1133 int chunklen
= ntohs(chunk
->chunk_hdr
->length
);
1134 int padlen
= chunklen
% 4;
1136 padding
= skb_put(chunk
->skb
, padlen
);
1137 target
= skb_put(chunk
->skb
, len
);
1139 memset(padding
, 0, padlen
);
1140 memcpy(target
, data
, len
);
1142 /* Adjust the chunk length field. */
1143 chunk
->chunk_hdr
->length
= htons(chunklen
+ padlen
+ len
);
1144 chunk
->chunk_end
= skb_tail_pointer(chunk
->skb
);
1149 /* Append bytes from user space to the end of a chunk. Will panic if
1150 * chunk is not big enough.
1151 * Returns a kernel err value.
1153 int sctp_user_addto_chunk(struct sctp_chunk
*chunk
, int off
, int len
,
1159 /* Make room in chunk for data. */
1160 target
= skb_put(chunk
->skb
, len
);
1162 /* Copy data (whole iovec) into chunk */
1163 if ((err
= memcpy_fromiovecend(target
, data
, off
, len
)))
1166 /* Adjust the chunk length field. */
1167 chunk
->chunk_hdr
->length
=
1168 htons(ntohs(chunk
->chunk_hdr
->length
) + len
);
1169 chunk
->chunk_end
= skb_tail_pointer(chunk
->skb
);
1175 /* Helper function to assign a TSN if needed. This assumes that both
1176 * the data_hdr and association have already been assigned.
1178 void sctp_chunk_assign_ssn(struct sctp_chunk
*chunk
)
1186 /* This is the last possible instant to assign a SSN. */
1187 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
1190 sid
= ntohs(chunk
->subh
.data_hdr
->stream
);
1191 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_LAST_FRAG
)
1192 ssn
= sctp_ssn_next(&chunk
->asoc
->ssnmap
->out
, sid
);
1194 ssn
= sctp_ssn_peek(&chunk
->asoc
->ssnmap
->out
, sid
);
1197 chunk
->subh
.data_hdr
->ssn
= htons(ssn
);
1201 /* Helper function to assign a TSN if needed. This assumes that both
1202 * the data_hdr and association have already been assigned.
1204 void sctp_chunk_assign_tsn(struct sctp_chunk
*chunk
)
1206 if (!chunk
->has_tsn
) {
1207 /* This is the last possible instant to
1210 chunk
->subh
.data_hdr
->tsn
=
1211 htonl(sctp_association_get_next_tsn(chunk
->asoc
));
1216 /* Create a CLOSED association to use with an incoming packet. */
1217 struct sctp_association
*sctp_make_temp_asoc(const struct sctp_endpoint
*ep
,
1218 struct sctp_chunk
*chunk
,
1221 struct sctp_association
*asoc
;
1222 struct sk_buff
*skb
;
1226 /* Create the bare association. */
1227 scope
= sctp_scope(sctp_source(chunk
));
1228 asoc
= sctp_association_new(ep
, ep
->base
.sk
, scope
, gfp
);
1233 /* Create an entry for the source address of the packet. */
1234 af
= sctp_get_af_specific(ipver2af(ip_hdr(skb
)->version
));
1237 af
->from_skb(&asoc
->c
.peer_addr
, skb
, 1);
1242 sctp_association_free(asoc
);
1246 /* Build a cookie representing asoc.
1247 * This INCLUDES the param header needed to put the cookie in the INIT ACK.
1249 static sctp_cookie_param_t
*sctp_pack_cookie(const struct sctp_endpoint
*ep
,
1250 const struct sctp_association
*asoc
,
1251 const struct sctp_chunk
*init_chunk
,
1253 const __u8
*raw_addrs
, int addrs_len
)
1255 sctp_cookie_param_t
*retval
;
1256 struct sctp_signed_cookie
*cookie
;
1257 struct scatterlist sg
;
1258 int headersize
, bodysize
;
1259 unsigned int keylen
;
1262 /* Header size is static data prior to the actual cookie, including
1265 headersize
= sizeof(sctp_paramhdr_t
) +
1266 (sizeof(struct sctp_signed_cookie
) -
1267 sizeof(struct sctp_cookie
));
1268 bodysize
= sizeof(struct sctp_cookie
)
1269 + ntohs(init_chunk
->chunk_hdr
->length
) + addrs_len
;
1271 /* Pad out the cookie to a multiple to make the signature
1272 * functions simpler to write.
1274 if (bodysize
% SCTP_COOKIE_MULTIPLE
)
1275 bodysize
+= SCTP_COOKIE_MULTIPLE
1276 - (bodysize
% SCTP_COOKIE_MULTIPLE
);
1277 *cookie_len
= headersize
+ bodysize
;
1279 /* Clear this memory since we are sending this data structure
1280 * out on the network.
1282 retval
= kzalloc(*cookie_len
, GFP_ATOMIC
);
1286 cookie
= (struct sctp_signed_cookie
*) retval
->body
;
1288 /* Set up the parameter header. */
1289 retval
->p
.type
= SCTP_PARAM_STATE_COOKIE
;
1290 retval
->p
.length
= htons(*cookie_len
);
1292 /* Copy the cookie part of the association itself. */
1293 cookie
->c
= asoc
->c
;
1294 /* Save the raw address list length in the cookie. */
1295 cookie
->c
.raw_addr_list_len
= addrs_len
;
1297 /* Remember PR-SCTP capability. */
1298 cookie
->c
.prsctp_capable
= asoc
->peer
.prsctp_capable
;
1300 /* Save adaptation indication in the cookie. */
1301 cookie
->c
.adaptation_ind
= asoc
->peer
.adaptation_ind
;
1303 /* Set an expiration time for the cookie. */
1304 do_gettimeofday(&cookie
->c
.expiration
);
1305 TIMEVAL_ADD(asoc
->cookie_life
, cookie
->c
.expiration
);
1307 /* Copy the peer's init packet. */
1308 memcpy(&cookie
->c
.peer_init
[0], init_chunk
->chunk_hdr
,
1309 ntohs(init_chunk
->chunk_hdr
->length
));
1311 /* Copy the raw local address list of the association. */
1312 memcpy((__u8
*)&cookie
->c
.peer_init
[0] +
1313 ntohs(init_chunk
->chunk_hdr
->length
), raw_addrs
, addrs_len
);
1315 if (sctp_sk(ep
->base
.sk
)->hmac
) {
1316 struct hash_desc desc
;
1318 /* Sign the message. */
1319 sg
.page
= virt_to_page(&cookie
->c
);
1320 sg
.offset
= (unsigned long)(&cookie
->c
) % PAGE_SIZE
;
1321 sg
.length
= bodysize
;
1322 keylen
= SCTP_SECRET_SIZE
;
1323 key
= (char *)ep
->secret_key
[ep
->current_key
];
1324 desc
.tfm
= sctp_sk(ep
->base
.sk
)->hmac
;
1327 if (crypto_hash_setkey(desc
.tfm
, key
, keylen
) ||
1328 crypto_hash_digest(&desc
, &sg
, bodysize
, cookie
->signature
))
1341 /* Unpack the cookie from COOKIE ECHO chunk, recreating the association. */
1342 struct sctp_association
*sctp_unpack_cookie(
1343 const struct sctp_endpoint
*ep
,
1344 const struct sctp_association
*asoc
,
1345 struct sctp_chunk
*chunk
, gfp_t gfp
,
1346 int *error
, struct sctp_chunk
**errp
)
1348 struct sctp_association
*retval
= NULL
;
1349 struct sctp_signed_cookie
*cookie
;
1350 struct sctp_cookie
*bear_cookie
;
1351 int headersize
, bodysize
, fixed_size
;
1352 __u8
*digest
= ep
->digest
;
1353 struct scatterlist sg
;
1354 unsigned int keylen
, len
;
1357 struct sk_buff
*skb
= chunk
->skb
;
1359 struct hash_desc desc
;
1361 /* Header size is static data prior to the actual cookie, including
1364 headersize
= sizeof(sctp_chunkhdr_t
) +
1365 (sizeof(struct sctp_signed_cookie
) -
1366 sizeof(struct sctp_cookie
));
1367 bodysize
= ntohs(chunk
->chunk_hdr
->length
) - headersize
;
1368 fixed_size
= headersize
+ sizeof(struct sctp_cookie
);
1370 /* Verify that the chunk looks like it even has a cookie.
1371 * There must be enough room for our cookie and our peer's
1374 len
= ntohs(chunk
->chunk_hdr
->length
);
1375 if (len
< fixed_size
+ sizeof(struct sctp_chunkhdr
))
1378 /* Verify that the cookie has been padded out. */
1379 if (bodysize
% SCTP_COOKIE_MULTIPLE
)
1382 /* Process the cookie. */
1383 cookie
= chunk
->subh
.cookie_hdr
;
1384 bear_cookie
= &cookie
->c
;
1386 if (!sctp_sk(ep
->base
.sk
)->hmac
)
1389 /* Check the signature. */
1390 keylen
= SCTP_SECRET_SIZE
;
1391 sg
.page
= virt_to_page(bear_cookie
);
1392 sg
.offset
= (unsigned long)(bear_cookie
) % PAGE_SIZE
;
1393 sg
.length
= bodysize
;
1394 key
= (char *)ep
->secret_key
[ep
->current_key
];
1395 desc
.tfm
= sctp_sk(ep
->base
.sk
)->hmac
;
1398 memset(digest
, 0x00, SCTP_SIGNATURE_SIZE
);
1399 if (crypto_hash_setkey(desc
.tfm
, key
, keylen
) ||
1400 crypto_hash_digest(&desc
, &sg
, bodysize
, digest
)) {
1401 *error
= -SCTP_IERROR_NOMEM
;
1405 if (memcmp(digest
, cookie
->signature
, SCTP_SIGNATURE_SIZE
)) {
1406 /* Try the previous key. */
1407 key
= (char *)ep
->secret_key
[ep
->last_key
];
1408 memset(digest
, 0x00, SCTP_SIGNATURE_SIZE
);
1409 if (crypto_hash_setkey(desc
.tfm
, key
, keylen
) ||
1410 crypto_hash_digest(&desc
, &sg
, bodysize
, digest
)) {
1411 *error
= -SCTP_IERROR_NOMEM
;
1415 if (memcmp(digest
, cookie
->signature
, SCTP_SIGNATURE_SIZE
)) {
1416 /* Yikes! Still bad signature! */
1417 *error
= -SCTP_IERROR_BAD_SIG
;
1423 /* IG Section 2.35.2:
1424 * 3) Compare the port numbers and the verification tag contained
1425 * within the COOKIE ECHO chunk to the actual port numbers and the
1426 * verification tag within the SCTP common header of the received
1427 * packet. If these values do not match the packet MUST be silently
1430 if (ntohl(chunk
->sctp_hdr
->vtag
) != bear_cookie
->my_vtag
) {
1431 *error
= -SCTP_IERROR_BAD_TAG
;
1435 if (chunk
->sctp_hdr
->source
!= bear_cookie
->peer_addr
.v4
.sin_port
||
1436 ntohs(chunk
->sctp_hdr
->dest
) != bear_cookie
->my_port
) {
1437 *error
= -SCTP_IERROR_BAD_PORTS
;
1441 /* Check to see if the cookie is stale. If there is already
1442 * an association, there is no need to check cookie's expiration
1443 * for init collision case of lost COOKIE ACK.
1444 * If skb has been timestamped, then use the stamp, otherwise
1445 * use current time. This introduces a small possibility that
1446 * that a cookie may be considered expired, but his would only slow
1447 * down the new association establishment instead of every packet.
1449 if (sock_flag(ep
->base
.sk
, SOCK_TIMESTAMP
))
1450 skb_get_timestamp(skb
, &tv
);
1452 do_gettimeofday(&tv
);
1454 if (!asoc
&& tv_lt(bear_cookie
->expiration
, tv
)) {
1457 * Section 3.3.10.3 Stale Cookie Error (3)
1461 * Stale Cookie Error: Indicates the receipt of a valid State
1462 * Cookie that has expired.
1464 len
= ntohs(chunk
->chunk_hdr
->length
);
1465 *errp
= sctp_make_op_error_space(asoc
, chunk
, len
);
1467 suseconds_t usecs
= (tv
.tv_sec
-
1468 bear_cookie
->expiration
.tv_sec
) * 1000000L +
1469 tv
.tv_usec
- bear_cookie
->expiration
.tv_usec
;
1470 __be32 n
= htonl(usecs
);
1472 sctp_init_cause(*errp
, SCTP_ERROR_STALE_COOKIE
,
1474 *error
= -SCTP_IERROR_STALE_COOKIE
;
1476 *error
= -SCTP_IERROR_NOMEM
;
1481 /* Make a new base association. */
1482 scope
= sctp_scope(sctp_source(chunk
));
1483 retval
= sctp_association_new(ep
, ep
->base
.sk
, scope
, gfp
);
1485 *error
= -SCTP_IERROR_NOMEM
;
1489 /* Set up our peer's port number. */
1490 retval
->peer
.port
= ntohs(chunk
->sctp_hdr
->source
);
1492 /* Populate the association from the cookie. */
1493 memcpy(&retval
->c
, bear_cookie
, sizeof(*bear_cookie
));
1495 if (sctp_assoc_set_bind_addr_from_cookie(retval
, bear_cookie
,
1497 *error
= -SCTP_IERROR_NOMEM
;
1501 /* Also, add the destination address. */
1502 if (list_empty(&retval
->base
.bind_addr
.address_list
)) {
1503 sctp_add_bind_addr(&retval
->base
.bind_addr
, &chunk
->dest
, 1,
1507 retval
->next_tsn
= retval
->c
.initial_tsn
;
1508 retval
->ctsn_ack_point
= retval
->next_tsn
- 1;
1509 retval
->addip_serial
= retval
->c
.initial_tsn
;
1510 retval
->adv_peer_ack_point
= retval
->ctsn_ack_point
;
1511 retval
->peer
.prsctp_capable
= retval
->c
.prsctp_capable
;
1512 retval
->peer
.adaptation_ind
= retval
->c
.adaptation_ind
;
1514 /* The INIT stuff will be done by the side effects. */
1519 sctp_association_free(retval
);
1524 /* Yikes! The packet is either corrupt or deliberately
1527 *error
= -SCTP_IERROR_MALFORMED
;
1531 /********************************************************************
1532 * 3rd Level Abstractions
1533 ********************************************************************/
1535 struct __sctp_missing
{
1538 } __attribute__((packed
));
1541 * Report a missing mandatory parameter.
1543 static int sctp_process_missing_param(const struct sctp_association
*asoc
,
1544 sctp_param_t paramtype
,
1545 struct sctp_chunk
*chunk
,
1546 struct sctp_chunk
**errp
)
1548 struct __sctp_missing report
;
1551 len
= WORD_ROUND(sizeof(report
));
1553 /* Make an ERROR chunk, preparing enough room for
1554 * returning multiple unknown parameters.
1557 *errp
= sctp_make_op_error_space(asoc
, chunk
, len
);
1560 report
.num_missing
= htonl(1);
1561 report
.type
= paramtype
;
1562 sctp_init_cause(*errp
, SCTP_ERROR_MISS_PARAM
,
1563 &report
, sizeof(report
));
1566 /* Stop processing this chunk. */
1570 /* Report an Invalid Mandatory Parameter. */
1571 static int sctp_process_inv_mandatory(const struct sctp_association
*asoc
,
1572 struct sctp_chunk
*chunk
,
1573 struct sctp_chunk
**errp
)
1575 /* Invalid Mandatory Parameter Error has no payload. */
1578 *errp
= sctp_make_op_error_space(asoc
, chunk
, 0);
1581 sctp_init_cause(*errp
, SCTP_ERROR_INV_PARAM
, NULL
, 0);
1583 /* Stop processing this chunk. */
1587 static int sctp_process_inv_paramlength(const struct sctp_association
*asoc
,
1588 struct sctp_paramhdr
*param
,
1589 const struct sctp_chunk
*chunk
,
1590 struct sctp_chunk
**errp
)
1592 char error
[] = "The following parameter had invalid length:";
1593 size_t payload_len
= WORD_ROUND(sizeof(error
)) +
1594 sizeof(sctp_paramhdr_t
);
1597 /* Create an error chunk and fill it in with our payload. */
1599 *errp
= sctp_make_op_error_space(asoc
, chunk
, payload_len
);
1602 sctp_init_cause(*errp
, SCTP_ERROR_PROTO_VIOLATION
, error
,
1604 sctp_addto_chunk(*errp
, sizeof(sctp_paramhdr_t
), param
);
1611 /* Do not attempt to handle the HOST_NAME parm. However, do
1612 * send back an indicator to the peer.
1614 static int sctp_process_hn_param(const struct sctp_association
*asoc
,
1615 union sctp_params param
,
1616 struct sctp_chunk
*chunk
,
1617 struct sctp_chunk
**errp
)
1619 __u16 len
= ntohs(param
.p
->length
);
1621 /* Make an ERROR chunk. */
1623 *errp
= sctp_make_op_error_space(asoc
, chunk
, len
);
1626 sctp_init_cause(*errp
, SCTP_ERROR_DNS_FAILED
,
1629 /* Stop processing this chunk. */
1633 /* RFC 3.2.1 & the Implementers Guide 2.2.
1635 * The Parameter Types are encoded such that the
1636 * highest-order two bits specify the action that must be
1637 * taken if the processing endpoint does not recognize the
1640 * 00 - Stop processing this SCTP chunk and discard it,
1641 * do not process any further chunks within it.
1643 * 01 - Stop processing this SCTP chunk and discard it,
1644 * do not process any further chunks within it, and report
1645 * the unrecognized parameter in an 'Unrecognized
1646 * Parameter Type' (in either an ERROR or in the INIT ACK).
1648 * 10 - Skip this parameter and continue processing.
1650 * 11 - Skip this parameter and continue processing but
1651 * report the unrecognized parameter in an
1652 * 'Unrecognized Parameter Type' (in either an ERROR or in
1656 * 0 - discard the chunk
1657 * 1 - continue with the chunk
1659 static int sctp_process_unk_param(const struct sctp_association
*asoc
,
1660 union sctp_params param
,
1661 struct sctp_chunk
*chunk
,
1662 struct sctp_chunk
**errp
)
1666 switch (param
.p
->type
& SCTP_PARAM_ACTION_MASK
) {
1667 case SCTP_PARAM_ACTION_DISCARD
:
1670 case SCTP_PARAM_ACTION_DISCARD_ERR
:
1672 /* Make an ERROR chunk, preparing enough room for
1673 * returning multiple unknown parameters.
1676 *errp
= sctp_make_op_error_space(asoc
, chunk
,
1677 ntohs(chunk
->chunk_hdr
->length
));
1680 sctp_init_cause(*errp
, SCTP_ERROR_UNKNOWN_PARAM
,
1682 WORD_ROUND(ntohs(param
.p
->length
)));
1685 case SCTP_PARAM_ACTION_SKIP
:
1687 case SCTP_PARAM_ACTION_SKIP_ERR
:
1688 /* Make an ERROR chunk, preparing enough room for
1689 * returning multiple unknown parameters.
1692 *errp
= sctp_make_op_error_space(asoc
, chunk
,
1693 ntohs(chunk
->chunk_hdr
->length
));
1696 sctp_init_cause(*errp
, SCTP_ERROR_UNKNOWN_PARAM
,
1698 WORD_ROUND(ntohs(param
.p
->length
)));
1700 /* If there is no memory for generating the ERROR
1701 * report as specified, an ABORT will be triggered
1702 * to the peer and the association won't be
1716 /* Find unrecognized parameters in the chunk.
1718 * 0 - discard the chunk
1719 * 1 - continue with the chunk
1721 static int sctp_verify_param(const struct sctp_association
*asoc
,
1722 union sctp_params param
,
1724 struct sctp_chunk
*chunk
,
1725 struct sctp_chunk
**err_chunk
)
1729 /* FIXME - This routine is not looking at each parameter per the
1730 * chunk type, i.e., unrecognized parameters should be further
1731 * identified based on the chunk id.
1734 switch (param
.p
->type
) {
1735 case SCTP_PARAM_IPV4_ADDRESS
:
1736 case SCTP_PARAM_IPV6_ADDRESS
:
1737 case SCTP_PARAM_COOKIE_PRESERVATIVE
:
1738 case SCTP_PARAM_SUPPORTED_ADDRESS_TYPES
:
1739 case SCTP_PARAM_STATE_COOKIE
:
1740 case SCTP_PARAM_HEARTBEAT_INFO
:
1741 case SCTP_PARAM_UNRECOGNIZED_PARAMETERS
:
1742 case SCTP_PARAM_ECN_CAPABLE
:
1743 case SCTP_PARAM_ADAPTATION_LAYER_IND
:
1746 case SCTP_PARAM_HOST_NAME_ADDRESS
:
1747 /* Tell the peer, we won't support this param. */
1748 return sctp_process_hn_param(asoc
, param
, chunk
, err_chunk
);
1749 case SCTP_PARAM_FWD_TSN_SUPPORT
:
1750 if (sctp_prsctp_enable
)
1754 SCTP_DEBUG_PRINTK("Unrecognized param: %d for chunk %d.\n",
1755 ntohs(param
.p
->type
), cid
);
1756 return sctp_process_unk_param(asoc
, param
, chunk
, err_chunk
);
1763 /* Verify the INIT packet before we process it. */
1764 int sctp_verify_init(const struct sctp_association
*asoc
,
1766 sctp_init_chunk_t
*peer_init
,
1767 struct sctp_chunk
*chunk
,
1768 struct sctp_chunk
**errp
)
1770 union sctp_params param
;
1773 /* Verify stream values are non-zero. */
1774 if ((0 == peer_init
->init_hdr
.num_outbound_streams
) ||
1775 (0 == peer_init
->init_hdr
.num_inbound_streams
) ||
1776 (0 == peer_init
->init_hdr
.init_tag
) ||
1777 (SCTP_DEFAULT_MINWINDOW
> ntohl(peer_init
->init_hdr
.a_rwnd
))) {
1779 sctp_process_inv_mandatory(asoc
, chunk
, errp
);
1783 /* Check for missing mandatory parameters. */
1784 sctp_walk_params(param
, peer_init
, init_hdr
.params
) {
1786 if (SCTP_PARAM_STATE_COOKIE
== param
.p
->type
)
1789 } /* for (loop through all parameters) */
1791 /* There is a possibility that a parameter length was bad and
1792 * in that case we would have stoped walking the parameters.
1793 * The current param.p would point at the bad one.
1794 * Current consensus on the mailing list is to generate a PROTOCOL
1795 * VIOLATION error. We build the ERROR chunk here and let the normal
1796 * error handling code build and send the packet.
1798 if (param
.v
< (void*)chunk
->chunk_end
- sizeof(sctp_paramhdr_t
)) {
1799 sctp_process_inv_paramlength(asoc
, param
.p
, chunk
, errp
);
1803 /* The only missing mandatory param possible today is
1804 * the state cookie for an INIT-ACK chunk.
1806 if ((SCTP_CID_INIT_ACK
== cid
) && !has_cookie
) {
1807 sctp_process_missing_param(asoc
, SCTP_PARAM_STATE_COOKIE
,
1812 /* Find unrecognized parameters. */
1814 sctp_walk_params(param
, peer_init
, init_hdr
.params
) {
1816 if (!sctp_verify_param(asoc
, param
, cid
, chunk
, errp
)) {
1817 if (SCTP_PARAM_HOST_NAME_ADDRESS
== param
.p
->type
)
1823 } /* for (loop through all parameters) */
1828 /* Unpack the parameters in an INIT packet into an association.
1829 * Returns 0 on failure, else success.
1830 * FIXME: This is an association method.
1832 int sctp_process_init(struct sctp_association
*asoc
, sctp_cid_t cid
,
1833 const union sctp_addr
*peer_addr
,
1834 sctp_init_chunk_t
*peer_init
, gfp_t gfp
)
1836 union sctp_params param
;
1837 struct sctp_transport
*transport
;
1838 struct list_head
*pos
, *temp
;
1841 /* We must include the address that the INIT packet came from.
1842 * This is the only address that matters for an INIT packet.
1843 * When processing a COOKIE ECHO, we retrieve the from address
1844 * of the INIT from the cookie.
1847 /* This implementation defaults to making the first transport
1848 * added as the primary transport. The source address seems to
1849 * be a a better choice than any of the embedded addresses.
1852 if(!sctp_assoc_add_peer(asoc
, peer_addr
, gfp
, SCTP_ACTIVE
))
1856 /* Process the initialization parameters. */
1858 sctp_walk_params(param
, peer_init
, init_hdr
.params
) {
1860 if (!sctp_process_param(asoc
, param
, peer_addr
, gfp
))
1864 /* Walk list of transports, removing transports in the UNKNOWN state. */
1865 list_for_each_safe(pos
, temp
, &asoc
->peer
.transport_addr_list
) {
1866 transport
= list_entry(pos
, struct sctp_transport
, transports
);
1867 if (transport
->state
== SCTP_UNKNOWN
) {
1868 sctp_assoc_rm_peer(asoc
, transport
);
1872 /* The fixed INIT headers are always in network byte
1875 asoc
->peer
.i
.init_tag
=
1876 ntohl(peer_init
->init_hdr
.init_tag
);
1877 asoc
->peer
.i
.a_rwnd
=
1878 ntohl(peer_init
->init_hdr
.a_rwnd
);
1879 asoc
->peer
.i
.num_outbound_streams
=
1880 ntohs(peer_init
->init_hdr
.num_outbound_streams
);
1881 asoc
->peer
.i
.num_inbound_streams
=
1882 ntohs(peer_init
->init_hdr
.num_inbound_streams
);
1883 asoc
->peer
.i
.initial_tsn
=
1884 ntohl(peer_init
->init_hdr
.initial_tsn
);
1886 /* Apply the upper bounds for output streams based on peer's
1887 * number of inbound streams.
1889 if (asoc
->c
.sinit_num_ostreams
>
1890 ntohs(peer_init
->init_hdr
.num_inbound_streams
)) {
1891 asoc
->c
.sinit_num_ostreams
=
1892 ntohs(peer_init
->init_hdr
.num_inbound_streams
);
1895 if (asoc
->c
.sinit_max_instreams
>
1896 ntohs(peer_init
->init_hdr
.num_outbound_streams
)) {
1897 asoc
->c
.sinit_max_instreams
=
1898 ntohs(peer_init
->init_hdr
.num_outbound_streams
);
1901 /* Copy Initiation tag from INIT to VT_peer in cookie. */
1902 asoc
->c
.peer_vtag
= asoc
->peer
.i
.init_tag
;
1904 /* Peer Rwnd : Current calculated value of the peer's rwnd. */
1905 asoc
->peer
.rwnd
= asoc
->peer
.i
.a_rwnd
;
1907 /* Copy cookie in case we need to resend COOKIE-ECHO. */
1908 cookie
= asoc
->peer
.cookie
;
1910 asoc
->peer
.cookie
= kmemdup(cookie
, asoc
->peer
.cookie_len
, gfp
);
1911 if (!asoc
->peer
.cookie
)
1915 /* RFC 2960 7.2.1 The initial value of ssthresh MAY be arbitrarily
1916 * high (for example, implementations MAY use the size of the receiver
1917 * advertised window).
1919 list_for_each(pos
, &asoc
->peer
.transport_addr_list
) {
1920 transport
= list_entry(pos
, struct sctp_transport
, transports
);
1921 transport
->ssthresh
= asoc
->peer
.i
.a_rwnd
;
1924 /* Set up the TSN tracking pieces. */
1925 sctp_tsnmap_init(&asoc
->peer
.tsn_map
, SCTP_TSN_MAP_SIZE
,
1926 asoc
->peer
.i
.initial_tsn
);
1928 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
1930 * The stream sequence number in all the streams shall start
1931 * from 0 when the association is established. Also, when the
1932 * stream sequence number reaches the value 65535 the next
1933 * stream sequence number shall be set to 0.
1936 /* Allocate storage for the negotiated streams if it is not a temporary
1942 asoc
->ssnmap
= sctp_ssnmap_new(asoc
->c
.sinit_max_instreams
,
1943 asoc
->c
.sinit_num_ostreams
, gfp
);
1947 error
= sctp_assoc_set_id(asoc
, gfp
);
1952 /* ADDIP Section 4.1 ASCONF Chunk Procedures
1954 * When an endpoint has an ASCONF signaled change to be sent to the
1955 * remote endpoint it should do the following:
1957 * A2) A serial number should be assigned to the Chunk. The serial
1958 * number should be a monotonically increasing number. All serial
1959 * numbers are defined to be initialized at the start of the
1960 * association to the same value as the Initial TSN.
1962 asoc
->peer
.addip_serial
= asoc
->peer
.i
.initial_tsn
- 1;
1966 /* Release the transport structures. */
1967 list_for_each_safe(pos
, temp
, &asoc
->peer
.transport_addr_list
) {
1968 transport
= list_entry(pos
, struct sctp_transport
, transports
);
1970 sctp_transport_free(transport
);
1973 asoc
->peer
.transport_count
= 0;
1980 /* Update asoc with the option described in param.
1982 * RFC2960 3.3.2.1 Optional/Variable Length Parameters in INIT
1984 * asoc is the association to update.
1985 * param is the variable length parameter to use for update.
1986 * cid tells us if this is an INIT, INIT ACK or COOKIE ECHO.
1987 * If the current packet is an INIT we want to minimize the amount of
1988 * work we do. In particular, we should not build transport
1989 * structures for the addresses.
1991 static int sctp_process_param(struct sctp_association
*asoc
,
1992 union sctp_params param
,
1993 const union sctp_addr
*peer_addr
,
1996 union sctp_addr addr
;
2004 /* We maintain all INIT parameters in network byte order all the
2005 * time. This allows us to not worry about whether the parameters
2006 * came from a fresh INIT, and INIT ACK, or were stored in a cookie.
2008 switch (param
.p
->type
) {
2009 case SCTP_PARAM_IPV6_ADDRESS
:
2010 if (PF_INET6
!= asoc
->base
.sk
->sk_family
)
2013 case SCTP_PARAM_IPV4_ADDRESS
:
2014 af
= sctp_get_af_specific(param_type2af(param
.p
->type
));
2015 af
->from_addr_param(&addr
, param
.addr
, htons(asoc
->peer
.port
), 0);
2016 scope
= sctp_scope(peer_addr
);
2017 if (sctp_in_scope(&addr
, scope
))
2018 if (!sctp_assoc_add_peer(asoc
, &addr
, gfp
, SCTP_UNCONFIRMED
))
2022 case SCTP_PARAM_COOKIE_PRESERVATIVE
:
2023 if (!sctp_cookie_preserve_enable
)
2026 stale
= ntohl(param
.life
->lifespan_increment
);
2028 /* Suggested Cookie Life span increment's unit is msec,
2031 asoc
->cookie_life
.tv_sec
+= stale
/ 1000;
2032 asoc
->cookie_life
.tv_usec
+= (stale
% 1000) * 1000;
2035 case SCTP_PARAM_HOST_NAME_ADDRESS
:
2036 SCTP_DEBUG_PRINTK("unimplemented SCTP_HOST_NAME_ADDRESS\n");
2039 case SCTP_PARAM_SUPPORTED_ADDRESS_TYPES
:
2040 /* Turn off the default values first so we'll know which
2041 * ones are really set by the peer.
2043 asoc
->peer
.ipv4_address
= 0;
2044 asoc
->peer
.ipv6_address
= 0;
2046 /* Cycle through address types; avoid divide by 0. */
2047 sat
= ntohs(param
.p
->length
) - sizeof(sctp_paramhdr_t
);
2049 sat
/= sizeof(__u16
);
2051 for (i
= 0; i
< sat
; ++i
) {
2052 switch (param
.sat
->types
[i
]) {
2053 case SCTP_PARAM_IPV4_ADDRESS
:
2054 asoc
->peer
.ipv4_address
= 1;
2057 case SCTP_PARAM_IPV6_ADDRESS
:
2058 asoc
->peer
.ipv6_address
= 1;
2061 case SCTP_PARAM_HOST_NAME_ADDRESS
:
2062 asoc
->peer
.hostname_address
= 1;
2065 default: /* Just ignore anything else. */
2071 case SCTP_PARAM_STATE_COOKIE
:
2072 asoc
->peer
.cookie_len
=
2073 ntohs(param
.p
->length
) - sizeof(sctp_paramhdr_t
);
2074 asoc
->peer
.cookie
= param
.cookie
->body
;
2077 case SCTP_PARAM_HEARTBEAT_INFO
:
2078 /* Would be odd to receive, but it causes no problems. */
2081 case SCTP_PARAM_UNRECOGNIZED_PARAMETERS
:
2082 /* Rejected during verify stage. */
2085 case SCTP_PARAM_ECN_CAPABLE
:
2086 asoc
->peer
.ecn_capable
= 1;
2089 case SCTP_PARAM_ADAPTATION_LAYER_IND
:
2090 asoc
->peer
.adaptation_ind
= param
.aind
->adaptation_ind
;
2093 case SCTP_PARAM_FWD_TSN_SUPPORT
:
2094 if (sctp_prsctp_enable
) {
2095 asoc
->peer
.prsctp_capable
= 1;
2100 /* Any unrecognized parameters should have been caught
2101 * and handled by sctp_verify_param() which should be
2102 * called prior to this routine. Simply log the error
2105 SCTP_DEBUG_PRINTK("Ignoring param: %d for association %p.\n",
2106 ntohs(param
.p
->type
), asoc
);
2113 /* Select a new verification tag. */
2114 __u32
sctp_generate_tag(const struct sctp_endpoint
*ep
)
2116 /* I believe that this random number generator complies with RFC1750.
2117 * A tag of 0 is reserved for special cases (e.g. INIT).
2122 get_random_bytes(&x
, sizeof(__u32
));
2128 /* Select an initial TSN to send during startup. */
2129 __u32
sctp_generate_tsn(const struct sctp_endpoint
*ep
)
2133 get_random_bytes(&retval
, sizeof(__u32
));
2138 * ADDIP 3.1.1 Address Configuration Change Chunk (ASCONF)
2140 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
2141 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2142 * | Type = 0xC1 | Chunk Flags | Chunk Length |
2143 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2145 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2146 * | Address Parameter |
2147 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2148 * | ASCONF Parameter #1 |
2149 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2153 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2154 * | ASCONF Parameter #N |
2155 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2157 * Address Parameter and other parameter will not be wrapped in this function
2159 static struct sctp_chunk
*sctp_make_asconf(struct sctp_association
*asoc
,
2160 union sctp_addr
*addr
,
2163 sctp_addiphdr_t asconf
;
2164 struct sctp_chunk
*retval
;
2165 int length
= sizeof(asconf
) + vparam_len
;
2166 union sctp_addr_param addrparam
;
2168 struct sctp_af
*af
= sctp_get_af_specific(addr
->v4
.sin_family
);
2170 addrlen
= af
->to_addr_param(addr
, &addrparam
);
2175 /* Create the chunk. */
2176 retval
= sctp_make_chunk(asoc
, SCTP_CID_ASCONF
, 0, length
);
2180 asconf
.serial
= htonl(asoc
->addip_serial
++);
2182 retval
->subh
.addip_hdr
=
2183 sctp_addto_chunk(retval
, sizeof(asconf
), &asconf
);
2184 retval
->param_hdr
.v
=
2185 sctp_addto_chunk(retval
, addrlen
, &addrparam
);
2191 * 3.2.1 Add IP Address
2193 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
2194 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2195 * | Type = 0xC001 | Length = Variable |
2196 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2197 * | ASCONF-Request Correlation ID |
2198 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2199 * | Address Parameter |
2200 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2202 * 3.2.2 Delete IP Address
2204 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
2205 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2206 * | Type = 0xC002 | Length = Variable |
2207 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2208 * | ASCONF-Request Correlation ID |
2209 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2210 * | Address Parameter |
2211 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2214 struct sctp_chunk
*sctp_make_asconf_update_ip(struct sctp_association
*asoc
,
2215 union sctp_addr
*laddr
,
2216 struct sockaddr
*addrs
,
2220 sctp_addip_param_t param
;
2221 struct sctp_chunk
*retval
;
2222 union sctp_addr_param addr_param
;
2223 union sctp_addr
*addr
;
2226 int paramlen
= sizeof(param
);
2227 int addr_param_len
= 0;
2231 /* Get total length of all the address parameters. */
2233 for (i
= 0; i
< addrcnt
; i
++) {
2234 addr
= (union sctp_addr
*)addr_buf
;
2235 af
= sctp_get_af_specific(addr
->v4
.sin_family
);
2236 addr_param_len
= af
->to_addr_param(addr
, &addr_param
);
2238 totallen
+= paramlen
;
2239 totallen
+= addr_param_len
;
2241 addr_buf
+= af
->sockaddr_len
;
2244 /* Create an asconf chunk with the required length. */
2245 retval
= sctp_make_asconf(asoc
, laddr
, totallen
);
2249 /* Add the address parameters to the asconf chunk. */
2251 for (i
= 0; i
< addrcnt
; i
++) {
2252 addr
= (union sctp_addr
*)addr_buf
;
2253 af
= sctp_get_af_specific(addr
->v4
.sin_family
);
2254 addr_param_len
= af
->to_addr_param(addr
, &addr_param
);
2255 param
.param_hdr
.type
= flags
;
2256 param
.param_hdr
.length
= htons(paramlen
+ addr_param_len
);
2259 sctp_addto_chunk(retval
, paramlen
, ¶m
);
2260 sctp_addto_chunk(retval
, addr_param_len
, &addr_param
);
2262 addr_buf
+= af
->sockaddr_len
;
2268 * 3.2.4 Set Primary IP Address
2270 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
2271 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2272 * | Type =0xC004 | Length = Variable |
2273 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2274 * | ASCONF-Request Correlation ID |
2275 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2276 * | Address Parameter |
2277 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2279 * Create an ASCONF chunk with Set Primary IP address parameter.
2281 struct sctp_chunk
*sctp_make_asconf_set_prim(struct sctp_association
*asoc
,
2282 union sctp_addr
*addr
)
2284 sctp_addip_param_t param
;
2285 struct sctp_chunk
*retval
;
2286 int len
= sizeof(param
);
2287 union sctp_addr_param addrparam
;
2289 struct sctp_af
*af
= sctp_get_af_specific(addr
->v4
.sin_family
);
2291 addrlen
= af
->to_addr_param(addr
, &addrparam
);
2296 /* Create the chunk and make asconf header. */
2297 retval
= sctp_make_asconf(asoc
, addr
, len
);
2301 param
.param_hdr
.type
= SCTP_PARAM_SET_PRIMARY
;
2302 param
.param_hdr
.length
= htons(len
);
2305 sctp_addto_chunk(retval
, sizeof(param
), ¶m
);
2306 sctp_addto_chunk(retval
, addrlen
, &addrparam
);
2311 /* ADDIP 3.1.2 Address Configuration Acknowledgement Chunk (ASCONF-ACK)
2313 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
2314 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2315 * | Type = 0x80 | Chunk Flags | Chunk Length |
2316 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2318 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2319 * | ASCONF Parameter Response#1 |
2320 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2324 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2325 * | ASCONF Parameter Response#N |
2326 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2328 * Create an ASCONF_ACK chunk with enough space for the parameter responses.
2330 static struct sctp_chunk
*sctp_make_asconf_ack(const struct sctp_association
*asoc
,
2331 __u32 serial
, int vparam_len
)
2333 sctp_addiphdr_t asconf
;
2334 struct sctp_chunk
*retval
;
2335 int length
= sizeof(asconf
) + vparam_len
;
2337 /* Create the chunk. */
2338 retval
= sctp_make_chunk(asoc
, SCTP_CID_ASCONF_ACK
, 0, length
);
2342 asconf
.serial
= htonl(serial
);
2344 retval
->subh
.addip_hdr
=
2345 sctp_addto_chunk(retval
, sizeof(asconf
), &asconf
);
2350 /* Add response parameters to an ASCONF_ACK chunk. */
2351 static void sctp_add_asconf_response(struct sctp_chunk
*chunk
, __be32 crr_id
,
2352 __be16 err_code
, sctp_addip_param_t
*asconf_param
)
2354 sctp_addip_param_t ack_param
;
2355 sctp_errhdr_t err_param
;
2356 int asconf_param_len
= 0;
2357 int err_param_len
= 0;
2358 __be16 response_type
;
2360 if (SCTP_ERROR_NO_ERROR
== err_code
) {
2361 response_type
= SCTP_PARAM_SUCCESS_REPORT
;
2363 response_type
= SCTP_PARAM_ERR_CAUSE
;
2364 err_param_len
= sizeof(err_param
);
2367 ntohs(asconf_param
->param_hdr
.length
);
2370 /* Add Success Indication or Error Cause Indication parameter. */
2371 ack_param
.param_hdr
.type
= response_type
;
2372 ack_param
.param_hdr
.length
= htons(sizeof(ack_param
) +
2375 ack_param
.crr_id
= crr_id
;
2376 sctp_addto_chunk(chunk
, sizeof(ack_param
), &ack_param
);
2378 if (SCTP_ERROR_NO_ERROR
== err_code
)
2381 /* Add Error Cause parameter. */
2382 err_param
.cause
= err_code
;
2383 err_param
.length
= htons(err_param_len
+ asconf_param_len
);
2384 sctp_addto_chunk(chunk
, err_param_len
, &err_param
);
2386 /* Add the failed TLV copied from ASCONF chunk. */
2388 sctp_addto_chunk(chunk
, asconf_param_len
, asconf_param
);
2391 /* Process a asconf parameter. */
2392 static __be16
sctp_process_asconf_param(struct sctp_association
*asoc
,
2393 struct sctp_chunk
*asconf
,
2394 sctp_addip_param_t
*asconf_param
)
2396 struct sctp_transport
*peer
;
2398 union sctp_addr addr
;
2399 struct list_head
*pos
;
2400 union sctp_addr_param
*addr_param
;
2402 addr_param
= (union sctp_addr_param
*)
2403 ((void *)asconf_param
+ sizeof(sctp_addip_param_t
));
2405 af
= sctp_get_af_specific(param_type2af(addr_param
->v4
.param_hdr
.type
));
2407 return SCTP_ERROR_INV_PARAM
;
2409 af
->from_addr_param(&addr
, addr_param
, htons(asoc
->peer
.port
), 0);
2410 switch (asconf_param
->param_hdr
.type
) {
2411 case SCTP_PARAM_ADD_IP
:
2412 /* ADDIP 4.3 D9) If an endpoint receives an ADD IP address
2413 * request and does not have the local resources to add this
2414 * new address to the association, it MUST return an Error
2415 * Cause TLV set to the new error code 'Operation Refused
2416 * Due to Resource Shortage'.
2419 peer
= sctp_assoc_add_peer(asoc
, &addr
, GFP_ATOMIC
, SCTP_UNCONFIRMED
);
2421 return SCTP_ERROR_RSRC_LOW
;
2423 /* Start the heartbeat timer. */
2424 if (!mod_timer(&peer
->hb_timer
, sctp_transport_timeout(peer
)))
2425 sctp_transport_hold(peer
);
2427 case SCTP_PARAM_DEL_IP
:
2428 /* ADDIP 4.3 D7) If a request is received to delete the
2429 * last remaining IP address of a peer endpoint, the receiver
2430 * MUST send an Error Cause TLV with the error cause set to the
2431 * new error code 'Request to Delete Last Remaining IP Address'.
2433 pos
= asoc
->peer
.transport_addr_list
.next
;
2434 if (pos
->next
== &asoc
->peer
.transport_addr_list
)
2435 return SCTP_ERROR_DEL_LAST_IP
;
2437 /* ADDIP 4.3 D8) If a request is received to delete an IP
2438 * address which is also the source address of the IP packet
2439 * which contained the ASCONF chunk, the receiver MUST reject
2440 * this request. To reject the request the receiver MUST send
2441 * an Error Cause TLV set to the new error code 'Request to
2442 * Delete Source IP Address'
2444 if (sctp_cmp_addr_exact(sctp_source(asconf
), &addr
))
2445 return SCTP_ERROR_DEL_SRC_IP
;
2447 sctp_assoc_del_peer(asoc
, &addr
);
2449 case SCTP_PARAM_SET_PRIMARY
:
2450 peer
= sctp_assoc_lookup_paddr(asoc
, &addr
);
2452 return SCTP_ERROR_INV_PARAM
;
2454 sctp_assoc_set_primary(asoc
, peer
);
2457 return SCTP_ERROR_INV_PARAM
;
2461 return SCTP_ERROR_NO_ERROR
;
2464 /* Process an incoming ASCONF chunk with the next expected serial no. and
2465 * return an ASCONF_ACK chunk to be sent in response.
2467 struct sctp_chunk
*sctp_process_asconf(struct sctp_association
*asoc
,
2468 struct sctp_chunk
*asconf
)
2470 sctp_addiphdr_t
*hdr
;
2471 union sctp_addr_param
*addr_param
;
2472 sctp_addip_param_t
*asconf_param
;
2473 struct sctp_chunk
*asconf_ack
;
2477 int chunk_len
= asconf
->skb
->len
;
2479 int all_param_pass
= 1;
2481 hdr
= (sctp_addiphdr_t
*)asconf
->skb
->data
;
2482 serial
= ntohl(hdr
->serial
);
2484 /* Skip the addiphdr and store a pointer to address parameter. */
2485 length
= sizeof(sctp_addiphdr_t
);
2486 addr_param
= (union sctp_addr_param
*)(asconf
->skb
->data
+ length
);
2487 chunk_len
-= length
;
2489 /* Skip the address parameter and store a pointer to the first
2492 length
= ntohs(addr_param
->v4
.param_hdr
.length
);
2493 asconf_param
= (sctp_addip_param_t
*)((void *)addr_param
+ length
);
2494 chunk_len
-= length
;
2496 /* create an ASCONF_ACK chunk.
2497 * Based on the definitions of parameters, we know that the size of
2498 * ASCONF_ACK parameters are less than or equal to the twice of ASCONF
2501 asconf_ack
= sctp_make_asconf_ack(asoc
, serial
, chunk_len
* 2);
2505 /* Process the TLVs contained within the ASCONF chunk. */
2506 while (chunk_len
> 0) {
2507 err_code
= sctp_process_asconf_param(asoc
, asconf
,
2510 * If an error response is received for a TLV parameter,
2511 * all TLVs with no response before the failed TLV are
2512 * considered successful if not reported. All TLVs after
2513 * the failed response are considered unsuccessful unless
2514 * a specific success indication is present for the parameter.
2516 if (SCTP_ERROR_NO_ERROR
!= err_code
)
2519 if (!all_param_pass
)
2520 sctp_add_asconf_response(asconf_ack
,
2521 asconf_param
->crr_id
, err_code
,
2524 /* ADDIP 4.3 D11) When an endpoint receiving an ASCONF to add
2525 * an IP address sends an 'Out of Resource' in its response, it
2526 * MUST also fail any subsequent add or delete requests bundled
2529 if (SCTP_ERROR_RSRC_LOW
== err_code
)
2532 /* Move to the next ASCONF param. */
2533 length
= ntohs(asconf_param
->param_hdr
.length
);
2534 asconf_param
= (sctp_addip_param_t
*)((void *)asconf_param
+
2536 chunk_len
-= length
;
2540 asoc
->peer
.addip_serial
++;
2542 /* If we are sending a new ASCONF_ACK hold a reference to it in assoc
2543 * after freeing the reference to old asconf ack if any.
2546 if (asoc
->addip_last_asconf_ack
)
2547 sctp_chunk_free(asoc
->addip_last_asconf_ack
);
2549 sctp_chunk_hold(asconf_ack
);
2550 asoc
->addip_last_asconf_ack
= asconf_ack
;
2556 /* Process a asconf parameter that is successfully acked. */
2557 static int sctp_asconf_param_success(struct sctp_association
*asoc
,
2558 sctp_addip_param_t
*asconf_param
)
2561 union sctp_addr addr
;
2562 struct sctp_bind_addr
*bp
= &asoc
->base
.bind_addr
;
2563 union sctp_addr_param
*addr_param
;
2564 struct list_head
*pos
;
2565 struct sctp_transport
*transport
;
2566 struct sctp_sockaddr_entry
*saddr
;
2569 addr_param
= (union sctp_addr_param
*)
2570 ((void *)asconf_param
+ sizeof(sctp_addip_param_t
));
2572 /* We have checked the packet before, so we do not check again. */
2573 af
= sctp_get_af_specific(param_type2af(addr_param
->v4
.param_hdr
.type
));
2574 af
->from_addr_param(&addr
, addr_param
, htons(bp
->port
), 0);
2576 switch (asconf_param
->param_hdr
.type
) {
2577 case SCTP_PARAM_ADD_IP
:
2578 sctp_local_bh_disable();
2579 sctp_write_lock(&asoc
->base
.addr_lock
);
2580 list_for_each(pos
, &bp
->address_list
) {
2581 saddr
= list_entry(pos
, struct sctp_sockaddr_entry
, list
);
2582 if (sctp_cmp_addr_exact(&saddr
->a
, &addr
))
2583 saddr
->use_as_src
= 1;
2585 sctp_write_unlock(&asoc
->base
.addr_lock
);
2586 sctp_local_bh_enable();
2588 case SCTP_PARAM_DEL_IP
:
2589 sctp_local_bh_disable();
2590 sctp_write_lock(&asoc
->base
.addr_lock
);
2591 retval
= sctp_del_bind_addr(bp
, &addr
);
2592 sctp_write_unlock(&asoc
->base
.addr_lock
);
2593 sctp_local_bh_enable();
2594 list_for_each(pos
, &asoc
->peer
.transport_addr_list
) {
2595 transport
= list_entry(pos
, struct sctp_transport
,
2597 dst_release(transport
->dst
);
2598 sctp_transport_route(transport
, NULL
,
2599 sctp_sk(asoc
->base
.sk
));
2609 /* Get the corresponding ASCONF response error code from the ASCONF_ACK chunk
2610 * for the given asconf parameter. If there is no response for this parameter,
2611 * return the error code based on the third argument 'no_err'.
2613 * A7) If an error response is received for a TLV parameter, all TLVs with no
2614 * response before the failed TLV are considered successful if not reported.
2615 * All TLVs after the failed response are considered unsuccessful unless a
2616 * specific success indication is present for the parameter.
2618 static __be16
sctp_get_asconf_response(struct sctp_chunk
*asconf_ack
,
2619 sctp_addip_param_t
*asconf_param
,
2622 sctp_addip_param_t
*asconf_ack_param
;
2623 sctp_errhdr_t
*err_param
;
2625 int asconf_ack_len
= asconf_ack
->skb
->len
;
2629 err_code
= SCTP_ERROR_NO_ERROR
;
2631 err_code
= SCTP_ERROR_REQ_REFUSED
;
2633 /* Skip the addiphdr from the asconf_ack chunk and store a pointer to
2634 * the first asconf_ack parameter.
2636 length
= sizeof(sctp_addiphdr_t
);
2637 asconf_ack_param
= (sctp_addip_param_t
*)(asconf_ack
->skb
->data
+
2639 asconf_ack_len
-= length
;
2641 while (asconf_ack_len
> 0) {
2642 if (asconf_ack_param
->crr_id
== asconf_param
->crr_id
) {
2643 switch(asconf_ack_param
->param_hdr
.type
) {
2644 case SCTP_PARAM_SUCCESS_REPORT
:
2645 return SCTP_ERROR_NO_ERROR
;
2646 case SCTP_PARAM_ERR_CAUSE
:
2647 length
= sizeof(sctp_addip_param_t
);
2648 err_param
= (sctp_errhdr_t
*)
2649 ((void *)asconf_ack_param
+ length
);
2650 asconf_ack_len
-= length
;
2651 if (asconf_ack_len
> 0)
2652 return err_param
->cause
;
2654 return SCTP_ERROR_INV_PARAM
;
2657 return SCTP_ERROR_INV_PARAM
;
2661 length
= ntohs(asconf_ack_param
->param_hdr
.length
);
2662 asconf_ack_param
= (sctp_addip_param_t
*)
2663 ((void *)asconf_ack_param
+ length
);
2664 asconf_ack_len
-= length
;
2670 /* Process an incoming ASCONF_ACK chunk against the cached last ASCONF chunk. */
2671 int sctp_process_asconf_ack(struct sctp_association
*asoc
,
2672 struct sctp_chunk
*asconf_ack
)
2674 struct sctp_chunk
*asconf
= asoc
->addip_last_asconf
;
2675 union sctp_addr_param
*addr_param
;
2676 sctp_addip_param_t
*asconf_param
;
2678 int asconf_len
= asconf
->skb
->len
;
2679 int all_param_pass
= 0;
2682 __be16 err_code
= SCTP_ERROR_NO_ERROR
;
2684 /* Skip the chunkhdr and addiphdr from the last asconf sent and store
2685 * a pointer to address parameter.
2687 length
= sizeof(sctp_addip_chunk_t
);
2688 addr_param
= (union sctp_addr_param
*)(asconf
->skb
->data
+ length
);
2689 asconf_len
-= length
;
2691 /* Skip the address parameter in the last asconf sent and store a
2692 * pointer to the first asconf paramter.
2694 length
= ntohs(addr_param
->v4
.param_hdr
.length
);
2695 asconf_param
= (sctp_addip_param_t
*)((void *)addr_param
+ length
);
2696 asconf_len
-= length
;
2699 * A8) If there is no response(s) to specific TLV parameter(s), and no
2700 * failures are indicated, then all request(s) are considered
2703 if (asconf_ack
->skb
->len
== sizeof(sctp_addiphdr_t
))
2706 /* Process the TLVs contained in the last sent ASCONF chunk. */
2707 while (asconf_len
> 0) {
2709 err_code
= SCTP_ERROR_NO_ERROR
;
2711 err_code
= sctp_get_asconf_response(asconf_ack
,
2714 if (no_err
&& (SCTP_ERROR_NO_ERROR
!= err_code
))
2719 case SCTP_ERROR_NO_ERROR
:
2720 retval
= sctp_asconf_param_success(asoc
, asconf_param
);
2723 case SCTP_ERROR_RSRC_LOW
:
2727 case SCTP_ERROR_INV_PARAM
:
2728 /* Disable sending this type of asconf parameter in
2731 asoc
->peer
.addip_disabled_mask
|=
2732 asconf_param
->param_hdr
.type
;
2735 case SCTP_ERROR_REQ_REFUSED
:
2736 case SCTP_ERROR_DEL_LAST_IP
:
2737 case SCTP_ERROR_DEL_SRC_IP
:
2742 /* Skip the processed asconf parameter and move to the next
2745 length
= ntohs(asconf_param
->param_hdr
.length
);
2746 asconf_param
= (sctp_addip_param_t
*)((void *)asconf_param
+
2748 asconf_len
-= length
;
2751 /* Free the cached last sent asconf chunk. */
2752 sctp_chunk_free(asconf
);
2753 asoc
->addip_last_asconf
= NULL
;
2755 /* Send the next asconf chunk from the addip chunk queue. */
2756 if (!list_empty(&asoc
->addip_chunk_list
)) {
2757 struct list_head
*entry
= asoc
->addip_chunk_list
.next
;
2758 asconf
= list_entry(entry
, struct sctp_chunk
, list
);
2760 list_del_init(entry
);
2762 /* Hold the chunk until an ASCONF_ACK is received. */
2763 sctp_chunk_hold(asconf
);
2764 if (sctp_primitive_ASCONF(asoc
, asconf
))
2765 sctp_chunk_free(asconf
);
2767 asoc
->addip_last_asconf
= asconf
;
2773 /* Make a FWD TSN chunk. */
2774 struct sctp_chunk
*sctp_make_fwdtsn(const struct sctp_association
*asoc
,
2775 __u32 new_cum_tsn
, size_t nstreams
,
2776 struct sctp_fwdtsn_skip
*skiplist
)
2778 struct sctp_chunk
*retval
= NULL
;
2779 struct sctp_fwdtsn_chunk
*ftsn_chunk
;
2780 struct sctp_fwdtsn_hdr ftsn_hdr
;
2781 struct sctp_fwdtsn_skip skip
;
2785 hint
= (nstreams
+ 1) * sizeof(__u32
);
2787 retval
= sctp_make_chunk(asoc
, SCTP_CID_FWD_TSN
, 0, hint
);
2792 ftsn_chunk
= (struct sctp_fwdtsn_chunk
*)retval
->subh
.fwdtsn_hdr
;
2794 ftsn_hdr
.new_cum_tsn
= htonl(new_cum_tsn
);
2795 retval
->subh
.fwdtsn_hdr
=
2796 sctp_addto_chunk(retval
, sizeof(ftsn_hdr
), &ftsn_hdr
);
2798 for (i
= 0; i
< nstreams
; i
++) {
2799 skip
.stream
= skiplist
[i
].stream
;
2800 skip
.ssn
= skiplist
[i
].ssn
;
2801 sctp_addto_chunk(retval
, sizeof(skip
), &skip
);