msg.h 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. /*
  2. * net/tipc/msg.h: Include file for TIPC message header routines
  3. *
  4. * Copyright (c) 2000-2007, 2014-2017 Ericsson AB
  5. * Copyright (c) 2005-2008, 2010-2011, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #ifndef _TIPC_MSG_H
  37. #define _TIPC_MSG_H
  38. #include <linux/tipc.h>
  39. #include "core.h"
  40. /*
  41. * Constants and routines used to read and write TIPC payload message headers
  42. *
  43. * Note: Some items are also used with TIPC internal message headers
  44. */
  45. #define TIPC_VERSION 2
  46. struct plist;
  47. /*
  48. * Payload message users are defined in TIPC's public API:
  49. * - TIPC_LOW_IMPORTANCE
  50. * - TIPC_MEDIUM_IMPORTANCE
  51. * - TIPC_HIGH_IMPORTANCE
  52. * - TIPC_CRITICAL_IMPORTANCE
  53. */
  54. #define TIPC_SYSTEM_IMPORTANCE 4
  55. /*
  56. * Payload message types
  57. */
  58. #define TIPC_CONN_MSG 0
  59. #define TIPC_MCAST_MSG 1
  60. #define TIPC_NAMED_MSG 2
  61. #define TIPC_DIRECT_MSG 3
  62. #define TIPC_GRP_MEMBER_EVT 4
  63. #define TIPC_GRP_BCAST_MSG 5
  64. #define TIPC_GRP_MCAST_MSG 6
  65. #define TIPC_GRP_UCAST_MSG 7
  66. /*
  67. * Internal message users
  68. */
  69. #define BCAST_PROTOCOL 5
  70. #define MSG_BUNDLER 6
  71. #define LINK_PROTOCOL 7
  72. #define CONN_MANAGER 8
  73. #define GROUP_PROTOCOL 9
  74. #define TUNNEL_PROTOCOL 10
  75. #define NAME_DISTRIBUTOR 11
  76. #define MSG_FRAGMENTER 12
  77. #define LINK_CONFIG 13
  78. #define SOCK_WAKEUP 14 /* pseudo user */
  79. #define TOP_SRV 15 /* pseudo user */
  80. /*
  81. * Message header sizes
  82. */
  83. #define SHORT_H_SIZE 24 /* In-cluster basic payload message */
  84. #define BASIC_H_SIZE 32 /* Basic payload message */
  85. #define NAMED_H_SIZE 40 /* Named payload message */
  86. #define MCAST_H_SIZE 44 /* Multicast payload message */
  87. #define GROUP_H_SIZE 44 /* Group payload message */
  88. #define INT_H_SIZE 40 /* Internal messages */
  89. #define MIN_H_SIZE 24 /* Smallest legal TIPC header size */
  90. #define MAX_H_SIZE 60 /* Largest possible TIPC header size */
  91. #define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE)
  92. #define TIPC_MEDIA_INFO_OFFSET 5
  93. struct tipc_skb_cb {
  94. u32 bytes_read;
  95. u32 orig_member;
  96. struct sk_buff *tail;
  97. bool validated;
  98. u16 chain_imp;
  99. u16 ackers;
  100. };
  101. #define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0]))
  102. struct tipc_msg {
  103. __be32 hdr[15];
  104. };
  105. static inline struct tipc_msg *buf_msg(struct sk_buff *skb)
  106. {
  107. return (struct tipc_msg *)skb->data;
  108. }
  109. static inline u32 msg_word(struct tipc_msg *m, u32 pos)
  110. {
  111. return ntohl(m->hdr[pos]);
  112. }
  113. static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val)
  114. {
  115. m->hdr[w] = htonl(val);
  116. }
  117. static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask)
  118. {
  119. return (msg_word(m, w) >> pos) & mask;
  120. }
  121. static inline void msg_set_bits(struct tipc_msg *m, u32 w,
  122. u32 pos, u32 mask, u32 val)
  123. {
  124. val = (val & mask) << pos;
  125. mask = mask << pos;
  126. m->hdr[w] &= ~htonl(mask);
  127. m->hdr[w] |= htonl(val);
  128. }
  129. static inline void msg_swap_words(struct tipc_msg *msg, u32 a, u32 b)
  130. {
  131. u32 temp = msg->hdr[a];
  132. msg->hdr[a] = msg->hdr[b];
  133. msg->hdr[b] = temp;
  134. }
  135. /*
  136. * Word 0
  137. */
  138. static inline u32 msg_version(struct tipc_msg *m)
  139. {
  140. return msg_bits(m, 0, 29, 7);
  141. }
  142. static inline void msg_set_version(struct tipc_msg *m)
  143. {
  144. msg_set_bits(m, 0, 29, 7, TIPC_VERSION);
  145. }
  146. static inline u32 msg_user(struct tipc_msg *m)
  147. {
  148. return msg_bits(m, 0, 25, 0xf);
  149. }
  150. static inline u32 msg_isdata(struct tipc_msg *m)
  151. {
  152. return msg_user(m) <= TIPC_CRITICAL_IMPORTANCE;
  153. }
  154. static inline void msg_set_user(struct tipc_msg *m, u32 n)
  155. {
  156. msg_set_bits(m, 0, 25, 0xf, n);
  157. }
  158. static inline u32 msg_hdr_sz(struct tipc_msg *m)
  159. {
  160. return msg_bits(m, 0, 21, 0xf) << 2;
  161. }
  162. static inline void msg_set_hdr_sz(struct tipc_msg *m, u32 n)
  163. {
  164. msg_set_bits(m, 0, 21, 0xf, n>>2);
  165. }
  166. static inline u32 msg_size(struct tipc_msg *m)
  167. {
  168. return msg_bits(m, 0, 0, 0x1ffff);
  169. }
  170. static inline u32 msg_blocks(struct tipc_msg *m)
  171. {
  172. return (msg_size(m) / 1024) + 1;
  173. }
  174. static inline u32 msg_data_sz(struct tipc_msg *m)
  175. {
  176. return msg_size(m) - msg_hdr_sz(m);
  177. }
  178. static inline int msg_non_seq(struct tipc_msg *m)
  179. {
  180. return msg_bits(m, 0, 20, 1);
  181. }
  182. static inline void msg_set_non_seq(struct tipc_msg *m, u32 n)
  183. {
  184. msg_set_bits(m, 0, 20, 1, n);
  185. }
  186. static inline int msg_dest_droppable(struct tipc_msg *m)
  187. {
  188. return msg_bits(m, 0, 19, 1);
  189. }
  190. static inline void msg_set_dest_droppable(struct tipc_msg *m, u32 d)
  191. {
  192. msg_set_bits(m, 0, 19, 1, d);
  193. }
  194. static inline int msg_is_keepalive(struct tipc_msg *m)
  195. {
  196. return msg_bits(m, 0, 19, 1);
  197. }
  198. static inline void msg_set_is_keepalive(struct tipc_msg *m, u32 d)
  199. {
  200. msg_set_bits(m, 0, 19, 1, d);
  201. }
  202. static inline int msg_src_droppable(struct tipc_msg *m)
  203. {
  204. return msg_bits(m, 0, 18, 1);
  205. }
  206. static inline void msg_set_src_droppable(struct tipc_msg *m, u32 d)
  207. {
  208. msg_set_bits(m, 0, 18, 1, d);
  209. }
  210. static inline void msg_set_size(struct tipc_msg *m, u32 sz)
  211. {
  212. m->hdr[0] = htonl((msg_word(m, 0) & ~0x1ffff) | sz);
  213. }
  214. static inline unchar *msg_data(struct tipc_msg *m)
  215. {
  216. return ((unchar *)m) + msg_hdr_sz(m);
  217. }
  218. static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m)
  219. {
  220. return (struct tipc_msg *)msg_data(m);
  221. }
  222. /*
  223. * Word 1
  224. */
  225. static inline u32 msg_type(struct tipc_msg *m)
  226. {
  227. return msg_bits(m, 1, 29, 0x7);
  228. }
  229. static inline void msg_set_type(struct tipc_msg *m, u32 n)
  230. {
  231. msg_set_bits(m, 1, 29, 0x7, n);
  232. }
  233. static inline int msg_in_group(struct tipc_msg *m)
  234. {
  235. int mtyp = msg_type(m);
  236. return mtyp >= TIPC_GRP_MEMBER_EVT && mtyp <= TIPC_GRP_UCAST_MSG;
  237. }
  238. static inline bool msg_is_grp_evt(struct tipc_msg *m)
  239. {
  240. return msg_type(m) == TIPC_GRP_MEMBER_EVT;
  241. }
  242. static inline u32 msg_named(struct tipc_msg *m)
  243. {
  244. return msg_type(m) == TIPC_NAMED_MSG;
  245. }
  246. static inline u32 msg_mcast(struct tipc_msg *m)
  247. {
  248. int mtyp = msg_type(m);
  249. return ((mtyp == TIPC_MCAST_MSG) || (mtyp == TIPC_GRP_BCAST_MSG) ||
  250. (mtyp == TIPC_GRP_MCAST_MSG));
  251. }
  252. static inline u32 msg_connected(struct tipc_msg *m)
  253. {
  254. return msg_type(m) == TIPC_CONN_MSG;
  255. }
  256. static inline u32 msg_errcode(struct tipc_msg *m)
  257. {
  258. return msg_bits(m, 1, 25, 0xf);
  259. }
  260. static inline void msg_set_errcode(struct tipc_msg *m, u32 err)
  261. {
  262. msg_set_bits(m, 1, 25, 0xf, err);
  263. }
  264. static inline u32 msg_reroute_cnt(struct tipc_msg *m)
  265. {
  266. return msg_bits(m, 1, 21, 0xf);
  267. }
  268. static inline void msg_incr_reroute_cnt(struct tipc_msg *m)
  269. {
  270. msg_set_bits(m, 1, 21, 0xf, msg_reroute_cnt(m) + 1);
  271. }
  272. static inline void msg_reset_reroute_cnt(struct tipc_msg *m)
  273. {
  274. msg_set_bits(m, 1, 21, 0xf, 0);
  275. }
  276. static inline u32 msg_lookup_scope(struct tipc_msg *m)
  277. {
  278. return msg_bits(m, 1, 19, 0x3);
  279. }
  280. static inline void msg_set_lookup_scope(struct tipc_msg *m, u32 n)
  281. {
  282. msg_set_bits(m, 1, 19, 0x3, n);
  283. }
  284. static inline u16 msg_bcast_ack(struct tipc_msg *m)
  285. {
  286. return msg_bits(m, 1, 0, 0xffff);
  287. }
  288. static inline void msg_set_bcast_ack(struct tipc_msg *m, u16 n)
  289. {
  290. msg_set_bits(m, 1, 0, 0xffff, n);
  291. }
  292. /*
  293. * Word 2
  294. */
  295. static inline u16 msg_ack(struct tipc_msg *m)
  296. {
  297. return msg_bits(m, 2, 16, 0xffff);
  298. }
  299. static inline void msg_set_ack(struct tipc_msg *m, u16 n)
  300. {
  301. msg_set_bits(m, 2, 16, 0xffff, n);
  302. }
  303. static inline u16 msg_seqno(struct tipc_msg *m)
  304. {
  305. return msg_bits(m, 2, 0, 0xffff);
  306. }
  307. static inline void msg_set_seqno(struct tipc_msg *m, u16 n)
  308. {
  309. msg_set_bits(m, 2, 0, 0xffff, n);
  310. }
  311. /*
  312. * Words 3-10
  313. */
  314. static inline u32 msg_importance(struct tipc_msg *m)
  315. {
  316. int usr = msg_user(m);
  317. if (likely((usr <= TIPC_CRITICAL_IMPORTANCE) && !msg_errcode(m)))
  318. return usr;
  319. if ((usr == MSG_FRAGMENTER) || (usr == MSG_BUNDLER))
  320. return msg_bits(m, 9, 0, 0x7);
  321. return TIPC_SYSTEM_IMPORTANCE;
  322. }
  323. static inline void msg_set_importance(struct tipc_msg *m, u32 i)
  324. {
  325. int usr = msg_user(m);
  326. if (likely((usr == MSG_FRAGMENTER) || (usr == MSG_BUNDLER)))
  327. msg_set_bits(m, 9, 0, 0x7, i);
  328. else if (i < TIPC_SYSTEM_IMPORTANCE)
  329. msg_set_user(m, i);
  330. else
  331. pr_warn("Trying to set illegal importance in message\n");
  332. }
  333. static inline u32 msg_prevnode(struct tipc_msg *m)
  334. {
  335. return msg_word(m, 3);
  336. }
  337. static inline void msg_set_prevnode(struct tipc_msg *m, u32 a)
  338. {
  339. msg_set_word(m, 3, a);
  340. }
  341. static inline u32 msg_origport(struct tipc_msg *m)
  342. {
  343. if (msg_user(m) == MSG_FRAGMENTER)
  344. m = msg_get_wrapped(m);
  345. return msg_word(m, 4);
  346. }
  347. static inline void msg_set_origport(struct tipc_msg *m, u32 p)
  348. {
  349. msg_set_word(m, 4, p);
  350. }
  351. static inline u32 msg_destport(struct tipc_msg *m)
  352. {
  353. return msg_word(m, 5);
  354. }
  355. static inline void msg_set_destport(struct tipc_msg *m, u32 p)
  356. {
  357. msg_set_word(m, 5, p);
  358. }
  359. static inline u32 msg_mc_netid(struct tipc_msg *m)
  360. {
  361. return msg_word(m, 5);
  362. }
  363. static inline void msg_set_mc_netid(struct tipc_msg *m, u32 p)
  364. {
  365. msg_set_word(m, 5, p);
  366. }
  367. static inline int msg_short(struct tipc_msg *m)
  368. {
  369. return msg_hdr_sz(m) == SHORT_H_SIZE;
  370. }
  371. static inline u32 msg_orignode(struct tipc_msg *m)
  372. {
  373. if (likely(msg_short(m)))
  374. return msg_prevnode(m);
  375. return msg_word(m, 6);
  376. }
  377. static inline void msg_set_orignode(struct tipc_msg *m, u32 a)
  378. {
  379. msg_set_word(m, 6, a);
  380. }
  381. static inline u32 msg_destnode(struct tipc_msg *m)
  382. {
  383. return msg_word(m, 7);
  384. }
  385. static inline void msg_set_destnode(struct tipc_msg *m, u32 a)
  386. {
  387. msg_set_word(m, 7, a);
  388. }
  389. static inline u32 msg_nametype(struct tipc_msg *m)
  390. {
  391. return msg_word(m, 8);
  392. }
  393. static inline void msg_set_nametype(struct tipc_msg *m, u32 n)
  394. {
  395. msg_set_word(m, 8, n);
  396. }
  397. static inline u32 msg_nameinst(struct tipc_msg *m)
  398. {
  399. return msg_word(m, 9);
  400. }
  401. static inline u32 msg_namelower(struct tipc_msg *m)
  402. {
  403. return msg_nameinst(m);
  404. }
  405. static inline void msg_set_namelower(struct tipc_msg *m, u32 n)
  406. {
  407. msg_set_word(m, 9, n);
  408. }
  409. static inline void msg_set_nameinst(struct tipc_msg *m, u32 n)
  410. {
  411. msg_set_namelower(m, n);
  412. }
  413. static inline u32 msg_nameupper(struct tipc_msg *m)
  414. {
  415. return msg_word(m, 10);
  416. }
  417. static inline void msg_set_nameupper(struct tipc_msg *m, u32 n)
  418. {
  419. msg_set_word(m, 10, n);
  420. }
  421. /*
  422. * Constants and routines used to read and write TIPC internal message headers
  423. */
  424. /*
  425. * Connection management protocol message types
  426. */
  427. #define CONN_PROBE 0
  428. #define CONN_PROBE_REPLY 1
  429. #define CONN_ACK 2
  430. /*
  431. * Name distributor message types
  432. */
  433. #define PUBLICATION 0
  434. #define WITHDRAWAL 1
  435. /*
  436. * Segmentation message types
  437. */
  438. #define FIRST_FRAGMENT 0
  439. #define FRAGMENT 1
  440. #define LAST_FRAGMENT 2
  441. /*
  442. * Link management protocol message types
  443. */
  444. #define STATE_MSG 0
  445. #define RESET_MSG 1
  446. #define ACTIVATE_MSG 2
  447. /*
  448. * Changeover tunnel message types
  449. */
  450. #define SYNCH_MSG 0
  451. #define FAILOVER_MSG 1
  452. /*
  453. * Config protocol message types
  454. */
  455. #define DSC_REQ_MSG 0
  456. #define DSC_RESP_MSG 1
  457. /*
  458. * Group protocol message types
  459. */
  460. #define GRP_JOIN_MSG 0
  461. #define GRP_LEAVE_MSG 1
  462. #define GRP_ADV_MSG 2
  463. #define GRP_ACK_MSG 3
  464. #define GRP_RECLAIM_MSG 4
  465. #define GRP_REMIT_MSG 5
  466. /*
  467. * Word 1
  468. */
  469. static inline u32 msg_seq_gap(struct tipc_msg *m)
  470. {
  471. return msg_bits(m, 1, 16, 0x1fff);
  472. }
  473. static inline void msg_set_seq_gap(struct tipc_msg *m, u32 n)
  474. {
  475. msg_set_bits(m, 1, 16, 0x1fff, n);
  476. }
  477. static inline u32 msg_node_sig(struct tipc_msg *m)
  478. {
  479. return msg_bits(m, 1, 0, 0xffff);
  480. }
  481. static inline void msg_set_node_sig(struct tipc_msg *m, u32 n)
  482. {
  483. msg_set_bits(m, 1, 0, 0xffff, n);
  484. }
  485. static inline u32 msg_node_capabilities(struct tipc_msg *m)
  486. {
  487. return msg_bits(m, 1, 15, 0x1fff);
  488. }
  489. static inline void msg_set_node_capabilities(struct tipc_msg *m, u32 n)
  490. {
  491. msg_set_bits(m, 1, 15, 0x1fff, n);
  492. }
  493. /*
  494. * Word 2
  495. */
  496. static inline u32 msg_dest_domain(struct tipc_msg *m)
  497. {
  498. return msg_word(m, 2);
  499. }
  500. static inline void msg_set_dest_domain(struct tipc_msg *m, u32 n)
  501. {
  502. msg_set_word(m, 2, n);
  503. }
  504. static inline u32 msg_bcgap_after(struct tipc_msg *m)
  505. {
  506. return msg_bits(m, 2, 16, 0xffff);
  507. }
  508. static inline void msg_set_bcgap_after(struct tipc_msg *m, u32 n)
  509. {
  510. msg_set_bits(m, 2, 16, 0xffff, n);
  511. }
  512. static inline u32 msg_bcgap_to(struct tipc_msg *m)
  513. {
  514. return msg_bits(m, 2, 0, 0xffff);
  515. }
  516. static inline void msg_set_bcgap_to(struct tipc_msg *m, u32 n)
  517. {
  518. msg_set_bits(m, 2, 0, 0xffff, n);
  519. }
  520. /*
  521. * Word 4
  522. */
  523. static inline u32 msg_last_bcast(struct tipc_msg *m)
  524. {
  525. return msg_bits(m, 4, 16, 0xffff);
  526. }
  527. static inline u32 msg_bc_snd_nxt(struct tipc_msg *m)
  528. {
  529. return msg_last_bcast(m) + 1;
  530. }
  531. static inline void msg_set_last_bcast(struct tipc_msg *m, u32 n)
  532. {
  533. msg_set_bits(m, 4, 16, 0xffff, n);
  534. }
  535. static inline void msg_set_fragm_no(struct tipc_msg *m, u32 n)
  536. {
  537. msg_set_bits(m, 4, 16, 0xffff, n);
  538. }
  539. static inline u16 msg_next_sent(struct tipc_msg *m)
  540. {
  541. return msg_bits(m, 4, 0, 0xffff);
  542. }
  543. static inline void msg_set_next_sent(struct tipc_msg *m, u16 n)
  544. {
  545. msg_set_bits(m, 4, 0, 0xffff, n);
  546. }
  547. static inline void msg_set_long_msgno(struct tipc_msg *m, u32 n)
  548. {
  549. msg_set_bits(m, 4, 0, 0xffff, n);
  550. }
  551. static inline u32 msg_bc_netid(struct tipc_msg *m)
  552. {
  553. return msg_word(m, 4);
  554. }
  555. static inline void msg_set_bc_netid(struct tipc_msg *m, u32 id)
  556. {
  557. msg_set_word(m, 4, id);
  558. }
  559. static inline u32 msg_link_selector(struct tipc_msg *m)
  560. {
  561. if (msg_user(m) == MSG_FRAGMENTER)
  562. m = (void *)msg_data(m);
  563. return msg_bits(m, 4, 0, 1);
  564. }
  565. /*
  566. * Word 5
  567. */
  568. static inline u16 msg_session(struct tipc_msg *m)
  569. {
  570. return msg_bits(m, 5, 16, 0xffff);
  571. }
  572. static inline void msg_set_session(struct tipc_msg *m, u16 n)
  573. {
  574. msg_set_bits(m, 5, 16, 0xffff, n);
  575. }
  576. static inline u32 msg_probe(struct tipc_msg *m)
  577. {
  578. return msg_bits(m, 5, 0, 1);
  579. }
  580. static inline void msg_set_probe(struct tipc_msg *m, u32 val)
  581. {
  582. msg_set_bits(m, 5, 0, 1, val);
  583. }
  584. static inline char msg_net_plane(struct tipc_msg *m)
  585. {
  586. return msg_bits(m, 5, 1, 7) + 'A';
  587. }
  588. static inline void msg_set_net_plane(struct tipc_msg *m, char n)
  589. {
  590. msg_set_bits(m, 5, 1, 7, (n - 'A'));
  591. }
  592. static inline u32 msg_linkprio(struct tipc_msg *m)
  593. {
  594. return msg_bits(m, 5, 4, 0x1f);
  595. }
  596. static inline void msg_set_linkprio(struct tipc_msg *m, u32 n)
  597. {
  598. msg_set_bits(m, 5, 4, 0x1f, n);
  599. }
  600. static inline u32 msg_bearer_id(struct tipc_msg *m)
  601. {
  602. return msg_bits(m, 5, 9, 0x7);
  603. }
  604. static inline void msg_set_bearer_id(struct tipc_msg *m, u32 n)
  605. {
  606. msg_set_bits(m, 5, 9, 0x7, n);
  607. }
  608. static inline u32 msg_redundant_link(struct tipc_msg *m)
  609. {
  610. return msg_bits(m, 5, 12, 0x1);
  611. }
  612. static inline void msg_set_redundant_link(struct tipc_msg *m, u32 r)
  613. {
  614. msg_set_bits(m, 5, 12, 0x1, r);
  615. }
  616. static inline u32 msg_peer_stopping(struct tipc_msg *m)
  617. {
  618. return msg_bits(m, 5, 13, 0x1);
  619. }
  620. static inline void msg_set_peer_stopping(struct tipc_msg *m, u32 s)
  621. {
  622. msg_set_bits(m, 5, 13, 0x1, s);
  623. }
  624. static inline bool msg_bc_ack_invalid(struct tipc_msg *m)
  625. {
  626. switch (msg_user(m)) {
  627. case BCAST_PROTOCOL:
  628. case NAME_DISTRIBUTOR:
  629. case LINK_PROTOCOL:
  630. return msg_bits(m, 5, 14, 0x1);
  631. default:
  632. return false;
  633. }
  634. }
  635. static inline void msg_set_bc_ack_invalid(struct tipc_msg *m, bool invalid)
  636. {
  637. msg_set_bits(m, 5, 14, 0x1, invalid);
  638. }
  639. static inline char *msg_media_addr(struct tipc_msg *m)
  640. {
  641. return (char *)&m->hdr[TIPC_MEDIA_INFO_OFFSET];
  642. }
  643. static inline u32 msg_bc_gap(struct tipc_msg *m)
  644. {
  645. return msg_bits(m, 8, 0, 0x3ff);
  646. }
  647. static inline void msg_set_bc_gap(struct tipc_msg *m, u32 n)
  648. {
  649. msg_set_bits(m, 8, 0, 0x3ff, n);
  650. }
  651. /*
  652. * Word 9
  653. */
  654. static inline u16 msg_msgcnt(struct tipc_msg *m)
  655. {
  656. return msg_bits(m, 9, 16, 0xffff);
  657. }
  658. static inline void msg_set_msgcnt(struct tipc_msg *m, u16 n)
  659. {
  660. msg_set_bits(m, 9, 16, 0xffff, n);
  661. }
  662. static inline u32 msg_conn_ack(struct tipc_msg *m)
  663. {
  664. return msg_bits(m, 9, 16, 0xffff);
  665. }
  666. static inline void msg_set_conn_ack(struct tipc_msg *m, u32 n)
  667. {
  668. msg_set_bits(m, 9, 16, 0xffff, n);
  669. }
  670. static inline u16 msg_adv_win(struct tipc_msg *m)
  671. {
  672. return msg_bits(m, 9, 0, 0xffff);
  673. }
  674. static inline void msg_set_adv_win(struct tipc_msg *m, u16 n)
  675. {
  676. msg_set_bits(m, 9, 0, 0xffff, n);
  677. }
  678. static inline u32 msg_max_pkt(struct tipc_msg *m)
  679. {
  680. return msg_bits(m, 9, 16, 0xffff) * 4;
  681. }
  682. static inline void msg_set_max_pkt(struct tipc_msg *m, u32 n)
  683. {
  684. msg_set_bits(m, 9, 16, 0xffff, (n / 4));
  685. }
  686. static inline u32 msg_link_tolerance(struct tipc_msg *m)
  687. {
  688. return msg_bits(m, 9, 0, 0xffff);
  689. }
  690. static inline void msg_set_link_tolerance(struct tipc_msg *m, u32 n)
  691. {
  692. msg_set_bits(m, 9, 0, 0xffff, n);
  693. }
  694. static inline u16 msg_grp_bc_syncpt(struct tipc_msg *m)
  695. {
  696. return msg_bits(m, 9, 16, 0xffff);
  697. }
  698. static inline void msg_set_grp_bc_syncpt(struct tipc_msg *m, u16 n)
  699. {
  700. msg_set_bits(m, 9, 16, 0xffff, n);
  701. }
  702. static inline u16 msg_grp_bc_acked(struct tipc_msg *m)
  703. {
  704. return msg_bits(m, 9, 16, 0xffff);
  705. }
  706. static inline void msg_set_grp_bc_acked(struct tipc_msg *m, u16 n)
  707. {
  708. msg_set_bits(m, 9, 16, 0xffff, n);
  709. }
  710. static inline u16 msg_grp_remitted(struct tipc_msg *m)
  711. {
  712. return msg_bits(m, 9, 16, 0xffff);
  713. }
  714. static inline void msg_set_grp_remitted(struct tipc_msg *m, u16 n)
  715. {
  716. msg_set_bits(m, 9, 16, 0xffff, n);
  717. }
  718. /* Word 10
  719. */
  720. static inline u16 msg_grp_evt(struct tipc_msg *m)
  721. {
  722. return msg_bits(m, 10, 0, 0x3);
  723. }
  724. static inline void msg_set_grp_evt(struct tipc_msg *m, int n)
  725. {
  726. msg_set_bits(m, 10, 0, 0x3, n);
  727. }
  728. static inline u16 msg_grp_bc_ack_req(struct tipc_msg *m)
  729. {
  730. return msg_bits(m, 10, 0, 0x1);
  731. }
  732. static inline void msg_set_grp_bc_ack_req(struct tipc_msg *m, bool n)
  733. {
  734. msg_set_bits(m, 10, 0, 0x1, n);
  735. }
  736. static inline u16 msg_grp_bc_seqno(struct tipc_msg *m)
  737. {
  738. return msg_bits(m, 10, 16, 0xffff);
  739. }
  740. static inline void msg_set_grp_bc_seqno(struct tipc_msg *m, u32 n)
  741. {
  742. msg_set_bits(m, 10, 16, 0xffff, n);
  743. }
  744. static inline bool msg_peer_link_is_up(struct tipc_msg *m)
  745. {
  746. if (likely(msg_user(m) != LINK_PROTOCOL))
  747. return true;
  748. if (msg_type(m) == STATE_MSG)
  749. return true;
  750. return false;
  751. }
  752. static inline bool msg_peer_node_is_up(struct tipc_msg *m)
  753. {
  754. if (msg_peer_link_is_up(m))
  755. return true;
  756. return msg_redundant_link(m);
  757. }
  758. static inline bool msg_is_reset(struct tipc_msg *hdr)
  759. {
  760. return (msg_user(hdr) == LINK_PROTOCOL) && (msg_type(hdr) == RESET_MSG);
  761. }
  762. struct sk_buff *tipc_buf_acquire(u32 size, gfp_t gfp);
  763. bool tipc_msg_validate(struct sk_buff **_skb);
  764. bool tipc_msg_reverse(u32 own_addr, struct sk_buff **skb, int err);
  765. void tipc_skb_reject(struct net *net, int err, struct sk_buff *skb,
  766. struct sk_buff_head *xmitq);
  767. void tipc_msg_init(u32 own_addr, struct tipc_msg *m, u32 user, u32 type,
  768. u32 hsize, u32 destnode);
  769. struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz,
  770. uint data_sz, u32 dnode, u32 onode,
  771. u32 dport, u32 oport, int errcode);
  772. int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf);
  773. bool tipc_msg_bundle(struct sk_buff *skb, struct tipc_msg *msg, u32 mtu);
  774. bool tipc_msg_make_bundle(struct sk_buff **skb, struct tipc_msg *msg,
  775. u32 mtu, u32 dnode);
  776. bool tipc_msg_extract(struct sk_buff *skb, struct sk_buff **iskb, int *pos);
  777. int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m,
  778. int offset, int dsz, int mtu, struct sk_buff_head *list);
  779. bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err);
  780. bool tipc_msg_reassemble(struct sk_buff_head *list, struct sk_buff_head *rcvq);
  781. bool tipc_msg_pskb_copy(u32 dst, struct sk_buff_head *msg,
  782. struct sk_buff_head *cpy);
  783. void __tipc_skb_queue_sorted(struct sk_buff_head *list, u16 seqno,
  784. struct sk_buff *skb);
  785. static inline u16 buf_seqno(struct sk_buff *skb)
  786. {
  787. return msg_seqno(buf_msg(skb));
  788. }
  789. static inline int buf_roundup_len(struct sk_buff *skb)
  790. {
  791. return (skb->len / 1024 + 1) * 1024;
  792. }
  793. /* tipc_skb_peek(): peek and reserve first buffer in list
  794. * @list: list to be peeked in
  795. * Returns pointer to first buffer in list, if any
  796. */
  797. static inline struct sk_buff *tipc_skb_peek(struct sk_buff_head *list,
  798. spinlock_t *lock)
  799. {
  800. struct sk_buff *skb;
  801. spin_lock_bh(lock);
  802. skb = skb_peek(list);
  803. if (skb)
  804. skb_get(skb);
  805. spin_unlock_bh(lock);
  806. return skb;
  807. }
  808. /* tipc_skb_peek_port(): find a destination port, ignoring all destinations
  809. * up to and including 'filter'.
  810. * Note: ignoring previously tried destinations minimizes the risk of
  811. * contention on the socket lock
  812. * @list: list to be peeked in
  813. * @filter: last destination to be ignored from search
  814. * Returns a destination port number, of applicable.
  815. */
  816. static inline u32 tipc_skb_peek_port(struct sk_buff_head *list, u32 filter)
  817. {
  818. struct sk_buff *skb;
  819. u32 dport = 0;
  820. bool ignore = true;
  821. spin_lock_bh(&list->lock);
  822. skb_queue_walk(list, skb) {
  823. dport = msg_destport(buf_msg(skb));
  824. if (!filter || skb_queue_is_last(list, skb))
  825. break;
  826. if (dport == filter)
  827. ignore = false;
  828. else if (!ignore)
  829. break;
  830. }
  831. spin_unlock_bh(&list->lock);
  832. return dport;
  833. }
  834. /* tipc_skb_dequeue(): unlink first buffer with dest 'dport' from list
  835. * @list: list to be unlinked from
  836. * @dport: selection criteria for buffer to unlink
  837. */
  838. static inline struct sk_buff *tipc_skb_dequeue(struct sk_buff_head *list,
  839. u32 dport)
  840. {
  841. struct sk_buff *_skb, *tmp, *skb = NULL;
  842. spin_lock_bh(&list->lock);
  843. skb_queue_walk_safe(list, _skb, tmp) {
  844. if (msg_destport(buf_msg(_skb)) == dport) {
  845. __skb_unlink(_skb, list);
  846. skb = _skb;
  847. break;
  848. }
  849. }
  850. spin_unlock_bh(&list->lock);
  851. return skb;
  852. }
  853. /* tipc_skb_queue_splice_tail - append an skb list to lock protected list
  854. * @list: the new list to append. Not lock protected
  855. * @head: target list. Lock protected.
  856. */
  857. static inline void tipc_skb_queue_splice_tail(struct sk_buff_head *list,
  858. struct sk_buff_head *head)
  859. {
  860. spin_lock_bh(&head->lock);
  861. skb_queue_splice_tail(list, head);
  862. spin_unlock_bh(&head->lock);
  863. }
  864. /* tipc_skb_queue_splice_tail_init - merge two lock protected skb lists
  865. * @list: the new list to add. Lock protected. Will be reinitialized
  866. * @head: target list. Lock protected.
  867. */
  868. static inline void tipc_skb_queue_splice_tail_init(struct sk_buff_head *list,
  869. struct sk_buff_head *head)
  870. {
  871. struct sk_buff_head tmp;
  872. __skb_queue_head_init(&tmp);
  873. spin_lock_bh(&list->lock);
  874. skb_queue_splice_tail_init(list, &tmp);
  875. spin_unlock_bh(&list->lock);
  876. tipc_skb_queue_splice_tail(&tmp, head);
  877. }
  878. #endif