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 /* \summary: Generic Protocol Extension for VXLAN (VXLAN GPE) printer */ 25 26 /* specification: draft-ietf-nvo3-vxlan-gpe-10 */ 27 28 #include <config.h> 29 30 #include "netdissect-stdinc.h" 31 32 #define ND_LONGJMP_FROM_TCHECK 33 #include "netdissect.h" 34 #include "extract.h" 35 36 static const struct tok vxlan_gpe_flags [] = { 37 { 0x08, "I" }, 38 { 0x04, "P" }, 39 { 0x02, "B" }, 40 { 0x01, "O" }, 41 { 0, NULL } 42 }; 43 44 #define VXLAN_GPE_HDR_LEN 8 45 46 /* 47 * VXLAN GPE header, draft-ietf-nvo3-vxlan-gpe-01 48 * Generic Protocol Extension for VXLAN 49 * 50 * 0 1 2 3 51 * 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 52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 53 * |R|R|Ver|I|P|R|O| Reserved |Next Protocol | 54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 55 * | VXLAN Network Identifier (VNI) | Reserved | 56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 57 */ 58 59 void 60 vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len) 61 { 62 uint8_t flags; 63 uint8_t next_protocol; 64 uint32_t vni; 65 66 ndo->ndo_protocol = "vxlan_gpe"; 67 ND_PRINT("VXLAN-GPE, "); 68 if (len < VXLAN_GPE_HDR_LEN) { 69 ND_PRINT(" (len %u < %u)", len, VXLAN_GPE_HDR_LEN); 70 goto invalid; 71 } 72 73 flags = GET_U_1(bp); 74 bp += 1; 75 len -= 1; 76 ND_PRINT("flags [%s], ", 77 bittok2str_nosep(vxlan_gpe_flags, "none", flags)); 78 79 /* Reserved */ 80 bp += 2; 81 len -= 2; 82 83 next_protocol = GET_U_1(bp); 84 bp += 1; 85 len -= 1; 86 87 vni = GET_BE_U_3(bp); 88 bp += 3; 89 len -= 3; 90 91 /* Reserved */ 92 ND_TCHECK_1(bp); 93 bp += 1; 94 len -= 1; 95 96 ND_PRINT("vni %u", vni); 97 ND_PRINT(ndo->ndo_vflag ? "\n " : ": "); 98 99 switch (next_protocol) { 100 case 0x1: 101 ip_print(ndo, bp, len); 102 break; 103 case 0x2: 104 ip6_print(ndo, bp, len); 105 break; 106 case 0x3: 107 ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL); 108 break; 109 case 0x4: 110 nsh_print(ndo, bp, len); 111 break; 112 default: 113 ND_PRINT("ERROR: unknown-next-protocol"); 114 goto invalid; 115 } 116 117 return; 118 119 invalid: 120 nd_print_invalid(ndo); 121 } 122 123