2 * Copyright (c) 2003 Markus Friedl. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <epan/packet.h>
34 #include <epan/resolv.h>
35 #include "packet-ip.h"
36 #include "packet-ipv6.h"
39 /* Can't trust stddef.h to be there for us */
40 # define offsetof(type, member) ((size_t)(&((type *)0)->member))
43 /* The header in OpenBSD Encapsulating Interface files. */
50 #define ENC_HDRLEN sizeof(struct enchdr)
52 # define BSD_ENC_INET 2
53 # define BSD_ENC_INET6 24
55 # define BSD_ENC_M_CONF 0x0400 /* payload encrypted */
56 # define BSD_ENC_M_AUTH 0x0800 /* payload authenticated */
57 # define BSD_ENC_M_COMP 0x1000 /* payload compressed */
58 # define BSD_ENC_M_AUTH_AH 0x2000 /* header authenticated */
60 static dissector_handle_t data_handle, ip_handle, ipv6_handle;
63 static unsigned int proto_enc = -1;
64 static unsigned int hf_enc_af = -1;
65 static unsigned int hf_enc_spi = -1;
66 static unsigned int hf_enc_flags = -1;
68 static gint ett_enc = -1;
71 capture_enc(const guchar *pd, int offset, int len, packet_counts *ld)
75 if (!BYTES_ARE_IN_FRAME(offset, len, (int)ENC_HDRLEN)) {
82 /* Copy out the enc header to insure alignment */
83 memcpy(&ench, pd, sizeof(ench));
84 ench.af = g_ntohl(ench.af);
89 capture_ip(pd, offset, len, ld);
94 capture_ipv6(pd, offset, len, ld);
104 static const value_string af_vals[] = {
105 { BSD_ENC_INET, "IPv4" },
106 { BSD_ENC_INET6, "IPv6" },
111 dissect_enc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
115 proto_tree *enc_tree;
118 if (check_col(pinfo->cinfo, COL_PROTOCOL))
119 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ENC");
121 /* Copy out the enc header to insure alignment */
122 tvb_memcpy(tvb, (guint8 *)&ench, 0, sizeof(ench));
124 /* Byteswap the header now */
125 ench.spi = g_ntohl(ench.spi);
126 /* ench.af = g_ntohl(ench.af); */
127 /* ench.flags = g_ntohl(ench.flags); */
130 ti = proto_tree_add_protocol_format(tree, proto_enc, tvb, 0,
132 "Enc %s, SPI 0x%8.8x, %s%s%s%s",
133 val_to_str(ench.af, af_vals, "unknown (%u)"),
135 ench.flags ? "" : "unprotected",
136 ench.flags & BSD_ENC_M_AUTH ? "authentic" : "",
137 (ench.flags & (BSD_ENC_M_AUTH|BSD_ENC_M_CONF)) ==
138 (BSD_ENC_M_AUTH|BSD_ENC_M_CONF) ? ", " : "",
139 ench.flags & BSD_ENC_M_CONF ? "confidential" : ""
141 enc_tree = proto_item_add_subtree(ti, ett_enc);
143 proto_tree_add_uint(enc_tree, hf_enc_af, tvb,
144 offsetof(struct enchdr, af), sizeof(ench.af),
146 proto_tree_add_uint(enc_tree, hf_enc_spi, tvb,
147 offsetof(struct enchdr, spi), sizeof(ench.spi),
149 proto_tree_add_uint(enc_tree, hf_enc_flags, tvb,
150 offsetof(struct enchdr, flags), sizeof(ench.flags),
154 /* Set the tvbuff for the payload after the header */
155 next_tvb = tvb_new_subset(tvb, ENC_HDRLEN, -1, -1);
160 call_dissector(ip_handle, next_tvb, pinfo, tree);
164 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
168 call_dissector(data_handle, next_tvb, pinfo, tree);
174 proto_register_enc(void)
176 static hf_register_info hf[] = {
178 { "Address Family", "enc.af", FT_UINT32, BASE_DEC, VALS(af_vals), 0x0,
179 "Protocol (IPv4 vs IPv6)", HFILL }},
181 { "SPI", "enc.spi", FT_UINT32, BASE_HEX, NULL, 0x0,
182 "Security Parameter Index", HFILL }},
184 { "Flags", "enc.flags", FT_UINT32, BASE_HEX, NULL, 0x0,
185 "ENC flags", HFILL }},
187 static gint *ett[] = { &ett_enc };
189 proto_enc = proto_register_protocol("OpenBSD Encapsulating device",
191 proto_register_field_array(proto_enc, hf, array_length(hf));
192 proto_register_subtree_array(ett, array_length(ett));
196 proto_reg_handoff_enc(void)
198 dissector_handle_t enc_handle;
200 ip_handle = find_dissector("ip");
201 ipv6_handle = find_dissector("ipv6");
202 data_handle = find_dissector("data");
204 enc_handle = create_dissector_handle(dissect_enc, proto_enc);
205 dissector_add("wtap_encap", WTAP_ENCAP_ENC, enc_handle);