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
193340d773SGleb Smirnoff /* \summary: Multicast Source Discovery Protocol (MSDP) printer */
203340d773SGleb Smirnoff
21*ee67461eSJoseph Mingrone #include <config.h>
22a90e161bSBill Fenner
23*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
245b0fe478SBruce M Simpson
253340d773SGleb Smirnoff #include "netdissect.h"
26a90e161bSBill Fenner #include "addrtoname.h"
27a90e161bSBill Fenner #include "extract.h"
28a90e161bSBill Fenner
29a90e161bSBill Fenner #define MSDP_TYPE_MAX 7
30a90e161bSBill Fenner
31a90e161bSBill Fenner void
msdp_print(netdissect_options * ndo,const u_char * sp,u_int length)323c602fabSXin LI msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
33a90e161bSBill Fenner {
34a90e161bSBill Fenner unsigned int type, len;
35a90e161bSBill Fenner
36*ee67461eSJoseph Mingrone ndo->ndo_protocol = "msdp";
37*ee67461eSJoseph Mingrone ND_PRINT(": ");
38*ee67461eSJoseph Mingrone nd_print_protocol(ndo);
39a90e161bSBill Fenner /* See if we think we're at the beginning of a compound packet */
40*ee67461eSJoseph Mingrone type = GET_U_1(sp);
41*ee67461eSJoseph Mingrone len = GET_BE_U_2(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 */
44*ee67461eSJoseph Mingrone while (length != 0) {
45*ee67461eSJoseph Mingrone type = GET_U_1(sp);
46*ee67461eSJoseph Mingrone len = GET_BE_U_2(sp + 1);
473c602fabSXin LI if (len > 1400 || ndo->ndo_vflag)
48*ee67461eSJoseph Mingrone ND_PRINT(" [len %u]", len);
49a90e161bSBill Fenner if (len < 3)
50a90e161bSBill Fenner goto trunc;
51*ee67461eSJoseph Mingrone if (length < len)
52*ee67461eSJoseph Mingrone 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)
59*ee67461eSJoseph Mingrone ND_PRINT(" SA");
60a90e161bSBill Fenner else
61*ee67461eSJoseph Mingrone ND_PRINT(" SA-Response");
62*ee67461eSJoseph Mingrone ND_PRINT(" %u entries", GET_U_1(sp));
63*ee67461eSJoseph Mingrone if ((u_int)((GET_U_1(sp) * 12) + 8) < len) {
64*ee67461eSJoseph Mingrone ND_PRINT(" [w/data]");
653c602fabSXin LI if (ndo->ndo_vflag > 1) {
66*ee67461eSJoseph Mingrone ND_PRINT(" ");
67*ee67461eSJoseph Mingrone ip_print(ndo, sp +
68*ee67461eSJoseph Mingrone GET_U_1(sp) * 12 + 8 - 3,
69*ee67461eSJoseph Mingrone len - (GET_U_1(sp) * 12 + 8));
70a90e161bSBill Fenner }
71a90e161bSBill Fenner }
72a90e161bSBill Fenner break;
73a90e161bSBill Fenner case 2:
74*ee67461eSJoseph Mingrone ND_PRINT(" SA-Request");
75*ee67461eSJoseph Mingrone ND_PRINT(" for %s", GET_IPADDR_STRING(sp + 1));
76a90e161bSBill Fenner break;
77a90e161bSBill Fenner case 4:
78*ee67461eSJoseph Mingrone ND_PRINT(" Keepalive");
79a90e161bSBill Fenner if (len != 3)
80*ee67461eSJoseph Mingrone ND_PRINT("[len=%u] ", len);
81a90e161bSBill Fenner break;
82a90e161bSBill Fenner case 5:
83*ee67461eSJoseph Mingrone ND_PRINT(" Notification");
84a90e161bSBill Fenner break;
85a90e161bSBill Fenner default:
86*ee67461eSJoseph Mingrone ND_PRINT(" [type=%u len=%u]", type, len);
87a90e161bSBill Fenner break;
88a90e161bSBill Fenner }
89a90e161bSBill Fenner sp += (len - 3);
90a90e161bSBill Fenner length -= (len - 3);
91a90e161bSBill Fenner }
92a90e161bSBill Fenner return;
93a90e161bSBill Fenner trunc:
94*ee67461eSJoseph Mingrone nd_print_trunc(ndo);
95a90e161bSBill Fenner }
96