xref: /freebsd/contrib/tcpdump/print-msdp.c (revision 3340d77368116708ab5b5b95acf6c9c710528300)
1a90e161bSBill Fenner /*
2a90e161bSBill Fenner  * Copyright (c) 2001 William C. Fenner.
3a90e161bSBill Fenner  *                All rights reserved.
4a90e161bSBill Fenner  *
5a90e161bSBill Fenner  * Redistribution and use in source and binary forms, with or without
6a90e161bSBill Fenner  * modification, are permitted provided that: (1) source code
7a90e161bSBill Fenner  * distributions retain the above copyright notice and this paragraph
8a90e161bSBill Fenner  * in its entirety, and (2) distributions including binary code include
9a90e161bSBill Fenner  * the above copyright notice and this paragraph in its entirety in
10a90e161bSBill Fenner  * the documentation or other materials provided with the distribution.
11a90e161bSBill Fenner  * The name of William C. Fenner may not be used to endorse or
12a90e161bSBill Fenner  * promote products derived from this software without specific prior
13a90e161bSBill Fenner  * written permission.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14a90e161bSBill Fenner  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15a90e161bSBill Fenner  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16a90e161bSBill Fenner  * FOR A PARTICULAR PURPOSE.
17a90e161bSBill Fenner  */
18a90e161bSBill Fenner 
19*3340d773SGleb Smirnoff /* \summary: Multicast Source Discovery Protocol (MSDP) printer */
20*3340d773SGleb Smirnoff 
21a90e161bSBill Fenner #ifdef HAVE_CONFIG_H
22a90e161bSBill Fenner #include "config.h"
23a90e161bSBill Fenner #endif
24a90e161bSBill Fenner 
25*3340d773SGleb Smirnoff #include <netdissect-stdinc.h>
265b0fe478SBruce M Simpson 
27*3340d773SGleb Smirnoff #include "netdissect.h"
28a90e161bSBill Fenner #include "addrtoname.h"
29a90e161bSBill Fenner #include "extract.h"
30a90e161bSBill Fenner 
31a90e161bSBill Fenner #define MSDP_TYPE_MAX	7
32a90e161bSBill Fenner 
33a90e161bSBill Fenner void
343c602fabSXin LI msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
35a90e161bSBill Fenner {
36a90e161bSBill Fenner 	unsigned int type, len;
37a90e161bSBill Fenner 
383c602fabSXin LI 	ND_TCHECK2(*sp, 3);
39a90e161bSBill Fenner 	/* See if we think we're at the beginning of a compound packet */
40a90e161bSBill Fenner 	type = *sp;
41a90e161bSBill Fenner 	len = EXTRACT_16BITS(sp + 1);
42a90e161bSBill Fenner 	if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
43a90e161bSBill Fenner 		goto trunc;	/* not really truncated, but still not decodable */
443c602fabSXin LI 	ND_PRINT((ndo, " msdp:"));
45a90e161bSBill Fenner 	while (length > 0) {
463c602fabSXin LI 		ND_TCHECK2(*sp, 3);
47a90e161bSBill Fenner 		type = *sp;
48a90e161bSBill Fenner 		len = EXTRACT_16BITS(sp + 1);
493c602fabSXin LI 		if (len > 1400 || ndo->ndo_vflag)
503c602fabSXin LI 			ND_PRINT((ndo, " [len %u]", len));
51a90e161bSBill Fenner 		if (len < 3)
52a90e161bSBill Fenner 			goto trunc;
53a90e161bSBill Fenner 		sp += 3;
54a90e161bSBill Fenner 		length -= 3;
55a90e161bSBill Fenner 		switch (type) {
56a90e161bSBill Fenner 		case 1:	/* IPv4 Source-Active */
57a90e161bSBill Fenner 		case 3: /* IPv4 Source-Active Response */
58a90e161bSBill Fenner 			if (type == 1)
593c602fabSXin LI 				ND_PRINT((ndo, " SA"));
60a90e161bSBill Fenner 			else
613c602fabSXin LI 				ND_PRINT((ndo, " SA-Response"));
623c602fabSXin LI 			ND_TCHECK(*sp);
633c602fabSXin LI 			ND_PRINT((ndo, " %u entries", *sp));
645b0fe478SBruce M Simpson 			if ((u_int)((*sp * 12) + 8) < len) {
653c602fabSXin LI 				ND_PRINT((ndo, " [w/data]"));
663c602fabSXin LI 				if (ndo->ndo_vflag > 1) {
673c602fabSXin LI 					ND_PRINT((ndo, " "));
683c602fabSXin LI 					ip_print(ndo, sp + *sp * 12 + 8 - 3,
69a90e161bSBill Fenner 					         len - (*sp * 12 + 8));
70a90e161bSBill Fenner 				}
71a90e161bSBill Fenner 			}
72a90e161bSBill Fenner 			break;
73a90e161bSBill Fenner 		case 2:
743c602fabSXin LI 			ND_PRINT((ndo, " SA-Request"));
753c602fabSXin LI 			ND_TCHECK2(*sp, 5);
763c602fabSXin LI 			ND_PRINT((ndo, " for %s", ipaddr_string(ndo, sp + 1)));
77a90e161bSBill Fenner 			break;
78a90e161bSBill Fenner 		case 4:
793c602fabSXin LI 			ND_PRINT((ndo, " Keepalive"));
80a90e161bSBill Fenner 			if (len != 3)
813c602fabSXin LI 				ND_PRINT((ndo, "[len=%d] ", len));
82a90e161bSBill Fenner 			break;
83a90e161bSBill Fenner 		case 5:
843c602fabSXin LI 			ND_PRINT((ndo, " Notification"));
85a90e161bSBill Fenner 			break;
86a90e161bSBill Fenner 		default:
873c602fabSXin LI 			ND_PRINT((ndo, " [type=%d len=%d]", type, len));
88a90e161bSBill Fenner 			break;
89a90e161bSBill Fenner 		}
90a90e161bSBill Fenner 		sp += (len - 3);
91a90e161bSBill Fenner 		length -= (len - 3);
92a90e161bSBill Fenner 	}
93a90e161bSBill Fenner 	return;
94a90e161bSBill Fenner trunc:
953c602fabSXin LI 	ND_PRINT((ndo, " [|msdp]"));
96a90e161bSBill Fenner }
971de50e9fSSam Leffler 
981de50e9fSSam Leffler /*
991de50e9fSSam Leffler  * Local Variables:
1001de50e9fSSam Leffler  * c-style: whitesmith
1011de50e9fSSam Leffler  * c-basic-offset: 8
1021de50e9fSSam Leffler  * End:
1031de50e9fSSam Leffler  */
104