msg.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * net/tipc/msg.c: TIPC message header routines
  3. *
  4. * Copyright (c) 2000-2006, Ericsson AB
  5. * Copyright (c) 2005, 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. #include "core.h"
  37. #include "addr.h"
  38. #include "dbg.h"
  39. #include "msg.h"
  40. #include "bearer.h"
  41. void msg_set_media_addr(struct tipc_msg *m, struct tipc_media_addr *a)
  42. {
  43. memcpy(&((int *)m)[5], a, sizeof(*a));
  44. }
  45. void msg_get_media_addr(struct tipc_msg *m, struct tipc_media_addr *a)
  46. {
  47. memcpy(a, &((int*)m)[5], sizeof(*a));
  48. }
  49. void msg_print(struct print_buf *buf, struct tipc_msg *msg, const char *str)
  50. {
  51. u32 usr = msg_user(msg);
  52. tipc_printf(buf, str);
  53. switch (usr) {
  54. case MSG_BUNDLER:
  55. tipc_printf(buf, "BNDL::");
  56. tipc_printf(buf, "MSGS(%u):", msg_msgcnt(msg));
  57. break;
  58. case BCAST_PROTOCOL:
  59. tipc_printf(buf, "BCASTP::");
  60. break;
  61. case MSG_FRAGMENTER:
  62. tipc_printf(buf, "FRAGM::");
  63. switch (msg_type(msg)) {
  64. case FIRST_FRAGMENT:
  65. tipc_printf(buf, "FIRST:");
  66. break;
  67. case FRAGMENT:
  68. tipc_printf(buf, "BODY:");
  69. break;
  70. case LAST_FRAGMENT:
  71. tipc_printf(buf, "LAST:");
  72. break;
  73. default:
  74. tipc_printf(buf, "UNKNOWN:%x",msg_type(msg));
  75. }
  76. tipc_printf(buf, "NO(%u/%u):",msg_long_msgno(msg),
  77. msg_fragm_no(msg));
  78. break;
  79. case DATA_LOW:
  80. case DATA_MEDIUM:
  81. case DATA_HIGH:
  82. case DATA_CRITICAL:
  83. tipc_printf(buf, "DAT%u:", msg_user(msg));
  84. if (msg_short(msg)) {
  85. tipc_printf(buf, "CON:");
  86. break;
  87. }
  88. switch (msg_type(msg)) {
  89. case TIPC_CONN_MSG:
  90. tipc_printf(buf, "CON:");
  91. break;
  92. case TIPC_MCAST_MSG:
  93. tipc_printf(buf, "MCST:");
  94. break;
  95. case TIPC_NAMED_MSG:
  96. tipc_printf(buf, "NAM:");
  97. break;
  98. case TIPC_DIRECT_MSG:
  99. tipc_printf(buf, "DIR:");
  100. break;
  101. default:
  102. tipc_printf(buf, "UNKNOWN TYPE %u",msg_type(msg));
  103. }
  104. if (msg_routed(msg) && !msg_non_seq(msg))
  105. tipc_printf(buf, "ROUT:");
  106. if (msg_reroute_cnt(msg))
  107. tipc_printf(buf, "REROUTED(%u):",
  108. msg_reroute_cnt(msg));
  109. break;
  110. case NAME_DISTRIBUTOR:
  111. tipc_printf(buf, "NMD::");
  112. switch (msg_type(msg)) {
  113. case PUBLICATION:
  114. tipc_printf(buf, "PUBL(%u):", (msg_size(msg) - msg_hdr_sz(msg)) / 20); /* Items */
  115. break;
  116. case WITHDRAWAL:
  117. tipc_printf(buf, "WDRW:");
  118. break;
  119. default:
  120. tipc_printf(buf, "UNKNOWN:%x",msg_type(msg));
  121. }
  122. if (msg_routed(msg))
  123. tipc_printf(buf, "ROUT:");
  124. if (msg_reroute_cnt(msg))
  125. tipc_printf(buf, "REROUTED(%u):",
  126. msg_reroute_cnt(msg));
  127. break;
  128. case CONN_MANAGER:
  129. tipc_printf(buf, "CONN_MNG:");
  130. switch (msg_type(msg)) {
  131. case CONN_PROBE:
  132. tipc_printf(buf, "PROBE:");
  133. break;
  134. case CONN_PROBE_REPLY:
  135. tipc_printf(buf, "PROBE_REPLY:");
  136. break;
  137. case CONN_ACK:
  138. tipc_printf(buf, "CONN_ACK:");
  139. tipc_printf(buf, "ACK(%u):",msg_msgcnt(msg));
  140. break;
  141. default:
  142. tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg));
  143. }
  144. if (msg_routed(msg))
  145. tipc_printf(buf, "ROUT:");
  146. if (msg_reroute_cnt(msg))
  147. tipc_printf(buf, "REROUTED(%u):",msg_reroute_cnt(msg));
  148. break;
  149. case LINK_PROTOCOL:
  150. tipc_printf(buf, "PROT:TIM(%u):",msg_timestamp(msg));
  151. switch (msg_type(msg)) {
  152. case STATE_MSG:
  153. tipc_printf(buf, "STATE:");
  154. tipc_printf(buf, "%s:",msg_probe(msg) ? "PRB" :"");
  155. tipc_printf(buf, "NXS(%u):",msg_next_sent(msg));
  156. tipc_printf(buf, "GAP(%u):",msg_seq_gap(msg));
  157. tipc_printf(buf, "LSTBC(%u):",msg_last_bcast(msg));
  158. break;
  159. case RESET_MSG:
  160. tipc_printf(buf, "RESET:");
  161. if (msg_size(msg) != msg_hdr_sz(msg))
  162. tipc_printf(buf, "BEAR:%s:",msg_data(msg));
  163. break;
  164. case ACTIVATE_MSG:
  165. tipc_printf(buf, "ACTIVATE:");
  166. break;
  167. default:
  168. tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg));
  169. }
  170. tipc_printf(buf, "PLANE(%c):",msg_net_plane(msg));
  171. tipc_printf(buf, "SESS(%u):",msg_session(msg));
  172. break;
  173. case CHANGEOVER_PROTOCOL:
  174. tipc_printf(buf, "TUNL:");
  175. switch (msg_type(msg)) {
  176. case DUPLICATE_MSG:
  177. tipc_printf(buf, "DUPL:");
  178. break;
  179. case ORIGINAL_MSG:
  180. tipc_printf(buf, "ORIG:");
  181. tipc_printf(buf, "EXP(%u)",msg_msgcnt(msg));
  182. break;
  183. default:
  184. tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg));
  185. }
  186. break;
  187. case ROUTE_DISTRIBUTOR:
  188. tipc_printf(buf, "ROUTING_MNG:");
  189. switch (msg_type(msg)) {
  190. case EXT_ROUTING_TABLE:
  191. tipc_printf(buf, "EXT_TBL:");
  192. tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
  193. break;
  194. case LOCAL_ROUTING_TABLE:
  195. tipc_printf(buf, "LOCAL_TBL:");
  196. tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
  197. break;
  198. case SLAVE_ROUTING_TABLE:
  199. tipc_printf(buf, "DP_TBL:");
  200. tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
  201. break;
  202. case ROUTE_ADDITION:
  203. tipc_printf(buf, "ADD:");
  204. tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
  205. break;
  206. case ROUTE_REMOVAL:
  207. tipc_printf(buf, "REMOVE:");
  208. tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
  209. break;
  210. default:
  211. tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg));
  212. }
  213. break;
  214. case LINK_CONFIG:
  215. tipc_printf(buf, "CFG:");
  216. switch (msg_type(msg)) {
  217. case DSC_REQ_MSG:
  218. tipc_printf(buf, "DSC_REQ:");
  219. break;
  220. case DSC_RESP_MSG:
  221. tipc_printf(buf, "DSC_RESP:");
  222. break;
  223. default:
  224. tipc_printf(buf, "UNKNOWN TYPE:%x:",msg_type(msg));
  225. break;
  226. }
  227. break;
  228. default:
  229. tipc_printf(buf, "UNKNOWN USER:");
  230. }
  231. switch (usr) {
  232. case CONN_MANAGER:
  233. case NAME_DISTRIBUTOR:
  234. case DATA_LOW:
  235. case DATA_MEDIUM:
  236. case DATA_HIGH:
  237. case DATA_CRITICAL:
  238. if (msg_short(msg))
  239. break; /* No error */
  240. switch (msg_errcode(msg)) {
  241. case TIPC_OK:
  242. break;
  243. case TIPC_ERR_NO_NAME:
  244. tipc_printf(buf, "NO_NAME:");
  245. break;
  246. case TIPC_ERR_NO_PORT:
  247. tipc_printf(buf, "NO_PORT:");
  248. break;
  249. case TIPC_ERR_NO_NODE:
  250. tipc_printf(buf, "NO_PROC:");
  251. break;
  252. case TIPC_ERR_OVERLOAD:
  253. tipc_printf(buf, "OVERLOAD:");
  254. break;
  255. case TIPC_CONN_SHUTDOWN:
  256. tipc_printf(buf, "SHUTDOWN:");
  257. break;
  258. default:
  259. tipc_printf(buf, "UNKNOWN ERROR(%x):",
  260. msg_errcode(msg));
  261. }
  262. default:{}
  263. }
  264. tipc_printf(buf, "HZ(%u):", msg_hdr_sz(msg));
  265. tipc_printf(buf, "SZ(%u):", msg_size(msg));
  266. tipc_printf(buf, "SQNO(%u):", msg_seqno(msg));
  267. if (msg_non_seq(msg))
  268. tipc_printf(buf, "NOSEQ:");
  269. else {
  270. tipc_printf(buf, "ACK(%u):", msg_ack(msg));
  271. }
  272. tipc_printf(buf, "BACK(%u):", msg_bcast_ack(msg));
  273. tipc_printf(buf, "PRND(%x)", msg_prevnode(msg));
  274. if (msg_isdata(msg)) {
  275. if (msg_named(msg)) {
  276. tipc_printf(buf, "NTYP(%u):", msg_nametype(msg));
  277. tipc_printf(buf, "NINST(%u)", msg_nameinst(msg));
  278. }
  279. }
  280. if ((usr != LINK_PROTOCOL) && (usr != LINK_CONFIG) &&
  281. (usr != MSG_BUNDLER)) {
  282. if (!msg_short(msg)) {
  283. tipc_printf(buf, ":ORIG(%x:%u):",
  284. msg_orignode(msg), msg_origport(msg));
  285. tipc_printf(buf, ":DEST(%x:%u):",
  286. msg_destnode(msg), msg_destport(msg));
  287. } else {
  288. tipc_printf(buf, ":OPRT(%u):", msg_origport(msg));
  289. tipc_printf(buf, ":DPRT(%u):", msg_destport(msg));
  290. }
  291. if (msg_routed(msg) && !msg_non_seq(msg))
  292. tipc_printf(buf, ":TSEQN(%u)", msg_transp_seqno(msg));
  293. }
  294. if (msg_user(msg) == NAME_DISTRIBUTOR) {
  295. tipc_printf(buf, ":ONOD(%x):", msg_orignode(msg));
  296. tipc_printf(buf, ":DNOD(%x):", msg_destnode(msg));
  297. if (msg_routed(msg)) {
  298. tipc_printf(buf, ":CSEQN(%u)", msg_transp_seqno(msg));
  299. }
  300. }
  301. if (msg_user(msg) == LINK_CONFIG) {
  302. u32* raw = (u32*)msg;
  303. struct tipc_media_addr* orig = (struct tipc_media_addr*)&raw[5];
  304. tipc_printf(buf, ":REQL(%u):", msg_req_links(msg));
  305. tipc_printf(buf, ":DDOM(%x):", msg_dest_domain(msg));
  306. tipc_printf(buf, ":NETID(%u):", msg_bc_netid(msg));
  307. media_addr_printf(buf, orig);
  308. }
  309. if (msg_user(msg) == BCAST_PROTOCOL) {
  310. tipc_printf(buf, "BCNACK:AFTER(%u):", msg_bcgap_after(msg));
  311. tipc_printf(buf, "TO(%u):", msg_bcgap_to(msg));
  312. }
  313. tipc_printf(buf, "\n");
  314. if ((usr == CHANGEOVER_PROTOCOL) && (msg_msgcnt(msg))) {
  315. msg_print(buf,msg_get_wrapped(msg)," /");
  316. }
  317. if ((usr == MSG_FRAGMENTER) && (msg_type(msg) == FIRST_FRAGMENT)) {
  318. msg_print(buf,msg_get_wrapped(msg)," /");
  319. }
  320. }