tipc.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. #define TIPC_SOCK_RECVQ_USED 137 /* Default: none (read only) */
  163. #define TIPC_NODELAY 138 /* Default: false */
  164. /*
  165. * Flag values
  166. */
  167. #define TIPC_GROUP_LOOPBACK 0x1 /* Receive copy of sent msg when match */
  168. #define TIPC_GROUP_MEMBER_EVTS 0x2 /* Receive membership events in socket */
  169. struct tipc_group_req {
  170. __u32 type; /* group id */
  171. __u32 instance; /* member id */
  172. __u32 scope; /* cluster/node */
  173. __u32 flags;
  174. };
  175. /*
  176. * Maximum sizes of TIPC bearer-related names (including terminating NULL)
  177. * The string formatting for each name element is:
  178. * media: media
  179. * interface: media:interface name
  180. * link: node:interface-node:interface
  181. */
  182. #define TIPC_NODEID_LEN 16
  183. #define TIPC_MAX_MEDIA_NAME 16
  184. #define TIPC_MAX_IF_NAME 16
  185. #define TIPC_MAX_BEARER_NAME 32
  186. #define TIPC_MAX_LINK_NAME 68
  187. #define SIOCGETLINKNAME SIOCPROTOPRIVATE
  188. #define SIOCGETNODEID (SIOCPROTOPRIVATE + 1)
  189. struct tipc_sioc_ln_req {
  190. __u32 peer;
  191. __u32 bearer_id;
  192. char linkname[TIPC_MAX_LINK_NAME];
  193. };
  194. struct tipc_sioc_nodeid_req {
  195. __u32 peer;
  196. char node_id[TIPC_NODEID_LEN];
  197. };
  198. /*
  199. * TIPC Crypto, AEAD
  200. */
  201. #define TIPC_AEAD_ALG_NAME (32)
  202. struct tipc_aead_key {
  203. char alg_name[TIPC_AEAD_ALG_NAME];
  204. unsigned int keylen; /* in bytes */
  205. char key[];
  206. };
  207. #define TIPC_AEAD_KEYLEN_MIN (16 + 4)
  208. #define TIPC_AEAD_KEYLEN_MAX (32 + 4)
  209. #define TIPC_AEAD_KEY_SIZE_MAX (sizeof(struct tipc_aead_key) + \
  210. TIPC_AEAD_KEYLEN_MAX)
  211. static inline int tipc_aead_key_size(struct tipc_aead_key *key)
  212. {
  213. return sizeof(*key) + key->keylen;
  214. }
  215. #define TIPC_REKEYING_NOW (~0U)
  216. /* The macros and functions below are deprecated:
  217. */
  218. #define TIPC_CFG_SRV 0
  219. #define TIPC_ZONE_SCOPE 1
  220. #define TIPC_ADDR_NAMESEQ 1
  221. #define TIPC_ADDR_NAME 2
  222. #define TIPC_ADDR_ID 3
  223. #define TIPC_NODE_BITS 12
  224. #define TIPC_CLUSTER_BITS 12
  225. #define TIPC_ZONE_BITS 8
  226. #define TIPC_NODE_OFFSET 0
  227. #define TIPC_CLUSTER_OFFSET TIPC_NODE_BITS
  228. #define TIPC_ZONE_OFFSET (TIPC_CLUSTER_OFFSET + TIPC_CLUSTER_BITS)
  229. #define TIPC_NODE_SIZE ((1UL << TIPC_NODE_BITS) - 1)
  230. #define TIPC_CLUSTER_SIZE ((1UL << TIPC_CLUSTER_BITS) - 1)
  231. #define TIPC_ZONE_SIZE ((1UL << TIPC_ZONE_BITS) - 1)
  232. #define TIPC_NODE_MASK (TIPC_NODE_SIZE << TIPC_NODE_OFFSET)
  233. #define TIPC_CLUSTER_MASK (TIPC_CLUSTER_SIZE << TIPC_CLUSTER_OFFSET)
  234. #define TIPC_ZONE_MASK (TIPC_ZONE_SIZE << TIPC_ZONE_OFFSET)
  235. #define TIPC_ZONE_CLUSTER_MASK (TIPC_ZONE_MASK | TIPC_CLUSTER_MASK)
  236. #define tipc_portid tipc_socket_addr
  237. #define tipc_name tipc_service_addr
  238. #define tipc_name_seq tipc_service_range
  239. static inline __u32 tipc_addr(unsigned int zone,
  240. unsigned int cluster,
  241. unsigned int node)
  242. {
  243. return (zone << TIPC_ZONE_OFFSET) |
  244. (cluster << TIPC_CLUSTER_OFFSET) |
  245. node;
  246. }
  247. static inline unsigned int tipc_zone(__u32 addr)
  248. {
  249. return addr >> TIPC_ZONE_OFFSET;
  250. }
  251. static inline unsigned int tipc_cluster(__u32 addr)
  252. {
  253. return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
  254. }
  255. static inline unsigned int tipc_node(__u32 addr)
  256. {
  257. return addr & TIPC_NODE_MASK;
  258. }
  259. #endif