47 #define VALID_GENEVE_VERSIONS \
51 #define GENEVE_VERSION(hdr_ptr) (hdr_ptr->ver_plus_len >> 6)
52 #define GENEVE_RESERVED_FLAGS(hdr_ptr) (hdr_ptr->flags & 0x3F)
54 #define GENEVE_MIN_HEADER_LEN sizeof(GeneveHeader)
55 #define GENEVE_TOTAL_OPT_LEN(hdr_ptr) ((uint8_t)((hdr_ptr->ver_plus_len & 0x3F) << 2))
56 #define GENEVE_TOTAL_HEADER_LEN(hdr_ptr) (GENEVE_MIN_HEADER_LEN + GENEVE_TOTAL_OPT_LEN(hdr_ptr))
58 #define GENEVE_MIN_SINGLE_OPT_LEN sizeof(GeneveOption)
59 #define GENEVE_SINGLE_OPT_LEN(option_ptr) ((uint8_t)((option_ptr->flags_plus_len & 0x1F) << 2))
60 #define GENEVE_SINGLE_OPT_TOTAL_LEN(option_ptr) \
61 (GENEVE_MIN_SINGLE_OPT_LEN + GENEVE_SINGLE_OPT_LEN(option_ptr))
63 #define GENEVE_MAX_PORTS 4
64 #define GENEVE_UNSET_PORT -1
65 #define GENEVE_DEFAULT_PORT 6081
66 #define GENEVE_DEFAULT_PORT_S "6081"
68 static bool g_geneve_enabled =
true;
69 static int g_geneve_ports_idx = 0;
93 SCLogDebug(
"ports %u->%u ports %d %d %d %d", sp, dp, g_geneve_ports[0], g_geneve_ports[1],
94 g_geneve_ports[2], g_geneve_ports[3]);
96 if (g_geneve_enabled) {
97 for (
int i = 0; i < g_geneve_ports_idx; i++) {
101 const int port = g_geneve_ports[i];
102 if (port == (
const int)sp || port == (
const int)dp)
109 static void DecodeGeneveConfigPorts(
const char *pstr)
116 g_geneve_ports_idx = 0;
122 g_geneve_ports[g_geneve_ports_idx++] = (int)p->port;
131 if (
ConfGetBool(
"decoder.geneve.enabled", &enabled) == 1) {
133 g_geneve_enabled =
true;
135 g_geneve_enabled =
false;
139 if (g_geneve_enabled) {
141 if (node && node->
val) {
142 DecodeGeneveConfigPorts(node->
val);
149 static inline bool IsValidGeneveVersion(
const GeneveHeader *geneve_hdr)
152 const int num_versions =
sizeof(valid_versions) /
sizeof(
int);
155 for (
int i = 0; i < num_versions; i++) {
156 if (valid_versions[i] == cur_version)
165 static inline bool IsHeaderLengthConsistentWithOptions(
const GeneveHeader *geneve_hdr)
167 uint8_t *geneve_opt_ptr = (uint8_t *)geneve_hdr->
options;
170 while (remaining_hdr_len > 0) {
174 geneve_opt_ptr += cur_option_len;
179 return (remaining_hdr_len == 0);
200 if (!PacketIncreaseCheckLayers(p)) {
206 if (
len < geneve_hdr_len)
209 if (!IsValidGeneveVersion(geneve_hdr))
215 if (!IsHeaderLengthConsistentWithOptions(geneve_hdr))
220 uint32_t vni = (geneve_hdr->
vni[0] << 16) + (geneve_hdr->
vni[1] << 8) + (geneve_hdr->
vni[2]);
249 "Geneve found unsupported Ethertype - expected IPv4, IPv6, ARP, or Ethernet");
256 tv,
dtv, p, pkt + geneve_hdr_len,
len - geneve_hdr_len, decode_tunnel_proto);
273 static int DecodeGeneveTest01(
void)
275 uint8_t raw_geneve[] = { 0x32, 0x10, 0x17, 0xc1, 0x00, 0xc1, 0x87, 0x51,
276 0x04, 0x00, 0x65, 0x58, 0x00, 0x00, 0x25, 0x00,
277 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
278 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
279 0x33, 0x33, 0x00, 0x01, 0x00, 0x02,
280 0x08, 0x00, 0x27, 0xfe, 0x8f, 0x95,
282 0x60, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x11, 0x01,
283 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x27, 0xff, 0xfe, 0xfe, 0x8f,
284 0x95, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
285 0x00, 0x02, 0x02, 0x22, 0x02, 0x23, 0x00, 0x6b, 0x9c, 0xfb,
286 0x03, 0x49, 0x17, 0x4e, 0x00, 0x01, 0x00, 0x0e,
287 0x00, 0x01, 0x00, 0x01, 0x1c, 0x39, 0xcf, 0x88, 0x08, 0x00, 0x27, 0xfe, 0x8f, 0x95, 0x00,
288 0x02, 0x00, 0x0e, 0x00, 0x01, 0x00, 0x01, 0x1c, 0x38, 0x25, 0xe8, 0x08, 0x00, 0x27, 0xd4,
289 0x10, 0xbb, 0x00, 0x06, 0x00, 0x04, 0x00, 0x17, 0x00, 0x18, 0x00, 0x08, 0x00, 0x02, 0x00,
290 0x00, 0x00, 0x19, 0x00, 0x29, 0x27, 0xfe, 0x8f, 0x95, 0x00, 0x00, 0x0e, 0x10, 0x00, 0x00,
291 0x15, 0x18, 0x00, 0x1a, 0x00, 0x19, 0x00, 0x00, 0x1c, 0x20, 0x00, 0x00, 0x1d, 0x4c, 0x40,
292 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 static int DecodeGeneveTest02(
void)
327 uint8_t raw_geneve[] = {
328 0x32, 0x10, 0x17, 0xc1, 0x00, 0x3c, 0x87, 0x51,
329 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x25, 0x00,
330 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
331 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
332 0x45, 0x00, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
333 0x44, 0x45, 0x0a, 0x60, 0x00, 0x0a, 0xb9, 0x1b, 0x73, 0x06, 0x00, 0x35, 0x30, 0x39, 0x00,
368 static int DecodeGeneveTest03(
void)
370 uint8_t raw_geneve[] = {
371 0x32, 0x10, 0x17, 0xc1, 0x00, 0x4e, 0x87, 0x51,
372 0x04, 0x00, 0x65, 0x58, 0x00, 0x00, 0x25, 0x00,
373 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
374 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
375 0x33, 0x33, 0x00, 0x01, 0x00, 0x02,
376 0x08, 0x00, 0x27, 0xfe, 0x8f, 0x95,
377 0x81, 0x00, 0x00, 0xad,
379 0x45, 0x00, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
380 0x44, 0x45, 0x0a, 0x60, 0x00, 0x0a, 0xb9, 0x1b, 0x73, 0x06, 0x00, 0x35, 0x30, 0x39, 0x00,
413 static int DecodeGeneveTest04(
void)
415 uint8_t raw_geneve[] = {
416 0x32, 0x10, 0x17, 0xc1, 0x00, 0x4a, 0x87, 0x51,
417 0x04, 0x00, 0x65, 0x58, 0x00, 0x00, 0x25, 0x00,
418 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
419 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
420 0x10, 0x00, 0x00, 0x0c, 0x01, 0x00,
421 0x00, 0x51, 0x52, 0xb3, 0x54, 0xe5,
423 0x45, 0x00, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
424 0x44, 0x45, 0x0a, 0x60, 0x00, 0x0a, 0xb9, 0x1b, 0x73, 0x06, 0x00, 0x35, 0x30, 0x39, 0x00,
433 DecodeGeneveConfigPorts(
"1");
453 static int DecodeGeneveTest05(
void)
455 uint8_t raw_geneve[] = {
456 0x32, 0x10, 0x17, 0xc1, 0x00, 0x4a, 0x87, 0x51,
457 0x04, 0x00, 0x65, 0x58, 0x00, 0x00, 0x25, 0x00,
458 0x01, 0x08, 0x00, 0x04, 0x11, 0x11, 0x11, 0x11,
459 0x01, 0x08, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
460 0x10, 0x00, 0x00, 0x0c, 0x01, 0x00,
461 0x00, 0x51, 0x52, 0xb3, 0x54, 0xe5,
463 0x45, 0x00, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
464 0x44, 0x45, 0x0a, 0x60, 0x00, 0x0a, 0xb9, 0x1b, 0x73, 0x06, 0x00, 0x35, 0x30, 0x39, 0x00,
493 UtRegisterTest(
"DecodeGeneveTest01 -- Ethernet+IPv6 DHCP Request", DecodeGeneveTest01);
494 UtRegisterTest(
"DecodeGeneveTest02 -- IPv4 DNS Request", DecodeGeneveTest02);
495 UtRegisterTest(
"DecodeGeneveTest03 -- VLAN+IPv4 DNS Request", DecodeGeneveTest03);
496 UtRegisterTest(
"DecodeGeneveTest04 -- Non-standard port configuration", DecodeGeneveTest04);
497 UtRegisterTest(
"DecodeGeneveTest05 -- Inconsistent Geneve hdr option lens", DecodeGeneveTest05);