1 1.1 christos /* 2 1.1 christos * Redistribution and use in source and binary forms, with or without 3 1.1 christos * modification, are permitted provided that: (1) source code 4 1.1 christos * distributions retain the above copyright notice and this paragraph 5 1.1 christos * in its entirety, and (2) distributions including binary code include 6 1.1 christos * the above copyright notice and this paragraph in its entirety in 7 1.1 christos * the documentation or other materials provided with the distribution. 8 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND 9 1.1 christos * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 10 1.1 christos * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 11 1.1 christos * FOR A PARTICULAR PURPOSE. 12 1.1 christos * 13 1.1 christos * Original code by Francesco Fondelli (francesco dot fondelli, gmail dot com) 14 1.1 christos */ 15 1.1 christos 16 1.2 christos #include <sys/cdefs.h> 17 1.2 christos #ifndef lint 18 1.5 christos __RCSID("$NetBSD: print-vxlan.c,v 1.5 2024/09/02 16:15:33 christos Exp $"); 19 1.2 christos #endif 20 1.2 christos 21 1.3 spz /* \summary: Virtual eXtensible Local Area Network (VXLAN) printer */ 22 1.3 spz 23 1.3 spz /* specification: RFC 7348 */ 24 1.3 spz 25 1.4 christos #include <config.h> 26 1.1 christos 27 1.4 christos #include "netdissect-stdinc.h" 28 1.1 christos 29 1.4 christos #define ND_LONGJMP_FROM_TCHECK 30 1.2 christos #include "netdissect.h" 31 1.2 christos #include "extract.h" 32 1.1 christos 33 1.4 christos static const struct tok vxlan_flags [] = { 34 1.4 christos { 0x08, "I" }, 35 1.4 christos { 0, NULL } 36 1.4 christos }; 37 1.2 christos #define VXLAN_HDR_LEN 8 38 1.1 christos 39 1.1 christos /* 40 1.2 christos * VXLAN header, RFC7348 41 1.2 christos * Virtual eXtensible Local Area Network (VXLAN): A Framework 42 1.2 christos * for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks 43 1.1 christos * 44 1.1 christos * 0 1 2 3 45 1.1 christos * 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 46 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 47 1.1 christos * |R|R|R|R|I|R|R|R| Reserved | 48 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 49 1.1 christos * | VXLAN Network Identifier (VNI) | Reserved | 50 1.2 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 51 1.1 christos */ 52 1.1 christos 53 1.1 christos void 54 1.2 christos vxlan_print(netdissect_options *ndo, const u_char *bp, u_int len) 55 1.1 christos { 56 1.2 christos uint8_t flags; 57 1.2 christos uint32_t vni; 58 1.2 christos 59 1.4 christos ndo->ndo_protocol = "vxlan"; 60 1.4 christos nd_print_protocol_caps(ndo); 61 1.2 christos if (len < VXLAN_HDR_LEN) 62 1.4 christos goto invalid; 63 1.2 christos 64 1.4 christos flags = GET_U_1(bp); 65 1.4 christos bp += 1; 66 1.4 christos ND_PRINT(", flags [%s] (0x%02x), ", 67 1.4 christos bittok2str_nosep(vxlan_flags, "invalid", flags), flags); 68 1.1 christos 69 1.4 christos /* 1st Reserved */ 70 1.4 christos bp += 3; 71 1.1 christos 72 1.4 christos vni = GET_BE_U_3(bp); 73 1.4 christos bp += 3; 74 1.4 christos ND_PRINT("vni %u\n", vni); 75 1.1 christos 76 1.4 christos /* 2nd Reserved */ 77 1.4 christos ND_TCHECK_1(bp); 78 1.4 christos bp += 1; 79 1.1 christos 80 1.4 christos ether_print(ndo, bp, len - VXLAN_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL); 81 1.1 christos 82 1.2 christos return; 83 1.1 christos 84 1.4 christos invalid: 85 1.4 christos nd_print_invalid(ndo); 86 1.1 christos } 87