]>
The Tcpdump Group git mirrors - tcpdump/blob - print-geneve.c
59dca93e047823de2ef2906decc6e7a314880a56
2 * Copyright (c) 2014 VMware, Inc. All Rights Reserved.
4 * Jesse Gross <jesse@nicira.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code
8 * distributions retain the above copyright notice and this paragraph
9 * in its entirety, and (2) distributions including binary code include
10 * the above copyright notice and this paragraph in its entirety in
11 * the documentation or other materials provided with the distribution.
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
13 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
14 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 * FOR A PARTICULAR PURPOSE.
18 /* \summary: Generic Network Virtualization Encapsulation (Geneve) printer */
19 /* specification: RFC 8926 */
25 #include "netdissect-stdinc.h"
27 #define ND_LONGJMP_FROM_TCHECK
28 #include "netdissect.h"
30 #include "ethertype.h"
36 * 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
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * |Ver| Opt Len |O|C| Rsvd. | Protocol Type |
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * | Virtual Network Identifier (VNI) | Reserved |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * ~ Variable-Length Options ~
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * 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
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * | Option Class | Type |R|R|R| Length |
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 * ~ Variable-Length Option Data ~
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 #define HDR_OPTS_LEN_MASK 0x3F
62 #define FLAG_OAM (1 << 7)
63 #define FLAG_CRITICAL (1 << 6)
64 #define FLAG_R1 (1 << 5)
65 #define FLAG_R2 (1 << 4)
66 #define FLAG_R3 (1 << 3)
67 #define FLAG_R4 (1 << 2)
68 #define FLAG_R5 (1 << 1)
69 #define FLAG_R6 (1 << 0)
71 #define OPT_TYPE_CRITICAL (1 << 7)
72 #define OPT_LEN_MASK 0x1F
74 static const struct tok geneve_flag_values
[] = {
76 { FLAG_CRITICAL
, "C" },
87 format_opt_class(const uint16_t opt_class
)
93 return "Open vSwitch";
95 return "Open Virtual Networking (OVN)";
97 return "In-band Network Telemetry (INT)";
153 if (opt_class
<= 0x00ff)
155 else if (opt_class
>= 0xfff0)
156 return "Experimental";
163 geneve_opts_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len
)
165 const char *sep
= "";
172 ND_ICHECKMSG_U("remaining options length", len
, <, 4);
176 opt_class
= GET_BE_U_2(bp
);
177 opt_type
= GET_U_1(bp
+ 2);
178 opt_len
= 4 + ((GET_U_1(bp
+ 3) & OPT_LEN_MASK
) * 4);
180 ND_PRINT("class %s (0x%x) type 0x%x%s len %u",
181 format_opt_class(opt_class
), opt_class
, opt_type
,
182 opt_type
& OPT_TYPE_CRITICAL
? "(C)" : "", opt_len
);
185 ND_PRINT(" [bad length]");
189 if (ndo
->ndo_vflag
> 1 && opt_len
> 4) {
190 const uint32_t *data
= (const uint32_t *)(bp
+ 4);
195 for (i
= 4; i
< opt_len
; i
+= 4) {
196 ND_PRINT(" %08x", GET_BE_U_4(data
));
200 ND_TCHECK_LEN(bp
, opt_len
);
207 ND_TCHECK_LEN(bp
, len
);
212 geneve_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len
)
222 ndo
->ndo_protocol
= "geneve";
225 ND_ICHECK_U(len
, <, 8);
227 ver_opt
= GET_U_1(bp
);
231 version
= ver_opt
>> VER_SHIFT
;
233 ND_PRINT(" ERROR: unknown-version %u", version
);
241 prot
= GET_BE_U_2(bp
);
245 vni
= GET_BE_U_3(bp
);
249 reserved
= GET_U_1(bp
);
253 ND_PRINT(", Flags [%s]",
254 bittok2str_nosep(geneve_flag_values
, "none", flags
));
255 ND_PRINT(", vni 0x%x", vni
);
258 ND_PRINT(", rsvd 0x%x", reserved
);
261 ND_PRINT(", proto %s (0x%04x)",
262 tok2str(ethertype_values
, "unknown", prot
), prot
);
264 opts_len
= (ver_opt
& HDR_OPTS_LEN_MASK
) * 4;
266 if (len
< opts_len
) {
267 ND_PRINT(" (opts_len %u > %u", opts_len
, len
);
272 ND_PRINT(", options [");
274 if (ndo
->ndo_vflag
) {
275 if (! geneve_opts_print(ndo
, bp
, opts_len
))
278 ND_TCHECK_LEN(bp
, opts_len
);
279 ND_PRINT("%u bytes", opts_len
);
288 if (ndo
->ndo_vflag
< 1)
293 if (ethertype_print(ndo
, prot
, bp
, len
, ND_BYTES_AVAILABLE_AFTER(bp
), NULL
, NULL
) == 0) {
294 if (prot
== ETHERTYPE_TEB
)
295 ether_print(ndo
, bp
, len
, ND_BYTES_AVAILABLE_AFTER(bp
), NULL
, NULL
);
297 ND_PRINT("geneve-proto-0x%x", prot
);
298 ND_TCHECK_LEN(bp
, len
);
305 nd_print_invalid(ndo
);