]> The Tcpdump Group git mirrors - tcpdump/blob - print-arista.c
de2841e447f93ec740cd66d21ad591d2d3fb9df4
[tcpdump] / print-arista.c
1 // Copyright (c) 2018 Arista Networks, Inc. All rights reserved.
2
3 /* \summary: EtherType protocol for Arista Networks printer */
4
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif
8
9 #include <netdissect-stdinc.h>
10
11 #include <string.h>
12
13 #include "netdissect.h"
14 #include "extract.h"
15 #include "addrtoname.h"
16
17 #define ARISTA_SUBTYPE_TIMESTAMP 0x01
18
19 #define ARISTA_TIMESTAMP_64_TAI 0x0010
20 #define ARISTA_TIMESTAMP_64_UTC 0x0110
21 #define ARISTA_TIMESTAMP_48_TAI 0x0020
22 #define ARISTA_TIMESTAMP_48_UTC 0x0120
23
24 static const struct tok ts_version_name[] = {
25 { ARISTA_TIMESTAMP_64_TAI, "TAI(64-bit)" },
26 { ARISTA_TIMESTAMP_64_UTC, "UTC(64-bit)" },
27 { ARISTA_TIMESTAMP_48_TAI, "TAI(48-bit)" },
28 { ARISTA_TIMESTAMP_48_UTC, "UTC(48-bit)" },
29 { 0, NULL }
30 };
31
32 static inline void
33 arista_print_date_hms_time(netdissect_options *ndo, uint32_t seconds,
34 uint32_t nanoseconds)
35 {
36 time_t ts;
37 struct tm *tm;
38 char buf[BUFSIZE];
39
40 ts = seconds + (nanoseconds / 1000000000);
41 if (NULL == (tm = gmtime(&ts)))
42 ND_PRINT(": gmtime() error");
43 else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
44 ND_PRINT(": strftime() error");
45 else
46 ND_PRINT(": %s, %09u ns, ", buf, nanoseconds);
47 }
48
49 int
50 arista_ethertype_print(netdissect_options *ndo, const u_char *bp, u_int len _U_)
51 {
52 uint16_t subTypeId;
53 uint16_t version;
54 u_short bytesConsumed = 0;
55 u_short size = 0;
56 uint32_t seconds, nanoseconds;
57
58 ndo->ndo_protocol = "arista";
59
60 subTypeId = GET_BE_U_2(bp);
61 bp += 2;
62 version = GET_BE_U_2(bp);
63 bp += 2;
64 bytesConsumed += 4;
65
66 ND_PRINT("SubType: 0x%1x, Version: 0x%04x, ", subTypeId, version);
67
68 // TapAgg Header Timestamping
69 if (subTypeId == ARISTA_SUBTYPE_TIMESTAMP) {
70 // Timestamp has 32-bit lsb in nanosec and remaining msb in sec
71 ND_PRINT("Timestamp %s", tok2str(ts_version_name,
72 "Unknown timestamp Version 0x%04x ", version));
73 switch (version) {
74 case ARISTA_TIMESTAMP_64_TAI:
75 case ARISTA_TIMESTAMP_64_UTC:
76 seconds = GET_BE_U_4(bp);
77 nanoseconds = GET_BE_U_4(bp + 4);
78 arista_print_date_hms_time(ndo, seconds, nanoseconds);
79 bytesConsumed += size + 8;
80 break;
81 case ARISTA_TIMESTAMP_48_TAI:
82 case ARISTA_TIMESTAMP_48_UTC:
83 ND_PRINT(": Seconds %u,", GET_BE_U_2(bp));
84 ND_PRINT(" Nanoseconds %u, ", GET_BE_U_4(bp + 2));
85 bytesConsumed += size + 6;
86 break;
87 default:
88 return -1;
89 }
90 } else {
91 return -1;
92 }
93 return bytesConsumed;
94 }