1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /* SCTP kernel implementation
3*4882a593Smuzhiyun * (C) Copyright IBM Corp. 2001, 2004
4*4882a593Smuzhiyun * Copyright (c) 1999-2000 Cisco, Inc.
5*4882a593Smuzhiyun * Copyright (c) 1999-2001 Motorola, Inc.
6*4882a593Smuzhiyun * Copyright (c) 2001 Intel Corp.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * This file is part of the SCTP kernel implementation
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Please send any bug reports or fixes you make to the
11*4882a593Smuzhiyun * email addresses:
12*4882a593Smuzhiyun * lksctp developers <linux-sctp@vger.kernel.org>
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * Written or modified by:
15*4882a593Smuzhiyun * Randall Stewart <randall@sctp.chicago.il.us>
16*4882a593Smuzhiyun * Ken Morneau <kmorneau@cisco.com>
17*4882a593Smuzhiyun * Qiaobing Xie <qxie1@email.mot.com>
18*4882a593Smuzhiyun * La Monte H.P. Yarroll <piggy@acm.org>
19*4882a593Smuzhiyun * Karl Knutson <karl@athena.chicago.il.us>
20*4882a593Smuzhiyun * Jon Grimm <jgrimm@us.ibm.com>
21*4882a593Smuzhiyun * Xingang Guo <xingang.guo@intel.com>
22*4882a593Smuzhiyun * Hui Huang <hui.huang@nokia.com>
23*4882a593Smuzhiyun * Sridhar Samudrala <sri@us.ibm.com>
24*4882a593Smuzhiyun * Daisy Chang <daisyc@us.ibm.com>
25*4882a593Smuzhiyun * Dajiang Zhang <dajiang.zhang@nokia.com>
26*4882a593Smuzhiyun * Ardelle Fan <ardelle.fan@intel.com>
27*4882a593Smuzhiyun * Ryan Layer <rmlayer@us.ibm.com>
28*4882a593Smuzhiyun * Anup Pemmaiah <pemmaiah@cc.usu.edu>
29*4882a593Smuzhiyun * Kevin Gao <kevin.gao@intel.com>
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #ifndef __sctp_structs_h__
33*4882a593Smuzhiyun #define __sctp_structs_h__
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #include <linux/ktime.h>
36*4882a593Smuzhiyun #include <linux/generic-radix-tree.h>
37*4882a593Smuzhiyun #include <linux/rhashtable-types.h>
38*4882a593Smuzhiyun #include <linux/socket.h> /* linux/in.h needs this!! */
39*4882a593Smuzhiyun #include <linux/in.h> /* We get struct sockaddr_in. */
40*4882a593Smuzhiyun #include <linux/in6.h> /* We get struct in6_addr */
41*4882a593Smuzhiyun #include <linux/ipv6.h>
42*4882a593Smuzhiyun #include <asm/param.h> /* We get MAXHOSTNAMELEN. */
43*4882a593Smuzhiyun #include <linux/atomic.h> /* This gets us atomic counters. */
44*4882a593Smuzhiyun #include <linux/skbuff.h> /* We need sk_buff_head. */
45*4882a593Smuzhiyun #include <linux/workqueue.h> /* We need tq_struct. */
46*4882a593Smuzhiyun #include <linux/sctp.h> /* We need sctp* header structs. */
47*4882a593Smuzhiyun #include <net/sctp/auth.h> /* We need auth specific structs */
48*4882a593Smuzhiyun #include <net/ip.h> /* For inet_skb_parm */
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun /* A convenience structure for handling sockaddr structures.
51*4882a593Smuzhiyun * We should wean ourselves off this.
52*4882a593Smuzhiyun */
53*4882a593Smuzhiyun union sctp_addr {
54*4882a593Smuzhiyun struct sockaddr_in v4;
55*4882a593Smuzhiyun struct sockaddr_in6 v6;
56*4882a593Smuzhiyun struct sockaddr sa;
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* Forward declarations for data structures. */
60*4882a593Smuzhiyun struct sctp_globals;
61*4882a593Smuzhiyun struct sctp_endpoint;
62*4882a593Smuzhiyun struct sctp_association;
63*4882a593Smuzhiyun struct sctp_transport;
64*4882a593Smuzhiyun struct sctp_packet;
65*4882a593Smuzhiyun struct sctp_chunk;
66*4882a593Smuzhiyun struct sctp_inq;
67*4882a593Smuzhiyun struct sctp_outq;
68*4882a593Smuzhiyun struct sctp_bind_addr;
69*4882a593Smuzhiyun struct sctp_ulpq;
70*4882a593Smuzhiyun struct sctp_ep_common;
71*4882a593Smuzhiyun struct crypto_shash;
72*4882a593Smuzhiyun struct sctp_stream;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun #include <net/sctp/tsnmap.h>
76*4882a593Smuzhiyun #include <net/sctp/ulpevent.h>
77*4882a593Smuzhiyun #include <net/sctp/ulpqueue.h>
78*4882a593Smuzhiyun #include <net/sctp/stream_interleave.h>
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /* Structures useful for managing bind/connect. */
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun struct sctp_bind_bucket {
83*4882a593Smuzhiyun unsigned short port;
84*4882a593Smuzhiyun signed char fastreuse;
85*4882a593Smuzhiyun signed char fastreuseport;
86*4882a593Smuzhiyun kuid_t fastuid;
87*4882a593Smuzhiyun struct hlist_node node;
88*4882a593Smuzhiyun struct hlist_head owner;
89*4882a593Smuzhiyun struct net *net;
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun struct sctp_bind_hashbucket {
93*4882a593Smuzhiyun spinlock_t lock;
94*4882a593Smuzhiyun struct hlist_head chain;
95*4882a593Smuzhiyun };
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun /* Used for hashing all associations. */
98*4882a593Smuzhiyun struct sctp_hashbucket {
99*4882a593Smuzhiyun rwlock_t lock;
100*4882a593Smuzhiyun struct hlist_head chain;
101*4882a593Smuzhiyun } __attribute__((__aligned__(8)));
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun /* The SCTP globals structure. */
105*4882a593Smuzhiyun extern struct sctp_globals {
106*4882a593Smuzhiyun /* This is a list of groups of functions for each address
107*4882a593Smuzhiyun * family that we support.
108*4882a593Smuzhiyun */
109*4882a593Smuzhiyun struct list_head address_families;
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun /* This is the hash of all endpoints. */
112*4882a593Smuzhiyun struct sctp_hashbucket *ep_hashtable;
113*4882a593Smuzhiyun /* This is the sctp port control hash. */
114*4882a593Smuzhiyun struct sctp_bind_hashbucket *port_hashtable;
115*4882a593Smuzhiyun /* This is the hash of all transports. */
116*4882a593Smuzhiyun struct rhltable transport_hashtable;
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun /* Sizes of above hashtables. */
119*4882a593Smuzhiyun int ep_hashsize;
120*4882a593Smuzhiyun int port_hashsize;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun /* Default initialization values to be applied to new associations. */
123*4882a593Smuzhiyun __u16 max_instreams;
124*4882a593Smuzhiyun __u16 max_outstreams;
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /* Flag to indicate whether computing and verifying checksum
127*4882a593Smuzhiyun * is disabled. */
128*4882a593Smuzhiyun bool checksum_disable;
129*4882a593Smuzhiyun } sctp_globals;
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun #define sctp_max_instreams (sctp_globals.max_instreams)
132*4882a593Smuzhiyun #define sctp_max_outstreams (sctp_globals.max_outstreams)
133*4882a593Smuzhiyun #define sctp_address_families (sctp_globals.address_families)
134*4882a593Smuzhiyun #define sctp_ep_hashsize (sctp_globals.ep_hashsize)
135*4882a593Smuzhiyun #define sctp_ep_hashtable (sctp_globals.ep_hashtable)
136*4882a593Smuzhiyun #define sctp_port_hashsize (sctp_globals.port_hashsize)
137*4882a593Smuzhiyun #define sctp_port_hashtable (sctp_globals.port_hashtable)
138*4882a593Smuzhiyun #define sctp_transport_hashtable (sctp_globals.transport_hashtable)
139*4882a593Smuzhiyun #define sctp_checksum_disable (sctp_globals.checksum_disable)
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun /* SCTP Socket type: UDP or TCP style. */
142*4882a593Smuzhiyun enum sctp_socket_type {
143*4882a593Smuzhiyun SCTP_SOCKET_UDP = 0,
144*4882a593Smuzhiyun SCTP_SOCKET_UDP_HIGH_BANDWIDTH,
145*4882a593Smuzhiyun SCTP_SOCKET_TCP
146*4882a593Smuzhiyun };
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun /* Per socket SCTP information. */
149*4882a593Smuzhiyun struct sctp_sock {
150*4882a593Smuzhiyun /* inet_sock has to be the first member of sctp_sock */
151*4882a593Smuzhiyun struct inet_sock inet;
152*4882a593Smuzhiyun /* What kind of a socket is this? */
153*4882a593Smuzhiyun enum sctp_socket_type type;
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun /* PF_ family specific functions. */
156*4882a593Smuzhiyun struct sctp_pf *pf;
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /* Access to HMAC transform. */
159*4882a593Smuzhiyun struct crypto_shash *hmac;
160*4882a593Smuzhiyun char *sctp_hmac_alg;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun /* What is our base endpointer? */
163*4882a593Smuzhiyun struct sctp_endpoint *ep;
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun struct sctp_bind_bucket *bind_hash;
166*4882a593Smuzhiyun /* Various Socket Options. */
167*4882a593Smuzhiyun __u16 default_stream;
168*4882a593Smuzhiyun __u32 default_ppid;
169*4882a593Smuzhiyun __u16 default_flags;
170*4882a593Smuzhiyun __u32 default_context;
171*4882a593Smuzhiyun __u32 default_timetolive;
172*4882a593Smuzhiyun __u32 default_rcv_context;
173*4882a593Smuzhiyun int max_burst;
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
176*4882a593Smuzhiyun * the destination address every heartbeat interval. This value
177*4882a593Smuzhiyun * will be inherited by all new associations.
178*4882a593Smuzhiyun */
179*4882a593Smuzhiyun __u32 hbinterval;
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun /* This is the max_retrans value for new associations. */
182*4882a593Smuzhiyun __u16 pathmaxrxt;
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun __u32 flowlabel;
185*4882a593Smuzhiyun __u8 dscp;
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun __u16 pf_retrans;
188*4882a593Smuzhiyun __u16 ps_retrans;
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun /* The initial Path MTU to use for new associations. */
191*4882a593Smuzhiyun __u32 pathmtu;
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun /* The default SACK delay timeout for new associations. */
194*4882a593Smuzhiyun __u32 sackdelay;
195*4882a593Smuzhiyun __u32 sackfreq;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
198*4882a593Smuzhiyun __u32 param_flags;
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun __u32 default_ss;
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun struct sctp_rtoinfo rtoinfo;
203*4882a593Smuzhiyun struct sctp_paddrparams paddrparam;
204*4882a593Smuzhiyun struct sctp_assocparams assocparams;
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun /*
207*4882a593Smuzhiyun * These two structures must be grouped together for the usercopy
208*4882a593Smuzhiyun * whitelist region.
209*4882a593Smuzhiyun */
210*4882a593Smuzhiyun __u16 subscribe;
211*4882a593Smuzhiyun struct sctp_initmsg initmsg;
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun int user_frag;
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun __u32 autoclose;
216*4882a593Smuzhiyun __u32 adaptation_ind;
217*4882a593Smuzhiyun __u32 pd_point;
218*4882a593Smuzhiyun __u16 nodelay:1,
219*4882a593Smuzhiyun pf_expose:2,
220*4882a593Smuzhiyun reuse:1,
221*4882a593Smuzhiyun disable_fragments:1,
222*4882a593Smuzhiyun v4mapped:1,
223*4882a593Smuzhiyun frag_interleave:1,
224*4882a593Smuzhiyun recvrcvinfo:1,
225*4882a593Smuzhiyun recvnxtinfo:1,
226*4882a593Smuzhiyun data_ready_signalled:1;
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun atomic_t pd_mode;
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun /* Fields after this point will be skipped on copies, like on accept
231*4882a593Smuzhiyun * and peeloff operations
232*4882a593Smuzhiyun */
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun /* Receive to here while partial delivery is in effect. */
235*4882a593Smuzhiyun struct sk_buff_head pd_lobby;
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun struct list_head auto_asconf_list;
238*4882a593Smuzhiyun int do_auto_asconf;
239*4882a593Smuzhiyun };
240*4882a593Smuzhiyun
sctp_sk(const struct sock * sk)241*4882a593Smuzhiyun static inline struct sctp_sock *sctp_sk(const struct sock *sk)
242*4882a593Smuzhiyun {
243*4882a593Smuzhiyun return (struct sctp_sock *)sk;
244*4882a593Smuzhiyun }
245*4882a593Smuzhiyun
sctp_opt2sk(const struct sctp_sock * sp)246*4882a593Smuzhiyun static inline struct sock *sctp_opt2sk(const struct sctp_sock *sp)
247*4882a593Smuzhiyun {
248*4882a593Smuzhiyun return (struct sock *)sp;
249*4882a593Smuzhiyun }
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_IPV6)
252*4882a593Smuzhiyun struct sctp6_sock {
253*4882a593Smuzhiyun struct sctp_sock sctp;
254*4882a593Smuzhiyun struct ipv6_pinfo inet6;
255*4882a593Smuzhiyun };
256*4882a593Smuzhiyun #endif /* CONFIG_IPV6 */
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun /* This is our APPLICATION-SPECIFIC state cookie.
260*4882a593Smuzhiyun * THIS IS NOT DICTATED BY THE SPECIFICATION.
261*4882a593Smuzhiyun */
262*4882a593Smuzhiyun /* These are the parts of an association which we send in the cookie.
263*4882a593Smuzhiyun * Most of these are straight out of:
264*4882a593Smuzhiyun * RFC2960 12.2 Parameters necessary per association (i.e. the TCB)
265*4882a593Smuzhiyun *
266*4882a593Smuzhiyun */
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun struct sctp_cookie {
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun /* My : Tag expected in every inbound packet and sent
271*4882a593Smuzhiyun * Verification: in the INIT or INIT ACK chunk.
272*4882a593Smuzhiyun * Tag :
273*4882a593Smuzhiyun */
274*4882a593Smuzhiyun __u32 my_vtag;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun /* Peer's : Tag expected in every outbound packet except
277*4882a593Smuzhiyun * Verification: in the INIT chunk.
278*4882a593Smuzhiyun * Tag :
279*4882a593Smuzhiyun */
280*4882a593Smuzhiyun __u32 peer_vtag;
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun /* The rest of these are not from the spec, but really need to
283*4882a593Smuzhiyun * be in the cookie.
284*4882a593Smuzhiyun */
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun /* My Tie Tag : Assist in discovering a restarting association. */
287*4882a593Smuzhiyun __u32 my_ttag;
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun /* Peer's Tie Tag: Assist in discovering a restarting association. */
290*4882a593Smuzhiyun __u32 peer_ttag;
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun /* When does this cookie expire? */
293*4882a593Smuzhiyun ktime_t expiration;
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun /* Number of inbound/outbound streams which are set
296*4882a593Smuzhiyun * and negotiated during the INIT process.
297*4882a593Smuzhiyun */
298*4882a593Smuzhiyun __u16 sinit_num_ostreams;
299*4882a593Smuzhiyun __u16 sinit_max_instreams;
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun /* This is the first sequence number I used. */
302*4882a593Smuzhiyun __u32 initial_tsn;
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun /* This holds the originating address of the INIT packet. */
305*4882a593Smuzhiyun union sctp_addr peer_addr;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun /* IG Section 2.35.3
308*4882a593Smuzhiyun * Include the source port of the INIT-ACK
309*4882a593Smuzhiyun */
310*4882a593Smuzhiyun __u16 my_port;
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun __u8 prsctp_capable;
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun /* Padding for future use */
315*4882a593Smuzhiyun __u8 padding;
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun __u32 adaptation_ind;
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun __u8 auth_random[sizeof(struct sctp_paramhdr) +
320*4882a593Smuzhiyun SCTP_AUTH_RANDOM_LENGTH];
321*4882a593Smuzhiyun __u8 auth_hmacs[SCTP_AUTH_NUM_HMACS * sizeof(__u16) + 2];
322*4882a593Smuzhiyun __u8 auth_chunks[sizeof(struct sctp_paramhdr) + SCTP_AUTH_MAX_CHUNKS];
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun /* This is a shim for my peer's INIT packet, followed by
325*4882a593Smuzhiyun * a copy of the raw address list of the association.
326*4882a593Smuzhiyun * The length of the raw address list is saved in the
327*4882a593Smuzhiyun * raw_addr_list_len field, which will be used at the time when
328*4882a593Smuzhiyun * the association TCB is re-constructed from the cookie.
329*4882a593Smuzhiyun */
330*4882a593Smuzhiyun __u32 raw_addr_list_len;
331*4882a593Smuzhiyun struct sctp_init_chunk peer_init[];
332*4882a593Smuzhiyun };
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun /* The format of our cookie that we send to our peer. */
336*4882a593Smuzhiyun struct sctp_signed_cookie {
337*4882a593Smuzhiyun __u8 signature[SCTP_SECRET_SIZE];
338*4882a593Smuzhiyun __u32 __pad; /* force sctp_cookie alignment to 64 bits */
339*4882a593Smuzhiyun struct sctp_cookie c;
340*4882a593Smuzhiyun } __packed;
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun /* This is another convenience type to allocate memory for address
343*4882a593Smuzhiyun * params for the maximum size and pass such structures around
344*4882a593Smuzhiyun * internally.
345*4882a593Smuzhiyun */
346*4882a593Smuzhiyun union sctp_addr_param {
347*4882a593Smuzhiyun struct sctp_paramhdr p;
348*4882a593Smuzhiyun struct sctp_ipv4addr_param v4;
349*4882a593Smuzhiyun struct sctp_ipv6addr_param v6;
350*4882a593Smuzhiyun };
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun /* A convenience type to allow walking through the various
353*4882a593Smuzhiyun * parameters and avoid casting all over the place.
354*4882a593Smuzhiyun */
355*4882a593Smuzhiyun union sctp_params {
356*4882a593Smuzhiyun void *v;
357*4882a593Smuzhiyun struct sctp_paramhdr *p;
358*4882a593Smuzhiyun struct sctp_cookie_preserve_param *life;
359*4882a593Smuzhiyun struct sctp_hostname_param *dns;
360*4882a593Smuzhiyun struct sctp_cookie_param *cookie;
361*4882a593Smuzhiyun struct sctp_supported_addrs_param *sat;
362*4882a593Smuzhiyun struct sctp_ipv4addr_param *v4;
363*4882a593Smuzhiyun struct sctp_ipv6addr_param *v6;
364*4882a593Smuzhiyun union sctp_addr_param *addr;
365*4882a593Smuzhiyun struct sctp_adaptation_ind_param *aind;
366*4882a593Smuzhiyun struct sctp_supported_ext_param *ext;
367*4882a593Smuzhiyun struct sctp_random_param *random;
368*4882a593Smuzhiyun struct sctp_chunks_param *chunks;
369*4882a593Smuzhiyun struct sctp_hmac_algo_param *hmac_algo;
370*4882a593Smuzhiyun struct sctp_addip_param *addip;
371*4882a593Smuzhiyun };
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun /* RFC 2960. Section 3.3.5 Heartbeat.
374*4882a593Smuzhiyun * Heartbeat Information: variable length
375*4882a593Smuzhiyun * The Sender-specific Heartbeat Info field should normally include
376*4882a593Smuzhiyun * information about the sender's current time when this HEARTBEAT
377*4882a593Smuzhiyun * chunk is sent and the destination transport address to which this
378*4882a593Smuzhiyun * HEARTBEAT is sent (see Section 8.3).
379*4882a593Smuzhiyun */
380*4882a593Smuzhiyun struct sctp_sender_hb_info {
381*4882a593Smuzhiyun struct sctp_paramhdr param_hdr;
382*4882a593Smuzhiyun union sctp_addr daddr;
383*4882a593Smuzhiyun unsigned long sent_at;
384*4882a593Smuzhiyun __u64 hb_nonce;
385*4882a593Smuzhiyun };
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
388*4882a593Smuzhiyun gfp_t gfp);
389*4882a593Smuzhiyun int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid);
390*4882a593Smuzhiyun void sctp_stream_free(struct sctp_stream *stream);
391*4882a593Smuzhiyun void sctp_stream_clear(struct sctp_stream *stream);
392*4882a593Smuzhiyun void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new);
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun /* What is the current SSN number for this stream? */
395*4882a593Smuzhiyun #define sctp_ssn_peek(stream, type, sid) \
396*4882a593Smuzhiyun (sctp_stream_##type((stream), (sid))->ssn)
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun /* Return the next SSN number for this stream. */
399*4882a593Smuzhiyun #define sctp_ssn_next(stream, type, sid) \
400*4882a593Smuzhiyun (sctp_stream_##type((stream), (sid))->ssn++)
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun /* Skip over this ssn and all below. */
403*4882a593Smuzhiyun #define sctp_ssn_skip(stream, type, sid, ssn) \
404*4882a593Smuzhiyun (sctp_stream_##type((stream), (sid))->ssn = ssn + 1)
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun /* What is the current MID number for this stream? */
407*4882a593Smuzhiyun #define sctp_mid_peek(stream, type, sid) \
408*4882a593Smuzhiyun (sctp_stream_##type((stream), (sid))->mid)
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun /* Return the next MID number for this stream. */
411*4882a593Smuzhiyun #define sctp_mid_next(stream, type, sid) \
412*4882a593Smuzhiyun (sctp_stream_##type((stream), (sid))->mid++)
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun /* Skip over this mid and all below. */
415*4882a593Smuzhiyun #define sctp_mid_skip(stream, type, sid, mid) \
416*4882a593Smuzhiyun (sctp_stream_##type((stream), (sid))->mid = mid + 1)
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun /* What is the current MID_uo number for this stream? */
419*4882a593Smuzhiyun #define sctp_mid_uo_peek(stream, type, sid) \
420*4882a593Smuzhiyun (sctp_stream_##type((stream), (sid))->mid_uo)
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun /* Return the next MID_uo number for this stream. */
423*4882a593Smuzhiyun #define sctp_mid_uo_next(stream, type, sid) \
424*4882a593Smuzhiyun (sctp_stream_##type((stream), (sid))->mid_uo++)
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun /*
427*4882a593Smuzhiyun * Pointers to address related SCTP functions.
428*4882a593Smuzhiyun * (i.e. things that depend on the address family.)
429*4882a593Smuzhiyun */
430*4882a593Smuzhiyun struct sctp_af {
431*4882a593Smuzhiyun int (*sctp_xmit) (struct sk_buff *skb,
432*4882a593Smuzhiyun struct sctp_transport *);
433*4882a593Smuzhiyun int (*setsockopt) (struct sock *sk,
434*4882a593Smuzhiyun int level,
435*4882a593Smuzhiyun int optname,
436*4882a593Smuzhiyun sockptr_t optval,
437*4882a593Smuzhiyun unsigned int optlen);
438*4882a593Smuzhiyun int (*getsockopt) (struct sock *sk,
439*4882a593Smuzhiyun int level,
440*4882a593Smuzhiyun int optname,
441*4882a593Smuzhiyun char __user *optval,
442*4882a593Smuzhiyun int __user *optlen);
443*4882a593Smuzhiyun void (*get_dst) (struct sctp_transport *t,
444*4882a593Smuzhiyun union sctp_addr *saddr,
445*4882a593Smuzhiyun struct flowi *fl,
446*4882a593Smuzhiyun struct sock *sk);
447*4882a593Smuzhiyun void (*get_saddr) (struct sctp_sock *sk,
448*4882a593Smuzhiyun struct sctp_transport *t,
449*4882a593Smuzhiyun struct flowi *fl);
450*4882a593Smuzhiyun void (*copy_addrlist) (struct list_head *,
451*4882a593Smuzhiyun struct net_device *);
452*4882a593Smuzhiyun int (*cmp_addr) (const union sctp_addr *addr1,
453*4882a593Smuzhiyun const union sctp_addr *addr2);
454*4882a593Smuzhiyun void (*addr_copy) (union sctp_addr *dst,
455*4882a593Smuzhiyun union sctp_addr *src);
456*4882a593Smuzhiyun void (*from_skb) (union sctp_addr *,
457*4882a593Smuzhiyun struct sk_buff *skb,
458*4882a593Smuzhiyun int saddr);
459*4882a593Smuzhiyun void (*from_sk) (union sctp_addr *,
460*4882a593Smuzhiyun struct sock *sk);
461*4882a593Smuzhiyun bool (*from_addr_param) (union sctp_addr *,
462*4882a593Smuzhiyun union sctp_addr_param *,
463*4882a593Smuzhiyun __be16 port, int iif);
464*4882a593Smuzhiyun int (*to_addr_param) (const union sctp_addr *,
465*4882a593Smuzhiyun union sctp_addr_param *);
466*4882a593Smuzhiyun int (*addr_valid) (union sctp_addr *,
467*4882a593Smuzhiyun struct sctp_sock *,
468*4882a593Smuzhiyun const struct sk_buff *);
469*4882a593Smuzhiyun enum sctp_scope (*scope)(union sctp_addr *);
470*4882a593Smuzhiyun void (*inaddr_any) (union sctp_addr *, __be16);
471*4882a593Smuzhiyun int (*is_any) (const union sctp_addr *);
472*4882a593Smuzhiyun int (*available) (union sctp_addr *,
473*4882a593Smuzhiyun struct sctp_sock *);
474*4882a593Smuzhiyun int (*skb_iif) (const struct sk_buff *sk);
475*4882a593Smuzhiyun int (*is_ce) (const struct sk_buff *sk);
476*4882a593Smuzhiyun void (*seq_dump_addr)(struct seq_file *seq,
477*4882a593Smuzhiyun union sctp_addr *addr);
478*4882a593Smuzhiyun void (*ecn_capable)(struct sock *sk);
479*4882a593Smuzhiyun __u16 net_header_len;
480*4882a593Smuzhiyun int sockaddr_len;
481*4882a593Smuzhiyun int (*ip_options_len)(struct sock *sk);
482*4882a593Smuzhiyun sa_family_t sa_family;
483*4882a593Smuzhiyun struct list_head list;
484*4882a593Smuzhiyun };
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun struct sctp_af *sctp_get_af_specific(sa_family_t);
487*4882a593Smuzhiyun int sctp_register_af(struct sctp_af *);
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun /* Protocol family functions. */
490*4882a593Smuzhiyun struct sctp_pf {
491*4882a593Smuzhiyun void (*event_msgname)(struct sctp_ulpevent *, char *, int *);
492*4882a593Smuzhiyun void (*skb_msgname) (struct sk_buff *, char *, int *);
493*4882a593Smuzhiyun int (*af_supported) (sa_family_t, struct sctp_sock *);
494*4882a593Smuzhiyun int (*cmp_addr) (const union sctp_addr *,
495*4882a593Smuzhiyun const union sctp_addr *,
496*4882a593Smuzhiyun struct sctp_sock *);
497*4882a593Smuzhiyun int (*bind_verify) (struct sctp_sock *, union sctp_addr *);
498*4882a593Smuzhiyun int (*send_verify) (struct sctp_sock *, union sctp_addr *);
499*4882a593Smuzhiyun int (*supported_addrs)(const struct sctp_sock *, __be16 *);
500*4882a593Smuzhiyun struct sock *(*create_accept_sk) (struct sock *sk,
501*4882a593Smuzhiyun struct sctp_association *asoc,
502*4882a593Smuzhiyun bool kern);
503*4882a593Smuzhiyun int (*addr_to_user)(struct sctp_sock *sk, union sctp_addr *addr);
504*4882a593Smuzhiyun void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
505*4882a593Smuzhiyun void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
506*4882a593Smuzhiyun void (*copy_ip_options)(struct sock *sk, struct sock *newsk);
507*4882a593Smuzhiyun struct sctp_af *af;
508*4882a593Smuzhiyun };
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun
511*4882a593Smuzhiyun /* Structure to track chunk fragments that have been acked, but peer
512*4882a593Smuzhiyun * fragments of the same message have not.
513*4882a593Smuzhiyun */
514*4882a593Smuzhiyun struct sctp_datamsg {
515*4882a593Smuzhiyun /* Chunks waiting to be submitted to lower layer. */
516*4882a593Smuzhiyun struct list_head chunks;
517*4882a593Smuzhiyun /* Reference counting. */
518*4882a593Smuzhiyun refcount_t refcnt;
519*4882a593Smuzhiyun /* When is this message no longer interesting to the peer? */
520*4882a593Smuzhiyun unsigned long expires_at;
521*4882a593Smuzhiyun /* Did the messenge fail to send? */
522*4882a593Smuzhiyun int send_error;
523*4882a593Smuzhiyun u8 send_failed:1,
524*4882a593Smuzhiyun can_delay:1, /* should this message be Nagle delayed */
525*4882a593Smuzhiyun abandoned:1; /* should this message be abandoned */
526*4882a593Smuzhiyun };
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *,
529*4882a593Smuzhiyun struct sctp_sndrcvinfo *,
530*4882a593Smuzhiyun struct iov_iter *);
531*4882a593Smuzhiyun void sctp_datamsg_free(struct sctp_datamsg *);
532*4882a593Smuzhiyun void sctp_datamsg_put(struct sctp_datamsg *);
533*4882a593Smuzhiyun void sctp_chunk_fail(struct sctp_chunk *, int error);
534*4882a593Smuzhiyun int sctp_chunk_abandoned(struct sctp_chunk *);
535*4882a593Smuzhiyun
536*4882a593Smuzhiyun /* RFC2960 1.4 Key Terms
537*4882a593Smuzhiyun *
538*4882a593Smuzhiyun * o Chunk: A unit of information within an SCTP packet, consisting of
539*4882a593Smuzhiyun * a chunk header and chunk-specific content.
540*4882a593Smuzhiyun *
541*4882a593Smuzhiyun * As a matter of convenience, we remember the SCTP common header for
542*4882a593Smuzhiyun * each chunk as well as a few other header pointers...
543*4882a593Smuzhiyun */
544*4882a593Smuzhiyun struct sctp_chunk {
545*4882a593Smuzhiyun struct list_head list;
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun refcount_t refcnt;
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun /* How many times this chunk have been sent, for prsctp RTX policy */
550*4882a593Smuzhiyun int sent_count;
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun union {
553*4882a593Smuzhiyun /* This is our link to the per-transport transmitted list. */
554*4882a593Smuzhiyun struct list_head transmitted_list;
555*4882a593Smuzhiyun /* List in specific stream outq */
556*4882a593Smuzhiyun struct list_head stream_list;
557*4882a593Smuzhiyun };
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun /* This field is used by chunks that hold fragmented data.
560*4882a593Smuzhiyun * For the first fragment this is the list that holds the rest of
561*4882a593Smuzhiyun * fragments. For the remaining fragments, this is the link to the
562*4882a593Smuzhiyun * frag_list maintained in the first fragment.
563*4882a593Smuzhiyun */
564*4882a593Smuzhiyun struct list_head frag_list;
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun /* This points to the sk_buff containing the actual data. */
567*4882a593Smuzhiyun struct sk_buff *skb;
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun union {
570*4882a593Smuzhiyun /* In case of GSO packets, this will store the head one */
571*4882a593Smuzhiyun struct sk_buff *head_skb;
572*4882a593Smuzhiyun /* In case of auth enabled, this will point to the shkey */
573*4882a593Smuzhiyun struct sctp_shared_key *shkey;
574*4882a593Smuzhiyun };
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun /* These are the SCTP headers by reverse order in a packet.
577*4882a593Smuzhiyun * Note that some of these may happen more than once. In that
578*4882a593Smuzhiyun * case, we point at the "current" one, whatever that means
579*4882a593Smuzhiyun * for that level of header.
580*4882a593Smuzhiyun */
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun /* We point this at the FIRST TLV parameter to chunk_hdr. */
583*4882a593Smuzhiyun union sctp_params param_hdr;
584*4882a593Smuzhiyun union {
585*4882a593Smuzhiyun __u8 *v;
586*4882a593Smuzhiyun struct sctp_datahdr *data_hdr;
587*4882a593Smuzhiyun struct sctp_inithdr *init_hdr;
588*4882a593Smuzhiyun struct sctp_sackhdr *sack_hdr;
589*4882a593Smuzhiyun struct sctp_heartbeathdr *hb_hdr;
590*4882a593Smuzhiyun struct sctp_sender_hb_info *hbs_hdr;
591*4882a593Smuzhiyun struct sctp_shutdownhdr *shutdown_hdr;
592*4882a593Smuzhiyun struct sctp_signed_cookie *cookie_hdr;
593*4882a593Smuzhiyun struct sctp_ecnehdr *ecne_hdr;
594*4882a593Smuzhiyun struct sctp_cwrhdr *ecn_cwr_hdr;
595*4882a593Smuzhiyun struct sctp_errhdr *err_hdr;
596*4882a593Smuzhiyun struct sctp_addiphdr *addip_hdr;
597*4882a593Smuzhiyun struct sctp_fwdtsn_hdr *fwdtsn_hdr;
598*4882a593Smuzhiyun struct sctp_authhdr *auth_hdr;
599*4882a593Smuzhiyun struct sctp_idatahdr *idata_hdr;
600*4882a593Smuzhiyun struct sctp_ifwdtsn_hdr *ifwdtsn_hdr;
601*4882a593Smuzhiyun } subh;
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun __u8 *chunk_end;
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun struct sctp_chunkhdr *chunk_hdr;
606*4882a593Smuzhiyun struct sctphdr *sctp_hdr;
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun /* This needs to be recoverable for SCTP_SEND_FAILED events. */
609*4882a593Smuzhiyun struct sctp_sndrcvinfo sinfo;
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun /* Which association does this belong to? */
612*4882a593Smuzhiyun struct sctp_association *asoc;
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun /* What endpoint received this chunk? */
615*4882a593Smuzhiyun struct sctp_ep_common *rcvr;
616*4882a593Smuzhiyun
617*4882a593Smuzhiyun /* We fill this in if we are calculating RTT. */
618*4882a593Smuzhiyun unsigned long sent_at;
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun /* What is the origin IP address for this chunk? */
621*4882a593Smuzhiyun union sctp_addr source;
622*4882a593Smuzhiyun /* Destination address for this chunk. */
623*4882a593Smuzhiyun union sctp_addr dest;
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun /* For outbound message, track all fragments for SEND_FAILED. */
626*4882a593Smuzhiyun struct sctp_datamsg *msg;
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun /* For an inbound chunk, this tells us where it came from.
629*4882a593Smuzhiyun * For an outbound chunk, it tells us where we'd like it to
630*4882a593Smuzhiyun * go. It is NULL if we have no preference.
631*4882a593Smuzhiyun */
632*4882a593Smuzhiyun struct sctp_transport *transport;
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun /* SCTP-AUTH: For the special case inbound processing of COOKIE-ECHO
635*4882a593Smuzhiyun * we need save a pointer to the AUTH chunk, since the SCTP-AUTH
636*4882a593Smuzhiyun * spec violates the principle premis that all chunks are processed
637*4882a593Smuzhiyun * in order.
638*4882a593Smuzhiyun */
639*4882a593Smuzhiyun struct sk_buff *auth_chunk;
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun #define SCTP_CAN_FRTX 0x0
642*4882a593Smuzhiyun #define SCTP_NEED_FRTX 0x1
643*4882a593Smuzhiyun #define SCTP_DONT_FRTX 0x2
644*4882a593Smuzhiyun __u16 rtt_in_progress:1, /* This chunk used for RTT calc? */
645*4882a593Smuzhiyun has_tsn:1, /* Does this chunk have a TSN yet? */
646*4882a593Smuzhiyun has_ssn:1, /* Does this chunk have a SSN yet? */
647*4882a593Smuzhiyun #define has_mid has_ssn
648*4882a593Smuzhiyun singleton:1, /* Only chunk in the packet? */
649*4882a593Smuzhiyun end_of_packet:1, /* Last chunk in the packet? */
650*4882a593Smuzhiyun ecn_ce_done:1, /* Have we processed the ECN CE bit? */
651*4882a593Smuzhiyun pdiscard:1, /* Discard the whole packet now? */
652*4882a593Smuzhiyun tsn_gap_acked:1, /* Is this chunk acked by a GAP ACK? */
653*4882a593Smuzhiyun data_accepted:1, /* At least 1 chunk accepted */
654*4882a593Smuzhiyun auth:1, /* IN: was auth'ed | OUT: needs auth */
655*4882a593Smuzhiyun has_asconf:1, /* IN: have seen an asconf before */
656*4882a593Smuzhiyun tsn_missing_report:2, /* Data chunk missing counter. */
657*4882a593Smuzhiyun fast_retransmit:2; /* Is this chunk fast retransmitted? */
658*4882a593Smuzhiyun };
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun #define sctp_chunk_retransmitted(chunk) (chunk->sent_count > 1)
661*4882a593Smuzhiyun void sctp_chunk_hold(struct sctp_chunk *);
662*4882a593Smuzhiyun void sctp_chunk_put(struct sctp_chunk *);
663*4882a593Smuzhiyun int sctp_user_addto_chunk(struct sctp_chunk *chunk, int len,
664*4882a593Smuzhiyun struct iov_iter *from);
665*4882a593Smuzhiyun void sctp_chunk_free(struct sctp_chunk *);
666*4882a593Smuzhiyun void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data);
667*4882a593Smuzhiyun struct sctp_chunk *sctp_chunkify(struct sk_buff *,
668*4882a593Smuzhiyun const struct sctp_association *,
669*4882a593Smuzhiyun struct sock *, gfp_t gfp);
670*4882a593Smuzhiyun void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
671*4882a593Smuzhiyun union sctp_addr *);
672*4882a593Smuzhiyun const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);
673*4882a593Smuzhiyun
sctp_chunk_stream_no(struct sctp_chunk * ch)674*4882a593Smuzhiyun static inline __u16 sctp_chunk_stream_no(struct sctp_chunk *ch)
675*4882a593Smuzhiyun {
676*4882a593Smuzhiyun return ntohs(ch->subh.data_hdr->stream);
677*4882a593Smuzhiyun }
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun enum {
680*4882a593Smuzhiyun SCTP_ADDR_NEW, /* new address added to assoc/ep */
681*4882a593Smuzhiyun SCTP_ADDR_SRC, /* address can be used as source */
682*4882a593Smuzhiyun SCTP_ADDR_DEL, /* address about to be deleted */
683*4882a593Smuzhiyun };
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun /* This is a structure for holding either an IPv6 or an IPv4 address. */
686*4882a593Smuzhiyun struct sctp_sockaddr_entry {
687*4882a593Smuzhiyun struct list_head list;
688*4882a593Smuzhiyun struct rcu_head rcu;
689*4882a593Smuzhiyun union sctp_addr a;
690*4882a593Smuzhiyun __u8 state;
691*4882a593Smuzhiyun __u8 valid;
692*4882a593Smuzhiyun };
693*4882a593Smuzhiyun
694*4882a593Smuzhiyun #define SCTP_ADDRESS_TICK_DELAY 500
695*4882a593Smuzhiyun
696*4882a593Smuzhiyun /* This structure holds lists of chunks as we are assembling for
697*4882a593Smuzhiyun * transmission.
698*4882a593Smuzhiyun */
699*4882a593Smuzhiyun struct sctp_packet {
700*4882a593Smuzhiyun /* These are the SCTP header values (host order) for the packet. */
701*4882a593Smuzhiyun __u16 source_port;
702*4882a593Smuzhiyun __u16 destination_port;
703*4882a593Smuzhiyun __u32 vtag;
704*4882a593Smuzhiyun
705*4882a593Smuzhiyun /* This contains the payload chunks. */
706*4882a593Smuzhiyun struct list_head chunk_list;
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun /* This is the overhead of the sctp and ip headers. */
709*4882a593Smuzhiyun size_t overhead;
710*4882a593Smuzhiyun /* This is the total size of all chunks INCLUDING padding. */
711*4882a593Smuzhiyun size_t size;
712*4882a593Smuzhiyun /* This is the maximum size this packet may have */
713*4882a593Smuzhiyun size_t max_size;
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun /* The packet is destined for this transport address.
716*4882a593Smuzhiyun * The function we finally use to pass down to the next lower
717*4882a593Smuzhiyun * layer lives in the transport structure.
718*4882a593Smuzhiyun */
719*4882a593Smuzhiyun struct sctp_transport *transport;
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun /* pointer to the auth chunk for this packet */
722*4882a593Smuzhiyun struct sctp_chunk *auth;
723*4882a593Smuzhiyun
724*4882a593Smuzhiyun u8 has_cookie_echo:1, /* This packet contains a COOKIE-ECHO chunk. */
725*4882a593Smuzhiyun has_sack:1, /* This packet contains a SACK chunk. */
726*4882a593Smuzhiyun has_auth:1, /* This packet contains an AUTH chunk */
727*4882a593Smuzhiyun has_data:1, /* This packet contains at least 1 DATA chunk */
728*4882a593Smuzhiyun ipfragok:1; /* So let ip fragment this packet */
729*4882a593Smuzhiyun };
730*4882a593Smuzhiyun
731*4882a593Smuzhiyun void sctp_packet_init(struct sctp_packet *, struct sctp_transport *,
732*4882a593Smuzhiyun __u16 sport, __u16 dport);
733*4882a593Smuzhiyun void sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
734*4882a593Smuzhiyun enum sctp_xmit sctp_packet_transmit_chunk(struct sctp_packet *packet,
735*4882a593Smuzhiyun struct sctp_chunk *chunk,
736*4882a593Smuzhiyun int one_packet, gfp_t gfp);
737*4882a593Smuzhiyun enum sctp_xmit sctp_packet_append_chunk(struct sctp_packet *packet,
738*4882a593Smuzhiyun struct sctp_chunk *chunk);
739*4882a593Smuzhiyun int sctp_packet_transmit(struct sctp_packet *, gfp_t);
740*4882a593Smuzhiyun void sctp_packet_free(struct sctp_packet *);
741*4882a593Smuzhiyun
sctp_packet_empty(struct sctp_packet * packet)742*4882a593Smuzhiyun static inline int sctp_packet_empty(struct sctp_packet *packet)
743*4882a593Smuzhiyun {
744*4882a593Smuzhiyun return packet->size == packet->overhead;
745*4882a593Smuzhiyun }
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun /* This represents a remote transport address.
748*4882a593Smuzhiyun * For local transport addresses, we just use union sctp_addr.
749*4882a593Smuzhiyun *
750*4882a593Smuzhiyun * RFC2960 Section 1.4 Key Terms
751*4882a593Smuzhiyun *
752*4882a593Smuzhiyun * o Transport address: A Transport Address is traditionally defined
753*4882a593Smuzhiyun * by Network Layer address, Transport Layer protocol and Transport
754*4882a593Smuzhiyun * Layer port number. In the case of SCTP running over IP, a
755*4882a593Smuzhiyun * transport address is defined by the combination of an IP address
756*4882a593Smuzhiyun * and an SCTP port number (where SCTP is the Transport protocol).
757*4882a593Smuzhiyun *
758*4882a593Smuzhiyun * RFC2960 Section 7.1 SCTP Differences from TCP Congestion control
759*4882a593Smuzhiyun *
760*4882a593Smuzhiyun * o The sender keeps a separate congestion control parameter set for
761*4882a593Smuzhiyun * each of the destination addresses it can send to (not each
762*4882a593Smuzhiyun * source-destination pair but for each destination). The parameters
763*4882a593Smuzhiyun * should decay if the address is not used for a long enough time
764*4882a593Smuzhiyun * period.
765*4882a593Smuzhiyun *
766*4882a593Smuzhiyun */
767*4882a593Smuzhiyun struct sctp_transport {
768*4882a593Smuzhiyun /* A list of transports. */
769*4882a593Smuzhiyun struct list_head transports;
770*4882a593Smuzhiyun struct rhlist_head node;
771*4882a593Smuzhiyun
772*4882a593Smuzhiyun /* Reference counting. */
773*4882a593Smuzhiyun refcount_t refcnt;
774*4882a593Smuzhiyun /* RTO-Pending : A flag used to track if one of the DATA
775*4882a593Smuzhiyun * chunks sent to this address is currently being
776*4882a593Smuzhiyun * used to compute a RTT. If this flag is 0,
777*4882a593Smuzhiyun * the next DATA chunk sent to this destination
778*4882a593Smuzhiyun * should be used to compute a RTT and this flag
779*4882a593Smuzhiyun * should be set. Every time the RTT
780*4882a593Smuzhiyun * calculation completes (i.e. the DATA chunk
781*4882a593Smuzhiyun * is SACK'd) clear this flag.
782*4882a593Smuzhiyun */
783*4882a593Smuzhiyun __u32 rto_pending:1,
784*4882a593Smuzhiyun
785*4882a593Smuzhiyun /*
786*4882a593Smuzhiyun * hb_sent : a flag that signals that we have a pending
787*4882a593Smuzhiyun * heartbeat.
788*4882a593Smuzhiyun */
789*4882a593Smuzhiyun hb_sent:1,
790*4882a593Smuzhiyun
791*4882a593Smuzhiyun /* Is the Path MTU update pending on this tranport */
792*4882a593Smuzhiyun pmtu_pending:1,
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun dst_pending_confirm:1, /* need to confirm neighbour */
795*4882a593Smuzhiyun
796*4882a593Smuzhiyun /* Has this transport moved the ctsn since we last sacked */
797*4882a593Smuzhiyun sack_generation:1;
798*4882a593Smuzhiyun u32 dst_cookie;
799*4882a593Smuzhiyun
800*4882a593Smuzhiyun struct flowi fl;
801*4882a593Smuzhiyun
802*4882a593Smuzhiyun /* This is the peer's IP address and port. */
803*4882a593Smuzhiyun union sctp_addr ipaddr;
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun /* These are the functions we call to handle LLP stuff. */
806*4882a593Smuzhiyun struct sctp_af *af_specific;
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun /* Which association do we belong to? */
809*4882a593Smuzhiyun struct sctp_association *asoc;
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun /* RFC2960
812*4882a593Smuzhiyun *
813*4882a593Smuzhiyun * 12.3 Per Transport Address Data
814*4882a593Smuzhiyun *
815*4882a593Smuzhiyun * For each destination transport address in the peer's
816*4882a593Smuzhiyun * address list derived from the INIT or INIT ACK chunk, a
817*4882a593Smuzhiyun * number of data elements needs to be maintained including:
818*4882a593Smuzhiyun */
819*4882a593Smuzhiyun /* RTO : The current retransmission timeout value. */
820*4882a593Smuzhiyun unsigned long rto;
821*4882a593Smuzhiyun
822*4882a593Smuzhiyun __u32 rtt; /* This is the most recent RTT. */
823*4882a593Smuzhiyun
824*4882a593Smuzhiyun /* RTTVAR : The current RTT variation. */
825*4882a593Smuzhiyun __u32 rttvar;
826*4882a593Smuzhiyun
827*4882a593Smuzhiyun /* SRTT : The current smoothed round trip time. */
828*4882a593Smuzhiyun __u32 srtt;
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun /*
831*4882a593Smuzhiyun * These are the congestion stats.
832*4882a593Smuzhiyun */
833*4882a593Smuzhiyun /* cwnd : The current congestion window. */
834*4882a593Smuzhiyun __u32 cwnd; /* This is the actual cwnd. */
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun /* ssthresh : The current slow start threshold value. */
837*4882a593Smuzhiyun __u32 ssthresh;
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun /* partial : The tracking method for increase of cwnd when in
840*4882a593Smuzhiyun * bytes acked : congestion avoidance mode (see Section 6.2.2)
841*4882a593Smuzhiyun */
842*4882a593Smuzhiyun __u32 partial_bytes_acked;
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun /* Data that has been sent, but not acknowledged. */
845*4882a593Smuzhiyun __u32 flight_size;
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun __u32 burst_limited; /* Holds old cwnd when max.burst is applied */
848*4882a593Smuzhiyun
849*4882a593Smuzhiyun /* Destination */
850*4882a593Smuzhiyun struct dst_entry *dst;
851*4882a593Smuzhiyun /* Source address. */
852*4882a593Smuzhiyun union sctp_addr saddr;
853*4882a593Smuzhiyun
854*4882a593Smuzhiyun /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
855*4882a593Smuzhiyun * the destination address every heartbeat interval.
856*4882a593Smuzhiyun */
857*4882a593Smuzhiyun unsigned long hbinterval;
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun /* SACK delay timeout */
860*4882a593Smuzhiyun unsigned long sackdelay;
861*4882a593Smuzhiyun __u32 sackfreq;
862*4882a593Smuzhiyun
863*4882a593Smuzhiyun atomic_t mtu_info;
864*4882a593Smuzhiyun
865*4882a593Smuzhiyun /* When was the last time that we heard from this transport? We use
866*4882a593Smuzhiyun * this to pick new active and retran paths.
867*4882a593Smuzhiyun */
868*4882a593Smuzhiyun ktime_t last_time_heard;
869*4882a593Smuzhiyun
870*4882a593Smuzhiyun /* When was the last time that we sent a chunk using this
871*4882a593Smuzhiyun * transport? We use this to check for idle transports
872*4882a593Smuzhiyun */
873*4882a593Smuzhiyun unsigned long last_time_sent;
874*4882a593Smuzhiyun
875*4882a593Smuzhiyun /* Last time(in jiffies) when cwnd is reduced due to the congestion
876*4882a593Smuzhiyun * indication based on ECNE chunk.
877*4882a593Smuzhiyun */
878*4882a593Smuzhiyun unsigned long last_time_ecne_reduced;
879*4882a593Smuzhiyun
880*4882a593Smuzhiyun /* This is the max_retrans value for the transport and will
881*4882a593Smuzhiyun * be initialized from the assocs value. This can be changed
882*4882a593Smuzhiyun * using the SCTP_SET_PEER_ADDR_PARAMS socket option.
883*4882a593Smuzhiyun */
884*4882a593Smuzhiyun __u16 pathmaxrxt;
885*4882a593Smuzhiyun
886*4882a593Smuzhiyun __u32 flowlabel;
887*4882a593Smuzhiyun __u8 dscp;
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun /* This is the partially failed retrans value for the transport
890*4882a593Smuzhiyun * and will be initialized from the assocs value. This can be changed
891*4882a593Smuzhiyun * using the SCTP_PEER_ADDR_THLDS socket option
892*4882a593Smuzhiyun */
893*4882a593Smuzhiyun __u16 pf_retrans;
894*4882a593Smuzhiyun /* Used for primary path switchover. */
895*4882a593Smuzhiyun __u16 ps_retrans;
896*4882a593Smuzhiyun /* PMTU : The current known path MTU. */
897*4882a593Smuzhiyun __u32 pathmtu;
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
900*4882a593Smuzhiyun __u32 param_flags;
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun /* The number of times INIT has been sent on this transport. */
903*4882a593Smuzhiyun int init_sent_count;
904*4882a593Smuzhiyun
905*4882a593Smuzhiyun /* state : The current state of this destination,
906*4882a593Smuzhiyun * : i.e. SCTP_ACTIVE, SCTP_INACTIVE, SCTP_UNKNOWN.
907*4882a593Smuzhiyun */
908*4882a593Smuzhiyun int state;
909*4882a593Smuzhiyun
910*4882a593Smuzhiyun /* These are the error stats for this destination. */
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun /* Error count : The current error count for this destination. */
913*4882a593Smuzhiyun unsigned short error_count;
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun /* Per : A timer used by each destination.
916*4882a593Smuzhiyun * Destination :
917*4882a593Smuzhiyun * Timer :
918*4882a593Smuzhiyun *
919*4882a593Smuzhiyun * [Everywhere else in the text this is called T3-rtx. -ed]
920*4882a593Smuzhiyun */
921*4882a593Smuzhiyun struct timer_list T3_rtx_timer;
922*4882a593Smuzhiyun
923*4882a593Smuzhiyun /* Heartbeat timer is per destination. */
924*4882a593Smuzhiyun struct timer_list hb_timer;
925*4882a593Smuzhiyun
926*4882a593Smuzhiyun /* Timer to handle ICMP proto unreachable envets */
927*4882a593Smuzhiyun struct timer_list proto_unreach_timer;
928*4882a593Smuzhiyun
929*4882a593Smuzhiyun /* Timer to handler reconf chunk rtx */
930*4882a593Smuzhiyun struct timer_list reconf_timer;
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun /* Since we're using per-destination retransmission timers
933*4882a593Smuzhiyun * (see above), we're also using per-destination "transmitted"
934*4882a593Smuzhiyun * queues. This probably ought to be a private struct
935*4882a593Smuzhiyun * accessible only within the outqueue, but it's not, yet.
936*4882a593Smuzhiyun */
937*4882a593Smuzhiyun struct list_head transmitted;
938*4882a593Smuzhiyun
939*4882a593Smuzhiyun /* We build bundle-able packets for this transport here. */
940*4882a593Smuzhiyun struct sctp_packet packet;
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun /* This is the list of transports that have chunks to send. */
943*4882a593Smuzhiyun struct list_head send_ready;
944*4882a593Smuzhiyun
945*4882a593Smuzhiyun /* State information saved for SFR_CACC algorithm. The key
946*4882a593Smuzhiyun * idea in SFR_CACC is to maintain state at the sender on a
947*4882a593Smuzhiyun * per-destination basis when a changeover happens.
948*4882a593Smuzhiyun * char changeover_active;
949*4882a593Smuzhiyun * char cycling_changeover;
950*4882a593Smuzhiyun * __u32 next_tsn_at_change;
951*4882a593Smuzhiyun * char cacc_saw_newack;
952*4882a593Smuzhiyun */
953*4882a593Smuzhiyun struct {
954*4882a593Smuzhiyun /* An unsigned integer, which stores the next TSN to be
955*4882a593Smuzhiyun * used by the sender, at the moment of changeover.
956*4882a593Smuzhiyun */
957*4882a593Smuzhiyun __u32 next_tsn_at_change;
958*4882a593Smuzhiyun
959*4882a593Smuzhiyun /* A flag which indicates the occurrence of a changeover */
960*4882a593Smuzhiyun char changeover_active;
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun /* A flag which indicates whether the change of primary is
963*4882a593Smuzhiyun * the first switch to this destination address during an
964*4882a593Smuzhiyun * active switch.
965*4882a593Smuzhiyun */
966*4882a593Smuzhiyun char cycling_changeover;
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun /* A temporary flag, which is used during the processing of
969*4882a593Smuzhiyun * a SACK to estimate the causative TSN(s)'s group.
970*4882a593Smuzhiyun */
971*4882a593Smuzhiyun char cacc_saw_newack;
972*4882a593Smuzhiyun } cacc;
973*4882a593Smuzhiyun
974*4882a593Smuzhiyun /* 64-bit random number sent with heartbeat. */
975*4882a593Smuzhiyun __u64 hb_nonce;
976*4882a593Smuzhiyun
977*4882a593Smuzhiyun struct rcu_head rcu;
978*4882a593Smuzhiyun };
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun struct sctp_transport *sctp_transport_new(struct net *, const union sctp_addr *,
981*4882a593Smuzhiyun gfp_t);
982*4882a593Smuzhiyun void sctp_transport_set_owner(struct sctp_transport *,
983*4882a593Smuzhiyun struct sctp_association *);
984*4882a593Smuzhiyun void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
985*4882a593Smuzhiyun struct sctp_sock *);
986*4882a593Smuzhiyun void sctp_transport_pmtu(struct sctp_transport *, struct sock *sk);
987*4882a593Smuzhiyun void sctp_transport_free(struct sctp_transport *);
988*4882a593Smuzhiyun void sctp_transport_reset_t3_rtx(struct sctp_transport *);
989*4882a593Smuzhiyun void sctp_transport_reset_hb_timer(struct sctp_transport *);
990*4882a593Smuzhiyun void sctp_transport_reset_reconf_timer(struct sctp_transport *transport);
991*4882a593Smuzhiyun int sctp_transport_hold(struct sctp_transport *);
992*4882a593Smuzhiyun void sctp_transport_put(struct sctp_transport *);
993*4882a593Smuzhiyun void sctp_transport_update_rto(struct sctp_transport *, __u32);
994*4882a593Smuzhiyun void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32);
995*4882a593Smuzhiyun void sctp_transport_lower_cwnd(struct sctp_transport *t,
996*4882a593Smuzhiyun enum sctp_lower_cwnd reason);
997*4882a593Smuzhiyun void sctp_transport_burst_limited(struct sctp_transport *);
998*4882a593Smuzhiyun void sctp_transport_burst_reset(struct sctp_transport *);
999*4882a593Smuzhiyun unsigned long sctp_transport_timeout(struct sctp_transport *);
1000*4882a593Smuzhiyun void sctp_transport_reset(struct sctp_transport *t);
1001*4882a593Smuzhiyun bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu);
1002*4882a593Smuzhiyun void sctp_transport_immediate_rtx(struct sctp_transport *);
1003*4882a593Smuzhiyun void sctp_transport_dst_release(struct sctp_transport *t);
1004*4882a593Smuzhiyun void sctp_transport_dst_confirm(struct sctp_transport *t);
1005*4882a593Smuzhiyun
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun /* This is the structure we use to queue packets as they come into
1008*4882a593Smuzhiyun * SCTP. We write packets to it and read chunks from it.
1009*4882a593Smuzhiyun */
1010*4882a593Smuzhiyun struct sctp_inq {
1011*4882a593Smuzhiyun /* This is actually a queue of sctp_chunk each
1012*4882a593Smuzhiyun * containing a partially decoded packet.
1013*4882a593Smuzhiyun */
1014*4882a593Smuzhiyun struct list_head in_chunk_list;
1015*4882a593Smuzhiyun /* This is the packet which is currently off the in queue and is
1016*4882a593Smuzhiyun * being worked on through the inbound chunk processing.
1017*4882a593Smuzhiyun */
1018*4882a593Smuzhiyun struct sctp_chunk *in_progress;
1019*4882a593Smuzhiyun
1020*4882a593Smuzhiyun /* This is the delayed task to finish delivering inbound
1021*4882a593Smuzhiyun * messages.
1022*4882a593Smuzhiyun */
1023*4882a593Smuzhiyun struct work_struct immediate;
1024*4882a593Smuzhiyun };
1025*4882a593Smuzhiyun
1026*4882a593Smuzhiyun void sctp_inq_init(struct sctp_inq *);
1027*4882a593Smuzhiyun void sctp_inq_free(struct sctp_inq *);
1028*4882a593Smuzhiyun void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet);
1029*4882a593Smuzhiyun struct sctp_chunk *sctp_inq_pop(struct sctp_inq *);
1030*4882a593Smuzhiyun struct sctp_chunkhdr *sctp_inq_peek(struct sctp_inq *);
1031*4882a593Smuzhiyun void sctp_inq_set_th_handler(struct sctp_inq *, work_func_t);
1032*4882a593Smuzhiyun
1033*4882a593Smuzhiyun /* This is the structure we use to hold outbound chunks. You push
1034*4882a593Smuzhiyun * chunks in and they automatically pop out the other end as bundled
1035*4882a593Smuzhiyun * packets (it calls (*output_handler)()).
1036*4882a593Smuzhiyun *
1037*4882a593Smuzhiyun * This structure covers sections 6.3, 6.4, 6.7, 6.8, 6.10, 7., 8.1,
1038*4882a593Smuzhiyun * and 8.2 of the v13 draft.
1039*4882a593Smuzhiyun *
1040*4882a593Smuzhiyun * It handles retransmissions. The connection to the timeout portion
1041*4882a593Smuzhiyun * of the state machine is through sctp_..._timeout() and timeout_handler.
1042*4882a593Smuzhiyun *
1043*4882a593Smuzhiyun * If you feed it SACKs, it will eat them.
1044*4882a593Smuzhiyun *
1045*4882a593Smuzhiyun * If you give it big chunks, it will fragment them.
1046*4882a593Smuzhiyun *
1047*4882a593Smuzhiyun * It assigns TSN's to data chunks. This happens at the last possible
1048*4882a593Smuzhiyun * instant before transmission.
1049*4882a593Smuzhiyun *
1050*4882a593Smuzhiyun * When free()'d, it empties itself out via output_handler().
1051*4882a593Smuzhiyun */
1052*4882a593Smuzhiyun struct sctp_outq {
1053*4882a593Smuzhiyun struct sctp_association *asoc;
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun /* Data pending that has never been transmitted. */
1056*4882a593Smuzhiyun struct list_head out_chunk_list;
1057*4882a593Smuzhiyun
1058*4882a593Smuzhiyun /* Stream scheduler being used */
1059*4882a593Smuzhiyun struct sctp_sched_ops *sched;
1060*4882a593Smuzhiyun
1061*4882a593Smuzhiyun unsigned int out_qlen; /* Total length of queued data chunks. */
1062*4882a593Smuzhiyun
1063*4882a593Smuzhiyun /* Error of send failed, may used in SCTP_SEND_FAILED event. */
1064*4882a593Smuzhiyun unsigned int error;
1065*4882a593Smuzhiyun
1066*4882a593Smuzhiyun /* These are control chunks we want to send. */
1067*4882a593Smuzhiyun struct list_head control_chunk_list;
1068*4882a593Smuzhiyun
1069*4882a593Smuzhiyun /* These are chunks that have been sacked but are above the
1070*4882a593Smuzhiyun * CTSN, or cumulative tsn ack point.
1071*4882a593Smuzhiyun */
1072*4882a593Smuzhiyun struct list_head sacked;
1073*4882a593Smuzhiyun
1074*4882a593Smuzhiyun /* Put chunks on this list to schedule them for
1075*4882a593Smuzhiyun * retransmission.
1076*4882a593Smuzhiyun */
1077*4882a593Smuzhiyun struct list_head retransmit;
1078*4882a593Smuzhiyun
1079*4882a593Smuzhiyun /* Put chunks on this list to save them for FWD TSN processing as
1080*4882a593Smuzhiyun * they were abandoned.
1081*4882a593Smuzhiyun */
1082*4882a593Smuzhiyun struct list_head abandoned;
1083*4882a593Smuzhiyun
1084*4882a593Smuzhiyun /* How many unackd bytes do we have in-flight? */
1085*4882a593Smuzhiyun __u32 outstanding_bytes;
1086*4882a593Smuzhiyun
1087*4882a593Smuzhiyun /* Are we doing fast-rtx on this queue */
1088*4882a593Smuzhiyun char fast_rtx;
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun /* Corked? */
1091*4882a593Smuzhiyun char cork;
1092*4882a593Smuzhiyun };
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
1095*4882a593Smuzhiyun void sctp_outq_teardown(struct sctp_outq *);
1096*4882a593Smuzhiyun void sctp_outq_free(struct sctp_outq*);
1097*4882a593Smuzhiyun void sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk, gfp_t);
1098*4882a593Smuzhiyun int sctp_outq_sack(struct sctp_outq *, struct sctp_chunk *);
1099*4882a593Smuzhiyun int sctp_outq_is_empty(const struct sctp_outq *);
1100*4882a593Smuzhiyun void sctp_outq_restart(struct sctp_outq *);
1101*4882a593Smuzhiyun
1102*4882a593Smuzhiyun void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
1103*4882a593Smuzhiyun enum sctp_retransmit_reason reason);
1104*4882a593Smuzhiyun void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
1105*4882a593Smuzhiyun void sctp_outq_uncork(struct sctp_outq *, gfp_t gfp);
1106*4882a593Smuzhiyun void sctp_prsctp_prune(struct sctp_association *asoc,
1107*4882a593Smuzhiyun struct sctp_sndrcvinfo *sinfo, int msg_len);
1108*4882a593Smuzhiyun void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
1109*4882a593Smuzhiyun /* Uncork and flush an outqueue. */
sctp_outq_cork(struct sctp_outq * q)1110*4882a593Smuzhiyun static inline void sctp_outq_cork(struct sctp_outq *q)
1111*4882a593Smuzhiyun {
1112*4882a593Smuzhiyun q->cork = 1;
1113*4882a593Smuzhiyun }
1114*4882a593Smuzhiyun
1115*4882a593Smuzhiyun /* SCTP skb control block.
1116*4882a593Smuzhiyun * sctp_input_cb is currently used on rx and sock rx queue
1117*4882a593Smuzhiyun */
1118*4882a593Smuzhiyun struct sctp_input_cb {
1119*4882a593Smuzhiyun union {
1120*4882a593Smuzhiyun struct inet_skb_parm h4;
1121*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_IPV6)
1122*4882a593Smuzhiyun struct inet6_skb_parm h6;
1123*4882a593Smuzhiyun #endif
1124*4882a593Smuzhiyun } header;
1125*4882a593Smuzhiyun struct sctp_chunk *chunk;
1126*4882a593Smuzhiyun struct sctp_af *af;
1127*4882a593Smuzhiyun };
1128*4882a593Smuzhiyun #define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0]))
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun struct sctp_output_cb {
1131*4882a593Smuzhiyun struct sk_buff *last;
1132*4882a593Smuzhiyun };
1133*4882a593Smuzhiyun #define SCTP_OUTPUT_CB(__skb) ((struct sctp_output_cb *)&((__skb)->cb[0]))
1134*4882a593Smuzhiyun
sctp_gso_headskb(const struct sk_buff * skb)1135*4882a593Smuzhiyun static inline const struct sk_buff *sctp_gso_headskb(const struct sk_buff *skb)
1136*4882a593Smuzhiyun {
1137*4882a593Smuzhiyun const struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
1138*4882a593Smuzhiyun
1139*4882a593Smuzhiyun return chunk->head_skb ? : skb;
1140*4882a593Smuzhiyun }
1141*4882a593Smuzhiyun
1142*4882a593Smuzhiyun /* These bind address data fields common between endpoints and associations */
1143*4882a593Smuzhiyun struct sctp_bind_addr {
1144*4882a593Smuzhiyun
1145*4882a593Smuzhiyun /* RFC 2960 12.1 Parameters necessary for the SCTP instance
1146*4882a593Smuzhiyun *
1147*4882a593Smuzhiyun * SCTP Port: The local SCTP port number the endpoint is
1148*4882a593Smuzhiyun * bound to.
1149*4882a593Smuzhiyun */
1150*4882a593Smuzhiyun __u16 port;
1151*4882a593Smuzhiyun
1152*4882a593Smuzhiyun /* RFC 2960 12.1 Parameters necessary for the SCTP instance
1153*4882a593Smuzhiyun *
1154*4882a593Smuzhiyun * Address List: The list of IP addresses that this instance
1155*4882a593Smuzhiyun * has bound. This information is passed to one's
1156*4882a593Smuzhiyun * peer(s) in INIT and INIT ACK chunks.
1157*4882a593Smuzhiyun */
1158*4882a593Smuzhiyun struct list_head address_list;
1159*4882a593Smuzhiyun };
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
1162*4882a593Smuzhiyun void sctp_bind_addr_free(struct sctp_bind_addr *);
1163*4882a593Smuzhiyun int sctp_bind_addr_copy(struct net *net, struct sctp_bind_addr *dest,
1164*4882a593Smuzhiyun const struct sctp_bind_addr *src,
1165*4882a593Smuzhiyun enum sctp_scope scope, gfp_t gfp,
1166*4882a593Smuzhiyun int flags);
1167*4882a593Smuzhiyun int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
1168*4882a593Smuzhiyun const struct sctp_bind_addr *src,
1169*4882a593Smuzhiyun gfp_t gfp);
1170*4882a593Smuzhiyun int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
1171*4882a593Smuzhiyun int new_size, __u8 addr_state, gfp_t gfp);
1172*4882a593Smuzhiyun int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
1173*4882a593Smuzhiyun int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *,
1174*4882a593Smuzhiyun struct sctp_sock *);
1175*4882a593Smuzhiyun int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
1176*4882a593Smuzhiyun struct sctp_sock *, struct sctp_sock *);
1177*4882a593Smuzhiyun int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
1178*4882a593Smuzhiyun const union sctp_addr *addr);
1179*4882a593Smuzhiyun int sctp_bind_addrs_check(struct sctp_sock *sp,
1180*4882a593Smuzhiyun struct sctp_sock *sp2, int cnt2);
1181*4882a593Smuzhiyun union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
1182*4882a593Smuzhiyun const union sctp_addr *addrs,
1183*4882a593Smuzhiyun int addrcnt,
1184*4882a593Smuzhiyun struct sctp_sock *opt);
1185*4882a593Smuzhiyun union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
1186*4882a593Smuzhiyun int *addrs_len,
1187*4882a593Smuzhiyun gfp_t gfp);
1188*4882a593Smuzhiyun int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
1189*4882a593Smuzhiyun __u16 port, gfp_t gfp);
1190*4882a593Smuzhiyun
1191*4882a593Smuzhiyun enum sctp_scope sctp_scope(const union sctp_addr *addr);
1192*4882a593Smuzhiyun int sctp_in_scope(struct net *net, const union sctp_addr *addr,
1193*4882a593Smuzhiyun const enum sctp_scope scope);
1194*4882a593Smuzhiyun int sctp_is_any(struct sock *sk, const union sctp_addr *addr);
1195*4882a593Smuzhiyun int sctp_is_ep_boundall(struct sock *sk);
1196*4882a593Smuzhiyun
1197*4882a593Smuzhiyun
1198*4882a593Smuzhiyun /* What type of endpoint? */
1199*4882a593Smuzhiyun enum sctp_endpoint_type {
1200*4882a593Smuzhiyun SCTP_EP_TYPE_SOCKET,
1201*4882a593Smuzhiyun SCTP_EP_TYPE_ASSOCIATION,
1202*4882a593Smuzhiyun };
1203*4882a593Smuzhiyun
1204*4882a593Smuzhiyun /*
1205*4882a593Smuzhiyun * A common base class to bridge the implmentation view of a
1206*4882a593Smuzhiyun * socket (usually listening) endpoint versus an association's
1207*4882a593Smuzhiyun * local endpoint.
1208*4882a593Smuzhiyun * This common structure is useful for several purposes:
1209*4882a593Smuzhiyun * 1) Common interface for lookup routines.
1210*4882a593Smuzhiyun * a) Subfunctions work for either endpoint or association
1211*4882a593Smuzhiyun * b) Single interface to lookup allows hiding the lookup lock rather
1212*4882a593Smuzhiyun * than acquiring it externally.
1213*4882a593Smuzhiyun * 2) Common interface for the inbound chunk handling/state machine.
1214*4882a593Smuzhiyun * 3) Common object handling routines for reference counting, etc.
1215*4882a593Smuzhiyun * 4) Disentangle association lookup from endpoint lookup, where we
1216*4882a593Smuzhiyun * do not have to find our endpoint to find our association.
1217*4882a593Smuzhiyun *
1218*4882a593Smuzhiyun */
1219*4882a593Smuzhiyun
1220*4882a593Smuzhiyun struct sctp_ep_common {
1221*4882a593Smuzhiyun /* Fields to help us manage our entries in the hash tables. */
1222*4882a593Smuzhiyun struct hlist_node node;
1223*4882a593Smuzhiyun int hashent;
1224*4882a593Smuzhiyun
1225*4882a593Smuzhiyun /* Runtime type information. What kind of endpoint is this? */
1226*4882a593Smuzhiyun enum sctp_endpoint_type type;
1227*4882a593Smuzhiyun
1228*4882a593Smuzhiyun /* Some fields to help us manage this object.
1229*4882a593Smuzhiyun * refcnt - Reference count access to this object.
1230*4882a593Smuzhiyun * dead - Do not attempt to use this object.
1231*4882a593Smuzhiyun */
1232*4882a593Smuzhiyun refcount_t refcnt;
1233*4882a593Smuzhiyun bool dead;
1234*4882a593Smuzhiyun
1235*4882a593Smuzhiyun /* What socket does this endpoint belong to? */
1236*4882a593Smuzhiyun struct sock *sk;
1237*4882a593Smuzhiyun
1238*4882a593Smuzhiyun /* Cache netns and it won't change once set */
1239*4882a593Smuzhiyun struct net *net;
1240*4882a593Smuzhiyun
1241*4882a593Smuzhiyun /* This is where we receive inbound chunks. */
1242*4882a593Smuzhiyun struct sctp_inq inqueue;
1243*4882a593Smuzhiyun
1244*4882a593Smuzhiyun /* This substructure includes the defining parameters of the
1245*4882a593Smuzhiyun * endpoint:
1246*4882a593Smuzhiyun * bind_addr.port is our shared port number.
1247*4882a593Smuzhiyun * bind_addr.address_list is our set of local IP addresses.
1248*4882a593Smuzhiyun */
1249*4882a593Smuzhiyun struct sctp_bind_addr bind_addr;
1250*4882a593Smuzhiyun };
1251*4882a593Smuzhiyun
1252*4882a593Smuzhiyun
1253*4882a593Smuzhiyun /* RFC Section 1.4 Key Terms
1254*4882a593Smuzhiyun *
1255*4882a593Smuzhiyun * o SCTP endpoint: The logical sender/receiver of SCTP packets. On a
1256*4882a593Smuzhiyun * multi-homed host, an SCTP endpoint is represented to its peers as a
1257*4882a593Smuzhiyun * combination of a set of eligible destination transport addresses to
1258*4882a593Smuzhiyun * which SCTP packets can be sent and a set of eligible source
1259*4882a593Smuzhiyun * transport addresses from which SCTP packets can be received.
1260*4882a593Smuzhiyun * All transport addresses used by an SCTP endpoint must use the
1261*4882a593Smuzhiyun * same port number, but can use multiple IP addresses. A transport
1262*4882a593Smuzhiyun * address used by an SCTP endpoint must not be used by another
1263*4882a593Smuzhiyun * SCTP endpoint. In other words, a transport address is unique
1264*4882a593Smuzhiyun * to an SCTP endpoint.
1265*4882a593Smuzhiyun *
1266*4882a593Smuzhiyun * From an implementation perspective, each socket has one of these.
1267*4882a593Smuzhiyun * A TCP-style socket will have exactly one association on one of
1268*4882a593Smuzhiyun * these. An UDP-style socket will have multiple associations hanging
1269*4882a593Smuzhiyun * off one of these.
1270*4882a593Smuzhiyun */
1271*4882a593Smuzhiyun
1272*4882a593Smuzhiyun struct sctp_endpoint {
1273*4882a593Smuzhiyun /* Common substructure for endpoint and association. */
1274*4882a593Smuzhiyun struct sctp_ep_common base;
1275*4882a593Smuzhiyun
1276*4882a593Smuzhiyun /* Associations: A list of current associations and mappings
1277*4882a593Smuzhiyun * to the data consumers for each association. This
1278*4882a593Smuzhiyun * may be in the form of a hash table or other
1279*4882a593Smuzhiyun * implementation dependent structure. The data
1280*4882a593Smuzhiyun * consumers may be process identification
1281*4882a593Smuzhiyun * information such as file descriptors, named pipe
1282*4882a593Smuzhiyun * pointer, or table pointers dependent on how SCTP
1283*4882a593Smuzhiyun * is implemented.
1284*4882a593Smuzhiyun */
1285*4882a593Smuzhiyun /* This is really a list of struct sctp_association entries. */
1286*4882a593Smuzhiyun struct list_head asocs;
1287*4882a593Smuzhiyun
1288*4882a593Smuzhiyun /* Secret Key: A secret key used by this endpoint to compute
1289*4882a593Smuzhiyun * the MAC. This SHOULD be a cryptographic quality
1290*4882a593Smuzhiyun * random number with a sufficient length.
1291*4882a593Smuzhiyun * Discussion in [RFC1750] can be helpful in
1292*4882a593Smuzhiyun * selection of the key.
1293*4882a593Smuzhiyun */
1294*4882a593Smuzhiyun __u8 secret_key[SCTP_SECRET_SIZE];
1295*4882a593Smuzhiyun
1296*4882a593Smuzhiyun /* digest: This is a digest of the sctp cookie. This field is
1297*4882a593Smuzhiyun * only used on the receive path when we try to validate
1298*4882a593Smuzhiyun * that the cookie has not been tampered with. We put
1299*4882a593Smuzhiyun * this here so we pre-allocate this once and can re-use
1300*4882a593Smuzhiyun * on every receive.
1301*4882a593Smuzhiyun */
1302*4882a593Smuzhiyun __u8 *digest;
1303*4882a593Smuzhiyun
1304*4882a593Smuzhiyun /* sendbuf acct. policy. */
1305*4882a593Smuzhiyun __u32 sndbuf_policy;
1306*4882a593Smuzhiyun
1307*4882a593Smuzhiyun /* rcvbuf acct. policy. */
1308*4882a593Smuzhiyun __u32 rcvbuf_policy;
1309*4882a593Smuzhiyun
1310*4882a593Smuzhiyun /* SCTP AUTH: array of the HMACs that will be allocated
1311*4882a593Smuzhiyun * we need this per association so that we don't serialize
1312*4882a593Smuzhiyun */
1313*4882a593Smuzhiyun struct crypto_shash **auth_hmacs;
1314*4882a593Smuzhiyun
1315*4882a593Smuzhiyun /* SCTP-AUTH: hmacs for the endpoint encoded into parameter */
1316*4882a593Smuzhiyun struct sctp_hmac_algo_param *auth_hmacs_list;
1317*4882a593Smuzhiyun
1318*4882a593Smuzhiyun /* SCTP-AUTH: chunks to authenticate encoded into parameter */
1319*4882a593Smuzhiyun struct sctp_chunks_param *auth_chunk_list;
1320*4882a593Smuzhiyun
1321*4882a593Smuzhiyun /* SCTP-AUTH: endpoint shared keys */
1322*4882a593Smuzhiyun struct list_head endpoint_shared_keys;
1323*4882a593Smuzhiyun __u16 active_key_id;
1324*4882a593Smuzhiyun __u8 ecn_enable:1,
1325*4882a593Smuzhiyun auth_enable:1,
1326*4882a593Smuzhiyun intl_enable:1,
1327*4882a593Smuzhiyun prsctp_enable:1,
1328*4882a593Smuzhiyun asconf_enable:1,
1329*4882a593Smuzhiyun reconf_enable:1;
1330*4882a593Smuzhiyun
1331*4882a593Smuzhiyun __u8 strreset_enable;
1332*4882a593Smuzhiyun
1333*4882a593Smuzhiyun /* Security identifiers from incoming (INIT). These are set by
1334*4882a593Smuzhiyun * security_sctp_assoc_request(). These will only be used by
1335*4882a593Smuzhiyun * SCTP TCP type sockets and peeled off connections as they
1336*4882a593Smuzhiyun * cause a new socket to be generated. security_sctp_sk_clone()
1337*4882a593Smuzhiyun * will then plug these into the new socket.
1338*4882a593Smuzhiyun */
1339*4882a593Smuzhiyun
1340*4882a593Smuzhiyun u32 secid;
1341*4882a593Smuzhiyun u32 peer_secid;
1342*4882a593Smuzhiyun struct rcu_head rcu;
1343*4882a593Smuzhiyun };
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun /* Recover the outter endpoint structure. */
sctp_ep(struct sctp_ep_common * base)1346*4882a593Smuzhiyun static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base)
1347*4882a593Smuzhiyun {
1348*4882a593Smuzhiyun struct sctp_endpoint *ep;
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun ep = container_of(base, struct sctp_endpoint, base);
1351*4882a593Smuzhiyun return ep;
1352*4882a593Smuzhiyun }
1353*4882a593Smuzhiyun
1354*4882a593Smuzhiyun /* These are function signatures for manipulating endpoints. */
1355*4882a593Smuzhiyun struct sctp_endpoint *sctp_endpoint_new(struct sock *, gfp_t);
1356*4882a593Smuzhiyun void sctp_endpoint_free(struct sctp_endpoint *);
1357*4882a593Smuzhiyun void sctp_endpoint_put(struct sctp_endpoint *);
1358*4882a593Smuzhiyun int sctp_endpoint_hold(struct sctp_endpoint *ep);
1359*4882a593Smuzhiyun void sctp_endpoint_add_asoc(struct sctp_endpoint *, struct sctp_association *);
1360*4882a593Smuzhiyun struct sctp_association *sctp_endpoint_lookup_assoc(
1361*4882a593Smuzhiyun const struct sctp_endpoint *ep,
1362*4882a593Smuzhiyun const union sctp_addr *paddr,
1363*4882a593Smuzhiyun struct sctp_transport **);
1364*4882a593Smuzhiyun bool sctp_endpoint_is_peeled_off(struct sctp_endpoint *ep,
1365*4882a593Smuzhiyun const union sctp_addr *paddr);
1366*4882a593Smuzhiyun struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *,
1367*4882a593Smuzhiyun struct net *, const union sctp_addr *);
1368*4882a593Smuzhiyun bool sctp_has_association(struct net *net, const union sctp_addr *laddr,
1369*4882a593Smuzhiyun const union sctp_addr *paddr);
1370*4882a593Smuzhiyun
1371*4882a593Smuzhiyun int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep,
1372*4882a593Smuzhiyun const struct sctp_association *asoc,
1373*4882a593Smuzhiyun enum sctp_cid cid, struct sctp_init_chunk *peer_init,
1374*4882a593Smuzhiyun struct sctp_chunk *chunk, struct sctp_chunk **err_chunk);
1375*4882a593Smuzhiyun int sctp_process_init(struct sctp_association *, struct sctp_chunk *chunk,
1376*4882a593Smuzhiyun const union sctp_addr *peer,
1377*4882a593Smuzhiyun struct sctp_init_chunk *init, gfp_t gfp);
1378*4882a593Smuzhiyun __u32 sctp_generate_tag(const struct sctp_endpoint *);
1379*4882a593Smuzhiyun __u32 sctp_generate_tsn(const struct sctp_endpoint *);
1380*4882a593Smuzhiyun
1381*4882a593Smuzhiyun struct sctp_inithdr_host {
1382*4882a593Smuzhiyun __u32 init_tag;
1383*4882a593Smuzhiyun __u32 a_rwnd;
1384*4882a593Smuzhiyun __u16 num_outbound_streams;
1385*4882a593Smuzhiyun __u16 num_inbound_streams;
1386*4882a593Smuzhiyun __u32 initial_tsn;
1387*4882a593Smuzhiyun };
1388*4882a593Smuzhiyun
1389*4882a593Smuzhiyun struct sctp_stream_priorities {
1390*4882a593Smuzhiyun /* List of priorities scheduled */
1391*4882a593Smuzhiyun struct list_head prio_sched;
1392*4882a593Smuzhiyun /* List of streams scheduled */
1393*4882a593Smuzhiyun struct list_head active;
1394*4882a593Smuzhiyun /* The next stream in line */
1395*4882a593Smuzhiyun struct sctp_stream_out_ext *next;
1396*4882a593Smuzhiyun __u16 prio;
1397*4882a593Smuzhiyun };
1398*4882a593Smuzhiyun
1399*4882a593Smuzhiyun struct sctp_stream_out_ext {
1400*4882a593Smuzhiyun __u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
1401*4882a593Smuzhiyun __u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
1402*4882a593Smuzhiyun struct list_head outq; /* chunks enqueued by this stream */
1403*4882a593Smuzhiyun union {
1404*4882a593Smuzhiyun struct {
1405*4882a593Smuzhiyun /* Scheduled streams list */
1406*4882a593Smuzhiyun struct list_head prio_list;
1407*4882a593Smuzhiyun struct sctp_stream_priorities *prio_head;
1408*4882a593Smuzhiyun };
1409*4882a593Smuzhiyun /* Fields used by RR scheduler */
1410*4882a593Smuzhiyun struct {
1411*4882a593Smuzhiyun struct list_head rr_list;
1412*4882a593Smuzhiyun };
1413*4882a593Smuzhiyun };
1414*4882a593Smuzhiyun };
1415*4882a593Smuzhiyun
1416*4882a593Smuzhiyun struct sctp_stream_out {
1417*4882a593Smuzhiyun union {
1418*4882a593Smuzhiyun __u32 mid;
1419*4882a593Smuzhiyun __u16 ssn;
1420*4882a593Smuzhiyun };
1421*4882a593Smuzhiyun __u32 mid_uo;
1422*4882a593Smuzhiyun struct sctp_stream_out_ext *ext;
1423*4882a593Smuzhiyun __u8 state;
1424*4882a593Smuzhiyun };
1425*4882a593Smuzhiyun
1426*4882a593Smuzhiyun struct sctp_stream_in {
1427*4882a593Smuzhiyun union {
1428*4882a593Smuzhiyun __u32 mid;
1429*4882a593Smuzhiyun __u16 ssn;
1430*4882a593Smuzhiyun };
1431*4882a593Smuzhiyun __u32 mid_uo;
1432*4882a593Smuzhiyun __u32 fsn;
1433*4882a593Smuzhiyun __u32 fsn_uo;
1434*4882a593Smuzhiyun char pd_mode;
1435*4882a593Smuzhiyun char pd_mode_uo;
1436*4882a593Smuzhiyun };
1437*4882a593Smuzhiyun
1438*4882a593Smuzhiyun struct sctp_stream {
1439*4882a593Smuzhiyun GENRADIX(struct sctp_stream_out) out;
1440*4882a593Smuzhiyun GENRADIX(struct sctp_stream_in) in;
1441*4882a593Smuzhiyun
1442*4882a593Smuzhiyun __u16 outcnt;
1443*4882a593Smuzhiyun __u16 incnt;
1444*4882a593Smuzhiyun /* Current stream being sent, if any */
1445*4882a593Smuzhiyun struct sctp_stream_out *out_curr;
1446*4882a593Smuzhiyun union {
1447*4882a593Smuzhiyun /* Fields used by priority scheduler */
1448*4882a593Smuzhiyun struct {
1449*4882a593Smuzhiyun /* List of priorities scheduled */
1450*4882a593Smuzhiyun struct list_head prio_list;
1451*4882a593Smuzhiyun };
1452*4882a593Smuzhiyun /* Fields used by RR scheduler */
1453*4882a593Smuzhiyun struct {
1454*4882a593Smuzhiyun /* List of streams scheduled */
1455*4882a593Smuzhiyun struct list_head rr_list;
1456*4882a593Smuzhiyun /* The next stream in line */
1457*4882a593Smuzhiyun struct sctp_stream_out_ext *rr_next;
1458*4882a593Smuzhiyun };
1459*4882a593Smuzhiyun };
1460*4882a593Smuzhiyun struct sctp_stream_interleave *si;
1461*4882a593Smuzhiyun };
1462*4882a593Smuzhiyun
sctp_stream_out(struct sctp_stream * stream,__u16 sid)1463*4882a593Smuzhiyun static inline struct sctp_stream_out *sctp_stream_out(
1464*4882a593Smuzhiyun struct sctp_stream *stream,
1465*4882a593Smuzhiyun __u16 sid)
1466*4882a593Smuzhiyun {
1467*4882a593Smuzhiyun return genradix_ptr(&stream->out, sid);
1468*4882a593Smuzhiyun }
1469*4882a593Smuzhiyun
sctp_stream_in(struct sctp_stream * stream,__u16 sid)1470*4882a593Smuzhiyun static inline struct sctp_stream_in *sctp_stream_in(
1471*4882a593Smuzhiyun struct sctp_stream *stream,
1472*4882a593Smuzhiyun __u16 sid)
1473*4882a593Smuzhiyun {
1474*4882a593Smuzhiyun return genradix_ptr(&stream->in, sid);
1475*4882a593Smuzhiyun }
1476*4882a593Smuzhiyun
1477*4882a593Smuzhiyun #define SCTP_SO(s, i) sctp_stream_out((s), (i))
1478*4882a593Smuzhiyun #define SCTP_SI(s, i) sctp_stream_in((s), (i))
1479*4882a593Smuzhiyun
1480*4882a593Smuzhiyun #define SCTP_STREAM_CLOSED 0x00
1481*4882a593Smuzhiyun #define SCTP_STREAM_OPEN 0x01
1482*4882a593Smuzhiyun
sctp_datachk_len(const struct sctp_stream * stream)1483*4882a593Smuzhiyun static inline __u16 sctp_datachk_len(const struct sctp_stream *stream)
1484*4882a593Smuzhiyun {
1485*4882a593Smuzhiyun return stream->si->data_chunk_len;
1486*4882a593Smuzhiyun }
1487*4882a593Smuzhiyun
sctp_datahdr_len(const struct sctp_stream * stream)1488*4882a593Smuzhiyun static inline __u16 sctp_datahdr_len(const struct sctp_stream *stream)
1489*4882a593Smuzhiyun {
1490*4882a593Smuzhiyun return stream->si->data_chunk_len - sizeof(struct sctp_chunkhdr);
1491*4882a593Smuzhiyun }
1492*4882a593Smuzhiyun
sctp_ftsnchk_len(const struct sctp_stream * stream)1493*4882a593Smuzhiyun static inline __u16 sctp_ftsnchk_len(const struct sctp_stream *stream)
1494*4882a593Smuzhiyun {
1495*4882a593Smuzhiyun return stream->si->ftsn_chunk_len;
1496*4882a593Smuzhiyun }
1497*4882a593Smuzhiyun
sctp_ftsnhdr_len(const struct sctp_stream * stream)1498*4882a593Smuzhiyun static inline __u16 sctp_ftsnhdr_len(const struct sctp_stream *stream)
1499*4882a593Smuzhiyun {
1500*4882a593Smuzhiyun return stream->si->ftsn_chunk_len - sizeof(struct sctp_chunkhdr);
1501*4882a593Smuzhiyun }
1502*4882a593Smuzhiyun
1503*4882a593Smuzhiyun /* SCTP_GET_ASSOC_STATS counters */
1504*4882a593Smuzhiyun struct sctp_priv_assoc_stats {
1505*4882a593Smuzhiyun /* Maximum observed rto in the association during subsequent
1506*4882a593Smuzhiyun * observations. Value is set to 0 if no RTO measurement took place
1507*4882a593Smuzhiyun * The transport where the max_rto was observed is returned in
1508*4882a593Smuzhiyun * obs_rto_ipaddr
1509*4882a593Smuzhiyun */
1510*4882a593Smuzhiyun struct sockaddr_storage obs_rto_ipaddr;
1511*4882a593Smuzhiyun __u64 max_obs_rto;
1512*4882a593Smuzhiyun /* Total In and Out SACKs received and sent */
1513*4882a593Smuzhiyun __u64 isacks;
1514*4882a593Smuzhiyun __u64 osacks;
1515*4882a593Smuzhiyun /* Total In and Out packets received and sent */
1516*4882a593Smuzhiyun __u64 opackets;
1517*4882a593Smuzhiyun __u64 ipackets;
1518*4882a593Smuzhiyun /* Total retransmitted chunks */
1519*4882a593Smuzhiyun __u64 rtxchunks;
1520*4882a593Smuzhiyun /* TSN received > next expected */
1521*4882a593Smuzhiyun __u64 outofseqtsns;
1522*4882a593Smuzhiyun /* Duplicate Chunks received */
1523*4882a593Smuzhiyun __u64 idupchunks;
1524*4882a593Smuzhiyun /* Gap Ack Blocks received */
1525*4882a593Smuzhiyun __u64 gapcnt;
1526*4882a593Smuzhiyun /* Unordered data chunks sent and received */
1527*4882a593Smuzhiyun __u64 ouodchunks;
1528*4882a593Smuzhiyun __u64 iuodchunks;
1529*4882a593Smuzhiyun /* Ordered data chunks sent and received */
1530*4882a593Smuzhiyun __u64 oodchunks;
1531*4882a593Smuzhiyun __u64 iodchunks;
1532*4882a593Smuzhiyun /* Control chunks sent and received */
1533*4882a593Smuzhiyun __u64 octrlchunks;
1534*4882a593Smuzhiyun __u64 ictrlchunks;
1535*4882a593Smuzhiyun };
1536*4882a593Smuzhiyun
1537*4882a593Smuzhiyun /* RFC2960
1538*4882a593Smuzhiyun *
1539*4882a593Smuzhiyun * 12. Recommended Transmission Control Block (TCB) Parameters
1540*4882a593Smuzhiyun *
1541*4882a593Smuzhiyun * This section details a recommended set of parameters that should
1542*4882a593Smuzhiyun * be contained within the TCB for an implementation. This section is
1543*4882a593Smuzhiyun * for illustrative purposes and should not be deemed as requirements
1544*4882a593Smuzhiyun * on an implementation or as an exhaustive list of all parameters
1545*4882a593Smuzhiyun * inside an SCTP TCB. Each implementation may need its own additional
1546*4882a593Smuzhiyun * parameters for optimization.
1547*4882a593Smuzhiyun */
1548*4882a593Smuzhiyun
1549*4882a593Smuzhiyun
1550*4882a593Smuzhiyun /* Here we have information about each individual association. */
1551*4882a593Smuzhiyun struct sctp_association {
1552*4882a593Smuzhiyun
1553*4882a593Smuzhiyun /* A base structure common to endpoint and association.
1554*4882a593Smuzhiyun * In this context, it represents the associations's view
1555*4882a593Smuzhiyun * of the local endpoint of the association.
1556*4882a593Smuzhiyun */
1557*4882a593Smuzhiyun struct sctp_ep_common base;
1558*4882a593Smuzhiyun
1559*4882a593Smuzhiyun /* Associations on the same socket. */
1560*4882a593Smuzhiyun struct list_head asocs;
1561*4882a593Smuzhiyun
1562*4882a593Smuzhiyun /* association id. */
1563*4882a593Smuzhiyun sctp_assoc_t assoc_id;
1564*4882a593Smuzhiyun
1565*4882a593Smuzhiyun /* This is our parent endpoint. */
1566*4882a593Smuzhiyun struct sctp_endpoint *ep;
1567*4882a593Smuzhiyun
1568*4882a593Smuzhiyun /* These are those association elements needed in the cookie. */
1569*4882a593Smuzhiyun struct sctp_cookie c;
1570*4882a593Smuzhiyun
1571*4882a593Smuzhiyun /* This is all information about our peer. */
1572*4882a593Smuzhiyun struct {
1573*4882a593Smuzhiyun /* transport_addr_list
1574*4882a593Smuzhiyun *
1575*4882a593Smuzhiyun * Peer : A list of SCTP transport addresses that the
1576*4882a593Smuzhiyun * Transport : peer is bound to. This information is derived
1577*4882a593Smuzhiyun * Address : from the INIT or INIT ACK and is used to
1578*4882a593Smuzhiyun * List : associate an inbound packet with a given
1579*4882a593Smuzhiyun * : association. Normally this information is
1580*4882a593Smuzhiyun * : hashed or keyed for quick lookup and access
1581*4882a593Smuzhiyun * : of the TCB.
1582*4882a593Smuzhiyun * : The list is also initialized with the list
1583*4882a593Smuzhiyun * : of addresses passed with the sctp_connectx()
1584*4882a593Smuzhiyun * : call.
1585*4882a593Smuzhiyun *
1586*4882a593Smuzhiyun * It is a list of SCTP_transport's.
1587*4882a593Smuzhiyun */
1588*4882a593Smuzhiyun struct list_head transport_addr_list;
1589*4882a593Smuzhiyun
1590*4882a593Smuzhiyun /* rwnd
1591*4882a593Smuzhiyun *
1592*4882a593Smuzhiyun * Peer Rwnd : Current calculated value of the peer's rwnd.
1593*4882a593Smuzhiyun */
1594*4882a593Smuzhiyun __u32 rwnd;
1595*4882a593Smuzhiyun
1596*4882a593Smuzhiyun /* transport_count
1597*4882a593Smuzhiyun *
1598*4882a593Smuzhiyun * Peer : A count of the number of peer addresses
1599*4882a593Smuzhiyun * Transport : in the Peer Transport Address List.
1600*4882a593Smuzhiyun * Address :
1601*4882a593Smuzhiyun * Count :
1602*4882a593Smuzhiyun */
1603*4882a593Smuzhiyun __u16 transport_count;
1604*4882a593Smuzhiyun
1605*4882a593Smuzhiyun /* port
1606*4882a593Smuzhiyun * The transport layer port number.
1607*4882a593Smuzhiyun */
1608*4882a593Smuzhiyun __u16 port;
1609*4882a593Smuzhiyun
1610*4882a593Smuzhiyun /* primary_path
1611*4882a593Smuzhiyun *
1612*4882a593Smuzhiyun * Primary : This is the current primary destination
1613*4882a593Smuzhiyun * Path : transport address of the peer endpoint. It
1614*4882a593Smuzhiyun * : may also specify a source transport address
1615*4882a593Smuzhiyun * : on this endpoint.
1616*4882a593Smuzhiyun *
1617*4882a593Smuzhiyun * All of these paths live on transport_addr_list.
1618*4882a593Smuzhiyun *
1619*4882a593Smuzhiyun * At the bakeoffs, we discovered that the intent of
1620*4882a593Smuzhiyun * primaryPath is that it only changes when the ULP
1621*4882a593Smuzhiyun * asks to have it changed. We add the activePath to
1622*4882a593Smuzhiyun * designate the connection we are currently using to
1623*4882a593Smuzhiyun * transmit new data and most control chunks.
1624*4882a593Smuzhiyun */
1625*4882a593Smuzhiyun struct sctp_transport *primary_path;
1626*4882a593Smuzhiyun
1627*4882a593Smuzhiyun /* Cache the primary path address here, when we
1628*4882a593Smuzhiyun * need a an address for msg_name.
1629*4882a593Smuzhiyun */
1630*4882a593Smuzhiyun union sctp_addr primary_addr;
1631*4882a593Smuzhiyun
1632*4882a593Smuzhiyun /* active_path
1633*4882a593Smuzhiyun * The path that we are currently using to
1634*4882a593Smuzhiyun * transmit new data and most control chunks.
1635*4882a593Smuzhiyun */
1636*4882a593Smuzhiyun struct sctp_transport *active_path;
1637*4882a593Smuzhiyun
1638*4882a593Smuzhiyun /* retran_path
1639*4882a593Smuzhiyun *
1640*4882a593Smuzhiyun * RFC2960 6.4 Multi-homed SCTP Endpoints
1641*4882a593Smuzhiyun * ...
1642*4882a593Smuzhiyun * Furthermore, when its peer is multi-homed, an
1643*4882a593Smuzhiyun * endpoint SHOULD try to retransmit a chunk to an
1644*4882a593Smuzhiyun * active destination transport address that is
1645*4882a593Smuzhiyun * different from the last destination address to
1646*4882a593Smuzhiyun * which the DATA chunk was sent.
1647*4882a593Smuzhiyun */
1648*4882a593Smuzhiyun struct sctp_transport *retran_path;
1649*4882a593Smuzhiyun
1650*4882a593Smuzhiyun /* Pointer to last transport I have sent on. */
1651*4882a593Smuzhiyun struct sctp_transport *last_sent_to;
1652*4882a593Smuzhiyun
1653*4882a593Smuzhiyun /* This is the last transport I have received DATA on. */
1654*4882a593Smuzhiyun struct sctp_transport *last_data_from;
1655*4882a593Smuzhiyun
1656*4882a593Smuzhiyun /*
1657*4882a593Smuzhiyun * Mapping An array of bits or bytes indicating which out of
1658*4882a593Smuzhiyun * Array order TSN's have been received (relative to the
1659*4882a593Smuzhiyun * Last Rcvd TSN). If no gaps exist, i.e. no out of
1660*4882a593Smuzhiyun * order packets have been received, this array
1661*4882a593Smuzhiyun * will be set to all zero. This structure may be
1662*4882a593Smuzhiyun * in the form of a circular buffer or bit array.
1663*4882a593Smuzhiyun *
1664*4882a593Smuzhiyun * Last Rcvd : This is the last TSN received in
1665*4882a593Smuzhiyun * TSN : sequence. This value is set initially by
1666*4882a593Smuzhiyun * : taking the peer's Initial TSN, received in
1667*4882a593Smuzhiyun * : the INIT or INIT ACK chunk, and subtracting
1668*4882a593Smuzhiyun * : one from it.
1669*4882a593Smuzhiyun *
1670*4882a593Smuzhiyun * Throughout most of the specification this is called the
1671*4882a593Smuzhiyun * "Cumulative TSN ACK Point". In this case, we
1672*4882a593Smuzhiyun * ignore the advice in 12.2 in favour of the term
1673*4882a593Smuzhiyun * used in the bulk of the text. This value is hidden
1674*4882a593Smuzhiyun * in tsn_map--we get it by calling sctp_tsnmap_get_ctsn().
1675*4882a593Smuzhiyun */
1676*4882a593Smuzhiyun struct sctp_tsnmap tsn_map;
1677*4882a593Smuzhiyun
1678*4882a593Smuzhiyun /* This mask is used to disable sending the ASCONF chunk
1679*4882a593Smuzhiyun * with specified parameter to peer.
1680*4882a593Smuzhiyun */
1681*4882a593Smuzhiyun __be16 addip_disabled_mask;
1682*4882a593Smuzhiyun
1683*4882a593Smuzhiyun /* These are capabilities which our peer advertised. */
1684*4882a593Smuzhiyun __u16 ecn_capable:1, /* Can peer do ECN? */
1685*4882a593Smuzhiyun ipv4_address:1, /* Peer understands IPv4 addresses? */
1686*4882a593Smuzhiyun ipv6_address:1, /* Peer understands IPv6 addresses? */
1687*4882a593Smuzhiyun hostname_address:1, /* Peer understands DNS addresses? */
1688*4882a593Smuzhiyun asconf_capable:1, /* Does peer support ADDIP? */
1689*4882a593Smuzhiyun prsctp_capable:1, /* Can peer do PR-SCTP? */
1690*4882a593Smuzhiyun reconf_capable:1, /* Can peer do RE-CONFIG? */
1691*4882a593Smuzhiyun intl_capable:1, /* Can peer do INTERLEAVE */
1692*4882a593Smuzhiyun auth_capable:1, /* Is peer doing SCTP-AUTH? */
1693*4882a593Smuzhiyun /* sack_needed:
1694*4882a593Smuzhiyun * This flag indicates if the next received
1695*4882a593Smuzhiyun * packet is to be responded to with a
1696*4882a593Smuzhiyun * SACK. This is initialized to 0. When a packet
1697*4882a593Smuzhiyun * is received sack_cnt is incremented. If this value
1698*4882a593Smuzhiyun * reaches 2 or more, a SACK is sent and the
1699*4882a593Smuzhiyun * value is reset to 0. Note: This is used only
1700*4882a593Smuzhiyun * when no DATA chunks are received out of
1701*4882a593Smuzhiyun * order. When DATA chunks are out of order,
1702*4882a593Smuzhiyun * SACK's are not delayed (see Section 6).
1703*4882a593Smuzhiyun */
1704*4882a593Smuzhiyun sack_needed:1, /* Do we need to sack the peer? */
1705*4882a593Smuzhiyun sack_generation:1,
1706*4882a593Smuzhiyun zero_window_announced:1;
1707*4882a593Smuzhiyun
1708*4882a593Smuzhiyun __u32 sack_cnt;
1709*4882a593Smuzhiyun
1710*4882a593Smuzhiyun __u32 adaptation_ind; /* Adaptation Code point. */
1711*4882a593Smuzhiyun
1712*4882a593Smuzhiyun struct sctp_inithdr_host i;
1713*4882a593Smuzhiyun void *cookie;
1714*4882a593Smuzhiyun int cookie_len;
1715*4882a593Smuzhiyun
1716*4882a593Smuzhiyun /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
1717*4882a593Smuzhiyun * C1) ... "Peer-Serial-Number'. This value MUST be initialized to the
1718*4882a593Smuzhiyun * Initial TSN Value minus 1
1719*4882a593Smuzhiyun */
1720*4882a593Smuzhiyun __u32 addip_serial;
1721*4882a593Smuzhiyun
1722*4882a593Smuzhiyun /* SCTP-AUTH: We need to know pears random number, hmac list
1723*4882a593Smuzhiyun * and authenticated chunk list. All that is part of the
1724*4882a593Smuzhiyun * cookie and these are just pointers to those locations
1725*4882a593Smuzhiyun */
1726*4882a593Smuzhiyun struct sctp_random_param *peer_random;
1727*4882a593Smuzhiyun struct sctp_chunks_param *peer_chunks;
1728*4882a593Smuzhiyun struct sctp_hmac_algo_param *peer_hmacs;
1729*4882a593Smuzhiyun } peer;
1730*4882a593Smuzhiyun
1731*4882a593Smuzhiyun /* State : A state variable indicating what state the
1732*4882a593Smuzhiyun * : association is in, i.e. COOKIE-WAIT,
1733*4882a593Smuzhiyun * : COOKIE-ECHOED, ESTABLISHED, SHUTDOWN-PENDING,
1734*4882a593Smuzhiyun * : SHUTDOWN-SENT, SHUTDOWN-RECEIVED, SHUTDOWN-ACK-SENT.
1735*4882a593Smuzhiyun *
1736*4882a593Smuzhiyun * Note: No "CLOSED" state is illustrated since if a
1737*4882a593Smuzhiyun * association is "CLOSED" its TCB SHOULD be removed.
1738*4882a593Smuzhiyun *
1739*4882a593Smuzhiyun * In this implementation we DO have a CLOSED
1740*4882a593Smuzhiyun * state which is used during initiation and shutdown.
1741*4882a593Smuzhiyun *
1742*4882a593Smuzhiyun * State takes values from SCTP_STATE_*.
1743*4882a593Smuzhiyun */
1744*4882a593Smuzhiyun enum sctp_state state;
1745*4882a593Smuzhiyun
1746*4882a593Smuzhiyun /* Overall : The overall association error count.
1747*4882a593Smuzhiyun * Error Count : [Clear this any time I get something.]
1748*4882a593Smuzhiyun */
1749*4882a593Smuzhiyun int overall_error_count;
1750*4882a593Smuzhiyun
1751*4882a593Smuzhiyun /* The cookie life I award for any cookie. */
1752*4882a593Smuzhiyun ktime_t cookie_life;
1753*4882a593Smuzhiyun
1754*4882a593Smuzhiyun /* These are the association's initial, max, and min RTO values.
1755*4882a593Smuzhiyun * These values will be initialized by system defaults, but can
1756*4882a593Smuzhiyun * be modified via the SCTP_RTOINFO socket option.
1757*4882a593Smuzhiyun */
1758*4882a593Smuzhiyun unsigned long rto_initial;
1759*4882a593Smuzhiyun unsigned long rto_max;
1760*4882a593Smuzhiyun unsigned long rto_min;
1761*4882a593Smuzhiyun
1762*4882a593Smuzhiyun /* Maximum number of new data packets that can be sent in a burst. */
1763*4882a593Smuzhiyun int max_burst;
1764*4882a593Smuzhiyun
1765*4882a593Smuzhiyun /* This is the max_retrans value for the association. This value will
1766*4882a593Smuzhiyun * be initialized from system defaults, but can be
1767*4882a593Smuzhiyun * modified by the SCTP_ASSOCINFO socket option.
1768*4882a593Smuzhiyun */
1769*4882a593Smuzhiyun int max_retrans;
1770*4882a593Smuzhiyun
1771*4882a593Smuzhiyun /* This is the partially failed retrans value for the transport
1772*4882a593Smuzhiyun * and will be initialized from the assocs value. This can be
1773*4882a593Smuzhiyun * changed using the SCTP_PEER_ADDR_THLDS socket option
1774*4882a593Smuzhiyun */
1775*4882a593Smuzhiyun __u16 pf_retrans;
1776*4882a593Smuzhiyun /* Used for primary path switchover. */
1777*4882a593Smuzhiyun __u16 ps_retrans;
1778*4882a593Smuzhiyun
1779*4882a593Smuzhiyun /* Maximum number of times the endpoint will retransmit INIT */
1780*4882a593Smuzhiyun __u16 max_init_attempts;
1781*4882a593Smuzhiyun
1782*4882a593Smuzhiyun /* How many times have we resent an INIT? */
1783*4882a593Smuzhiyun __u16 init_retries;
1784*4882a593Smuzhiyun
1785*4882a593Smuzhiyun /* The largest timeout or RTO value to use in attempting an INIT */
1786*4882a593Smuzhiyun unsigned long max_init_timeo;
1787*4882a593Smuzhiyun
1788*4882a593Smuzhiyun /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
1789*4882a593Smuzhiyun * the destination address every heartbeat interval. This value
1790*4882a593Smuzhiyun * will be inherited by all new transports.
1791*4882a593Smuzhiyun */
1792*4882a593Smuzhiyun unsigned long hbinterval;
1793*4882a593Smuzhiyun
1794*4882a593Smuzhiyun /* This is the max_retrans value for new transports in the
1795*4882a593Smuzhiyun * association.
1796*4882a593Smuzhiyun */
1797*4882a593Smuzhiyun __u16 pathmaxrxt;
1798*4882a593Smuzhiyun
1799*4882a593Smuzhiyun __u32 flowlabel;
1800*4882a593Smuzhiyun __u8 dscp;
1801*4882a593Smuzhiyun
1802*4882a593Smuzhiyun /* Flag that path mtu update is pending */
1803*4882a593Smuzhiyun __u8 pmtu_pending;
1804*4882a593Smuzhiyun
1805*4882a593Smuzhiyun /* Association : The smallest PMTU discovered for all of the
1806*4882a593Smuzhiyun * PMTU : peer's transport addresses.
1807*4882a593Smuzhiyun */
1808*4882a593Smuzhiyun __u32 pathmtu;
1809*4882a593Smuzhiyun
1810*4882a593Smuzhiyun /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
1811*4882a593Smuzhiyun __u32 param_flags;
1812*4882a593Smuzhiyun
1813*4882a593Smuzhiyun __u32 sackfreq;
1814*4882a593Smuzhiyun /* SACK delay timeout */
1815*4882a593Smuzhiyun unsigned long sackdelay;
1816*4882a593Smuzhiyun
1817*4882a593Smuzhiyun unsigned long timeouts[SCTP_NUM_TIMEOUT_TYPES];
1818*4882a593Smuzhiyun struct timer_list timers[SCTP_NUM_TIMEOUT_TYPES];
1819*4882a593Smuzhiyun
1820*4882a593Smuzhiyun /* Transport to which SHUTDOWN chunk was last sent. */
1821*4882a593Smuzhiyun struct sctp_transport *shutdown_last_sent_to;
1822*4882a593Smuzhiyun
1823*4882a593Smuzhiyun /* Transport to which INIT chunk was last sent. */
1824*4882a593Smuzhiyun struct sctp_transport *init_last_sent_to;
1825*4882a593Smuzhiyun
1826*4882a593Smuzhiyun /* How many times have we resent a SHUTDOWN */
1827*4882a593Smuzhiyun int shutdown_retries;
1828*4882a593Smuzhiyun
1829*4882a593Smuzhiyun /* Next TSN : The next TSN number to be assigned to a new
1830*4882a593Smuzhiyun * : DATA chunk. This is sent in the INIT or INIT
1831*4882a593Smuzhiyun * : ACK chunk to the peer and incremented each
1832*4882a593Smuzhiyun * : time a DATA chunk is assigned a TSN
1833*4882a593Smuzhiyun * : (normally just prior to transmit or during
1834*4882a593Smuzhiyun * : fragmentation).
1835*4882a593Smuzhiyun */
1836*4882a593Smuzhiyun __u32 next_tsn;
1837*4882a593Smuzhiyun
1838*4882a593Smuzhiyun /*
1839*4882a593Smuzhiyun * Last Rcvd : This is the last TSN received in sequence. This value
1840*4882a593Smuzhiyun * TSN : is set initially by taking the peer's Initial TSN,
1841*4882a593Smuzhiyun * : received in the INIT or INIT ACK chunk, and
1842*4882a593Smuzhiyun * : subtracting one from it.
1843*4882a593Smuzhiyun *
1844*4882a593Smuzhiyun * Most of RFC 2960 refers to this as the Cumulative TSN Ack Point.
1845*4882a593Smuzhiyun */
1846*4882a593Smuzhiyun
1847*4882a593Smuzhiyun __u32 ctsn_ack_point;
1848*4882a593Smuzhiyun
1849*4882a593Smuzhiyun /* PR-SCTP Advanced.Peer.Ack.Point */
1850*4882a593Smuzhiyun __u32 adv_peer_ack_point;
1851*4882a593Smuzhiyun
1852*4882a593Smuzhiyun /* Highest TSN that is acknowledged by incoming SACKs. */
1853*4882a593Smuzhiyun __u32 highest_sacked;
1854*4882a593Smuzhiyun
1855*4882a593Smuzhiyun /* TSN marking the fast recovery exit point */
1856*4882a593Smuzhiyun __u32 fast_recovery_exit;
1857*4882a593Smuzhiyun
1858*4882a593Smuzhiyun /* Flag to track the current fast recovery state */
1859*4882a593Smuzhiyun __u8 fast_recovery;
1860*4882a593Smuzhiyun
1861*4882a593Smuzhiyun /* The number of unacknowledged data chunks. Reported through
1862*4882a593Smuzhiyun * the SCTP_STATUS sockopt.
1863*4882a593Smuzhiyun */
1864*4882a593Smuzhiyun __u16 unack_data;
1865*4882a593Smuzhiyun
1866*4882a593Smuzhiyun /* The total number of data chunks that we've had to retransmit
1867*4882a593Smuzhiyun * as the result of a T3 timer expiration
1868*4882a593Smuzhiyun */
1869*4882a593Smuzhiyun __u32 rtx_data_chunks;
1870*4882a593Smuzhiyun
1871*4882a593Smuzhiyun /* This is the association's receive buffer space. This value is used
1872*4882a593Smuzhiyun * to set a_rwnd field in an INIT or a SACK chunk.
1873*4882a593Smuzhiyun */
1874*4882a593Smuzhiyun __u32 rwnd;
1875*4882a593Smuzhiyun
1876*4882a593Smuzhiyun /* This is the last advertised value of rwnd over a SACK chunk. */
1877*4882a593Smuzhiyun __u32 a_rwnd;
1878*4882a593Smuzhiyun
1879*4882a593Smuzhiyun /* Number of bytes by which the rwnd has slopped. The rwnd is allowed
1880*4882a593Smuzhiyun * to slop over a maximum of the association's frag_point.
1881*4882a593Smuzhiyun */
1882*4882a593Smuzhiyun __u32 rwnd_over;
1883*4882a593Smuzhiyun
1884*4882a593Smuzhiyun /* Keeps treack of rwnd pressure. This happens when we have
1885*4882a593Smuzhiyun * a window, but not recevie buffer (i.e small packets). This one
1886*4882a593Smuzhiyun * is releases slowly (1 PMTU at a time ).
1887*4882a593Smuzhiyun */
1888*4882a593Smuzhiyun __u32 rwnd_press;
1889*4882a593Smuzhiyun
1890*4882a593Smuzhiyun /* This is the sndbuf size in use for the association.
1891*4882a593Smuzhiyun * This corresponds to the sndbuf size for the association,
1892*4882a593Smuzhiyun * as specified in the sk->sndbuf.
1893*4882a593Smuzhiyun */
1894*4882a593Smuzhiyun int sndbuf_used;
1895*4882a593Smuzhiyun
1896*4882a593Smuzhiyun /* This is the amount of memory that this association has allocated
1897*4882a593Smuzhiyun * in the receive path at any given time.
1898*4882a593Smuzhiyun */
1899*4882a593Smuzhiyun atomic_t rmem_alloc;
1900*4882a593Smuzhiyun
1901*4882a593Smuzhiyun /* This is the wait queue head for send requests waiting on
1902*4882a593Smuzhiyun * the association sndbuf space.
1903*4882a593Smuzhiyun */
1904*4882a593Smuzhiyun wait_queue_head_t wait;
1905*4882a593Smuzhiyun
1906*4882a593Smuzhiyun /* The message size at which SCTP fragmentation will occur. */
1907*4882a593Smuzhiyun __u32 frag_point;
1908*4882a593Smuzhiyun __u32 user_frag;
1909*4882a593Smuzhiyun
1910*4882a593Smuzhiyun /* Counter used to count INIT errors. */
1911*4882a593Smuzhiyun int init_err_counter;
1912*4882a593Smuzhiyun
1913*4882a593Smuzhiyun /* Count the number of INIT cycles (for doubling timeout). */
1914*4882a593Smuzhiyun int init_cycle;
1915*4882a593Smuzhiyun
1916*4882a593Smuzhiyun /* Default send parameters. */
1917*4882a593Smuzhiyun __u16 default_stream;
1918*4882a593Smuzhiyun __u16 default_flags;
1919*4882a593Smuzhiyun __u32 default_ppid;
1920*4882a593Smuzhiyun __u32 default_context;
1921*4882a593Smuzhiyun __u32 default_timetolive;
1922*4882a593Smuzhiyun
1923*4882a593Smuzhiyun /* Default receive parameters */
1924*4882a593Smuzhiyun __u32 default_rcv_context;
1925*4882a593Smuzhiyun
1926*4882a593Smuzhiyun /* Stream arrays */
1927*4882a593Smuzhiyun struct sctp_stream stream;
1928*4882a593Smuzhiyun
1929*4882a593Smuzhiyun /* All outbound chunks go through this structure. */
1930*4882a593Smuzhiyun struct sctp_outq outqueue;
1931*4882a593Smuzhiyun
1932*4882a593Smuzhiyun /* A smart pipe that will handle reordering and fragmentation,
1933*4882a593Smuzhiyun * as well as handle passing events up to the ULP.
1934*4882a593Smuzhiyun */
1935*4882a593Smuzhiyun struct sctp_ulpq ulpq;
1936*4882a593Smuzhiyun
1937*4882a593Smuzhiyun /* Last TSN that caused an ECNE Chunk to be sent. */
1938*4882a593Smuzhiyun __u32 last_ecne_tsn;
1939*4882a593Smuzhiyun
1940*4882a593Smuzhiyun /* Last TSN that caused a CWR Chunk to be sent. */
1941*4882a593Smuzhiyun __u32 last_cwr_tsn;
1942*4882a593Smuzhiyun
1943*4882a593Smuzhiyun /* How many duplicated TSNs have we seen? */
1944*4882a593Smuzhiyun int numduptsns;
1945*4882a593Smuzhiyun
1946*4882a593Smuzhiyun /* These are to support
1947*4882a593Smuzhiyun * "SCTP Extensions for Dynamic Reconfiguration of IP Addresses
1948*4882a593Smuzhiyun * and Enforcement of Flow and Message Limits"
1949*4882a593Smuzhiyun * <draft-ietf-tsvwg-addip-sctp-02.txt>
1950*4882a593Smuzhiyun * or "ADDIP" for short.
1951*4882a593Smuzhiyun */
1952*4882a593Smuzhiyun
1953*4882a593Smuzhiyun
1954*4882a593Smuzhiyun
1955*4882a593Smuzhiyun /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
1956*4882a593Smuzhiyun *
1957*4882a593Smuzhiyun * R1) One and only one ASCONF Chunk MAY be in transit and
1958*4882a593Smuzhiyun * unacknowledged at any one time. If a sender, after sending
1959*4882a593Smuzhiyun * an ASCONF chunk, decides it needs to transfer another
1960*4882a593Smuzhiyun * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
1961*4882a593Smuzhiyun * returns from the previous ASCONF Chunk before sending a
1962*4882a593Smuzhiyun * subsequent ASCONF. Note this restriction binds each side,
1963*4882a593Smuzhiyun * so at any time two ASCONF may be in-transit on any given
1964*4882a593Smuzhiyun * association (one sent from each endpoint).
1965*4882a593Smuzhiyun *
1966*4882a593Smuzhiyun * [This is our one-and-only-one ASCONF in flight. If we do
1967*4882a593Smuzhiyun * not have an ASCONF in flight, this is NULL.]
1968*4882a593Smuzhiyun */
1969*4882a593Smuzhiyun struct sctp_chunk *addip_last_asconf;
1970*4882a593Smuzhiyun
1971*4882a593Smuzhiyun /* ADDIP Section 5.2 Upon reception of an ASCONF Chunk.
1972*4882a593Smuzhiyun *
1973*4882a593Smuzhiyun * This is needed to implement itmes E1 - E4 of the updated
1974*4882a593Smuzhiyun * spec. Here is the justification:
1975*4882a593Smuzhiyun *
1976*4882a593Smuzhiyun * Since the peer may bundle multiple ASCONF chunks toward us,
1977*4882a593Smuzhiyun * we now need the ability to cache multiple ACKs. The section
1978*4882a593Smuzhiyun * describes in detail how they are cached and cleaned up.
1979*4882a593Smuzhiyun */
1980*4882a593Smuzhiyun struct list_head asconf_ack_list;
1981*4882a593Smuzhiyun
1982*4882a593Smuzhiyun /* These ASCONF chunks are waiting to be sent.
1983*4882a593Smuzhiyun *
1984*4882a593Smuzhiyun * These chunaks can't be pushed to outqueue until receiving
1985*4882a593Smuzhiyun * ASCONF_ACK for the previous ASCONF indicated by
1986*4882a593Smuzhiyun * addip_last_asconf, so as to guarantee that only one ASCONF
1987*4882a593Smuzhiyun * is in flight at any time.
1988*4882a593Smuzhiyun *
1989*4882a593Smuzhiyun * ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
1990*4882a593Smuzhiyun *
1991*4882a593Smuzhiyun * In defining the ASCONF Chunk transfer procedures, it is
1992*4882a593Smuzhiyun * essential that these transfers MUST NOT cause congestion
1993*4882a593Smuzhiyun * within the network. To achieve this, we place these
1994*4882a593Smuzhiyun * restrictions on the transfer of ASCONF Chunks:
1995*4882a593Smuzhiyun *
1996*4882a593Smuzhiyun * R1) One and only one ASCONF Chunk MAY be in transit and
1997*4882a593Smuzhiyun * unacknowledged at any one time. If a sender, after sending
1998*4882a593Smuzhiyun * an ASCONF chunk, decides it needs to transfer another
1999*4882a593Smuzhiyun * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
2000*4882a593Smuzhiyun * returns from the previous ASCONF Chunk before sending a
2001*4882a593Smuzhiyun * subsequent ASCONF. Note this restriction binds each side,
2002*4882a593Smuzhiyun * so at any time two ASCONF may be in-transit on any given
2003*4882a593Smuzhiyun * association (one sent from each endpoint).
2004*4882a593Smuzhiyun *
2005*4882a593Smuzhiyun *
2006*4882a593Smuzhiyun * [I really think this is EXACTLY the sort of intelligence
2007*4882a593Smuzhiyun * which already resides in sctp_outq. Please move this
2008*4882a593Smuzhiyun * queue and its supporting logic down there. --piggy]
2009*4882a593Smuzhiyun */
2010*4882a593Smuzhiyun struct list_head addip_chunk_list;
2011*4882a593Smuzhiyun
2012*4882a593Smuzhiyun /* ADDIP Section 4.1 ASCONF Chunk Procedures
2013*4882a593Smuzhiyun *
2014*4882a593Smuzhiyun * A2) A serial number should be assigned to the Chunk. The
2015*4882a593Smuzhiyun * serial number SHOULD be a monotonically increasing
2016*4882a593Smuzhiyun * number. The serial number SHOULD be initialized at
2017*4882a593Smuzhiyun * the start of the association to the same value as the
2018*4882a593Smuzhiyun * Initial TSN and every time a new ASCONF chunk is created
2019*4882a593Smuzhiyun * it is incremented by one after assigning the serial number
2020*4882a593Smuzhiyun * to the newly created chunk.
2021*4882a593Smuzhiyun *
2022*4882a593Smuzhiyun * ADDIP
2023*4882a593Smuzhiyun * 3.1.1 Address/Stream Configuration Change Chunk (ASCONF)
2024*4882a593Smuzhiyun *
2025*4882a593Smuzhiyun * Serial Number : 32 bits (unsigned integer)
2026*4882a593Smuzhiyun *
2027*4882a593Smuzhiyun * This value represents a Serial Number for the ASCONF
2028*4882a593Smuzhiyun * Chunk. The valid range of Serial Number is from 0 to
2029*4882a593Smuzhiyun * 4294967295 (2^32 - 1). Serial Numbers wrap back to 0
2030*4882a593Smuzhiyun * after reaching 4294967295.
2031*4882a593Smuzhiyun */
2032*4882a593Smuzhiyun __u32 addip_serial;
2033*4882a593Smuzhiyun int src_out_of_asoc_ok;
2034*4882a593Smuzhiyun union sctp_addr *asconf_addr_del_pending;
2035*4882a593Smuzhiyun struct sctp_transport *new_transport;
2036*4882a593Smuzhiyun
2037*4882a593Smuzhiyun /* SCTP AUTH: list of the endpoint shared keys. These
2038*4882a593Smuzhiyun * keys are provided out of band by the user applicaton
2039*4882a593Smuzhiyun * and can't change during the lifetime of the association
2040*4882a593Smuzhiyun */
2041*4882a593Smuzhiyun struct list_head endpoint_shared_keys;
2042*4882a593Smuzhiyun
2043*4882a593Smuzhiyun /* SCTP AUTH:
2044*4882a593Smuzhiyun * The current generated assocaition shared key (secret)
2045*4882a593Smuzhiyun */
2046*4882a593Smuzhiyun struct sctp_auth_bytes *asoc_shared_key;
2047*4882a593Smuzhiyun struct sctp_shared_key *shkey;
2048*4882a593Smuzhiyun
2049*4882a593Smuzhiyun /* SCTP AUTH: hmac id of the first peer requested algorithm
2050*4882a593Smuzhiyun * that we support.
2051*4882a593Smuzhiyun */
2052*4882a593Smuzhiyun __u16 default_hmac_id;
2053*4882a593Smuzhiyun
2054*4882a593Smuzhiyun __u16 active_key_id;
2055*4882a593Smuzhiyun
2056*4882a593Smuzhiyun __u8 need_ecne:1, /* Need to send an ECNE Chunk? */
2057*4882a593Smuzhiyun temp:1, /* Is it a temporary association? */
2058*4882a593Smuzhiyun pf_expose:2, /* Expose pf state? */
2059*4882a593Smuzhiyun force_delay:1;
2060*4882a593Smuzhiyun
2061*4882a593Smuzhiyun __u8 strreset_enable;
2062*4882a593Smuzhiyun __u8 strreset_outstanding; /* request param count on the fly */
2063*4882a593Smuzhiyun
2064*4882a593Smuzhiyun __u32 strreset_outseq; /* Update after receiving response */
2065*4882a593Smuzhiyun __u32 strreset_inseq; /* Update after receiving request */
2066*4882a593Smuzhiyun __u32 strreset_result[2]; /* save the results of last 2 responses */
2067*4882a593Smuzhiyun
2068*4882a593Smuzhiyun struct sctp_chunk *strreset_chunk; /* save request chunk */
2069*4882a593Smuzhiyun
2070*4882a593Smuzhiyun struct sctp_priv_assoc_stats stats;
2071*4882a593Smuzhiyun
2072*4882a593Smuzhiyun int sent_cnt_removable;
2073*4882a593Smuzhiyun
2074*4882a593Smuzhiyun __u16 subscribe;
2075*4882a593Smuzhiyun
2076*4882a593Smuzhiyun __u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
2077*4882a593Smuzhiyun __u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
2078*4882a593Smuzhiyun
2079*4882a593Smuzhiyun struct rcu_head rcu;
2080*4882a593Smuzhiyun };
2081*4882a593Smuzhiyun
2082*4882a593Smuzhiyun
2083*4882a593Smuzhiyun /* An eyecatcher for determining if we are really looking at an
2084*4882a593Smuzhiyun * association data structure.
2085*4882a593Smuzhiyun */
2086*4882a593Smuzhiyun enum {
2087*4882a593Smuzhiyun SCTP_ASSOC_EYECATCHER = 0xa550c123,
2088*4882a593Smuzhiyun };
2089*4882a593Smuzhiyun
2090*4882a593Smuzhiyun /* Recover the outter association structure. */
sctp_assoc(struct sctp_ep_common * base)2091*4882a593Smuzhiyun static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base)
2092*4882a593Smuzhiyun {
2093*4882a593Smuzhiyun struct sctp_association *asoc;
2094*4882a593Smuzhiyun
2095*4882a593Smuzhiyun asoc = container_of(base, struct sctp_association, base);
2096*4882a593Smuzhiyun return asoc;
2097*4882a593Smuzhiyun }
2098*4882a593Smuzhiyun
2099*4882a593Smuzhiyun /* These are function signatures for manipulating associations. */
2100*4882a593Smuzhiyun
2101*4882a593Smuzhiyun
2102*4882a593Smuzhiyun struct sctp_association *
2103*4882a593Smuzhiyun sctp_association_new(const struct sctp_endpoint *ep, const struct sock *sk,
2104*4882a593Smuzhiyun enum sctp_scope scope, gfp_t gfp);
2105*4882a593Smuzhiyun void sctp_association_free(struct sctp_association *);
2106*4882a593Smuzhiyun void sctp_association_put(struct sctp_association *);
2107*4882a593Smuzhiyun void sctp_association_hold(struct sctp_association *);
2108*4882a593Smuzhiyun
2109*4882a593Smuzhiyun struct sctp_transport *sctp_assoc_choose_alter_transport(
2110*4882a593Smuzhiyun struct sctp_association *, struct sctp_transport *);
2111*4882a593Smuzhiyun void sctp_assoc_update_retran_path(struct sctp_association *);
2112*4882a593Smuzhiyun struct sctp_transport *sctp_assoc_lookup_paddr(const struct sctp_association *,
2113*4882a593Smuzhiyun const union sctp_addr *);
2114*4882a593Smuzhiyun int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
2115*4882a593Smuzhiyun const union sctp_addr *laddr);
2116*4882a593Smuzhiyun struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *,
2117*4882a593Smuzhiyun const union sctp_addr *address,
2118*4882a593Smuzhiyun const gfp_t gfp,
2119*4882a593Smuzhiyun const int peer_state);
2120*4882a593Smuzhiyun void sctp_assoc_del_peer(struct sctp_association *asoc,
2121*4882a593Smuzhiyun const union sctp_addr *addr);
2122*4882a593Smuzhiyun void sctp_assoc_rm_peer(struct sctp_association *asoc,
2123*4882a593Smuzhiyun struct sctp_transport *peer);
2124*4882a593Smuzhiyun void sctp_assoc_control_transport(struct sctp_association *asoc,
2125*4882a593Smuzhiyun struct sctp_transport *transport,
2126*4882a593Smuzhiyun enum sctp_transport_cmd command,
2127*4882a593Smuzhiyun sctp_sn_error_t error);
2128*4882a593Smuzhiyun struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32);
2129*4882a593Smuzhiyun void sctp_assoc_migrate(struct sctp_association *, struct sock *);
2130*4882a593Smuzhiyun int sctp_assoc_update(struct sctp_association *old,
2131*4882a593Smuzhiyun struct sctp_association *new);
2132*4882a593Smuzhiyun
2133*4882a593Smuzhiyun __u32 sctp_association_get_next_tsn(struct sctp_association *);
2134*4882a593Smuzhiyun
2135*4882a593Smuzhiyun void sctp_assoc_update_frag_point(struct sctp_association *asoc);
2136*4882a593Smuzhiyun void sctp_assoc_set_pmtu(struct sctp_association *asoc, __u32 pmtu);
2137*4882a593Smuzhiyun void sctp_assoc_sync_pmtu(struct sctp_association *asoc);
2138*4882a593Smuzhiyun void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned int);
2139*4882a593Smuzhiyun void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned int);
2140*4882a593Smuzhiyun void sctp_assoc_set_primary(struct sctp_association *,
2141*4882a593Smuzhiyun struct sctp_transport *);
2142*4882a593Smuzhiyun void sctp_assoc_del_nonprimary_peers(struct sctp_association *,
2143*4882a593Smuzhiyun struct sctp_transport *);
2144*4882a593Smuzhiyun int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
2145*4882a593Smuzhiyun enum sctp_scope scope, gfp_t gfp);
2146*4882a593Smuzhiyun int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *,
2147*4882a593Smuzhiyun struct sctp_cookie*,
2148*4882a593Smuzhiyun gfp_t gfp);
2149*4882a593Smuzhiyun int sctp_assoc_set_id(struct sctp_association *, gfp_t);
2150*4882a593Smuzhiyun void sctp_assoc_clean_asconf_ack_cache(const struct sctp_association *asoc);
2151*4882a593Smuzhiyun struct sctp_chunk *sctp_assoc_lookup_asconf_ack(
2152*4882a593Smuzhiyun const struct sctp_association *asoc,
2153*4882a593Smuzhiyun __be32 serial);
2154*4882a593Smuzhiyun void sctp_asconf_queue_teardown(struct sctp_association *asoc);
2155*4882a593Smuzhiyun
2156*4882a593Smuzhiyun int sctp_cmp_addr_exact(const union sctp_addr *ss1,
2157*4882a593Smuzhiyun const union sctp_addr *ss2);
2158*4882a593Smuzhiyun struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc);
2159*4882a593Smuzhiyun
2160*4882a593Smuzhiyun /* A convenience structure to parse out SCTP specific CMSGs. */
2161*4882a593Smuzhiyun struct sctp_cmsgs {
2162*4882a593Smuzhiyun struct sctp_initmsg *init;
2163*4882a593Smuzhiyun struct sctp_sndrcvinfo *srinfo;
2164*4882a593Smuzhiyun struct sctp_sndinfo *sinfo;
2165*4882a593Smuzhiyun struct sctp_prinfo *prinfo;
2166*4882a593Smuzhiyun struct sctp_authinfo *authinfo;
2167*4882a593Smuzhiyun struct msghdr *addrs_msg;
2168*4882a593Smuzhiyun };
2169*4882a593Smuzhiyun
2170*4882a593Smuzhiyun /* Structure for tracking memory objects */
2171*4882a593Smuzhiyun struct sctp_dbg_objcnt_entry {
2172*4882a593Smuzhiyun char *label;
2173*4882a593Smuzhiyun atomic_t *counter;
2174*4882a593Smuzhiyun };
2175*4882a593Smuzhiyun
2176*4882a593Smuzhiyun #endif /* __sctp_structs_h__ */
2177