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