3 * Routines for Virtual eXtensible Local Area Network (VXLAN) packet dissection
4 * RFC 7348 plus draft-smith-vxlan-group-policy-01
6 * (c) Copyright 2016, Sumit Kumar Jha <sjha3@ncsu.edu>
7 * Support for VXLAN GPE (https://datatracker.ietf.org/doc/html/draft-ietf-nvo3-vxlan-gpe-02)
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * SPDX-License-Identifier: GPL-2.0-or-later
18 #include <epan/packet.h>
20 #include "packet-vxlan.h"
22 #define UDP_PORT_VXLAN "4789,8472" /* The IANA assigned port is 4789, but Linux default is 8472 for compatibility with early adopters */
23 #define UDP_PORT_VXLAN_GPE 4790
25 void proto_register_vxlan(void);
26 void proto_reg_handoff_vxlan(void);
28 static dissector_handle_t vxlan_handle
;
29 static dissector_handle_t vxlan_gpe_handle
;
31 static int proto_vxlan
;
32 static int proto_vxlan_gpe
;
34 static int hf_vxlan_flags
;
35 static int hf_vxlan_gpe_flags
;
36 static int hf_vxlan_flags_reserved
;
37 static int hf_vxlan_reserved_8
;
38 static int hf_vxlan_flag_a
;
39 static int hf_vxlan_flag_d
;
40 static int hf_vxlan_flag_i
;
41 static int hf_vxlan_flag_g
;
42 static int hf_vxlan_gbp
;
43 static int hf_vxlan_vni
;
44 static int hf_vxlan_gpe_flag_i
;
45 static int hf_vxlan_gpe_flag_p
;
46 static int hf_vxlan_gpe_flag_o
;
47 static int hf_vxlan_gpe_flag_ver
;
48 static int hf_vxlan_gpe_flag_reserved
;
49 static int hf_vxlan_gpe_reserved_16
;
50 static int hf_vxlan_next_proto
;
52 static int ett_vxlan_flags
;
54 static int * const flags_fields
[] = {
59 &hf_vxlan_flags_reserved
,
63 static int * const gpe_flags_fields
[] = {
64 &hf_vxlan_gpe_flag_ver
,
68 &hf_vxlan_gpe_flag_reserved
,
73 static const value_string vxlan_next_protocols
[] = {
74 { VXLAN_IPV4
, "IPv4" },
75 { VXLAN_IPV6
, "IPv6" },
76 { VXLAN_ETHERNET
, "Ethernet" },
77 { VXLAN_NSH
, "Network Service Header" },
78 { VXLAN_MPLS
, "MPLS"},
82 static dissector_handle_t eth_handle
;
83 static dissector_table_t vxlan_dissector_table
;
86 dissect_vxlan_common(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, int is_gpe
)
88 proto_tree
*vxlan_tree
;
92 uint32_t vxlan_next_proto
;
94 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "VxLAN");
95 col_clear(pinfo
->cinfo
, COL_INFO
);
98 ti
= proto_tree_add_item(tree
, proto_vxlan
, tvb
, offset
, 8, ENC_NA
);
99 vxlan_tree
= proto_item_add_subtree(ti
, ett_vxlan
);
102 proto_tree_add_bitmask(vxlan_tree
, tvb
, offset
, hf_vxlan_gpe_flags
, ett_vxlan_flags
, gpe_flags_fields
, ENC_BIG_ENDIAN
);
105 proto_tree_add_item(vxlan_tree
, hf_vxlan_gpe_reserved_16
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
108 proto_tree_add_item_ret_uint(vxlan_tree
, hf_vxlan_next_proto
, tvb
, offset
, 1, ENC_BIG_ENDIAN
, &vxlan_next_proto
);
111 proto_tree_add_bitmask(vxlan_tree
, tvb
, offset
, hf_vxlan_flags
, ett_vxlan_flags
, flags_fields
, ENC_BIG_ENDIAN
);
114 proto_tree_add_item(vxlan_tree
, hf_vxlan_gbp
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
118 proto_tree_add_item(vxlan_tree
, hf_vxlan_vni
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
121 proto_tree_add_item(vxlan_tree
, hf_vxlan_reserved_8
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
124 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
127 if(!dissector_try_uint(vxlan_dissector_table
, vxlan_next_proto
, next_tvb
, pinfo
, tree
)) {
128 call_data_dissector(next_tvb
, pinfo
, tree
);
131 call_dissector(eth_handle
, next_tvb
, pinfo
, tree
);
134 return tvb_captured_length(tvb
);
138 dissect_vxlan_gpe(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
140 return dissect_vxlan_common(tvb
, pinfo
, tree
, true);
145 dissect_vxlan(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
147 return dissect_vxlan_common(tvb
, pinfo
, tree
, false);
153 /* Register VxLAN with Wireshark */
155 proto_register_vxlan(void)
157 static hf_register_info hf
[] = {
159 { "Flags", "vxlan.flags",
160 FT_UINT16
, BASE_HEX
, NULL
, 0x00,
164 { &hf_vxlan_gpe_flags
,
165 { "Flags", "vxlan.flags",
166 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
170 { &hf_vxlan_flags_reserved
,
171 { "Reserved(R)", "vxlan.flags_reserved",
172 FT_UINT16
, BASE_HEX
, NULL
, 0x77b7,
176 { &hf_vxlan_gpe_flag_reserved
,
177 { "Reserved(R)", "vxlan.flags_reserved",
178 FT_UINT8
, BASE_DEC
, NULL
, 0xC2,
183 { "GBP Extension", "vxlan.flag_g",
184 FT_BOOLEAN
, 16, TFS(&tfs_defined_not_defined
), 0x8000,
189 { "VXLAN Network ID (VNI)", "vxlan.flag_i",
190 FT_BOOLEAN
, 16, NULL
, 0x0800,
195 { "Don't Learn", "vxlan.flag_d",
196 FT_BOOLEAN
, 16, NULL
, 0x0040,
201 { "Policy Applied", "vxlan.flag_a",
202 FT_BOOLEAN
, 16, NULL
, 0x0008,
206 { &hf_vxlan_gpe_flag_ver
,
207 { "Version", "vxlan.ver",
208 FT_UINT8
, BASE_DEC
, NULL
, 0x30,
212 { &hf_vxlan_gpe_flag_i
,
213 { "Instance", "vxlan.i_bit",
214 FT_UINT8
, BASE_DEC
, NULL
, 0x08,
218 { &hf_vxlan_gpe_flag_p
,
219 { "Next Protocol Bit", "vxlan.p_bit",
220 FT_UINT8
, BASE_DEC
, NULL
, 0x04,
224 { &hf_vxlan_gpe_flag_o
,
225 { "OAM bit", "vxlan.o_bit",
226 FT_UINT8
, BASE_DEC
, NULL
, 0x01,
231 { "Group Policy ID", "vxlan.gbp",
232 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
237 { "VXLAN Network Identifier (VNI)", "vxlan.vni",
238 FT_UINT24
, BASE_DEC
, NULL
, 0x0,
242 { &hf_vxlan_reserved_8
,
243 { "Reserved", "vxlan.reserved8",
244 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
248 { &hf_vxlan_gpe_reserved_16
,
249 { "Reserved", "vxlan.reserved_16",
250 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
254 { &hf_vxlan_next_proto
,
255 { "Next Protocol", "vxlan.next_proto",
256 FT_UINT8
, BASE_DEC
, VALS(vxlan_next_protocols
), 0x0,
262 /* Setup protocol subtree array */
263 static int *ett
[] = {
268 /* Register the protocol name and description */
269 proto_vxlan
= proto_register_protocol("Virtual eXtensible Local Area Network", "VXLAN", "vxlan");
271 /* Protocol registered just for Decode As */
272 proto_vxlan_gpe
= proto_register_protocol_in_name_only("Virtual eXtensible Local Area Network (GPE)", "VXLAN (GPE)", "vxlan_gpe", proto_vxlan
, FT_PROTOCOL
);
274 /* Required function calls to register the header fields and subtrees used */
275 proto_register_field_array(proto_vxlan
, hf
, array_length(hf
));
276 proto_register_subtree_array(ett
, array_length(ett
));
277 vxlan_dissector_table
= register_dissector_table("vxlan.next_proto", "VXLAN Next Protocol", proto_vxlan
, FT_UINT8
, BASE_DEC
);
279 /* Register dissector handles */
280 vxlan_handle
= register_dissector("vxlan", dissect_vxlan
, proto_vxlan
);
281 vxlan_gpe_handle
= register_dissector("vxlan_gpe", dissect_vxlan_gpe
, proto_vxlan_gpe
);
285 proto_reg_handoff_vxlan(void)
288 * RFC 7348 Figures 1 and 2, in the Payload section, say
290 * "(Note that the original Ethernet Frame's FCS is not included)"
292 * meaning that the inner Ethernet frame does *not* include an
295 eth_handle
= find_dissector_add_dependency("eth_withoutfcs", proto_vxlan
);
297 dissector_add_uint_range_with_preference("udp.port", UDP_PORT_VXLAN
, vxlan_handle
);
298 dissector_add_uint_with_preference("udp.port", UDP_PORT_VXLAN_GPE
, vxlan_gpe_handle
);
302 * Editor modelines - https://www.wireshark.org/tools/modelines.html
307 * indent-tabs-mode: nil
310 * vi: set shiftwidth=4 tabstop=8 expandtab:
311 * :indentSize=4:tabSize=8:noTabs=true: