]> The Tcpdump Group git mirrors - tcpdump/commitdiff
add basic support for the IEEE Link Discovery Protocol as per 802.1ab
authorhannes <hannes>
Fri, 3 Aug 2007 11:03:19 +0000 (11:03 +0000)
committerhannes <hannes>
Fri, 3 Aug 2007 11:03:19 +0000 (11:03 +0000)
FILES
Makefile.in
ethertype.h
interface.h
print-ether.c
print-lldp.c [new file with mode: 0644]
win32/prj/GNUmakefile
win32/prj/WinDump.dsp

diff --git a/FILES b/FILES
index f4e5e5b0160a5ae57f9e04d429904d4a8bf4d7e3..b79d1d636bcc2a2e890ebc45c89d1c49b5b140a6 100644 (file)
--- a/FILES
+++ b/FILES
@@ -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
index 5c73c0df04a6db5974b37be9621f6ff754e55690..6f06744ec4c9e0c6a023407c3d0fbf0f066ed37c 100644 (file)
@@ -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 \
index f73f7b0fab4d8579ba2e497c41684c7bd6818ef8..f358c4571c4d61a1c42462e788606fcfd3f6f2a6 100644 (file)
@@ -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)
  */
 
 /*
 #ifndef ETHERTYPE_JUMBO
 #define ETHERTYPE_JUMBO         0x8870
 #endif
+#ifndef ETHERTYPE_LLDP
+#define ETHERTYPE_LLDP          0x88cc
+#endif
 #ifndef ETHERTYPE_EAPOL
 #define ETHERTYPE_EAPOL        0x888e
 #endif
index ceb366e48cec142fe937b0df949d808e6e9d49cc..adc9b8b475afeb0eb6ae1642c48a5da2b085bb20 100644 (file)
@@ -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);
index e54c9d4eff37db54d39fc1d12b354d5a1b1fb8fe..08434b9ae87fa88ad5bb064a2b670f4a31ef5bc7 100644 (file)
@@ -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 (file)
index 0000000..0319f67
--- /dev/null
@@ -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 ([email protected])
+ */
+
+#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]");
+}
index 9d7060c2a4fac9b8932eb5a8d729b604f6c1b28d..d75063536120d1dafc2263cececc8f9c53a9d09d 100644 (file)
@@ -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 \
index 975d24e9b88c539e16f180eaabee5d1a06356f2f..a9d77268071e733d568c993b61342c35c35e6890 100644 (file)
@@ -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