Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* SCTP kernel implementation
0003  * (C) Copyright IBM Corp. 2001, 2004
0004  * Copyright (c) 1999-2000 Cisco, Inc.
0005  * Copyright (c) 1999-2001 Motorola, Inc.
0006  * Copyright (c) 2001 Intel Corp.
0007  *
0008  * This file is part of the SCTP kernel implementation
0009  *
0010  * Please send any bug reports or fixes you make to the
0011  * email address(es):
0012  *    lksctp developers <linux-sctp@vger.kernel.org>
0013  *
0014  * Written or modified by:
0015  *   La Monte H.P. Yarroll <piggy@acm.org>
0016  *   Karl Knutson          <karl@athena.chicago.il.us>
0017  *   Randall Stewart       <randall@stewart.chicago.il.us>
0018  *   Ken Morneau           <kmorneau@cisco.com>
0019  *   Qiaobing Xie          <qxie1@motorola.com>
0020  *   Xingang Guo           <xingang.guo@intel.com>
0021  *   Sridhar Samudrala     <samudrala@us.ibm.com>
0022  *   Daisy Chang           <daisyc@us.ibm.com>
0023  */
0024 
0025 #ifndef __sctp_constants_h__
0026 #define __sctp_constants_h__
0027 
0028 #include <linux/sctp.h>
0029 #include <linux/ipv6.h> /* For ipv6hdr. */
0030 #include <net/tcp_states.h>  /* For TCP states used in enum sctp_sock_state */
0031 
0032 /* Value used for stream negotiation. */
0033 enum { SCTP_MAX_STREAM = 0xffff };
0034 enum { SCTP_DEFAULT_OUTSTREAMS = 10 };
0035 enum { SCTP_DEFAULT_INSTREAMS = SCTP_MAX_STREAM };
0036 
0037 /* Since CIDs are sparse, we need all four of the following
0038  * symbols.  CIDs are dense through SCTP_CID_BASE_MAX.
0039  */
0040 #define SCTP_CID_BASE_MAX       SCTP_CID_SHUTDOWN_COMPLETE
0041 
0042 #define SCTP_NUM_BASE_CHUNK_TYPES   (SCTP_CID_BASE_MAX + 1)
0043 
0044 #define SCTP_NUM_ADDIP_CHUNK_TYPES  2
0045 
0046 #define SCTP_NUM_PRSCTP_CHUNK_TYPES 1
0047 
0048 #define SCTP_NUM_RECONF_CHUNK_TYPES 1
0049 
0050 #define SCTP_NUM_AUTH_CHUNK_TYPES   1
0051 
0052 #define SCTP_NUM_CHUNK_TYPES        (SCTP_NUM_BASE_CHUNK_TYPES + \
0053                      SCTP_NUM_ADDIP_CHUNK_TYPES +\
0054                      SCTP_NUM_PRSCTP_CHUNK_TYPES +\
0055                      SCTP_NUM_RECONF_CHUNK_TYPES +\
0056                      SCTP_NUM_AUTH_CHUNK_TYPES)
0057 
0058 /* These are the different flavours of event.  */
0059 enum sctp_event_type {
0060     SCTP_EVENT_T_CHUNK = 1,
0061     SCTP_EVENT_T_TIMEOUT,
0062     SCTP_EVENT_T_OTHER,
0063     SCTP_EVENT_T_PRIMITIVE
0064 };
0065 
0066 /* As a convenience for the state machine, we append SCTP_EVENT_* and
0067  * SCTP_ULP_* to the list of possible chunks.
0068  */
0069 
0070 enum sctp_event_timeout {
0071     SCTP_EVENT_TIMEOUT_NONE = 0,
0072     SCTP_EVENT_TIMEOUT_T1_COOKIE,
0073     SCTP_EVENT_TIMEOUT_T1_INIT,
0074     SCTP_EVENT_TIMEOUT_T2_SHUTDOWN,
0075     SCTP_EVENT_TIMEOUT_T3_RTX,
0076     SCTP_EVENT_TIMEOUT_T4_RTO,
0077     SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD,
0078     SCTP_EVENT_TIMEOUT_HEARTBEAT,
0079     SCTP_EVENT_TIMEOUT_RECONF,
0080     SCTP_EVENT_TIMEOUT_PROBE,
0081     SCTP_EVENT_TIMEOUT_SACK,
0082     SCTP_EVENT_TIMEOUT_AUTOCLOSE,
0083 };
0084 
0085 #define SCTP_EVENT_TIMEOUT_MAX      SCTP_EVENT_TIMEOUT_AUTOCLOSE
0086 #define SCTP_NUM_TIMEOUT_TYPES      (SCTP_EVENT_TIMEOUT_MAX + 1)
0087 
0088 enum sctp_event_other {
0089     SCTP_EVENT_NO_PENDING_TSN = 0,
0090     SCTP_EVENT_ICMP_PROTO_UNREACH,
0091 };
0092 
0093 #define SCTP_EVENT_OTHER_MAX        SCTP_EVENT_ICMP_PROTO_UNREACH
0094 #define SCTP_NUM_OTHER_TYPES        (SCTP_EVENT_OTHER_MAX + 1)
0095 
0096 /* These are primitive requests from the ULP.  */
0097 enum sctp_event_primitive {
0098     SCTP_PRIMITIVE_ASSOCIATE = 0,
0099     SCTP_PRIMITIVE_SHUTDOWN,
0100     SCTP_PRIMITIVE_ABORT,
0101     SCTP_PRIMITIVE_SEND,
0102     SCTP_PRIMITIVE_REQUESTHEARTBEAT,
0103     SCTP_PRIMITIVE_ASCONF,
0104     SCTP_PRIMITIVE_RECONF,
0105 };
0106 
0107 #define SCTP_EVENT_PRIMITIVE_MAX    SCTP_PRIMITIVE_RECONF
0108 #define SCTP_NUM_PRIMITIVE_TYPES    (SCTP_EVENT_PRIMITIVE_MAX + 1)
0109 
0110 /* We define here a utility type for manipulating subtypes.
0111  * The subtype constructors all work like this:
0112  *
0113  *   union sctp_subtype foo = SCTP_ST_CHUNK(SCTP_CID_INIT);
0114  */
0115 
0116 union sctp_subtype {
0117     enum sctp_cid chunk;
0118     enum sctp_event_timeout timeout;
0119     enum sctp_event_other other;
0120     enum sctp_event_primitive primitive;
0121 };
0122 
0123 #define SCTP_SUBTYPE_CONSTRUCTOR(_name, _type, _elt) \
0124 static inline union sctp_subtype    \
0125 SCTP_ST_## _name (_type _arg)       \
0126 { union sctp_subtype _retval; _retval._elt = _arg; return _retval; }
0127 
0128 SCTP_SUBTYPE_CONSTRUCTOR(CHUNK,     enum sctp_cid,      chunk)
0129 SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT,   enum sctp_event_timeout, timeout)
0130 SCTP_SUBTYPE_CONSTRUCTOR(OTHER,     enum sctp_event_other,  other)
0131 SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE, enum sctp_event_primitive, primitive)
0132 
0133 
0134 #define sctp_chunk_is_data(a) (a->chunk_hdr->type == SCTP_CID_DATA || \
0135                    a->chunk_hdr->type == SCTP_CID_I_DATA)
0136 
0137 /* Internal error codes */
0138 enum sctp_ierror {
0139     SCTP_IERROR_NO_ERROR            = 0,
0140     SCTP_IERROR_BASE        = 1000,
0141     SCTP_IERROR_NO_COOKIE,
0142     SCTP_IERROR_BAD_SIG,
0143     SCTP_IERROR_STALE_COOKIE,
0144     SCTP_IERROR_NOMEM,
0145     SCTP_IERROR_MALFORMED,
0146     SCTP_IERROR_BAD_TAG,
0147     SCTP_IERROR_BIG_GAP,
0148     SCTP_IERROR_DUP_TSN,
0149     SCTP_IERROR_HIGH_TSN,
0150     SCTP_IERROR_IGNORE_TSN,
0151     SCTP_IERROR_NO_DATA,
0152     SCTP_IERROR_BAD_STREAM,
0153     SCTP_IERROR_BAD_PORTS,
0154     SCTP_IERROR_AUTH_BAD_HMAC,
0155     SCTP_IERROR_AUTH_BAD_KEYID,
0156     SCTP_IERROR_PROTO_VIOLATION,
0157     SCTP_IERROR_ERROR,
0158     SCTP_IERROR_ABORT,
0159 };
0160 
0161 
0162 
0163 /* SCTP state defines for internal state machine */
0164 enum sctp_state {
0165 
0166     SCTP_STATE_CLOSED       = 0,
0167     SCTP_STATE_COOKIE_WAIT      = 1,
0168     SCTP_STATE_COOKIE_ECHOED    = 2,
0169     SCTP_STATE_ESTABLISHED      = 3,
0170     SCTP_STATE_SHUTDOWN_PENDING = 4,
0171     SCTP_STATE_SHUTDOWN_SENT    = 5,
0172     SCTP_STATE_SHUTDOWN_RECEIVED    = 6,
0173     SCTP_STATE_SHUTDOWN_ACK_SENT    = 7,
0174 
0175 };
0176 
0177 #define SCTP_STATE_MAX          SCTP_STATE_SHUTDOWN_ACK_SENT
0178 #define SCTP_STATE_NUM_STATES       (SCTP_STATE_MAX + 1)
0179 
0180 /* These are values for sk->state.
0181  * For a UDP-style SCTP socket, the states are defined as follows
0182  * - A socket in SCTP_SS_CLOSED state indicates that it is not willing to
0183  *   accept new associations, but it can initiate the creation of new ones.
0184  * - A socket in SCTP_SS_LISTENING state indicates that it is willing to
0185  *   accept new  associations and can initiate the creation of new ones.
0186  * - A socket in SCTP_SS_ESTABLISHED state indicates that it is a peeled off
0187  *   socket with one association.
0188  * For a TCP-style SCTP socket, the states are defined as follows
0189  * - A socket in SCTP_SS_CLOSED state indicates that it is not willing to
0190  *   accept new associations, but it can initiate the creation of new ones.
0191  * - A socket in SCTP_SS_LISTENING state indicates that it is willing to
0192  *   accept new associations, but cannot initiate the creation of new ones.
0193  * - A socket in SCTP_SS_ESTABLISHED state indicates that it has a single 
0194  *   association.
0195  */
0196 enum sctp_sock_state {
0197     SCTP_SS_CLOSED         = TCP_CLOSE,
0198     SCTP_SS_LISTENING      = TCP_LISTEN,
0199     SCTP_SS_ESTABLISHING   = TCP_SYN_SENT,
0200     SCTP_SS_ESTABLISHED    = TCP_ESTABLISHED,
0201     SCTP_SS_CLOSING        = TCP_CLOSE_WAIT,
0202 };
0203 
0204 enum sctp_plpmtud_state {
0205     SCTP_PL_DISABLED,
0206     SCTP_PL_BASE,
0207     SCTP_PL_SEARCH,
0208     SCTP_PL_COMPLETE,
0209     SCTP_PL_ERROR,
0210 };
0211 
0212 #define SCTP_BASE_PLPMTU    1200
0213 #define SCTP_MAX_PLPMTU     9000
0214 #define SCTP_MIN_PLPMTU     512
0215 
0216 #define SCTP_MAX_PROBES     3
0217 
0218 #define SCTP_PL_BIG_STEP    32
0219 #define SCTP_PL_MIN_STEP    4
0220 
0221 /* These functions map various type to printable names.  */
0222 const char *sctp_cname(const union sctp_subtype id);    /* chunk types */
0223 const char *sctp_oname(const union sctp_subtype id);    /* other events */
0224 const char *sctp_tname(const union sctp_subtype id);    /* timeouts */
0225 const char *sctp_pname(const union sctp_subtype id);    /* primitives */
0226 
0227 /* This is a table of printable names of sctp_state_t's.  */
0228 extern const char *const sctp_state_tbl[];
0229 extern const char *const sctp_evttype_tbl[];
0230 extern const char *const sctp_status_tbl[];
0231 
0232 /* Maximum chunk length considering padding requirements. */
0233 enum { SCTP_MAX_CHUNK_LEN = ((1<<16) - sizeof(__u32)) };
0234 
0235 /* Encourage Cookie-Echo bundling by pre-fragmenting chunks a little
0236  * harder (until reaching ESTABLISHED state).
0237  */
0238 enum { SCTP_ARBITRARY_COOKIE_ECHO_LEN = 200 };
0239 
0240 /* Guess at how big to make the TSN mapping array.
0241  * We guarantee that we can handle at least this big a gap between the
0242  * cumulative ACK and the highest TSN.  In practice, we can often
0243  * handle up to twice this value.
0244  *
0245  * NEVER make this more than 32767 (2^15-1).  The Gap Ack Blocks in a
0246  * SACK (see  section 3.3.4) are only 16 bits, so 2*SCTP_TSN_MAP_SIZE
0247  * must be less than 65535 (2^16 - 1), or we will have overflow
0248  * problems creating SACK's.
0249  */
0250 #define SCTP_TSN_MAP_INITIAL BITS_PER_LONG
0251 #define SCTP_TSN_MAP_INCREMENT SCTP_TSN_MAP_INITIAL
0252 #define SCTP_TSN_MAP_SIZE 4096
0253 
0254 /* We will not record more than this many duplicate TSNs between two
0255  * SACKs.  The minimum PMTU is 512.  Remove all the headers and there
0256  * is enough room for 117 duplicate reports.  Round down to the
0257  * nearest power of 2.
0258  */
0259 enum { SCTP_MAX_DUP_TSNS = 16 };
0260 enum { SCTP_MAX_GABS = 16 };
0261 
0262 /* Heartbeat interval - 30 secs */
0263 #define SCTP_DEFAULT_TIMEOUT_HEARTBEAT  (30*1000)
0264 
0265 /* Delayed sack timer - 200ms */
0266 #define SCTP_DEFAULT_TIMEOUT_SACK   (200)
0267 
0268 /* RTO.Initial              - 3  seconds
0269  * RTO.Min                  - 1  second
0270  * RTO.Max                  - 60 seconds
0271  * RTO.Alpha                - 1/8
0272  * RTO.Beta                 - 1/4
0273  */
0274 #define SCTP_RTO_INITIAL    (3 * 1000)
0275 #define SCTP_RTO_MIN        (1 * 1000)
0276 #define SCTP_RTO_MAX        (60 * 1000)
0277 
0278 #define SCTP_RTO_ALPHA          3   /* 1/8 when converted to right shifts. */
0279 #define SCTP_RTO_BETA           2   /* 1/4 when converted to right shifts. */
0280 
0281 /* Maximum number of new data packets that can be sent in a burst.  */
0282 #define SCTP_DEFAULT_MAX_BURST      4
0283 
0284 #define SCTP_CLOCK_GRANULARITY  1   /* 1 jiffy */
0285 
0286 #define SCTP_DEFAULT_COOKIE_LIFE    (60 * 1000) /* 60 seconds */
0287 
0288 #define SCTP_DEFAULT_MINWINDOW  1500    /* default minimum rwnd size */
0289 #define SCTP_DEFAULT_MAXWINDOW  65535   /* default rwnd size */
0290 #define SCTP_DEFAULT_RWND_SHIFT  4  /* by default, update on 1/16 of
0291                      * rcvbuf, which is 1/8 of initial
0292                      * window
0293                      */
0294 #define SCTP_DEFAULT_MAXSEGMENT 1500    /* MTU size, this is the limit
0295                                          * to which we will raise the P-MTU.
0296                      */
0297 #define SCTP_DEFAULT_MINSEGMENT 512 /* MTU size ... if no mtu disc */
0298 
0299 #define SCTP_SECRET_SIZE 32     /* Number of octets in a 256 bits. */
0300 
0301 #define SCTP_SIGNATURE_SIZE 20          /* size of a SLA-1 signature */
0302 
0303 #define SCTP_COOKIE_MULTIPLE 32 /* Pad out our cookie to make our hash
0304                  * functions simpler to write.
0305                  */
0306 
0307 #define SCTP_DEFAULT_UDP_PORT 9899  /* default UDP tunneling port */
0308 
0309 /* These are the values for pf exposure, UNUSED is to keep compatible with old
0310  * applications by default.
0311  */
0312 enum {
0313     SCTP_PF_EXPOSE_UNSET,
0314     SCTP_PF_EXPOSE_DISABLE,
0315     SCTP_PF_EXPOSE_ENABLE,
0316 };
0317 #define SCTP_PF_EXPOSE_MAX  SCTP_PF_EXPOSE_ENABLE
0318 
0319 #define SCTP_PS_RETRANS_MAX 0xffff
0320 
0321 /* These return values describe the success or failure of a number of
0322  * routines which form the lower interface to SCTP_outqueue.
0323  */
0324 enum sctp_xmit {
0325     SCTP_XMIT_OK,
0326     SCTP_XMIT_PMTU_FULL,
0327     SCTP_XMIT_RWND_FULL,
0328     SCTP_XMIT_DELAY,
0329 };
0330 
0331 /* These are the commands for manipulating transports.  */
0332 enum sctp_transport_cmd {
0333     SCTP_TRANSPORT_UP,
0334     SCTP_TRANSPORT_DOWN,
0335     SCTP_TRANSPORT_PF,
0336 };
0337 
0338 /* These are the address scopes defined mainly for IPv4 addresses
0339  * based on draft of SCTP IPv4 scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
0340  * These scopes are hopefully generic enough to be used on scoping both
0341  * IPv4 and IPv6 addresses in SCTP.
0342  * At this point, the IPv6 scopes will be mapped to these internal scopes
0343  * as much as possible.
0344  */
0345 enum sctp_scope {
0346     SCTP_SCOPE_GLOBAL,      /* IPv4 global addresses */
0347     SCTP_SCOPE_PRIVATE,     /* IPv4 private addresses */
0348     SCTP_SCOPE_LINK,        /* IPv4 link local address */
0349     SCTP_SCOPE_LOOPBACK,        /* IPv4 loopback address */
0350     SCTP_SCOPE_UNUSABLE,        /* IPv4 unusable addresses */
0351 };
0352 
0353 enum {
0354     SCTP_SCOPE_POLICY_DISABLE,  /* Disable IPv4 address scoping */
0355     SCTP_SCOPE_POLICY_ENABLE,   /* Enable IPv4 address scoping */
0356     SCTP_SCOPE_POLICY_PRIVATE,  /* Follow draft but allow IPv4 private addresses */
0357     SCTP_SCOPE_POLICY_LINK,     /* Follow draft but allow IPv4 link local addresses */
0358 };
0359 
0360 #define SCTP_SCOPE_POLICY_MAX   SCTP_SCOPE_POLICY_LINK
0361 
0362 /* Based on IPv4 scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>,
0363  * SCTP IPv4 unusable addresses: 0.0.0.0/8, 224.0.0.0/4, 192.88.99.0/24.
0364  * Also, RFC 8.4, non-unicast addresses are not considered valid SCTP
0365  * addresses.
0366  */
0367 #define IS_IPV4_UNUSABLE_ADDRESS(a)     \
0368     ((htonl(INADDR_BROADCAST) == a) ||  \
0369      ipv4_is_multicast(a) ||        \
0370      ipv4_is_zeronet(a) ||          \
0371      ipv4_is_anycast_6to4(a))
0372 
0373 /* Flags used for the bind address copy functions.  */
0374 #define SCTP_ADDR4_ALLOWED  0x00000001  /* IPv4 address is allowed by
0375                            local sock family */
0376 #define SCTP_ADDR6_ALLOWED  0x00000002  /* IPv6 address is allowed by
0377                            local sock family */
0378 #define SCTP_ADDR4_PEERSUPP 0x00000004  /* IPv4 address is supported by
0379                            peer */
0380 #define SCTP_ADDR6_PEERSUPP 0x00000008  /* IPv6 address is supported by
0381                            peer */
0382 
0383 /* Reasons to retransmit. */
0384 enum sctp_retransmit_reason {
0385     SCTP_RTXR_T3_RTX,
0386     SCTP_RTXR_FAST_RTX,
0387     SCTP_RTXR_PMTUD,
0388     SCTP_RTXR_T1_RTX,
0389 };
0390 
0391 /* Reasons to lower cwnd. */
0392 enum sctp_lower_cwnd {
0393     SCTP_LOWER_CWND_T3_RTX,
0394     SCTP_LOWER_CWND_FAST_RTX,
0395     SCTP_LOWER_CWND_ECNE,
0396     SCTP_LOWER_CWND_INACTIVE,
0397 };
0398 
0399 
0400 /* SCTP-AUTH Necessary constants */
0401 
0402 /* SCTP-AUTH, Section 3.3
0403  *
0404  *  The following Table 2 shows the currently defined values for HMAC
0405  *  identifiers.
0406  *
0407  *  +-----------------+--------------------------+
0408  *  | HMAC Identifier | Message Digest Algorithm |
0409  *  +-----------------+--------------------------+
0410  *  | 0               | Reserved                 |
0411  *  | 1               | SHA-1 defined in [8]     |
0412  *  | 2               | Reserved                 |
0413  *  | 3               | SHA-256 defined in [8]   |
0414  *  +-----------------+--------------------------+
0415  */
0416 enum {
0417     SCTP_AUTH_HMAC_ID_RESERVED_0,
0418     SCTP_AUTH_HMAC_ID_SHA1,
0419     SCTP_AUTH_HMAC_ID_RESERVED_2,
0420 #if defined (CONFIG_CRYPTO_SHA256) || defined (CONFIG_CRYPTO_SHA256_MODULE)
0421     SCTP_AUTH_HMAC_ID_SHA256,
0422 #endif
0423     __SCTP_AUTH_HMAC_MAX
0424 };
0425 
0426 #define SCTP_AUTH_HMAC_ID_MAX   __SCTP_AUTH_HMAC_MAX - 1
0427 #define SCTP_AUTH_NUM_HMACS     __SCTP_AUTH_HMAC_MAX
0428 #define SCTP_SHA1_SIG_SIZE 20
0429 #define SCTP_SHA256_SIG_SIZE 32
0430 
0431 /*  SCTP-AUTH, Section 3.2
0432  *     The chunk types for INIT, INIT-ACK, SHUTDOWN-COMPLETE and AUTH chunks
0433  *     MUST NOT be listed in the CHUNKS parameter
0434  */
0435 #define SCTP_NUM_NOAUTH_CHUNKS  4
0436 #define SCTP_AUTH_MAX_CHUNKS    (SCTP_NUM_CHUNK_TYPES - SCTP_NUM_NOAUTH_CHUNKS)
0437 
0438 /* SCTP-AUTH Section 6.1
0439  * The RANDOM parameter MUST contain a 32 byte random number.
0440  */
0441 #define SCTP_AUTH_RANDOM_LENGTH 32
0442 
0443 #define SCTP_PROBE_TIMER_MIN    5000
0444 
0445 #endif /* __sctp_constants_h__ */