xref: /freebsd/contrib/tcpdump/print-msdp.c (revision 87b759f0fa1f7554d50ce640c40138512bbded44)
1 /*
2  * Copyright (c) 2001 William C. Fenner.
3  *                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
7  * distributions retain the above copyright notice and this paragraph
8  * in its entirety, and (2) distributions including binary code include
9  * the above copyright notice and this paragraph in its entirety in
10  * the documentation or other materials provided with the distribution.
11  * The name of William C. Fenner may not be used to endorse or
12  * promote products derived from this software without specific prior
13  * written permission.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16  * FOR A PARTICULAR PURPOSE.
17  */
18 
19 /* \summary: Multicast Source Discovery Protocol (MSDP) printer */
20 
21 #include <config.h>
22 
23 #include "netdissect-stdinc.h"
24 
25 #include "netdissect.h"
26 #include "addrtoname.h"
27 #include "extract.h"
28 
29 #define MSDP_TYPE_MAX	7
30 
31 void
32 msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
33 {
34 	unsigned int type, len;
35 
36 	ndo->ndo_protocol = "msdp";
37 	ND_PRINT(": ");
38 	nd_print_protocol(ndo);
39 	/* See if we think we're at the beginning of a compound packet */
40 	type = GET_U_1(sp);
41 	len = GET_BE_U_2(sp + 1);
42 	if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
43 		goto trunc;	/* not really truncated, but still not decodable */
44 	while (length != 0) {
45 		type = GET_U_1(sp);
46 		len = GET_BE_U_2(sp + 1);
47 		if (len > 1400 || ndo->ndo_vflag)
48 			ND_PRINT(" [len %u]", len);
49 		if (len < 3)
50 			goto trunc;
51 		if (length < len)
52 			goto trunc;
53 		sp += 3;
54 		length -= 3;
55 		switch (type) {
56 		case 1:	/* IPv4 Source-Active */
57 		case 3: /* IPv4 Source-Active Response */
58 			if (type == 1)
59 				ND_PRINT(" SA");
60 			else
61 				ND_PRINT(" SA-Response");
62 			ND_PRINT(" %u entries", GET_U_1(sp));
63 			if ((u_int)((GET_U_1(sp) * 12) + 8) < len) {
64 				ND_PRINT(" [w/data]");
65 				if (ndo->ndo_vflag > 1) {
66 					ND_PRINT(" ");
67 					ip_print(ndo, sp +
68 						 GET_U_1(sp) * 12 + 8 - 3,
69 						 len - (GET_U_1(sp) * 12 + 8));
70 				}
71 			}
72 			break;
73 		case 2:
74 			ND_PRINT(" SA-Request");
75 			ND_PRINT(" for %s", GET_IPADDR_STRING(sp + 1));
76 			break;
77 		case 4:
78 			ND_PRINT(" Keepalive");
79 			if (len != 3)
80 				ND_PRINT("[len=%u] ", len);
81 			break;
82 		case 5:
83 			ND_PRINT(" Notification");
84 			break;
85 		default:
86 			ND_PRINT(" [type=%u len=%u]", type, len);
87 			break;
88 		}
89 		sp += (len - 3);
90 		length -= (len - 3);
91 	}
92 	return;
93 trunc:
94 	nd_print_trunc(ndo);
95 }
96