1 /* SCTP kernel reference Implementation
2 * Copyright (c) 1999-2000 Cisco, Inc.
3 * Copyright (c) 1999-2001 Motorola, Inc.
4 * Copyright (c) 2001-2003 International Business Machines, Corp.
5 * Copyright (c) 2001 Intel Corp.
6 * Copyright (c) 2001 Nokia, Inc.
7 * Copyright (c) 2001 La Monte H.P. Yarroll
9 * This file is part of the SCTP kernel reference Implementation
11 * These functions handle all input from the IP layer into SCTP.
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 * Xingang Guo <xingang.guo@intel.com>
41 * Jon Grimm <jgrimm@us.ibm.com>
42 * Hui Huang <hui.huang@nokia.com>
43 * Daisy Chang <daisyc@us.ibm.com>
44 * Sridhar Samudrala <sri@us.ibm.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
47 * Any bugs reported given to us we will try to fix... any fixes shared will
48 * be incorporated into the next SCTP release.
51 #include <linux/types.h>
52 #include <linux/list.h> /* For struct list_head */
53 #include <linux/socket.h>
55 #include <linux/time.h> /* For struct timeval */
61 #include <net/sctp/sctp.h>
62 #include <net/sctp/sm.h>
64 /* Forward declarations for internal helpers. */
65 static int sctp_rcv_ootb(struct sk_buff
*);
66 static struct sctp_association
*__sctp_rcv_lookup(struct sk_buff
*skb
,
67 const union sctp_addr
*laddr
,
68 const union sctp_addr
*paddr
,
69 struct sctp_transport
**transportp
);
70 static struct sctp_endpoint
*__sctp_rcv_lookup_endpoint(const union sctp_addr
*laddr
);
71 static struct sctp_association
*__sctp_lookup_association(
72 const union sctp_addr
*local
,
73 const union sctp_addr
*peer
,
74 struct sctp_transport
**pt
);
77 /* Calculate the SCTP checksum of an SCTP packet. */
78 static inline int sctp_rcv_checksum(struct sk_buff
*skb
)
82 struct sk_buff
*list
= skb_shinfo(skb
)->frag_list
;
84 sh
= (struct sctphdr
*) skb
->h
.raw
;
85 cmp
= ntohl(sh
->checksum
);
87 val
= sctp_start_cksum((__u8
*)sh
, skb_headlen(skb
));
89 for (; list
; list
= list
->next
)
90 val
= sctp_update_cksum((__u8
*)list
->data
, skb_headlen(list
),
93 val
= sctp_end_cksum(val
);
96 /* CRC failure, dump it. */
97 SCTP_INC_STATS_BH(SCTP_MIB_CHECKSUMERRORS
);
103 /* The free routine for skbuffs that sctp receives */
104 static void sctp_rfree(struct sk_buff
*skb
)
106 atomic_sub(sizeof(struct sctp_chunk
),&skb
->sk
->sk_rmem_alloc
);
110 /* The ownership wrapper routine to do receive buffer accounting */
111 static void sctp_rcv_set_owner_r(struct sk_buff
*skb
, struct sock
*sk
)
113 skb_set_owner_r(skb
,sk
);
114 skb
->destructor
= sctp_rfree
;
115 atomic_add(sizeof(struct sctp_chunk
),&sk
->sk_rmem_alloc
);
118 struct sctp_input_cb
{
120 struct inet_skb_parm h4
;
121 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
122 struct inet6_skb_parm h6
;
125 struct sctp_chunk
*chunk
;
127 #define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0]))
130 * This is the routine which IP calls when receiving an SCTP packet.
132 int sctp_rcv(struct sk_buff
*skb
)
135 struct sctp_association
*asoc
;
136 struct sctp_endpoint
*ep
= NULL
;
137 struct sctp_ep_common
*rcvr
;
138 struct sctp_transport
*transport
= NULL
;
139 struct sctp_chunk
*chunk
;
142 union sctp_addr dest
;
147 if (skb
->pkt_type
!=PACKET_HOST
)
150 SCTP_INC_STATS_BH(SCTP_MIB_INSCTPPACKS
);
152 sh
= (struct sctphdr
*) skb
->h
.raw
;
154 /* Pull up the IP and SCTP headers. */
155 __skb_pull(skb
, skb
->h
.raw
- skb
->data
);
156 if (skb
->len
< sizeof(struct sctphdr
))
158 if (sctp_rcv_checksum(skb
) < 0)
161 skb_pull(skb
, sizeof(struct sctphdr
));
163 /* Make sure we at least have chunk headers worth of data left. */
164 if (skb
->len
< sizeof(struct sctp_chunkhdr
))
167 family
= ipver2af(skb
->nh
.iph
->version
);
168 af
= sctp_get_af_specific(family
);
172 /* Initialize local addresses for lookups. */
173 af
->from_skb(&src
, skb
, 1);
174 af
->from_skb(&dest
, skb
, 0);
176 /* If the packet is to or from a non-unicast address,
177 * silently discard the packet.
179 * This is not clearly defined in the RFC except in section
180 * 8.4 - OOTB handling. However, based on the book "Stream Control
181 * Transmission Protocol" 2.1, "It is important to note that the
182 * IP address of an SCTP transport address must be a routable
183 * unicast address. In other words, IP multicast addresses and
184 * IP broadcast addresses cannot be used in an SCTP transport
187 if (!af
->addr_valid(&src
, NULL
) || !af
->addr_valid(&dest
, NULL
))
190 asoc
= __sctp_rcv_lookup(skb
, &src
, &dest
, &transport
);
193 ep
= __sctp_rcv_lookup_endpoint(&dest
);
195 /* Retrieve the common input handling substructure. */
196 rcvr
= asoc
? &asoc
->base
: &ep
->base
;
200 * If a frame arrives on an interface and the receiving socket is
201 * bound to another interface, via SO_BINDTODEVICE, treat it as OOTB
203 if (sk
->sk_bound_dev_if
&& (sk
->sk_bound_dev_if
!= af
->skb_iif(skb
)))
207 sctp_association_put(asoc
);
210 sctp_endpoint_put(ep
);
213 sk
= sctp_get_ctl_sock();
214 ep
= sctp_sk(sk
)->ep
;
215 sctp_endpoint_hold(ep
);
220 if (atomic_read(&sk
->sk_rmem_alloc
) >= sk
->sk_rcvbuf
)
221 goto discard_release
;
224 * RFC 2960, 8.4 - Handle "Out of the blue" Packets.
225 * An SCTP packet is called an "out of the blue" (OOTB)
226 * packet if it is correctly formed, i.e., passed the
227 * receiver's checksum check, but the receiver is not
228 * able to identify the association to which this
232 if (sctp_rcv_ootb(skb
)) {
233 SCTP_INC_STATS_BH(SCTP_MIB_OUTOFBLUES
);
234 goto discard_release
;
238 /* SCTP seems to always need a timestamp right now (FIXME) */
239 if (skb
->stamp
.tv_sec
== 0) {
240 do_gettimeofday(&skb
->stamp
);
241 sock_enable_timestamp(sk
);
244 if (!xfrm_policy_check(sk
, XFRM_POLICY_IN
, skb
, family
))
245 goto discard_release
;
247 ret
= sk_filter(sk
, skb
, 1);
249 goto discard_release
;
251 /* Create an SCTP packet structure. */
252 chunk
= sctp_chunkify(skb
, asoc
, sk
);
255 goto discard_release
;
257 SCTP_INPUT_CB(skb
)->chunk
= chunk
;
259 sctp_rcv_set_owner_r(skb
,sk
);
261 /* Remember what endpoint is to handle this packet. */
264 /* Remember the SCTP header. */
265 chunk
->sctp_hdr
= sh
;
267 /* Set the source and destination addresses of the incoming chunk. */
268 sctp_init_addrs(chunk
, &src
, &dest
);
270 /* Remember where we came from. */
271 chunk
->transport
= transport
;
273 /* Acquire access to the sock lock. Note: We are safe from other
274 * bottom halves on this lock, but a user may be in the lock too,
275 * so check if it is busy.
277 sctp_bh_lock_sock(sk
);
279 if (sock_owned_by_user(sk
))
280 sk_add_backlog(sk
, skb
);
282 sctp_backlog_rcv(sk
, skb
);
284 /* Release the sock and any reference counts we took in the
287 sctp_bh_unlock_sock(sk
);
289 sctp_association_put(asoc
);
291 sctp_endpoint_put(ep
);
300 /* Release any structures we may be holding. */
303 sctp_association_put(asoc
);
305 sctp_endpoint_put(ep
);
310 /* Handle second half of inbound skb processing. If the sock was busy,
311 * we may have need to delay processing until later when the sock is
312 * released (on the backlog). If not busy, we call this routine
313 * directly from the bottom half.
315 int sctp_backlog_rcv(struct sock
*sk
, struct sk_buff
*skb
)
317 struct sctp_chunk
*chunk
= SCTP_INPUT_CB(skb
)->chunk
;
318 struct sctp_inq
*inqueue
= &chunk
->rcvr
->inqueue
;
320 sctp_inq_push(inqueue
, chunk
);
324 /* Handle icmp frag needed error. */
325 void sctp_icmp_frag_needed(struct sock
*sk
, struct sctp_association
*asoc
,
326 struct sctp_transport
*t
, __u32 pmtu
)
328 if (unlikely(pmtu
< SCTP_DEFAULT_MINSEGMENT
)) {
329 printk(KERN_WARNING
"%s: Reported pmtu %d too low, "
330 "using default minimum of %d\n", __FUNCTION__
, pmtu
,
331 SCTP_DEFAULT_MINSEGMENT
);
332 pmtu
= SCTP_DEFAULT_MINSEGMENT
;
335 if (!sock_owned_by_user(sk
) && t
&& (t
->pmtu
!= pmtu
)) {
337 sctp_assoc_sync_pmtu(asoc
);
338 sctp_retransmit(&asoc
->outqueue
, t
, SCTP_RTXR_PMTUD
);
343 * SCTP Implementer's Guide, 2.37 ICMP handling procedures
345 * ICMP8) If the ICMP code is a "Unrecognized next header type encountered"
346 * or a "Protocol Unreachable" treat this message as an abort
347 * with the T bit set.
349 * This function sends an event to the state machine, which will abort the
353 void sctp_icmp_proto_unreachable(struct sock
*sk
,
354 struct sctp_endpoint
*ep
,
355 struct sctp_association
*asoc
,
356 struct sctp_transport
*t
)
358 SCTP_DEBUG_PRINTK("%s\n", __FUNCTION__
);
360 sctp_do_sm(SCTP_EVENT_T_OTHER
,
361 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH
),
362 asoc
->state
, asoc
->ep
, asoc
, t
,
367 /* Common lookup code for icmp/icmpv6 error handler. */
368 struct sock
*sctp_err_lookup(int family
, struct sk_buff
*skb
,
369 struct sctphdr
*sctphdr
,
370 struct sctp_endpoint
**epp
,
371 struct sctp_association
**app
,
372 struct sctp_transport
**tpp
)
374 union sctp_addr saddr
;
375 union sctp_addr daddr
;
377 struct sock
*sk
= NULL
;
378 struct sctp_endpoint
*ep
= NULL
;
379 struct sctp_association
*asoc
= NULL
;
380 struct sctp_transport
*transport
= NULL
;
382 *app
= NULL
; *epp
= NULL
; *tpp
= NULL
;
384 af
= sctp_get_af_specific(family
);
389 /* Initialize local addresses for lookups. */
390 af
->from_skb(&saddr
, skb
, 1);
391 af
->from_skb(&daddr
, skb
, 0);
393 /* Look for an association that matches the incoming ICMP error
396 asoc
= __sctp_lookup_association(&saddr
, &daddr
, &transport
);
398 /* If there is no matching association, see if it matches any
399 * endpoint. This may happen for an ICMP error generated in
400 * response to an INIT_ACK.
402 ep
= __sctp_rcv_lookup_endpoint(&daddr
);
411 if (ntohl(sctphdr
->vtag
) != asoc
->c
.peer_vtag
) {
412 ICMP_INC_STATS_BH(ICMP_MIB_INERRORS
);
418 sctp_bh_lock_sock(sk
);
420 /* If too many ICMPs get dropped on busy
421 * servers this needs to be solved differently.
423 if (sock_owned_by_user(sk
))
424 NET_INC_STATS_BH(LINUX_MIB_LOCKDROPPEDICMPS
);
434 sctp_association_put(asoc
);
436 sctp_endpoint_put(ep
);
440 /* Common cleanup code for icmp/icmpv6 error handler. */
441 void sctp_err_finish(struct sock
*sk
, struct sctp_endpoint
*ep
,
442 struct sctp_association
*asoc
)
444 sctp_bh_unlock_sock(sk
);
447 sctp_association_put(asoc
);
449 sctp_endpoint_put(ep
);
453 * This routine is called by the ICMP module when it gets some
454 * sort of error condition. If err < 0 then the socket should
455 * be closed and the error returned to the user. If err > 0
456 * it's just the icmp type << 8 | icmp code. After adjustment
457 * header points to the first 8 bytes of the sctp header. We need
458 * to find the appropriate port.
460 * The locking strategy used here is very "optimistic". When
461 * someone else accesses the socket the ICMP is just dropped
462 * and for some paths there is no check at all.
463 * A more general error queue to queue errors for later handling
464 * is probably better.
467 void sctp_v4_err(struct sk_buff
*skb
, __u32 info
)
469 struct iphdr
*iph
= (struct iphdr
*)skb
->data
;
470 struct sctphdr
*sh
= (struct sctphdr
*)(skb
->data
+ (iph
->ihl
<<2));
471 int type
= skb
->h
.icmph
->type
;
472 int code
= skb
->h
.icmph
->code
;
474 struct sctp_endpoint
*ep
;
475 struct sctp_association
*asoc
;
476 struct sctp_transport
*transport
;
477 struct inet_sock
*inet
;
478 char *saveip
, *savesctp
;
481 if (skb
->len
< ((iph
->ihl
<< 2) + 8)) {
482 ICMP_INC_STATS_BH(ICMP_MIB_INERRORS
);
486 /* Fix up skb to look at the embedded net header. */
487 saveip
= skb
->nh
.raw
;
488 savesctp
= skb
->h
.raw
;
490 skb
->h
.raw
= (char *)sh
;
491 sk
= sctp_err_lookup(AF_INET
, skb
, sh
, &ep
, &asoc
, &transport
);
492 /* Put back, the original pointers. */
493 skb
->nh
.raw
= saveip
;
494 skb
->h
.raw
= savesctp
;
496 ICMP_INC_STATS_BH(ICMP_MIB_INERRORS
);
499 /* Warning: The sock lock is held. Remember to call
504 case ICMP_PARAMETERPROB
:
507 case ICMP_DEST_UNREACH
:
508 if (code
> NR_ICMP_UNREACH
)
511 /* PMTU discovery (RFC1191) */
512 if (ICMP_FRAG_NEEDED
== code
) {
513 sctp_icmp_frag_needed(sk
, asoc
, transport
, info
);
517 if (ICMP_PROT_UNREACH
== code
) {
518 sctp_icmp_proto_unreachable(sk
, ep
, asoc
,
523 err
= icmp_err_convert
[code
].errno
;
525 case ICMP_TIME_EXCEEDED
:
526 /* Ignore any time exceeded errors due to fragment reassembly
529 if (ICMP_EXC_FRAGTIME
== code
)
539 if (!sock_owned_by_user(sk
) && inet
->recverr
) {
541 sk
->sk_error_report(sk
);
542 } else { /* Only an error on timeout */
543 sk
->sk_err_soft
= err
;
547 sctp_err_finish(sk
, ep
, asoc
);
551 * RFC 2960, 8.4 - Handle "Out of the blue" Packets.
553 * This function scans all the chunks in the OOTB packet to determine if
554 * the packet should be discarded right away. If a response might be needed
555 * for this packet, or, if further processing is possible, the packet will
556 * be queued to a proper inqueue for the next phase of handling.
559 * Return 0 - If further processing is needed.
560 * Return 1 - If the packet can be discarded right away.
562 int sctp_rcv_ootb(struct sk_buff
*skb
)
568 ch
= (sctp_chunkhdr_t
*) skb
->data
;
569 ch_end
= ((__u8
*) ch
) + WORD_ROUND(ntohs(ch
->length
));
571 /* Scan through all the chunks in the packet. */
572 while (ch_end
> (__u8
*)ch
&& ch_end
< skb
->tail
) {
574 /* RFC 8.4, 2) If the OOTB packet contains an ABORT chunk, the
575 * receiver MUST silently discard the OOTB packet and take no
578 if (SCTP_CID_ABORT
== ch
->type
)
581 /* RFC 8.4, 6) If the packet contains a SHUTDOWN COMPLETE
582 * chunk, the receiver should silently discard the packet
583 * and take no further action.
585 if (SCTP_CID_SHUTDOWN_COMPLETE
== ch
->type
)
588 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
589 * or a COOKIE ACK the SCTP Packet should be silently
592 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
595 if (SCTP_CID_ERROR
== ch
->type
) {
596 sctp_walk_errors(err
, ch
) {
597 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
602 ch
= (sctp_chunkhdr_t
*) ch_end
;
603 ch_end
= ((__u8
*) ch
) + WORD_ROUND(ntohs(ch
->length
));
612 /* Insert endpoint into the hash table. */
613 static void __sctp_hash_endpoint(struct sctp_endpoint
*ep
)
615 struct sctp_ep_common
**epp
;
616 struct sctp_ep_common
*epb
;
617 struct sctp_hashbucket
*head
;
621 epb
->hashent
= sctp_ep_hashfn(epb
->bind_addr
.port
);
622 head
= &sctp_ep_hashtable
[epb
->hashent
];
624 sctp_write_lock(&head
->lock
);
628 (*epp
)->pprev
= &epb
->next
;
631 sctp_write_unlock(&head
->lock
);
634 /* Add an endpoint to the hash. Local BH-safe. */
635 void sctp_hash_endpoint(struct sctp_endpoint
*ep
)
637 sctp_local_bh_disable();
638 __sctp_hash_endpoint(ep
);
639 sctp_local_bh_enable();
642 /* Remove endpoint from the hash table. */
643 static void __sctp_unhash_endpoint(struct sctp_endpoint
*ep
)
645 struct sctp_hashbucket
*head
;
646 struct sctp_ep_common
*epb
;
650 epb
->hashent
= sctp_ep_hashfn(epb
->bind_addr
.port
);
652 head
= &sctp_ep_hashtable
[epb
->hashent
];
654 sctp_write_lock(&head
->lock
);
658 epb
->next
->pprev
= epb
->pprev
;
659 *epb
->pprev
= epb
->next
;
663 sctp_write_unlock(&head
->lock
);
666 /* Remove endpoint from the hash. Local BH-safe. */
667 void sctp_unhash_endpoint(struct sctp_endpoint
*ep
)
669 sctp_local_bh_disable();
670 __sctp_unhash_endpoint(ep
);
671 sctp_local_bh_enable();
674 /* Look up an endpoint. */
675 static struct sctp_endpoint
*__sctp_rcv_lookup_endpoint(const union sctp_addr
*laddr
)
677 struct sctp_hashbucket
*head
;
678 struct sctp_ep_common
*epb
;
679 struct sctp_endpoint
*ep
;
682 hash
= sctp_ep_hashfn(laddr
->v4
.sin_port
);
683 head
= &sctp_ep_hashtable
[hash
];
684 read_lock(&head
->lock
);
685 for (epb
= head
->chain
; epb
; epb
= epb
->next
) {
687 if (sctp_endpoint_is_match(ep
, laddr
))
691 ep
= sctp_sk((sctp_get_ctl_sock()))->ep
;
695 sctp_endpoint_hold(ep
);
697 read_unlock(&head
->lock
);
701 /* Insert association into the hash table. */
702 static void __sctp_hash_established(struct sctp_association
*asoc
)
704 struct sctp_ep_common
**epp
;
705 struct sctp_ep_common
*epb
;
706 struct sctp_hashbucket
*head
;
710 /* Calculate which chain this entry will belong to. */
711 epb
->hashent
= sctp_assoc_hashfn(epb
->bind_addr
.port
, asoc
->peer
.port
);
713 head
= &sctp_assoc_hashtable
[epb
->hashent
];
715 sctp_write_lock(&head
->lock
);
719 (*epp
)->pprev
= &epb
->next
;
722 sctp_write_unlock(&head
->lock
);
725 /* Add an association to the hash. Local BH-safe. */
726 void sctp_hash_established(struct sctp_association
*asoc
)
728 sctp_local_bh_disable();
729 __sctp_hash_established(asoc
);
730 sctp_local_bh_enable();
733 /* Remove association from the hash table. */
734 static void __sctp_unhash_established(struct sctp_association
*asoc
)
736 struct sctp_hashbucket
*head
;
737 struct sctp_ep_common
*epb
;
741 epb
->hashent
= sctp_assoc_hashfn(epb
->bind_addr
.port
,
744 head
= &sctp_assoc_hashtable
[epb
->hashent
];
746 sctp_write_lock(&head
->lock
);
750 epb
->next
->pprev
= epb
->pprev
;
751 *epb
->pprev
= epb
->next
;
755 sctp_write_unlock(&head
->lock
);
758 /* Remove association from the hash table. Local BH-safe. */
759 void sctp_unhash_established(struct sctp_association
*asoc
)
761 sctp_local_bh_disable();
762 __sctp_unhash_established(asoc
);
763 sctp_local_bh_enable();
766 /* Look up an association. */
767 static struct sctp_association
*__sctp_lookup_association(
768 const union sctp_addr
*local
,
769 const union sctp_addr
*peer
,
770 struct sctp_transport
**pt
)
772 struct sctp_hashbucket
*head
;
773 struct sctp_ep_common
*epb
;
774 struct sctp_association
*asoc
;
775 struct sctp_transport
*transport
;
778 /* Optimize here for direct hit, only listening connections can
779 * have wildcards anyways.
781 hash
= sctp_assoc_hashfn(local
->v4
.sin_port
, peer
->v4
.sin_port
);
782 head
= &sctp_assoc_hashtable
[hash
];
783 read_lock(&head
->lock
);
784 for (epb
= head
->chain
; epb
; epb
= epb
->next
) {
785 asoc
= sctp_assoc(epb
);
786 transport
= sctp_assoc_is_match(asoc
, local
, peer
);
791 read_unlock(&head
->lock
);
797 sctp_association_hold(asoc
);
799 read_unlock(&head
->lock
);
803 /* Look up an association. BH-safe. */
805 struct sctp_association
*sctp_lookup_association(const union sctp_addr
*laddr
,
806 const union sctp_addr
*paddr
,
807 struct sctp_transport
**transportp
)
809 struct sctp_association
*asoc
;
811 sctp_local_bh_disable();
812 asoc
= __sctp_lookup_association(laddr
, paddr
, transportp
);
813 sctp_local_bh_enable();
818 /* Is there an association matching the given local and peer addresses? */
819 int sctp_has_association(const union sctp_addr
*laddr
,
820 const union sctp_addr
*paddr
)
822 struct sctp_association
*asoc
;
823 struct sctp_transport
*transport
;
825 if ((asoc
= sctp_lookup_association(laddr
, paddr
, &transport
))) {
826 sock_put(asoc
->base
.sk
);
827 sctp_association_put(asoc
);
835 * SCTP Implementors Guide, 2.18 Handling of address
836 * parameters within the INIT or INIT-ACK.
838 * D) When searching for a matching TCB upon reception of an INIT
839 * or INIT-ACK chunk the receiver SHOULD use not only the
840 * source address of the packet (containing the INIT or
841 * INIT-ACK) but the receiver SHOULD also use all valid
842 * address parameters contained within the chunk.
844 * 2.18.3 Solution description
846 * This new text clearly specifies to an implementor the need
847 * to look within the INIT or INIT-ACK. Any implementation that
848 * does not do this, may not be able to establish associations
849 * in certain circumstances.
852 static struct sctp_association
*__sctp_rcv_init_lookup(struct sk_buff
*skb
,
853 const union sctp_addr
*laddr
, struct sctp_transport
**transportp
)
855 struct sctp_association
*asoc
;
856 union sctp_addr addr
;
857 union sctp_addr
*paddr
= &addr
;
858 struct sctphdr
*sh
= (struct sctphdr
*) skb
->h
.raw
;
860 union sctp_params params
;
861 sctp_init_chunk_t
*init
;
862 struct sctp_transport
*transport
;
865 ch
= (sctp_chunkhdr_t
*) skb
->data
;
867 /* If this is INIT/INIT-ACK look inside the chunk too. */
870 case SCTP_CID_INIT_ACK
:
876 /* The code below will attempt to walk the chunk and extract
877 * parameter information. Before we do that, we need to verify
878 * that the chunk length doesn't cause overflow. Otherwise, we'll
881 if (WORD_ROUND(ntohs(ch
->length
)) > skb
->len
)
885 * This code will NOT touch anything inside the chunk--it is
886 * strictly READ-ONLY.
888 * RFC 2960 3 SCTP packet Format
890 * Multiple chunks can be bundled into one SCTP packet up to
891 * the MTU size, except for the INIT, INIT ACK, and SHUTDOWN
892 * COMPLETE chunks. These chunks MUST NOT be bundled with any
893 * other chunk in a packet. See Section 6.10 for more details
897 /* Find the start of the TLVs and the end of the chunk. This is
898 * the region we search for address parameters.
900 init
= (sctp_init_chunk_t
*)skb
->data
;
902 /* Walk the parameters looking for embedded addresses. */
903 sctp_walk_params(params
, init
, init_hdr
.params
) {
905 /* Note: Ignoring hostname addresses. */
906 af
= sctp_get_af_specific(param_type2af(params
.p
->type
));
910 af
->from_addr_param(paddr
, params
.addr
, ntohs(sh
->source
), 0);
912 asoc
= __sctp_lookup_association(laddr
, paddr
, &transport
);
920 /* Lookup an association for an inbound skb. */
921 static struct sctp_association
*__sctp_rcv_lookup(struct sk_buff
*skb
,
922 const union sctp_addr
*paddr
,
923 const union sctp_addr
*laddr
,
924 struct sctp_transport
**transportp
)
926 struct sctp_association
*asoc
;
928 asoc
= __sctp_lookup_association(laddr
, paddr
, transportp
);
930 /* Further lookup for INIT/INIT-ACK packets.
931 * SCTP Implementors Guide, 2.18 Handling of address
932 * parameters within the INIT or INIT-ACK.
935 asoc
= __sctp_rcv_init_lookup(skb
, laddr
, transportp
);