diff options
author | hannes <hannes> | 2007-08-03 11:03:19 +0000 |
---|---|---|
committer | hannes <hannes> | 2007-08-03 11:03:19 +0000 |
commit | bbb40509692dc2dc06665c909ee6cb1327a40e79 (patch) | |
tree | 9e85c254ce1647076abf77a7d4f3721312000f87 | |
parent | 74b6e507b01e759cb51f8fb70591249e6fa31cd7 (diff) | |
download | tcpdump-bbb40509692dc2dc06665c909ee6cb1327a40e79.tar.gz |
add basic support for the IEEE Link Discovery Protocol as per 802.1ab
-rw-r--r-- | FILES | 1 | ||||
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | ethertype.h | 5 | ||||
-rw-r--r-- | interface.h | 3 | ||||
-rw-r--r-- | print-ether.c | 7 | ||||
-rw-r--r-- | print-lldp.c | 138 | ||||
-rw-r--r-- | win32/prj/GNUmakefile | 1 | ||||
-rw-r--r-- | win32/prj/WinDump.dsp | 4 |
8 files changed, 158 insertions, 5 deletions
@@ -164,6 +164,7 @@ print-krb.c print-l2tp.c print-lane.c print-ldp.c +print-lldp.c print-llc.c print-lmp.c print-lspping.c diff --git a/Makefile.in b/Makefile.in index 5c73c0df..6f06744e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -17,7 +17,7 @@ # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # -# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.312 2007-07-24 16:07:29 hannes Exp $ (LBL) +# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.313 2007-08-03 11:03:19 hannes Exp $ (LBL) # # Various configurable paths (remember to edit Makefile.in, not Makefile) @@ -77,7 +77,7 @@ CSRC = addrtoname.c af.c checksum.c cpack.c gmpls.c oui.c gmt2local.c ipproto.c print-gre.c print-hsrp.c print-icmp.c print-igmp.c \ print-igrp.c print-ip.c print-ipcomp.c print-ipfc.c \ print-ipx.c print-isakmp.c print-isoclns.c print-juniper.c print-krb.c \ - print-l2tp.c print-lane.c print-ldp.c print-llc.c \ + print-l2tp.c print-lane.c print-ldp.c print-lldp.c print-llc.c \ print-lmp.c print-lspping.c print-lwapp.c \ print-lwres.c print-mobile.c print-mpcp.c print-mpls.c print-msdp.c \ print-nfs.c print-ntp.c print-null.c print-olsr.c print-ospf.c \ diff --git a/ethertype.h b/ethertype.h index f73f7b0f..f358c457 100644 --- a/ethertype.h +++ b/ethertype.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/ethertype.h,v 1.28 2007-07-23 09:01:09 hannes Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/ethertype.h,v 1.29 2007-08-03 11:03:19 hannes Exp $ (LBL) */ /* @@ -130,6 +130,9 @@ #ifndef ETHERTYPE_JUMBO #define ETHERTYPE_JUMBO 0x8870 #endif +#ifndef ETHERTYPE_LLDP +#define ETHERTYPE_LLDP 0x88cc +#endif #ifndef ETHERTYPE_EAPOL #define ETHERTYPE_EAPOL 0x888e #endif diff --git a/interface.h b/interface.h index ceb366e4..adc9b8b4 100644 --- a/interface.h +++ b/interface.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.276 2007-07-24 16:07:30 hannes Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.277 2007-08-03 11:03:19 hannes Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -242,6 +242,7 @@ extern void pimv1_print(const u_char *, u_int); extern void cisco_autorp_print(const u_char *, u_int); extern void rsvp_print(const u_char *, u_int); extern void ldp_print(const u_char *, u_int); +extern void lldp_print(const u_char *, u_int); extern void lmp_print(const u_char *, u_int); extern void lspping_print(const u_char *, u_int); extern void lwapp_control_print(const u_char *, u_int, int); diff --git a/print-ether.c b/print-ether.c index e54c9d4e..08434b9a 100644 --- a/print-ether.c +++ b/print-ether.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.104 2007-07-23 09:01:09 hannes Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.105 2007-08-03 11:03:19 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -76,6 +76,7 @@ const struct tok ethertype_values[] = { { ETHERTYPE_GRE_ISO, "GRE-OSI" }, { ETHERTYPE_CFM_OLD, "CFM (old)" }, { ETHERTYPE_CFM, "CFM" }, + { ETHERTYPE_LLDP, "LLDP" }, { 0, NULL} }; @@ -314,6 +315,10 @@ ether_encap_print(u_short ether_type, const u_char *p, cfm_print(p, length); return (1); + case ETHERTYPE_LLDP: + lldp_print(p, length); + return (1); + case ETHERTYPE_LOOPBACK: return (1); diff --git a/print-lldp.c b/print-lldp.c new file mode 100644 index 00000000..0319f671 --- /dev/null +++ b/print-lldp.c @@ -0,0 +1,138 @@ +/* + * 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. + * + * support for the IEEE Link Discovery Protocol as per 802.1ab + * + * Original code by Hannes Gredler (hannes@juniper.net) + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-lldp.c,v 1.1 2007-08-03 11:03:19 hannes Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <tcpdump-stdinc.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "interface.h" +#include "extract.h" +#include "addrtoname.h" + +#define LLDP_EXTRACT_TYPE(x) (((x)&0xfe00)>>9) +#define LLDP_EXTRACT_LEN(x) ((x)&0x01ff) + +#define LLDP_END_TLV 0 +#define LLDP_CHASSIS_ID_TLV 1 +#define LLDP_PORT_ID_TLV 2 +#define LLDP_TTL_TLV 3 +#define LLDP_PORT_DESCR_TLV 4 +#define LLDP_SYSTEM_NAME_TLV 5 +#define LLDP_SYSTEM_DESCR_TLV 6 +#define LLDP_SYSTEM_CAP_TLV 7 +#define LLDP_MGMT_ADDR_TLV 8 +#define LLDP_PRIVATE_TLV 127 + + +static const struct tok lldp_tlv_values[] = { + { LLDP_END_TLV, "End" }, + { LLDP_CHASSIS_ID_TLV, "Chassis ID" }, + { LLDP_PORT_ID_TLV, "Port ID" }, + { LLDP_TTL_TLV, "Time to Live" }, + { LLDP_PORT_DESCR_TLV, "Port Description" }, + { LLDP_SYSTEM_NAME_TLV, "System Name" }, + { LLDP_SYSTEM_DESCR_TLV, "System Description" }, + { LLDP_SYSTEM_CAP_TLV, "System Capabilities" }, + { LLDP_MGMT_ADDR_TLV, "Management Address" }, + { LLDP_PRIVATE_TLV, "Organization specific" }, + { 0, NULL} +}; + +void lldp_print(register const u_char *pptr, register u_int len) { + + u_int16_t tlv; + u_int tlen, hexdump, tlv_type, tlv_len; + const u_char *tptr; + + tptr = pptr; + tlen = len; + + printf("LLDP, length %u", len); + + if (!vflag) { + return; + } + + while (tlen >= sizeof(tlv)) { + + TCHECK2(*tptr, sizeof(tlv)); + + tlv = EXTRACT_16BITS(tptr); + + tlv_type = LLDP_EXTRACT_TYPE(tlv); + tlv_len = LLDP_EXTRACT_LEN(tlv); + hexdump = FALSE; + + tlen -= sizeof(tlv); + tptr += sizeof(tlv); + + printf("\n\t%s TLV (%u), length %u", + tok2str(lldp_tlv_values, "Unknown", tlv_type), + tlv_type, tlv_len); + + /* infinite loop check */ + if (!tlv_type || !tlv_len) { + break; + } + + TCHECK2(*tptr, tlv_len); + + switch (tlv_type) { + case LLDP_TTL_TLV: + printf(", TTL %us", EXTRACT_16BITS(tptr)); + break; + + case LLDP_SYSTEM_NAME_TLV: + case LLDP_PORT_DESCR_TLV: + printf(", "); + safeputs((const char *)tptr, tlv_len); + break; + + case LLDP_SYSTEM_DESCR_TLV: + printf("\n\t "); + safeputs((const char *)tptr, tlv_len); + break; + + default: + hexdump = TRUE; + } + + /* do we also want to see a hex dump ? */ + if (vflag > 1 || hexdump) { + print_unknown_data(tptr,"\n\t ", tlv_len); + } + + tlen -= tlv_len; + tptr += tlv_len; + } + return; + trunc: + printf("\n\t[|LLDP]"); +} diff --git a/win32/prj/GNUmakefile b/win32/prj/GNUmakefile index 9d7060c2..d7506353 100644 --- a/win32/prj/GNUmakefile +++ b/win32/prj/GNUmakefile @@ -91,6 +91,7 @@ OBJS = \ ../../print-l2tp.o \ ../../print-lane.o \ ../../print-ldp.o \ + ../../print-lldp.o \ ../../print-llc.o \ ../../print-lwapp.o \ ../../print-lwres.o \ diff --git a/win32/prj/WinDump.dsp b/win32/prj/WinDump.dsp index 975d24e9..a9d77268 100644 --- a/win32/prj/WinDump.dsp +++ b/win32/prj/WinDump.dsp @@ -369,6 +369,10 @@ SOURCE="..\..\print-ldp.c" # End Source File # Begin Source File +SOURCE="..\..\print-lldp.c" +# End Source File +# Begin Source File + SOURCE="..\..\print-llc.c" # End Source File # Begin Source File |