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