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