blob: fb802b58fd4dff387fd65434ade35a24eabd021d [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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 */
The Android Open Source Project2949f582009-03-03 19:30:46 -080018
Elliott Hughes892a68b2015-10-19 14:43:53 -070019#define NETDISSECT_REWORKED
The Android Open Source Project2949f582009-03-03 19:30:46 -080020#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <tcpdump-stdinc.h>
25
The Android Open Source Project2949f582009-03-03 19:30:46 -080026#include "interface.h"
27#include "addrtoname.h"
28#include "extract.h"
29
30#define MSDP_TYPE_MAX 7
31
32void
Elliott Hughes892a68b2015-10-19 14:43:53 -070033msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -080034{
35 unsigned int type, len;
36
Elliott Hughes892a68b2015-10-19 14:43:53 -070037 ND_TCHECK2(*sp, 3);
The Android Open Source Project2949f582009-03-03 19:30:46 -080038 /* See if we think we're at the beginning of a compound packet */
39 type = *sp;
40 len = EXTRACT_16BITS(sp + 1);
41 if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
42 goto trunc; /* not really truncated, but still not decodable */
Elliott Hughes892a68b2015-10-19 14:43:53 -070043 ND_PRINT((ndo, " msdp:"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080044 while (length > 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -070045 ND_TCHECK2(*sp, 3);
The Android Open Source Project2949f582009-03-03 19:30:46 -080046 type = *sp;
47 len = EXTRACT_16BITS(sp + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -070048 if (len > 1400 || ndo->ndo_vflag)
49 ND_PRINT((ndo, " [len %u]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -080050 if (len < 3)
51 goto trunc;
52 sp += 3;
53 length -= 3;
54 switch (type) {
55 case 1: /* IPv4 Source-Active */
56 case 3: /* IPv4 Source-Active Response */
57 if (type == 1)
Elliott Hughes892a68b2015-10-19 14:43:53 -070058 ND_PRINT((ndo, " SA"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080059 else
Elliott Hughes892a68b2015-10-19 14:43:53 -070060 ND_PRINT((ndo, " SA-Response"));
61 ND_TCHECK(*sp);
62 ND_PRINT((ndo, " %u entries", *sp));
The Android Open Source Project2949f582009-03-03 19:30:46 -080063 if ((u_int)((*sp * 12) + 8) < len) {
Elliott Hughes892a68b2015-10-19 14:43:53 -070064 ND_PRINT((ndo, " [w/data]"));
65 if (ndo->ndo_vflag > 1) {
66 ND_PRINT((ndo, " "));
67 ip_print(ndo, sp + *sp * 12 + 8 - 3,
The Android Open Source Project2949f582009-03-03 19:30:46 -080068 len - (*sp * 12 + 8));
69 }
70 }
71 break;
72 case 2:
Elliott Hughes892a68b2015-10-19 14:43:53 -070073 ND_PRINT((ndo, " SA-Request"));
74 ND_TCHECK2(*sp, 5);
75 ND_PRINT((ndo, " for %s", ipaddr_string(ndo, sp + 1)));
The Android Open Source Project2949f582009-03-03 19:30:46 -080076 break;
77 case 4:
Elliott Hughes892a68b2015-10-19 14:43:53 -070078 ND_PRINT((ndo, " Keepalive"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080079 if (len != 3)
Elliott Hughes892a68b2015-10-19 14:43:53 -070080 ND_PRINT((ndo, "[len=%d] ", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -080081 break;
82 case 5:
Elliott Hughes892a68b2015-10-19 14:43:53 -070083 ND_PRINT((ndo, " Notification"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080084 break;
85 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -070086 ND_PRINT((ndo, " [type=%d len=%d]", type, len));
The Android Open Source Project2949f582009-03-03 19:30:46 -080087 break;
88 }
89 sp += (len - 3);
90 length -= (len - 3);
91 }
92 return;
93trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -070094 ND_PRINT((ndo, " [|msdp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080095}
96
97/*
98 * Local Variables:
99 * c-style: whitesmith
100 * c-basic-offset: 8
101 * End:
102 */