blob: 54179a4ea605c6be1785d07d197ffe59c13fbd43 [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/*
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
Elliott Hughese2e3bd12017-05-15 10:59:29 -070022/* \summary: Transparent Inter-Process Communication (TIPC) protocol printer */
23
24/*
25 * specification:
Elliott Hughes820eced2021-08-20 18:00:50 -070026 * 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
Elliott Hughese2e3bd12017-05-15 10:59:29 -070028 */
29
JP Abgrall53f17a92014-02-12 14:02:41 -080030#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070031#include <config.h>
JP Abgrall53f17a92014-02-12 14:02:41 -080032#endif
33
Elliott Hughes820eced2021-08-20 18:00:50 -070034#include "netdissect-stdinc.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080035
Elliott Hughese2e3bd12017-05-15 10:59:29 -070036#include "netdissect.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080037#include "ethertype.h"
Elliott Hughese2e3bd12017-05-15 10:59:29 -070038#include "extract.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080039
Elliott Hughes892a68b2015-10-19 14:43:53 -070040
JP Abgrall53f17a92014-02-12 14:02:41 -080041#define TIPC_USER_LOW_IMPORTANCE 0
42#define TIPC_USER_MEDIUM_IMPORTANCE 1
43#define TIPC_USER_HIGH_IMPORTANCE 2
44#define TIPC_USER_CRITICAL_IMPORTANCE 3
45#define TIPC_USER_BCAST_PROTOCOL 5
46#define TIPC_USER_MSG_BUNDLER 6
47#define TIPC_USER_LINK_PROTOCOL 7
48#define TIPC_USER_CONN_MANAGER 8
49#define TIPC_USER_CHANGEOVER_PROTOCOL 10
50#define TIPC_USER_NAME_DISTRIBUTOR 11
51#define TIPC_USER_MSG_FRAGMENTER 12
52#define TIPC_USER_LINK_CONFIG 13
53
54#define TIPC_CONN_MSG 0
55#define TIPC_DIRECT_MSG 1
56#define TIPC_NAMED_MSG 2
57#define TIPC_MCAST_MSG 3
58
59#define TIPC_ZONE(addr) (((addr) >> 24) & 0xFF)
60#define TIPC_CLUSTER(addr) (((addr) >> 12) & 0xFFF)
61#define TIPC_NODE(addr) (((addr) >> 0) & 0xFFF)
62
63struct tipc_pkthdr {
Elliott Hughes820eced2021-08-20 18:00:50 -070064 nd_uint32_t w0;
65 nd_uint32_t w1;
JP Abgrall53f17a92014-02-12 14:02:41 -080066};
67
68#define TIPC_VER(w0) (((w0) >> 29) & 0x07)
69#define TIPC_USER(w0) (((w0) >> 25) & 0x0F)
70#define TIPC_HSIZE(w0) (((w0) >> 21) & 0x0F)
Elliott Hughes820eced2021-08-20 18:00:50 -070071#define TIPC_MSIZE(w0) (((w0) >> 0) & 0x1FFFF)
JP Abgrall53f17a92014-02-12 14:02:41 -080072#define TIPC_MTYPE(w1) (((w1) >> 29) & 0x07)
73#define TIPC_BROADCAST_ACK(w1) (((w1) >> 0) & 0xFFFF)
74#define TIPC_LINK_ACK(w2) (((w2) >> 16) & 0xFFFF)
75#define TIPC_LINK_SEQ(w2) (((w2) >> 0) & 0xFFFF)
76
77static const struct tok tipcuser_values[] = {
78 { TIPC_USER_LOW_IMPORTANCE, "Low Importance Data payload" },
79 { TIPC_USER_MEDIUM_IMPORTANCE, "Medium Importance Data payload" },
80 { TIPC_USER_HIGH_IMPORTANCE, "High Importance Data payload" },
81 { TIPC_USER_CRITICAL_IMPORTANCE, "Critical Importance Data payload" },
82 { TIPC_USER_BCAST_PROTOCOL, "Broadcast Link Protocol internal" },
83 { TIPC_USER_MSG_BUNDLER, "Message Bundler Protocol internal" },
84 { TIPC_USER_LINK_PROTOCOL, "Link State Protocol internal" },
85 { TIPC_USER_CONN_MANAGER, "Connection Manager internal" },
86 { TIPC_USER_CHANGEOVER_PROTOCOL, "Link Changeover Protocol internal" },
87 { TIPC_USER_NAME_DISTRIBUTOR, "Name Table Update Protocol internal" },
88 { TIPC_USER_MSG_FRAGMENTER, "Message Fragmentation Protocol internal" },
89 { TIPC_USER_LINK_CONFIG, "Neighbor Detection Protocol internal" },
90 { 0, NULL }
91};
92
93static const struct tok tipcmtype_values[] = {
94 { TIPC_CONN_MSG, "CONN_MSG" },
95 { TIPC_DIRECT_MSG, "MCAST_MSG" },
96 { TIPC_NAMED_MSG, "NAMED_MSG" },
97 { TIPC_MCAST_MSG, "DIRECT_MSG" },
98 { 0, NULL }
99};
100
101static const struct tok tipc_linkconf_mtype_values[] = {
102 { 0, "Link request" },
103 { 1, "Link response" },
104 { 0, NULL }
105};
106
107struct payload_tipc_pkthdr {
Elliott Hughes820eced2021-08-20 18:00:50 -0700108 nd_uint32_t w0;
109 nd_uint32_t w1;
110 nd_uint32_t w2;
111 nd_uint32_t prev_node;
112 nd_uint32_t orig_port;
113 nd_uint32_t dest_port;
114 nd_uint32_t orig_node;
115 nd_uint32_t dest_node;
116 nd_uint32_t name_type;
117 nd_uint32_t w9;
118 nd_uint32_t wA;
JP Abgrall53f17a92014-02-12 14:02:41 -0800119};
120
121struct internal_tipc_pkthdr {
Elliott Hughes820eced2021-08-20 18:00:50 -0700122 nd_uint32_t w0;
123 nd_uint32_t w1;
124 nd_uint32_t w2;
125 nd_uint32_t prev_node;
126 nd_uint32_t w4;
127 nd_uint32_t w5;
128 nd_uint32_t orig_node;
129 nd_uint32_t dest_node;
130 nd_uint32_t trans_seq;
131 nd_uint32_t w9;
JP Abgrall53f17a92014-02-12 14:02:41 -0800132};
133
134#define TIPC_SEQ_GAP(w1) (((w1) >> 16) & 0x1FFF)
135#define TIPC_BC_GAP_AFTER(w2) (((w2) >> 16) & 0xFFFF)
136#define TIPC_BC_GAP_TO(w2) (((w2) >> 0) & 0xFFFF)
137#define TIPC_LAST_SENT_FRAG(w4) (((w4) >> 16) & 0xFFFF)
138#define TIPC_NEXT_SENT_FRAG(w4) (((w4) >> 0) & 0xFFFF)
139#define TIPC_SESS_NO(w5) (((w5) >> 16) & 0xFFFF)
140#define TIPC_MSG_CNT(w9) (((w9) >> 16) & 0xFFFF)
141#define TIPC_LINK_TOL(w9) (((w9) >> 0) & 0xFFFF)
142
143struct link_conf_tipc_pkthdr {
Elliott Hughes820eced2021-08-20 18:00:50 -0700144 nd_uint32_t w0;
145 nd_uint32_t w1;
146 nd_uint32_t dest_domain;
147 nd_uint32_t prev_node;
148 nd_uint32_t ntwrk_id;
149 nd_uint32_t w5;
150 nd_byte media_address[16];
JP Abgrall53f17a92014-02-12 14:02:41 -0800151};
152
153#define TIPC_NODE_SIG(w1) (((w1) >> 0) & 0xFFFF)
154#define TIPC_MEDIA_ID(w5) (((w5) >> 0) & 0xFF)
155
156static void
157print_payload(netdissect_options *ndo, const struct payload_tipc_pkthdr *ap)
158{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700159 uint32_t w0, w1, w2;
JP Abgrall53f17a92014-02-12 14:02:41 -0800160 u_int user;
161 u_int hsize;
162 u_int msize;
163 u_int mtype;
164 u_int broadcast_ack;
165 u_int link_ack;
166 u_int link_seq;
167 u_int prev_node;
168 u_int orig_port;
169 u_int dest_port;
170 u_int orig_node;
171 u_int dest_node;
172
Elliott Hughes820eced2021-08-20 18:00:50 -0700173 w0 = GET_BE_U_4(ap->w0);
JP Abgrall53f17a92014-02-12 14:02:41 -0800174 user = TIPC_USER(w0);
175 hsize = TIPC_HSIZE(w0);
176 msize = TIPC_MSIZE(w0);
Elliott Hughes820eced2021-08-20 18:00:50 -0700177 w1 = GET_BE_U_4(ap->w1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800178 mtype = TIPC_MTYPE(w1);
Elliott Hughes820eced2021-08-20 18:00:50 -0700179 prev_node = GET_BE_U_4(ap->prev_node);
180 orig_port = GET_BE_U_4(ap->orig_port);
181 dest_port = GET_BE_U_4(ap->dest_port);
JP Abgrall53f17a92014-02-12 14:02:41 -0800182 if (hsize <= 6) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700183 ND_PRINT("TIPC v%u.0 %u.%u.%u:%u > %u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s",
JP Abgrall53f17a92014-02-12 14:02:41 -0800184 TIPC_VER(w0),
185 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node),
186 orig_port, dest_port,
187 hsize*4, msize,
188 tok2str(tipcuser_values, "unknown", user),
Elliott Hughes820eced2021-08-20 18:00:50 -0700189 tok2str(tipcmtype_values, "Unknown", mtype));
JP Abgrall53f17a92014-02-12 14:02:41 -0800190 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700191 orig_node = GET_BE_U_4(ap->orig_node);
192 dest_node = GET_BE_U_4(ap->dest_node);
193 ND_PRINT("TIPC v%u.0 %u.%u.%u:%u > %u.%u.%u:%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s",
JP Abgrall53f17a92014-02-12 14:02:41 -0800194 TIPC_VER(w0),
195 TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node),
196 orig_port,
197 TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node),
198 dest_port,
199 hsize*4, msize,
200 tok2str(tipcuser_values, "unknown", user),
Elliott Hughes820eced2021-08-20 18:00:50 -0700201 tok2str(tipcmtype_values, "Unknown", mtype));
JP Abgrall53f17a92014-02-12 14:02:41 -0800202
203 if (ndo->ndo_vflag) {
204 broadcast_ack = TIPC_BROADCAST_ACK(w1);
Elliott Hughes820eced2021-08-20 18:00:50 -0700205 w2 = GET_BE_U_4(ap->w2);
JP Abgrall53f17a92014-02-12 14:02:41 -0800206 link_ack = TIPC_LINK_ACK(w2);
207 link_seq = TIPC_LINK_SEQ(w2);
Elliott Hughes820eced2021-08-20 18:00:50 -0700208 ND_PRINT("\n\tPrevious Node %u.%u.%u, Broadcast Ack %u, Link Ack %u, Link Sequence %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800209 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node),
Elliott Hughes820eced2021-08-20 18:00:50 -0700210 broadcast_ack, link_ack, link_seq);
JP Abgrall53f17a92014-02-12 14:02:41 -0800211 }
212 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800213}
Elliott Hughes892a68b2015-10-19 14:43:53 -0700214
JP Abgrall53f17a92014-02-12 14:02:41 -0800215static void
216print_internal(netdissect_options *ndo, const struct internal_tipc_pkthdr *ap)
217{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700218 uint32_t w0, w1, w2, w4, w5, w9;
JP Abgrall53f17a92014-02-12 14:02:41 -0800219 u_int user;
220 u_int hsize;
221 u_int msize;
222 u_int mtype;
223 u_int seq_gap;
224 u_int broadcast_ack;
225 u_int bc_gap_after;
226 u_int bc_gap_to;
227 u_int prev_node;
228 u_int last_sent_frag;
229 u_int next_sent_frag;
230 u_int sess_no;
231 u_int orig_node;
232 u_int dest_node;
233 u_int trans_seq;
234 u_int msg_cnt;
235 u_int link_tol;
236
Elliott Hughes820eced2021-08-20 18:00:50 -0700237 w0 = GET_BE_U_4(ap->w0);
JP Abgrall53f17a92014-02-12 14:02:41 -0800238 user = TIPC_USER(w0);
239 hsize = TIPC_HSIZE(w0);
240 msize = TIPC_MSIZE(w0);
Elliott Hughes820eced2021-08-20 18:00:50 -0700241 w1 = GET_BE_U_4(ap->w1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800242 mtype = TIPC_MTYPE(w1);
Elliott Hughes820eced2021-08-20 18:00:50 -0700243 orig_node = GET_BE_U_4(ap->orig_node);
244 dest_node = GET_BE_U_4(ap->dest_node);
245 ND_PRINT("TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s (0x%08x)",
JP Abgrall53f17a92014-02-12 14:02:41 -0800246 TIPC_VER(w0),
247 TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node),
248 TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node),
249 hsize*4, msize,
250 tok2str(tipcuser_values, "unknown", user),
Elliott Hughes820eced2021-08-20 18:00:50 -0700251 tok2str(tipcmtype_values, "Unknown", mtype), w1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800252
253 if (ndo->ndo_vflag) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800254 seq_gap = TIPC_SEQ_GAP(w1);
255 broadcast_ack = TIPC_BROADCAST_ACK(w1);
Elliott Hughes820eced2021-08-20 18:00:50 -0700256 w2 = GET_BE_U_4(ap->w2);
JP Abgrall53f17a92014-02-12 14:02:41 -0800257 bc_gap_after = TIPC_BC_GAP_AFTER(w2);
258 bc_gap_to = TIPC_BC_GAP_TO(w2);
Elliott Hughes820eced2021-08-20 18:00:50 -0700259 prev_node = GET_BE_U_4(ap->prev_node);
260 w4 = GET_BE_U_4(ap->w4);
JP Abgrall53f17a92014-02-12 14:02:41 -0800261 last_sent_frag = TIPC_LAST_SENT_FRAG(w4);
262 next_sent_frag = TIPC_NEXT_SENT_FRAG(w4);
Elliott Hughes820eced2021-08-20 18:00:50 -0700263 w5 = GET_BE_U_4(ap->w5);
JP Abgrall53f17a92014-02-12 14:02:41 -0800264 sess_no = TIPC_SESS_NO(w5);
Elliott Hughes820eced2021-08-20 18:00:50 -0700265 trans_seq = GET_BE_U_4(ap->trans_seq);
266 w9 = GET_BE_U_4(ap->w9);
JP Abgrall53f17a92014-02-12 14:02:41 -0800267 msg_cnt = TIPC_MSG_CNT(w9);
268 link_tol = TIPC_LINK_TOL(w9);
Elliott Hughes820eced2021-08-20 18:00:50 -0700269 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",
JP Abgrall53f17a92014-02-12 14:02:41 -0800270 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node),
271 sess_no, broadcast_ack, seq_gap, bc_gap_after, bc_gap_to,
272 last_sent_frag, next_sent_frag, trans_seq, msg_cnt,
Elliott Hughes820eced2021-08-20 18:00:50 -0700273 link_tol);
JP Abgrall53f17a92014-02-12 14:02:41 -0800274 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800275}
276
277static void
278print_link_conf(netdissect_options *ndo, const struct link_conf_tipc_pkthdr *ap)
279{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700280 uint32_t w0, w1, w5;
JP Abgrall53f17a92014-02-12 14:02:41 -0800281 u_int user;
282 u_int hsize;
283 u_int msize;
284 u_int mtype;
285 u_int node_sig;
286 u_int prev_node;
287 u_int dest_domain;
288 u_int ntwrk_id;
289 u_int media_id;
290
Elliott Hughes820eced2021-08-20 18:00:50 -0700291 w0 = GET_BE_U_4(ap->w0);
JP Abgrall53f17a92014-02-12 14:02:41 -0800292 user = TIPC_USER(w0);
293 hsize = TIPC_HSIZE(w0);
294 msize = TIPC_MSIZE(w0);
Elliott Hughes820eced2021-08-20 18:00:50 -0700295 w1 = GET_BE_U_4(ap->w1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800296 mtype = TIPC_MTYPE(w1);
Elliott Hughes820eced2021-08-20 18:00:50 -0700297 dest_domain = GET_BE_U_4(ap->dest_domain);
298 prev_node = GET_BE_U_4(ap->prev_node);
JP Abgrall53f17a92014-02-12 14:02:41 -0800299
Elliott Hughes820eced2021-08-20 18:00:50 -0700300 ND_PRINT("TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s",
JP Abgrall53f17a92014-02-12 14:02:41 -0800301 TIPC_VER(w0),
302 TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node),
303 TIPC_ZONE(dest_domain), TIPC_CLUSTER(dest_domain), TIPC_NODE(dest_domain),
304 hsize*4, msize,
305 tok2str(tipcuser_values, "unknown", user),
Elliott Hughes820eced2021-08-20 18:00:50 -0700306 tok2str(tipc_linkconf_mtype_values, "Unknown", mtype));
JP Abgrall53f17a92014-02-12 14:02:41 -0800307 if (ndo->ndo_vflag) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800308 node_sig = TIPC_NODE_SIG(w1);
Elliott Hughes820eced2021-08-20 18:00:50 -0700309 ntwrk_id = GET_BE_U_4(ap->ntwrk_id);
310 w5 = GET_BE_U_4(ap->w5);
JP Abgrall53f17a92014-02-12 14:02:41 -0800311 media_id = TIPC_MEDIA_ID(w5);
Elliott Hughes820eced2021-08-20 18:00:50 -0700312 ND_PRINT("\n\tNodeSignature %u, network_id %u, media_id %u",
313 node_sig, ntwrk_id, media_id);
JP Abgrall53f17a92014-02-12 14:02:41 -0800314 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800315}
316
317void
318tipc_print(netdissect_options *ndo, const u_char *bp, u_int length _U_,
319 u_int caplen _U_)
320{
321 const struct tipc_pkthdr *ap;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700322 uint32_t w0;
JP Abgrall53f17a92014-02-12 14:02:41 -0800323 u_int user;
324
Elliott Hughes820eced2021-08-20 18:00:50 -0700325 ndo->ndo_protocol = "tipc";
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700326 ap = (const struct tipc_pkthdr *)bp;
Elliott Hughes820eced2021-08-20 18:00:50 -0700327 w0 = GET_BE_U_4(ap->w0);
JP Abgrall53f17a92014-02-12 14:02:41 -0800328 user = TIPC_USER(w0);
329
330 switch (user)
331 {
332 case TIPC_USER_LOW_IMPORTANCE:
333 case TIPC_USER_MEDIUM_IMPORTANCE:
334 case TIPC_USER_HIGH_IMPORTANCE:
335 case TIPC_USER_CRITICAL_IMPORTANCE:
336 case TIPC_USER_NAME_DISTRIBUTOR:
337 case TIPC_USER_CONN_MANAGER:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700338 print_payload(ndo, (const struct payload_tipc_pkthdr *)bp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700339 break;
JP Abgrall53f17a92014-02-12 14:02:41 -0800340
341 case TIPC_USER_LINK_CONFIG:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700342 print_link_conf(ndo, (const struct link_conf_tipc_pkthdr *)bp);
JP Abgrall53f17a92014-02-12 14:02:41 -0800343 break;
344
345 case TIPC_USER_BCAST_PROTOCOL:
346 case TIPC_USER_MSG_BUNDLER:
347 case TIPC_USER_LINK_PROTOCOL:
348 case TIPC_USER_CHANGEOVER_PROTOCOL:
349 case TIPC_USER_MSG_FRAGMENTER:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700350 print_internal(ndo, (const struct internal_tipc_pkthdr *)bp);
JP Abgrall53f17a92014-02-12 14:02:41 -0800351 break;
352
353 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800354}