2003-10-27 18:13:44 +08:00
|
|
|
/*
|
|
|
|
* 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 (hannes@juniper.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <tcpdump-stdinc.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-03-11 20:08:24 +08:00
|
|
|
#include "netdissect.h"
|
2003-10-27 18:13:44 +08:00
|
|
|
#include "extract.h"
|
|
|
|
|
2003-10-28 06:44:37 +08:00
|
|
|
#include "udp.h"
|
|
|
|
|
2003-10-27 18:13:44 +08:00
|
|
|
/*
|
2005-04-28 07:00:53 +08:00
|
|
|
* Control packet, BFDv0, draft-katz-ward-bfd-01.txt
|
2003-10-27 18:13:44 +08:00
|
|
|
*
|
|
|
|
* 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 |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*/
|
|
|
|
|
2014-01-02 10:27:54 +08:00
|
|
|
/*
|
2005-04-28 07:00:53 +08:00
|
|
|
* Control packet, BFDv1, draft-ietf-bfd-base-02.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 |Sta|P|F|C|A|D|R| Detect Mult | Length |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | My Discriminator |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Your Discriminator |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Desired Min TX Interval |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Required Min RX Interval |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Required Min Echo RX Interval |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*/
|
|
|
|
|
2003-10-27 18:13:44 +08:00
|
|
|
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];
|
|
|
|
};
|
|
|
|
|
2005-04-28 07:00:53 +08:00
|
|
|
/*
|
|
|
|
* An optional Authentication Header may be present
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Auth Type | Auth Len | Authentication Data... |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct bfd_auth_header_t {
|
|
|
|
u_int8_t auth_type;
|
|
|
|
u_int8_t auth_len;
|
|
|
|
u_int8_t auth_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tok bfd_v1_authentication_values[] = {
|
|
|
|
{ 0, "Reserved" },
|
|
|
|
{ 1, "Simple Password" },
|
|
|
|
{ 2, "Keyed MD5" },
|
|
|
|
{ 3, "Meticulous Keyed MD5" },
|
|
|
|
{ 4, "Keyed SHA1" },
|
|
|
|
{ 5, "Meticulous Keyed SHA1" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2003-10-27 18:13:44 +08:00
|
|
|
#define BFD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
|
|
|
|
#define BFD_EXTRACT_DIAG(x) ((x)&0x1f)
|
|
|
|
|
|
|
|
static const struct tok bfd_port_values[] = {
|
2003-10-28 06:44:37 +08:00
|
|
|
{ BFD_CONTROL_PORT, "Control" },
|
|
|
|
{ BFD_ECHO_PORT, "Echo" },
|
2003-10-27 18:13:44 +08:00
|
|
|
{ 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" },
|
2005-04-28 07:00:53 +08:00
|
|
|
{ 8, "Reverse Concatenated Path Down" },
|
2003-10-27 18:13:44 +08:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2005-04-28 07:00:53 +08:00
|
|
|
static const struct tok bfd_v0_flag_values[] = {
|
2003-10-27 18:13:44 +08:00
|
|
|
{ 0x80, "I Hear You" },
|
|
|
|
{ 0x40, "Demand" },
|
|
|
|
{ 0x20, "Poll" },
|
|
|
|
{ 0x10, "Final" },
|
|
|
|
{ 0x08, "Reserved" },
|
|
|
|
{ 0x04, "Reserved" },
|
|
|
|
{ 0x02, "Reserved" },
|
|
|
|
{ 0x01, "Reserved" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2005-04-28 17:27:35 +08:00
|
|
|
#define BFD_FLAG_AUTH 0x04
|
2005-04-28 07:00:53 +08:00
|
|
|
|
|
|
|
static const struct tok bfd_v1_flag_values[] = {
|
|
|
|
{ 0x20, "Poll" },
|
|
|
|
{ 0x10, "Final" },
|
|
|
|
{ 0x08, "Control Plane Independent" },
|
|
|
|
{ BFD_FLAG_AUTH, "Authentication Present" },
|
|
|
|
{ 0x02, "Demand" },
|
|
|
|
{ 0x01, "Reserved" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tok bfd_v1_state_values[] = {
|
|
|
|
{ 0, "AdminDown" },
|
|
|
|
{ 1, "Down" },
|
|
|
|
{ 2, "Init" },
|
|
|
|
{ 3, "Up" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2003-10-27 18:13:44 +08:00
|
|
|
void
|
2014-03-11 20:08:24 +08:00
|
|
|
bfd_print(netdissect_options *ndo, register const u_char *pptr,
|
|
|
|
register u_int len, register u_int port)
|
2003-10-27 18:13:44 +08:00
|
|
|
{
|
|
|
|
const struct bfd_header_t *bfd_header;
|
2005-04-28 07:00:53 +08:00
|
|
|
const struct bfd_auth_header_t *bfd_auth_header;
|
2009-03-27 16:25:39 +08:00
|
|
|
u_int8_t version = 0;
|
2003-10-27 18:13:44 +08:00
|
|
|
|
|
|
|
bfd_header = (const struct bfd_header_t *)pptr;
|
2009-03-27 16:25:39 +08:00
|
|
|
if (port == BFD_CONTROL_PORT) {
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_TCHECK(*bfd_header);
|
2009-03-27 16:25:39 +08:00
|
|
|
version = BFD_EXTRACT_VERSION(bfd_header->version_diag);
|
|
|
|
} else if (port == BFD_ECHO_PORT) {
|
|
|
|
/* Echo is BFD v1 only */
|
|
|
|
version = 1;
|
|
|
|
}
|
|
|
|
switch ((port << 8) | version) {
|
2003-10-28 06:44:37 +08:00
|
|
|
|
2005-04-28 07:00:53 +08:00
|
|
|
/* BFDv0 */
|
|
|
|
case (BFD_CONTROL_PORT << 8):
|
2014-03-11 20:08:24 +08:00
|
|
|
if (ndo->ndo_vflag < 1)
|
2003-10-28 06:44:37 +08:00
|
|
|
{
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "BFDv%u, %s, Flags: [%s], length: %u",
|
2005-04-28 07:00:53 +08:00
|
|
|
version,
|
2003-10-28 06:44:37 +08:00
|
|
|
tok2str(bfd_port_values, "unknown (%u)", port),
|
2005-04-28 07:00:53 +08:00
|
|
|
bittok2str(bfd_v0_flag_values, "none", bfd_header->flags),
|
2014-03-11 20:08:24 +08:00
|
|
|
len));
|
2003-10-28 06:44:37 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "BFDv%u, length: %u\n\t%s, Flags: [%s], Diagnostic: %s (0x%02x)",
|
2005-04-28 07:00:53 +08:00
|
|
|
version,
|
2003-10-28 06:44:37 +08:00
|
|
|
len,
|
2003-10-28 01:21:32 +08:00
|
|
|
tok2str(bfd_port_values, "unknown (%u)", port),
|
2005-04-28 07:00:53 +08:00
|
|
|
bittok2str(bfd_v0_flag_values, "none", bfd_header->flags),
|
2003-10-28 06:44:37 +08:00
|
|
|
tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
|
2014-03-11 20:08:24 +08:00
|
|
|
BFD_EXTRACT_DIAG(bfd_header->version_diag)));
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
|
2003-10-28 06:44:37 +08:00
|
|
|
bfd_header->detect_time_multiplier,
|
|
|
|
bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
|
2014-03-11 20:08:24 +08:00
|
|
|
bfd_header->length));
|
2003-10-28 01:21:32 +08:00
|
|
|
|
|
|
|
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator)));
|
|
|
|
ND_PRINT((ndo, ", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator)));
|
|
|
|
ND_PRINT((ndo, "\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000));
|
|
|
|
ND_PRINT((ndo, "\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000));
|
|
|
|
ND_PRINT((ndo, "\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000));
|
2003-10-28 06:44:37 +08:00
|
|
|
break;
|
2003-10-27 18:13:44 +08:00
|
|
|
|
2005-04-28 07:00:53 +08:00
|
|
|
/* BFDv1 */
|
|
|
|
case (BFD_CONTROL_PORT << 8 | 1):
|
2014-03-11 20:08:24 +08:00
|
|
|
if (ndo->ndo_vflag < 1)
|
2005-04-28 07:00:53 +08:00
|
|
|
{
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "BFDv%u, %s, State %s, Flags: [%s], length: %u",
|
2005-04-28 07:00:53 +08:00
|
|
|
version,
|
|
|
|
tok2str(bfd_port_values, "unknown (%u)", port),
|
2006-02-02 14:35:52 +08:00
|
|
|
tok2str(bfd_v1_state_values, "unknown (%u)", (bfd_header->flags & 0xc0) >> 6),
|
2005-04-28 15:29:13 +08:00
|
|
|
bittok2str(bfd_v1_flag_values, "none", bfd_header->flags & 0x3f),
|
2014-03-11 20:08:24 +08:00
|
|
|
len));
|
2005-04-28 07:00:53 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "BFDv%u, length: %u\n\t%s, State %s, Flags: [%s], Diagnostic: %s (0x%02x)",
|
2005-04-28 07:00:53 +08:00
|
|
|
version,
|
|
|
|
len,
|
|
|
|
tok2str(bfd_port_values, "unknown (%u)", port),
|
2005-04-28 15:29:13 +08:00
|
|
|
tok2str(bfd_v1_state_values, "unknown (%u)", (bfd_header->flags & 0xc0) >> 6),
|
|
|
|
bittok2str(bfd_v1_flag_values, "none", bfd_header->flags & 0x3f),
|
2005-04-28 07:00:53 +08:00
|
|
|
tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
|
2014-03-11 20:08:24 +08:00
|
|
|
BFD_EXTRACT_DIAG(bfd_header->version_diag)));
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
|
2005-04-28 07:00:53 +08:00
|
|
|
bfd_header->detect_time_multiplier,
|
|
|
|
bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
|
2014-03-11 20:08:24 +08:00
|
|
|
bfd_header->length));
|
2005-04-28 07:00:53 +08:00
|
|
|
|
|
|
|
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator)));
|
|
|
|
ND_PRINT((ndo, ", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator)));
|
|
|
|
ND_PRINT((ndo, "\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000));
|
|
|
|
ND_PRINT((ndo, "\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000));
|
|
|
|
ND_PRINT((ndo, "\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000));
|
2005-04-28 07:00:53 +08:00
|
|
|
|
|
|
|
if (bfd_header->flags & BFD_FLAG_AUTH) {
|
2005-04-28 07:14:02 +08:00
|
|
|
pptr += sizeof (const struct bfd_header_t);
|
|
|
|
bfd_auth_header = (const struct bfd_auth_header_t *)pptr;
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_TCHECK2(*bfd_auth_header, sizeof(const struct bfd_auth_header_t));
|
|
|
|
ND_PRINT((ndo, "\n\t%s (%u) Authentication, length %u present",
|
2005-04-28 07:00:53 +08:00
|
|
|
tok2str(bfd_v1_authentication_values,"Unknown",bfd_auth_header->auth_type),
|
|
|
|
bfd_auth_header->auth_type,
|
2014-03-11 20:08:24 +08:00
|
|
|
bfd_auth_header->auth_len));
|
2005-04-28 07:00:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* BFDv0 */
|
|
|
|
case (BFD_ECHO_PORT << 8): /* not yet supported - fall through */
|
|
|
|
/* BFDv1 */
|
|
|
|
case (BFD_ECHO_PORT << 8 | 1):
|
2003-10-28 06:44:37 +08:00
|
|
|
|
|
|
|
default:
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "BFD, %s, length: %u",
|
2003-10-28 06:44:37 +08:00
|
|
|
tok2str(bfd_port_values, "unknown (%u)", port),
|
2014-03-11 20:08:24 +08:00
|
|
|
len));
|
|
|
|
if (ndo->ndo_vflag >= 1) {
|
|
|
|
if(!print_unknown_data(ndo, pptr,"\n\t",len))
|
2014-01-02 09:43:45 +08:00
|
|
|
return;
|
2003-10-28 06:44:37 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-10-27 18:13:44 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
2014-03-11 20:08:24 +08:00
|
|
|
ND_PRINT((ndo, "[|BFD]"));
|
2003-10-27 18:13:44 +08:00
|
|
|
}
|
2014-01-02 09:43:45 +08:00
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-style: whitesmith
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|