| 1 |
|
| 2 | |
| 3 | * (C) Copyright IBM Corp. 2001, 2004
|
| 4 | * Copyright (C) 1999-2001 Cisco, Motorola
|
| 5 | *
|
| 6 | * This file is part of the SCTP kernel implementation
|
| 7 | *
|
| 8 | * These are the definitions needed for the command object.
|
| 9 | *
|
| 10 | * Please send any bug reports or fixes you make to the
|
| 11 | * email address(es):
|
| 12 | * lksctp developers <[email protected]>
|
| 13 | *
|
| 14 | * Written or modified by:
|
| 15 | * La Monte H.P. Yarroll <[email protected]>
|
| 16 | * Karl Knutson <[email protected]>
|
| 17 | * Ardelle Fan <[email protected]>
|
| 18 | * Sridhar Samudrala <[email protected]>
|
| 19 |
|
| 20 |
|
| 21 | #ifndef __net_sctp_command_h__
|
| 22 | #define __net_sctp_command_h__
|
| 23 |
|
| 24 | #include <net/sctp/constants.h>
|
| 25 | #include <net/sctp/structs.h>
|
| 26 |
|
| 27 |
|
| 28 | enum sctp_verb {
|
| 29 | SCTP_CMD_NOP = 0,
|
| 30 | SCTP_CMD_NEW_ASOC,
|
| 31 | SCTP_CMD_DELETE_TCB,
|
| 32 | SCTP_CMD_NEW_STATE,
|
| 33 | SCTP_CMD_REPORT_TSN,
|
| 34 | SCTP_CMD_GEN_SACK,
|
| 35 | SCTP_CMD_PROCESS_SACK,
|
| 36 | SCTP_CMD_GEN_INIT_ACK,
|
| 37 | SCTP_CMD_PEER_INIT,
|
| 38 | SCTP_CMD_GEN_COOKIE_ECHO,
|
| 39 | SCTP_CMD_CHUNK_ULP,
|
| 40 | SCTP_CMD_EVENT_ULP,
|
| 41 | SCTP_CMD_REPLY,
|
| 42 | SCTP_CMD_SEND_PKT,
|
| 43 | SCTP_CMD_RETRAN,
|
| 44 | SCTP_CMD_ECN_CE,
|
| 45 | SCTP_CMD_ECN_ECNE,
|
| 46 | SCTP_CMD_ECN_CWR,
|
| 47 | SCTP_CMD_TIMER_START,
|
| 48 | SCTP_CMD_TIMER_START_ONCE,
|
| 49 | SCTP_CMD_TIMER_RESTART,
|
| 50 | SCTP_CMD_TIMER_STOP,
|
| 51 | SCTP_CMD_INIT_CHOOSE_TRANSPORT,
|
| 52 | SCTP_CMD_INIT_COUNTER_RESET,
|
| 53 | SCTP_CMD_INIT_COUNTER_INC,
|
| 54 | SCTP_CMD_INIT_RESTART,
|
| 55 | SCTP_CMD_COOKIEECHO_RESTART,
|
| 56 | SCTP_CMD_INIT_FAILED,
|
| 57 | SCTP_CMD_REPORT_DUP,
|
| 58 | SCTP_CMD_STRIKE,
|
| 59 | SCTP_CMD_HB_TIMERS_START,
|
| 60 | SCTP_CMD_HB_TIMER_UPDATE,
|
| 61 | SCTP_CMD_HB_TIMERS_STOP,
|
| 62 | SCTP_CMD_PROBE_TIMER_UPDATE,
|
| 63 | SCTP_CMD_TRANSPORT_HB_SENT,
|
| 64 | SCTP_CMD_TRANSPORT_IDLE,
|
| 65 | SCTP_CMD_TRANSPORT_ON,
|
| 66 | SCTP_CMD_REPORT_ERROR,
|
| 67 | SCTP_CMD_REPORT_BAD_TAG,
|
| 68 | SCTP_CMD_PROCESS_CTSN,
|
| 69 | SCTP_CMD_ASSOC_FAILED,
|
| 70 | SCTP_CMD_DISCARD_PACKET,
|
| 71 | SCTP_CMD_GEN_SHUTDOWN,
|
| 72 | SCTP_CMD_PURGE_OUTQUEUE,
|
| 73 | SCTP_CMD_SETUP_T2,
|
| 74 | SCTP_CMD_RTO_PENDING,
|
| 75 | SCTP_CMD_PART_DELIVER,
|
| 76 | SCTP_CMD_RENEGE,
|
| 77 | SCTP_CMD_SETUP_T4,
|
| 78 | SCTP_CMD_PROCESS_OPERR,
|
| 79 | SCTP_CMD_REPORT_FWDTSN,
|
| 80 | SCTP_CMD_PROCESS_FWDTSN,
|
| 81 | SCTP_CMD_CLEAR_INIT_TAG,
|
| 82 | SCTP_CMD_DEL_NON_PRIMARY,
|
| 83 | SCTP_CMD_T3_RTX_TIMERS_STOP,
|
| 84 | SCTP_CMD_FORCE_PRIM_RETRAN,
|
| 85 | SCTP_CMD_SET_SK_ERR,
|
| 86 | SCTP_CMD_ASSOC_CHANGE,
|
| 87 | SCTP_CMD_ADAPTATION_IND,
|
| 88 | SCTP_CMD_PEER_NO_AUTH,
|
| 89 | SCTP_CMD_ASSOC_SHKEY,
|
| 90 | SCTP_CMD_T1_RETRAN,
|
| 91 | SCTP_CMD_UPDATE_INITTAG,
|
| 92 | SCTP_CMD_SEND_MSG,
|
| 93 | SCTP_CMD_PURGE_ASCONF_QUEUE,
|
| 94 | SCTP_CMD_SET_ASOC,
|
| 95 | SCTP_CMD_LAST
|
| 96 | };
|
| 97 |
|
| 98 | |
| 99 | * This is a rather arbitrary number, ideally derived from a careful
|
| 100 | * analysis of the state functions, but in reality just taken from
|
| 101 | * thin air in the hopes othat we don't trigger a kernel panic.
|
| 102 |
|
| 103 | #define SCTP_MAX_NUM_COMMANDS 20
|
| 104 |
|
| 105 | union sctp_arg {
|
| 106 | void *zero_all;
|
| 107 | __s32 i32;
|
| 108 | __u32 u32;
|
| 109 | __be32 be32;
|
| 110 | __u16 u16;
|
| 111 | __u8 u8;
|
| 112 | int error;
|
| 113 | __be16 err;
|
| 114 | enum sctp_state state;
|
| 115 | enum sctp_event_timeout to;
|
| 116 | struct sctp_chunk *chunk;
|
| 117 | struct sctp_association *asoc;
|
| 118 | struct sctp_transport *transport;
|
| 119 | struct sctp_bind_addr *bp;
|
| 120 | struct sctp_init_chunk *init;
|
| 121 | struct sctp_ulpevent *ulpevent;
|
| 122 | struct sctp_packet *packet;
|
| 123 | struct sctp_sackhdr *sackh;
|
| 124 | struct sctp_datamsg *msg;
|
| 125 | };
|
| 126 |
|
| 127 | |
| 128 | *
|
| 129 | * SCTP_ARG_CONSTRUCTOR(NAME, TYPE, ELT) builds a function called
|
| 130 | * SCTP_NAME() which takes an argument of type TYPE and returns an
|
| 131 | * union sctp_arg. It does this by inserting the sole argument into
|
| 132 | * the ELT union element of a local union sctp_arg.
|
| 133 | *
|
| 134 | * E.g., SCTP_ARG_CONSTRUCTOR(I32, __s32, i32) builds SCTP_I32(arg),
|
| 135 | * which takes an __s32 and returns a union sctp_arg containing the
|
| 136 | * __s32. So, after foo = SCTP_I32(arg), foo.i32 == arg.
|
| 137 |
|
| 138 |
|
| 139 | #define SCTP_ARG_CONSTRUCTOR(name, type, elt) \
|
| 140 | static inline union sctp_arg \
|
| 141 | SCTP_## name (type arg) \
|
| 142 | { union sctp_arg retval;\
|
| 143 | retval.zero_all = NULL;\
|
| 144 | retval.elt = arg;\
|
| 145 | return retval;\
|
| 146 | }
|
| 147 |
|
| 148 | SCTP_ARG_CONSTRUCTOR(I32, __s32, i32)
|
| 149 | SCTP_ARG_CONSTRUCTOR(U32, __u32, u32)
|
| 150 | SCTP_ARG_CONSTRUCTOR(BE32, __be32, be32)
|
| 151 | SCTP_ARG_CONSTRUCTOR(U16, __u16, u16)
|
| 152 | SCTP_ARG_CONSTRUCTOR(U8, __u8, u8)
|
| 153 | SCTP_ARG_CONSTRUCTOR(ERROR, int, error)
|
| 154 | SCTP_ARG_CONSTRUCTOR(PERR, __be16, err)
|
| 155 | SCTP_ARG_CONSTRUCTOR(STATE, enum sctp_state, state)
|
| 156 | SCTP_ARG_CONSTRUCTOR(TO, enum sctp_event_timeout, to)
|
| 157 | SCTP_ARG_CONSTRUCTOR(CHUNK, struct sctp_chunk *, chunk)
|
| 158 | SCTP_ARG_CONSTRUCTOR(ASOC, struct sctp_association *, asoc)
|
| 159 | SCTP_ARG_CONSTRUCTOR(TRANSPORT, struct sctp_transport *, transport)
|
| 160 | SCTP_ARG_CONSTRUCTOR(BA, struct sctp_bind_addr *, bp)
|
| 161 | SCTP_ARG_CONSTRUCTOR(PEER_INIT, struct sctp_init_chunk *, init)
|
| 162 | SCTP_ARG_CONSTRUCTOR(ULPEVENT, struct sctp_ulpevent *, ulpevent)
|
| 163 | SCTP_ARG_CONSTRUCTOR(PACKET, struct sctp_packet *, packet)
|
| 164 | SCTP_ARG_CONSTRUCTOR(SACKH, struct sctp_sackhdr *, sackh)
|
| 165 | SCTP_ARG_CONSTRUCTOR(DATAMSG, struct sctp_datamsg *, msg)
|
| 166 |
|
| 167 | static inline union sctp_arg SCTP_FORCE(void)
|
| 168 | {
|
| 169 | return SCTP_I32(1);
|
| 170 | }
|
| 171 |
|
| 172 | static inline union sctp_arg SCTP_NOFORCE(void)
|
| 173 | {
|
| 174 | return SCTP_I32(0);
|
| 175 | }
|
| 176 |
|
| 177 | static inline union sctp_arg SCTP_NULL(void)
|
| 178 | {
|
| 179 | union sctp_arg retval;
|
| 180 | retval.zero_all = NULL;
|
| 181 | return retval;
|
| 182 | }
|
| 183 |
|
| 184 | struct sctp_cmd {
|
| 185 | union sctp_arg obj;
|
| 186 | enum sctp_verb verb;
|
| 187 | };
|
| 188 |
|
| 189 | struct sctp_cmd_seq {
|
| 190 | struct sctp_cmd cmds[SCTP_MAX_NUM_COMMANDS];
|
| 191 | struct sctp_cmd *last_used_slot;
|
| 192 | struct sctp_cmd *next_cmd;
|
| 193 | };
|
| 194 |
|
| 195 |
|
| 196 | |
| 197 | * Return 0 if the initialization fails.
|
| 198 |
|
| 199 | static inline int sctp_init_cmd_seq(struct sctp_cmd_seq *seq)
|
| 200 | {
|
| 201 |
|
| 202 | seq->last_used_slot = seq->cmds + SCTP_MAX_NUM_COMMANDS;
|
| 203 | seq->next_cmd = seq->last_used_slot;
|
| 204 | return 1;
|
| 205 | }
|
| 206 |
|
| 207 |
|
| 208 | |
| 209 | *
|
| 210 | * Use the SCTP_* constructors defined by SCTP_ARG_CONSTRUCTOR() above
|
| 211 | * to wrap data which goes in the obj argument.
|
| 212 |
|
| 213 | static inline void sctp_add_cmd_sf(struct sctp_cmd_seq *seq,
|
| 214 | enum sctp_verb verb, union sctp_arg obj)
|
| 215 | {
|
| 216 | struct sctp_cmd *cmd = seq->last_used_slot - 1;
|
| 217 |
|
| 218 | BUG_ON(cmd < seq->cmds);
|
| 219 |
|
| 220 | cmd->verb = verb;
|
| 221 | cmd->obj = obj;
|
| 222 | seq->last_used_slot = cmd;
|
| 223 | }
|
| 224 |
|
| 225 | |
| 226 | * Return NULL at the end of the sequence.
|
| 227 |
|
| 228 | static inline struct sctp_cmd *sctp_next_cmd(struct sctp_cmd_seq *seq)
|
| 229 | {
|
| 230 | if (seq->next_cmd <= seq->last_used_slot)
|
| 231 | return NULL;
|
| 232 |
|
| 233 | return --seq->next_cmd;
|
| 234 | }
|
| 235 |
|
| 236 | #endif
|