^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* SCTP kernel Implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * (C) Copyright IBM Corp. 2001, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 1999-2001 Cisco, Motorola
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This file is part of the SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * These are the definitions needed for the command object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * La Monte H.P. Yarroll <piggy@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Karl Knutson <karl@athena.chicago.il.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Ardelle Fan <ardelle.fan@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Sridhar Samudrala <sri@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #ifndef __net_sctp_command_h__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define __net_sctp_command_h__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/sctp/constants.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <net/sctp/structs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) enum sctp_verb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) SCTP_CMD_NOP = 0, /* Do nothing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) SCTP_CMD_NEW_ASOC, /* Register a new association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) SCTP_CMD_DELETE_TCB, /* Delete the current association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) SCTP_CMD_NEW_STATE, /* Enter a new state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) SCTP_CMD_REPORT_TSN, /* Record the arrival of a TSN. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) SCTP_CMD_GEN_SACK, /* Send a Selective ACK (maybe). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) SCTP_CMD_PROCESS_SACK, /* Process an inbound SACK. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) SCTP_CMD_GEN_INIT_ACK, /* Generate an INIT ACK chunk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) SCTP_CMD_PEER_INIT, /* Process a INIT from the peer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) SCTP_CMD_GEN_COOKIE_ECHO, /* Generate a COOKIE ECHO chunk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) SCTP_CMD_CHUNK_ULP, /* Send a chunk to the sockets layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) SCTP_CMD_EVENT_ULP, /* Send a notification to the sockets layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) SCTP_CMD_REPLY, /* Send a chunk to our peer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) SCTP_CMD_SEND_PKT, /* Send a full packet to our peer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) SCTP_CMD_RETRAN, /* Mark a transport for retransmission. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) SCTP_CMD_ECN_CE, /* Do delayed CE processing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) SCTP_CMD_ECN_ECNE, /* Do delayed ECNE processing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) SCTP_CMD_ECN_CWR, /* Do delayed CWR processing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) SCTP_CMD_TIMER_START, /* Start a timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) SCTP_CMD_TIMER_START_ONCE, /* Start a timer once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) SCTP_CMD_TIMER_RESTART, /* Restart a timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) SCTP_CMD_TIMER_STOP, /* Stop a timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) SCTP_CMD_INIT_CHOOSE_TRANSPORT, /* Choose transport for an INIT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) SCTP_CMD_INIT_COUNTER_RESET, /* Reset init counter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) SCTP_CMD_INIT_COUNTER_INC, /* Increment init counter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) SCTP_CMD_INIT_RESTART, /* High level, do init timer work. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) SCTP_CMD_COOKIEECHO_RESTART, /* High level, do cookie-echo timer work. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) SCTP_CMD_INIT_FAILED, /* High level, do init failure work. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) SCTP_CMD_REPORT_DUP, /* Report a duplicate TSN. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) SCTP_CMD_STRIKE, /* Mark a strike against a transport. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) SCTP_CMD_HB_TIMERS_START, /* Start the heartbeat timers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) SCTP_CMD_HB_TIMER_UPDATE, /* Update a heartbeat timers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) SCTP_CMD_HB_TIMERS_STOP, /* Stop the heartbeat timers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) SCTP_CMD_TRANSPORT_HB_SENT, /* Reset the status of a transport. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) SCTP_CMD_TRANSPORT_IDLE, /* Do manipulations on idle transport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) SCTP_CMD_TRANSPORT_ON, /* Mark the transport as active. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) SCTP_CMD_REPORT_ERROR, /* Pass this error back out of the sm. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) SCTP_CMD_REPORT_BAD_TAG, /* Verification tags didn't match. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) SCTP_CMD_PROCESS_CTSN, /* Sideeffect from shutdown. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) SCTP_CMD_ASSOC_FAILED, /* Handle association failure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) SCTP_CMD_DISCARD_PACKET, /* Discard the whole packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) SCTP_CMD_GEN_SHUTDOWN, /* Generate a SHUTDOWN chunk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) SCTP_CMD_UPDATE_ASSOC, /* Update association information. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) SCTP_CMD_PURGE_OUTQUEUE, /* Purge all data waiting to be sent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) SCTP_CMD_SETUP_T2, /* Hi-level, setup T2-shutdown parms. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) SCTP_CMD_RTO_PENDING, /* Set transport's rto_pending. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) SCTP_CMD_PART_DELIVER, /* Partial data delivery considerations. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) SCTP_CMD_RENEGE, /* Renege data on an association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) SCTP_CMD_SETUP_T4, /* ADDIP, setup T4 RTO timer parms. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) SCTP_CMD_PROCESS_OPERR, /* Process an ERROR chunk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) SCTP_CMD_REPORT_FWDTSN, /* Report new cumulative TSN Ack. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) SCTP_CMD_PROCESS_FWDTSN, /* Skips were reported, so process further. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) SCTP_CMD_CLEAR_INIT_TAG, /* Clears association peer's inittag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) SCTP_CMD_DEL_NON_PRIMARY, /* Removes non-primary peer transports. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) SCTP_CMD_T3_RTX_TIMERS_STOP, /* Stops T3-rtx pending timers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) SCTP_CMD_FORCE_PRIM_RETRAN, /* Forces retrans. over primary path. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) SCTP_CMD_SET_SK_ERR, /* Set sk_err */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) SCTP_CMD_ASSOC_CHANGE, /* generate and send assoc_change event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) SCTP_CMD_ADAPTATION_IND, /* generate and send adaptation event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) SCTP_CMD_PEER_NO_AUTH, /* generate and send authentication event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) SCTP_CMD_ASSOC_SHKEY, /* generate the association shared keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) SCTP_CMD_T1_RETRAN, /* Mark for retransmission after T1 timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) SCTP_CMD_UPDATE_INITTAG, /* Update peer inittag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) SCTP_CMD_SEND_MSG, /* Send the whole use message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) SCTP_CMD_PURGE_ASCONF_QUEUE, /* Purge all asconf queues.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) SCTP_CMD_SET_ASOC, /* Restore association context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) SCTP_CMD_LAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* How many commands can you put in an struct sctp_cmd_seq?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * This is a rather arbitrary number, ideally derived from a careful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * analysis of the state functions, but in reality just taken from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * thin air in the hopes othat we don't trigger a kernel panic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define SCTP_MAX_NUM_COMMANDS 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) union sctp_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void *zero_all; /* Set to NULL to clear the entire union */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) __s32 i32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) __u32 u32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) __be32 be32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) __u16 u16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) __u8 u8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) __be16 err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) enum sctp_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) enum sctp_event_timeout to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct sctp_bind_addr *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct sctp_init_chunk *init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct sctp_ulpevent *ulpevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct sctp_sackhdr *sackh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct sctp_datamsg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* We are simulating ML type constructors here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * SCTP_ARG_CONSTRUCTOR(NAME, TYPE, ELT) builds a function called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * SCTP_NAME() which takes an argument of type TYPE and returns an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * union sctp_arg. It does this by inserting the sole argument into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * the ELT union element of a local union sctp_arg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * E.g., SCTP_ARG_CONSTRUCTOR(I32, __s32, i32) builds SCTP_I32(arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * which takes an __s32 and returns a union sctp_arg containing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * __s32. So, after foo = SCTP_I32(arg), foo.i32 == arg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define SCTP_ARG_CONSTRUCTOR(name, type, elt) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static inline union sctp_arg \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) SCTP_## name (type arg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) { union sctp_arg retval;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) retval.zero_all = NULL;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) retval.elt = arg;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return retval;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) SCTP_ARG_CONSTRUCTOR(I32, __s32, i32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) SCTP_ARG_CONSTRUCTOR(U32, __u32, u32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) SCTP_ARG_CONSTRUCTOR(BE32, __be32, be32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) SCTP_ARG_CONSTRUCTOR(U16, __u16, u16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) SCTP_ARG_CONSTRUCTOR(U8, __u8, u8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) SCTP_ARG_CONSTRUCTOR(ERROR, int, error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) SCTP_ARG_CONSTRUCTOR(PERR, __be16, err) /* protocol error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) SCTP_ARG_CONSTRUCTOR(STATE, enum sctp_state, state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) SCTP_ARG_CONSTRUCTOR(TO, enum sctp_event_timeout, to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) SCTP_ARG_CONSTRUCTOR(CHUNK, struct sctp_chunk *, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) SCTP_ARG_CONSTRUCTOR(ASOC, struct sctp_association *, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) SCTP_ARG_CONSTRUCTOR(TRANSPORT, struct sctp_transport *, transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) SCTP_ARG_CONSTRUCTOR(BA, struct sctp_bind_addr *, bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) SCTP_ARG_CONSTRUCTOR(PEER_INIT, struct sctp_init_chunk *, init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) SCTP_ARG_CONSTRUCTOR(ULPEVENT, struct sctp_ulpevent *, ulpevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) SCTP_ARG_CONSTRUCTOR(PACKET, struct sctp_packet *, packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) SCTP_ARG_CONSTRUCTOR(SACKH, struct sctp_sackhdr *, sackh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) SCTP_ARG_CONSTRUCTOR(DATAMSG, struct sctp_datamsg *, msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static inline union sctp_arg SCTP_FORCE(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return SCTP_I32(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static inline union sctp_arg SCTP_NOFORCE(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return SCTP_I32(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static inline union sctp_arg SCTP_NULL(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) union sctp_arg retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) retval.zero_all = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct sctp_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) union sctp_arg obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) enum sctp_verb verb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct sctp_cmd_seq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct sctp_cmd cmds[SCTP_MAX_NUM_COMMANDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct sctp_cmd *last_used_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct sctp_cmd *next_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* Initialize a block of memory as a command sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * Return 0 if the initialization fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static inline int sctp_init_cmd_seq(struct sctp_cmd_seq *seq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* cmds[] is filled backwards to simplify the overflow BUG() check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) seq->last_used_slot = seq->cmds + SCTP_MAX_NUM_COMMANDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) seq->next_cmd = seq->last_used_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return 1; /* We always succeed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* Add a command to an struct sctp_cmd_seq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * Use the SCTP_* constructors defined by SCTP_ARG_CONSTRUCTOR() above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * to wrap data which goes in the obj argument.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static inline void sctp_add_cmd_sf(struct sctp_cmd_seq *seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) enum sctp_verb verb, union sctp_arg obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct sctp_cmd *cmd = seq->last_used_slot - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) BUG_ON(cmd < seq->cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) cmd->verb = verb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) cmd->obj = obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) seq->last_used_slot = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* Return the next command structure in an sctp_cmd_seq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * Return NULL at the end of the sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static inline struct sctp_cmd *sctp_next_cmd(struct sctp_cmd_seq *seq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (seq->next_cmd <= seq->last_used_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return --seq->next_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #endif /* __net_sctp_command_h__ */