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