freebsd-nq/print-dtp.c

119 lines
2.6 KiB
C
Raw Normal View History

2009-03-21 16:23:46 +00:00
/*
* Copyright (c) 1998-2007 The TCPDUMP project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code
* distributions retain the above copyright notice and this paragraph
* in its entirety, and (2) distributions including binary code include
* the above copyright notice and this paragraph in its entirety in
* the documentation or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND
* WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Dynamic Trunk Protocol (DTP)
*
* Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
*/
2015-01-06 19:03:11 +00:00
#define NETDISSECT_REWORKED
2009-03-21 16:23:46 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tcpdump-stdinc.h>
#include "interface.h"
#include "addrtoname.h"
2015-01-06 19:03:11 +00:00
#include "extract.h"
2009-03-21 16:23:46 +00:00
#define DTP_HEADER_LEN 1
#define DTP_DOMAIN_TLV 0x0001
#define DTP_STATUS_TLV 0x0002
#define DTP_DTP_TYPE_TLV 0x0003
#define DTP_NEIGHBOR_TLV 0x0004
2015-01-06 19:03:11 +00:00
static const struct tok dtp_tlv_values[] = {
2009-03-21 16:23:46 +00:00
{ DTP_DOMAIN_TLV, "Domain TLV"},
{ DTP_STATUS_TLV, "Status TLV"},
{ DTP_DTP_TYPE_TLV, "DTP type TLV"},
{ DTP_NEIGHBOR_TLV, "Neighbor TLV"},
{ 0, NULL}
};
void
2015-01-06 19:03:11 +00:00
dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
2009-03-21 16:23:46 +00:00
{
int type, len;
const u_char *tptr;
if (length < DTP_HEADER_LEN)
goto trunc;
2015-01-06 19:03:11 +00:00
tptr = pptr;
2009-03-21 16:23:46 +00:00
2015-01-06 19:03:11 +00:00
ND_TCHECK2(*tptr, DTP_HEADER_LEN);
2009-03-21 16:23:46 +00:00
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, "DTPv%u, length %u",
2009-03-21 16:23:46 +00:00
(*tptr),
2015-01-06 19:03:11 +00:00
length));
2009-03-21 16:23:46 +00:00
/*
* In non-verbose mode, just print version.
*/
2015-01-06 19:03:11 +00:00
if (ndo->ndo_vflag < 1) {
2009-03-21 16:23:46 +00:00
return;
}
tptr += DTP_HEADER_LEN;
while (tptr < (pptr+length)) {
2015-01-06 19:03:11 +00:00
ND_TCHECK2(*tptr, 4);
2009-03-21 16:23:46 +00:00
type = EXTRACT_16BITS(tptr);
2015-01-06 19:03:11 +00:00
len = EXTRACT_16BITS(tptr+2);
2009-03-21 16:23:46 +00:00
/* infinite loop check */
if (type == 0 || len == 0) {
return;
}
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
2009-03-21 16:23:46 +00:00
tok2str(dtp_tlv_values, "Unknown", type),
2015-01-06 19:03:11 +00:00
type, len));
2009-03-21 16:23:46 +00:00
switch (type) {
case DTP_DOMAIN_TLV:
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, ", %s", tptr+4));
2009-03-21 16:23:46 +00:00
break;
2015-01-06 19:03:11 +00:00
case DTP_STATUS_TLV:
2009-03-21 16:23:46 +00:00
case DTP_DTP_TYPE_TLV:
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, ", 0x%x", *(tptr+4)));
2009-03-21 16:23:46 +00:00
break;
case DTP_NEIGHBOR_TLV:
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, ", %s", etheraddr_string(ndo, tptr+4)));
2009-03-21 16:23:46 +00:00
break;
default:
break;
2015-01-06 19:03:11 +00:00
}
2009-03-21 16:23:46 +00:00
tptr += len;
}
return;
trunc:
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, "[|dtp]"));
2009-03-21 16:23:46 +00:00
}
/*
* Local Variables:
* c-style: whitesmith
* c-basic-offset: 4
* End:
*/