2019-05-18 21:18:30 +08:00
|
|
|
// Copyright (c) 2018 Arista Networks, Inc. All rights reserved.
|
|
|
|
|
2019-05-23 17:20:16 +08:00
|
|
|
/* \summary: EtherType protocol for Arista Networks printer */
|
|
|
|
|
2019-05-18 21:18:30 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2020-04-26 07:48:36 +08:00
|
|
|
#include <config.h>
|
2019-05-18 21:18:30 +08:00
|
|
|
#endif
|
|
|
|
|
2019-09-02 18:08:23 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2019-05-18 21:18:30 +08:00
|
|
|
|
|
|
|
#include "netdissect.h"
|
|
|
|
#include "extract.h"
|
|
|
|
#include "addrtoname.h"
|
|
|
|
|
|
|
|
#define ARISTA_SUBTYPE_TIMESTAMP 0x01
|
|
|
|
|
2019-06-21 13:54:58 +08:00
|
|
|
#define ARISTA_TIMESTAMP_64_TAI 0x0010
|
|
|
|
#define ARISTA_TIMESTAMP_64_UTC 0x0110
|
|
|
|
#define ARISTA_TIMESTAMP_48_TAI 0x0020
|
|
|
|
#define ARISTA_TIMESTAMP_48_UTC 0x0120
|
|
|
|
|
|
|
|
static const struct tok ts_version_name[] = {
|
|
|
|
{ ARISTA_TIMESTAMP_64_TAI, "TAI(64-bit)" },
|
|
|
|
{ ARISTA_TIMESTAMP_64_UTC, "UTC(64-bit)" },
|
|
|
|
{ ARISTA_TIMESTAMP_48_TAI, "TAI(48-bit)" },
|
|
|
|
{ ARISTA_TIMESTAMP_48_UTC, "UTC(48-bit)" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
arista_print_date_hms_time(netdissect_options *ndo, uint32_t seconds,
|
|
|
|
uint32_t nanoseconds)
|
|
|
|
{
|
|
|
|
time_t ts;
|
|
|
|
struct tm *tm;
|
|
|
|
char buf[BUFSIZE];
|
|
|
|
|
|
|
|
ts = seconds + (nanoseconds / 1000000000);
|
|
|
|
if (NULL == (tm = gmtime(&ts)))
|
|
|
|
ND_PRINT(": gmtime() error");
|
|
|
|
else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
|
|
|
|
ND_PRINT(": strftime() error");
|
|
|
|
else
|
|
|
|
ND_PRINT(": %s, %09u ns, ", buf, nanoseconds);
|
|
|
|
}
|
2019-05-18 21:18:30 +08:00
|
|
|
|
|
|
|
int
|
2019-05-23 17:20:16 +08:00
|
|
|
arista_ethertype_print(netdissect_options *ndo, const u_char *bp, u_int len _U_)
|
2019-05-18 21:18:30 +08:00
|
|
|
{
|
|
|
|
uint16_t subTypeId;
|
|
|
|
uint16_t version;
|
|
|
|
u_short bytesConsumed = 0;
|
|
|
|
u_short size = 0;
|
2019-06-21 13:54:58 +08:00
|
|
|
uint32_t seconds, nanoseconds;
|
2019-05-18 21:18:30 +08:00
|
|
|
|
|
|
|
ndo->ndo_protocol = "arista";
|
|
|
|
|
|
|
|
subTypeId = GET_BE_U_2(bp);
|
|
|
|
bp += 2;
|
|
|
|
version = GET_BE_U_2(bp);
|
|
|
|
bp += 2;
|
|
|
|
bytesConsumed += 4;
|
|
|
|
|
2019-06-21 13:54:58 +08:00
|
|
|
ND_PRINT("SubType: 0x%1x, Version: 0x%04x, ", subTypeId, version);
|
2019-05-18 21:18:30 +08:00
|
|
|
|
|
|
|
// TapAgg Header Timestamping
|
|
|
|
if (subTypeId == ARISTA_SUBTYPE_TIMESTAMP) {
|
|
|
|
// Timestamp has 32-bit lsb in nanosec and remaining msb in sec
|
2019-06-21 13:54:58 +08:00
|
|
|
ND_PRINT("Timestamp %s", tok2str(ts_version_name,
|
|
|
|
"Unknown timestamp Version 0x%04x ", version));
|
2019-05-18 21:18:30 +08:00
|
|
|
switch (version) {
|
2019-06-21 13:54:58 +08:00
|
|
|
case ARISTA_TIMESTAMP_64_TAI:
|
|
|
|
case ARISTA_TIMESTAMP_64_UTC:
|
|
|
|
seconds = GET_BE_U_4(bp);
|
|
|
|
nanoseconds = GET_BE_U_4(bp + 4);
|
|
|
|
arista_print_date_hms_time(ndo, seconds, nanoseconds);
|
2019-05-18 21:18:30 +08:00
|
|
|
bytesConsumed += size + 8;
|
|
|
|
break;
|
2019-06-21 13:54:58 +08:00
|
|
|
case ARISTA_TIMESTAMP_48_TAI:
|
|
|
|
case ARISTA_TIMESTAMP_48_UTC:
|
2019-05-18 21:18:30 +08:00
|
|
|
ND_PRINT(": Seconds %u,", GET_BE_U_2(bp));
|
|
|
|
ND_PRINT(" Nanoseconds %u, ", GET_BE_U_4(bp + 2));
|
|
|
|
bytesConsumed += size + 6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return bytesConsumed;
|
|
|
|
}
|