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
52
53#include <linux/types.h>
54#include <linux/kernel.h>
55#include <linux/ip.h>
56#include <linux/ipv6.h>
57#include <linux/net.h>
58#include <linux/inet.h>
59#include <net/sock.h>
60#include <net/inet_ecn.h>
61#include <linux/skbuff.h>
62#include <net/sctp/sctp.h>
63#include <net/sctp/sm.h>
64#include <net/sctp/structs.h>
65
66static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
67 const struct sctp_association *asoc,
68 struct sctp_chunk *chunk,
69 const void *payload,
70 size_t paylen);
71static int sctp_eat_data(const struct sctp_association *asoc,
72 struct sctp_chunk *chunk,
73 sctp_cmd_seq_t *commands);
74static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
75 const struct sctp_chunk *chunk);
76static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
77 const struct sctp_association *asoc,
78 const struct sctp_chunk *chunk,
79 sctp_cmd_seq_t *commands,
80 struct sctp_chunk *err_chunk);
81static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
82 const struct sctp_association *asoc,
83 const sctp_subtype_t type,
84 void *arg,
85 sctp_cmd_seq_t *commands);
86static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
87 const struct sctp_association *asoc,
88 const sctp_subtype_t type,
89 void *arg,
90 sctp_cmd_seq_t *commands);
91static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
92 const struct sctp_association *asoc,
93 const sctp_subtype_t type,
94 void *arg,
95 sctp_cmd_seq_t *commands);
96static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
97
98static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
99 __be16 error, int sk_err,
100 const struct sctp_association *asoc,
101 struct sctp_transport *transport);
102
103static sctp_disposition_t sctp_sf_abort_violation(
104 const struct sctp_endpoint *ep,
105 const struct sctp_association *asoc,
106 void *arg,
107 sctp_cmd_seq_t *commands,
108 const __u8 *payload,
109 const size_t paylen);
110
111static sctp_disposition_t sctp_sf_violation_chunklen(
112 const struct sctp_endpoint *ep,
113 const struct sctp_association *asoc,
114 const sctp_subtype_t type,
115 void *arg,
116 sctp_cmd_seq_t *commands);
117
118static sctp_disposition_t sctp_sf_violation_paramlen(
119 const struct sctp_endpoint *ep,
120 const struct sctp_association *asoc,
121 const sctp_subtype_t type,
122 void *arg, void *ext,
123 sctp_cmd_seq_t *commands);
124
125static sctp_disposition_t sctp_sf_violation_ctsn(
126 const struct sctp_endpoint *ep,
127 const struct sctp_association *asoc,
128 const sctp_subtype_t type,
129 void *arg,
130 sctp_cmd_seq_t *commands);
131
132static sctp_disposition_t sctp_sf_violation_chunk(
133 const struct sctp_endpoint *ep,
134 const struct sctp_association *asoc,
135 const sctp_subtype_t type,
136 void *arg,
137 sctp_cmd_seq_t *commands);
138
139static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep,
140 const struct sctp_association *asoc,
141 const sctp_subtype_t type,
142 struct sctp_chunk *chunk);
143
144static sctp_disposition_t __sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
145 const struct sctp_association *asoc,
146 const sctp_subtype_t type,
147 void *arg,
148 sctp_cmd_seq_t *commands);
149
150
151
152
153
154
155
156
157static inline int
158sctp_chunk_length_valid(struct sctp_chunk *chunk,
159 __u16 required_length)
160{
161 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
162
163 if (unlikely(chunk_length < required_length))
164 return 0;
165
166 return 1;
167}
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
205 const struct sctp_association *asoc,
206 const sctp_subtype_t type,
207 void *arg,
208 sctp_cmd_seq_t *commands)
209{
210 struct sctp_chunk *chunk = arg;
211 struct sctp_ulpevent *ev;
212
213 if (!sctp_vtag_verify_either(chunk, asoc))
214 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
215
216
217
218
219
220
221 if (!chunk->singleton)
222 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
223
224
225 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
226 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
227 commands);
228
229
230
231
232
233
234
235
236 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
237 0, 0, 0, NULL, GFP_ATOMIC);
238 if (ev)
239 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
240 SCTP_ULPEVENT(ev));
241
242
243
244
245
246
247
248
249
250 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
251 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
252
253 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
254 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
255
256 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
257 SCTP_STATE(SCTP_STATE_CLOSED));
258
259 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
260 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
261
262 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
263
264 return SCTP_DISPOSITION_DELETE_TCB;
265}
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
290 const struct sctp_association *asoc,
291 const sctp_subtype_t type,
292 void *arg,
293 sctp_cmd_seq_t *commands)
294{
295 struct sctp_chunk *chunk = arg;
296 struct sctp_chunk *repl;
297 struct sctp_association *new_asoc;
298 struct sctp_chunk *err_chunk;
299 struct sctp_packet *packet;
300 sctp_unrecognized_param_t *unk_param;
301 int len;
302
303
304
305
306
307
308
309
310
311
312 if (!chunk->singleton)
313 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
314
315
316
317
318 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) {
319 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
320 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
321 }
322
323
324
325
326 if (chunk->sctp_hdr->vtag != 0)
327 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
328
329
330
331
332
333
334 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
335 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
336
337
338 err_chunk = NULL;
339 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
340 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
341 &err_chunk)) {
342
343
344
345 if (err_chunk) {
346 packet = sctp_abort_pkt_new(ep, asoc, arg,
347 (__u8 *)(err_chunk->chunk_hdr) +
348 sizeof(sctp_chunkhdr_t),
349 ntohs(err_chunk->chunk_hdr->length) -
350 sizeof(sctp_chunkhdr_t));
351
352 sctp_chunk_free(err_chunk);
353
354 if (packet) {
355 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
356 SCTP_PACKET(packet));
357 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
358 return SCTP_DISPOSITION_CONSUME;
359 } else {
360 return SCTP_DISPOSITION_NOMEM;
361 }
362 } else {
363 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
364 commands);
365 }
366 }
367
368
369 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
370
371
372 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
373
374 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
375 if (!new_asoc)
376 goto nomem;
377
378
379 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
380 sctp_source(chunk),
381 (sctp_init_chunk_t *)chunk->chunk_hdr,
382 GFP_ATOMIC))
383 goto nomem_init;
384
385
386
387
388
389
390 len = 0;
391 if (err_chunk)
392 len = ntohs(err_chunk->chunk_hdr->length) -
393 sizeof(sctp_chunkhdr_t);
394
395 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
396 goto nomem_init;
397
398 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
399 if (!repl)
400 goto nomem_init;
401
402
403
404
405
406 if (err_chunk) {
407
408
409
410
411
412
413
414 unk_param = (sctp_unrecognized_param_t *)
415 ((__u8 *)(err_chunk->chunk_hdr) +
416 sizeof(sctp_chunkhdr_t));
417
418
419
420 sctp_addto_chunk(repl, len, unk_param);
421 sctp_chunk_free(err_chunk);
422 }
423
424 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
425
426 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
427
428
429
430
431
432
433
434 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
435
436 return SCTP_DISPOSITION_DELETE_TCB;
437
438nomem_init:
439 sctp_association_free(new_asoc);
440nomem:
441 if (err_chunk)
442 sctp_chunk_free(err_chunk);
443 return SCTP_DISPOSITION_NOMEM;
444}
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
475 const struct sctp_association *asoc,
476 const sctp_subtype_t type,
477 void *arg,
478 sctp_cmd_seq_t *commands)
479{
480 struct sctp_chunk *chunk = arg;
481 sctp_init_chunk_t *initchunk;
482 struct sctp_chunk *err_chunk;
483 struct sctp_packet *packet;
484
485 if (!sctp_vtag_verify(chunk, asoc))
486 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
487
488
489
490
491
492 if (!chunk->singleton)
493 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
494
495
496 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
497 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
498 commands);
499
500 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
501
502
503 err_chunk = NULL;
504 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
505 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
506 &err_chunk)) {
507
508 sctp_error_t error = SCTP_ERROR_NO_RESOURCE;
509
510
511
512
513
514
515 if (err_chunk) {
516 packet = sctp_abort_pkt_new(ep, asoc, arg,
517 (__u8 *)(err_chunk->chunk_hdr) +
518 sizeof(sctp_chunkhdr_t),
519 ntohs(err_chunk->chunk_hdr->length) -
520 sizeof(sctp_chunkhdr_t));
521
522 sctp_chunk_free(err_chunk);
523
524 if (packet) {
525 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
526 SCTP_PACKET(packet));
527 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
528 error = SCTP_ERROR_INV_PARAM;
529 }
530 }
531
532
533
534
535
536
537
538
539
540
541
542
543 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
544 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
545
546 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
547 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED,
548 asoc, chunk->transport);
549 }
550
551
552
553
554 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
555
556 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
557
558 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
559 SCTP_PEER_INIT(initchunk));
560
561
562 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
563
564
565
566
567
568 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
569 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
570 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
571 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
572 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
573 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
574
575
576
577
578 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
579
580
581
582
583
584
585
586 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
587 SCTP_CHUNK(err_chunk));
588
589 return SCTP_DISPOSITION_CONSUME;
590}
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
624 const struct sctp_association *asoc,
625 const sctp_subtype_t type, void *arg,
626 sctp_cmd_seq_t *commands)
627{
628 struct sctp_chunk *chunk = arg;
629 struct sctp_association *new_asoc;
630 sctp_init_chunk_t *peer_init;
631 struct sctp_chunk *repl;
632 struct sctp_ulpevent *ev, *ai_ev = NULL;
633 int error = 0;
634 struct sctp_chunk *err_chk_p;
635 struct sock *sk;
636
637
638
639
640 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) {
641 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
642 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
643 }
644
645
646
647
648
649
650 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
651 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
652
653
654
655
656
657 sk = ep->base.sk;
658 if (!sctp_sstate(sk, LISTENING) ||
659 (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
660 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
661
662
663
664
665 chunk->subh.cookie_hdr =
666 (struct sctp_signed_cookie *)chunk->skb->data;
667 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
668 sizeof(sctp_chunkhdr_t)))
669 goto nomem;
670
671
672
673
674
675 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
676 &err_chk_p);
677
678
679
680
681
682
683
684 if (!new_asoc) {
685
686
687
688 switch (error) {
689 case -SCTP_IERROR_NOMEM:
690 goto nomem;
691
692 case -SCTP_IERROR_STALE_COOKIE:
693 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
694 err_chk_p);
695 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
696
697 case -SCTP_IERROR_BAD_SIG:
698 default:
699 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
700 }
701 }
702
703
704
705
706
707
708
709
710
711
712 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
713
714 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
715 &chunk->subh.cookie_hdr->c.peer_addr,
716 peer_init, GFP_ATOMIC))
717 goto nomem_init;
718
719
720
721
722
723 error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
724 if (error)
725 goto nomem_init;
726
727
728
729
730
731
732
733 if (chunk->auth_chunk) {
734 struct sctp_chunk auth;
735 sctp_ierror_t ret;
736
737
738 auth.skb = chunk->auth_chunk;
739 auth.asoc = chunk->asoc;
740 auth.sctp_hdr = chunk->sctp_hdr;
741 auth.chunk_hdr = (sctp_chunkhdr_t *)skb_push(chunk->auth_chunk,
742 sizeof(sctp_chunkhdr_t));
743 skb_pull(chunk->auth_chunk, sizeof(sctp_chunkhdr_t));
744 auth.transport = chunk->transport;
745
746 ret = sctp_sf_authenticate(ep, new_asoc, type, &auth);
747
748
749 kfree_skb(chunk->auth_chunk);
750
751 if (ret != SCTP_IERROR_NO_ERROR) {
752 sctp_association_free(new_asoc);
753 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
754 }
755 }
756
757 repl = sctp_make_cookie_ack(new_asoc, chunk);
758 if (!repl)
759 goto nomem_init;
760
761
762
763
764
765
766
767 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
768 new_asoc->c.sinit_num_ostreams,
769 new_asoc->c.sinit_max_instreams,
770 NULL, GFP_ATOMIC);
771 if (!ev)
772 goto nomem_ev;
773
774
775
776
777
778
779 if (new_asoc->peer.adaptation_ind) {
780 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
781 GFP_ATOMIC);
782 if (!ai_ev)
783 goto nomem_aiev;
784 }
785
786
787
788
789
790
791 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
792 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
793 SCTP_STATE(SCTP_STATE_ESTABLISHED));
794 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
795 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
796 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
797
798 if (new_asoc->autoclose)
799 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
800 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
801
802
803 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
804
805
806 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
807
808
809 if (ai_ev)
810 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
811 SCTP_ULPEVENT(ai_ev));
812
813 return SCTP_DISPOSITION_CONSUME;
814
815nomem_aiev:
816 sctp_ulpevent_free(ev);
817nomem_ev:
818 sctp_chunk_free(repl);
819nomem_init:
820 sctp_association_free(new_asoc);
821nomem:
822 return SCTP_DISPOSITION_NOMEM;
823}
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
847 const struct sctp_association *asoc,
848 const sctp_subtype_t type, void *arg,
849 sctp_cmd_seq_t *commands)
850{
851 struct sctp_chunk *chunk = arg;
852 struct sctp_ulpevent *ev;
853
854 if (!sctp_vtag_verify(chunk, asoc))
855 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
856
857
858
859
860 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
861 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
862 commands);
863
864
865
866
867
868
869
870 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
871
872
873
874
875
876
877
878 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
879 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
880 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
881 SCTP_STATE(SCTP_STATE_ESTABLISHED));
882 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
883 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
884 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
885 if (asoc->autoclose)
886 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
887 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
888
889
890
891
892
893 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
894 0, asoc->c.sinit_num_ostreams,
895 asoc->c.sinit_max_instreams,
896 NULL, GFP_ATOMIC);
897
898 if (!ev)
899 goto nomem;
900
901 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
902
903
904
905
906
907
908 if (asoc->peer.adaptation_ind) {
909 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
910 if (!ev)
911 goto nomem;
912
913 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
914 SCTP_ULPEVENT(ev));
915 }
916
917 return SCTP_DISPOSITION_CONSUME;
918nomem:
919 return SCTP_DISPOSITION_NOMEM;
920}
921
922
923static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
924 const struct sctp_association *asoc,
925 const sctp_subtype_t type,
926 void *arg,
927 sctp_cmd_seq_t *commands)
928{
929 struct sctp_transport *transport = (struct sctp_transport *) arg;
930 struct sctp_chunk *reply;
931 sctp_sender_hb_info_t hbinfo;
932 size_t paylen = 0;
933
934 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
935 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
936 hbinfo.daddr = transport->ipaddr;
937 hbinfo.sent_at = jiffies;
938 hbinfo.hb_nonce = transport->hb_nonce;
939
940
941 paylen = sizeof(sctp_sender_hb_info_t);
942 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
943 if (!reply)
944 return SCTP_DISPOSITION_NOMEM;
945
946
947
948
949 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
950 SCTP_TRANSPORT(transport));
951
952 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
953 return SCTP_DISPOSITION_CONSUME;
954}
955
956
957sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
958 const struct sctp_association *asoc,
959 const sctp_subtype_t type,
960 void *arg,
961 sctp_cmd_seq_t *commands)
962{
963 struct sctp_transport *transport = (struct sctp_transport *) arg;
964
965 if (asoc->overall_error_count > asoc->max_retrans) {
966 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
967 SCTP_ERROR(ETIMEDOUT));
968
969 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
970 SCTP_PERR(SCTP_ERROR_NO_ERROR));
971 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
972 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
973 return SCTP_DISPOSITION_DELETE_TCB;
974 }
975
976
977
978
979
980
981
982
983 if (transport->param_flags & SPP_HB_ENABLE) {
984 if (SCTP_DISPOSITION_NOMEM ==
985 sctp_sf_heartbeat(ep, asoc, type, arg,
986 commands))
987 return SCTP_DISPOSITION_NOMEM;
988
989
990
991 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE,
992 SCTP_TRANSPORT(transport));
993 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
994 SCTP_TRANSPORT(transport));
995 }
996 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
997 SCTP_TRANSPORT(transport));
998
999 return SCTP_DISPOSITION_CONSUME;
1000}
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
1027 const struct sctp_association *asoc,
1028 const sctp_subtype_t type,
1029 void *arg,
1030 sctp_cmd_seq_t *commands)
1031{
1032 struct sctp_chunk *chunk = arg;
1033 struct sctp_chunk *reply;
1034 size_t paylen = 0;
1035
1036 if (!sctp_vtag_verify(chunk, asoc))
1037 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1038
1039
1040 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1041 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1042 commands);
1043
1044
1045
1046
1047
1048 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
1049 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
1050 if (!pskb_pull(chunk->skb, paylen))
1051 goto nomem;
1052
1053 reply = sctp_make_heartbeat_ack(asoc, chunk,
1054 chunk->subh.hb_hdr, paylen);
1055 if (!reply)
1056 goto nomem;
1057
1058 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1059 return SCTP_DISPOSITION_CONSUME;
1060
1061nomem:
1062 return SCTP_DISPOSITION_NOMEM;
1063}
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1094 const struct sctp_association *asoc,
1095 const sctp_subtype_t type,
1096 void *arg,
1097 sctp_cmd_seq_t *commands)
1098{
1099 struct sctp_chunk *chunk = arg;
1100 union sctp_addr from_addr;
1101 struct sctp_transport *link;
1102 sctp_sender_hb_info_t *hbinfo;
1103 unsigned long max_interval;
1104
1105 if (!sctp_vtag_verify(chunk, asoc))
1106 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1107
1108
1109 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1110 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1111 commands);
1112
1113 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1114
1115 if (ntohs(hbinfo->param_hdr.length) !=
1116 sizeof(sctp_sender_hb_info_t)) {
1117 return SCTP_DISPOSITION_DISCARD;
1118 }
1119
1120 from_addr = hbinfo->daddr;
1121 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1122
1123
1124 if (unlikely(!link)) {
1125 if (from_addr.sa.sa_family == AF_INET6) {
1126 if (net_ratelimit())
1127 printk(KERN_WARNING
1128 "%s association %p could not find address %pI6\n",
1129 __func__,
1130 asoc,
1131 &from_addr.v6.sin6_addr);
1132 } else {
1133 if (net_ratelimit())
1134 printk(KERN_WARNING
1135 "%s association %p could not find address %pI4\n",
1136 __func__,
1137 asoc,
1138 &from_addr.v4.sin_addr.s_addr);
1139 }
1140 return SCTP_DISPOSITION_DISCARD;
1141 }
1142
1143
1144 if (hbinfo->hb_nonce != link->hb_nonce)
1145 return SCTP_DISPOSITION_DISCARD;
1146
1147 max_interval = link->hbinterval + link->rto;
1148
1149
1150 if (time_after(hbinfo->sent_at, jiffies) ||
1151 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1152 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1153 "received for transport: %p\n",
1154 __func__, link);
1155 return SCTP_DISPOSITION_DISCARD;
1156 }
1157
1158
1159
1160
1161
1162
1163
1164 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1165
1166 return SCTP_DISPOSITION_CONSUME;
1167}
1168
1169
1170
1171
1172static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1173 struct sctp_chunk *init,
1174 sctp_cmd_seq_t *commands)
1175{
1176 int len;
1177 struct sctp_packet *pkt;
1178 union sctp_addr_param *addrparm;
1179 struct sctp_errhdr *errhdr;
1180 struct sctp_endpoint *ep;
1181 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1182 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1183
1184
1185
1186
1187 errhdr = (struct sctp_errhdr *)buffer;
1188 addrparm = (union sctp_addr_param *)errhdr->variable;
1189
1190
1191 len = af->to_addr_param(ssa, addrparm);
1192 len += sizeof(sctp_errhdr_t);
1193
1194 errhdr->cause = SCTP_ERROR_RESTART;
1195 errhdr->length = htons(len);
1196
1197
1198 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1199
1200
1201
1202
1203 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1204
1205 if (!pkt)
1206 goto out;
1207 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1208
1209 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1210
1211
1212 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1213
1214out:
1215
1216
1217
1218 return 0;
1219}
1220
1221
1222
1223
1224static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1225 const struct sctp_association *asoc,
1226 struct sctp_chunk *init,
1227 sctp_cmd_seq_t *commands)
1228{
1229 struct sctp_transport *new_addr, *addr;
1230 int found;
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243 new_addr = NULL;
1244 found = 0;
1245
1246 list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list,
1247 transports) {
1248 found = 0;
1249 list_for_each_entry(addr, &asoc->peer.transport_addr_list,
1250 transports) {
1251 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1252 &addr->ipaddr)) {
1253 found = 1;
1254 break;
1255 }
1256 }
1257 if (!found)
1258 break;
1259 }
1260
1261
1262 if (!found && new_addr) {
1263 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1264 }
1265
1266
1267 return found;
1268}
1269
1270
1271
1272
1273
1274
1275static void sctp_tietags_populate(struct sctp_association *new_asoc,
1276 const struct sctp_association *asoc)
1277{
1278 switch (asoc->state) {
1279
1280
1281
1282 case SCTP_STATE_COOKIE_WAIT:
1283 new_asoc->c.my_vtag = asoc->c.my_vtag;
1284 new_asoc->c.my_ttag = asoc->c.my_vtag;
1285 new_asoc->c.peer_ttag = 0;
1286 break;
1287
1288 case SCTP_STATE_COOKIE_ECHOED:
1289 new_asoc->c.my_vtag = asoc->c.my_vtag;
1290 new_asoc->c.my_ttag = asoc->c.my_vtag;
1291 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1292 break;
1293
1294
1295
1296
1297 default:
1298 new_asoc->c.my_ttag = asoc->c.my_vtag;
1299 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1300 break;
1301 }
1302
1303
1304
1305
1306
1307 new_asoc->rwnd = asoc->rwnd;
1308 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1309 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1310 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1311}
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322static char sctp_tietags_compare(struct sctp_association *new_asoc,
1323 const struct sctp_association *asoc)
1324{
1325
1326 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1327 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1328 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1329 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1330 return 'A';
1331
1332
1333 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1334 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1335 (0 == asoc->c.peer_vtag))) {
1336 return 'B';
1337 }
1338
1339
1340 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1341 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1342 return 'D';
1343
1344
1345 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1346 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1347 (0 == new_asoc->c.my_ttag) &&
1348 (0 == new_asoc->c.peer_ttag))
1349 return 'C';
1350
1351
1352 return 'E';
1353}
1354
1355
1356
1357
1358static sctp_disposition_t sctp_sf_do_unexpected_init(
1359 const struct sctp_endpoint *ep,
1360 const struct sctp_association *asoc,
1361 const sctp_subtype_t type,
1362 void *arg, sctp_cmd_seq_t *commands)
1363{
1364 sctp_disposition_t retval;
1365 struct sctp_chunk *chunk = arg;
1366 struct sctp_chunk *repl;
1367 struct sctp_association *new_asoc;
1368 struct sctp_chunk *err_chunk;
1369 struct sctp_packet *packet;
1370 sctp_unrecognized_param_t *unk_param;
1371 int len;
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382 if (!chunk->singleton)
1383 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1384
1385
1386
1387
1388 if (chunk->sctp_hdr->vtag != 0)
1389 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1390
1391
1392
1393
1394
1395 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1396 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1397 commands);
1398
1399 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1400
1401
1402 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1403
1404
1405 err_chunk = NULL;
1406 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1407 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1408 &err_chunk)) {
1409
1410
1411
1412 if (err_chunk) {
1413 packet = sctp_abort_pkt_new(ep, asoc, arg,
1414 (__u8 *)(err_chunk->chunk_hdr) +
1415 sizeof(sctp_chunkhdr_t),
1416 ntohs(err_chunk->chunk_hdr->length) -
1417 sizeof(sctp_chunkhdr_t));
1418
1419 if (packet) {
1420 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1421 SCTP_PACKET(packet));
1422 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1423 retval = SCTP_DISPOSITION_CONSUME;
1424 } else {
1425 retval = SCTP_DISPOSITION_NOMEM;
1426 }
1427 goto cleanup;
1428 } else {
1429 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1430 commands);
1431 }
1432 }
1433
1434
1435
1436
1437
1438
1439
1440
1441 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1442 if (!new_asoc)
1443 goto nomem;
1444
1445
1446
1447
1448
1449 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1450 sctp_source(chunk),
1451 (sctp_init_chunk_t *)chunk->chunk_hdr,
1452 GFP_ATOMIC))
1453 goto nomem;
1454
1455
1456
1457
1458
1459
1460 if (!sctp_state(asoc, COOKIE_WAIT)) {
1461 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1462 commands)) {
1463 retval = SCTP_DISPOSITION_CONSUME;
1464 goto nomem_retval;
1465 }
1466 }
1467
1468 sctp_tietags_populate(new_asoc, asoc);
1469
1470
1471
1472
1473
1474
1475 len = 0;
1476 if (err_chunk) {
1477 len = ntohs(err_chunk->chunk_hdr->length) -
1478 sizeof(sctp_chunkhdr_t);
1479 }
1480
1481 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1482 goto nomem;
1483
1484 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1485 if (!repl)
1486 goto nomem;
1487
1488
1489
1490
1491
1492 if (err_chunk) {
1493
1494
1495
1496
1497
1498
1499
1500 unk_param = (sctp_unrecognized_param_t *)
1501 ((__u8 *)(err_chunk->chunk_hdr) +
1502 sizeof(sctp_chunkhdr_t));
1503
1504
1505
1506 sctp_addto_chunk(repl, len, unk_param);
1507 }
1508
1509 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1510 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1511
1512
1513
1514
1515
1516
1517 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1518 retval = SCTP_DISPOSITION_CONSUME;
1519
1520 return retval;
1521
1522nomem:
1523 retval = SCTP_DISPOSITION_NOMEM;
1524nomem_retval:
1525 if (new_asoc)
1526 sctp_association_free(new_asoc);
1527cleanup:
1528 if (err_chunk)
1529 sctp_chunk_free(err_chunk);
1530 return retval;
1531}
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1572 const struct sctp_association *asoc,
1573 const sctp_subtype_t type,
1574 void *arg,
1575 sctp_cmd_seq_t *commands)
1576{
1577
1578
1579
1580 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1581}
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1625 const struct sctp_association *asoc,
1626 const sctp_subtype_t type,
1627 void *arg,
1628 sctp_cmd_seq_t *commands)
1629{
1630
1631
1632
1633 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1634}
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep,
1647 const struct sctp_association *asoc,
1648 const sctp_subtype_t type,
1649 void *arg, sctp_cmd_seq_t *commands)
1650{
1651
1652
1653
1654 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
1655 return sctp_sf_ootb(ep, asoc, type, arg, commands);
1656 else
1657 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
1658}
1659
1660
1661
1662
1663
1664
1665static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1666 const struct sctp_association *asoc,
1667 struct sctp_chunk *chunk,
1668 sctp_cmd_seq_t *commands,
1669 struct sctp_association *new_asoc)
1670{
1671 sctp_init_chunk_t *peer_init;
1672 struct sctp_ulpevent *ev;
1673 struct sctp_chunk *repl;
1674 struct sctp_chunk *err;
1675 sctp_disposition_t disposition;
1676
1677
1678
1679
1680 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1681
1682 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1683 sctp_source(chunk), peer_init,
1684 GFP_ATOMIC))
1685 goto nomem;
1686
1687
1688
1689
1690
1691 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1692 return SCTP_DISPOSITION_CONSUME;
1693 }
1694
1695
1696
1697
1698
1699
1700
1701 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1702 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1703 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1704 chunk, commands);
1705 if (SCTP_DISPOSITION_NOMEM == disposition)
1706 goto nomem;
1707
1708 err = sctp_make_op_error(asoc, chunk,
1709 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1710 NULL, 0);
1711 if (err)
1712 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1713 SCTP_CHUNK(err));
1714
1715 return SCTP_DISPOSITION_CONSUME;
1716 }
1717
1718
1719
1720
1721 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1722
1723 repl = sctp_make_cookie_ack(new_asoc, chunk);
1724 if (!repl)
1725 goto nomem;
1726
1727
1728 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1729 new_asoc->c.sinit_num_ostreams,
1730 new_asoc->c.sinit_max_instreams,
1731 NULL, GFP_ATOMIC);
1732 if (!ev)
1733 goto nomem_ev;
1734
1735
1736 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1737 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1738 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1739 return SCTP_DISPOSITION_CONSUME;
1740
1741nomem_ev:
1742 sctp_chunk_free(repl);
1743nomem:
1744 return SCTP_DISPOSITION_NOMEM;
1745}
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1756 const struct sctp_association *asoc,
1757 struct sctp_chunk *chunk,
1758 sctp_cmd_seq_t *commands,
1759 struct sctp_association *new_asoc)
1760{
1761 sctp_init_chunk_t *peer_init;
1762 struct sctp_chunk *repl;
1763
1764
1765
1766
1767 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1768 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1769 sctp_source(chunk), peer_init,
1770 GFP_ATOMIC))
1771 goto nomem;
1772
1773
1774 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1775 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1776 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1777 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1778 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1779
1780 repl = sctp_make_cookie_ack(new_asoc, chunk);
1781 if (!repl)
1782 goto nomem;
1783
1784 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808 if (asoc->peer.adaptation_ind)
1809 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
1810
1811 return SCTP_DISPOSITION_CONSUME;
1812
1813nomem:
1814 return SCTP_DISPOSITION_NOMEM;
1815}
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1827 const struct sctp_association *asoc,
1828 struct sctp_chunk *chunk,
1829 sctp_cmd_seq_t *commands,
1830 struct sctp_association *new_asoc)
1831{
1832
1833
1834
1835
1836 return SCTP_DISPOSITION_DISCARD;
1837}
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1848 const struct sctp_association *asoc,
1849 struct sctp_chunk *chunk,
1850 sctp_cmd_seq_t *commands,
1851 struct sctp_association *new_asoc)
1852{
1853 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL;
1854 struct sctp_chunk *repl;
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1865 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1866 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1867 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1868 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1869 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1870 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1871 SCTP_NULL());
1872
1873
1874
1875
1876
1877
1878
1879
1880 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
1881 SCTP_COMM_UP, 0,
1882 asoc->c.sinit_num_ostreams,
1883 asoc->c.sinit_max_instreams,
1884 NULL, GFP_ATOMIC);
1885 if (!ev)
1886 goto nomem;
1887
1888
1889
1890
1891
1892
1893 if (asoc->peer.adaptation_ind) {
1894 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
1895 GFP_ATOMIC);
1896 if (!ai_ev)
1897 goto nomem;
1898
1899 }
1900 }
1901
1902 repl = sctp_make_cookie_ack(new_asoc, chunk);
1903 if (!repl)
1904 goto nomem;
1905
1906 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1907
1908 if (ev)
1909 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1910 SCTP_ULPEVENT(ev));
1911 if (ai_ev)
1912 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1913 SCTP_ULPEVENT(ai_ev));
1914
1915 return SCTP_DISPOSITION_CONSUME;
1916
1917nomem:
1918 if (ai_ev)
1919 sctp_ulpevent_free(ai_ev);
1920 if (ev)
1921 sctp_ulpevent_free(ev);
1922 return SCTP_DISPOSITION_NOMEM;
1923}
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1942 const struct sctp_association *asoc,
1943 const sctp_subtype_t type,
1944 void *arg,
1945 sctp_cmd_seq_t *commands)
1946{
1947 sctp_disposition_t retval;
1948 struct sctp_chunk *chunk = arg;
1949 struct sctp_association *new_asoc;
1950 int error = 0;
1951 char action;
1952 struct sctp_chunk *err_chk_p;
1953
1954
1955
1956
1957
1958
1959 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1960 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1961 commands);
1962
1963
1964
1965
1966 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1967 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1968 sizeof(sctp_chunkhdr_t)))
1969 goto nomem;
1970
1971
1972
1973
1974
1975
1976 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1977 &err_chk_p);
1978
1979
1980
1981
1982
1983
1984
1985 if (!new_asoc) {
1986
1987
1988
1989 switch (error) {
1990 case -SCTP_IERROR_NOMEM:
1991 goto nomem;
1992
1993 case -SCTP_IERROR_STALE_COOKIE:
1994 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1995 err_chk_p);
1996 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1997 case -SCTP_IERROR_BAD_SIG:
1998 default:
1999 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2000 }
2001 }
2002
2003
2004
2005
2006 action = sctp_tietags_compare(new_asoc, asoc);
2007
2008 switch (action) {
2009 case 'A':
2010 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
2011 new_asoc);
2012 break;
2013
2014 case 'B':
2015 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
2016 new_asoc);
2017 break;
2018
2019 case 'C':
2020 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
2021 new_asoc);
2022 break;
2023
2024 case 'D':
2025 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
2026 new_asoc);
2027 break;
2028
2029 default:
2030 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2031 break;
2032 }
2033
2034
2035 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
2036 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2037
2038 return retval;
2039
2040nomem:
2041 return SCTP_DISPOSITION_NOMEM;
2042}
2043
2044
2045
2046
2047
2048
2049sctp_disposition_t sctp_sf_shutdown_pending_abort(
2050 const struct sctp_endpoint *ep,
2051 const struct sctp_association *asoc,
2052 const sctp_subtype_t type,
2053 void *arg,
2054 sctp_cmd_seq_t *commands)
2055{
2056 struct sctp_chunk *chunk = arg;
2057
2058 if (!sctp_vtag_verify_either(chunk, asoc))
2059 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2072 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2073
2074
2075
2076
2077
2078
2079 if (SCTP_ADDR_DEL ==
2080 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2081 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2082
2083 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2084}
2085
2086
2087
2088
2089
2090
2091sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
2092 const struct sctp_association *asoc,
2093 const sctp_subtype_t type,
2094 void *arg,
2095 sctp_cmd_seq_t *commands)
2096{
2097 struct sctp_chunk *chunk = arg;
2098
2099 if (!sctp_vtag_verify_either(chunk, asoc))
2100 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2113 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2114
2115
2116
2117
2118
2119
2120 if (SCTP_ADDR_DEL ==
2121 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2122 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2123
2124
2125 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2126 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2127
2128
2129 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2130 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2131
2132 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2133}
2134
2135
2136
2137
2138
2139
2140sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2141 const struct sctp_endpoint *ep,
2142 const struct sctp_association *asoc,
2143 const sctp_subtype_t type,
2144 void *arg,
2145 sctp_cmd_seq_t *commands)
2146{
2147
2148
2149
2150 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2151}
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2168 const struct sctp_association *asoc,
2169 const sctp_subtype_t type,
2170 void *arg,
2171 sctp_cmd_seq_t *commands)
2172{
2173 struct sctp_chunk *chunk = arg;
2174 sctp_errhdr_t *err;
2175
2176 if (!sctp_vtag_verify(chunk, asoc))
2177 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2178
2179
2180
2181
2182 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2183 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2184 commands);
2185
2186
2187
2188
2189
2190
2191 sctp_walk_errors(err, chunk->chunk_hdr) {
2192 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2193 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2194 arg, commands);
2195 }
2196
2197
2198
2199
2200
2201
2202 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2203}
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2231 const struct sctp_association *asoc,
2232 const sctp_subtype_t type,
2233 void *arg,
2234 sctp_cmd_seq_t *commands)
2235{
2236 struct sctp_chunk *chunk = arg;
2237 time_t stale;
2238 sctp_cookie_preserve_param_t bht;
2239 sctp_errhdr_t *err;
2240 struct sctp_chunk *reply;
2241 struct sctp_bind_addr *bp;
2242 int attempts = asoc->init_err_counter + 1;
2243
2244 if (attempts > asoc->max_init_attempts) {
2245 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2246 SCTP_ERROR(ETIMEDOUT));
2247 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2248 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2249 return SCTP_DISPOSITION_DELETE_TCB;
2250 }
2251
2252 err = (sctp_errhdr_t *)(chunk->skb->data);
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t)));
2269 stale = (stale * 2) / 1000;
2270
2271 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2272 bht.param_hdr.length = htons(sizeof(bht));
2273 bht.lifespan_increment = htonl(stale);
2274
2275
2276 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2277 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2278 if (!reply)
2279 goto nomem;
2280
2281 sctp_addto_chunk(reply, sizeof(bht), &bht);
2282
2283
2284 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2285
2286
2287 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2288 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2289
2290
2291
2292
2293 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2294
2295
2296
2297
2298 sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN,
2299 SCTP_TRANSPORT(asoc->peer.primary_path));
2300
2301
2302
2303
2304 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2305
2306 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2307 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2308 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2309 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2310 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2311 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2312
2313 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2314
2315 return SCTP_DISPOSITION_CONSUME;
2316
2317nomem:
2318 return SCTP_DISPOSITION_NOMEM;
2319}
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2353 const struct sctp_association *asoc,
2354 const sctp_subtype_t type,
2355 void *arg,
2356 sctp_cmd_seq_t *commands)
2357{
2358 struct sctp_chunk *chunk = arg;
2359
2360 if (!sctp_vtag_verify_either(chunk, asoc))
2361 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2374 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2375
2376
2377
2378
2379
2380
2381 if (SCTP_ADDR_DEL ==
2382 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2383 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2384
2385 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2386}
2387
2388static sctp_disposition_t __sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2389 const struct sctp_association *asoc,
2390 const sctp_subtype_t type,
2391 void *arg,
2392 sctp_cmd_seq_t *commands)
2393{
2394 struct sctp_chunk *chunk = arg;
2395 unsigned len;
2396 __be16 error = SCTP_ERROR_NO_ERROR;
2397
2398
2399 len = ntohs(chunk->chunk_hdr->length);
2400 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2401 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2402
2403 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2404
2405 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2406 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2407 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2408
2409 return SCTP_DISPOSITION_ABORT;
2410}
2411
2412
2413
2414
2415
2416
2417sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2418 const struct sctp_association *asoc,
2419 const sctp_subtype_t type,
2420 void *arg,
2421 sctp_cmd_seq_t *commands)
2422{
2423 struct sctp_chunk *chunk = arg;
2424 unsigned len;
2425 __be16 error = SCTP_ERROR_NO_ERROR;
2426
2427 if (!sctp_vtag_verify_either(chunk, asoc))
2428 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2441 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2442
2443
2444 len = ntohs(chunk->chunk_hdr->length);
2445 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2446 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2447
2448 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc,
2449 chunk->transport);
2450}
2451
2452
2453
2454
2455sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2456 const struct sctp_association *asoc,
2457 const sctp_subtype_t type,
2458 void *arg,
2459 sctp_cmd_seq_t *commands)
2460{
2461 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR,
2462 ENOPROTOOPT, asoc,
2463 (struct sctp_transport *)arg);
2464}
2465
2466
2467
2468
2469sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2470 const struct sctp_association *asoc,
2471 const sctp_subtype_t type,
2472 void *arg,
2473 sctp_cmd_seq_t *commands)
2474{
2475
2476
2477
2478 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2479}
2480
2481
2482
2483
2484
2485
2486static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2487 __be16 error, int sk_err,
2488 const struct sctp_association *asoc,
2489 struct sctp_transport *transport)
2490{
2491 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2492 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2493 SCTP_STATE(SCTP_STATE_CLOSED));
2494 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2495 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2496 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2497 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2498
2499 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2500 SCTP_PERR(error));
2501 return SCTP_DISPOSITION_ABORT;
2502}
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2538 const struct sctp_association *asoc,
2539 const sctp_subtype_t type,
2540 void *arg,
2541 sctp_cmd_seq_t *commands)
2542{
2543 struct sctp_chunk *chunk = arg;
2544 sctp_shutdownhdr_t *sdh;
2545 sctp_disposition_t disposition;
2546 struct sctp_ulpevent *ev;
2547 __u32 ctsn;
2548
2549 if (!sctp_vtag_verify(chunk, asoc))
2550 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2551
2552
2553 if (!sctp_chunk_length_valid(chunk,
2554 sizeof(struct sctp_shutdown_chunk_t)))
2555 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2556 commands);
2557
2558
2559 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2560 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2561 chunk->subh.shutdown_hdr = sdh;
2562 ctsn = ntohl(sdh->cum_tsn_ack);
2563
2564
2565
2566
2567
2568 if (!TSN_lt(ctsn, asoc->next_tsn))
2569 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
2570
2571
2572
2573
2574
2575 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2576 if (!ev) {
2577 disposition = SCTP_DISPOSITION_NOMEM;
2578 goto out;
2579 }
2580 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2581
2582
2583
2584
2585
2586
2587
2588 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2589 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2590 disposition = SCTP_DISPOSITION_CONSUME;
2591
2592 if (sctp_outq_is_empty(&asoc->outqueue)) {
2593 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2594 arg, commands);
2595 }
2596
2597 if (SCTP_DISPOSITION_NOMEM == disposition)
2598 goto out;
2599
2600
2601
2602
2603
2604 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2605 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2606
2607out:
2608 return disposition;
2609}
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619sctp_disposition_t sctp_sf_do_9_2_shut_ctsn(const struct sctp_endpoint *ep,
2620 const struct sctp_association *asoc,
2621 const sctp_subtype_t type,
2622 void *arg,
2623 sctp_cmd_seq_t *commands)
2624{
2625 struct sctp_chunk *chunk = arg;
2626 sctp_shutdownhdr_t *sdh;
2627
2628 if (!sctp_vtag_verify(chunk, asoc))
2629 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2630
2631
2632 if (!sctp_chunk_length_valid(chunk,
2633 sizeof(struct sctp_shutdown_chunk_t)))
2634 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2635 commands);
2636
2637 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2638
2639
2640
2641
2642
2643 if (!TSN_lt(ntohl(sdh->cum_tsn_ack), asoc->next_tsn))
2644 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
2645
2646
2647
2648
2649
2650 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2651 SCTP_BE32(sdh->cum_tsn_ack));
2652
2653 return SCTP_DISPOSITION_CONSUME;
2654}
2655
2656
2657
2658
2659
2660
2661
2662
2663sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2664 const struct sctp_association *asoc,
2665 const sctp_subtype_t type,
2666 void *arg,
2667 sctp_cmd_seq_t *commands)
2668{
2669 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2670 struct sctp_chunk *reply;
2671
2672
2673 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
2674 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2675 commands);
2676
2677
2678
2679
2680
2681 reply = sctp_make_shutdown_ack(asoc, chunk);
2682 if (NULL == reply)
2683 goto nomem;
2684
2685
2686
2687
2688 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2689
2690
2691 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2692 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2693
2694 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2695
2696 return SCTP_DISPOSITION_CONSUME;
2697nomem:
2698 return SCTP_DISPOSITION_NOMEM;
2699}
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2727 const struct sctp_association *asoc,
2728 const sctp_subtype_t type,
2729 void *arg,
2730 sctp_cmd_seq_t *commands)
2731{
2732 sctp_cwrhdr_t *cwr;
2733 struct sctp_chunk *chunk = arg;
2734 u32 lowest_tsn;
2735
2736 if (!sctp_vtag_verify(chunk, asoc))
2737 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2738
2739 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2740 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2741 commands);
2742
2743 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2744 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2745
2746 lowest_tsn = ntohl(cwr->lowest_tsn);
2747
2748
2749 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
2750
2751 sctp_add_cmd_sf(commands,
2752 SCTP_CMD_ECN_CWR,
2753 SCTP_U32(lowest_tsn));
2754 }
2755 return SCTP_DISPOSITION_CONSUME;
2756}
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2782 const struct sctp_association *asoc,
2783 const sctp_subtype_t type,
2784 void *arg,
2785 sctp_cmd_seq_t *commands)
2786{
2787 sctp_ecnehdr_t *ecne;
2788 struct sctp_chunk *chunk = arg;
2789
2790 if (!sctp_vtag_verify(chunk, asoc))
2791 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2792
2793 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2794 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2795 commands);
2796
2797 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2798 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2799
2800
2801 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2802 SCTP_U32(ntohl(ecne->lowest_tsn)));
2803
2804 return SCTP_DISPOSITION_CONSUME;
2805}
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2838 const struct sctp_association *asoc,
2839 const sctp_subtype_t type,
2840 void *arg,
2841 sctp_cmd_seq_t *commands)
2842{
2843 struct sctp_chunk *chunk = arg;
2844 int error;
2845
2846 if (!sctp_vtag_verify(chunk, asoc)) {
2847 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2848 SCTP_NULL());
2849 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2850 }
2851
2852 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2853 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2854 commands);
2855
2856 error = sctp_eat_data(asoc, chunk, commands );
2857 switch (error) {
2858 case SCTP_IERROR_NO_ERROR:
2859 break;
2860 case SCTP_IERROR_HIGH_TSN:
2861 case SCTP_IERROR_BAD_STREAM:
2862 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2863 goto discard_noforce;
2864 case SCTP_IERROR_DUP_TSN:
2865 case SCTP_IERROR_IGNORE_TSN:
2866 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2867 goto discard_force;
2868 case SCTP_IERROR_NO_DATA:
2869 goto consume;
2870 default:
2871 BUG();
2872 }
2873
2874 if (asoc->autoclose) {
2875 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2876 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2877 }
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901 if (chunk->end_of_packet)
2902 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2903
2904 return SCTP_DISPOSITION_CONSUME;
2905
2906discard_force:
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921 if (chunk->end_of_packet)
2922 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2923 return SCTP_DISPOSITION_DISCARD;
2924
2925discard_noforce:
2926 if (chunk->end_of_packet)
2927 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2928
2929 return SCTP_DISPOSITION_DISCARD;
2930consume:
2931 return SCTP_DISPOSITION_CONSUME;
2932
2933}
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2952 const struct sctp_association *asoc,
2953 const sctp_subtype_t type,
2954 void *arg,
2955 sctp_cmd_seq_t *commands)
2956{
2957 struct sctp_chunk *chunk = arg;
2958 int error;
2959
2960 if (!sctp_vtag_verify(chunk, asoc)) {
2961 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2962 SCTP_NULL());
2963 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2964 }
2965
2966 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2967 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2968 commands);
2969
2970 error = sctp_eat_data(asoc, chunk, commands );
2971 switch (error) {
2972 case SCTP_IERROR_NO_ERROR:
2973 case SCTP_IERROR_HIGH_TSN:
2974 case SCTP_IERROR_DUP_TSN:
2975 case SCTP_IERROR_IGNORE_TSN:
2976 case SCTP_IERROR_BAD_STREAM:
2977 break;
2978 case SCTP_IERROR_NO_DATA:
2979 goto consume;
2980 default:
2981 BUG();
2982 }
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992 if (chunk->end_of_packet) {
2993
2994
2995
2996 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2997 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2998 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2999 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3000 }
3001
3002consume:
3003 return SCTP_DISPOSITION_CONSUME;
3004}
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
3039 const struct sctp_association *asoc,
3040 const sctp_subtype_t type,
3041 void *arg,
3042 sctp_cmd_seq_t *commands)
3043{
3044 struct sctp_chunk *chunk = arg;
3045 sctp_sackhdr_t *sackh;
3046 __u32 ctsn;
3047
3048 if (!sctp_vtag_verify(chunk, asoc))
3049 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3050
3051
3052 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
3053 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3054 commands);
3055
3056
3057 sackh = sctp_sm_pull_sack(chunk);
3058
3059 if (!sackh)
3060 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3061 chunk->subh.sack_hdr = sackh;
3062 ctsn = ntohl(sackh->cum_tsn_ack);
3063
3064
3065
3066
3067
3068
3069
3070 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
3071 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
3072 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
3073 return SCTP_DISPOSITION_DISCARD;
3074 }
3075
3076
3077
3078
3079
3080 if (!TSN_lt(ctsn, asoc->next_tsn))
3081 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
3082
3083
3084 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
3085
3086
3087
3088
3089 return SCTP_DISPOSITION_CONSUME;
3090}
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
3111 const struct sctp_association *asoc,
3112 const sctp_subtype_t type,
3113 void *arg,
3114 sctp_cmd_seq_t *commands)
3115{
3116 struct sctp_packet *packet = NULL;
3117 struct sctp_chunk *chunk = arg;
3118 struct sctp_chunk *abort;
3119
3120 packet = sctp_ootb_pkt_new(asoc, chunk);
3121
3122 if (packet) {
3123
3124
3125
3126 abort = sctp_make_abort(asoc, chunk, 0);
3127 if (!abort) {
3128 sctp_ootb_pkt_free(packet);
3129 return SCTP_DISPOSITION_NOMEM;
3130 }
3131
3132
3133 if (sctp_test_T_bit(abort))
3134 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3135
3136
3137 abort->skb->sk = ep->base.sk;
3138
3139 sctp_packet_append_chunk(packet, abort);
3140
3141 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3142 SCTP_PACKET(packet));
3143
3144 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3145
3146 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3147 return SCTP_DISPOSITION_CONSUME;
3148 }
3149
3150 return SCTP_DISPOSITION_NOMEM;
3151}
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
3162 const struct sctp_association *asoc,
3163 const sctp_subtype_t type,
3164 void *arg,
3165 sctp_cmd_seq_t *commands)
3166{
3167 struct sctp_chunk *chunk = arg;
3168
3169 if (!sctp_vtag_verify(chunk, asoc))
3170 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3171
3172
3173 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
3174 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3175 commands);
3176
3177 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3178 SCTP_CHUNK(chunk));
3179
3180 return SCTP_DISPOSITION_CONSUME;
3181}
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
3194 const struct sctp_association *asoc,
3195 const sctp_subtype_t type,
3196 void *arg,
3197 sctp_cmd_seq_t *commands)
3198{
3199 struct sctp_chunk *chunk = arg;
3200 struct sctp_chunk *reply;
3201 struct sctp_ulpevent *ev;
3202
3203 if (!sctp_vtag_verify(chunk, asoc))
3204 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3205
3206
3207 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3208 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3209 commands);
3210
3211
3212
3213
3214
3215 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3216 0, 0, 0, NULL, GFP_ATOMIC);
3217 if (!ev)
3218 goto nomem;
3219
3220
3221 reply = sctp_make_shutdown_complete(asoc, chunk);
3222 if (!reply)
3223 goto nomem_chunk;
3224
3225
3226
3227
3228 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3229
3230
3231
3232
3233 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3234 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3235
3236 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3237 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3238
3239 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3240 SCTP_STATE(SCTP_STATE_CLOSED));
3241 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3242 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3243 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3244
3245
3246 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3247 return SCTP_DISPOSITION_DELETE_TCB;
3248
3249nomem_chunk:
3250 sctp_ulpevent_free(ev);
3251nomem:
3252 return SCTP_DISPOSITION_NOMEM;
3253}
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3276 const struct sctp_association *asoc,
3277 const sctp_subtype_t type,
3278 void *arg,
3279 sctp_cmd_seq_t *commands)
3280{
3281 struct sctp_chunk *chunk = arg;
3282 struct sk_buff *skb = chunk->skb;
3283 sctp_chunkhdr_t *ch;
3284 __u8 *ch_end;
3285 int ootb_shut_ack = 0;
3286
3287 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3288
3289 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
3290 do {
3291
3292 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
3293 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3294 commands);
3295
3296
3297
3298
3299 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3300 ootb_shut_ack = 1;
3301
3302
3303
3304
3305
3306
3307 if (SCTP_CID_ABORT == ch->type)
3308 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3309
3310
3311 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3312 if (ch_end > skb_tail_pointer(skb))
3313 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3314 commands);
3315
3316 ch = (sctp_chunkhdr_t *) ch_end;
3317 } while (ch_end < skb_tail_pointer(skb));
3318
3319 if (ootb_shut_ack)
3320 return sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
3321 else
3322 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
3323}
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3347 const struct sctp_association *asoc,
3348 const sctp_subtype_t type,
3349 void *arg,
3350 sctp_cmd_seq_t *commands)
3351{
3352 struct sctp_packet *packet = NULL;
3353 struct sctp_chunk *chunk = arg;
3354 struct sctp_chunk *shut;
3355
3356 packet = sctp_ootb_pkt_new(asoc, chunk);
3357
3358 if (packet) {
3359
3360
3361
3362 shut = sctp_make_shutdown_complete(asoc, chunk);
3363 if (!shut) {
3364 sctp_ootb_pkt_free(packet);
3365 return SCTP_DISPOSITION_NOMEM;
3366 }
3367
3368
3369 if (sctp_test_T_bit(shut))
3370 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3371
3372
3373 shut->skb->sk = ep->base.sk;
3374
3375 sctp_packet_append_chunk(packet, shut);
3376
3377 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3378 SCTP_PACKET(packet));
3379
3380 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3381
3382
3383
3384
3385 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3386 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3387
3388
3389
3390
3391
3392 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3393 }
3394
3395 return SCTP_DISPOSITION_NOMEM;
3396}
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3410 const struct sctp_association *asoc,
3411 const sctp_subtype_t type,
3412 void *arg,
3413 sctp_cmd_seq_t *commands)
3414{
3415 struct sctp_chunk *chunk = arg;
3416
3417
3418 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3419 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3420 commands);
3421
3422
3423
3424
3425
3426
3427 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3428
3429 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3430}
3431
3432
3433sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3434 const struct sctp_association *asoc,
3435 const sctp_subtype_t type, void *arg,
3436 sctp_cmd_seq_t *commands)
3437{
3438 struct sctp_chunk *chunk = arg;
3439 struct sctp_chunk *asconf_ack = NULL;
3440 struct sctp_paramhdr *err_param = NULL;
3441 sctp_addiphdr_t *hdr;
3442 union sctp_addr_param *addr_param;
3443 __u32 serial;
3444 int length;
3445
3446 if (!sctp_vtag_verify(chunk, asoc)) {
3447 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3448 SCTP_NULL());
3449 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3450 }
3451
3452
3453
3454
3455
3456
3457
3458 if (!sctp_addip_noauth && !chunk->auth)
3459 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
3460
3461
3462 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t)))
3463 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3464 commands);
3465
3466 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3467 serial = ntohl(hdr->serial);
3468
3469 addr_param = (union sctp_addr_param *)hdr->params;
3470 length = ntohs(addr_param->p.length);
3471 if (length < sizeof(sctp_paramhdr_t))
3472 return sctp_sf_violation_paramlen(ep, asoc, type, arg,
3473 (void *)addr_param, commands);
3474
3475
3476 if (!sctp_verify_asconf(asoc,
3477 (sctp_paramhdr_t *)((void *)addr_param + length),
3478 (void *)chunk->chunk_end,
3479 &err_param))
3480 return sctp_sf_violation_paramlen(ep, asoc, type, arg,
3481 (void *)err_param, commands);
3482
3483
3484
3485
3486
3487 if (serial == asoc->peer.addip_serial + 1) {
3488
3489
3490
3491 if (!chunk->has_asconf)
3492 sctp_assoc_clean_asconf_ack_cache(asoc);
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502 asconf_ack = sctp_process_asconf((struct sctp_association *)
3503 asoc, chunk);
3504 if (!asconf_ack)
3505 return SCTP_DISPOSITION_NOMEM;
3506 } else if (serial < asoc->peer.addip_serial + 1) {
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519 asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial);
3520 if (!asconf_ack)
3521 return SCTP_DISPOSITION_DISCARD;
3522 } else {
3523
3524
3525
3526 return SCTP_DISPOSITION_DISCARD;
3527 }
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538 asconf_ack->dest = chunk->source;
3539 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3540
3541 return SCTP_DISPOSITION_CONSUME;
3542}
3543
3544
3545
3546
3547
3548
3549sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3550 const struct sctp_association *asoc,
3551 const sctp_subtype_t type, void *arg,
3552 sctp_cmd_seq_t *commands)
3553{
3554 struct sctp_chunk *asconf_ack = arg;
3555 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3556 struct sctp_chunk *abort;
3557 struct sctp_paramhdr *err_param = NULL;
3558 sctp_addiphdr_t *addip_hdr;
3559 __u32 sent_serial, rcvd_serial;
3560
3561 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3562 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3563 SCTP_NULL());
3564 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3565 }
3566
3567
3568
3569
3570
3571
3572
3573 if (!sctp_addip_noauth && !asconf_ack->auth)
3574 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
3575
3576
3577 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t)))
3578 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3579 commands);
3580
3581 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3582 rcvd_serial = ntohl(addip_hdr->serial);
3583
3584
3585 if (!sctp_verify_asconf(asoc,
3586 (sctp_paramhdr_t *)addip_hdr->params,
3587 (void *)asconf_ack->chunk_end,
3588 &err_param))
3589 return sctp_sf_violation_paramlen(ep, asoc, type, arg,
3590 (void *)err_param, commands);
3591
3592 if (last_asconf) {
3593 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3594 sent_serial = ntohl(addip_hdr->serial);
3595 } else {
3596 sent_serial = asoc->addip_serial - 1;
3597 }
3598
3599
3600
3601
3602
3603
3604
3605 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3606 !(asoc->addip_last_asconf)) {
3607 abort = sctp_make_abort(asoc, asconf_ack,
3608 sizeof(sctp_errhdr_t));
3609 if (abort) {
3610 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
3611 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3612 SCTP_CHUNK(abort));
3613 }
3614
3615
3616
3617 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3618 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3619 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3620 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3621 SCTP_ERROR(ECONNABORTED));
3622 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3623 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3624 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3625 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3626 return SCTP_DISPOSITION_ABORT;
3627 }
3628
3629 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3630 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3631 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3632
3633 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3634 asconf_ack))
3635 return SCTP_DISPOSITION_CONSUME;
3636
3637 abort = sctp_make_abort(asoc, asconf_ack,
3638 sizeof(sctp_errhdr_t));
3639 if (abort) {
3640 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
3641 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3642 SCTP_CHUNK(abort));
3643 }
3644
3645
3646
3647 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3648 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3649 SCTP_ERROR(ECONNABORTED));
3650 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3651 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3652 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3653 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3654 return SCTP_DISPOSITION_ABORT;
3655 }
3656
3657 return SCTP_DISPOSITION_DISCARD;
3658}
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3675 const struct sctp_association *asoc,
3676 const sctp_subtype_t type,
3677 void *arg,
3678 sctp_cmd_seq_t *commands)
3679{
3680 struct sctp_chunk *chunk = arg;
3681 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3682 struct sctp_fwdtsn_skip *skip;
3683 __u16 len;
3684 __u32 tsn;
3685
3686 if (!sctp_vtag_verify(chunk, asoc)) {
3687 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3688 SCTP_NULL());
3689 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3690 }
3691
3692
3693 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3694 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3695 commands);
3696
3697 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3698 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3699 len = ntohs(chunk->chunk_hdr->length);
3700 len -= sizeof(struct sctp_chunkhdr);
3701 skb_pull(chunk->skb, len);
3702
3703 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3704 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__, tsn);
3705
3706
3707
3708
3709 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3710 goto discard_noforce;
3711
3712
3713 sctp_walk_fwdtsn(skip, chunk) {
3714 if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
3715 goto discard_noforce;
3716 }
3717
3718 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3719 if (len > sizeof(struct sctp_fwdtsn_hdr))
3720 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3721 SCTP_CHUNK(chunk));
3722
3723
3724 if (asoc->autoclose) {
3725 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3726 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3727 }
3728
3729
3730
3731
3732 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3733
3734 return SCTP_DISPOSITION_CONSUME;
3735
3736discard_noforce:
3737 return SCTP_DISPOSITION_DISCARD;
3738}
3739
3740sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3741 const struct sctp_endpoint *ep,
3742 const struct sctp_association *asoc,
3743 const sctp_subtype_t type,
3744 void *arg,
3745 sctp_cmd_seq_t *commands)
3746{
3747 struct sctp_chunk *chunk = arg;
3748 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3749 struct sctp_fwdtsn_skip *skip;
3750 __u16 len;
3751 __u32 tsn;
3752
3753 if (!sctp_vtag_verify(chunk, asoc)) {
3754 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3755 SCTP_NULL());
3756 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3757 }
3758
3759
3760 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3761 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3762 commands);
3763
3764 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3765 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3766 len = ntohs(chunk->chunk_hdr->length);
3767 len -= sizeof(struct sctp_chunkhdr);
3768 skb_pull(chunk->skb, len);
3769
3770 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3771 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__, tsn);
3772
3773
3774
3775
3776 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3777 goto gen_shutdown;
3778
3779
3780 sctp_walk_fwdtsn(skip, chunk) {
3781 if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
3782 goto gen_shutdown;
3783 }
3784
3785 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3786 if (len > sizeof(struct sctp_fwdtsn_hdr))
3787 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3788 SCTP_CHUNK(chunk));
3789
3790
3791gen_shutdown:
3792
3793
3794
3795
3796
3797
3798 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3799 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3800 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3801 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3802
3803 return SCTP_DISPOSITION_CONSUME;
3804}
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep,
3829 const struct sctp_association *asoc,
3830 const sctp_subtype_t type,
3831 struct sctp_chunk *chunk)
3832{
3833 struct sctp_authhdr *auth_hdr;
3834 struct sctp_hmac *hmac;
3835 unsigned int sig_len;
3836 __u16 key_id;
3837 __u8 *save_digest;
3838 __u8 *digest;
3839
3840
3841 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
3842 chunk->subh.auth_hdr = auth_hdr;
3843 skb_pull(chunk->skb, sizeof(struct sctp_authhdr));
3844
3845
3846
3847
3848 if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id))
3849 return SCTP_IERROR_AUTH_BAD_HMAC;
3850
3851
3852
3853
3854 key_id = ntohs(auth_hdr->shkey_id);
3855 if (key_id != asoc->active_key_id && !sctp_auth_get_shkey(asoc, key_id))
3856 return SCTP_IERROR_AUTH_BAD_KEYID;
3857
3858
3859
3860
3861
3862 sig_len = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_auth_chunk_t);
3863 hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id));
3864 if (sig_len != hmac->hmac_len)
3865 return SCTP_IERROR_PROTO_VIOLATION;
3866
3867
3868
3869
3870
3871
3872
3873
3874 digest = auth_hdr->hmac;
3875 skb_pull(chunk->skb, sig_len);
3876
3877 save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
3878 if (!save_digest)
3879 goto nomem;
3880
3881 memset(digest, 0, sig_len);
3882
3883 sctp_auth_calculate_hmac(asoc, chunk->skb,
3884 (struct sctp_auth_chunk *)chunk->chunk_hdr,
3885 GFP_ATOMIC);
3886
3887
3888 if (memcmp(save_digest, digest, sig_len)) {
3889 kfree(save_digest);
3890 return SCTP_IERROR_BAD_SIG;
3891 }
3892
3893 kfree(save_digest);
3894 chunk->auth = 1;
3895
3896 return SCTP_IERROR_NO_ERROR;
3897nomem:
3898 return SCTP_IERROR_NOMEM;
3899}
3900
3901sctp_disposition_t sctp_sf_eat_auth(const struct sctp_endpoint *ep,
3902 const struct sctp_association *asoc,
3903 const sctp_subtype_t type,
3904 void *arg,
3905 sctp_cmd_seq_t *commands)
3906{
3907 struct sctp_authhdr *auth_hdr;
3908 struct sctp_chunk *chunk = arg;
3909 struct sctp_chunk *err_chunk;
3910 sctp_ierror_t error;
3911
3912
3913 if (!asoc->peer.auth_capable)
3914 return sctp_sf_unk_chunk(ep, asoc, type, arg, commands);
3915
3916 if (!sctp_vtag_verify(chunk, asoc)) {
3917 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3918 SCTP_NULL());
3919 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3920 }
3921
3922
3923 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk)))
3924 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3925 commands);
3926
3927 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
3928 error = sctp_sf_authenticate(ep, asoc, type, chunk);
3929 switch (error) {
3930 case SCTP_IERROR_AUTH_BAD_HMAC:
3931
3932
3933
3934 err_chunk = sctp_make_op_error(asoc, chunk,
3935 SCTP_ERROR_UNSUP_HMAC,
3936 &auth_hdr->hmac_id,
3937 sizeof(__u16));
3938 if (err_chunk) {
3939 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3940 SCTP_CHUNK(err_chunk));
3941 }
3942
3943 case SCTP_IERROR_AUTH_BAD_KEYID:
3944 case SCTP_IERROR_BAD_SIG:
3945 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3946 break;
3947 case SCTP_IERROR_PROTO_VIOLATION:
3948 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3949 commands);
3950 break;
3951 case SCTP_IERROR_NOMEM:
3952 return SCTP_DISPOSITION_NOMEM;
3953 default:
3954 break;
3955 }
3956
3957 if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) {
3958 struct sctp_ulpevent *ev;
3959
3960 ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id),
3961 SCTP_AUTH_NEWKEY, GFP_ATOMIC);
3962
3963 if (!ev)
3964 return -ENOMEM;
3965
3966 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
3967 SCTP_ULPEVENT(ev));
3968 }
3969
3970 return SCTP_DISPOSITION_CONSUME;
3971}
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3997 const struct sctp_association *asoc,
3998 const sctp_subtype_t type,
3999 void *arg,
4000 sctp_cmd_seq_t *commands)
4001{
4002 struct sctp_chunk *unk_chunk = arg;
4003 struct sctp_chunk *err_chunk;
4004 sctp_chunkhdr_t *hdr;
4005
4006 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
4007
4008 if (!sctp_vtag_verify(unk_chunk, asoc))
4009 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
4010
4011
4012
4013
4014
4015 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t)))
4016 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4017 commands);
4018
4019 switch (type.chunk & SCTP_CID_ACTION_MASK) {
4020 case SCTP_CID_ACTION_DISCARD:
4021
4022 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
4023 break;
4024 case SCTP_CID_ACTION_DISCARD_ERR:
4025
4026 hdr = unk_chunk->chunk_hdr;
4027 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4028 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4029 WORD_ROUND(ntohs(hdr->length)));
4030 if (err_chunk) {
4031 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4032 SCTP_CHUNK(err_chunk));
4033 }
4034
4035
4036 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
4037 return SCTP_DISPOSITION_CONSUME;
4038 break;
4039 case SCTP_CID_ACTION_SKIP:
4040
4041 return SCTP_DISPOSITION_DISCARD;
4042 break;
4043 case SCTP_CID_ACTION_SKIP_ERR:
4044
4045 hdr = unk_chunk->chunk_hdr;
4046 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4047 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4048 WORD_ROUND(ntohs(hdr->length)));
4049 if (err_chunk) {
4050 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4051 SCTP_CHUNK(err_chunk));
4052 }
4053
4054 return SCTP_DISPOSITION_CONSUME;
4055 break;
4056 default:
4057 break;
4058 }
4059
4060 return SCTP_DISPOSITION_DISCARD;
4061}
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
4078 const struct sctp_association *asoc,
4079 const sctp_subtype_t type,
4080 void *arg,
4081 sctp_cmd_seq_t *commands)
4082{
4083 struct sctp_chunk *chunk = arg;
4084
4085
4086
4087
4088
4089 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
4090 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4091 commands);
4092
4093 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
4094 return SCTP_DISPOSITION_DISCARD;
4095}
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
4116 const struct sctp_association *asoc,
4117 const sctp_subtype_t type,
4118 void *arg,
4119 sctp_cmd_seq_t *commands)
4120{
4121 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS);
4122 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
4123
4124 return SCTP_DISPOSITION_CONSUME;
4125}
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
4143 const struct sctp_association *asoc,
4144 const sctp_subtype_t type,
4145 void *arg,
4146 sctp_cmd_seq_t *commands)
4147{
4148 struct sctp_chunk *chunk = arg;
4149
4150
4151 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
4152 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4153 commands);
4154
4155 return SCTP_DISPOSITION_VIOLATION;
4156}
4157
4158
4159
4160
4161static sctp_disposition_t sctp_sf_abort_violation(
4162 const struct sctp_endpoint *ep,
4163 const struct sctp_association *asoc,
4164 void *arg,
4165 sctp_cmd_seq_t *commands,
4166 const __u8 *payload,
4167 const size_t paylen)
4168{
4169 struct sctp_packet *packet = NULL;
4170 struct sctp_chunk *chunk = arg;
4171 struct sctp_chunk *abort = NULL;
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4185 goto discard;
4186
4187
4188 abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
4189 if (!abort)
4190 goto nomem;
4191
4192 if (asoc) {
4193
4194 if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK &&
4195 !asoc->peer.i.init_tag) {
4196 sctp_initack_chunk_t *initack;
4197
4198 initack = (sctp_initack_chunk_t *)chunk->chunk_hdr;
4199 if (!sctp_chunk_length_valid(chunk,
4200 sizeof(sctp_initack_chunk_t)))
4201 abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T;
4202 else {
4203 unsigned int inittag;
4204
4205 inittag = ntohl(initack->init_hdr.init_tag);
4206 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_INITTAG,
4207 SCTP_U32(inittag));
4208 }
4209 }
4210
4211 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4212 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4213
4214 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
4215 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4216 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4217 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4218 SCTP_ERROR(ECONNREFUSED));
4219 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4220 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4221 } else {
4222 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4223 SCTP_ERROR(ECONNABORTED));
4224 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4225 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4226 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4227 }
4228 } else {
4229 packet = sctp_ootb_pkt_new(asoc, chunk);
4230
4231 if (!packet)
4232 goto nomem_pkt;
4233
4234 if (sctp_test_T_bit(abort))
4235 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
4236
4237 abort->skb->sk = ep->base.sk;
4238
4239 sctp_packet_append_chunk(packet, abort);
4240
4241 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4242 SCTP_PACKET(packet));
4243
4244 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4245 }
4246
4247 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4248
4249discard:
4250 sctp_sf_pdiscard(ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4251 return SCTP_DISPOSITION_ABORT;
4252
4253nomem_pkt:
4254 sctp_chunk_free(abort);
4255nomem:
4256 return SCTP_DISPOSITION_NOMEM;
4257}
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278static sctp_disposition_t sctp_sf_violation_chunklen(
4279 const struct sctp_endpoint *ep,
4280 const struct sctp_association *asoc,
4281 const sctp_subtype_t type,
4282 void *arg,
4283 sctp_cmd_seq_t *commands)
4284{
4285 static const char err_str[]="The following chunk had invalid length:";
4286
4287 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4288 sizeof(err_str));
4289}
4290
4291
4292
4293
4294
4295
4296static sctp_disposition_t sctp_sf_violation_paramlen(
4297 const struct sctp_endpoint *ep,
4298 const struct sctp_association *asoc,
4299 const sctp_subtype_t type,
4300 void *arg, void *ext,
4301 sctp_cmd_seq_t *commands)
4302{
4303 struct sctp_chunk *chunk = arg;
4304 struct sctp_paramhdr *param = ext;
4305 struct sctp_chunk *abort = NULL;
4306
4307 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4308 goto discard;
4309
4310
4311 abort = sctp_make_violation_paramlen(asoc, chunk, param);
4312 if (!abort)
4313 goto nomem;
4314
4315 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4316 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4317
4318 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4319 SCTP_ERROR(ECONNABORTED));
4320 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4321 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4322 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4323 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4324
4325discard:
4326 sctp_sf_pdiscard(ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4327 return SCTP_DISPOSITION_ABORT;
4328nomem:
4329 return SCTP_DISPOSITION_NOMEM;
4330}
4331
4332
4333
4334
4335
4336
4337
4338static sctp_disposition_t sctp_sf_violation_ctsn(
4339 const struct sctp_endpoint *ep,
4340 const struct sctp_association *asoc,
4341 const sctp_subtype_t type,
4342 void *arg,
4343 sctp_cmd_seq_t *commands)
4344{
4345 static const char err_str[]="The cumulative tsn ack beyond the max tsn currently sent:";
4346
4347 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4348 sizeof(err_str));
4349}
4350
4351
4352
4353
4354
4355
4356
4357static sctp_disposition_t sctp_sf_violation_chunk(
4358 const struct sctp_endpoint *ep,
4359 const struct sctp_association *asoc,
4360 const sctp_subtype_t type,
4361 void *arg,
4362 sctp_cmd_seq_t *commands)
4363{
4364 static const char err_str[]="The following chunk violates protocol:";
4365
4366 if (!asoc)
4367 return sctp_sf_violation(ep, asoc, type, arg, commands);
4368
4369 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4370 sizeof(err_str));
4371}
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
4433 const struct sctp_association *asoc,
4434 const sctp_subtype_t type,
4435 void *arg,
4436 sctp_cmd_seq_t *commands)
4437{
4438 struct sctp_chunk *repl;
4439 struct sctp_association* my_asoc;
4440
4441
4442
4443
4444
4445 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4446 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
4457 if (!repl)
4458 goto nomem;
4459
4460
4461
4462
4463 my_asoc = (struct sctp_association *)asoc;
4464 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(my_asoc));
4465
4466
4467 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4468 SCTP_CHUNK(repl));
4469
4470
4471
4472
4473 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4474 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4475 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4476 return SCTP_DISPOSITION_CONSUME;
4477
4478nomem:
4479 return SCTP_DISPOSITION_NOMEM;
4480}
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
4544 const struct sctp_association *asoc,
4545 const sctp_subtype_t type,
4546 void *arg,
4547 sctp_cmd_seq_t *commands)
4548{
4549 struct sctp_chunk *chunk = arg;
4550
4551 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4552 return SCTP_DISPOSITION_CONSUME;
4553}
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569