port.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * net/tipc/port.h: Include file for TIPC port code
  3. *
  4. * Copyright (c) 2003-2005, Ericsson Research Canada
  5. * Copyright (c) 2004-2005, Wind River Systems
  6. * Copyright (c) 2005-2006, Ericsson AB
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #ifndef _TIPC_PORT_H
  34. #define _TIPC_PORT_H
  35. #include <net/tipc/tipc_port.h>
  36. #include "ref.h"
  37. #include "net.h"
  38. #include "msg.h"
  39. #include "dbg.h"
  40. #include "node_subscr.h"
  41. /**
  42. * struct user_port - TIPC user port (used with native API)
  43. * @user_ref: id of user who created user port
  44. * @usr_handle: user-specified field
  45. * @ref: object reference to associated TIPC port
  46. * <various callback routines>
  47. * @uport_list: adjacent user ports in list of ports held by user
  48. */
  49. struct user_port {
  50. u32 user_ref;
  51. void *usr_handle;
  52. u32 ref;
  53. tipc_msg_err_event err_cb;
  54. tipc_named_msg_err_event named_err_cb;
  55. tipc_conn_shutdown_event conn_err_cb;
  56. tipc_msg_event msg_cb;
  57. tipc_named_msg_event named_msg_cb;
  58. tipc_conn_msg_event conn_msg_cb;
  59. tipc_continue_event continue_event_cb;
  60. struct list_head uport_list;
  61. };
  62. /**
  63. * struct port - TIPC port structure
  64. * @publ: TIPC port info available to privileged users
  65. * @port_list: adjacent ports in TIPC's global list of ports
  66. * @dispatcher: ptr to routine which handles received messages
  67. * @wakeup: ptr to routine to call when port is no longer congested
  68. * @user_port: ptr to user port associated with port (if any)
  69. * @wait_list: adjacent ports in list of ports waiting on link congestion
  70. * @congested_link: ptr to congested link port is waiting on
  71. * @waiting_pkts:
  72. * @sent:
  73. * @acked:
  74. * @publications: list of publications for port
  75. * @pub_count: total # of publications port has made during its lifetime
  76. * @max_pkt: maximum packet size "hint" used when building messages sent by port
  77. * @probing_state:
  78. * @probing_interval:
  79. * @last_in_seqno:
  80. * @timer_ref:
  81. * @subscription: "node down" subscription used to terminate failed connections
  82. */
  83. struct port {
  84. struct tipc_port publ;
  85. struct list_head port_list;
  86. u32 (*dispatcher)(struct tipc_port *, struct sk_buff *);
  87. void (*wakeup)(struct tipc_port *);
  88. struct user_port *user_port;
  89. struct list_head wait_list;
  90. struct link *congested_link;
  91. u32 waiting_pkts;
  92. u32 sent;
  93. u32 acked;
  94. struct list_head publications;
  95. u32 pub_count;
  96. u32 max_pkt;
  97. u32 probing_state;
  98. u32 probing_interval;
  99. u32 last_in_seqno;
  100. struct timer_list timer;
  101. struct node_subscr subscription;
  102. };
  103. extern spinlock_t port_list_lock;
  104. struct port_list;
  105. int port_recv_sections(struct port *p_ptr, u32 num_sect,
  106. struct iovec const *msg_sect);
  107. int port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr,
  108. struct iovec const *msg_sect, u32 num_sect,
  109. int err);
  110. struct sk_buff *port_get_ports(void);
  111. struct sk_buff *port_show_stats(const void *req_tlv_area, int req_tlv_space);
  112. void port_recv_proto_msg(struct sk_buff *buf);
  113. void port_recv_mcast(struct sk_buff *buf, struct port_list *dp);
  114. void port_reinit(void);
  115. /**
  116. * port_lock - lock port instance referred to and return its pointer
  117. */
  118. static inline struct port *port_lock(u32 ref)
  119. {
  120. return (struct port *)ref_lock(ref);
  121. }
  122. /**
  123. * port_unlock - unlock a port instance
  124. *
  125. * Can use pointer instead of ref_unlock() since port is already locked.
  126. */
  127. static inline void port_unlock(struct port *p_ptr)
  128. {
  129. spin_unlock_bh(p_ptr->publ.lock);
  130. }
  131. static inline struct port* port_deref(u32 ref)
  132. {
  133. return (struct port *)ref_deref(ref);
  134. }
  135. static inline u32 peer_port(struct port *p_ptr)
  136. {
  137. return msg_destport(&p_ptr->publ.phdr);
  138. }
  139. static inline u32 peer_node(struct port *p_ptr)
  140. {
  141. return msg_destnode(&p_ptr->publ.phdr);
  142. }
  143. static inline int port_congested(struct port *p_ptr)
  144. {
  145. return((p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2));
  146. }
  147. /**
  148. * port_recv_msg - receive message from lower layer and deliver to port user
  149. */
  150. static inline int port_recv_msg(struct sk_buff *buf)
  151. {
  152. struct port *p_ptr;
  153. struct tipc_msg *msg = buf_msg(buf);
  154. u32 destport = msg_destport(msg);
  155. u32 dsz = msg_data_sz(msg);
  156. u32 err;
  157. /* forward unresolved named message */
  158. if (unlikely(!destport)) {
  159. net_route_msg(buf);
  160. return dsz;
  161. }
  162. /* validate destination & pass to port, otherwise reject message */
  163. p_ptr = port_lock(destport);
  164. if (likely(p_ptr)) {
  165. if (likely(p_ptr->publ.connected)) {
  166. if ((unlikely(msg_origport(msg) != peer_port(p_ptr))) ||
  167. (unlikely(msg_orignode(msg) != peer_node(p_ptr))) ||
  168. (unlikely(!msg_connected(msg)))) {
  169. err = TIPC_ERR_NO_PORT;
  170. port_unlock(p_ptr);
  171. goto reject;
  172. }
  173. }
  174. err = p_ptr->dispatcher(&p_ptr->publ, buf);
  175. port_unlock(p_ptr);
  176. if (likely(!err))
  177. return dsz;
  178. } else {
  179. err = TIPC_ERR_NO_PORT;
  180. }
  181. reject:
  182. dbg("port->rejecting, err = %x..\n",err);
  183. return tipc_reject_msg(buf, err);
  184. }
  185. #endif