ulpevent.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* SCTP kernel implementation
  2. * (C) Copyright IBM Corp. 2001, 2004
  3. * Copyright (c) 1999-2000 Cisco, Inc.
  4. * Copyright (c) 1999-2001 Motorola, Inc.
  5. * Copyright (c) 2001 Intel Corp.
  6. * Copyright (c) 2001 Nokia, Inc.
  7. * Copyright (c) 2001 La Monte H.P. Yarroll
  8. *
  9. * These are the definitions needed for the sctp_ulpevent type. The
  10. * sctp_ulpevent type is used to carry information from the state machine
  11. * upwards to the ULP.
  12. *
  13. * This file is part of the SCTP kernel implementation
  14. *
  15. * This SCTP implementation is free software;
  16. * you can redistribute it and/or modify it under the terms of
  17. * the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2, or (at your option)
  19. * any later version.
  20. *
  21. * This SCTP implementation is distributed in the hope that it
  22. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  23. * ************************
  24. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. * See the GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with GNU CC; see the file COPYING. If not, see
  29. * <http://www.gnu.org/licenses/>.
  30. *
  31. * Please send any bug reports or fixes you make to the
  32. * email address(es):
  33. * lksctp developers <linux-sctp@vger.kernel.org>
  34. *
  35. * Written or modified by:
  36. * Jon Grimm <jgrimm@us.ibm.com>
  37. * La Monte H.P. Yarroll <piggy@acm.org>
  38. * Karl Knutson <karl@athena.chicago.il.us>
  39. * Sridhar Samudrala <sri@us.ibm.com>
  40. */
  41. #ifndef __sctp_ulpevent_h__
  42. #define __sctp_ulpevent_h__
  43. /* A structure to carry information to the ULP (e.g. Sockets API) */
  44. /* Warning: This sits inside an skb.cb[] area. Be very careful of
  45. * growing this structure as it is at the maximum limit now.
  46. */
  47. struct sctp_ulpevent {
  48. struct sctp_association *asoc;
  49. struct sctp_chunk *chunk;
  50. unsigned int rmem_len;
  51. __u32 ppid;
  52. __u32 tsn;
  53. __u32 cumtsn;
  54. __u16 stream;
  55. __u16 ssn;
  56. __u16 flags;
  57. __u16 msg_flags;
  58. };
  59. /* Retrieve the skb this event sits inside of. */
  60. static inline struct sk_buff *sctp_event2skb(const struct sctp_ulpevent *ev)
  61. {
  62. return container_of((void *)ev, struct sk_buff, cb);
  63. }
  64. /* Retrieve & cast the event sitting inside the skb. */
  65. static inline struct sctp_ulpevent *sctp_skb2event(struct sk_buff *skb)
  66. {
  67. return (struct sctp_ulpevent *)skb->cb;
  68. }
  69. void sctp_ulpevent_free(struct sctp_ulpevent *);
  70. int sctp_ulpevent_is_notification(const struct sctp_ulpevent *);
  71. unsigned int sctp_queue_purge_ulpevents(struct sk_buff_head *list);
  72. struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
  73. const struct sctp_association *asoc,
  74. __u16 flags,
  75. __u16 state,
  76. __u16 error,
  77. __u16 outbound,
  78. __u16 inbound,
  79. struct sctp_chunk *chunk,
  80. gfp_t gfp);
  81. struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
  82. const struct sctp_association *asoc,
  83. const struct sockaddr_storage *aaddr,
  84. int flags,
  85. int state,
  86. int error,
  87. gfp_t gfp);
  88. struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
  89. const struct sctp_association *asoc,
  90. struct sctp_chunk *chunk,
  91. __u16 flags,
  92. gfp_t gfp);
  93. struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
  94. const struct sctp_association *asoc,
  95. struct sctp_chunk *chunk,
  96. __u16 flags,
  97. __u32 error,
  98. gfp_t gfp);
  99. struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
  100. const struct sctp_association *asoc,
  101. __u16 flags,
  102. gfp_t gfp);
  103. struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
  104. const struct sctp_association *asoc,
  105. __u32 indication, gfp_t gfp);
  106. struct sctp_ulpevent *sctp_ulpevent_make_adaptation_indication(
  107. const struct sctp_association *asoc, gfp_t gfp);
  108. struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
  109. struct sctp_chunk *chunk,
  110. gfp_t gfp);
  111. struct sctp_ulpevent *sctp_ulpevent_make_authkey(
  112. const struct sctp_association *asoc, __u16 key_id,
  113. __u32 indication, gfp_t gfp);
  114. struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event(
  115. const struct sctp_association *asoc, gfp_t gfp);
  116. struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event(
  117. const struct sctp_association *asoc, __u16 flags,
  118. __u16 stream_num, __be16 *stream_list, gfp_t gfp);
  119. struct sctp_ulpevent *sctp_ulpevent_make_assoc_reset_event(
  120. const struct sctp_association *asoc, __u16 flags,
  121. __u32 local_tsn, __u32 remote_tsn, gfp_t gfp);
  122. struct sctp_ulpevent *sctp_ulpevent_make_stream_change_event(
  123. const struct sctp_association *asoc, __u16 flags,
  124. __u32 strchange_instrms, __u32 strchange_outstrms, gfp_t gfp);
  125. void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
  126. struct msghdr *);
  127. void sctp_ulpevent_read_rcvinfo(const struct sctp_ulpevent *event,
  128. struct msghdr *);
  129. void sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event,
  130. struct msghdr *, struct sock *sk);
  131. __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event);
  132. /* Is this event type enabled? */
  133. static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
  134. struct sctp_event_subscribe *mask)
  135. {
  136. int offset = sn_type - SCTP_SN_TYPE_BASE;
  137. char *amask = (char *) mask;
  138. if (offset >= sizeof(struct sctp_event_subscribe))
  139. return 0;
  140. return amask[offset];
  141. }
  142. /* Given an event subscription, is this event enabled? */
  143. static inline int sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
  144. struct sctp_event_subscribe *mask)
  145. {
  146. __u16 sn_type;
  147. int enabled = 1;
  148. if (sctp_ulpevent_is_notification(event)) {
  149. sn_type = sctp_ulpevent_get_notification_type(event);
  150. enabled = sctp_ulpevent_type_enabled(sn_type, mask);
  151. }
  152. return enabled;
  153. }
  154. #endif /* __sctp_ulpevent_h__ */