iw_portmap.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Copyright (c) 2014 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2014 Chelsio, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #ifndef _IW_PORTMAP_H
  34. #define _IW_PORTMAP_H
  35. #define IWPM_ULIBNAME_SIZE 32
  36. #define IWPM_DEVNAME_SIZE 32
  37. #define IWPM_IFNAME_SIZE 16
  38. #define IWPM_IPADDR_SIZE 16
  39. enum {
  40. IWPM_INVALID_NLMSG_ERR = 10,
  41. IWPM_CREATE_MAPPING_ERR,
  42. IWPM_DUPLICATE_MAPPING_ERR,
  43. IWPM_UNKNOWN_MAPPING_ERR,
  44. IWPM_CLIENT_DEV_INFO_ERR,
  45. IWPM_USER_LIB_INFO_ERR,
  46. IWPM_REMOTE_QUERY_REJECT
  47. };
  48. struct iwpm_dev_data {
  49. char dev_name[IWPM_DEVNAME_SIZE];
  50. char if_name[IWPM_IFNAME_SIZE];
  51. };
  52. struct iwpm_sa_data {
  53. struct sockaddr_storage loc_addr;
  54. struct sockaddr_storage mapped_loc_addr;
  55. struct sockaddr_storage rem_addr;
  56. struct sockaddr_storage mapped_rem_addr;
  57. };
  58. /**
  59. * iwpm_init - Allocate resources for the iwarp port mapper
  60. *
  61. * Should be called when network interface goes up.
  62. */
  63. int iwpm_init(u8);
  64. /**
  65. * iwpm_exit - Deallocate resources for the iwarp port mapper
  66. *
  67. * Should be called when network interface goes down.
  68. */
  69. int iwpm_exit(u8);
  70. /**
  71. * iwpm_valid_pid - Check if the userspace iwarp port mapper pid is valid
  72. *
  73. * Returns true if the pid is greater than zero, otherwise returns false
  74. */
  75. int iwpm_valid_pid(void);
  76. /**
  77. * iwpm_register_pid - Send a netlink query to userspace
  78. * to get the iwarp port mapper pid
  79. * @pm_msg: Contains driver info to send to the userspace port mapper
  80. * @nl_client: The index of the netlink client
  81. */
  82. int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client);
  83. /**
  84. * iwpm_add_mapping - Send a netlink add mapping request to
  85. * the userspace port mapper
  86. * @pm_msg: Contains the local ip/tcp address info to send
  87. * @nl_client: The index of the netlink client
  88. *
  89. * If the request is successful, the pm_msg stores
  90. * the port mapper response (mapped address info)
  91. */
  92. int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client);
  93. /**
  94. * iwpm_add_and_query_mapping - Send a netlink add and query mapping request
  95. * to the userspace port mapper
  96. * @pm_msg: Contains the local and remote ip/tcp address info to send
  97. * @nl_client: The index of the netlink client
  98. *
  99. * If the request is successful, the pm_msg stores the
  100. * port mapper response (mapped local and remote address info)
  101. */
  102. int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client);
  103. /**
  104. * iwpm_remove_mapping - Send a netlink remove mapping request
  105. * to the userspace port mapper
  106. *
  107. * @local_addr: Local ip/tcp address to remove
  108. * @nl_client: The index of the netlink client
  109. */
  110. int iwpm_remove_mapping(struct sockaddr_storage *local_addr, u8 nl_client);
  111. /**
  112. * iwpm_register_pid_cb - Process the port mapper response to
  113. * iwpm_register_pid query
  114. * @skb:
  115. * @cb: Contains the received message (payload and netlink header)
  116. *
  117. * If successful, the function receives the userspace port mapper pid
  118. * which is used in future communication with the port mapper
  119. */
  120. int iwpm_register_pid_cb(struct sk_buff *, struct netlink_callback *);
  121. /**
  122. * iwpm_add_mapping_cb - Process the port mapper response to
  123. * iwpm_add_mapping request
  124. * @skb:
  125. * @cb: Contains the received message (payload and netlink header)
  126. */
  127. int iwpm_add_mapping_cb(struct sk_buff *, struct netlink_callback *);
  128. /**
  129. * iwpm_add_and_query_mapping_cb - Process the port mapper response to
  130. * iwpm_add_and_query_mapping request
  131. * @skb:
  132. * @cb: Contains the received message (payload and netlink header)
  133. */
  134. int iwpm_add_and_query_mapping_cb(struct sk_buff *, struct netlink_callback *);
  135. /**
  136. * iwpm_remote_info_cb - Process remote connecting peer address info, which
  137. * the port mapper has received from the connecting peer
  138. *
  139. * @cb: Contains the received message (payload and netlink header)
  140. *
  141. * Stores the IPv4/IPv6 address info in a hash table
  142. */
  143. int iwpm_remote_info_cb(struct sk_buff *, struct netlink_callback *);
  144. /**
  145. * iwpm_mapping_error_cb - Process port mapper notification for error
  146. *
  147. * @skb:
  148. * @cb: Contains the received message (payload and netlink header)
  149. */
  150. int iwpm_mapping_error_cb(struct sk_buff *, struct netlink_callback *);
  151. /**
  152. * iwpm_mapping_info_cb - Process a notification that the userspace
  153. * port mapper daemon is started
  154. * @skb:
  155. * @cb: Contains the received message (payload and netlink header)
  156. *
  157. * Using the received port mapper pid, send all the local mapping
  158. * info records to the userspace port mapper
  159. */
  160. int iwpm_mapping_info_cb(struct sk_buff *, struct netlink_callback *);
  161. /**
  162. * iwpm_ack_mapping_info_cb - Process the port mapper ack for
  163. * the provided local mapping info records
  164. * @skb:
  165. * @cb: Contains the received message (payload and netlink header)
  166. */
  167. int iwpm_ack_mapping_info_cb(struct sk_buff *, struct netlink_callback *);
  168. /**
  169. * iwpm_get_remote_info - Get the remote connecting peer address info
  170. *
  171. * @mapped_loc_addr: Mapped local address of the listening peer
  172. * @mapped_rem_addr: Mapped remote address of the connecting peer
  173. * @remote_addr: To store the remote address of the connecting peer
  174. * @nl_client: The index of the netlink client
  175. *
  176. * The remote address info is retrieved and provided to the client in
  177. * the remote_addr. After that it is removed from the hash table
  178. */
  179. int iwpm_get_remote_info(struct sockaddr_storage *mapped_loc_addr,
  180. struct sockaddr_storage *mapped_rem_addr,
  181. struct sockaddr_storage *remote_addr, u8 nl_client);
  182. /**
  183. * iwpm_create_mapinfo - Store local and mapped IPv4/IPv6 address
  184. * info in a hash table
  185. * @local_addr: Local ip/tcp address
  186. * @mapped_addr: Mapped local ip/tcp address
  187. * @nl_client: The index of the netlink client
  188. */
  189. int iwpm_create_mapinfo(struct sockaddr_storage *local_addr,
  190. struct sockaddr_storage *mapped_addr, u8 nl_client);
  191. /**
  192. * iwpm_remove_mapinfo - Remove local and mapped IPv4/IPv6 address
  193. * info from the hash table
  194. * @local_addr: Local ip/tcp address
  195. * @mapped_addr: Mapped local ip/tcp address
  196. *
  197. * Returns err code if mapping info is not found in the hash table,
  198. * otherwise returns 0
  199. */
  200. int iwpm_remove_mapinfo(struct sockaddr_storage *local_addr,
  201. struct sockaddr_storage *mapped_addr);
  202. #endif /* _IW_PORTMAP_H */