1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#ifndef __net_sctp_command_h__
37#define __net_sctp_command_h__
38
39#include <net/sctp/constants.h>
40#include <net/sctp/structs.h>
41
42
43typedef enum {
44 SCTP_CMD_NOP = 0,
45 SCTP_CMD_NEW_ASOC,
46 SCTP_CMD_DELETE_TCB,
47 SCTP_CMD_NEW_STATE,
48 SCTP_CMD_REPORT_TSN,
49 SCTP_CMD_GEN_SACK,
50 SCTP_CMD_PROCESS_SACK,
51 SCTP_CMD_GEN_INIT_ACK,
52 SCTP_CMD_PEER_INIT,
53 SCTP_CMD_GEN_COOKIE_ECHO,
54 SCTP_CMD_CHUNK_ULP,
55 SCTP_CMD_EVENT_ULP,
56 SCTP_CMD_REPLY,
57 SCTP_CMD_SEND_PKT,
58 SCTP_CMD_RETRAN,
59 SCTP_CMD_ECN_CE,
60 SCTP_CMD_ECN_ECNE,
61 SCTP_CMD_ECN_CWR,
62 SCTP_CMD_TIMER_START,
63 SCTP_CMD_TIMER_START_ONCE,
64 SCTP_CMD_TIMER_RESTART,
65 SCTP_CMD_TIMER_STOP,
66 SCTP_CMD_INIT_CHOOSE_TRANSPORT,
67 SCTP_CMD_INIT_COUNTER_RESET,
68 SCTP_CMD_INIT_COUNTER_INC,
69 SCTP_CMD_INIT_RESTART,
70 SCTP_CMD_COOKIEECHO_RESTART,
71 SCTP_CMD_INIT_FAILED,
72 SCTP_CMD_REPORT_DUP,
73 SCTP_CMD_STRIKE,
74 SCTP_CMD_HB_TIMERS_START,
75 SCTP_CMD_HB_TIMER_UPDATE,
76 SCTP_CMD_HB_TIMERS_STOP,
77 SCTP_CMD_TRANSPORT_HB_SENT,
78 SCTP_CMD_TRANSPORT_IDLE,
79 SCTP_CMD_TRANSPORT_ON,
80 SCTP_CMD_REPORT_ERROR,
81 SCTP_CMD_REPORT_BAD_TAG,
82 SCTP_CMD_PROCESS_CTSN,
83 SCTP_CMD_ASSOC_FAILED,
84 SCTP_CMD_DISCARD_PACKET,
85 SCTP_CMD_GEN_SHUTDOWN,
86 SCTP_CMD_UPDATE_ASSOC,
87 SCTP_CMD_PURGE_OUTQUEUE,
88 SCTP_CMD_SETUP_T2,
89 SCTP_CMD_RTO_PENDING,
90 SCTP_CMD_PART_DELIVER,
91 SCTP_CMD_RENEGE,
92 SCTP_CMD_SETUP_T4,
93 SCTP_CMD_PROCESS_OPERR,
94 SCTP_CMD_REPORT_FWDTSN,
95 SCTP_CMD_PROCESS_FWDTSN,
96 SCTP_CMD_CLEAR_INIT_TAG,
97 SCTP_CMD_DEL_NON_PRIMARY,
98 SCTP_CMD_T3_RTX_TIMERS_STOP,
99 SCTP_CMD_FORCE_PRIM_RETRAN,
100 SCTP_CMD_SET_SK_ERR,
101 SCTP_CMD_ASSOC_CHANGE,
102 SCTP_CMD_ADAPTATION_IND,
103 SCTP_CMD_ASSOC_SHKEY,
104 SCTP_CMD_T1_RETRAN,
105 SCTP_CMD_UPDATE_INITTAG,
106 SCTP_CMD_SEND_MSG,
107 SCTP_CMD_SEND_NEXT_ASCONF,
108 SCTP_CMD_PURGE_ASCONF_QUEUE,
109 SCTP_CMD_SET_ASOC,
110 SCTP_CMD_LAST
111} sctp_verb_t;
112
113
114
115
116
117
118#define SCTP_MAX_NUM_COMMANDS 20
119
120typedef union {
121 void *zero_all;
122 __s32 i32;
123 __u32 u32;
124 __be32 be32;
125 __u16 u16;
126 __u8 u8;
127 int error;
128 __be16 err;
129 sctp_state_t state;
130 sctp_event_timeout_t to;
131 struct sctp_chunk *chunk;
132 struct sctp_association *asoc;
133 struct sctp_transport *transport;
134 struct sctp_bind_addr *bp;
135 sctp_init_chunk_t *init;
136 struct sctp_ulpevent *ulpevent;
137 struct sctp_packet *packet;
138 sctp_sackhdr_t *sackh;
139 struct sctp_datamsg *msg;
140} sctp_arg_t;
141
142
143
144
145
146
147
148
149
150
151
152
153
154#define SCTP_ARG_CONSTRUCTOR(name, type, elt) \
155static inline sctp_arg_t \
156SCTP_## name (type arg) \
157{ sctp_arg_t retval;\
158 retval.zero_all = NULL;\
159 retval.elt = arg;\
160 return retval;\
161}
162
163SCTP_ARG_CONSTRUCTOR(I32, __s32, i32)
164SCTP_ARG_CONSTRUCTOR(U32, __u32, u32)
165SCTP_ARG_CONSTRUCTOR(BE32, __be32, be32)
166SCTP_ARG_CONSTRUCTOR(U16, __u16, u16)
167SCTP_ARG_CONSTRUCTOR(U8, __u8, u8)
168SCTP_ARG_CONSTRUCTOR(ERROR, int, error)
169SCTP_ARG_CONSTRUCTOR(PERR, __be16, err)
170SCTP_ARG_CONSTRUCTOR(STATE, sctp_state_t, state)
171SCTP_ARG_CONSTRUCTOR(TO, sctp_event_timeout_t, to)
172SCTP_ARG_CONSTRUCTOR(CHUNK, struct sctp_chunk *, chunk)
173SCTP_ARG_CONSTRUCTOR(ASOC, struct sctp_association *, asoc)
174SCTP_ARG_CONSTRUCTOR(TRANSPORT, struct sctp_transport *, transport)
175SCTP_ARG_CONSTRUCTOR(BA, struct sctp_bind_addr *, bp)
176SCTP_ARG_CONSTRUCTOR(PEER_INIT, sctp_init_chunk_t *, init)
177SCTP_ARG_CONSTRUCTOR(ULPEVENT, struct sctp_ulpevent *, ulpevent)
178SCTP_ARG_CONSTRUCTOR(PACKET, struct sctp_packet *, packet)
179SCTP_ARG_CONSTRUCTOR(SACKH, sctp_sackhdr_t *, sackh)
180SCTP_ARG_CONSTRUCTOR(DATAMSG, struct sctp_datamsg *, msg)
181
182static inline sctp_arg_t SCTP_FORCE(void)
183{
184 return SCTP_I32(1);
185}
186
187static inline sctp_arg_t SCTP_NOFORCE(void)
188{
189 return SCTP_I32(0);
190}
191
192static inline sctp_arg_t SCTP_NULL(void)
193{
194 sctp_arg_t retval;
195 retval.zero_all = NULL;
196 return retval;
197}
198
199typedef struct {
200 sctp_arg_t obj;
201 sctp_verb_t verb;
202} sctp_cmd_t;
203
204typedef struct {
205 sctp_cmd_t cmds[SCTP_MAX_NUM_COMMANDS];
206 sctp_cmd_t *last_used_slot;
207 sctp_cmd_t *next_cmd;
208} sctp_cmd_seq_t;
209
210
211
212
213
214static inline int sctp_init_cmd_seq(sctp_cmd_seq_t *seq)
215{
216
217 seq->last_used_slot = seq->cmds + SCTP_MAX_NUM_COMMANDS;
218 seq->next_cmd = seq->last_used_slot;
219 return 1;
220}
221
222
223
224
225
226
227
228static inline void sctp_add_cmd_sf(sctp_cmd_seq_t *seq, sctp_verb_t verb,
229 sctp_arg_t obj)
230{
231 sctp_cmd_t *cmd = seq->last_used_slot - 1;
232
233 BUG_ON(cmd < seq->cmds);
234
235 cmd->verb = verb;
236 cmd->obj = obj;
237 seq->last_used_slot = cmd;
238}
239
240
241
242
243static inline sctp_cmd_t *sctp_next_cmd(sctp_cmd_seq_t *seq)
244{
245 if (seq->next_cmd <= seq->last_used_slot)
246 return NULL;
247
248 return --seq->next_cmd;
249}
250
251#endif
252