1026d7285Schristos /* 2026d7285Schristos * Redistribution and use in source and binary forms, with or without 3026d7285Schristos * modification, are permitted provided that: (1) source code 4026d7285Schristos * distributions retain the above copyright notice and this paragraph 5026d7285Schristos * in its entirety, and (2) distributions including binary code include 6026d7285Schristos * the above copyright notice and this paragraph in its entirety in 7026d7285Schristos * the documentation or other materials provided with the distribution. 8026d7285Schristos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND 9026d7285Schristos * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 10026d7285Schristos * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 11026d7285Schristos * FOR A PARTICULAR PURPOSE. 12026d7285Schristos * 13026d7285Schristos * Original code by Francesco Fondelli (francesco dot fondelli, gmail dot com) 14026d7285Schristos */ 15026d7285Schristos 16fdccd7e4Schristos #include <sys/cdefs.h> 17fdccd7e4Schristos #ifndef lint 18*26ba0b50Schristos __RCSID("$NetBSD: print-vxlan.c,v 1.5 2024/09/02 16:15:33 christos Exp $"); 19fdccd7e4Schristos #endif 20fdccd7e4Schristos 21dc860a36Sspz /* \summary: Virtual eXtensible Local Area Network (VXLAN) printer */ 22dc860a36Sspz 23dc860a36Sspz /* specification: RFC 7348 */ 24dc860a36Sspz 25c74ad251Schristos #include <config.h> 26026d7285Schristos 27c74ad251Schristos #include "netdissect-stdinc.h" 28026d7285Schristos 29c74ad251Schristos #define ND_LONGJMP_FROM_TCHECK 30784088dfSchristos #include "netdissect.h" 31026d7285Schristos #include "extract.h" 32026d7285Schristos 33c74ad251Schristos static const struct tok vxlan_flags [] = { 34c74ad251Schristos { 0x08, "I" }, 35c74ad251Schristos { 0, NULL } 36c74ad251Schristos }; 37784088dfSchristos #define VXLAN_HDR_LEN 8 38784088dfSchristos 39026d7285Schristos /* 403d25ea14Schristos * VXLAN header, RFC7348 413d25ea14Schristos * Virtual eXtensible Local Area Network (VXLAN): A Framework 423d25ea14Schristos * for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks 43026d7285Schristos * 44026d7285Schristos * 0 1 2 3 45026d7285Schristos * 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 46026d7285Schristos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 47026d7285Schristos * |R|R|R|R|I|R|R|R| Reserved | 48026d7285Schristos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 49026d7285Schristos * | VXLAN Network Identifier (VNI) | Reserved | 50026d7285Schristos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 51026d7285Schristos */ 52026d7285Schristos 53026d7285Schristos void 54c47fd378Schristos vxlan_print(netdissect_options *ndo, const u_char *bp, u_int len) 55026d7285Schristos { 56c47fd378Schristos uint8_t flags; 57c47fd378Schristos uint32_t vni; 58026d7285Schristos 59c74ad251Schristos ndo->ndo_protocol = "vxlan"; 60c74ad251Schristos nd_print_protocol_caps(ndo); 61784088dfSchristos if (len < VXLAN_HDR_LEN) 62c74ad251Schristos goto invalid; 63784088dfSchristos 64c74ad251Schristos flags = GET_U_1(bp); 65c74ad251Schristos bp += 1; 66c74ad251Schristos ND_PRINT(", flags [%s] (0x%02x), ", 67c74ad251Schristos bittok2str_nosep(vxlan_flags, "invalid", flags), flags); 68026d7285Schristos 69c74ad251Schristos /* 1st Reserved */ 70c74ad251Schristos bp += 3; 71026d7285Schristos 72c74ad251Schristos vni = GET_BE_U_3(bp); 73c74ad251Schristos bp += 3; 74c74ad251Schristos ND_PRINT("vni %u\n", vni); 75026d7285Schristos 76c74ad251Schristos /* 2nd Reserved */ 77c74ad251Schristos ND_TCHECK_1(bp); 78c74ad251Schristos bp += 1; 79026d7285Schristos 80c74ad251Schristos ether_print(ndo, bp, len - VXLAN_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL); 81784088dfSchristos 82784088dfSchristos return; 83784088dfSchristos 84c74ad251Schristos invalid: 85c74ad251Schristos nd_print_invalid(ndo); 86026d7285Schristos } 87