wireshark  1.10.12
About: Wireshark is a network protocol analyzer. It lets you capture and interactively browse the traffic running on a computer network. Old stable release.
  Fossies Dox: wireshark-1.10.12.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

packet-vxlan.c
Go to the documentation of this file.
1 /* packet-vxlan.c
2  *
3  * Routines for Virtual eXtensible Local Area Network (VXLAN) packet dissection
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * Protocol ref:
26  * http://tools.ietf.org/html/draft-mahalingam-dutt-dcops-vxlan-00
27  */
28 
29 
30 #include "config.h"
31 
32 #include <epan/packet.h>
33 
34 
35 
36 static int proto_vxlan = -1;
37 
38 static int hf_vxlan_flags = -1;
39 static int hf_vxlan_flag_b7 = -1;
40 static int hf_vxlan_flag_b6 = -1;
41 static int hf_vxlan_flag_b5 = -1;
42 static int hf_vxlan_flag_b4 = -1;
43 static int hf_vxlan_flag_i = -1;
44 static int hf_vxlan_flag_b2 = -1;
45 static int hf_vxlan_flag_b1 = -1;
46 static int hf_vxlan_flag_b0 = -1;
47 static int hf_vxlan_reserved_24 = -1;
48 static int hf_vxlan_vni = -1;
49 static int hf_vxlan_reserved_8 = -1;
50 
51 
52 static int ett_vxlan = -1;
53 static int ett_vxlan_flgs = -1;
54 
55 
56 static dissector_handle_t eth_handle;
57 
58 static void
59 dissect_vxlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
60 {
61  proto_tree *vxlan_tree, *flg_tree;
62  proto_item *ti, *flg_item;
63  tvbuff_t *next_tvb;
64  int offset = 0;
65 
66  /* Make entry in Protocol column on summary display */
67  col_set_str(pinfo->cinfo, COL_PROTOCOL, "VxLAN");
68 
69  col_clear(pinfo->cinfo, COL_INFO);
70 
71  ti = proto_tree_add_item(tree, proto_vxlan, tvb, offset, -1, ENC_NA);
72  vxlan_tree = proto_item_add_subtree(ti, ett_vxlan);
73 
74 /*
75  0 1 2 3
76  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
77  VXLAN Header:
78  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79  |R|R|R|R|I|R|R|R| Reserved |
80  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81  | VXLAN Network Identifier (VNI) | Reserved |
82  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 */
84  /* Flags (8 bits) where the I flag MUST be set to 1 for a valid
85  * VXLAN Network ID (VNI). The remaining 7 bits (designated "R") are
86  * reserved fields and MUST be set to zero.
87  */
88  flg_item = proto_tree_add_item(vxlan_tree, hf_vxlan_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
89  flg_tree = proto_item_add_subtree(flg_item, ett_vxlan_flgs);
90 
91  proto_tree_add_item(flg_tree, hf_vxlan_flag_b7, tvb, offset, 1, ENC_BIG_ENDIAN);
92  proto_tree_add_item(flg_tree, hf_vxlan_flag_b6, tvb, offset, 1, ENC_BIG_ENDIAN);
93  proto_tree_add_item(flg_tree, hf_vxlan_flag_b5, tvb, offset, 1, ENC_BIG_ENDIAN);
94  proto_tree_add_item(flg_tree, hf_vxlan_flag_b4, tvb, offset, 1, ENC_BIG_ENDIAN);
95 
96  proto_tree_add_item(flg_tree, hf_vxlan_flag_i, tvb, offset, 1, ENC_BIG_ENDIAN);
97  proto_tree_add_item(flg_tree, hf_vxlan_flag_b2, tvb, offset, 1, ENC_BIG_ENDIAN);
98  proto_tree_add_item(flg_tree, hf_vxlan_flag_b1, tvb, offset, 1, ENC_BIG_ENDIAN);
99  proto_tree_add_item(flg_tree, hf_vxlan_flag_b0, tvb, offset, 1, ENC_BIG_ENDIAN);
100  offset++;
101 
102  proto_tree_add_item(vxlan_tree, hf_vxlan_reserved_24, tvb, offset, 3, ENC_BIG_ENDIAN);
103  offset+=3;
104 
105  proto_tree_add_item(vxlan_tree, hf_vxlan_vni, tvb, offset, 3, ENC_BIG_ENDIAN);
106  offset+=3;
107 
108 
109  proto_tree_add_item(vxlan_tree, hf_vxlan_reserved_8, tvb, offset, 1, ENC_BIG_ENDIAN);
110  offset++;
111 
112  next_tvb = tvb_new_subset_remaining(tvb, offset);
113  call_dissector(eth_handle, next_tvb, pinfo, tree);
114 
115 }
116 
117 
118 /* Register VxLAN with Wireshark */
119 void
121 {
122  static hf_register_info hf[] = {
123  { &hf_vxlan_flags,
124  { "Flags", "vxlan.flags",
125  FT_UINT8, BASE_HEX, NULL, 0x00,
126  NULL, HFILL
127  },
128  },
129  { &hf_vxlan_flag_b7,
130  { "Reserved(R)", "vxlan.flag_b7",
131  FT_BOOLEAN, 8, NULL, 0x80,
132  NULL, HFILL,
133  },
134  },
135  { &hf_vxlan_flag_b6,
136  { "Reserved(R)", "vxlan.flag_b6",
137  FT_BOOLEAN, 8, NULL, 0x40,
138  NULL, HFILL,
139  },
140  },
141  { &hf_vxlan_flag_b5,
142  { "Reserved(R)", "vxlan.flag_b5",
143  FT_BOOLEAN, 8, NULL, 0x20,
144  NULL, HFILL,
145  },
146  },
147  { &hf_vxlan_flag_b4,
148  { "Reserved(R)", "vxlan.flag_b4",
149  FT_BOOLEAN, 8, NULL, 0x10,
150  NULL, HFILL,
151  },
152  },
153  { &hf_vxlan_flag_i,
154  { "VXLAN Network ID(VNI)", "vxlan.flag_i",
156  NULL, HFILL,
157  },
158  },
159  { &hf_vxlan_flag_b2,
160  { "Reserved(R)", "vxlan.flag_b2",
161  FT_BOOLEAN, 8, NULL, 0x10,
162  NULL, HFILL,
163  },
164  },
165  { &hf_vxlan_flag_b1,
166  { "Reserved(R)", "vxlan.flag_b1",
167  FT_BOOLEAN, 8, NULL, 0x10,
168  NULL, HFILL,
169  },
170  },
171  { &hf_vxlan_flag_b0,
172  { "Reserved(R)", "vxlan.flag_b0",
173  FT_BOOLEAN, 8, NULL, 0x10,
174  NULL, HFILL,
175  },
176  },
177  { &hf_vxlan_reserved_24,
178  { "Reserved", "vxlan.reserved24",
179  FT_UINT24, BASE_HEX, NULL, 0x00,
180  NULL, HFILL
181  },
182  },
183  { &hf_vxlan_vni,
184  { "VXLAN Network Identifier (VNI)", "vxlan.vni",
185  FT_UINT24, BASE_DEC, NULL, 0x00,
186  NULL, HFILL
187  },
188  },
189  { &hf_vxlan_reserved_8,
190  { "Reserved", "vxlan.reserved8",
191  FT_UINT8, BASE_DEC, NULL, 0x00,
192  NULL, HFILL
193  },
194  },
195  };
196 
197  /* Setup protocol subtree array */
198  static gint *ett[] = {
199  &ett_vxlan,
200  &ett_vxlan_flgs,
201  };
202 
203  /* Register the protocol name and description */
204  proto_vxlan = proto_register_protocol("Virtual eXtensible Local Area Network",
205  "VXLAN", "vxlan");
206 
207  /* Required function calls to register the header fields and subtrees used */
208  proto_register_field_array(proto_vxlan, hf, array_length(hf));
210 
211 
212 }
213 
214 void
216 {
217  dissector_handle_t vxlan_handle;
218 
219  eth_handle = find_dissector("eth");
220 
221  vxlan_handle = create_dissector_handle(dissect_vxlan, proto_vxlan);
222  dissector_add_handle("udp.port", vxlan_handle); /* For 'Decode As' */
223 }
224 
225 /*
226  * Editor modelines - http://www.wireshark.org/tools/modelines.html
227  *
228  * Local variables:
229  * c-basic-offset: 4
230  * tab-width: 8
231  * indent-tabs-mode: nil
232  * End:
233  *
234  * vi: set shiftwidth=4 tabstop=8 expandtab:
235  * :indentSize=4:tabSize=8:noTabs=true:
236  */
237 
238 
void col_set_str(column_info *cinfo, const gint el, const gchar *str)
Definition: column-utils.c:523
dissector_handle_t find_dissector(const char *name)
Definition: packet.c:1966
column_info * cinfo
Definition: packet_info.h:50
void proto_register_subtree_array(gint *const *indices, const int num_indices)
Definition: proto.c:5219
#define ENC_NA
Definition: proto.h:306
void dissector_add_handle(const char *name, dissector_handle_t handle)
Definition: packet.c:1292
#define TFS(x)
Definition: proto.h:72
void proto_reg_handoff_vxlan(void)
Definition: packet-vxlan.c:215
const true_false_string tfs_present_not_present
Definition: tfs.c:52
#define ENC_BIG_ENDIAN
Definition: proto.h:231
int call_dissector(dissector_handle_t handle, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
Definition: packet.c:2088
#define HFILL
Definition: proto.h:376
void proto_register_vxlan(void)
Definition: packet-vxlan.c:120
void proto_register_field_array(const int parent, hf_register_info *hf, const int num_records)
Definition: proto.c:4800
int proto_register_protocol(const char *name, const char *short_name, const char *filter_name)
Definition: proto.c:4475
void col_clear(column_info *cinfo, const gint el)
Definition: column-utils.c:195
proto_tree * proto_item_add_subtree(proto_item *pi, const gint idx)
Definition: proto.c:4336
#define array_length(x)
proto_item * proto_tree_add_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb, const gint start, gint length, const guint encoding)
Definition: proto.c:1823
dissector_handle_t create_dissector_handle(dissector_t dissector, const int proto)
Definition: packet.c:1974
tvbuff_t * tvb_new_subset_remaining(tvbuff_t *backing, const gint backing_offset)
Definition: tvbuff.c:494