1d03c0883SXin LI /* 2d03c0883SXin LI * Redistribution and use in source and binary forms, with or without 3d03c0883SXin LI * modification, are permitted provided that: (1) source code 4d03c0883SXin LI * distributions retain the above copyright notice and this paragraph 5d03c0883SXin LI * in its entirety, and (2) distributions including binary code include 6d03c0883SXin LI * the above copyright notice and this paragraph in its entirety in 7d03c0883SXin LI * the documentation or other materials provided with the distribution. 8d03c0883SXin LI * THIS SOFTWARE IS PROVIDED ``AS IS'' AND 9d03c0883SXin LI * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 10d03c0883SXin LI * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 11d03c0883SXin LI * FOR A PARTICULAR PURPOSE. 12d03c0883SXin LI * 13d03c0883SXin LI * Original code by Francesco Fondelli (francesco dot fondelli, gmail dot com) 14d03c0883SXin LI */ 15d03c0883SXin LI 163340d773SGleb Smirnoff /* \summary: Virtual eXtensible Local Area Network (VXLAN) printer */ 173340d773SGleb Smirnoff 183340d773SGleb Smirnoff /* specification: RFC 7348 */ 193340d773SGleb Smirnoff 20*ee67461eSJoseph Mingrone #include <config.h> 21d03c0883SXin LI 22*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h" 23d03c0883SXin LI 24*ee67461eSJoseph Mingrone #define ND_LONGJMP_FROM_TCHECK 253340d773SGleb Smirnoff #include "netdissect.h" 26d03c0883SXin LI #include "extract.h" 27d03c0883SXin LI 28*ee67461eSJoseph Mingrone static const struct tok vxlan_flags [] = { 29*ee67461eSJoseph Mingrone { 0x08, "I" }, 30*ee67461eSJoseph Mingrone { 0, NULL } 31*ee67461eSJoseph Mingrone }; 323340d773SGleb Smirnoff #define VXLAN_HDR_LEN 8 333340d773SGleb Smirnoff 34d03c0883SXin LI /* 358bdc5a62SPatrick Kelsey * VXLAN header, RFC7348 368bdc5a62SPatrick Kelsey * Virtual eXtensible Local Area Network (VXLAN): A Framework 378bdc5a62SPatrick Kelsey * for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks 38d03c0883SXin LI * 39d03c0883SXin LI * 0 1 2 3 40d03c0883SXin LI * 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 41d03c0883SXin LI * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 42d03c0883SXin LI * |R|R|R|R|I|R|R|R| Reserved | 43d03c0883SXin LI * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 44d03c0883SXin LI * | VXLAN Network Identifier (VNI) | Reserved | 45d03c0883SXin LI * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 46d03c0883SXin LI */ 47d03c0883SXin LI 48d03c0883SXin LI void 493c602fabSXin LI vxlan_print(netdissect_options *ndo, const u_char *bp, u_int len) 50d03c0883SXin LI { 513c602fabSXin LI uint8_t flags; 523c602fabSXin LI uint32_t vni; 53d03c0883SXin LI 54*ee67461eSJoseph Mingrone ndo->ndo_protocol = "vxlan"; 55*ee67461eSJoseph Mingrone nd_print_protocol_caps(ndo); 563340d773SGleb Smirnoff if (len < VXLAN_HDR_LEN) 57*ee67461eSJoseph Mingrone goto invalid; 583340d773SGleb Smirnoff 59*ee67461eSJoseph Mingrone flags = GET_U_1(bp); 60*ee67461eSJoseph Mingrone bp += 1; 61*ee67461eSJoseph Mingrone ND_PRINT(", flags [%s] (0x%02x), ", 62*ee67461eSJoseph Mingrone bittok2str_nosep(vxlan_flags, "invalid", flags), flags); 63d03c0883SXin LI 64*ee67461eSJoseph Mingrone /* 1st Reserved */ 65*ee67461eSJoseph Mingrone bp += 3; 66d03c0883SXin LI 67*ee67461eSJoseph Mingrone vni = GET_BE_U_3(bp); 68*ee67461eSJoseph Mingrone bp += 3; 69*ee67461eSJoseph Mingrone ND_PRINT("vni %u\n", vni); 70d03c0883SXin LI 71*ee67461eSJoseph Mingrone /* 2nd Reserved */ 72*ee67461eSJoseph Mingrone ND_TCHECK_1(bp); 73*ee67461eSJoseph Mingrone bp += 1; 74d03c0883SXin LI 75*ee67461eSJoseph Mingrone ether_print(ndo, bp, len - VXLAN_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL); 763340d773SGleb Smirnoff 773340d773SGleb Smirnoff return; 783340d773SGleb Smirnoff 79*ee67461eSJoseph Mingrone invalid: 80*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 81d03c0883SXin LI } 82