epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-vxlan.c
blob8206f687f8fce72df4bbdb4c1aa8a7f46d5196b0
1 /* packet-vxlan.c
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
16 #include "config.h"
18 #include <epan/packet.h>
19 #include <epan/tfs.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;
51 static int ett_vxlan;
52 static int ett_vxlan_flags;
54 static int * const flags_fields[] = {
55 &hf_vxlan_flag_g,
56 &hf_vxlan_flag_i,
57 &hf_vxlan_flag_d,
58 &hf_vxlan_flag_a,
59 &hf_vxlan_flags_reserved,
60 NULL
63 static int * const gpe_flags_fields[] = {
64 &hf_vxlan_gpe_flag_ver,
65 &hf_vxlan_gpe_flag_i,
66 &hf_vxlan_gpe_flag_p,
67 &hf_vxlan_gpe_flag_o,
68 &hf_vxlan_gpe_flag_reserved,
69 NULL
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"},
79 { 0, NULL }
82 static dissector_handle_t eth_handle;
83 static dissector_table_t vxlan_dissector_table;
85 static int
86 dissect_vxlan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int is_gpe)
88 proto_tree *vxlan_tree;
89 proto_item *ti;
90 tvbuff_t *next_tvb;
91 int offset = 0;
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);
101 if(is_gpe) {
102 proto_tree_add_bitmask(vxlan_tree, tvb, offset, hf_vxlan_gpe_flags, ett_vxlan_flags, gpe_flags_fields, ENC_BIG_ENDIAN);
103 offset += 1;
105 proto_tree_add_item(vxlan_tree, hf_vxlan_gpe_reserved_16, tvb, offset, 2, ENC_BIG_ENDIAN);
106 offset += 2;
108 proto_tree_add_item_ret_uint(vxlan_tree, hf_vxlan_next_proto, tvb, offset, 1, ENC_BIG_ENDIAN, &vxlan_next_proto);
109 offset += 1;
110 } else {
111 proto_tree_add_bitmask(vxlan_tree, tvb, offset, hf_vxlan_flags, ett_vxlan_flags, flags_fields, ENC_BIG_ENDIAN);
112 offset += 2;
114 proto_tree_add_item(vxlan_tree, hf_vxlan_gbp, tvb, offset, 2, ENC_BIG_ENDIAN);
115 offset += 2;
118 proto_tree_add_item(vxlan_tree, hf_vxlan_vni, tvb, offset, 3, ENC_BIG_ENDIAN);
119 offset += 3;
121 proto_tree_add_item(vxlan_tree, hf_vxlan_reserved_8, tvb, offset, 1, ENC_BIG_ENDIAN);
122 offset += 1;
124 next_tvb = tvb_new_subset_remaining(tvb, offset);
126 if(is_gpe){
127 if(!dissector_try_uint(vxlan_dissector_table, vxlan_next_proto, next_tvb, pinfo, tree)) {
128 call_data_dissector(next_tvb, pinfo, tree);
130 } else {
131 call_dissector(eth_handle, next_tvb, pinfo, tree);
134 return tvb_captured_length(tvb);
137 static int
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);
144 static int
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 */
154 void
155 proto_register_vxlan(void)
157 static hf_register_info hf[] = {
158 { &hf_vxlan_flags,
159 { "Flags", "vxlan.flags",
160 FT_UINT16, BASE_HEX, NULL, 0x00,
161 NULL, HFILL
164 { &hf_vxlan_gpe_flags,
165 { "Flags", "vxlan.flags",
166 FT_UINT8, BASE_HEX, NULL, 0x00,
167 NULL, HFILL
170 { &hf_vxlan_flags_reserved,
171 { "Reserved(R)", "vxlan.flags_reserved",
172 FT_UINT16, BASE_HEX, NULL, 0x77b7,
173 NULL, HFILL,
176 { &hf_vxlan_gpe_flag_reserved,
177 { "Reserved(R)", "vxlan.flags_reserved",
178 FT_UINT8, BASE_DEC, NULL, 0xC2,
179 NULL, HFILL,
182 { &hf_vxlan_flag_g,
183 { "GBP Extension", "vxlan.flag_g",
184 FT_BOOLEAN, 16, TFS(&tfs_defined_not_defined), 0x8000,
185 NULL, HFILL,
188 { &hf_vxlan_flag_i,
189 { "VXLAN Network ID (VNI)", "vxlan.flag_i",
190 FT_BOOLEAN, 16, NULL, 0x0800,
191 NULL, HFILL,
194 { &hf_vxlan_flag_d,
195 { "Don't Learn", "vxlan.flag_d",
196 FT_BOOLEAN, 16, NULL, 0x0040,
197 NULL, HFILL,
200 { &hf_vxlan_flag_a,
201 { "Policy Applied", "vxlan.flag_a",
202 FT_BOOLEAN, 16, NULL, 0x0008,
203 NULL, HFILL,
206 { &hf_vxlan_gpe_flag_ver,
207 { "Version", "vxlan.ver",
208 FT_UINT8, BASE_DEC, NULL, 0x30,
209 NULL, HFILL,
212 { &hf_vxlan_gpe_flag_i,
213 { "Instance", "vxlan.i_bit",
214 FT_UINT8, BASE_DEC, NULL, 0x08,
215 NULL, HFILL,
218 { &hf_vxlan_gpe_flag_p,
219 { "Next Protocol Bit", "vxlan.p_bit",
220 FT_UINT8, BASE_DEC, NULL, 0x04,
221 NULL, HFILL,
224 { &hf_vxlan_gpe_flag_o,
225 { "OAM bit", "vxlan.o_bit",
226 FT_UINT8, BASE_DEC, NULL, 0x01,
227 NULL, HFILL,
230 { &hf_vxlan_gbp,
231 { "Group Policy ID", "vxlan.gbp",
232 FT_UINT16, BASE_DEC, NULL, 0x0,
233 NULL, HFILL
236 { &hf_vxlan_vni,
237 { "VXLAN Network Identifier (VNI)", "vxlan.vni",
238 FT_UINT24, BASE_DEC, NULL, 0x0,
239 NULL, HFILL
242 { &hf_vxlan_reserved_8,
243 { "Reserved", "vxlan.reserved8",
244 FT_UINT8, BASE_DEC, NULL, 0x0,
245 NULL, HFILL
248 { &hf_vxlan_gpe_reserved_16,
249 { "Reserved", "vxlan.reserved_16",
250 FT_UINT16, BASE_DEC, NULL, 0x0,
251 NULL, HFILL
254 { &hf_vxlan_next_proto,
255 { "Next Protocol", "vxlan.next_proto",
256 FT_UINT8, BASE_DEC, VALS(vxlan_next_protocols), 0x0,
257 NULL, HFILL
262 /* Setup protocol subtree array */
263 static int *ett[] = {
264 &ett_vxlan,
265 &ett_vxlan_flags,
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);
284 void
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
293 * FCS.
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
304 * Local variables:
305 * c-basic-offset: 4
306 * tab-width: 8
307 * indent-tabs-mode: nil
308 * End:
310 * vi: set shiftwidth=4 tabstop=8 expandtab:
311 * :indentSize=4:tabSize=8:noTabs=true: