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