epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-gre.c
blobf884c33d8f584544df272ce3da8cbbd39ccd9899
1 /* packet-gre.c
2 * Routines for the Generic Routing Encapsulation (GRE) protocol
3 * Brad Robel-Forrest <brad.robel-forrest@watchguard.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/tfs.h>
16 #include <epan/capture_dissectors.h>
17 #include <epan/etypes.h>
18 #include <epan/in_cksum.h>
19 #include <epan/expert.h>
20 #include <epan/ipproto.h>
21 #include <epan/llcsaps.h>
22 #include "packet-gre.h"
23 #include "packet-wccp.h"
25 #include <epan/decode_as.h>
27 #define GRE_IN_UDP_PORT 4754
29 void proto_register_gre(void);
30 void proto_reg_handoff_gre(void);
32 static dissector_handle_t gre_handle;
33 static capture_dissector_handle_t gre_cap_handle;
37 * See RFC 1701 "Generic Routing Encapsulation (GRE)", RFC 1702
38 * "Generic Routing Encapsulation over IPv4 networks", RFC 2637
39 * "Point-to-Point Tunneling Protocol (PPTP)", RFC 2784 "Generic
40 * Routing Encapsulation (GRE)", RFC 2890 "Key and Sequence
41 * Number Extensions to GRE", RFC 8086 "GRE-in-UDP Encapsulation",
42 * and draft-ietf-mpls-in-ip-or-gre-07.txt
43 * "Encapsulating MPLS in IP or Generic Routing Encapsulation (GRE)".
46 static int proto_gre;
47 static int hf_gre_proto;
48 static int hf_gre_flags_and_version;
49 static int hf_gre_flags_checksum;
50 static int hf_gre_flags_routing;
51 static int hf_gre_flags_key;
52 static int hf_gre_flags_sequence_number;
53 static int hf_gre_flags_strict_source_route;
54 static int hf_gre_flags_recursion_control;
55 static int hf_gre_flags_ack;
56 static int hf_gre_flags_reserved_ppp;
57 static int hf_gre_flags_reserved;
58 static int hf_gre_flags_version;
59 static int hf_gre_checksum;
60 static int hf_gre_checksum_status;
61 static int hf_gre_offset;
62 static int hf_gre_key;
63 static int hf_gre_key_payload_length;
64 static int hf_gre_key_call_id;
65 static int hf_gre_sequence_number;
66 static int hf_gre_ack_number;
67 static int hf_gre_routing;
68 static int hf_gre_routing_address_family;
69 static int hf_gre_routing_sre_length;
70 static int hf_gre_routing_sre_offset;
71 static int hf_gre_routing_information;
73 /* Ref 3GPP2 A.S0012-C v2.0 and A.S0008-A v1.0 */
74 static int hf_gre_3gpp2_attrib;
75 static int hf_gre_3gpp2_attrib_id;
76 static int hf_gre_3gpp2_attrib_length;
77 static int hf_gre_3gpp2_sdi;
78 static int hf_gre_3gpp2_fci;
79 static int hf_gre_3gpp2_di;
80 static int hf_gre_3gpp2_flow_disc;
81 static int hf_gre_3gpp2_seg;
83 static int hf_gre_wccp_redirect_header;
84 static int hf_gre_wccp_dynamic_service;
85 static int hf_gre_wccp_alternative_bucket_used;
86 static int hf_gre_wccp_redirect_header_valid;
87 static int hf_gre_wccp_service_id;
88 static int hf_gre_wccp_alternative_bucket;
89 static int hf_gre_wccp_primary_bucket;
91 static int ett_gre;
92 static int ett_gre_flags;
93 static int ett_gre_routing;
94 static int ett_gre_wccp2_redirect_header;
95 static int ett_3gpp2_attribs;
96 static int ett_3gpp2_attr;
98 static expert_field ei_gre_checksum_incorrect;
100 static dissector_table_t gre_dissector_table;
102 static dissector_table_t gre_subdissector_table;
104 static const value_string gre_version[] = {
105 { 0, "GRE" }, /* [RFC2784] */
106 { 1, "Enhanced GRE" }, /* [RFC2637] */
107 { 0, NULL}
109 const value_string gre_typevals[] = {
110 { GRE_KEEPALIVE, "Possible GRE keepalive packet" },
111 { ETHERTYPE_PPP, "PPP" },
112 { ETHERTYPE_IP, "IP" },
113 { ETHERTYPE_ARP, "ARP" },
114 { SAP_OSINL5, "OSI"},
115 { GRE_WCCP, "WCCP"},
116 { GRE_CISCO_CDP, "CDP (Cisco)"},
117 { GRE_NHRP, "NHRP"},
118 { GRE_ERSPAN_88BE, "ERSPAN"},
119 { GRE_ERSPAN_22EB, "ERSPAN III"},
120 { GRE_MIKROTIK_EOIP, "MIKROTIK EoIP"},
121 { GRE_AIROHIVE, "AIROHIVE AP AP"},
122 { ETHERTYPE_IPX, "IPX"},
123 { ETHERTYPE_ETHBRIDGE, "Transparent Ethernet bridging" },
124 { ETHERTYPE_RAW_FR, "Frame Relay"},
125 { ETHERTYPE_IPv6, "IPv6" },
126 { ETHERTYPE_MPLS, "MPLS label switched packet" },
127 { ETHERTYPE_NSH, "Network Service Header" },
128 { ETHERTYPE_CDMA2000_A10_UBS,"CDMA2000 A10 Unstructured byte stream" },
129 { ETHERTYPE_3GPP2, "CDMA2000 A10 3GPP2 Packet" },
130 { ETHERTYPE_CMD, "CiscoMetaData" },
131 { GRE_GREBONDING, "Huawei GRE bonding" },
132 { GRE_ARUBA_8200, "ARUBA WLAN" },
133 { GRE_ARUBA_8210, "ARUBA WLAN" },
134 { GRE_ARUBA_8220, "ARUBA WLAN" },
135 { GRE_ARUBA_8230, "ARUBA WLAN" },
136 { GRE_ARUBA_8240, "ARUBA WLAN" },
137 { GRE_ARUBA_8250, "ARUBA WLAN" },
138 { GRE_ARUBA_8260, "ARUBA WLAN" },
139 { GRE_ARUBA_8270, "ARUBA WLAN" },
140 { GRE_ARUBA_8280, "ARUBA WLAN" },
141 { GRE_ARUBA_8290, "ARUBA WLAN" },
142 { GRE_ARUBA_82A0, "ARUBA WLAN" },
143 { GRE_ARUBA_82B0, "ARUBA WLAN" },
144 { GRE_ARUBA_82C0, "ARUBA WLAN" },
145 { GRE_ARUBA_82D0, "ARUBA WLAN" },
146 { GRE_ARUBA_82E0, "ARUBA WLAN" },
147 { GRE_ARUBA_82F0, "ARUBA WLAN" },
148 { GRE_ARUBA_8300, "ARUBA WLAN" },
149 { GRE_ARUBA_8310, "ARUBA WLAN" },
150 { GRE_ARUBA_8320, "ARUBA WLAN" },
151 { GRE_ARUBA_8330, "ARUBA WLAN" },
152 { GRE_ARUBA_8340, "ARUBA WLAN" },
153 { GRE_ARUBA_8350, "ARUBA WLAN" },
154 { GRE_ARUBA_8360, "ARUBA WLAN" },
155 { GRE_ARUBA_8370, "ARUBA WLAN" },
156 { GRE_ARUBA_9000, "ARUBA WLAN" },
157 { 0, NULL }
160 #define ID_3GPP2_SDI_FLAG 1
161 #define ID_3GPP2_FLOW_CTRL 2
162 #define ID_3GPP2_FLOW_DISCRIMINATOR 3
163 #define ID_3GPP2_SEG 4
165 static const value_string gre_3gpp2_seg_vals[] = {
166 { 0x00, "Packet Started" },
167 { 0x01, "Packet continued" },
168 { 0x02, "Packet Ended" },
169 { 0, NULL }
171 /* 3GPP2 A.S0012-C v2.0
172 * 2.6.1 GRE Attributes
174 static const value_string gre_3gpp2_attrib_id_vals[] = {
175 { 0x01, "1x SDB/HRPD DOS Indicator" },
176 { 0x02, "Flow Control Indication" },
177 /* A.S0008-A v1.0 */
178 { 0x03, "IP Flow Discriminator" },
179 { 0x04, "Segmentation Indication" },
180 { 0, NULL }
183 static const true_false_string gre_3gpp2_sdi_val = {
184 "Packet suitable for 1x SDB or HRPD DOS transmission",
185 "Reserved"
188 static const true_false_string gre_3gpp2_fci_val = {
189 "XOFF",
190 "XON"
193 static const true_false_string gre_3gpp2_di_val = {
194 "INDEFINITE:",
195 "TEMPORARY"
198 static const true_false_string gre_wccp_dynamic_service_val = {
199 "Dynamic service",
200 "Well-known service"
203 static const true_false_string gre_wccp_alternative_bucket_used_val = {
204 "Alternative bucket used",
205 "Primary bucket used",
208 static const true_false_string gre_wccp_redirect_header_valid_val = {
209 "Header is present, but ignore contents",
210 "Header contents are valid",
214 static int
215 dissect_gre_3gpp2_attribs(tvbuff_t *tvb, int offset, proto_tree *tree)
217 bool last_attrib = false;
218 proto_item *attr_item;
219 proto_tree *attr_tree;
220 uint8_t value;
221 int start_offset = offset;
223 proto_item *ti = proto_tree_add_item(tree, hf_gre_3gpp2_attrib, tvb, offset, 0, ENC_NA);
224 proto_tree *atree = proto_item_add_subtree(ti, ett_3gpp2_attribs);
226 while(last_attrib != true)
228 uint8_t attrib_id = tvb_get_uint8(tvb, offset);
229 uint8_t attrib_length = tvb_get_uint8(tvb, offset + 1);
231 attr_tree = proto_tree_add_subtree(atree, tvb, offset, attrib_length + 1 + 1, ett_3gpp2_attr, &attr_item,
232 val_to_str((attrib_id&0x7f), gre_3gpp2_attrib_id_vals, "%u (Unknown)"));
234 proto_tree_add_item(attr_tree, hf_gre_3gpp2_attrib_id, tvb, offset, 1, ENC_BIG_ENDIAN);
235 proto_tree_add_item(attr_tree, hf_gre_3gpp2_attrib_length, tvb, offset+1, 1, ENC_BIG_ENDIAN);
237 offset += 2;
238 last_attrib = (attrib_id & 0x80)?true:false;
239 attrib_id &= 0x7F;
241 switch(attrib_id)
243 case ID_3GPP2_FLOW_DISCRIMINATOR:
245 value = tvb_get_uint8(tvb,offset);
246 proto_tree_add_item(attr_tree, hf_gre_3gpp2_flow_disc, tvb, offset, attrib_length, ENC_NA);
247 proto_item_append_text(attr_item," - 0x%x",value);
249 break;
250 case ID_3GPP2_SDI_FLAG:
252 value = tvb_get_uint8(tvb,offset);
253 proto_tree_add_item(attr_tree, hf_gre_3gpp2_sdi, tvb, offset, attrib_length, ENC_BIG_ENDIAN);
254 proto_item_append_text(attr_item," - %s",
255 (value & 0x80) ? "Packet suitable for 1x SDB or HRPD DOS transmission" : "Reserved");
258 break;
259 case ID_3GPP2_SEG:
261 value = tvb_get_uint8(tvb,offset) >>6;
262 proto_tree_add_item(attr_tree, hf_gre_3gpp2_seg, tvb, offset, attrib_length, ENC_BIG_ENDIAN);
263 proto_item_append_text(attr_item," - %s",val_to_str(value, gre_3gpp2_seg_vals, "0x%02X - Unknown"));
265 break;
266 case ID_3GPP2_FLOW_CTRL:
268 value = tvb_get_uint8(tvb,offset);
269 proto_tree_add_item(attr_tree, hf_gre_3gpp2_fci, tvb, offset, attrib_length, ENC_BIG_ENDIAN);
270 proto_item_append_text(attr_item," - %s",
271 (value & 0x80) ? "XON" : "XOFF");
272 proto_tree_add_item(attr_tree, hf_gre_3gpp2_di, tvb, offset, attrib_length, ENC_BIG_ENDIAN);
273 proto_item_append_text(attr_item,"/%s",
274 (value & 0x40) ? "INDEFINITE" : "TEMPORARY");
276 break;
279 offset += attrib_length;
281 proto_item_set_len(ti, offset - start_offset);
283 return offset;
286 static void
287 dissect_gre_wccp2_redirect_header(tvbuff_t *tvb, int offset, proto_tree *tree)
289 proto_item *ti;
290 proto_tree *rh_tree;
292 ti = proto_tree_add_item(tree, hf_gre_wccp_redirect_header, tvb, offset, 4, ENC_NA);
293 rh_tree = proto_item_add_subtree(ti, ett_gre_wccp2_redirect_header);
295 proto_tree_add_item(rh_tree, hf_gre_wccp_dynamic_service, tvb, offset, 1, ENC_BIG_ENDIAN);
297 proto_tree_add_item(rh_tree, hf_gre_wccp_alternative_bucket_used, tvb, offset, 1, ENC_BIG_ENDIAN);
299 proto_tree_add_item(rh_tree, hf_gre_wccp_redirect_header_valid, tvb, offset, 1, ENC_BIG_ENDIAN);
301 proto_tree_add_item(rh_tree, hf_gre_wccp_service_id, tvb, offset +1, 1, ENC_BIG_ENDIAN);
303 proto_tree_add_item(rh_tree, hf_gre_wccp_alternative_bucket, tvb, offset +2, 1, ENC_BIG_ENDIAN);
305 proto_tree_add_item(rh_tree, hf_gre_wccp_primary_bucket, tvb, offset +3, 1, ENC_BIG_ENDIAN);
308 static bool
309 capture_gre(const unsigned char *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
311 capture_dissector_increment_count(cpinfo, proto_gre);
312 return true;
315 static int
316 dissect_gre(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
319 int offset = 0;
320 gre_hdr_info_t gre_hdr_info;
321 uint16_t type;
322 bool is_ppp = false;
323 bool is_wccp2 = false;
324 proto_item *ti, *it_flags;
325 proto_tree *gre_tree, *fv_tree = NULL;
326 uint16_t sre_af;
327 uint8_t sre_length;
328 tvbuff_t *next_tvb;
330 gre_hdr_info.flags_and_ver = tvb_get_ntohs(tvb, offset);
331 type = tvb_get_ntohs(tvb, offset + 2);
333 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GRE");
335 col_add_fstr(pinfo->cinfo, COL_INFO, "Encapsulated %s", val_to_str(type, gre_typevals, "0x%04X (unknown)"));
337 switch (type) {
339 case ETHERTYPE_PPP:
340 if (gre_hdr_info.flags_and_ver & GRE_VERSION)
341 is_ppp = true;
342 break;
343 case ETHERTYPE_3GPP2:
344 case ETHERTYPE_CDMA2000_A10_UBS:
345 is_ppp = true;
346 break;
348 case GRE_WCCP:
349 /* WCCP2 puts an extra 4 octets into the header, but uses the same
350 encapsulation type; if it looks as if the first octet of the packet
351 isn't the beginning of an IPv4 header, assume it's WCCP2. */
352 if ((tvb_get_uint8(tvb, offset + 2 + 2) & 0xF0) != 0x40) {
353 is_wccp2 = true;
355 break;
358 /* Per README.developer, section 1.2, we must call subdissectors regardless
359 * of whether "tree" is NULL or not. That is done below using
360 * call_dissector(), but since the next_tvb must begin at the correct offset,
361 * it's easier and more readable to always enter this block in order to
362 * compute the correct offset to pass to tvb_new_subset_remaining().
364 if (1) {
365 ti = proto_tree_add_protocol_format(tree, proto_gre, tvb, offset, -1, "Generic Routing Encapsulation (%s)",
366 val_to_str(type, gre_typevals, "0x%04X - unknown"));
367 gre_tree = proto_item_add_subtree(ti, ett_gre);
370 it_flags = proto_tree_add_item(gre_tree, hf_gre_flags_and_version, tvb, offset, 2, ENC_BIG_ENDIAN);
371 fv_tree = proto_item_add_subtree(it_flags, ett_gre_flags);
373 proto_tree_add_item(fv_tree, hf_gre_flags_checksum, tvb, offset, 2, ENC_BIG_ENDIAN);
375 proto_tree_add_item(fv_tree, hf_gre_flags_routing, tvb, offset, 2, ENC_BIG_ENDIAN);
377 proto_tree_add_item(fv_tree, hf_gre_flags_key, tvb, offset, 2, ENC_BIG_ENDIAN);
379 proto_tree_add_item(fv_tree, hf_gre_flags_sequence_number, tvb, offset, 2, ENC_BIG_ENDIAN);
381 proto_tree_add_item(fv_tree, hf_gre_flags_strict_source_route, tvb, offset, 2, ENC_BIG_ENDIAN);
383 proto_tree_add_item(fv_tree, hf_gre_flags_recursion_control, tvb, offset, 2, ENC_BIG_ENDIAN);
385 /* RFC2637 Section 4.1 : Enhanced GRE Header */
386 if (is_ppp) {
387 proto_tree_add_item(fv_tree, hf_gre_flags_ack, tvb, offset, 2, ENC_BIG_ENDIAN);
389 proto_tree_add_item(fv_tree, hf_gre_flags_reserved_ppp, tvb, offset, 2, ENC_BIG_ENDIAN);
391 else {
392 proto_tree_add_item(fv_tree, hf_gre_flags_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
395 proto_tree_add_item(fv_tree, hf_gre_flags_version, tvb, offset, 2, ENC_BIG_ENDIAN);
397 offset += 2;
399 proto_tree_add_item(gre_tree, hf_gre_proto, tvb, offset, 2, ENC_BIG_ENDIAN);
400 offset += 2;
402 if (gre_hdr_info.flags_and_ver & GRE_CHECKSUM || gre_hdr_info.flags_and_ver & GRE_ROUTING) {
403 unsigned length, reported_length;
404 vec_t cksum_vec[1];
406 /* Checksum check !... */
407 length = tvb_captured_length(tvb);
408 reported_length = tvb_reported_length(tvb);
409 /* The Checksum Present bit is set, and the packet isn't part of a
410 fragmented datagram and isn't truncated, so we can checksum it. */
411 if ((gre_hdr_info.flags_and_ver & GRE_CHECKSUM) && !pinfo->fragmented && length >= reported_length) {
412 SET_CKSUM_VEC_TVB(cksum_vec[0], tvb, 0, reported_length);
413 proto_tree_add_checksum(gre_tree, tvb, offset, hf_gre_checksum, hf_gre_checksum_status, &ei_gre_checksum_incorrect, pinfo, in_cksum(cksum_vec, 1),
414 ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM);
415 } else {
416 proto_tree_add_checksum(gre_tree, tvb, offset, hf_gre_checksum, hf_gre_checksum_status, &ei_gre_checksum_incorrect, pinfo, 0,
417 ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
419 offset += 2;
421 proto_tree_add_item(gre_tree, hf_gre_offset, tvb, offset, 2, ENC_BIG_ENDIAN);
422 offset += 2;
425 if (gre_hdr_info.flags_and_ver & GRE_KEY) {
426 /* RFC2637 Section 4.1 : Enhanced GRE Header */
427 if (is_ppp && type!=ETHERTYPE_CDMA2000_A10_UBS) {
429 proto_tree_add_item(gre_tree, hf_gre_key_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN);
430 offset += 2;
432 proto_tree_add_item(gre_tree, hf_gre_key_call_id, tvb, offset, 2, ENC_BIG_ENDIAN);
433 offset += 2;
435 else {
436 proto_tree_add_item_ret_uint(gre_tree, hf_gre_key, tvb, offset, 4, ENC_BIG_ENDIAN, &gre_hdr_info.key);
437 offset += 4;
440 if (gre_hdr_info.flags_and_ver & GRE_SEQUENCE) {
442 proto_tree_add_item(gre_tree, hf_gre_sequence_number , tvb, offset, 4, ENC_BIG_ENDIAN);
443 offset += 4;
445 if (is_ppp && (gre_hdr_info.flags_and_ver & GRE_ACK)) {
447 proto_tree_add_item(gre_tree, hf_gre_ack_number , tvb, offset, 4, ENC_BIG_ENDIAN);
448 offset += 4;
450 if (gre_hdr_info.flags_and_ver & GRE_ROUTING) {
451 proto_item *it_routing;
452 proto_tree *r_tree;
453 for (;;) {
455 it_routing = proto_tree_add_item(gre_tree, hf_gre_routing, tvb, offset, -1, ENC_NA);
456 r_tree = proto_item_add_subtree(ti, ett_gre_routing);
458 sre_af = tvb_get_ntohs(tvb, offset);
459 proto_tree_add_item(r_tree, hf_gre_routing_address_family , tvb, offset, 2, ENC_BIG_ENDIAN);
460 offset += 2;
462 proto_tree_add_item(r_tree, hf_gre_routing_sre_offset , tvb, offset, 1, ENC_BIG_ENDIAN);
463 offset += 1;
465 sre_length = tvb_get_uint8(tvb, offset);
466 proto_tree_add_item(r_tree, hf_gre_routing_sre_length , tvb, offset, 1, ENC_BIG_ENDIAN);
467 offset += 1;
469 proto_item_set_len(it_routing, 2 + 1 +1 + sre_length);
470 if (sre_af == 0 && sre_length == 0)
471 break;
473 proto_tree_add_item(r_tree, hf_gre_routing_information , tvb, offset, sre_length, ENC_NA);
474 offset += sre_length;
478 if (type == GRE_WCCP && is_wccp2) {
479 dissect_gre_wccp2_redirect_header(tvb, offset, gre_tree);
480 offset += 4;
482 if (type == ETHERTYPE_3GPP2) {
483 offset = dissect_gre_3gpp2_attribs(tvb, offset, gre_tree);
486 proto_item_set_len(ti, offset);
488 /* If the S bit is not set, this packet might not have a payload, so
489 check whether there's any data left, first.
491 XXX - the S bit isn't in RFC 2784, which deprecates that bit
492 and some other bits in RFC 1701 and says that they should be
493 zero for RFC 2784-compliant GRE; as such, the absence of the
494 S bit doesn't necessarily mean there's no payload. */
495 if (!(gre_hdr_info.flags_and_ver & GRE_SEQUENCE)) {
496 if (tvb_reported_length_remaining(tvb, offset) <= 0)
497 return offset; /* no payload */
499 next_tvb = tvb_new_subset_remaining(tvb, offset);
500 pinfo->flags.in_gre_pkt = true;
501 if (!dissector_try_uint_new(gre_dissector_table, type, next_tvb, pinfo, tree, true, &gre_hdr_info))
502 if (!dissector_try_payload_new(gre_subdissector_table, next_tvb, pinfo, tree, true, &gre_hdr_info)) {
503 call_data_dissector(next_tvb, pinfo, gre_tree);
506 return tvb_captured_length(tvb);
509 static void
510 gre_prompt(packet_info *pinfo _U_, char* result)
512 snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "GRE proto as");
515 void
516 proto_register_gre(void)
518 static hf_register_info hf[] = {
519 { &hf_gre_proto,
520 { "Protocol Type", "gre.proto",
521 FT_UINT16, BASE_HEX, VALS(gre_typevals), 0x0,
522 "The protocol that is GRE encapsulated", HFILL }
524 { &hf_gre_flags_and_version,
525 { "Flags and Version", "gre.flags_and_version",
526 FT_UINT16, BASE_HEX, NULL, 0x0,
527 "The GRE flags are encoded in the first two octets", HFILL }
529 { &hf_gre_flags_checksum,
530 { "Checksum Bit", "gre.flags.checksum",
531 FT_BOOLEAN, 16, TFS(&tfs_yes_no), GRE_CHECKSUM,
532 "Indicates if the Checksum field is present", HFILL }
534 { &hf_gre_flags_routing,
535 { "Routing Bit", "gre.flags.routing",
536 FT_BOOLEAN, 16, TFS(&tfs_yes_no), GRE_ROUTING,
537 "Indicates if the Routing and Checksum/Offset field are present", HFILL }
539 { &hf_gre_flags_key,
540 { "Key Bit", "gre.flags.key",
541 FT_BOOLEAN, 16, TFS(&tfs_yes_no), GRE_KEY,
542 "Indicates if the Key field is present", HFILL }
544 { &hf_gre_flags_sequence_number,
545 { "Sequence Number Bit", "gre.flags.sequence_number",
546 FT_BOOLEAN, 16, TFS(&tfs_yes_no), GRE_SEQUENCE,
547 "Indicates if the Sequence Number field is present", HFILL }
549 { &hf_gre_flags_strict_source_route,
550 { "Strict Source Route Bit", "gre.flags.strict_source_route",
551 FT_BOOLEAN, 16, TFS(&tfs_yes_no), GRE_STRICTSOURCE,
552 NULL, HFILL }
554 { &hf_gre_flags_recursion_control,
555 { "Recursion control", "gre.flags.recursion_control",
556 FT_UINT16, BASE_DEC, NULL, GRE_RECURSION,
557 NULL, HFILL }
559 { &hf_gre_flags_ack,
560 { "Acknowledgment", "gre.flags.ack",
561 FT_BOOLEAN, 16, TFS(&tfs_yes_no), GRE_ACK,
562 "Indicates if the packet contains an Acknowledgment Number to be used for acknowledging previously transmitted data", HFILL }
564 { &hf_gre_flags_reserved,
565 { "Flags (Reserved)", "gre.flags.reserved",
566 FT_UINT16, BASE_DEC, NULL, GRE_RESERVED,
567 NULL, HFILL }
569 { &hf_gre_flags_reserved_ppp,
570 { "Flags (Reserved)", "gre.flags.reserved",
571 FT_UINT16, BASE_DEC, NULL, GRE_RESERVED_PPP,
572 NULL, HFILL }
574 { &hf_gre_flags_version,
575 { "Version", "gre.flags.version",
576 FT_UINT16, BASE_DEC, VALS(gre_version), GRE_VERSION,
577 NULL, HFILL }
579 { &hf_gre_checksum,
580 { "Checksum", "gre.checksum",
581 FT_UINT16, BASE_HEX, NULL, 0x0,
582 "The Checksum field contains the IP (one's complement) checksum of the GRE header and the payload packet", HFILL }
584 { &hf_gre_checksum_status,
585 { "Checksum Status", "gre.checksum.status",
586 FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0,
587 NULL, HFILL }
589 { &hf_gre_offset,
590 { "Offset", "gre.offset",
591 FT_UINT16, BASE_DEC, NULL, 0x0,
592 "The offset field indicates the octet offset from the start of the Routing field to the first octet of the active Source Route Entry to be examined", HFILL }
594 { &hf_gre_key,
595 { "Key", "gre.key",
596 FT_UINT32, BASE_HEX, NULL, 0x0,
597 "The Key field contains a four octet number which was inserted by the encapsulator", HFILL }
599 { &hf_gre_key_payload_length,
600 { "Payload Length", "gre.key.payload_length",
601 FT_UINT16, BASE_DEC, NULL, 0x0,
602 "Size of the payload, not including the GRE header", HFILL }
604 { &hf_gre_key_call_id,
605 { "Call ID", "gre.key.call_id",
606 FT_UINT16, BASE_DEC, NULL, 0x0,
607 "Contains the Peer's Call ID for the session to which this packet belongs.", HFILL }
609 { &hf_gre_sequence_number,
610 { "Sequence Number", "gre.sequence_number",
611 FT_UINT32, BASE_DEC, NULL, 0x0,
612 "The Sequence Number field contains an unsigned 32 bit integer which is inserted by the encapsulator", HFILL }
614 { &hf_gre_ack_number,
615 { "Acknowledgment Number", "gre.ack_number",
616 FT_UINT32, BASE_DEC, NULL, 0x0,
617 "Contains the sequence number of the highest numbered GRE packet received by the sending peer for this user session", HFILL }
619 { &hf_gre_routing,
620 { "Routing", "gre.routing",
621 FT_NONE, BASE_NONE, NULL, 0x0,
622 "The Routing field is a list of Source Route Entries (SREs)", HFILL }
624 { &hf_gre_routing_address_family,
625 { "Address Family", "gre.routing.address_family",
626 FT_UINT16, BASE_DEC, NULL, 0x0,
627 "The Address Family field contains a two octet value which indicates the syntax and semantics of the Routing Information field", HFILL }
629 { &hf_gre_routing_sre_offset,
630 { "SRE Offset", "gre.routing.sre_offset",
631 FT_UINT8, BASE_DEC, NULL, 0x0,
632 "The Address Family field contains a two octet value which indicates the syntax and semantics of the Routing Information field", HFILL }
634 { &hf_gre_routing_sre_length,
635 { "SRE Length", "gre.routing.src_length",
636 FT_UINT8, BASE_DEC, NULL, 0x0,
637 "The SRE Length field contains the number of octets in the SRE", HFILL }
639 { &hf_gre_routing_information,
640 { "Routing Information", "gre.routing.information",
641 FT_BYTES, BASE_NONE, NULL, 0x0,
642 "The Routing Information field contains data which may be used in routing this packet", HFILL }
644 { &hf_gre_3gpp2_attrib,
645 { "3GPP2 Attributes", "gre.3gpp2_attrib",
646 FT_NONE, BASE_NONE, NULL, 0x0,
647 NULL, HFILL }
649 { &hf_gre_3gpp2_attrib_id,
650 { "Type", "gre.3gpp2_attrib_id",
651 FT_UINT8, BASE_HEX, VALS(gre_3gpp2_attrib_id_vals), 0x7f,
652 NULL, HFILL }
654 { &hf_gre_3gpp2_attrib_length,
655 { "Length", "gre.3gpp2_attrib_length",
656 FT_UINT8, BASE_HEX, NULL, 0x0,
657 NULL, HFILL }
659 { &hf_gre_3gpp2_sdi,
660 { "SDI/DOS", "gre.3gpp2_sdi",
661 FT_BOOLEAN, 16, TFS(&gre_3gpp2_sdi_val), 0x8000,
662 "Short Data Indicator(SDI)/Data Over Signaling (DOS)", HFILL }
664 { &hf_gre_3gpp2_fci,
665 { "Flow Control Indicator", "gre.3gpp2_fci",
666 FT_BOOLEAN, 16, TFS(&gre_3gpp2_fci_val), 0x8000,
667 NULL, HFILL }
669 { &hf_gre_3gpp2_di,
670 { "Duration Indicator", "gre.3gpp2_di",
671 FT_BOOLEAN, 16, TFS(&gre_3gpp2_di_val), 0x4000,
672 NULL, HFILL }
674 { &hf_gre_3gpp2_flow_disc,
675 { "Flow ID", "gre.ggp2_flow_disc",
676 FT_BYTES, BASE_NONE, NULL, 0x0,
677 NULL, HFILL }
679 { &hf_gre_3gpp2_seg,
680 { "Type", "gre.ggp2_3gpp2_seg",
681 FT_UINT16, BASE_HEX, VALS(gre_3gpp2_seg_vals), 0xc000,
682 NULL, HFILL }
685 { &hf_gre_wccp_redirect_header,
686 { "Redirect Header", "gre.wccp.redirect_header",
687 FT_NONE, BASE_NONE, NULL, 0x0,
688 NULL, HFILL }
690 { &hf_gre_wccp_dynamic_service,
691 { "Dynamic Service", "gre.wccp.dynamic_service",
692 FT_BOOLEAN, 8, TFS(&gre_wccp_dynamic_service_val), 0x01,
693 NULL, HFILL }
695 { &hf_gre_wccp_alternative_bucket_used,
696 { "Alternative bucket used", "gre.wccp.alternative_bucket_used",
697 FT_BOOLEAN, 8, TFS(&gre_wccp_alternative_bucket_used_val), 0x02,
698 NULL, HFILL }
700 { &hf_gre_wccp_redirect_header_valid,
701 { "WCCP Redirect header is valid", "gre.wccp.redirect_header_valid",
702 FT_BOOLEAN, 8, TFS(&gre_wccp_redirect_header_valid_val), 0x04,
703 NULL, HFILL }
705 { &hf_gre_wccp_service_id,
706 { "Service ID", "gre.wccp.service_id",
707 FT_UINT8, BASE_DEC, VALS(service_id_vals), 0x00,
708 "Service Group identifier", HFILL }
710 { &hf_gre_wccp_alternative_bucket,
711 { "Alternative Bucket", "gre.wccp.alternative_bucket",
712 FT_UINT8, BASE_DEC, NULL, 0x0,
713 "Alternative bucket index used to redirect the packet.", HFILL }
715 { &hf_gre_wccp_primary_bucket,
716 { "Primary Bucket", "gre.wccp.primary_bucket",
717 FT_UINT8, BASE_DEC, NULL, 0x0,
718 "Primary bucket index used to redirect the packet.", HFILL }
721 static int *ett[] = {
722 &ett_gre,
723 &ett_gre_flags,
724 &ett_gre_routing,
725 &ett_gre_wccp2_redirect_header,
726 &ett_3gpp2_attribs,
727 &ett_3gpp2_attr,
731 static ei_register_info ei[] = {
732 { &ei_gre_checksum_incorrect, { "gre.checksum.incorrect", PI_PROTOCOL, PI_WARN, "Incorrect GRE Checksum", EXPFILL }},
735 expert_module_t* expert_gre;
737 proto_gre = proto_register_protocol("Generic Routing Encapsulation",
738 "GRE", "gre");
739 gre_handle = register_dissector("gre", dissect_gre, proto_gre);
740 gre_cap_handle = register_capture_dissector("gre", capture_gre, proto_gre);
741 proto_register_field_array(proto_gre, hf, array_length(hf));
742 proto_register_subtree_array(ett, array_length(ett));
743 expert_gre = expert_register_protocol(proto_gre);
744 expert_register_field_array(expert_gre, ei, array_length(ei));
747 * Dissector table.
749 * XXX - according to
751 * https://www.iana.org/assignments/gre-parameters/gre-parameters.xhtml#gre-parameters-1
753 * these are just Ethertypes; should we use "gre.proto" only for
754 * protocols *not* registered as Ethertypes, such as those listed
755 * in the table in "Current List of Protocol Types" in RFC 1701
756 * ("For historical reasons, a number of other values have been
757 * used for some protocols."), and for protocols encapsulated in GRE
758 * differently from the way they're encapsulated over LAN protocols
759 * (for example, Cisco MetaData), and if we don't get a match there,
760 * use the "ethertype" table?
762 * And should we also somehow do something similar for mapping values
763 * to strings, falling back on etype_vals?
765 gre_dissector_table = register_dissector_table("gre.proto",
766 "GRE protocol type", proto_gre, FT_UINT16, BASE_HEX);
768 gre_subdissector_table = register_decode_as_next_proto(proto_gre, "gre.subproto",
769 "GRE protocol type", gre_prompt);
772 void
773 proto_reg_handoff_gre(void)
775 dissector_add_uint("ip.proto", IP_PROTO_GRE, gre_handle);
776 dissector_add_uint("udp.port", GRE_IN_UDP_PORT, gre_handle);
777 capture_dissector_add_uint("ip.proto", IP_PROTO_GRE, gre_cap_handle);
781 * Editor modelines - https://www.wireshark.org/tools/modelines.html
783 * Local variables:
784 * c-basic-offset: 4
785 * tab-width: 8
786 * indent-tabs-mode: nil
787 * End:
789 * vi: set shiftwidth=4 tabstop=8 expandtab:
790 * :indentSize=4:tabSize=8:noTabs=true: