xref: /netbsd-src/external/bsd/tcpdump/dist/print-msdp.c (revision cc576e1d8e4f4078fd4e81238abca9fca216f6ec)
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 #include <sys/cdefs.h>
20 #ifndef lint
21 __RCSID("$NetBSD: print-msdp.c,v 1.5 2017/01/24 23:29:14 christos Exp $");
22 #endif
23 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 #include <netdissect-stdinc.h>
29 
30 #include "netdissect.h"
31 #include "addrtoname.h"
32 #include "extract.h"
33 
34 #define MSDP_TYPE_MAX	7
35 
36 void
37 msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
38 {
39 	unsigned int type, len;
40 
41 	ND_TCHECK2(*sp, 3);
42 	/* See if we think we're at the beginning of a compound packet */
43 	type = *sp;
44 	len = EXTRACT_16BITS(sp + 1);
45 	if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
46 		goto trunc;	/* not really truncated, but still not decodable */
47 	ND_PRINT((ndo, " msdp:"));
48 	while (length > 0) {
49 		ND_TCHECK2(*sp, 3);
50 		type = *sp;
51 		len = EXTRACT_16BITS(sp + 1);
52 		if (len > 1400 || ndo->ndo_vflag)
53 			ND_PRINT((ndo, " [len %u]", len));
54 		if (len < 3)
55 			goto trunc;
56 		sp += 3;
57 		length -= 3;
58 		switch (type) {
59 		case 1:	/* IPv4 Source-Active */
60 		case 3: /* IPv4 Source-Active Response */
61 			if (type == 1)
62 				ND_PRINT((ndo, " SA"));
63 			else
64 				ND_PRINT((ndo, " SA-Response"));
65 			ND_TCHECK(*sp);
66 			ND_PRINT((ndo, " %u entries", *sp));
67 			if ((u_int)((*sp * 12) + 8) < len) {
68 				ND_PRINT((ndo, " [w/data]"));
69 				if (ndo->ndo_vflag > 1) {
70 					ND_PRINT((ndo, " "));
71 					ip_print(ndo, sp + *sp * 12 + 8 - 3,
72 					         len - (*sp * 12 + 8));
73 				}
74 			}
75 			break;
76 		case 2:
77 			ND_PRINT((ndo, " SA-Request"));
78 			ND_TCHECK2(*sp, 5);
79 			ND_PRINT((ndo, " for %s", ipaddr_string(ndo, sp + 1)));
80 			break;
81 		case 4:
82 			ND_PRINT((ndo, " Keepalive"));
83 			if (len != 3)
84 				ND_PRINT((ndo, "[len=%d] ", len));
85 			break;
86 		case 5:
87 			ND_PRINT((ndo, " Notification"));
88 			break;
89 		default:
90 			ND_PRINT((ndo, " [type=%d len=%d]", type, len));
91 			break;
92 		}
93 		sp += (len - 3);
94 		length -= (len - 3);
95 	}
96 	return;
97 trunc:
98 	ND_PRINT((ndo, " [|msdp]"));
99 }
100 
101 /*
102  * Local Variables:
103  * c-style: whitesmith
104  * c-basic-offset: 8
105  * End:
106  */
107