2 * Common CLV decode routines.
4 * $Id: packet-isis-clv.c,v 1.19 2002/04/07 23:39:00 guy Exp $
5 * Stuart Stanley <stuarts@mxmail.net>
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
38 #ifdef NEED_SNPRINTF_H
39 # include "snprintf.h"
42 #include <epan/packet.h>
43 #include "packet-osi.h"
44 #include "packet-isis.h"
45 #include "packet-isis-clv.h"
50 * Name: isis_dissect_area_address_clv()
53 * Take an area address CLV and display it pieces. An area address
54 * CLV is n, x byte hex strings.
57 * tvbuff_t * : tvbuffer for packet data
58 * proto_tree * : protocol display tree to fill out. May be NULL
59 * int : offset into packet data where we are.
60 * int : length of clv we are decoding
63 * void, but we will add to proto tree if !NULL.
66 isis_dissect_area_address_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
72 while ( length > 0 ) {
73 mylen = tvb_get_guint8(tvb, offset);
76 isis_dissect_unknown(tvb, tree, offset,
77 "short address (no length for payload)");
80 if ( mylen > length) {
81 isis_dissect_unknown(tvb, tree, offset,
82 "short address, packet say %d, we have %d left",
88 * Lets turn the area address into "standard" 0000.0000.etc
91 /* sbuf = isis_address_to_string ( tvb, offset + 1, mylen );*/
92 sbuf = print_nsap_net( tvb_get_ptr(tvb, offset + 1, mylen), mylen );
95 proto_tree_add_text ( tree, tvb, offset, mylen + 1,
96 "Area address (%d): %s", mylen, sbuf );
99 length -= mylen; /* length already adjusted for len fld*/
105 * Name: isis_dissect_authentication_clv()
108 * Take apart the CLV that hold authentication information. This
109 * is currently 1 octet auth type (which must be 1) and then
110 * the clear text password.
112 * An ISIS password has different meaning depending where it
113 * is found. Thus we support a passed in prefix string to
117 * tvbuff_t * : tvbuffer for packet data
118 * proto_tree * : protocol display tree to fill out. May be NULL
119 * int : offset into packet data where we are.
120 * int : length of clv we are decoding
121 * char * : Password meaning
124 * void, but we will add to proto tree if !NULL.
127 isis_dissect_authentication_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
128 int length, char *meaning)
131 char sbuf[300]; /* 255 + header info area */
133 int auth_unsupported;
139 pw_type = tvb_get_guint8(tvb, offset);
142 auth_unsupported = FALSE;
146 s += sprintf ( s, "clear text (1), password (length %d) = ", length );
149 strncpy(s, tvb_get_ptr(tvb, offset, length), length);
152 strcat(s, "no clear-text password found!!!" );
156 s += sprintf ( s, "hmac-md5 (54), password (length %d) = ", length );
158 if ( length == 16 ) {
159 s += sprintf ( s, "0x%02x", tvb_get_guint8(tvb, offset) );
163 s += sprintf ( s, "%02x", tvb_get_guint8(tvb, offset) );
169 strcat(s, "illegal hmac-md5 digest format (must be 16 bytes)" );
173 s += sprintf ( s, "type 0x%02x (0x%02x): ", pw_type, length );
174 auth_unsupported=TRUE;
178 proto_tree_add_text ( tree, tvb, offset - 1, length + 1,
179 "%s %s", meaning, sbuf );
181 if ( auth_unsupported ) {
182 isis_dissect_unknown(tvb, tree, offset,
183 "Unknown authentication type" );
188 * Name: isis_dissect_hostname_clv()
191 * dump the hostname information found in TLV 137
192 * pls note that the hostname is not null terminated
195 * tvbuff_t * : tvbuffer for packet data
196 * proto_tree * : protocol display tree to fill out. May be NULL
197 * int : offset into packet data where we are.
198 * int : length of clv we are decoding
201 * void, but we will add to proto tree if !NULL.
206 isis_dissect_hostname_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
209 if ( !tree ) return; /* nothing to do! */
212 proto_tree_add_text ( tree, tvb, offset, length,
213 "Hostname: --none--" );
215 proto_tree_add_text ( tree, tvb, offset, length,
216 "Hostname: %.*s", length,
217 tvb_get_ptr(tvb, offset, length) );
225 isis_dissect_mt_clv(tvbuff_t *tvb, proto_tree *tree, int offset, int length,
232 /* length can only be a multiple of 2, otherwise there is
233 something broken -> so decode down until length is 1 */
235 /* fetch two bytes */
236 mt_block=tvb_get_ntohs(tvb, offset);
238 /* mask out the lower 12 bits */
239 switch(mt_block&0x0fff) {
241 strcpy(mt_desc,"IPv4 unicast");
244 strcpy(mt_desc,"In-Band Management");
247 strcpy(mt_desc,"IPv6 unicast");
250 strcpy(mt_desc,"Multicast");
253 strcpy(mt_desc,"Development, Experimental or Proprietary");
256 strcpy(mt_desc,"Reserved for IETF Consensus");
259 proto_tree_add_uint_format ( tree, tree_id, tvb, offset, 2,
261 "%s Topology (0x%03x)%s%s",
264 (mt_block&0x8000) ? "" : ", no sub-TLVs present",
265 (mt_block&0x4000) ? ", ATT bit set" : "" );
267 proto_tree_add_text ( tree, tvb, offset, 1,
278 * Name: isis_dissect_ip_int_clv()
281 * Take apart the CLV that lists all the IP interfaces. The
282 * meaning of which is slightly different for the different base packet
283 * types, but the display is not different. What we have is n ip
284 * addresses, plain and simple.
287 * tvbuff_t * : tvbuffer for packet data
288 * proto_tree * : protocol display tree to fill out. May be NULL
289 * int : offset into packet data where we are.
290 * int : length of clv we are decoding
291 * int : tree id to use for proto tree.
294 * void, but we will add to proto tree if !NULL.
297 isis_dissect_ip_int_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
298 int length, int tree_id)
304 while ( length > 0 ) {
306 isis_dissect_unknown(tvb, tree, offset,
307 "Short ip interface address (%d vs 4)",length );
312 proto_tree_add_item(tree, tree_id, tvb, offset, 4, FALSE);
320 * Name: isis_dissect_ipv6_int_clv()
323 * Take apart the CLV that lists all the IPv6 interfaces. The
324 * meaning of which is slightly different for the different base packet
325 * types, but the display is not different. What we have is n ip
326 * addresses, plain and simple.
329 * tvbuff_t * : tvbuffer for packet data
330 * proto_tree * : protocol display tree to fill out. May be NULL
331 * int : offset into packet data where we are.
332 * int : length of clv we are decoding
333 * int : tree id to use for proto tree.
336 * void, but we will add to proto tree if !NULL.
339 isis_dissect_ipv6_int_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
340 int length, int tree_id)
348 while ( length > 0 ) {
350 isis_dissect_unknown(tvb, tree, offset,
351 "Short IPv6 interface address (%d vs 16)",length );
354 tvb_memcpy(tvb, addr, offset, sizeof(addr));
356 proto_tree_add_ipv6(tree, tree_id, tvb, offset, 16, addr);
365 * Name: isis_dissect_te_router_id_clv()
368 * Display the Traffic Engineering Router ID TLV #134.
369 * This TLV is like the IP Interface TLV, except that
370 * only _one_ IP address is present
373 * tvbuff_t * : tvbuffer for packet data
374 * proto_tree * : protocol display tree to fill out. May be NULL
375 * int : offset into packet data where we are.
376 * int : length of clv we are decoding
377 * int : tree id to use for proto tree.
380 * void, but we will add to proto tree if !NULL.
383 isis_dissect_te_router_id_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
384 int length, int tree_id)
391 isis_dissect_unknown(tvb, tree, offset,
392 "malformed Traffic Engineering Router ID (%d vs 4)",length );
396 proto_tree_add_item(tree, tree_id, tvb, offset, 4, FALSE);
401 * Name: isis_dissect_nlpid_clv()
404 * Take apart a NLPID packet and display it. The NLPID (for intergrated
405 * ISIS, contains n network layer protocol IDs that the box supports.
406 * Our display buffer we use is upto 255 entries, 6 bytes per (0x00, )
407 * plus 1 for zero termination. We just just 256*6 for simplicity.
410 * tvbuff_t * : tvbuffer for packet data
411 * proto_tree * : protocol display tree to fill out. May be NULL
412 * int : offset into packet data where we are.
413 * int : length of clv we are decoding
416 * void, but we will add to proto tree if !NULL.
419 isis_dissect_nlpid_clv(tvbuff_t *tvb, proto_tree *tree, int offset, int length)
424 int old_offset = offset;
426 if ( !tree ) return; /* nothing to do! */
428 while ( length-- > 0 ) {
430 s += sprintf ( s, ", " );
432 s += sprintf ( s, "%s (0x%02x)",
433 val_to_str(tvb_get_guint8(tvb, offset), nlpid_vals,
434 "Unknown"), tvb_get_guint8(tvb, offset));
439 sprintf ( sbuf, "--none--" );
442 proto_tree_add_text ( tree, tvb, old_offset, hlen,
443 "NLPID(s): %s", sbuf );
447 * Name: isis_dissect_clvs()
450 * Dispatch routine to shred all the CLVs in a packet. We just
451 * walk through the clv entries in the packet. For each one, we
452 * search the passed in valid clv's for this protocol (opts) for
453 * a matching code. If found, we add to the display tree and
454 * then call the dissector. If it is not, we just post an
455 * "unknown" clv entry using the passed in unknown clv tree id.
458 * tvbuff_t * : tvbuffer for packet data
459 * proto_tree * : protocol display tree to fill out. May be NULL
460 * int : offset into packet data where we are.
461 * isis_clv_handle_t * : NULL dissector terminated array of codes
462 * and handlers (along with tree text and tree id's).
463 * int : length of CLV area.
464 * int : length of IDs in packet.
465 * int : unknown clv tree id
468 * void, but we will add to proto tree if !NULL.
471 isis_dissect_clvs(tvbuff_t *tvb, proto_tree *tree, int offset,
472 const isis_clv_handle_t *opts, int len, int id_length,
479 proto_tree *clv_tree;
484 code = tvb_get_guint8(tvb, offset);
487 length = tvb_get_guint8(tvb, offset);
490 adj = (sizeof(code) + sizeof(length) + length);
493 isis_dissect_unknown(tvb, tree, offset,
494 "Short CLV header (%d vs %d)",
499 while ((opts[q].dissect != NULL )&&( opts[q].optcode != code )){
502 if ( opts[q].dissect ) {
504 /* adjust by 2 for code/len octets */
505 snprintf ( sbuf, sizeof(sbuf), "%s (%d)",
506 opts[q].tree_text, length );
507 ti = proto_tree_add_text(tree, tvb, offset - 2,
509 clv_tree = proto_item_add_subtree(ti,
514 opts[q].dissect(tvb, clv_tree, offset,
518 snprintf ( sbuf, sizeof(sbuf),
519 "Unknown code (%d:%d)", code, length );
520 ti = proto_tree_add_text(tree, tvb, offset - 2,
522 clv_tree = proto_item_add_subtree(ti,