Home | History | Annotate | Line # | Download | only in dist
      1 /*     NetBSD: print-juniper.c,v 1.2 2007/07/24 11:53:45 drochner Exp        */
      2 
      3 /*
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that: (1) source code
      6  * distributions retain the above copyright notice and this paragraph
      7  * in its entirety, and (2) distributions including binary code include
      8  * the above copyright notice and this paragraph in its entirety in
      9  * the documentation or other materials provided with the distribution.
     10  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
     11  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
     12  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     13  * FOR A PARTICULAR PURPOSE.
     14  *
     15  * Original code by Hannes Gredler (hannes (at) gredler.at)
     16  */
     17 
     18 /* \summary: DLT_JUNIPER_* printers */
     19 
     20 #include <sys/cdefs.h>
     21 #ifndef lint
     22 __RCSID("$NetBSD: print-juniper.c,v 1.12 2024/09/02 16:15:31 christos Exp $");
     23 #endif
     24 
     25 #include <config.h>
     26 
     27 #include "netdissect-stdinc.h"
     28 
     29 #include <string.h>
     30 
     31 #define ND_LONGJMP_FROM_TCHECK
     32 #include "netdissect.h"
     33 #include "addrtoname.h"
     34 #include "extract.h"
     35 #include "ppp.h"
     36 #include "llc.h"
     37 #include "nlpid.h"
     38 #include "ethertype.h"
     39 #include "atm.h"
     40 
     41 /*
     42  * If none of the Juniper DLT_s are defined, there's nothing to do.
     43  */
     44 #if defined(DLT_JUNIPER_GGSN) || defined(DLT_JUNIPER_ES) || \
     45     defined(DLT_JUNIPER_MONITOR) || defined(DLT_JUNIPER_SERVICES) || \
     46     defined(DLT_JUNIPER_PPPOE) || defined(DLT_JUNIPER_ETHER) || \
     47     defined(DLT_JUNIPER_PPP) || defined(DLT_JUNIPER_FRELAY) || \
     48     defined(DLT_JUNIPER_CHDLC) || defined(DLT_JUNIPER_PPPOE_ATM) || \
     49     defined(DLT_JUNIPER_MLPPP) || defined(DLT_JUNIPER_MFR) || \
     50     defined(DLT_JUNIPER_MLFR) || defined(DLT_JUNIPER_ATM1) || \
     51     defined(DLT_JUNIPER_ATM2)
     52 #define JUNIPER_BPF_OUT           0       /* Outgoing packet */
     53 #define JUNIPER_BPF_IN            1       /* Incoming packet */
     54 #define JUNIPER_BPF_PKT_IN        0x1     /* Incoming packet */
     55 #define JUNIPER_BPF_NO_L2         0x2     /* L2 header stripped */
     56 #define JUNIPER_BPF_IIF           0x4     /* IIF is valid */
     57 #define JUNIPER_BPF_FILTER        0x40    /* BPF filtering is supported */
     58 #define JUNIPER_BPF_EXT           0x80    /* extensions present */
     59 #define JUNIPER_MGC_NUMBER        0x4d4743 /* = "MGC" */
     60 
     61 #define JUNIPER_LSQ_COOKIE_RE         (1 << 3)
     62 #define JUNIPER_LSQ_COOKIE_DIR        (1 << 2)
     63 #define JUNIPER_LSQ_L3_PROTO_SHIFT     4
     64 #define JUNIPER_LSQ_L3_PROTO_MASK     (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT)
     65 #define JUNIPER_LSQ_L3_PROTO_IPV4     (0 << JUNIPER_LSQ_L3_PROTO_SHIFT)
     66 #define JUNIPER_LSQ_L3_PROTO_IPV6     (1 << JUNIPER_LSQ_L3_PROTO_SHIFT)
     67 #define JUNIPER_LSQ_L3_PROTO_MPLS     (2 << JUNIPER_LSQ_L3_PROTO_SHIFT)
     68 #define JUNIPER_LSQ_L3_PROTO_ISO      (3 << JUNIPER_LSQ_L3_PROTO_SHIFT)
     69 #define AS_PIC_COOKIE_LEN 8
     70 
     71 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1
     72 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2
     73 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3
     74 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4
     75 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5
     76 
     77 #ifdef DLT_JUNIPER_ES
     78 static const struct tok juniper_ipsec_type_values[] = {
     79     { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE, "ESP ENCR-AUTH" },
     80     { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE, "ESP ENCR-AH AUTH" },
     81     { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE, "ESP AUTH" },
     82     { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE, "AH AUTH" },
     83     { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE, "ESP ENCR" },
     84     { 0, NULL}
     85 };
     86 #endif
     87 
     88 static const struct tok juniper_direction_values[] = {
     89     { JUNIPER_BPF_IN,  "In"},
     90     { JUNIPER_BPF_OUT, "Out"},
     91     { 0, NULL}
     92 };
     93 
     94 /* codepoints for encoding extensions to a .pcap file */
     95 enum {
     96     JUNIPER_EXT_TLV_IFD_IDX = 1,
     97     JUNIPER_EXT_TLV_IFD_NAME = 2,
     98     JUNIPER_EXT_TLV_IFD_MEDIATYPE = 3,
     99     JUNIPER_EXT_TLV_IFL_IDX = 4,
    100     JUNIPER_EXT_TLV_IFL_UNIT = 5,
    101     JUNIPER_EXT_TLV_IFL_ENCAPS = 6,
    102     JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE = 7,
    103     JUNIPER_EXT_TLV_TTP_IFL_ENCAPS = 8
    104 };
    105 
    106 /* 1 byte type and 1-byte length */
    107 #define JUNIPER_EXT_TLV_OVERHEAD 2U
    108 
    109 static const struct tok jnx_ext_tlv_values[] = {
    110     { JUNIPER_EXT_TLV_IFD_IDX, "Device Interface Index" },
    111     { JUNIPER_EXT_TLV_IFD_NAME,"Device Interface Name" },
    112     { JUNIPER_EXT_TLV_IFD_MEDIATYPE, "Device Media Type" },
    113     { JUNIPER_EXT_TLV_IFL_IDX, "Logical Interface Index" },
    114     { JUNIPER_EXT_TLV_IFL_UNIT,"Logical Unit Number" },
    115     { JUNIPER_EXT_TLV_IFL_ENCAPS, "Logical Interface Encapsulation" },
    116     { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE, "TTP derived Device Media Type" },
    117     { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS, "TTP derived Logical Interface Encapsulation" },
    118     { 0, NULL }
    119 };
    120 
    121 static const struct tok jnx_flag_values[] = {
    122     { JUNIPER_BPF_EXT, "Ext" },
    123     { JUNIPER_BPF_FILTER, "Filter" },
    124     { JUNIPER_BPF_IIF, "IIF" },
    125     { JUNIPER_BPF_NO_L2, "no-L2" },
    126     { JUNIPER_BPF_PKT_IN, "In" },
    127     { 0, NULL }
    128 };
    129 
    130 #define JUNIPER_IFML_ETHER              1
    131 #define JUNIPER_IFML_FDDI               2
    132 #define JUNIPER_IFML_TOKENRING          3
    133 #define JUNIPER_IFML_PPP                4
    134 #define JUNIPER_IFML_FRAMERELAY         5
    135 #define JUNIPER_IFML_CISCOHDLC          6
    136 #define JUNIPER_IFML_SMDSDXI            7
    137 #define JUNIPER_IFML_ATMPVC             8
    138 #define JUNIPER_IFML_PPP_CCC            9
    139 #define JUNIPER_IFML_FRAMERELAY_CCC     10
    140 #define JUNIPER_IFML_IPIP               11
    141 #define JUNIPER_IFML_GRE                12
    142 #define JUNIPER_IFML_PIM                13
    143 #define JUNIPER_IFML_PIMD               14
    144 #define JUNIPER_IFML_CISCOHDLC_CCC      15
    145 #define JUNIPER_IFML_VLAN_CCC           16
    146 #define JUNIPER_IFML_MLPPP              17
    147 #define JUNIPER_IFML_MLFR               18
    148 #define JUNIPER_IFML_ML                 19
    149 #define JUNIPER_IFML_LSI                20
    150 #define JUNIPER_IFML_DFE                21
    151 #define JUNIPER_IFML_ATM_CELLRELAY_CCC  22
    152 #define JUNIPER_IFML_CRYPTO             23
    153 #define JUNIPER_IFML_GGSN               24
    154 #define JUNIPER_IFML_LSI_PPP            25
    155 #define JUNIPER_IFML_LSI_CISCOHDLC      26
    156 #define JUNIPER_IFML_PPP_TCC            27
    157 #define JUNIPER_IFML_FRAMERELAY_TCC     28
    158 #define JUNIPER_IFML_CISCOHDLC_TCC      29
    159 #define JUNIPER_IFML_ETHERNET_CCC       30
    160 #define JUNIPER_IFML_VT                 31
    161 #define JUNIPER_IFML_EXTENDED_VLAN_CCC  32
    162 #define JUNIPER_IFML_ETHER_OVER_ATM     33
    163 #define JUNIPER_IFML_MONITOR            34
    164 #define JUNIPER_IFML_ETHERNET_TCC       35
    165 #define JUNIPER_IFML_VLAN_TCC           36
    166 #define JUNIPER_IFML_EXTENDED_VLAN_TCC  37
    167 #define JUNIPER_IFML_CONTROLLER         38
    168 #define JUNIPER_IFML_MFR                39
    169 #define JUNIPER_IFML_LS                 40
    170 #define JUNIPER_IFML_ETHERNET_VPLS      41
    171 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42
    172 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43
    173 #define JUNIPER_IFML_LT                 44
    174 #define JUNIPER_IFML_SERVICES           45
    175 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46
    176 #define JUNIPER_IFML_FR_PORT_CCC        47
    177 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48
    178 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49
    179 #define JUNIPER_IFML_FRAMERELAY_FLEX    50
    180 #define JUNIPER_IFML_GGSNI              51
    181 #define JUNIPER_IFML_ETHERNET_FLEX      52
    182 #define JUNIPER_IFML_COLLECTOR          53
    183 #define JUNIPER_IFML_AGGREGATOR         54
    184 #define JUNIPER_IFML_LAPD               55
    185 #define JUNIPER_IFML_PPPOE              56
    186 #define JUNIPER_IFML_PPP_SUBORDINATE    57
    187 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE  58
    188 #define JUNIPER_IFML_DFC                59
    189 #define JUNIPER_IFML_PICPEER            60
    190 
    191 static const struct tok juniper_ifmt_values[] = {
    192     { JUNIPER_IFML_ETHER, "Ethernet" },
    193     { JUNIPER_IFML_FDDI, "FDDI" },
    194     { JUNIPER_IFML_TOKENRING, "Token-Ring" },
    195     { JUNIPER_IFML_PPP, "PPP" },
    196     { JUNIPER_IFML_PPP_SUBORDINATE, "PPP-Subordinate" },
    197     { JUNIPER_IFML_FRAMERELAY, "Frame-Relay" },
    198     { JUNIPER_IFML_CISCOHDLC, "Cisco-HDLC" },
    199     { JUNIPER_IFML_SMDSDXI, "SMDS-DXI" },
    200     { JUNIPER_IFML_ATMPVC, "ATM-PVC" },
    201     { JUNIPER_IFML_PPP_CCC, "PPP-CCC" },
    202     { JUNIPER_IFML_FRAMERELAY_CCC, "Frame-Relay-CCC" },
    203     { JUNIPER_IFML_FRAMERELAY_EXT_CCC, "Extended FR-CCC" },
    204     { JUNIPER_IFML_IPIP, "IP-over-IP" },
    205     { JUNIPER_IFML_GRE, "GRE" },
    206     { JUNIPER_IFML_PIM, "PIM-Encapsulator" },
    207     { JUNIPER_IFML_PIMD, "PIM-Decapsulator" },
    208     { JUNIPER_IFML_CISCOHDLC_CCC, "Cisco-HDLC-CCC" },
    209     { JUNIPER_IFML_VLAN_CCC, "VLAN-CCC" },
    210     { JUNIPER_IFML_EXTENDED_VLAN_CCC, "Extended-VLAN-CCC" },
    211     { JUNIPER_IFML_MLPPP, "Multilink-PPP" },
    212     { JUNIPER_IFML_MLFR, "Multilink-FR" },
    213     { JUNIPER_IFML_MFR, "Multilink-FR-UNI-NNI" },
    214     { JUNIPER_IFML_ML, "Multilink" },
    215     { JUNIPER_IFML_LS, "LinkService" },
    216     { JUNIPER_IFML_LSI, "LSI" },
    217     { JUNIPER_IFML_ATM_CELLRELAY_CCC, "ATM-CCC-Cell-Relay" },
    218     { JUNIPER_IFML_CRYPTO, "IPSEC-over-IP" },
    219     { JUNIPER_IFML_GGSN, "GGSN" },
    220     { JUNIPER_IFML_PPP_TCC, "PPP-TCC" },
    221     { JUNIPER_IFML_FRAMERELAY_TCC, "Frame-Relay-TCC" },
    222     { JUNIPER_IFML_FRAMERELAY_EXT_TCC, "Extended FR-TCC" },
    223     { JUNIPER_IFML_CISCOHDLC_TCC, "Cisco-HDLC-TCC" },
    224     { JUNIPER_IFML_ETHERNET_CCC, "Ethernet-CCC" },
    225     { JUNIPER_IFML_VT, "VPN-Loopback-tunnel" },
    226     { JUNIPER_IFML_ETHER_OVER_ATM, "Ethernet-over-ATM" },
    227     { JUNIPER_IFML_ETHER_VPLS_OVER_ATM, "Ethernet-VPLS-over-ATM" },
    228     { JUNIPER_IFML_MONITOR, "Monitor" },
    229     { JUNIPER_IFML_ETHERNET_TCC, "Ethernet-TCC" },
    230     { JUNIPER_IFML_VLAN_TCC, "VLAN-TCC" },
    231     { JUNIPER_IFML_EXTENDED_VLAN_TCC, "Extended-VLAN-TCC" },
    232     { JUNIPER_IFML_CONTROLLER, "Controller" },
    233     { JUNIPER_IFML_ETHERNET_VPLS, "VPLS" },
    234     { JUNIPER_IFML_ETHERNET_VLAN_VPLS, "VLAN-VPLS" },
    235     { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS, "Extended-VLAN-VPLS" },
    236     { JUNIPER_IFML_LT, "Logical-tunnel" },
    237     { JUNIPER_IFML_SERVICES, "General-Services" },
    238     { JUNIPER_IFML_PPPOE, "PPPoE" },
    239     { JUNIPER_IFML_ETHERNET_FLEX, "Flexible-Ethernet-Services" },
    240     { JUNIPER_IFML_FRAMERELAY_FLEX, "Flexible-FrameRelay" },
    241     { JUNIPER_IFML_COLLECTOR, "Flow-collection" },
    242     { JUNIPER_IFML_PICPEER, "PIC Peer" },
    243     { JUNIPER_IFML_DFC, "Dynamic-Flow-Capture" },
    244     {0,                    NULL}
    245 };
    246 
    247 #define JUNIPER_IFLE_ATM_SNAP           2
    248 #define JUNIPER_IFLE_ATM_NLPID          3
    249 #define JUNIPER_IFLE_ATM_VCMUX          4
    250 #define JUNIPER_IFLE_ATM_LLC            5
    251 #define JUNIPER_IFLE_ATM_PPP_VCMUX      6
    252 #define JUNIPER_IFLE_ATM_PPP_LLC        7
    253 #define JUNIPER_IFLE_ATM_PPP_FUNI       8
    254 #define JUNIPER_IFLE_ATM_CCC            9
    255 #define JUNIPER_IFLE_FR_NLPID           10
    256 #define JUNIPER_IFLE_FR_SNAP            11
    257 #define JUNIPER_IFLE_FR_PPP             12
    258 #define JUNIPER_IFLE_FR_CCC             13
    259 #define JUNIPER_IFLE_ENET2              14
    260 #define JUNIPER_IFLE_IEEE8023_SNAP      15
    261 #define JUNIPER_IFLE_IEEE8023_LLC       16
    262 #define JUNIPER_IFLE_PPP                17
    263 #define JUNIPER_IFLE_CISCOHDLC          18
    264 #define JUNIPER_IFLE_PPP_CCC            19
    265 #define JUNIPER_IFLE_IPIP_NULL          20
    266 #define JUNIPER_IFLE_PIM_NULL           21
    267 #define JUNIPER_IFLE_GRE_NULL           22
    268 #define JUNIPER_IFLE_GRE_PPP            23
    269 #define JUNIPER_IFLE_PIMD_DECAPS        24
    270 #define JUNIPER_IFLE_CISCOHDLC_CCC      25
    271 #define JUNIPER_IFLE_ATM_CISCO_NLPID    26
    272 #define JUNIPER_IFLE_VLAN_CCC           27
    273 #define JUNIPER_IFLE_MLPPP              28
    274 #define JUNIPER_IFLE_MLFR               29
    275 #define JUNIPER_IFLE_LSI_NULL           30
    276 #define JUNIPER_IFLE_AGGREGATE_UNUSED   31
    277 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC  32
    278 #define JUNIPER_IFLE_CRYPTO             33
    279 #define JUNIPER_IFLE_GGSN               34
    280 #define JUNIPER_IFLE_ATM_TCC            35
    281 #define JUNIPER_IFLE_FR_TCC             36
    282 #define JUNIPER_IFLE_PPP_TCC            37
    283 #define JUNIPER_IFLE_CISCOHDLC_TCC      38
    284 #define JUNIPER_IFLE_ETHERNET_CCC       39
    285 #define JUNIPER_IFLE_VT                 40
    286 #define JUNIPER_IFLE_ATM_EOA_LLC        41
    287 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC          42
    288 #define JUNIPER_IFLE_ATM_SNAP_TCC       43
    289 #define JUNIPER_IFLE_MONITOR            44
    290 #define JUNIPER_IFLE_ETHERNET_TCC       45
    291 #define JUNIPER_IFLE_VLAN_TCC           46
    292 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC  47
    293 #define JUNIPER_IFLE_MFR                48
    294 #define JUNIPER_IFLE_ETHERNET_VPLS      49
    295 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50
    296 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51
    297 #define JUNIPER_IFLE_SERVICES           52
    298 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC                53
    299 #define JUNIPER_IFLE_FR_PORT_CCC        54
    300 #define JUNIPER_IFLE_ATM_MLPPP_LLC      55
    301 #define JUNIPER_IFLE_ATM_EOA_CCC        56
    302 #define JUNIPER_IFLE_LT_VLAN            57
    303 #define JUNIPER_IFLE_COLLECTOR          58
    304 #define JUNIPER_IFLE_AGGREGATOR         59
    305 #define JUNIPER_IFLE_LAPD               60
    306 #define JUNIPER_IFLE_ATM_PPPOE_LLC          61
    307 #define JUNIPER_IFLE_ETHERNET_PPPOE         62
    308 #define JUNIPER_IFLE_PPPOE                  63
    309 #define JUNIPER_IFLE_PPP_SUBORDINATE        64
    310 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE  65
    311 #define JUNIPER_IFLE_DFC                    66
    312 #define JUNIPER_IFLE_PICPEER                67
    313 
    314 static const struct tok juniper_ifle_values[] = {
    315     { JUNIPER_IFLE_AGGREGATOR, "Aggregator" },
    316     { JUNIPER_IFLE_ATM_CCC, "CCC over ATM" },
    317     { JUNIPER_IFLE_ATM_CELLRELAY_CCC, "ATM CCC Cell Relay" },
    318     { JUNIPER_IFLE_ATM_CISCO_NLPID, "CISCO compatible NLPID" },
    319     { JUNIPER_IFLE_ATM_EOA_CCC, "Ethernet over ATM CCC" },
    320     { JUNIPER_IFLE_ATM_EOA_LLC, "Ethernet over ATM LLC" },
    321     { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC, "Ethernet VPLS over ATM LLC" },
    322     { JUNIPER_IFLE_ATM_LLC, "ATM LLC" },
    323     { JUNIPER_IFLE_ATM_MLPPP_LLC, "MLPPP over ATM LLC" },
    324     { JUNIPER_IFLE_ATM_NLPID, "ATM NLPID" },
    325     { JUNIPER_IFLE_ATM_PPPOE_LLC, "PPPoE over ATM LLC" },
    326     { JUNIPER_IFLE_ATM_PPP_FUNI, "PPP over FUNI" },
    327     { JUNIPER_IFLE_ATM_PPP_LLC, "PPP over ATM LLC" },
    328     { JUNIPER_IFLE_ATM_PPP_VCMUX, "PPP over ATM VCMUX" },
    329     { JUNIPER_IFLE_ATM_SNAP, "ATM SNAP" },
    330     { JUNIPER_IFLE_ATM_SNAP_TCC, "ATM SNAP TCC" },
    331     { JUNIPER_IFLE_ATM_TCC, "ATM VCMUX TCC" },
    332     { JUNIPER_IFLE_ATM_VCMUX, "ATM VCMUX" },
    333     { JUNIPER_IFLE_CISCOHDLC, "C-HDLC" },
    334     { JUNIPER_IFLE_CISCOHDLC_CCC, "C-HDLC CCC" },
    335     { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE, "C-HDLC via dialer" },
    336     { JUNIPER_IFLE_CISCOHDLC_TCC, "C-HDLC TCC" },
    337     { JUNIPER_IFLE_COLLECTOR, "Collector" },
    338     { JUNIPER_IFLE_CRYPTO, "Crypto" },
    339     { JUNIPER_IFLE_ENET2, "Ethernet" },
    340     { JUNIPER_IFLE_ETHERNET_CCC, "Ethernet CCC" },
    341     { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS, "Extended VLAN VPLS" },
    342     { JUNIPER_IFLE_ETHERNET_PPPOE, "PPPoE over Ethernet" },
    343     { JUNIPER_IFLE_ETHERNET_TCC, "Ethernet TCC" },
    344     { JUNIPER_IFLE_ETHERNET_VLAN_VPLS, "VLAN VPLS" },
    345     { JUNIPER_IFLE_ETHERNET_VPLS, "VPLS" },
    346     { JUNIPER_IFLE_EXTENDED_VLAN_CCC, "Extended VLAN CCC" },
    347     { JUNIPER_IFLE_EXTENDED_VLAN_TCC, "Extended VLAN TCC" },
    348     { JUNIPER_IFLE_FR_CCC, "FR CCC" },
    349     { JUNIPER_IFLE_FR_NLPID, "FR NLPID" },
    350     { JUNIPER_IFLE_FR_PORT_CCC, "FR CCC" },
    351     { JUNIPER_IFLE_FR_PPP, "FR PPP" },
    352     { JUNIPER_IFLE_FR_SNAP, "FR SNAP" },
    353     { JUNIPER_IFLE_FR_TCC, "FR TCC" },
    354     { JUNIPER_IFLE_GGSN, "GGSN" },
    355     { JUNIPER_IFLE_GRE_NULL, "GRE NULL" },
    356     { JUNIPER_IFLE_GRE_PPP, "PPP over GRE" },
    357     { JUNIPER_IFLE_IPIP_NULL, "IPIP" },
    358     { JUNIPER_IFLE_LAPD, "LAPD" },
    359     { JUNIPER_IFLE_LSI_NULL, "LSI Null" },
    360     { JUNIPER_IFLE_LT_VLAN, "LT VLAN" },
    361     { JUNIPER_IFLE_MFR, "MFR" },
    362     { JUNIPER_IFLE_MLFR, "MLFR" },
    363     { JUNIPER_IFLE_MLPPP, "MLPPP" },
    364     { JUNIPER_IFLE_MONITOR, "Monitor" },
    365     { JUNIPER_IFLE_PIMD_DECAPS, "PIMd" },
    366     { JUNIPER_IFLE_PIM_NULL, "PIM Null" },
    367     { JUNIPER_IFLE_PPP, "PPP" },
    368     { JUNIPER_IFLE_PPPOE, "PPPoE" },
    369     { JUNIPER_IFLE_PPP_CCC, "PPP CCC" },
    370     { JUNIPER_IFLE_PPP_SUBORDINATE, "" },
    371     { JUNIPER_IFLE_PPP_TCC, "PPP TCC" },
    372     { JUNIPER_IFLE_SERVICES, "General Services" },
    373     { JUNIPER_IFLE_VLAN_CCC, "VLAN CCC" },
    374     { JUNIPER_IFLE_VLAN_TCC, "VLAN TCC" },
    375     { JUNIPER_IFLE_VT, "VT" },
    376     {0,                    NULL}
    377 };
    378 
    379 struct juniper_cookie_table_t {
    380     uint32_t pictype;		/* pic type */
    381     uint8_t  cookie_len;	/* cookie len */
    382     const char *s;		/* pic name */
    383 };
    384 
    385 static const struct juniper_cookie_table_t juniper_cookie_table[] = {
    386 #ifdef DLT_JUNIPER_ATM1
    387     { DLT_JUNIPER_ATM1,  4, "ATM1"},
    388 #endif
    389 #ifdef DLT_JUNIPER_ATM2
    390     { DLT_JUNIPER_ATM2,  8, "ATM2"},
    391 #endif
    392 #ifdef DLT_JUNIPER_MLPPP
    393     { DLT_JUNIPER_MLPPP, 2, "MLPPP"},
    394 #endif
    395 #ifdef DLT_JUNIPER_MLFR
    396     { DLT_JUNIPER_MLFR,  2, "MLFR"},
    397 #endif
    398 #ifdef DLT_JUNIPER_MFR
    399     { DLT_JUNIPER_MFR,   4, "MFR"},
    400 #endif
    401 #ifdef DLT_JUNIPER_PPPOE
    402     { DLT_JUNIPER_PPPOE, 0, "PPPoE"},
    403 #endif
    404 #ifdef DLT_JUNIPER_PPPOE_ATM
    405     { DLT_JUNIPER_PPPOE_ATM, 0, "PPPoE ATM"},
    406 #endif
    407 #ifdef DLT_JUNIPER_GGSN
    408     { DLT_JUNIPER_GGSN, 8, "GGSN"},
    409 #endif
    410 #ifdef DLT_JUNIPER_MONITOR
    411     { DLT_JUNIPER_MONITOR, 8, "MONITOR"},
    412 #endif
    413 #ifdef DLT_JUNIPER_SERVICES
    414     { DLT_JUNIPER_SERVICES, 8, "AS"},
    415 #endif
    416 #ifdef DLT_JUNIPER_ES
    417     { DLT_JUNIPER_ES, 0, "ES"},
    418 #endif
    419     { 0, 0, NULL }
    420 };
    421 
    422 struct juniper_l2info_t {
    423     uint32_t length;
    424     uint32_t caplen;
    425     uint32_t pictype;
    426     uint8_t direction;
    427     u_int header_len;
    428     uint8_t cookie_len;
    429     uint8_t cookie_type;
    430     uint8_t cookie[8];
    431     u_int bundle;
    432     uint16_t proto;
    433     uint8_t flags;
    434 };
    435 
    436 #define LS_COOKIE_ID            0x54
    437 #define AS_COOKIE_ID            0x47
    438 #define LS_MLFR_COOKIE_LEN	4
    439 #define ML_MLFR_COOKIE_LEN	2
    440 #define LS_MFR_COOKIE_LEN	6
    441 #define ATM1_COOKIE_LEN         4
    442 #define ATM2_COOKIE_LEN         8
    443 
    444 #define ATM2_PKT_TYPE_MASK  0x70
    445 #define ATM2_GAP_COUNT_MASK 0x3F
    446 
    447 #define JUNIPER_PROTO_NULL          1
    448 #define JUNIPER_PROTO_IPV4          2
    449 #define JUNIPER_PROTO_IPV6          6
    450 
    451 #define MFR_BE_MASK 0xc0
    452 
    453 #ifdef DLT_JUNIPER_GGSN
    454 static const struct tok juniper_protocol_values[] = {
    455     { JUNIPER_PROTO_NULL, "Null" },
    456     { JUNIPER_PROTO_IPV4, "IPv4" },
    457     { JUNIPER_PROTO_IPV6, "IPv6" },
    458     { 0, NULL}
    459 };
    460 #endif
    461 
    462 static int ip_heuristic_guess(netdissect_options *, const u_char *, u_int);
    463 #ifdef DLT_JUNIPER_ATM2
    464 static int juniper_ppp_heuristic_guess(netdissect_options *, const u_char *, u_int);
    465 #endif
    466 static int juniper_parse_header(netdissect_options *, const u_char *, const struct pcap_pkthdr *, struct juniper_l2info_t *);
    467 
    468 #ifdef DLT_JUNIPER_GGSN
    469 void
    470 juniper_ggsn_if_print(netdissect_options *ndo,
    471                       const struct pcap_pkthdr *h, const u_char *p)
    472 {
    473         struct juniper_l2info_t l2info;
    474         struct juniper_ggsn_header {
    475             nd_uint8_t  svc_id;
    476             nd_uint8_t  flags_len;
    477             nd_uint8_t  proto;
    478             nd_uint8_t  flags;
    479             nd_uint16_t vlan_id;
    480             nd_byte     res[2];
    481         };
    482         const struct juniper_ggsn_header *gh;
    483         uint8_t proto;
    484 
    485         ndo->ndo_protocol = "juniper_ggsn";
    486         memset(&l2info, 0, sizeof(l2info));
    487         l2info.pictype = DLT_JUNIPER_GGSN;
    488         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    489             ndo->ndo_ll_hdr_len += l2info.header_len;
    490             return;
    491         }
    492 
    493         p+=l2info.header_len;
    494         gh = (struct juniper_ggsn_header *)&l2info.cookie;
    495 
    496         /* use EXTRACT_, not GET_ (not packet buffer pointer) */
    497         proto = EXTRACT_U_1(gh->proto);
    498         if (ndo->ndo_eflag) {
    499             ND_PRINT("proto %s (%u), vlan %u: ",
    500                    tok2str(juniper_protocol_values,"Unknown",proto),
    501                    proto,
    502                    EXTRACT_BE_U_2(gh->vlan_id));
    503         }
    504 
    505         switch (proto) {
    506         case JUNIPER_PROTO_IPV4:
    507             ip_print(ndo, p, l2info.length);
    508             break;
    509         case JUNIPER_PROTO_IPV6:
    510             ip6_print(ndo, p, l2info.length);
    511             break;
    512         default:
    513             if (!ndo->ndo_eflag)
    514                 ND_PRINT("unknown GGSN proto (%u)", proto);
    515         }
    516 
    517         ndo->ndo_ll_hdr_len += l2info.header_len;
    518 }
    519 #endif
    520 
    521 #ifdef DLT_JUNIPER_ES
    522 void
    523 juniper_es_if_print(netdissect_options *ndo,
    524                     const struct pcap_pkthdr *h, const u_char *p)
    525 {
    526         struct juniper_l2info_t l2info;
    527         struct juniper_ipsec_header {
    528             nd_uint16_t sa_index;
    529             nd_uint8_t  ttl;
    530             nd_uint8_t  type;
    531             nd_uint32_t spi;
    532             nd_ipv4     src_ip;
    533             nd_ipv4     dst_ip;
    534         };
    535         u_int rewrite_len,es_type_bundle;
    536         const struct juniper_ipsec_header *ih;
    537 
    538         ndo->ndo_protocol = "juniper_es";
    539         memset(&l2info, 0, sizeof(l2info));
    540         l2info.pictype = DLT_JUNIPER_ES;
    541         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    542             ndo->ndo_ll_hdr_len += l2info.header_len;
    543             return;
    544         }
    545 
    546         p+=l2info.header_len;
    547         ih = (const struct juniper_ipsec_header *)p;
    548 
    549         ND_TCHECK_SIZE(ih);
    550         switch (GET_U_1(ih->type)) {
    551         case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE:
    552         case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE:
    553             rewrite_len = 0;
    554             es_type_bundle = 1;
    555             break;
    556         case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE:
    557         case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE:
    558         case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE:
    559             rewrite_len = 16;
    560             es_type_bundle = 0;
    561             break;
    562         default:
    563             ND_PRINT("ES Invalid type %u, length %u",
    564                    GET_U_1(ih->type),
    565                    l2info.length);
    566             ndo->ndo_ll_hdr_len += l2info.header_len;
    567             return;
    568         }
    569 
    570         l2info.length-=rewrite_len;
    571         p+=rewrite_len;
    572 
    573         if (ndo->ndo_eflag) {
    574             if (!es_type_bundle) {
    575                 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
    576                        GET_BE_U_2(ih->sa_index),
    577                        GET_U_1(ih->ttl),
    578                        tok2str(juniper_ipsec_type_values,"Unknown",GET_U_1(ih->type)),
    579                        GET_U_1(ih->type),
    580                        GET_BE_U_4(ih->spi),
    581                        GET_IPADDR_STRING(ih->src_ip),
    582                        GET_IPADDR_STRING(ih->dst_ip),
    583                        l2info.length);
    584             } else {
    585                 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), length %u\n",
    586                        GET_BE_U_2(ih->sa_index),
    587                        GET_U_1(ih->ttl),
    588                        tok2str(juniper_ipsec_type_values,"Unknown",GET_U_1(ih->type)),
    589                        GET_U_1(ih->type),
    590                        l2info.length);
    591             }
    592         }
    593 
    594         ip_print(ndo, p, l2info.length);
    595         ndo->ndo_ll_hdr_len += l2info.header_len;
    596 }
    597 #endif
    598 
    599 #ifdef DLT_JUNIPER_MONITOR
    600 void
    601 juniper_monitor_if_print(netdissect_options *ndo,
    602                          const struct pcap_pkthdr *h, const u_char *p)
    603 {
    604         struct juniper_l2info_t l2info;
    605         struct juniper_monitor_header {
    606             nd_uint8_t  pkt_type;
    607             nd_byte     padding;
    608             nd_uint16_t iif;
    609             nd_uint32_t service_id;
    610         };
    611         const struct juniper_monitor_header *mh;
    612 
    613         ndo->ndo_protocol = "juniper_monitor";
    614         memset(&l2info, 0, sizeof(l2info));
    615         l2info.pictype = DLT_JUNIPER_MONITOR;
    616         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    617             ndo->ndo_ll_hdr_len += l2info.header_len;
    618             return;
    619         }
    620 
    621         p+=l2info.header_len;
    622         mh = (const struct juniper_monitor_header *)p;
    623 
    624         ND_TCHECK_SIZE(mh);
    625         if (ndo->ndo_eflag)
    626             ND_PRINT("service-id %u, iif %u, pkt-type %u: ",
    627                    GET_BE_U_4(mh->service_id),
    628                    GET_BE_U_2(mh->iif),
    629                    GET_U_1(mh->pkt_type));
    630 
    631         /* no proto field - lets guess by first byte of IP header*/
    632         ip_heuristic_guess (ndo, p, l2info.length);
    633 
    634         ndo->ndo_ll_hdr_len += l2info.header_len;
    635 }
    636 #endif
    637 
    638 #ifdef DLT_JUNIPER_SERVICES
    639 void
    640 juniper_services_if_print(netdissect_options *ndo,
    641                           const struct pcap_pkthdr *h, const u_char *p)
    642 {
    643         struct juniper_l2info_t l2info;
    644         struct juniper_services_header {
    645             nd_uint8_t  svc_id;
    646             nd_uint8_t  flags_len;
    647             nd_uint16_t svc_set_id;
    648             nd_byte     pad;
    649             nd_uint24_t dir_iif;
    650         };
    651         const struct juniper_services_header *sh;
    652 
    653         ndo->ndo_protocol = "juniper_services";
    654         memset(&l2info, 0, sizeof(l2info));
    655         l2info.pictype = DLT_JUNIPER_SERVICES;
    656         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    657             ndo->ndo_ll_hdr_len += l2info.header_len;
    658             return;
    659         }
    660 
    661         p+=l2info.header_len;
    662         sh = (const struct juniper_services_header *)p;
    663 
    664         ND_TCHECK_SIZE(sh);
    665         if (ndo->ndo_eflag)
    666             ND_PRINT("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
    667                    GET_U_1(sh->svc_id),
    668                    GET_U_1(sh->flags_len),
    669                    GET_BE_U_2(sh->svc_set_id),
    670                    GET_BE_U_3(sh->dir_iif));
    671 
    672         /* no proto field - lets guess by first byte of IP header*/
    673         ip_heuristic_guess (ndo, p, l2info.length);
    674 
    675         ndo->ndo_ll_hdr_len += l2info.header_len;
    676 }
    677 #endif
    678 
    679 #ifdef DLT_JUNIPER_PPPOE
    680 void
    681 juniper_pppoe_if_print(netdissect_options *ndo,
    682                        const struct pcap_pkthdr *h, const u_char *p)
    683 {
    684         struct juniper_l2info_t l2info;
    685 
    686         ndo->ndo_protocol = "juniper_pppoe";
    687         memset(&l2info, 0, sizeof(l2info));
    688         l2info.pictype = DLT_JUNIPER_PPPOE;
    689         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    690             ndo->ndo_ll_hdr_len += l2info.header_len;
    691             return;
    692         }
    693 
    694         p+=l2info.header_len;
    695         /* this DLT contains nothing but raw ethernet frames */
    696         ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
    697         ndo->ndo_ll_hdr_len += l2info.header_len;
    698 }
    699 #endif
    700 
    701 #ifdef DLT_JUNIPER_ETHER
    702 void
    703 juniper_ether_if_print(netdissect_options *ndo,
    704                        const struct pcap_pkthdr *h, const u_char *p)
    705 {
    706         struct juniper_l2info_t l2info;
    707 
    708         ndo->ndo_protocol = "juniper_ether";
    709         memset(&l2info, 0, sizeof(l2info));
    710         l2info.pictype = DLT_JUNIPER_ETHER;
    711         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    712             ndo->ndo_ll_hdr_len += l2info.header_len;
    713             return;
    714         }
    715 
    716         p+=l2info.header_len;
    717         /* this DLT contains nothing but raw Ethernet frames */
    718         ndo->ndo_ll_hdr_len +=
    719 		l2info.header_len +
    720 		ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
    721 }
    722 #endif
    723 
    724 #ifdef DLT_JUNIPER_PPP
    725 void
    726 juniper_ppp_if_print(netdissect_options *ndo,
    727                      const struct pcap_pkthdr *h, const u_char *p)
    728 {
    729         struct juniper_l2info_t l2info;
    730 
    731         ndo->ndo_protocol = "juniper_ppp";
    732         memset(&l2info, 0, sizeof(l2info));
    733         l2info.pictype = DLT_JUNIPER_PPP;
    734         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    735             ndo->ndo_ll_hdr_len += l2info.header_len;
    736             return;
    737         }
    738 
    739         p+=l2info.header_len;
    740         /* this DLT contains nothing but raw ppp frames */
    741         ppp_print(ndo, p, l2info.length);
    742         ndo->ndo_ll_hdr_len += l2info.header_len;
    743 }
    744 #endif
    745 
    746 #ifdef DLT_JUNIPER_FRELAY
    747 void
    748 juniper_frelay_if_print(netdissect_options *ndo,
    749                         const struct pcap_pkthdr *h, const u_char *p)
    750 {
    751         struct juniper_l2info_t l2info;
    752 
    753         ndo->ndo_protocol = "juniper_frelay";
    754         memset(&l2info, 0, sizeof(l2info));
    755         l2info.pictype = DLT_JUNIPER_FRELAY;
    756         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    757             ndo->ndo_ll_hdr_len += l2info.header_len;
    758             return;
    759         }
    760 
    761         p+=l2info.header_len;
    762         /* this DLT contains nothing but raw frame-relay frames */
    763         fr_print(ndo, p, l2info.length);
    764         ndo->ndo_ll_hdr_len += l2info.header_len;
    765 }
    766 #endif
    767 
    768 #ifdef DLT_JUNIPER_CHDLC
    769 void
    770 juniper_chdlc_if_print(netdissect_options *ndo,
    771                        const struct pcap_pkthdr *h, const u_char *p)
    772 {
    773         struct juniper_l2info_t l2info;
    774 
    775         ndo->ndo_protocol = "juniper_chdlc";
    776         memset(&l2info, 0, sizeof(l2info));
    777         l2info.pictype = DLT_JUNIPER_CHDLC;
    778         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    779             ndo->ndo_ll_hdr_len += l2info.header_len;
    780             return;
    781         }
    782 
    783         p+=l2info.header_len;
    784         /* this DLT contains nothing but raw c-hdlc frames */
    785         chdlc_print(ndo, p, l2info.length);
    786         ndo->ndo_ll_hdr_len += l2info.header_len;
    787 }
    788 #endif
    789 
    790 #ifdef DLT_JUNIPER_PPPOE_ATM
    791 void
    792 juniper_pppoe_atm_if_print(netdissect_options *ndo,
    793                            const struct pcap_pkthdr *h, const u_char *p)
    794 {
    795         struct juniper_l2info_t l2info;
    796         uint16_t extracted_ethertype;
    797 
    798         ndo->ndo_protocol = "juniper_pppoe_atm";
    799         memset(&l2info, 0, sizeof(l2info));
    800         l2info.pictype = DLT_JUNIPER_PPPOE_ATM;
    801         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    802             ndo->ndo_ll_hdr_len += l2info.header_len;
    803             return;
    804         }
    805 
    806         p+=l2info.header_len;
    807 
    808         extracted_ethertype = GET_BE_U_2(p);
    809         /* this DLT contains nothing but raw PPPoE frames,
    810          * prepended with a type field*/
    811         if (ethertype_print(ndo, extracted_ethertype,
    812                               p+ETHERTYPE_LEN,
    813                               l2info.length-ETHERTYPE_LEN,
    814                               l2info.caplen-ETHERTYPE_LEN,
    815                               NULL, NULL) == 0)
    816             /* ether_type not known, probably it wasn't one */
    817             ND_PRINT("unknown ethertype 0x%04x", extracted_ethertype);
    818 
    819         ndo->ndo_ll_hdr_len += l2info.header_len;
    820 }
    821 #endif
    822 
    823 #ifdef DLT_JUNIPER_MLPPP
    824 void
    825 juniper_mlppp_if_print(netdissect_options *ndo,
    826                        const struct pcap_pkthdr *h, const u_char *p)
    827 {
    828         struct juniper_l2info_t l2info;
    829 
    830         ndo->ndo_protocol = "juniper_mlppp";
    831         memset(&l2info, 0, sizeof(l2info));
    832         l2info.pictype = DLT_JUNIPER_MLPPP;
    833         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    834             ndo->ndo_ll_hdr_len += l2info.header_len;
    835             return;
    836         }
    837 
    838         /* suppress Bundle-ID if frame was captured on a child-link
    839          * best indicator if the cookie looks like a proto */
    840         if (ndo->ndo_eflag &&
    841             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
    842             EXTRACT_BE_U_2(&l2info.cookie) != PPP_OSI &&
    843             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
    844             EXTRACT_BE_U_2(&l2info.cookie) !=  (PPP_ADDRESS << 8 | PPP_CONTROL))
    845             ND_PRINT("Bundle-ID %u: ", l2info.bundle);
    846 
    847         p+=l2info.header_len;
    848 
    849         /* first try the LSQ protos */
    850         switch(l2info.proto) {
    851         case JUNIPER_LSQ_L3_PROTO_IPV4:
    852             /* IP traffic going to the RE would not have a cookie
    853              * -> this must be incoming IS-IS over PPP
    854              */
    855             if (l2info.cookie[4] == (JUNIPER_LSQ_COOKIE_RE|JUNIPER_LSQ_COOKIE_DIR))
    856                 ppp_print(ndo, p, l2info.length);
    857             else
    858                 ip_print(ndo, p, l2info.length);
    859             ndo->ndo_ll_hdr_len += l2info.header_len;
    860             return;
    861         case JUNIPER_LSQ_L3_PROTO_IPV6:
    862             ip6_print(ndo, p,l2info.length);
    863             ndo->ndo_ll_hdr_len += l2info.header_len;
    864             return;
    865         case JUNIPER_LSQ_L3_PROTO_MPLS:
    866             mpls_print(ndo, p, l2info.length);
    867             ndo->ndo_ll_hdr_len += l2info.header_len;
    868             return;
    869         case JUNIPER_LSQ_L3_PROTO_ISO:
    870             isoclns_print(ndo, p, l2info.length);
    871             ndo->ndo_ll_hdr_len += l2info.header_len;
    872             return;
    873         default:
    874             break;
    875         }
    876 
    877         /* zero length cookie ? */
    878         /* use EXTRACT_, not GET_ (not packet buffer pointer) */
    879         switch (EXTRACT_BE_U_2(&l2info.cookie)) {
    880         case PPP_OSI:
    881             ppp_print(ndo, p - 2, l2info.length + 2);
    882             break;
    883         case (PPP_ADDRESS << 8 | PPP_CONTROL): /* fall through */
    884         default:
    885             ppp_print(ndo, p, l2info.length);
    886             break;
    887         }
    888 
    889         ndo->ndo_ll_hdr_len += l2info.header_len;
    890 }
    891 #endif
    892 
    893 
    894 #ifdef DLT_JUNIPER_MFR
    895 void
    896 juniper_mfr_if_print(netdissect_options *ndo,
    897                      const struct pcap_pkthdr *h, const u_char *p)
    898 {
    899         struct juniper_l2info_t l2info;
    900 
    901         ndo->ndo_protocol = "juniper_mfr";
    902         memset(&l2info, 0, sizeof(l2info));
    903         l2info.pictype = DLT_JUNIPER_MFR;
    904         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    905             ndo->ndo_ll_hdr_len += l2info.header_len;
    906             return;
    907         }
    908 
    909         p+=l2info.header_len;
    910 
    911         /* child-link ? */
    912         if (l2info.cookie_len == 0) {
    913             mfr_print(ndo, p, l2info.length);
    914             ndo->ndo_ll_hdr_len += l2info.header_len;
    915             return;
    916         }
    917 
    918         /* first try the LSQ protos */
    919         if (l2info.cookie_len == AS_PIC_COOKIE_LEN) {
    920             switch(l2info.proto) {
    921             case JUNIPER_LSQ_L3_PROTO_IPV4:
    922                 ip_print(ndo, p, l2info.length);
    923                 ndo->ndo_ll_hdr_len += l2info.header_len;
    924                 return;
    925             case JUNIPER_LSQ_L3_PROTO_IPV6:
    926                 ip6_print(ndo, p,l2info.length);
    927                 ndo->ndo_ll_hdr_len += l2info.header_len;
    928                 return;
    929             case JUNIPER_LSQ_L3_PROTO_MPLS:
    930                 mpls_print(ndo, p, l2info.length);
    931                 ndo->ndo_ll_hdr_len += l2info.header_len;
    932                 return;
    933             case JUNIPER_LSQ_L3_PROTO_ISO:
    934                 isoclns_print(ndo, p, l2info.length);
    935                 ndo->ndo_ll_hdr_len += l2info.header_len;
    936                 return;
    937             default:
    938                 break;
    939             }
    940             ndo->ndo_ll_hdr_len += l2info.header_len;
    941             return;
    942         }
    943 
    944         /* suppress Bundle-ID if frame was captured on a child-link */
    945         /* use EXTRACT_, not GET_ (not packet buffer pointer) */
    946         if (ndo->ndo_eflag && EXTRACT_BE_U_4(l2info.cookie) != 1)
    947             ND_PRINT("Bundle-ID %u, ", l2info.bundle);
    948         switch (l2info.proto) {
    949         case (LLCSAP_ISONS<<8 | LLCSAP_ISONS):
    950             /* At least one byte is required */
    951             ND_TCHECK_LEN(p, 1);
    952             isoclns_print(ndo, p + 1, l2info.length - 1);
    953             break;
    954         case (LLC_UI<<8 | NLPID_Q933):
    955         case (LLC_UI<<8 | NLPID_IP):
    956         case (LLC_UI<<8 | NLPID_IP6):
    957             /* pass IP{4,6} to the OSI layer for proper link-layer printing */
    958             isoclns_print(ndo, p - 1, l2info.length + 1);
    959             break;
    960         default:
    961             ND_PRINT("unknown protocol 0x%04x, length %u", l2info.proto, l2info.length);
    962         }
    963 
    964         ndo->ndo_ll_hdr_len += l2info.header_len;
    965 }
    966 #endif
    967 
    968 #ifdef DLT_JUNIPER_MLFR
    969 void
    970 juniper_mlfr_if_print(netdissect_options *ndo,
    971                       const struct pcap_pkthdr *h, const u_char *p)
    972 {
    973         struct juniper_l2info_t l2info;
    974 
    975         ndo->ndo_protocol = "juniper_mlfr";
    976         memset(&l2info, 0, sizeof(l2info));
    977         l2info.pictype = DLT_JUNIPER_MLFR;
    978         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
    979             ndo->ndo_ll_hdr_len += l2info.header_len;
    980             return;
    981         }
    982 
    983         p+=l2info.header_len;
    984 
    985         /* suppress Bundle-ID if frame was captured on a child-link */
    986         /* use EXTRACT_, not GET_ (not packet buffer pointer) */
    987         if (ndo->ndo_eflag && EXTRACT_BE_U_4(l2info.cookie) != 1)
    988             ND_PRINT("Bundle-ID %u, ", l2info.bundle);
    989         switch (l2info.proto) {
    990         case (LLC_UI):
    991         case (LLC_UI<<8):
    992             isoclns_print(ndo, p, l2info.length);
    993             break;
    994         case (LLC_UI<<8 | NLPID_Q933):
    995         case (LLC_UI<<8 | NLPID_IP):
    996         case (LLC_UI<<8 | NLPID_IP6):
    997             /* pass IP{4,6} to the OSI layer for proper link-layer printing */
    998             isoclns_print(ndo, p - 1, l2info.length + 1);
    999             break;
   1000         default:
   1001             ND_PRINT("unknown protocol 0x%04x, length %u", l2info.proto, l2info.length);
   1002         }
   1003 
   1004         ndo->ndo_ll_hdr_len += l2info.header_len;
   1005 }
   1006 #endif
   1007 
   1008 /*
   1009  *     ATM1 PIC cookie format
   1010  *
   1011  *     +-----+-------------------------+-------------------------------+
   1012  *     |fmtid|     vc index            |  channel  ID                  |
   1013  *     +-----+-------------------------+-------------------------------+
   1014  */
   1015 
   1016 #ifdef DLT_JUNIPER_ATM1
   1017 void
   1018 juniper_atm1_if_print(netdissect_options *ndo,
   1019                       const struct pcap_pkthdr *h, const u_char *p)
   1020 {
   1021         int llc_hdrlen;
   1022 
   1023         struct juniper_l2info_t l2info;
   1024 
   1025         ndo->ndo_protocol = "juniper_atm1";
   1026         memset(&l2info, 0, sizeof(l2info));
   1027         l2info.pictype = DLT_JUNIPER_ATM1;
   1028         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
   1029             ndo->ndo_ll_hdr_len += l2info.header_len;
   1030             return;
   1031         }
   1032 
   1033         p+=l2info.header_len;
   1034 
   1035         if (l2info.cookie[0] == 0x80) { /* OAM cell ? */
   1036             oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC);
   1037             ndo->ndo_ll_hdr_len += l2info.header_len;
   1038             return;
   1039         }
   1040 
   1041         if (GET_BE_U_3(p) == 0xfefe03 || /* NLPID encaps ? */
   1042             GET_BE_U_3(p) == 0xaaaa03) { /* SNAP encaps ? */
   1043 
   1044             llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
   1045             if (llc_hdrlen > 0) {
   1046                 ndo->ndo_ll_hdr_len += l2info.header_len;
   1047                 return;
   1048             }
   1049         }
   1050 
   1051         if (GET_U_1(p) == 0x03) { /* Cisco style NLPID encaps ? */
   1052             /* At least one byte is required */
   1053             ND_TCHECK_LEN(p, 1);
   1054             isoclns_print(ndo, p + 1, l2info.length - 1);
   1055             /* FIXME check if frame was recognized */
   1056             ndo->ndo_ll_hdr_len += l2info.header_len;
   1057             return;
   1058         }
   1059 
   1060         if (ip_heuristic_guess(ndo, p, l2info.length) != 0) { /* last try - vcmux encaps ? */
   1061             ndo->ndo_ll_hdr_len += l2info.header_len;
   1062             return;
   1063         }
   1064 
   1065         ndo->ndo_ll_hdr_len += l2info.header_len;
   1066 }
   1067 #endif
   1068 
   1069 /*
   1070  *     ATM2 PIC cookie format
   1071  *
   1072  *     +-------------------------------+---------+---+-----+-----------+
   1073  *     |     channel ID                |  reserv |AAL| CCRQ| gap cnt   |
   1074  *     +-------------------------------+---------+---+-----+-----------+
   1075  */
   1076 
   1077 #ifdef DLT_JUNIPER_ATM2
   1078 void
   1079 juniper_atm2_if_print(netdissect_options *ndo,
   1080                       const struct pcap_pkthdr *h, const u_char *p)
   1081 {
   1082         int llc_hdrlen;
   1083 
   1084         struct juniper_l2info_t l2info;
   1085 
   1086         ndo->ndo_protocol = "juniper_atm2";
   1087         memset(&l2info, 0, sizeof(l2info));
   1088         l2info.pictype = DLT_JUNIPER_ATM2;
   1089         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
   1090             ndo->ndo_ll_hdr_len += l2info.header_len;
   1091             return;
   1092         }
   1093 
   1094         p+=l2info.header_len;
   1095 
   1096         if (l2info.cookie[7] & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */
   1097             oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC);
   1098             ndo->ndo_ll_hdr_len += l2info.header_len;
   1099             return;
   1100         }
   1101 
   1102         if (GET_BE_U_3(p) == 0xfefe03 || /* NLPID encaps ? */
   1103             GET_BE_U_3(p) == 0xaaaa03) { /* SNAP encaps ? */
   1104 
   1105             llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
   1106             if (llc_hdrlen > 0) {
   1107                 ndo->ndo_ll_hdr_len += l2info.header_len;
   1108                 return;
   1109             }
   1110         }
   1111 
   1112         if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */
   1113             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
   1114             (EXTRACT_BE_U_4(l2info.cookie) & ATM2_GAP_COUNT_MASK)) {
   1115             ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
   1116             ndo->ndo_ll_hdr_len += l2info.header_len;
   1117             return;
   1118         }
   1119 
   1120         if (GET_U_1(p) == 0x03) { /* Cisco style NLPID encaps ? */
   1121             /* At least one byte is required */
   1122             ND_TCHECK_LEN(p, 1);
   1123             isoclns_print(ndo, p + 1, l2info.length - 1);
   1124             /* FIXME check if frame was recognized */
   1125             ndo->ndo_ll_hdr_len += l2info.header_len;
   1126             return;
   1127         }
   1128 
   1129         if(juniper_ppp_heuristic_guess(ndo, p, l2info.length) != 0) { /* PPPoA vcmux encaps ? */
   1130             ndo->ndo_ll_hdr_len += l2info.header_len;
   1131             return;
   1132         }
   1133 
   1134         if (ip_heuristic_guess(ndo, p, l2info.length) != 0) { /* last try - vcmux encaps ? */
   1135             ndo->ndo_ll_hdr_len += l2info.header_len;
   1136             return;
   1137         }
   1138 
   1139         ndo->ndo_ll_hdr_len += l2info.header_len;
   1140 }
   1141 
   1142 /* try to guess, based on all PPP protos that are supported in
   1143  * a juniper router if the payload data is encapsulated using PPP */
   1144 static int
   1145 juniper_ppp_heuristic_guess(netdissect_options *ndo,
   1146                             const u_char *p, u_int length)
   1147 {
   1148     switch(GET_BE_U_2(p)) {
   1149     case PPP_IP :
   1150     case PPP_OSI :
   1151     case PPP_MPLS_UCAST :
   1152     case PPP_MPLS_MCAST :
   1153     case PPP_IPCP :
   1154     case PPP_OSICP :
   1155     case PPP_MPLSCP :
   1156     case PPP_LCP :
   1157     case PPP_PAP :
   1158     case PPP_CHAP :
   1159     case PPP_ML :
   1160     case PPP_IPV6 :
   1161     case PPP_IPV6CP :
   1162         ppp_print(ndo, p, length);
   1163         break;
   1164 
   1165     default:
   1166         return 0; /* did not find a ppp header */
   1167         break;
   1168     }
   1169     return 1; /* we printed a ppp packet */
   1170 }
   1171 #endif
   1172 
   1173 static int
   1174 ip_heuristic_guess(netdissect_options *ndo,
   1175                    const u_char *p, u_int length)
   1176 {
   1177     switch(GET_U_1(p)) {
   1178     case 0x45:
   1179     case 0x46:
   1180     case 0x47:
   1181     case 0x48:
   1182     case 0x49:
   1183     case 0x4a:
   1184     case 0x4b:
   1185     case 0x4c:
   1186     case 0x4d:
   1187     case 0x4e:
   1188     case 0x4f:
   1189         ip_print(ndo, p, length);
   1190         break;
   1191     case 0x60:
   1192     case 0x61:
   1193     case 0x62:
   1194     case 0x63:
   1195     case 0x64:
   1196     case 0x65:
   1197     case 0x66:
   1198     case 0x67:
   1199     case 0x68:
   1200     case 0x69:
   1201     case 0x6a:
   1202     case 0x6b:
   1203     case 0x6c:
   1204     case 0x6d:
   1205     case 0x6e:
   1206     case 0x6f:
   1207         ip6_print(ndo, p, length);
   1208         break;
   1209     default:
   1210         return 0; /* did not find a ip header */
   1211         break;
   1212     }
   1213     return 1; /* we printed an v4/v6 packet */
   1214 }
   1215 
   1216 static int
   1217 juniper_read_tlv_value(netdissect_options *ndo,
   1218 		       const u_char *p, u_int tlv_type, u_int tlv_len)
   1219 {
   1220    int tlv_value;
   1221 
   1222    /* TLVs < 128 are little endian encoded */
   1223    if (tlv_type < 128) {
   1224        switch (tlv_len) {
   1225        case 1:
   1226            tlv_value = GET_U_1(p);
   1227            break;
   1228        case 2:
   1229            tlv_value = GET_LE_U_2(p);
   1230            break;
   1231        case 3:
   1232            tlv_value = GET_LE_U_3(p);
   1233            break;
   1234        case 4:
   1235            tlv_value = GET_LE_U_4(p);
   1236            break;
   1237        default:
   1238            tlv_value = -1;
   1239            break;
   1240        }
   1241    } else {
   1242        /* TLVs >= 128 are big endian encoded */
   1243        switch (tlv_len) {
   1244        case 1:
   1245            tlv_value = GET_U_1(p);
   1246            break;
   1247        case 2:
   1248            tlv_value = GET_BE_U_2(p);
   1249            break;
   1250        case 3:
   1251            tlv_value = GET_BE_U_3(p);
   1252            break;
   1253        case 4:
   1254            tlv_value = GET_BE_U_4(p);
   1255            break;
   1256        default:
   1257            tlv_value = -1;
   1258            break;
   1259        }
   1260    }
   1261    return tlv_value;
   1262 }
   1263 
   1264 static int
   1265 juniper_parse_header(netdissect_options *ndo,
   1266                      const u_char *p, const struct pcap_pkthdr *h, struct juniper_l2info_t *l2info)
   1267 {
   1268     const struct juniper_cookie_table_t *lp;
   1269     u_int idx, extension_length, jnx_header_len = 0;
   1270     uint8_t tlv_type,tlv_len;
   1271 #ifdef DLT_JUNIPER_ATM2
   1272     uint32_t control_word;
   1273 #endif
   1274     int tlv_value;
   1275     const u_char *tptr;
   1276 
   1277 
   1278     l2info->header_len = 0;
   1279     l2info->cookie_len = 0;
   1280     l2info->proto = 0;
   1281 
   1282 
   1283     l2info->length = h->len;
   1284     l2info->caplen = h->caplen;
   1285     l2info->flags = GET_U_1(p + 3);
   1286     l2info->direction = GET_U_1(p + 3) & JUNIPER_BPF_PKT_IN;
   1287 
   1288     if (GET_BE_U_3(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */
   1289         ND_PRINT("no magic-number found!");
   1290         return 0;
   1291     }
   1292 
   1293     if (ndo->ndo_eflag) /* print direction */
   1294         ND_PRINT("%3s ", tok2str(juniper_direction_values, "---", l2info->direction));
   1295 
   1296     /* magic number + flags */
   1297     jnx_header_len = 4;
   1298 
   1299     if (ndo->ndo_vflag > 1)
   1300         ND_PRINT("\n\tJuniper PCAP Flags [%s]",
   1301                bittok2str(jnx_flag_values, "none", l2info->flags));
   1302 
   1303     /* extensions present ?  - calculate how much bytes to skip */
   1304     if ((l2info->flags & JUNIPER_BPF_EXT ) == JUNIPER_BPF_EXT ) {
   1305 
   1306         tptr = p+jnx_header_len;
   1307 
   1308         /* ok to read extension length ? */
   1309         extension_length = GET_BE_U_2(tptr);
   1310         jnx_header_len += 2;
   1311         tptr +=2;
   1312 
   1313         /* nail up the total length -
   1314          * just in case something goes wrong
   1315          * with TLV parsing */
   1316         jnx_header_len += extension_length;
   1317 
   1318         if (ndo->ndo_vflag > 1)
   1319             ND_PRINT(", PCAP Extension(s) total length %u", extension_length);
   1320 
   1321         ND_TCHECK_LEN(tptr, extension_length);
   1322         while (extension_length > JUNIPER_EXT_TLV_OVERHEAD) {
   1323             tlv_type = GET_U_1(tptr);
   1324             tptr++;
   1325             tlv_len = GET_U_1(tptr);
   1326             tptr++;
   1327             tlv_value = 0;
   1328 
   1329             /* sanity checks */
   1330             if (tlv_type == 0 || tlv_len == 0)
   1331                 break;
   1332             ND_ICHECK_U(extension_length, <,
   1333                         tlv_len + JUNIPER_EXT_TLV_OVERHEAD);
   1334 
   1335             if (ndo->ndo_vflag > 1)
   1336                 ND_PRINT("\n\t  %s Extension TLV #%u, length %u, value ",
   1337                        tok2str(jnx_ext_tlv_values,"Unknown",tlv_type),
   1338                        tlv_type,
   1339                        tlv_len);
   1340 
   1341             tlv_value = juniper_read_tlv_value(ndo, tptr, tlv_type, tlv_len);
   1342             switch (tlv_type) {
   1343             case JUNIPER_EXT_TLV_IFD_NAME:
   1344                 /* FIXME */
   1345                 break;
   1346             case JUNIPER_EXT_TLV_IFD_MEDIATYPE:
   1347             case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE:
   1348                 if (tlv_value != -1) {
   1349                     if (ndo->ndo_vflag > 1)
   1350                         ND_PRINT("%s (%u)",
   1351                                tok2str(juniper_ifmt_values, "Unknown", tlv_value),
   1352                                tlv_value);
   1353                 }
   1354                 break;
   1355             case JUNIPER_EXT_TLV_IFL_ENCAPS:
   1356             case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS:
   1357                 if (tlv_value != -1) {
   1358                     if (ndo->ndo_vflag > 1)
   1359                         ND_PRINT("%s (%u)",
   1360                                tok2str(juniper_ifle_values, "Unknown", tlv_value),
   1361                                tlv_value);
   1362                 }
   1363                 break;
   1364             case JUNIPER_EXT_TLV_IFL_IDX: /* fall through */
   1365             case JUNIPER_EXT_TLV_IFL_UNIT:
   1366             case JUNIPER_EXT_TLV_IFD_IDX:
   1367             default:
   1368                 if (tlv_value != -1) {
   1369                     if (ndo->ndo_vflag > 1)
   1370                         ND_PRINT("%u", tlv_value);
   1371                 }
   1372                 break;
   1373             }
   1374 
   1375             tptr+=tlv_len;
   1376             extension_length -= tlv_len+JUNIPER_EXT_TLV_OVERHEAD;
   1377         }
   1378 
   1379         if (ndo->ndo_vflag > 1)
   1380             ND_PRINT("\n\t-----original packet-----\n\t");
   1381     }
   1382 
   1383     if ((l2info->flags & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) {
   1384         if (ndo->ndo_eflag)
   1385             ND_PRINT("no-L2-hdr, ");
   1386 
   1387         /* there is no link-layer present -
   1388          * perform the v4/v6 heuristics
   1389          * to figure out what it is
   1390          */
   1391         ND_TCHECK_1(p + (jnx_header_len + 4));
   1392         if (ip_heuristic_guess(ndo, p + jnx_header_len + 4,
   1393                                l2info->length - (jnx_header_len + 4)) == 0)
   1394             ND_PRINT("no IP-hdr found!");
   1395 
   1396         l2info->header_len=jnx_header_len+4;
   1397         return 0; /* stop parsing the output further */
   1398 
   1399     }
   1400     l2info->header_len = jnx_header_len;
   1401     p+=l2info->header_len;
   1402     l2info->length -= l2info->header_len;
   1403     l2info->caplen -= l2info->header_len;
   1404 
   1405     /* search through the cookie table for one matching our PIC type */
   1406     lp = NULL;
   1407     for (const struct juniper_cookie_table_t *table_lp = juniper_cookie_table;
   1408          table_lp->s != NULL; table_lp++) {
   1409         if (table_lp->pictype == l2info->pictype) {
   1410             lp = table_lp;
   1411             break;
   1412         }
   1413     }
   1414 
   1415     /* If we found one matching our PIC type, copy its values */
   1416     if (lp != NULL) {
   1417         l2info->cookie_len += lp->cookie_len;
   1418 
   1419         switch (GET_U_1(p)) {
   1420         case LS_COOKIE_ID:
   1421             l2info->cookie_type = LS_COOKIE_ID;
   1422             l2info->cookie_len += 2;
   1423             break;
   1424         case AS_COOKIE_ID:
   1425             l2info->cookie_type = AS_COOKIE_ID;
   1426             l2info->cookie_len = 8;
   1427             break;
   1428 
   1429         default:
   1430             l2info->bundle = l2info->cookie[0];
   1431             break;
   1432         }
   1433 
   1434 
   1435 #ifdef DLT_JUNIPER_MFR
   1436         /* MFR child links don't carry cookies */
   1437         if (l2info->pictype == DLT_JUNIPER_MFR &&
   1438             (GET_U_1(p) & MFR_BE_MASK) == MFR_BE_MASK) {
   1439             l2info->cookie_len = 0;
   1440         }
   1441 #endif
   1442 
   1443         l2info->header_len += l2info->cookie_len;
   1444         l2info->length -= l2info->cookie_len;
   1445         l2info->caplen -= l2info->cookie_len;
   1446 
   1447         if (ndo->ndo_eflag)
   1448             ND_PRINT("%s-PIC, cookie-len %u",
   1449                    lp->s,
   1450                    l2info->cookie_len);
   1451 
   1452         if (l2info->cookie_len > 8) {
   1453             nd_print_invalid(ndo);
   1454             return 0;
   1455         }
   1456 
   1457         if (l2info->cookie_len > 0) {
   1458             ND_TCHECK_LEN(p, l2info->cookie_len);
   1459             if (ndo->ndo_eflag)
   1460                 ND_PRINT(", cookie 0x");
   1461             for (idx = 0; idx < l2info->cookie_len; idx++) {
   1462                 l2info->cookie[idx] = GET_U_1(p + idx); /* copy cookie data */
   1463                 if (ndo->ndo_eflag) ND_PRINT("%02x", GET_U_1(p + idx));
   1464             }
   1465         }
   1466 
   1467         if (ndo->ndo_eflag) ND_PRINT(": "); /* print demarc b/w L2/L3*/
   1468 
   1469 
   1470         l2info->proto = GET_BE_U_2(p + l2info->cookie_len);
   1471     }
   1472     p+=l2info->cookie_len;
   1473 
   1474     /* DLT_ specific parsing */
   1475     switch(l2info->pictype) {
   1476 #ifdef DLT_JUNIPER_MLPPP
   1477     case DLT_JUNIPER_MLPPP:
   1478         switch (l2info->cookie_type) {
   1479         case LS_COOKIE_ID:
   1480             l2info->bundle = l2info->cookie[1];
   1481             break;
   1482         case AS_COOKIE_ID:
   1483             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
   1484             l2info->bundle = (EXTRACT_BE_U_2(&l2info->cookie[6])>>3)&0xfff;
   1485             l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
   1486             break;
   1487         default:
   1488             l2info->bundle = l2info->cookie[0];
   1489             break;
   1490         }
   1491         break;
   1492 #endif
   1493 #ifdef DLT_JUNIPER_MLFR
   1494     case DLT_JUNIPER_MLFR:
   1495         switch (l2info->cookie_type) {
   1496         case LS_COOKIE_ID:
   1497             l2info->bundle = l2info->cookie[1];
   1498             l2info->proto = GET_BE_U_2(p);
   1499             l2info->header_len += 2;
   1500             l2info->length -= 2;
   1501             l2info->caplen -= 2;
   1502             break;
   1503         case AS_COOKIE_ID:
   1504             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
   1505             l2info->bundle = (EXTRACT_BE_U_2(&l2info->cookie[6])>>3)&0xfff;
   1506             l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
   1507             break;
   1508         default:
   1509             l2info->bundle = l2info->cookie[0];
   1510             l2info->header_len += 2;
   1511             l2info->length -= 2;
   1512             l2info->caplen -= 2;
   1513             break;
   1514         }
   1515         break;
   1516 #endif
   1517 #ifdef DLT_JUNIPER_MFR
   1518     case DLT_JUNIPER_MFR:
   1519         switch (l2info->cookie_type) {
   1520         case LS_COOKIE_ID:
   1521             l2info->bundle = l2info->cookie[1];
   1522             l2info->proto = GET_BE_U_2(p);
   1523             l2info->header_len += 2;
   1524             l2info->length -= 2;
   1525             l2info->caplen -= 2;
   1526             break;
   1527         case AS_COOKIE_ID:
   1528             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
   1529             l2info->bundle = (EXTRACT_BE_U_2(&l2info->cookie[6])>>3)&0xfff;
   1530             l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
   1531             break;
   1532         default:
   1533             l2info->bundle = l2info->cookie[0];
   1534             break;
   1535         }
   1536         break;
   1537 #endif
   1538 #ifdef DLT_JUNIPER_ATM2
   1539     case DLT_JUNIPER_ATM2:
   1540         ND_TCHECK_4(p);
   1541         /* ATM cell relay control word present ? */
   1542         if (l2info->cookie[7] & ATM2_PKT_TYPE_MASK) {
   1543             control_word = GET_BE_U_4(p);
   1544             /* some control word heuristics */
   1545             switch(control_word) {
   1546             case 0: /* zero control word */
   1547             case 0x08000000: /* < JUNOS 7.4 control-word */
   1548             case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
   1549                 l2info->header_len += 4;
   1550                 break;
   1551             default:
   1552                 break;
   1553             }
   1554 
   1555             if (ndo->ndo_eflag)
   1556                 ND_PRINT("control-word 0x%08x ", control_word);
   1557         }
   1558         break;
   1559 #endif
   1560 #ifdef DLT_JUNIPER_ES
   1561     case DLT_JUNIPER_ES:
   1562         break;
   1563 #endif
   1564 #ifdef DLT_JUNIPER_GGSN
   1565     case DLT_JUNIPER_GGSN:
   1566         break;
   1567 #endif
   1568 #ifdef DLT_JUNIPER_SERVICES
   1569     case DLT_JUNIPER_SERVICES:
   1570         break;
   1571 #endif
   1572 #ifdef DLT_JUNIPER_ATM1
   1573     case DLT_JUNIPER_ATM1:
   1574         break;
   1575 #endif
   1576 #ifdef DLT_JUNIPER_PPP
   1577     case DLT_JUNIPER_PPP:
   1578         break;
   1579 #endif
   1580 #ifdef DLT_JUNIPER_CHDLC
   1581     case DLT_JUNIPER_CHDLC:
   1582         break;
   1583 #endif
   1584 #ifdef DLT_JUNIPER_ETHER
   1585     case DLT_JUNIPER_ETHER:
   1586         break;
   1587 #endif
   1588 #ifdef DLT_JUNIPER_FRELAY
   1589     case DLT_JUNIPER_FRELAY:
   1590         break;
   1591 #endif
   1592 #ifdef DLT_JUNIPER_MONITOR
   1593     case DLT_JUNIPER_MONITOR:
   1594         break;
   1595 #endif
   1596 #ifdef DLT_JUNIPER_PPPOE
   1597     case DLT_JUNIPER_PPPOE:
   1598         break;
   1599 #endif
   1600 #ifdef DLT_JUNIPER_PPPOE_ATM
   1601     case DLT_JUNIPER_PPPOE_ATM:
   1602         break;
   1603 #endif
   1604 
   1605     default:
   1606         ND_PRINT("Unknown Juniper DLT_ type %u: ", l2info->pictype);
   1607         break;
   1608     }
   1609 
   1610     if (ndo->ndo_eflag)
   1611         ND_PRINT("hlen %u, proto 0x%04x, ", l2info->header_len, l2info->proto);
   1612 
   1613     return 1; /* everything went ok so far. continue parsing */
   1614 invalid:
   1615     nd_print_invalid(ndo);
   1616     return 0;
   1617 }
   1618 #endif /* defined(DLT_JUNIPER_GGSN) || defined(DLT_JUNIPER_ES) || \
   1619           defined(DLT_JUNIPER_MONITOR) || defined(DLT_JUNIPER_SERVICES) || \
   1620           defined(DLT_JUNIPER_PPPOE) || defined(DLT_JUNIPER_ETHER) || \
   1621           defined(DLT_JUNIPER_PPP) || defined(DLT_JUNIPER_FRELAY) || \
   1622           defined(DLT_JUNIPER_CHDLC) || defined(DLT_JUNIPER_PPPOE_ATM) || \
   1623           defined(DLT_JUNIPER_MLPPP) || defined(DLT_JUNIPER_MFR) || \
   1624           defined(DLT_JUNIPER_MLFR) || defined(DLT_JUNIPER_ATM1) || \
   1625           defined(DLT_JUNIPER_ATM2) */
   1626