1 /* packet-teredo.c v.1.0
2 * Routines for TEREDO packet disassembly
3 * draft-huitema-v6ops-teredo-00.txt
6 * Copyright 2003, Ragi BEJJANI - 6WIND - <ragi.bejjani@6wind.com>
7 * Copyright 2003, Vincent JARDIN - 6WIND - <vincent.jardin@6wind.com>
9 * $Id: packet-teredo.c,v 1.2 2003/09/10 19:23:29 guy Exp $
11 * Ethereal - Network traffic analyzer
12 * By Gerald Combs <gerald@ethereal.com>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 #include <epan/packet.h>
40 #include <epan/resolv.h>
44 #include "packet-ip.h"
47 #define UDP_PORT_TERREDO 3544
49 static int teredo_tap = -1;
51 static int proto_teredo = -1;
52 static int hf_teredo_orgheader = -1;
53 static int hf_teredo_authheader = -1;
54 static int hf_teredo_orgport = -1;
55 static int hf_teredo_orgaddr = -1;
57 static gint ett_teredo = -1;
72 /* Place TEREDO summary in proto tree */
73 static gboolean teredo_summary_in_tree = TRUE;
75 static dissector_table_t teredo_dissector_table;
76 /*static heur_dissector_list_t heur_subdissector_list;*/
77 static dissector_handle_t data_handle;
79 /* Determine if there is a sub-dissector and call it. This has been */
80 /* separated into a stand alone routine to other protocol dissectors */
81 /* can call to it, ie. socks */
85 decode_teredo_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,proto_tree *tree, int th_header)
89 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
91 if (dissector_try_port(teredo_dissector_table, th_header, next_tvb, pinfo, tree))
94 call_dissector(data_handle,next_tvb, pinfo, tree);
98 dissect_teredo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
100 proto_tree *teredo_tree;
103 static e_teredohdr teredohstruct[4], *teredoh;
104 static int teredoh_count = 0;
107 proto_tree *teredo_origin_tree;
110 if(teredoh_count>=4){
113 teredoh = &teredohstruct[teredoh_count];
115 if (check_col(pinfo->cinfo, COL_PROTOCOL))
116 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TEREDO");
117 if (check_col(pinfo->cinfo, COL_INFO))
118 col_clear(pinfo->cinfo, COL_INFO);
120 teredoh->th_header = tvb_get_ntohs(tvb, offset);
121 teredoh->th_ip_v_hl = tvb_get_guint8(tvb, offset);
122 teredoh->th_indtyp = 0;
124 if ( (teredoh->th_header)== 1 ) {
125 teredoh->th_indtyp = teredoh->th_header;
126 teredoh->th_cidlen = tvb_get_guint8(tvb,offset+2); /*Authentication header octet*/
127 teredoh->th_authdlen = tvb_get_guint8(tvb,offset+3);
128 teredoh->th_nonce = tvb_get_ntohieee_double(tvb, offset+4);
129 teredoh->th_conf = tvb_get_guint8(tvb,offset+12);
131 /*Skip over Authentication Header (fixed length-no authentication)*/
133 teredoh->th_header = tvb_get_ntohs(tvb, offset);
134 teredoh->th_ip_v_hl = tvb_get_guint8(tvb, offset);
136 if (check_col(pinfo->cinfo, COL_INFO))
137 col_set_str(pinfo->cinfo, COL_INFO,
138 "Teredo : Tunneling IPv6 over UDP through NATs");
140 proto_tree_add_uint_hidden(tree, hf_teredo_authheader, tvb, offset-13, 2, teredoh->th_indtyp);
142 if (teredo_summary_in_tree) {
144 if (teredoh->th_header!=0) {
145 ti = proto_tree_add_protocol_format(tree, proto_teredo, tvb, offset-13, 13,
146 "TEREDO with Authentication encapsulation");
150 ti = proto_tree_add_item(tree, proto_teredo, tvb, offset, 13, FALSE);
154 if ( (teredoh->th_header)== 0 ) {
155 teredoh->th_orgport=tvb_get_ntohs(tvb, offset+2);
156 tvb_memcpy(tvb, (guint8 *)&teredoh->th_iporgaddr, offset + 4, 4);
158 if (check_col(pinfo->cinfo, COL_INFO))
159 col_set_str(pinfo->cinfo, COL_INFO,
160 "Teredo : Tunneling IPv6 over UDP through NATs");
163 if (teredo_summary_in_tree) {
164 if (teredoh->th_indtyp==1){
165 to = proto_tree_add_protocol_format(tree, proto_teredo, tvb, offset-13, 13+8,
166 "TEREDO with Authentication and Origin Indicator encapsulation");
167 teredo_tree = proto_item_add_subtree(to, ett_teredo);
168 proto_tree_add_protocol_format(teredo_tree,proto_teredo, tvb,offset-13, 13,
169 "Authentication encapsulation");
170 ti = proto_tree_add_protocol_format(teredo_tree, proto_teredo, tvb, offset, 8,
171 "Origin indicator encapsulation") ;
173 ti = proto_tree_add_protocol_format(tree, proto_teredo, tvb, offset, 8,
174 "TEREDO with Origin indicator encapsulation");
177 ti = proto_tree_add_item(tree, proto_teredo, tvb, offset, 8, FALSE);
180 teredo_origin_tree = proto_item_add_subtree(ti, ett_teredo);
182 proto_tree_add_uint_format(teredo_origin_tree, hf_teredo_orgheader, tvb, offset, 2,
184 "Teredo Origin encapsulation header: 0x%04x",
185 (teredoh->th_header));
186 proto_tree_add_uint_format(teredo_origin_tree, hf_teredo_orgport, tvb, offset + 2, 2,
189 ((teredoh->th_orgport)^(0xFFFF)));
190 proto_tree_add_ipv4_format(teredo_origin_tree, hf_teredo_orgaddr, tvb, offset + 4, 4,
191 teredoh->th_iporgaddr,
192 "Origin address: %s",
193 get_hostname((teredoh->th_iporgaddr)^(0xFFFFFFFF)));
195 proto_tree_add_uint_hidden(teredo_origin_tree, hf_teredo_orgheader, tvb, offset, 2,
197 proto_tree_add_uint_hidden(teredo_origin_tree, hf_teredo_orgport, tvb, offset+2, 2,
198 ((teredoh->th_orgport)^(0xFFFF)));
199 proto_tree_add_ipv4_hidden(teredo_origin_tree, hf_teredo_orgaddr, tvb, offset + 4, 4,
200 ((teredoh->th_iporgaddr)^(0xFFFFFFFF)));
203 offset+=8; /*Skip over Origin Header*/
206 if ( (hi_nibble(teredoh->th_ip_v_hl) == 6)
207 && ((teredoh->th_indtyp) != 1) ) { /* checking if the first 4 bits = 6 */
210 if (teredo_summary_in_tree) {
211 ti = proto_tree_add_protocol_format(tree, proto_teredo, tvb, offset, 0,"TEREDO simple encapsulation ");
218 decode_teredo_ports(tvb, offset, pinfo, tree, teredoh->th_header /* , teredoh->th_orgport*/);
219 tap_queue_packet(teredo_tap, pinfo, teredoh);
223 proto_register_teredo(void)
225 static hf_register_info hf[] = {
227 { &hf_teredo_authheader,
228 { "Teredo Authentication packet Header","teredo.authheader", FT_UINT16, BASE_DEC, NULL, 0x0,"", HFILL }},
230 { &hf_teredo_orgheader,
231 { "Teredo Origin encapsulation header","teredo.orgheader", FT_UINT16, BASE_DEC, NULL, 0x0,"", HFILL }},
233 { &hf_teredo_orgport,
234 { "Origin Port", "teredo.orgport", FT_UINT16, BASE_DEC, NULL, 0x0,"", HFILL }},
236 { &hf_teredo_orgaddr,
237 { "Origin IPv4 address","teredo.orgaddr", FT_IPv4, BASE_NONE, NULL, 0x0,"", HFILL }},
241 static gint *ett[] = {
245 proto_teredo = proto_register_protocol("TEREDO Tunneling IPv6 over UDP through NATs",
247 proto_register_field_array(proto_teredo, hf, array_length(hf));
248 proto_register_subtree_array(ett, array_length(ett));
250 /* subdissector code */
251 teredo_dissector_table = register_dissector_table("teredo","TEREDO ", FT_UINT16, BASE_DEC);
252 /* register_heur_dissector_list("teredo.heur", &heur_subdissector_list); */
257 proto_reg_handoff_teredo(void)
259 dissector_handle_t teredo_handle;
261 teredo_handle = create_dissector_handle(dissect_teredo, proto_teredo);
262 data_handle = find_dissector("ipv6");
263 teredo_tap = register_tap("teredo");
265 dissector_add("udp.port", UDP_PORT_TERREDO, teredo_handle);