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