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