Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-drm-fsl-dcu.git] / include / net / sctp / constants.h
1 /* SCTP kernel implementation
2  * (C) Copyright IBM Corp. 2001, 2004
3  * Copyright (c) 1999-2000 Cisco, Inc.
4  * Copyright (c) 1999-2001 Motorola, Inc.
5  * Copyright (c) 2001 Intel Corp.
6  *
7  * This file is part of the SCTP kernel implementation
8  *
9  * This SCTP implementation is free software;
10  * you can redistribute it and/or modify it under the terms of
11  * the GNU General Public License as published by
12  * the Free Software Foundation; either version 2, or (at your option)
13  * any later version.
14  *
15  * This SCTP implementation is distributed in the hope that it
16  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17  *                 ************************
18  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with GNU CC; see the file COPYING.  If not, write to
23  * the Free Software Foundation, 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * Please send any bug reports or fixes you make to the
27  * email address(es):
28  *    lksctp developers <linux-sctp@vger.kernel.org>
29  *
30  * Written or modified by:
31  *   La Monte H.P. Yarroll <piggy@acm.org>
32  *   Karl Knutson          <karl@athena.chicago.il.us>
33  *   Randall Stewart       <randall@stewart.chicago.il.us>
34  *   Ken Morneau           <kmorneau@cisco.com>
35  *   Qiaobing Xie          <qxie1@motorola.com>
36  *   Xingang Guo           <xingang.guo@intel.com>
37  *   Sridhar Samudrala     <samudrala@us.ibm.com>
38  *   Daisy Chang           <daisyc@us.ibm.com>
39  */
40
41 #ifndef __sctp_constants_h__
42 #define __sctp_constants_h__
43
44 #include <linux/sctp.h>
45 #include <linux/ipv6.h> /* For ipv6hdr. */
46 #include <net/tcp_states.h>  /* For TCP states used in sctp_sock_state_t */
47
48 /* Value used for stream negotiation. */
49 enum { SCTP_MAX_STREAM = 0xffff };
50 enum { SCTP_DEFAULT_OUTSTREAMS = 10 };
51 enum { SCTP_DEFAULT_INSTREAMS = SCTP_MAX_STREAM };
52
53 /* Since CIDs are sparse, we need all four of the following
54  * symbols.  CIDs are dense through SCTP_CID_BASE_MAX.
55  */
56 #define SCTP_CID_BASE_MAX               SCTP_CID_SHUTDOWN_COMPLETE
57
58 #define SCTP_NUM_BASE_CHUNK_TYPES       (SCTP_CID_BASE_MAX + 1)
59
60 #define SCTP_NUM_ADDIP_CHUNK_TYPES      2
61
62 #define SCTP_NUM_PRSCTP_CHUNK_TYPES     1
63
64 #define SCTP_NUM_AUTH_CHUNK_TYPES       1
65
66 #define SCTP_NUM_CHUNK_TYPES            (SCTP_NUM_BASE_CHUNK_TYPES + \
67                                          SCTP_NUM_ADDIP_CHUNK_TYPES +\
68                                          SCTP_NUM_PRSCTP_CHUNK_TYPES +\
69                                          SCTP_NUM_AUTH_CHUNK_TYPES)
70
71 /* These are the different flavours of event.  */
72 typedef enum {
73
74         SCTP_EVENT_T_CHUNK = 1,
75         SCTP_EVENT_T_TIMEOUT,
76         SCTP_EVENT_T_OTHER,
77         SCTP_EVENT_T_PRIMITIVE
78
79 } sctp_event_t;
80
81 /* As a convenience for the state machine, we append SCTP_EVENT_* and
82  * SCTP_ULP_* to the list of possible chunks.
83  */
84
85 typedef enum {
86         SCTP_EVENT_TIMEOUT_NONE = 0,
87         SCTP_EVENT_TIMEOUT_T1_COOKIE,
88         SCTP_EVENT_TIMEOUT_T1_INIT,
89         SCTP_EVENT_TIMEOUT_T2_SHUTDOWN,
90         SCTP_EVENT_TIMEOUT_T3_RTX,
91         SCTP_EVENT_TIMEOUT_T4_RTO,
92         SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD,
93         SCTP_EVENT_TIMEOUT_HEARTBEAT,
94         SCTP_EVENT_TIMEOUT_SACK,
95         SCTP_EVENT_TIMEOUT_AUTOCLOSE,
96 } sctp_event_timeout_t;
97
98 #define SCTP_EVENT_TIMEOUT_MAX          SCTP_EVENT_TIMEOUT_AUTOCLOSE
99 #define SCTP_NUM_TIMEOUT_TYPES          (SCTP_EVENT_TIMEOUT_MAX + 1)
100
101 typedef enum {
102         SCTP_EVENT_NO_PENDING_TSN = 0,
103         SCTP_EVENT_ICMP_PROTO_UNREACH,
104 } sctp_event_other_t;
105
106 #define SCTP_EVENT_OTHER_MAX            SCTP_EVENT_ICMP_PROTO_UNREACH
107 #define SCTP_NUM_OTHER_TYPES            (SCTP_EVENT_OTHER_MAX + 1)
108
109 /* These are primitive requests from the ULP.  */
110 typedef enum {
111         SCTP_PRIMITIVE_ASSOCIATE = 0,
112         SCTP_PRIMITIVE_SHUTDOWN,
113         SCTP_PRIMITIVE_ABORT,
114         SCTP_PRIMITIVE_SEND,
115         SCTP_PRIMITIVE_REQUESTHEARTBEAT,
116         SCTP_PRIMITIVE_ASCONF,
117 } sctp_event_primitive_t;
118
119 #define SCTP_EVENT_PRIMITIVE_MAX        SCTP_PRIMITIVE_ASCONF
120 #define SCTP_NUM_PRIMITIVE_TYPES        (SCTP_EVENT_PRIMITIVE_MAX + 1)
121
122 /* We define here a utility type for manipulating subtypes.
123  * The subtype constructors all work like this:
124  *
125  *      sctp_subtype_t foo = SCTP_ST_CHUNK(SCTP_CID_INIT);
126  */
127
128 typedef union {
129         sctp_cid_t chunk;
130         sctp_event_timeout_t timeout;
131         sctp_event_other_t other;
132         sctp_event_primitive_t primitive;
133 } sctp_subtype_t;
134
135 #define SCTP_SUBTYPE_CONSTRUCTOR(_name, _type, _elt) \
136 static inline sctp_subtype_t    \
137 SCTP_ST_## _name (_type _arg)           \
138 { sctp_subtype_t _retval; _retval._elt = _arg; return _retval; }
139
140 SCTP_SUBTYPE_CONSTRUCTOR(CHUNK,         sctp_cid_t,             chunk)
141 SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT,       sctp_event_timeout_t,   timeout)
142 SCTP_SUBTYPE_CONSTRUCTOR(OTHER,         sctp_event_other_t,     other)
143 SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE,     sctp_event_primitive_t, primitive)
144
145
146 #define sctp_chunk_is_data(a) (a->chunk_hdr->type == SCTP_CID_DATA)
147
148 /* Calculate the actual data size in a data chunk */
149 #define SCTP_DATA_SNDSIZE(c) ((int)((unsigned long)(c->chunk_end)\
150                                 - (unsigned long)(c->chunk_hdr)\
151                                 - sizeof(sctp_data_chunk_t)))
152
153 /* Internal error codes */
154 typedef enum {
155
156         SCTP_IERROR_NO_ERROR            = 0,
157         SCTP_IERROR_BASE                = 1000,
158         SCTP_IERROR_NO_COOKIE,
159         SCTP_IERROR_BAD_SIG,
160         SCTP_IERROR_STALE_COOKIE,
161         SCTP_IERROR_NOMEM,
162         SCTP_IERROR_MALFORMED,
163         SCTP_IERROR_BAD_TAG,
164         SCTP_IERROR_BIG_GAP,
165         SCTP_IERROR_DUP_TSN,
166         SCTP_IERROR_HIGH_TSN,
167         SCTP_IERROR_IGNORE_TSN,
168         SCTP_IERROR_NO_DATA,
169         SCTP_IERROR_BAD_STREAM,
170         SCTP_IERROR_BAD_PORTS,
171         SCTP_IERROR_AUTH_BAD_HMAC,
172         SCTP_IERROR_AUTH_BAD_KEYID,
173         SCTP_IERROR_PROTO_VIOLATION,
174         SCTP_IERROR_ERROR,
175         SCTP_IERROR_ABORT,
176 } sctp_ierror_t;
177
178
179
180 /* SCTP state defines for internal state machine */
181 typedef enum {
182
183         SCTP_STATE_CLOSED               = 0,
184         SCTP_STATE_COOKIE_WAIT          = 1,
185         SCTP_STATE_COOKIE_ECHOED        = 2,
186         SCTP_STATE_ESTABLISHED          = 3,
187         SCTP_STATE_SHUTDOWN_PENDING     = 4,
188         SCTP_STATE_SHUTDOWN_SENT        = 5,
189         SCTP_STATE_SHUTDOWN_RECEIVED    = 6,
190         SCTP_STATE_SHUTDOWN_ACK_SENT    = 7,
191
192 } sctp_state_t;
193
194 #define SCTP_STATE_MAX                  SCTP_STATE_SHUTDOWN_ACK_SENT
195 #define SCTP_STATE_NUM_STATES           (SCTP_STATE_MAX + 1)
196
197 /* These are values for sk->state.
198  * For a UDP-style SCTP socket, the states are defined as follows
199  * - A socket in SCTP_SS_CLOSED state indicates that it is not willing to
200  *   accept new associations, but it can initiate the creation of new ones.
201  * - A socket in SCTP_SS_LISTENING state indicates that it is willing to
202  *   accept new  associations and can initiate the creation of new ones.
203  * - A socket in SCTP_SS_ESTABLISHED state indicates that it is a peeled off
204  *   socket with one association.
205  * For a TCP-style SCTP socket, the states are defined as follows
206  * - A socket in SCTP_SS_CLOSED state indicates that it is not willing to
207  *   accept new associations, but it can initiate the creation of new ones.
208  * - A socket in SCTP_SS_LISTENING state indicates that it is willing to
209  *   accept new associations, but cannot initiate the creation of new ones.
210  * - A socket in SCTP_SS_ESTABLISHED state indicates that it has a single 
211  *   association.
212  */
213 typedef enum {
214         SCTP_SS_CLOSED         = TCP_CLOSE,
215         SCTP_SS_LISTENING      = TCP_LISTEN,
216         SCTP_SS_ESTABLISHING   = TCP_SYN_SENT,
217         SCTP_SS_ESTABLISHED    = TCP_ESTABLISHED,
218         SCTP_SS_CLOSING        = TCP_CLOSING,
219 } sctp_sock_state_t;
220
221 /* These functions map various type to printable names.  */
222 const char *sctp_cname(const sctp_subtype_t);   /* chunk types */
223 const char *sctp_oname(const sctp_subtype_t);   /* other events */
224 const char *sctp_tname(const sctp_subtype_t);   /* timeouts */
225 const char *sctp_pname(const sctp_subtype_t);   /* primitives */
226
227 /* This is a table of printable names of sctp_state_t's.  */
228 extern const char *const sctp_state_tbl[];
229 extern const char *const sctp_evttype_tbl[];
230 extern const char *const sctp_status_tbl[];
231
232 /* Maximum chunk length considering padding requirements. */
233 enum { SCTP_MAX_CHUNK_LEN = ((1<<16) - sizeof(__u32)) };
234
235 /* Encourage Cookie-Echo bundling by pre-fragmenting chunks a little
236  * harder (until reaching ESTABLISHED state).
237  */
238 enum { SCTP_ARBITRARY_COOKIE_ECHO_LEN = 200 };
239
240 /* Guess at how big to make the TSN mapping array.
241  * We guarantee that we can handle at least this big a gap between the
242  * cumulative ACK and the highest TSN.  In practice, we can often
243  * handle up to twice this value.
244  *
245  * NEVER make this more than 32767 (2^15-1).  The Gap Ack Blocks in a
246  * SACK (see  section 3.3.4) are only 16 bits, so 2*SCTP_TSN_MAP_SIZE
247  * must be less than 65535 (2^16 - 1), or we will have overflow
248  * problems creating SACK's.
249  */
250 #define SCTP_TSN_MAP_INITIAL BITS_PER_LONG
251 #define SCTP_TSN_MAP_INCREMENT SCTP_TSN_MAP_INITIAL
252 #define SCTP_TSN_MAP_SIZE 4096
253
254 /* We will not record more than this many duplicate TSNs between two
255  * SACKs.  The minimum PMTU is 576.  Remove all the headers and there
256  * is enough room for 131 duplicate reports.  Round down to the
257  * nearest power of 2.
258  */
259 enum { SCTP_MIN_PMTU = 576 };
260 enum { SCTP_MAX_DUP_TSNS = 16 };
261 enum { SCTP_MAX_GABS = 16 };
262
263 /* Heartbeat interval - 30 secs */
264 #define SCTP_DEFAULT_TIMEOUT_HEARTBEAT  (30*1000)
265
266 /* Delayed sack timer - 200ms */
267 #define SCTP_DEFAULT_TIMEOUT_SACK       (200)
268
269 /* RTO.Initial              - 3  seconds
270  * RTO.Min                  - 1  second
271  * RTO.Max                  - 60 seconds
272  * RTO.Alpha                - 1/8
273  * RTO.Beta                 - 1/4
274  */
275 #define SCTP_RTO_INITIAL        (3 * 1000)
276 #define SCTP_RTO_MIN            (1 * 1000)
277 #define SCTP_RTO_MAX            (60 * 1000)
278
279 #define SCTP_RTO_ALPHA          3   /* 1/8 when converted to right shifts. */
280 #define SCTP_RTO_BETA           2   /* 1/4 when converted to right shifts. */
281
282 /* Maximum number of new data packets that can be sent in a burst.  */
283 #define SCTP_DEFAULT_MAX_BURST          4
284
285 #define SCTP_CLOCK_GRANULARITY  1       /* 1 jiffy */
286
287 #define SCTP_DEFAULT_COOKIE_LIFE        (60 * 1000) /* 60 seconds */
288
289 #define SCTP_DEFAULT_MINWINDOW  1500    /* default minimum rwnd size */
290 #define SCTP_DEFAULT_MAXWINDOW  65535   /* default rwnd size */
291 #define SCTP_DEFAULT_RWND_SHIFT  4      /* by default, update on 1/16 of
292                                          * rcvbuf, which is 1/8 of initial
293                                          * window
294                                          */
295 #define SCTP_DEFAULT_MAXSEGMENT 1500    /* MTU size, this is the limit
296                                          * to which we will raise the P-MTU.
297                                          */
298 #define SCTP_DEFAULT_MINSEGMENT 512     /* MTU size ... if no mtu disc */
299
300 #define SCTP_SECRET_SIZE 32             /* Number of octets in a 256 bits. */
301
302 #define SCTP_SIGNATURE_SIZE 20          /* size of a SLA-1 signature */
303
304 #define SCTP_COOKIE_MULTIPLE 32 /* Pad out our cookie to make our hash
305                                  * functions simpler to write.
306                                  */
307
308 /* These return values describe the success or failure of a number of
309  * routines which form the lower interface to SCTP_outqueue.
310  */
311 typedef enum {
312         SCTP_XMIT_OK,
313         SCTP_XMIT_PMTU_FULL,
314         SCTP_XMIT_RWND_FULL,
315         SCTP_XMIT_NAGLE_DELAY,
316 } sctp_xmit_t;
317
318 /* These are the commands for manipulating transports.  */
319 typedef enum {
320         SCTP_TRANSPORT_UP,
321         SCTP_TRANSPORT_DOWN,
322         SCTP_TRANSPORT_PF,
323 } sctp_transport_cmd_t;
324
325 /* These are the address scopes defined mainly for IPv4 addresses
326  * based on draft of SCTP IPv4 scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
327  * These scopes are hopefully generic enough to be used on scoping both
328  * IPv4 and IPv6 addresses in SCTP.
329  * At this point, the IPv6 scopes will be mapped to these internal scopes
330  * as much as possible.
331  */
332 typedef enum {
333         SCTP_SCOPE_GLOBAL,              /* IPv4 global addresses */
334         SCTP_SCOPE_PRIVATE,             /* IPv4 private addresses */
335         SCTP_SCOPE_LINK,                /* IPv4 link local address */
336         SCTP_SCOPE_LOOPBACK,            /* IPv4 loopback address */
337         SCTP_SCOPE_UNUSABLE,            /* IPv4 unusable addresses */
338 } sctp_scope_t;
339
340 typedef enum {
341         SCTP_SCOPE_POLICY_DISABLE,      /* Disable IPv4 address scoping */
342         SCTP_SCOPE_POLICY_ENABLE,       /* Enable IPv4 address scoping */
343         SCTP_SCOPE_POLICY_PRIVATE,      /* Follow draft but allow IPv4 private addresses */
344         SCTP_SCOPE_POLICY_LINK,         /* Follow draft but allow IPv4 link local addresses */
345 } sctp_scope_policy_t;
346
347 /* Based on IPv4 scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>,
348  * SCTP IPv4 unusable addresses: 0.0.0.0/8, 224.0.0.0/4, 198.18.0.0/24,
349  * 192.88.99.0/24.
350  * Also, RFC 8.4, non-unicast addresses are not considered valid SCTP
351  * addresses.
352  */
353 #define IS_IPV4_UNUSABLE_ADDRESS(a)         \
354         ((htonl(INADDR_BROADCAST) == a) ||  \
355          ipv4_is_multicast(a) ||            \
356          ipv4_is_zeronet(a) ||              \
357          ipv4_is_test_198(a) ||             \
358          ipv4_is_anycast_6to4(a))
359
360 /* Flags used for the bind address copy functions.  */
361 #define SCTP_ADDR6_ALLOWED      0x00000001      /* IPv6 address is allowed by
362                                                    local sock family */
363 #define SCTP_ADDR4_PEERSUPP     0x00000002      /* IPv4 address is supported by
364                                                    peer */
365 #define SCTP_ADDR6_PEERSUPP     0x00000004      /* IPv6 address is supported by
366                                                    peer */
367
368 /* Reasons to retransmit. */
369 typedef enum {
370         SCTP_RTXR_T3_RTX,
371         SCTP_RTXR_FAST_RTX,
372         SCTP_RTXR_PMTUD,
373         SCTP_RTXR_T1_RTX,
374 } sctp_retransmit_reason_t;
375
376 /* Reasons to lower cwnd. */
377 typedef enum {
378         SCTP_LOWER_CWND_T3_RTX,
379         SCTP_LOWER_CWND_FAST_RTX,
380         SCTP_LOWER_CWND_ECNE,
381         SCTP_LOWER_CWND_INACTIVE,
382 } sctp_lower_cwnd_t;
383
384
385 /* SCTP-AUTH Necessary constants */
386
387 /* SCTP-AUTH, Section 3.3
388  *
389  *  The following Table 2 shows the currently defined values for HMAC
390  *  identifiers.
391  *
392  *  +-----------------+--------------------------+
393  *  | HMAC Identifier | Message Digest Algorithm |
394  *  +-----------------+--------------------------+
395  *  | 0               | Reserved                 |
396  *  | 1               | SHA-1 defined in [8]     |
397  *  | 2               | Reserved                 |
398  *  | 3               | SHA-256 defined in [8]   |
399  *  +-----------------+--------------------------+
400  */
401 enum {
402         SCTP_AUTH_HMAC_ID_RESERVED_0,
403         SCTP_AUTH_HMAC_ID_SHA1,
404         SCTP_AUTH_HMAC_ID_RESERVED_2,
405 #if defined (CONFIG_CRYPTO_SHA256) || defined (CONFIG_CRYPTO_SHA256_MODULE)
406         SCTP_AUTH_HMAC_ID_SHA256,
407 #endif
408         __SCTP_AUTH_HMAC_MAX
409 };
410
411 #define SCTP_AUTH_HMAC_ID_MAX   __SCTP_AUTH_HMAC_MAX - 1
412 #define SCTP_AUTH_NUM_HMACS     __SCTP_AUTH_HMAC_MAX
413 #define SCTP_SHA1_SIG_SIZE 20
414 #define SCTP_SHA256_SIG_SIZE 32
415
416 /*  SCTP-AUTH, Section 3.2
417  *     The chunk types for INIT, INIT-ACK, SHUTDOWN-COMPLETE and AUTH chunks
418  *     MUST NOT be listed in the CHUNKS parameter
419  */
420 #define SCTP_NUM_NOAUTH_CHUNKS  4
421 #define SCTP_AUTH_MAX_CHUNKS    (SCTP_NUM_CHUNK_TYPES - SCTP_NUM_NOAUTH_CHUNKS)
422
423 /* SCTP-AUTH Section 6.1
424  * The RANDOM parameter MUST contain a 32 byte random number.
425  */
426 #define SCTP_AUTH_RANDOM_LENGTH 32
427
428 #endif /* __sctp_constants_h__ */