1
0

sctp.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Stream Control Transmission Protocol (RFC 2960).
  3. *
  4. * Copyright (c) 2008 Daniel Roethlisberger <daniel@roe.ch>
  5. * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  6. *
  7. */
  8. #ifndef SCTP_H
  9. #define SCTP_H
  10. #define SCTP_HDR_LEN 12
  11. struct sctp_hdr {
  12. uint16_t sh_sport; /* source port */
  13. uint16_t sh_dport; /* destination port */
  14. uint32_t sh_vtag; /* sctp verification tag */
  15. uint32_t sh_sum; /* sctp checksum */
  16. };
  17. #define SCTP_PORT_MAX 65535
  18. #define sctp_pack_hdr(hdr, sport, dport, vtag) do { \
  19. struct sctp_hdr *sctp_pack_p = (struct sctp_hdr *)(hdr); \
  20. sctp_pack_p->sh_sport = htons(sport); \
  21. sctp_pack_p->sh_dport = htons(dport); \
  22. sctp_pack_p->sh_vtag = htonl(vtag); \
  23. } while (0)
  24. struct sctp_chunkhdr {
  25. uint8_t sch_type; /* chunk type */
  26. uint8_t sch_flags; /* chunk flags */
  27. uint16_t sch_length; /* chunk length */
  28. };
  29. /* chunk types */
  30. #define SCTP_DATA 0x00
  31. #define SCTP_INIT 0x01
  32. #define SCTP_INIT_ACK 0x02
  33. #define SCTP_SACK 0x03
  34. #define SCTP_HEARTBEAT 0x04
  35. #define SCTP_HEARTBEAT_ACK 0x05
  36. #define SCTP_ABORT 0x06
  37. #define SCTP_SHUTDOWN 0x07
  38. #define SCTP_SHUTDOWN_ACK 0x08
  39. #define SCTP_ERROR 0x09
  40. #define SCTP_COOKIE_ECHO 0x0a
  41. #define SCTP_COOKIE_ACK 0x0b
  42. #define SCTP_ECNE 0x0c
  43. #define SCTP_CWR 0x0d
  44. #define SCTP_SHUTDOWN_COMPLETE 0x0e
  45. #define SCTP_AUTH 0x0f /* RFC 4895 */
  46. #define SCTP_ASCONF_ACK 0x80 /* RFC 5061 */
  47. #define SCTP_PKTDROP 0x81 /* draft-stewart-sctp-pktdrprep-08 */
  48. #define SCTP_PAD 0x84 /* RFC 4820 */
  49. #define SCTP_FORWARD_TSN 0xc0 /* RFC 3758 */
  50. #define SCTP_ASCONF 0xc1 /* RFC 5061 */
  51. /* chunk types bitmask flags */
  52. #define SCTP_TYPEFLAG_REPORT 1
  53. #define SCTP_TYPEFLAG_SKIP 2
  54. #define sctp_pack_chunkhdr(hdr, type, flags, length) do { \
  55. struct sctp_chunkhdr *sctp_pack_chp = (struct sctp_chunkhdr *)(hdr);\
  56. sctp_pack_chp->sch_type = type; \
  57. sctp_pack_chp->sch_flags = flags; \
  58. sctp_pack_chp->sch_length = htons(length); \
  59. } while (0)
  60. struct sctp_chunkhdr_init {
  61. struct sctp_chunkhdr chunkhdr;
  62. int32_t schi_itag; /* Initiate Tag */
  63. int32_t schi_arwnd; /* Advertised Receiver Window Credit */
  64. int16_t schi_nos; /* Number of Outbound Streams */
  65. int16_t schi_nis; /* Number of Inbound Streams */
  66. int32_t schi_itsn; /* Initial TSN */
  67. };
  68. #define sctp_pack_chunkhdr_init(hdr, type, flags, length, itag, \
  69. arwnd, nos, nis, itsn) do { \
  70. struct sctp_chunkhdr_init *sctp_pack_chip = (struct sctp_chunkhdr_init *)(hdr);\
  71. sctp_pack_chunkhdr(sctp_pack_chip, type, flags, length);\
  72. sctp_pack_chip->schi_itag = htonl(itag); \
  73. sctp_pack_chip->schi_arwnd = htonl(arwnd); \
  74. sctp_pack_chip->schi_nos = htons(nos); \
  75. sctp_pack_chip->schi_nis = htons(nis); \
  76. sctp_pack_chip->schi_itsn = htonl(itsn); \
  77. } while (0)
  78. /*
  79. * COOKIE ECHO chunk
  80. */
  81. struct sctp_chunkhdr_cookie_echo {
  82. struct sctp_chunkhdr chunkhdr;
  83. /* empty */
  84. };
  85. #define sctp_pack_chunkhdr_cookie_echo(hdr, type, flags, length) do { \
  86. struct sctp_chunkhdr_cookie_echo *sctp_pack_chip = \
  87. (struct sctp_chunkhdr_cookie_echo *)(hdr); \
  88. sctp_pack_chunkhdr(sctp_pack_chip, type, flags, length); \
  89. } while (0)
  90. #endif /* SCTP_H */