]> The Tcpdump Group git mirrors - tcpdump/commitdiff
support for bi-directional fault detection (BFD) Control packets
authorhannes <hannes>
Mon, 27 Oct 2003 10:13:44 +0000 (10:13 +0000)
committerhannes <hannes>
Mon, 27 Oct 2003 10:13:44 +0000 (10:13 +0000)
  as per draft-katz-ward-bfd-01.txt

FILES
Makefile.in
interface.h
print-bfd.c [new file with mode: 0644]
print-udp.c

diff --git a/FILES b/FILES
index 8d1ac7d8130b79d316f3e699640bad840dd38cf7..1a1ee3361651edaafd62ae709432bec4af7e19fa 100644 (file)
--- a/FILES
+++ b/FILES
@@ -99,6 +99,7 @@ print-ascii.c
 print-atalk.c
 print-atm.c
 print-beep.c
+print-bfd.c
 print-bgp.c
 print-bootp.c
 print-cdp.c
index f99cc1997c38e481929816c836c581078911641f..1a582d5d3a57d8e6690b33504c17cd64ba2b908a 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.275 2003-08-06 06:49:39 guy Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.276 2003-10-27 10:13:45 hannes Exp $ (LBL)
 
 #
 # Various configurable paths (remember to edit Makefile.in, not Makefile)
@@ -68,7 +68,7 @@ INSTALL_DATA = @INSTALL_DATA@
 CSRC = addrtoname.c gmpls.c gmt2local.c machdep.c parsenfsfh.c \
        print-802_11.c print-ah.c print-arcnet.c print-aodv.c \
        print-arp.c print-ascii.c print-atalk.c print-atm.c \
-       print-beep.c print-bgp.c print-bootp.c print-cdp.c \
+       print-beep.c print-bfd.c print-bgp.c print-bootp.c print-cdp.c \
        print-chdlc.c print-cip.c print-cnfp.c print-decnet.c \
        print-domain.c print-dvmrp.c print-enc.c print-egp.c \
        print-esp.c print-ether.c print-fddi.c print-fr.c \
index 85bdb9a736ac23a38021b2fe56bf790ec9c671f7..744b89ddd647b1e26a92932c2ae04b4347a3162f 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.215 2003-09-12 22:05:56 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.216 2003-10-27 10:13:45 hannes Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -307,6 +307,7 @@ extern void mpls_print(const u_char *, u_int);
 extern void mpls_lsp_ping_print(const u_char *, u_int);
 extern void zephyr_print(const u_char *, int);
 extern void hsrp_print(const u_char *, u_int);
+extern void bfd_print(const u_char *, u_int, u_int);
 
 #ifdef INET6
 extern void ip6_print(const u_char *, u_int);
diff --git a/print-bfd.c b/print-bfd.c
new file mode 100644 (file)
index 0000000..9121ebb
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ *
+ * Original code by Hannes Gredler ([email protected])
+ */
+
+#ifndef lint
+static const char rcsid[] =
+    "@(#) $Header: /tcpdump/master/tcpdump/print-bfd.c,v 1.1 2003-10-27 10:13:44 hannes Exp $";
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <tcpdump-stdinc.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "interface.h"
+#include "extract.h"
+#include "addrtoname.h"
+
+/*
+ * Control packet, draft-katz-ward-bfd-01.txt
+ *
+ *     0                   1                   2                   3
+ *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |Vers |  Diag   |H|D|P|F| Rsvd  |  Detect Mult  |    Length     |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |                       My Discriminator                        |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |                      Your Discriminator                       |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |                    Desired Min TX Interval                    |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |                   Required Min RX Interval                    |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |                 Required Min Echo RX Interval                 |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+struct bfd_header_t {
+    u_int8_t version_diag;
+    u_int8_t flags;
+    u_int8_t detect_time_multiplier;
+    u_int8_t length;
+    u_int8_t my_discriminator[4];
+    u_int8_t your_discriminator[4];
+    u_int8_t desired_min_tx_interval[4];
+    u_int8_t required_min_rx_interval[4];
+    u_int8_t required_min_echo_interval[4];
+};
+
+#define        BFD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
+#define        BFD_EXTRACT_DIAG(x)     ((x)&0x1f)
+
+static const struct tok bfd_port_values[] = {
+    { 3784, "Control" },
+    { 3785, "Echo" },
+    { 0, NULL }
+};
+
+
+static const struct tok bfd_diag_values[] = {
+    { 0, "No Diagnostic" },
+    { 1, "Control Detection Time Expired" },
+    { 2, "Echo Function Failed" },
+    { 3, "Neighbor Signaled Session Down" },
+    { 4, "Forwarding Plane Reset" },
+    { 5, "Path Down" },
+    { 6, "Concatenated Path Down" },
+    { 7, "Administratively Down" },
+    { 0, NULL }
+};
+
+static const struct tok bfd_flag_values[] = {
+    { 0x80,    "I Hear You" },
+    { 0x40,    "Demand" },
+    { 0x20,    "Poll" },
+    { 0x10,    "Final" },
+    { 0x08,    "Reserved" },
+    { 0x04,    "Reserved" },
+    { 0x02,    "Reserved" },
+    { 0x01,    "Reserved" },
+    { 0, NULL }
+};
+
+void
+bfd_print(register const u_char *pptr, register u_int len, register u_int port)
+{
+        const struct bfd_header_t *bfd_header;
+
+        bfd_header = (const struct bfd_header_t *)pptr;
+        TCHECK(*bfd_header);
+
+        printf("BFDv%u, %s, Flags: [%s], length: %u",
+               BFD_EXTRACT_VERSION(bfd_header->version_diag),
+               tok2str(bfd_port_values, "unknown (%u)", port),
+               bittok2str(bfd_flag_values, "none", bfd_header->flags),
+               len);
+
+        if (vflag >= 1) {
+            printf("\n\tDiagnostic: %s (0x%02x), Detection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
+                   tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
+                   BFD_EXTRACT_DIAG(bfd_header->version_diag),
+                   bfd_header->detect_time_multiplier,
+                   bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
+                   bfd_header->length);
+
+
+            printf("\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator));
+            printf(", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator));
+            printf("\n\t  Desired min Tx Interval:    %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000);
+            printf("\n\t  Required min Rx Interval:   %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000);
+            printf("\n\t  Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000);
+        }
+
+        return;
+
+trunc:
+        printf("[|BFD]");
+}
index e289be615e008ab40f0ce3f125e0db08dda3b5e5..dafc2b226b9a0e94b00a9ef6987cb0bbfe772fed 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.121 2003-09-12 22:05:57 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.122 2003-10-27 10:13:44 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -393,6 +393,8 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
 #define ZEPHYR_SRV_PORT                2103
 #define ZEPHYR_CLT_PORT                2104
 #define MPLS_LSP_PING_PORT      3503 /* draft-ietf-mpls-lsp-ping-02.txt */
+#define BFD_CONTROL_PORT        3784 /* draft-katz-ward-bfd-v4v6-1hop-00.txt */
+#define BFD_ECHO_PORT           3785 /* draft-katz-ward-bfd-v4v6-1hop-00.txt */
 
 #ifdef INET6
 #define RIPNG_PORT 521         /*XXX*/
@@ -714,10 +716,13 @@ udp_print(register const u_char *bp, u_int length,
                        ldp_print((const u_char *)(up + 1), length);
                 else if (ISPORT(MPLS_LSP_PING_PORT))
                        mpls_lsp_ping_print((const u_char *)(up + 1), length);
+               else if (dport == BFD_CONTROL_PORT ||
+                        dport == BFD_ECHO_PORT )
+                       bfd_print((const u_char *)(up+1), length, dport);
                else
-                       (void)printf("udp %u",
+                       (void)printf("UDP, length: %u",
                            (u_int32_t)(ulen - sizeof(*up)));
 #undef ISPORT
        } else
-               (void)printf("udp %u", (u_int32_t)(ulen - sizeof(*up)));
+               (void)printf("UDP, length: %u", (u_int32_t)(ulen - sizeof(*up)));
 }