wireshark  1.99.8
About: Wireshark is a network protocol analyzer. It lets you capture and interactively browse the traffic running on a computer network. Development release.
  Fossies Dox: wireshark-1.99.8.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  * 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 #include <epan/tfs.h>
32 
33 #define UDP_PORT_VXLAN 4789
34 
35 void proto_register_vxlan(void);
36 void proto_reg_handoff_vxlan(void);
37 
38 static int proto_vxlan = -1;
39 
40 static int hf_vxlan_flags = -1;
41 static int hf_vxlan_flags_reserved = -1;
42 static int hf_vxlan_flag_a = -1;
43 static int hf_vxlan_flag_d = -1;
44 static int hf_vxlan_flag_i = -1;
45 static int hf_vxlan_flag_g = -1;
46 static int hf_vxlan_gbp = -1;
47 static int hf_vxlan_vni = -1;
48 static int hf_vxlan_reserved_8 = -1;
49 
50 
51 static int ett_vxlan = -1;
52 static int ett_vxlan_flgs = -1;
53 
54 static const int *flags_fields[] = {
55  &hf_vxlan_flag_g,
56  &hf_vxlan_flag_d,
57  &hf_vxlan_flag_i,
58  &hf_vxlan_flag_a,
59  &hf_vxlan_flags_reserved,
60  NULL
61  };
62 
63 static dissector_handle_t eth_handle;
64 
65 static void
66 dissect_vxlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
67 {
68  proto_tree *vxlan_tree;
69  proto_item *ti;
70  tvbuff_t *next_tvb;
71  int offset = 0;
72 
73  /* Make entry in Protocol column on summary display */
74  col_set_str(pinfo->cinfo, COL_PROTOCOL, "VxLAN");
75 
76  col_clear(pinfo->cinfo, COL_INFO);
77 
78  ti = proto_tree_add_item(tree, proto_vxlan, tvb, offset, -1, ENC_NA);
79  vxlan_tree = proto_item_add_subtree(ti, ett_vxlan);
80 
81 /*
82  0 1 2 3
83  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
84  VXLAN Header:
85  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
86  |G|R|R|R|I|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
87  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88  | VXLAN Network Identifier (VNI) | Reserved |
89  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 */
91  /* Flags (16 bits) where the I flag MUST be set to 1 for a valid
92  * VXLAN Network ID (VNI). The remaining 12 bits (designated "R") are
93  * reserved fields and MUST be set to zero.
94  */
95  proto_tree_add_bitmask(vxlan_tree, tvb, offset, hf_vxlan_flags,
96  ett_vxlan_flgs, flags_fields, ENC_BIG_ENDIAN);
97  offset+=2;
98 
99  proto_tree_add_item(vxlan_tree, hf_vxlan_gbp, tvb, offset, 2, ENC_BIG_ENDIAN);
100  offset+=2;
101 
102  proto_tree_add_item(vxlan_tree, hf_vxlan_vni, tvb, offset, 3, ENC_BIG_ENDIAN);
103  offset+=3;
104 
105 
106  proto_tree_add_item(vxlan_tree, hf_vxlan_reserved_8, tvb, offset, 1, ENC_BIG_ENDIAN);
107  offset++;
108 
109  next_tvb = tvb_new_subset_remaining(tvb, offset);
110  call_dissector(eth_handle, next_tvb, pinfo, tree);
111 
112 }
113 
114 
115 /* Register VxLAN with Wireshark */
116 void
118 {
119  static hf_register_info hf[] = {
120  { &hf_vxlan_flags,
121  { "Flags", "vxlan.flags",
122  FT_UINT16, BASE_HEX, NULL, 0x00,
123  NULL, HFILL
124  },
125  },
126  { &hf_vxlan_flags_reserved,
127  { "Reserved(R)", "vxlan.flags_reserved",
128  FT_BOOLEAN, 16, NULL, 0x77b7,
129  NULL, HFILL,
130  },
131  },
132  { &hf_vxlan_flag_g,
133  { "GBP Extension", "vxlan.flag_g",
134  FT_BOOLEAN, 16, TFS(&tfs_defined_not_defined), 0x8000,
135  NULL, HFILL,
136  },
137  },
138  { &hf_vxlan_flag_i,
139  { "VXLAN Network ID (VNI)", "vxlan.flag_i",
140  FT_BOOLEAN, 16, NULL, 0x0800,
141  NULL, HFILL,
142  },
143  },
144  { &hf_vxlan_flag_d,
145  { "Don't Learn", "vxlan.flag_d",
146  FT_BOOLEAN, 16, NULL, 0x0040,
147  NULL, HFILL,
148  },
149  },
150  { &hf_vxlan_flag_a,
151  { "Policy Applied", "vxlan.flag_a",
152  FT_BOOLEAN, 16, NULL, 0x0008,
153  NULL, HFILL,
154  },
155  },
156  { &hf_vxlan_gbp,
157  { "Group Policy ID", "vxlan.gbp",
158  FT_UINT16, BASE_DEC, NULL, 0x00,
159  NULL, HFILL
160  },
161  },
162  { &hf_vxlan_vni,
163  { "VXLAN Network Identifier (VNI)", "vxlan.vni",
164  FT_UINT24, BASE_DEC, NULL, 0x00,
165  NULL, HFILL
166  },
167  },
168  { &hf_vxlan_reserved_8,
169  { "Reserved", "vxlan.reserved8",
170  FT_UINT8, BASE_DEC, NULL, 0x00,
171  NULL, HFILL
172  },
173  },
174  };
175 
176  /* Setup protocol subtree array */
177  static gint *ett[] = {
178  &ett_vxlan,
179  &ett_vxlan_flgs,
180  };
181 
182  /* Register the protocol name and description */
183  proto_vxlan = proto_register_protocol("Virtual eXtensible Local Area Network",
184  "VXLAN", "vxlan");
185 
186  /* Required function calls to register the header fields and subtrees used */
187  proto_register_field_array(proto_vxlan, hf, array_length(hf));
189 
190 
191 }
192 
193 void
195 {
196  dissector_handle_t vxlan_handle;
197 
198  eth_handle = find_dissector("eth");
199 
200  vxlan_handle = create_dissector_handle(dissect_vxlan, proto_vxlan);
201  dissector_add_uint("udp.port", UDP_PORT_VXLAN, vxlan_handle);
202  dissector_add_for_decode_as("udp.port", vxlan_handle);
203 
204 }
205 
206 /*
207  * Editor modelines - http://www.wireshark.org/tools/modelines.html
208  *
209  * Local variables:
210  * c-basic-offset: 4
211  * tab-width: 8
212  * indent-tabs-mode: nil
213  * End:
214  *
215  * vi: set shiftwidth=4 tabstop=8 expandtab:
216  * :indentSize=4:tabSize=8:noTabs=true:
217  */
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:2269
void col_set_str(column_info *cinfo, const gint el, const gchar *str)
Definition: column-utils.c:618
#define TFS(x)
Definition: proto.h:85
proto_item * proto_tree_add_bitmask(proto_tree *parent_tree, tvbuff_t *tvb, const guint offset, const int hf_hdr, const gint ett, const int **fields, const guint encoding)
Definition: proto.c:8293
#define UDP_PORT_VXLAN
Definition: packet-vxlan.c:33
void proto_register_subtree_array(gint *const *indices, const int num_indices)
Definition: proto.c:6167
void proto_register_field_array(const int parent, hf_register_info *hf, const int num_records)
Definition: proto.c:5573
const true_false_string tfs_defined_not_defined
Definition: tfs.c:89
void proto_reg_handoff_vxlan(void)
Definition: packet-vxlan.c:194
struct epan_column_info * cinfo
Definition: packet_info.h:51
void dissector_add_for_decode_as(const char *name, dissector_handle_t handle)
Definition: packet.c:1563
proto_tree * proto_item_add_subtree(proto_item *pi, const gint idx)
Definition: proto.c:4994
dissector_handle_t create_dissector_handle(dissector_t dissector, const int proto)
Definition: packet.c:2418
void proto_register_vxlan(void)
Definition: packet-vxlan.c:117
proto_item * ti
Definition: packet-wsp.c:2839
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:2401
void dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t handle)
Definition: packet.c:897
void col_clear(column_info *cinfo, const gint el)
Definition: column-utils.c:227
#define ENC_NA
Definition: proto.h:452
#define array_length(x)
#define HFILL
Definition: proto.h:576
int call_dissector(dissector_handle_t handle, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
Definition: packet.c:2537
tvbuff_t * tvb
Definition: packet-wsp.c:2834
int proto_register_protocol(const char *name, const char *short_name, const char *filter_name)
Definition: proto.c:5146
#define ENC_BIG_ENDIAN
Definition: proto.h:356