blob: 13cba422937778626aaf9c212c908b4748a80679 [file] [log] [blame]
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001/* 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
Elliott Hughes820eced2021-08-20 18:00:50 -070026/* specification: draft-ietf-nvo3-vxlan-gpe-10 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -070027
28#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070029#include <config.h>
Elliott Hughese2e3bd12017-05-15 10:59:29 -070030#endif
31
Elliott Hughes820eced2021-08-20 18:00:50 -070032#include "netdissect-stdinc.h"
Elliott Hughese2e3bd12017-05-15 10:59:29 -070033
Elliott Hughes820eced2021-08-20 18:00:50 -070034#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070035#include "netdissect.h"
36#include "extract.h"
37
Elliott Hughese2e3bd12017-05-15 10:59:29 -070038static const struct tok vxlan_gpe_flags [] = {
39 { 0x08, "I" },
40 { 0x04, "P" },
Elliott Hughes820eced2021-08-20 18:00:50 -070041 { 0x02, "B" },
Elliott Hughese2e3bd12017-05-15 10:59:29 -070042 { 0x01, "O" },
43 { 0, NULL }
44};
45
46#define VXLAN_GPE_HDR_LEN 8
47
48/*
49 * VXLAN GPE header, draft-ietf-nvo3-vxlan-gpe-01
50 * Generic Protocol Extension for VXLAN
51 *
52 * 0 1 2 3
53 * 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
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 * |R|R|Ver|I|P|R|O| Reserved |Next Protocol |
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 * | VXLAN Network Identifier (VNI) | Reserved |
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 */
60
61void
62vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len)
63{
64 uint8_t flags;
65 uint8_t next_protocol;
66 uint32_t vni;
67
Elliott Hughes820eced2021-08-20 18:00:50 -070068 ndo->ndo_protocol = "vxlan_gpe";
69 ND_PRINT("VXLAN-GPE, ");
70 if (len < VXLAN_GPE_HDR_LEN) {
71 ND_PRINT(" (len %u < %u)", len, VXLAN_GPE_HDR_LEN);
72 goto invalid;
73 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -070074
Elliott Hughes820eced2021-08-20 18:00:50 -070075 flags = GET_U_1(bp);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070076 bp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -070077 len -= 1;
78 ND_PRINT("flags [%s], ",
79 bittok2str_nosep(vxlan_gpe_flags, "none", flags));
Elliott Hughese2e3bd12017-05-15 10:59:29 -070080
Elliott Hughes820eced2021-08-20 18:00:50 -070081 /* Reserved */
82 bp += 2;
83 len -= 2;
Elliott Hughese2e3bd12017-05-15 10:59:29 -070084
Elliott Hughes820eced2021-08-20 18:00:50 -070085 next_protocol = GET_U_1(bp);
86 bp += 1;
87 len -= 1;
88
89 vni = GET_BE_U_3(bp);
90 bp += 3;
91 len -= 3;
92
93 /* Reserved */
94 ND_TCHECK_1(bp);
95 bp += 1;
96 len -= 1;
97
98 ND_PRINT("vni %u", vni);
99 ND_PRINT(ndo->ndo_vflag ? "\n " : ": ");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700100
101 switch (next_protocol) {
102 case 0x1:
Elliott Hughes820eced2021-08-20 18:00:50 -0700103 ip_print(ndo, bp, len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700104 break;
105 case 0x2:
Elliott Hughes820eced2021-08-20 18:00:50 -0700106 ip6_print(ndo, bp, len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700107 break;
108 case 0x3:
Elliott Hughes820eced2021-08-20 18:00:50 -0700109 ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700110 break;
111 case 0x4:
Elliott Hughes820eced2021-08-20 18:00:50 -0700112 nsh_print(ndo, bp, len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700113 break;
114 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700115 ND_PRINT("ERROR: unknown-next-protocol");
116 goto invalid;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700117 }
118
119 return;
120
Elliott Hughes820eced2021-08-20 18:00:50 -0700121invalid:
122 nd_print_invalid(ndo);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700123}
124