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