1 /* Copyright (c) 2015, bugyo 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 1. Redistributions of source code must retain the above copyright notice, 7 * this list of conditions and the following disclaimer. 8 * 2. Redistributions in binary form must reproduce the above copyright notice, 9 * this list of conditions and the following disclaimer in the documentation 10 * and/or other materials provided with the distribution. 11 * 12 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 13 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 16 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 19 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 */ 23 24 #include <sys/cdefs.h> 25 #ifndef lint 26 __RCSID("$NetBSD: print-vxlan-gpe.c,v 1.5 2024/09/02 16:15:33 christos Exp $"); 27 #endif 28 29 /* \summary: Generic Protocol Extension for VXLAN (VXLAN GPE) printer */ 30 31 /* specification: draft-ietf-nvo3-vxlan-gpe-10 */ 32 33 #include <config.h> 34 35 #include "netdissect-stdinc.h" 36 37 #define ND_LONGJMP_FROM_TCHECK 38 #include "netdissect.h" 39 #include "extract.h" 40 41 static const struct tok vxlan_gpe_flags [] = { 42 { 0x08, "I" }, 43 { 0x04, "P" }, 44 { 0x02, "B" }, 45 { 0x01, "O" }, 46 { 0, NULL } 47 }; 48 49 #define VXLAN_GPE_HDR_LEN 8 50 51 /* 52 * VXLAN GPE header, draft-ietf-nvo3-vxlan-gpe-01 53 * Generic Protocol Extension for VXLAN 54 * 55 * 0 1 2 3 56 * 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 57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 58 * |R|R|Ver|I|P|R|O| Reserved |Next Protocol | 59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 60 * | VXLAN Network Identifier (VNI) | Reserved | 61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 62 */ 63 64 void 65 vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len) 66 { 67 uint8_t flags; 68 uint8_t next_protocol; 69 uint32_t vni; 70 71 ndo->ndo_protocol = "vxlan_gpe"; 72 ND_PRINT("VXLAN-GPE, "); 73 if (len < VXLAN_GPE_HDR_LEN) { 74 ND_PRINT(" (len %u < %u)", len, VXLAN_GPE_HDR_LEN); 75 goto invalid; 76 } 77 78 flags = GET_U_1(bp); 79 bp += 1; 80 len -= 1; 81 ND_PRINT("flags [%s], ", 82 bittok2str_nosep(vxlan_gpe_flags, "none", flags)); 83 84 /* Reserved */ 85 bp += 2; 86 len -= 2; 87 88 next_protocol = GET_U_1(bp); 89 bp += 1; 90 len -= 1; 91 92 vni = GET_BE_U_3(bp); 93 bp += 3; 94 len -= 3; 95 96 /* Reserved */ 97 ND_TCHECK_1(bp); 98 bp += 1; 99 len -= 1; 100 101 ND_PRINT("vni %u", vni); 102 ND_PRINT(ndo->ndo_vflag ? "\n " : ": "); 103 104 switch (next_protocol) { 105 case 0x1: 106 ip_print(ndo, bp, len); 107 break; 108 case 0x2: 109 ip6_print(ndo, bp, len); 110 break; 111 case 0x3: 112 ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL); 113 break; 114 case 0x4: 115 nsh_print(ndo, bp, len); 116 break; 117 default: 118 ND_PRINT("ERROR: unknown-next-protocol"); 119 goto invalid; 120 } 121 122 return; 123 124 invalid: 125 nd_print_invalid(ndo); 126 } 127 128