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