1 /**
2  * Interface for Linux TIPC sockets, /usr/include/linux/tipc.h
3  *
4  * Copyright: Public Domain
5  * License:   Public Domain
6  * Authors:   Leandro Lucarella
7  */
8 
9 module core.sys.linux.tipc;
10 
11 version (linux):
12 extern (C) nothrow @nogc:
13 
14 struct tipc_portid
15 {
16         uint ref_;
17         uint node;
18 }
19 
20 struct tipc_name
21 {
22         uint type;
23         uint instance;
24 }
25 
26 struct tipc_name_seq
27 {
28         uint type;
29         uint lower;
30         uint upper;
31 }
32 
33 struct tipc_subscr
34 {
35         tipc_name_seq seq;
36         uint timeout;
37         uint filter;
38         ubyte[8] usr_handle;
39 }
40 
41 struct tipc_event
42 {
43         uint event;
44         uint found_lower;
45         uint found_upper;
46         tipc_portid port;
47         tipc_subscr s;
48 }
49 
50 struct sockaddr_tipc
51 {
52         ushort family;
53         ubyte addrtype;
54         byte scope_;
55         union Addr
56         {
57                 tipc_portid id;
58                 tipc_name_seq nameseq;
59                 static struct Name
60                 {
61                         tipc_name name;
62                         uint domain;
63                 }
64                 Name name;
65         }
66         Addr addr;
67 }
68 
69 uint tipc_addr(uint zone, uint cluster, uint node)
70 {
71         return (zone << 24) | (cluster << 12) | node;
72 }
73 
74 unittest
75 {
76         assert (tipc_addr(0, 0, 0) == 0);
77         assert (tipc_addr(1, 1, 1) == 16781313);
78         assert (tipc_addr(2, 1, 27) == 33558555);
79         assert (tipc_addr(3, 1, 63) == 50335807);
80 }
81 
82 uint tipc_zone(uint addr)
83 {
84         return addr >> 24;
85 }
86 
87 unittest
88 {
89         assert (tipc_zone(0u) == 0);
90         assert (tipc_zone(16781313u) == 1);
91         assert (tipc_zone(33558555u) == 2);
92         assert (tipc_zone(50335807u) == 3);
93 }
94 
95 uint tipc_cluster(uint addr)
96 {
97         return (addr >> 12) & 0xfff;
98 }
99 
100 unittest
101 {
102         assert (tipc_cluster(0u) == 0);
103         assert (tipc_cluster(16781313u) == 1);
104         assert (tipc_cluster(33558555u) == 1);
105         assert (tipc_cluster(50335807u) == 1);
106 }
107 
108 uint tipc_node(uint addr)
109 {
110         return addr & 0xfff;
111 }
112 
113 unittest
114 {
115         assert (tipc_node(0u) == 0);
116         assert (tipc_node(16781313u) == 1);
117         assert (tipc_node(33558555u) == 27);
118         assert (tipc_node(50335807u) == 63);
119 }
120 
121 enum: int
122 {
123         TIPC_CFG_SRV    = 0,
124         TIPC_TOP_SRV    = 1,
125         TIPC_RESERVED_TYPES = 64,
126 }
127 
128 enum: int
129 {
130         TIPC_ZONE_SCOPE    = 1,
131         TIPC_CLUSTER_SCOPE = 2,
132         TIPC_NODE_SCOPE    = 3,
133 }
134 
135 enum: int
136 {
137         TIPC_MAX_USER_MSG_SIZE = 66000,
138 }
139 
140 enum: int
141 {
142         TIPC_LOW_IMPORTANCE      = 0,
143         TIPC_MEDIUM_IMPORTANCE   = 1,
144         TIPC_HIGH_IMPORTANCE     = 2,
145         TIPC_CRITICAL_IMPORTANCE = 3,
146 }
147 
148 enum: int
149 {
150         TIPC_OK     = 0,
151         TIPC_ERR_NO_NAME   = 1,
152         TIPC_ERR_NO_PORT   = 2,
153         TIPC_ERR_NO_NODE   = 3,
154         TIPC_ERR_OVERLOAD  = 4,
155         TIPC_CONN_SHUTDOWN = 5,
156 }
157 
158 enum: int
159 {
160         TIPC_SUB_PORTS    = 0x01,
161         TIPC_SUB_SERVICE  = 0x02,
162         TIPC_SUB_CANCEL   = 0x04,
163 }
164 
165 version (none) enum: int
166 {
167         TIPC_SUB_NO_BIND_EVTS   = 0x04,
168         TIPC_SUB_NO_UNBIND_EVTS = 0x08,
169         TIPC_SUB_SINGLE_EVT     = 0x10,
170 }
171 
172 enum: int
173 {
174         TIPC_WAIT_FOREVER = ~0,
175 }
176 
177 enum: int
178 {
179 
180         TIPC_PUBLISHED      = 1,
181         TIPC_WITHDRAWN      = 2,
182         TIPC_SUBSCR_TIMEOUT = 3,
183 }
184 
185 enum: int
186 {
187         AF_TIPC    = 30,
188         PF_TIPC    = 30,
189         SOL_TIPC          = 271,
190         TIPC_ADDR_NAMESEQ = 1,
191         TIPC_ADDR_MCAST   = 1,
192         TIPC_ADDR_NAME    = 2,
193         TIPC_ADDR_ID      = 3,
194 }
195 
196 enum: int
197 {
198         TIPC_ERRINFO  = 1,
199         TIPC_RETDATA  = 2,
200         TIPC_DESTNAME = 3,
201 }
202 
203 enum: int
204 {
205         TIPC_IMPORTANCE     = 127,
206         TIPC_SRC_DROPPABLE  = 128,
207         TIPC_DEST_DROPPABLE = 129,
208         TIPC_CONN_TIMEOUT   = 130,
209 }