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 #define NETDISSECT_REWORKED
23 #include <tcpdump-stdinc.h>
25 #include "interface.h"
27 #include "ethertype.h"
30 * Geneve header, draft-gross-geneve-02
33 * 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
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * |Ver| Opt Len |O|C| Rsvd. | Protocol Type |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | Virtual Network Identifier (VNI) | Reserved |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * | Variable Length Options |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * | Option Class | Type |R|R|R| Length |
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Variable Option Data |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 #define HDR_OPTS_LEN_MASK 0x3F
53 #define FLAG_OAM (1 << 7)
54 #define FLAG_CRITICAL (1 << 6)
55 #define FLAG_R1 (1 << 5)
56 #define FLAG_R2 (1 << 4)
57 #define FLAG_R3 (1 << 3)
58 #define FLAG_R4 (1 << 2)
59 #define FLAG_R5 (1 << 1)
60 #define FLAG_R6 (1 << 0)
62 #define OPT_TYPE_CRITICAL (1 << 7)
63 #define OPT_LEN_MASK 0x1F
65 static const struct tok geneve_flag_values
[] = {
67 { FLAG_CRITICAL
, "C" },
78 format_opt_class(uint16_t opt_class
)
80 if (opt_class
<= 0xff)
82 else if (opt_class
== 0xffff)
83 return "Experimental";
89 geneve_opts_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len
)
98 ND_PRINT((ndo
, "%s", sep
));
101 opt_class
= EXTRACT_16BITS(bp
);
102 opt_type
= *(bp
+ 2);
103 opt_len
= 4 + ((*(bp
+ 3) & OPT_LEN_MASK
) * 4);
105 ND_PRINT((ndo
, "class %s (0x%x) type 0x%x%s len %u",
106 format_opt_class(opt_class
), opt_class
, opt_type
,
107 opt_type
& OPT_TYPE_CRITICAL
? "(C)" : "", opt_len
));
110 ND_PRINT((ndo
, " [bad length]"));
114 if (ndo
->ndo_vflag
> 1 && opt_len
> 4) {
115 uint32_t *print_data
= (uint32_t *)(bp
+ 4);
118 ND_PRINT((ndo
, " data"));
120 for (i
= 4; i
< opt_len
; i
+= 4) {
121 ND_PRINT((ndo
, " %08x", EXTRACT_32BITS(print_data
)));
132 geneve_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len
)
142 ND_PRINT((ndo
, "Geneve"));
150 version
= ver_opt
>> VER_SHIFT
;
152 ND_PRINT((ndo
, " ERROR: unknown-version %u", version
));
160 prot
= EXTRACT_16BITS(bp
);
164 vni
= EXTRACT_24BITS(bp
);
172 ND_PRINT((ndo
, ", Flags [%s]",
173 bittok2str_nosep(geneve_flag_values
, "none", flags
)));
174 ND_PRINT((ndo
, ", vni 0x%x", vni
));
177 ND_PRINT((ndo
, ", rsvd 0x%x", reserved
));
180 ND_PRINT((ndo
, ", proto %s (0x%04x)",
181 tok2str(ethertype_values
, "unknown", prot
), prot
));
183 opts_len
= (ver_opt
& HDR_OPTS_LEN_MASK
) * 4;
185 if (len
< opts_len
) {
186 ND_PRINT((ndo
, " truncated-geneve - %u bytes missing",
191 ND_TCHECK2(*bp
, opts_len
);
194 ND_PRINT((ndo
, ", options ["));
197 geneve_opts_print(ndo
, bp
, opts_len
);
199 ND_PRINT((ndo
, "%u bytes", opts_len
));
201 ND_PRINT((ndo
, "]"));
207 if (ndo
->ndo_vflag
< 1)
208 ND_PRINT((ndo
, ": "));
210 ND_PRINT((ndo
, "\n\t"));
212 if (ethertype_print(ndo
, prot
, bp
, len
, len
) == 0) {
213 if (prot
== ETHERTYPE_TEB
)
214 ether_print(ndo
, bp
, len
, len
, NULL
, NULL
);
216 ND_PRINT((ndo
, "geneve-proto-0x%x", prot
));
222 ND_PRINT((ndo
, " [|geneve]"));