ulpevent.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* SCTP kernel implementation
  3. * (C) Copyright IBM Corp. 2001, 2004
  4. * Copyright (c) 1999-2000 Cisco, Inc.
  5. * Copyright (c) 1999-2001 Motorola, Inc.
  6. * Copyright (c) 2001 Intel Corp.
  7. * Copyright (c) 2001 Nokia, Inc.
  8. * Copyright (c) 2001 La Monte H.P. Yarroll
  9. *
  10. * These are the definitions needed for the sctp_ulpevent type. The
  11. * sctp_ulpevent type is used to carry information from the state machine
  12. * upwards to the ULP.
  13. *
  14. * This file is part of the SCTP kernel implementation
  15. *
  16. * Please send any bug reports or fixes you make to the
  17. * email address(es):
  18. * lksctp developers <[email protected]>
  19. *
  20. * Written or modified by:
  21. * Jon Grimm <[email protected]>
  22. * La Monte H.P. Yarroll <[email protected]>
  23. * Karl Knutson <[email protected]>
  24. * Sridhar Samudrala <[email protected]>
  25. */
  26. #ifndef __sctp_ulpevent_h__
  27. #define __sctp_ulpevent_h__
  28. /* A structure to carry information to the ULP (e.g. Sockets API) */
  29. /* Warning: This sits inside an skb.cb[] area. Be very careful of
  30. * growing this structure as it is at the maximum limit now.
  31. *
  32. * sctp_ulpevent is saved in sk->cb(48 bytes), whose last 4 bytes
  33. * have been taken by sock_skb_cb, So here it has to use 'packed'
  34. * to make sctp_ulpevent fit into the rest 44 bytes.
  35. */
  36. struct sctp_ulpevent {
  37. struct sctp_association *asoc;
  38. struct sctp_chunk *chunk;
  39. unsigned int rmem_len;
  40. union {
  41. __u32 mid;
  42. __u16 ssn;
  43. };
  44. union {
  45. __u32 ppid;
  46. __u32 fsn;
  47. };
  48. __u32 tsn;
  49. __u32 cumtsn;
  50. __u16 stream;
  51. __u16 flags;
  52. __u16 msg_flags;
  53. } __packed;
  54. /* Retrieve the skb this event sits inside of. */
  55. static inline struct sk_buff *sctp_event2skb(const struct sctp_ulpevent *ev)
  56. {
  57. return container_of((void *)ev, struct sk_buff, cb);
  58. }
  59. /* Retrieve & cast the event sitting inside the skb. */
  60. static inline struct sctp_ulpevent *sctp_skb2event(struct sk_buff *skb)
  61. {
  62. return (struct sctp_ulpevent *)skb->cb;
  63. }
  64. void sctp_ulpevent_free(struct sctp_ulpevent *);
  65. int sctp_ulpevent_is_notification(const struct sctp_ulpevent *);
  66. unsigned int sctp_queue_purge_ulpevents(struct sk_buff_head *list);
  67. struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
  68. const struct sctp_association *asoc,
  69. __u16 flags,
  70. __u16 state,
  71. __u16 error,
  72. __u16 outbound,
  73. __u16 inbound,
  74. struct sctp_chunk *chunk,
  75. gfp_t gfp);
  76. void sctp_ulpevent_notify_peer_addr_change(struct sctp_transport *transport,
  77. int state, int error);
  78. struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
  79. const struct sctp_association *asoc,
  80. struct sctp_chunk *chunk,
  81. __u16 flags,
  82. gfp_t gfp);
  83. struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
  84. const struct sctp_association *asoc,
  85. struct sctp_chunk *chunk,
  86. __u16 flags,
  87. __u32 error,
  88. gfp_t gfp);
  89. struct sctp_ulpevent *sctp_ulpevent_make_send_failed_event(
  90. const struct sctp_association *asoc,
  91. struct sctp_chunk *chunk,
  92. __u16 flags,
  93. __u32 error,
  94. gfp_t gfp);
  95. struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
  96. const struct sctp_association *asoc,
  97. __u16 flags,
  98. gfp_t gfp);
  99. struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
  100. const struct sctp_association *asoc,
  101. __u32 indication, __u32 sid, __u32 seq,
  102. __u32 flags, gfp_t gfp);
  103. struct sctp_ulpevent *sctp_ulpevent_make_adaptation_indication(
  104. const struct sctp_association *asoc, gfp_t gfp);
  105. struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
  106. struct sctp_chunk *chunk,
  107. gfp_t gfp);
  108. struct sctp_ulpevent *sctp_ulpevent_make_authkey(
  109. const struct sctp_association *asoc, __u16 key_id,
  110. __u32 indication, gfp_t gfp);
  111. struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event(
  112. const struct sctp_association *asoc, gfp_t gfp);
  113. struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event(
  114. const struct sctp_association *asoc, __u16 flags,
  115. __u16 stream_num, __be16 *stream_list, gfp_t gfp);
  116. struct sctp_ulpevent *sctp_ulpevent_make_assoc_reset_event(
  117. const struct sctp_association *asoc, __u16 flags,
  118. __u32 local_tsn, __u32 remote_tsn, gfp_t gfp);
  119. struct sctp_ulpevent *sctp_ulpevent_make_stream_change_event(
  120. const struct sctp_association *asoc, __u16 flags,
  121. __u32 strchange_instrms, __u32 strchange_outstrms, gfp_t gfp);
  122. struct sctp_ulpevent *sctp_make_reassembled_event(
  123. struct net *net, struct sk_buff_head *queue,
  124. struct sk_buff *f_frag, struct sk_buff *l_frag);
  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. static inline void sctp_ulpevent_type_set(__u16 *subscribe,
  133. __u16 sn_type, __u8 on)
  134. {
  135. if (sn_type > SCTP_SN_TYPE_MAX)
  136. return;
  137. if (on)
  138. *subscribe |= (1 << (sn_type - SCTP_SN_TYPE_BASE));
  139. else
  140. *subscribe &= ~(1 << (sn_type - SCTP_SN_TYPE_BASE));
  141. }
  142. /* Is this event type enabled? */
  143. static inline bool sctp_ulpevent_type_enabled(__u16 subscribe, __u16 sn_type)
  144. {
  145. if (sn_type > SCTP_SN_TYPE_MAX)
  146. return false;
  147. return subscribe & (1 << (sn_type - SCTP_SN_TYPE_BASE));
  148. }
  149. /* Given an event subscription, is this event enabled? */
  150. static inline bool sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
  151. __u16 subscribe)
  152. {
  153. __u16 sn_type;
  154. if (!sctp_ulpevent_is_notification(event))
  155. return true;
  156. sn_type = sctp_ulpevent_get_notification_type(event);
  157. return sctp_ulpevent_type_enabled(subscribe, sn_type);
  158. }
  159. #endif /* __sctp_ulpevent_h__ */