epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / epan / dissectors / packet-ipsec-udp.c
blob099cd57ec4c69ba01b18f0efd1393736e8cb3bef
1 /*
2 * Copyright (c) 2003 Markus Friedl. All rights reserved.
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
7 #include "config.h"
9 #include <epan/packet.h>
11 void proto_register_udpencap(void);
12 void proto_reg_handoff_udpencap(void);
14 #define UDPENCAP_PORT 4500
16 static int proto_udpencap;
18 static int hf_nat_keepalive;
19 static int hf_non_esp_marker;
21 static int ett_udpencap;
23 static dissector_handle_t udpencap_handle;
24 static dissector_handle_t esp_handle;
25 static dissector_handle_t isakmp_handle;
28 * UDP Encapsulation of IPsec Packets
29 * draft-ietf-ipsec-udp-encaps-06.txt
31 static int
32 dissect_udpencap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
34 tvbuff_t *next_tvb;
35 proto_tree *udpencap_tree;
36 proto_item *ti;
37 uint32_t spi;
39 col_set_str(pinfo->cinfo, COL_PROTOCOL, "UDPENCAP");
40 col_clear(pinfo->cinfo, COL_INFO);
42 ti = proto_tree_add_item(tree, proto_udpencap, tvb, 0, -1, ENC_NA);
43 udpencap_tree = proto_item_add_subtree(ti, ett_udpencap);
45 /* 1 byte of 0xFF indicates NAT-keepalive */
46 if ((tvb_captured_length(tvb) == 1) && (tvb_get_uint8(tvb, 0) == 0xff)) {
47 col_set_str(pinfo->cinfo, COL_INFO, "NAT-keepalive");
48 proto_tree_add_item(udpencap_tree, hf_nat_keepalive, tvb, 0, 1, ENC_NA);
49 } else {
50 /* SPI of zero indicates IKE traffic, otherwise it's ESP */
51 spi = tvb_get_ntohl(tvb, 0);
52 if (spi == 0) {
53 col_set_str(pinfo->cinfo, COL_INFO, "ISAKMP");
54 proto_tree_add_item(udpencap_tree, hf_non_esp_marker, tvb, 0, 4, ENC_NA);
55 proto_item_set_len(ti, 4);
56 next_tvb = tvb_new_subset_remaining(tvb, 4);
57 call_dissector(isakmp_handle, next_tvb, pinfo, tree);
58 } else {
59 col_set_str(pinfo->cinfo, COL_INFO, "ESP");
60 proto_item_set_len(ti, 0);
61 call_dissector(esp_handle, tvb, pinfo, tree);
64 return tvb_captured_length(tvb);
67 void
68 proto_register_udpencap(void)
70 static hf_register_info hf[] = {
71 { &hf_nat_keepalive, { "NAT-keepalive packet", "udpencap.nat_keepalive",
72 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
73 { &hf_non_esp_marker, { "Non-ESP Marker", "udpencap.non_esp_marker",
74 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
77 static int *ett[] = {
78 &ett_udpencap,
81 proto_udpencap = proto_register_protocol("UDP Encapsulation of IPsec Packets", "UDPENCAP", "udpencap");
82 proto_register_field_array(proto_udpencap, hf, array_length(hf));
83 proto_register_subtree_array(ett, array_length(ett));
85 udpencap_handle = register_dissector("udpencap", dissect_udpencap, proto_udpencap);
88 void
89 proto_reg_handoff_udpencap(void)
92 esp_handle = find_dissector_add_dependency("esp", proto_udpencap);
93 isakmp_handle = find_dissector_add_dependency("isakmp", proto_udpencap);
95 dissector_add_uint_with_preference("udp.port", UDPENCAP_PORT, udpencap_handle);
99 * Editor modelines - https://www.wireshark.org/tools/modelines.html
101 * Local Variables:
102 * c-basic-offset: 2
103 * tab-width: 8
104 * indent-tabs-mode: nil
105 * End:
107 * ex: set shiftwidth=2 tabstop=8 expandtab:
108 * :indentSize=2:tabSize=8:noTabs=true: