1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#ifndef __sctp_structs_h__
48#define __sctp_structs_h__
49
50#include <linux/ktime.h>
51#include <linux/rhashtable-types.h>
52#include <linux/socket.h>
53#include <linux/in.h>
54#include <linux/in6.h>
55#include <linux/ipv6.h>
56#include <asm/param.h>
57#include <linux/atomic.h>
58#include <linux/skbuff.h>
59#include <linux/workqueue.h>
60#include <linux/flex_array.h>
61#include <linux/sctp.h>
62#include <net/sctp/auth.h>
63#include <net/ip.h>
64
65
66
67
68union sctp_addr {
69 struct sockaddr_in v4;
70 struct sockaddr_in6 v6;
71 struct sockaddr sa;
72};
73
74
75struct sctp_globals;
76struct sctp_endpoint;
77struct sctp_association;
78struct sctp_transport;
79struct sctp_packet;
80struct sctp_chunk;
81struct sctp_inq;
82struct sctp_outq;
83struct sctp_bind_addr;
84struct sctp_ulpq;
85struct sctp_ep_common;
86struct crypto_shash;
87struct sctp_stream;
88
89
90#include <net/sctp/tsnmap.h>
91#include <net/sctp/ulpevent.h>
92#include <net/sctp/ulpqueue.h>
93#include <net/sctp/stream_interleave.h>
94
95
96
97struct sctp_bind_bucket {
98 unsigned short port;
99 unsigned short fastreuse;
100 struct hlist_node node;
101 struct hlist_head owner;
102 struct net *net;
103};
104
105struct sctp_bind_hashbucket {
106 spinlock_t lock;
107 struct hlist_head chain;
108};
109
110
111struct sctp_hashbucket {
112 rwlock_t lock;
113 struct hlist_head chain;
114} __attribute__((__aligned__(8)));
115
116
117
118extern struct sctp_globals {
119
120
121
122 struct list_head address_families;
123
124
125 struct sctp_hashbucket *ep_hashtable;
126
127 struct sctp_bind_hashbucket *port_hashtable;
128
129 struct rhltable transport_hashtable;
130
131
132 int ep_hashsize;
133 int port_hashsize;
134
135
136 __u16 max_instreams;
137 __u16 max_outstreams;
138
139
140
141 bool checksum_disable;
142} sctp_globals;
143
144#define sctp_max_instreams (sctp_globals.max_instreams)
145#define sctp_max_outstreams (sctp_globals.max_outstreams)
146#define sctp_address_families (sctp_globals.address_families)
147#define sctp_ep_hashsize (sctp_globals.ep_hashsize)
148#define sctp_ep_hashtable (sctp_globals.ep_hashtable)
149#define sctp_port_hashsize (sctp_globals.port_hashsize)
150#define sctp_port_hashtable (sctp_globals.port_hashtable)
151#define sctp_transport_hashtable (sctp_globals.transport_hashtable)
152#define sctp_checksum_disable (sctp_globals.checksum_disable)
153
154
155enum sctp_socket_type {
156 SCTP_SOCKET_UDP = 0,
157 SCTP_SOCKET_UDP_HIGH_BANDWIDTH,
158 SCTP_SOCKET_TCP
159};
160
161
162struct sctp_sock {
163
164 struct inet_sock inet;
165
166 enum sctp_socket_type type;
167
168
169 struct sctp_pf *pf;
170
171
172 struct crypto_shash *hmac;
173 char *sctp_hmac_alg;
174
175
176 struct sctp_endpoint *ep;
177
178 struct sctp_bind_bucket *bind_hash;
179
180 __u16 default_stream;
181 __u32 default_ppid;
182 __u16 default_flags;
183 __u32 default_context;
184 __u32 default_timetolive;
185 __u32 default_rcv_context;
186 int max_burst;
187
188
189
190
191
192 __u32 hbinterval;
193
194
195 __u16 pathmaxrxt;
196
197 __u32 flowlabel;
198 __u8 dscp;
199
200
201 __u32 pathmtu;
202
203
204 __u32 sackdelay;
205 __u32 sackfreq;
206
207
208 __u32 param_flags;
209
210 struct sctp_rtoinfo rtoinfo;
211 struct sctp_paddrparams paddrparam;
212 struct sctp_assocparams assocparams;
213
214
215
216
217
218 struct sctp_event_subscribe subscribe;
219 struct sctp_initmsg initmsg;
220
221 int user_frag;
222
223 __u32 autoclose;
224 __u32 adaptation_ind;
225 __u32 pd_point;
226 __u16 nodelay:1,
227 reuse:1,
228 disable_fragments:1,
229 v4mapped:1,
230 frag_interleave:1,
231 strm_interleave:1,
232 recvrcvinfo:1,
233 recvnxtinfo:1,
234 data_ready_signalled:1;
235
236 atomic_t pd_mode;
237
238 struct sk_buff_head pd_lobby;
239
240
241
242
243 struct list_head auto_asconf_list;
244 int do_auto_asconf;
245};
246
247static inline struct sctp_sock *sctp_sk(const struct sock *sk)
248{
249 return (struct sctp_sock *)sk;
250}
251
252static inline struct sock *sctp_opt2sk(const struct sctp_sock *sp)
253{
254 return (struct sock *)sp;
255}
256
257#if IS_ENABLED(CONFIG_IPV6)
258struct sctp6_sock {
259 struct sctp_sock sctp;
260 struct ipv6_pinfo inet6;
261};
262#endif
263
264
265
266
267
268
269
270
271
272
273
274struct sctp_cookie {
275
276
277
278
279
280 __u32 my_vtag;
281
282
283
284
285
286 __u32 peer_vtag;
287
288
289
290
291
292
293 __u32 my_ttag;
294
295
296 __u32 peer_ttag;
297
298
299 ktime_t expiration;
300
301
302
303
304 __u16 sinit_num_ostreams;
305 __u16 sinit_max_instreams;
306
307
308 __u32 initial_tsn;
309
310
311 union sctp_addr peer_addr;
312
313
314
315
316 __u16 my_port;
317
318 __u8 prsctp_capable;
319
320
321 __u8 padding;
322
323 __u32 adaptation_ind;
324
325 __u8 auth_random[sizeof(struct sctp_paramhdr) +
326 SCTP_AUTH_RANDOM_LENGTH];
327 __u8 auth_hmacs[SCTP_AUTH_NUM_HMACS * sizeof(__u16) + 2];
328 __u8 auth_chunks[sizeof(struct sctp_paramhdr) + SCTP_AUTH_MAX_CHUNKS];
329
330
331
332
333
334
335
336 __u32 raw_addr_list_len;
337 struct sctp_init_chunk peer_init[0];
338};
339
340
341
342struct sctp_signed_cookie {
343 __u8 signature[SCTP_SECRET_SIZE];
344 __u32 __pad;
345 struct sctp_cookie c;
346} __packed;
347
348
349
350
351
352union sctp_addr_param {
353 struct sctp_paramhdr p;
354 struct sctp_ipv4addr_param v4;
355 struct sctp_ipv6addr_param v6;
356};
357
358
359
360
361union sctp_params {
362 void *v;
363 struct sctp_paramhdr *p;
364 struct sctp_cookie_preserve_param *life;
365 struct sctp_hostname_param *dns;
366 struct sctp_cookie_param *cookie;
367 struct sctp_supported_addrs_param *sat;
368 struct sctp_ipv4addr_param *v4;
369 struct sctp_ipv6addr_param *v6;
370 union sctp_addr_param *addr;
371 struct sctp_adaptation_ind_param *aind;
372 struct sctp_supported_ext_param *ext;
373 struct sctp_random_param *random;
374 struct sctp_chunks_param *chunks;
375 struct sctp_hmac_algo_param *hmac_algo;
376 struct sctp_addip_param *addip;
377};
378
379
380
381
382
383
384
385
386struct sctp_sender_hb_info {
387 struct sctp_paramhdr param_hdr;
388 union sctp_addr daddr;
389 unsigned long sent_at;
390 __u64 hb_nonce;
391};
392
393int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
394 gfp_t gfp);
395int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid);
396void sctp_stream_free(struct sctp_stream *stream);
397void sctp_stream_clear(struct sctp_stream *stream);
398void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new);
399
400
401#define sctp_ssn_peek(stream, type, sid) \
402 (sctp_stream_##type((stream), (sid))->ssn)
403
404
405#define sctp_ssn_next(stream, type, sid) \
406 (sctp_stream_##type((stream), (sid))->ssn++)
407
408
409#define sctp_ssn_skip(stream, type, sid, ssn) \
410 (sctp_stream_##type((stream), (sid))->ssn = ssn + 1)
411
412
413#define sctp_mid_peek(stream, type, sid) \
414 (sctp_stream_##type((stream), (sid))->mid)
415
416
417#define sctp_mid_next(stream, type, sid) \
418 (sctp_stream_##type((stream), (sid))->mid++)
419
420
421#define sctp_mid_skip(stream, type, sid, mid) \
422 (sctp_stream_##type((stream), (sid))->mid = mid + 1)
423
424
425#define sctp_mid_uo_peek(stream, type, sid) \
426 (sctp_stream_##type((stream), (sid))->mid_uo)
427
428
429#define sctp_mid_uo_next(stream, type, sid) \
430 (sctp_stream_##type((stream), (sid))->mid_uo++)
431
432
433
434
435
436struct sctp_af {
437 int (*sctp_xmit) (struct sk_buff *skb,
438 struct sctp_transport *);
439 int (*setsockopt) (struct sock *sk,
440 int level,
441 int optname,
442 char __user *optval,
443 unsigned int optlen);
444 int (*getsockopt) (struct sock *sk,
445 int level,
446 int optname,
447 char __user *optval,
448 int __user *optlen);
449 int (*compat_setsockopt) (struct sock *sk,
450 int level,
451 int optname,
452 char __user *optval,
453 unsigned int optlen);
454 int (*compat_getsockopt) (struct sock *sk,
455 int level,
456 int optname,
457 char __user *optval,
458 int __user *optlen);
459 void (*get_dst) (struct sctp_transport *t,
460 union sctp_addr *saddr,
461 struct flowi *fl,
462 struct sock *sk);
463 void (*get_saddr) (struct sctp_sock *sk,
464 struct sctp_transport *t,
465 struct flowi *fl);
466 void (*copy_addrlist) (struct list_head *,
467 struct net_device *);
468 int (*cmp_addr) (const union sctp_addr *addr1,
469 const union sctp_addr *addr2);
470 void (*addr_copy) (union sctp_addr *dst,
471 union sctp_addr *src);
472 void (*from_skb) (union sctp_addr *,
473 struct sk_buff *skb,
474 int saddr);
475 void (*from_sk) (union sctp_addr *,
476 struct sock *sk);
477 void (*from_addr_param) (union sctp_addr *,
478 union sctp_addr_param *,
479 __be16 port, int iif);
480 int (*to_addr_param) (const union sctp_addr *,
481 union sctp_addr_param *);
482 int (*addr_valid) (union sctp_addr *,
483 struct sctp_sock *,
484 const struct sk_buff *);
485 enum sctp_scope (*scope)(union sctp_addr *);
486 void (*inaddr_any) (union sctp_addr *, __be16);
487 int (*is_any) (const union sctp_addr *);
488 int (*available) (union sctp_addr *,
489 struct sctp_sock *);
490 int (*skb_iif) (const struct sk_buff *sk);
491 int (*is_ce) (const struct sk_buff *sk);
492 void (*seq_dump_addr)(struct seq_file *seq,
493 union sctp_addr *addr);
494 void (*ecn_capable)(struct sock *sk);
495 __u16 net_header_len;
496 int sockaddr_len;
497 int (*ip_options_len)(struct sock *sk);
498 sa_family_t sa_family;
499 struct list_head list;
500};
501
502struct sctp_af *sctp_get_af_specific(sa_family_t);
503int sctp_register_af(struct sctp_af *);
504
505
506struct sctp_pf {
507 void (*event_msgname)(struct sctp_ulpevent *, char *, int *);
508 void (*skb_msgname) (struct sk_buff *, char *, int *);
509 int (*af_supported) (sa_family_t, struct sctp_sock *);
510 int (*cmp_addr) (const union sctp_addr *,
511 const union sctp_addr *,
512 struct sctp_sock *);
513 int (*bind_verify) (struct sctp_sock *, union sctp_addr *);
514 int (*send_verify) (struct sctp_sock *, union sctp_addr *);
515 int (*supported_addrs)(const struct sctp_sock *, __be16 *);
516 struct sock *(*create_accept_sk) (struct sock *sk,
517 struct sctp_association *asoc,
518 bool kern);
519 int (*addr_to_user)(struct sctp_sock *sk, union sctp_addr *addr);
520 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
521 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
522 void (*copy_ip_options)(struct sock *sk, struct sock *newsk);
523 struct sctp_af *af;
524};
525
526
527
528
529
530struct sctp_datamsg {
531
532 struct list_head chunks;
533
534 refcount_t refcnt;
535
536 unsigned long expires_at;
537
538 int send_error;
539 u8 send_failed:1,
540 can_delay:1,
541 abandoned:1;
542};
543
544struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *,
545 struct sctp_sndrcvinfo *,
546 struct iov_iter *);
547void sctp_datamsg_free(struct sctp_datamsg *);
548void sctp_datamsg_put(struct sctp_datamsg *);
549void sctp_chunk_fail(struct sctp_chunk *, int error);
550int sctp_chunk_abandoned(struct sctp_chunk *);
551
552
553
554
555
556
557
558
559
560struct sctp_chunk {
561 struct list_head list;
562
563 refcount_t refcnt;
564
565
566 int sent_count;
567
568 union {
569
570 struct list_head transmitted_list;
571
572 struct list_head stream_list;
573 };
574
575
576
577
578
579
580 struct list_head frag_list;
581
582
583 struct sk_buff *skb;
584
585 union {
586
587 struct sk_buff *head_skb;
588
589 struct sctp_shared_key *shkey;
590 };
591
592
593
594
595
596
597
598
599 union sctp_params param_hdr;
600 union {
601 __u8 *v;
602 struct sctp_datahdr *data_hdr;
603 struct sctp_inithdr *init_hdr;
604 struct sctp_sackhdr *sack_hdr;
605 struct sctp_heartbeathdr *hb_hdr;
606 struct sctp_sender_hb_info *hbs_hdr;
607 struct sctp_shutdownhdr *shutdown_hdr;
608 struct sctp_signed_cookie *cookie_hdr;
609 struct sctp_ecnehdr *ecne_hdr;
610 struct sctp_cwrhdr *ecn_cwr_hdr;
611 struct sctp_errhdr *err_hdr;
612 struct sctp_addiphdr *addip_hdr;
613 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
614 struct sctp_authhdr *auth_hdr;
615 struct sctp_idatahdr *idata_hdr;
616 struct sctp_ifwdtsn_hdr *ifwdtsn_hdr;
617 } subh;
618
619 __u8 *chunk_end;
620
621 struct sctp_chunkhdr *chunk_hdr;
622 struct sctphdr *sctp_hdr;
623
624
625 struct sctp_sndrcvinfo sinfo;
626
627
628 struct sctp_association *asoc;
629
630
631 struct sctp_ep_common *rcvr;
632
633
634 unsigned long sent_at;
635
636
637 union sctp_addr source;
638
639 union sctp_addr dest;
640
641
642 struct sctp_datamsg *msg;
643
644
645
646
647
648 struct sctp_transport *transport;
649
650
651
652
653
654
655 struct sk_buff *auth_chunk;
656
657#define SCTP_CAN_FRTX 0x0
658#define SCTP_NEED_FRTX 0x1
659#define SCTP_DONT_FRTX 0x2
660 __u16 rtt_in_progress:1,
661 has_tsn:1,
662 has_ssn:1,
663#define has_mid has_ssn
664 singleton:1,
665 end_of_packet:1,
666 ecn_ce_done:1,
667 pdiscard:1,
668 tsn_gap_acked:1,
669 data_accepted:1,
670 auth:1,
671 has_asconf:1,
672 tsn_missing_report:2,
673 fast_retransmit:2;
674};
675
676#define sctp_chunk_retransmitted(chunk) (chunk->sent_count > 1)
677void sctp_chunk_hold(struct sctp_chunk *);
678void sctp_chunk_put(struct sctp_chunk *);
679int sctp_user_addto_chunk(struct sctp_chunk *chunk, int len,
680 struct iov_iter *from);
681void sctp_chunk_free(struct sctp_chunk *);
682void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data);
683struct sctp_chunk *sctp_chunkify(struct sk_buff *,
684 const struct sctp_association *,
685 struct sock *, gfp_t gfp);
686void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
687 union sctp_addr *);
688const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);
689
690static inline __u16 sctp_chunk_stream_no(struct sctp_chunk *ch)
691{
692 return ntohs(ch->subh.data_hdr->stream);
693}
694
695enum {
696 SCTP_ADDR_NEW,
697 SCTP_ADDR_SRC,
698 SCTP_ADDR_DEL,
699};
700
701
702struct sctp_sockaddr_entry {
703 struct list_head list;
704 struct rcu_head rcu;
705 union sctp_addr a;
706 __u8 state;
707 __u8 valid;
708};
709
710#define SCTP_ADDRESS_TICK_DELAY 500
711
712
713
714
715struct sctp_packet {
716
717 __u16 source_port;
718 __u16 destination_port;
719 __u32 vtag;
720
721
722 struct list_head chunk_list;
723
724
725 size_t overhead;
726
727 size_t size;
728
729 size_t max_size;
730
731
732
733
734
735 struct sctp_transport *transport;
736
737
738 struct sctp_chunk *auth;
739
740 u8 has_cookie_echo:1,
741 has_sack:1,
742 has_auth:1,
743 has_data:1,
744 ipfragok:1;
745};
746
747void sctp_packet_init(struct sctp_packet *, struct sctp_transport *,
748 __u16 sport, __u16 dport);
749void sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
750enum sctp_xmit sctp_packet_transmit_chunk(struct sctp_packet *packet,
751 struct sctp_chunk *chunk,
752 int one_packet, gfp_t gfp);
753enum sctp_xmit sctp_packet_append_chunk(struct sctp_packet *packet,
754 struct sctp_chunk *chunk);
755int sctp_packet_transmit(struct sctp_packet *, gfp_t);
756void sctp_packet_free(struct sctp_packet *);
757
758static inline int sctp_packet_empty(struct sctp_packet *packet)
759{
760 return packet->size == packet->overhead;
761}
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783struct sctp_transport {
784
785 struct list_head transports;
786 struct rhlist_head node;
787
788
789 refcount_t refcnt;
790
791
792
793
794
795
796
797
798
799 __u32 rto_pending:1,
800
801
802
803
804
805 hb_sent:1,
806
807
808 pmtu_pending:1,
809
810 dst_pending_confirm:1,
811
812
813 sack_generation:1;
814 u32 dst_cookie;
815
816 struct flowi fl;
817
818
819 union sctp_addr ipaddr;
820
821
822 struct sctp_af *af_specific;
823
824
825 struct sctp_association *asoc;
826
827
828
829
830
831
832
833
834
835
836 unsigned long rto;
837
838 __u32 rtt;
839
840
841 __u32 rttvar;
842
843
844 __u32 srtt;
845
846
847
848
849
850 __u32 cwnd;
851
852
853 __u32 ssthresh;
854
855
856
857
858 __u32 partial_bytes_acked;
859
860
861 __u32 flight_size;
862
863 __u32 burst_limited;
864
865
866 struct dst_entry *dst;
867
868 union sctp_addr saddr;
869
870
871
872
873 unsigned long hbinterval;
874
875
876 unsigned long sackdelay;
877 __u32 sackfreq;
878
879 atomic_t mtu_info;
880
881
882
883
884 ktime_t last_time_heard;
885
886
887
888
889 unsigned long last_time_sent;
890
891
892
893
894 unsigned long last_time_ecne_reduced;
895
896
897
898
899
900 __u16 pathmaxrxt;
901
902 __u32 flowlabel;
903 __u8 dscp;
904
905
906
907
908
909 int pf_retrans;
910
911 __u32 pathmtu;
912
913
914 __u32 param_flags;
915
916
917 int init_sent_count;
918
919
920
921
922 int state;
923
924
925
926
927 unsigned short error_count;
928
929
930
931
932
933
934
935 struct timer_list T3_rtx_timer;
936
937
938 struct timer_list hb_timer;
939
940
941 struct timer_list proto_unreach_timer;
942
943
944 struct timer_list reconf_timer;
945
946
947
948
949
950
951 struct list_head transmitted;
952
953
954 struct sctp_packet packet;
955
956
957 struct list_head send_ready;
958
959
960
961
962
963
964
965
966
967 struct {
968
969
970
971 __u32 next_tsn_at_change;
972
973
974 char changeover_active;
975
976
977
978
979
980 char cycling_changeover;
981
982
983
984
985 char cacc_saw_newack;
986 } cacc;
987
988
989 __u64 hb_nonce;
990
991 struct rcu_head rcu;
992};
993
994struct sctp_transport *sctp_transport_new(struct net *, const union sctp_addr *,
995 gfp_t);
996void sctp_transport_set_owner(struct sctp_transport *,
997 struct sctp_association *);
998void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
999 struct sctp_sock *);
1000void sctp_transport_pmtu(struct sctp_transport *, struct sock *sk);
1001void sctp_transport_free(struct sctp_transport *);
1002void sctp_transport_reset_t3_rtx(struct sctp_transport *);
1003void sctp_transport_reset_hb_timer(struct sctp_transport *);
1004void sctp_transport_reset_reconf_timer(struct sctp_transport *transport);
1005int sctp_transport_hold(struct sctp_transport *);
1006void sctp_transport_put(struct sctp_transport *);
1007void sctp_transport_update_rto(struct sctp_transport *, __u32);
1008void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32);
1009void sctp_transport_lower_cwnd(struct sctp_transport *t,
1010 enum sctp_lower_cwnd reason);
1011void sctp_transport_burst_limited(struct sctp_transport *);
1012void sctp_transport_burst_reset(struct sctp_transport *);
1013unsigned long sctp_transport_timeout(struct sctp_transport *);
1014void sctp_transport_reset(struct sctp_transport *t);
1015bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu);
1016void sctp_transport_immediate_rtx(struct sctp_transport *);
1017void sctp_transport_dst_release(struct sctp_transport *t);
1018void sctp_transport_dst_confirm(struct sctp_transport *t);
1019
1020
1021
1022
1023
1024struct sctp_inq {
1025
1026
1027
1028 struct list_head in_chunk_list;
1029
1030
1031
1032 struct sctp_chunk *in_progress;
1033
1034
1035
1036
1037 struct work_struct immediate;
1038};
1039
1040void sctp_inq_init(struct sctp_inq *);
1041void sctp_inq_free(struct sctp_inq *);
1042void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet);
1043struct sctp_chunk *sctp_inq_pop(struct sctp_inq *);
1044struct sctp_chunkhdr *sctp_inq_peek(struct sctp_inq *);
1045void sctp_inq_set_th_handler(struct sctp_inq *, work_func_t);
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066struct sctp_outq {
1067 struct sctp_association *asoc;
1068
1069
1070 struct list_head out_chunk_list;
1071
1072
1073 struct sctp_sched_ops *sched;
1074
1075 unsigned int out_qlen;
1076
1077
1078 unsigned int error;
1079
1080
1081 struct list_head control_chunk_list;
1082
1083
1084
1085
1086 struct list_head sacked;
1087
1088
1089
1090
1091 struct list_head retransmit;
1092
1093
1094
1095
1096 struct list_head abandoned;
1097
1098
1099 __u32 outstanding_bytes;
1100
1101
1102 char fast_rtx;
1103
1104
1105 char cork;
1106};
1107
1108void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
1109void sctp_outq_teardown(struct sctp_outq *);
1110void sctp_outq_free(struct sctp_outq*);
1111void sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk, gfp_t);
1112int sctp_outq_sack(struct sctp_outq *, struct sctp_chunk *);
1113int sctp_outq_is_empty(const struct sctp_outq *);
1114void sctp_outq_restart(struct sctp_outq *);
1115
1116void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
1117 enum sctp_retransmit_reason reason);
1118void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
1119void sctp_outq_uncork(struct sctp_outq *, gfp_t gfp);
1120void sctp_prsctp_prune(struct sctp_association *asoc,
1121 struct sctp_sndrcvinfo *sinfo, int msg_len);
1122void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
1123
1124static inline void sctp_outq_cork(struct sctp_outq *q)
1125{
1126 q->cork = 1;
1127}
1128
1129
1130
1131
1132struct sctp_input_cb {
1133 union {
1134 struct inet_skb_parm h4;
1135#if IS_ENABLED(CONFIG_IPV6)
1136 struct inet6_skb_parm h6;
1137#endif
1138 } header;
1139 struct sctp_chunk *chunk;
1140 struct sctp_af *af;
1141};
1142#define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0]))
1143
1144struct sctp_output_cb {
1145 struct sk_buff *last;
1146};
1147#define SCTP_OUTPUT_CB(__skb) ((struct sctp_output_cb *)&((__skb)->cb[0]))
1148
1149static inline const struct sk_buff *sctp_gso_headskb(const struct sk_buff *skb)
1150{
1151 const struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
1152
1153 return chunk->head_skb ? : skb;
1154}
1155
1156
1157struct sctp_bind_addr {
1158
1159
1160
1161
1162
1163
1164 __u16 port;
1165
1166
1167
1168
1169
1170
1171
1172 struct list_head address_list;
1173};
1174
1175void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
1176void sctp_bind_addr_free(struct sctp_bind_addr *);
1177int sctp_bind_addr_copy(struct net *net, struct sctp_bind_addr *dest,
1178 const struct sctp_bind_addr *src,
1179 enum sctp_scope scope, gfp_t gfp,
1180 int flags);
1181int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
1182 const struct sctp_bind_addr *src,
1183 gfp_t gfp);
1184int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
1185 int new_size, __u8 addr_state, gfp_t gfp);
1186int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
1187int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *,
1188 struct sctp_sock *);
1189int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
1190 struct sctp_sock *, struct sctp_sock *);
1191int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
1192 const union sctp_addr *addr);
1193union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
1194 const union sctp_addr *addrs,
1195 int addrcnt,
1196 struct sctp_sock *opt);
1197union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
1198 int *addrs_len,
1199 gfp_t gfp);
1200int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
1201 __u16 port, gfp_t gfp);
1202
1203enum sctp_scope sctp_scope(const union sctp_addr *addr);
1204int sctp_in_scope(struct net *net, const union sctp_addr *addr,
1205 const enum sctp_scope scope);
1206int sctp_is_any(struct sock *sk, const union sctp_addr *addr);
1207int sctp_is_ep_boundall(struct sock *sk);
1208
1209
1210
1211enum sctp_endpoint_type {
1212 SCTP_EP_TYPE_SOCKET,
1213 SCTP_EP_TYPE_ASSOCIATION,
1214};
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232struct sctp_ep_common {
1233
1234 struct hlist_node node;
1235 int hashent;
1236
1237
1238 enum sctp_endpoint_type type;
1239
1240
1241
1242
1243
1244 refcount_t refcnt;
1245 bool dead;
1246
1247
1248 struct sock *sk;
1249
1250
1251 struct sctp_inq inqueue;
1252
1253
1254
1255
1256
1257
1258 struct sctp_bind_addr bind_addr;
1259};
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281struct sctp_endpoint {
1282
1283 struct sctp_ep_common base;
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295 struct list_head asocs;
1296
1297
1298
1299
1300
1301
1302
1303 __u8 secret_key[SCTP_SECRET_SIZE];
1304
1305
1306
1307
1308
1309
1310
1311 __u8 *digest;
1312
1313
1314 __u32 sndbuf_policy;
1315
1316
1317 __u32 rcvbuf_policy;
1318
1319
1320
1321
1322 struct crypto_shash **auth_hmacs;
1323
1324
1325 struct sctp_hmac_algo_param *auth_hmacs_list;
1326
1327
1328 struct sctp_chunks_param *auth_chunk_list;
1329
1330
1331 struct list_head endpoint_shared_keys;
1332 __u16 active_key_id;
1333 __u8 auth_enable:1,
1334 prsctp_enable:1,
1335 reconf_enable:1;
1336
1337 __u8 strreset_enable;
1338
1339
1340
1341
1342
1343
1344
1345
1346 u32 secid;
1347 u32 peer_secid;
1348};
1349
1350
1351static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base)
1352{
1353 struct sctp_endpoint *ep;
1354
1355 ep = container_of(base, struct sctp_endpoint, base);
1356 return ep;
1357}
1358
1359
1360struct sctp_endpoint *sctp_endpoint_new(struct sock *, gfp_t);
1361void sctp_endpoint_free(struct sctp_endpoint *);
1362void sctp_endpoint_put(struct sctp_endpoint *);
1363void sctp_endpoint_hold(struct sctp_endpoint *);
1364void sctp_endpoint_add_asoc(struct sctp_endpoint *, struct sctp_association *);
1365struct sctp_association *sctp_endpoint_lookup_assoc(
1366 const struct sctp_endpoint *ep,
1367 const union sctp_addr *paddr,
1368 struct sctp_transport **);
1369bool sctp_endpoint_is_peeled_off(struct sctp_endpoint *ep,
1370 const union sctp_addr *paddr);
1371struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *,
1372 struct net *, const union sctp_addr *);
1373bool sctp_has_association(struct net *net, const union sctp_addr *laddr,
1374 const union sctp_addr *paddr);
1375
1376int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep,
1377 const struct sctp_association *asoc,
1378 enum sctp_cid cid, struct sctp_init_chunk *peer_init,
1379 struct sctp_chunk *chunk, struct sctp_chunk **err_chunk);
1380int sctp_process_init(struct sctp_association *, struct sctp_chunk *chunk,
1381 const union sctp_addr *peer,
1382 struct sctp_init_chunk *init, gfp_t gfp);
1383__u32 sctp_generate_tag(const struct sctp_endpoint *);
1384__u32 sctp_generate_tsn(const struct sctp_endpoint *);
1385
1386struct sctp_inithdr_host {
1387 __u32 init_tag;
1388 __u32 a_rwnd;
1389 __u16 num_outbound_streams;
1390 __u16 num_inbound_streams;
1391 __u32 initial_tsn;
1392};
1393
1394struct sctp_stream_priorities {
1395
1396 struct list_head prio_sched;
1397
1398 struct list_head active;
1399
1400 struct sctp_stream_out_ext *next;
1401 __u16 prio;
1402};
1403
1404struct sctp_stream_out_ext {
1405 __u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
1406 __u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
1407 struct list_head outq;
1408 union {
1409 struct {
1410
1411 struct list_head prio_list;
1412 struct sctp_stream_priorities *prio_head;
1413 };
1414
1415 struct {
1416 struct list_head rr_list;
1417 };
1418 };
1419};
1420
1421struct sctp_stream_out {
1422 union {
1423 __u32 mid;
1424 __u16 ssn;
1425 };
1426 __u32 mid_uo;
1427 struct sctp_stream_out_ext *ext;
1428 __u8 state;
1429};
1430
1431struct sctp_stream_in {
1432 union {
1433 __u32 mid;
1434 __u16 ssn;
1435 };
1436 __u32 mid_uo;
1437 __u32 fsn;
1438 __u32 fsn_uo;
1439 char pd_mode;
1440 char pd_mode_uo;
1441};
1442
1443struct sctp_stream {
1444 struct flex_array *out;
1445 struct flex_array *in;
1446 __u16 outcnt;
1447 __u16 incnt;
1448
1449 struct sctp_stream_out *out_curr;
1450 union {
1451
1452 struct {
1453
1454 struct list_head prio_list;
1455 };
1456
1457 struct {
1458
1459 struct list_head rr_list;
1460
1461 struct sctp_stream_out_ext *rr_next;
1462 };
1463 };
1464 struct sctp_stream_interleave *si;
1465};
1466
1467static inline struct sctp_stream_out *sctp_stream_out(
1468 const struct sctp_stream *stream,
1469 __u16 sid)
1470{
1471 return flex_array_get(stream->out, sid);
1472}
1473
1474static inline struct sctp_stream_in *sctp_stream_in(
1475 const struct sctp_stream *stream,
1476 __u16 sid)
1477{
1478 return flex_array_get(stream->in, sid);
1479}
1480
1481#define SCTP_SO(s, i) sctp_stream_out((s), (i))
1482#define SCTP_SI(s, i) sctp_stream_in((s), (i))
1483
1484#define SCTP_STREAM_CLOSED 0x00
1485#define SCTP_STREAM_OPEN 0x01
1486
1487static inline __u16 sctp_datachk_len(const struct sctp_stream *stream)
1488{
1489 return stream->si->data_chunk_len;
1490}
1491
1492static inline __u16 sctp_datahdr_len(const struct sctp_stream *stream)
1493{
1494 return stream->si->data_chunk_len - sizeof(struct sctp_chunkhdr);
1495}
1496
1497static inline __u16 sctp_ftsnchk_len(const struct sctp_stream *stream)
1498{
1499 return stream->si->ftsn_chunk_len;
1500}
1501
1502static inline __u16 sctp_ftsnhdr_len(const struct sctp_stream *stream)
1503{
1504 return stream->si->ftsn_chunk_len - sizeof(struct sctp_chunkhdr);
1505}
1506
1507
1508struct sctp_priv_assoc_stats {
1509
1510
1511
1512
1513
1514 struct sockaddr_storage obs_rto_ipaddr;
1515 __u64 max_obs_rto;
1516
1517 __u64 isacks;
1518 __u64 osacks;
1519
1520 __u64 opackets;
1521 __u64 ipackets;
1522
1523 __u64 rtxchunks;
1524
1525 __u64 outofseqtsns;
1526
1527 __u64 idupchunks;
1528
1529 __u64 gapcnt;
1530
1531 __u64 ouodchunks;
1532 __u64 iuodchunks;
1533
1534 __u64 oodchunks;
1535 __u64 iodchunks;
1536
1537 __u64 octrlchunks;
1538 __u64 ictrlchunks;
1539};
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555struct sctp_association {
1556
1557
1558
1559
1560
1561 struct sctp_ep_common base;
1562
1563
1564 struct list_head asocs;
1565
1566
1567 sctp_assoc_t assoc_id;
1568
1569
1570 struct sctp_endpoint *ep;
1571
1572
1573 struct sctp_cookie c;
1574
1575
1576 struct {
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592 struct list_head transport_addr_list;
1593
1594
1595
1596
1597
1598 __u32 rwnd;
1599
1600
1601
1602
1603
1604
1605
1606
1607 __u16 transport_count;
1608
1609
1610
1611
1612 __u16 port;
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629 struct sctp_transport *primary_path;
1630
1631
1632
1633
1634 union sctp_addr primary_addr;
1635
1636
1637
1638
1639
1640 struct sctp_transport *active_path;
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652 struct sctp_transport *retran_path;
1653
1654
1655 struct sctp_transport *last_sent_to;
1656
1657
1658 struct sctp_transport *last_data_from;
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680 struct sctp_tsnmap tsn_map;
1681
1682
1683
1684
1685 __be16 addip_disabled_mask;
1686
1687
1688 __u8 ecn_capable:1,
1689 ipv4_address:1,
1690 ipv6_address:1,
1691 hostname_address:1,
1692 asconf_capable:1,
1693 prsctp_capable:1,
1694 reconf_capable:1,
1695 auth_capable:1;
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707 __u8 sack_needed:1,
1708 sack_generation:1,
1709 zero_window_announced:1;
1710 __u32 sack_cnt;
1711
1712 __u32 adaptation_ind;
1713
1714 struct sctp_inithdr_host i;
1715 void *cookie;
1716 int cookie_len;
1717
1718
1719
1720
1721
1722 __u32 addip_serial;
1723
1724
1725
1726
1727
1728 struct sctp_random_param *peer_random;
1729 struct sctp_chunks_param *peer_chunks;
1730 struct sctp_hmac_algo_param *peer_hmacs;
1731 } peer;
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746 enum sctp_state state;
1747
1748
1749
1750
1751 int overall_error_count;
1752
1753
1754 ktime_t cookie_life;
1755
1756
1757
1758
1759
1760 unsigned long rto_initial;
1761 unsigned long rto_max;
1762 unsigned long rto_min;
1763
1764
1765 int max_burst;
1766
1767
1768
1769
1770
1771 int max_retrans;
1772
1773
1774
1775
1776
1777 int pf_retrans;
1778
1779
1780 __u16 max_init_attempts;
1781
1782
1783 __u16 init_retries;
1784
1785
1786 unsigned long max_init_timeo;
1787
1788
1789
1790
1791
1792 unsigned long hbinterval;
1793
1794
1795
1796
1797 __u16 pathmaxrxt;
1798
1799 __u32 flowlabel;
1800 __u8 dscp;
1801
1802
1803 __u8 pmtu_pending;
1804
1805
1806
1807
1808 __u32 pathmtu;
1809
1810
1811 __u32 param_flags;
1812
1813 __u32 sackfreq;
1814
1815 unsigned long sackdelay;
1816
1817 unsigned long timeouts[SCTP_NUM_TIMEOUT_TYPES];
1818 struct timer_list timers[SCTP_NUM_TIMEOUT_TYPES];
1819
1820
1821 struct sctp_transport *shutdown_last_sent_to;
1822
1823
1824 struct sctp_transport *init_last_sent_to;
1825
1826
1827 int shutdown_retries;
1828
1829
1830
1831
1832
1833
1834
1835
1836 __u32 next_tsn;
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847 __u32 ctsn_ack_point;
1848
1849
1850 __u32 adv_peer_ack_point;
1851
1852
1853 __u32 highest_sacked;
1854
1855
1856 __u32 fast_recovery_exit;
1857
1858
1859 __u8 fast_recovery;
1860
1861
1862
1863
1864 __u16 unack_data;
1865
1866
1867
1868
1869 __u32 rtx_data_chunks;
1870
1871
1872
1873
1874 __u32 rwnd;
1875
1876
1877 __u32 a_rwnd;
1878
1879
1880
1881
1882 __u32 rwnd_over;
1883
1884
1885
1886
1887
1888 __u32 rwnd_press;
1889
1890
1891
1892
1893
1894 int sndbuf_used;
1895
1896
1897
1898
1899 atomic_t rmem_alloc;
1900
1901
1902
1903
1904 wait_queue_head_t wait;
1905
1906
1907 __u32 frag_point;
1908 __u32 user_frag;
1909
1910
1911 int init_err_counter;
1912
1913
1914 int init_cycle;
1915
1916
1917 __u16 default_stream;
1918 __u16 default_flags;
1919 __u32 default_ppid;
1920 __u32 default_context;
1921 __u32 default_timetolive;
1922
1923
1924 __u32 default_rcv_context;
1925
1926
1927 struct sctp_stream stream;
1928
1929
1930 struct sctp_outq outqueue;
1931
1932
1933
1934
1935 struct sctp_ulpq ulpq;
1936
1937
1938 __u32 last_ecne_tsn;
1939
1940
1941 __u32 last_cwr_tsn;
1942
1943
1944 int numduptsns;
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969 struct sctp_chunk *addip_last_asconf;
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980 struct list_head asconf_ack_list;
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010 struct list_head addip_chunk_list;
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032 __u32 addip_serial;
2033 int src_out_of_asoc_ok;
2034 union sctp_addr *asconf_addr_del_pending;
2035 struct sctp_transport *new_transport;
2036
2037
2038
2039
2040
2041 struct list_head endpoint_shared_keys;
2042
2043
2044
2045
2046 struct sctp_auth_bytes *asoc_shared_key;
2047 struct sctp_shared_key *shkey;
2048
2049
2050
2051
2052 __u16 default_hmac_id;
2053
2054 __u16 active_key_id;
2055
2056 __u8 need_ecne:1,
2057 temp:1,
2058 force_delay:1,
2059 intl_enable:1,
2060 prsctp_enable:1,
2061 reconf_enable:1;
2062
2063 __u8 strreset_enable;
2064 __u8 strreset_outstanding;
2065
2066 __u32 strreset_outseq;
2067 __u32 strreset_inseq;
2068 __u32 strreset_result[2];
2069
2070 struct sctp_chunk *strreset_chunk;
2071
2072 struct sctp_priv_assoc_stats stats;
2073
2074 int sent_cnt_removable;
2075
2076 __u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
2077 __u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
2078
2079 struct rcu_head rcu;
2080};
2081
2082
2083
2084
2085
2086enum {
2087 SCTP_ASSOC_EYECATCHER = 0xa550c123,
2088};
2089
2090
2091static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base)
2092{
2093 struct sctp_association *asoc;
2094
2095 asoc = container_of(base, struct sctp_association, base);
2096 return asoc;
2097}
2098
2099
2100
2101
2102struct sctp_association *
2103sctp_association_new(const struct sctp_endpoint *ep, const struct sock *sk,
2104 enum sctp_scope scope, gfp_t gfp);
2105void sctp_association_free(struct sctp_association *);
2106void sctp_association_put(struct sctp_association *);
2107void sctp_association_hold(struct sctp_association *);
2108
2109struct sctp_transport *sctp_assoc_choose_alter_transport(
2110 struct sctp_association *, struct sctp_transport *);
2111void sctp_assoc_update_retran_path(struct sctp_association *);
2112struct sctp_transport *sctp_assoc_lookup_paddr(const struct sctp_association *,
2113 const union sctp_addr *);
2114int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
2115 const union sctp_addr *laddr);
2116struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *,
2117 const union sctp_addr *address,
2118 const gfp_t gfp,
2119 const int peer_state);
2120void sctp_assoc_del_peer(struct sctp_association *asoc,
2121 const union sctp_addr *addr);
2122void sctp_assoc_rm_peer(struct sctp_association *asoc,
2123 struct sctp_transport *peer);
2124void sctp_assoc_control_transport(struct sctp_association *asoc,
2125 struct sctp_transport *transport,
2126 enum sctp_transport_cmd command,
2127 sctp_sn_error_t error);
2128struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32);
2129void sctp_assoc_migrate(struct sctp_association *, struct sock *);
2130int sctp_assoc_update(struct sctp_association *old,
2131 struct sctp_association *new);
2132
2133__u32 sctp_association_get_next_tsn(struct sctp_association *);
2134
2135void sctp_assoc_update_frag_point(struct sctp_association *asoc);
2136void sctp_assoc_set_pmtu(struct sctp_association *asoc, __u32 pmtu);
2137void sctp_assoc_sync_pmtu(struct sctp_association *asoc);
2138void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned int);
2139void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned int);
2140void sctp_assoc_set_primary(struct sctp_association *,
2141 struct sctp_transport *);
2142void sctp_assoc_del_nonprimary_peers(struct sctp_association *,
2143 struct sctp_transport *);
2144int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
2145 enum sctp_scope scope, gfp_t gfp);
2146int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *,
2147 struct sctp_cookie*,
2148 gfp_t gfp);
2149int sctp_assoc_set_id(struct sctp_association *, gfp_t);
2150void sctp_assoc_clean_asconf_ack_cache(const struct sctp_association *asoc);
2151struct sctp_chunk *sctp_assoc_lookup_asconf_ack(
2152 const struct sctp_association *asoc,
2153 __be32 serial);
2154void sctp_asconf_queue_teardown(struct sctp_association *asoc);
2155
2156int sctp_cmp_addr_exact(const union sctp_addr *ss1,
2157 const union sctp_addr *ss2);
2158struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc);
2159
2160
2161struct sctp_cmsgs {
2162 struct sctp_initmsg *init;
2163 struct sctp_sndrcvinfo *srinfo;
2164 struct sctp_sndinfo *sinfo;
2165 struct sctp_prinfo *prinfo;
2166 struct sctp_authinfo *authinfo;
2167 struct msghdr *addrs_msg;
2168};
2169
2170
2171struct sctp_dbg_objcnt_entry {
2172 char *label;
2173 atomic_t *counter;
2174};
2175
2176#endif
2177