tipc.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
  2. /*
  3. * include/uapi/linux/tipc.h: Header for TIPC socket interface
  4. *
  5. * Copyright (c) 2003-2006, 2015-2016 Ericsson AB
  6. * Copyright (c) 2005, 2010-2011, Wind River Systems
  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. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the names of the copyright holders nor the names of its
  18. * contributors may be used to endorse or promote products derived from
  19. * this software without specific prior written permission.
  20. *
  21. * Alternatively, this software may be distributed under the terms of the
  22. * GNU General Public License ("GPL") version 2 as published by the Free
  23. * Software Foundation.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #ifndef _LINUX_TIPC_H_
  38. #define _LINUX_TIPC_H_
  39. #include <linux/types.h>
  40. #include <linux/sockios.h>
  41. /*
  42. * TIPC addressing primitives
  43. */
  44. struct tipc_socket_addr {
  45. __u32 ref;
  46. __u32 node;
  47. };
  48. struct tipc_service_addr {
  49. __u32 type;
  50. __u32 instance;
  51. };
  52. struct tipc_service_range {
  53. __u32 type;
  54. __u32 lower;
  55. __u32 upper;
  56. };
  57. /*
  58. * Application-accessible service types
  59. */
  60. #define TIPC_NODE_STATE 0 /* node state service type */
  61. #define TIPC_TOP_SRV 1 /* topology server service type */
  62. #define TIPC_LINK_STATE 2 /* link state service type */
  63. #define TIPC_RESERVED_TYPES 64 /* lowest user-allowed service type */
  64. /*
  65. * Publication scopes when binding service / service range
  66. */
  67. enum tipc_scope {
  68. TIPC_CLUSTER_SCOPE = 2, /* 0 can also be used */
  69. TIPC_NODE_SCOPE = 3
  70. };
  71. /*
  72. * Limiting values for messages
  73. */
  74. #define TIPC_MAX_USER_MSG_SIZE 66000U
  75. /*
  76. * Message importance levels
  77. */
  78. #define TIPC_LOW_IMPORTANCE 0
  79. #define TIPC_MEDIUM_IMPORTANCE 1
  80. #define TIPC_HIGH_IMPORTANCE 2
  81. #define TIPC_CRITICAL_IMPORTANCE 3
  82. /*
  83. * Msg rejection/connection shutdown reasons
  84. */
  85. #define TIPC_OK 0
  86. #define TIPC_ERR_NO_NAME 1
  87. #define TIPC_ERR_NO_PORT 2
  88. #define TIPC_ERR_NO_NODE 3
  89. #define TIPC_ERR_OVERLOAD 4
  90. #define TIPC_CONN_SHUTDOWN 5
  91. /*
  92. * TIPC topology subscription service definitions
  93. */
  94. #define TIPC_SUB_PORTS 0x01 /* filter: evt at each match */
  95. #define TIPC_SUB_SERVICE 0x02 /* filter: evt at first up/last down */
  96. #define TIPC_SUB_CANCEL 0x04 /* filter: cancel a subscription */
  97. #define TIPC_WAIT_FOREVER (~0) /* timeout for permanent subscription */
  98. struct tipc_subscr {
  99. struct tipc_service_range seq; /* range of interest */
  100. __u32 timeout; /* subscription duration (in ms) */
  101. __u32 filter; /* bitmask of filter options */
  102. char usr_handle[8]; /* available for subscriber use */
  103. };
  104. #define TIPC_PUBLISHED 1 /* publication event */
  105. #define TIPC_WITHDRAWN 2 /* withdrawal event */
  106. #define TIPC_SUBSCR_TIMEOUT 3 /* subscription timeout event */
  107. struct tipc_event {
  108. __u32 event; /* event type */
  109. __u32 found_lower; /* matching range */
  110. __u32 found_upper; /* " " */
  111. struct tipc_socket_addr port; /* associated socket */
  112. struct tipc_subscr s; /* associated subscription */
  113. };
  114. /*
  115. * Socket API
  116. */
  117. #ifndef AF_TIPC
  118. #define AF_TIPC 30
  119. #endif
  120. #ifndef PF_TIPC
  121. #define PF_TIPC AF_TIPC
  122. #endif
  123. #ifndef SOL_TIPC
  124. #define SOL_TIPC 271
  125. #endif
  126. #define TIPC_ADDR_MCAST 1
  127. #define TIPC_SERVICE_RANGE 1
  128. #define TIPC_SERVICE_ADDR 2
  129. #define TIPC_SOCKET_ADDR 3
  130. struct sockaddr_tipc {
  131. unsigned short family;
  132. unsigned char addrtype;
  133. signed char scope;
  134. union {
  135. struct tipc_socket_addr id;
  136. struct tipc_service_range nameseq;
  137. struct {
  138. struct tipc_service_addr name;
  139. __u32 domain;
  140. } name;
  141. } addr;
  142. };
  143. /*
  144. * Ancillary data objects supported by recvmsg()
  145. */
  146. #define TIPC_ERRINFO 1 /* error info */
  147. #define TIPC_RETDATA 2 /* returned data */
  148. #define TIPC_DESTNAME 3 /* destination name */
  149. /*
  150. * TIPC-specific socket option names
  151. */
  152. #define TIPC_IMPORTANCE 127 /* Default: TIPC_LOW_IMPORTANCE */
  153. #define TIPC_SRC_DROPPABLE 128 /* Default: based on socket type */
  154. #define TIPC_DEST_DROPPABLE 129 /* Default: based on socket type */
  155. #define TIPC_CONN_TIMEOUT 130 /* Default: 8000 (ms) */
  156. #define TIPC_NODE_RECVQ_DEPTH 131 /* Default: none (read only) */
  157. #define TIPC_SOCK_RECVQ_DEPTH 132 /* Default: none (read only) */
  158. #define TIPC_MCAST_BROADCAST 133 /* Default: TIPC selects. No arg */
  159. #define TIPC_MCAST_REPLICAST 134 /* Default: TIPC selects. No arg */
  160. #define TIPC_GROUP_JOIN 135 /* Takes struct tipc_group_req* */
  161. #define TIPC_GROUP_LEAVE 136 /* No argument */
  162. /*
  163. * Flag values
  164. */
  165. #define TIPC_GROUP_LOOPBACK 0x1 /* Receive copy of sent msg when match */
  166. #define TIPC_GROUP_MEMBER_EVTS 0x2 /* Receive membership events in socket */
  167. struct tipc_group_req {
  168. __u32 type; /* group id */
  169. __u32 instance; /* member id */
  170. __u32 scope; /* cluster/node */
  171. __u32 flags;
  172. };
  173. /*
  174. * Maximum sizes of TIPC bearer-related names (including terminating NULL)
  175. * The string formatting for each name element is:
  176. * media: media
  177. * interface: media:interface name
  178. * link: node:interface-node:interface
  179. */
  180. #define TIPC_NODEID_LEN 16
  181. #define TIPC_MAX_MEDIA_NAME 16
  182. #define TIPC_MAX_IF_NAME 16
  183. #define TIPC_MAX_BEARER_NAME 32
  184. #define TIPC_MAX_LINK_NAME 68
  185. #define SIOCGETLINKNAME SIOCPROTOPRIVATE
  186. #define SIOCGETNODEID (SIOCPROTOPRIVATE + 1)
  187. struct tipc_sioc_ln_req {
  188. __u32 peer;
  189. __u32 bearer_id;
  190. char linkname[TIPC_MAX_LINK_NAME];
  191. };
  192. struct tipc_sioc_nodeid_req {
  193. __u32 peer;
  194. char node_id[TIPC_NODEID_LEN];
  195. };
  196. /* The macros and functions below are deprecated:
  197. */
  198. #define TIPC_CFG_SRV 0
  199. #define TIPC_ZONE_SCOPE 1
  200. #define TIPC_ADDR_NAMESEQ 1
  201. #define TIPC_ADDR_NAME 2
  202. #define TIPC_ADDR_ID 3
  203. #define TIPC_NODE_BITS 12
  204. #define TIPC_CLUSTER_BITS 12
  205. #define TIPC_ZONE_BITS 8
  206. #define TIPC_NODE_OFFSET 0
  207. #define TIPC_CLUSTER_OFFSET TIPC_NODE_BITS
  208. #define TIPC_ZONE_OFFSET (TIPC_CLUSTER_OFFSET + TIPC_CLUSTER_BITS)
  209. #define TIPC_NODE_SIZE ((1UL << TIPC_NODE_BITS) - 1)
  210. #define TIPC_CLUSTER_SIZE ((1UL << TIPC_CLUSTER_BITS) - 1)
  211. #define TIPC_ZONE_SIZE ((1UL << TIPC_ZONE_BITS) - 1)
  212. #define TIPC_NODE_MASK (TIPC_NODE_SIZE << TIPC_NODE_OFFSET)
  213. #define TIPC_CLUSTER_MASK (TIPC_CLUSTER_SIZE << TIPC_CLUSTER_OFFSET)
  214. #define TIPC_ZONE_MASK (TIPC_ZONE_SIZE << TIPC_ZONE_OFFSET)
  215. #define TIPC_ZONE_CLUSTER_MASK (TIPC_ZONE_MASK | TIPC_CLUSTER_MASK)
  216. #define tipc_portid tipc_socket_addr
  217. #define tipc_name tipc_service_addr
  218. #define tipc_name_seq tipc_service_range
  219. static inline __u32 tipc_addr(unsigned int zone,
  220. unsigned int cluster,
  221. unsigned int node)
  222. {
  223. return (zone << TIPC_ZONE_OFFSET) |
  224. (cluster << TIPC_CLUSTER_OFFSET) |
  225. node;
  226. }
  227. static inline unsigned int tipc_zone(__u32 addr)
  228. {
  229. return addr >> TIPC_ZONE_OFFSET;
  230. }
  231. static inline unsigned int tipc_cluster(__u32 addr)
  232. {
  233. return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
  234. }
  235. static inline unsigned int tipc_node(__u32 addr)
  236. {
  237. return addr & TIPC_NODE_MASK;
  238. }
  239. #endif