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