command.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SCTP kernel implementation Copyright (C) 1999-2001
  2. * Cisco, Motorola, and IBM
  3. * Copyright 2001 La Monte H.P. Yarroll
  4. *
  5. * This file is part of the SCTP kernel implementation
  6. *
  7. * These functions manipulate sctp command sequences.
  8. *
  9. * This SCTP 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. * This SCTP 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, see
  23. * <http://www.gnu.org/licenses/>.
  24. *
  25. * Please send any bug reports or fixes you make to the
  26. * email address(es):
  27. * lksctp developers <linux-sctp@vger.kernel.org>
  28. *
  29. * Written or modified by:
  30. * La Monte H.P. Yarroll <piggy@acm.org>
  31. * Karl Knutson <karl@athena.chicago.il.us>
  32. */
  33. #include <linux/types.h>
  34. #include <net/sctp/sctp.h>
  35. #include <net/sctp/sm.h>
  36. /* Initialize a block of memory as a command sequence. */
  37. int sctp_init_cmd_seq(sctp_cmd_seq_t *seq)
  38. {
  39. memset(seq, 0, sizeof(sctp_cmd_seq_t));
  40. return 1; /* We always succeed. */
  41. }
  42. /* Add a command to a sctp_cmd_seq_t.
  43. * Return 0 if the command sequence is full.
  44. */
  45. void sctp_add_cmd_sf(sctp_cmd_seq_t *seq, sctp_verb_t verb, sctp_arg_t obj)
  46. {
  47. BUG_ON(seq->next_free_slot >= SCTP_MAX_NUM_COMMANDS);
  48. seq->cmds[seq->next_free_slot].verb = verb;
  49. seq->cmds[seq->next_free_slot++].obj = obj;
  50. }
  51. /* Return the next command structure in a sctp_cmd_seq.
  52. * Returns NULL at the end of the sequence.
  53. */
  54. sctp_cmd_t *sctp_next_cmd(sctp_cmd_seq_t *seq)
  55. {
  56. sctp_cmd_t *retval = NULL;
  57. if (seq->next_cmd < seq->next_free_slot)
  58. retval = &seq->cmds[seq->next_cmd++];
  59. return retval;
  60. }