Home | History | Annotate | Line # | Download | only in dist
print-isoclns.c revision 1.7
      1  1.1  christos /*
      2  1.1  christos  * Copyright (c) 1992, 1993, 1994, 1995, 1996
      3  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      4  1.1  christos  *
      5  1.1  christos  * Redistribution and use in source and binary forms, with or without
      6  1.1  christos  * modification, are permitted provided that: (1) source code distributions
      7  1.1  christos  * retain the above copyright notice and this paragraph in its entirety, (2)
      8  1.1  christos  * distributions including binary code include the above copyright notice and
      9  1.1  christos  * this paragraph in its entirety in the documentation or other materials
     10  1.1  christos  * provided with the distribution, and (3) all advertising materials mentioning
     11  1.1  christos  * features or use of this software display the following acknowledgement:
     12  1.1  christos  * ``This product includes software developed by the University of California,
     13  1.1  christos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
     14  1.1  christos  * the University nor the names of its contributors may be used to endorse
     15  1.1  christos  * or promote products derived from this software without specific prior
     16  1.1  christos  * written permission.
     17  1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
     18  1.1  christos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
     19  1.1  christos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     20  1.1  christos  *
     21  1.1  christos  * Original code by Matt Thomas, Digital Equipment Corporation
     22  1.1  christos  *
     23  1.1  christos  * Extensively modified by Hannes Gredler (hannes (at) juniper.net) for more
     24  1.1  christos  * complete IS-IS & CLNP support.
     25  1.1  christos  */
     26  1.1  christos 
     27  1.2  christos #include <sys/cdefs.h>
     28  1.1  christos #ifndef lint
     29  1.7  christos __RCSID("$NetBSD: print-isoclns.c,v 1.7 2017/01/24 23:29:14 christos Exp $");
     30  1.1  christos #endif
     31  1.1  christos 
     32  1.1  christos #ifdef HAVE_CONFIG_H
     33  1.1  christos #include "config.h"
     34  1.1  christos #endif
     35  1.1  christos 
     36  1.7  christos #include <netdissect-stdinc.h>
     37  1.1  christos 
     38  1.1  christos #include <string.h>
     39  1.1  christos 
     40  1.7  christos #include "netdissect.h"
     41  1.1  christos #include "addrtoname.h"
     42  1.1  christos #include "ether.h"
     43  1.1  christos #include "nlpid.h"
     44  1.1  christos #include "extract.h"
     45  1.1  christos #include "gmpls.h"
     46  1.1  christos #include "oui.h"
     47  1.1  christos #include "signature.h"
     48  1.1  christos 
     49  1.7  christos static const char tstr[] = " [|isis]";
     50  1.7  christos 
     51  1.1  christos /*
     52  1.1  christos  * IS-IS is defined in ISO 10589.  Look there for protocol definitions.
     53  1.1  christos  */
     54  1.1  christos 
     55  1.1  christos #define SYSTEM_ID_LEN	ETHER_ADDR_LEN
     56  1.1  christos #define NODE_ID_LEN     SYSTEM_ID_LEN+1
     57  1.1  christos #define LSP_ID_LEN      SYSTEM_ID_LEN+2
     58  1.1  christos 
     59  1.1  christos #define ISIS_VERSION	1
     60  1.1  christos #define ESIS_VERSION	1
     61  1.1  christos #define CLNP_VERSION	1
     62  1.1  christos 
     63  1.1  christos #define ISIS_PDU_TYPE_MASK      0x1F
     64  1.1  christos #define ESIS_PDU_TYPE_MASK      0x1F
     65  1.1  christos #define CLNP_PDU_TYPE_MASK      0x1F
     66  1.1  christos #define CLNP_FLAG_MASK          0xE0
     67  1.1  christos #define ISIS_LAN_PRIORITY_MASK  0x7F
     68  1.1  christos 
     69  1.1  christos #define ISIS_PDU_L1_LAN_IIH	15
     70  1.1  christos #define ISIS_PDU_L2_LAN_IIH	16
     71  1.1  christos #define ISIS_PDU_PTP_IIH	17
     72  1.1  christos #define ISIS_PDU_L1_LSP       	18
     73  1.1  christos #define ISIS_PDU_L2_LSP       	20
     74  1.1  christos #define ISIS_PDU_L1_CSNP  	24
     75  1.1  christos #define ISIS_PDU_L2_CSNP  	25
     76  1.1  christos #define ISIS_PDU_L1_PSNP        26
     77  1.1  christos #define ISIS_PDU_L2_PSNP        27
     78  1.1  christos 
     79  1.4  christos static const struct tok isis_pdu_values[] = {
     80  1.1  christos     { ISIS_PDU_L1_LAN_IIH,       "L1 Lan IIH"},
     81  1.1  christos     { ISIS_PDU_L2_LAN_IIH,       "L2 Lan IIH"},
     82  1.1  christos     { ISIS_PDU_PTP_IIH,          "p2p IIH"},
     83  1.1  christos     { ISIS_PDU_L1_LSP,           "L1 LSP"},
     84  1.1  christos     { ISIS_PDU_L2_LSP,           "L2 LSP"},
     85  1.1  christos     { ISIS_PDU_L1_CSNP,          "L1 CSNP"},
     86  1.1  christos     { ISIS_PDU_L2_CSNP,          "L2 CSNP"},
     87  1.1  christos     { ISIS_PDU_L1_PSNP,          "L1 PSNP"},
     88  1.1  christos     { ISIS_PDU_L2_PSNP,          "L2 PSNP"},
     89  1.1  christos     { 0, NULL}
     90  1.1  christos };
     91  1.1  christos 
     92  1.1  christos /*
     93  1.1  christos  * A TLV is a tuple of a type, length and a value and is normally used for
     94  1.1  christos  * encoding information in all sorts of places.  This is an enumeration of
     95  1.1  christos  * the well known types.
     96  1.1  christos  *
     97  1.1  christos  * list taken from rfc3359 plus some memory from veterans ;-)
     98  1.1  christos  */
     99  1.1  christos 
    100  1.1  christos #define ISIS_TLV_AREA_ADDR           1   /* iso10589 */
    101  1.1  christos #define ISIS_TLV_IS_REACH            2   /* iso10589 */
    102  1.1  christos #define ISIS_TLV_ESNEIGH             3   /* iso10589 */
    103  1.1  christos #define ISIS_TLV_PART_DIS            4   /* iso10589 */
    104  1.1  christos #define ISIS_TLV_PREFIX_NEIGH        5   /* iso10589 */
    105  1.1  christos #define ISIS_TLV_ISNEIGH             6   /* iso10589 */
    106  1.1  christos #define ISIS_TLV_ISNEIGH_VARLEN      7   /* iso10589 */
    107  1.1  christos #define ISIS_TLV_PADDING             8   /* iso10589 */
    108  1.1  christos #define ISIS_TLV_LSP                 9   /* iso10589 */
    109  1.1  christos #define ISIS_TLV_AUTH                10  /* iso10589, rfc3567 */
    110  1.1  christos #define ISIS_TLV_CHECKSUM            12  /* rfc3358 */
    111  1.1  christos #define ISIS_TLV_CHECKSUM_MINLEN 2
    112  1.7  christos #define ISIS_TLV_POI                 13  /* rfc6232 */
    113  1.1  christos #define ISIS_TLV_LSP_BUFFERSIZE      14  /* iso10589 rev2 */
    114  1.1  christos #define ISIS_TLV_LSP_BUFFERSIZE_MINLEN 2
    115  1.1  christos #define ISIS_TLV_EXT_IS_REACH        22  /* draft-ietf-isis-traffic-05 */
    116  1.1  christos #define ISIS_TLV_IS_ALIAS_ID         24  /* draft-ietf-isis-ext-lsp-frags-02 */
    117  1.1  christos #define ISIS_TLV_DECNET_PHASE4       42
    118  1.1  christos #define ISIS_TLV_LUCENT_PRIVATE      66
    119  1.1  christos #define ISIS_TLV_INT_IP_REACH        128 /* rfc1195, rfc2966 */
    120  1.1  christos #define ISIS_TLV_PROTOCOLS           129 /* rfc1195 */
    121  1.1  christos #define ISIS_TLV_EXT_IP_REACH        130 /* rfc1195, rfc2966 */
    122  1.1  christos #define ISIS_TLV_IDRP_INFO           131 /* rfc1195 */
    123  1.1  christos #define ISIS_TLV_IDRP_INFO_MINLEN      1
    124  1.1  christos #define ISIS_TLV_IPADDR              132 /* rfc1195 */
    125  1.1  christos #define ISIS_TLV_IPAUTH              133 /* rfc1195 */
    126  1.1  christos #define ISIS_TLV_TE_ROUTER_ID        134 /* draft-ietf-isis-traffic-05 */
    127  1.1  christos #define ISIS_TLV_EXTD_IP_REACH       135 /* draft-ietf-isis-traffic-05 */
    128  1.1  christos #define ISIS_TLV_HOSTNAME            137 /* rfc2763 */
    129  1.1  christos #define ISIS_TLV_SHARED_RISK_GROUP   138 /* draft-ietf-isis-gmpls-extensions */
    130  1.4  christos #define ISIS_TLV_MT_PORT_CAP         143 /* rfc6165 */
    131  1.4  christos #define ISIS_TLV_MT_CAPABILITY       144 /* rfc6329 */
    132  1.1  christos #define ISIS_TLV_NORTEL_PRIVATE1     176
    133  1.1  christos #define ISIS_TLV_NORTEL_PRIVATE2     177
    134  1.1  christos #define ISIS_TLV_RESTART_SIGNALING   211 /* rfc3847 */
    135  1.1  christos #define ISIS_TLV_RESTART_SIGNALING_FLAGLEN 1
    136  1.1  christos #define ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN 2
    137  1.1  christos #define ISIS_TLV_MT_IS_REACH         222 /* draft-ietf-isis-wg-multi-topology-05 */
    138  1.1  christos #define ISIS_TLV_MT_SUPPORTED        229 /* draft-ietf-isis-wg-multi-topology-05 */
    139  1.1  christos #define ISIS_TLV_MT_SUPPORTED_MINLEN 2
    140  1.1  christos #define ISIS_TLV_IP6ADDR             232 /* draft-ietf-isis-ipv6-02 */
    141  1.1  christos #define ISIS_TLV_MT_IP_REACH         235 /* draft-ietf-isis-wg-multi-topology-05 */
    142  1.1  christos #define ISIS_TLV_IP6_REACH           236 /* draft-ietf-isis-ipv6-02 */
    143  1.1  christos #define ISIS_TLV_MT_IP6_REACH        237 /* draft-ietf-isis-wg-multi-topology-05 */
    144  1.1  christos #define ISIS_TLV_PTP_ADJ             240 /* rfc3373 */
    145  1.1  christos #define ISIS_TLV_IIH_SEQNR           241 /* draft-shen-isis-iih-sequence-00 */
    146  1.1  christos #define ISIS_TLV_IIH_SEQNR_MINLEN 4
    147  1.1  christos #define ISIS_TLV_VENDOR_PRIVATE      250 /* draft-ietf-isis-experimental-tlv-01 */
    148  1.1  christos #define ISIS_TLV_VENDOR_PRIVATE_MINLEN 3
    149  1.1  christos 
    150  1.4  christos static const struct tok isis_tlv_values[] = {
    151  1.1  christos     { ISIS_TLV_AREA_ADDR,	   "Area address(es)"},
    152  1.1  christos     { ISIS_TLV_IS_REACH,           "IS Reachability"},
    153  1.1  christos     { ISIS_TLV_ESNEIGH,            "ES Neighbor(s)"},
    154  1.1  christos     { ISIS_TLV_PART_DIS,           "Partition DIS"},
    155  1.1  christos     { ISIS_TLV_PREFIX_NEIGH,       "Prefix Neighbors"},
    156  1.1  christos     { ISIS_TLV_ISNEIGH,            "IS Neighbor(s)"},
    157  1.1  christos     { ISIS_TLV_ISNEIGH_VARLEN,     "IS Neighbor(s) (variable length)"},
    158  1.1  christos     { ISIS_TLV_PADDING,            "Padding"},
    159  1.1  christos     { ISIS_TLV_LSP,                "LSP entries"},
    160  1.1  christos     { ISIS_TLV_AUTH,               "Authentication"},
    161  1.1  christos     { ISIS_TLV_CHECKSUM,           "Checksum"},
    162  1.7  christos     { ISIS_TLV_POI,                "Purge Originator Identifier"},
    163  1.1  christos     { ISIS_TLV_LSP_BUFFERSIZE,     "LSP Buffersize"},
    164  1.1  christos     { ISIS_TLV_EXT_IS_REACH,       "Extended IS Reachability"},
    165  1.1  christos     { ISIS_TLV_IS_ALIAS_ID,        "IS Alias ID"},
    166  1.1  christos     { ISIS_TLV_DECNET_PHASE4,      "DECnet Phase IV"},
    167  1.1  christos     { ISIS_TLV_LUCENT_PRIVATE,     "Lucent Proprietary"},
    168  1.1  christos     { ISIS_TLV_INT_IP_REACH,       "IPv4 Internal Reachability"},
    169  1.1  christos     { ISIS_TLV_PROTOCOLS,          "Protocols supported"},
    170  1.1  christos     { ISIS_TLV_EXT_IP_REACH,       "IPv4 External Reachability"},
    171  1.1  christos     { ISIS_TLV_IDRP_INFO,          "Inter-Domain Information Type"},
    172  1.1  christos     { ISIS_TLV_IPADDR,             "IPv4 Interface address(es)"},
    173  1.1  christos     { ISIS_TLV_IPAUTH,             "IPv4 authentication (deprecated)"},
    174  1.1  christos     { ISIS_TLV_TE_ROUTER_ID,       "Traffic Engineering Router ID"},
    175  1.1  christos     { ISIS_TLV_EXTD_IP_REACH,      "Extended IPv4 Reachability"},
    176  1.1  christos     { ISIS_TLV_SHARED_RISK_GROUP,  "Shared Risk Link Group"},
    177  1.4  christos     { ISIS_TLV_MT_PORT_CAP,        "Multi-Topology-Aware Port Capability"},
    178  1.4  christos     { ISIS_TLV_MT_CAPABILITY,      "Multi-Topology Capability"},
    179  1.1  christos     { ISIS_TLV_NORTEL_PRIVATE1,    "Nortel Proprietary"},
    180  1.1  christos     { ISIS_TLV_NORTEL_PRIVATE2,    "Nortel Proprietary"},
    181  1.1  christos     { ISIS_TLV_HOSTNAME,           "Hostname"},
    182  1.1  christos     { ISIS_TLV_RESTART_SIGNALING,  "Restart Signaling"},
    183  1.1  christos     { ISIS_TLV_MT_IS_REACH,        "Multi Topology IS Reachability"},
    184  1.1  christos     { ISIS_TLV_MT_SUPPORTED,       "Multi Topology"},
    185  1.1  christos     { ISIS_TLV_IP6ADDR,            "IPv6 Interface address(es)"},
    186  1.1  christos     { ISIS_TLV_MT_IP_REACH,        "Multi-Topology IPv4 Reachability"},
    187  1.1  christos     { ISIS_TLV_IP6_REACH,          "IPv6 reachability"},
    188  1.1  christos     { ISIS_TLV_MT_IP6_REACH,       "Multi-Topology IP6 Reachability"},
    189  1.1  christos     { ISIS_TLV_PTP_ADJ,            "Point-to-point Adjacency State"},
    190  1.1  christos     { ISIS_TLV_IIH_SEQNR,          "Hello PDU Sequence Number"},
    191  1.1  christos     { ISIS_TLV_VENDOR_PRIVATE,     "Vendor Private"},
    192  1.1  christos     { 0, NULL }
    193  1.1  christos };
    194  1.1  christos 
    195  1.1  christos #define ESIS_OPTION_PROTOCOLS        129
    196  1.1  christos #define ESIS_OPTION_QOS_MAINTENANCE  195 /* iso9542 */
    197  1.1  christos #define ESIS_OPTION_SECURITY         197 /* iso9542 */
    198  1.1  christos #define ESIS_OPTION_ES_CONF_TIME     198 /* iso9542 */
    199  1.1  christos #define ESIS_OPTION_PRIORITY         205 /* iso9542 */
    200  1.1  christos #define ESIS_OPTION_ADDRESS_MASK     225 /* iso9542 */
    201  1.1  christos #define ESIS_OPTION_SNPA_MASK        226 /* iso9542 */
    202  1.1  christos 
    203  1.4  christos static const struct tok esis_option_values[] = {
    204  1.1  christos     { ESIS_OPTION_PROTOCOLS,       "Protocols supported"},
    205  1.1  christos     { ESIS_OPTION_QOS_MAINTENANCE, "QoS Maintenance" },
    206  1.1  christos     { ESIS_OPTION_SECURITY,        "Security" },
    207  1.1  christos     { ESIS_OPTION_ES_CONF_TIME,    "ES Configuration Time" },
    208  1.1  christos     { ESIS_OPTION_PRIORITY,        "Priority" },
    209  1.1  christos     { ESIS_OPTION_ADDRESS_MASK,    "Addressk Mask" },
    210  1.1  christos     { ESIS_OPTION_SNPA_MASK,       "SNPA Mask" },
    211  1.1  christos     { 0, NULL }
    212  1.1  christos };
    213  1.1  christos 
    214  1.1  christos #define CLNP_OPTION_DISCARD_REASON   193
    215  1.1  christos #define CLNP_OPTION_QOS_MAINTENANCE  195 /* iso8473 */
    216  1.1  christos #define CLNP_OPTION_SECURITY         197 /* iso8473 */
    217  1.1  christos #define CLNP_OPTION_SOURCE_ROUTING   200 /* iso8473 */
    218  1.1  christos #define CLNP_OPTION_ROUTE_RECORDING  203 /* iso8473 */
    219  1.1  christos #define CLNP_OPTION_PADDING          204 /* iso8473 */
    220  1.1  christos #define CLNP_OPTION_PRIORITY         205 /* iso8473 */
    221  1.1  christos 
    222  1.4  christos static const struct tok clnp_option_values[] = {
    223  1.1  christos     { CLNP_OPTION_DISCARD_REASON,  "Discard Reason"},
    224  1.1  christos     { CLNP_OPTION_PRIORITY,        "Priority"},
    225  1.1  christos     { CLNP_OPTION_QOS_MAINTENANCE, "QoS Maintenance"},
    226  1.1  christos     { CLNP_OPTION_SECURITY, "Security"},
    227  1.1  christos     { CLNP_OPTION_SOURCE_ROUTING, "Source Routing"},
    228  1.1  christos     { CLNP_OPTION_ROUTE_RECORDING, "Route Recording"},
    229  1.1  christos     { CLNP_OPTION_PADDING, "Padding"},
    230  1.1  christos     { 0, NULL }
    231  1.1  christos };
    232  1.1  christos 
    233  1.4  christos static const struct tok clnp_option_rfd_class_values[] = {
    234  1.1  christos     { 0x0, "General"},
    235  1.1  christos     { 0x8, "Address"},
    236  1.1  christos     { 0x9, "Source Routeing"},
    237  1.1  christos     { 0xa, "Lifetime"},
    238  1.1  christos     { 0xb, "PDU Discarded"},
    239  1.1  christos     { 0xc, "Reassembly"},
    240  1.1  christos     { 0, NULL }
    241  1.1  christos };
    242  1.1  christos 
    243  1.4  christos static const struct tok clnp_option_rfd_general_values[] = {
    244  1.1  christos     { 0x0, "Reason not specified"},
    245  1.1  christos     { 0x1, "Protocol procedure error"},
    246  1.1  christos     { 0x2, "Incorrect checksum"},
    247  1.1  christos     { 0x3, "PDU discarded due to congestion"},
    248  1.1  christos     { 0x4, "Header syntax error (cannot be parsed)"},
    249  1.1  christos     { 0x5, "Segmentation needed but not permitted"},
    250  1.1  christos     { 0x6, "Incomplete PDU received"},
    251  1.1  christos     { 0x7, "Duplicate option"},
    252  1.1  christos     { 0, NULL }
    253  1.1  christos };
    254  1.1  christos 
    255  1.4  christos static const struct tok clnp_option_rfd_address_values[] = {
    256  1.1  christos     { 0x0, "Destination address unreachable"},
    257  1.1  christos     { 0x1, "Destination address unknown"},
    258  1.1  christos     { 0, NULL }
    259  1.1  christos };
    260  1.1  christos 
    261  1.4  christos static const struct tok clnp_option_rfd_source_routeing_values[] = {
    262  1.1  christos     { 0x0, "Unspecified source routeing error"},
    263  1.1  christos     { 0x1, "Syntax error in source routeing field"},
    264  1.1  christos     { 0x2, "Unknown address in source routeing field"},
    265  1.1  christos     { 0x3, "Path not acceptable"},
    266  1.1  christos     { 0, NULL }
    267  1.1  christos };
    268  1.1  christos 
    269  1.4  christos static const struct tok clnp_option_rfd_lifetime_values[] = {
    270  1.1  christos     { 0x0, "Lifetime expired while data unit in transit"},
    271  1.1  christos     { 0x1, "Lifetime expired during reassembly"},
    272  1.1  christos     { 0, NULL }
    273  1.1  christos };
    274  1.1  christos 
    275  1.4  christos static const struct tok clnp_option_rfd_pdu_discard_values[] = {
    276  1.1  christos     { 0x0, "Unsupported option not specified"},
    277  1.1  christos     { 0x1, "Unsupported protocol version"},
    278  1.1  christos     { 0x2, "Unsupported security option"},
    279  1.1  christos     { 0x3, "Unsupported source routeing option"},
    280  1.1  christos     { 0x4, "Unsupported recording of route option"},
    281  1.1  christos     { 0, NULL }
    282  1.1  christos };
    283  1.1  christos 
    284  1.4  christos static const struct tok clnp_option_rfd_reassembly_values[] = {
    285  1.1  christos     { 0x0, "Reassembly interference"},
    286  1.1  christos     { 0, NULL }
    287  1.1  christos };
    288  1.1  christos 
    289  1.1  christos /* array of 16 error-classes */
    290  1.4  christos static const struct tok *clnp_option_rfd_error_class[] = {
    291  1.1  christos     clnp_option_rfd_general_values,
    292  1.1  christos     NULL,
    293  1.1  christos     NULL,
    294  1.1  christos     NULL,
    295  1.1  christos     NULL,
    296  1.1  christos     NULL,
    297  1.1  christos     NULL,
    298  1.1  christos     NULL,
    299  1.1  christos     clnp_option_rfd_address_values,
    300  1.1  christos     clnp_option_rfd_source_routeing_values,
    301  1.1  christos     clnp_option_rfd_lifetime_values,
    302  1.1  christos     clnp_option_rfd_pdu_discard_values,
    303  1.1  christos     clnp_option_rfd_reassembly_values,
    304  1.1  christos     NULL,
    305  1.1  christos     NULL,
    306  1.1  christos     NULL
    307  1.1  christos };
    308  1.1  christos 
    309  1.1  christos #define CLNP_OPTION_OPTION_QOS_MASK 0x3f
    310  1.1  christos #define CLNP_OPTION_SCOPE_MASK      0xc0
    311  1.1  christos #define CLNP_OPTION_SCOPE_SA_SPEC   0x40
    312  1.1  christos #define CLNP_OPTION_SCOPE_DA_SPEC   0x80
    313  1.1  christos #define CLNP_OPTION_SCOPE_GLOBAL    0xc0
    314  1.1  christos 
    315  1.4  christos static const struct tok clnp_option_scope_values[] = {
    316  1.1  christos     { CLNP_OPTION_SCOPE_SA_SPEC, "Source Address Specific"},
    317  1.1  christos     { CLNP_OPTION_SCOPE_DA_SPEC, "Destination Address Specific"},
    318  1.1  christos     { CLNP_OPTION_SCOPE_GLOBAL, "Globally unique"},
    319  1.1  christos     { 0, NULL }
    320  1.1  christos };
    321  1.1  christos 
    322  1.4  christos static const struct tok clnp_option_sr_rr_values[] = {
    323  1.1  christos     { 0x0, "partial"},
    324  1.1  christos     { 0x1, "complete"},
    325  1.1  christos     { 0, NULL }
    326  1.1  christos };
    327  1.1  christos 
    328  1.4  christos static const struct tok clnp_option_sr_rr_string_values[] = {
    329  1.1  christos     { CLNP_OPTION_SOURCE_ROUTING, "source routing"},
    330  1.1  christos     { CLNP_OPTION_ROUTE_RECORDING, "recording of route in progress"},
    331  1.1  christos     { 0, NULL }
    332  1.1  christos };
    333  1.1  christos 
    334  1.4  christos static const struct tok clnp_option_qos_global_values[] = {
    335  1.1  christos     { 0x20, "reserved"},
    336  1.1  christos     { 0x10, "sequencing vs. delay"},
    337  1.1  christos     { 0x08, "congested"},
    338  1.1  christos     { 0x04, "delay vs. cost"},
    339  1.1  christos     { 0x02, "error vs. delay"},
    340  1.1  christos     { 0x01, "error vs. cost"},
    341  1.1  christos     { 0, NULL }
    342  1.1  christos };
    343  1.1  christos 
    344  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP           3 /* draft-ietf-isis-traffic-05 */
    345  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID  4 /* rfc4205 */
    346  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID        5 /* draft-ietf-isis-traffic-05 */
    347  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR        6 /* draft-ietf-isis-traffic-05 */
    348  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR    8 /* draft-ietf-isis-traffic-05 */
    349  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW           9 /* draft-ietf-isis-traffic-05 */
    350  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW        10 /* draft-ietf-isis-traffic-05 */
    351  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW        11 /* rfc4124 */
    352  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD   12 /* draft-ietf-tewg-diff-te-proto-06 */
    353  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC            18 /* draft-ietf-isis-traffic-05 */
    354  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_LINK_ATTRIBUTE       19 /* draft-ietf-isis-link-attr-01 */
    355  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE 20 /* rfc4205 */
    356  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR    21 /* rfc4205 */
    357  1.1  christos #define ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS       22 /* rfc4124 */
    358  1.1  christos 
    359  1.4  christos #define ISIS_SUBTLV_SPB_METRIC                        29 /* rfc6329 */
    360  1.4  christos 
    361  1.4  christos static const struct tok isis_ext_is_reach_subtlv_values[] = {
    362  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP,            "Administrative groups" },
    363  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID,   "Link Local/Remote Identifier" },
    364  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID,         "Link Remote Identifier" },
    365  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR,         "IPv4 interface address" },
    366  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR,     "IPv4 neighbor address" },
    367  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW,            "Maximum link bandwidth" },
    368  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW,          "Reservable link bandwidth" },
    369  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW,          "Unreserved bandwidth" },
    370  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC,              "Traffic Engineering Metric" },
    371  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_LINK_ATTRIBUTE,         "Link Attribute" },
    372  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE,   "Link Protection Type" },
    373  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR,      "Interface Switching Capability" },
    374  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD,     "Bandwidth Constraints (old)" },
    375  1.1  christos     { ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS,         "Bandwidth Constraints" },
    376  1.4  christos     { ISIS_SUBTLV_SPB_METRIC,                          "SPB Metric" },
    377  1.1  christos     { 250,                                             "Reserved for cisco specific extensions" },
    378  1.1  christos     { 251,                                             "Reserved for cisco specific extensions" },
    379  1.1  christos     { 252,                                             "Reserved for cisco specific extensions" },
    380  1.1  christos     { 253,                                             "Reserved for cisco specific extensions" },
    381  1.1  christos     { 254,                                             "Reserved for cisco specific extensions" },
    382  1.1  christos     { 255,                                             "Reserved for future expansion" },
    383  1.1  christos     { 0, NULL }
    384  1.1  christos };
    385  1.1  christos 
    386  1.1  christos #define ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32          1 /* draft-ietf-isis-admin-tags-01 */
    387  1.1  christos #define ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64          2 /* draft-ietf-isis-admin-tags-01 */
    388  1.1  christos #define ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR  117 /* draft-ietf-isis-wg-multi-topology-05 */
    389  1.1  christos 
    390  1.4  christos static const struct tok isis_ext_ip_reach_subtlv_values[] = {
    391  1.1  christos     { ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32,           "32-Bit Administrative tag" },
    392  1.1  christos     { ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64,           "64-Bit Administrative tag" },
    393  1.1  christos     { ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR,     "Management Prefix Color" },
    394  1.1  christos     { 0, NULL }
    395  1.1  christos };
    396  1.1  christos 
    397  1.4  christos static const struct tok isis_subtlv_link_attribute_values[] = {
    398  1.1  christos     { 0x01, "Local Protection Available" },
    399  1.1  christos     { 0x02, "Link excluded from local protection path" },
    400  1.1  christos     { 0x04, "Local maintenance required"},
    401  1.1  christos     { 0, NULL }
    402  1.1  christos };
    403  1.1  christos 
    404  1.1  christos #define ISIS_SUBTLV_AUTH_SIMPLE        1
    405  1.3  christos #define ISIS_SUBTLV_AUTH_GENERIC       3 /* rfc 5310 */
    406  1.1  christos #define ISIS_SUBTLV_AUTH_MD5          54
    407  1.1  christos #define ISIS_SUBTLV_AUTH_MD5_LEN      16
    408  1.1  christos #define ISIS_SUBTLV_AUTH_PRIVATE     255
    409  1.1  christos 
    410  1.4  christos static const struct tok isis_subtlv_auth_values[] = {
    411  1.1  christos     { ISIS_SUBTLV_AUTH_SIMPLE,	"simple text password"},
    412  1.3  christos     { ISIS_SUBTLV_AUTH_GENERIC, "Generic Crypto key-id"},
    413  1.1  christos     { ISIS_SUBTLV_AUTH_MD5,	"HMAC-MD5 password"},
    414  1.1  christos     { ISIS_SUBTLV_AUTH_PRIVATE,	"Routing Domain private password"},
    415  1.1  christos     { 0, NULL }
    416  1.1  christos };
    417  1.1  christos 
    418  1.1  christos #define ISIS_SUBTLV_IDRP_RES           0
    419  1.1  christos #define ISIS_SUBTLV_IDRP_LOCAL         1
    420  1.1  christos #define ISIS_SUBTLV_IDRP_ASN           2
    421  1.1  christos 
    422  1.4  christos static const struct tok isis_subtlv_idrp_values[] = {
    423  1.1  christos     { ISIS_SUBTLV_IDRP_RES,         "Reserved"},
    424  1.1  christos     { ISIS_SUBTLV_IDRP_LOCAL,       "Routing-Domain Specific"},
    425  1.1  christos     { ISIS_SUBTLV_IDRP_ASN,         "AS Number Tag"},
    426  1.1  christos     { 0, NULL}
    427  1.1  christos };
    428  1.1  christos 
    429  1.4  christos #define ISIS_SUBTLV_SPB_MCID          4
    430  1.4  christos #define ISIS_SUBTLV_SPB_DIGEST        5
    431  1.4  christos #define ISIS_SUBTLV_SPB_BVID          6
    432  1.4  christos 
    433  1.4  christos #define ISIS_SUBTLV_SPB_INSTANCE      1
    434  1.4  christos #define ISIS_SUBTLV_SPBM_SI           3
    435  1.4  christos 
    436  1.4  christos #define ISIS_SPB_MCID_LEN                         51
    437  1.4  christos #define ISIS_SUBTLV_SPB_MCID_MIN_LEN              102
    438  1.4  christos #define ISIS_SUBTLV_SPB_DIGEST_MIN_LEN            33
    439  1.4  christos #define ISIS_SUBTLV_SPB_BVID_MIN_LEN              6
    440  1.4  christos #define ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN          19
    441  1.4  christos #define ISIS_SUBTLV_SPB_INSTANCE_VLAN_TUPLE_LEN   8
    442  1.4  christos 
    443  1.4  christos static const struct tok isis_mt_port_cap_subtlv_values[] = {
    444  1.4  christos     { ISIS_SUBTLV_SPB_MCID,           "SPB MCID" },
    445  1.4  christos     { ISIS_SUBTLV_SPB_DIGEST,         "SPB Digest" },
    446  1.4  christos     { ISIS_SUBTLV_SPB_BVID,           "SPB BVID" },
    447  1.4  christos     { 0, NULL }
    448  1.4  christos };
    449  1.4  christos 
    450  1.4  christos static const struct tok isis_mt_capability_subtlv_values[] = {
    451  1.4  christos     { ISIS_SUBTLV_SPB_INSTANCE,      "SPB Instance" },
    452  1.4  christos     { ISIS_SUBTLV_SPBM_SI,      "SPBM Service Identifier and Unicast Address" },
    453  1.4  christos     { 0, NULL }
    454  1.4  christos };
    455  1.4  christos 
    456  1.4  christos struct isis_spb_mcid {
    457  1.5  christos   uint8_t  format_id;
    458  1.5  christos   uint8_t  name[32];
    459  1.5  christos   uint8_t  revision_lvl[2];
    460  1.5  christos   uint8_t  digest[16];
    461  1.4  christos };
    462  1.4  christos 
    463  1.4  christos struct isis_subtlv_spb_mcid {
    464  1.4  christos   struct isis_spb_mcid mcid;
    465  1.4  christos   struct isis_spb_mcid aux_mcid;
    466  1.4  christos };
    467  1.4  christos 
    468  1.4  christos struct isis_subtlv_spb_instance {
    469  1.5  christos   uint8_t cist_root_id[8];
    470  1.5  christos   uint8_t cist_external_root_path_cost[4];
    471  1.5  christos   uint8_t bridge_priority[2];
    472  1.5  christos   uint8_t spsourceid[4];
    473  1.5  christos   uint8_t no_of_trees;
    474  1.4  christos };
    475  1.4  christos 
    476  1.1  christos #define CLNP_SEGMENT_PART  0x80
    477  1.1  christos #define CLNP_MORE_SEGMENTS 0x40
    478  1.1  christos #define CLNP_REQUEST_ER    0x20
    479  1.1  christos 
    480  1.4  christos static const struct tok clnp_flag_values[] = {
    481  1.1  christos     { CLNP_SEGMENT_PART, "Segmentation permitted"},
    482  1.1  christos     { CLNP_MORE_SEGMENTS, "more Segments"},
    483  1.1  christos     { CLNP_REQUEST_ER, "request Error Report"},
    484  1.1  christos     { 0, NULL}
    485  1.1  christos };
    486  1.1  christos 
    487  1.1  christos #define ISIS_MASK_LSP_OL_BIT(x)            ((x)&0x4)
    488  1.1  christos #define ISIS_MASK_LSP_ISTYPE_BITS(x)       ((x)&0x3)
    489  1.1  christos #define ISIS_MASK_LSP_PARTITION_BIT(x)     ((x)&0x80)
    490  1.1  christos #define ISIS_MASK_LSP_ATT_BITS(x)          ((x)&0x78)
    491  1.1  christos #define ISIS_MASK_LSP_ATT_ERROR_BIT(x)     ((x)&0x40)
    492  1.1  christos #define ISIS_MASK_LSP_ATT_EXPENSE_BIT(x)   ((x)&0x20)
    493  1.1  christos #define ISIS_MASK_LSP_ATT_DELAY_BIT(x)     ((x)&0x10)
    494  1.1  christos #define ISIS_MASK_LSP_ATT_DEFAULT_BIT(x)   ((x)&0x8)
    495  1.1  christos 
    496  1.1  christos #define ISIS_MASK_MTID(x)                  ((x)&0x0fff)
    497  1.1  christos #define ISIS_MASK_MTFLAGS(x)               ((x)&0xf000)
    498  1.1  christos 
    499  1.4  christos static const struct tok isis_mt_flag_values[] = {
    500  1.3  christos     { 0x4000,                  "ATT bit set"},
    501  1.3  christos     { 0x8000,                  "Overload bit set"},
    502  1.1  christos     { 0, NULL}
    503  1.1  christos };
    504  1.1  christos 
    505  1.1  christos #define ISIS_MASK_TLV_EXTD_IP_UPDOWN(x)     ((x)&0x80)
    506  1.1  christos #define ISIS_MASK_TLV_EXTD_IP_SUBTLV(x)     ((x)&0x40)
    507  1.1  christos 
    508  1.1  christos #define ISIS_MASK_TLV_EXTD_IP6_IE(x)        ((x)&0x40)
    509  1.1  christos #define ISIS_MASK_TLV_EXTD_IP6_SUBTLV(x)    ((x)&0x20)
    510  1.1  christos 
    511  1.1  christos #define ISIS_LSP_TLV_METRIC_SUPPORTED(x)   ((x)&0x80)
    512  1.1  christos #define ISIS_LSP_TLV_METRIC_IE(x)          ((x)&0x40)
    513  1.1  christos #define ISIS_LSP_TLV_METRIC_UPDOWN(x)      ((x)&0x80)
    514  1.1  christos #define ISIS_LSP_TLV_METRIC_VALUE(x)	   ((x)&0x3f)
    515  1.1  christos 
    516  1.1  christos #define ISIS_MASK_TLV_SHARED_RISK_GROUP(x) ((x)&0x1)
    517  1.1  christos 
    518  1.4  christos static const struct tok isis_mt_values[] = {
    519  1.1  christos     { 0,    "IPv4 unicast"},
    520  1.1  christos     { 1,    "In-Band Management"},
    521  1.1  christos     { 2,    "IPv6 unicast"},
    522  1.1  christos     { 3,    "Multicast"},
    523  1.1  christos     { 4095, "Development, Experimental or Proprietary"},
    524  1.1  christos     { 0, NULL }
    525  1.1  christos };
    526  1.1  christos 
    527  1.4  christos static const struct tok isis_iih_circuit_type_values[] = {
    528  1.1  christos     { 1,    "Level 1 only"},
    529  1.1  christos     { 2,    "Level 2 only"},
    530  1.1  christos     { 3,    "Level 1, Level 2"},
    531  1.1  christos     { 0, NULL}
    532  1.1  christos };
    533  1.1  christos 
    534  1.1  christos #define ISIS_LSP_TYPE_UNUSED0   0
    535  1.1  christos #define ISIS_LSP_TYPE_LEVEL_1   1
    536  1.1  christos #define ISIS_LSP_TYPE_UNUSED2   2
    537  1.1  christos #define ISIS_LSP_TYPE_LEVEL_2   3
    538  1.1  christos 
    539  1.4  christos static const struct tok isis_lsp_istype_values[] = {
    540  1.1  christos     { ISIS_LSP_TYPE_UNUSED0,	"Unused 0x0 (invalid)"},
    541  1.1  christos     { ISIS_LSP_TYPE_LEVEL_1,	"L1 IS"},
    542  1.1  christos     { ISIS_LSP_TYPE_UNUSED2,	"Unused 0x2 (invalid)"},
    543  1.1  christos     { ISIS_LSP_TYPE_LEVEL_2,	"L2 IS"},
    544  1.1  christos     { 0, NULL }
    545  1.1  christos };
    546  1.1  christos 
    547  1.1  christos /*
    548  1.1  christos  * Katz's point to point adjacency TLV uses codes to tell us the state of
    549  1.1  christos  * the remote adjacency.  Enumerate them.
    550  1.1  christos  */
    551  1.1  christos 
    552  1.1  christos #define ISIS_PTP_ADJ_UP   0
    553  1.1  christos #define ISIS_PTP_ADJ_INIT 1
    554  1.1  christos #define ISIS_PTP_ADJ_DOWN 2
    555  1.1  christos 
    556  1.4  christos static const struct tok isis_ptp_adjancey_values[] = {
    557  1.1  christos     { ISIS_PTP_ADJ_UP,    "Up" },
    558  1.1  christos     { ISIS_PTP_ADJ_INIT,  "Initializing" },
    559  1.1  christos     { ISIS_PTP_ADJ_DOWN,  "Down" },
    560  1.1  christos     { 0, NULL}
    561  1.1  christos };
    562  1.1  christos 
    563  1.1  christos struct isis_tlv_ptp_adj {
    564  1.5  christos     uint8_t adjacency_state;
    565  1.5  christos     uint8_t extd_local_circuit_id[4];
    566  1.5  christos     uint8_t neighbor_sysid[SYSTEM_ID_LEN];
    567  1.5  christos     uint8_t neighbor_extd_local_circuit_id[4];
    568  1.1  christos };
    569  1.1  christos 
    570  1.7  christos static int osi_print_cksum(netdissect_options *, const uint8_t *pptr,
    571  1.7  christos 			    uint16_t checksum, int checksum_offset, int length);
    572  1.5  christos static int clnp_print(netdissect_options *, const uint8_t *, u_int);
    573  1.5  christos static void esis_print(netdissect_options *, const uint8_t *, u_int);
    574  1.5  christos static int isis_print(netdissect_options *, const uint8_t *, u_int);
    575  1.1  christos 
    576  1.1  christos struct isis_metric_block {
    577  1.5  christos     uint8_t metric_default;
    578  1.5  christos     uint8_t metric_delay;
    579  1.5  christos     uint8_t metric_expense;
    580  1.5  christos     uint8_t metric_error;
    581  1.1  christos };
    582  1.1  christos 
    583  1.1  christos struct isis_tlv_is_reach {
    584  1.1  christos     struct isis_metric_block isis_metric_block;
    585  1.5  christos     uint8_t neighbor_nodeid[NODE_ID_LEN];
    586  1.1  christos };
    587  1.1  christos 
    588  1.1  christos struct isis_tlv_es_reach {
    589  1.1  christos     struct isis_metric_block isis_metric_block;
    590  1.5  christos     uint8_t neighbor_sysid[SYSTEM_ID_LEN];
    591  1.1  christos };
    592  1.1  christos 
    593  1.1  christos struct isis_tlv_ip_reach {
    594  1.1  christos     struct isis_metric_block isis_metric_block;
    595  1.5  christos     uint8_t prefix[4];
    596  1.5  christos     uint8_t mask[4];
    597  1.1  christos };
    598  1.1  christos 
    599  1.4  christos static const struct tok isis_is_reach_virtual_values[] = {
    600  1.1  christos     { 0,    "IsNotVirtual"},
    601  1.1  christos     { 1,    "IsVirtual"},
    602  1.1  christos     { 0, NULL }
    603  1.1  christos };
    604  1.1  christos 
    605  1.4  christos static const struct tok isis_restart_flag_values[] = {
    606  1.1  christos     { 0x1,  "Restart Request"},
    607  1.1  christos     { 0x2,  "Restart Acknowledgement"},
    608  1.1  christos     { 0x4,  "Suppress adjacency advertisement"},
    609  1.1  christos     { 0, NULL }
    610  1.1  christos };
    611  1.1  christos 
    612  1.1  christos struct isis_common_header {
    613  1.5  christos     uint8_t nlpid;
    614  1.5  christos     uint8_t fixed_len;
    615  1.5  christos     uint8_t version;			/* Protocol version */
    616  1.5  christos     uint8_t id_length;
    617  1.5  christos     uint8_t pdu_type;		        /* 3 MSbits are reserved */
    618  1.5  christos     uint8_t pdu_version;		/* Packet format version */
    619  1.5  christos     uint8_t reserved;
    620  1.5  christos     uint8_t max_area;
    621  1.1  christos };
    622  1.1  christos 
    623  1.1  christos struct isis_iih_lan_header {
    624  1.5  christos     uint8_t circuit_type;
    625  1.5  christos     uint8_t source_id[SYSTEM_ID_LEN];
    626  1.5  christos     uint8_t holding_time[2];
    627  1.5  christos     uint8_t pdu_len[2];
    628  1.5  christos     uint8_t priority;
    629  1.5  christos     uint8_t lan_id[NODE_ID_LEN];
    630  1.1  christos };
    631  1.1  christos 
    632  1.1  christos struct isis_iih_ptp_header {
    633  1.5  christos     uint8_t circuit_type;
    634  1.5  christos     uint8_t source_id[SYSTEM_ID_LEN];
    635  1.5  christos     uint8_t holding_time[2];
    636  1.5  christos     uint8_t pdu_len[2];
    637  1.5  christos     uint8_t circuit_id;
    638  1.1  christos };
    639  1.1  christos 
    640  1.1  christos struct isis_lsp_header {
    641  1.5  christos     uint8_t pdu_len[2];
    642  1.5  christos     uint8_t remaining_lifetime[2];
    643  1.5  christos     uint8_t lsp_id[LSP_ID_LEN];
    644  1.5  christos     uint8_t sequence_number[4];
    645  1.5  christos     uint8_t checksum[2];
    646  1.5  christos     uint8_t typeblock;
    647  1.1  christos };
    648  1.1  christos 
    649  1.1  christos struct isis_csnp_header {
    650  1.5  christos     uint8_t pdu_len[2];
    651  1.5  christos     uint8_t source_id[NODE_ID_LEN];
    652  1.5  christos     uint8_t start_lsp_id[LSP_ID_LEN];
    653  1.5  christos     uint8_t end_lsp_id[LSP_ID_LEN];
    654  1.1  christos };
    655  1.1  christos 
    656  1.1  christos struct isis_psnp_header {
    657  1.5  christos     uint8_t pdu_len[2];
    658  1.5  christos     uint8_t source_id[NODE_ID_LEN];
    659  1.1  christos };
    660  1.1  christos 
    661  1.1  christos struct isis_tlv_lsp {
    662  1.5  christos     uint8_t remaining_lifetime[2];
    663  1.5  christos     uint8_t lsp_id[LSP_ID_LEN];
    664  1.5  christos     uint8_t sequence_number[4];
    665  1.5  christos     uint8_t checksum[2];
    666  1.1  christos };
    667  1.1  christos 
    668  1.1  christos #define ISIS_COMMON_HEADER_SIZE (sizeof(struct isis_common_header))
    669  1.1  christos #define ISIS_IIH_LAN_HEADER_SIZE (sizeof(struct isis_iih_lan_header))
    670  1.1  christos #define ISIS_IIH_PTP_HEADER_SIZE (sizeof(struct isis_iih_ptp_header))
    671  1.1  christos #define ISIS_LSP_HEADER_SIZE (sizeof(struct isis_lsp_header))
    672  1.1  christos #define ISIS_CSNP_HEADER_SIZE (sizeof(struct isis_csnp_header))
    673  1.1  christos #define ISIS_PSNP_HEADER_SIZE (sizeof(struct isis_psnp_header))
    674  1.1  christos 
    675  1.7  christos void
    676  1.7  christos isoclns_print(netdissect_options *ndo,
    677  1.7  christos               const uint8_t *p, u_int length, u_int caplen)
    678  1.1  christos {
    679  1.5  christos 	if (caplen <= 1) { /* enough bytes on the wire ? */
    680  1.5  christos 		ND_PRINT((ndo, "|OSI"));
    681  1.5  christos 		return;
    682  1.5  christos 	}
    683  1.5  christos 
    684  1.5  christos 	if (ndo->ndo_eflag)
    685  1.5  christos 		ND_PRINT((ndo, "OSI NLPID %s (0x%02x): ", tok2str(nlpid_values, "Unknown", *p), *p));
    686  1.1  christos 
    687  1.1  christos 	switch (*p) {
    688  1.1  christos 
    689  1.1  christos 	case NLPID_CLNP:
    690  1.5  christos 		if (!clnp_print(ndo, p, length))
    691  1.5  christos 			print_unknown_data(ndo, p, "\n\t", caplen);
    692  1.1  christos 		break;
    693  1.1  christos 
    694  1.1  christos 	case NLPID_ESIS:
    695  1.5  christos 		esis_print(ndo, p, length);
    696  1.1  christos 		return;
    697  1.1  christos 
    698  1.1  christos 	case NLPID_ISIS:
    699  1.5  christos 		if (!isis_print(ndo, p, length))
    700  1.5  christos 			print_unknown_data(ndo, p, "\n\t", caplen);
    701  1.1  christos 		break;
    702  1.1  christos 
    703  1.1  christos 	case NLPID_NULLNS:
    704  1.5  christos 		ND_PRINT((ndo, "%slength: %u", ndo->ndo_eflag ? "" : ", ", length));
    705  1.1  christos 		break;
    706  1.1  christos 
    707  1.5  christos 	case NLPID_Q933:
    708  1.5  christos 		q933_print(ndo, p + 1, length - 1);
    709  1.5  christos 		break;
    710  1.1  christos 
    711  1.5  christos 	case NLPID_IP:
    712  1.5  christos 		ip_print(ndo, p + 1, length - 1);
    713  1.5  christos 		break;
    714  1.1  christos 
    715  1.5  christos 	case NLPID_IP6:
    716  1.5  christos 		ip6_print(ndo, p + 1, length - 1);
    717  1.5  christos 		break;
    718  1.1  christos 
    719  1.5  christos 	case NLPID_PPP:
    720  1.5  christos 		ppp_print(ndo, p + 1, length - 1);
    721  1.5  christos 		break;
    722  1.1  christos 
    723  1.1  christos 	default:
    724  1.5  christos 		if (!ndo->ndo_eflag)
    725  1.5  christos 			ND_PRINT((ndo, "OSI NLPID 0x%02x unknown", *p));
    726  1.5  christos 		ND_PRINT((ndo, "%slength: %u", ndo->ndo_eflag ? "" : ", ", length));
    727  1.1  christos 		if (caplen > 1)
    728  1.5  christos 			print_unknown_data(ndo, p, "\n\t", caplen);
    729  1.1  christos 		break;
    730  1.1  christos 	}
    731  1.1  christos }
    732  1.1  christos 
    733  1.1  christos #define	CLNP_PDU_ER	 1
    734  1.1  christos #define	CLNP_PDU_DT	28
    735  1.1  christos #define	CLNP_PDU_MD	29
    736  1.1  christos #define	CLNP_PDU_ERQ	30
    737  1.1  christos #define	CLNP_PDU_ERP	31
    738  1.1  christos 
    739  1.4  christos static const struct tok clnp_pdu_values[] = {
    740  1.1  christos     { CLNP_PDU_ER,  "Error Report"},
    741  1.1  christos     { CLNP_PDU_MD,  "MD"},
    742  1.1  christos     { CLNP_PDU_DT,  "Data"},
    743  1.1  christos     { CLNP_PDU_ERQ, "Echo Request"},
    744  1.1  christos     { CLNP_PDU_ERP, "Echo Response"},
    745  1.1  christos     { 0, NULL }
    746  1.1  christos };
    747  1.1  christos 
    748  1.1  christos struct clnp_header_t {
    749  1.5  christos     uint8_t nlpid;
    750  1.5  christos     uint8_t length_indicator;
    751  1.5  christos     uint8_t version;
    752  1.5  christos     uint8_t lifetime; /* units of 500ms */
    753  1.5  christos     uint8_t type;
    754  1.5  christos     uint8_t segment_length[2];
    755  1.5  christos     uint8_t cksum[2];
    756  1.1  christos };
    757  1.1  christos 
    758  1.1  christos struct clnp_segment_header_t {
    759  1.5  christos     uint8_t data_unit_id[2];
    760  1.5  christos     uint8_t segment_offset[2];
    761  1.5  christos     uint8_t total_length[2];
    762  1.1  christos };
    763  1.1  christos 
    764  1.1  christos /*
    765  1.1  christos  * clnp_print
    766  1.1  christos  * Decode CLNP packets.  Return 0 on error.
    767  1.1  christos  */
    768  1.1  christos 
    769  1.5  christos static int
    770  1.5  christos clnp_print(netdissect_options *ndo,
    771  1.5  christos            const uint8_t *pptr, u_int length)
    772  1.1  christos {
    773  1.5  christos 	const uint8_t *optr,*source_address,*dest_address;
    774  1.1  christos         u_int li,tlen,nsap_offset,source_address_length,dest_address_length, clnp_pdu_type, clnp_flags;
    775  1.1  christos 	const struct clnp_header_t *clnp_header;
    776  1.1  christos 	const struct clnp_segment_header_t *clnp_segment_header;
    777  1.5  christos         uint8_t rfd_error_major,rfd_error_minor;
    778  1.1  christos 
    779  1.1  christos 	clnp_header = (const struct clnp_header_t *) pptr;
    780  1.5  christos         ND_TCHECK(*clnp_header);
    781  1.1  christos 
    782  1.1  christos         li = clnp_header->length_indicator;
    783  1.1  christos         optr = pptr;
    784  1.1  christos 
    785  1.5  christos         if (!ndo->ndo_eflag)
    786  1.5  christos             ND_PRINT((ndo, "CLNP"));
    787  1.1  christos 
    788  1.1  christos         /*
    789  1.1  christos          * Sanity checking of the header.
    790  1.1  christos          */
    791  1.1  christos 
    792  1.1  christos         if (clnp_header->version != CLNP_VERSION) {
    793  1.5  christos             ND_PRINT((ndo, "version %d packet not supported", clnp_header->version));
    794  1.1  christos             return (0);
    795  1.1  christos         }
    796  1.1  christos 
    797  1.1  christos         /* FIXME further header sanity checking */
    798  1.1  christos 
    799  1.1  christos         clnp_pdu_type = clnp_header->type & CLNP_PDU_TYPE_MASK;
    800  1.1  christos         clnp_flags = clnp_header->type & CLNP_FLAG_MASK;
    801  1.1  christos 
    802  1.1  christos         pptr += sizeof(struct clnp_header_t);
    803  1.1  christos         li -= sizeof(struct clnp_header_t);
    804  1.1  christos         dest_address_length = *pptr;
    805  1.1  christos         dest_address = pptr + 1;
    806  1.1  christos 
    807  1.1  christos         pptr += (1 + dest_address_length);
    808  1.1  christos         li -= (1 + dest_address_length);
    809  1.1  christos         source_address_length = *pptr;
    810  1.1  christos         source_address = pptr +1;
    811  1.1  christos 
    812  1.1  christos         pptr += (1 + source_address_length);
    813  1.1  christos         li -= (1 + source_address_length);
    814  1.1  christos 
    815  1.5  christos         if (ndo->ndo_vflag < 1) {
    816  1.5  christos             ND_PRINT((ndo, "%s%s > %s, %s, length %u",
    817  1.5  christos                    ndo->ndo_eflag ? "" : ", ",
    818  1.7  christos                    isonsap_string(ndo, source_address, source_address_length),
    819  1.7  christos                    isonsap_string(ndo, dest_address, dest_address_length),
    820  1.1  christos                    tok2str(clnp_pdu_values,"unknown (%u)",clnp_pdu_type),
    821  1.5  christos                    length));
    822  1.1  christos             return (1);
    823  1.1  christos         }
    824  1.5  christos         ND_PRINT((ndo, "%slength %u", ndo->ndo_eflag ? "" : ", ", length));
    825  1.1  christos 
    826  1.5  christos         ND_PRINT((ndo, "\n\t%s PDU, hlen: %u, v: %u, lifetime: %u.%us, Segment PDU length: %u, checksum: 0x%04x",
    827  1.1  christos                tok2str(clnp_pdu_values, "unknown (%u)",clnp_pdu_type),
    828  1.1  christos                clnp_header->length_indicator,
    829  1.1  christos                clnp_header->version,
    830  1.1  christos                clnp_header->lifetime/2,
    831  1.1  christos                (clnp_header->lifetime%2)*5,
    832  1.1  christos                EXTRACT_16BITS(clnp_header->segment_length),
    833  1.5  christos                EXTRACT_16BITS(clnp_header->cksum)));
    834  1.1  christos 
    835  1.7  christos         if (osi_print_cksum(ndo, optr, EXTRACT_16BITS(clnp_header->cksum), 7,
    836  1.7  christos                             clnp_header->length_indicator) == 0)
    837  1.7  christos                 goto trunc;
    838  1.1  christos 
    839  1.5  christos         ND_PRINT((ndo, "\n\tFlags [%s]",
    840  1.5  christos                bittok2str(clnp_flag_values, "none", clnp_flags)));
    841  1.1  christos 
    842  1.5  christos         ND_PRINT((ndo, "\n\tsource address (length %u): %s\n\tdest   address (length %u): %s",
    843  1.1  christos                source_address_length,
    844  1.7  christos                isonsap_string(ndo, source_address, source_address_length),
    845  1.1  christos                dest_address_length,
    846  1.7  christos                isonsap_string(ndo, dest_address, dest_address_length)));
    847  1.1  christos 
    848  1.1  christos         if (clnp_flags & CLNP_SEGMENT_PART) {
    849  1.1  christos             	clnp_segment_header = (const struct clnp_segment_header_t *) pptr;
    850  1.5  christos                 ND_TCHECK(*clnp_segment_header);
    851  1.5  christos                 ND_PRINT((ndo, "\n\tData Unit ID: 0x%04x, Segment Offset: %u, Total PDU Length: %u",
    852  1.1  christos                        EXTRACT_16BITS(clnp_segment_header->data_unit_id),
    853  1.1  christos                        EXTRACT_16BITS(clnp_segment_header->segment_offset),
    854  1.5  christos                        EXTRACT_16BITS(clnp_segment_header->total_length)));
    855  1.1  christos                 pptr+=sizeof(const struct clnp_segment_header_t);
    856  1.1  christos                 li-=sizeof(const struct clnp_segment_header_t);
    857  1.1  christos         }
    858  1.1  christos 
    859  1.1  christos         /* now walk the options */
    860  1.1  christos         while (li >= 2) {
    861  1.1  christos             u_int op, opli;
    862  1.5  christos             const uint8_t *tptr;
    863  1.5  christos 
    864  1.5  christos             ND_TCHECK2(*pptr, 2);
    865  1.1  christos             if (li < 2) {
    866  1.5  christos                 ND_PRINT((ndo, ", bad opts/li"));
    867  1.1  christos                 return (0);
    868  1.1  christos             }
    869  1.1  christos             op = *pptr++;
    870  1.1  christos             opli = *pptr++;
    871  1.1  christos             li -= 2;
    872  1.5  christos             ND_TCHECK2(*pptr, opli);
    873  1.1  christos             if (opli > li) {
    874  1.5  christos                 ND_PRINT((ndo, ", opt (%d) too long", op));
    875  1.1  christos                 return (0);
    876  1.1  christos             }
    877  1.1  christos             li -= opli;
    878  1.1  christos             tptr = pptr;
    879  1.1  christos             tlen = opli;
    880  1.5  christos 
    881  1.5  christos             ND_PRINT((ndo, "\n\t  %s Option #%u, length %u, value: ",
    882  1.1  christos                    tok2str(clnp_option_values,"Unknown",op),
    883  1.1  christos                    op,
    884  1.5  christos                    opli));
    885  1.1  christos 
    886  1.1  christos             switch (op) {
    887  1.1  christos 
    888  1.1  christos 
    889  1.1  christos             case CLNP_OPTION_ROUTE_RECORDING: /* those two options share the format */
    890  1.5  christos             case CLNP_OPTION_SOURCE_ROUTING:
    891  1.5  christos                     ND_PRINT((ndo, "%s %s",
    892  1.1  christos                            tok2str(clnp_option_sr_rr_values,"Unknown",*tptr),
    893  1.5  christos                            tok2str(clnp_option_sr_rr_string_values, "Unknown Option %u", op)));
    894  1.1  christos                     nsap_offset=*(tptr+1);
    895  1.1  christos                     if (nsap_offset == 0) {
    896  1.5  christos                             ND_PRINT((ndo, " Bad NSAP offset (0)"));
    897  1.1  christos                             break;
    898  1.1  christos                     }
    899  1.1  christos                     nsap_offset-=1; /* offset to nsap list */
    900  1.1  christos                     if (nsap_offset > tlen) {
    901  1.5  christos                             ND_PRINT((ndo, " Bad NSAP offset (past end of option)"));
    902  1.1  christos                             break;
    903  1.1  christos                     }
    904  1.1  christos                     tptr+=nsap_offset;
    905  1.1  christos                     tlen-=nsap_offset;
    906  1.1  christos                     while (tlen > 0) {
    907  1.1  christos                             source_address_length=*tptr;
    908  1.1  christos                             if (tlen < source_address_length+1) {
    909  1.5  christos                                     ND_PRINT((ndo, "\n\t    NSAP address goes past end of option"));
    910  1.1  christos                                     break;
    911  1.1  christos                             }
    912  1.1  christos                             if (source_address_length > 0) {
    913  1.1  christos                                     source_address=(tptr+1);
    914  1.5  christos                                     ND_TCHECK2(*source_address, source_address_length);
    915  1.5  christos                                     ND_PRINT((ndo, "\n\t    NSAP address (length %u): %s",
    916  1.1  christos                                            source_address_length,
    917  1.7  christos                                            isonsap_string(ndo, source_address, source_address_length)));
    918  1.1  christos                             }
    919  1.1  christos                             tlen-=source_address_length+1;
    920  1.1  christos                     }
    921  1.1  christos                     break;
    922  1.1  christos 
    923  1.1  christos             case CLNP_OPTION_PRIORITY:
    924  1.5  christos                     ND_PRINT((ndo, "0x%1x", *tptr&0x0f));
    925  1.1  christos                     break;
    926  1.1  christos 
    927  1.1  christos             case CLNP_OPTION_QOS_MAINTENANCE:
    928  1.5  christos                     ND_PRINT((ndo, "\n\t    Format Code: %s",
    929  1.5  christos                            tok2str(clnp_option_scope_values, "Reserved", *tptr&CLNP_OPTION_SCOPE_MASK)));
    930  1.1  christos 
    931  1.1  christos                     if ((*tptr&CLNP_OPTION_SCOPE_MASK) == CLNP_OPTION_SCOPE_GLOBAL)
    932  1.5  christos                             ND_PRINT((ndo, "\n\t    QoS Flags [%s]",
    933  1.1  christos                                    bittok2str(clnp_option_qos_global_values,
    934  1.1  christos                                               "none",
    935  1.5  christos                                               *tptr&CLNP_OPTION_OPTION_QOS_MASK)));
    936  1.1  christos                     break;
    937  1.1  christos 
    938  1.1  christos             case CLNP_OPTION_SECURITY:
    939  1.5  christos                     ND_PRINT((ndo, "\n\t    Format Code: %s, Security-Level %u",
    940  1.1  christos                            tok2str(clnp_option_scope_values,"Reserved",*tptr&CLNP_OPTION_SCOPE_MASK),
    941  1.5  christos                            *(tptr+1)));
    942  1.1  christos                     break;
    943  1.1  christos 
    944  1.1  christos             case CLNP_OPTION_DISCARD_REASON:
    945  1.1  christos                 rfd_error_major = (*tptr&0xf0) >> 4;
    946  1.1  christos                 rfd_error_minor = *tptr&0x0f;
    947  1.5  christos                 ND_PRINT((ndo, "\n\t    Class: %s Error (0x%01x), %s (0x%01x)",
    948  1.1  christos                        tok2str(clnp_option_rfd_class_values,"Unknown",rfd_error_major),
    949  1.1  christos                        rfd_error_major,
    950  1.1  christos                        tok2str(clnp_option_rfd_error_class[rfd_error_major],"Unknown",rfd_error_minor),
    951  1.5  christos                        rfd_error_minor));
    952  1.1  christos                 break;
    953  1.1  christos 
    954  1.1  christos             case CLNP_OPTION_PADDING:
    955  1.5  christos                     ND_PRINT((ndo, "padding data"));
    956  1.1  christos                 break;
    957  1.1  christos 
    958  1.1  christos                 /*
    959  1.1  christos                  * FIXME those are the defined Options that lack a decoder
    960  1.1  christos                  * you are welcome to contribute code ;-)
    961  1.1  christos                  */
    962  1.1  christos 
    963  1.1  christos             default:
    964  1.5  christos                 print_unknown_data(ndo, tptr, "\n\t  ", opli);
    965  1.1  christos                 break;
    966  1.1  christos             }
    967  1.5  christos             if (ndo->ndo_vflag > 1)
    968  1.5  christos                 print_unknown_data(ndo, pptr, "\n\t  ", opli);
    969  1.1  christos             pptr += opli;
    970  1.1  christos         }
    971  1.1  christos 
    972  1.1  christos         switch (clnp_pdu_type) {
    973  1.1  christos 
    974  1.1  christos         case    CLNP_PDU_ER: /* fall through */
    975  1.1  christos         case 	CLNP_PDU_ERP:
    976  1.5  christos             ND_TCHECK(*pptr);
    977  1.1  christos             if (*(pptr) == NLPID_CLNP) {
    978  1.5  christos                 ND_PRINT((ndo, "\n\t-----original packet-----\n\t"));
    979  1.1  christos                 /* FIXME recursion protection */
    980  1.5  christos                 clnp_print(ndo, pptr, length - clnp_header->length_indicator);
    981  1.1  christos                 break;
    982  1.5  christos             }
    983  1.1  christos 
    984  1.1  christos         case 	CLNP_PDU_DT:
    985  1.1  christos         case 	CLNP_PDU_MD:
    986  1.1  christos         case 	CLNP_PDU_ERQ:
    987  1.5  christos 
    988  1.1  christos         default:
    989  1.1  christos             /* dump the PDU specific data */
    990  1.1  christos             if (length-(pptr-optr) > 0) {
    991  1.5  christos                 ND_PRINT((ndo, "\n\t  undecoded non-header data, length %u", length-clnp_header->length_indicator));
    992  1.5  christos                 print_unknown_data(ndo, pptr, "\n\t  ", length - (pptr - optr));
    993  1.1  christos             }
    994  1.1  christos         }
    995  1.1  christos 
    996  1.1  christos         return (1);
    997  1.1  christos 
    998  1.1  christos  trunc:
    999  1.5  christos     ND_PRINT((ndo, "[|clnp]"));
   1000  1.1  christos     return (1);
   1001  1.1  christos 
   1002  1.1  christos }
   1003  1.1  christos 
   1004  1.1  christos 
   1005  1.1  christos #define	ESIS_PDU_REDIRECT	6
   1006  1.1  christos #define	ESIS_PDU_ESH	        2
   1007  1.1  christos #define	ESIS_PDU_ISH	        4
   1008  1.1  christos 
   1009  1.4  christos static const struct tok esis_pdu_values[] = {
   1010  1.1  christos     { ESIS_PDU_REDIRECT, "redirect"},
   1011  1.1  christos     { ESIS_PDU_ESH,      "ESH"},
   1012  1.1  christos     { ESIS_PDU_ISH,      "ISH"},
   1013  1.1  christos     { 0, NULL }
   1014  1.1  christos };
   1015  1.1  christos 
   1016  1.1  christos struct esis_header_t {
   1017  1.5  christos 	uint8_t nlpid;
   1018  1.5  christos 	uint8_t length_indicator;
   1019  1.5  christos 	uint8_t version;
   1020  1.5  christos 	uint8_t reserved;
   1021  1.5  christos 	uint8_t type;
   1022  1.5  christos 	uint8_t holdtime[2];
   1023  1.5  christos 	uint8_t cksum[2];
   1024  1.1  christos };
   1025  1.1  christos 
   1026  1.1  christos static void
   1027  1.5  christos esis_print(netdissect_options *ndo,
   1028  1.5  christos            const uint8_t *pptr, u_int length)
   1029  1.1  christos {
   1030  1.5  christos 	const uint8_t *optr;
   1031  1.1  christos 	u_int li,esis_pdu_type,source_address_length, source_address_number;
   1032  1.1  christos 	const struct esis_header_t *esis_header;
   1033  1.1  christos 
   1034  1.5  christos 	if (!ndo->ndo_eflag)
   1035  1.5  christos 		ND_PRINT((ndo, "ES-IS"));
   1036  1.1  christos 
   1037  1.1  christos 	if (length <= 2) {
   1038  1.5  christos 		ND_PRINT((ndo, ndo->ndo_qflag ? "bad pkt!" : "no header at all!"));
   1039  1.1  christos 		return;
   1040  1.1  christos 	}
   1041  1.1  christos 
   1042  1.1  christos 	esis_header = (const struct esis_header_t *) pptr;
   1043  1.5  christos         ND_TCHECK(*esis_header);
   1044  1.1  christos         li = esis_header->length_indicator;
   1045  1.1  christos         optr = pptr;
   1046  1.1  christos 
   1047  1.1  christos         /*
   1048  1.1  christos          * Sanity checking of the header.
   1049  1.1  christos          */
   1050  1.1  christos 
   1051  1.1  christos         if (esis_header->nlpid != NLPID_ESIS) {
   1052  1.5  christos             ND_PRINT((ndo, " nlpid 0x%02x packet not supported", esis_header->nlpid));
   1053  1.1  christos             return;
   1054  1.1  christos         }
   1055  1.1  christos 
   1056  1.1  christos         if (esis_header->version != ESIS_VERSION) {
   1057  1.5  christos             ND_PRINT((ndo, " version %d packet not supported", esis_header->version));
   1058  1.1  christos             return;
   1059  1.1  christos         }
   1060  1.5  christos 
   1061  1.1  christos 	if (li > length) {
   1062  1.5  christos             ND_PRINT((ndo, " length indicator(%d) > PDU size (%d)!", li, length));
   1063  1.1  christos             return;
   1064  1.1  christos 	}
   1065  1.1  christos 
   1066  1.1  christos 	if (li < sizeof(struct esis_header_t) + 2) {
   1067  1.5  christos             ND_PRINT((ndo, " length indicator < min PDU size %d:", li));
   1068  1.6  christos             while (pptr < ndo->ndo_snapend)
   1069  1.5  christos                 ND_PRINT((ndo, "%02X", *pptr++));
   1070  1.1  christos             return;
   1071  1.1  christos 	}
   1072  1.1  christos 
   1073  1.1  christos         esis_pdu_type = esis_header->type & ESIS_PDU_TYPE_MASK;
   1074  1.1  christos 
   1075  1.5  christos         if (ndo->ndo_vflag < 1) {
   1076  1.5  christos             ND_PRINT((ndo, "%s%s, length %u",
   1077  1.5  christos                    ndo->ndo_eflag ? "" : ", ",
   1078  1.1  christos                    tok2str(esis_pdu_values,"unknown type (%u)",esis_pdu_type),
   1079  1.5  christos                    length));
   1080  1.1  christos             return;
   1081  1.1  christos         } else
   1082  1.5  christos             ND_PRINT((ndo, "%slength %u\n\t%s (%u)",
   1083  1.5  christos                    ndo->ndo_eflag ? "" : ", ",
   1084  1.1  christos                    length,
   1085  1.1  christos                    tok2str(esis_pdu_values,"unknown type: %u", esis_pdu_type),
   1086  1.5  christos                    esis_pdu_type));
   1087  1.1  christos 
   1088  1.5  christos         ND_PRINT((ndo, ", v: %u%s", esis_header->version, esis_header->version == ESIS_VERSION ? "" : "unsupported" ));
   1089  1.5  christos         ND_PRINT((ndo, ", checksum: 0x%04x", EXTRACT_16BITS(esis_header->cksum)));
   1090  1.1  christos 
   1091  1.7  christos         if (osi_print_cksum(ndo, pptr, EXTRACT_16BITS(esis_header->cksum), 7, li) == 0)
   1092  1.7  christos                 goto trunc;
   1093  1.1  christos 
   1094  1.5  christos         ND_PRINT((ndo, ", holding time: %us, length indicator: %u",
   1095  1.5  christos                   EXTRACT_16BITS(esis_header->holdtime), li));
   1096  1.1  christos 
   1097  1.5  christos         if (ndo->ndo_vflag > 1)
   1098  1.5  christos             print_unknown_data(ndo, optr, "\n\t", sizeof(struct esis_header_t));
   1099  1.1  christos 
   1100  1.1  christos 	pptr += sizeof(struct esis_header_t);
   1101  1.1  christos 	li -= sizeof(struct esis_header_t);
   1102  1.1  christos 
   1103  1.1  christos 	switch (esis_pdu_type) {
   1104  1.1  christos 	case ESIS_PDU_REDIRECT: {
   1105  1.5  christos 		const uint8_t *dst, *snpa, *neta;
   1106  1.1  christos 		u_int dstl, snpal, netal;
   1107  1.1  christos 
   1108  1.5  christos 		ND_TCHECK(*pptr);
   1109  1.1  christos 		if (li < 1) {
   1110  1.5  christos 			ND_PRINT((ndo, ", bad redirect/li"));
   1111  1.1  christos 			return;
   1112  1.1  christos 		}
   1113  1.1  christos 		dstl = *pptr;
   1114  1.1  christos 		pptr++;
   1115  1.1  christos 		li--;
   1116  1.5  christos 		ND_TCHECK2(*pptr, dstl);
   1117  1.1  christos 		if (li < dstl) {
   1118  1.5  christos 			ND_PRINT((ndo, ", bad redirect/li"));
   1119  1.1  christos 			return;
   1120  1.1  christos 		}
   1121  1.1  christos 		dst = pptr;
   1122  1.1  christos 		pptr += dstl;
   1123  1.1  christos                 li -= dstl;
   1124  1.7  christos 		ND_PRINT((ndo, "\n\t  %s", isonsap_string(ndo, dst, dstl)));
   1125  1.1  christos 
   1126  1.5  christos 		ND_TCHECK(*pptr);
   1127  1.1  christos 		if (li < 1) {
   1128  1.5  christos 			ND_PRINT((ndo, ", bad redirect/li"));
   1129  1.1  christos 			return;
   1130  1.1  christos 		}
   1131  1.1  christos 		snpal = *pptr;
   1132  1.1  christos 		pptr++;
   1133  1.1  christos 		li--;
   1134  1.5  christos 		ND_TCHECK2(*pptr, snpal);
   1135  1.1  christos 		if (li < snpal) {
   1136  1.5  christos 			ND_PRINT((ndo, ", bad redirect/li"));
   1137  1.1  christos 			return;
   1138  1.1  christos 		}
   1139  1.1  christos 		snpa = pptr;
   1140  1.1  christos 		pptr += snpal;
   1141  1.1  christos                 li -= snpal;
   1142  1.5  christos 		ND_TCHECK(*pptr);
   1143  1.1  christos 		if (li < 1) {
   1144  1.5  christos 			ND_PRINT((ndo, ", bad redirect/li"));
   1145  1.1  christos 			return;
   1146  1.1  christos 		}
   1147  1.1  christos 		netal = *pptr;
   1148  1.1  christos 		pptr++;
   1149  1.5  christos 		ND_TCHECK2(*pptr, netal);
   1150  1.1  christos 		if (li < netal) {
   1151  1.5  christos 			ND_PRINT((ndo, ", bad redirect/li"));
   1152  1.1  christos 			return;
   1153  1.1  christos 		}
   1154  1.1  christos 		neta = pptr;
   1155  1.1  christos 		pptr += netal;
   1156  1.1  christos                 li -= netal;
   1157  1.1  christos 
   1158  1.1  christos 		if (netal == 0)
   1159  1.5  christos 			ND_PRINT((ndo, "\n\t  %s", etheraddr_string(ndo, snpa)));
   1160  1.1  christos 		else
   1161  1.7  christos 			ND_PRINT((ndo, "\n\t  %s", isonsap_string(ndo, neta, netal)));
   1162  1.1  christos 		break;
   1163  1.1  christos 	}
   1164  1.1  christos 
   1165  1.1  christos 	case ESIS_PDU_ESH:
   1166  1.5  christos             ND_TCHECK(*pptr);
   1167  1.1  christos             if (li < 1) {
   1168  1.5  christos                 ND_PRINT((ndo, ", bad esh/li"));
   1169  1.1  christos                 return;
   1170  1.1  christos             }
   1171  1.1  christos             source_address_number = *pptr;
   1172  1.1  christos             pptr++;
   1173  1.1  christos             li--;
   1174  1.1  christos 
   1175  1.5  christos             ND_PRINT((ndo, "\n\t  Number of Source Addresses: %u", source_address_number));
   1176  1.5  christos 
   1177  1.1  christos             while (source_address_number > 0) {
   1178  1.5  christos                 ND_TCHECK(*pptr);
   1179  1.1  christos             	if (li < 1) {
   1180  1.5  christos                     ND_PRINT((ndo, ", bad esh/li"));
   1181  1.1  christos             	    return;
   1182  1.1  christos             	}
   1183  1.1  christos                 source_address_length = *pptr;
   1184  1.1  christos                 pptr++;
   1185  1.1  christos             	li--;
   1186  1.1  christos 
   1187  1.5  christos                 ND_TCHECK2(*pptr, source_address_length);
   1188  1.1  christos             	if (li < source_address_length) {
   1189  1.5  christos                     ND_PRINT((ndo, ", bad esh/li"));
   1190  1.1  christos             	    return;
   1191  1.1  christos             	}
   1192  1.5  christos                 ND_PRINT((ndo, "\n\t  NET (length: %u): %s",
   1193  1.1  christos                        source_address_length,
   1194  1.7  christos                        isonsap_string(ndo, pptr, source_address_length)));
   1195  1.1  christos                 pptr += source_address_length;
   1196  1.1  christos                 li -= source_address_length;
   1197  1.1  christos                 source_address_number--;
   1198  1.1  christos             }
   1199  1.1  christos 
   1200  1.1  christos             break;
   1201  1.1  christos 
   1202  1.1  christos 	case ESIS_PDU_ISH: {
   1203  1.5  christos             ND_TCHECK(*pptr);
   1204  1.1  christos             if (li < 1) {
   1205  1.5  christos                 ND_PRINT((ndo, ", bad ish/li"));
   1206  1.1  christos                 return;
   1207  1.1  christos             }
   1208  1.1  christos             source_address_length = *pptr;
   1209  1.1  christos             pptr++;
   1210  1.1  christos             li--;
   1211  1.5  christos             ND_TCHECK2(*pptr, source_address_length);
   1212  1.1  christos             if (li < source_address_length) {
   1213  1.5  christos                 ND_PRINT((ndo, ", bad ish/li"));
   1214  1.1  christos                 return;
   1215  1.1  christos             }
   1216  1.7  christos             ND_PRINT((ndo, "\n\t  NET (length: %u): %s", source_address_length, isonsap_string(ndo, pptr, source_address_length)));
   1217  1.1  christos             pptr += source_address_length;
   1218  1.1  christos             li -= source_address_length;
   1219  1.1  christos             break;
   1220  1.1  christos 	}
   1221  1.1  christos 
   1222  1.1  christos 	default:
   1223  1.5  christos 		if (ndo->ndo_vflag <= 1) {
   1224  1.5  christos 			if (pptr < ndo->ndo_snapend)
   1225  1.5  christos 				print_unknown_data(ndo, pptr, "\n\t  ", ndo->ndo_snapend - pptr);
   1226  1.5  christos 		}
   1227  1.5  christos 		return;
   1228  1.1  christos 	}
   1229  1.1  christos 
   1230  1.1  christos         /* now walk the options */
   1231  1.3  christos         while (li != 0) {
   1232  1.1  christos             u_int op, opli;
   1233  1.5  christos             const uint8_t *tptr;
   1234  1.5  christos 
   1235  1.1  christos             if (li < 2) {
   1236  1.5  christos                 ND_PRINT((ndo, ", bad opts/li"));
   1237  1.1  christos                 return;
   1238  1.1  christos             }
   1239  1.5  christos             ND_TCHECK2(*pptr, 2);
   1240  1.1  christos             op = *pptr++;
   1241  1.1  christos             opli = *pptr++;
   1242  1.1  christos             li -= 2;
   1243  1.1  christos             if (opli > li) {
   1244  1.5  christos                 ND_PRINT((ndo, ", opt (%d) too long", op));
   1245  1.1  christos                 return;
   1246  1.1  christos             }
   1247  1.1  christos             li -= opli;
   1248  1.1  christos             tptr = pptr;
   1249  1.5  christos 
   1250  1.5  christos             ND_PRINT((ndo, "\n\t  %s Option #%u, length %u, value: ",
   1251  1.1  christos                    tok2str(esis_option_values,"Unknown",op),
   1252  1.1  christos                    op,
   1253  1.5  christos                    opli));
   1254  1.1  christos 
   1255  1.1  christos             switch (op) {
   1256  1.1  christos 
   1257  1.1  christos             case ESIS_OPTION_ES_CONF_TIME:
   1258  1.3  christos                 if (opli == 2) {
   1259  1.5  christos                     ND_TCHECK2(*pptr, 2);
   1260  1.5  christos                     ND_PRINT((ndo, "%us", EXTRACT_16BITS(tptr)));
   1261  1.3  christos                 } else
   1262  1.5  christos                     ND_PRINT((ndo, "(bad length)"));
   1263  1.1  christos                 break;
   1264  1.1  christos 
   1265  1.1  christos             case ESIS_OPTION_PROTOCOLS:
   1266  1.1  christos                 while (opli>0) {
   1267  1.5  christos                     ND_TCHECK(*pptr);
   1268  1.5  christos                     ND_PRINT((ndo, "%s (0x%02x)",
   1269  1.1  christos                            tok2str(nlpid_values,
   1270  1.1  christos                                    "unknown",
   1271  1.1  christos                                    *tptr),
   1272  1.5  christos                            *tptr));
   1273  1.1  christos                     if (opli>1) /* further NPLIDs ? - put comma */
   1274  1.5  christos                         ND_PRINT((ndo, ", "));
   1275  1.1  christos                     tptr++;
   1276  1.1  christos                     opli--;
   1277  1.1  christos                 }
   1278  1.1  christos                 break;
   1279  1.1  christos 
   1280  1.1  christos                 /*
   1281  1.1  christos                  * FIXME those are the defined Options that lack a decoder
   1282  1.1  christos                  * you are welcome to contribute code ;-)
   1283  1.1  christos                  */
   1284  1.1  christos 
   1285  1.1  christos             case ESIS_OPTION_QOS_MAINTENANCE:
   1286  1.1  christos             case ESIS_OPTION_SECURITY:
   1287  1.1  christos             case ESIS_OPTION_PRIORITY:
   1288  1.1  christos             case ESIS_OPTION_ADDRESS_MASK:
   1289  1.1  christos             case ESIS_OPTION_SNPA_MASK:
   1290  1.1  christos 
   1291  1.1  christos             default:
   1292  1.5  christos                 print_unknown_data(ndo, tptr, "\n\t  ", opli);
   1293  1.1  christos                 break;
   1294  1.1  christos             }
   1295  1.5  christos             if (ndo->ndo_vflag > 1)
   1296  1.5  christos                 print_unknown_data(ndo, pptr, "\n\t  ", opli);
   1297  1.1  christos             pptr += opli;
   1298  1.1  christos         }
   1299  1.1  christos trunc:
   1300  1.1  christos 	return;
   1301  1.5  christos }
   1302  1.4  christos 
   1303  1.4  christos static void
   1304  1.5  christos isis_print_mcid(netdissect_options *ndo,
   1305  1.5  christos                 const struct isis_spb_mcid *mcid)
   1306  1.4  christos {
   1307  1.4  christos   int i;
   1308  1.4  christos 
   1309  1.7  christos   ND_TCHECK(*mcid);
   1310  1.5  christos   ND_PRINT((ndo,  "ID: %d, Name: ", mcid->format_id));
   1311  1.4  christos 
   1312  1.7  christos   if (fn_printzp(ndo, mcid->name, 32, ndo->ndo_snapend))
   1313  1.7  christos     goto trunc;
   1314  1.4  christos 
   1315  1.5  christos   ND_PRINT((ndo, "\n\t              Lvl: %d", EXTRACT_16BITS(mcid->revision_lvl)));
   1316  1.4  christos 
   1317  1.5  christos   ND_PRINT((ndo,  ", Digest: "));
   1318  1.4  christos 
   1319  1.5  christos   for(i=0;i<16;i++)
   1320  1.5  christos     ND_PRINT((ndo, "%.2x ", mcid->digest[i]));
   1321  1.7  christos 
   1322  1.7  christos trunc:
   1323  1.7  christos   ND_PRINT((ndo, "%s", tstr));
   1324  1.4  christos }
   1325  1.4  christos 
   1326  1.4  christos static int
   1327  1.5  christos isis_print_mt_port_cap_subtlv(netdissect_options *ndo,
   1328  1.5  christos                               const uint8_t *tptr, int len)
   1329  1.4  christos {
   1330  1.4  christos   int stlv_type, stlv_len;
   1331  1.4  christos   const struct isis_subtlv_spb_mcid *subtlv_spb_mcid;
   1332  1.4  christos   int i;
   1333  1.4  christos 
   1334  1.7  christos   while (len > 2)
   1335  1.4  christos   {
   1336  1.4  christos     stlv_type = *(tptr++);
   1337  1.4  christos     stlv_len  = *(tptr++);
   1338  1.4  christos 
   1339  1.4  christos     /* first lets see if we know the subTLVs name*/
   1340  1.5  christos     ND_PRINT((ndo, "\n\t       %s subTLV #%u, length: %u",
   1341  1.4  christos                tok2str(isis_mt_port_cap_subtlv_values, "unknown", stlv_type),
   1342  1.4  christos                stlv_type,
   1343  1.5  christos                stlv_len));
   1344  1.4  christos 
   1345  1.4  christos     /*len -= TLV_TYPE_LEN_OFFSET;*/
   1346  1.4  christos     len = len -2;
   1347  1.4  christos 
   1348  1.4  christos     switch (stlv_type)
   1349  1.4  christos     {
   1350  1.4  christos       case ISIS_SUBTLV_SPB_MCID:
   1351  1.4  christos       {
   1352  1.5  christos         if (!ND_TTEST2(*(tptr), ISIS_SUBTLV_SPB_MCID_MIN_LEN))
   1353  1.4  christos           goto trunctlv;
   1354  1.4  christos 
   1355  1.7  christos         subtlv_spb_mcid = (const struct isis_subtlv_spb_mcid *)tptr;
   1356  1.4  christos 
   1357  1.5  christos         ND_PRINT((ndo,  "\n\t         MCID: "));
   1358  1.5  christos         isis_print_mcid(ndo, &(subtlv_spb_mcid->mcid));
   1359  1.4  christos 
   1360  1.4  christos           /*tptr += SPB_MCID_MIN_LEN;
   1361  1.4  christos             len -= SPB_MCID_MIN_LEN; */
   1362  1.4  christos 
   1363  1.5  christos         ND_PRINT((ndo,  "\n\t         AUX-MCID: "));
   1364  1.5  christos         isis_print_mcid(ndo, &(subtlv_spb_mcid->aux_mcid));
   1365  1.4  christos 
   1366  1.4  christos           /*tptr += SPB_MCID_MIN_LEN;
   1367  1.4  christos             len -= SPB_MCID_MIN_LEN; */
   1368  1.4  christos         tptr = tptr + sizeof(struct isis_subtlv_spb_mcid);
   1369  1.4  christos         len = len - sizeof(struct isis_subtlv_spb_mcid);
   1370  1.4  christos 
   1371  1.4  christos         break;
   1372  1.4  christos       }
   1373  1.4  christos 
   1374  1.4  christos       case ISIS_SUBTLV_SPB_DIGEST:
   1375  1.4  christos       {
   1376  1.5  christos         if (!ND_TTEST2(*(tptr), ISIS_SUBTLV_SPB_DIGEST_MIN_LEN))
   1377  1.4  christos           goto trunctlv;
   1378  1.4  christos 
   1379  1.5  christos         ND_PRINT((ndo, "\n\t        RES: %d V: %d A: %d D: %d",
   1380  1.4  christos                         (*(tptr) >> 5), (((*tptr)>> 4) & 0x01),
   1381  1.5  christos                         ((*(tptr) >> 2) & 0x03), ((*tptr) & 0x03)));
   1382  1.4  christos 
   1383  1.4  christos         tptr++;
   1384  1.4  christos 
   1385  1.5  christos         ND_PRINT((ndo,  "\n\t         Digest: "));
   1386  1.5  christos 
   1387  1.4  christos         for(i=1;i<=8; i++)
   1388  1.4  christos         {
   1389  1.5  christos             ND_PRINT((ndo, "%08x ", EXTRACT_32BITS(tptr)));
   1390  1.4  christos             if (i%4 == 0 && i != 8)
   1391  1.5  christos               ND_PRINT((ndo, "\n\t                 "));
   1392  1.4  christos             tptr = tptr + 4;
   1393  1.4  christos         }
   1394  1.4  christos 
   1395  1.4  christos         len = len - ISIS_SUBTLV_SPB_DIGEST_MIN_LEN;
   1396  1.4  christos 
   1397  1.4  christos         break;
   1398  1.4  christos       }
   1399  1.4  christos 
   1400  1.4  christos       case ISIS_SUBTLV_SPB_BVID:
   1401  1.4  christos       {
   1402  1.5  christos         if (!ND_TTEST2(*(tptr), stlv_len))
   1403  1.4  christos           goto trunctlv;
   1404  1.4  christos 
   1405  1.7  christos         while (len >= ISIS_SUBTLV_SPB_BVID_MIN_LEN)
   1406  1.4  christos         {
   1407  1.5  christos           if (!ND_TTEST2(*(tptr), ISIS_SUBTLV_SPB_BVID_MIN_LEN))
   1408  1.4  christos             goto trunctlv;
   1409  1.4  christos 
   1410  1.5  christos           ND_PRINT((ndo, "\n\t           ECT: %08x",
   1411  1.5  christos                       EXTRACT_32BITS(tptr)));
   1412  1.4  christos 
   1413  1.4  christos           tptr = tptr+4;
   1414  1.4  christos 
   1415  1.5  christos           ND_PRINT((ndo, " BVID: %d, U:%01x M:%01x ",
   1416  1.4  christos                      (EXTRACT_16BITS (tptr) >> 4) ,
   1417  1.4  christos                      (EXTRACT_16BITS (tptr) >> 3) & 0x01,
   1418  1.5  christos                      (EXTRACT_16BITS (tptr) >> 2) & 0x01));
   1419  1.4  christos 
   1420  1.4  christos           tptr = tptr + 2;
   1421  1.4  christos           len = len - ISIS_SUBTLV_SPB_BVID_MIN_LEN;
   1422  1.4  christos         }
   1423  1.4  christos 
   1424  1.4  christos         break;
   1425  1.4  christos       }
   1426  1.5  christos 
   1427  1.4  christos       default:
   1428  1.4  christos           break;
   1429  1.4  christos     }
   1430  1.4  christos   }
   1431  1.4  christos 
   1432  1.4  christos   return 0;
   1433  1.4  christos 
   1434  1.4  christos   trunctlv:
   1435  1.7  christos     ND_PRINT((ndo, "\n\t\t"));
   1436  1.7  christos     ND_PRINT((ndo, "%s", tstr));
   1437  1.5  christos     return(1);
   1438  1.4  christos }
   1439  1.4  christos 
   1440  1.4  christos static int
   1441  1.5  christos isis_print_mt_capability_subtlv(netdissect_options *ndo,
   1442  1.5  christos                                 const uint8_t *tptr, int len)
   1443  1.4  christos {
   1444  1.4  christos   int stlv_type, stlv_len, tmp;
   1445  1.4  christos 
   1446  1.7  christos   while (len > 2)
   1447  1.5  christos   {
   1448  1.4  christos     stlv_type = *(tptr++);
   1449  1.4  christos     stlv_len  = *(tptr++);
   1450  1.4  christos 
   1451  1.4  christos     /* first lets see if we know the subTLVs name*/
   1452  1.5  christos     ND_PRINT((ndo, "\n\t      %s subTLV #%u, length: %u",
   1453  1.4  christos                tok2str(isis_mt_capability_subtlv_values, "unknown", stlv_type),
   1454  1.4  christos                stlv_type,
   1455  1.5  christos                stlv_len));
   1456  1.5  christos 
   1457  1.4  christos     len = len - 2;
   1458  1.4  christos 
   1459  1.4  christos     switch (stlv_type)
   1460  1.5  christos     {
   1461  1.4  christos       case ISIS_SUBTLV_SPB_INSTANCE:
   1462  1.4  christos 
   1463  1.7  christos           ND_TCHECK2(*tptr, ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN);
   1464  1.4  christos 
   1465  1.5  christos           ND_PRINT((ndo, "\n\t        CIST Root-ID: %08x", EXTRACT_32BITS(tptr)));
   1466  1.4  christos           tptr = tptr+4;
   1467  1.5  christos           ND_PRINT((ndo, " %08x", EXTRACT_32BITS(tptr)));
   1468  1.4  christos           tptr = tptr+4;
   1469  1.5  christos           ND_PRINT((ndo, ", Path Cost: %08x", EXTRACT_32BITS(tptr)));
   1470  1.4  christos           tptr = tptr+4;
   1471  1.5  christos           ND_PRINT((ndo, ", Prio: %d", EXTRACT_16BITS(tptr)));
   1472  1.5  christos           tptr = tptr + 2;
   1473  1.5  christos           ND_PRINT((ndo, "\n\t        RES: %d",
   1474  1.5  christos                     EXTRACT_16BITS(tptr) >> 5));
   1475  1.5  christos           ND_PRINT((ndo, ", V: %d",
   1476  1.5  christos                     (EXTRACT_16BITS(tptr) >> 4) & 0x0001));
   1477  1.5  christos           ND_PRINT((ndo, ", SPSource-ID: %d",
   1478  1.5  christos                     (EXTRACT_32BITS(tptr) & 0x000fffff)));
   1479  1.4  christos           tptr = tptr+4;
   1480  1.5  christos           ND_PRINT((ndo, ", No of Trees: %x", *(tptr)));
   1481  1.4  christos 
   1482  1.4  christos           tmp = *(tptr++);
   1483  1.4  christos 
   1484  1.4  christos           len = len - ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN;
   1485  1.4  christos 
   1486  1.4  christos           while (tmp)
   1487  1.4  christos           {
   1488  1.7  christos             ND_TCHECK2(*tptr, ISIS_SUBTLV_SPB_INSTANCE_VLAN_TUPLE_LEN);
   1489  1.4  christos 
   1490  1.5  christos             ND_PRINT((ndo, "\n\t         U:%d, M:%d, A:%d, RES:%d",
   1491  1.4  christos                       *(tptr) >> 7, (*(tptr) >> 6) & 0x01,
   1492  1.5  christos                       (*(tptr) >> 5) & 0x01, (*(tptr) & 0x1f)));
   1493  1.5  christos 
   1494  1.4  christos             tptr++;
   1495  1.5  christos 
   1496  1.5  christos             ND_PRINT((ndo, ", ECT: %08x", EXTRACT_32BITS(tptr)));
   1497  1.4  christos 
   1498  1.4  christos             tptr = tptr + 4;
   1499  1.4  christos 
   1500  1.5  christos             ND_PRINT((ndo, ", BVID: %d, SPVID: %d",
   1501  1.4  christos                       (EXTRACT_24BITS(tptr) >> 12) & 0x000fff,
   1502  1.5  christos                       EXTRACT_24BITS(tptr) & 0x000fff));
   1503  1.4  christos 
   1504  1.4  christos             tptr = tptr + 3;
   1505  1.4  christos             len = len - ISIS_SUBTLV_SPB_INSTANCE_VLAN_TUPLE_LEN;
   1506  1.5  christos             tmp--;
   1507  1.4  christos           }
   1508  1.4  christos 
   1509  1.4  christos           break;
   1510  1.4  christos 
   1511  1.4  christos       case ISIS_SUBTLV_SPBM_SI:
   1512  1.4  christos 
   1513  1.7  christos           ND_TCHECK2(*tptr, 8);
   1514  1.4  christos 
   1515  1.5  christos           ND_PRINT((ndo, "\n\t        BMAC: %08x", EXTRACT_32BITS(tptr)));
   1516  1.4  christos           tptr = tptr+4;
   1517  1.5  christos           ND_PRINT((ndo, "%04x", EXTRACT_16BITS(tptr)));
   1518  1.4  christos           tptr = tptr+2;
   1519  1.4  christos 
   1520  1.5  christos           ND_PRINT((ndo, ", RES: %d, VID: %d", EXTRACT_16BITS(tptr) >> 12,
   1521  1.5  christos                     (EXTRACT_16BITS(tptr)) & 0x0fff));
   1522  1.4  christos 
   1523  1.4  christos           tptr = tptr+2;
   1524  1.4  christos           len = len - 8;
   1525  1.4  christos           stlv_len = stlv_len - 8;
   1526  1.4  christos 
   1527  1.7  christos           while (stlv_len >= 4) {
   1528  1.7  christos             ND_TCHECK2(*tptr, 4);
   1529  1.5  christos             ND_PRINT((ndo, "\n\t        T: %d, R: %d, RES: %d, ISID: %d",
   1530  1.4  christos                     (EXTRACT_32BITS(tptr) >> 31),
   1531  1.4  christos                     (EXTRACT_32BITS(tptr) >> 30) & 0x01,
   1532  1.4  christos                     (EXTRACT_32BITS(tptr) >> 24) & 0x03f,
   1533  1.5  christos                     (EXTRACT_32BITS(tptr)) & 0x0ffffff));
   1534  1.4  christos 
   1535  1.4  christos             tptr = tptr + 4;
   1536  1.4  christos             len = len - 4;
   1537  1.4  christos             stlv_len = stlv_len - 4;
   1538  1.4  christos           }
   1539  1.4  christos 
   1540  1.4  christos         break;
   1541  1.4  christos 
   1542  1.4  christos       default:
   1543  1.4  christos         break;
   1544  1.4  christos     }
   1545  1.4  christos   }
   1546  1.4  christos   return 0;
   1547  1.4  christos 
   1548  1.7  christos   trunc:
   1549  1.7  christos     ND_PRINT((ndo, "\n\t\t"));
   1550  1.7  christos     ND_PRINT((ndo, "%s", tstr));
   1551  1.4  christos     return(1);
   1552  1.4  christos }
   1553  1.4  christos 
   1554  1.1  christos /* shared routine for printing system, node and lsp-ids */
   1555  1.1  christos static char *
   1556  1.5  christos isis_print_id(const uint8_t *cp, int id_len)
   1557  1.1  christos {
   1558  1.1  christos     int i;
   1559  1.1  christos     static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")];
   1560  1.1  christos     char *pos = id;
   1561  1.1  christos 
   1562  1.1  christos     for (i = 1; i <= SYSTEM_ID_LEN; i++) {
   1563  1.1  christos         snprintf(pos, sizeof(id) - (pos - id), "%02x", *cp++);
   1564  1.1  christos 	pos += strlen(pos);
   1565  1.1  christos 	if (i == 2 || i == 4)
   1566  1.1  christos 	    *pos++ = '.';
   1567  1.1  christos 	}
   1568  1.1  christos     if (id_len >= NODE_ID_LEN) {
   1569  1.1  christos         snprintf(pos, sizeof(id) - (pos - id), ".%02x", *cp++);
   1570  1.1  christos 	pos += strlen(pos);
   1571  1.1  christos     }
   1572  1.1  christos     if (id_len == LSP_ID_LEN)
   1573  1.1  christos         snprintf(pos, sizeof(id) - (pos - id), "-%02x", *cp);
   1574  1.1  christos     return (id);
   1575  1.1  christos }
   1576  1.1  christos 
   1577  1.1  christos /* print the 4-byte metric block which is common found in the old-style TLVs */
   1578  1.1  christos static int
   1579  1.5  christos isis_print_metric_block(netdissect_options *ndo,
   1580  1.5  christos                         const struct isis_metric_block *isis_metric_block)
   1581  1.1  christos {
   1582  1.5  christos     ND_PRINT((ndo, ", Default Metric: %d, %s",
   1583  1.1  christos            ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_default),
   1584  1.5  christos            ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_default) ? "External" : "Internal"));
   1585  1.1  christos     if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_delay))
   1586  1.5  christos         ND_PRINT((ndo, "\n\t\t  Delay Metric: %d, %s",
   1587  1.1  christos                ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_delay),
   1588  1.5  christos                ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_delay) ? "External" : "Internal"));
   1589  1.1  christos     if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_expense))
   1590  1.5  christos         ND_PRINT((ndo, "\n\t\t  Expense Metric: %d, %s",
   1591  1.1  christos                ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_expense),
   1592  1.5  christos                ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_expense) ? "External" : "Internal"));
   1593  1.1  christos     if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_error))
   1594  1.5  christos         ND_PRINT((ndo, "\n\t\t  Error Metric: %d, %s",
   1595  1.1  christos                ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_error),
   1596  1.5  christos                ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_error) ? "External" : "Internal"));
   1597  1.1  christos 
   1598  1.1  christos     return(1); /* everything is ok */
   1599  1.1  christos }
   1600  1.1  christos 
   1601  1.1  christos static int
   1602  1.5  christos isis_print_tlv_ip_reach(netdissect_options *ndo,
   1603  1.5  christos                         const uint8_t *cp, const char *ident, int length)
   1604  1.1  christos {
   1605  1.1  christos 	int prefix_len;
   1606  1.1  christos 	const struct isis_tlv_ip_reach *tlv_ip_reach;
   1607  1.1  christos 
   1608  1.1  christos 	tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp;
   1609  1.1  christos 
   1610  1.1  christos 	while (length > 0) {
   1611  1.1  christos 		if ((size_t)length < sizeof(*tlv_ip_reach)) {
   1612  1.5  christos 			ND_PRINT((ndo, "short IPv4 Reachability (%d vs %lu)",
   1613  1.1  christos                                length,
   1614  1.5  christos                                (unsigned long)sizeof(*tlv_ip_reach)));
   1615  1.1  christos 			return (0);
   1616  1.1  christos 		}
   1617  1.1  christos 
   1618  1.5  christos 		if (!ND_TTEST(*tlv_ip_reach))
   1619  1.1  christos 		    return (0);
   1620  1.1  christos 
   1621  1.1  christos 		prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask));
   1622  1.1  christos 
   1623  1.1  christos 		if (prefix_len == -1)
   1624  1.5  christos 			ND_PRINT((ndo, "%sIPv4 prefix: %s mask %s",
   1625  1.1  christos                                ident,
   1626  1.5  christos 			       ipaddr_string(ndo, (tlv_ip_reach->prefix)),
   1627  1.5  christos 			       ipaddr_string(ndo, (tlv_ip_reach->mask))));
   1628  1.1  christos 		else
   1629  1.5  christos 			ND_PRINT((ndo, "%sIPv4 prefix: %15s/%u",
   1630  1.1  christos                                ident,
   1631  1.5  christos 			       ipaddr_string(ndo, (tlv_ip_reach->prefix)),
   1632  1.5  christos 			       prefix_len));
   1633  1.1  christos 
   1634  1.5  christos 		ND_PRINT((ndo, ", Distribution: %s, Metric: %u, %s",
   1635  1.1  christos                        ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up",
   1636  1.1  christos                        ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default),
   1637  1.5  christos                        ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal"));
   1638  1.1  christos 
   1639  1.1  christos 		if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay))
   1640  1.5  christos                     ND_PRINT((ndo, "%s  Delay Metric: %u, %s",
   1641  1.1  christos                            ident,
   1642  1.1  christos                            ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay),
   1643  1.5  christos                            ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal"));
   1644  1.5  christos 
   1645  1.1  christos 		if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense))
   1646  1.5  christos                     ND_PRINT((ndo, "%s  Expense Metric: %u, %s",
   1647  1.1  christos                            ident,
   1648  1.1  christos                            ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense),
   1649  1.5  christos                            ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal"));
   1650  1.5  christos 
   1651  1.1  christos 		if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error))
   1652  1.5  christos                     ND_PRINT((ndo, "%s  Error Metric: %u, %s",
   1653  1.1  christos                            ident,
   1654  1.1  christos                            ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error),
   1655  1.5  christos                            ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal"));
   1656  1.1  christos 
   1657  1.1  christos 		length -= sizeof(struct isis_tlv_ip_reach);
   1658  1.1  christos 		tlv_ip_reach++;
   1659  1.1  christos 	}
   1660  1.1  christos 	return (1);
   1661  1.1  christos }
   1662  1.1  christos 
   1663  1.1  christos /*
   1664  1.1  christos  * this is the common IP-REACH subTLV decoder it is called
   1665  1.1  christos  * from various EXTD-IP REACH TLVs (135,235,236,237)
   1666  1.1  christos  */
   1667  1.1  christos 
   1668  1.1  christos static int
   1669  1.5  christos isis_print_ip_reach_subtlv(netdissect_options *ndo,
   1670  1.5  christos                            const uint8_t *tptr, int subt, int subl,
   1671  1.6  christos                            const char *ident)
   1672  1.6  christos {
   1673  1.1  christos         /* first lets see if we know the subTLVs name*/
   1674  1.5  christos 	ND_PRINT((ndo, "%s%s subTLV #%u, length: %u",
   1675  1.5  christos 	          ident, tok2str(isis_ext_ip_reach_subtlv_values, "unknown", subt),
   1676  1.5  christos 	          subt, subl));
   1677  1.1  christos 
   1678  1.5  christos 	if (!ND_TTEST2(*tptr,subl))
   1679  1.1  christos 	    goto trunctlv;
   1680  1.1  christos 
   1681  1.1  christos     switch(subt) {
   1682  1.1  christos     case ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR: /* fall through */
   1683  1.1  christos     case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32:
   1684  1.1  christos         while (subl >= 4) {
   1685  1.5  christos 	    ND_PRINT((ndo, ", 0x%08x (=%u)",
   1686  1.1  christos 		   EXTRACT_32BITS(tptr),
   1687  1.5  christos 		   EXTRACT_32BITS(tptr)));
   1688  1.1  christos 	    tptr+=4;
   1689  1.1  christos 	    subl-=4;
   1690  1.1  christos 	}
   1691  1.1  christos 	break;
   1692  1.1  christos     case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64:
   1693  1.1  christos         while (subl >= 8) {
   1694  1.5  christos 	    ND_PRINT((ndo, ", 0x%08x%08x",
   1695  1.1  christos 		   EXTRACT_32BITS(tptr),
   1696  1.5  christos 		   EXTRACT_32BITS(tptr+4)));
   1697  1.1  christos 	    tptr+=8;
   1698  1.1  christos 	    subl-=8;
   1699  1.1  christos 	}
   1700  1.1  christos 	break;
   1701  1.1  christos     default:
   1702  1.5  christos 	if (!print_unknown_data(ndo, tptr, "\n\t\t    ", subl))
   1703  1.1  christos 	  return(0);
   1704  1.1  christos 	break;
   1705  1.1  christos     }
   1706  1.1  christos     return(1);
   1707  1.5  christos 
   1708  1.1  christos trunctlv:
   1709  1.7  christos     ND_PRINT((ndo, "%s", ident));
   1710  1.7  christos     ND_PRINT((ndo, "%s", tstr));
   1711  1.1  christos     return(0);
   1712  1.1  christos }
   1713  1.1  christos 
   1714  1.1  christos /*
   1715  1.1  christos  * this is the common IS-REACH subTLV decoder it is called
   1716  1.1  christos  * from isis_print_ext_is_reach()
   1717  1.1  christos  */
   1718  1.1  christos 
   1719  1.1  christos static int
   1720  1.5  christos isis_print_is_reach_subtlv(netdissect_options *ndo,
   1721  1.5  christos                            const uint8_t *tptr, u_int subt, u_int subl,
   1722  1.6  christos                            const char *ident)
   1723  1.6  christos {
   1724  1.1  christos         u_int te_class,priority_level,gmpls_switch_cap;
   1725  1.1  christos         union { /* int to float conversion buffer for several subTLVs */
   1726  1.5  christos             float f;
   1727  1.5  christos             uint32_t i;
   1728  1.1  christos         } bw;
   1729  1.1  christos 
   1730  1.1  christos         /* first lets see if we know the subTLVs name*/
   1731  1.5  christos 	ND_PRINT((ndo, "%s%s subTLV #%u, length: %u",
   1732  1.5  christos 	          ident, tok2str(isis_ext_is_reach_subtlv_values, "unknown", subt),
   1733  1.5  christos 	          subt, subl));
   1734  1.1  christos 
   1735  1.7  christos 	ND_TCHECK2(*tptr, subl);
   1736  1.1  christos 
   1737  1.1  christos         switch(subt) {
   1738  1.5  christos         case ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP:
   1739  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID:
   1740  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID:
   1741  1.1  christos 	    if (subl >= 4) {
   1742  1.5  christos 	      ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(tptr)));
   1743  1.1  christos 	      if (subl == 8) /* rfc4205 */
   1744  1.5  christos 	        ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(tptr+4)));
   1745  1.1  christos 	    }
   1746  1.1  christos 	    break;
   1747  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
   1748  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
   1749  1.1  christos             if (subl >= sizeof(struct in_addr))
   1750  1.5  christos               ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
   1751  1.1  christos             break;
   1752  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
   1753  1.5  christos 	case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW:
   1754  1.1  christos             if (subl >= 4) {
   1755  1.1  christos               bw.i = EXTRACT_32BITS(tptr);
   1756  1.5  christos               ND_PRINT((ndo, ", %.3f Mbps", bw.f * 8 / 1000000));
   1757  1.1  christos             }
   1758  1.1  christos             break;
   1759  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
   1760  1.1  christos             if (subl >= 32) {
   1761  1.1  christos               for (te_class = 0; te_class < 8; te_class++) {
   1762  1.1  christos                 bw.i = EXTRACT_32BITS(tptr);
   1763  1.5  christos                 ND_PRINT((ndo, "%s  TE-Class %u: %.3f Mbps",
   1764  1.1  christos                        ident,
   1765  1.1  christos                        te_class,
   1766  1.5  christos                        bw.f * 8 / 1000000));
   1767  1.1  christos 		tptr+=4;
   1768  1.1  christos 	      }
   1769  1.1  christos             }
   1770  1.1  christos             break;
   1771  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS: /* fall through */
   1772  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD:
   1773  1.5  christos             ND_PRINT((ndo, "%sBandwidth Constraints Model ID: %s (%u)",
   1774  1.1  christos                    ident,
   1775  1.1  christos                    tok2str(diffserv_te_bc_values, "unknown", *tptr),
   1776  1.5  christos                    *tptr));
   1777  1.1  christos             tptr++;
   1778  1.1  christos             /* decode BCs until the subTLV ends */
   1779  1.1  christos             for (te_class = 0; te_class < (subl-1)/4; te_class++) {
   1780  1.7  christos                 ND_TCHECK2(*tptr, 4);
   1781  1.1  christos                 bw.i = EXTRACT_32BITS(tptr);
   1782  1.5  christos                 ND_PRINT((ndo, "%s  Bandwidth constraint CT%u: %.3f Mbps",
   1783  1.1  christos                        ident,
   1784  1.1  christos                        te_class,
   1785  1.5  christos                        bw.f * 8 / 1000000));
   1786  1.1  christos 		tptr+=4;
   1787  1.1  christos             }
   1788  1.1  christos             break;
   1789  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC:
   1790  1.1  christos             if (subl >= 3)
   1791  1.5  christos               ND_PRINT((ndo, ", %u", EXTRACT_24BITS(tptr)));
   1792  1.1  christos             break;
   1793  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_LINK_ATTRIBUTE:
   1794  1.1  christos             if (subl == 2) {
   1795  1.5  christos                ND_PRINT((ndo, ", [ %s ] (0x%04x)",
   1796  1.1  christos                       bittok2str(isis_subtlv_link_attribute_values,
   1797  1.1  christos                                  "Unknown",
   1798  1.1  christos                                  EXTRACT_16BITS(tptr)),
   1799  1.5  christos                       EXTRACT_16BITS(tptr)));
   1800  1.1  christos             }
   1801  1.1  christos             break;
   1802  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE:
   1803  1.1  christos             if (subl >= 2) {
   1804  1.5  christos               ND_PRINT((ndo, ", %s, Priority %u",
   1805  1.1  christos 		   bittok2str(gmpls_link_prot_values, "none", *tptr),
   1806  1.5  christos                    *(tptr+1)));
   1807  1.1  christos             }
   1808  1.1  christos             break;
   1809  1.4  christos         case ISIS_SUBTLV_SPB_METRIC:
   1810  1.4  christos             if (subl >= 6) {
   1811  1.5  christos               ND_PRINT((ndo, ", LM: %u", EXTRACT_24BITS(tptr)));
   1812  1.4  christos               tptr=tptr+3;
   1813  1.5  christos               ND_PRINT((ndo, ", P: %u", *(tptr)));
   1814  1.5  christos               tptr++;
   1815  1.5  christos               ND_PRINT((ndo, ", P-ID: %u", EXTRACT_16BITS(tptr)));
   1816  1.4  christos             }
   1817  1.4  christos             break;
   1818  1.1  christos         case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
   1819  1.1  christos             if (subl >= 36) {
   1820  1.1  christos               gmpls_switch_cap = *tptr;
   1821  1.5  christos               ND_PRINT((ndo, "%s  Interface Switching Capability:%s",
   1822  1.1  christos                    ident,
   1823  1.5  christos                    tok2str(gmpls_switch_cap_values, "Unknown", gmpls_switch_cap)));
   1824  1.5  christos               ND_PRINT((ndo, ", LSP Encoding: %s",
   1825  1.5  christos                    tok2str(gmpls_encoding_values, "Unknown", *(tptr + 1))));
   1826  1.1  christos 	      tptr+=4;
   1827  1.5  christos               ND_PRINT((ndo, "%s  Max LSP Bandwidth:", ident));
   1828  1.1  christos               for (priority_level = 0; priority_level < 8; priority_level++) {
   1829  1.1  christos                 bw.i = EXTRACT_32BITS(tptr);
   1830  1.5  christos                 ND_PRINT((ndo, "%s    priority level %d: %.3f Mbps",
   1831  1.1  christos                        ident,
   1832  1.1  christos                        priority_level,
   1833  1.5  christos                        bw.f * 8 / 1000000));
   1834  1.1  christos 		tptr+=4;
   1835  1.1  christos               }
   1836  1.1  christos               subl-=36;
   1837  1.1  christos               switch (gmpls_switch_cap) {
   1838  1.1  christos               case GMPLS_PSC1:
   1839  1.1  christos               case GMPLS_PSC2:
   1840  1.1  christos               case GMPLS_PSC3:
   1841  1.1  christos               case GMPLS_PSC4:
   1842  1.7  christos                 ND_TCHECK2(*tptr, 6);
   1843  1.1  christos                 bw.i = EXTRACT_32BITS(tptr);
   1844  1.5  christos                 ND_PRINT((ndo, "%s  Min LSP Bandwidth: %.3f Mbps", ident, bw.f * 8 / 1000000));
   1845  1.5  christos                 ND_PRINT((ndo, "%s  Interface MTU: %u", ident, EXTRACT_16BITS(tptr + 4)));
   1846  1.1  christos                 break;
   1847  1.1  christos               case GMPLS_TSC:
   1848  1.7  christos                 ND_TCHECK2(*tptr, 8);
   1849  1.1  christos                 bw.i = EXTRACT_32BITS(tptr);
   1850  1.5  christos                 ND_PRINT((ndo, "%s  Min LSP Bandwidth: %.3f Mbps", ident, bw.f * 8 / 1000000));
   1851  1.5  christos                 ND_PRINT((ndo, "%s  Indication %s", ident,
   1852  1.5  christos                        tok2str(gmpls_switch_cap_tsc_indication_values, "Unknown (%u)", *(tptr + 4))));
   1853  1.1  christos                 break;
   1854  1.1  christos               default:
   1855  1.1  christos                 /* there is some optional stuff left to decode but this is as of yet
   1856  1.1  christos                    not specified so just lets hexdump what is left */
   1857  1.1  christos                 if(subl>0){
   1858  1.5  christos                   if (!print_unknown_data(ndo, tptr, "\n\t\t    ", subl))
   1859  1.1  christos                     return(0);
   1860  1.1  christos                 }
   1861  1.1  christos               }
   1862  1.1  christos             }
   1863  1.1  christos             break;
   1864  1.1  christos         default:
   1865  1.5  christos             if (!print_unknown_data(ndo, tptr, "\n\t\t    ", subl))
   1866  1.1  christos                 return(0);
   1867  1.1  christos             break;
   1868  1.1  christos         }
   1869  1.1  christos         return(1);
   1870  1.1  christos 
   1871  1.7  christos trunc:
   1872  1.1  christos     return(0);
   1873  1.1  christos }
   1874  1.1  christos 
   1875  1.1  christos /*
   1876  1.1  christos  * this is the common IS-REACH decoder it is called
   1877  1.1  christos  * from various EXTD-IS REACH style TLVs (22,24,222)
   1878  1.1  christos  */
   1879  1.1  christos 
   1880  1.1  christos static int
   1881  1.5  christos isis_print_ext_is_reach(netdissect_options *ndo,
   1882  1.6  christos                         const uint8_t *tptr, const char *ident, int tlv_type)
   1883  1.6  christos {
   1884  1.1  christos     char ident_buffer[20];
   1885  1.1  christos     int subtlv_type,subtlv_len,subtlv_sum_len;
   1886  1.1  christos     int proc_bytes = 0; /* how many bytes did we process ? */
   1887  1.5  christos 
   1888  1.5  christos     if (!ND_TTEST2(*tptr, NODE_ID_LEN))
   1889  1.1  christos         return(0);
   1890  1.1  christos 
   1891  1.5  christos     ND_PRINT((ndo, "%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN)));
   1892  1.1  christos     tptr+=(NODE_ID_LEN);
   1893  1.1  christos 
   1894  1.1  christos     if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
   1895  1.5  christos         if (!ND_TTEST2(*tptr, 3))    /* and is therefore skipped */
   1896  1.1  christos 	    return(0);
   1897  1.5  christos 	ND_PRINT((ndo, ", Metric: %d", EXTRACT_24BITS(tptr)));
   1898  1.1  christos 	tptr+=3;
   1899  1.1  christos     }
   1900  1.5  christos 
   1901  1.5  christos     if (!ND_TTEST2(*tptr, 1))
   1902  1.1  christos         return(0);
   1903  1.1  christos     subtlv_sum_len=*(tptr++); /* read out subTLV length */
   1904  1.1  christos     proc_bytes=NODE_ID_LEN+3+1;
   1905  1.5  christos     ND_PRINT((ndo, ", %ssub-TLVs present",subtlv_sum_len ? "" : "no "));
   1906  1.1  christos     if (subtlv_sum_len) {
   1907  1.5  christos         ND_PRINT((ndo, " (%u)", subtlv_sum_len));
   1908  1.1  christos         while (subtlv_sum_len>0) {
   1909  1.5  christos             if (!ND_TTEST2(*tptr,2))
   1910  1.1  christos                 return(0);
   1911  1.1  christos             subtlv_type=*(tptr++);
   1912  1.1  christos             subtlv_len=*(tptr++);
   1913  1.7  christos             /* prepend the indent string */
   1914  1.1  christos             snprintf(ident_buffer, sizeof(ident_buffer), "%s  ",ident);
   1915  1.5  christos             if (!isis_print_is_reach_subtlv(ndo, tptr, subtlv_type, subtlv_len, ident_buffer))
   1916  1.1  christos                 return(0);
   1917  1.1  christos             tptr+=subtlv_len;
   1918  1.1  christos             subtlv_sum_len-=(subtlv_len+2);
   1919  1.1  christos             proc_bytes+=(subtlv_len+2);
   1920  1.1  christos         }
   1921  1.1  christos     }
   1922  1.1  christos     return(proc_bytes);
   1923  1.1  christos }
   1924  1.1  christos 
   1925  1.1  christos /*
   1926  1.1  christos  * this is the common Multi Topology ID decoder
   1927  1.1  christos  * it is called from various MT-TLVs (222,229,235,237)
   1928  1.1  christos  */
   1929  1.1  christos 
   1930  1.1  christos static int
   1931  1.5  christos isis_print_mtid(netdissect_options *ndo,
   1932  1.6  christos                 const uint8_t *tptr, const char *ident)
   1933  1.6  christos {
   1934  1.5  christos     if (!ND_TTEST2(*tptr, 2))
   1935  1.1  christos         return(0);
   1936  1.1  christos 
   1937  1.5  christos     ND_PRINT((ndo, "%s%s",
   1938  1.1  christos            ident,
   1939  1.1  christos            tok2str(isis_mt_values,
   1940  1.1  christos                    "Reserved for IETF Consensus",
   1941  1.5  christos                    ISIS_MASK_MTID(EXTRACT_16BITS(tptr)))));
   1942  1.1  christos 
   1943  1.5  christos     ND_PRINT((ndo, " Topology (0x%03x), Flags: [%s]",
   1944  1.1  christos            ISIS_MASK_MTID(EXTRACT_16BITS(tptr)),
   1945  1.5  christos            bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr)))));
   1946  1.1  christos 
   1947  1.1  christos     return(2);
   1948  1.1  christos }
   1949  1.1  christos 
   1950  1.1  christos /*
   1951  1.1  christos  * this is the common extended IP reach decoder
   1952  1.1  christos  * it is called from TLVs (135,235,236,237)
   1953  1.1  christos  * we process the TLV and optional subTLVs and return
   1954  1.1  christos  * the amount of processed bytes
   1955  1.1  christos  */
   1956  1.1  christos 
   1957  1.1  christos static int
   1958  1.5  christos isis_print_extd_ip_reach(netdissect_options *ndo,
   1959  1.6  christos                          const uint8_t *tptr, const char *ident, uint16_t afi)
   1960  1.6  christos {
   1961  1.1  christos     char ident_buffer[20];
   1962  1.5  christos     uint8_t prefix[sizeof(struct in6_addr)]; /* shared copy buffer for IPv4 and IPv6 prefixes */
   1963  1.1  christos     u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
   1964  1.1  christos 
   1965  1.5  christos     if (!ND_TTEST2(*tptr, 4))
   1966  1.1  christos         return (0);
   1967  1.1  christos     metric = EXTRACT_32BITS(tptr);
   1968  1.1  christos     processed=4;
   1969  1.1  christos     tptr+=4;
   1970  1.5  christos 
   1971  1.1  christos     if (afi == AF_INET) {
   1972  1.5  christos         if (!ND_TTEST2(*tptr, 1)) /* fetch status byte */
   1973  1.1  christos             return (0);
   1974  1.1  christos         status_byte=*(tptr++);
   1975  1.1  christos         bit_length = status_byte&0x3f;
   1976  1.1  christos         if (bit_length > 32) {
   1977  1.5  christos             ND_PRINT((ndo, "%sIPv4 prefix: bad bit length %u",
   1978  1.1  christos                    ident,
   1979  1.5  christos                    bit_length));
   1980  1.1  christos             return (0);
   1981  1.1  christos         }
   1982  1.1  christos         processed++;
   1983  1.1  christos     } else if (afi == AF_INET6) {
   1984  1.5  christos         if (!ND_TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */
   1985  1.1  christos             return (0);
   1986  1.1  christos         status_byte=*(tptr++);
   1987  1.1  christos         bit_length=*(tptr++);
   1988  1.1  christos         if (bit_length > 128) {
   1989  1.5  christos             ND_PRINT((ndo, "%sIPv6 prefix: bad bit length %u",
   1990  1.1  christos                    ident,
   1991  1.5  christos                    bit_length));
   1992  1.1  christos             return (0);
   1993  1.1  christos         }
   1994  1.1  christos         processed+=2;
   1995  1.1  christos     } else
   1996  1.1  christos         return (0); /* somebody is fooling us */
   1997  1.1  christos 
   1998  1.1  christos     byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
   1999  1.5  christos 
   2000  1.5  christos     if (!ND_TTEST2(*tptr, byte_length))
   2001  1.1  christos         return (0);
   2002  1.1  christos     memset(prefix, 0, sizeof prefix);   /* clear the copy buffer */
   2003  1.1  christos     memcpy(prefix,tptr,byte_length);    /* copy as much as is stored in the TLV */
   2004  1.1  christos     tptr+=byte_length;
   2005  1.1  christos     processed+=byte_length;
   2006  1.1  christos 
   2007  1.1  christos     if (afi == AF_INET)
   2008  1.5  christos         ND_PRINT((ndo, "%sIPv4 prefix: %15s/%u",
   2009  1.1  christos                ident,
   2010  1.5  christos                ipaddr_string(ndo, prefix),
   2011  1.5  christos                bit_length));
   2012  1.7  christos     else if (afi == AF_INET6)
   2013  1.5  christos         ND_PRINT((ndo, "%sIPv6 prefix: %s/%u",
   2014  1.1  christos                ident,
   2015  1.5  christos                ip6addr_string(ndo, prefix),
   2016  1.5  christos                bit_length));
   2017  1.5  christos 
   2018  1.5  christos     ND_PRINT((ndo, ", Distribution: %s, Metric: %u",
   2019  1.1  christos            ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
   2020  1.5  christos            metric));
   2021  1.1  christos 
   2022  1.1  christos     if (afi == AF_INET && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
   2023  1.5  christos         ND_PRINT((ndo, ", sub-TLVs present"));
   2024  1.7  christos     else if (afi == AF_INET6)
   2025  1.5  christos         ND_PRINT((ndo, ", %s%s",
   2026  1.1  christos                ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
   2027  1.5  christos                ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : ""));
   2028  1.5  christos 
   2029  1.1  christos     if ((afi == AF_INET  && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
   2030  1.1  christos      || (afi == AF_INET6 && ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte))
   2031  1.1  christos 	) {
   2032  1.1  christos         /* assume that one prefix can hold more
   2033  1.1  christos            than one subTLV - therefore the first byte must reflect
   2034  1.1  christos            the aggregate bytecount of the subTLVs for this prefix
   2035  1.1  christos         */
   2036  1.5  christos         if (!ND_TTEST2(*tptr, 1))
   2037  1.1  christos             return (0);
   2038  1.1  christos         sublen=*(tptr++);
   2039  1.1  christos         processed+=sublen+1;
   2040  1.5  christos         ND_PRINT((ndo, " (%u)", sublen));   /* print out subTLV length */
   2041  1.5  christos 
   2042  1.1  christos         while (sublen>0) {
   2043  1.5  christos             if (!ND_TTEST2(*tptr,2))
   2044  1.1  christos                 return (0);
   2045  1.1  christos             subtlvtype=*(tptr++);
   2046  1.1  christos             subtlvlen=*(tptr++);
   2047  1.7  christos             /* prepend the indent string */
   2048  1.1  christos             snprintf(ident_buffer, sizeof(ident_buffer), "%s  ",ident);
   2049  1.5  christos             if (!isis_print_ip_reach_subtlv(ndo, tptr, subtlvtype, subtlvlen, ident_buffer))
   2050  1.1  christos                 return(0);
   2051  1.1  christos             tptr+=subtlvlen;
   2052  1.1  christos             sublen-=(subtlvlen+2);
   2053  1.1  christos         }
   2054  1.1  christos     }
   2055  1.1  christos     return (processed);
   2056  1.1  christos }
   2057  1.1  christos 
   2058  1.1  christos /*
   2059  1.7  christos  * Clear checksum and lifetime prior to signature verification.
   2060  1.7  christos  */
   2061  1.7  christos static void
   2062  1.7  christos isis_clear_checksum_lifetime(void *header)
   2063  1.7  christos {
   2064  1.7  christos     struct isis_lsp_header *header_lsp = (struct isis_lsp_header *) header;
   2065  1.7  christos 
   2066  1.7  christos     header_lsp->checksum[0] = 0;
   2067  1.7  christos     header_lsp->checksum[1] = 0;
   2068  1.7  christos     header_lsp->remaining_lifetime[0] = 0;
   2069  1.7  christos     header_lsp->remaining_lifetime[1] = 0;
   2070  1.7  christos }
   2071  1.7  christos 
   2072  1.7  christos /*
   2073  1.1  christos  * isis_print
   2074  1.1  christos  * Decode IS-IS packets.  Return 0 on error.
   2075  1.1  christos  */
   2076  1.1  christos 
   2077  1.5  christos static int
   2078  1.5  christos isis_print(netdissect_options *ndo,
   2079  1.5  christos            const uint8_t *p, u_int length)
   2080  1.1  christos {
   2081  1.1  christos     const struct isis_common_header *isis_header;
   2082  1.1  christos 
   2083  1.1  christos     const struct isis_iih_lan_header *header_iih_lan;
   2084  1.1  christos     const struct isis_iih_ptp_header *header_iih_ptp;
   2085  1.7  christos     const struct isis_lsp_header *header_lsp;
   2086  1.1  christos     const struct isis_csnp_header *header_csnp;
   2087  1.1  christos     const struct isis_psnp_header *header_psnp;
   2088  1.1  christos 
   2089  1.1  christos     const struct isis_tlv_lsp *tlv_lsp;
   2090  1.1  christos     const struct isis_tlv_ptp_adj *tlv_ptp_adj;
   2091  1.1  christos     const struct isis_tlv_is_reach *tlv_is_reach;
   2092  1.1  christos     const struct isis_tlv_es_reach *tlv_es_reach;
   2093  1.1  christos 
   2094  1.5  christos     uint8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len;
   2095  1.5  christos     uint8_t ext_is_len, ext_ip_len, mt_len;
   2096  1.5  christos     const uint8_t *optr, *pptr, *tptr;
   2097  1.3  christos     u_short packet_len,pdu_len, key_id;
   2098  1.1  christos     u_int i,vendor_id;
   2099  1.1  christos     int sigcheck;
   2100  1.1  christos 
   2101  1.1  christos     packet_len=length;
   2102  1.1  christos     optr = p; /* initialize the _o_riginal pointer to the packet start -
   2103  1.1  christos                  need it for parsing the checksum TLV and authentication
   2104  1.1  christos                  TLV verification */
   2105  1.1  christos     isis_header = (const struct isis_common_header *)p;
   2106  1.5  christos     ND_TCHECK(*isis_header);
   2107  1.1  christos     pptr = p+(ISIS_COMMON_HEADER_SIZE);
   2108  1.1  christos     header_iih_lan = (const struct isis_iih_lan_header *)pptr;
   2109  1.1  christos     header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;
   2110  1.7  christos     header_lsp = (const struct isis_lsp_header *)pptr;
   2111  1.1  christos     header_csnp = (const struct isis_csnp_header *)pptr;
   2112  1.1  christos     header_psnp = (const struct isis_psnp_header *)pptr;
   2113  1.1  christos 
   2114  1.5  christos     if (!ndo->ndo_eflag)
   2115  1.5  christos         ND_PRINT((ndo, "IS-IS"));
   2116  1.1  christos 
   2117  1.1  christos     /*
   2118  1.1  christos      * Sanity checking of the header.
   2119  1.1  christos      */
   2120  1.1  christos 
   2121  1.1  christos     if (isis_header->version != ISIS_VERSION) {
   2122  1.5  christos 	ND_PRINT((ndo, "version %d packet not supported", isis_header->version));
   2123  1.1  christos 	return (0);
   2124  1.1  christos     }
   2125  1.1  christos 
   2126  1.1  christos     if ((isis_header->id_length != SYSTEM_ID_LEN) && (isis_header->id_length != 0)) {
   2127  1.5  christos 	ND_PRINT((ndo, "system ID length of %d is not supported",
   2128  1.5  christos 	       isis_header->id_length));
   2129  1.1  christos 	return (0);
   2130  1.1  christos     }
   2131  1.1  christos 
   2132  1.1  christos     if (isis_header->pdu_version != ISIS_VERSION) {
   2133  1.5  christos 	ND_PRINT((ndo, "version %d packet not supported", isis_header->pdu_version));
   2134  1.1  christos 	return (0);
   2135  1.1  christos     }
   2136  1.1  christos 
   2137  1.1  christos     max_area = isis_header->max_area;
   2138  1.1  christos     switch(max_area) {
   2139  1.1  christos     case 0:
   2140  1.1  christos 	max_area = 3;	 /* silly shit */
   2141  1.1  christos 	break;
   2142  1.1  christos     case 255:
   2143  1.5  christos 	ND_PRINT((ndo, "bad packet -- 255 areas"));
   2144  1.1  christos 	return (0);
   2145  1.1  christos     default:
   2146  1.1  christos 	break;
   2147  1.1  christos     }
   2148  1.1  christos 
   2149  1.1  christos     id_length = isis_header->id_length;
   2150  1.1  christos     switch(id_length) {
   2151  1.1  christos     case 0:
   2152  1.1  christos         id_length = 6;	 /* silly shit again */
   2153  1.1  christos 	break;
   2154  1.1  christos     case 1:              /* 1-8 are valid sys-ID lenghts */
   2155  1.1  christos     case 2:
   2156  1.1  christos     case 3:
   2157  1.1  christos     case 4:
   2158  1.1  christos     case 5:
   2159  1.1  christos     case 6:
   2160  1.1  christos     case 7:
   2161  1.1  christos     case 8:
   2162  1.1  christos         break;
   2163  1.1  christos     case 255:
   2164  1.1  christos         id_length = 0;   /* entirely useless */
   2165  1.1  christos 	break;
   2166  1.1  christos     default:
   2167  1.1  christos         break;
   2168  1.1  christos     }
   2169  1.1  christos 
   2170  1.1  christos     /* toss any non 6-byte sys-ID len PDUs */
   2171  1.5  christos     if (id_length != 6 ) {
   2172  1.5  christos 	ND_PRINT((ndo, "bad packet -- illegal sys-ID length (%u)", id_length));
   2173  1.1  christos 	return (0);
   2174  1.1  christos     }
   2175  1.1  christos 
   2176  1.1  christos     pdu_type=isis_header->pdu_type;
   2177  1.1  christos 
   2178  1.1  christos     /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/
   2179  1.5  christos     if (ndo->ndo_vflag < 1) {
   2180  1.5  christos         ND_PRINT((ndo, "%s%s",
   2181  1.5  christos                ndo->ndo_eflag ? "" : ", ",
   2182  1.5  christos                tok2str(isis_pdu_values, "unknown PDU-Type %u", pdu_type)));
   2183  1.1  christos 
   2184  1.1  christos 	switch (pdu_type) {
   2185  1.1  christos 
   2186  1.1  christos 	case ISIS_PDU_L1_LAN_IIH:
   2187  1.1  christos 	case ISIS_PDU_L2_LAN_IIH:
   2188  1.7  christos 	    ND_TCHECK(*header_iih_lan);
   2189  1.5  christos 	    ND_PRINT((ndo, ", src-id %s",
   2190  1.5  christos                    isis_print_id(header_iih_lan->source_id, SYSTEM_ID_LEN)));
   2191  1.5  christos 	    ND_PRINT((ndo, ", lan-id %s, prio %u",
   2192  1.1  christos                    isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN),
   2193  1.5  christos                    header_iih_lan->priority));
   2194  1.1  christos 	    break;
   2195  1.1  christos 	case ISIS_PDU_PTP_IIH:
   2196  1.7  christos 	    ND_TCHECK(*header_iih_ptp);
   2197  1.5  christos 	    ND_PRINT((ndo, ", src-id %s", isis_print_id(header_iih_ptp->source_id, SYSTEM_ID_LEN)));
   2198  1.1  christos 	    break;
   2199  1.1  christos 	case ISIS_PDU_L1_LSP:
   2200  1.1  christos 	case ISIS_PDU_L2_LSP:
   2201  1.7  christos 	    ND_TCHECK(*header_lsp);
   2202  1.5  christos 	    ND_PRINT((ndo, ", lsp-id %s, seq 0x%08x, lifetime %5us",
   2203  1.1  christos 		   isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
   2204  1.1  christos 		   EXTRACT_32BITS(header_lsp->sequence_number),
   2205  1.5  christos 		   EXTRACT_16BITS(header_lsp->remaining_lifetime)));
   2206  1.1  christos 	    break;
   2207  1.1  christos 	case ISIS_PDU_L1_CSNP:
   2208  1.1  christos 	case ISIS_PDU_L2_CSNP:
   2209  1.7  christos 	    ND_TCHECK(*header_csnp);
   2210  1.5  christos 	    ND_PRINT((ndo, ", src-id %s", isis_print_id(header_csnp->source_id, NODE_ID_LEN)));
   2211  1.1  christos 	    break;
   2212  1.1  christos 	case ISIS_PDU_L1_PSNP:
   2213  1.1  christos 	case ISIS_PDU_L2_PSNP:
   2214  1.7  christos 	    ND_TCHECK(*header_psnp);
   2215  1.5  christos 	    ND_PRINT((ndo, ", src-id %s", isis_print_id(header_psnp->source_id, NODE_ID_LEN)));
   2216  1.1  christos 	    break;
   2217  1.1  christos 
   2218  1.1  christos 	}
   2219  1.5  christos 	ND_PRINT((ndo, ", length %u", length));
   2220  1.1  christos 
   2221  1.1  christos         return(1);
   2222  1.1  christos     }
   2223  1.1  christos 
   2224  1.1  christos     /* ok they seem to want to know everything - lets fully decode it */
   2225  1.5  christos     ND_PRINT((ndo, "%slength %u", ndo->ndo_eflag ? "" : ", ", length));
   2226  1.1  christos 
   2227  1.5  christos     ND_PRINT((ndo, "\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
   2228  1.1  christos            tok2str(isis_pdu_values,
   2229  1.1  christos                    "unknown, type %u",
   2230  1.1  christos                    pdu_type),
   2231  1.1  christos            isis_header->fixed_len,
   2232  1.1  christos            isis_header->version,
   2233  1.1  christos            isis_header->pdu_version,
   2234  1.1  christos 	   id_length,
   2235  1.1  christos 	   isis_header->id_length,
   2236  1.1  christos            max_area,
   2237  1.5  christos            isis_header->max_area));
   2238  1.1  christos 
   2239  1.5  christos     if (ndo->ndo_vflag > 1) {
   2240  1.5  christos         if (!print_unknown_data(ndo, optr, "\n\t", 8)) /* provide the _o_riginal pointer */
   2241  1.1  christos             return(0);                         /* for optionally debugging the common header */
   2242  1.1  christos     }
   2243  1.1  christos 
   2244  1.1  christos     switch (pdu_type) {
   2245  1.1  christos 
   2246  1.1  christos     case ISIS_PDU_L1_LAN_IIH:
   2247  1.1  christos     case ISIS_PDU_L2_LAN_IIH:
   2248  1.1  christos 	if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {
   2249  1.5  christos 	    ND_PRINT((ndo, ", bogus fixed header length %u should be %lu",
   2250  1.5  christos 		   isis_header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE));
   2251  1.1  christos 	    return (0);
   2252  1.1  christos 	}
   2253  1.1  christos 
   2254  1.7  christos 	ND_TCHECK(*header_iih_lan);
   2255  1.1  christos 	pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len);
   2256  1.1  christos 	if (packet_len>pdu_len) {
   2257  1.1  christos             packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
   2258  1.1  christos             length=pdu_len;
   2259  1.1  christos 	}
   2260  1.1  christos 
   2261  1.5  christos 	ND_PRINT((ndo, "\n\t  source-id: %s,  holding time: %us, Flags: [%s]",
   2262  1.1  christos                isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN),
   2263  1.1  christos                EXTRACT_16BITS(header_iih_lan->holding_time),
   2264  1.1  christos                tok2str(isis_iih_circuit_type_values,
   2265  1.1  christos                        "unknown circuit type 0x%02x",
   2266  1.5  christos                        header_iih_lan->circuit_type)));
   2267  1.1  christos 
   2268  1.5  christos 	ND_PRINT((ndo, "\n\t  lan-id:    %s, Priority: %u, PDU length: %u",
   2269  1.1  christos                isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN),
   2270  1.1  christos                (header_iih_lan->priority) & ISIS_LAN_PRIORITY_MASK,
   2271  1.5  christos                pdu_len));
   2272  1.1  christos 
   2273  1.5  christos 	if (ndo->ndo_vflag > 1) {
   2274  1.5  christos 		if (!print_unknown_data(ndo, pptr, "\n\t  ", ISIS_IIH_LAN_HEADER_SIZE))
   2275  1.5  christos 			return(0);
   2276  1.5  christos 	}
   2277  1.1  christos 
   2278  1.1  christos 	packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
   2279  1.1  christos 	pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
   2280  1.1  christos 	break;
   2281  1.1  christos 
   2282  1.1  christos     case ISIS_PDU_PTP_IIH:
   2283  1.1  christos 	if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) {
   2284  1.5  christos 	    ND_PRINT((ndo, ", bogus fixed header length %u should be %lu",
   2285  1.5  christos 		   isis_header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE));
   2286  1.1  christos 	    return (0);
   2287  1.1  christos 	}
   2288  1.1  christos 
   2289  1.7  christos 	ND_TCHECK(*header_iih_ptp);
   2290  1.1  christos 	pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len);
   2291  1.1  christos 	if (packet_len>pdu_len) {
   2292  1.1  christos             packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
   2293  1.1  christos             length=pdu_len;
   2294  1.1  christos 	}
   2295  1.1  christos 
   2296  1.5  christos 	ND_PRINT((ndo, "\n\t  source-id: %s, holding time: %us, Flags: [%s]",
   2297  1.1  christos                isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN),
   2298  1.1  christos                EXTRACT_16BITS(header_iih_ptp->holding_time),
   2299  1.1  christos                tok2str(isis_iih_circuit_type_values,
   2300  1.1  christos                        "unknown circuit type 0x%02x",
   2301  1.5  christos                        header_iih_ptp->circuit_type)));
   2302  1.1  christos 
   2303  1.5  christos 	ND_PRINT((ndo, "\n\t  circuit-id: 0x%02x, PDU length: %u",
   2304  1.1  christos                header_iih_ptp->circuit_id,
   2305  1.5  christos                pdu_len));
   2306  1.1  christos 
   2307  1.5  christos 	if (ndo->ndo_vflag > 1) {
   2308  1.5  christos 		if (!print_unknown_data(ndo, pptr, "\n\t  ", ISIS_IIH_PTP_HEADER_SIZE))
   2309  1.5  christos 			return(0);
   2310  1.5  christos 	}
   2311  1.1  christos 
   2312  1.1  christos 	packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
   2313  1.1  christos 	pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
   2314  1.1  christos 	break;
   2315  1.1  christos 
   2316  1.1  christos     case ISIS_PDU_L1_LSP:
   2317  1.1  christos     case ISIS_PDU_L2_LSP:
   2318  1.1  christos 	if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) {
   2319  1.5  christos 	    ND_PRINT((ndo, ", bogus fixed header length %u should be %lu",
   2320  1.5  christos 		   isis_header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE));
   2321  1.1  christos 	    return (0);
   2322  1.1  christos 	}
   2323  1.1  christos 
   2324  1.7  christos 	ND_TCHECK(*header_lsp);
   2325  1.1  christos 	pdu_len=EXTRACT_16BITS(header_lsp->pdu_len);
   2326  1.1  christos 	if (packet_len>pdu_len) {
   2327  1.1  christos             packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
   2328  1.1  christos             length=pdu_len;
   2329  1.1  christos 	}
   2330  1.1  christos 
   2331  1.5  christos 	ND_PRINT((ndo, "\n\t  lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t  chksum: 0x%04x",
   2332  1.1  christos                isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
   2333  1.1  christos                EXTRACT_32BITS(header_lsp->sequence_number),
   2334  1.1  christos                EXTRACT_16BITS(header_lsp->remaining_lifetime),
   2335  1.5  christos                EXTRACT_16BITS(header_lsp->checksum)));
   2336  1.1  christos 
   2337  1.7  christos         if (osi_print_cksum(ndo, (const uint8_t *)header_lsp->lsp_id,
   2338  1.7  christos                             EXTRACT_16BITS(header_lsp->checksum),
   2339  1.7  christos                             12, length-12) == 0)
   2340  1.7  christos                                 goto trunc;
   2341  1.5  christos 
   2342  1.5  christos 	ND_PRINT((ndo, ", PDU length: %u, Flags: [ %s",
   2343  1.1  christos                pdu_len,
   2344  1.5  christos                ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : ""));
   2345  1.1  christos 
   2346  1.1  christos 	if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) {
   2347  1.5  christos 	    ND_PRINT((ndo, "%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : ""));
   2348  1.5  christos 	    ND_PRINT((ndo, "%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : ""));
   2349  1.5  christos 	    ND_PRINT((ndo, "%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : ""));
   2350  1.5  christos 	    ND_PRINT((ndo, "%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : ""));
   2351  1.5  christos 	    ND_PRINT((ndo, "ATT bit set, "));
   2352  1.5  christos 	}
   2353  1.5  christos 	ND_PRINT((ndo, "%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : ""));
   2354  1.5  christos 	ND_PRINT((ndo, "%s ]", tok2str(isis_lsp_istype_values, "Unknown(0x%x)",
   2355  1.5  christos 	          ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock))));
   2356  1.5  christos 
   2357  1.5  christos 	if (ndo->ndo_vflag > 1) {
   2358  1.5  christos 		if (!print_unknown_data(ndo, pptr, "\n\t  ", ISIS_LSP_HEADER_SIZE))
   2359  1.5  christos 			return(0);
   2360  1.1  christos 	}
   2361  1.1  christos 
   2362  1.1  christos 	packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
   2363  1.1  christos 	pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
   2364  1.1  christos 	break;
   2365  1.1  christos 
   2366  1.1  christos     case ISIS_PDU_L1_CSNP:
   2367  1.1  christos     case ISIS_PDU_L2_CSNP:
   2368  1.1  christos 	if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) {
   2369  1.5  christos 	    ND_PRINT((ndo, ", bogus fixed header length %u should be %lu",
   2370  1.5  christos 		   isis_header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE));
   2371  1.1  christos 	    return (0);
   2372  1.1  christos 	}
   2373  1.1  christos 
   2374  1.7  christos 	ND_TCHECK(*header_csnp);
   2375  1.1  christos 	pdu_len=EXTRACT_16BITS(header_csnp->pdu_len);
   2376  1.1  christos 	if (packet_len>pdu_len) {
   2377  1.1  christos             packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
   2378  1.1  christos             length=pdu_len;
   2379  1.1  christos 	}
   2380  1.1  christos 
   2381  1.5  christos 	ND_PRINT((ndo, "\n\t  source-id:    %s, PDU length: %u",
   2382  1.1  christos                isis_print_id(header_csnp->source_id, NODE_ID_LEN),
   2383  1.5  christos                pdu_len));
   2384  1.5  christos 	ND_PRINT((ndo, "\n\t  start lsp-id: %s",
   2385  1.5  christos                isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN)));
   2386  1.5  christos 	ND_PRINT((ndo, "\n\t  end lsp-id:   %s",
   2387  1.5  christos                isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN)));
   2388  1.5  christos 
   2389  1.5  christos 	if (ndo->ndo_vflag > 1) {
   2390  1.5  christos 		if (!print_unknown_data(ndo, pptr, "\n\t  ", ISIS_CSNP_HEADER_SIZE))
   2391  1.5  christos 			return(0);
   2392  1.5  christos 	}
   2393  1.1  christos 
   2394  1.1  christos 	packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
   2395  1.1  christos 	pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
   2396  1.1  christos         break;
   2397  1.1  christos 
   2398  1.1  christos     case ISIS_PDU_L1_PSNP:
   2399  1.1  christos     case ISIS_PDU_L2_PSNP:
   2400  1.1  christos 	if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) {
   2401  1.5  christos 	    ND_PRINT((ndo, "- bogus fixed header length %u should be %lu",
   2402  1.5  christos 		   isis_header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE));
   2403  1.1  christos 	    return (0);
   2404  1.1  christos 	}
   2405  1.1  christos 
   2406  1.7  christos 	ND_TCHECK(*header_psnp);
   2407  1.1  christos 	pdu_len=EXTRACT_16BITS(header_psnp->pdu_len);
   2408  1.1  christos 	if (packet_len>pdu_len) {
   2409  1.1  christos             packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
   2410  1.1  christos             length=pdu_len;
   2411  1.1  christos 	}
   2412  1.1  christos 
   2413  1.5  christos 	ND_PRINT((ndo, "\n\t  source-id:    %s, PDU length: %u",
   2414  1.1  christos                isis_print_id(header_psnp->source_id, NODE_ID_LEN),
   2415  1.5  christos                pdu_len));
   2416  1.1  christos 
   2417  1.5  christos 	if (ndo->ndo_vflag > 1) {
   2418  1.5  christos 		if (!print_unknown_data(ndo, pptr, "\n\t  ", ISIS_PSNP_HEADER_SIZE))
   2419  1.5  christos 			return(0);
   2420  1.5  christos 	}
   2421  1.1  christos 
   2422  1.1  christos 	packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
   2423  1.1  christos 	pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
   2424  1.1  christos 	break;
   2425  1.1  christos 
   2426  1.1  christos     default:
   2427  1.6  christos 	(void)print_unknown_data(ndo, pptr, "\n\t  ", length);
   2428  1.1  christos 	return (0);
   2429  1.1  christos     }
   2430  1.1  christos 
   2431  1.1  christos     /*
   2432  1.1  christos      * Now print the TLV's.
   2433  1.1  christos      */
   2434  1.1  christos 
   2435  1.1  christos     while (packet_len >= 2) {
   2436  1.5  christos         if (pptr == ndo->ndo_snapend) {
   2437  1.5  christos             return (1);
   2438  1.1  christos         }
   2439  1.1  christos 
   2440  1.7  christos 	ND_TCHECK2(*pptr, 2);
   2441  1.1  christos 	tlv_type = *pptr++;
   2442  1.1  christos 	tlv_len = *pptr++;
   2443  1.1  christos         tmp =tlv_len; /* copy temporary len & pointer to packet data */
   2444  1.1  christos         tptr = pptr;
   2445  1.1  christos 	packet_len -= 2;
   2446  1.1  christos 	if (tlv_len > packet_len) {
   2447  1.1  christos 	    break;
   2448  1.1  christos 	}
   2449  1.1  christos 
   2450  1.1  christos         /* first lets see if we know the TLVs name*/
   2451  1.5  christos 	ND_PRINT((ndo, "\n\t    %s TLV #%u, length: %u",
   2452  1.1  christos                tok2str(isis_tlv_values,
   2453  1.1  christos                        "unknown",
   2454  1.1  christos                        tlv_type),
   2455  1.1  christos                tlv_type,
   2456  1.5  christos                tlv_len));
   2457  1.1  christos 
   2458  1.7  christos         if (tlv_len == 0) /* something is invalid */
   2459  1.1  christos 	    continue;
   2460  1.1  christos 
   2461  1.1  christos         /* now check if we have a decoder otherwise do a hexdump at the end*/
   2462  1.1  christos 	switch (tlv_type) {
   2463  1.1  christos 	case ISIS_TLV_AREA_ADDR:
   2464  1.5  christos 	    if (!ND_TTEST2(*tptr, 1))
   2465  1.1  christos 		goto trunctlv;
   2466  1.1  christos 	    alen = *tptr++;
   2467  1.1  christos 	    while (tmp && alen < tmp) {
   2468  1.5  christos 		ND_PRINT((ndo, "\n\t      Area address (length: %u): %s",
   2469  1.1  christos                        alen,
   2470  1.7  christos                        isonsap_string(ndo, tptr, alen)));
   2471  1.1  christos 		tptr += alen;
   2472  1.1  christos 		tmp -= alen + 1;
   2473  1.1  christos 		if (tmp==0) /* if this is the last area address do not attemt a boundary check */
   2474  1.1  christos                     break;
   2475  1.5  christos 		if (!ND_TTEST2(*tptr, 1))
   2476  1.1  christos 		    goto trunctlv;
   2477  1.1  christos 		alen = *tptr++;
   2478  1.1  christos 	    }
   2479  1.1  christos 	    break;
   2480  1.1  christos 	case ISIS_TLV_ISNEIGH:
   2481  1.1  christos 	    while (tmp >= ETHER_ADDR_LEN) {
   2482  1.5  christos                 if (!ND_TTEST2(*tptr, ETHER_ADDR_LEN))
   2483  1.1  christos                     goto trunctlv;
   2484  1.5  christos                 ND_PRINT((ndo, "\n\t      SNPA: %s", isis_print_id(tptr, ETHER_ADDR_LEN)));
   2485  1.1  christos                 tmp -= ETHER_ADDR_LEN;
   2486  1.1  christos                 tptr += ETHER_ADDR_LEN;
   2487  1.1  christos 	    }
   2488  1.1  christos 	    break;
   2489  1.1  christos 
   2490  1.1  christos         case ISIS_TLV_ISNEIGH_VARLEN:
   2491  1.5  christos             if (!ND_TTEST2(*tptr, 1) || tmp < 3) /* min. TLV length */
   2492  1.1  christos 		goto trunctlv;
   2493  1.1  christos 	    lan_alen = *tptr++; /* LAN address length */
   2494  1.1  christos 	    if (lan_alen == 0) {
   2495  1.5  christos                 ND_PRINT((ndo, "\n\t      LAN address length 0 bytes (invalid)"));
   2496  1.1  christos                 break;
   2497  1.1  christos             }
   2498  1.1  christos             tmp --;
   2499  1.5  christos             ND_PRINT((ndo, "\n\t      LAN address length %u bytes ", lan_alen));
   2500  1.1  christos 	    while (tmp >= lan_alen) {
   2501  1.5  christos                 if (!ND_TTEST2(*tptr, lan_alen))
   2502  1.1  christos                     goto trunctlv;
   2503  1.5  christos                 ND_PRINT((ndo, "\n\t\tIS Neighbor: %s", isis_print_id(tptr, lan_alen)));
   2504  1.1  christos                 tmp -= lan_alen;
   2505  1.1  christos                 tptr +=lan_alen;
   2506  1.1  christos             }
   2507  1.1  christos             break;
   2508  1.1  christos 
   2509  1.1  christos 	case ISIS_TLV_PADDING:
   2510  1.1  christos 	    break;
   2511  1.1  christos 
   2512  1.1  christos         case ISIS_TLV_MT_IS_REACH:
   2513  1.5  christos             mt_len = isis_print_mtid(ndo, tptr, "\n\t      ");
   2514  1.1  christos             if (mt_len == 0) /* did something go wrong ? */
   2515  1.1  christos                 goto trunctlv;
   2516  1.1  christos             tptr+=mt_len;
   2517  1.1  christos             tmp-=mt_len;
   2518  1.1  christos             while (tmp >= 2+NODE_ID_LEN+3+1) {
   2519  1.5  christos                 ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t      ", tlv_type);
   2520  1.1  christos                 if (ext_is_len == 0) /* did something go wrong ? */
   2521  1.1  christos                     goto trunctlv;
   2522  1.5  christos 
   2523  1.1  christos                 tmp-=ext_is_len;
   2524  1.1  christos                 tptr+=ext_is_len;
   2525  1.1  christos             }
   2526  1.1  christos             break;
   2527  1.1  christos 
   2528  1.1  christos         case ISIS_TLV_IS_ALIAS_ID:
   2529  1.1  christos 	    while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */
   2530  1.5  christos 	        ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t      ", tlv_type);
   2531  1.1  christos 		if (ext_is_len == 0) /* did something go wrong ? */
   2532  1.1  christos 	            goto trunctlv;
   2533  1.1  christos 		tmp-=ext_is_len;
   2534  1.1  christos 		tptr+=ext_is_len;
   2535  1.1  christos 	    }
   2536  1.1  christos 	    break;
   2537  1.1  christos 
   2538  1.1  christos         case ISIS_TLV_EXT_IS_REACH:
   2539  1.1  christos             while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */
   2540  1.5  christos                 ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t      ", tlv_type);
   2541  1.1  christos                 if (ext_is_len == 0) /* did something go wrong ? */
   2542  1.5  christos                     goto trunctlv;
   2543  1.1  christos                 tmp-=ext_is_len;
   2544  1.1  christos                 tptr+=ext_is_len;
   2545  1.1  christos             }
   2546  1.1  christos             break;
   2547  1.1  christos         case ISIS_TLV_IS_REACH:
   2548  1.5  christos 	    if (!ND_TTEST2(*tptr,1))  /* check if there is one byte left to read out the virtual flag */
   2549  1.1  christos                 goto trunctlv;
   2550  1.5  christos             ND_PRINT((ndo, "\n\t      %s",
   2551  1.1  christos                    tok2str(isis_is_reach_virtual_values,
   2552  1.1  christos                            "bogus virtual flag 0x%02x",
   2553  1.5  christos                            *tptr++)));
   2554  1.1  christos 	    tlv_is_reach = (const struct isis_tlv_is_reach *)tptr;
   2555  1.1  christos             while (tmp >= sizeof(struct isis_tlv_is_reach)) {
   2556  1.5  christos 		if (!ND_TTEST(*tlv_is_reach))
   2557  1.1  christos 		    goto trunctlv;
   2558  1.5  christos 		ND_PRINT((ndo, "\n\t      IS Neighbor: %s",
   2559  1.5  christos 		       isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN)));
   2560  1.5  christos 		isis_print_metric_block(ndo, &tlv_is_reach->isis_metric_block);
   2561  1.1  christos 		tmp -= sizeof(struct isis_tlv_is_reach);
   2562  1.1  christos 		tlv_is_reach++;
   2563  1.1  christos 	    }
   2564  1.1  christos             break;
   2565  1.1  christos 
   2566  1.1  christos         case ISIS_TLV_ESNEIGH:
   2567  1.1  christos 	    tlv_es_reach = (const struct isis_tlv_es_reach *)tptr;
   2568  1.1  christos             while (tmp >= sizeof(struct isis_tlv_es_reach)) {
   2569  1.5  christos 		if (!ND_TTEST(*tlv_es_reach))
   2570  1.1  christos 		    goto trunctlv;
   2571  1.5  christos 		ND_PRINT((ndo, "\n\t      ES Neighbor: %s",
   2572  1.5  christos                        isis_print_id(tlv_es_reach->neighbor_sysid, SYSTEM_ID_LEN)));
   2573  1.5  christos 		isis_print_metric_block(ndo, &tlv_es_reach->isis_metric_block);
   2574  1.1  christos 		tmp -= sizeof(struct isis_tlv_es_reach);
   2575  1.1  christos 		tlv_es_reach++;
   2576  1.1  christos 	    }
   2577  1.1  christos             break;
   2578  1.1  christos 
   2579  1.1  christos             /* those two TLVs share the same format */
   2580  1.1  christos 	case ISIS_TLV_INT_IP_REACH:
   2581  1.1  christos 	case ISIS_TLV_EXT_IP_REACH:
   2582  1.5  christos 		if (!isis_print_tlv_ip_reach(ndo, pptr, "\n\t      ", tlv_len))
   2583  1.5  christos 			return (1);
   2584  1.5  christos 		break;
   2585  1.1  christos 
   2586  1.1  christos 	case ISIS_TLV_EXTD_IP_REACH:
   2587  1.1  christos 	    while (tmp>0) {
   2588  1.5  christos                 ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t      ", AF_INET);
   2589  1.1  christos                 if (ext_ip_len == 0) /* did something go wrong ? */
   2590  1.1  christos                     goto trunctlv;
   2591  1.1  christos                 tptr+=ext_ip_len;
   2592  1.1  christos 		tmp-=ext_ip_len;
   2593  1.1  christos 	    }
   2594  1.1  christos 	    break;
   2595  1.1  christos 
   2596  1.1  christos         case ISIS_TLV_MT_IP_REACH:
   2597  1.5  christos             mt_len = isis_print_mtid(ndo, tptr, "\n\t      ");
   2598  1.1  christos             if (mt_len == 0) { /* did something go wrong ? */
   2599  1.1  christos                 goto trunctlv;
   2600  1.1  christos             }
   2601  1.1  christos             tptr+=mt_len;
   2602  1.1  christos             tmp-=mt_len;
   2603  1.1  christos 
   2604  1.1  christos             while (tmp>0) {
   2605  1.5  christos                 ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t      ", AF_INET);
   2606  1.1  christos                 if (ext_ip_len == 0) /* did something go wrong ? */
   2607  1.1  christos                     goto trunctlv;
   2608  1.1  christos                 tptr+=ext_ip_len;
   2609  1.1  christos 		tmp-=ext_ip_len;
   2610  1.1  christos 	    }
   2611  1.1  christos 	    break;
   2612  1.1  christos 
   2613  1.1  christos 	case ISIS_TLV_IP6_REACH:
   2614  1.1  christos 	    while (tmp>0) {
   2615  1.5  christos                 ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t      ", AF_INET6);
   2616  1.1  christos                 if (ext_ip_len == 0) /* did something go wrong ? */
   2617  1.1  christos                     goto trunctlv;
   2618  1.1  christos                 tptr+=ext_ip_len;
   2619  1.1  christos 		tmp-=ext_ip_len;
   2620  1.1  christos 	    }
   2621  1.1  christos 	    break;
   2622  1.1  christos 
   2623  1.1  christos 	case ISIS_TLV_MT_IP6_REACH:
   2624  1.5  christos             mt_len = isis_print_mtid(ndo, tptr, "\n\t      ");
   2625  1.1  christos             if (mt_len == 0) { /* did something go wrong ? */
   2626  1.1  christos                 goto trunctlv;
   2627  1.1  christos             }
   2628  1.1  christos             tptr+=mt_len;
   2629  1.1  christos             tmp-=mt_len;
   2630  1.1  christos 
   2631  1.1  christos 	    while (tmp>0) {
   2632  1.5  christos                 ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t      ", AF_INET6);
   2633  1.1  christos                 if (ext_ip_len == 0) /* did something go wrong ? */
   2634  1.1  christos                     goto trunctlv;
   2635  1.1  christos                 tptr+=ext_ip_len;
   2636  1.1  christos 		tmp-=ext_ip_len;
   2637  1.1  christos 	    }
   2638  1.1  christos 	    break;
   2639  1.1  christos 
   2640  1.1  christos 	case ISIS_TLV_IP6ADDR:
   2641  1.1  christos 	    while (tmp>=sizeof(struct in6_addr)) {
   2642  1.5  christos 		if (!ND_TTEST2(*tptr, sizeof(struct in6_addr)))
   2643  1.1  christos 		    goto trunctlv;
   2644  1.1  christos 
   2645  1.5  christos                 ND_PRINT((ndo, "\n\t      IPv6 interface address: %s",
   2646  1.5  christos 		       ip6addr_string(ndo, tptr)));
   2647  1.1  christos 
   2648  1.1  christos 		tptr += sizeof(struct in6_addr);
   2649  1.1  christos 		tmp -= sizeof(struct in6_addr);
   2650  1.1  christos 	    }
   2651  1.1  christos 	    break;
   2652  1.1  christos 	case ISIS_TLV_AUTH:
   2653  1.5  christos 	    if (!ND_TTEST2(*tptr, 1))
   2654  1.1  christos 		goto trunctlv;
   2655  1.1  christos 
   2656  1.5  christos             ND_PRINT((ndo, "\n\t      %s: ",
   2657  1.1  christos                    tok2str(isis_subtlv_auth_values,
   2658  1.1  christos                            "unknown Authentication type 0x%02x",
   2659  1.5  christos                            *tptr)));
   2660  1.1  christos 
   2661  1.1  christos 	    switch (*tptr) {
   2662  1.1  christos 	    case ISIS_SUBTLV_AUTH_SIMPLE:
   2663  1.7  christos 		if (fn_printzp(ndo, tptr + 1, tlv_len - 1, ndo->ndo_snapend))
   2664  1.7  christos 		    goto trunctlv;
   2665  1.1  christos 		break;
   2666  1.1  christos 	    case ISIS_SUBTLV_AUTH_MD5:
   2667  1.1  christos 		for(i=1;i<tlv_len;i++) {
   2668  1.5  christos 		    if (!ND_TTEST2(*(tptr + i), 1))
   2669  1.1  christos 			goto trunctlv;
   2670  1.5  christos 		    ND_PRINT((ndo, "%02x", *(tptr + i)));
   2671  1.1  christos 		}
   2672  1.1  christos 		if (tlv_len != ISIS_SUBTLV_AUTH_MD5_LEN+1)
   2673  1.7  christos                     ND_PRINT((ndo, ", (invalid subTLV) "));
   2674  1.1  christos 
   2675  1.7  christos                 sigcheck = signature_verify(ndo, optr, length, tptr + 1,
   2676  1.7  christos                                             isis_clear_checksum_lifetime,
   2677  1.7  christos                                             header_lsp);
   2678  1.5  christos                 ND_PRINT((ndo, " (%s)", tok2str(signature_check_values, "Unknown", sigcheck)));
   2679  1.1  christos 
   2680  1.1  christos 		break;
   2681  1.3  christos             case ISIS_SUBTLV_AUTH_GENERIC:
   2682  1.7  christos 		ND_TCHECK2(*(tptr + 1), 2);
   2683  1.3  christos                 key_id = EXTRACT_16BITS((tptr+1));
   2684  1.5  christos                 ND_PRINT((ndo, "%u, password: ", key_id));
   2685  1.5  christos                 for(i=1 + sizeof(uint16_t);i<tlv_len;i++) {
   2686  1.5  christos                     if (!ND_TTEST2(*(tptr + i), 1))
   2687  1.3  christos                         goto trunctlv;
   2688  1.5  christos                     ND_PRINT((ndo, "%02x", *(tptr + i)));
   2689  1.3  christos                 }
   2690  1.3  christos                 break;
   2691  1.1  christos 	    case ISIS_SUBTLV_AUTH_PRIVATE:
   2692  1.1  christos 	    default:
   2693  1.5  christos 		if (!print_unknown_data(ndo, tptr + 1, "\n\t\t  ", tlv_len - 1))
   2694  1.1  christos 		    return(0);
   2695  1.1  christos 		break;
   2696  1.1  christos 	    }
   2697  1.1  christos 	    break;
   2698  1.1  christos 
   2699  1.1  christos 	case ISIS_TLV_PTP_ADJ:
   2700  1.1  christos 	    tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr;
   2701  1.1  christos 	    if(tmp>=1) {
   2702  1.5  christos 		if (!ND_TTEST2(*tptr, 1))
   2703  1.1  christos 		    goto trunctlv;
   2704  1.5  christos 		ND_PRINT((ndo, "\n\t      Adjacency State: %s (%u)",
   2705  1.1  christos 		       tok2str(isis_ptp_adjancey_values, "unknown", *tptr),
   2706  1.5  christos                         *tptr));
   2707  1.1  christos 		tmp--;
   2708  1.1  christos 	    }
   2709  1.1  christos 	    if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) {
   2710  1.5  christos 		if (!ND_TTEST2(tlv_ptp_adj->extd_local_circuit_id,
   2711  1.1  christos                             sizeof(tlv_ptp_adj->extd_local_circuit_id)))
   2712  1.1  christos 		    goto trunctlv;
   2713  1.5  christos 		ND_PRINT((ndo, "\n\t      Extended Local circuit-ID: 0x%08x",
   2714  1.5  christos 		       EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id)));
   2715  1.1  christos 		tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id);
   2716  1.1  christos 	    }
   2717  1.1  christos 	    if(tmp>=SYSTEM_ID_LEN) {
   2718  1.5  christos 		if (!ND_TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN))
   2719  1.1  christos 		    goto trunctlv;
   2720  1.5  christos 		ND_PRINT((ndo, "\n\t      Neighbor System-ID: %s",
   2721  1.5  christos 		       isis_print_id(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN)));
   2722  1.1  christos 		tmp-=SYSTEM_ID_LEN;
   2723  1.1  christos 	    }
   2724  1.1  christos 	    if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) {
   2725  1.5  christos 		if (!ND_TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id,
   2726  1.1  christos                             sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)))
   2727  1.1  christos 		    goto trunctlv;
   2728  1.5  christos 		ND_PRINT((ndo, "\n\t      Neighbor Extended Local circuit-ID: 0x%08x",
   2729  1.5  christos 		       EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id)));
   2730  1.1  christos 	    }
   2731  1.1  christos 	    break;
   2732  1.1  christos 
   2733  1.1  christos 	case ISIS_TLV_PROTOCOLS:
   2734  1.5  christos 	    ND_PRINT((ndo, "\n\t      NLPID(s): "));
   2735  1.1  christos 	    while (tmp>0) {
   2736  1.5  christos 		if (!ND_TTEST2(*(tptr), 1))
   2737  1.1  christos 		    goto trunctlv;
   2738  1.5  christos 		ND_PRINT((ndo, "%s (0x%02x)",
   2739  1.1  christos                        tok2str(nlpid_values,
   2740  1.1  christos                                "unknown",
   2741  1.1  christos                                *tptr),
   2742  1.5  christos                        *tptr));
   2743  1.1  christos 		if (tmp>1) /* further NPLIDs ? - put comma */
   2744  1.5  christos 		    ND_PRINT((ndo, ", "));
   2745  1.1  christos                 tptr++;
   2746  1.1  christos                 tmp--;
   2747  1.1  christos 	    }
   2748  1.1  christos 	    break;
   2749  1.1  christos 
   2750  1.4  christos     case ISIS_TLV_MT_PORT_CAP:
   2751  1.4  christos     {
   2752  1.5  christos       if (!ND_TTEST2(*(tptr), 2))
   2753  1.4  christos         goto trunctlv;
   2754  1.4  christos 
   2755  1.5  christos       ND_PRINT((ndo, "\n\t       RES: %d, MTID(s): %d",
   2756  1.5  christos               (EXTRACT_16BITS (tptr) >> 12),
   2757  1.5  christos               (EXTRACT_16BITS (tptr) & 0x0fff)));
   2758  1.4  christos 
   2759  1.4  christos       tmp = tmp-2;
   2760  1.4  christos       tptr = tptr+2;
   2761  1.4  christos 
   2762  1.4  christos       if (tmp)
   2763  1.5  christos         isis_print_mt_port_cap_subtlv(ndo, tptr, tmp);
   2764  1.4  christos 
   2765  1.4  christos       break;
   2766  1.4  christos     }
   2767  1.4  christos 
   2768  1.4  christos     case ISIS_TLV_MT_CAPABILITY:
   2769  1.4  christos 
   2770  1.5  christos       if (!ND_TTEST2(*(tptr), 2))
   2771  1.4  christos         goto trunctlv;
   2772  1.4  christos 
   2773  1.5  christos       ND_PRINT((ndo, "\n\t      O: %d, RES: %d, MTID(s): %d",
   2774  1.4  christos                 (EXTRACT_16BITS(tptr) >> 15) & 0x01,
   2775  1.4  christos                 (EXTRACT_16BITS(tptr) >> 12) & 0x07,
   2776  1.5  christos                 EXTRACT_16BITS(tptr) & 0x0fff));
   2777  1.4  christos 
   2778  1.4  christos       tmp = tmp-2;
   2779  1.4  christos       tptr = tptr+2;
   2780  1.4  christos 
   2781  1.4  christos       if (tmp)
   2782  1.5  christos         isis_print_mt_capability_subtlv(ndo, tptr, tmp);
   2783  1.4  christos 
   2784  1.4  christos       break;
   2785  1.4  christos 
   2786  1.1  christos 	case ISIS_TLV_TE_ROUTER_ID:
   2787  1.5  christos 	    if (!ND_TTEST2(*pptr, sizeof(struct in_addr)))
   2788  1.1  christos 		goto trunctlv;
   2789  1.5  christos 	    ND_PRINT((ndo, "\n\t      Traffic Engineering Router ID: %s", ipaddr_string(ndo, pptr)));
   2790  1.1  christos 	    break;
   2791  1.1  christos 
   2792  1.1  christos 	case ISIS_TLV_IPADDR:
   2793  1.1  christos 	    while (tmp>=sizeof(struct in_addr)) {
   2794  1.5  christos 		if (!ND_TTEST2(*tptr, sizeof(struct in_addr)))
   2795  1.1  christos 		    goto trunctlv;
   2796  1.5  christos 		ND_PRINT((ndo, "\n\t      IPv4 interface address: %s", ipaddr_string(ndo, tptr)));
   2797  1.1  christos 		tptr += sizeof(struct in_addr);
   2798  1.1  christos 		tmp -= sizeof(struct in_addr);
   2799  1.1  christos 	    }
   2800  1.1  christos 	    break;
   2801  1.1  christos 
   2802  1.1  christos 	case ISIS_TLV_HOSTNAME:
   2803  1.5  christos 	    ND_PRINT((ndo, "\n\t      Hostname: "));
   2804  1.7  christos 	    if (fn_printzp(ndo, tptr, tmp, ndo->ndo_snapend))
   2805  1.7  christos 		goto trunctlv;
   2806  1.1  christos 	    break;
   2807  1.1  christos 
   2808  1.1  christos 	case ISIS_TLV_SHARED_RISK_GROUP:
   2809  1.1  christos 	    if (tmp < NODE_ID_LEN)
   2810  1.1  christos 	        break;
   2811  1.5  christos 	    if (!ND_TTEST2(*tptr, NODE_ID_LEN))
   2812  1.1  christos                 goto trunctlv;
   2813  1.5  christos 	    ND_PRINT((ndo, "\n\t      IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN)));
   2814  1.1  christos 	    tptr+=(NODE_ID_LEN);
   2815  1.1  christos 	    tmp-=(NODE_ID_LEN);
   2816  1.1  christos 
   2817  1.1  christos 	    if (tmp < 1)
   2818  1.1  christos 	        break;
   2819  1.5  christos 	    if (!ND_TTEST2(*tptr, 1))
   2820  1.1  christos                 goto trunctlv;
   2821  1.5  christos 	    ND_PRINT((ndo, ", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered"));
   2822  1.1  christos 	    tmp--;
   2823  1.1  christos 
   2824  1.1  christos 	    if (tmp < sizeof(struct in_addr))
   2825  1.1  christos 	        break;
   2826  1.5  christos 	    if (!ND_TTEST2(*tptr, sizeof(struct in_addr)))
   2827  1.1  christos                 goto trunctlv;
   2828  1.5  christos 	    ND_PRINT((ndo, "\n\t      IPv4 interface address: %s", ipaddr_string(ndo, tptr)));
   2829  1.1  christos 	    tptr+=sizeof(struct in_addr);
   2830  1.1  christos 	    tmp-=sizeof(struct in_addr);
   2831  1.1  christos 
   2832  1.1  christos 	    if (tmp < sizeof(struct in_addr))
   2833  1.1  christos 	        break;
   2834  1.5  christos 	    if (!ND_TTEST2(*tptr, sizeof(struct in_addr)))
   2835  1.1  christos                 goto trunctlv;
   2836  1.5  christos 	    ND_PRINT((ndo, "\n\t      IPv4 neighbor address: %s", ipaddr_string(ndo, tptr)));
   2837  1.1  christos 	    tptr+=sizeof(struct in_addr);
   2838  1.1  christos 	    tmp-=sizeof(struct in_addr);
   2839  1.1  christos 
   2840  1.1  christos 	    while (tmp>=4) {
   2841  1.5  christos                 if (!ND_TTEST2(*tptr, 4))
   2842  1.1  christos                     goto trunctlv;
   2843  1.5  christos                 ND_PRINT((ndo, "\n\t      Link-ID: 0x%08x", EXTRACT_32BITS(tptr)));
   2844  1.1  christos                 tptr+=4;
   2845  1.1  christos                 tmp-=4;
   2846  1.1  christos 	    }
   2847  1.1  christos 	    break;
   2848  1.1  christos 
   2849  1.1  christos 	case ISIS_TLV_LSP:
   2850  1.1  christos 	    tlv_lsp = (const struct isis_tlv_lsp *)tptr;
   2851  1.1  christos 	    while(tmp>=sizeof(struct isis_tlv_lsp)) {
   2852  1.5  christos 		if (!ND_TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN-1]))
   2853  1.1  christos 		    goto trunctlv;
   2854  1.5  christos 		ND_PRINT((ndo, "\n\t      lsp-id: %s",
   2855  1.5  christos                        isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN)));
   2856  1.5  christos 		if (!ND_TTEST2(tlv_lsp->sequence_number, 4))
   2857  1.1  christos 		    goto trunctlv;
   2858  1.5  christos 		ND_PRINT((ndo, ", seq: 0x%08x", EXTRACT_32BITS(tlv_lsp->sequence_number)));
   2859  1.5  christos 		if (!ND_TTEST2(tlv_lsp->remaining_lifetime, 2))
   2860  1.1  christos 		    goto trunctlv;
   2861  1.5  christos 		ND_PRINT((ndo, ", lifetime: %5ds", EXTRACT_16BITS(tlv_lsp->remaining_lifetime)));
   2862  1.5  christos 		if (!ND_TTEST2(tlv_lsp->checksum, 2))
   2863  1.1  christos 		    goto trunctlv;
   2864  1.5  christos 		ND_PRINT((ndo, ", chksum: 0x%04x", EXTRACT_16BITS(tlv_lsp->checksum)));
   2865  1.1  christos 		tmp-=sizeof(struct isis_tlv_lsp);
   2866  1.1  christos 		tlv_lsp++;
   2867  1.1  christos 	    }
   2868  1.1  christos 	    break;
   2869  1.1  christos 
   2870  1.1  christos 	case ISIS_TLV_CHECKSUM:
   2871  1.1  christos 	    if (tmp < ISIS_TLV_CHECKSUM_MINLEN)
   2872  1.1  christos 	        break;
   2873  1.5  christos 	    if (!ND_TTEST2(*tptr, ISIS_TLV_CHECKSUM_MINLEN))
   2874  1.1  christos 		goto trunctlv;
   2875  1.5  christos 	    ND_PRINT((ndo, "\n\t      checksum: 0x%04x ", EXTRACT_16BITS(tptr)));
   2876  1.1  christos             /* do not attempt to verify the checksum if it is zero
   2877  1.1  christos              * most likely a HMAC-MD5 TLV is also present and
   2878  1.1  christos              * to avoid conflicts the checksum TLV is zeroed.
   2879  1.1  christos              * see rfc3358 for details
   2880  1.1  christos              */
   2881  1.7  christos             if (osi_print_cksum(ndo, optr, EXTRACT_16BITS(tptr), tptr-optr,
   2882  1.7  christos                 length) == 0)
   2883  1.7  christos                     goto trunc;
   2884  1.7  christos 	    break;
   2885  1.7  christos 
   2886  1.7  christos 	case ISIS_TLV_POI:
   2887  1.7  christos 	    if (tlv_len >= SYSTEM_ID_LEN + 1) {
   2888  1.7  christos 		if (!ND_TTEST2(*tptr, SYSTEM_ID_LEN + 1))
   2889  1.7  christos 		    goto trunctlv;
   2890  1.7  christos 		ND_PRINT((ndo, "\n\t      Purge Originator System-ID: %s",
   2891  1.7  christos 		       isis_print_id(tptr + 1, SYSTEM_ID_LEN)));
   2892  1.7  christos 	    }
   2893  1.7  christos 
   2894  1.7  christos 	    if (tlv_len == 2 * SYSTEM_ID_LEN + 1) {
   2895  1.7  christos 		if (!ND_TTEST2(*tptr, 2 * SYSTEM_ID_LEN + 1))
   2896  1.7  christos 		    goto trunctlv;
   2897  1.7  christos 		ND_PRINT((ndo, "\n\t      Received from System-ID: %s",
   2898  1.7  christos 		       isis_print_id(tptr + SYSTEM_ID_LEN + 1, SYSTEM_ID_LEN)));
   2899  1.7  christos 	    }
   2900  1.1  christos 	    break;
   2901  1.1  christos 
   2902  1.1  christos 	case ISIS_TLV_MT_SUPPORTED:
   2903  1.1  christos             if (tmp < ISIS_TLV_MT_SUPPORTED_MINLEN)
   2904  1.1  christos                 break;
   2905  1.1  christos 	    while (tmp>1) {
   2906  1.1  christos 		/* length can only be a multiple of 2, otherwise there is
   2907  1.1  christos 		   something broken -> so decode down until length is 1 */
   2908  1.1  christos 		if (tmp!=1) {
   2909  1.5  christos                     mt_len = isis_print_mtid(ndo, tptr, "\n\t      ");
   2910  1.1  christos                     if (mt_len == 0) /* did something go wrong ? */
   2911  1.1  christos                         goto trunctlv;
   2912  1.1  christos                     tptr+=mt_len;
   2913  1.1  christos                     tmp-=mt_len;
   2914  1.1  christos 		} else {
   2915  1.7  christos 		    ND_PRINT((ndo, "\n\t      invalid MT-ID"));
   2916  1.1  christos 		    break;
   2917  1.1  christos 		}
   2918  1.1  christos 	    }
   2919  1.1  christos 	    break;
   2920  1.1  christos 
   2921  1.1  christos 	case ISIS_TLV_RESTART_SIGNALING:
   2922  1.1  christos             /* first attempt to decode the flags */
   2923  1.1  christos             if (tmp < ISIS_TLV_RESTART_SIGNALING_FLAGLEN)
   2924  1.1  christos                 break;
   2925  1.5  christos             if (!ND_TTEST2(*tptr, ISIS_TLV_RESTART_SIGNALING_FLAGLEN))
   2926  1.1  christos                 goto trunctlv;
   2927  1.5  christos             ND_PRINT((ndo, "\n\t      Flags [%s]",
   2928  1.5  christos                    bittok2str(isis_restart_flag_values, "none", *tptr)));
   2929  1.1  christos             tptr+=ISIS_TLV_RESTART_SIGNALING_FLAGLEN;
   2930  1.1  christos             tmp-=ISIS_TLV_RESTART_SIGNALING_FLAGLEN;
   2931  1.1  christos 
   2932  1.1  christos             /* is there anything other than the flags field? */
   2933  1.1  christos             if (tmp == 0)
   2934  1.1  christos                 break;
   2935  1.1  christos 
   2936  1.1  christos             if (tmp < ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN)
   2937  1.1  christos                 break;
   2938  1.5  christos             if (!ND_TTEST2(*tptr, ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN))
   2939  1.1  christos                 goto trunctlv;
   2940  1.1  christos 
   2941  1.5  christos             ND_PRINT((ndo, ", Remaining holding time %us", EXTRACT_16BITS(tptr)));
   2942  1.1  christos             tptr+=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN;
   2943  1.1  christos             tmp-=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN;
   2944  1.1  christos 
   2945  1.1  christos             /* is there an additional sysid field present ?*/
   2946  1.1  christos             if (tmp == SYSTEM_ID_LEN) {
   2947  1.5  christos                     if (!ND_TTEST2(*tptr, SYSTEM_ID_LEN))
   2948  1.1  christos                             goto trunctlv;
   2949  1.5  christos                     ND_PRINT((ndo, ", for %s", isis_print_id(tptr,SYSTEM_ID_LEN)));
   2950  1.5  christos             }
   2951  1.1  christos 	    break;
   2952  1.1  christos 
   2953  1.1  christos         case ISIS_TLV_IDRP_INFO:
   2954  1.1  christos 	    if (tmp < ISIS_TLV_IDRP_INFO_MINLEN)
   2955  1.1  christos 	        break;
   2956  1.5  christos             if (!ND_TTEST2(*tptr, ISIS_TLV_IDRP_INFO_MINLEN))
   2957  1.1  christos                 goto trunctlv;
   2958  1.5  christos             ND_PRINT((ndo, "\n\t      Inter-Domain Information Type: %s",
   2959  1.1  christos                    tok2str(isis_subtlv_idrp_values,
   2960  1.1  christos                            "Unknown (0x%02x)",
   2961  1.5  christos                            *tptr)));
   2962  1.1  christos             switch (*tptr++) {
   2963  1.1  christos             case ISIS_SUBTLV_IDRP_ASN:
   2964  1.5  christos                 if (!ND_TTEST2(*tptr, 2)) /* fetch AS number */
   2965  1.1  christos                     goto trunctlv;
   2966  1.5  christos                 ND_PRINT((ndo, "AS Number: %u", EXTRACT_16BITS(tptr)));
   2967  1.1  christos                 break;
   2968  1.1  christos             case ISIS_SUBTLV_IDRP_LOCAL:
   2969  1.1  christos             case ISIS_SUBTLV_IDRP_RES:
   2970  1.1  christos             default:
   2971  1.5  christos                 if (!print_unknown_data(ndo, tptr, "\n\t      ", tlv_len - 1))
   2972  1.1  christos                     return(0);
   2973  1.1  christos                 break;
   2974  1.1  christos             }
   2975  1.1  christos             break;
   2976  1.1  christos 
   2977  1.1  christos         case ISIS_TLV_LSP_BUFFERSIZE:
   2978  1.1  christos 	    if (tmp < ISIS_TLV_LSP_BUFFERSIZE_MINLEN)
   2979  1.1  christos 	        break;
   2980  1.5  christos             if (!ND_TTEST2(*tptr, ISIS_TLV_LSP_BUFFERSIZE_MINLEN))
   2981  1.1  christos                 goto trunctlv;
   2982  1.5  christos             ND_PRINT((ndo, "\n\t      LSP Buffersize: %u", EXTRACT_16BITS(tptr)));
   2983  1.1  christos             break;
   2984  1.1  christos 
   2985  1.1  christos         case ISIS_TLV_PART_DIS:
   2986  1.1  christos             while (tmp >= SYSTEM_ID_LEN) {
   2987  1.5  christos                 if (!ND_TTEST2(*tptr, SYSTEM_ID_LEN))
   2988  1.1  christos                     goto trunctlv;
   2989  1.5  christos                 ND_PRINT((ndo, "\n\t      %s", isis_print_id(tptr, SYSTEM_ID_LEN)));
   2990  1.1  christos                 tptr+=SYSTEM_ID_LEN;
   2991  1.1  christos                 tmp-=SYSTEM_ID_LEN;
   2992  1.1  christos             }
   2993  1.1  christos             break;
   2994  1.1  christos 
   2995  1.1  christos         case ISIS_TLV_PREFIX_NEIGH:
   2996  1.1  christos 	    if (tmp < sizeof(struct isis_metric_block))
   2997  1.1  christos 	        break;
   2998  1.5  christos             if (!ND_TTEST2(*tptr, sizeof(struct isis_metric_block)))
   2999  1.1  christos                 goto trunctlv;
   3000  1.5  christos             ND_PRINT((ndo, "\n\t      Metric Block"));
   3001  1.5  christos             isis_print_metric_block(ndo, (const struct isis_metric_block *)tptr);
   3002  1.1  christos             tptr+=sizeof(struct isis_metric_block);
   3003  1.1  christos             tmp-=sizeof(struct isis_metric_block);
   3004  1.1  christos 
   3005  1.1  christos             while(tmp>0) {
   3006  1.5  christos                 if (!ND_TTEST2(*tptr, 1))
   3007  1.1  christos                     goto trunctlv;
   3008  1.1  christos                 prefix_len=*tptr++; /* read out prefix length in semioctets*/
   3009  1.1  christos                 if (prefix_len < 2) {
   3010  1.5  christos                     ND_PRINT((ndo, "\n\t\tAddress: prefix length %u < 2", prefix_len));
   3011  1.1  christos                     break;
   3012  1.1  christos                 }
   3013  1.1  christos                 tmp--;
   3014  1.1  christos                 if (tmp < prefix_len/2)
   3015  1.1  christos                     break;
   3016  1.5  christos                 if (!ND_TTEST2(*tptr, prefix_len / 2))
   3017  1.1  christos                     goto trunctlv;
   3018  1.5  christos                 ND_PRINT((ndo, "\n\t\tAddress: %s/%u",
   3019  1.7  christos                        isonsap_string(ndo, tptr, prefix_len / 2), prefix_len * 4));
   3020  1.1  christos                 tptr+=prefix_len/2;
   3021  1.1  christos                 tmp-=prefix_len/2;
   3022  1.1  christos             }
   3023  1.1  christos             break;
   3024  1.1  christos 
   3025  1.1  christos         case ISIS_TLV_IIH_SEQNR:
   3026  1.1  christos 	    if (tmp < ISIS_TLV_IIH_SEQNR_MINLEN)
   3027  1.1  christos 	        break;
   3028  1.5  christos             if (!ND_TTEST2(*tptr, ISIS_TLV_IIH_SEQNR_MINLEN)) /* check if four bytes are on the wire */
   3029  1.1  christos                 goto trunctlv;
   3030  1.5  christos             ND_PRINT((ndo, "\n\t      Sequence number: %u", EXTRACT_32BITS(tptr)));
   3031  1.1  christos             break;
   3032  1.1  christos 
   3033  1.1  christos         case ISIS_TLV_VENDOR_PRIVATE:
   3034  1.1  christos 	    if (tmp < ISIS_TLV_VENDOR_PRIVATE_MINLEN)
   3035  1.1  christos 	        break;
   3036  1.5  christos             if (!ND_TTEST2(*tptr, ISIS_TLV_VENDOR_PRIVATE_MINLEN)) /* check if enough byte for a full oui */
   3037  1.1  christos                 goto trunctlv;
   3038  1.1  christos             vendor_id = EXTRACT_24BITS(tptr);
   3039  1.5  christos             ND_PRINT((ndo, "\n\t      Vendor: %s (%u)",
   3040  1.5  christos                    tok2str(oui_values, "Unknown", vendor_id),
   3041  1.5  christos                    vendor_id));
   3042  1.1  christos             tptr+=3;
   3043  1.1  christos             tmp-=3;
   3044  1.1  christos             if (tmp > 0) /* hexdump the rest */
   3045  1.5  christos                 if (!print_unknown_data(ndo, tptr, "\n\t\t", tmp))
   3046  1.1  christos                     return(0);
   3047  1.1  christos             break;
   3048  1.1  christos             /*
   3049  1.1  christos              * FIXME those are the defined TLVs that lack a decoder
   3050  1.1  christos              * you are welcome to contribute code ;-)
   3051  1.1  christos              */
   3052  1.1  christos 
   3053  1.1  christos         case ISIS_TLV_DECNET_PHASE4:
   3054  1.1  christos         case ISIS_TLV_LUCENT_PRIVATE:
   3055  1.1  christos         case ISIS_TLV_IPAUTH:
   3056  1.1  christos         case ISIS_TLV_NORTEL_PRIVATE1:
   3057  1.1  christos         case ISIS_TLV_NORTEL_PRIVATE2:
   3058  1.1  christos 
   3059  1.1  christos 	default:
   3060  1.5  christos 		if (ndo->ndo_vflag <= 1) {
   3061  1.5  christos 			if (!print_unknown_data(ndo, pptr, "\n\t\t", tlv_len))
   3062  1.5  christos 				return(0);
   3063  1.5  christos 		}
   3064  1.5  christos 		break;
   3065  1.1  christos 	}
   3066  1.1  christos         /* do we want to see an additionally hexdump ? */
   3067  1.5  christos 	if (ndo->ndo_vflag> 1) {
   3068  1.5  christos 		if (!print_unknown_data(ndo, pptr, "\n\t      ", tlv_len))
   3069  1.5  christos 			return(0);
   3070  1.5  christos 	}
   3071  1.1  christos 
   3072  1.1  christos 	pptr += tlv_len;
   3073  1.1  christos 	packet_len -= tlv_len;
   3074  1.1  christos     }
   3075  1.1  christos 
   3076  1.1  christos     if (packet_len != 0) {
   3077  1.5  christos 	ND_PRINT((ndo, "\n\t      %u straggler bytes", packet_len));
   3078  1.1  christos     }
   3079  1.1  christos     return (1);
   3080  1.1  christos 
   3081  1.1  christos  trunc:
   3082  1.7  christos     ND_PRINT((ndo, "%s", tstr));
   3083  1.1  christos     return (1);
   3084  1.1  christos 
   3085  1.1  christos  trunctlv:
   3086  1.7  christos     ND_PRINT((ndo, "\n\t\t"));
   3087  1.7  christos     ND_PRINT((ndo, "%s", tstr));
   3088  1.1  christos     return(1);
   3089  1.1  christos }
   3090  1.1  christos 
   3091  1.7  christos static int
   3092  1.7  christos osi_print_cksum(netdissect_options *ndo, const uint8_t *pptr,
   3093  1.7  christos 	        uint16_t checksum, int checksum_offset, int length)
   3094  1.1  christos {
   3095  1.5  christos         uint16_t calculated_checksum;
   3096  1.1  christos 
   3097  1.6  christos         /* do not attempt to verify the checksum if it is zero,
   3098  1.6  christos          * if the total length is nonsense,
   3099  1.6  christos          * if the offset is nonsense,
   3100  1.6  christos          * or the base pointer is not sane
   3101  1.6  christos          */
   3102  1.6  christos         if (!checksum
   3103  1.7  christos             || length < 0
   3104  1.7  christos             || checksum_offset < 0
   3105  1.6  christos             || length > ndo->ndo_snaplen
   3106  1.6  christos             || checksum_offset > ndo->ndo_snaplen
   3107  1.6  christos             || checksum_offset > length) {
   3108  1.7  christos                 ND_PRINT((ndo, " (unverified)"));
   3109  1.7  christos                 return 1;
   3110  1.1  christos         } else {
   3111  1.7  christos #if 0
   3112  1.7  christos                 printf("\nosi_print_cksum: %p %u %u %u\n", pptr, checksum_offset, length, ndo->ndo_snaplen);
   3113  1.7  christos #endif
   3114  1.7  christos                 ND_TCHECK2(*pptr, length);
   3115  1.1  christos                 calculated_checksum = create_osi_cksum(pptr, checksum_offset, length);
   3116  1.1  christos                 if (checksum == calculated_checksum) {
   3117  1.5  christos                         ND_PRINT((ndo, " (correct)"));
   3118  1.1  christos                 } else {
   3119  1.7  christos                         ND_PRINT((ndo, " (incorrect should be 0x%04x)", calculated_checksum));
   3120  1.1  christos                 }
   3121  1.7  christos                 return 1;
   3122  1.1  christos         }
   3123  1.7  christos trunc:
   3124  1.7  christos         return 0;
   3125  1.1  christos }
   3126  1.1  christos 
   3127  1.1  christos /*
   3128  1.1  christos  * Local Variables:
   3129  1.1  christos  * c-style: whitesmith
   3130  1.1  christos  * c-basic-offset: 8
   3131  1.1  christos  * End:
   3132  1.1  christos  */
   3133