blob: 1d8c66a0004634e06206350eaad49a462ba222c9 [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/*
2 * Copyright (c) 1998-2007 The TCPDUMP project
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
JP Abgrall53f17a92014-02-12 14:02:41 -080015 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
16 */
17
Elliott Hughese2e3bd12017-05-15 10:59:29 -070018/* \summary: Dynamic Trunking Protocol (DTP) printer */
19
JP Abgrall53f17a92014-02-12 14:02:41 -080020#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
Elliott Hughese2e3bd12017-05-15 10:59:29 -070024#include <netdissect-stdinc.h>
JP Abgrall53f17a92014-02-12 14:02:41 -080025
Elliott Hughese2e3bd12017-05-15 10:59:29 -070026#include "netdissect.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080027#include "addrtoname.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070028#include "extract.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080029
Elliott Hughese2e3bd12017-05-15 10:59:29 -070030static const char tstr[] = " [|dtp]";
31
JP Abgrall53f17a92014-02-12 14:02:41 -080032#define DTP_HEADER_LEN 1
33#define DTP_DOMAIN_TLV 0x0001
34#define DTP_STATUS_TLV 0x0002
35#define DTP_DTP_TYPE_TLV 0x0003
36#define DTP_NEIGHBOR_TLV 0x0004
37
38static const struct tok dtp_tlv_values[] = {
39 { DTP_DOMAIN_TLV, "Domain TLV"},
40 { DTP_STATUS_TLV, "Status TLV"},
41 { DTP_DTP_TYPE_TLV, "DTP type TLV"},
42 { DTP_NEIGHBOR_TLV, "Neighbor TLV"},
43 { 0, NULL}
44};
45
46void
Elliott Hughes892a68b2015-10-19 14:43:53 -070047dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
JP Abgrall53f17a92014-02-12 14:02:41 -080048{
49 int type, len;
50 const u_char *tptr;
51
52 if (length < DTP_HEADER_LEN)
53 goto trunc;
54
Elliott Hughes892a68b2015-10-19 14:43:53 -070055 tptr = pptr;
JP Abgrall53f17a92014-02-12 14:02:41 -080056
Elliott Hughes892a68b2015-10-19 14:43:53 -070057 ND_TCHECK2(*tptr, DTP_HEADER_LEN);
JP Abgrall53f17a92014-02-12 14:02:41 -080058
Elliott Hughes892a68b2015-10-19 14:43:53 -070059 ND_PRINT((ndo, "DTPv%u, length %u",
JP Abgrall53f17a92014-02-12 14:02:41 -080060 (*tptr),
Elliott Hughes892a68b2015-10-19 14:43:53 -070061 length));
JP Abgrall53f17a92014-02-12 14:02:41 -080062
63 /*
64 * In non-verbose mode, just print version.
65 */
Elliott Hughes892a68b2015-10-19 14:43:53 -070066 if (ndo->ndo_vflag < 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -080067 return;
68 }
69
70 tptr += DTP_HEADER_LEN;
71
72 while (tptr < (pptr+length)) {
73
Elliott Hughes892a68b2015-10-19 14:43:53 -070074 ND_TCHECK2(*tptr, 4);
JP Abgrall53f17a92014-02-12 14:02:41 -080075 type = EXTRACT_16BITS(tptr);
Elliott Hughes892a68b2015-10-19 14:43:53 -070076 len = EXTRACT_16BITS(tptr+2);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070077 /* XXX: should not be but sometimes it is, see the test captures */
78 if (type == 0)
JP Abgrall53f17a92014-02-12 14:02:41 -080079 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -070080 ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
JP Abgrall53f17a92014-02-12 14:02:41 -080081 tok2str(dtp_tlv_values, "Unknown", type),
Elliott Hughes892a68b2015-10-19 14:43:53 -070082 type, len));
JP Abgrall53f17a92014-02-12 14:02:41 -080083
Elliott Hughese2e3bd12017-05-15 10:59:29 -070084 /* infinite loop check */
85 if (len < 4)
86 goto invalid;
87 ND_TCHECK2(*tptr, len);
88
JP Abgrall53f17a92014-02-12 14:02:41 -080089 switch (type) {
90 case DTP_DOMAIN_TLV:
Elliott Hughese2e3bd12017-05-15 10:59:29 -070091 ND_PRINT((ndo, ", "));
92 fn_printzp(ndo, tptr+4, len-4, pptr+length);
JP Abgrall53f17a92014-02-12 14:02:41 -080093 break;
94
Elliott Hughes892a68b2015-10-19 14:43:53 -070095 case DTP_STATUS_TLV:
JP Abgrall53f17a92014-02-12 14:02:41 -080096 case DTP_DTP_TYPE_TLV:
Elliott Hughese2e3bd12017-05-15 10:59:29 -070097 if (len < 5)
98 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -070099 ND_PRINT((ndo, ", 0x%x", *(tptr+4)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800100 break;
101
102 case DTP_NEIGHBOR_TLV:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700103 if (len < 10)
104 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700105 ND_PRINT((ndo, ", %s", etheraddr_string(ndo, tptr+4)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800106 break;
107
108 default:
109 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700110 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800111 tptr += len;
112 }
113
114 return;
115
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700116 invalid:
117 ND_PRINT((ndo, "%s", istr));
118 return;
JP Abgrall53f17a92014-02-12 14:02:41 -0800119 trunc:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700120 ND_PRINT((ndo, "%s", tstr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800121}
122
123/*
124 * Local Variables:
125 * c-style: whitesmith
126 * c-basic-offset: 4
127 * End:
128 */