ulpevent.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. * sctp_ulpevent is saved in sk->cb(48 bytes), whose last 4 bytes
  48. * have been taken by sock_skb_cb, So here it has to use 'packed'
  49. * to make sctp_ulpevent fit into the rest 44 bytes.
  50. */
  51. struct sctp_ulpevent {
  52. struct sctp_association *asoc;
  53. struct sctp_chunk *chunk;
  54. unsigned int rmem_len;
  55. union {
  56. __u32 mid;
  57. __u16 ssn;
  58. };
  59. union {
  60. __u32 ppid;
  61. __u32 fsn;
  62. };
  63. __u32 tsn;
  64. __u32 cumtsn;
  65. __u16 stream;
  66. __u16 flags;
  67. __u16 msg_flags;
  68. } __packed;
  69. /* Retrieve the skb this event sits inside of. */
  70. static inline struct sk_buff *sctp_event2skb(const struct sctp_ulpevent *ev)
  71. {
  72. return container_of((void *)ev, struct sk_buff, cb);
  73. }
  74. /* Retrieve & cast the event sitting inside the skb. */
  75. static inline struct sctp_ulpevent *sctp_skb2event(struct sk_buff *skb)
  76. {
  77. return (struct sctp_ulpevent *)skb->cb;
  78. }
  79. void sctp_ulpevent_free(struct sctp_ulpevent *);
  80. int sctp_ulpevent_is_notification(const struct sctp_ulpevent *);
  81. unsigned int sctp_queue_purge_ulpevents(struct sk_buff_head *list);
  82. struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
  83. const struct sctp_association *asoc,
  84. __u16 flags,
  85. __u16 state,
  86. __u16 error,
  87. __u16 outbound,
  88. __u16 inbound,
  89. struct sctp_chunk *chunk,
  90. gfp_t gfp);
  91. struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
  92. const struct sctp_association *asoc,
  93. const struct sockaddr_storage *aaddr,
  94. int flags,
  95. int state,
  96. int error,
  97. gfp_t gfp);
  98. struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
  99. const struct sctp_association *asoc,
  100. struct sctp_chunk *chunk,
  101. __u16 flags,
  102. gfp_t gfp);
  103. struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
  104. const struct sctp_association *asoc,
  105. struct sctp_chunk *chunk,
  106. __u16 flags,
  107. __u32 error,
  108. gfp_t gfp);
  109. struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
  110. const struct sctp_association *asoc,
  111. __u16 flags,
  112. gfp_t gfp);
  113. struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
  114. const struct sctp_association *asoc,
  115. __u32 indication, __u32 sid, __u32 seq,
  116. __u32 flags, gfp_t gfp);
  117. struct sctp_ulpevent *sctp_ulpevent_make_adaptation_indication(
  118. const struct sctp_association *asoc, gfp_t gfp);
  119. struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
  120. struct sctp_chunk *chunk,
  121. gfp_t gfp);
  122. struct sctp_ulpevent *sctp_ulpevent_make_authkey(
  123. const struct sctp_association *asoc, __u16 key_id,
  124. __u32 indication, gfp_t gfp);
  125. struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event(
  126. const struct sctp_association *asoc, gfp_t gfp);
  127. struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event(
  128. const struct sctp_association *asoc, __u16 flags,
  129. __u16 stream_num, __be16 *stream_list, gfp_t gfp);
  130. struct sctp_ulpevent *sctp_ulpevent_make_assoc_reset_event(
  131. const struct sctp_association *asoc, __u16 flags,
  132. __u32 local_tsn, __u32 remote_tsn, gfp_t gfp);
  133. struct sctp_ulpevent *sctp_ulpevent_make_stream_change_event(
  134. const struct sctp_association *asoc, __u16 flags,
  135. __u32 strchange_instrms, __u32 strchange_outstrms, gfp_t gfp);
  136. struct sctp_ulpevent *sctp_make_reassembled_event(
  137. struct net *net, struct sk_buff_head *queue,
  138. struct sk_buff *f_frag, struct sk_buff *l_frag);
  139. void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
  140. struct msghdr *);
  141. void sctp_ulpevent_read_rcvinfo(const struct sctp_ulpevent *event,
  142. struct msghdr *);
  143. void sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event,
  144. struct msghdr *, struct sock *sk);
  145. __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event);
  146. /* Is this event type enabled? */
  147. static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
  148. struct sctp_event_subscribe *mask)
  149. {
  150. int offset = sn_type - SCTP_SN_TYPE_BASE;
  151. char *amask = (char *) mask;
  152. if (offset >= sizeof(struct sctp_event_subscribe))
  153. return 0;
  154. return amask[offset];
  155. }
  156. /* Given an event subscription, is this event enabled? */
  157. static inline int sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
  158. struct sctp_event_subscribe *mask)
  159. {
  160. __u16 sn_type;
  161. int enabled = 1;
  162. if (sctp_ulpevent_is_notification(event)) {
  163. sn_type = sctp_ulpevent_get_notification_type(event);
  164. enabled = sctp_ulpevent_type_enabled(sn_type, mask);
  165. }
  166. return enabled;
  167. }
  168. #endif /* __sctp_ulpevent_h__ */