aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/sctp
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/net/sctp
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/net/sctp')
-rw-r--r--include/net/sctp/command.h211
-rw-r--r--include/net/sctp/constants.h432
-rw-r--r--include/net/sctp/sctp.h620
-rw-r--r--include/net/sctp/sm.h442
-rw-r--r--include/net/sctp/structs.h1752
-rw-r--r--include/net/sctp/tsnmap.h207
-rw-r--r--include/net/sctp/ulpevent.h162
-rw-r--r--include/net/sctp/ulpqueue.h92
-rw-r--r--include/net/sctp/user.h589
9 files changed, 4507 insertions, 0 deletions
diff --git a/include/net/sctp/command.h b/include/net/sctp/command.h
new file mode 100644
index 00000000000..ebc5282e6d5
--- /dev/null
+++ b/include/net/sctp/command.h
@@ -0,0 +1,211 @@
1/* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (C) 1999-2001 Cisco, Motorola
4 *
5 * This file is part of the SCTP kernel reference Implementation
6 *
7 * These are the definitions needed for the command object.
8 *
9 * The SCTP reference 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 * the SCTP reference 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 one of the
27 * following email addresses:
28 *
29 * La Monte H.P. Yarroll <piggy@acm.org>
30 * Karl Knutson <karl@athena.chicago.il.us>
31 * Ardelle Fan <ardelle.fan@intel.com>
32 * Sridhar Samudrala <sri@us.ibm.com>
33 *
34 * Any bugs reported given to us we will try to fix... any fixes shared will
35 * be incorporated into the next SCTP release.
36 */
37
38
39#ifndef __net_sctp_command_h__
40#define __net_sctp_command_h__
41
42#include <net/sctp/constants.h>
43#include <net/sctp/structs.h>
44
45
46typedef enum {
47 SCTP_CMD_NOP = 0, /* Do nothing. */
48 SCTP_CMD_NEW_ASOC, /* Register a new association. */
49 SCTP_CMD_DELETE_TCB, /* Delete the current association. */
50 SCTP_CMD_NEW_STATE, /* Enter a new state. */
51 SCTP_CMD_REPORT_TSN, /* Record the arrival of a TSN. */
52 SCTP_CMD_GEN_SACK, /* Send a Selective ACK (maybe). */
53 SCTP_CMD_PROCESS_SACK, /* Process an inbound SACK. */
54 SCTP_CMD_GEN_INIT_ACK, /* Generate an INIT ACK chunk. */
55 SCTP_CMD_PEER_INIT, /* Process a INIT from the peer. */
56 SCTP_CMD_GEN_COOKIE_ECHO, /* Generate a COOKIE ECHO chunk. */
57 SCTP_CMD_CHUNK_ULP, /* Send a chunk to the sockets layer. */
58 SCTP_CMD_EVENT_ULP, /* Send a notification to the sockets layer. */
59 SCTP_CMD_REPLY, /* Send a chunk to our peer. */
60 SCTP_CMD_SEND_PKT, /* Send a full packet to our peer. */
61 SCTP_CMD_RETRAN, /* Mark a transport for retransmission. */
62 SCTP_CMD_ECN_CE, /* Do delayed CE processing. */
63 SCTP_CMD_ECN_ECNE, /* Do delayed ECNE processing. */
64 SCTP_CMD_ECN_CWR, /* Do delayed CWR processing. */
65 SCTP_CMD_TIMER_START, /* Start a timer. */
66 SCTP_CMD_TIMER_RESTART, /* Restart a timer. */
67 SCTP_CMD_TIMER_STOP, /* Stop a timer. */
68 SCTP_CMD_COUNTER_RESET, /* Reset a counter. */
69 SCTP_CMD_COUNTER_INC, /* Increment a counter. */
70 SCTP_CMD_INIT_RESTART, /* High level, do init timer work. */
71 SCTP_CMD_INIT_FAILED, /* High level, do init failure work. */
72 SCTP_CMD_REPORT_DUP, /* Report a duplicate TSN. */
73 SCTP_CMD_STRIKE, /* Mark a strike against a transport. */
74 SCTP_CMD_TRANSMIT, /* Transmit the outqueue. */
75 SCTP_CMD_HB_TIMERS_START, /* Start the heartbeat timers. */
76 SCTP_CMD_HB_TIMER_UPDATE, /* Update a heartbeat timers. */
77 SCTP_CMD_HB_TIMERS_STOP, /* Stop the heartbeat timers. */
78 SCTP_CMD_TRANSPORT_RESET, /* Reset the status of a transport. */
79 SCTP_CMD_TRANSPORT_ON, /* Mark the transport as active. */
80 SCTP_CMD_REPORT_ERROR, /* Pass this error back out of the sm. */
81 SCTP_CMD_REPORT_BAD_TAG, /* Verification tags didn't match. */
82 SCTP_CMD_PROCESS_CTSN, /* Sideeffect from shutdown. */
83 SCTP_CMD_ASSOC_FAILED, /* Handle association failure. */
84 SCTP_CMD_DISCARD_PACKET, /* Discard the whole packet. */
85 SCTP_CMD_GEN_SHUTDOWN, /* Generate a SHUTDOWN chunk. */
86 SCTP_CMD_UPDATE_ASSOC, /* Update association information. */
87 SCTP_CMD_PURGE_OUTQUEUE, /* Purge all data waiting to be sent. */
88 SCTP_CMD_SETUP_T2, /* Hi-level, setup T2-shutdown parms. */
89 SCTP_CMD_RTO_PENDING, /* Set transport's rto_pending. */
90 SCTP_CMD_PART_DELIVER, /* Partial data delivery considerations. */
91 SCTP_CMD_RENEGE, /* Renege data on an association. */
92 SCTP_CMD_SETUP_T4, /* ADDIP, setup T4 RTO timer parms. */
93 SCTP_CMD_PROCESS_OPERR, /* Process an ERROR chunk. */
94 SCTP_CMD_REPORT_FWDTSN, /* Report new cumulative TSN Ack. */
95 SCTP_CMD_PROCESS_FWDTSN, /* Skips were reported, so process further. */
96 SCTP_CMD_CLEAR_INIT_TAG, /* Clears association peer's inittag. */
97 SCTP_CMD_DEL_NON_PRIMARY, /* Removes non-primary peer transports. */
98 SCTP_CMD_T3_RTX_TIMERS_STOP, /* Stops T3-rtx pending timers */
99 SCTP_CMD_FORCE_PRIM_RETRAN, /* Forces retrans. over primary path. */
100 SCTP_CMD_LAST
101} sctp_verb_t;
102
103#define SCTP_CMD_MAX (SCTP_CMD_LAST - 1)
104#define SCTP_CMD_NUM_VERBS (SCTP_CMD_MAX + 1)
105
106/* How many commands can you put in an sctp_cmd_seq_t?
107 * This is a rather arbitrary number, ideally derived from a careful
108 * analysis of the state functions, but in reality just taken from
109 * thin air in the hopes othat we don't trigger a kernel panic.
110 */
111#define SCTP_MAX_NUM_COMMANDS 14
112
113typedef union {
114 __s32 i32;
115 __u32 u32;
116 __u16 u16;
117 __u8 u8;
118 int error;
119 sctp_state_t state;
120 sctp_event_timeout_t to;
121 sctp_counter_t counter;
122 void *ptr;
123 struct sctp_chunk *chunk;
124 struct sctp_association *asoc;
125 struct sctp_transport *transport;
126 struct sctp_bind_addr *bp;
127 sctp_init_chunk_t *init;
128 struct sctp_ulpevent *ulpevent;
129 struct sctp_packet *packet;
130 sctp_sackhdr_t *sackh;
131} sctp_arg_t;
132
133/* We are simulating ML type constructors here.
134 *
135 * SCTP_ARG_CONSTRUCTOR(NAME, TYPE, ELT) builds a function called
136 * SCTP_NAME() which takes an argument of type TYPE and returns an
137 * sctp_arg_t. It does this by inserting the sole argument into the
138 * ELT union element of a local sctp_arg_t.
139 *
140 * E.g., SCTP_ARG_CONSTRUCTOR(I32, __s32, i32) builds SCTP_I32(arg),
141 * which takes an __s32 and returns a sctp_arg_t containing the
142 * __s32. So, after foo = SCTP_I32(arg), foo.i32 == arg.
143 */
144static inline sctp_arg_t SCTP_NULL(void)
145{
146 sctp_arg_t retval; retval.ptr = NULL; return retval;
147}
148static inline sctp_arg_t SCTP_NOFORCE(void)
149{
150 sctp_arg_t retval; retval.i32 = 0; return retval;
151}
152static inline sctp_arg_t SCTP_FORCE(void)
153{
154 sctp_arg_t retval; retval.i32 = 1; return retval;
155}
156
157#define SCTP_ARG_CONSTRUCTOR(name, type, elt) \
158static inline sctp_arg_t \
159SCTP_## name (type arg) \
160{ sctp_arg_t retval; retval.elt = arg; return retval; }
161
162SCTP_ARG_CONSTRUCTOR(I32, __s32, i32)
163SCTP_ARG_CONSTRUCTOR(U32, __u32, u32)
164SCTP_ARG_CONSTRUCTOR(U16, __u16, u16)
165SCTP_ARG_CONSTRUCTOR(U8, __u8, u8)
166SCTP_ARG_CONSTRUCTOR(ERROR, int, error)
167SCTP_ARG_CONSTRUCTOR(STATE, sctp_state_t, state)
168SCTP_ARG_CONSTRUCTOR(COUNTER, sctp_counter_t, counter)
169SCTP_ARG_CONSTRUCTOR(TO, sctp_event_timeout_t, to)
170SCTP_ARG_CONSTRUCTOR(PTR, void *, ptr)
171SCTP_ARG_CONSTRUCTOR(CHUNK, struct sctp_chunk *, chunk)
172SCTP_ARG_CONSTRUCTOR(ASOC, struct sctp_association *, asoc)
173SCTP_ARG_CONSTRUCTOR(TRANSPORT, struct sctp_transport *, transport)
174SCTP_ARG_CONSTRUCTOR(BA, struct sctp_bind_addr *, bp)
175SCTP_ARG_CONSTRUCTOR(PEER_INIT, sctp_init_chunk_t *, init)
176SCTP_ARG_CONSTRUCTOR(ULPEVENT, struct sctp_ulpevent *, ulpevent)
177SCTP_ARG_CONSTRUCTOR(PACKET, struct sctp_packet *, packet)
178SCTP_ARG_CONSTRUCTOR(SACKH, sctp_sackhdr_t *, sackh)
179
180typedef struct {
181 sctp_arg_t obj;
182 sctp_verb_t verb;
183} sctp_cmd_t;
184
185typedef struct {
186 sctp_cmd_t cmds[SCTP_MAX_NUM_COMMANDS];
187 __u8 next_free_slot;
188 __u8 next_cmd;
189} sctp_cmd_seq_t;
190
191
192/* Initialize a block of memory as a command sequence.
193 * Return 0 if the initialization fails.
194 */
195int sctp_init_cmd_seq(sctp_cmd_seq_t *seq);
196
197/* Add a command to an sctp_cmd_seq_t.
198 * Return 0 if the command sequence is full.
199 *
200 * Use the SCTP_* constructors defined by SCTP_ARG_CONSTRUCTOR() above
201 * to wrap data which goes in the obj argument.
202 */
203int sctp_add_cmd(sctp_cmd_seq_t *seq, sctp_verb_t verb, sctp_arg_t obj);
204
205/* Return the next command structure in an sctp_cmd_seq.
206 * Return NULL at the end of the sequence.
207 */
208sctp_cmd_t *sctp_next_cmd(sctp_cmd_seq_t *seq);
209
210#endif /* __net_sctp_command_h__ */
211
diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
new file mode 100644
index 00000000000..2b76c0f4bab
--- /dev/null
+++ b/include/net/sctp/constants.h
@@ -0,0 +1,432 @@
1/* SCTP kernel reference 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 reference Implementation
8 *
9 * The SCTP reference 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 * The SCTP reference 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 <lksctp-developers@lists.sourceforge.net>
29 *
30 * Or submit a bug report through the following website:
31 * http://www.sf.net/projects/lksctp
32 *
33 * Written or modified by:
34 * La Monte H.P. Yarroll <piggy@acm.org>
35 * Karl Knutson <karl@athena.chicago.il.us>
36 * Randall Stewart <randall@stewart.chicago.il.us>
37 * Ken Morneau <kmorneau@cisco.com>
38 * Qiaobing Xie <qxie1@motorola.com>
39 * Xingang Guo <xingang.guo@intel.com>
40 * Sridhar Samudrala <samudrala@us.ibm.com>
41 * Daisy Chang <daisyc@us.ibm.com>
42 *
43 * Any bugs reported given to us we will try to fix... any fixes shared will
44 * be incorporated into the next SCTP release.
45 */
46
47#ifndef __sctp_constants_h__
48#define __sctp_constants_h__
49
50#include <linux/tcp.h> /* For TCP states used in sctp_sock_state_t */
51#include <linux/sctp.h>
52#include <linux/ipv6.h> /* For ipv6hdr. */
53#include <net/sctp/user.h>
54
55/* Value used for stream negotiation. */
56enum { SCTP_MAX_STREAM = 0xffff };
57enum { SCTP_DEFAULT_OUTSTREAMS = 10 };
58enum { SCTP_DEFAULT_INSTREAMS = SCTP_MAX_STREAM };
59
60/* Since CIDs are sparse, we need all four of the following
61 * symbols. CIDs are dense through SCTP_CID_BASE_MAX.
62 */
63#define SCTP_CID_BASE_MAX SCTP_CID_SHUTDOWN_COMPLETE
64#define SCTP_CID_MAX SCTP_CID_ASCONF_ACK
65
66#define SCTP_NUM_BASE_CHUNK_TYPES (SCTP_CID_BASE_MAX + 1)
67#define SCTP_NUM_CHUNK_TYPES (SCTP_NUM_BASE_CHUNKTYPES + 2)
68
69#define SCTP_NUM_ADDIP_CHUNK_TYPES 2
70
71#define SCTP_NUM_PRSCTP_CHUNK_TYPES 1
72
73/* These are the different flavours of event. */
74typedef enum {
75
76 SCTP_EVENT_T_CHUNK = 1,
77 SCTP_EVENT_T_TIMEOUT,
78 SCTP_EVENT_T_OTHER,
79 SCTP_EVENT_T_PRIMITIVE
80
81} sctp_event_t;
82
83#define SCTP_EVENT_T_MAX SCTP_EVENT_T_PRIMITIVE
84#define SCTP_EVENT_T_NUM (SCTP_EVENT_T_MAX + 1)
85
86/* As a convenience for the state machine, we append SCTP_EVENT_* and
87 * SCTP_ULP_* to the list of possible chunks.
88 */
89
90typedef enum {
91 SCTP_EVENT_TIMEOUT_NONE = 0,
92 SCTP_EVENT_TIMEOUT_T1_COOKIE,
93 SCTP_EVENT_TIMEOUT_T1_INIT,
94 SCTP_EVENT_TIMEOUT_T2_SHUTDOWN,
95 SCTP_EVENT_TIMEOUT_T3_RTX,
96 SCTP_EVENT_TIMEOUT_T4_RTO,
97 SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD,
98 SCTP_EVENT_TIMEOUT_HEARTBEAT,
99 SCTP_EVENT_TIMEOUT_SACK,
100 SCTP_EVENT_TIMEOUT_AUTOCLOSE,
101} sctp_event_timeout_t;
102
103#define SCTP_EVENT_TIMEOUT_MAX SCTP_EVENT_TIMEOUT_AUTOCLOSE
104#define SCTP_NUM_TIMEOUT_TYPES (SCTP_EVENT_TIMEOUT_MAX + 1)
105
106typedef enum {
107 SCTP_EVENT_NO_PENDING_TSN = 0,
108 SCTP_EVENT_ICMP_PROTO_UNREACH,
109} sctp_event_other_t;
110
111#define SCTP_EVENT_OTHER_MAX SCTP_EVENT_ICMP_PROTO_UNREACH
112#define SCTP_NUM_OTHER_TYPES (SCTP_EVENT_OTHER_MAX + 1)
113
114/* These are primitive requests from the ULP. */
115typedef enum {
116 SCTP_PRIMITIVE_ASSOCIATE = 0,
117 SCTP_PRIMITIVE_SHUTDOWN,
118 SCTP_PRIMITIVE_ABORT,
119 SCTP_PRIMITIVE_SEND,
120 SCTP_PRIMITIVE_REQUESTHEARTBEAT,
121 SCTP_PRIMITIVE_ASCONF,
122} sctp_event_primitive_t;
123
124#define SCTP_EVENT_PRIMITIVE_MAX SCTP_PRIMITIVE_ASCONF
125#define SCTP_NUM_PRIMITIVE_TYPES (SCTP_EVENT_PRIMITIVE_MAX + 1)
126
127/* We define here a utility type for manipulating subtypes.
128 * The subtype constructors all work like this:
129 *
130 * sctp_subtype_t foo = SCTP_ST_CHUNK(SCTP_CID_INIT);
131 */
132
133typedef union {
134 sctp_cid_t chunk;
135 sctp_event_timeout_t timeout;
136 sctp_event_other_t other;
137 sctp_event_primitive_t primitive;
138} sctp_subtype_t;
139
140#define SCTP_SUBTYPE_CONSTRUCTOR(_name, _type, _elt) \
141static inline sctp_subtype_t \
142SCTP_ST_## _name (_type _arg) \
143{ sctp_subtype_t _retval; _retval._elt = _arg; return _retval; }
144
145SCTP_SUBTYPE_CONSTRUCTOR(CHUNK, sctp_cid_t, chunk)
146SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT, sctp_event_timeout_t, timeout)
147SCTP_SUBTYPE_CONSTRUCTOR(OTHER, sctp_event_other_t, other)
148SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE, sctp_event_primitive_t, primitive)
149
150
151#define sctp_chunk_is_control(a) (a->chunk_hdr->type != SCTP_CID_DATA)
152#define sctp_chunk_is_data(a) (a->chunk_hdr->type == SCTP_CID_DATA)
153
154/* Calculate the actual data size in a data chunk */
155#define SCTP_DATA_SNDSIZE(c) ((int)((unsigned long)(c->chunk_end)\
156 - (unsigned long)(c->chunk_hdr)\
157 - sizeof(sctp_data_chunk_t)))
158
159#define SCTP_MAX_ERROR_CAUSE SCTP_ERROR_NONEXIST_IP
160#define SCTP_NUM_ERROR_CAUSE 10
161
162/* Internal error codes */
163typedef enum {
164
165 SCTP_IERROR_NO_ERROR = 0,
166 SCTP_IERROR_BASE = 1000,
167 SCTP_IERROR_NO_COOKIE,
168 SCTP_IERROR_BAD_SIG,
169 SCTP_IERROR_STALE_COOKIE,
170 SCTP_IERROR_NOMEM,
171 SCTP_IERROR_MALFORMED,
172 SCTP_IERROR_BAD_TAG,
173 SCTP_IERROR_BIG_GAP,
174 SCTP_IERROR_DUP_TSN,
175 SCTP_IERROR_HIGH_TSN,
176 SCTP_IERROR_IGNORE_TSN,
177 SCTP_IERROR_NO_DATA,
178 SCTP_IERROR_BAD_STREAM,
179 SCTP_IERROR_BAD_PORTS,
180
181} sctp_ierror_t;
182
183
184
185/* SCTP state defines for internal state machine */
186typedef enum {
187
188 SCTP_STATE_EMPTY = 0,
189 SCTP_STATE_CLOSED = 1,
190 SCTP_STATE_COOKIE_WAIT = 2,
191 SCTP_STATE_COOKIE_ECHOED = 3,
192 SCTP_STATE_ESTABLISHED = 4,
193 SCTP_STATE_SHUTDOWN_PENDING = 5,
194 SCTP_STATE_SHUTDOWN_SENT = 6,
195 SCTP_STATE_SHUTDOWN_RECEIVED = 7,
196 SCTP_STATE_SHUTDOWN_ACK_SENT = 8,
197
198} sctp_state_t;
199
200#define SCTP_STATE_MAX SCTP_STATE_SHUTDOWN_ACK_SENT
201#define SCTP_STATE_NUM_STATES (SCTP_STATE_MAX + 1)
202
203/* These are values for sk->state.
204 * For a UDP-style SCTP socket, the states are defined as follows
205 * - A socket in SCTP_SS_CLOSED state indicates that it is not willing to
206 * accept new associations, but it can initiate the creation of new ones.
207 * - A socket in SCTP_SS_LISTENING state indicates that it is willing to
208 * accept new associations and can initiate the creation of new ones.
209 * - A socket in SCTP_SS_ESTABLISHED state indicates that it is a peeled off
210 * socket with one association.
211 * For a TCP-style SCTP socket, the states are defined as follows
212 * - A socket in SCTP_SS_CLOSED state indicates that it is not willing to
213 * accept new associations, but it can initiate the creation of new ones.
214 * - A socket in SCTP_SS_LISTENING state indicates that it is willing to
215 * accept new associations, but cannot initiate the creation of new ones.
216 * - A socket in SCTP_SS_ESTABLISHED state indicates that it has a single
217 * association.
218 */
219typedef enum {
220 SCTP_SS_CLOSED = TCP_CLOSE,
221 SCTP_SS_LISTENING = TCP_LISTEN,
222 SCTP_SS_ESTABLISHING = TCP_SYN_SENT,
223 SCTP_SS_ESTABLISHED = TCP_ESTABLISHED,
224 SCTP_SS_DISCONNECTING = TCP_CLOSING,
225} sctp_sock_state_t;
226
227/* These functions map various type to printable names. */
228const char *sctp_cname(const sctp_subtype_t); /* chunk types */
229const char *sctp_oname(const sctp_subtype_t); /* other events */
230const char *sctp_tname(const sctp_subtype_t); /* timeouts */
231const char *sctp_pname(const sctp_subtype_t); /* primitives */
232
233/* This is a table of printable names of sctp_state_t's. */
234extern const char *sctp_state_tbl[], *sctp_evttype_tbl[], *sctp_status_tbl[];
235
236/* Maximum chunk length considering padding requirements. */
237enum { SCTP_MAX_CHUNK_LEN = ((1<<16) - sizeof(__u32)) };
238
239/* Encourage Cookie-Echo bundling by pre-fragmenting chunks a little
240 * harder (until reaching ESTABLISHED state).
241 */
242enum { SCTP_ARBITRARY_COOKIE_ECHO_LEN = 200 };
243
244/* Guess at how big to make the TSN mapping array.
245 * We guarantee that we can handle at least this big a gap between the
246 * cumulative ACK and the highest TSN. In practice, we can often
247 * handle up to twice this value.
248 *
249 * NEVER make this more than 32767 (2^15-1). The Gap Ack Blocks in a
250 * SACK (see section 3.3.4) are only 16 bits, so 2*SCTP_TSN_MAP_SIZE
251 * must be less than 65535 (2^16 - 1), or we will have overflow
252 * problems creating SACK's.
253 */
254#define SCTP_TSN_MAP_SIZE 2048
255#define SCTP_TSN_MAX_GAP 65535
256
257/* We will not record more than this many duplicate TSNs between two
258 * SACKs. The minimum PMTU is 576. Remove all the headers and there
259 * is enough room for 131 duplicate reports. Round down to the
260 * nearest power of 2.
261 */
262enum { SCTP_MIN_PMTU = 576 };
263enum { SCTP_MAX_DUP_TSNS = 16 };
264enum { SCTP_MAX_GABS = 16 };
265
266typedef enum {
267 SCTP_COUNTER_INIT_ERROR,
268} sctp_counter_t;
269
270/* How many counters does an association need? */
271#define SCTP_NUMBER_COUNTERS 5
272
273/* Here we define the default timers. */
274
275/* cookie timer def = ? seconds */
276#define SCTP_DEFAULT_TIMEOUT_T1_COOKIE (3 * HZ)
277
278/* init timer def = 3 seconds */
279#define SCTP_DEFAULT_TIMEOUT_T1_INIT (3 * HZ)
280
281/* shutdown timer def = 300 ms */
282#define SCTP_DEFAULT_TIMEOUT_T2_SHUTDOWN ((300 * HZ) / 1000)
283
284/* 0 seconds + RTO */
285#define SCTP_DEFAULT_TIMEOUT_HEARTBEAT (10 * HZ)
286
287/* recv timer def = 200ms (in usec) */
288#define SCTP_DEFAULT_TIMEOUT_SACK ((200 * HZ) / 1000)
289#define SCTP_DEFAULT_TIMEOUT_SACK_MAX ((500 * HZ) / 1000) /* 500 ms */
290
291/* RTO.Initial - 3 seconds
292 * RTO.Min - 1 second
293 * RTO.Max - 60 seconds
294 * RTO.Alpha - 1/8
295 * RTO.Beta - 1/4
296 */
297#define SCTP_RTO_INITIAL (3 * HZ)
298#define SCTP_RTO_MIN (1 * HZ)
299#define SCTP_RTO_MAX (60 * HZ)
300
301#define SCTP_RTO_ALPHA 3 /* 1/8 when converted to right shifts. */
302#define SCTP_RTO_BETA 2 /* 1/4 when converted to right shifts. */
303
304/* Maximum number of new data packets that can be sent in a burst. */
305#define SCTP_MAX_BURST 4
306
307#define SCTP_CLOCK_GRANULARITY 1 /* 1 jiffy */
308
309#define SCTP_DEF_MAX_INIT 6
310#define SCTP_DEF_MAX_SEND 10
311
312#define SCTP_DEFAULT_COOKIE_LIFE_SEC 60 /* seconds */
313#define SCTP_DEFAULT_COOKIE_LIFE_USEC 0 /* microseconds */
314
315#define SCTP_DEFAULT_MINWINDOW 1500 /* default minimum rwnd size */
316#define SCTP_DEFAULT_MAXWINDOW 65535 /* default rwnd size */
317#define SCTP_DEFAULT_MAXSEGMENT 1500 /* MTU size, this is the limit
318 * to which we will raise the P-MTU.
319 */
320#define SCTP_DEFAULT_MINSEGMENT 512 /* MTU size ... if no mtu disc */
321#define SCTP_HOW_MANY_SECRETS 2 /* How many secrets I keep */
322#define SCTP_HOW_LONG_COOKIE_LIVE 3600 /* How many seconds the current
323 * secret will live?
324 */
325#define SCTP_SECRET_SIZE 32 /* Number of octets in a 256 bits. */
326
327#define SCTP_SIGNATURE_SIZE 20 /* size of a SLA-1 signature */
328
329#define SCTP_COOKIE_MULTIPLE 32 /* Pad out our cookie to make our hash
330 * functions simpler to write.
331 */
332
333#if defined (CONFIG_SCTP_HMAC_MD5)
334#define SCTP_COOKIE_HMAC_ALG "md5"
335#elif defined (CONFIG_SCTP_HMAC_SHA1)
336#define SCTP_COOKIE_HMAC_ALG "sha1"
337#else
338#define SCTP_COOKIE_HMAC_ALG NULL
339#endif
340
341/* These return values describe the success or failure of a number of
342 * routines which form the lower interface to SCTP_outqueue.
343 */
344typedef enum {
345 SCTP_XMIT_OK,
346 SCTP_XMIT_PMTU_FULL,
347 SCTP_XMIT_RWND_FULL,
348 SCTP_XMIT_NAGLE_DELAY,
349} sctp_xmit_t;
350
351/* These are the commands for manipulating transports. */
352typedef enum {
353 SCTP_TRANSPORT_UP,
354 SCTP_TRANSPORT_DOWN,
355} sctp_transport_cmd_t;
356
357/* These are the address scopes defined mainly for IPv4 addresses
358 * based on draft of SCTP IPv4 scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
359 * These scopes are hopefully generic enough to be used on scoping both
360 * IPv4 and IPv6 addresses in SCTP.
361 * At this point, the IPv6 scopes will be mapped to these internal scopes
362 * as much as possible.
363 */
364typedef enum {
365 SCTP_SCOPE_GLOBAL, /* IPv4 global addresses */
366 SCTP_SCOPE_PRIVATE, /* IPv4 private addresses */
367 SCTP_SCOPE_LINK, /* IPv4 link local address */
368 SCTP_SCOPE_LOOPBACK, /* IPv4 loopback address */
369 SCTP_SCOPE_UNUSABLE, /* IPv4 unusable addresses */
370} sctp_scope_t;
371
372/* Based on IPv4 scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>,
373 * SCTP IPv4 unusable addresses: 0.0.0.0/8, 224.0.0.0/4, 198.18.0.0/24,
374 * 192.88.99.0/24.
375 * Also, RFC 8.4, non-unicast addresses are not considered valid SCTP
376 * addresses.
377 */
378#define IS_IPV4_UNUSABLE_ADDRESS(a) \
379 ((INADDR_BROADCAST == *a) || \
380 (MULTICAST(*a)) || \
381 (((unsigned char *)(a))[0] == 0) || \
382 ((((unsigned char *)(a))[0] == 198) && \
383 (((unsigned char *)(a))[1] == 18) && \
384 (((unsigned char *)(a))[2] == 0)) || \
385 ((((unsigned char *)(a))[0] == 192) && \
386 (((unsigned char *)(a))[1] == 88) && \
387 (((unsigned char *)(a))[2] == 99)))
388
389/* IPv4 Link-local addresses: 169.254.0.0/16. */
390#define IS_IPV4_LINK_ADDRESS(a) \
391 ((((unsigned char *)(a))[0] == 169) && \
392 (((unsigned char *)(a))[1] == 254))
393
394/* RFC 1918 "Address Allocation for Private Internets" defines the IPv4
395 * private address space as the following:
396 *
397 * 10.0.0.0 - 10.255.255.255 (10/8 prefix)
398 * 172.16.0.0.0 - 172.31.255.255 (172.16/12 prefix)
399 * 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
400 */
401#define IS_IPV4_PRIVATE_ADDRESS(a) \
402 ((((unsigned char *)(a))[0] == 10) || \
403 ((((unsigned char *)(a))[0] == 172) && \
404 (((unsigned char *)(a))[1] >= 16) && \
405 (((unsigned char *)(a))[1] < 32)) || \
406 ((((unsigned char *)(a))[0] == 192) && \
407 (((unsigned char *)(a))[1] == 168)))
408
409/* Flags used for the bind address copy functions. */
410#define SCTP_ADDR6_ALLOWED 0x00000001 /* IPv6 address is allowed by
411 local sock family */
412#define SCTP_ADDR4_PEERSUPP 0x00000002 /* IPv4 address is supported by
413 peer */
414#define SCTP_ADDR6_PEERSUPP 0x00000004 /* IPv6 address is supported by
415 peer */
416
417/* Reasons to retransmit. */
418typedef enum {
419 SCTP_RTXR_T3_RTX,
420 SCTP_RTXR_FAST_RTX,
421 SCTP_RTXR_PMTUD,
422} sctp_retransmit_reason_t;
423
424/* Reasons to lower cwnd. */
425typedef enum {
426 SCTP_LOWER_CWND_T3_RTX,
427 SCTP_LOWER_CWND_FAST_RTX,
428 SCTP_LOWER_CWND_ECNE,
429 SCTP_LOWER_CWND_INACTIVE,
430} sctp_lower_cwnd_t;
431
432#endif /* __sctp_constants_h__ */
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
new file mode 100644
index 00000000000..960abfa48d6
--- /dev/null
+++ b/include/net/sctp/sctp.h
@@ -0,0 +1,620 @@
1/* SCTP kernel reference 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-2003 Intel Corp.
6 *
7 * This file is part of the SCTP kernel reference Implementation
8 *
9 * The base lksctp header.
10 *
11 * The SCTP reference implementation is free software;
12 * you can redistribute it and/or modify it under the terms of
13 * the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * The SCTP reference implementation is distributed in the hope that it
18 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
19 * ************************
20 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 * See the GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with GNU CC; see the file COPYING. If not, write to
25 * the Free Software Foundation, 59 Temple Place - Suite 330,
26 * Boston, MA 02111-1307, USA.
27 *
28 * Please send any bug reports or fixes you make to the
29 * email address(es):
30 * lksctp developers <lksctp-developers@lists.sourceforge.net>
31 *
32 * Or submit a bug report through the following website:
33 * http://www.sf.net/projects/lksctp
34 *
35 * Written or modified by:
36 * La Monte H.P. Yarroll <piggy@acm.org>
37 * Xingang Guo <xingang.guo@intel.com>
38 * Jon Grimm <jgrimm@us.ibm.com>
39 * Daisy Chang <daisyc@us.ibm.com>
40 * Sridhar Samudrala <sri@us.ibm.com>
41 * Ardelle Fan <ardelle.fan@intel.com>
42 * Ryan Layer <rmlayer@us.ibm.com>
43 * Kevin Gao <kevin.gao@intel.com>
44 *
45 * Any bugs reported given to us we will try to fix... any fixes shared will
46 * be incorporated into the next SCTP release.
47 */
48
49#ifndef __net_sctp_h__
50#define __net_sctp_h__
51
52/* Header Strategy.
53 * Start getting some control over the header file depencies:
54 * includes
55 * constants
56 * structs
57 * prototypes
58 * macros, externs, and inlines
59 *
60 * Move test_frame specific items out of the kernel headers
61 * and into the test frame headers. This is not perfect in any sense
62 * and will continue to evolve.
63 */
64
65
66#include <linux/config.h>
67
68#ifdef TEST_FRAME
69#undef CONFIG_PROC_FS
70#undef CONFIG_SCTP_DBG_OBJCNT
71#undef CONFIG_SYSCTL
72#endif /* TEST_FRAME */
73
74#include <linux/types.h>
75#include <linux/slab.h>
76#include <linux/in.h>
77#include <linux/tty.h>
78#include <linux/proc_fs.h>
79#include <linux/spinlock.h>
80#include <linux/jiffies.h>
81#include <linux/idr.h>
82
83#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
84#include <net/ipv6.h>
85#include <net/ip6_route.h>
86#endif
87
88#include <asm/uaccess.h>
89#include <asm/page.h>
90#include <net/sock.h>
91#include <net/snmp.h>
92#include <net/sctp/structs.h>
93#include <net/sctp/constants.h>
94
95
96/* Set SCTP_DEBUG flag via config if not already set. */
97#ifndef SCTP_DEBUG
98#ifdef CONFIG_SCTP_DBG_MSG
99#define SCTP_DEBUG 1
100#else
101#define SCTP_DEBUG 0
102#endif /* CONFIG_SCTP_DBG */
103#endif /* SCTP_DEBUG */
104
105#ifdef CONFIG_IP_SCTP_MODULE
106#define SCTP_PROTOSW_FLAG 0
107#else /* static! */
108#define SCTP_PROTOSW_FLAG INET_PROTOSW_PERMANENT
109#endif
110
111
112/* Certain internal static functions need to be exported when
113 * compiled into the test frame.
114 */
115#ifndef SCTP_STATIC
116#define SCTP_STATIC static
117#endif
118
119/*
120 * Function declarations.
121 */
122
123/*
124 * sctp/protocol.c
125 */
126extern struct sock *sctp_get_ctl_sock(void);
127extern int sctp_copy_local_addr_list(struct sctp_bind_addr *,
128 sctp_scope_t, int gfp, int flags);
129extern struct sctp_pf *sctp_get_pf_specific(sa_family_t family);
130extern int sctp_register_pf(struct sctp_pf *, sa_family_t);
131
132/*
133 * sctp/socket.c
134 */
135int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb);
136int sctp_inet_listen(struct socket *sock, int backlog);
137void sctp_write_space(struct sock *sk);
138unsigned int sctp_poll(struct file *file, struct socket *sock,
139 poll_table *wait);
140
141/*
142 * sctp/primitive.c
143 */
144int sctp_primitive_ASSOCIATE(struct sctp_association *, void *arg);
145int sctp_primitive_SHUTDOWN(struct sctp_association *, void *arg);
146int sctp_primitive_ABORT(struct sctp_association *, void *arg);
147int sctp_primitive_SEND(struct sctp_association *, void *arg);
148int sctp_primitive_REQUESTHEARTBEAT(struct sctp_association *, void *arg);
149int sctp_primitive_ASCONF(struct sctp_association *, void *arg);
150
151/*
152 * sctp/crc32c.c
153 */
154__u32 sctp_start_cksum(__u8 *ptr, __u16 count);
155__u32 sctp_update_cksum(__u8 *ptr, __u16 count, __u32 cksum);
156__u32 sctp_end_cksum(__u32 cksum);
157__u32 sctp_update_copy_cksum(__u8 *, __u8 *, __u16 count, __u32 cksum);
158
159/*
160 * sctp/input.c
161 */
162int sctp_rcv(struct sk_buff *skb);
163void sctp_v4_err(struct sk_buff *skb, u32 info);
164void sctp_hash_established(struct sctp_association *);
165void sctp_unhash_established(struct sctp_association *);
166void sctp_hash_endpoint(struct sctp_endpoint *);
167void sctp_unhash_endpoint(struct sctp_endpoint *);
168struct sock *sctp_err_lookup(int family, struct sk_buff *,
169 struct sctphdr *, struct sctp_endpoint **,
170 struct sctp_association **,
171 struct sctp_transport **);
172void sctp_err_finish(struct sock *, struct sctp_endpoint *,
173 struct sctp_association *);
174void sctp_icmp_frag_needed(struct sock *, struct sctp_association *,
175 struct sctp_transport *t, __u32 pmtu);
176void sctp_icmp_proto_unreachable(struct sock *sk,
177 struct sctp_endpoint *ep,
178 struct sctp_association *asoc,
179 struct sctp_transport *t);
180
181/*
182 * Section: Macros, externs, and inlines
183 */
184
185
186#ifdef TEST_FRAME
187#include <test_frame.h>
188#else
189
190/* spin lock wrappers. */
191#define sctp_spin_lock_irqsave(lock, flags) spin_lock_irqsave(lock, flags)
192#define sctp_spin_unlock_irqrestore(lock, flags) \
193 spin_unlock_irqrestore(lock, flags)
194#define sctp_local_bh_disable() local_bh_disable()
195#define sctp_local_bh_enable() local_bh_enable()
196#define sctp_spin_lock(lock) spin_lock(lock)
197#define sctp_spin_unlock(lock) spin_unlock(lock)
198#define sctp_write_lock(lock) write_lock(lock)
199#define sctp_write_unlock(lock) write_unlock(lock)
200#define sctp_read_lock(lock) read_lock(lock)
201#define sctp_read_unlock(lock) read_unlock(lock)
202
203/* sock lock wrappers. */
204#define sctp_lock_sock(sk) lock_sock(sk)
205#define sctp_release_sock(sk) release_sock(sk)
206#define sctp_bh_lock_sock(sk) bh_lock_sock(sk)
207#define sctp_bh_unlock_sock(sk) bh_unlock_sock(sk)
208#define SCTP_SOCK_SLEEP_PRE(sk) SOCK_SLEEP_PRE(sk)
209#define SCTP_SOCK_SLEEP_POST(sk) SOCK_SLEEP_POST(sk)
210
211/* SCTP SNMP MIB stats handlers */
212DECLARE_SNMP_STAT(struct sctp_mib, sctp_statistics);
213#define SCTP_INC_STATS(field) SNMP_INC_STATS(sctp_statistics, field)
214#define SCTP_INC_STATS_BH(field) SNMP_INC_STATS_BH(sctp_statistics, field)
215#define SCTP_INC_STATS_USER(field) SNMP_INC_STATS_USER(sctp_statistics, field)
216#define SCTP_DEC_STATS(field) SNMP_DEC_STATS(sctp_statistics, field)
217
218#endif /* !TEST_FRAME */
219
220
221/* Print debugging messages. */
222#if SCTP_DEBUG
223extern int sctp_debug_flag;
224#define SCTP_DEBUG_PRINTK(whatever...) \
225 ((void) (sctp_debug_flag && printk(KERN_DEBUG whatever)))
226#define SCTP_ENABLE_DEBUG { sctp_debug_flag = 1; }
227#define SCTP_DISABLE_DEBUG { sctp_debug_flag = 0; }
228
229#define SCTP_ASSERT(expr, str, func) \
230 if (!(expr)) { \
231 SCTP_DEBUG_PRINTK("Assertion Failed: %s(%s) at %s:%s:%d\n", \
232 str, (#expr), __FILE__, __FUNCTION__, __LINE__); \
233 func; \
234 }
235
236#else /* SCTP_DEBUG */
237
238#define SCTP_DEBUG_PRINTK(whatever...)
239#define SCTP_ENABLE_DEBUG
240#define SCTP_DISABLE_DEBUG
241#define SCTP_ASSERT(expr, str, func)
242
243#endif /* SCTP_DEBUG */
244
245
246/*
247 * Macros for keeping a global reference of object allocations.
248 */
249#ifdef CONFIG_SCTP_DBG_OBJCNT
250
251extern atomic_t sctp_dbg_objcnt_sock;
252extern atomic_t sctp_dbg_objcnt_ep;
253extern atomic_t sctp_dbg_objcnt_assoc;
254extern atomic_t sctp_dbg_objcnt_transport;
255extern atomic_t sctp_dbg_objcnt_chunk;
256extern atomic_t sctp_dbg_objcnt_bind_addr;
257extern atomic_t sctp_dbg_objcnt_bind_bucket;
258extern atomic_t sctp_dbg_objcnt_addr;
259extern atomic_t sctp_dbg_objcnt_ssnmap;
260extern atomic_t sctp_dbg_objcnt_datamsg;
261
262/* Macros to atomically increment/decrement objcnt counters. */
263#define SCTP_DBG_OBJCNT_INC(name) \
264atomic_inc(&sctp_dbg_objcnt_## name)
265#define SCTP_DBG_OBJCNT_DEC(name) \
266atomic_dec(&sctp_dbg_objcnt_## name)
267#define SCTP_DBG_OBJCNT(name) \
268atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0)
269
270/* Macro to help create new entries in in the global array of
271 * objcnt counters.
272 */
273#define SCTP_DBG_OBJCNT_ENTRY(name) \
274{.label= #name, .counter= &sctp_dbg_objcnt_## name}
275
276void sctp_dbg_objcnt_init(void);
277void sctp_dbg_objcnt_exit(void);
278
279#else
280
281#define SCTP_DBG_OBJCNT_INC(name)
282#define SCTP_DBG_OBJCNT_DEC(name)
283
284static inline void sctp_dbg_objcnt_init(void) { return; }
285static inline void sctp_dbg_objcnt_exit(void) { return; }
286
287#endif /* CONFIG_SCTP_DBG_OBJCOUNT */
288
289#if defined CONFIG_SYSCTL
290void sctp_sysctl_register(void);
291void sctp_sysctl_unregister(void);
292#else
293static inline void sctp_sysctl_register(void) { return; }
294static inline void sctp_sysctl_unregister(void) { return; }
295static inline int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen,
296 void __user *oldval, size_t __user *oldlenp,
297 void __user *newval, size_t newlen, void **context) {
298 return -ENOSYS;
299}
300#endif
301
302/* Size of Supported Address Parameter for 'x' address types. */
303#define SCTP_SAT_LEN(x) (sizeof(struct sctp_paramhdr) + (x) * sizeof(__u16))
304
305#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
306
307int sctp_v6_init(void);
308void sctp_v6_exit(void);
309
310#else /* #ifdef defined(CONFIG_IPV6) */
311
312static inline int sctp_v6_init(void) { return 0; }
313static inline void sctp_v6_exit(void) { return; }
314
315#endif /* #if defined(CONFIG_IPV6) */
316
317/* Some wrappers, in case crypto not available. */
318#if defined (CONFIG_CRYPTO_HMAC)
319#define sctp_crypto_alloc_tfm crypto_alloc_tfm
320#define sctp_crypto_free_tfm crypto_free_tfm
321#define sctp_crypto_hmac crypto_hmac
322#else
323#define sctp_crypto_alloc_tfm(x...) NULL
324#define sctp_crypto_free_tfm(x...)
325#define sctp_crypto_hmac(x...)
326#endif
327
328
329/* Map an association to an assoc_id. */
330static inline sctp_assoc_t sctp_assoc2id(const struct sctp_association *asoc)
331{
332 return (asoc?asoc->assoc_id:0);
333}
334
335/* Look up the association by its id. */
336struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id);
337
338
339/* A macro to walk a list of skbs. */
340#define sctp_skb_for_each(pos, head, tmp) \
341for (pos = (head)->next;\
342 tmp = (pos)->next, pos != ((struct sk_buff *)(head));\
343 pos = tmp)
344
345
346/* A helper to append an entire skb list (list) to another (head). */
347static inline void sctp_skb_list_tail(struct sk_buff_head *list,
348 struct sk_buff_head *head)
349{
350 unsigned long flags;
351
352 sctp_spin_lock_irqsave(&head->lock, flags);
353 sctp_spin_lock(&list->lock);
354
355 list_splice((struct list_head *)list, (struct list_head *)head->prev);
356
357 head->qlen += list->qlen;
358 list->qlen = 0;
359
360 sctp_spin_unlock(&list->lock);
361 sctp_spin_unlock_irqrestore(&head->lock, flags);
362}
363
364/**
365 * sctp_list_dequeue - remove from the head of the queue
366 * @list: list to dequeue from
367 *
368 * Remove the head of the list. The head item is
369 * returned or %NULL if the list is empty.
370 */
371
372static inline struct list_head *sctp_list_dequeue(struct list_head *list)
373{
374 struct list_head *result = NULL;
375
376 if (list->next != list) {
377 result = list->next;
378 list->next = result->next;
379 list->next->prev = list;
380 INIT_LIST_HEAD(result);
381 }
382 return result;
383}
384
385/* Tests if the list has one and only one entry. */
386static inline int sctp_list_single_entry(struct list_head *head)
387{
388 return ((head->next != head) && (head->next == head->prev));
389}
390
391/* Calculate the size (in bytes) occupied by the data of an iovec. */
392static inline size_t get_user_iov_size(struct iovec *iov, int iovlen)
393{
394 size_t retval = 0;
395
396 for (; iovlen > 0; --iovlen) {
397 retval += iov->iov_len;
398 iov++;
399 }
400
401 return retval;
402}
403
404/* Generate a random jitter in the range of -50% ~ +50% of input RTO. */
405static inline __s32 sctp_jitter(__u32 rto)
406{
407 static __u32 sctp_rand;
408 __s32 ret;
409
410 /* Avoid divide by zero. */
411 if (!rto)
412 rto = 1;
413
414 sctp_rand += jiffies;
415 sctp_rand ^= (sctp_rand << 12);
416 sctp_rand ^= (sctp_rand >> 20);
417
418 /* Choose random number from 0 to rto, then move to -50% ~ +50%
419 * of rto.
420 */
421 ret = sctp_rand % rto - (rto >> 1);
422 return ret;
423}
424
425/* Break down data chunks at this point. */
426static inline int sctp_frag_point(const struct sctp_sock *sp, int pmtu)
427{
428 int frag = pmtu;
429
430 frag -= sp->pf->af->net_header_len;
431 frag -= sizeof(struct sctphdr) + sizeof(struct sctp_data_chunk);
432
433 if (sp->user_frag)
434 frag = min_t(int, frag, sp->user_frag);
435
436 frag = min_t(int, frag, SCTP_MAX_CHUNK_LEN);
437
438 return frag;
439}
440
441/* Walk through a list of TLV parameters. Don't trust the
442 * individual parameter lengths and instead depend on
443 * the chunk length to indicate when to stop. Make sure
444 * there is room for a param header too.
445 */
446#define sctp_walk_params(pos, chunk, member)\
447_sctp_walk_params((pos), (chunk), WORD_ROUND(ntohs((chunk)->chunk_hdr.length)), member)
448
449#define _sctp_walk_params(pos, chunk, end, member)\
450for (pos.v = chunk->member;\
451 pos.v <= (void *)chunk + end - sizeof(sctp_paramhdr_t) &&\
452 pos.v <= (void *)chunk + end - WORD_ROUND(ntohs(pos.p->length)) &&\
453 ntohs(pos.p->length) >= sizeof(sctp_paramhdr_t);\
454 pos.v += WORD_ROUND(ntohs(pos.p->length)))
455
456#define sctp_walk_errors(err, chunk_hdr)\
457_sctp_walk_errors((err), (chunk_hdr), ntohs((chunk_hdr)->length))
458
459#define _sctp_walk_errors(err, chunk_hdr, end)\
460for (err = (sctp_errhdr_t *)((void *)chunk_hdr + \
461 sizeof(sctp_chunkhdr_t));\
462 (void *)err <= (void *)chunk_hdr + end - sizeof(sctp_errhdr_t) &&\
463 (void *)err <= (void *)chunk_hdr + end - WORD_ROUND(ntohs(err->length)) &&\
464 ntohs(err->length) >= sizeof(sctp_errhdr_t); \
465 err = (sctp_errhdr_t *)((void *)err + WORD_ROUND(ntohs(err->length))))
466
467#define sctp_walk_fwdtsn(pos, chunk)\
468_sctp_walk_fwdtsn((pos), (chunk), ntohs((chunk)->chunk_hdr->length) - sizeof(struct sctp_fwdtsn_chunk))
469
470#define _sctp_walk_fwdtsn(pos, chunk, end)\
471for (pos = chunk->subh.fwdtsn_hdr->skip;\
472 (void *)pos <= (void *)chunk->subh.fwdtsn_hdr->skip + end - sizeof(struct sctp_fwdtsn_skip);\
473 pos++)
474
475/* Round an int up to the next multiple of 4. */
476#define WORD_ROUND(s) (((s)+3)&~3)
477
478/* Make a new instance of type. */
479#define t_new(type, flags) (type *)kmalloc(sizeof(type), flags)
480
481/* Compare two timevals. */
482#define tv_lt(s, t) \
483 (s.tv_sec < t.tv_sec || (s.tv_sec == t.tv_sec && s.tv_usec < t.tv_usec))
484
485/* Add tv1 to tv2. */
486#define TIMEVAL_ADD(tv1, tv2) \
487({ \
488 suseconds_t usecs = (tv2).tv_usec + (tv1).tv_usec; \
489 time_t secs = (tv2).tv_sec + (tv1).tv_sec; \
490\
491 if (usecs >= 1000000) { \
492 usecs -= 1000000; \
493 secs++; \
494 } \
495 (tv2).tv_sec = secs; \
496 (tv2).tv_usec = usecs; \
497})
498
499/* External references. */
500
501extern struct proto sctp_prot;
502extern struct proto sctpv6_prot;
503extern struct proc_dir_entry *proc_net_sctp;
504void sctp_put_port(struct sock *sk);
505
506extern struct idr sctp_assocs_id;
507extern spinlock_t sctp_assocs_id_lock;
508
509/* Static inline functions. */
510
511/* Convert from an IP version number to an Address Family symbol. */
512static inline int ipver2af(__u8 ipver)
513{
514 switch (ipver) {
515 case 4:
516 return AF_INET;
517 case 6:
518 return AF_INET6;
519 default:
520 return 0;
521 };
522}
523
524/* Convert from an address parameter type to an address family. */
525static inline int param_type2af(__u16 type)
526{
527 switch (type) {
528 case SCTP_PARAM_IPV4_ADDRESS:
529 return AF_INET;
530 case SCTP_PARAM_IPV6_ADDRESS:
531 return AF_INET6;
532 default:
533 return 0;
534 };
535}
536
537/* Perform some sanity checks. */
538static inline int sctp_sanity_check(void)
539{
540 SCTP_ASSERT(sizeof(struct sctp_ulpevent) <=
541 sizeof(((struct sk_buff *)0)->cb),
542 "SCTP: ulpevent does not fit in skb!\n", return 0);
543
544 return 1;
545}
546
547/* Warning: The following hash functions assume a power of two 'size'. */
548/* This is the hash function for the SCTP port hash table. */
549static inline int sctp_phashfn(__u16 lport)
550{
551 return (lport & (sctp_port_hashsize - 1));
552}
553
554/* This is the hash function for the endpoint hash table. */
555static inline int sctp_ep_hashfn(__u16 lport)
556{
557 return (lport & (sctp_ep_hashsize - 1));
558}
559
560/* This is the hash function for the association hash table. */
561static inline int sctp_assoc_hashfn(__u16 lport, __u16 rport)
562{
563 int h = (lport << 16) + rport;
564 h ^= h>>8;
565 return (h & (sctp_assoc_hashsize - 1));
566}
567
568/* This is the hash function for the association hash table. This is
569 * not used yet, but could be used as a better hash function when
570 * we have a vtag.
571 */
572static inline int sctp_vtag_hashfn(__u16 lport, __u16 rport, __u32 vtag)
573{
574 int h = (lport << 16) + rport;
575 h ^= vtag;
576 return (h & (sctp_assoc_hashsize-1));
577}
578
579/* Is a socket of this style? */
580#define sctp_style(sk, style) __sctp_style((sk), (SCTP_SOCKET_##style))
581static inline int __sctp_style(const struct sock *sk, sctp_socket_type_t style)
582{
583 return sctp_sk(sk)->type == style;
584}
585
586/* Is the association in this state? */
587#define sctp_state(asoc, state) __sctp_state((asoc), (SCTP_STATE_##state))
588static inline int __sctp_state(const struct sctp_association *asoc,
589 sctp_state_t state)
590{
591 return asoc->state == state;
592}
593
594/* Is the socket in this state? */
595#define sctp_sstate(sk, state) __sctp_sstate((sk), (SCTP_SS_##state))
596static inline int __sctp_sstate(const struct sock *sk, sctp_sock_state_t state)
597{
598 return sk->sk_state == state;
599}
600
601/* Map v4-mapped v6 address back to v4 address */
602static inline void sctp_v6_map_v4(union sctp_addr *addr)
603{
604 addr->v4.sin_family = AF_INET;
605 addr->v4.sin_port = addr->v6.sin6_port;
606 addr->v4.sin_addr.s_addr = addr->v6.sin6_addr.s6_addr32[3];
607}
608
609/* Map v4 address to v4-mapped v6 address */
610static inline void sctp_v4_map_v6(union sctp_addr *addr)
611{
612 addr->v6.sin6_family = AF_INET6;
613 addr->v6.sin6_port = addr->v4.sin_port;
614 addr->v6.sin6_addr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
615 addr->v6.sin6_addr.s6_addr32[0] = 0;
616 addr->v6.sin6_addr.s6_addr32[1] = 0;
617 addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff);
618}
619
620#endif /* __net_sctp_h__ */
diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
new file mode 100644
index 00000000000..5576db56324
--- /dev/null
+++ b/include/net/sctp/sm.h
@@ -0,0 +1,442 @@
1/* SCTP kernel reference 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 reference Implementation
8 *
9 * These are definitions needed by the state machine.
10 *
11 * The SCTP reference implementation is free software;
12 * you can redistribute it and/or modify it under the terms of
13 * the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * The SCTP reference implementation is distributed in the hope that it
18 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
19 * ************************
20 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 * See the GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with GNU CC; see the file COPYING. If not, write to
25 * the Free Software Foundation, 59 Temple Place - Suite 330,
26 * Boston, MA 02111-1307, USA.
27 *
28 * Please send any bug reports or fixes you make to the
29 * email addresses:
30 * lksctp developers <lksctp-developers@lists.sourceforge.net>
31 *
32 * Or submit a bug report through the following website:
33 * http://www.sf.net/projects/lksctp
34 *
35 * Written or modified by:
36 * La Monte H.P. Yarroll <piggy@acm.org>
37 * Karl Knutson <karl@athena.chicago.il.us>
38 * Xingang Guo <xingang.guo@intel.com>
39 * Jon Grimm <jgrimm@us.ibm.com>
40 * Dajiang Zhang <dajiang.zhang@nokia.com>
41 * Sridhar Samudrala <sri@us.ibm.com>
42 * Daisy Chang <daisyc@us.ibm.com>
43 * Ardelle Fan <ardelle.fan@intel.com>
44 * Kevin Gao <kevin.gao@intel.com>
45 *
46 * Any bugs reported given to us we will try to fix... any fixes shared will
47 * be incorporated into the next SCTP release.
48 */
49
50#include <linux/types.h>
51#include <linux/compiler.h>
52#include <linux/slab.h>
53#include <linux/in.h>
54#include <net/sctp/command.h>
55#include <net/sctp/sctp.h>
56
57#ifndef __sctp_sm_h__
58#define __sctp_sm_h__
59
60/*
61 * Possible values for the disposition are:
62 */
63typedef enum {
64 SCTP_DISPOSITION_DISCARD, /* No further processing. */
65 SCTP_DISPOSITION_CONSUME, /* Process return values normally. */
66 SCTP_DISPOSITION_NOMEM, /* We ran out of memory--recover. */
67 SCTP_DISPOSITION_DELETE_TCB, /* Close the association. */
68 SCTP_DISPOSITION_ABORT, /* Close the association NOW. */
69 SCTP_DISPOSITION_VIOLATION, /* The peer is misbehaving. */
70 SCTP_DISPOSITION_NOT_IMPL, /* This entry is not implemented. */
71 SCTP_DISPOSITION_ERROR, /* This is plain old user error. */
72 SCTP_DISPOSITION_BUG, /* This is a bug. */
73} sctp_disposition_t;
74
75typedef struct {
76 int name;
77 int action;
78} sctp_sm_command_t;
79
80typedef sctp_disposition_t (sctp_state_fn_t) (const struct sctp_endpoint *,
81 const struct sctp_association *,
82 const sctp_subtype_t type,
83 void *arg,
84 sctp_cmd_seq_t *);
85typedef void (sctp_timer_event_t) (unsigned long);
86typedef struct {
87 sctp_state_fn_t *fn;
88 const char *name;
89} sctp_sm_table_entry_t;
90
91/* A naming convention of "sctp_sf_xxx" applies to all the state functions
92 * currently in use.
93 */
94
95/* Prototypes for generic state functions. */
96sctp_state_fn_t sctp_sf_not_impl;
97sctp_state_fn_t sctp_sf_bug;
98
99/* Prototypes for gener timer state functions. */
100sctp_state_fn_t sctp_sf_timer_ignore;
101
102/* Prototypes for chunk state functions. */
103sctp_state_fn_t sctp_sf_do_9_1_abort;
104sctp_state_fn_t sctp_sf_cookie_wait_abort;
105sctp_state_fn_t sctp_sf_cookie_echoed_abort;
106sctp_state_fn_t sctp_sf_shutdown_pending_abort;
107sctp_state_fn_t sctp_sf_shutdown_sent_abort;
108sctp_state_fn_t sctp_sf_shutdown_ack_sent_abort;
109sctp_state_fn_t sctp_sf_do_5_1B_init;
110sctp_state_fn_t sctp_sf_do_5_1C_ack;
111sctp_state_fn_t sctp_sf_do_5_1D_ce;
112sctp_state_fn_t sctp_sf_do_5_1E_ca;
113sctp_state_fn_t sctp_sf_do_4_C;
114sctp_state_fn_t sctp_sf_eat_data_6_2;
115sctp_state_fn_t sctp_sf_eat_data_fast_4_4;
116sctp_state_fn_t sctp_sf_eat_sack_6_2;
117sctp_state_fn_t sctp_sf_tabort_8_4_8;
118sctp_state_fn_t sctp_sf_operr_notify;
119sctp_state_fn_t sctp_sf_t1_timer_expire;
120sctp_state_fn_t sctp_sf_t2_timer_expire;
121sctp_state_fn_t sctp_sf_t4_timer_expire;
122sctp_state_fn_t sctp_sf_t5_timer_expire;
123sctp_state_fn_t sctp_sf_sendbeat_8_3;
124sctp_state_fn_t sctp_sf_beat_8_3;
125sctp_state_fn_t sctp_sf_backbeat_8_3;
126sctp_state_fn_t sctp_sf_do_9_2_final;
127sctp_state_fn_t sctp_sf_do_9_2_shutdown;
128sctp_state_fn_t sctp_sf_do_ecn_cwr;
129sctp_state_fn_t sctp_sf_do_ecne;
130sctp_state_fn_t sctp_sf_ootb;
131sctp_state_fn_t sctp_sf_pdiscard;
132sctp_state_fn_t sctp_sf_violation;
133sctp_state_fn_t sctp_sf_violation_chunklen;
134sctp_state_fn_t sctp_sf_discard_chunk;
135sctp_state_fn_t sctp_sf_do_5_2_1_siminit;
136sctp_state_fn_t sctp_sf_do_5_2_2_dupinit;
137sctp_state_fn_t sctp_sf_do_5_2_4_dupcook;
138sctp_state_fn_t sctp_sf_unk_chunk;
139sctp_state_fn_t sctp_sf_do_8_5_1_E_sa;
140sctp_state_fn_t sctp_sf_cookie_echoed_err;
141sctp_state_fn_t sctp_sf_do_asconf;
142sctp_state_fn_t sctp_sf_do_asconf_ack;
143sctp_state_fn_t sctp_sf_do_9_2_reshutack;
144sctp_state_fn_t sctp_sf_eat_fwd_tsn;
145sctp_state_fn_t sctp_sf_eat_fwd_tsn_fast;
146
147/* Prototypes for primitive event state functions. */
148sctp_state_fn_t sctp_sf_do_prm_asoc;
149sctp_state_fn_t sctp_sf_do_prm_send;
150sctp_state_fn_t sctp_sf_do_9_2_prm_shutdown;
151sctp_state_fn_t sctp_sf_cookie_wait_prm_shutdown;
152sctp_state_fn_t sctp_sf_cookie_echoed_prm_shutdown;
153sctp_state_fn_t sctp_sf_do_9_1_prm_abort;
154sctp_state_fn_t sctp_sf_cookie_wait_prm_abort;
155sctp_state_fn_t sctp_sf_cookie_echoed_prm_abort;
156sctp_state_fn_t sctp_sf_shutdown_pending_prm_abort;
157sctp_state_fn_t sctp_sf_shutdown_sent_prm_abort;
158sctp_state_fn_t sctp_sf_shutdown_ack_sent_prm_abort;
159sctp_state_fn_t sctp_sf_error_closed;
160sctp_state_fn_t sctp_sf_error_shutdown;
161sctp_state_fn_t sctp_sf_ignore_primitive;
162sctp_state_fn_t sctp_sf_do_prm_requestheartbeat;
163sctp_state_fn_t sctp_sf_do_prm_asconf;
164
165/* Prototypes for other event state functions. */
166sctp_state_fn_t sctp_sf_do_9_2_start_shutdown;
167sctp_state_fn_t sctp_sf_do_9_2_shutdown_ack;
168sctp_state_fn_t sctp_sf_ignore_other;
169sctp_state_fn_t sctp_sf_cookie_wait_icmp_abort;
170
171/* Prototypes for timeout event state functions. */
172sctp_state_fn_t sctp_sf_do_6_3_3_rtx;
173sctp_state_fn_t sctp_sf_do_6_2_sack;
174sctp_state_fn_t sctp_sf_autoclose_timer_expire;
175
176/* Prototypes for utility support functions. */
177__u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
178const sctp_sm_table_entry_t *sctp_sm_lookup_event(sctp_event_t,
179 sctp_state_t,
180 sctp_subtype_t);
181int sctp_chunk_iif(const struct sctp_chunk *);
182struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
183 struct sctp_chunk *,
184 int gfp);
185__u32 sctp_generate_verification_tag(void);
186void sctp_populate_tie_tags(__u8 *cookie, __u32 curTag, __u32 hisTag);
187
188/* Prototypes for chunk-building functions. */
189struct sctp_chunk *sctp_make_init(const struct sctp_association *,
190 const struct sctp_bind_addr *,
191 int gfp, int vparam_len);
192struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *,
193 const struct sctp_chunk *,
194 const int gfp,
195 const int unkparam_len);
196struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *,
197 const struct sctp_chunk *);
198struct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *,
199 const struct sctp_chunk *);
200struct sctp_chunk *sctp_make_cwr(const struct sctp_association *,
201 const __u32 lowest_tsn,
202 const struct sctp_chunk *);
203struct sctp_chunk * sctp_make_datafrag_empty(struct sctp_association *,
204 const struct sctp_sndrcvinfo *sinfo,
205 int len, const __u8 flags,
206 __u16 ssn);
207struct sctp_chunk *sctp_make_ecne(const struct sctp_association *,
208 const __u32);
209struct sctp_chunk *sctp_make_sack(const struct sctp_association *);
210struct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc,
211 const struct sctp_chunk *chunk);
212struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc,
213 const struct sctp_chunk *);
214struct sctp_chunk *sctp_make_shutdown_complete(const struct sctp_association *,
215 const struct sctp_chunk *);
216void sctp_init_cause(struct sctp_chunk *, __u16 cause, const void *, size_t);
217struct sctp_chunk *sctp_make_abort(const struct sctp_association *,
218 const struct sctp_chunk *,
219 const size_t hint);
220struct sctp_chunk *sctp_make_abort_no_data(const struct sctp_association *,
221 const struct sctp_chunk *,
222 __u32 tsn);
223struct sctp_chunk *sctp_make_abort_user(const struct sctp_association *,
224 const struct sctp_chunk *,
225 const struct msghdr *);
226struct sctp_chunk *sctp_make_abort_violation(const struct sctp_association *,
227 const struct sctp_chunk *,
228 const __u8 *,
229 const size_t );
230struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *,
231 const struct sctp_transport *,
232 const void *payload,
233 const size_t paylen);
234struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *,
235 const struct sctp_chunk *,
236 const void *payload,
237 const size_t paylen);
238struct sctp_chunk *sctp_make_op_error(const struct sctp_association *,
239 const struct sctp_chunk *chunk,
240 __u16 cause_code,
241 const void *payload,
242 size_t paylen);
243
244struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *,
245 union sctp_addr *,
246 struct sockaddr *,
247 int, __u16);
248struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
249 union sctp_addr *addr);
250struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
251 struct sctp_chunk *asconf);
252int sctp_process_asconf_ack(struct sctp_association *asoc,
253 struct sctp_chunk *asconf_ack);
254struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
255 __u32 new_cum_tsn, size_t nstreams,
256 struct sctp_fwdtsn_skip *skiplist);
257
258void sctp_chunk_assign_tsn(struct sctp_chunk *);
259void sctp_chunk_assign_ssn(struct sctp_chunk *);
260
261void sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, __u16 error);
262
263/* Prototypes for statetable processing. */
264
265int sctp_do_sm(sctp_event_t event_type, sctp_subtype_t subtype,
266 sctp_state_t state,
267 struct sctp_endpoint *,
268 struct sctp_association *asoc,
269 void *event_arg,
270 int gfp);
271
272/* 2nd level prototypes */
273void sctp_generate_t3_rtx_event(unsigned long peer);
274void sctp_generate_heartbeat_event(unsigned long peer);
275
276void sctp_ootb_pkt_free(struct sctp_packet *);
277
278struct sctp_association *sctp_unpack_cookie(const struct sctp_endpoint *,
279 const struct sctp_association *,
280 struct sctp_chunk *, int gfp, int *err,
281 struct sctp_chunk **err_chk_p);
282int sctp_addip_addr_config(struct sctp_association *, sctp_param_t,
283 struct sockaddr_storage*, int);
284
285/* 3rd level prototypes */
286__u32 sctp_generate_tag(const struct sctp_endpoint *);
287__u32 sctp_generate_tsn(const struct sctp_endpoint *);
288
289/* Extern declarations for major data structures. */
290extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
291
292
293/* Get the size of a DATA chunk payload. */
294static inline __u16 sctp_data_size(struct sctp_chunk *chunk)
295{
296 __u16 size;
297
298 size = ntohs(chunk->chunk_hdr->length);
299 size -= sizeof(sctp_data_chunk_t);
300
301 return size;
302}
303
304/* Compare two TSNs */
305
306/* RFC 1982 - Serial Number Arithmetic
307 *
308 * 2. Comparison
309 * Then, s1 is said to be equal to s2 if and only if i1 is equal to i2,
310 * in all other cases, s1 is not equal to s2.
311 *
312 * s1 is said to be less than s2 if, and only if, s1 is not equal to s2,
313 * and
314 *
315 * (i1 < i2 and i2 - i1 < 2^(SERIAL_BITS - 1)) or
316 * (i1 > i2 and i1 - i2 > 2^(SERIAL_BITS - 1))
317 *
318 * s1 is said to be greater than s2 if, and only if, s1 is not equal to
319 * s2, and
320 *
321 * (i1 < i2 and i2 - i1 > 2^(SERIAL_BITS - 1)) or
322 * (i1 > i2 and i1 - i2 < 2^(SERIAL_BITS - 1))
323 */
324
325/*
326 * RFC 2960
327 * 1.6 Serial Number Arithmetic
328 *
329 * Comparisons and arithmetic on TSNs in this document SHOULD use Serial
330 * Number Arithmetic as defined in [RFC1982] where SERIAL_BITS = 32.
331 */
332
333enum {
334 TSN_SIGN_BIT = (1<<31)
335};
336
337static inline int TSN_lt(__u32 s, __u32 t)
338{
339 return (((s) - (t)) & TSN_SIGN_BIT);
340}
341
342static inline int TSN_lte(__u32 s, __u32 t)
343{
344 return (((s) == (t)) || (((s) - (t)) & TSN_SIGN_BIT));
345}
346
347/* Compare two SSNs */
348
349/*
350 * RFC 2960
351 * 1.6 Serial Number Arithmetic
352 *
353 * Comparisons and arithmetic on Stream Sequence Numbers in this document
354 * SHOULD use Serial Number Arithmetic as defined in [RFC1982] where
355 * SERIAL_BITS = 16.
356 */
357enum {
358 SSN_SIGN_BIT = (1<<15)
359};
360
361static inline int SSN_lt(__u16 s, __u16 t)
362{
363 return (((s) - (t)) & SSN_SIGN_BIT);
364}
365
366static inline int SSN_lte(__u16 s, __u16 t)
367{
368 return (((s) == (t)) || (((s) - (t)) & SSN_SIGN_BIT));
369}
370
371/*
372 * ADDIP 3.1.1
373 * The valid range of Serial Number is from 0 to 4294967295 (2**32 - 1). Serial
374 * Numbers wrap back to 0 after reaching 4294967295.
375 */
376enum {
377 ADDIP_SERIAL_SIGN_BIT = (1<<31)
378};
379
380static inline int ADDIP_SERIAL_gte(__u16 s, __u16 t)
381{
382 return (((s) == (t)) || (((t) - (s)) & ADDIP_SERIAL_SIGN_BIT));
383}
384
385
386/* Run sctp_add_cmd() generating a BUG() if there is a failure. */
387static inline void sctp_add_cmd_sf(sctp_cmd_seq_t *seq, sctp_verb_t verb, sctp_arg_t obj)
388{
389 if (unlikely(!sctp_add_cmd(seq, verb, obj)))
390 BUG();
391}
392
393/* Check VTAG of the packet matches the sender's own tag. */
394static inline int
395sctp_vtag_verify(const struct sctp_chunk *chunk,
396 const struct sctp_association *asoc)
397{
398 /* RFC 2960 Sec 8.5 When receiving an SCTP packet, the endpoint
399 * MUST ensure that the value in the Verification Tag field of
400 * the received SCTP packet matches its own Tag. If the received
401 * Verification Tag value does not match the receiver's own
402 * tag value, the receiver shall silently discard the packet...
403 */
404 if (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)
405 return 1;
406
407 return 0;
408}
409
410/* Check VTAG of the packet matches the sender's own tag OR its peer's
411 * tag and the T bit is set in the Chunk Flags.
412 */
413static inline int
414sctp_vtag_verify_either(const struct sctp_chunk *chunk,
415 const struct sctp_association *asoc)
416{
417 /* RFC 2960 Section 8.5.1, sctpimpguide-06 Section 2.13.2
418 *
419 * B) The receiver of a ABORT shall accept the packet if the
420 * Verification Tag field of the packet matches its own tag OR it
421 * is set to its peer's tag and the T bit is set in the Chunk
422 * Flags. Otherwise, the receiver MUST silently discard the packet
423 * and take no further action.
424 *
425 * (C) The receiver of a SHUTDOWN COMPLETE shall accept the
426 * packet if the Verification Tag field of the packet
427 * matches its own tag OR it is set to its peer's tag and
428 * the T bit is set in the Chunk Flags. Otherwise, the
429 * receiver MUST silently discard the packet and take no
430 * further action....
431 *
432 */
433 if ((ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag) ||
434 (sctp_test_T_bit(chunk) && (ntohl(chunk->sctp_hdr->vtag)
435 == asoc->c.peer_vtag))) {
436 return 1;
437 }
438
439 return 0;
440}
441
442#endif /* __sctp_sm_h__ */
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
new file mode 100644
index 00000000000..7e64cf6bda1
--- /dev/null
+++ b/include/net/sctp/structs.h
@@ -0,0 +1,1752 @@
1/* SCTP kernel reference 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 reference Implementation
8 *
9 * The SCTP reference 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 * The SCTP reference 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 addresses:
28 * lksctp developers <lksctp-developers@lists.sourceforge.net>
29 *
30 * Or submit a bug report through the following website:
31 * http://www.sf.net/projects/lksctp
32 *
33 * Written or modified by:
34 * Randall Stewart <randall@sctp.chicago.il.us>
35 * Ken Morneau <kmorneau@cisco.com>
36 * Qiaobing Xie <qxie1@email.mot.com>
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Jon Grimm <jgrimm@us.ibm.com>
40 * Xingang Guo <xingang.guo@intel.com>
41 * Hui Huang <hui.huang@nokia.com>
42 * Sridhar Samudrala <sri@us.ibm.com>
43 * Daisy Chang <daisyc@us.ibm.com>
44 * Dajiang Zhang <dajiang.zhang@nokia.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Ryan Layer <rmlayer@us.ibm.com>
47 * Anup Pemmaiah <pemmaiah@cc.usu.edu>
48 * Kevin Gao <kevin.gao@intel.com>
49 *
50 * Any bugs reported given to us we will try to fix... any fixes shared will
51 * be incorporated into the next SCTP release.
52 */
53
54#ifndef __sctp_structs_h__
55#define __sctp_structs_h__
56
57#include <linux/time.h> /* We get struct timespec. */
58#include <linux/socket.h> /* linux/in.h needs this!! */
59#include <linux/in.h> /* We get struct sockaddr_in. */
60#include <linux/in6.h> /* We get struct in6_addr */
61#include <linux/ipv6.h>
62#include <asm/param.h> /* We get MAXHOSTNAMELEN. */
63#include <asm/atomic.h> /* This gets us atomic counters. */
64#include <linux/skbuff.h> /* We need sk_buff_head. */
65#include <linux/workqueue.h> /* We need tq_struct. */
66#include <linux/sctp.h> /* We need sctp* header structs. */
67
68/* A convenience structure for handling sockaddr structures.
69 * We should wean ourselves off this.
70 */
71union sctp_addr {
72 struct sockaddr_in v4;
73 struct sockaddr_in6 v6;
74 struct sockaddr sa;
75};
76
77/* Forward declarations for data structures. */
78struct sctp_globals;
79struct sctp_endpoint;
80struct sctp_association;
81struct sctp_transport;
82struct sctp_packet;
83struct sctp_chunk;
84struct sctp_inq;
85struct sctp_outq;
86struct sctp_bind_addr;
87struct sctp_ulpq;
88struct sctp_ep_common;
89struct sctp_ssnmap;
90
91
92#include <net/sctp/tsnmap.h>
93#include <net/sctp/ulpevent.h>
94#include <net/sctp/ulpqueue.h>
95
96/* Structures useful for managing bind/connect. */
97
98struct sctp_bind_bucket {
99 unsigned short port;
100 unsigned short fastreuse;
101 struct sctp_bind_bucket *next;
102 struct sctp_bind_bucket **pprev;
103 struct hlist_head owner;
104};
105
106struct sctp_bind_hashbucket {
107 spinlock_t lock;
108 struct sctp_bind_bucket *chain;
109};
110
111/* Used for hashing all associations. */
112struct sctp_hashbucket {
113 rwlock_t lock;
114 struct sctp_ep_common *chain;
115} __attribute__((__aligned__(8)));
116
117
118/* The SCTP globals structure. */
119extern struct sctp_globals {
120 /* RFC2960 Section 14. Suggested SCTP Protocol Parameter Values
121 *
122 * The following protocol parameters are RECOMMENDED:
123 *
124 * RTO.Initial - 3 seconds
125 * RTO.Min - 1 second
126 * RTO.Max - 60 seconds
127 * RTO.Alpha - 1/8 (3 when converted to right shifts.)
128 * RTO.Beta - 1/4 (2 when converted to right shifts.)
129 */
130 __u32 rto_initial;
131 __u32 rto_min;
132 __u32 rto_max;
133
134 /* Note: rto_alpha and rto_beta are really defined as inverse
135 * powers of two to facilitate integer operations.
136 */
137 int rto_alpha;
138 int rto_beta;
139
140 /* Max.Burst - 4 */
141 int max_burst;
142
143 /* Valid.Cookie.Life - 60 seconds */
144 int valid_cookie_life;
145
146 /* Whether Cookie Preservative is enabled(1) or not(0) */
147 int cookie_preserve_enable;
148
149 /* Association.Max.Retrans - 10 attempts
150 * Path.Max.Retrans - 5 attempts (per destination address)
151 * Max.Init.Retransmits - 8 attempts
152 */
153 int max_retrans_association;
154 int max_retrans_path;
155 int max_retrans_init;
156
157 /* HB.interval - 30 seconds */
158 int hb_interval;
159
160 /* The following variables are implementation specific. */
161
162 /* Default initialization values to be applied to new associations. */
163 __u16 max_instreams;
164 __u16 max_outstreams;
165
166 /* This is a list of groups of functions for each address
167 * family that we support.
168 */
169 struct list_head address_families;
170
171 /* This is the hash of all endpoints. */
172 int ep_hashsize;
173 struct sctp_hashbucket *ep_hashtable;
174
175 /* This is the hash of all associations. */
176 int assoc_hashsize;
177 struct sctp_hashbucket *assoc_hashtable;
178
179 /* This is the sctp port control hash. */
180 int port_hashsize;
181 int port_rover;
182 spinlock_t port_alloc_lock; /* Protects port_rover. */
183 struct sctp_bind_hashbucket *port_hashtable;
184
185 /* This is the global local address list.
186 * We actively maintain this complete list of interfaces on
187 * the system by catching routing events.
188 *
189 * It is a list of sctp_sockaddr_entry.
190 */
191 struct list_head local_addr_list;
192 spinlock_t local_addr_lock;
193
194 /* Flag to indicate if addip is enabled. */
195 int addip_enable;
196
197 /* Flag to indicate if PR-SCTP is enabled. */
198 int prsctp_enable;
199} sctp_globals;
200
201#define sctp_rto_initial (sctp_globals.rto_initial)
202#define sctp_rto_min (sctp_globals.rto_min)
203#define sctp_rto_max (sctp_globals.rto_max)
204#define sctp_rto_alpha (sctp_globals.rto_alpha)
205#define sctp_rto_beta (sctp_globals.rto_beta)
206#define sctp_max_burst (sctp_globals.max_burst)
207#define sctp_valid_cookie_life (sctp_globals.valid_cookie_life)
208#define sctp_cookie_preserve_enable (sctp_globals.cookie_preserve_enable)
209#define sctp_max_retrans_association (sctp_globals.max_retrans_association)
210#define sctp_max_retrans_path (sctp_globals.max_retrans_path)
211#define sctp_max_retrans_init (sctp_globals.max_retrans_init)
212#define sctp_hb_interval (sctp_globals.hb_interval)
213#define sctp_max_instreams (sctp_globals.max_instreams)
214#define sctp_max_outstreams (sctp_globals.max_outstreams)
215#define sctp_address_families (sctp_globals.address_families)
216#define sctp_ep_hashsize (sctp_globals.ep_hashsize)
217#define sctp_ep_hashtable (sctp_globals.ep_hashtable)
218#define sctp_assoc_hashsize (sctp_globals.assoc_hashsize)
219#define sctp_assoc_hashtable (sctp_globals.assoc_hashtable)
220#define sctp_port_hashsize (sctp_globals.port_hashsize)
221#define sctp_port_rover (sctp_globals.port_rover)
222#define sctp_port_alloc_lock (sctp_globals.port_alloc_lock)
223#define sctp_port_hashtable (sctp_globals.port_hashtable)
224#define sctp_local_addr_list (sctp_globals.local_addr_list)
225#define sctp_local_addr_lock (sctp_globals.local_addr_lock)
226#define sctp_addip_enable (sctp_globals.addip_enable)
227#define sctp_prsctp_enable (sctp_globals.prsctp_enable)
228
229/* SCTP Socket type: UDP or TCP style. */
230typedef enum {
231 SCTP_SOCKET_UDP = 0,
232 SCTP_SOCKET_UDP_HIGH_BANDWIDTH,
233 SCTP_SOCKET_TCP
234} sctp_socket_type_t;
235
236/* Per socket SCTP information. */
237struct sctp_sock {
238 /* inet_sock has to be the first member of sctp_sock */
239 struct inet_sock inet;
240 /* What kind of a socket is this? */
241 sctp_socket_type_t type;
242
243 /* PF_ family specific functions. */
244 struct sctp_pf *pf;
245
246 /* Access to HMAC transform. */
247 struct crypto_tfm *hmac;
248
249 /* What is our base endpointer? */
250 struct sctp_endpoint *ep;
251
252 struct sctp_bind_bucket *bind_hash;
253 /* Various Socket Options. */
254 __u16 default_stream;
255 __u32 default_ppid;
256 __u16 default_flags;
257 __u32 default_context;
258 __u32 default_timetolive;
259
260 struct sctp_initmsg initmsg;
261 struct sctp_rtoinfo rtoinfo;
262 struct sctp_paddrparams paddrparam;
263 struct sctp_event_subscribe subscribe;
264 struct sctp_assocparams assocparams;
265 int user_frag;
266 __u32 autoclose;
267 __u8 nodelay;
268 __u8 disable_fragments;
269 __u8 pd_mode;
270 __u8 v4mapped;
271 __u32 adaption_ind;
272
273 /* Receive to here while partial delivery is in effect. */
274 struct sk_buff_head pd_lobby;
275};
276
277static inline struct sctp_sock *sctp_sk(const struct sock *sk)
278{
279 return (struct sctp_sock *)sk;
280}
281
282static inline struct sock *sctp_opt2sk(const struct sctp_sock *sp)
283{
284 return (struct sock *)sp;
285}
286
287#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
288struct sctp6_sock {
289 struct sctp_sock sctp;
290 struct ipv6_pinfo inet6;
291};
292#endif /* CONFIG_IPV6 */
293
294
295/* This is our APPLICATION-SPECIFIC state cookie.
296 * THIS IS NOT DICTATED BY THE SPECIFICATION.
297 */
298/* These are the parts of an association which we send in the cookie.
299 * Most of these are straight out of:
300 * RFC2960 12.2 Parameters necessary per association (i.e. the TCB)
301 *
302 */
303
304struct sctp_cookie {
305
306 /* My : Tag expected in every inbound packet and sent
307 * Verification: in the INIT or INIT ACK chunk.
308 * Tag :
309 */
310 __u32 my_vtag;
311
312 /* Peer's : Tag expected in every outbound packet except
313 * Verification: in the INIT chunk.
314 * Tag :
315 */
316 __u32 peer_vtag;
317
318 /* The rest of these are not from the spec, but really need to
319 * be in the cookie.
320 */
321
322 /* My Tie Tag : Assist in discovering a restarting association. */
323 __u32 my_ttag;
324
325 /* Peer's Tie Tag: Assist in discovering a restarting association. */
326 __u32 peer_ttag;
327
328 /* When does this cookie expire? */
329 struct timeval expiration;
330
331 /* Number of inbound/outbound streams which are set
332 * and negotiated during the INIT process.
333 */
334 __u16 sinit_num_ostreams;
335 __u16 sinit_max_instreams;
336
337 /* This is the first sequence number I used. */
338 __u32 initial_tsn;
339
340 /* This holds the originating address of the INIT packet. */
341 union sctp_addr peer_addr;
342
343 /* IG Section 2.35.3
344 * Include the source port of the INIT-ACK
345 */
346 __u16 my_port;
347
348 __u8 prsctp_capable;
349
350 /* Padding for future use */
351 __u8 padding;
352
353 __u32 adaption_ind;
354
355
356 /* This is a shim for my peer's INIT packet, followed by
357 * a copy of the raw address list of the association.
358 * The length of the raw address list is saved in the
359 * raw_addr_list_len field, which will be used at the time when
360 * the association TCB is re-constructed from the cookie.
361 */
362 __u32 raw_addr_list_len;
363 struct sctp_init_chunk peer_init[0];
364};
365
366
367/* The format of our cookie that we send to our peer. */
368struct sctp_signed_cookie {
369 __u8 signature[SCTP_SECRET_SIZE];
370 struct sctp_cookie c;
371};
372
373/* This is another convenience type to allocate memory for address
374 * params for the maximum size and pass such structures around
375 * internally.
376 */
377union sctp_addr_param {
378 struct sctp_ipv4addr_param v4;
379 struct sctp_ipv6addr_param v6;
380};
381
382/* A convenience type to allow walking through the various
383 * parameters and avoid casting all over the place.
384 */
385union sctp_params {
386 void *v;
387 struct sctp_paramhdr *p;
388 struct sctp_cookie_preserve_param *life;
389 struct sctp_hostname_param *dns;
390 struct sctp_cookie_param *cookie;
391 struct sctp_supported_addrs_param *sat;
392 struct sctp_ipv4addr_param *v4;
393 struct sctp_ipv6addr_param *v6;
394 union sctp_addr_param *addr;
395 struct sctp_adaption_ind_param *aind;
396};
397
398/* RFC 2960. Section 3.3.5 Heartbeat.
399 * Heartbeat Information: variable length
400 * The Sender-specific Heartbeat Info field should normally include
401 * information about the sender's current time when this HEARTBEAT
402 * chunk is sent and the destination transport address to which this
403 * HEARTBEAT is sent (see Section 8.3).
404 */
405typedef struct sctp_sender_hb_info {
406 struct sctp_paramhdr param_hdr;
407 union sctp_addr daddr;
408 unsigned long sent_at;
409} __attribute__((packed)) sctp_sender_hb_info_t;
410
411/*
412 * RFC 2960 1.3.2 Sequenced Delivery within Streams
413 *
414 * The term "stream" is used in SCTP to refer to a sequence of user
415 * messages that are to be delivered to the upper-layer protocol in
416 * order with respect to other messages within the same stream. This is
417 * in contrast to its usage in TCP, where it refers to a sequence of
418 * bytes (in this document a byte is assumed to be eight bits).
419 * ...
420 *
421 * This is the structure we use to track both our outbound and inbound
422 * SSN, or Stream Sequence Numbers.
423 */
424
425struct sctp_stream {
426 __u16 *ssn;
427 unsigned int len;
428};
429
430struct sctp_ssnmap {
431 struct sctp_stream in;
432 struct sctp_stream out;
433 int malloced;
434};
435
436struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out, int gfp);
437void sctp_ssnmap_free(struct sctp_ssnmap *map);
438void sctp_ssnmap_clear(struct sctp_ssnmap *map);
439
440/* What is the current SSN number for this stream? */
441static inline __u16 sctp_ssn_peek(struct sctp_stream *stream, __u16 id)
442{
443 return stream->ssn[id];
444}
445
446/* Return the next SSN number for this stream. */
447static inline __u16 sctp_ssn_next(struct sctp_stream *stream, __u16 id)
448{
449 return stream->ssn[id]++;
450}
451
452/* Skip over this ssn and all below. */
453static inline void sctp_ssn_skip(struct sctp_stream *stream, __u16 id,
454 __u16 ssn)
455{
456 stream->ssn[id] = ssn+1;
457}
458
459/*
460 * Pointers to address related SCTP functions.
461 * (i.e. things that depend on the address family.)
462 */
463struct sctp_af {
464 int (*sctp_xmit) (struct sk_buff *skb,
465 struct sctp_transport *,
466 int ipfragok);
467 int (*setsockopt) (struct sock *sk,
468 int level,
469 int optname,
470 char __user *optval,
471 int optlen);
472 int (*getsockopt) (struct sock *sk,
473 int level,
474 int optname,
475 char __user *optval,
476 int __user *optlen);
477 struct dst_entry *(*get_dst) (struct sctp_association *asoc,
478 union sctp_addr *daddr,
479 union sctp_addr *saddr);
480 void (*get_saddr) (struct sctp_association *asoc,
481 struct dst_entry *dst,
482 union sctp_addr *daddr,
483 union sctp_addr *saddr);
484 void (*copy_addrlist) (struct list_head *,
485 struct net_device *);
486 void (*dst_saddr) (union sctp_addr *saddr,
487 struct dst_entry *dst,
488 unsigned short port);
489 int (*cmp_addr) (const union sctp_addr *addr1,
490 const union sctp_addr *addr2);
491 void (*addr_copy) (union sctp_addr *dst,
492 union sctp_addr *src);
493 void (*from_skb) (union sctp_addr *,
494 struct sk_buff *skb,
495 int saddr);
496 void (*from_sk) (union sctp_addr *,
497 struct sock *sk);
498 void (*to_sk_saddr) (union sctp_addr *,
499 struct sock *sk);
500 void (*to_sk_daddr) (union sctp_addr *,
501 struct sock *sk);
502 void (*from_addr_param) (union sctp_addr *,
503 union sctp_addr_param *,
504 __u16 port, int iif);
505 int (*to_addr_param) (const union sctp_addr *,
506 union sctp_addr_param *);
507 int (*addr_valid) (union sctp_addr *,
508 struct sctp_sock *);
509 sctp_scope_t (*scope) (union sctp_addr *);
510 void (*inaddr_any) (union sctp_addr *, unsigned short);
511 int (*is_any) (const union sctp_addr *);
512 int (*available) (union sctp_addr *,
513 struct sctp_sock *);
514 int (*skb_iif) (const struct sk_buff *sk);
515 int (*is_ce) (const struct sk_buff *sk);
516 void (*seq_dump_addr)(struct seq_file *seq,
517 union sctp_addr *addr);
518 __u16 net_header_len;
519 int sockaddr_len;
520 sa_family_t sa_family;
521 struct list_head list;
522};
523
524struct sctp_af *sctp_get_af_specific(sa_family_t);
525int sctp_register_af(struct sctp_af *);
526
527/* Protocol family functions. */
528struct sctp_pf {
529 void (*event_msgname)(struct sctp_ulpevent *, char *, int *);
530 void (*skb_msgname) (struct sk_buff *, char *, int *);
531 int (*af_supported) (sa_family_t, struct sctp_sock *);
532 int (*cmp_addr) (const union sctp_addr *,
533 const union sctp_addr *,
534 struct sctp_sock *);
535 int (*bind_verify) (struct sctp_sock *, union sctp_addr *);
536 int (*send_verify) (struct sctp_sock *, union sctp_addr *);
537 int (*supported_addrs)(const struct sctp_sock *, __u16 *);
538 struct sock *(*create_accept_sk) (struct sock *sk,
539 struct sctp_association *asoc);
540 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
541 struct sctp_af *af;
542};
543
544
545/* Structure to track chunk fragments that have been acked, but peer
546 * fragments of the same message have not.
547 */
548struct sctp_datamsg {
549 /* Chunks waiting to be submitted to lower layer. */
550 struct list_head chunks;
551 /* Chunks that have been transmitted. */
552 struct list_head track;
553 /* Reference counting. */
554 atomic_t refcnt;
555 /* When is this message no longer interesting to the peer? */
556 unsigned long expires_at;
557 /* Did the messenge fail to send? */
558 int send_error;
559 char send_failed;
560 /* Control whether chunks from this message can be abandoned. */
561 char can_abandon;
562};
563
564struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *,
565 struct sctp_sndrcvinfo *,
566 struct msghdr *, int len);
567void sctp_datamsg_put(struct sctp_datamsg *);
568void sctp_datamsg_free(struct sctp_datamsg *);
569void sctp_datamsg_track(struct sctp_chunk *);
570void sctp_chunk_fail(struct sctp_chunk *, int error);
571int sctp_chunk_abandoned(struct sctp_chunk *);
572
573
574/* RFC2960 1.4 Key Terms
575 *
576 * o Chunk: A unit of information within an SCTP packet, consisting of
577 * a chunk header and chunk-specific content.
578 *
579 * As a matter of convenience, we remember the SCTP common header for
580 * each chunk as well as a few other header pointers...
581 */
582struct sctp_chunk {
583 /* These first three elements MUST PRECISELY match the first
584 * three elements of struct sk_buff. This allows us to reuse
585 * all the skb_* queue management functions.
586 */
587 struct sctp_chunk *next;
588 struct sctp_chunk *prev;
589 struct sk_buff_head *list;
590 atomic_t refcnt;
591
592 /* This is our link to the per-transport transmitted list. */
593 struct list_head transmitted_list;
594
595 /* This field is used by chunks that hold fragmented data.
596 * For the first fragment this is the list that holds the rest of
597 * fragments. For the remaining fragments, this is the link to the
598 * frag_list maintained in the first fragment.
599 */
600 struct list_head frag_list;
601
602 /* This points to the sk_buff containing the actual data. */
603 struct sk_buff *skb;
604
605 /* These are the SCTP headers by reverse order in a packet.
606 * Note that some of these may happen more than once. In that
607 * case, we point at the "current" one, whatever that means
608 * for that level of header.
609 */
610
611 /* We point this at the FIRST TLV parameter to chunk_hdr. */
612 union sctp_params param_hdr;
613 union {
614 __u8 *v;
615 struct sctp_datahdr *data_hdr;
616 struct sctp_inithdr *init_hdr;
617 struct sctp_sackhdr *sack_hdr;
618 struct sctp_heartbeathdr *hb_hdr;
619 struct sctp_sender_hb_info *hbs_hdr;
620 struct sctp_shutdownhdr *shutdown_hdr;
621 struct sctp_signed_cookie *cookie_hdr;
622 struct sctp_ecnehdr *ecne_hdr;
623 struct sctp_cwrhdr *ecn_cwr_hdr;
624 struct sctp_errhdr *err_hdr;
625 struct sctp_addiphdr *addip_hdr;
626 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
627 } subh;
628
629 __u8 *chunk_end;
630
631 struct sctp_chunkhdr *chunk_hdr;
632 struct sctphdr *sctp_hdr;
633
634 /* This needs to be recoverable for SCTP_SEND_FAILED events. */
635 struct sctp_sndrcvinfo sinfo;
636
637 /* Which association does this belong to? */
638 struct sctp_association *asoc;
639
640 /* What endpoint received this chunk? */
641 struct sctp_ep_common *rcvr;
642
643 /* We fill this in if we are calculating RTT. */
644 unsigned long sent_at;
645
646 /* What is the origin IP address for this chunk? */
647 union sctp_addr source;
648 /* Destination address for this chunk. */
649 union sctp_addr dest;
650
651 /* For outbound message, track all fragments for SEND_FAILED. */
652 struct sctp_datamsg *msg;
653
654 /* For an inbound chunk, this tells us where it came from.
655 * For an outbound chunk, it tells us where we'd like it to
656 * go. It is NULL if we have no preference.
657 */
658 struct sctp_transport *transport;
659
660 __u8 rtt_in_progress; /* Is this chunk used for RTT calculation? */
661 __u8 resent; /* Has this chunk ever been retransmitted. */
662 __u8 has_tsn; /* Does this chunk have a TSN yet? */
663 __u8 has_ssn; /* Does this chunk have a SSN yet? */
664 __u8 singleton; /* Was this the only chunk in the packet? */
665 __u8 end_of_packet; /* Was this the last chunk in the packet? */
666 __u8 ecn_ce_done; /* Have we processed the ECN CE bit? */
667 __u8 pdiscard; /* Discard the whole packet now? */
668 __u8 tsn_gap_acked; /* Is this chunk acked by a GAP ACK? */
669 __u8 fast_retransmit; /* Is this chunk fast retransmitted? */
670 __u8 tsn_missing_report; /* Data chunk missing counter. */
671};
672
673void sctp_chunk_hold(struct sctp_chunk *);
674void sctp_chunk_put(struct sctp_chunk *);
675int sctp_user_addto_chunk(struct sctp_chunk *chunk, int off, int len,
676 struct iovec *data);
677void sctp_chunk_free(struct sctp_chunk *);
678void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data);
679struct sctp_chunk *sctp_chunkify(struct sk_buff *,
680 const struct sctp_association *,
681 struct sock *);
682void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
683 union sctp_addr *);
684const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);
685
686/* This is a structure for holding either an IPv6 or an IPv4 address. */
687/* sin_family -- AF_INET or AF_INET6
688 * sin_port -- ordinary port number
689 * sin_addr -- cast to either (struct in_addr) or (struct in6_addr)
690 */
691struct sctp_sockaddr_entry {
692 struct list_head list;
693 union sctp_addr a;
694};
695
696typedef struct sctp_chunk *(sctp_packet_phandler_t)(struct sctp_association *);
697
698/* This structure holds lists of chunks as we are assembling for
699 * transmission.
700 */
701struct sctp_packet {
702 /* These are the SCTP header values (host order) for the packet. */
703 __u16 source_port;
704 __u16 destination_port;
705 __u32 vtag;
706
707 /* This contains the payload chunks. */
708 struct sk_buff_head chunks;
709
710 /* This is the overhead of the sctp and ip headers. */
711 size_t overhead;
712 /* This is the total size of all chunks INCLUDING padding. */
713 size_t size;
714
715 /* The packet is destined for this transport address.
716 * The function we finally use to pass down to the next lower
717 * layer lives in the transport structure.
718 */
719 struct sctp_transport *transport;
720
721 /* This packet contains a COOKIE-ECHO chunk. */
722 char has_cookie_echo;
723
724 /* This packet containsa SACK chunk. */
725 char has_sack;
726
727 /* SCTP cannot fragment this packet. So let ip fragment it. */
728 char ipfragok;
729
730 int malloced;
731};
732
733struct sctp_packet *sctp_packet_init(struct sctp_packet *,
734 struct sctp_transport *,
735 __u16 sport, __u16 dport);
736struct sctp_packet *sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
737sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *,
738 struct sctp_chunk *);
739sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *,
740 struct sctp_chunk *);
741int sctp_packet_transmit(struct sctp_packet *);
742void sctp_packet_free(struct sctp_packet *);
743
744static inline int sctp_packet_empty(struct sctp_packet *packet)
745{
746 return (packet->size == packet->overhead);
747}
748
749/* This represents a remote transport address.
750 * For local transport addresses, we just use union sctp_addr.
751 *
752 * RFC2960 Section 1.4 Key Terms
753 *
754 * o Transport address: A Transport Address is traditionally defined
755 * by Network Layer address, Transport Layer protocol and Transport
756 * Layer port number. In the case of SCTP running over IP, a
757 * transport address is defined by the combination of an IP address
758 * and an SCTP port number (where SCTP is the Transport protocol).
759 *
760 * RFC2960 Section 7.1 SCTP Differences from TCP Congestion control
761 *
762 * o The sender keeps a separate congestion control parameter set for
763 * each of the destination addresses it can send to (not each
764 * source-destination pair but for each destination). The parameters
765 * should decay if the address is not used for a long enough time
766 * period.
767 *
768 */
769struct sctp_transport {
770 /* A list of transports. */
771 struct list_head transports;
772
773 /* Reference counting. */
774 atomic_t refcnt;
775 int dead;
776
777 /* This is the peer's IP address and port. */
778 union sctp_addr ipaddr;
779
780 /* These are the functions we call to handle LLP stuff. */
781 struct sctp_af *af_specific;
782
783 /* Which association do we belong to? */
784 struct sctp_association *asoc;
785
786 /* RFC2960
787 *
788 * 12.3 Per Transport Address Data
789 *
790 * For each destination transport address in the peer's
791 * address list derived from the INIT or INIT ACK chunk, a
792 * number of data elements needs to be maintained including:
793 */
794 __u32 rtt; /* This is the most recent RTT. */
795
796 /* RTO : The current retransmission timeout value. */
797 __u32 rto;
798
799 /* RTTVAR : The current RTT variation. */
800 __u32 rttvar;
801
802 /* SRTT : The current smoothed round trip time. */
803 __u32 srtt;
804
805 /* RTO-Pending : A flag used to track if one of the DATA
806 * chunks sent to this address is currently being
807 * used to compute a RTT. If this flag is 0,
808 * the next DATA chunk sent to this destination
809 * should be used to compute a RTT and this flag
810 * should be set. Every time the RTT
811 * calculation completes (i.e. the DATA chunk
812 * is SACK'd) clear this flag.
813 */
814 int rto_pending;
815
816 /*
817 * These are the congestion stats.
818 */
819 /* cwnd : The current congestion window. */
820 __u32 cwnd; /* This is the actual cwnd. */
821
822 /* ssthresh : The current slow start threshold value. */
823 __u32 ssthresh;
824
825 /* partial : The tracking method for increase of cwnd when in
826 * bytes acked : congestion avoidance mode (see Section 6.2.2)
827 */
828 __u32 partial_bytes_acked;
829
830 /* Data that has been sent, but not acknowledged. */
831 __u32 flight_size;
832
833 /* PMTU : The current known path MTU. */
834 __u32 pmtu;
835
836 /* Destination */
837 struct dst_entry *dst;
838 /* Source address. */
839 union sctp_addr saddr;
840
841 /* When was the last time(in jiffies) that a data packet was sent on
842 * this transport? This is used to adjust the cwnd when the transport
843 * becomes inactive.
844 */
845 unsigned long last_time_used;
846
847 /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
848 * the destination address every heartbeat interval.
849 */
850 int hb_interval;
851
852 /* When was the last time (in jiffies) that we heard from this
853 * transport? We use this to pick new active and retran paths.
854 */
855 unsigned long last_time_heard;
856
857 /* Last time(in jiffies) when cwnd is reduced due to the congestion
858 * indication based on ECNE chunk.
859 */
860 unsigned long last_time_ecne_reduced;
861
862 /* active : The current active state of this destination,
863 * : i.e. DOWN, UP, etc.
864 */
865 int active;
866
867 /* hb_allowed : The current heartbeat state of this destination,
868 * : i.e. ALLOW-HB, NO-HEARTBEAT, etc.
869 */
870 int hb_allowed;
871
872 /* These are the error stats for this destination. */
873
874 /* Error count : The current error count for this destination. */
875 unsigned short error_count;
876
877 /* This is the max_retrans value for the transport and will
878 * be initialized to proto.max_retrans.path. This can be changed
879 * using SCTP_SET_PEER_ADDR_PARAMS socket option.
880 */
881 int max_retrans;
882
883 /* Per : A timer used by each destination.
884 * Destination :
885 * Timer :
886 *
887 * [Everywhere else in the text this is called T3-rtx. -ed]
888 */
889 struct timer_list T3_rtx_timer;
890
891 /* Heartbeat timer is per destination. */
892 struct timer_list hb_timer;
893
894 /* Since we're using per-destination retransmission timers
895 * (see above), we're also using per-destination "transmitted"
896 * queues. This probably ought to be a private struct
897 * accessible only within the outqueue, but it's not, yet.
898 */
899 struct list_head transmitted;
900
901 /* We build bundle-able packets for this transport here. */
902 struct sctp_packet packet;
903
904 /* This is the list of transports that have chunks to send. */
905 struct list_head send_ready;
906
907 int malloced; /* Is this structure kfree()able? */
908
909 /* State information saved for SFR_CACC algorithm. The key
910 * idea in SFR_CACC is to maintain state at the sender on a
911 * per-destination basis when a changeover happens.
912 * char changeover_active;
913 * char cycling_changeover;
914 * __u32 next_tsn_at_change;
915 * char cacc_saw_newack;
916 */
917 struct {
918 /* An unsigned integer, which stores the next TSN to be
919 * used by the sender, at the moment of changeover.
920 */
921 __u32 next_tsn_at_change;
922
923 /* A flag which indicates the occurrence of a changeover */
924 char changeover_active;
925
926 /* A flag which indicates whether the change of primary is
927 * the first switch to this destination address during an
928 * active switch.
929 */
930 char cycling_changeover;
931
932 /* A temporary flag, which is used during the processing of
933 * a SACK to estimate the causative TSN(s)'s group.
934 */
935 char cacc_saw_newack;
936 } cacc;
937};
938
939struct sctp_transport *sctp_transport_new(const union sctp_addr *, int);
940void sctp_transport_set_owner(struct sctp_transport *,
941 struct sctp_association *);
942void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
943 struct sctp_sock *);
944void sctp_transport_pmtu(struct sctp_transport *);
945void sctp_transport_free(struct sctp_transport *);
946void sctp_transport_reset_timers(struct sctp_transport *);
947void sctp_transport_hold(struct sctp_transport *);
948void sctp_transport_put(struct sctp_transport *);
949void sctp_transport_update_rto(struct sctp_transport *, __u32);
950void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32);
951void sctp_transport_lower_cwnd(struct sctp_transport *, sctp_lower_cwnd_t);
952unsigned long sctp_transport_timeout(struct sctp_transport *);
953
954
955/* This is the structure we use to queue packets as they come into
956 * SCTP. We write packets to it and read chunks from it.
957 */
958struct sctp_inq {
959 /* This is actually a queue of sctp_chunk each
960 * containing a partially decoded packet.
961 */
962 struct sk_buff_head in;
963 /* This is the packet which is currently off the in queue and is
964 * being worked on through the inbound chunk processing.
965 */
966 struct sctp_chunk *in_progress;
967
968 /* This is the delayed task to finish delivering inbound
969 * messages.
970 */
971 struct work_struct immediate;
972
973 int malloced; /* Is this structure kfree()able? */
974};
975
976void sctp_inq_init(struct sctp_inq *);
977void sctp_inq_free(struct sctp_inq *);
978void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet);
979struct sctp_chunk *sctp_inq_pop(struct sctp_inq *);
980void sctp_inq_set_th_handler(struct sctp_inq *, void (*)(void *), void *);
981
982/* This is the structure we use to hold outbound chunks. You push
983 * chunks in and they automatically pop out the other end as bundled
984 * packets (it calls (*output_handler)()).
985 *
986 * This structure covers sections 6.3, 6.4, 6.7, 6.8, 6.10, 7., 8.1,
987 * and 8.2 of the v13 draft.
988 *
989 * It handles retransmissions. The connection to the timeout portion
990 * of the state machine is through sctp_..._timeout() and timeout_handler.
991 *
992 * If you feed it SACKs, it will eat them.
993 *
994 * If you give it big chunks, it will fragment them.
995 *
996 * It assigns TSN's to data chunks. This happens at the last possible
997 * instant before transmission.
998 *
999 * When free()'d, it empties itself out via output_handler().
1000 */
1001struct sctp_outq {
1002 struct sctp_association *asoc;
1003
1004 /* Data pending that has never been transmitted. */
1005 struct sk_buff_head out;
1006
1007 unsigned out_qlen; /* Total length of queued data chunks. */
1008
1009 /* Error of send failed, may used in SCTP_SEND_FAILED event. */
1010 unsigned error;
1011
1012 /* These are control chunks we want to send. */
1013 struct sk_buff_head control;
1014
1015 /* These are chunks that have been sacked but are above the
1016 * CTSN, or cumulative tsn ack point.
1017 */
1018 struct list_head sacked;
1019
1020 /* Put chunks on this list to schedule them for
1021 * retransmission.
1022 */
1023 struct list_head retransmit;
1024
1025 /* Put chunks on this list to save them for FWD TSN processing as
1026 * they were abandoned.
1027 */
1028 struct list_head abandoned;
1029
1030 /* How many unackd bytes do we have in-flight? */
1031 __u32 outstanding_bytes;
1032
1033 /* Corked? */
1034 char cork;
1035
1036 /* Is this structure empty? */
1037 char empty;
1038
1039 /* Are we kfree()able? */
1040 char malloced;
1041};
1042
1043void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
1044void sctp_outq_teardown(struct sctp_outq *);
1045void sctp_outq_free(struct sctp_outq*);
1046int sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk);
1047int sctp_outq_flush(struct sctp_outq *, int);
1048int sctp_outq_sack(struct sctp_outq *, struct sctp_sackhdr *);
1049int sctp_outq_is_empty(const struct sctp_outq *);
1050void sctp_outq_restart(struct sctp_outq *);
1051
1052void sctp_retransmit(struct sctp_outq *, struct sctp_transport *,
1053 sctp_retransmit_reason_t);
1054void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
1055int sctp_outq_uncork(struct sctp_outq *);
1056/* Uncork and flush an outqueue. */
1057static inline void sctp_outq_cork(struct sctp_outq *q)
1058{
1059 q->cork = 1;
1060}
1061
1062/* These bind address data fields common between endpoints and associations */
1063struct sctp_bind_addr {
1064
1065 /* RFC 2960 12.1 Parameters necessary for the SCTP instance
1066 *
1067 * SCTP Port: The local SCTP port number the endpoint is
1068 * bound to.
1069 */
1070 __u16 port;
1071
1072 /* RFC 2960 12.1 Parameters necessary for the SCTP instance
1073 *
1074 * Address List: The list of IP addresses that this instance
1075 * has bound. This information is passed to one's
1076 * peer(s) in INIT and INIT ACK chunks.
1077 */
1078 struct list_head address_list;
1079
1080 int malloced; /* Are we kfree()able? */
1081};
1082
1083void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
1084void sctp_bind_addr_free(struct sctp_bind_addr *);
1085int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
1086 const struct sctp_bind_addr *src,
1087 sctp_scope_t scope, int gfp,int flags);
1088int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
1089 int gfp);
1090int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
1091int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *,
1092 struct sctp_sock *);
1093union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
1094 const union sctp_addr *addrs,
1095 int addrcnt,
1096 struct sctp_sock *opt);
1097union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
1098 int *addrs_len, int gfp);
1099int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
1100 __u16 port, int gfp);
1101
1102sctp_scope_t sctp_scope(const union sctp_addr *);
1103int sctp_in_scope(const union sctp_addr *addr, const sctp_scope_t scope);
1104int sctp_is_any(const union sctp_addr *addr);
1105int sctp_addr_is_valid(const union sctp_addr *addr);
1106
1107
1108/* What type of endpoint? */
1109typedef enum {
1110 SCTP_EP_TYPE_SOCKET,
1111 SCTP_EP_TYPE_ASSOCIATION,
1112} sctp_endpoint_type_t;
1113
1114/*
1115 * A common base class to bridge the implmentation view of a
1116 * socket (usually listening) endpoint versus an association's
1117 * local endpoint.
1118 * This common structure is useful for several purposes:
1119 * 1) Common interface for lookup routines.
1120 * a) Subfunctions work for either endpoint or association
1121 * b) Single interface to lookup allows hiding the lookup lock rather
1122 * than acquiring it externally.
1123 * 2) Common interface for the inbound chunk handling/state machine.
1124 * 3) Common object handling routines for reference counting, etc.
1125 * 4) Disentangle association lookup from endpoint lookup, where we
1126 * do not have to find our endpoint to find our association.
1127 *
1128 */
1129
1130struct sctp_ep_common {
1131 /* Fields to help us manage our entries in the hash tables. */
1132 struct sctp_ep_common *next;
1133 struct sctp_ep_common **pprev;
1134 int hashent;
1135
1136 /* Runtime type information. What kind of endpoint is this? */
1137 sctp_endpoint_type_t type;
1138
1139 /* Some fields to help us manage this object.
1140 * refcnt - Reference count access to this object.
1141 * dead - Do not attempt to use this object.
1142 * malloced - Do we need to kfree this object?
1143 */
1144 atomic_t refcnt;
1145 char dead;
1146 char malloced;
1147
1148 /* What socket does this endpoint belong to? */
1149 struct sock *sk;
1150
1151 /* This is where we receive inbound chunks. */
1152 struct sctp_inq inqueue;
1153
1154 /* This substructure includes the defining parameters of the
1155 * endpoint:
1156 * bind_addr.port is our shared port number.
1157 * bind_addr.address_list is our set of local IP addresses.
1158 */
1159 struct sctp_bind_addr bind_addr;
1160
1161 /* Protection during address list comparisons. */
1162 rwlock_t addr_lock;
1163};
1164
1165
1166/* RFC Section 1.4 Key Terms
1167 *
1168 * o SCTP endpoint: The logical sender/receiver of SCTP packets. On a
1169 * multi-homed host, an SCTP endpoint is represented to its peers as a
1170 * combination of a set of eligible destination transport addresses to
1171 * which SCTP packets can be sent and a set of eligible source
1172 * transport addresses from which SCTP packets can be received.
1173 * All transport addresses used by an SCTP endpoint must use the
1174 * same port number, but can use multiple IP addresses. A transport
1175 * address used by an SCTP endpoint must not be used by another
1176 * SCTP endpoint. In other words, a transport address is unique
1177 * to an SCTP endpoint.
1178 *
1179 * From an implementation perspective, each socket has one of these.
1180 * A TCP-style socket will have exactly one association on one of
1181 * these. An UDP-style socket will have multiple associations hanging
1182 * off one of these.
1183 */
1184
1185struct sctp_endpoint {
1186 /* Common substructure for endpoint and association. */
1187 struct sctp_ep_common base;
1188
1189 /* Associations: A list of current associations and mappings
1190 * to the data consumers for each association. This
1191 * may be in the form of a hash table or other
1192 * implementation dependent structure. The data
1193 * consumers may be process identification
1194 * information such as file descriptors, named pipe
1195 * pointer, or table pointers dependent on how SCTP
1196 * is implemented.
1197 */
1198 /* This is really a list of struct sctp_association entries. */
1199 struct list_head asocs;
1200
1201 /* Secret Key: A secret key used by this endpoint to compute
1202 * the MAC. This SHOULD be a cryptographic quality
1203 * random number with a sufficient length.
1204 * Discussion in [RFC1750] can be helpful in
1205 * selection of the key.
1206 */
1207 __u8 secret_key[SCTP_HOW_MANY_SECRETS][SCTP_SECRET_SIZE];
1208 int current_key;
1209 int last_key;
1210 int key_changed_at;
1211
1212 /* Default timeouts. */
1213 int timeouts[SCTP_NUM_TIMEOUT_TYPES];
1214
1215 /* Various thresholds. */
1216
1217 /* Name for debugging output... */
1218 char *debug_name;
1219};
1220
1221/* Recover the outter endpoint structure. */
1222static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base)
1223{
1224 struct sctp_endpoint *ep;
1225
1226 ep = container_of(base, struct sctp_endpoint, base);
1227 return ep;
1228}
1229
1230/* These are function signatures for manipulating endpoints. */
1231struct sctp_endpoint *sctp_endpoint_new(struct sock *, int);
1232void sctp_endpoint_free(struct sctp_endpoint *);
1233void sctp_endpoint_put(struct sctp_endpoint *);
1234void sctp_endpoint_hold(struct sctp_endpoint *);
1235void sctp_endpoint_add_asoc(struct sctp_endpoint *, struct sctp_association *);
1236struct sctp_association *sctp_endpoint_lookup_assoc(
1237 const struct sctp_endpoint *ep,
1238 const union sctp_addr *paddr,
1239 struct sctp_transport **);
1240int sctp_endpoint_is_peeled_off(struct sctp_endpoint *,
1241 const union sctp_addr *);
1242struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *,
1243 const union sctp_addr *);
1244int sctp_has_association(const union sctp_addr *laddr,
1245 const union sctp_addr *paddr);
1246
1247int sctp_verify_init(const struct sctp_association *asoc, sctp_cid_t,
1248 sctp_init_chunk_t *peer_init, struct sctp_chunk *chunk,
1249 struct sctp_chunk **err_chunk);
1250int sctp_process_init(struct sctp_association *, sctp_cid_t cid,
1251 const union sctp_addr *peer,
1252 sctp_init_chunk_t *init, int gfp);
1253__u32 sctp_generate_tag(const struct sctp_endpoint *);
1254__u32 sctp_generate_tsn(const struct sctp_endpoint *);
1255
1256
1257/* RFC2960
1258 *
1259 * 12. Recommended Transmission Control Block (TCB) Parameters
1260 *
1261 * This section details a recommended set of parameters that should
1262 * be contained within the TCB for an implementation. This section is
1263 * for illustrative purposes and should not be deemed as requirements
1264 * on an implementation or as an exhaustive list of all parameters
1265 * inside an SCTP TCB. Each implementation may need its own additional
1266 * parameters for optimization.
1267 */
1268
1269
1270/* Here we have information about each individual association. */
1271struct sctp_association {
1272
1273 /* A base structure common to endpoint and association.
1274 * In this context, it represents the associations's view
1275 * of the local endpoint of the association.
1276 */
1277 struct sctp_ep_common base;
1278
1279 /* Associations on the same socket. */
1280 struct list_head asocs;
1281
1282 /* association id. */
1283 sctp_assoc_t assoc_id;
1284
1285 /* This is our parent endpoint. */
1286 struct sctp_endpoint *ep;
1287
1288 /* These are those association elements needed in the cookie. */
1289 struct sctp_cookie c;
1290
1291 /* This is all information about our peer. */
1292 struct {
1293 /* rwnd
1294 *
1295 * Peer Rwnd : Current calculated value of the peer's rwnd.
1296 */
1297 __u32 rwnd;
1298
1299 /* transport_addr_list
1300 *
1301 * Peer : A list of SCTP transport addresses that the
1302 * Transport : peer is bound to. This information is derived
1303 * Address : from the INIT or INIT ACK and is used to
1304 * List : associate an inbound packet with a given
1305 * : association. Normally this information is
1306 * : hashed or keyed for quick lookup and access
1307 * : of the TCB.
1308 *
1309 * It is a list of SCTP_transport's.
1310 */
1311 struct list_head transport_addr_list;
1312
1313 /* port
1314 * The transport layer port number.
1315 */
1316 __u16 port;
1317
1318 /* primary_path
1319 *
1320 * Primary : This is the current primary destination
1321 * Path : transport address of the peer endpoint. It
1322 * : may also specify a source transport address
1323 * : on this endpoint.
1324 *
1325 * All of these paths live on transport_addr_list.
1326 *
1327 * At the bakeoffs, we discovered that the intent of
1328 * primaryPath is that it only changes when the ULP
1329 * asks to have it changed. We add the activePath to
1330 * designate the connection we are currently using to
1331 * transmit new data and most control chunks.
1332 */
1333 struct sctp_transport *primary_path;
1334
1335 /* Cache the primary path address here, when we
1336 * need a an address for msg_name.
1337 */
1338 union sctp_addr primary_addr;
1339
1340 /* active_path
1341 * The path that we are currently using to
1342 * transmit new data and most control chunks.
1343 */
1344 struct sctp_transport *active_path;
1345
1346 /* retran_path
1347 *
1348 * RFC2960 6.4 Multi-homed SCTP Endpoints
1349 * ...
1350 * Furthermore, when its peer is multi-homed, an
1351 * endpoint SHOULD try to retransmit a chunk to an
1352 * active destination transport address that is
1353 * different from the last destination address to
1354 * which the DATA chunk was sent.
1355 */
1356 struct sctp_transport *retran_path;
1357
1358 /* Pointer to last transport I have sent on. */
1359 struct sctp_transport *last_sent_to;
1360
1361 /* This is the last transport I have received DATA on. */
1362 struct sctp_transport *last_data_from;
1363
1364 /*
1365 * Mapping An array of bits or bytes indicating which out of
1366 * Array order TSN's have been received (relative to the
1367 * Last Rcvd TSN). If no gaps exist, i.e. no out of
1368 * order packets have been received, this array
1369 * will be set to all zero. This structure may be
1370 * in the form of a circular buffer or bit array.
1371 *
1372 * Last Rcvd : This is the last TSN received in
1373 * TSN : sequence. This value is set initially by
1374 * : taking the peer's Initial TSN, received in
1375 * : the INIT or INIT ACK chunk, and subtracting
1376 * : one from it.
1377 *
1378 * Throughout most of the specification this is called the
1379 * "Cumulative TSN ACK Point". In this case, we
1380 * ignore the advice in 12.2 in favour of the term
1381 * used in the bulk of the text. This value is hidden
1382 * in tsn_map--we get it by calling sctp_tsnmap_get_ctsn().
1383 */
1384 struct sctp_tsnmap tsn_map;
1385 __u8 _map[sctp_tsnmap_storage_size(SCTP_TSN_MAP_SIZE)];
1386
1387 /* Ack State : This flag indicates if the next received
1388 * : packet is to be responded to with a
1389 * : SACK. This is initializedto 0. When a packet
1390 * : is received it is incremented. If this value
1391 * : reaches 2 or more, a SACK is sent and the
1392 * : value is reset to 0. Note: This is used only
1393 * : when no DATA chunks are received out of
1394 * : order. When DATA chunks are out of order,
1395 * : SACK's are not delayed (see Section 6).
1396 */
1397 __u8 sack_needed; /* Do we need to sack the peer? */
1398
1399 /* These are capabilities which our peer advertised. */
1400 __u8 ecn_capable; /* Can peer do ECN? */
1401 __u8 ipv4_address; /* Peer understands IPv4 addresses? */
1402 __u8 ipv6_address; /* Peer understands IPv6 addresses? */
1403 __u8 hostname_address;/* Peer understands DNS addresses? */
1404 __u8 asconf_capable; /* Does peer support ADDIP? */
1405 __u8 prsctp_capable; /* Can peer do PR-SCTP? */
1406
1407 __u32 adaption_ind; /* Adaption Code point. */
1408
1409 /* This mask is used to disable sending the ASCONF chunk
1410 * with specified parameter to peer.
1411 */
1412 __u16 addip_disabled_mask;
1413
1414 struct sctp_inithdr i;
1415 int cookie_len;
1416 void *cookie;
1417
1418 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
1419 * C1) ... "Peer-Serial-Number'. This value MUST be initialized to the
1420 * Initial TSN Value minus 1
1421 */
1422 __u32 addip_serial;
1423 } peer;
1424
1425 /* State : A state variable indicating what state the
1426 * : association is in, i.e. COOKIE-WAIT,
1427 * : COOKIE-ECHOED, ESTABLISHED, SHUTDOWN-PENDING,
1428 * : SHUTDOWN-SENT, SHUTDOWN-RECEIVED, SHUTDOWN-ACK-SENT.
1429 *
1430 * Note: No "CLOSED" state is illustrated since if a
1431 * association is "CLOSED" its TCB SHOULD be removed.
1432 *
1433 * In this implementation we DO have a CLOSED
1434 * state which is used during initiation and shutdown.
1435 *
1436 * State takes values from SCTP_STATE_*.
1437 */
1438 sctp_state_t state;
1439
1440 /* The cookie life I award for any cookie. */
1441 struct timeval cookie_life;
1442
1443 /* Overall : The overall association error count.
1444 * Error Count : [Clear this any time I get something.]
1445 */
1446 int overall_error_count;
1447
1448 /* These are the association's initial, max, and min RTO values.
1449 * These values will be initialized by system defaults, but can
1450 * be modified via the SCTP_RTOINFO socket option.
1451 */
1452 __u32 rto_initial;
1453 __u32 rto_max;
1454 __u32 rto_min;
1455
1456 /* Maximum number of new data packets that can be sent in a burst. */
1457 int max_burst;
1458
1459 /* This is the max_retrans value for the association. This value will
1460 * be initialized initialized from system defaults, but can be
1461 * modified by the SCTP_ASSOCINFO socket option.
1462 */
1463 int max_retrans;
1464
1465 /* Maximum number of times the endpoint will retransmit INIT */
1466 __u16 max_init_attempts;
1467
1468 /* How many times have we resent an INIT? */
1469 __u16 init_retries;
1470
1471 /* The largest timeout or RTO value to use in attempting an INIT */
1472 __u16 max_init_timeo;
1473
1474 int timeouts[SCTP_NUM_TIMEOUT_TYPES];
1475 struct timer_list timers[SCTP_NUM_TIMEOUT_TYPES];
1476
1477 /* Transport to which SHUTDOWN chunk was last sent. */
1478 struct sctp_transport *shutdown_last_sent_to;
1479
1480 /* Next TSN : The next TSN number to be assigned to a new
1481 * : DATA chunk. This is sent in the INIT or INIT
1482 * : ACK chunk to the peer and incremented each
1483 * : time a DATA chunk is assigned a TSN
1484 * : (normally just prior to transmit or during
1485 * : fragmentation).
1486 */
1487 __u32 next_tsn;
1488
1489 /*
1490 * Last Rcvd : This is the last TSN received in sequence. This value
1491 * TSN : is set initially by taking the peer's Initial TSN,
1492 * : received in the INIT or INIT ACK chunk, and
1493 * : subtracting one from it.
1494 *
1495 * Most of RFC 2960 refers to this as the Cumulative TSN Ack Point.
1496 */
1497
1498 __u32 ctsn_ack_point;
1499
1500 /* PR-SCTP Advanced.Peer.Ack.Point */
1501 __u32 adv_peer_ack_point;
1502
1503 /* Highest TSN that is acknowledged by incoming SACKs. */
1504 __u32 highest_sacked;
1505
1506 /* The number of unacknowledged data chunks. Reported through
1507 * the SCTP_STATUS sockopt.
1508 */
1509 __u16 unack_data;
1510
1511 /* This is the association's receive buffer space. This value is used
1512 * to set a_rwnd field in an INIT or a SACK chunk.
1513 */
1514 __u32 rwnd;
1515
1516 /* This is the last advertised value of rwnd over a SACK chunk. */
1517 __u32 a_rwnd;
1518
1519 /* Number of bytes by which the rwnd has slopped. The rwnd is allowed
1520 * to slop over a maximum of the association's frag_point.
1521 */
1522 __u32 rwnd_over;
1523
1524 /* This is the sndbuf size in use for the association.
1525 * This corresponds to the sndbuf size for the association,
1526 * as specified in the sk->sndbuf.
1527 */
1528 int sndbuf_used;
1529
1530 /* This is the wait queue head for send requests waiting on
1531 * the association sndbuf space.
1532 */
1533 wait_queue_head_t wait;
1534
1535 /* Association : The smallest PMTU discovered for all of the
1536 * PMTU : peer's transport addresses.
1537 */
1538 __u32 pmtu;
1539
1540 /* The message size at which SCTP fragmentation will occur. */
1541 __u32 frag_point;
1542
1543 /* Currently only one counter is used to count INIT errors. */
1544 int counters[SCTP_NUMBER_COUNTERS];
1545
1546 /* Default send parameters. */
1547 __u16 default_stream;
1548 __u16 default_flags;
1549 __u32 default_ppid;
1550 __u32 default_context;
1551 __u32 default_timetolive;
1552
1553 /* This tracks outbound ssn for a given stream. */
1554 struct sctp_ssnmap *ssnmap;
1555
1556 /* All outbound chunks go through this structure. */
1557 struct sctp_outq outqueue;
1558
1559 /* A smart pipe that will handle reordering and fragmentation,
1560 * as well as handle passing events up to the ULP.
1561 */
1562 struct sctp_ulpq ulpq;
1563
1564 /* Last TSN that caused an ECNE Chunk to be sent. */
1565 __u32 last_ecne_tsn;
1566
1567 /* Last TSN that caused a CWR Chunk to be sent. */
1568 __u32 last_cwr_tsn;
1569
1570 /* How many duplicated TSNs have we seen? */
1571 int numduptsns;
1572
1573 /* Number of seconds of idle time before an association is closed. */
1574 __u32 autoclose;
1575
1576 /* These are to support
1577 * "SCTP Extensions for Dynamic Reconfiguration of IP Addresses
1578 * and Enforcement of Flow and Message Limits"
1579 * <draft-ietf-tsvwg-addip-sctp-02.txt>
1580 * or "ADDIP" for short.
1581 */
1582
1583
1584
1585 /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
1586 *
1587 * R1) One and only one ASCONF Chunk MAY be in transit and
1588 * unacknowledged at any one time. If a sender, after sending
1589 * an ASCONF chunk, decides it needs to transfer another
1590 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
1591 * returns from the previous ASCONF Chunk before sending a
1592 * subsequent ASCONF. Note this restriction binds each side,
1593 * so at any time two ASCONF may be in-transit on any given
1594 * association (one sent from each endpoint).
1595 *
1596 * [This is our one-and-only-one ASCONF in flight. If we do
1597 * not have an ASCONF in flight, this is NULL.]
1598 */
1599 struct sctp_chunk *addip_last_asconf;
1600
1601 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
1602 *
1603 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
1604 * to save the last ASCONF-ACK for some predetermined period
1605 * of time and instead of re-processing the ASCONF (with the
1606 * same serial number) it may just re-transmit the
1607 * ASCONF-ACK. It may wish to use the arrival of a new serial
1608 * number to discard the previously saved ASCONF-ACK or any
1609 * other means it may choose to expire the saved ASCONF-ACK.
1610 *
1611 * [This is our saved ASCONF-ACK. We invalidate it when a new
1612 * ASCONF serial number arrives.]
1613 */
1614 struct sctp_chunk *addip_last_asconf_ack;
1615
1616 /* These ASCONF chunks are waiting to be sent.
1617 *
1618 * These chunaks can't be pushed to outqueue until receiving
1619 * ASCONF_ACK for the previous ASCONF indicated by
1620 * addip_last_asconf, so as to guarantee that only one ASCONF
1621 * is in flight at any time.
1622 *
1623 * ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
1624 *
1625 * In defining the ASCONF Chunk transfer procedures, it is
1626 * essential that these transfers MUST NOT cause congestion
1627 * within the network. To achieve this, we place these
1628 * restrictions on the transfer of ASCONF Chunks:
1629 *
1630 * R1) One and only one ASCONF Chunk MAY be in transit and
1631 * unacknowledged at any one time. If a sender, after sending
1632 * an ASCONF chunk, decides it needs to transfer another
1633 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
1634 * returns from the previous ASCONF Chunk before sending a
1635 * subsequent ASCONF. Note this restriction binds each side,
1636 * so at any time two ASCONF may be in-transit on any given
1637 * association (one sent from each endpoint).
1638 *
1639 *
1640 * [I really think this is EXACTLY the sort of intelligence
1641 * which already resides in sctp_outq. Please move this
1642 * queue and its supporting logic down there. --piggy]
1643 */
1644 struct sk_buff_head addip_chunks;
1645
1646 /* ADDIP Section 4.1 ASCONF Chunk Procedures
1647 *
1648 * A2) A serial number should be assigned to the Chunk. The
1649 * serial number SHOULD be a monotonically increasing
1650 * number. The serial number SHOULD be initialized at
1651 * the start of the association to the same value as the
1652 * Initial TSN and every time a new ASCONF chunk is created
1653 * it is incremented by one after assigning the serial number
1654 * to the newly created chunk.
1655 *
1656 * ADDIP
1657 * 3.1.1 Address/Stream Configuration Change Chunk (ASCONF)
1658 *
1659 * Serial Number : 32 bits (unsigned integer)
1660 *
1661 * This value represents a Serial Number for the ASCONF
1662 * Chunk. The valid range of Serial Number is from 0 to
1663 * 4294967295 (2^32 - 1). Serial Numbers wrap back to 0
1664 * after reaching 4294967295.
1665 */
1666 __u32 addip_serial;
1667
1668 /* Need to send an ECNE Chunk? */
1669 char need_ecne;
1670
1671 /* Is it a temporary association? */
1672 char temp;
1673};
1674
1675
1676/* An eyecatcher for determining if we are really looking at an
1677 * association data structure.
1678 */
1679enum {
1680 SCTP_ASSOC_EYECATCHER = 0xa550c123,
1681};
1682
1683/* Recover the outter association structure. */
1684static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base)
1685{
1686 struct sctp_association *asoc;
1687
1688 asoc = container_of(base, struct sctp_association, base);
1689 return asoc;
1690}
1691
1692/* These are function signatures for manipulating associations. */
1693
1694
1695struct sctp_association *
1696sctp_association_new(const struct sctp_endpoint *, const struct sock *,
1697 sctp_scope_t scope, int gfp);
1698void sctp_association_free(struct sctp_association *);
1699void sctp_association_put(struct sctp_association *);
1700void sctp_association_hold(struct sctp_association *);
1701
1702struct sctp_transport *sctp_assoc_choose_shutdown_transport(
1703 struct sctp_association *);
1704void sctp_assoc_update_retran_path(struct sctp_association *);
1705struct sctp_transport *sctp_assoc_lookup_paddr(const struct sctp_association *,
1706 const union sctp_addr *);
1707int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
1708 const union sctp_addr *laddr);
1709struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *,
1710 const union sctp_addr *address,
1711 const int gfp);
1712void sctp_assoc_del_peer(struct sctp_association *asoc,
1713 const union sctp_addr *addr);
1714void sctp_assoc_control_transport(struct sctp_association *,
1715 struct sctp_transport *,
1716 sctp_transport_cmd_t, sctp_sn_error_t);
1717struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32);
1718struct sctp_transport *sctp_assoc_is_match(struct sctp_association *,
1719 const union sctp_addr *,
1720 const union sctp_addr *);
1721void sctp_assoc_migrate(struct sctp_association *, struct sock *);
1722void sctp_assoc_update(struct sctp_association *old,
1723 struct sctp_association *new);
1724
1725__u32 sctp_association_get_next_tsn(struct sctp_association *);
1726
1727void sctp_assoc_sync_pmtu(struct sctp_association *);
1728void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned);
1729void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned);
1730void sctp_assoc_set_primary(struct sctp_association *,
1731 struct sctp_transport *);
1732int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *, int);
1733int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *,
1734 struct sctp_cookie*, int gfp);
1735
1736int sctp_cmp_addr_exact(const union sctp_addr *ss1,
1737 const union sctp_addr *ss2);
1738struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc);
1739
1740/* A convenience structure to parse out SCTP specific CMSGs. */
1741typedef struct sctp_cmsgs {
1742 struct sctp_initmsg *init;
1743 struct sctp_sndrcvinfo *info;
1744} sctp_cmsgs_t;
1745
1746/* Structure for tracking memory objects */
1747typedef struct {
1748 char *label;
1749 atomic_t *counter;
1750} sctp_dbg_objcnt_entry_t;
1751
1752#endif /* __sctp_structs_h__ */
diff --git a/include/net/sctp/tsnmap.h b/include/net/sctp/tsnmap.h
new file mode 100644
index 00000000000..021947da70e
--- /dev/null
+++ b/include/net/sctp/tsnmap.h
@@ -0,0 +1,207 @@
1/* SCTP kernel reference 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 reference Implementation
8 *
9 * These are the definitions needed for the tsnmap type. The tsnmap is used
10 * to track out of order TSNs received.
11 *
12 * The SCTP reference implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
16 * any later version.
17 *
18 * The SCTP reference implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
28 *
29 * Please send any bug reports or fixes you make to the
30 * email address(es):
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
32 *
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
35 *
36 * Written or modified by:
37 * Jon Grimm <jgrimm@us.ibm.com>
38 * La Monte H.P. Yarroll <piggy@acm.org>
39 * Karl Knutson <karl@athena.chicago.il.us>
40 * Sridhar Samudrala <sri@us.ibm.com>
41 *
42 * Any bugs reported given to us we will try to fix... any fixes shared will
43 * be incorporated into the next SCTP release.
44 */
45#include <net/sctp/constants.h>
46
47#ifndef __sctp_tsnmap_h__
48#define __sctp_tsnmap_h__
49
50/* RFC 2960 12.2 Parameters necessary per association (i.e. the TCB)
51 * Mapping An array of bits or bytes indicating which out of
52 * Array order TSN's have been received (relative to the
53 * Last Rcvd TSN). If no gaps exist, i.e. no out of
54 * order packets have been received, this array
55 * will be set to all zero. This structure may be
56 * in the form of a circular buffer or bit array.
57 */
58struct sctp_tsnmap {
59 /* This array counts the number of chunks with each TSN.
60 * It points at one of the two buffers with which we will
61 * ping-pong between.
62 */
63 __u8 *tsn_map;
64
65 /* This marks the tsn which overflows the tsn_map, when the
66 * cumulative ack point reaches this point we know we can switch
67 * maps (tsn_map and overflow_map swap).
68 */
69 __u32 overflow_tsn;
70
71 /* This is the overflow array for tsn_map.
72 * It points at one of the other ping-pong buffers.
73 */
74 __u8 *overflow_map;
75
76 /* This is the TSN at tsn_map[0]. */
77 __u32 base_tsn;
78
79 /* Last Rcvd : This is the last TSN received in
80 * TSN : sequence. This value is set initially by
81 * : taking the peer's Initial TSN, received in
82 * : the INIT or INIT ACK chunk, and subtracting
83 * : one from it.
84 *
85 * Throughout most of the specification this is called the
86 * "Cumulative TSN ACK Point". In this case, we
87 * ignore the advice in 12.2 in favour of the term
88 * used in the bulk of the text.
89 */
90 __u32 cumulative_tsn_ack_point;
91
92 /* This is the minimum number of TSNs we can track. This corresponds
93 * to the size of tsn_map. Note: the overflow_map allows us to
94 * potentially track more than this quantity.
95 */
96 __u16 len;
97
98 /* This is the highest TSN we've marked. */
99 __u32 max_tsn_seen;
100
101 /* Data chunks pending receipt. used by SCTP_STATUS sockopt */
102 __u16 pending_data;
103
104 /* Record duplicate TSNs here. We clear this after
105 * every SACK. Store up to SCTP_MAX_DUP_TSNS worth of
106 * information.
107 */
108 __u32 dup_tsns[SCTP_MAX_DUP_TSNS];
109 __u16 num_dup_tsns;
110
111 /* Record gap ack block information here. */
112 struct sctp_gap_ack_block gabs[SCTP_MAX_GABS];
113
114 int malloced;
115
116 __u8 raw_map[0];
117};
118
119struct sctp_tsnmap_iter {
120 __u32 start;
121};
122
123/* This macro assists in creation of external storage for variable length
124 * internal buffers. We double allocate so the overflow map works.
125 */
126#define sctp_tsnmap_storage_size(count) (sizeof(__u8) * (count) * 2)
127
128/* Initialize a block of memory as a tsnmap. */
129struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *, __u16 len,
130 __u32 initial_tsn);
131
132/* Test the tracking state of this TSN.
133 * Returns:
134 * 0 if the TSN has not yet been seen
135 * >0 if the TSN has been seen (duplicate)
136 * <0 if the TSN is invalid (too large to track)
137 */
138int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn);
139
140/* Mark this TSN as seen. */
141void sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn);
142
143/* Mark this TSN and all lower as seen. */
144void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn);
145
146/* Retrieve the Cumulative TSN ACK Point. */
147static inline __u32 sctp_tsnmap_get_ctsn(const struct sctp_tsnmap *map)
148{
149 return map->cumulative_tsn_ack_point;
150}
151
152/* Retrieve the highest TSN we've seen. */
153static inline __u32 sctp_tsnmap_get_max_tsn_seen(const struct sctp_tsnmap *map)
154{
155 return map->max_tsn_seen;
156}
157
158/* How many duplicate TSNs are stored? */
159static inline __u16 sctp_tsnmap_num_dups(struct sctp_tsnmap *map)
160{
161 return map->num_dup_tsns;
162}
163
164/* Return pointer to duplicate tsn array as needed by SACK. */
165static inline __u32 *sctp_tsnmap_get_dups(struct sctp_tsnmap *map)
166{
167 map->num_dup_tsns = 0;
168 return map->dup_tsns;
169}
170
171/* How many gap ack blocks do we have recorded? */
172__u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map);
173
174/* Refresh the count on pending data. */
175__u16 sctp_tsnmap_pending(struct sctp_tsnmap *map);
176
177/* Return pointer to gap ack blocks as needed by SACK. */
178static inline struct sctp_gap_ack_block *sctp_tsnmap_get_gabs(struct sctp_tsnmap *map)
179{
180 return map->gabs;
181}
182
183/* Is there a gap in the TSN map? */
184static inline int sctp_tsnmap_has_gap(const struct sctp_tsnmap *map)
185{
186 int has_gap;
187
188 has_gap = (map->cumulative_tsn_ack_point != map->max_tsn_seen);
189 return has_gap;
190}
191
192/* Mark a duplicate TSN. Note: limit the storage of duplicate TSN
193 * information.
194 */
195static inline void sctp_tsnmap_mark_dup(struct sctp_tsnmap *map, __u32 tsn)
196{
197 if (map->num_dup_tsns < SCTP_MAX_DUP_TSNS)
198 map->dup_tsns[map->num_dup_tsns++] = htonl(tsn);
199}
200
201/* Renege a TSN that was seen. */
202void sctp_tsnmap_renege(struct sctp_tsnmap *, __u32 tsn);
203
204/* Is there a gap in the TSN map? */
205int sctp_tsnmap_has_gap(const struct sctp_tsnmap *);
206
207#endif /* __sctp_tsnmap_h__ */
diff --git a/include/net/sctp/ulpevent.h b/include/net/sctp/ulpevent.h
new file mode 100644
index 00000000000..1019d83a580
--- /dev/null
+++ b/include/net/sctp/ulpevent.h
@@ -0,0 +1,162 @@
1/* SCTP kernel reference 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 * Copyright (c) 2001 Nokia, Inc.
7 * Copyright (c) 2001 La Monte H.P. Yarroll
8 *
9 * These are the definitions needed for the sctp_ulpevent type. The
10 * sctp_ulpevent type is used to carry information from the state machine
11 * upwards to the ULP.
12 *
13 * This file is part of the SCTP kernel reference Implementation
14 *
15 * The SCTP reference implementation is free software;
16 * you can redistribute it and/or modify it under the terms of
17 * the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * The SCTP reference implementation is distributed in the hope that it
22 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
23 * ************************
24 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 * See the GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with GNU CC; see the file COPYING. If not, write to
29 * the Free Software Foundation, 59 Temple Place - Suite 330,
30 * Boston, MA 02111-1307, USA.
31 *
32 * Please send any bug reports or fixes you make to the
33 * email address(es):
34 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 *
36 * Or submit a bug report through the following website:
37 * http://www.sf.net/projects/lksctp
38 *
39 * Written or modified by:
40 * Jon Grimm <jgrimm@us.ibm.com>
41 * La Monte H.P. Yarroll <piggy@acm.org>
42 * Karl Knutson <karl@athena.chicago.il.us>
43 * Sridhar Samudrala <sri@us.ibm.com>
44 *
45 * Any bugs reported given to us we will try to fix... any fixes shared will
46 * be incorporated into the next SCTP release.
47 */
48
49#ifndef __sctp_ulpevent_h__
50#define __sctp_ulpevent_h__
51
52/* A structure to carry information to the ULP (e.g. Sockets API) */
53/* Warning: This sits inside an skb.cb[] area. Be very careful of
54 * growing this structure as it is at the maximum limit now.
55 */
56struct sctp_ulpevent {
57 struct sctp_association *asoc;
58 __u16 stream;
59 __u16 ssn;
60 __u16 flags;
61 __u32 ppid;
62 __u32 tsn;
63 __u32 cumtsn;
64 int msg_flags;
65 int iif;
66};
67
68/* Retrieve the skb this event sits inside of. */
69static inline struct sk_buff *sctp_event2skb(struct sctp_ulpevent *ev)
70{
71 return container_of((void *)ev, struct sk_buff, cb);
72}
73
74/* Retrieve & cast the event sitting inside the skb. */
75static inline struct sctp_ulpevent *sctp_skb2event(struct sk_buff *skb)
76{
77 return (struct sctp_ulpevent *)skb->cb;
78}
79
80void sctp_ulpevent_free(struct sctp_ulpevent *);
81int sctp_ulpevent_is_notification(const struct sctp_ulpevent *);
82void sctp_queue_purge_ulpevents(struct sk_buff_head *list);
83
84struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
85 const struct sctp_association *asoc,
86 __u16 flags,
87 __u16 state,
88 __u16 error,
89 __u16 outbound,
90 __u16 inbound,
91 int gfp);
92
93struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
94 const struct sctp_association *asoc,
95 const struct sockaddr_storage *aaddr,
96 int flags,
97 int state,
98 int error,
99 int gfp);
100
101struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
102 const struct sctp_association *asoc,
103 struct sctp_chunk *chunk,
104 __u16 flags,
105 int gfp);
106struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
107 const struct sctp_association *asoc,
108 struct sctp_chunk *chunk,
109 __u16 flags,
110 __u32 error,
111 int gfp);
112
113struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
114 const struct sctp_association *asoc,
115 __u16 flags,
116 int gfp);
117
118struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
119 const struct sctp_association *asoc,
120 __u32 indication, int gfp);
121
122struct sctp_ulpevent *sctp_ulpevent_make_adaption_indication(
123 const struct sctp_association *asoc, int gfp);
124
125struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
126 struct sctp_chunk *chunk,
127 int gfp);
128
129void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
130 struct msghdr *);
131__u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event);
132
133/* Is this event type enabled? */
134static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
135 struct sctp_event_subscribe *mask)
136{
137 char *amask = (char *) mask;
138 return amask[sn_type - SCTP_SN_TYPE_BASE];
139}
140
141/* Given an event subscription, is this event enabled? */
142static inline int sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
143 struct sctp_event_subscribe *mask)
144{
145 __u16 sn_type;
146 int enabled = 1;
147
148 if (sctp_ulpevent_is_notification(event)) {
149 sn_type = sctp_ulpevent_get_notification_type(event);
150 enabled = sctp_ulpevent_type_enabled(sn_type, mask);
151 }
152 return enabled;
153}
154
155#endif /* __sctp_ulpevent_h__ */
156
157
158
159
160
161
162
diff --git a/include/net/sctp/ulpqueue.h b/include/net/sctp/ulpqueue.h
new file mode 100644
index 00000000000..961736d29d2
--- /dev/null
+++ b/include/net/sctp/ulpqueue.h
@@ -0,0 +1,92 @@
1/* SCTP kernel reference 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 * Copyright (c) 2001 Nokia, Inc.
7 * Copyright (c) 2001 La Monte H.P. Yarroll
8 *
9 * These are the definitions needed for the sctp_ulpq type. The
10 * sctp_ulpq is the interface between the Upper Layer Protocol, or ULP,
11 * and the core SCTP state machine. This is the component which handles
12 * reassembly and ordering.
13 *
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version.
19 *
20 * the SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
30 *
31 * Please send any bug reports or fixes you make to the
32 * email addresses:
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
34 *
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
37 *
38 * Written or modified by:
39 * Jon Grimm <jgrimm@us.ibm.com>
40 * La Monte H.P. Yarroll <piggy@acm.org>
41 * Sridhar Samudrala <sri@us.ibm.com>
42 *
43 * Any bugs reported given to us we will try to fix... any fixes shared will
44 * be incorporated into the next SCTP release.
45 */
46
47#ifndef __sctp_ulpqueue_h__
48#define __sctp_ulpqueue_h__
49
50/* A structure to carry information to the ULP (e.g. Sockets API) */
51struct sctp_ulpq {
52 char malloced;
53 char pd_mode;
54 struct sctp_association *asoc;
55 struct sk_buff_head reasm;
56 struct sk_buff_head lobby;
57};
58
59/* Prototypes. */
60struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *,
61 struct sctp_association *);
62void sctp_ulpq_free(struct sctp_ulpq *);
63
64/* Add a new DATA chunk for processing. */
65int sctp_ulpq_tail_data(struct sctp_ulpq *, struct sctp_chunk *, int);
66
67/* Add a new event for propagation to the ULP. */
68int sctp_ulpq_tail_event(struct sctp_ulpq *, struct sctp_ulpevent *ev);
69
70/* Renege previously received chunks. */
71void sctp_ulpq_renege(struct sctp_ulpq *, struct sctp_chunk *, int);
72
73/* Perform partial delivery. */
74void sctp_ulpq_partial_delivery(struct sctp_ulpq *, struct sctp_chunk *, int);
75
76/* Abort the partial delivery. */
77void sctp_ulpq_abort_pd(struct sctp_ulpq *, int);
78
79/* Clear the partial data delivery condition on this socket. */
80int sctp_clear_pd(struct sock *sk);
81
82/* Skip over an SSN. */
83void sctp_ulpq_skip(struct sctp_ulpq *ulpq, __u16 sid, __u16 ssn);
84
85#endif /* __sctp_ulpqueue_h__ */
86
87
88
89
90
91
92
diff --git a/include/net/sctp/user.h b/include/net/sctp/user.h
new file mode 100644
index 00000000000..2758e8ce4f2
--- /dev/null
+++ b/include/net/sctp/user.h
@@ -0,0 +1,589 @@
1/* SCTP kernel reference 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) 2002 Intel Corp.
6 *
7 * This file is part of the SCTP kernel reference Implementation
8 *
9 * This header represents the structures and constants needed to support
10 * the SCTP Extension to the Sockets API.
11 *
12 * The SCTP reference implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
16 * any later version.
17 *
18 * The SCTP reference implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
28 *
29 * Please send any bug reports or fixes you make to the
30 * email address(es):
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
32 *
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
35 *
36 * Written or modified by:
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * R. Stewart <randall@sctp.chicago.il.us>
39 * K. Morneau <kmorneau@cisco.com>
40 * Q. Xie <qxie1@email.mot.com>
41 * Karl Knutson <karl@athena.chicago.il.us>
42 * Jon Grimm <jgrimm@us.ibm.com>
43 * Daisy Chang <daisyc@us.ibm.com>
44 * Ryan Layer <rmlayer@us.ibm.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Sridhar Samudrala <sri@us.ibm.com>
47 *
48 * Any bugs reported given to us we will try to fix... any fixes shared will
49 * be incorporated into the next SCTP release.
50 */
51
52#ifndef __net_sctp_user_h__
53#define __net_sctp_user_h__
54
55#include <linux/types.h>
56#include <linux/socket.h>
57
58typedef __s32 sctp_assoc_t;
59
60/* The following symbols come from the Sockets API Extensions for
61 * SCTP <draft-ietf-tsvwg-sctpsocket-07.txt>.
62 */
63enum sctp_optname {
64 SCTP_RTOINFO,
65#define SCTP_RTOINFO SCTP_RTOINFO
66 SCTP_ASSOCINFO,
67#define SCTP_ASSOCINFO SCTP_ASSOCINFO
68 SCTP_INITMSG,
69#define SCTP_INITMSG SCTP_INITMSG
70 SCTP_NODELAY, /* Get/set nodelay option. */
71#define SCTP_NODELAY SCTP_NODELAY
72 SCTP_AUTOCLOSE,
73#define SCTP_AUTOCLOSE SCTP_AUTOCLOSE
74 SCTP_SET_PEER_PRIMARY_ADDR,
75#define SCTP_SET_PEER_PRIMARY_ADDR SCTP_SET_PEER_PRIMARY_ADDR
76 SCTP_PRIMARY_ADDR,
77#define SCTP_PRIMARY_ADDR SCTP_PRIMARY_ADDR
78 SCTP_ADAPTION_LAYER,
79#define SCTP_ADAPTION_LAYER SCTP_ADAPTION_LAYER
80 SCTP_DISABLE_FRAGMENTS,
81#define SCTP_DISABLE_FRAGMENTS SCTP_DISABLE_FRAGMENTS
82 SCTP_PEER_ADDR_PARAMS,
83#define SCTP_PEER_ADDR_PARAMS SCTP_PEER_ADDR_PARAMS
84 SCTP_DEFAULT_SEND_PARAM,
85#define SCTP_DEFAULT_SEND_PARAM SCTP_DEFAULT_SEND_PARAM
86 SCTP_EVENTS,
87#define SCTP_EVENTS SCTP_EVENTS
88 SCTP_I_WANT_MAPPED_V4_ADDR, /* Turn on/off mapped v4 addresses */
89#define SCTP_I_WANT_MAPPED_V4_ADDR SCTP_I_WANT_MAPPED_V4_ADDR
90 SCTP_MAXSEG, /* Get/set maximum fragment. */
91#define SCTP_MAXSEG SCTP_MAXSEG
92 SCTP_STATUS,
93#define SCTP_STATUS SCTP_STATUS
94 SCTP_GET_PEER_ADDR_INFO,
95#define SCTP_GET_PEER_ADDR_INFO SCTP_GET_PEER_ADDR_INFO
96
97 /* Internal Socket Options. Some of the sctp library functions are
98 * implemented using these socket options.
99 */
100 SCTP_SOCKOPT_BINDX_ADD = 100,/* BINDX requests for adding addresses. */
101#define SCTP_SOCKOPT_BINDX_ADD SCTP_SOCKOPT_BINDX_ADD
102 SCTP_SOCKOPT_BINDX_REM, /* BINDX requests for removing addresses. */
103#define SCTP_SOCKOPT_BINDX_REM SCTP_SOCKOPT_BINDX_REM
104 SCTP_SOCKOPT_PEELOFF, /* peel off association. */
105#define SCTP_SOCKOPT_PEELOFF SCTP_SOCKOPT_PEELOFF
106 SCTP_GET_PEER_ADDRS_NUM, /* Get number of peer addresss. */
107#define SCTP_GET_PEER_ADDRS_NUM SCTP_GET_PEER_ADDRS_NUM
108 SCTP_GET_PEER_ADDRS, /* Get all peer addresss. */
109#define SCTP_GET_PEER_ADDRS SCTP_GET_PEER_ADDRS
110 SCTP_GET_LOCAL_ADDRS_NUM, /* Get number of local addresss. */
111#define SCTP_GET_LOCAL_ADDRS_NUM SCTP_GET_LOCAL_ADDRS_NUM
112 SCTP_GET_LOCAL_ADDRS, /* Get all local addresss. */
113#define SCTP_GET_LOCAL_ADDRS SCTP_GET_LOCAL_ADDRS
114};
115
116/*
117 * 5.2.1 SCTP Initiation Structure (SCTP_INIT)
118 *
119 * This cmsghdr structure provides information for initializing new
120 * SCTP associations with sendmsg(). The SCTP_INITMSG socket option
121 * uses this same data structure. This structure is not used for
122 * recvmsg().
123 *
124 * cmsg_level cmsg_type cmsg_data[]
125 * ------------ ------------ ----------------------
126 * IPPROTO_SCTP SCTP_INIT struct sctp_initmsg
127 *
128 */
129struct sctp_initmsg {
130 __u16 sinit_num_ostreams;
131 __u16 sinit_max_instreams;
132 __u16 sinit_max_attempts;
133 __u16 sinit_max_init_timeo;
134};
135
136/*
137 * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
138 *
139 * This cmsghdr structure specifies SCTP options for sendmsg() and
140 * describes SCTP header information about a received message through
141 * recvmsg().
142 *
143 * cmsg_level cmsg_type cmsg_data[]
144 * ------------ ------------ ----------------------
145 * IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo
146 *
147 */
148struct sctp_sndrcvinfo {
149 __u16 sinfo_stream;
150 __u16 sinfo_ssn;
151 __u16 sinfo_flags;
152 __u32 sinfo_ppid;
153 __u32 sinfo_context;
154 __u32 sinfo_timetolive;
155 __u32 sinfo_tsn;
156 __u32 sinfo_cumtsn;
157 sctp_assoc_t sinfo_assoc_id;
158};
159
160/*
161 * sinfo_flags: 16 bits (unsigned integer)
162 *
163 * This field may contain any of the following flags and is composed of
164 * a bitwise OR of these values.
165 */
166
167enum sctp_sinfo_flags {
168 MSG_UNORDERED = 1, /* Send/receive message unordered. */
169 MSG_ADDR_OVER = 2, /* Override the primary destination. */
170 MSG_ABORT=4, /* Send an ABORT message to the peer. */
171 /* MSG_EOF is already defined per socket.h */
172};
173
174
175typedef union {
176 __u8 raw;
177 struct sctp_initmsg init;
178 struct sctp_sndrcvinfo sndrcv;
179} sctp_cmsg_data_t;
180
181/* These are cmsg_types. */
182typedef enum sctp_cmsg_type {
183 SCTP_INIT, /* 5.2.1 SCTP Initiation Structure */
184 SCTP_SNDRCV, /* 5.2.2 SCTP Header Information Structure */
185} sctp_cmsg_t;
186
187
188/*
189 * 5.3.1.1 SCTP_ASSOC_CHANGE
190 *
191 * Communication notifications inform the ULP that an SCTP association
192 * has either begun or ended. The identifier for a new association is
193 * provided by this notificaion. The notification information has the
194 * following format:
195 *
196 */
197struct sctp_assoc_change {
198 __u16 sac_type;
199 __u16 sac_flags;
200 __u32 sac_length;
201 __u16 sac_state;
202 __u16 sac_error;
203 __u16 sac_outbound_streams;
204 __u16 sac_inbound_streams;
205 sctp_assoc_t sac_assoc_id;
206};
207
208/*
209 * sac_state: 32 bits (signed integer)
210 *
211 * This field holds one of a number of values that communicate the
212 * event that happened to the association. They include:
213 *
214 * Note: The following state names deviate from the API draft as
215 * the names clash too easily with other kernel symbols.
216 */
217enum sctp_sac_state {
218 SCTP_COMM_UP,
219 SCTP_COMM_LOST,
220 SCTP_RESTART,
221 SCTP_SHUTDOWN_COMP,
222 SCTP_CANT_STR_ASSOC,
223};
224
225/*
226 * 5.3.1.2 SCTP_PEER_ADDR_CHANGE
227 *
228 * When a destination address on a multi-homed peer encounters a change
229 * an interface details event is sent. The information has the
230 * following structure:
231 */
232struct sctp_paddr_change {
233 __u16 spc_type;
234 __u16 spc_flags;
235 __u32 spc_length;
236 struct sockaddr_storage spc_aaddr;
237 int spc_state;
238 int spc_error;
239 sctp_assoc_t spc_assoc_id;
240};
241
242/*
243 * spc_state: 32 bits (signed integer)
244 *
245 * This field holds one of a number of values that communicate the
246 * event that happened to the address. They include:
247 */
248enum sctp_spc_state {
249 SCTP_ADDR_AVAILABLE,
250 SCTP_ADDR_UNREACHABLE,
251 SCTP_ADDR_REMOVED,
252 SCTP_ADDR_ADDED,
253 SCTP_ADDR_MADE_PRIM,
254};
255
256
257/*
258 * 5.3.1.3 SCTP_REMOTE_ERROR
259 *
260 * A remote peer may send an Operational Error message to its peer.
261 * This message indicates a variety of error conditions on an
262 * association. The entire error TLV as it appears on the wire is
263 * included in a SCTP_REMOTE_ERROR event. Please refer to the SCTP
264 * specification [SCTP] and any extensions for a list of possible
265 * error formats. SCTP error TLVs have the format:
266 */
267struct sctp_remote_error {
268 __u16 sre_type;
269 __u16 sre_flags;
270 __u32 sre_length;
271 __u16 sre_error;
272 sctp_assoc_t sre_assoc_id;
273 __u8 sre_data[0];
274};
275
276
277/*
278 * 5.3.1.4 SCTP_SEND_FAILED
279 *
280 * If SCTP cannot deliver a message it may return the message as a
281 * notification.
282 */
283struct sctp_send_failed {
284 __u16 ssf_type;
285 __u16 ssf_flags;
286 __u32 ssf_length;
287 __u32 ssf_error;
288 struct sctp_sndrcvinfo ssf_info;
289 sctp_assoc_t ssf_assoc_id;
290 __u8 ssf_data[0];
291};
292
293/*
294 * ssf_flags: 16 bits (unsigned integer)
295 *
296 * The flag value will take one of the following values
297 *
298 * SCTP_DATA_UNSENT - Indicates that the data was never put on
299 * the wire.
300 *
301 * SCTP_DATA_SENT - Indicates that the data was put on the wire.
302 * Note that this does not necessarily mean that the
303 * data was (or was not) successfully delivered.
304 */
305enum sctp_ssf_flags {
306 SCTP_DATA_UNSENT,
307 SCTP_DATA_SENT,
308};
309
310/*
311 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
312 *
313 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
314 * inform the application that it should cease sending data.
315 */
316struct sctp_shutdown_event {
317 __u16 sse_type;
318 __u16 sse_flags;
319 __u32 sse_length;
320 sctp_assoc_t sse_assoc_id;
321};
322
323/*
324 * 5.3.1.6 SCTP_ADAPTION_INDICATION
325 *
326 * When a peer sends a Adaption Layer Indication parameter , SCTP
327 * delivers this notification to inform the application
328 * that of the peers requested adaption layer.
329 */
330struct sctp_adaption_event {
331 __u16 sai_type;
332 __u16 sai_flags;
333 __u32 sai_length;
334 __u32 sai_adaption_ind;
335 sctp_assoc_t sai_assoc_id;
336};
337
338/*
339 * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
340 *
341 * When a receiver is engaged in a partial delivery of a
342 * message this notification will be used to indicate
343 * various events.
344 */
345struct sctp_pdapi_event {
346 __u16 pdapi_type;
347 __u16 pdapi_flags;
348 __u32 pdapi_length;
349 __u32 pdapi_indication;
350 sctp_assoc_t pdapi_assoc_id;
351};
352
353enum { SCTP_PARTIAL_DELIVERY_ABORTED=0, };
354
355/*
356 * Described in Section 7.3
357 * Ancillary Data and Notification Interest Options
358 */
359struct sctp_event_subscribe {
360 __u8 sctp_data_io_event;
361 __u8 sctp_association_event;
362 __u8 sctp_address_event;
363 __u8 sctp_send_failure_event;
364 __u8 sctp_peer_error_event;
365 __u8 sctp_shutdown_event;
366 __u8 sctp_partial_delivery_event;
367 __u8 sctp_adaption_layer_event;
368};
369
370/*
371 * 5.3.1 SCTP Notification Structure
372 *
373 * The notification structure is defined as the union of all
374 * notification types.
375 *
376 */
377union sctp_notification {
378 struct {
379 __u16 sn_type; /* Notification type. */
380 __u16 sn_flags;
381 __u32 sn_length;
382 } sn_header;
383 struct sctp_assoc_change sn_assoc_change;
384 struct sctp_paddr_change sn_paddr_change;
385 struct sctp_remote_error sn_remote_error;
386 struct sctp_send_failed sn_send_failed;
387 struct sctp_shutdown_event sn_shutdown_event;
388 struct sctp_adaption_event sn_adaption_event;
389 struct sctp_pdapi_event sn_pdapi_event;
390};
391
392/* Section 5.3.1
393 * All standard values for sn_type flags are greater than 2^15.
394 * Values from 2^15 and down are reserved.
395 */
396
397enum sctp_sn_type {
398 SCTP_SN_TYPE_BASE = (1<<15),
399 SCTP_ASSOC_CHANGE,
400 SCTP_PEER_ADDR_CHANGE,
401 SCTP_SEND_FAILED,
402 SCTP_REMOTE_ERROR,
403 SCTP_SHUTDOWN_EVENT,
404 SCTP_PARTIAL_DELIVERY_EVENT,
405 SCTP_ADAPTION_INDICATION,
406};
407
408/* Notification error codes used to fill up the error fields in some
409 * notifications.
410 * SCTP_PEER_ADDRESS_CHAGE : spc_error
411 * SCTP_ASSOC_CHANGE : sac_error
412 * These names should be potentially included in the draft 04 of the SCTP
413 * sockets API specification.
414 */
415typedef enum sctp_sn_error {
416 SCTP_FAILED_THRESHOLD,
417 SCTP_RECEIVED_SACK,
418 SCTP_HEARTBEAT_SUCCESS,
419 SCTP_RESPONSE_TO_USER_REQ,
420 SCTP_INTERNAL_ERROR,
421 SCTP_SHUTDOWN_GUARD_EXPIRES,
422 SCTP_PEER_FAULTY,
423} sctp_sn_error_t;
424
425/*
426 * 7.1.1 Retransmission Timeout Parameters (SCTP_RTOINFO)
427 *
428 * The protocol parameters used to initialize and bound retransmission
429 * timeout (RTO) are tunable. See [SCTP] for more information on how
430 * these parameters are used in RTO calculation.
431 */
432struct sctp_rtoinfo {
433 sctp_assoc_t srto_assoc_id;
434 __u32 srto_initial;
435 __u32 srto_max;
436 __u32 srto_min;
437};
438
439/*
440 * 7.1.2 Association Parameters (SCTP_ASSOCINFO)
441 *
442 * This option is used to both examine and set various association and
443 * endpoint parameters.
444 */
445struct sctp_assocparams {
446 sctp_assoc_t sasoc_assoc_id;
447 __u16 sasoc_asocmaxrxt;
448 __u16 sasoc_number_peer_destinations;
449 __u32 sasoc_peer_rwnd;
450 __u32 sasoc_local_rwnd;
451 __u32 sasoc_cookie_life;
452};
453
454/*
455 * 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR)
456 *
457 * Requests that the peer mark the enclosed address as the association
458 * primary. The enclosed address must be one of the association's
459 * locally bound addresses. The following structure is used to make a
460 * set primary request:
461 */
462struct sctp_setpeerprim {
463 sctp_assoc_t sspp_assoc_id;
464 struct sockaddr_storage sspp_addr;
465};
466
467/*
468 * 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR)
469 *
470 * Requests that the local SCTP stack use the enclosed peer address as
471 * the association primary. The enclosed address must be one of the
472 * association peer's addresses. The following structure is used to
473 * make a set peer primary request:
474 */
475struct sctp_prim {
476 sctp_assoc_t ssp_assoc_id;
477 struct sockaddr_storage ssp_addr;
478};
479
480/*
481 * 7.1.11 Set Adaption Layer Indicator (SCTP_ADAPTION_LAYER)
482 *
483 * Requests that the local endpoint set the specified Adaption Layer
484 * Indication parameter for all future INIT and INIT-ACK exchanges.
485 */
486struct sctp_setadaption {
487 __u32 ssb_adaption_ind;
488};
489
490/*
491 * 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS)
492 *
493 * Applications can enable or disable heartbeats for any peer address
494 * of an association, modify an address's heartbeat interval, force a
495 * heartbeat to be sent immediately, and adjust the address's maximum
496 * number of retransmissions sent before an address is considered
497 * unreachable. The following structure is used to access and modify an
498 * address's parameters:
499 */
500struct sctp_paddrparams {
501 sctp_assoc_t spp_assoc_id;
502 struct sockaddr_storage spp_address;
503 __u32 spp_hbinterval;
504 __u16 spp_pathmaxrxt;
505};
506
507/*
508 * 7.2.2 Peer Address Information
509 *
510 * Applications can retrieve information about a specific peer address
511 * of an association, including its reachability state, congestion
512 * window, and retransmission timer values. This information is
513 * read-only. The following structure is used to access this
514 * information:
515 */
516struct sctp_paddrinfo {
517 sctp_assoc_t spinfo_assoc_id;
518 struct sockaddr_storage spinfo_address;
519 __s32 spinfo_state;
520 __u32 spinfo_cwnd;
521 __u32 spinfo_srtt;
522 __u32 spinfo_rto;
523 __u32 spinfo_mtu;
524};
525
526/* Peer addresses's state. */
527enum sctp_spinfo_state {
528 SCTP_INACTIVE,
529 SCTP_ACTIVE,
530};
531
532/*
533 * 7.2.1 Association Status (SCTP_STATUS)
534 *
535 * Applications can retrieve current status information about an
536 * association, including association state, peer receiver window size,
537 * number of unacked data chunks, and number of data chunks pending
538 * receipt. This information is read-only. The following structure is
539 * used to access this information:
540 */
541struct sctp_status {
542 sctp_assoc_t sstat_assoc_id;
543 __s32 sstat_state;
544 __u32 sstat_rwnd;
545 __u16 sstat_unackdata;
546 __u16 sstat_penddata;
547 __u16 sstat_instrms;
548 __u16 sstat_outstrms;
549 __u32 sstat_fragmentation_point;
550 struct sctp_paddrinfo sstat_primary;
551};
552
553/*
554 * 8.3, 8.5 get all peer/local addresses in an association.
555 * This parameter struct is used by SCTP_GET_PEER_ADDRS and
556 * SCTP_GET_LOCAL_ADDRS socket options used internally to implement
557 * sctp_getpaddrs() and sctp_getladdrs() API.
558 */
559struct sctp_getaddrs {
560 sctp_assoc_t assoc_id;
561 int addr_num;
562 struct sockaddr __user *addrs;
563};
564
565/* These are bit fields for msghdr->msg_flags. See section 5.1. */
566/* On user space Linux, these live in <bits/socket.h> as an enum. */
567enum sctp_msg_flags {
568 MSG_NOTIFICATION = 0x8000,
569#define MSG_NOTIFICATION MSG_NOTIFICATION
570};
571
572/*
573 * 8.1 sctp_bindx()
574 *
575 * The flags parameter is formed from the bitwise OR of zero or more of the
576 * following currently defined flags:
577 */
578#define SCTP_BINDX_ADD_ADDR 0x01
579#define SCTP_BINDX_REM_ADDR 0x02
580
581/* This is the structure that is passed as an argument(optval) to
582 * getsockopt(SCTP_SOCKOPT_PEELOFF).
583 */
584typedef struct {
585 sctp_assoc_t associd;
586 int sd;
587} sctp_peeloff_arg_t;
588
589#endif /* __net_sctp_user_h__ */