913be638f3085901b69b8659b2e5379f529bc07d
[obnox/wireshark/wip.git] / epan / dissectors / packet-clnp.c
1 /* packet-clnp.c
2  * Routines for ISO/OSI network protocol packet disassembly
3  *
4  * $Id$
5  * Laurent Deniel <laurent.deniel@free.fr>
6  * Ralf Schneider <Ralf.Schneider@t-online.de>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <glib.h>
32 #include <epan/prefs.h>
33 #include <epan/packet.h>
34 #include <epan/reassemble.h>
35 #include "packet-frame.h"
36 #include "packet-osi.h"
37 #include "packet-osi-options.h"
38 #include "packet-isis.h"
39 #include "packet-esis.h"
40 #include <epan/nlpid.h>
41 #include <epan/ipproto.h>
42
43 /* protocols and fields */
44
45 static int  proto_clnp         = -1;
46 static gint ett_clnp           = -1;
47 static gint ett_clnp_type      = -1;
48 static gint ett_clnp_segments  = -1;
49 static gint ett_clnp_segment   = -1;
50 static gint ett_clnp_disc_pdu  = -1;
51
52 static int hf_clnp_id          = -1;
53 static int hf_clnp_length      = -1;
54 static int hf_clnp_version     = -1;
55 static int hf_clnp_ttl         = -1;
56 static int hf_clnp_type        = -1;
57 static int hf_clnp_pdu_length  = -1;
58 static int hf_clnp_checksum    = -1;
59 static int hf_clnp_dest_length = -1;
60 static int hf_clnp_dest        = -1;
61 static int hf_clnp_src_length  = -1;
62 static int hf_clnp_src         = -1;
63 static int hf_clnp_segments    = -1;
64 static int hf_clnp_segment     = -1;
65 static int hf_clnp_segment_overlap = -1;
66 static int hf_clnp_segment_overlap_conflict = -1;
67 static int hf_clnp_segment_multiple_tails = -1;
68 static int hf_clnp_segment_too_long_segment = -1;
69 static int hf_clnp_segment_error = -1;
70 static int hf_clnp_reassembled_in = -1;
71
72 static const fragment_items clnp_frag_items = {
73         &ett_clnp_segment,
74         &ett_clnp_segments,
75         &hf_clnp_segments,
76         &hf_clnp_segment,
77         &hf_clnp_segment_overlap,
78         &hf_clnp_segment_overlap_conflict,
79         &hf_clnp_segment_multiple_tails,
80         &hf_clnp_segment_too_long_segment,
81         &hf_clnp_segment_error,
82         &hf_clnp_reassembled_in,
83         "segments"
84 };
85
86 static dissector_handle_t clnp_handle;
87 static dissector_handle_t ositp_handle;
88 static dissector_handle_t ositp_inactive_handle;
89 static dissector_handle_t data_handle;
90
91 /*
92  * ISO 8473 OSI CLNP definition (see RFC994)
93  *
94  *            _________________________________
95  *           |           Fixed Part            |
96  *           |_________________________________|
97  *           |          Address Part           |
98  *           |_________________________________|
99  *           |   Segmentation Part (optional)  |
100  *           |_________________________________|
101  *           |     Options Part (optional)     |
102  *           |_________________________________|
103  *           |         Data (optional)         |
104  *           |_________________________________|
105  */
106
107 #define ISO8473_V1  0x01    /* CLNP version 1 */
108
109 /* Fixed part */
110
111 #define CNF_TYPE                0x1f
112 #define CNF_ERR_OK              0x20
113 #define CNF_MORE_SEGS           0x40
114 #define CNF_SEG_OK              0x80
115
116 #define DT_NPDU                 0x1C
117 #define MD_NPDU                 0x1D
118 #define ER_NPDU                 0x01
119 #define ERQ_NPDU                0x1E
120 #define ERP_NPDU                0x1F
121
122 static const value_string npdu_type_abbrev_vals[] = {
123   { DT_NPDU,    "DT" },
124   { MD_NPDU,    "MD" },
125   { ER_NPDU,    "ER" },
126   { ERQ_NPDU,   "ERQ" },
127   { ERP_NPDU,   "ERP" },
128   { 0,          NULL }
129 };
130
131 static const value_string npdu_type_vals[] = {
132   { DT_NPDU,    "Data" },
133   { MD_NPDU,    "Multicast Data" },
134   { ER_NPDU,    "Error Report" },
135   { ERQ_NPDU,   "Echo Request" },
136   { ERP_NPDU,   "Echo Response" },
137   { 0,          NULL }
138 };
139
140 /* field position */
141
142 #define P_CLNP_PROTO_ID         0
143 #define P_CLNP_HDR_LEN          1
144 #define P_CLNP_VERS             2
145 #define P_CLNP_TTL              3
146 #define P_CLNP_TYPE             4
147 #define P_CLNP_SEGLEN           5
148 #define P_CLNP_CKSUM            7
149 #define P_CLNP_ADDRESS_PART     9
150
151 /* Segmentation part */
152
153 struct clnp_segment {
154   gushort       cng_id;         /* data unit identifier */
155   gushort       cng_off;        /* segment offset */
156   gushort       cng_tot_len;    /* total length */
157 };
158
159 /* NSAP selector */
160
161 #define NSEL_NET                0x00
162 #define NSEL_NP                 0x20
163 #define NSEL_TP                 0x21
164
165 /* global variables */
166
167 /* List of dissectors to call for CLNP packets */
168 static heur_dissector_list_t clnp_heur_subdissector_list;
169
170 /*
171  * Reassembly of CLNP.
172  */
173 static GHashTable *clnp_segment_table = NULL;
174 static GHashTable *clnp_reassembled_table = NULL;
175
176 /* options */
177 static guint tp_nsap_selector = NSEL_TP;
178 static gboolean always_decode_transport = FALSE;
179 static gboolean clnp_reassemble = TRUE;
180
181 /* function definitions */
182
183 /*
184  *  CLNP part / main entry point
185 */
186
187 static void dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
188 {
189   proto_tree *clnp_tree = NULL;
190   proto_item *ti;
191   guint8      cnf_proto_id;
192   guint8      cnf_hdr_len;
193   guint8      cnf_vers;
194   guint8      cnf_ttl;
195   guint8      cnf_type;
196   char        flag_string[6+1];
197   const char *pdu_type_string;
198   proto_tree *type_tree;
199   guint16     segment_length;
200   guint16     du_id = 0;
201   guint16     segment_offset = 0;
202   guint16     cnf_cksum;
203   cksum_status_t cksum_status;
204   int         offset;
205   guchar      src_len, dst_len, nsel, opt_len = 0;
206   const guint8     *dst_addr, *src_addr;
207   gint        len;
208   guint       next_length;
209   proto_tree *discpdu_tree;
210   gboolean    save_in_error_pkt;
211   fragment_data *fd_head;
212   tvbuff_t   *next_tvb;
213   gboolean    update_col_info = TRUE;
214   gboolean    save_fragmented;
215
216   col_set_str(pinfo->cinfo, COL_PROTOCOL, "CLNP");
217   col_clear(pinfo->cinfo, COL_INFO);
218
219   cnf_proto_id = tvb_get_guint8(tvb, P_CLNP_PROTO_ID);
220   if (cnf_proto_id == NLPID_NULL) {
221     col_set_str(pinfo->cinfo, COL_INFO, "Inactive subset");
222     if (tree) {
223       ti = proto_tree_add_item(tree, proto_clnp, tvb, P_CLNP_PROTO_ID, 1, FALSE);
224       clnp_tree = proto_item_add_subtree(ti, ett_clnp);
225       proto_tree_add_uint_format(clnp_tree, hf_clnp_id, tvb, P_CLNP_PROTO_ID, 1,
226                                  cnf_proto_id,
227                                  "Inactive subset");
228     }
229     next_tvb = tvb_new_subset_remaining(tvb, 1);
230     if (call_dissector(ositp_inactive_handle, next_tvb, pinfo, tree) == 0)
231       call_dissector(data_handle,tvb, pinfo, tree);
232     return;
233   }
234
235   /* return if version not known */
236   cnf_vers = tvb_get_guint8(tvb, P_CLNP_VERS);
237   if (cnf_vers != ISO8473_V1) {
238     call_dissector(data_handle,tvb, pinfo, tree);
239     return;
240   }
241
242   /* fixed part decoding */
243   cnf_hdr_len = tvb_get_guint8(tvb, P_CLNP_HDR_LEN);
244   opt_len = cnf_hdr_len;
245
246   if (tree) {
247     ti = proto_tree_add_item(tree, proto_clnp, tvb, 0, cnf_hdr_len, FALSE);
248     clnp_tree = proto_item_add_subtree(ti, ett_clnp);
249     proto_tree_add_uint(clnp_tree, hf_clnp_id, tvb, P_CLNP_PROTO_ID, 1,
250                                cnf_proto_id);
251     proto_tree_add_uint(clnp_tree, hf_clnp_length, tvb, P_CLNP_HDR_LEN, 1,
252                         cnf_hdr_len);
253     proto_tree_add_uint(clnp_tree, hf_clnp_version, tvb, P_CLNP_VERS, 1,
254                         cnf_vers);
255     cnf_ttl = tvb_get_guint8(tvb, P_CLNP_TTL);
256     proto_tree_add_uint_format(clnp_tree, hf_clnp_ttl, tvb, P_CLNP_TTL, 1,
257                                cnf_ttl,
258                                "Holding Time : %u (%u.%u secs)",
259                                cnf_ttl, cnf_ttl / 2, (cnf_ttl % 2) * 5);
260   }
261
262   cnf_type = tvb_get_guint8(tvb, P_CLNP_TYPE);
263   pdu_type_string = val_to_str(cnf_type & CNF_TYPE, npdu_type_abbrev_vals,
264                                 "Unknown (0x%02x)");
265   flag_string[0] = '\0';
266   if (cnf_type & CNF_SEG_OK)
267     g_strlcat(flag_string, "S ", 7);
268   if (cnf_type & CNF_MORE_SEGS)
269     g_strlcat(flag_string, "M ", 7);
270   if (cnf_type & CNF_ERR_OK)
271     g_strlcat(flag_string, "E ", 7);
272   if (tree) {
273     ti = proto_tree_add_uint_format(clnp_tree, hf_clnp_type, tvb, P_CLNP_TYPE, 1,
274                                cnf_type,
275                                "PDU Type     : 0x%02x (%s%s)",
276                                cnf_type,
277                                flag_string,
278                                pdu_type_string);
279     type_tree = proto_item_add_subtree(ti, ett_clnp_type);
280     proto_tree_add_text(type_tree, tvb, P_CLNP_TYPE, 1, "%s",
281                         decode_boolean_bitfield(cnf_type, CNF_SEG_OK, 8,
282                                       "Segmentation permitted",
283                                       "Segmentation not permitted"));
284     proto_tree_add_text(type_tree, tvb, P_CLNP_TYPE, 1, "%s",
285                         decode_boolean_bitfield(cnf_type, CNF_MORE_SEGS, 8,
286                                       "More segments",
287                                       "Last segment"));
288     proto_tree_add_text(type_tree, tvb, P_CLNP_TYPE, 1, "%s",
289                         decode_boolean_bitfield(cnf_type, CNF_ERR_OK, 8,
290                                       "Report error if PDU discarded",
291                                       "Don't report error if PDU discarded"));
292     proto_tree_add_text(type_tree, tvb, P_CLNP_TYPE, 1, "%s",
293                         decode_enumerated_bitfield(cnf_type, CNF_TYPE, 8,
294                                       npdu_type_vals, "%s"));
295   }
296
297   /* If we don't have the full header - i.e., not enough to see the
298      segmentation part and determine whether this datagram is segmented
299      or not - set the Info column now; we'll get an exception before
300      we set it otherwise. */
301
302   if (tvb_length(tvb) < cnf_hdr_len) {
303     if (check_col(pinfo->cinfo, COL_INFO))
304       col_add_fstr(pinfo->cinfo, COL_INFO, "%s NPDU %s", pdu_type_string, flag_string);
305   }
306
307   segment_length = tvb_get_ntohs(tvb, P_CLNP_SEGLEN);
308   cnf_cksum = tvb_get_ntohs(tvb, P_CLNP_CKSUM);
309   cksum_status = calc_checksum(tvb, 0, cnf_hdr_len, cnf_cksum);
310   if (tree) {
311     proto_tree_add_uint(clnp_tree, hf_clnp_pdu_length, tvb, P_CLNP_SEGLEN, 2,
312                         segment_length);
313     switch (cksum_status) {
314
315     default:
316         /*
317          * No checksum present, or not enough of the header present to
318          * checksum it.
319          */
320         proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
321                                P_CLNP_CKSUM, 2,
322                                cnf_cksum,
323                                "Checksum     : 0x%04x",
324                                cnf_cksum);
325         break;
326
327     case CKSUM_OK:
328         /*
329          * Checksum is correct.
330          */
331         proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
332                                P_CLNP_CKSUM, 2,
333                                cnf_cksum,
334                                "Checksum     : 0x%04x (correct)",
335                                cnf_cksum);
336         break;
337
338     case CKSUM_NOT_OK:
339         /*
340          * Checksum is not correct.
341          */
342         proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
343                                P_CLNP_CKSUM, 2,
344                                cnf_cksum,
345                                "Checksum     : 0x%04x (incorrect)",
346                                cnf_cksum);
347         break;
348     }
349     opt_len -= 9; /* Fixed part of Hesder */
350   } /* tree */
351
352   /* address part */
353
354   offset = P_CLNP_ADDRESS_PART;
355   dst_len  = tvb_get_guint8(tvb, offset);
356   dst_addr = tvb_get_ptr(tvb, offset + 1, dst_len);
357   nsel     = tvb_get_guint8(tvb, offset + dst_len);
358   src_len  = tvb_get_guint8(tvb, offset + dst_len + 1);
359   src_addr = tvb_get_ptr(tvb, offset + dst_len + 2, src_len);
360
361   if (tree) {
362     proto_tree_add_uint(clnp_tree, hf_clnp_dest_length, tvb, offset, 1,
363                         dst_len);
364     proto_tree_add_bytes_format(clnp_tree, hf_clnp_dest, tvb, offset + 1 , dst_len,
365                                dst_addr,
366                                " DA : %s",
367                                print_nsap_net(dst_addr, dst_len));
368     proto_tree_add_uint(clnp_tree, hf_clnp_src_length, tvb,
369                         offset + 1 + dst_len, 1, src_len);
370     proto_tree_add_bytes_format(clnp_tree, hf_clnp_src, tvb,
371                                offset + dst_len + 2, src_len,
372                                src_addr,
373                                " SA : %s",
374                                print_nsap_net(src_addr, src_len));
375
376     opt_len -= dst_len + src_len +2;
377   }
378
379   SET_ADDRESS(&pinfo->net_src, AT_OSI, src_len, src_addr);
380   SET_ADDRESS(&pinfo->src, AT_OSI, src_len, src_addr);
381   SET_ADDRESS(&pinfo->net_dst, AT_OSI, dst_len, dst_addr);
382   SET_ADDRESS(&pinfo->dst, AT_OSI, dst_len, dst_addr);
383
384   /* Segmentation Part */
385
386   offset += dst_len + src_len + 2;
387
388   if (cnf_type & CNF_SEG_OK) {
389     struct clnp_segment seg;                    /* XXX - not used */
390     tvb_memcpy(tvb, (guint8 *)&seg, offset, sizeof(seg));       /* XXX - not used */
391
392     segment_offset = tvb_get_ntohs(tvb, offset + 2);
393     du_id = tvb_get_ntohs(tvb, offset);
394     if (tree) {
395       proto_tree_add_text(clnp_tree, tvb, offset, 2,
396                         "Data unit identifier: %06u",
397                         du_id);
398       proto_tree_add_text(clnp_tree, tvb, offset + 2 , 2,
399                         "Segment offset      : %6u",
400                         segment_offset);
401       proto_tree_add_text(clnp_tree, tvb, offset + 4 , 2,
402                         "Total length        : %6u",
403                         tvb_get_ntohs(tvb, offset + 4));
404     }
405
406     offset  += 6;
407     opt_len -= 6;
408   }
409
410   if (tree) {
411     /* To do : decode options  */
412 /*
413     proto_tree_add_text(clnp_tree, tvb, offset,
414                         cnf_hdr_len - offset,
415                         "Options/Data: <not shown>");
416 */
417 /* QUICK HACK Option Len:= PDU_Hd_length-( FixedPart+AddresPart+SegmentPart )*/
418
419     dissect_osi_options( opt_len,
420                          tvb, offset, clnp_tree );
421   }
422
423   /* Length of CLNP datagram plus headers above it. */
424   len = segment_length;
425
426   offset = cnf_hdr_len;
427
428   /* If clnp_reassemble is on, this is a segment, we have all the
429    * data in the segment, and the checksum is valid, then just add the
430    * segment to the hashtable.
431    */
432   save_fragmented = pinfo->fragmented;
433   if (clnp_reassemble && (cnf_type & CNF_SEG_OK) &&
434         ((cnf_type & CNF_MORE_SEGS) || segment_offset != 0) &&
435         tvb_bytes_exist(tvb, offset, segment_length - cnf_hdr_len) &&
436         segment_length > cnf_hdr_len &&
437         cksum_status != CKSUM_NOT_OK) {
438     fd_head = fragment_add_check(tvb, offset, pinfo, du_id, clnp_segment_table,
439                            clnp_reassembled_table, segment_offset,
440                            segment_length - cnf_hdr_len,
441                            cnf_type & CNF_MORE_SEGS);
442
443     next_tvb = process_reassembled_data(tvb, offset, pinfo, "Reassembled CLNP",
444         fd_head, &clnp_frag_items, &update_col_info, clnp_tree);
445   } else {
446     /* If this is the first segment, dissect its contents, otherwise
447        just show it as a segment.
448
449        XXX - if we eventually don't save the reassembled contents of all
450        segmented datagrams, we may want to always reassemble. */
451     if ((cnf_type & CNF_SEG_OK) && segment_offset != 0) {
452       /* Not the first segment - don't dissect it. */
453       next_tvb = NULL;
454     } else {
455       /* First segment, or not segmented.  Dissect what we have here. */
456
457       /* Get a tvbuff for the payload. */
458       next_tvb = tvb_new_subset_remaining(tvb, offset);
459
460       /*
461        * If this is the first segment, but not the only segment,
462        * tell the next protocol that.
463        */
464       if ((cnf_type & (CNF_SEG_OK|CNF_MORE_SEGS)) == (CNF_SEG_OK|CNF_MORE_SEGS))
465         pinfo->fragmented = TRUE;
466       else
467         pinfo->fragmented = FALSE;
468     }
469   }
470
471   if (next_tvb == NULL) {
472     /* Just show this as a segment. */
473     if (check_col(pinfo->cinfo, COL_INFO))
474       col_add_fstr(pinfo->cinfo, COL_INFO, "Fragmented %s NPDU %s(off=%u)",
475                 pdu_type_string, flag_string, segment_offset);
476
477     /* As we haven't reassembled anything, we haven't changed "pi", so
478        we don't have to restore it. */
479     call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo,
480                    tree);
481     pinfo->fragmented = save_fragmented;
482     return;
483   }
484
485   if (tvb_offset_exists(tvb, offset)) {
486     switch (cnf_type & CNF_TYPE) {
487
488     case DT_NPDU:
489     case MD_NPDU:
490       /* Continue with COTP if any data.
491          XXX - if this isn't the first Derived PDU of a segmented Initial
492          PDU, skip that? */
493
494       if (nsel == (char)tp_nsap_selector || always_decode_transport) {
495         if (call_dissector(ositp_handle, next_tvb, pinfo, tree) != 0) {
496           pinfo->fragmented = save_fragmented;
497           return;       /* yes, it appears to be COTP or CLTP */
498         }
499       }
500       if (dissector_try_heuristic(clnp_heur_subdissector_list, next_tvb,
501                                   pinfo, tree)) {
502           pinfo->fragmented = save_fragmented;
503           return;       /* yes, it appears to be one of the protocols in the heuristic list */
504       }
505
506       break;
507
508     case ER_NPDU:
509       /* The payload is the header and "none, some, or all of the data
510          part of the discarded PDU", i.e. it's like an ICMP error;
511          dissect it as a CLNP PDU. */
512       if (check_col(pinfo->cinfo, COL_INFO))
513         col_add_fstr(pinfo->cinfo, COL_INFO, "%s NPDU %s", pdu_type_string, flag_string);
514       if (tree) {
515         next_length = tvb_length_remaining(tvb, offset);
516         if (next_length != 0) {
517           /* We have payload; dissect it. */
518           ti = proto_tree_add_text(clnp_tree, tvb, offset, next_length,
519             "Discarded PDU");
520           discpdu_tree = proto_item_add_subtree(ti, ett_clnp_disc_pdu);
521
522           /* Save the current value of the "we're inside an error packet"
523              flag, and set that flag; subdissectors may treat packets
524              that are the payload of error packets differently from
525              "real" packets. */
526           save_in_error_pkt = pinfo->in_error_pkt;
527           pinfo->in_error_pkt = TRUE;
528
529           call_dissector(clnp_handle, next_tvb, pinfo, discpdu_tree);
530
531           /* Restore the "we're inside an error packet" flag. */
532           pinfo->in_error_pkt = save_in_error_pkt;
533         }
534       }
535       pinfo->fragmented = save_fragmented;
536       return;   /* we're done with this PDU */
537
538     case ERQ_NPDU:
539     case ERP_NPDU:
540       /* XXX - dissect this */
541       break;
542     }
543   }
544   if (check_col(pinfo->cinfo, COL_INFO))
545     col_add_fstr(pinfo->cinfo, COL_INFO, "%s NPDU %s", pdu_type_string, flag_string);
546   call_dissector(data_handle,next_tvb, pinfo, tree);
547   pinfo->fragmented = save_fragmented;
548 } /* dissect_clnp */
549
550 static void
551 clnp_reassemble_init(void)
552 {
553   fragment_table_init(&clnp_segment_table);
554   reassembled_table_init(&clnp_reassembled_table);
555 }
556
557 void proto_register_clnp(void)
558 {
559   static hf_register_info hf[] = {
560     { &hf_clnp_id,
561       { "Network Layer Protocol Identifier", "clnp.nlpi", FT_UINT8, BASE_HEX,
562         VALS(nlpid_vals), 0x0, NULL, HFILL }},
563
564     { &hf_clnp_length,
565       { "HDR Length", "clnp.len",          FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
566
567     { &hf_clnp_version,
568       { "Version", "clnp.version",  FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
569
570     { &hf_clnp_ttl,
571       { "Holding Time", "clnp.ttl",        FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
572
573     { &hf_clnp_type,
574       { "PDU Type", "clnp.type",     FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
575
576     { &hf_clnp_pdu_length,
577       { "PDU length", "clnp.pdu.len",  FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
578
579     { &hf_clnp_checksum,
580       { "Checksum", "clnp.checksum", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
581
582     { &hf_clnp_dest_length,
583       { "DAL", "clnp.dsap.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
584
585     { &hf_clnp_dest,
586       { "DA", "clnp.dsap",     FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
587
588     { &hf_clnp_src_length,
589       { "SAL", "clnp.ssap.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
590
591     { &hf_clnp_src,
592       { "SA", "clnp.ssap",     FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
593
594     { &hf_clnp_segment_overlap,
595       { "Segment overlap", "clnp.segment.overlap", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
596         "Segment overlaps with other segments", HFILL }},
597
598     { &hf_clnp_segment_overlap_conflict,
599       { "Conflicting data in segment overlap", "clnp.segment.overlap.conflict", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
600         "Overlapping segments contained conflicting data", HFILL }},
601
602     { &hf_clnp_segment_multiple_tails,
603       { "Multiple tail segments found", "clnp.segment.multipletails", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
604         "Several tails were found when reassembling the packet", HFILL }},
605
606     { &hf_clnp_segment_too_long_segment,
607       { "Segment too long", "clnp.segment.toolongsegment", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
608         "Segment contained data past end of packet", HFILL }},
609
610     { &hf_clnp_segment_error,
611       { "Reassembly error", "clnp.segment.error", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
612         "Reassembly error due to illegal segments", HFILL }},
613
614     { &hf_clnp_segment,
615       { "CLNP Segment", "clnp.segment", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
616         NULL, HFILL }},
617
618     { &hf_clnp_segments,
619       { "CLNP Segments", "clnp.segments", FT_NONE, BASE_NONE, NULL, 0x0,
620         NULL, HFILL }},
621
622     { &hf_clnp_reassembled_in,
623       { "Reassembled CLNP in frame", "clnp.reassembled_in", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
624         "This CLNP packet is reassembled in this frame", HFILL }}
625   };
626   static gint *ett[] = {
627     &ett_clnp,
628     &ett_clnp_type,
629     &ett_clnp_segments,
630     &ett_clnp_segment,
631     &ett_clnp_disc_pdu,
632   };
633
634   module_t *clnp_module;
635
636   proto_clnp = proto_register_protocol(PROTO_STRING_CLNP, "CLNP", "clnp");
637   proto_register_field_array(proto_clnp, hf, array_length(hf));
638   proto_register_subtree_array(ett, array_length(ett));
639   register_dissector("clnp", dissect_clnp, proto_clnp);
640   register_heur_dissector_list("clnp", &clnp_heur_subdissector_list);
641   register_init_routine(clnp_reassemble_init);
642
643   clnp_module = prefs_register_protocol(proto_clnp, NULL);
644   prefs_register_uint_preference(clnp_module, "tp_nsap_selector",
645         "NSAP selector for Transport Protocol (last byte in hex)",
646         "NSAP selector for Transport Protocol (last byte in hex)",
647         16, &tp_nsap_selector);
648   prefs_register_bool_preference(clnp_module, "always_decode_transport",
649         "Always try to decode NSDU as transport PDUs",
650         "Always try to decode NSDU as transport PDUs",
651         &always_decode_transport);
652   prefs_register_bool_preference(clnp_module, "reassemble",
653         "Reassemble segmented CLNP datagrams",
654         "Whether segmented CLNP datagrams should be reassembled",
655         &clnp_reassemble);
656 }
657
658 void
659 proto_reg_handoff_clnp(void)
660 {
661   ositp_handle = find_dissector("ositp");
662   ositp_inactive_handle = find_dissector("ositp_inactive");
663   data_handle = find_dissector("data");
664
665   clnp_handle = create_dissector_handle(dissect_clnp, proto_clnp);
666   dissector_add("osinl", NLPID_ISO8473_CLNP, clnp_handle);
667   dissector_add("osinl", NLPID_NULL, clnp_handle); /* Inactive subset */
668   dissector_add("x.25.spi", NLPID_ISO8473_CLNP, clnp_handle);
669 }