13340d773SGleb Smirnoff /* Copyright (c) 2015, bugyo
23340d773SGleb Smirnoff * All rights reserved.
33340d773SGleb Smirnoff *
43340d773SGleb Smirnoff * Redistribution and use in source and binary forms, with or without
53340d773SGleb Smirnoff * modification, are permitted provided that the following conditions are met:
63340d773SGleb Smirnoff * 1. Redistributions of source code must retain the above copyright notice,
73340d773SGleb Smirnoff * this list of conditions and the following disclaimer.
83340d773SGleb Smirnoff * 2. Redistributions in binary form must reproduce the above copyright notice,
93340d773SGleb Smirnoff * this list of conditions and the following disclaimer in the documentation
103340d773SGleb Smirnoff * and/or other materials provided with the distribution.
113340d773SGleb Smirnoff *
123340d773SGleb Smirnoff * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
133340d773SGleb Smirnoff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
143340d773SGleb Smirnoff * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
153340d773SGleb Smirnoff * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
163340d773SGleb Smirnoff * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
173340d773SGleb Smirnoff * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
183340d773SGleb Smirnoff * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
193340d773SGleb Smirnoff * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
203340d773SGleb Smirnoff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
213340d773SGleb Smirnoff * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223340d773SGleb Smirnoff */
233340d773SGleb Smirnoff
243340d773SGleb Smirnoff /* \summary: Generic Protocol Extension for VXLAN (VXLAN GPE) printer */
253340d773SGleb Smirnoff
26*ee67461eSJoseph Mingrone /* specification: draft-ietf-nvo3-vxlan-gpe-10 */
273340d773SGleb Smirnoff
28*ee67461eSJoseph Mingrone #include <config.h>
293340d773SGleb Smirnoff
30*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
313340d773SGleb Smirnoff
32*ee67461eSJoseph Mingrone #define ND_LONGJMP_FROM_TCHECK
333340d773SGleb Smirnoff #include "netdissect.h"
343340d773SGleb Smirnoff #include "extract.h"
353340d773SGleb Smirnoff
363340d773SGleb Smirnoff static const struct tok vxlan_gpe_flags [] = {
373340d773SGleb Smirnoff { 0x08, "I" },
383340d773SGleb Smirnoff { 0x04, "P" },
39*ee67461eSJoseph Mingrone { 0x02, "B" },
403340d773SGleb Smirnoff { 0x01, "O" },
413340d773SGleb Smirnoff { 0, NULL }
423340d773SGleb Smirnoff };
433340d773SGleb Smirnoff
443340d773SGleb Smirnoff #define VXLAN_GPE_HDR_LEN 8
453340d773SGleb Smirnoff
463340d773SGleb Smirnoff /*
473340d773SGleb Smirnoff * VXLAN GPE header, draft-ietf-nvo3-vxlan-gpe-01
483340d773SGleb Smirnoff * Generic Protocol Extension for VXLAN
493340d773SGleb Smirnoff *
503340d773SGleb Smirnoff * 0 1 2 3
513340d773SGleb Smirnoff * 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
523340d773SGleb Smirnoff * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
533340d773SGleb Smirnoff * |R|R|Ver|I|P|R|O| Reserved |Next Protocol |
543340d773SGleb Smirnoff * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
553340d773SGleb Smirnoff * | VXLAN Network Identifier (VNI) | Reserved |
563340d773SGleb Smirnoff * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
573340d773SGleb Smirnoff */
583340d773SGleb Smirnoff
593340d773SGleb Smirnoff void
vxlan_gpe_print(netdissect_options * ndo,const u_char * bp,u_int len)603340d773SGleb Smirnoff vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len)
613340d773SGleb Smirnoff {
623340d773SGleb Smirnoff uint8_t flags;
633340d773SGleb Smirnoff uint8_t next_protocol;
643340d773SGleb Smirnoff uint32_t vni;
653340d773SGleb Smirnoff
66*ee67461eSJoseph Mingrone ndo->ndo_protocol = "vxlan_gpe";
67*ee67461eSJoseph Mingrone ND_PRINT("VXLAN-GPE, ");
68*ee67461eSJoseph Mingrone if (len < VXLAN_GPE_HDR_LEN) {
69*ee67461eSJoseph Mingrone ND_PRINT(" (len %u < %u)", len, VXLAN_GPE_HDR_LEN);
70*ee67461eSJoseph Mingrone goto invalid;
71*ee67461eSJoseph Mingrone }
723340d773SGleb Smirnoff
73*ee67461eSJoseph Mingrone flags = GET_U_1(bp);
743340d773SGleb Smirnoff bp += 1;
75*ee67461eSJoseph Mingrone len -= 1;
76*ee67461eSJoseph Mingrone ND_PRINT("flags [%s], ",
77*ee67461eSJoseph Mingrone bittok2str_nosep(vxlan_gpe_flags, "none", flags));
783340d773SGleb Smirnoff
79*ee67461eSJoseph Mingrone /* Reserved */
80*ee67461eSJoseph Mingrone bp += 2;
81*ee67461eSJoseph Mingrone len -= 2;
823340d773SGleb Smirnoff
83*ee67461eSJoseph Mingrone next_protocol = GET_U_1(bp);
84*ee67461eSJoseph Mingrone bp += 1;
85*ee67461eSJoseph Mingrone len -= 1;
86*ee67461eSJoseph Mingrone
87*ee67461eSJoseph Mingrone vni = GET_BE_U_3(bp);
88*ee67461eSJoseph Mingrone bp += 3;
89*ee67461eSJoseph Mingrone len -= 3;
90*ee67461eSJoseph Mingrone
91*ee67461eSJoseph Mingrone /* Reserved */
92*ee67461eSJoseph Mingrone ND_TCHECK_1(bp);
93*ee67461eSJoseph Mingrone bp += 1;
94*ee67461eSJoseph Mingrone len -= 1;
95*ee67461eSJoseph Mingrone
96*ee67461eSJoseph Mingrone ND_PRINT("vni %u", vni);
97*ee67461eSJoseph Mingrone ND_PRINT(ndo->ndo_vflag ? "\n " : ": ");
983340d773SGleb Smirnoff
993340d773SGleb Smirnoff switch (next_protocol) {
1003340d773SGleb Smirnoff case 0x1:
101*ee67461eSJoseph Mingrone ip_print(ndo, bp, len);
1023340d773SGleb Smirnoff break;
1033340d773SGleb Smirnoff case 0x2:
104*ee67461eSJoseph Mingrone ip6_print(ndo, bp, len);
1053340d773SGleb Smirnoff break;
1063340d773SGleb Smirnoff case 0x3:
107*ee67461eSJoseph Mingrone ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
1083340d773SGleb Smirnoff break;
1093340d773SGleb Smirnoff case 0x4:
110*ee67461eSJoseph Mingrone nsh_print(ndo, bp, len);
1113340d773SGleb Smirnoff break;
1123340d773SGleb Smirnoff default:
113*ee67461eSJoseph Mingrone ND_PRINT("ERROR: unknown-next-protocol");
114*ee67461eSJoseph Mingrone goto invalid;
1153340d773SGleb Smirnoff }
1163340d773SGleb Smirnoff
1173340d773SGleb Smirnoff return;
1183340d773SGleb Smirnoff
119*ee67461eSJoseph Mingrone invalid:
120*ee67461eSJoseph Mingrone nd_print_invalid(ndo);
1213340d773SGleb Smirnoff }
1223340d773SGleb Smirnoff
123