msg.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. /*
  2. * net/tipc/msg.h: Include file for TIPC message header routines
  3. *
  4. * Copyright (c) 2000-2007, 2014, 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. /*
  40. * Constants and routines used to read and write TIPC payload message headers
  41. *
  42. * Note: Some items are also used with TIPC internal message headers
  43. */
  44. #define TIPC_VERSION 2
  45. struct plist;
  46. /*
  47. * Payload message users are defined in TIPC's public API:
  48. * - TIPC_LOW_IMPORTANCE
  49. * - TIPC_MEDIUM_IMPORTANCE
  50. * - TIPC_HIGH_IMPORTANCE
  51. * - TIPC_CRITICAL_IMPORTANCE
  52. */
  53. /*
  54. * Payload message types
  55. */
  56. #define TIPC_CONN_MSG 0
  57. #define TIPC_MCAST_MSG 1
  58. #define TIPC_NAMED_MSG 2
  59. #define TIPC_DIRECT_MSG 3
  60. /*
  61. * Message header sizes
  62. */
  63. #define SHORT_H_SIZE 24 /* In-cluster basic payload message */
  64. #define BASIC_H_SIZE 32 /* Basic payload message */
  65. #define NAMED_H_SIZE 40 /* Named payload message */
  66. #define MCAST_H_SIZE 44 /* Multicast payload message */
  67. #define INT_H_SIZE 40 /* Internal messages */
  68. #define MIN_H_SIZE 24 /* Smallest legal TIPC header size */
  69. #define MAX_H_SIZE 60 /* Largest possible TIPC header size */
  70. #define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE)
  71. #define TIPC_MEDIA_INFO_OFFSET 5
  72. /**
  73. * TIPC message buffer code
  74. *
  75. * TIPC message buffer headroom reserves space for the worst-case
  76. * link-level device header (in case the message is sent off-node).
  77. *
  78. * Note: Headroom should be a multiple of 4 to ensure the TIPC header fields
  79. * are word aligned for quicker access
  80. */
  81. #define BUF_HEADROOM (LL_MAX_HEADER + 48)
  82. struct tipc_skb_cb {
  83. void *handle;
  84. struct sk_buff *tail;
  85. bool deferred;
  86. bool wakeup_pending;
  87. bool bundling;
  88. u16 chain_sz;
  89. u16 chain_imp;
  90. };
  91. #define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0]))
  92. struct tipc_msg {
  93. __be32 hdr[15];
  94. };
  95. static inline struct tipc_msg *buf_msg(struct sk_buff *skb)
  96. {
  97. return (struct tipc_msg *)skb->data;
  98. }
  99. static inline u32 msg_word(struct tipc_msg *m, u32 pos)
  100. {
  101. return ntohl(m->hdr[pos]);
  102. }
  103. static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val)
  104. {
  105. m->hdr[w] = htonl(val);
  106. }
  107. static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask)
  108. {
  109. return (msg_word(m, w) >> pos) & mask;
  110. }
  111. static inline void msg_set_bits(struct tipc_msg *m, u32 w,
  112. u32 pos, u32 mask, u32 val)
  113. {
  114. val = (val & mask) << pos;
  115. mask = mask << pos;
  116. m->hdr[w] &= ~htonl(mask);
  117. m->hdr[w] |= htonl(val);
  118. }
  119. static inline void msg_swap_words(struct tipc_msg *msg, u32 a, u32 b)
  120. {
  121. u32 temp = msg->hdr[a];
  122. msg->hdr[a] = msg->hdr[b];
  123. msg->hdr[b] = temp;
  124. }
  125. /*
  126. * Word 0
  127. */
  128. static inline u32 msg_version(struct tipc_msg *m)
  129. {
  130. return msg_bits(m, 0, 29, 7);
  131. }
  132. static inline void msg_set_version(struct tipc_msg *m)
  133. {
  134. msg_set_bits(m, 0, 29, 7, TIPC_VERSION);
  135. }
  136. static inline u32 msg_user(struct tipc_msg *m)
  137. {
  138. return msg_bits(m, 0, 25, 0xf);
  139. }
  140. static inline u32 msg_isdata(struct tipc_msg *m)
  141. {
  142. return msg_user(m) <= TIPC_CRITICAL_IMPORTANCE;
  143. }
  144. static inline void msg_set_user(struct tipc_msg *m, u32 n)
  145. {
  146. msg_set_bits(m, 0, 25, 0xf, n);
  147. }
  148. static inline u32 msg_importance(struct tipc_msg *m)
  149. {
  150. return msg_bits(m, 0, 25, 0xf);
  151. }
  152. static inline void msg_set_importance(struct tipc_msg *m, u32 i)
  153. {
  154. msg_set_user(m, i);
  155. }
  156. static inline u32 msg_hdr_sz(struct tipc_msg *m)
  157. {
  158. return msg_bits(m, 0, 21, 0xf) << 2;
  159. }
  160. static inline void msg_set_hdr_sz(struct tipc_msg *m, u32 n)
  161. {
  162. msg_set_bits(m, 0, 21, 0xf, n>>2);
  163. }
  164. static inline u32 msg_size(struct tipc_msg *m)
  165. {
  166. return msg_bits(m, 0, 0, 0x1ffff);
  167. }
  168. static inline u32 msg_data_sz(struct tipc_msg *m)
  169. {
  170. return msg_size(m) - msg_hdr_sz(m);
  171. }
  172. static inline int msg_non_seq(struct tipc_msg *m)
  173. {
  174. return msg_bits(m, 0, 20, 1);
  175. }
  176. static inline void msg_set_non_seq(struct tipc_msg *m, u32 n)
  177. {
  178. msg_set_bits(m, 0, 20, 1, n);
  179. }
  180. static inline int msg_dest_droppable(struct tipc_msg *m)
  181. {
  182. return msg_bits(m, 0, 19, 1);
  183. }
  184. static inline void msg_set_dest_droppable(struct tipc_msg *m, u32 d)
  185. {
  186. msg_set_bits(m, 0, 19, 1, d);
  187. }
  188. static inline int msg_src_droppable(struct tipc_msg *m)
  189. {
  190. return msg_bits(m, 0, 18, 1);
  191. }
  192. static inline void msg_set_src_droppable(struct tipc_msg *m, u32 d)
  193. {
  194. msg_set_bits(m, 0, 18, 1, d);
  195. }
  196. static inline void msg_set_size(struct tipc_msg *m, u32 sz)
  197. {
  198. m->hdr[0] = htonl((msg_word(m, 0) & ~0x1ffff) | sz);
  199. }
  200. /*
  201. * Word 1
  202. */
  203. static inline u32 msg_type(struct tipc_msg *m)
  204. {
  205. return msg_bits(m, 1, 29, 0x7);
  206. }
  207. static inline void msg_set_type(struct tipc_msg *m, u32 n)
  208. {
  209. msg_set_bits(m, 1, 29, 0x7, n);
  210. }
  211. static inline u32 msg_named(struct tipc_msg *m)
  212. {
  213. return msg_type(m) == TIPC_NAMED_MSG;
  214. }
  215. static inline u32 msg_mcast(struct tipc_msg *m)
  216. {
  217. return msg_type(m) == TIPC_MCAST_MSG;
  218. }
  219. static inline u32 msg_connected(struct tipc_msg *m)
  220. {
  221. return msg_type(m) == TIPC_CONN_MSG;
  222. }
  223. static inline u32 msg_errcode(struct tipc_msg *m)
  224. {
  225. return msg_bits(m, 1, 25, 0xf);
  226. }
  227. static inline void msg_set_errcode(struct tipc_msg *m, u32 err)
  228. {
  229. msg_set_bits(m, 1, 25, 0xf, err);
  230. }
  231. static inline u32 msg_reroute_cnt(struct tipc_msg *m)
  232. {
  233. return msg_bits(m, 1, 21, 0xf);
  234. }
  235. static inline void msg_incr_reroute_cnt(struct tipc_msg *m)
  236. {
  237. msg_set_bits(m, 1, 21, 0xf, msg_reroute_cnt(m) + 1);
  238. }
  239. static inline void msg_reset_reroute_cnt(struct tipc_msg *m)
  240. {
  241. msg_set_bits(m, 1, 21, 0xf, 0);
  242. }
  243. static inline u32 msg_lookup_scope(struct tipc_msg *m)
  244. {
  245. return msg_bits(m, 1, 19, 0x3);
  246. }
  247. static inline void msg_set_lookup_scope(struct tipc_msg *m, u32 n)
  248. {
  249. msg_set_bits(m, 1, 19, 0x3, n);
  250. }
  251. static inline u32 msg_bcast_ack(struct tipc_msg *m)
  252. {
  253. return msg_bits(m, 1, 0, 0xffff);
  254. }
  255. static inline void msg_set_bcast_ack(struct tipc_msg *m, u32 n)
  256. {
  257. msg_set_bits(m, 1, 0, 0xffff, n);
  258. }
  259. /*
  260. * Word 2
  261. */
  262. static inline u32 msg_ack(struct tipc_msg *m)
  263. {
  264. return msg_bits(m, 2, 16, 0xffff);
  265. }
  266. static inline void msg_set_ack(struct tipc_msg *m, u32 n)
  267. {
  268. msg_set_bits(m, 2, 16, 0xffff, n);
  269. }
  270. static inline u32 msg_seqno(struct tipc_msg *m)
  271. {
  272. return msg_bits(m, 2, 0, 0xffff);
  273. }
  274. static inline void msg_set_seqno(struct tipc_msg *m, u32 n)
  275. {
  276. msg_set_bits(m, 2, 0, 0xffff, n);
  277. }
  278. /*
  279. * Words 3-10
  280. */
  281. static inline u32 msg_prevnode(struct tipc_msg *m)
  282. {
  283. return msg_word(m, 3);
  284. }
  285. static inline void msg_set_prevnode(struct tipc_msg *m, u32 a)
  286. {
  287. msg_set_word(m, 3, a);
  288. }
  289. static inline u32 msg_origport(struct tipc_msg *m)
  290. {
  291. return msg_word(m, 4);
  292. }
  293. static inline void msg_set_origport(struct tipc_msg *m, u32 p)
  294. {
  295. msg_set_word(m, 4, p);
  296. }
  297. static inline u32 msg_destport(struct tipc_msg *m)
  298. {
  299. return msg_word(m, 5);
  300. }
  301. static inline void msg_set_destport(struct tipc_msg *m, u32 p)
  302. {
  303. msg_set_word(m, 5, p);
  304. }
  305. static inline u32 msg_mc_netid(struct tipc_msg *m)
  306. {
  307. return msg_word(m, 5);
  308. }
  309. static inline void msg_set_mc_netid(struct tipc_msg *m, u32 p)
  310. {
  311. msg_set_word(m, 5, p);
  312. }
  313. static inline int msg_short(struct tipc_msg *m)
  314. {
  315. return msg_hdr_sz(m) == SHORT_H_SIZE;
  316. }
  317. static inline u32 msg_orignode(struct tipc_msg *m)
  318. {
  319. if (likely(msg_short(m)))
  320. return msg_prevnode(m);
  321. return msg_word(m, 6);
  322. }
  323. static inline void msg_set_orignode(struct tipc_msg *m, u32 a)
  324. {
  325. msg_set_word(m, 6, a);
  326. }
  327. static inline u32 msg_destnode(struct tipc_msg *m)
  328. {
  329. return msg_word(m, 7);
  330. }
  331. static inline void msg_set_destnode(struct tipc_msg *m, u32 a)
  332. {
  333. msg_set_word(m, 7, a);
  334. }
  335. static inline u32 msg_nametype(struct tipc_msg *m)
  336. {
  337. return msg_word(m, 8);
  338. }
  339. static inline void msg_set_nametype(struct tipc_msg *m, u32 n)
  340. {
  341. msg_set_word(m, 8, n);
  342. }
  343. static inline u32 msg_nameinst(struct tipc_msg *m)
  344. {
  345. return msg_word(m, 9);
  346. }
  347. static inline u32 msg_namelower(struct tipc_msg *m)
  348. {
  349. return msg_nameinst(m);
  350. }
  351. static inline void msg_set_namelower(struct tipc_msg *m, u32 n)
  352. {
  353. msg_set_word(m, 9, n);
  354. }
  355. static inline void msg_set_nameinst(struct tipc_msg *m, u32 n)
  356. {
  357. msg_set_namelower(m, n);
  358. }
  359. static inline u32 msg_nameupper(struct tipc_msg *m)
  360. {
  361. return msg_word(m, 10);
  362. }
  363. static inline void msg_set_nameupper(struct tipc_msg *m, u32 n)
  364. {
  365. msg_set_word(m, 10, n);
  366. }
  367. static inline unchar *msg_data(struct tipc_msg *m)
  368. {
  369. return ((unchar *)m) + msg_hdr_sz(m);
  370. }
  371. static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m)
  372. {
  373. return (struct tipc_msg *)msg_data(m);
  374. }
  375. /*
  376. * Constants and routines used to read and write TIPC internal message headers
  377. */
  378. /*
  379. * Internal message users
  380. */
  381. #define BCAST_PROTOCOL 5
  382. #define MSG_BUNDLER 6
  383. #define LINK_PROTOCOL 7
  384. #define CONN_MANAGER 8
  385. #define ROUTE_DISTRIBUTOR 9 /* obsoleted */
  386. #define CHANGEOVER_PROTOCOL 10
  387. #define NAME_DISTRIBUTOR 11
  388. #define MSG_FRAGMENTER 12
  389. #define LINK_CONFIG 13
  390. #define SOCK_WAKEUP 14 /* pseudo user */
  391. /*
  392. * Connection management protocol message types
  393. */
  394. #define CONN_PROBE 0
  395. #define CONN_PROBE_REPLY 1
  396. #define CONN_ACK 2
  397. /*
  398. * Name distributor message types
  399. */
  400. #define PUBLICATION 0
  401. #define WITHDRAWAL 1
  402. /*
  403. * Segmentation message types
  404. */
  405. #define FIRST_FRAGMENT 0
  406. #define FRAGMENT 1
  407. #define LAST_FRAGMENT 2
  408. /*
  409. * Link management protocol message types
  410. */
  411. #define STATE_MSG 0
  412. #define RESET_MSG 1
  413. #define ACTIVATE_MSG 2
  414. /*
  415. * Changeover tunnel message types
  416. */
  417. #define DUPLICATE_MSG 0
  418. #define ORIGINAL_MSG 1
  419. /*
  420. * Config protocol message types
  421. */
  422. #define DSC_REQ_MSG 0
  423. #define DSC_RESP_MSG 1
  424. /*
  425. * Word 1
  426. */
  427. static inline u32 msg_seq_gap(struct tipc_msg *m)
  428. {
  429. return msg_bits(m, 1, 16, 0x1fff);
  430. }
  431. static inline void msg_set_seq_gap(struct tipc_msg *m, u32 n)
  432. {
  433. msg_set_bits(m, 1, 16, 0x1fff, n);
  434. }
  435. static inline u32 msg_node_sig(struct tipc_msg *m)
  436. {
  437. return msg_bits(m, 1, 0, 0xffff);
  438. }
  439. static inline void msg_set_node_sig(struct tipc_msg *m, u32 n)
  440. {
  441. msg_set_bits(m, 1, 0, 0xffff, n);
  442. }
  443. /*
  444. * Word 2
  445. */
  446. static inline u32 msg_dest_domain(struct tipc_msg *m)
  447. {
  448. return msg_word(m, 2);
  449. }
  450. static inline void msg_set_dest_domain(struct tipc_msg *m, u32 n)
  451. {
  452. msg_set_word(m, 2, n);
  453. }
  454. static inline u32 msg_bcgap_after(struct tipc_msg *m)
  455. {
  456. return msg_bits(m, 2, 16, 0xffff);
  457. }
  458. static inline void msg_set_bcgap_after(struct tipc_msg *m, u32 n)
  459. {
  460. msg_set_bits(m, 2, 16, 0xffff, n);
  461. }
  462. static inline u32 msg_bcgap_to(struct tipc_msg *m)
  463. {
  464. return msg_bits(m, 2, 0, 0xffff);
  465. }
  466. static inline void msg_set_bcgap_to(struct tipc_msg *m, u32 n)
  467. {
  468. msg_set_bits(m, 2, 0, 0xffff, n);
  469. }
  470. /*
  471. * Word 4
  472. */
  473. static inline u32 msg_last_bcast(struct tipc_msg *m)
  474. {
  475. return msg_bits(m, 4, 16, 0xffff);
  476. }
  477. static inline void msg_set_last_bcast(struct tipc_msg *m, u32 n)
  478. {
  479. msg_set_bits(m, 4, 16, 0xffff, n);
  480. }
  481. static inline void msg_set_fragm_no(struct tipc_msg *m, u32 n)
  482. {
  483. msg_set_bits(m, 4, 16, 0xffff, n);
  484. }
  485. static inline u32 msg_next_sent(struct tipc_msg *m)
  486. {
  487. return msg_bits(m, 4, 0, 0xffff);
  488. }
  489. static inline void msg_set_next_sent(struct tipc_msg *m, u32 n)
  490. {
  491. msg_set_bits(m, 4, 0, 0xffff, n);
  492. }
  493. static inline void msg_set_long_msgno(struct tipc_msg *m, u32 n)
  494. {
  495. msg_set_bits(m, 4, 0, 0xffff, n);
  496. }
  497. static inline u32 msg_bc_netid(struct tipc_msg *m)
  498. {
  499. return msg_word(m, 4);
  500. }
  501. static inline void msg_set_bc_netid(struct tipc_msg *m, u32 id)
  502. {
  503. msg_set_word(m, 4, id);
  504. }
  505. static inline u32 msg_link_selector(struct tipc_msg *m)
  506. {
  507. return msg_bits(m, 4, 0, 1);
  508. }
  509. static inline void msg_set_link_selector(struct tipc_msg *m, u32 n)
  510. {
  511. msg_set_bits(m, 4, 0, 1, n);
  512. }
  513. /*
  514. * Word 5
  515. */
  516. static inline u32 msg_session(struct tipc_msg *m)
  517. {
  518. return msg_bits(m, 5, 16, 0xffff);
  519. }
  520. static inline void msg_set_session(struct tipc_msg *m, u32 n)
  521. {
  522. msg_set_bits(m, 5, 16, 0xffff, n);
  523. }
  524. static inline u32 msg_probe(struct tipc_msg *m)
  525. {
  526. return msg_bits(m, 5, 0, 1);
  527. }
  528. static inline void msg_set_probe(struct tipc_msg *m, u32 val)
  529. {
  530. msg_set_bits(m, 5, 0, 1, val);
  531. }
  532. static inline char msg_net_plane(struct tipc_msg *m)
  533. {
  534. return msg_bits(m, 5, 1, 7) + 'A';
  535. }
  536. static inline void msg_set_net_plane(struct tipc_msg *m, char n)
  537. {
  538. msg_set_bits(m, 5, 1, 7, (n - 'A'));
  539. }
  540. static inline u32 msg_linkprio(struct tipc_msg *m)
  541. {
  542. return msg_bits(m, 5, 4, 0x1f);
  543. }
  544. static inline void msg_set_linkprio(struct tipc_msg *m, u32 n)
  545. {
  546. msg_set_bits(m, 5, 4, 0x1f, n);
  547. }
  548. static inline u32 msg_bearer_id(struct tipc_msg *m)
  549. {
  550. return msg_bits(m, 5, 9, 0x7);
  551. }
  552. static inline void msg_set_bearer_id(struct tipc_msg *m, u32 n)
  553. {
  554. msg_set_bits(m, 5, 9, 0x7, n);
  555. }
  556. static inline u32 msg_redundant_link(struct tipc_msg *m)
  557. {
  558. return msg_bits(m, 5, 12, 0x1);
  559. }
  560. static inline void msg_set_redundant_link(struct tipc_msg *m, u32 r)
  561. {
  562. msg_set_bits(m, 5, 12, 0x1, r);
  563. }
  564. static inline char *msg_media_addr(struct tipc_msg *m)
  565. {
  566. return (char *)&m->hdr[TIPC_MEDIA_INFO_OFFSET];
  567. }
  568. /*
  569. * Word 9
  570. */
  571. static inline u32 msg_msgcnt(struct tipc_msg *m)
  572. {
  573. return msg_bits(m, 9, 16, 0xffff);
  574. }
  575. static inline void msg_set_msgcnt(struct tipc_msg *m, u32 n)
  576. {
  577. msg_set_bits(m, 9, 16, 0xffff, n);
  578. }
  579. static inline u32 msg_bcast_tag(struct tipc_msg *m)
  580. {
  581. return msg_bits(m, 9, 16, 0xffff);
  582. }
  583. static inline void msg_set_bcast_tag(struct tipc_msg *m, u32 n)
  584. {
  585. msg_set_bits(m, 9, 16, 0xffff, n);
  586. }
  587. static inline u32 msg_max_pkt(struct tipc_msg *m)
  588. {
  589. return msg_bits(m, 9, 16, 0xffff) * 4;
  590. }
  591. static inline void msg_set_max_pkt(struct tipc_msg *m, u32 n)
  592. {
  593. msg_set_bits(m, 9, 16, 0xffff, (n / 4));
  594. }
  595. static inline u32 msg_link_tolerance(struct tipc_msg *m)
  596. {
  597. return msg_bits(m, 9, 0, 0xffff);
  598. }
  599. static inline void msg_set_link_tolerance(struct tipc_msg *m, u32 n)
  600. {
  601. msg_set_bits(m, 9, 0, 0xffff, n);
  602. }
  603. static inline u32 tipc_msg_tot_importance(struct tipc_msg *m)
  604. {
  605. if ((msg_user(m) == MSG_FRAGMENTER) && (msg_type(m) == FIRST_FRAGMENT))
  606. return msg_importance(msg_get_wrapped(m));
  607. return msg_importance(m);
  608. }
  609. static inline u32 msg_tot_origport(struct tipc_msg *m)
  610. {
  611. if ((msg_user(m) == MSG_FRAGMENTER) && (msg_type(m) == FIRST_FRAGMENT))
  612. return msg_origport(msg_get_wrapped(m));
  613. return msg_origport(m);
  614. }
  615. struct sk_buff *tipc_buf_acquire(u32 size);
  616. bool tipc_msg_reverse(u32 own_addr, struct sk_buff *buf, u32 *dnode,
  617. int err);
  618. void tipc_msg_init(u32 own_addr, struct tipc_msg *m, u32 user, u32 type,
  619. u32 hsize, u32 destnode);
  620. struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz,
  621. uint data_sz, u32 dnode, u32 onode,
  622. u32 dport, u32 oport, int errcode);
  623. int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf);
  624. bool tipc_msg_bundle(struct sk_buff_head *list, struct sk_buff *skb, u32 mtu);
  625. bool tipc_msg_make_bundle(struct sk_buff_head *list,
  626. struct sk_buff *skb, u32 mtu, u32 dnode);
  627. bool tipc_msg_extract(struct sk_buff *skb, struct sk_buff **iskb, int *pos);
  628. int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m,
  629. int offset, int dsz, int mtu, struct sk_buff_head *list);
  630. bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, u32 *dnode,
  631. int *err);
  632. struct sk_buff *tipc_msg_reassemble(struct sk_buff_head *list);
  633. /* tipc_skb_peek(): peek and reserve first buffer in list
  634. * @list: list to be peeked in
  635. * Returns pointer to first buffer in list, if any
  636. */
  637. static inline struct sk_buff *tipc_skb_peek(struct sk_buff_head *list,
  638. spinlock_t *lock)
  639. {
  640. struct sk_buff *skb;
  641. spin_lock_bh(lock);
  642. skb = skb_peek(list);
  643. if (skb)
  644. skb_get(skb);
  645. spin_unlock_bh(lock);
  646. return skb;
  647. }
  648. /* tipc_skb_peek_port(): find a destination port, ignoring all destinations
  649. * up to and including 'filter'.
  650. * Note: ignoring previously tried destinations minimizes the risk of
  651. * contention on the socket lock
  652. * @list: list to be peeked in
  653. * @filter: last destination to be ignored from search
  654. * Returns a destination port number, of applicable.
  655. */
  656. static inline u32 tipc_skb_peek_port(struct sk_buff_head *list, u32 filter)
  657. {
  658. struct sk_buff *skb;
  659. u32 dport = 0;
  660. bool ignore = true;
  661. spin_lock_bh(&list->lock);
  662. skb_queue_walk(list, skb) {
  663. dport = msg_destport(buf_msg(skb));
  664. if (!filter || skb_queue_is_last(list, skb))
  665. break;
  666. if (dport == filter)
  667. ignore = false;
  668. else if (!ignore)
  669. break;
  670. }
  671. spin_unlock_bh(&list->lock);
  672. return dport;
  673. }
  674. /* tipc_skb_dequeue(): unlink first buffer with dest 'dport' from list
  675. * @list: list to be unlinked from
  676. * @dport: selection criteria for buffer to unlink
  677. */
  678. static inline struct sk_buff *tipc_skb_dequeue(struct sk_buff_head *list,
  679. u32 dport)
  680. {
  681. struct sk_buff *_skb, *tmp, *skb = NULL;
  682. spin_lock_bh(&list->lock);
  683. skb_queue_walk_safe(list, _skb, tmp) {
  684. if (msg_destport(buf_msg(_skb)) == dport) {
  685. __skb_unlink(_skb, list);
  686. skb = _skb;
  687. break;
  688. }
  689. }
  690. spin_unlock_bh(&list->lock);
  691. return skb;
  692. }
  693. /* tipc_skb_queue_tail(): add buffer to tail of list;
  694. * @list: list to be appended to
  695. * @skb: buffer to append. Always appended
  696. * @dport: the destination port of the buffer
  697. * returns true if dport differs from previous destination
  698. */
  699. static inline bool tipc_skb_queue_tail(struct sk_buff_head *list,
  700. struct sk_buff *skb, u32 dport)
  701. {
  702. struct sk_buff *_skb = NULL;
  703. bool rv = false;
  704. spin_lock_bh(&list->lock);
  705. _skb = skb_peek_tail(list);
  706. if (!_skb || (msg_destport(buf_msg(_skb)) != dport) ||
  707. (skb_queue_len(list) > 32))
  708. rv = true;
  709. __skb_queue_tail(list, skb);
  710. spin_unlock_bh(&list->lock);
  711. return rv;
  712. }
  713. #endif