diff options
Diffstat (limited to 'net/tipc/msg.h')
-rw-r--r-- | net/tipc/msg.h | 168 |
1 files changed, 161 insertions, 7 deletions
diff --git a/net/tipc/msg.h b/net/tipc/msg.h index 031aad18efce..aee53864d7a0 100644 --- a/net/tipc/msg.h +++ b/net/tipc/msg.h | |||
@@ -37,10 +37,51 @@ | |||
37 | #ifndef _TIPC_MSG_H | 37 | #ifndef _TIPC_MSG_H |
38 | #define _TIPC_MSG_H | 38 | #define _TIPC_MSG_H |
39 | 39 | ||
40 | #include "core.h" | 40 | #include "bearer.h" |
41 | 41 | ||
42 | #define TIPC_VERSION 2 | 42 | #define TIPC_VERSION 2 |
43 | 43 | ||
44 | /* | ||
45 | * TIPC user data message header format, version 2: | ||
46 | * | ||
47 | * | ||
48 | * 1 0 9 8 7 6 5 4|3 2 1 0 9 8 7 6|5 4 3 2 1 0 9 8|7 6 5 4 3 2 1 0 | ||
49 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
50 | * w0:|vers | user |hdr sz |n|d|s|-| message size | | ||
51 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
52 | * w1:|mstyp| error |rer cnt|lsc|opt p| broadcast ack no | | ||
53 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
54 | * w2:| link level ack no | broadcast/link level seq no | | ||
55 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
56 | * w3:| previous node | | ||
57 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
58 | * w4:| originating port | | ||
59 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
60 | * w5:| destination port | | ||
61 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
62 | * w6:| originating node | | ||
63 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
64 | * w7:| destination node | | ||
65 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
66 | * w8:| name type / transport sequence number | | ||
67 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
68 | * w9:| name instance/multicast lower bound | | ||
69 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
70 | * wA:| multicast upper bound | | ||
71 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
72 | * / / | ||
73 | * \ options \ | ||
74 | * / / | ||
75 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
76 | * | ||
77 | */ | ||
78 | |||
79 | #define TIPC_CONN_MSG 0 | ||
80 | #define TIPC_MCAST_MSG 1 | ||
81 | #define TIPC_NAMED_MSG 2 | ||
82 | #define TIPC_DIRECT_MSG 3 | ||
83 | |||
84 | |||
44 | #define SHORT_H_SIZE 24 /* Connected, in-cluster messages */ | 85 | #define SHORT_H_SIZE 24 /* Connected, in-cluster messages */ |
45 | #define DIR_MSG_H_SIZE 32 /* Directly addressed messages */ | 86 | #define DIR_MSG_H_SIZE 32 /* Directly addressed messages */ |
46 | #define LONG_H_SIZE 40 /* Named messages */ | 87 | #define LONG_H_SIZE 40 /* Named messages */ |
@@ -52,20 +93,26 @@ | |||
52 | #define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE) | 93 | #define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE) |
53 | 94 | ||
54 | 95 | ||
55 | /* | 96 | struct tipc_msg { |
56 | TIPC user data message header format, version 2 | 97 | __be32 hdr[15]; |
98 | }; | ||
57 | 99 | ||
58 | - Fundamental definitions available to privileged TIPC users | ||
59 | are located in tipc_msg.h. | ||
60 | - Remaining definitions available to TIPC internal users appear below. | ||
61 | */ | ||
62 | 100 | ||
101 | static inline u32 msg_word(struct tipc_msg *m, u32 pos) | ||
102 | { | ||
103 | return ntohl(m->hdr[pos]); | ||
104 | } | ||
63 | 105 | ||
64 | static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val) | 106 | static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val) |
65 | { | 107 | { |
66 | m->hdr[w] = htonl(val); | 108 | m->hdr[w] = htonl(val); |
67 | } | 109 | } |
68 | 110 | ||
111 | static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask) | ||
112 | { | ||
113 | return (msg_word(m, w) >> pos) & mask; | ||
114 | } | ||
115 | |||
69 | static inline void msg_set_bits(struct tipc_msg *m, u32 w, | 116 | static inline void msg_set_bits(struct tipc_msg *m, u32 w, |
70 | u32 pos, u32 mask, u32 val) | 117 | u32 pos, u32 mask, u32 val) |
71 | { | 118 | { |
@@ -112,16 +159,36 @@ static inline void msg_set_user(struct tipc_msg *m, u32 n) | |||
112 | msg_set_bits(m, 0, 25, 0xf, n); | 159 | msg_set_bits(m, 0, 25, 0xf, n); |
113 | } | 160 | } |
114 | 161 | ||
162 | static inline u32 msg_importance(struct tipc_msg *m) | ||
163 | { | ||
164 | return msg_bits(m, 0, 25, 0xf); | ||
165 | } | ||
166 | |||
115 | static inline void msg_set_importance(struct tipc_msg *m, u32 i) | 167 | static inline void msg_set_importance(struct tipc_msg *m, u32 i) |
116 | { | 168 | { |
117 | msg_set_user(m, i); | 169 | msg_set_user(m, i); |
118 | } | 170 | } |
119 | 171 | ||
172 | static inline u32 msg_hdr_sz(struct tipc_msg *m) | ||
173 | { | ||
174 | return msg_bits(m, 0, 21, 0xf) << 2; | ||
175 | } | ||
176 | |||
120 | static inline void msg_set_hdr_sz(struct tipc_msg *m,u32 n) | 177 | static inline void msg_set_hdr_sz(struct tipc_msg *m,u32 n) |
121 | { | 178 | { |
122 | msg_set_bits(m, 0, 21, 0xf, n>>2); | 179 | msg_set_bits(m, 0, 21, 0xf, n>>2); |
123 | } | 180 | } |
124 | 181 | ||
182 | static inline u32 msg_size(struct tipc_msg *m) | ||
183 | { | ||
184 | return msg_bits(m, 0, 0, 0x1ffff); | ||
185 | } | ||
186 | |||
187 | static inline u32 msg_data_sz(struct tipc_msg *m) | ||
188 | { | ||
189 | return msg_size(m) - msg_hdr_sz(m); | ||
190 | } | ||
191 | |||
125 | static inline int msg_non_seq(struct tipc_msg *m) | 192 | static inline int msg_non_seq(struct tipc_msg *m) |
126 | { | 193 | { |
127 | return msg_bits(m, 0, 20, 1); | 194 | return msg_bits(m, 0, 20, 1); |
@@ -162,11 +229,36 @@ static inline void msg_set_size(struct tipc_msg *m, u32 sz) | |||
162 | * Word 1 | 229 | * Word 1 |
163 | */ | 230 | */ |
164 | 231 | ||
232 | static inline u32 msg_type(struct tipc_msg *m) | ||
233 | { | ||
234 | return msg_bits(m, 1, 29, 0x7); | ||
235 | } | ||
236 | |||
165 | static inline void msg_set_type(struct tipc_msg *m, u32 n) | 237 | static inline void msg_set_type(struct tipc_msg *m, u32 n) |
166 | { | 238 | { |
167 | msg_set_bits(m, 1, 29, 0x7, n); | 239 | msg_set_bits(m, 1, 29, 0x7, n); |
168 | } | 240 | } |
169 | 241 | ||
242 | static inline u32 msg_named(struct tipc_msg *m) | ||
243 | { | ||
244 | return msg_type(m) == TIPC_NAMED_MSG; | ||
245 | } | ||
246 | |||
247 | static inline u32 msg_mcast(struct tipc_msg *m) | ||
248 | { | ||
249 | return msg_type(m) == TIPC_MCAST_MSG; | ||
250 | } | ||
251 | |||
252 | static inline u32 msg_connected(struct tipc_msg *m) | ||
253 | { | ||
254 | return msg_type(m) == TIPC_CONN_MSG; | ||
255 | } | ||
256 | |||
257 | static inline u32 msg_errcode(struct tipc_msg *m) | ||
258 | { | ||
259 | return msg_bits(m, 1, 25, 0xf); | ||
260 | } | ||
261 | |||
170 | static inline void msg_set_errcode(struct tipc_msg *m, u32 err) | 262 | static inline void msg_set_errcode(struct tipc_msg *m, u32 err) |
171 | { | 263 | { |
172 | msg_set_bits(m, 1, 25, 0xf, err); | 264 | msg_set_bits(m, 1, 25, 0xf, err); |
@@ -257,31 +349,68 @@ static inline void msg_set_destnode_cache(struct tipc_msg *m, u32 dnode) | |||
257 | */ | 349 | */ |
258 | 350 | ||
259 | 351 | ||
352 | static inline u32 msg_prevnode(struct tipc_msg *m) | ||
353 | { | ||
354 | return msg_word(m, 3); | ||
355 | } | ||
356 | |||
260 | static inline void msg_set_prevnode(struct tipc_msg *m, u32 a) | 357 | static inline void msg_set_prevnode(struct tipc_msg *m, u32 a) |
261 | { | 358 | { |
262 | msg_set_word(m, 3, a); | 359 | msg_set_word(m, 3, a); |
263 | } | 360 | } |
264 | 361 | ||
362 | static inline u32 msg_origport(struct tipc_msg *m) | ||
363 | { | ||
364 | return msg_word(m, 4); | ||
365 | } | ||
366 | |||
265 | static inline void msg_set_origport(struct tipc_msg *m, u32 p) | 367 | static inline void msg_set_origport(struct tipc_msg *m, u32 p) |
266 | { | 368 | { |
267 | msg_set_word(m, 4, p); | 369 | msg_set_word(m, 4, p); |
268 | } | 370 | } |
269 | 371 | ||
372 | static inline u32 msg_destport(struct tipc_msg *m) | ||
373 | { | ||
374 | return msg_word(m, 5); | ||
375 | } | ||
376 | |||
270 | static inline void msg_set_destport(struct tipc_msg *m, u32 p) | 377 | static inline void msg_set_destport(struct tipc_msg *m, u32 p) |
271 | { | 378 | { |
272 | msg_set_word(m, 5, p); | 379 | msg_set_word(m, 5, p); |
273 | } | 380 | } |
274 | 381 | ||
382 | static inline u32 msg_mc_netid(struct tipc_msg *m) | ||
383 | { | ||
384 | return msg_word(m, 5); | ||
385 | } | ||
386 | |||
275 | static inline void msg_set_mc_netid(struct tipc_msg *m, u32 p) | 387 | static inline void msg_set_mc_netid(struct tipc_msg *m, u32 p) |
276 | { | 388 | { |
277 | msg_set_word(m, 5, p); | 389 | msg_set_word(m, 5, p); |
278 | } | 390 | } |
279 | 391 | ||
392 | static inline int msg_short(struct tipc_msg *m) | ||
393 | { | ||
394 | return msg_hdr_sz(m) == 24; | ||
395 | } | ||
396 | |||
397 | static inline u32 msg_orignode(struct tipc_msg *m) | ||
398 | { | ||
399 | if (likely(msg_short(m))) | ||
400 | return msg_prevnode(m); | ||
401 | return msg_word(m, 6); | ||
402 | } | ||
403 | |||
280 | static inline void msg_set_orignode(struct tipc_msg *m, u32 a) | 404 | static inline void msg_set_orignode(struct tipc_msg *m, u32 a) |
281 | { | 405 | { |
282 | msg_set_word(m, 6, a); | 406 | msg_set_word(m, 6, a); |
283 | } | 407 | } |
284 | 408 | ||
409 | static inline u32 msg_destnode(struct tipc_msg *m) | ||
410 | { | ||
411 | return msg_word(m, 7); | ||
412 | } | ||
413 | |||
285 | static inline void msg_set_destnode(struct tipc_msg *m, u32 a) | 414 | static inline void msg_set_destnode(struct tipc_msg *m, u32 a) |
286 | { | 415 | { |
287 | msg_set_word(m, 7, a); | 416 | msg_set_word(m, 7, a); |
@@ -299,6 +428,11 @@ static inline u32 msg_routed(struct tipc_msg *m) | |||
299 | return(msg_destnode(m) ^ msg_orignode(m)) >> 11; | 428 | return(msg_destnode(m) ^ msg_orignode(m)) >> 11; |
300 | } | 429 | } |
301 | 430 | ||
431 | static inline u32 msg_nametype(struct tipc_msg *m) | ||
432 | { | ||
433 | return msg_word(m, 8); | ||
434 | } | ||
435 | |||
302 | static inline void msg_set_nametype(struct tipc_msg *m, u32 n) | 436 | static inline void msg_set_nametype(struct tipc_msg *m, u32 n) |
303 | { | 437 | { |
304 | msg_set_word(m, 8, n); | 438 | msg_set_word(m, 8, n); |
@@ -324,6 +458,16 @@ static inline void msg_set_transp_seqno(struct tipc_msg *m, u32 n) | |||
324 | msg_set_word(m, 8, n); | 458 | msg_set_word(m, 8, n); |
325 | } | 459 | } |
326 | 460 | ||
461 | static inline u32 msg_nameinst(struct tipc_msg *m) | ||
462 | { | ||
463 | return msg_word(m, 9); | ||
464 | } | ||
465 | |||
466 | static inline u32 msg_namelower(struct tipc_msg *m) | ||
467 | { | ||
468 | return msg_nameinst(m); | ||
469 | } | ||
470 | |||
327 | static inline void msg_set_namelower(struct tipc_msg *m, u32 n) | 471 | static inline void msg_set_namelower(struct tipc_msg *m, u32 n) |
328 | { | 472 | { |
329 | msg_set_word(m, 9, n); | 473 | msg_set_word(m, 9, n); |
@@ -334,11 +478,21 @@ static inline void msg_set_nameinst(struct tipc_msg *m, u32 n) | |||
334 | msg_set_namelower(m, n); | 478 | msg_set_namelower(m, n); |
335 | } | 479 | } |
336 | 480 | ||
481 | static inline u32 msg_nameupper(struct tipc_msg *m) | ||
482 | { | ||
483 | return msg_word(m, 10); | ||
484 | } | ||
485 | |||
337 | static inline void msg_set_nameupper(struct tipc_msg *m, u32 n) | 486 | static inline void msg_set_nameupper(struct tipc_msg *m, u32 n) |
338 | { | 487 | { |
339 | msg_set_word(m, 10, n); | 488 | msg_set_word(m, 10, n); |
340 | } | 489 | } |
341 | 490 | ||
491 | static inline unchar *msg_data(struct tipc_msg *m) | ||
492 | { | ||
493 | return ((unchar *)m) + msg_hdr_sz(m); | ||
494 | } | ||
495 | |||
342 | static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m) | 496 | static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m) |
343 | { | 497 | { |
344 | return (struct tipc_msg *)msg_data(m); | 498 | return (struct tipc_msg *)msg_data(m); |