wireshark  1.8.15
About: Wireshark is a network traffic/protocol analyzer (old name was "ethereal"). Old stable release.
  Fossies Dox: wireshark-1.8.15.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups Pages
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  *
25  * Protocol ref:
26  * http://tools.ietf.org/html/draft-mahalingam-dutt-dcops-vxlan-00
27  */
28 
29 
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33 
34 #include <epan/packet.h>
35 
36 
37 
38 static int proto_vxlan = -1;
39 
40 static int hf_vxlan_flags = -1;
41 static int hf_vxlan_flag_b7 = -1;
42 static int hf_vxlan_flag_b6 = -1;
43 static int hf_vxlan_flag_b5 = -1;
44 static int hf_vxlan_flag_b4 = -1;
45 static int hf_vxlan_flag_i = -1;
46 static int hf_vxlan_flag_b2 = -1;
47 static int hf_vxlan_flag_b1 = -1;
48 static int hf_vxlan_flag_b0 = -1;
49 static int hf_vxlan_reserved_24 = -1;
50 static int hf_vxlan_vni = -1;
51 static int hf_vxlan_reserved_8 = -1;
52 
53 
54 static int ett_vxlan = -1;
55 static int ett_vxlan_flgs = -1;
56 
57 
58 static dissector_handle_t eth_handle;
59 
60 static void
61 dissect_vxlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
62 {
63  proto_tree *vxlan_tree, *flg_tree;
64  proto_item *ti, *flg_item;
65  tvbuff_t *next_tvb;
66  int offset = 0;
67 
68  /* Make entry in Protocol column on summary display */
69  col_set_str(pinfo->cinfo, COL_PROTOCOL, "VxLAN");
70 
71  col_clear(pinfo->cinfo, COL_INFO);
72 
73  ti = proto_tree_add_item(tree, proto_vxlan, tvb, offset, -1, ENC_NA);
74  vxlan_tree = proto_item_add_subtree(ti, ett_vxlan);
75 
76 /*
77  0 1 2 3
78  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
79  VXLAN Header:
80  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81  |R|R|R|R|I|R|R|R| Reserved |
82  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83  | VXLAN Network Identifier (VNI) | Reserved |
84  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85 */
86  /* Flags (8 bits) where the I flag MUST be set to 1 for a valid
87  * VXLAN Network ID (VNI). The remaining 7 bits (designated "R") are
88  * reserved fields and MUST be set to zero.
89  */
90  flg_item = proto_tree_add_item(vxlan_tree, hf_vxlan_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
91  flg_tree = proto_item_add_subtree(flg_item, ett_vxlan_flgs);
92 
93  proto_tree_add_item(flg_tree, hf_vxlan_flag_b7, tvb, offset, 1, ENC_BIG_ENDIAN);
94  proto_tree_add_item(flg_tree, hf_vxlan_flag_b6, tvb, offset, 1, ENC_BIG_ENDIAN);
95  proto_tree_add_item(flg_tree, hf_vxlan_flag_b5, tvb, offset, 1, ENC_BIG_ENDIAN);
96  proto_tree_add_item(flg_tree, hf_vxlan_flag_b4, tvb, offset, 1, ENC_BIG_ENDIAN);
97 
98  proto_tree_add_item(flg_tree, hf_vxlan_flag_i, tvb, offset, 1, ENC_BIG_ENDIAN);
99  proto_tree_add_item(flg_tree, hf_vxlan_flag_b2, tvb, offset, 1, ENC_BIG_ENDIAN);
100  proto_tree_add_item(flg_tree, hf_vxlan_flag_b1, tvb, offset, 1, ENC_BIG_ENDIAN);
101  proto_tree_add_item(flg_tree, hf_vxlan_flag_b0, tvb, offset, 1, ENC_BIG_ENDIAN);
102  offset++;
103 
104  proto_tree_add_item(vxlan_tree, hf_vxlan_reserved_24, tvb, offset, 3, ENC_BIG_ENDIAN);
105  offset+=3;
106 
107  proto_tree_add_item(vxlan_tree, hf_vxlan_vni, tvb, offset, 3, ENC_BIG_ENDIAN);
108  offset+=3;
109 
110 
111  proto_tree_add_item(vxlan_tree, hf_vxlan_reserved_8, tvb, offset, 1, ENC_BIG_ENDIAN);
112  offset++;
113 
114  next_tvb = tvb_new_subset_remaining(tvb, offset);
115  call_dissector(eth_handle, next_tvb, pinfo, tree);
116 
117 }
118 
119 
120 /* Register VxLAN with Wireshark */
121 void
123 {
124  static hf_register_info hf[] = {
125  { &hf_vxlan_flags,
126  { "Flags", "vxlan.flags",
127  FT_UINT8, BASE_HEX, NULL, 0x00,
128  NULL, HFILL
129  },
130  },
131  { &hf_vxlan_flag_b7,
132  { "Reserved(R)", "vxlan.flag_b7",
133  FT_BOOLEAN, 8, NULL, 0x80,
134  NULL, HFILL,
135  },
136  },
137  { &hf_vxlan_flag_b6,
138  { "Reserved(R)", "vxlan.flag_b6",
139  FT_BOOLEAN, 8, NULL, 0x40,
140  NULL, HFILL,
141  },
142  },
143  { &hf_vxlan_flag_b5,
144  { "Reserved(R)", "vxlan.flag_b5",
145  FT_BOOLEAN, 8, NULL, 0x20,
146  NULL, HFILL,
147  },
148  },
149  { &hf_vxlan_flag_b4,
150  { "Reserved(R)", "vxlan.flag_b4",
151  FT_BOOLEAN, 8, NULL, 0x10,
152  NULL, HFILL,
153  },
154  },
155  { &hf_vxlan_flag_i,
156  { "VXLAN Network ID(VNI)", "vxlan.flag_i",
158  NULL, HFILL,
159  },
160  },
161  { &hf_vxlan_flag_b2,
162  { "Reserved(R)", "vxlan.flag_b2",
163  FT_BOOLEAN, 8, NULL, 0x10,
164  NULL, HFILL,
165  },
166  },
167  { &hf_vxlan_flag_b1,
168  { "Reserved(R)", "vxlan.flag_b1",
169  FT_BOOLEAN, 8, NULL, 0x10,
170  NULL, HFILL,
171  },
172  },
173  { &hf_vxlan_flag_b0,
174  { "Reserved(R)", "vxlan.flag_b0",
175  FT_BOOLEAN, 8, NULL, 0x10,
176  NULL, HFILL,
177  },
178  },
179  { &hf_vxlan_reserved_24,
180  { "Reserved", "vxlan.reserved24",
181  FT_UINT24, BASE_HEX, NULL, 0x00,
182  NULL, HFILL
183  },
184  },
185  { &hf_vxlan_vni,
186  { "VXLAN Network Identifier (VNI)", "vxlan.vni",
187  FT_UINT24, BASE_DEC, NULL, 0x00,
188  NULL, HFILL
189  },
190  },
191  { &hf_vxlan_reserved_8,
192  { "Reserved", "vxlan.reserved8",
193  FT_UINT8, BASE_DEC, NULL, 0x00,
194  NULL, HFILL
195  },
196  },
197  };
198 
199  /* Setup protocol subtree array */
200  static gint *ett[] = {
201  &ett_vxlan,
202  &ett_vxlan_flgs,
203  };
204 
205  /* Register the protocol name and description */
206  proto_vxlan = proto_register_protocol("Virtual eXtensible Local Area Network",
207  "VXLAN", "vxlan");
208 
209  /* Required function calls to register the header fields and subtrees used */
210  proto_register_field_array(proto_vxlan, hf, array_length(hf));
212 
213 
214 }
215 
216 void
218 {
219  dissector_handle_t vxlan_handle;
220 
221  eth_handle = find_dissector("eth");
222 
223  vxlan_handle = create_dissector_handle(dissect_vxlan, proto_vxlan);
224  dissector_add_handle("udp.port", vxlan_handle); /* For 'Decode As' */
225 }
226 
227 /*
228  * Editor modelines - http://www.wireshark.org/tools/modelines.html
229  *
230  * Local variables:
231  * c-basic-offset: 4
232  * tab-width: 8
233  * indent-tabs-mode: nil
234  * End:
235  *
236  * vi: set shiftwidth=4 tabstop=8 expandtab:
237  * :indentSize=4:tabSize=8:noTabs=true:
238  */
239 
240 
void col_set_str(column_info *cinfo, const gint el, const gchar *str)
Definition: column-utils.c:475
dissector_handle_t find_dissector(const char *name)
Definition: packet.c:1895
column_info * cinfo
Definition: packet_info.h:50
void proto_register_subtree_array(gint *const *indices, const int num_indices)
Definition: proto.c:5164
#define ENC_NA
Definition: proto.h:305
void dissector_add_handle(const char *name, dissector_handle_t handle)
Definition: packet.c:1247
#define TFS(x)
Definition: proto.h:71
void proto_reg_handoff_vxlan(void)
Definition: packet-vxlan.c:217
const true_false_string tfs_present_not_present
Definition: tfs.c:53
#define ENC_BIG_ENDIAN
Definition: proto.h:230
int call_dissector(dissector_handle_t handle, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
Definition: packet.c:1997
#define HFILL
Definition: proto.h:375
void proto_register_vxlan(void)
Definition: packet-vxlan.c:122
void proto_register_field_array(const int parent, hf_register_info *hf, const int num_records)
Definition: proto.c:4745
int proto_register_protocol(const char *name, const char *short_name, const char *filter_name)
Definition: proto.c:4425
void col_clear(column_info *cinfo, const gint el)
Definition: column-utils.c:147
proto_tree * proto_item_add_subtree(proto_item *pi, const gint idx)
Definition: proto.c:4286
#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:1771
dissector_handle_t create_dissector_handle(dissector_t dissector, const int proto)
Definition: packet.c:1903
tvbuff_t * tvb_new_subset_remaining(tvbuff_t *backing, const gint backing_offset)
Definition: tvbuff.c:569