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