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 #include <sys/cdefs.h> 23 #ifndef lint 24 __RCSID("$NetBSD: print-tipc.c,v 1.5 2023/08/17 20:19:40 christos Exp $"); 25 #endif 26 27 /* \summary: Transparent Inter-Process Communication (TIPC) protocol printer */ 28 29 /* 30 * specification: 31 * https://web.archive.org/web/20150302152944/http://tipc.sourceforge.net/doc/draft-spec-tipc-07.html 32 * https://web.archive.org/web/20161025110514/http://tipc.sourceforge.net/doc/tipc_message_formats.html 33 */ 34 35 #ifdef HAVE_CONFIG_H 36 #include <config.h> 37 #endif 38 39 #include "netdissect-stdinc.h" 40 41 #include "netdissect.h" 42 #include "ethertype.h" 43 #include "extract.h" 44 45 46 #define TIPC_USER_LOW_IMPORTANCE 0 47 #define TIPC_USER_MEDIUM_IMPORTANCE 1 48 #define TIPC_USER_HIGH_IMPORTANCE 2 49 #define TIPC_USER_CRITICAL_IMPORTANCE 3 50 #define TIPC_USER_BCAST_PROTOCOL 5 51 #define TIPC_USER_MSG_BUNDLER 6 52 #define TIPC_USER_LINK_PROTOCOL 7 53 #define TIPC_USER_CONN_MANAGER 8 54 #define TIPC_USER_CHANGEOVER_PROTOCOL 10 55 #define TIPC_USER_NAME_DISTRIBUTOR 11 56 #define TIPC_USER_MSG_FRAGMENTER 12 57 #define TIPC_USER_LINK_CONFIG 13 58 59 #define TIPC_CONN_MSG 0 60 #define TIPC_DIRECT_MSG 1 61 #define TIPC_NAMED_MSG 2 62 #define TIPC_MCAST_MSG 3 63 64 #define TIPC_ZONE(addr) (((addr) >> 24) & 0xFF) 65 #define TIPC_CLUSTER(addr) (((addr) >> 12) & 0xFFF) 66 #define TIPC_NODE(addr) (((addr) >> 0) & 0xFFF) 67 68 struct tipc_pkthdr { 69 nd_uint32_t w0; 70 nd_uint32_t w1; 71 }; 72 73 #define TIPC_VER(w0) (((w0) >> 29) & 0x07) 74 #define TIPC_USER(w0) (((w0) >> 25) & 0x0F) 75 #define TIPC_HSIZE(w0) (((w0) >> 21) & 0x0F) 76 #define TIPC_MSIZE(w0) (((w0) >> 0) & 0x1FFFF) 77 #define TIPC_MTYPE(w1) (((w1) >> 29) & 0x07) 78 #define TIPC_BROADCAST_ACK(w1) (((w1) >> 0) & 0xFFFF) 79 #define TIPC_LINK_ACK(w2) (((w2) >> 16) & 0xFFFF) 80 #define TIPC_LINK_SEQ(w2) (((w2) >> 0) & 0xFFFF) 81 82 static const struct tok tipcuser_values[] = { 83 { TIPC_USER_LOW_IMPORTANCE, "Low Importance Data payload" }, 84 { TIPC_USER_MEDIUM_IMPORTANCE, "Medium Importance Data payload" }, 85 { TIPC_USER_HIGH_IMPORTANCE, "High Importance Data payload" }, 86 { TIPC_USER_CRITICAL_IMPORTANCE, "Critical Importance Data payload" }, 87 { TIPC_USER_BCAST_PROTOCOL, "Broadcast Link Protocol internal" }, 88 { TIPC_USER_MSG_BUNDLER, "Message Bundler Protocol internal" }, 89 { TIPC_USER_LINK_PROTOCOL, "Link State Protocol internal" }, 90 { TIPC_USER_CONN_MANAGER, "Connection Manager internal" }, 91 { TIPC_USER_CHANGEOVER_PROTOCOL, "Link Changeover Protocol internal" }, 92 { TIPC_USER_NAME_DISTRIBUTOR, "Name Table Update Protocol internal" }, 93 { TIPC_USER_MSG_FRAGMENTER, "Message Fragmentation Protocol internal" }, 94 { TIPC_USER_LINK_CONFIG, "Neighbor Detection Protocol internal" }, 95 { 0, NULL } 96 }; 97 98 static const struct tok tipcmtype_values[] = { 99 { TIPC_CONN_MSG, "CONN_MSG" }, 100 { TIPC_DIRECT_MSG, "MCAST_MSG" }, 101 { TIPC_NAMED_MSG, "NAMED_MSG" }, 102 { TIPC_MCAST_MSG, "DIRECT_MSG" }, 103 { 0, NULL } 104 }; 105 106 static const struct tok tipc_linkconf_mtype_values[] = { 107 { 0, "Link request" }, 108 { 1, "Link response" }, 109 { 0, NULL } 110 }; 111 112 struct payload_tipc_pkthdr { 113 nd_uint32_t w0; 114 nd_uint32_t w1; 115 nd_uint32_t w2; 116 nd_uint32_t prev_node; 117 nd_uint32_t orig_port; 118 nd_uint32_t dest_port; 119 nd_uint32_t orig_node; 120 nd_uint32_t dest_node; 121 nd_uint32_t name_type; 122 nd_uint32_t w9; 123 nd_uint32_t wA; 124 }; 125 126 struct internal_tipc_pkthdr { 127 nd_uint32_t w0; 128 nd_uint32_t w1; 129 nd_uint32_t w2; 130 nd_uint32_t prev_node; 131 nd_uint32_t w4; 132 nd_uint32_t w5; 133 nd_uint32_t orig_node; 134 nd_uint32_t dest_node; 135 nd_uint32_t trans_seq; 136 nd_uint32_t w9; 137 }; 138 139 #define TIPC_SEQ_GAP(w1) (((w1) >> 16) & 0x1FFF) 140 #define TIPC_BC_GAP_AFTER(w2) (((w2) >> 16) & 0xFFFF) 141 #define TIPC_BC_GAP_TO(w2) (((w2) >> 0) & 0xFFFF) 142 #define TIPC_LAST_SENT_FRAG(w4) (((w4) >> 16) & 0xFFFF) 143 #define TIPC_NEXT_SENT_FRAG(w4) (((w4) >> 0) & 0xFFFF) 144 #define TIPC_SESS_NO(w5) (((w5) >> 16) & 0xFFFF) 145 #define TIPC_MSG_CNT(w9) (((w9) >> 16) & 0xFFFF) 146 #define TIPC_LINK_TOL(w9) (((w9) >> 0) & 0xFFFF) 147 148 struct link_conf_tipc_pkthdr { 149 nd_uint32_t w0; 150 nd_uint32_t w1; 151 nd_uint32_t dest_domain; 152 nd_uint32_t prev_node; 153 nd_uint32_t ntwrk_id; 154 nd_uint32_t w5; 155 nd_byte media_address[16]; 156 }; 157 158 #define TIPC_NODE_SIG(w1) (((w1) >> 0) & 0xFFFF) 159 #define TIPC_MEDIA_ID(w5) (((w5) >> 0) & 0xFF) 160 161 static void 162 print_payload(netdissect_options *ndo, const struct payload_tipc_pkthdr *ap) 163 { 164 uint32_t w0, w1, w2; 165 u_int user; 166 u_int hsize; 167 u_int msize; 168 u_int mtype; 169 u_int broadcast_ack; 170 u_int link_ack; 171 u_int link_seq; 172 u_int prev_node; 173 u_int orig_port; 174 u_int dest_port; 175 u_int orig_node; 176 u_int dest_node; 177 178 w0 = GET_BE_U_4(ap->w0); 179 user = TIPC_USER(w0); 180 hsize = TIPC_HSIZE(w0); 181 msize = TIPC_MSIZE(w0); 182 w1 = GET_BE_U_4(ap->w1); 183 mtype = TIPC_MTYPE(w1); 184 prev_node = GET_BE_U_4(ap->prev_node); 185 orig_port = GET_BE_U_4(ap->orig_port); 186 dest_port = GET_BE_U_4(ap->dest_port); 187 if (hsize <= 6) { 188 ND_PRINT("TIPC v%u.0 %u.%u.%u:%u > %u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 189 TIPC_VER(w0), 190 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 191 orig_port, dest_port, 192 hsize*4, msize, 193 tok2str(tipcuser_values, "unknown", user), 194 tok2str(tipcmtype_values, "Unknown", mtype)); 195 } else { 196 orig_node = GET_BE_U_4(ap->orig_node); 197 dest_node = GET_BE_U_4(ap->dest_node); 198 ND_PRINT("TIPC v%u.0 %u.%u.%u:%u > %u.%u.%u:%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 199 TIPC_VER(w0), 200 TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node), 201 orig_port, 202 TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node), 203 dest_port, 204 hsize*4, msize, 205 tok2str(tipcuser_values, "unknown", user), 206 tok2str(tipcmtype_values, "Unknown", mtype)); 207 208 if (ndo->ndo_vflag) { 209 broadcast_ack = TIPC_BROADCAST_ACK(w1); 210 w2 = GET_BE_U_4(ap->w2); 211 link_ack = TIPC_LINK_ACK(w2); 212 link_seq = TIPC_LINK_SEQ(w2); 213 ND_PRINT("\n\tPrevious Node %u.%u.%u, Broadcast Ack %u, Link Ack %u, Link Sequence %u", 214 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 215 broadcast_ack, link_ack, link_seq); 216 } 217 } 218 } 219 220 UNALIGNED_OK 221 static void 222 print_internal(netdissect_options *ndo, const struct internal_tipc_pkthdr *ap) 223 { 224 uint32_t w0, w1, w2, w4, w5, w9; 225 u_int user; 226 u_int hsize; 227 u_int msize; 228 u_int mtype; 229 u_int seq_gap; 230 u_int broadcast_ack; 231 u_int bc_gap_after; 232 u_int bc_gap_to; 233 u_int prev_node; 234 u_int last_sent_frag; 235 u_int next_sent_frag; 236 u_int sess_no; 237 u_int orig_node; 238 u_int dest_node; 239 u_int trans_seq; 240 u_int msg_cnt; 241 u_int link_tol; 242 243 w0 = GET_BE_U_4(ap->w0); 244 user = TIPC_USER(w0); 245 hsize = TIPC_HSIZE(w0); 246 msize = TIPC_MSIZE(w0); 247 w1 = GET_BE_U_4(ap->w1); 248 mtype = TIPC_MTYPE(w1); 249 orig_node = GET_BE_U_4(ap->orig_node); 250 dest_node = GET_BE_U_4(ap->dest_node); 251 ND_PRINT("TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s (0x%08x)", 252 TIPC_VER(w0), 253 TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node), 254 TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node), 255 hsize*4, msize, 256 tok2str(tipcuser_values, "unknown", user), 257 tok2str(tipcmtype_values, "Unknown", mtype), w1); 258 259 if (ndo->ndo_vflag) { 260 seq_gap = TIPC_SEQ_GAP(w1); 261 broadcast_ack = TIPC_BROADCAST_ACK(w1); 262 w2 = GET_BE_U_4(ap->w2); 263 bc_gap_after = TIPC_BC_GAP_AFTER(w2); 264 bc_gap_to = TIPC_BC_GAP_TO(w2); 265 prev_node = GET_BE_U_4(ap->prev_node); 266 w4 = GET_BE_U_4(ap->w4); 267 last_sent_frag = TIPC_LAST_SENT_FRAG(w4); 268 next_sent_frag = TIPC_NEXT_SENT_FRAG(w4); 269 w5 = GET_BE_U_4(ap->w5); 270 sess_no = TIPC_SESS_NO(w5); 271 trans_seq = GET_BE_U_4(ap->trans_seq); 272 w9 = GET_BE_U_4(ap->w9); 273 msg_cnt = TIPC_MSG_CNT(w9); 274 link_tol = TIPC_LINK_TOL(w9); 275 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", 276 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 277 sess_no, broadcast_ack, seq_gap, bc_gap_after, bc_gap_to, 278 last_sent_frag, next_sent_frag, trans_seq, msg_cnt, 279 link_tol); 280 } 281 } 282 283 static void 284 print_link_conf(netdissect_options *ndo, const struct link_conf_tipc_pkthdr *ap) 285 { 286 uint32_t w0, w1, w5; 287 u_int user; 288 u_int hsize; 289 u_int msize; 290 u_int mtype; 291 u_int node_sig; 292 u_int prev_node; 293 u_int dest_domain; 294 u_int ntwrk_id; 295 u_int media_id; 296 297 w0 = GET_BE_U_4(ap->w0); 298 user = TIPC_USER(w0); 299 hsize = TIPC_HSIZE(w0); 300 msize = TIPC_MSIZE(w0); 301 w1 = GET_BE_U_4(ap->w1); 302 mtype = TIPC_MTYPE(w1); 303 dest_domain = GET_BE_U_4(ap->dest_domain); 304 prev_node = GET_BE_U_4(ap->prev_node); 305 306 ND_PRINT("TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 307 TIPC_VER(w0), 308 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 309 TIPC_ZONE(dest_domain), TIPC_CLUSTER(dest_domain), TIPC_NODE(dest_domain), 310 hsize*4, msize, 311 tok2str(tipcuser_values, "unknown", user), 312 tok2str(tipc_linkconf_mtype_values, "Unknown", mtype)); 313 if (ndo->ndo_vflag) { 314 node_sig = TIPC_NODE_SIG(w1); 315 ntwrk_id = GET_BE_U_4(ap->ntwrk_id); 316 w5 = GET_BE_U_4(ap->w5); 317 media_id = TIPC_MEDIA_ID(w5); 318 ND_PRINT("\n\tNodeSignature %u, network_id %u, media_id %u", 319 node_sig, ntwrk_id, media_id); 320 } 321 } 322 323 UNALIGNED_OK 324 void 325 tipc_print(netdissect_options *ndo, const u_char *bp, u_int length _U_, 326 u_int caplen _U_) 327 { 328 const struct tipc_pkthdr *ap; 329 uint32_t w0; 330 u_int user; 331 332 ndo->ndo_protocol = "tipc"; 333 ap = (const struct tipc_pkthdr *)bp; 334 w0 = GET_BE_U_4(ap->w0); 335 user = TIPC_USER(w0); 336 337 switch (user) 338 { 339 case TIPC_USER_LOW_IMPORTANCE: 340 case TIPC_USER_MEDIUM_IMPORTANCE: 341 case TIPC_USER_HIGH_IMPORTANCE: 342 case TIPC_USER_CRITICAL_IMPORTANCE: 343 case TIPC_USER_NAME_DISTRIBUTOR: 344 case TIPC_USER_CONN_MANAGER: 345 print_payload(ndo, (const struct payload_tipc_pkthdr *)bp); 346 break; 347 348 case TIPC_USER_LINK_CONFIG: 349 print_link_conf(ndo, (const struct link_conf_tipc_pkthdr *)bp); 350 break; 351 352 case TIPC_USER_BCAST_PROTOCOL: 353 case TIPC_USER_MSG_BUNDLER: 354 case TIPC_USER_LINK_PROTOCOL: 355 case TIPC_USER_CHANGEOVER_PROTOCOL: 356 case TIPC_USER_MSG_FRAGMENTER: 357 print_internal(ndo, (const struct internal_tipc_pkthdr *)bp); 358 break; 359 360 } 361 } 362