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

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