1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51#include <linux/types.h>
52#include <linux/list.h>
53#include <linux/socket.h>
54#include <linux/ip.h>
55#include <linux/time.h>
56#include <net/ip.h>
57#include <net/icmp.h>
58#include <net/snmp.h>
59#include <net/sock.h>
60#include <net/xfrm.h>
61#include <net/sctp/sctp.h>
62#include <net/sctp/sm.h>
63#include <net/sctp/checksum.h>
64#include <net/net_namespace.h>
65
66
67static int sctp_rcv_ootb(struct sk_buff *);
68static struct sctp_association *__sctp_rcv_lookup(struct sk_buff *skb,
69 const union sctp_addr *laddr,
70 const union sctp_addr *paddr,
71 struct sctp_transport **transportp);
72static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *laddr);
73static struct sctp_association *__sctp_lookup_association(
74 const union sctp_addr *local,
75 const union sctp_addr *peer,
76 struct sctp_transport **pt);
77
78static void sctp_add_backlog(struct sock *sk, struct sk_buff *skb);
79
80
81
82static inline int sctp_rcv_checksum(struct sk_buff *skb)
83{
84 struct sctphdr *sh = sctp_hdr(skb);
85 __le32 cmp = sh->checksum;
86 struct sk_buff *list;
87 __le32 val;
88 __u32 tmp = sctp_start_cksum((__u8 *)sh, skb_headlen(skb));
89
90 skb_walk_frags(skb, list)
91 tmp = sctp_update_cksum((__u8 *)list->data, skb_headlen(list),
92 tmp);
93
94 val = sctp_end_cksum(tmp);
95
96 if (val != cmp) {
97
98 SCTP_INC_STATS_BH(SCTP_MIB_CHECKSUMERRORS);
99 return -1;
100 }
101 return 0;
102}
103
104struct sctp_input_cb {
105 union {
106 struct inet_skb_parm h4;
107#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
108 struct inet6_skb_parm h6;
109#endif
110 } header;
111 struct sctp_chunk *chunk;
112};
113#define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0]))
114
115
116
117
118int sctp_rcv(struct sk_buff *skb)
119{
120 struct sock *sk;
121 struct sctp_association *asoc;
122 struct sctp_endpoint *ep = NULL;
123 struct sctp_ep_common *rcvr;
124 struct sctp_transport *transport = NULL;
125 struct sctp_chunk *chunk;
126 struct sctphdr *sh;
127 union sctp_addr src;
128 union sctp_addr dest;
129 int family;
130 struct sctp_af *af;
131
132 if (skb->pkt_type!=PACKET_HOST)
133 goto discard_it;
134
135 SCTP_INC_STATS_BH(SCTP_MIB_INSCTPPACKS);
136
137 if (skb_linearize(skb))
138 goto discard_it;
139
140 sh = sctp_hdr(skb);
141
142
143 __skb_pull(skb, skb_transport_offset(skb));
144 if (skb->len < sizeof(struct sctphdr))
145 goto discard_it;
146 if (!sctp_checksum_disable && !skb_csum_unnecessary(skb) &&
147 sctp_rcv_checksum(skb) < 0)
148 goto discard_it;
149
150 skb_pull(skb, sizeof(struct sctphdr));
151
152
153 if (skb->len < sizeof(struct sctp_chunkhdr))
154 goto discard_it;
155
156 family = ipver2af(ip_hdr(skb)->version);
157 af = sctp_get_af_specific(family);
158 if (unlikely(!af))
159 goto discard_it;
160
161
162 af->from_skb(&src, skb, 1);
163 af->from_skb(&dest, skb, 0);
164
165
166
167
168
169
170
171
172
173
174
175
176 if (!af->addr_valid(&src, NULL, skb) ||
177 !af->addr_valid(&dest, NULL, skb))
178 goto discard_it;
179
180 asoc = __sctp_rcv_lookup(skb, &src, &dest, &transport);
181
182 if (!asoc)
183 ep = __sctp_rcv_lookup_endpoint(&dest);
184
185
186 rcvr = asoc ? &asoc->base : &ep->base;
187 sk = rcvr->sk;
188
189
190
191
192
193 if (sk->sk_bound_dev_if && (sk->sk_bound_dev_if != af->skb_iif(skb)))
194 {
195 if (asoc) {
196 sctp_association_put(asoc);
197 asoc = NULL;
198 } else {
199 sctp_endpoint_put(ep);
200 ep = NULL;
201 }
202 sk = sctp_get_ctl_sock();
203 ep = sctp_sk(sk)->ep;
204 sctp_endpoint_hold(ep);
205 rcvr = &ep->base;
206 }
207
208
209
210
211
212
213
214
215
216 if (!asoc) {
217 if (sctp_rcv_ootb(skb)) {
218 SCTP_INC_STATS_BH(SCTP_MIB_OUTOFBLUES);
219 goto discard_release;
220 }
221 }
222
223 if (!xfrm_policy_check(sk, XFRM_POLICY_IN, skb, family))
224 goto discard_release;
225 nf_reset(skb);
226
227 if (sk_filter(sk, skb))
228 goto discard_release;
229
230
231 chunk = sctp_chunkify(skb, asoc, sk);
232 if (!chunk)
233 goto discard_release;
234 SCTP_INPUT_CB(skb)->chunk = chunk;
235
236
237 chunk->rcvr = rcvr;
238
239
240 chunk->sctp_hdr = sh;
241
242
243 sctp_init_addrs(chunk, &src, &dest);
244
245
246 chunk->transport = transport;
247
248
249
250
251
252 sctp_bh_lock_sock(sk);
253
254 if (sk != rcvr->sk) {
255
256
257
258
259
260
261
262 sctp_bh_unlock_sock(sk);
263 sk = rcvr->sk;
264 sctp_bh_lock_sock(sk);
265 }
266
267 if (sock_owned_by_user(sk)) {
268 SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_BACKLOG);
269 sctp_add_backlog(sk, skb);
270 } else {
271 SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_SOFTIRQ);
272 sctp_inq_push(&chunk->rcvr->inqueue, chunk);
273 }
274
275 sctp_bh_unlock_sock(sk);
276
277
278 if (asoc)
279 sctp_association_put(asoc);
280 else
281 sctp_endpoint_put(ep);
282
283 return 0;
284
285discard_it:
286 SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_DISCARDS);
287 kfree_skb(skb);
288 return 0;
289
290discard_release:
291
292 if (asoc)
293 sctp_association_put(asoc);
294 else
295 sctp_endpoint_put(ep);
296
297 goto discard_it;
298}
299
300
301
302
303
304
305int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
306{
307 struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
308 struct sctp_inq *inqueue = &chunk->rcvr->inqueue;
309 struct sctp_ep_common *rcvr = NULL;
310 int backloged = 0;
311
312 rcvr = chunk->rcvr;
313
314
315
316
317
318 if (rcvr->dead) {
319 sctp_chunk_free(chunk);
320 goto done;
321 }
322
323 if (unlikely(rcvr->sk != sk)) {
324
325
326
327
328
329
330
331
332
333
334
335 sk = rcvr->sk;
336 sctp_bh_lock_sock(sk);
337
338 if (sock_owned_by_user(sk)) {
339 sk_add_backlog(sk, skb);
340 backloged = 1;
341 } else
342 sctp_inq_push(inqueue, chunk);
343
344 sctp_bh_unlock_sock(sk);
345
346
347 if (backloged)
348 return 0;
349 } else {
350 sctp_inq_push(inqueue, chunk);
351 }
352
353done:
354
355 if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type)
356 sctp_association_put(sctp_assoc(rcvr));
357 else if (SCTP_EP_TYPE_SOCKET == rcvr->type)
358 sctp_endpoint_put(sctp_ep(rcvr));
359 else
360 BUG();
361
362 return 0;
363}
364
365static void sctp_add_backlog(struct sock *sk, struct sk_buff *skb)
366{
367 struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
368 struct sctp_ep_common *rcvr = chunk->rcvr;
369
370
371
372
373 if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type)
374 sctp_association_hold(sctp_assoc(rcvr));
375 else if (SCTP_EP_TYPE_SOCKET == rcvr->type)
376 sctp_endpoint_hold(sctp_ep(rcvr));
377 else
378 BUG();
379
380 sk_add_backlog(sk, skb);
381}
382
383
384void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc,
385 struct sctp_transport *t, __u32 pmtu)
386{
387 if (!t || (t->pathmtu <= pmtu))
388 return;
389
390 if (sock_owned_by_user(sk)) {
391 asoc->pmtu_pending = 1;
392 t->pmtu_pending = 1;
393 return;
394 }
395
396 if (t->param_flags & SPP_PMTUD_ENABLE) {
397
398 sctp_transport_update_pmtu(t, pmtu);
399
400
401 sctp_assoc_sync_pmtu(asoc);
402 }
403
404
405
406
407
408
409
410 sctp_retransmit(&asoc->outqueue, t, SCTP_RTXR_PMTUD);
411}
412
413
414
415
416
417
418
419
420
421
422
423
424void sctp_icmp_proto_unreachable(struct sock *sk,
425 struct sctp_association *asoc,
426 struct sctp_transport *t)
427{
428 SCTP_DEBUG_PRINTK("%s\n", __func__);
429
430 sctp_do_sm(SCTP_EVENT_T_OTHER,
431 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH),
432 asoc->state, asoc->ep, asoc, t,
433 GFP_ATOMIC);
434
435}
436
437
438struct sock *sctp_err_lookup(int family, struct sk_buff *skb,
439 struct sctphdr *sctphdr,
440 struct sctp_association **app,
441 struct sctp_transport **tpp)
442{
443 union sctp_addr saddr;
444 union sctp_addr daddr;
445 struct sctp_af *af;
446 struct sock *sk = NULL;
447 struct sctp_association *asoc;
448 struct sctp_transport *transport = NULL;
449 struct sctp_init_chunk *chunkhdr;
450 __u32 vtag = ntohl(sctphdr->vtag);
451 int len = skb->len - ((void *)sctphdr - (void *)skb->data);
452
453 *app = NULL; *tpp = NULL;
454
455 af = sctp_get_af_specific(family);
456 if (unlikely(!af)) {
457 return NULL;
458 }
459
460
461 af->from_skb(&saddr, skb, 1);
462 af->from_skb(&daddr, skb, 0);
463
464
465
466
467 asoc = __sctp_lookup_association(&saddr, &daddr, &transport);
468 if (!asoc)
469 return NULL;
470
471 sk = asoc->base.sk;
472
473
474
475
476
477
478
479
480
481
482
483
484
485 if (vtag == 0) {
486 chunkhdr = (struct sctp_init_chunk *)((void *)sctphdr
487 + sizeof(struct sctphdr));
488 if (len < sizeof(struct sctphdr) + sizeof(sctp_chunkhdr_t)
489 + sizeof(__be32) ||
490 chunkhdr->chunk_hdr.type != SCTP_CID_INIT ||
491 ntohl(chunkhdr->init_hdr.init_tag) != asoc->c.my_vtag) {
492 goto out;
493 }
494 } else if (vtag != asoc->c.peer_vtag) {
495 goto out;
496 }
497
498 sctp_bh_lock_sock(sk);
499
500
501
502
503 if (sock_owned_by_user(sk))
504 NET_INC_STATS_BH(&init_net, LINUX_MIB_LOCKDROPPEDICMPS);
505
506 *app = asoc;
507 *tpp = transport;
508 return sk;
509
510out:
511 if (asoc)
512 sctp_association_put(asoc);
513 return NULL;
514}
515
516
517void sctp_err_finish(struct sock *sk, struct sctp_association *asoc)
518{
519 sctp_bh_unlock_sock(sk);
520 if (asoc)
521 sctp_association_put(asoc);
522}
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539void sctp_v4_err(struct sk_buff *skb, __u32 info)
540{
541 struct iphdr *iph = (struct iphdr *)skb->data;
542 const int ihlen = iph->ihl * 4;
543 const int type = icmp_hdr(skb)->type;
544 const int code = icmp_hdr(skb)->code;
545 struct sock *sk;
546 struct sctp_association *asoc = NULL;
547 struct sctp_transport *transport;
548 struct inet_sock *inet;
549 sk_buff_data_t saveip, savesctp;
550 int err;
551
552 if (skb->len < ihlen + 8) {
553 ICMP_INC_STATS_BH(&init_net, ICMP_MIB_INERRORS);
554 return;
555 }
556
557
558 saveip = skb->network_header;
559 savesctp = skb->transport_header;
560 skb_reset_network_header(skb);
561 skb_set_transport_header(skb, ihlen);
562 sk = sctp_err_lookup(AF_INET, skb, sctp_hdr(skb), &asoc, &transport);
563
564 skb->network_header = saveip;
565 skb->transport_header = savesctp;
566 if (!sk) {
567 ICMP_INC_STATS_BH(&init_net, ICMP_MIB_INERRORS);
568 return;
569 }
570
571
572
573
574 switch (type) {
575 case ICMP_PARAMETERPROB:
576 err = EPROTO;
577 break;
578 case ICMP_DEST_UNREACH:
579 if (code > NR_ICMP_UNREACH)
580 goto out_unlock;
581
582
583 if (ICMP_FRAG_NEEDED == code) {
584 sctp_icmp_frag_needed(sk, asoc, transport, info);
585 goto out_unlock;
586 }
587 else {
588 if (ICMP_PROT_UNREACH == code) {
589 sctp_icmp_proto_unreachable(sk, asoc,
590 transport);
591 goto out_unlock;
592 }
593 }
594 err = icmp_err_convert[code].errno;
595 break;
596 case ICMP_TIME_EXCEEDED:
597
598
599
600 if (ICMP_EXC_FRAGTIME == code)
601 goto out_unlock;
602
603 err = EHOSTUNREACH;
604 break;
605 default:
606 goto out_unlock;
607 }
608
609 inet = inet_sk(sk);
610 if (!sock_owned_by_user(sk) && inet->recverr) {
611 sk->sk_err = err;
612 sk->sk_error_report(sk);
613 } else {
614 sk->sk_err_soft = err;
615 }
616
617out_unlock:
618 sctp_err_finish(sk, asoc);
619}
620
621
622
623
624
625
626
627
628
629
630
631
632
633static int sctp_rcv_ootb(struct sk_buff *skb)
634{
635 sctp_chunkhdr_t *ch;
636 __u8 *ch_end;
637 sctp_errhdr_t *err;
638
639 ch = (sctp_chunkhdr_t *) skb->data;
640
641
642 do {
643
644 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
645 break;
646
647 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
648 if (ch_end > skb_tail_pointer(skb))
649 break;
650
651
652
653
654
655 if (SCTP_CID_ABORT == ch->type)
656 goto discard;
657
658
659
660
661
662 if (SCTP_CID_SHUTDOWN_COMPLETE == ch->type)
663 goto discard;
664
665
666
667
668
669
670 if (SCTP_CID_INIT == ch->type && (void *)ch != skb->data)
671 goto discard;
672
673
674
675
676
677 if (SCTP_CID_COOKIE_ACK == ch->type)
678 goto discard;
679
680 if (SCTP_CID_ERROR == ch->type) {
681 sctp_walk_errors(err, ch) {
682 if (SCTP_ERROR_STALE_COOKIE == err->cause)
683 goto discard;
684 }
685 }
686
687 ch = (sctp_chunkhdr_t *) ch_end;
688 } while (ch_end < skb_tail_pointer(skb));
689
690 return 0;
691
692discard:
693 return 1;
694}
695
696
697static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
698{
699 struct sctp_ep_common *epb;
700 struct sctp_hashbucket *head;
701
702 epb = &ep->base;
703
704 epb->hashent = sctp_ep_hashfn(epb->bind_addr.port);
705 head = &sctp_ep_hashtable[epb->hashent];
706
707 sctp_write_lock(&head->lock);
708 hlist_add_head(&epb->node, &head->chain);
709 sctp_write_unlock(&head->lock);
710}
711
712
713void sctp_hash_endpoint(struct sctp_endpoint *ep)
714{
715 sctp_local_bh_disable();
716 __sctp_hash_endpoint(ep);
717 sctp_local_bh_enable();
718}
719
720
721static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
722{
723 struct sctp_hashbucket *head;
724 struct sctp_ep_common *epb;
725
726 epb = &ep->base;
727
728 if (hlist_unhashed(&epb->node))
729 return;
730
731 epb->hashent = sctp_ep_hashfn(epb->bind_addr.port);
732
733 head = &sctp_ep_hashtable[epb->hashent];
734
735 sctp_write_lock(&head->lock);
736 __hlist_del(&epb->node);
737 sctp_write_unlock(&head->lock);
738}
739
740
741void sctp_unhash_endpoint(struct sctp_endpoint *ep)
742{
743 sctp_local_bh_disable();
744 __sctp_unhash_endpoint(ep);
745 sctp_local_bh_enable();
746}
747
748
749static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *laddr)
750{
751 struct sctp_hashbucket *head;
752 struct sctp_ep_common *epb;
753 struct sctp_endpoint *ep;
754 struct hlist_node *node;
755 int hash;
756
757 hash = sctp_ep_hashfn(ntohs(laddr->v4.sin_port));
758 head = &sctp_ep_hashtable[hash];
759 read_lock(&head->lock);
760 sctp_for_each_hentry(epb, node, &head->chain) {
761 ep = sctp_ep(epb);
762 if (sctp_endpoint_is_match(ep, laddr))
763 goto hit;
764 }
765
766 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
767
768hit:
769 sctp_endpoint_hold(ep);
770 read_unlock(&head->lock);
771 return ep;
772}
773
774
775static void __sctp_hash_established(struct sctp_association *asoc)
776{
777 struct sctp_ep_common *epb;
778 struct sctp_hashbucket *head;
779
780 epb = &asoc->base;
781
782
783 epb->hashent = sctp_assoc_hashfn(epb->bind_addr.port, asoc->peer.port);
784
785 head = &sctp_assoc_hashtable[epb->hashent];
786
787 sctp_write_lock(&head->lock);
788 hlist_add_head(&epb->node, &head->chain);
789 sctp_write_unlock(&head->lock);
790}
791
792
793void sctp_hash_established(struct sctp_association *asoc)
794{
795 if (asoc->temp)
796 return;
797
798 sctp_local_bh_disable();
799 __sctp_hash_established(asoc);
800 sctp_local_bh_enable();
801}
802
803
804static void __sctp_unhash_established(struct sctp_association *asoc)
805{
806 struct sctp_hashbucket *head;
807 struct sctp_ep_common *epb;
808
809 epb = &asoc->base;
810
811 epb->hashent = sctp_assoc_hashfn(epb->bind_addr.port,
812 asoc->peer.port);
813
814 head = &sctp_assoc_hashtable[epb->hashent];
815
816 sctp_write_lock(&head->lock);
817 __hlist_del(&epb->node);
818 sctp_write_unlock(&head->lock);
819}
820
821
822void sctp_unhash_established(struct sctp_association *asoc)
823{
824 if (asoc->temp)
825 return;
826
827 sctp_local_bh_disable();
828 __sctp_unhash_established(asoc);
829 sctp_local_bh_enable();
830}
831
832
833static struct sctp_association *__sctp_lookup_association(
834 const union sctp_addr *local,
835 const union sctp_addr *peer,
836 struct sctp_transport **pt)
837{
838 struct sctp_hashbucket *head;
839 struct sctp_ep_common *epb;
840 struct sctp_association *asoc;
841 struct sctp_transport *transport;
842 struct hlist_node *node;
843 int hash;
844
845
846
847
848 hash = sctp_assoc_hashfn(ntohs(local->v4.sin_port), ntohs(peer->v4.sin_port));
849 head = &sctp_assoc_hashtable[hash];
850 read_lock(&head->lock);
851 sctp_for_each_hentry(epb, node, &head->chain) {
852 asoc = sctp_assoc(epb);
853 transport = sctp_assoc_is_match(asoc, local, peer);
854 if (transport)
855 goto hit;
856 }
857
858 read_unlock(&head->lock);
859
860 return NULL;
861
862hit:
863 *pt = transport;
864 sctp_association_hold(asoc);
865 read_unlock(&head->lock);
866 return asoc;
867}
868
869
870SCTP_STATIC
871struct sctp_association *sctp_lookup_association(const union sctp_addr *laddr,
872 const union sctp_addr *paddr,
873 struct sctp_transport **transportp)
874{
875 struct sctp_association *asoc;
876
877 sctp_local_bh_disable();
878 asoc = __sctp_lookup_association(laddr, paddr, transportp);
879 sctp_local_bh_enable();
880
881 return asoc;
882}
883
884
885int sctp_has_association(const union sctp_addr *laddr,
886 const union sctp_addr *paddr)
887{
888 struct sctp_association *asoc;
889 struct sctp_transport *transport;
890
891 if ((asoc = sctp_lookup_association(laddr, paddr, &transport))) {
892 sctp_association_put(asoc);
893 return 1;
894 }
895
896 return 0;
897}
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917static struct sctp_association *__sctp_rcv_init_lookup(struct sk_buff *skb,
918 const union sctp_addr *laddr, struct sctp_transport **transportp)
919{
920 struct sctp_association *asoc;
921 union sctp_addr addr;
922 union sctp_addr *paddr = &addr;
923 struct sctphdr *sh = sctp_hdr(skb);
924 sctp_chunkhdr_t *ch;
925 union sctp_params params;
926 sctp_init_chunk_t *init;
927 struct sctp_transport *transport;
928 struct sctp_af *af;
929
930 ch = (sctp_chunkhdr_t *) skb->data;
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948 init = (sctp_init_chunk_t *)skb->data;
949
950
951 sctp_walk_params(params, init, init_hdr.params) {
952
953
954 af = sctp_get_af_specific(param_type2af(params.p->type));
955 if (!af)
956 continue;
957
958 af->from_addr_param(paddr, params.addr, sh->source, 0);
959
960 asoc = __sctp_lookup_association(laddr, paddr, &transport);
961 if (asoc)
962 return asoc;
963 }
964
965 return NULL;
966}
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982static struct sctp_association *__sctp_rcv_asconf_lookup(
983 sctp_chunkhdr_t *ch,
984 const union sctp_addr *laddr,
985 __be16 peer_port,
986 struct sctp_transport **transportp)
987{
988 sctp_addip_chunk_t *asconf = (struct sctp_addip_chunk *)ch;
989 struct sctp_af *af;
990 union sctp_addr_param *param;
991 union sctp_addr paddr;
992
993
994 param = (union sctp_addr_param *)(asconf + 1);
995
996 af = sctp_get_af_specific(param_type2af(param->v4.param_hdr.type));
997 if (unlikely(!af))
998 return NULL;
999
1000 af->from_addr_param(&paddr, param, peer_port, 0);
1001
1002 return __sctp_lookup_association(laddr, &paddr, transportp);
1003}
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015static struct sctp_association *__sctp_rcv_walk_lookup(struct sk_buff *skb,
1016 const union sctp_addr *laddr,
1017 struct sctp_transport **transportp)
1018{
1019 struct sctp_association *asoc = NULL;
1020 sctp_chunkhdr_t *ch;
1021 int have_auth = 0;
1022 unsigned int chunk_num = 1;
1023 __u8 *ch_end;
1024
1025
1026
1027
1028 ch = (sctp_chunkhdr_t *) skb->data;
1029 do {
1030
1031 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
1032 break;
1033
1034 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
1035 if (ch_end > skb_tail_pointer(skb))
1036 break;
1037
1038 switch(ch->type) {
1039 case SCTP_CID_AUTH:
1040 have_auth = chunk_num;
1041 break;
1042
1043 case SCTP_CID_COOKIE_ECHO:
1044
1045
1046
1047
1048
1049
1050
1051 if (have_auth == 1 && chunk_num == 2)
1052 return NULL;
1053 break;
1054
1055 case SCTP_CID_ASCONF:
1056 if (have_auth || sctp_addip_noauth)
1057 asoc = __sctp_rcv_asconf_lookup(ch, laddr,
1058 sctp_hdr(skb)->source,
1059 transportp);
1060 default:
1061 break;
1062 }
1063
1064 if (asoc)
1065 break;
1066
1067 ch = (sctp_chunkhdr_t *) ch_end;
1068 chunk_num++;
1069 } while (ch_end < skb_tail_pointer(skb));
1070
1071 return asoc;
1072}
1073
1074
1075
1076
1077
1078
1079
1080static struct sctp_association *__sctp_rcv_lookup_harder(struct sk_buff *skb,
1081 const union sctp_addr *laddr,
1082 struct sctp_transport **transportp)
1083{
1084 sctp_chunkhdr_t *ch;
1085
1086 ch = (sctp_chunkhdr_t *) skb->data;
1087
1088
1089
1090
1091
1092
1093 if (WORD_ROUND(ntohs(ch->length)) > skb->len)
1094 return NULL;
1095
1096
1097 switch (ch->type) {
1098 case SCTP_CID_INIT:
1099 case SCTP_CID_INIT_ACK:
1100 return __sctp_rcv_init_lookup(skb, laddr, transportp);
1101 break;
1102
1103 default:
1104 return __sctp_rcv_walk_lookup(skb, laddr, transportp);
1105 break;
1106 }
1107
1108
1109 return NULL;
1110}
1111
1112
1113static struct sctp_association *__sctp_rcv_lookup(struct sk_buff *skb,
1114 const union sctp_addr *paddr,
1115 const union sctp_addr *laddr,
1116 struct sctp_transport **transportp)
1117{
1118 struct sctp_association *asoc;
1119
1120 asoc = __sctp_lookup_association(laddr, paddr, transportp);
1121
1122
1123
1124
1125
1126 if (!asoc)
1127 asoc = __sctp_rcv_lookup_harder(skb, laddr, transportp);
1128
1129 return asoc;
1130}
1131