19546e36dSchristos /* 29546e36dSchristos * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 39546e36dSchristos * The Regents of the University of California. All rights reserved. 49546e36dSchristos * 59546e36dSchristos * Redistribution and use in source and binary forms, with or without 69546e36dSchristos * modification, are permitted provided that: (1) source code distributions 79546e36dSchristos * retain the above copyright notice and this paragraph in its entirety, (2) 89546e36dSchristos * distributions including binary code include the above copyright notice and 99546e36dSchristos * this paragraph in its entirety in the documentation or other materials 109546e36dSchristos * provided with the distribution, and (3) all advertising materials mentioning 119546e36dSchristos * features or use of this software display the following acknowledgement: 129546e36dSchristos * ``This product includes software developed by the University of California, 139546e36dSchristos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 149546e36dSchristos * the University nor the names of its contributors may be used to endorse 159546e36dSchristos * or promote products derived from this software without specific prior 169546e36dSchristos * written permission. 179546e36dSchristos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 189546e36dSchristos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 199546e36dSchristos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 209546e36dSchristos */ 219546e36dSchristos 22fdccd7e4Schristos #include <sys/cdefs.h> 23fdccd7e4Schristos #ifndef lint 24*26ba0b50Schristos __RCSID("$NetBSD: print-tipc.c,v 1.6 2024/09/02 16:15:33 christos Exp $"); 25fdccd7e4Schristos #endif 26fdccd7e4Schristos 27dc860a36Sspz /* \summary: Transparent Inter-Process Communication (TIPC) protocol printer */ 28dc860a36Sspz 29dc860a36Sspz /* 30dc860a36Sspz * specification: 31c74ad251Schristos * https://web.archive.org/web/20150302152944/http://tipc.sourceforge.net/doc/draft-spec-tipc-07.html 32c74ad251Schristos * https://web.archive.org/web/20161025110514/http://tipc.sourceforge.net/doc/tipc_message_formats.html 33dc860a36Sspz */ 34dc860a36Sspz 35c74ad251Schristos #include <config.h> 369546e36dSchristos 37c74ad251Schristos #include "netdissect-stdinc.h" 389546e36dSchristos 39784088dfSchristos #include "netdissect.h" 40784088dfSchristos #include "extract.h" 419546e36dSchristos 42c47fd378Schristos 439546e36dSchristos #define TIPC_USER_LOW_IMPORTANCE 0 449546e36dSchristos #define TIPC_USER_MEDIUM_IMPORTANCE 1 459546e36dSchristos #define TIPC_USER_HIGH_IMPORTANCE 2 469546e36dSchristos #define TIPC_USER_CRITICAL_IMPORTANCE 3 479546e36dSchristos #define TIPC_USER_BCAST_PROTOCOL 5 489546e36dSchristos #define TIPC_USER_MSG_BUNDLER 6 499546e36dSchristos #define TIPC_USER_LINK_PROTOCOL 7 509546e36dSchristos #define TIPC_USER_CONN_MANAGER 8 519546e36dSchristos #define TIPC_USER_CHANGEOVER_PROTOCOL 10 529546e36dSchristos #define TIPC_USER_NAME_DISTRIBUTOR 11 539546e36dSchristos #define TIPC_USER_MSG_FRAGMENTER 12 549546e36dSchristos #define TIPC_USER_LINK_CONFIG 13 559546e36dSchristos 569546e36dSchristos #define TIPC_CONN_MSG 0 579546e36dSchristos #define TIPC_DIRECT_MSG 1 589546e36dSchristos #define TIPC_NAMED_MSG 2 599546e36dSchristos #define TIPC_MCAST_MSG 3 609546e36dSchristos 619546e36dSchristos #define TIPC_ZONE(addr) (((addr) >> 24) & 0xFF) 629546e36dSchristos #define TIPC_CLUSTER(addr) (((addr) >> 12) & 0xFFF) 639546e36dSchristos #define TIPC_NODE(addr) (((addr) >> 0) & 0xFFF) 649546e36dSchristos 659546e36dSchristos struct tipc_pkthdr { 66c74ad251Schristos nd_uint32_t w0; 67c74ad251Schristos nd_uint32_t w1; 689546e36dSchristos }; 699546e36dSchristos 709546e36dSchristos #define TIPC_VER(w0) (((w0) >> 29) & 0x07) 719546e36dSchristos #define TIPC_USER(w0) (((w0) >> 25) & 0x0F) 729546e36dSchristos #define TIPC_HSIZE(w0) (((w0) >> 21) & 0x0F) 73c74ad251Schristos #define TIPC_MSIZE(w0) (((w0) >> 0) & 0x1FFFF) 749546e36dSchristos #define TIPC_MTYPE(w1) (((w1) >> 29) & 0x07) 759546e36dSchristos #define TIPC_BROADCAST_ACK(w1) (((w1) >> 0) & 0xFFFF) 769546e36dSchristos #define TIPC_LINK_ACK(w2) (((w2) >> 16) & 0xFFFF) 779546e36dSchristos #define TIPC_LINK_SEQ(w2) (((w2) >> 0) & 0xFFFF) 789546e36dSchristos 799546e36dSchristos static const struct tok tipcuser_values[] = { 809546e36dSchristos { TIPC_USER_LOW_IMPORTANCE, "Low Importance Data payload" }, 819546e36dSchristos { TIPC_USER_MEDIUM_IMPORTANCE, "Medium Importance Data payload" }, 829546e36dSchristos { TIPC_USER_HIGH_IMPORTANCE, "High Importance Data payload" }, 839546e36dSchristos { TIPC_USER_CRITICAL_IMPORTANCE, "Critical Importance Data payload" }, 849546e36dSchristos { TIPC_USER_BCAST_PROTOCOL, "Broadcast Link Protocol internal" }, 859546e36dSchristos { TIPC_USER_MSG_BUNDLER, "Message Bundler Protocol internal" }, 869546e36dSchristos { TIPC_USER_LINK_PROTOCOL, "Link State Protocol internal" }, 879546e36dSchristos { TIPC_USER_CONN_MANAGER, "Connection Manager internal" }, 889546e36dSchristos { TIPC_USER_CHANGEOVER_PROTOCOL, "Link Changeover Protocol internal" }, 899546e36dSchristos { TIPC_USER_NAME_DISTRIBUTOR, "Name Table Update Protocol internal" }, 909546e36dSchristos { TIPC_USER_MSG_FRAGMENTER, "Message Fragmentation Protocol internal" }, 919546e36dSchristos { TIPC_USER_LINK_CONFIG, "Neighbor Detection Protocol internal" }, 929546e36dSchristos { 0, NULL } 939546e36dSchristos }; 949546e36dSchristos 959546e36dSchristos static const struct tok tipcmtype_values[] = { 969546e36dSchristos { TIPC_CONN_MSG, "CONN_MSG" }, 979546e36dSchristos { TIPC_DIRECT_MSG, "MCAST_MSG" }, 989546e36dSchristos { TIPC_NAMED_MSG, "NAMED_MSG" }, 999546e36dSchristos { TIPC_MCAST_MSG, "DIRECT_MSG" }, 1009546e36dSchristos { 0, NULL } 1019546e36dSchristos }; 1029546e36dSchristos 1039546e36dSchristos static const struct tok tipc_linkconf_mtype_values[] = { 1049546e36dSchristos { 0, "Link request" }, 1059546e36dSchristos { 1, "Link response" }, 1069546e36dSchristos { 0, NULL } 1079546e36dSchristos }; 1089546e36dSchristos 1099546e36dSchristos struct payload_tipc_pkthdr { 110c74ad251Schristos nd_uint32_t w0; 111c74ad251Schristos nd_uint32_t w1; 112c74ad251Schristos nd_uint32_t w2; 113c74ad251Schristos nd_uint32_t prev_node; 114c74ad251Schristos nd_uint32_t orig_port; 115c74ad251Schristos nd_uint32_t dest_port; 116c74ad251Schristos nd_uint32_t orig_node; 117c74ad251Schristos nd_uint32_t dest_node; 118c74ad251Schristos nd_uint32_t name_type; 119c74ad251Schristos nd_uint32_t w9; 120c74ad251Schristos nd_uint32_t wA; 1219546e36dSchristos }; 1229546e36dSchristos 1239546e36dSchristos struct internal_tipc_pkthdr { 124c74ad251Schristos nd_uint32_t w0; 125c74ad251Schristos nd_uint32_t w1; 126c74ad251Schristos nd_uint32_t w2; 127c74ad251Schristos nd_uint32_t prev_node; 128c74ad251Schristos nd_uint32_t w4; 129c74ad251Schristos nd_uint32_t w5; 130c74ad251Schristos nd_uint32_t orig_node; 131c74ad251Schristos nd_uint32_t dest_node; 132c74ad251Schristos nd_uint32_t trans_seq; 133c74ad251Schristos nd_uint32_t w9; 1349546e36dSchristos }; 1359546e36dSchristos 1369546e36dSchristos #define TIPC_SEQ_GAP(w1) (((w1) >> 16) & 0x1FFF) 1379546e36dSchristos #define TIPC_BC_GAP_AFTER(w2) (((w2) >> 16) & 0xFFFF) 1389546e36dSchristos #define TIPC_BC_GAP_TO(w2) (((w2) >> 0) & 0xFFFF) 1399546e36dSchristos #define TIPC_LAST_SENT_FRAG(w4) (((w4) >> 16) & 0xFFFF) 1409546e36dSchristos #define TIPC_NEXT_SENT_FRAG(w4) (((w4) >> 0) & 0xFFFF) 1419546e36dSchristos #define TIPC_SESS_NO(w5) (((w5) >> 16) & 0xFFFF) 1429546e36dSchristos #define TIPC_MSG_CNT(w9) (((w9) >> 16) & 0xFFFF) 1439546e36dSchristos #define TIPC_LINK_TOL(w9) (((w9) >> 0) & 0xFFFF) 1449546e36dSchristos 1459546e36dSchristos struct link_conf_tipc_pkthdr { 146c74ad251Schristos nd_uint32_t w0; 147c74ad251Schristos nd_uint32_t w1; 148c74ad251Schristos nd_uint32_t dest_domain; 149c74ad251Schristos nd_uint32_t prev_node; 150c74ad251Schristos nd_uint32_t ntwrk_id; 151c74ad251Schristos nd_uint32_t w5; 152c74ad251Schristos nd_byte media_address[16]; 1539546e36dSchristos }; 1549546e36dSchristos 1559546e36dSchristos #define TIPC_NODE_SIG(w1) (((w1) >> 0) & 0xFFFF) 1569546e36dSchristos #define TIPC_MEDIA_ID(w5) (((w5) >> 0) & 0xFF) 1579546e36dSchristos 1589546e36dSchristos static void 1599546e36dSchristos print_payload(netdissect_options *ndo, const struct payload_tipc_pkthdr *ap) 1609546e36dSchristos { 161c47fd378Schristos uint32_t w0, w1, w2; 1629546e36dSchristos u_int user; 1639546e36dSchristos u_int hsize; 1649546e36dSchristos u_int msize; 1659546e36dSchristos u_int mtype; 1669546e36dSchristos u_int broadcast_ack; 1679546e36dSchristos u_int link_ack; 1689546e36dSchristos u_int link_seq; 1699546e36dSchristos u_int prev_node; 1709546e36dSchristos u_int orig_port; 1719546e36dSchristos u_int dest_port; 1729546e36dSchristos u_int orig_node; 1739546e36dSchristos u_int dest_node; 1749546e36dSchristos 175c74ad251Schristos w0 = GET_BE_U_4(ap->w0); 1769546e36dSchristos user = TIPC_USER(w0); 1779546e36dSchristos hsize = TIPC_HSIZE(w0); 1789546e36dSchristos msize = TIPC_MSIZE(w0); 179c74ad251Schristos w1 = GET_BE_U_4(ap->w1); 1809546e36dSchristos mtype = TIPC_MTYPE(w1); 181c74ad251Schristos prev_node = GET_BE_U_4(ap->prev_node); 182c74ad251Schristos orig_port = GET_BE_U_4(ap->orig_port); 183c74ad251Schristos dest_port = GET_BE_U_4(ap->dest_port); 1849546e36dSchristos if (hsize <= 6) { 185c74ad251Schristos ND_PRINT("TIPC v%u.0 %u.%u.%u:%u > %u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 1869546e36dSchristos TIPC_VER(w0), 1879546e36dSchristos TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 1889546e36dSchristos orig_port, dest_port, 1899546e36dSchristos hsize*4, msize, 1909546e36dSchristos tok2str(tipcuser_values, "unknown", user), 191c74ad251Schristos tok2str(tipcmtype_values, "Unknown", mtype)); 1929546e36dSchristos } else { 193c74ad251Schristos orig_node = GET_BE_U_4(ap->orig_node); 194c74ad251Schristos dest_node = GET_BE_U_4(ap->dest_node); 195c74ad251Schristos ND_PRINT("TIPC v%u.0 %u.%u.%u:%u > %u.%u.%u:%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 1969546e36dSchristos TIPC_VER(w0), 1979546e36dSchristos TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node), 1989546e36dSchristos orig_port, 1999546e36dSchristos TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node), 2009546e36dSchristos dest_port, 2019546e36dSchristos hsize*4, msize, 2029546e36dSchristos tok2str(tipcuser_values, "unknown", user), 203c74ad251Schristos tok2str(tipcmtype_values, "Unknown", mtype)); 2049546e36dSchristos 2059546e36dSchristos if (ndo->ndo_vflag) { 2069546e36dSchristos broadcast_ack = TIPC_BROADCAST_ACK(w1); 207c74ad251Schristos w2 = GET_BE_U_4(ap->w2); 2089546e36dSchristos link_ack = TIPC_LINK_ACK(w2); 2099546e36dSchristos link_seq = TIPC_LINK_SEQ(w2); 210c74ad251Schristos ND_PRINT("\n\tPrevious Node %u.%u.%u, Broadcast Ack %u, Link Ack %u, Link Sequence %u", 2119546e36dSchristos TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 212c74ad251Schristos broadcast_ack, link_ack, link_seq); 2139546e36dSchristos } 2149546e36dSchristos } 2159546e36dSchristos } 2169546e36dSchristos 217a8e08e94Skamil UNALIGNED_OK 2189546e36dSchristos static void 2199546e36dSchristos print_internal(netdissect_options *ndo, const struct internal_tipc_pkthdr *ap) 2209546e36dSchristos { 221c47fd378Schristos uint32_t w0, w1, w2, w4, w5, w9; 2229546e36dSchristos u_int user; 2239546e36dSchristos u_int hsize; 2249546e36dSchristos u_int msize; 2259546e36dSchristos u_int mtype; 2269546e36dSchristos u_int seq_gap; 2279546e36dSchristos u_int broadcast_ack; 2289546e36dSchristos u_int bc_gap_after; 2299546e36dSchristos u_int bc_gap_to; 2309546e36dSchristos u_int prev_node; 2319546e36dSchristos u_int last_sent_frag; 2329546e36dSchristos u_int next_sent_frag; 2339546e36dSchristos u_int sess_no; 2349546e36dSchristos u_int orig_node; 2359546e36dSchristos u_int dest_node; 2369546e36dSchristos u_int trans_seq; 2379546e36dSchristos u_int msg_cnt; 2389546e36dSchristos u_int link_tol; 2399546e36dSchristos 240c74ad251Schristos w0 = GET_BE_U_4(ap->w0); 2419546e36dSchristos user = TIPC_USER(w0); 2429546e36dSchristos hsize = TIPC_HSIZE(w0); 2439546e36dSchristos msize = TIPC_MSIZE(w0); 244c74ad251Schristos w1 = GET_BE_U_4(ap->w1); 2459546e36dSchristos mtype = TIPC_MTYPE(w1); 246c74ad251Schristos orig_node = GET_BE_U_4(ap->orig_node); 247c74ad251Schristos dest_node = GET_BE_U_4(ap->dest_node); 248c74ad251Schristos ND_PRINT("TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s (0x%08x)", 2499546e36dSchristos TIPC_VER(w0), 2509546e36dSchristos TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node), 2519546e36dSchristos TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node), 2529546e36dSchristos hsize*4, msize, 2539546e36dSchristos tok2str(tipcuser_values, "unknown", user), 254c74ad251Schristos tok2str(tipcmtype_values, "Unknown", mtype), w1); 2559546e36dSchristos 2569546e36dSchristos if (ndo->ndo_vflag) { 2579546e36dSchristos seq_gap = TIPC_SEQ_GAP(w1); 2589546e36dSchristos broadcast_ack = TIPC_BROADCAST_ACK(w1); 259c74ad251Schristos w2 = GET_BE_U_4(ap->w2); 2609546e36dSchristos bc_gap_after = TIPC_BC_GAP_AFTER(w2); 2619546e36dSchristos bc_gap_to = TIPC_BC_GAP_TO(w2); 262c74ad251Schristos prev_node = GET_BE_U_4(ap->prev_node); 263c74ad251Schristos w4 = GET_BE_U_4(ap->w4); 2649546e36dSchristos last_sent_frag = TIPC_LAST_SENT_FRAG(w4); 2659546e36dSchristos next_sent_frag = TIPC_NEXT_SENT_FRAG(w4); 266c74ad251Schristos w5 = GET_BE_U_4(ap->w5); 2679546e36dSchristos sess_no = TIPC_SESS_NO(w5); 268c74ad251Schristos trans_seq = GET_BE_U_4(ap->trans_seq); 269c74ad251Schristos w9 = GET_BE_U_4(ap->w9); 2709546e36dSchristos msg_cnt = TIPC_MSG_CNT(w9); 2719546e36dSchristos link_tol = TIPC_LINK_TOL(w9); 272c74ad251Schristos 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", 2739546e36dSchristos TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 2749546e36dSchristos sess_no, broadcast_ack, seq_gap, bc_gap_after, bc_gap_to, 2759546e36dSchristos last_sent_frag, next_sent_frag, trans_seq, msg_cnt, 276c74ad251Schristos link_tol); 2779546e36dSchristos } 2789546e36dSchristos } 2799546e36dSchristos 2809546e36dSchristos static void 2819546e36dSchristos print_link_conf(netdissect_options *ndo, const struct link_conf_tipc_pkthdr *ap) 2829546e36dSchristos { 283c47fd378Schristos uint32_t w0, w1, w5; 2849546e36dSchristos u_int user; 2859546e36dSchristos u_int hsize; 2869546e36dSchristos u_int msize; 2879546e36dSchristos u_int mtype; 2889546e36dSchristos u_int node_sig; 2899546e36dSchristos u_int prev_node; 2909546e36dSchristos u_int dest_domain; 2919546e36dSchristos u_int ntwrk_id; 2929546e36dSchristos u_int media_id; 2939546e36dSchristos 294c74ad251Schristos w0 = GET_BE_U_4(ap->w0); 2959546e36dSchristos user = TIPC_USER(w0); 2969546e36dSchristos hsize = TIPC_HSIZE(w0); 2979546e36dSchristos msize = TIPC_MSIZE(w0); 298c74ad251Schristos w1 = GET_BE_U_4(ap->w1); 2999546e36dSchristos mtype = TIPC_MTYPE(w1); 300c74ad251Schristos dest_domain = GET_BE_U_4(ap->dest_domain); 301c74ad251Schristos prev_node = GET_BE_U_4(ap->prev_node); 3029546e36dSchristos 303c74ad251Schristos ND_PRINT("TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", 3049546e36dSchristos TIPC_VER(w0), 3059546e36dSchristos TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), 3069546e36dSchristos TIPC_ZONE(dest_domain), TIPC_CLUSTER(dest_domain), TIPC_NODE(dest_domain), 3079546e36dSchristos hsize*4, msize, 3089546e36dSchristos tok2str(tipcuser_values, "unknown", user), 309c74ad251Schristos tok2str(tipc_linkconf_mtype_values, "Unknown", mtype)); 3109546e36dSchristos if (ndo->ndo_vflag) { 3119546e36dSchristos node_sig = TIPC_NODE_SIG(w1); 312c74ad251Schristos ntwrk_id = GET_BE_U_4(ap->ntwrk_id); 313c74ad251Schristos w5 = GET_BE_U_4(ap->w5); 3149546e36dSchristos media_id = TIPC_MEDIA_ID(w5); 315c74ad251Schristos ND_PRINT("\n\tNodeSignature %u, network_id %u, media_id %u", 316c74ad251Schristos node_sig, ntwrk_id, media_id); 3179546e36dSchristos } 3189546e36dSchristos } 3199546e36dSchristos 320a8e08e94Skamil UNALIGNED_OK 3219546e36dSchristos void 3229546e36dSchristos tipc_print(netdissect_options *ndo, const u_char *bp, u_int length _U_, 3239546e36dSchristos u_int caplen _U_) 3249546e36dSchristos { 3259546e36dSchristos const struct tipc_pkthdr *ap; 326c47fd378Schristos uint32_t w0; 3279546e36dSchristos u_int user; 3289546e36dSchristos 329c74ad251Schristos ndo->ndo_protocol = "tipc"; 330784088dfSchristos ap = (const struct tipc_pkthdr *)bp; 331c74ad251Schristos w0 = GET_BE_U_4(ap->w0); 3329546e36dSchristos user = TIPC_USER(w0); 3339546e36dSchristos 334*26ba0b50Schristos switch (user) { 3359546e36dSchristos case TIPC_USER_LOW_IMPORTANCE: 3369546e36dSchristos case TIPC_USER_MEDIUM_IMPORTANCE: 3379546e36dSchristos case TIPC_USER_HIGH_IMPORTANCE: 3389546e36dSchristos case TIPC_USER_CRITICAL_IMPORTANCE: 3399546e36dSchristos case TIPC_USER_NAME_DISTRIBUTOR: 3409546e36dSchristos case TIPC_USER_CONN_MANAGER: 341784088dfSchristos print_payload(ndo, (const struct payload_tipc_pkthdr *)bp); 3429546e36dSchristos break; 3439546e36dSchristos 3449546e36dSchristos case TIPC_USER_LINK_CONFIG: 345784088dfSchristos print_link_conf(ndo, (const struct link_conf_tipc_pkthdr *)bp); 3469546e36dSchristos break; 3479546e36dSchristos 3489546e36dSchristos case TIPC_USER_BCAST_PROTOCOL: 3499546e36dSchristos case TIPC_USER_MSG_BUNDLER: 3509546e36dSchristos case TIPC_USER_LINK_PROTOCOL: 3519546e36dSchristos case TIPC_USER_CHANGEOVER_PROTOCOL: 3529546e36dSchristos case TIPC_USER_MSG_FRAGMENTER: 353784088dfSchristos print_internal(ndo, (const struct internal_tipc_pkthdr *)bp); 3549546e36dSchristos break; 3559546e36dSchristos 3569546e36dSchristos } 3579546e36dSchristos } 358