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