constants.h 13.9 KB
Newer Older
Jon Grimm's avatar
Jon Grimm committed
1 2 3 4 5
/* SCTP kernel reference Implementation
 * Copyright (c) 1999-2000 Cisco, Inc.
 * Copyright (c) 1999-2001 Motorola, Inc.
 * Copyright (c) 2001 Intel Corp.
 * Copyright (c) 2001-2002 International Business Machines Corp.
Jon Grimm's avatar
Jon Grimm committed
6
 *
Jon Grimm's avatar
Jon Grimm committed
7
 * This file is part of the SCTP kernel reference Implementation
Jon Grimm's avatar
Jon Grimm committed
8
 *
Jon Grimm's avatar
Jon Grimm committed
9 10 11
 * This file is part of the implementation of the add-IP extension,
 * based on <draft-ietf-tsvwg-addip-sctp-02.txt> June 29, 2001,
 * for the SCTP kernel reference Implementation.
Jon Grimm's avatar
Jon Grimm committed
12 13 14
 *
 * The SCTP reference implementation  is free software;
 * you can redistribute it and/or modify it under the terms of
Jon Grimm's avatar
Jon Grimm committed
15 16 17
 * the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
Jon Grimm's avatar
Jon Grimm committed
18 19
 *
 * the SCTP reference implementation  is distributed in the hope that it
Jon Grimm's avatar
Jon Grimm committed
20 21 22 23
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 *                 ************************
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
Jon Grimm's avatar
Jon Grimm committed
24
 *
Jon Grimm's avatar
Jon Grimm committed
25 26 27
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
Jon Grimm's avatar
Jon Grimm committed
28 29
 * Boston, MA 02111-1307, USA.
 *
Jon Grimm's avatar
Jon Grimm committed
30 31
 * Please send any bug reports or fixes you make to one of the following email
 * addresses:
Jon Grimm's avatar
Jon Grimm committed
32
 *
Jon Grimm's avatar
Jon Grimm committed
33 34 35 36 37 38 39 40
 * La Monte H.P. Yarroll <piggy@acm.org>
 * Karl Knutson <karl@athena.chicago.il.us>
 * Randall Stewart <randall@stewart.chicago.il.us>
 * Ken Morneau <kmorneau@cisco.com>
 * Qiaobing Xie <qxie1@motorola.com>
 * Xingang Guo <xingang.guo@intel.com>
 * Sridhar Samudrala <samudrala@us.ibm.com>
 * Daisy Chang <daisyc@us.ibm.com>
Jon Grimm's avatar
Jon Grimm committed
41
 *
Jon Grimm's avatar
Jon Grimm committed
42 43
 * Any bugs reported given to us we will try to fix... any fixes shared will
 * be incorporated into the next SCTP release.
Jon Grimm's avatar
Jon Grimm committed
44
 *
Jon Grimm's avatar
Jon Grimm committed
45 46
 * There are still LOTS of bugs in this code... I always run on the motto
 * "it is a wonder any code ever works :)"
Jon Grimm's avatar
Jon Grimm committed
47 48
 *
 *
Jon Grimm's avatar
Jon Grimm committed
49 50 51 52 53 54 55 56
 */

#ifndef __sctp_constants_h__
#define __sctp_constants_h__

#include <linux/tcp.h>  /* For TCP states used in sctp_sock_state_t */
#include <linux/sctp.h>
#include <linux/ipv6.h> /* For ipv6hdr. */
57
#include <net/sctp/user.h>
Jon Grimm's avatar
Jon Grimm committed
58

59 60 61 62
/* Value used for stream negotiation. */
enum { SCTP_MAX_STREAM = 0xffff };
enum { SCTP_DEFAULT_OUTSTREAMS = 10 };
enum { SCTP_DEFAULT_INSTREAMS = SCTP_MAX_STREAM };
Jon Grimm's avatar
Jon Grimm committed
63

64 65
/* Define the amount of space to reserve for SCTP, IP, LL.
 * There is a little bit of waste that we are always allocating
Jon Grimm's avatar
Jon Grimm committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
 * for ipv6 headers, but this seems worth the simplicity.
 */

#define SCTP_IP_OVERHEAD ((sizeof(struct sctphdr)\
                          + sizeof(struct ipv6hdr)\
                          + MAX_HEADER))

/* Since CIDs are sparse, we need all four of the following
 * symbols.  CIDs are dense through SCTP_CID_BASE_MAX.
 */
#define SCTP_CID_BASE_MAX		SCTP_CID_SHUTDOWN_COMPLETE
#define SCTP_CID_MAX			SCTP_CID_ASCONF_ACK

#define SCTP_NUM_BASE_CHUNK_TYPES	(SCTP_CID_BASE_MAX + 1)
#define SCTP_NUM_CHUNK_TYPES		(SCTP_NUM_BASE_CHUNKTYPES + 2)


/* These are the different flavours of event.  */
typedef enum {

86 87 88 89
	SCTP_EVENT_T_CHUNK = 1,
	SCTP_EVENT_T_TIMEOUT,
	SCTP_EVENT_T_OTHER,
	SCTP_EVENT_T_PRIMITIVE
Jon Grimm's avatar
Jon Grimm committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

} sctp_event_t;

#define SCTP_EVENT_T_MAX SCTP_EVENT_T_PRIMITIVE
#define SCTP_EVENT_T_NUM (SCTP_EVENT_T_MAX + 1)

/* As a convenience for the state machine, we append SCTP_EVENT_* and
 * SCTP_ULP_* to the list of possible chunks.
 */

typedef enum {
	SCTP_EVENT_TIMEOUT_NONE = 0,
	SCTP_EVENT_TIMEOUT_T1_COOKIE,
	SCTP_EVENT_TIMEOUT_T1_INIT,
	SCTP_EVENT_TIMEOUT_T2_SHUTDOWN,
	SCTP_EVENT_TIMEOUT_T3_RTX,
Jon Grimm's avatar
Jon Grimm committed
106
	SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD,
Jon Grimm's avatar
Jon Grimm committed
107 108 109 110 111
	SCTP_EVENT_TIMEOUT_HEARTBEAT,
	SCTP_EVENT_TIMEOUT_SACK,
	SCTP_EVENT_TIMEOUT_AUTOCLOSE,
} sctp_event_timeout_t;

112
#define SCTP_EVENT_TIMEOUT_MAX		SCTP_EVENT_TIMEOUT_AUTOCLOSE
Jon Grimm's avatar
Jon Grimm committed
113 114 115
#define SCTP_NUM_TIMEOUT_TYPES		(SCTP_EVENT_TIMEOUT_MAX + 1)

typedef enum {
116
	SCTP_EVENT_NO_PENDING_TSN = 0,
Jon Grimm's avatar
Jon Grimm committed
117 118
} sctp_event_other_t;

119
#define SCTP_EVENT_OTHER_MAX		SCTP_EVENT_NO_PENDING_TSN
Jon Grimm's avatar
Jon Grimm committed
120 121 122 123
#define SCTP_NUM_OTHER_TYPES		(SCTP_EVENT_OTHER_MAX + 1)

/* These are primitive requests from the ULP.  */
typedef enum {
124
	SCTP_PRIMITIVE_ASSOCIATE = 0,
125 126 127 128
	SCTP_PRIMITIVE_SHUTDOWN,
	SCTP_PRIMITIVE_ABORT,
	SCTP_PRIMITIVE_SEND,
	SCTP_PRIMITIVE_REQUESTHEARTBEAT,
Jon Grimm's avatar
Jon Grimm committed
129 130
} sctp_event_primitive_t;

131
#define SCTP_EVENT_PRIMITIVE_MAX	SCTP_PRIMITIVE_REQUESTHEARTBEAT
Jon Grimm's avatar
Jon Grimm committed
132 133 134 135 136 137 138 139 140
#define SCTP_NUM_PRIMITIVE_TYPES	(SCTP_EVENT_PRIMITIVE_MAX + 1)

/* We define here a utility type for manipulating subtypes.
 * The subtype constructors all work like this:
 *
 * 	sctp_subtype_t foo = SCTP_ST_CHUNK(SCTP_CID_INIT);
 */

typedef union {
141

Jon Grimm's avatar
Jon Grimm committed
142 143 144 145 146 147 148 149 150 151
	sctp_cid_t chunk;
	sctp_event_timeout_t timeout;
	sctp_event_other_t other;
	sctp_event_primitive_t primitive;

} sctp_subtype_t;

#define SCTP_SUBTYPE_CONSTRUCTOR(_name, _type, _elt) \
static inline sctp_subtype_t	\
SCTP_ST_## _name (_type _arg)		\
152
{ sctp_subtype_t _retval; _retval._elt = _arg; return _retval; }
Jon Grimm's avatar
Jon Grimm committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

SCTP_SUBTYPE_CONSTRUCTOR(CHUNK,		sctp_cid_t,		chunk)
SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT,	sctp_event_timeout_t,	timeout)
SCTP_SUBTYPE_CONSTRUCTOR(OTHER,		sctp_event_other_t,	other)
SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE,	sctp_event_primitive_t,	primitive)


#define sctp_chunk_is_control(a) (a->chunk_hdr->type != SCTP_CID_DATA)
#define sctp_chunk_is_data(a) (a->chunk_hdr->type == SCTP_CID_DATA)

/* Calculate the actual data size in a data chunk */
#define SCTP_DATA_SNDSIZE(c) ((int)((unsigned long)(c->chunk_end)\
		       		- (unsigned long)(c->chunk_hdr)\
				- sizeof(sctp_data_chunk_t)))

/* This is a table of printable names of sctp_param_t's.  */
extern const char *sctp_param_tbl[];


#define SCTP_MAX_ERROR_CAUSE  SCTP_ERROR_NONEXIST_IP
#define SCTP_NUM_ERROR_CAUSE  10

/* Internal error codes */
typedef enum {

178 179 180 181 182 183 184 185 186 187
	SCTP_IERROR_NO_ERROR	        = 0,
	SCTP_IERROR_BASE		= 1000,
	SCTP_IERROR_NO_COOKIE,
	SCTP_IERROR_BAD_SIG,
	SCTP_IERROR_STALE_COOKIE,
	SCTP_IERROR_NOMEM,
	SCTP_IERROR_MALFORMED,
	SCTP_IERROR_BAD_TAG,
	SCTP_IERROR_BIG_GAP,
	SCTP_IERROR_DUP_TSN,
Jon Grimm's avatar
Jon Grimm committed
188

189
} sctp_ierror_t;
Jon Grimm's avatar
Jon Grimm committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205



/* SCTP state defines for internal state machine */
typedef enum {

	SCTP_STATE_EMPTY		= 0,
	SCTP_STATE_CLOSED		= 1,
	SCTP_STATE_COOKIE_WAIT		= 2,
	SCTP_STATE_COOKIE_ECHOED	= 3,
	SCTP_STATE_ESTABLISHED		= 4,
	SCTP_STATE_SHUTDOWN_PENDING	= 5,
	SCTP_STATE_SHUTDOWN_SENT	= 6,
	SCTP_STATE_SHUTDOWN_RECEIVED	= 7,
	SCTP_STATE_SHUTDOWN_ACK_SENT	= 8,

206
} sctp_state_t;
Jon Grimm's avatar
Jon Grimm committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

#define SCTP_STATE_MAX			SCTP_STATE_SHUTDOWN_ACK_SENT
#define SCTP_STATE_NUM_STATES		(SCTP_STATE_MAX + 1)

/* These are values for sk->state.
 * For a UDP-style SCTP socket, the states are defined as follows
 *   (at this point of time, may change later after more discussions: FIXME)
 * A socket in SCTP_SS_UNCONNECTED state indicates that it is not willing
 * to accept new associations, but it can initiate the creation of new
 * ones.
 * A socket in SCTP_SS_LISTENING state indicates that it is willing to
 * accept new  associations and can initiate the creation of new ones.
 * A socket in SCTP_SS_ESTABLISHED state indicates that it is a peeled off
 * socket with one association.
 */
typedef enum {
	SCTP_SS_CLOSED         = TCP_CLOSE,
	SCTP_SS_LISTENING      = TCP_LISTEN,
	SCTP_SS_ESTABLISHING   = TCP_SYN_SENT,
	SCTP_SS_ESTABLISHED    = TCP_ESTABLISHED,
	SCTP_SS_DISCONNECTING  = TCP_CLOSING,
} sctp_sock_state_t;

/* These functions map various type to printable names.  */
const char *sctp_cname(const sctp_subtype_t);	/* chunk types */
const char *sctp_oname(const sctp_subtype_t);	/* other events */
const char *sctp_tname(const sctp_subtype_t);	/* timeouts */
const char *sctp_pname(const sctp_subtype_t);	/* primitives */

236
/* This is a table of printable names of sctp_state_t's.  */
Jon Grimm's avatar
Jon Grimm committed
237 238 239 240 241 242 243
extern const char *sctp_state_tbl[], *sctp_evttype_tbl[], *sctp_status_tbl[];

/* SCTP reachability state for each address */
#define SCTP_ADDR_NOHB			4
#define SCTP_ADDR_REACHABLE		2
#define SCTP_ADDR_NOT_REACHABLE		1

Jon Grimm's avatar
Jon Grimm committed
244 245
/* Maximum chunk length considering padding requirements. */
enum { SCTP_MAX_CHUNK_LEN = ((1<<16) - sizeof(__u32)) };
Jon Grimm's avatar
Jon Grimm committed
246

Jon Grimm's avatar
Jon Grimm committed
247 248 249 250
/* Encourage Cookie-Echo bundling by pre-fragmenting chunks a little
 * harder (until reaching ESTABLISHED state).
 */
enum { SCTP_ARBITRARY_COOKIE_ECHO_LEN = 200 };
Jon Grimm's avatar
Jon Grimm committed
251 252 253 254 255 256 257 258 259

/* Guess at how big to make the TSN mapping array.
 * We guarantee that we can handle at least this big a gap between the
 * cumulative ACK and the highest TSN.  In practice, we can often
 * handle up to twice this value.
 *
 * NEVER make this more than 32767 (2^15-1).  The Gap Ack Blocks in a
 * SACK (see  section 3.3.4) are only 16 bits, so 2*SCTP_TSN_MAP_SIZE
 * must be less than 65535 (2^16 - 1), or we will have overflow
260
 * problems creating SACK's.
Jon Grimm's avatar
Jon Grimm committed
261 262 263 264 265 266 267
 */
#define SCTP_TSN_MAP_SIZE 2048
#define SCTP_TSN_MAX_GAP  65535

/* We will not record more than this many duplicate TSNs between two
 * SACKs.  The minimum PMTU is 576.  Remove all the headers and there
 * is enough room for 131 duplicate reports.  Round down to the
268
 * nearest power of 2.
Jon Grimm's avatar
Jon Grimm committed
269
 */
Jon Grimm's avatar
Jon Grimm committed
270 271
enum { SCTP_MIN_PMTU = 576 };
enum { SCTP_MAX_DUP_TSNS = 128 };
Jon Grimm's avatar
Jon Grimm committed
272 273 274

typedef enum {
	SCTP_COUNTER_INIT_ERROR,
275
} sctp_counter_t;
Jon Grimm's avatar
Jon Grimm committed
276 277 278 279

/* How many counters does an association need? */
#define SCTP_NUMBER_COUNTERS	5

280
/* Here we define the default timers.  */
Jon Grimm's avatar
Jon Grimm committed
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

/* cookie timer def = ? seconds */
#define SCTP_DEFAULT_TIMEOUT_T1_COOKIE	(3 * HZ)

/* init timer def = 3 seconds  */
#define SCTP_DEFAULT_TIMEOUT_T1_INIT	(3 * HZ)

/* shutdown timer def = 300 ms */
#define SCTP_DEFAULT_TIMEOUT_T2_SHUTDOWN ((300 * HZ) / 1000)

/* 0 seconds + RTO */
#define SCTP_DEFAULT_TIMEOUT_HEARTBEAT	(10 * HZ)

/* recv timer def = 200ms (in usec) */
#define SCTP_DEFAULT_TIMEOUT_SACK	((200 * HZ) / 1000)
#define SCTP_DEFAULT_TIMEOUT_SACK_MAX	((500 * HZ) / 1000) /* 500 ms */

/* RTO.Initial              - 3  seconds
 * RTO.Min                  - 1  second
 * RTO.Max                  - 60 seconds
 * RTO.Alpha                - 1/8
 * RTO.Beta                 - 1/4
 */
#define SCTP_RTO_INITIAL	(3 * HZ)
#define SCTP_RTO_MIN		(1 * HZ)
#define SCTP_RTO_MAX		(60 * HZ)

#define SCTP_RTO_ALPHA          3   /* 1/8 when converted to right shifts. */
#define SCTP_RTO_BETA           2   /* 1/4 when converted to right shifts. */

/* Maximum number of new data packets that can be sent in a burst.  */
#define SCTP_MAX_BURST		4

#define SCTP_CLOCK_GRANULARITY	1	/* 1 jiffy */

#define SCTP_DEF_MAX_INIT 6
#define SCTP_DEF_MAX_SEND 10

#define SCTP_DEFAULT_COOKIE_LIFE_SEC	60 /* seconds */
#define SCTP_DEFAULT_COOKIE_LIFE_USEC	0  /* microseconds */

#define SCTP_DEFAULT_MINWINDOW	1500	/* default minimum rwnd size */
#define SCTP_DEFAULT_MAXWINDOW	32768	/* default rwnd size */
#define SCTP_DEFAULT_MAXSEGMENT 1500	/* MTU size, this is the limit
                                         * to which we will raise the P-MTU.
					 */
#define SCTP_DEFAULT_MINSEGMENT 512	/* MTU size ... if no mtu disc */
#define SCTP_HOW_MANY_SECRETS 2		/* How many secrets I keep */
329
#define SCTP_HOW_LONG_COOKIE_LIVE 3600	/* How many seconds the current
Jon Grimm's avatar
Jon Grimm committed
330 331 332 333 334 335 336 337 338 339 340 341 342 343
					 * secret will live?
					 */
#define SCTP_SECRET_SIZE 32		/* Number of octets in a 256 bits. */

#define SCTP_SIGNATURE_SIZE 20	        /* size of a SLA-1 signature */

#define SCTP_COOKIE_MULTIPLE 64 /* Pad out our cookie to make our hash
				 * functions simpler to write.
				 */

/* These return values describe the success or failure of a number of
 * routines which form the lower interface to SCTP_outqueue.
 */
typedef enum {
344 345 346 347
	SCTP_XMIT_OK,
	SCTP_XMIT_PMTU_FULL,
	SCTP_XMIT_RWND_FULL,
	SCTP_XMIT_MUST_FRAG,
348
	SCTP_XMIT_NAGLE_DELAY,
Jon Grimm's avatar
Jon Grimm committed
349 350 351 352 353 354 355 356 357
} sctp_xmit_t;

/* These are the commands for manipulating transports.  */
typedef enum {
	SCTP_TRANSPORT_UP,
	SCTP_TRANSPORT_DOWN,
} sctp_transport_cmd_t;

/* These are the address scopes defined mainly for IPv4 addresses
358 359 360
 * based on draft of SCTP IPv4 scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
 * These scopes are hopefully generic enough to be used on scoping both
 * IPv4 and IPv6 addresses in SCTP.
Jon Grimm's avatar
Jon Grimm committed
361 362 363 364 365 366 367 368 369 370 371
 * At this point, the IPv6 scopes will be mapped to these internal scopes
 * as much as possible.
 */
typedef enum {
	SCTP_SCOPE_GLOBAL,		/* IPv4 global addresses */
	SCTP_SCOPE_PRIVATE,		/* IPv4 private addresses */
	SCTP_SCOPE_LINK,		/* IPv4 link local address */
	SCTP_SCOPE_LOOPBACK,		/* IPv4 loopback address */
	SCTP_SCOPE_UNUSABLE,		/* IPv4 unusable addresses */
} sctp_scope_t;

372 373
/* Based on IPv4 scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>,
 * SCTP IPv4 unusable addresses: 0.0.0.0/8, 224.0.0.0/4, 198.18.0.0/24,
Jon Grimm's avatar
Jon Grimm committed
374
 * 192.88.99.0/24.
375
 * Also, RFC 8.4, non-unicast addresses are not considered valid SCTP
Jon Grimm's avatar
Jon Grimm committed
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
 * addresses.
 */
#define IS_IPV4_UNUSABLE_ADDRESS(a) \
	((INADDR_BROADCAST == *a) || \
	(MULTICAST(*a)) || \
	(((unsigned char *)(a))[0] == 0) || \
	((((unsigned char *)(a))[0] == 198) && \
	(((unsigned char *)(a))[1] == 18) && \
	(((unsigned char *)(a))[2] == 0)) || \
	((((unsigned char *)(a))[0] == 192) && \
	(((unsigned char *)(a))[1] == 88) && \
	(((unsigned char *)(a))[2] == 99)))

/* IPv4 Link-local addresses: 169.254.0.0/16.  */
#define IS_IPV4_LINK_ADDRESS(a) \
	((((unsigned char *)(a))[0] == 169) && \
	(((unsigned char *)(a))[1] == 254))

/* RFC 1918 "Address Allocation for Private Internets" defines the IPv4
 * private address space as the following:
 *
 * 10.0.0.0 - 10.255.255.255 (10/8 prefix)
 * 172.16.0.0.0 - 172.31.255.255 (172.16/12 prefix)
 * 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
 */
#define IS_IPV4_PRIVATE_ADDRESS(a) \
	((((unsigned char *)(a))[0] == 10) || \
	((((unsigned char *)(a))[0] == 172) && \
	(((unsigned char *)(a))[1] >= 16) && \
	(((unsigned char *)(a))[1] < 32)) || \
	((((unsigned char *)(a))[0] == 192) && \
	(((unsigned char *)(a))[1] == 168)))

/* Flags used for the bind address copy functions.  */
#define SCTP_ADDR6_ALLOWED	0x00000001	/* IPv6 address is allowed by
411
						   local sock family */
Jon Grimm's avatar
Jon Grimm committed
412 413 414 415 416
#define SCTP_ADDR4_PEERSUPP	0x00000002	/* IPv4 address is supported by
						   peer */
#define SCTP_ADDR6_PEERSUPP	0x00000004	/* IPv6 address is supported by
						   peer */

417 418 419 420 421 422 423
/* Reasons to retransmit. */
typedef enum {
	SCTP_RETRANSMIT_T3_RTX,
	SCTP_RETRANSMIT_FAST_RTX,
	SCTP_RETRANSMIT_PMTU_DISCOVERY,
} sctp_retransmit_reason_t;

Jon Grimm's avatar
Jon Grimm committed
424 425 426 427 428 429 430 431 432
/* Reasons to lower cwnd. */
typedef enum {
	SCTP_LOWER_CWND_T3_RTX,
	SCTP_LOWER_CWND_FAST_RTX,
	SCTP_LOWER_CWND_ECNE,
	SCTP_LOWER_CWND_INACTIVE,
} sctp_lower_cwnd_t;

#endif /* __sctp_constants_h__ */