1 /* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning 11 * features or use of this software display the following acknowledgement: 12 * ``This product includes software developed by the University of California, 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 */ 21 22 /* \summary: Transparent Inter-Process Communication (TIPC) protocol printer */ 23 24 /* 25 * specification: 26 * https://web.archive.org/web/20150302152944/http://tipc.sourceforge.net/doc/draft-spec-tipc-07.html 27 * https://web.archive.org/web/20161025110514/http://tipc.sourceforge.net/doc/tipc_message_formats.html 28 */ 29 30 #include <config.h> 31 32 #include "netdissect-stdinc.h" 33 34 #include "netdissect.h" 35 #include "extract.h" 36 37 38 #define TIPC_USER_LOW_IMPORTANCE 0 39 #define TIPC_USER_MEDIUM_IMPORTANCE 1 40 #define TIPC_USER_HIGH_IMPORTANCE 2 41 #define TIPC_USER_CRITICAL_IMPORTANCE 3 42 #define TIPC_USER_BCAST_PROTOCOL 5 43 #define TIPC_USER_MSG_BUNDLER 6 44 #define TIPC_USER_LINK_PROTOCOL 7 45 #define TIPC_USER_CONN_MANAGER 8 46 #define TIPC_USER_CHANGEOVER_PROTOCOL 10 47 #define TIPC_USER_NAME_DISTRIBUTOR 11 48 #define TIPC_USER_MSG_FRAGMENTER 12 49 #define TIPC_USER_LINK_CONFIG 13 50 51 #define TIPC_CONN_MSG 0 52 #define TIPC_DIRECT_MSG 1 53 #define TIPC_NAMED_MSG 2 54 #define TIPC_MCAST_MSG 3 55 56 #define TIPC_ZONE(addr) (((addr) >> 24) & 0xFF) 57 #define TIPC_CLUSTER(addr) (((addr) >> 12) & 0xFFF) 58 #define TIPC_NODE(addr) (((addr) >> 0) & 0xFFF) 59 60 struct tipc_pkthdr { 61 nd_uint32_t w0; 62 nd_uint32_t w1; 63 }; 64 65 #define TIPC_VER(w0) (((w0) >> 29) & 0x07) 66 #define TIPC_USER(w0) (((w0) >> 25) & 0x0F) 67 #define TIPC_HSIZE(w0) (((w0) >> 21) & 0x0F) 68 #define TIPC_MSIZE(w0) (((w0) >> 0) & 0x1FFFF) 69 #define TIPC_MTYPE(w1) (((w1) >> 29) & 0x07) 70 #define TIPC_BROADCAST_ACK(w1) (((w1) >> 0) & 0xFFFF) 71 #define TIPC_LINK_ACK(w2) (((w2) >> 16) & 0xFFFF) 72 #define TIPC_LINK_SEQ(w2) (((w2) >> 0) & 0xFFFF) 73 74 static const struct tok tipcuser_values[] = { 75 { TIPC_USER_LOW_IMPORTANCE, "Low Importance Data payload" }, 76 { TIPC_USER_MEDIUM_IMPORTANCE, "Medium Importance Data payload" }, 77 { TIPC_USER_HIGH_IMPORTANCE, "High Importance Data payload" }, 78 { TIPC_USER_CRITICAL_IMPORTANCE, "Critical Importance Data payload" }, 79 { TIPC_USER_BCAST_PROTOCOL, "Broadcast Link Protocol internal" }, 80 { TIPC_USER_MSG_BUNDLER, "Message Bundler Protocol internal" }, 81 { TIPC_USER_LINK_PROTOCOL, "Link State Protocol internal" }, 82 { TIPC_USER_CONN_MANAGER, "Connection Manager internal" }, 83 { TIPC_USER_CHANGEOVER_PROTOCOL, "Link Changeover Protocol internal" }, 84 { TIPC_USER_NAME_DISTRIBUTOR, "Name Table Update Protocol internal" }, 85 { TIPC_USER_MSG_FRAGMENTER, "Message Fragmentation Protocol internal" }, 86 { TIPC_USER_LINK_CONFIG, "Neighbor Detection Protocol internal" }, 87 { 0, NULL } 88 }; 89 90 static const struct tok tipcmtype_values[] = { 91 { TIPC_CONN_MSG, "CONN_MSG" }, 92 { TIPC_DIRECT_MSG, "MCAST_MSG" }, 93 { TIPC_NAMED_MSG, "NAMED_MSG" }, 94 { TIPC_MCAST_MSG, "DIRECT_MSG" }, 95 { 0, NULL } 96 }; 97 98 static const struct tok tipc_linkconf_mtype_values[] = { 99 { 0, "Link request" }, 100 { 1, "Link response" }, 101 { 0, NULL } 102 }; 103 104 struct payload_tipc_pkthdr { 105 nd_uint32_t w0; 106 nd_uint32_t w1; 107 nd_uint32_t w2; 108 nd_uint32_t prev_node; 109 nd_uint32_t orig_port; 110 nd_uint32_t dest_port; 111 nd_uint32_t orig_node; 112 nd_uint32_t dest_node; 113 nd_uint32_t name_type; 114 nd_uint32_t w9; 115 nd_uint32_t wA; 116 }; 117 118 struct internal_tipc_pkthdr { 119 nd_uint32_t w0; 120 nd_uint32_t w1; 121 nd_uint32_t w2; 122 nd_uint32_t prev_node; 123 nd_uint32_t w4; 124 nd_uint32_t w5; 125 nd_uint32_t orig_node; 126 nd_uint32_t dest_node; 127 nd_uint32_t trans_seq; 128 nd_uint32_t w9; 129 }; 130 131 #define TIPC_SEQ_GAP(w1) (((w1) >> 16) & 0x1FFF) 132 #define TIPC_BC_GAP_AFTER(w2) (((w2) >> 16) & 0xFFFF) 133 #define TIPC_BC_GAP_TO(w2) (((w2) >> 0) & 0xFFFF) 134 #define TIPC_LAST_SENT_FRAG(w4) (((w4) >> 16) & 0xFFFF) 135 #define TIPC_NEXT_SENT_FRAG(w4) (((w4) >> 0) & 0xFFFF) 136 #define TIPC_SESS_NO(w5) (((w5) >> 16) & 0xFFFF) 137 #define TIPC_MSG_CNT(w9) (((w9) >> 16) & 0xFFFF) 138 #define TIPC_LINK_TOL(w9) (((w9) >> 0) & 0xFFFF) 139 140 struct link_conf_tipc_pkthdr { 141 nd_uint32_t w0; 142 nd_uint32_t w1; 143 nd_uint32_t dest_domain; 144 nd_uint32_t prev_node; 145 nd_uint32_t ntwrk_id; 146 nd_uint32_t w5; 147 nd_byte media_address[16]; 148 }; 149 150 #define TIPC_NODE_SIG(w1) (((w1) >> 0) & 0xFFFF) 151 #define TIPC_MEDIA_ID(w5) (((w5) >> 0) & 0xFF) 152 153 static void 154 print_payload(netdissect_options *ndo, const struct payload_tipc_pkthdr *ap) 155 { 156 uint32_t w0, w1, w2; 157 u_int user; 158 u_int hsize; 159 u_int msize; 160 u_int mtype; 161 u_int broadcast_ack; 162 u_int link_ack; 163 u_int link_seq; 164 u_int prev_node; 165 u_int orig_port; 166 u_int dest_port; 167 u_int orig_node; 168 u_int dest_node; 169 170 w0 = GET_BE_U_4(ap->w0); 171 user = TIPC_USER(w0); 172 hsize = TIPC_HSIZE(w0); 173 msize = TIPC_MSIZE(w0); 174 w1 = GET_BE_U_4(ap->w1); 175 mtype = TIPC_MTYPE(w1); 176 prev_node = GET_BE_U_4(ap->prev_node); 177 orig_port = GET_BE_U_4(ap->orig_port); 178 dest_port = GET_BE_U_4(ap->dest_port); 179 if (hsize <= 6) { 180 ND_PRINT("TIPC v%u.0 %u.%u.%u:%u > %u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 181 TIPC_VER(w0), 182 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 183 orig_port, dest_port, 184 hsize*4, msize, 185 tok2str(tipcuser_values, "unknown", user), 186 tok2str(tipcmtype_values, "Unknown", mtype)); 187 } else { 188 orig_node = GET_BE_U_4(ap->orig_node); 189 dest_node = GET_BE_U_4(ap->dest_node); 190 ND_PRINT("TIPC v%u.0 %u.%u.%u:%u > %u.%u.%u:%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 191 TIPC_VER(w0), 192 TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node), 193 orig_port, 194 TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node), 195 dest_port, 196 hsize*4, msize, 197 tok2str(tipcuser_values, "unknown", user), 198 tok2str(tipcmtype_values, "Unknown", mtype)); 199 200 if (ndo->ndo_vflag) { 201 broadcast_ack = TIPC_BROADCAST_ACK(w1); 202 w2 = GET_BE_U_4(ap->w2); 203 link_ack = TIPC_LINK_ACK(w2); 204 link_seq = TIPC_LINK_SEQ(w2); 205 ND_PRINT("\n\tPrevious Node %u.%u.%u, Broadcast Ack %u, Link Ack %u, Link Sequence %u", 206 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 207 broadcast_ack, link_ack, link_seq); 208 } 209 } 210 } 211 212 static void 213 print_internal(netdissect_options *ndo, const struct internal_tipc_pkthdr *ap) 214 { 215 uint32_t w0, w1, w2, w4, w5, w9; 216 u_int user; 217 u_int hsize; 218 u_int msize; 219 u_int mtype; 220 u_int seq_gap; 221 u_int broadcast_ack; 222 u_int bc_gap_after; 223 u_int bc_gap_to; 224 u_int prev_node; 225 u_int last_sent_frag; 226 u_int next_sent_frag; 227 u_int sess_no; 228 u_int orig_node; 229 u_int dest_node; 230 u_int trans_seq; 231 u_int msg_cnt; 232 u_int link_tol; 233 234 w0 = GET_BE_U_4(ap->w0); 235 user = TIPC_USER(w0); 236 hsize = TIPC_HSIZE(w0); 237 msize = TIPC_MSIZE(w0); 238 w1 = GET_BE_U_4(ap->w1); 239 mtype = TIPC_MTYPE(w1); 240 orig_node = GET_BE_U_4(ap->orig_node); 241 dest_node = GET_BE_U_4(ap->dest_node); 242 ND_PRINT("TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s (0x%08x)", 243 TIPC_VER(w0), 244 TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node), 245 TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node), 246 hsize*4, msize, 247 tok2str(tipcuser_values, "unknown", user), 248 tok2str(tipcmtype_values, "Unknown", mtype), w1); 249 250 if (ndo->ndo_vflag) { 251 seq_gap = TIPC_SEQ_GAP(w1); 252 broadcast_ack = TIPC_BROADCAST_ACK(w1); 253 w2 = GET_BE_U_4(ap->w2); 254 bc_gap_after = TIPC_BC_GAP_AFTER(w2); 255 bc_gap_to = TIPC_BC_GAP_TO(w2); 256 prev_node = GET_BE_U_4(ap->prev_node); 257 w4 = GET_BE_U_4(ap->w4); 258 last_sent_frag = TIPC_LAST_SENT_FRAG(w4); 259 next_sent_frag = TIPC_NEXT_SENT_FRAG(w4); 260 w5 = GET_BE_U_4(ap->w5); 261 sess_no = TIPC_SESS_NO(w5); 262 trans_seq = GET_BE_U_4(ap->trans_seq); 263 w9 = GET_BE_U_4(ap->w9); 264 msg_cnt = TIPC_MSG_CNT(w9); 265 link_tol = TIPC_LINK_TOL(w9); 266 ND_PRINT("\n\tPrevious Node %u.%u.%u, Session No. %u, Broadcast Ack %u, Sequence Gap %u, Broadcast Gap After %u, Broadcast Gap To %u, Last Sent Packet No. %u, Next sent Packet No. %u, Transport Sequence %u, msg_count %u, Link Tolerance %u", 267 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 268 sess_no, broadcast_ack, seq_gap, bc_gap_after, bc_gap_to, 269 last_sent_frag, next_sent_frag, trans_seq, msg_cnt, 270 link_tol); 271 } 272 } 273 274 static void 275 print_link_conf(netdissect_options *ndo, const struct link_conf_tipc_pkthdr *ap) 276 { 277 uint32_t w0, w1, w5; 278 u_int user; 279 u_int hsize; 280 u_int msize; 281 u_int mtype; 282 u_int node_sig; 283 u_int prev_node; 284 u_int dest_domain; 285 u_int ntwrk_id; 286 u_int media_id; 287 288 w0 = GET_BE_U_4(ap->w0); 289 user = TIPC_USER(w0); 290 hsize = TIPC_HSIZE(w0); 291 msize = TIPC_MSIZE(w0); 292 w1 = GET_BE_U_4(ap->w1); 293 mtype = TIPC_MTYPE(w1); 294 dest_domain = GET_BE_U_4(ap->dest_domain); 295 prev_node = GET_BE_U_4(ap->prev_node); 296 297 ND_PRINT("TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 298 TIPC_VER(w0), 299 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 300 TIPC_ZONE(dest_domain), TIPC_CLUSTER(dest_domain), TIPC_NODE(dest_domain), 301 hsize*4, msize, 302 tok2str(tipcuser_values, "unknown", user), 303 tok2str(tipc_linkconf_mtype_values, "Unknown", mtype)); 304 if (ndo->ndo_vflag) { 305 node_sig = TIPC_NODE_SIG(w1); 306 ntwrk_id = GET_BE_U_4(ap->ntwrk_id); 307 w5 = GET_BE_U_4(ap->w5); 308 media_id = TIPC_MEDIA_ID(w5); 309 ND_PRINT("\n\tNodeSignature %u, network_id %u, media_id %u", 310 node_sig, ntwrk_id, media_id); 311 } 312 } 313 314 void 315 tipc_print(netdissect_options *ndo, const u_char *bp, u_int length _U_, 316 u_int caplen _U_) 317 { 318 const struct tipc_pkthdr *ap; 319 uint32_t w0; 320 u_int user; 321 322 ndo->ndo_protocol = "tipc"; 323 ap = (const struct tipc_pkthdr *)bp; 324 w0 = GET_BE_U_4(ap->w0); 325 user = TIPC_USER(w0); 326 327 switch (user) { 328 case TIPC_USER_LOW_IMPORTANCE: 329 case TIPC_USER_MEDIUM_IMPORTANCE: 330 case TIPC_USER_HIGH_IMPORTANCE: 331 case TIPC_USER_CRITICAL_IMPORTANCE: 332 case TIPC_USER_NAME_DISTRIBUTOR: 333 case TIPC_USER_CONN_MANAGER: 334 print_payload(ndo, (const struct payload_tipc_pkthdr *)bp); 335 break; 336 337 case TIPC_USER_LINK_CONFIG: 338 print_link_conf(ndo, (const struct link_conf_tipc_pkthdr *)bp); 339 break; 340 341 case TIPC_USER_BCAST_PROTOCOL: 342 case TIPC_USER_MSG_BUNDLER: 343 case TIPC_USER_LINK_PROTOCOL: 344 case TIPC_USER_CHANGEOVER_PROTOCOL: 345 case TIPC_USER_MSG_FRAGMENTER: 346 print_internal(ndo, (const struct internal_tipc_pkthdr *)bp); 347 break; 348 349 } 350 } 351