Some minor bugfixes for netlogon
[obnox/wireshark/wip.git] / packet-osi-options.c
1 /* packet-osi-options.c
2  * Routines for the decode of ISO/OSI option part 
3  * Covers:
4  * ISO  8473 CLNP (ConnectionLess Mode Network Service Protocol)
5  * ISO 10589 ISIS (Intradomain Routing Information Exchange Protocol)
6  * ISO  9542 ESIS (End System To Intermediate System Routing Exchange Protocol)
7  *
8  * $Id: packet-osi-options.c,v 1.9 2002/01/21 07:36:38 guy Exp $
9  * Ralf Schneider <Ralf.Schneider@t-online.de>
10  *
11  * Ethereal - Network traffic analyzer
12  * By Gerald Combs <gerald@ethereal.com>
13  * Copyright 1998 Gerald Combs
14  * 
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.
19  * 
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.
24  * 
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.
28  *
29  *
30  */
31
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #ifdef HAVE_SYS_TYPES_H
37 # include <sys/types.h>
38 #endif
39
40 #include <stdio.h>
41 #include <string.h>
42 #include <glib.h>
43 #include <epan/packet.h>
44 #include "nlpid.h"
45 #include "packet-osi.h"
46 #include "packet-isis.h"
47 #include "packet-isis-clv.h"
48 #include "packet-isis-hello.h"
49 #include "packet-isis-lsp.h"
50 #include "packet-isis-snp.h"
51 #include "packet-esis.h"
52 #include "packet-osi-options.h"
53
54 #define OSI_OPT_SECURITY           0xc5
55 #define OSI_OPT_QOS_MAINTANANCE    0xc3
56 #define OSI_OPT_PRIORITY           0xcd
57 #define OSI_OPT_ADDRESS_MASK       0xe1
58 #define OSI_OPT_SNPA_MASK          0xe2
59 #define OSI_OPT_ES_CONFIG_TIMER    0xc6
60
61 #define OSI_OPT_MAX_PRIORITY       0x0e
62
63 #define OSI_OPT_PADDING            0xcc
64 #define OSI_OPT_SOURCE_ROUTING     0xc8
65 #define OSI_OPT_RECORD_OF_ROUTE    0xcb
66 #define OSI_OPT_REASON_OF_DISCARD  0xc1
67
68 #define OSI_OPT_SEC_MASK           0xc0
69 #define OSI_OPT_SEC_RESERVED       0x00
70 #define OSI_OPT_SEC_SRC_ADR_SPEC   0x40
71 #define OSI_OPT_SEC_DST_ADR_SPEC   0x80
72 #define OSI_OPT_SEC_GLOBAL_UNIQUE  0xc0
73
74 #define OSI_OPT_QOS_MASK           0xc0
75 #define OSI_OPT_QOS_RESERVED       0x00
76 #define OSI_OPT_QOS_SRC_ADR_SPEC   0x40
77 #define OSI_OPT_QOS_DST_ADR_SPEC   0x80
78 #define OSI_OPT_QOS_GLOBAL_UNIQUE  0xc0
79  
80 #define OSI_OPT_QOS_SUB_MASK        0x3f
81 #define OSI_OPT_QOS_SUB_RSVD        0x20
82 #define OSI_OPT_QOS_SUB_SEQ_VS_TRS  0x10
83 #define OSI_OPT_QOS_SUB_CONG_EXPED  0x08
84 #define OSI_OPT_QOS_SUB_TSD_VS_COST 0x04
85 #define OSI_OPT_QOS_SUB_RESERR_TRS  0x02
86 #define OSI_OPT_QOS_SUB_RESERR_COST 0x01
87
88 #define OSI_OPT_RFD_GENERAL         0x00
89 #define OSI_OPT_RFD_ADDRESS         0x80
90 #define OSI_OPT_RFD_SOURCE_ROUTING  0x90
91 #define OSI_OPT_RFD_LIFETIME        0xa0
92 #define OSI_OPT_RFD_PDU_DISCARDED   0xb0
93 #define OSI_OPT_RFD_REASSEMBLY      0xc0
94
95 #define OSI_OPT_RFD_MASK            0xf0
96 #define OSI_OPT_RFD_SUB_MASK        0x0f
97
98
99
100
101 static gint ott_osi_options       = -1;
102 static gint ott_osi_qos           = -1;
103 static gint ott_osi_route         = -1;
104 static gint ott_osi_redirect      = -1;
105
106 static const value_string osi_opt_sec_vals[] = {
107         { OSI_OPT_SEC_RESERVED,      "Reserved"},
108         { OSI_OPT_SEC_SRC_ADR_SPEC,  "Source Address Specific"},
109         { OSI_OPT_SEC_DST_ADR_SPEC,  "Destination Address Specific"},
110         { OSI_OPT_SEC_GLOBAL_UNIQUE, "Globally Unique"},
111         { 0,            NULL} };
112      
113 static const value_string osi_opt_qos_vals[] = {
114         { OSI_OPT_QOS_RESERVED,      "Reserved"},
115         { OSI_OPT_QOS_SRC_ADR_SPEC,  "Source Address Specific"},
116         { OSI_OPT_QOS_DST_ADR_SPEC,  "Destination Address Specific"},
117         { OSI_OPT_QOS_GLOBAL_UNIQUE, "Globally Unique"},
118         { 0,            NULL} };
119      
120 static const value_string osi_opt_qos_sub_vals[] = {
121         { 0x20,  " xx10 0000 Reserved"},
122         { 0x10,  " xx01 0000 Sequencing versus transit delay"},
123         { 0x08,  " xx00 1000 Congestion experienced"},
124         { 0x04,  " xx00 0100 Transit delay versus cost"},
125         { 0x02,  " xx00 0010 Residual error probability versus transit delay"},
126         { 0x01,  " xx00 0001 Residual error probability versus cost"},
127         { 0,            NULL} };
128   
129 static const value_string osi_opt_rfd_general[] = {
130         { 0x00, "Reason not specified"},
131         { 0x01, "Protocol procedure error"},
132         { 0x02, "Incorrect checksum"},
133         { 0x03, "PDU discarded due to congestion"},
134         { 0x04, "Header syntax error ( cannot be parsed )"},
135         { 0x05, "Segmentation needed but not permitted"},
136         { 0x06, "Incomplete PDU received"},
137         { 0x07, "Duplicate option"},
138         { 0,    NULL} };
139      
140 static const value_string osi_opt_rfd_address[] = {
141         { 0x00, "Destination Address unreachable"},
142         { 0x01, "Destination Address unknown"},
143         { 0,    NULL} };
144      
145 static const value_string osi_opt_rfd_src_route[] = {
146         { 0x00, "Unspecified source routing error"},
147         { 0x01, "Syntax error in source routing field"},
148         { 0x02, "Unknown address in source routing field"},
149         { 0x03, "Path not acceptable"},
150         { 0,    NULL} };
151      
152 static const value_string osi_opt_rfd_lifetime[] = {
153         { 0x00, "Lifetime expired while data unit in transit"},
154         { 0x01, "Lifetime expired during reassembly"},
155         { 0,    NULL} };
156      
157 static const value_string osi_opt_rfd_discarded[] = {
158         { 0x00, "Unsupported option not specified"},
159         { 0x01, "Unsupported protocol version"},
160         { 0x02, "Unsupported security option"},
161         { 0x03, "Unsupported source routing option"},
162         { 0x04, "Unsupported recording of route option"},
163         { 0,    NULL} };
164      
165 static const value_string osi_opt_rfd_reassembly[] = {
166         { 0x00, "Reassembly interference"},
167         { 0,    NULL} };
168      
169
170 void
171 dissect_option_qos( const u_char type, const u_char sub_type, int offset,
172                     u_char len, tvbuff_t *tvb, proto_tree *tree ) {
173
174   u_char      tmp_type = 0;
175   proto_item *ti;
176   proto_tree *osi_qos_tree = NULL;
177   
178   
179   ti = proto_tree_add_text( tree, tvb, offset, len,
180                             "Quality of service maintenance: %s",
181                        val_to_str( type, osi_opt_qos_vals, "Unknown (0x%x)") );
182   
183   osi_qos_tree = proto_item_add_subtree( ti, ott_osi_qos );
184                            
185   if ( OSI_OPT_SEC_MASK == type ) {     /* Analye BIT field to get all Values */
186
187     tmp_type = sub_type & OSI_OPT_QOS_SUB_RSVD;
188     if ( tmp_type ) {
189          proto_tree_add_text( osi_qos_tree, tvb, offset, len,
190          val_to_str( tmp_type, osi_opt_qos_sub_vals, "Unknown (0x%x)") );
191     }
192     tmp_type = sub_type & OSI_OPT_QOS_SUB_SEQ_VS_TRS;
193     if ( tmp_type ) {
194          proto_tree_add_text( osi_qos_tree, tvb, offset, len,
195          val_to_str( tmp_type, osi_opt_qos_sub_vals, "Unknown (0x%x)") );
196     }
197     tmp_type = sub_type &OSI_OPT_QOS_SUB_CONG_EXPED;
198     if ( tmp_type ) {
199          proto_tree_add_text( osi_qos_tree, tvb, offset, len,
200          val_to_str( tmp_type, osi_opt_qos_sub_vals, "Unknown (0x%x)") );
201     }
202     tmp_type = sub_type & OSI_OPT_QOS_SUB_TSD_VS_COST;
203     
204     if ( tmp_type ) {
205          proto_tree_add_text( osi_qos_tree, tvb, offset, len,
206          val_to_str( tmp_type, osi_opt_qos_sub_vals, "Unknown (0x%x)") );
207     }
208     tmp_type = sub_type & OSI_OPT_QOS_SUB_RESERR_TRS;
209     if ( tmp_type ) {
210          proto_tree_add_text( osi_qos_tree, tvb, offset, len,
211          val_to_str( tmp_type, osi_opt_qos_sub_vals, "Unknown (0x%x)") );
212     }
213     tmp_type = sub_type & OSI_OPT_QOS_SUB_RESERR_COST;
214     if ( tmp_type ) {
215          proto_tree_add_text( osi_qos_tree, tvb, offset, len,
216          val_to_str( tmp_type, osi_opt_qos_sub_vals, "Unknown (0x%x)") );
217     }
218   }
219 }
220
221 void
222 dissect_option_route( u_char parm_type, u_char offset, u_char parm_len, 
223                       tvbuff_t *tvb, proto_tree *tree ) {
224
225   u_char      next_hop = 0;
226   u_char      this_hop = 0;
227   u_char      netl     = 0;
228   u_char      last_hop = 0;
229   u_char      cnt_hops = 0;
230   
231   proto_item *ti;
232   proto_tree *osi_route_tree = NULL;
233
234   static const value_string osi_opt_route[] = {
235         { 0x03, "No Network Entity Titles Recorded Yet"},
236         { 0xff, "Recording Terminated !"},
237         { 0,    NULL} };
238
239   if ( parm_type == OSI_OPT_SOURCE_ROUTING ) {
240     next_hop = tvb_get_guint8(tvb, offset + 1 );
241     netl     = tvb_get_guint8(tvb, next_hop + 2 );
242     this_hop = offset + 3;         /* points to first netl */
243
244     ti = proto_tree_add_text( tree, tvb, offset + next_hop, netl, 
245             "Source Routing: %s   ( Next Hop Highlighted In Data Buffer )",
246             (tvb_get_guint8(tvb, offset) == 0) ? "Partial Source Routing" :
247                                                  "Complete Source Routing"  ); 
248   }
249   else {
250     last_hop = tvb_get_guint8(tvb, offset + 1 );
251         /* points to the end of the list */
252     netl     = tvb_get_guint8(tvb, last_hop );
253         /* mis-used to highlight buffer */
254
255     ti = proto_tree_add_text( tree, tvb, offset + next_hop, netl,
256             "Record of Route: %s : %s",
257             (tvb_get_guint8(tvb, offset) == 0) ? "Partial Source Routing" :
258                                                  "Complete Source Routing" ,
259             val_to_str( last_hop, osi_opt_route, "Unknown (0x%x" ) );
260     if ( 255 == last_hop ) 
261       this_hop = parm_len + 1;   /* recording terminated, nothing to show */
262     else
263       this_hop = offset + 3;
264   }
265   osi_route_tree = proto_item_add_subtree( ti, ott_osi_route );
266   
267   while ( this_hop < parm_len ) {
268     netl = tvb_get_guint8(tvb, this_hop + 1);
269     proto_tree_add_text( osi_route_tree, tvb, offset + this_hop, netl,
270                   "Hop #%3u NETL: %2u, NET: %s",
271                   cnt_hops++,
272                   netl,
273                   print_nsap_net( tvb_get_ptr(tvb, this_hop + 1, netl), netl ) );
274     this_hop += 1 + netl;
275   }
276 }
277
278
279
280
281
282 void
283 dissect_option_rfd( const u_char error, const u_char field, u_char offset,
284                           u_char len, tvbuff_t *tvb, proto_tree *tree ) {
285   u_char error_class = 0;
286   char   *format_string[] = 
287              { "Reason for discard {General}        : %s, in field %u",
288                "Reason for discard {Address}        : %s, in field %u",
289                "Reason for discard {Source Routing}: %s, in field %u",
290                "Reason for discard {Lifetime}       : %s, in field %u",
291                "Reason for discard {PDU discarded}  : %s, in field %u",
292                "Reason for discard {Reassembly}     : %s, in field %u"
293              };
294   
295   error_class = error & OSI_OPT_RFD_MASK;
296
297   if ( OSI_OPT_RFD_GENERAL == error_class ) {
298     proto_tree_add_text( tree, tvb, offset + field, 1, format_string[0],
299                          val_to_str( error & OSI_OPT_RFD_SUB_MASK,
300                                osi_opt_rfd_general, "Unknown (0x%x)"), field );
301   }
302   else if ( OSI_OPT_RFD_ADDRESS == error_class ) {
303     proto_tree_add_text( tree, tvb, offset + field, 1, format_string[1],
304                          val_to_str( error & OSI_OPT_RFD_SUB_MASK,
305                                osi_opt_rfd_address, "Unknown (0x%x)"), field );
306   }
307   else if ( OSI_OPT_RFD_SOURCE_ROUTING == error_class ) {
308     proto_tree_add_text( tree, tvb, offset + field, 1, format_string[2],
309                          val_to_str( error & OSI_OPT_RFD_SUB_MASK,
310                              osi_opt_rfd_src_route, "Unknown (0x%x)"), field );
311   }
312   else if ( OSI_OPT_RFD_LIFETIME == error_class ) {
313     proto_tree_add_text( tree, tvb, offset + field, 1, format_string[3],
314                          val_to_str( error & OSI_OPT_RFD_SUB_MASK,
315                               osi_opt_rfd_lifetime, "Unknown (0x%x)"), field );
316   }
317   else if ( OSI_OPT_RFD_PDU_DISCARDED == error_class ) {
318     proto_tree_add_text( tree, tvb, offset + field, 1, format_string[4],
319                          val_to_str( error & OSI_OPT_RFD_SUB_MASK,
320                              osi_opt_rfd_discarded, "Unknown (0x%x)"), field );
321   }
322   else if ( OSI_OPT_RFD_REASSEMBLY == error_class ) {
323     proto_tree_add_text( tree, tvb, offset + field, 1, format_string[5],
324                          val_to_str( error & OSI_OPT_RFD_SUB_MASK,
325                             osi_opt_rfd_reassembly, "Unknown (0x%x)"), field );
326   }
327   else {
328     proto_tree_add_text( tree, tvb, offset, len,
329                          "Reason for discard: UNKNOWN Error Class" );
330   } 
331 }
332
333 /* ############################## Dissection Functions ###################### */
334
335 /*
336  * Name: dissect_osi_options()
337  * 
338  * Description:
339  *   Main entry area for esis de-mangling.  This will build the
340  *   main esis tree data and call the sub-protocols as needed.
341  *
342  * Input:
343  *   u_char       : PDU type to check if option is allowed or not
344  *   u_char       : length of option section 
345  *   u_char *     : packet data
346  *   int          : offset into packet where we are (packet_data[offset]== start
347  *                  of what we care about)
348  *   frame_data * : frame data (whole packet with extra info)
349  *   proto_tree * : tree of display data.  May be NULL.
350  *
351  * Output:
352  *   void, but we will add to the proto_tree if it is not NULL.
353  */
354 void
355 dissect_osi_options( u_char pdu_type, u_char opt_len, tvbuff_t *tvb, 
356                      int offset, packet_info *pinfo, proto_tree *tree) {
357    proto_item *ti;
358    proto_tree *osi_option_tree = NULL;
359    u_char      parm_len        = 0;
360    u_char      parm_type       = 0;
361    guint8      octet;
362
363    if (tree) {
364      if ( 0 == opt_len ) {
365        proto_tree_add_text( tree, tvb, offset, 0, 
366                             "### No Options for this PDU ###" );
367        return;
368      }
369      
370      ti = proto_tree_add_text( tree, tvb, offset, opt_len,
371                                "### Option Section ###" );
372      osi_option_tree = proto_item_add_subtree( ti, ott_osi_options );
373
374      while ( 0 < opt_len ) {
375         parm_type   = (int) tvb_get_guint8(tvb, offset);
376         offset++;
377         parm_len    = (int) tvb_get_guint8(tvb, offset);
378         offset++;
379          
380         switch ( parm_type ) {
381           case   OSI_OPT_QOS_MAINTANANCE:
382                  octet = tvb_get_guint8(tvb, offset);
383                  dissect_option_qos( octet&OSI_OPT_QOS_MASK,
384                                      octet&OSI_OPT_QOS_SUB_MASK,
385                                      offset, parm_len, tvb, osi_option_tree );
386           break;
387           case   OSI_OPT_SECURITY:
388                  octet = tvb_get_guint8(tvb, offset);
389                  proto_tree_add_text( osi_option_tree, tvb, offset, parm_len,
390                   "Security type: %s",
391                   val_to_str( octet&OSI_OPT_SEC_MASK,
392                               osi_opt_sec_vals, "Unknown (0x%x)")  );
393           break;
394           case   OSI_OPT_PRIORITY:
395                  octet = tvb_get_guint8(tvb, offset);
396                  if ( OSI_OPT_MAX_PRIORITY >= octet ) { 
397                    proto_tree_add_text( osi_option_tree, tvb, offset, parm_len,
398                                         "Priority    : %u", octet );
399                  }
400                  else {
401                    proto_tree_add_text( osi_option_tree, tvb, offset, parm_len,
402                                         "Priority    : %u ( Invalid )", 
403                                         octet );
404                  } 
405           break;
406           case   OSI_OPT_ADDRESS_MASK:
407                  proto_tree_add_text( osi_option_tree, tvb, offset, parm_len,
408                   "Address Mask: %s",
409                   print_area( tvb_get_ptr(tvb, offset, parm_len), parm_len ) );
410           break;
411           case   OSI_OPT_SNPA_MASK:
412                  proto_tree_add_text( osi_option_tree, tvb, offset, parm_len,
413                   "SNPA Mask   : %s",
414                   print_system_id( tvb_get_ptr(tvb, offset, parm_len), parm_len ));
415           break;
416           case   OSI_OPT_ES_CONFIG_TIMER:
417                  proto_tree_add_text( osi_option_tree, tvb, offset, parm_len,
418                   "ESCT     : %u seconds", tvb_get_ntohs( tvb, offset ) ); 
419           break;
420           case   OSI_OPT_PADDING:
421                  proto_tree_add_text( osi_option_tree, tvb, offset, parm_len,
422                   "Padding  : %u Octets", parm_len ) ;
423           break;
424           case   OSI_OPT_SOURCE_ROUTING:
425           case   OSI_OPT_RECORD_OF_ROUTE:
426                  dissect_option_route( parm_type,
427                                        offset, parm_len, tvb, osi_option_tree );
428           break;
429           case   OSI_OPT_REASON_OF_DISCARD:
430                  dissect_option_rfd( tvb_get_guint8(tvb, offset),
431                                      tvb_get_guint8(tvb, offset + 1),
432                                      offset, parm_len, tvb, osi_option_tree );
433           break;
434         }
435         opt_len -= parm_len + 2;
436         offset  += parm_len;
437       }
438    } 
439 } /* dissect-osi-options */
440
441
442 /*
443  * Name: proto_register_osi_options()
444  *
445  * Description:
446  *      main register for esis protocol set.  We register some display
447  *      formats and the protocol module variables.
448  *
449  *      NOTE: this procedure to autolinked by the makefile process that
450  *      builds register.c
451  *
452  * Input:
453  *      void
454  *
455  * Output:
456  *      void
457  */
458
459 void
460 proto_register_osi_options(void) {
461   static gint *ott[] = {
462     &ott_osi_options,
463     &ott_osi_qos,
464     &ott_osi_route,
465     &ott_osi_redirect,
466   };
467   proto_register_subtree_array( ott, array_length(ott));
468 }