msg.c 9.1 KB

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