1 /* NetBSD: print-juniper.c,v 1.2 2007/07/24 11:53:45 drochner Exp */
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.
15 * Original code by Hannes Gredler (hannes@juniper.net)
20 __RCSID("NetBSD: print-juniper.c,v 1.3 2007/07/25 06:31:32 dogcow Exp ");
27 #include <tcpdump-stdinc.h>
31 #include "interface.h"
32 #include "addrtoname.h"
37 #include "ethertype.h"
40 #define JUNIPER_BPF_OUT 0 /* Outgoing packet */
41 #define JUNIPER_BPF_IN 1 /* Incoming packet */
42 #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */
43 #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */
44 #define JUNIPER_BPF_IIF 0x4 /* IIF is valid */
45 #define JUNIPER_BPF_FILTER 0x40 /* BPF filtering is supported */
46 #define JUNIPER_BPF_EXT 0x80 /* extensions present */
47 #define JUNIPER_MGC_NUMBER 0x4d4743 /* = "MGC" */
49 #define JUNIPER_LSQ_COOKIE_RE (1 << 3)
50 #define JUNIPER_LSQ_COOKIE_DIR (1 << 2)
51 #define JUNIPER_LSQ_L3_PROTO_SHIFT 4
52 #define JUNIPER_LSQ_L3_PROTO_MASK (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT)
53 #define JUNIPER_LSQ_L3_PROTO_IPV4 (0 << JUNIPER_LSQ_L3_PROTO_SHIFT)
54 #define JUNIPER_LSQ_L3_PROTO_IPV6 (1 << JUNIPER_LSQ_L3_PROTO_SHIFT)
55 #define JUNIPER_LSQ_L3_PROTO_MPLS (2 << JUNIPER_LSQ_L3_PROTO_SHIFT)
56 #define JUNIPER_LSQ_L3_PROTO_ISO (3 << JUNIPER_LSQ_L3_PROTO_SHIFT)
57 #define AS_PIC_COOKIE_LEN 8
59 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1
60 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2
61 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3
62 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4
63 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5
65 static const struct tok juniper_ipsec_type_values
[] = {
66 { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
, "ESP ENCR-AUTH" },
67 { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
, "ESP ENCR-AH AUTH" },
68 { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
, "ESP AUTH" },
69 { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
, "AH AUTH" },
70 { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
, "ESP ENCR" },
74 static const struct tok juniper_direction_values
[] = {
75 { JUNIPER_BPF_IN
, "In"},
76 { JUNIPER_BPF_OUT
, "Out"},
80 /* codepoints for encoding extensions to a .pcap file */
82 JUNIPER_EXT_TLV_IFD_IDX
= 1,
83 JUNIPER_EXT_TLV_IFD_NAME
= 2,
84 JUNIPER_EXT_TLV_IFD_MEDIATYPE
= 3,
85 JUNIPER_EXT_TLV_IFL_IDX
= 4,
86 JUNIPER_EXT_TLV_IFL_UNIT
= 5,
87 JUNIPER_EXT_TLV_IFL_ENCAPS
= 6,
88 JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
= 7,
89 JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
= 8
92 /* 1 byte type and 1-byte length */
93 #define JUNIPER_EXT_TLV_OVERHEAD 2
95 static const struct tok jnx_ext_tlv_values
[] = {
96 { JUNIPER_EXT_TLV_IFD_IDX
, "Device Interface Index" },
97 { JUNIPER_EXT_TLV_IFD_NAME
,"Device Interface Name" },
98 { JUNIPER_EXT_TLV_IFD_MEDIATYPE
, "Device Media Type" },
99 { JUNIPER_EXT_TLV_IFL_IDX
, "Logical Interface Index" },
100 { JUNIPER_EXT_TLV_IFL_UNIT
,"Logical Unit Number" },
101 { JUNIPER_EXT_TLV_IFL_ENCAPS
, "Logical Interface Encapsulation" },
102 { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
, "TTP derived Device Media Type" },
103 { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
, "TTP derived Logical Interface Encapsulation" },
107 static const struct tok jnx_flag_values
[] = {
108 { JUNIPER_BPF_EXT
, "Ext" },
109 { JUNIPER_BPF_FILTER
, "Filter" },
110 { JUNIPER_BPF_IIF
, "IIF" },
111 { JUNIPER_BPF_NO_L2
, "no-L2" },
112 { JUNIPER_BPF_PKT_IN
, "In" },
116 #define JUNIPER_IFML_ETHER 1
117 #define JUNIPER_IFML_FDDI 2
118 #define JUNIPER_IFML_TOKENRING 3
119 #define JUNIPER_IFML_PPP 4
120 #define JUNIPER_IFML_FRAMERELAY 5
121 #define JUNIPER_IFML_CISCOHDLC 6
122 #define JUNIPER_IFML_SMDSDXI 7
123 #define JUNIPER_IFML_ATMPVC 8
124 #define JUNIPER_IFML_PPP_CCC 9
125 #define JUNIPER_IFML_FRAMERELAY_CCC 10
126 #define JUNIPER_IFML_IPIP 11
127 #define JUNIPER_IFML_GRE 12
128 #define JUNIPER_IFML_PIM 13
129 #define JUNIPER_IFML_PIMD 14
130 #define JUNIPER_IFML_CISCOHDLC_CCC 15
131 #define JUNIPER_IFML_VLAN_CCC 16
132 #define JUNIPER_IFML_MLPPP 17
133 #define JUNIPER_IFML_MLFR 18
134 #define JUNIPER_IFML_ML 19
135 #define JUNIPER_IFML_LSI 20
136 #define JUNIPER_IFML_DFE 21
137 #define JUNIPER_IFML_ATM_CELLRELAY_CCC 22
138 #define JUNIPER_IFML_CRYPTO 23
139 #define JUNIPER_IFML_GGSN 24
140 #define JUNIPER_IFML_LSI_PPP 25
141 #define JUNIPER_IFML_LSI_CISCOHDLC 26
142 #define JUNIPER_IFML_PPP_TCC 27
143 #define JUNIPER_IFML_FRAMERELAY_TCC 28
144 #define JUNIPER_IFML_CISCOHDLC_TCC 29
145 #define JUNIPER_IFML_ETHERNET_CCC 30
146 #define JUNIPER_IFML_VT 31
147 #define JUNIPER_IFML_EXTENDED_VLAN_CCC 32
148 #define JUNIPER_IFML_ETHER_OVER_ATM 33
149 #define JUNIPER_IFML_MONITOR 34
150 #define JUNIPER_IFML_ETHERNET_TCC 35
151 #define JUNIPER_IFML_VLAN_TCC 36
152 #define JUNIPER_IFML_EXTENDED_VLAN_TCC 37
153 #define JUNIPER_IFML_CONTROLLER 38
154 #define JUNIPER_IFML_MFR 39
155 #define JUNIPER_IFML_LS 40
156 #define JUNIPER_IFML_ETHERNET_VPLS 41
157 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42
158 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43
159 #define JUNIPER_IFML_LT 44
160 #define JUNIPER_IFML_SERVICES 45
161 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46
162 #define JUNIPER_IFML_FR_PORT_CCC 47
163 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48
164 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49
165 #define JUNIPER_IFML_FRAMERELAY_FLEX 50
166 #define JUNIPER_IFML_GGSNI 51
167 #define JUNIPER_IFML_ETHERNET_FLEX 52
168 #define JUNIPER_IFML_COLLECTOR 53
169 #define JUNIPER_IFML_AGGREGATOR 54
170 #define JUNIPER_IFML_LAPD 55
171 #define JUNIPER_IFML_PPPOE 56
172 #define JUNIPER_IFML_PPP_SUBORDINATE 57
173 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE 58
174 #define JUNIPER_IFML_DFC 59
175 #define JUNIPER_IFML_PICPEER 60
177 static const struct tok juniper_ifmt_values
[] = {
178 { JUNIPER_IFML_ETHER
, "Ethernet" },
179 { JUNIPER_IFML_FDDI
, "FDDI" },
180 { JUNIPER_IFML_TOKENRING
, "Token-Ring" },
181 { JUNIPER_IFML_PPP
, "PPP" },
182 { JUNIPER_IFML_PPP_SUBORDINATE
, "PPP-Subordinate" },
183 { JUNIPER_IFML_FRAMERELAY
, "Frame-Relay" },
184 { JUNIPER_IFML_CISCOHDLC
, "Cisco-HDLC" },
185 { JUNIPER_IFML_SMDSDXI
, "SMDS-DXI" },
186 { JUNIPER_IFML_ATMPVC
, "ATM-PVC" },
187 { JUNIPER_IFML_PPP_CCC
, "PPP-CCC" },
188 { JUNIPER_IFML_FRAMERELAY_CCC
, "Frame-Relay-CCC" },
189 { JUNIPER_IFML_FRAMERELAY_EXT_CCC
, "Extended FR-CCC" },
190 { JUNIPER_IFML_IPIP
, "IP-over-IP" },
191 { JUNIPER_IFML_GRE
, "GRE" },
192 { JUNIPER_IFML_PIM
, "PIM-Encapsulator" },
193 { JUNIPER_IFML_PIMD
, "PIM-Decapsulator" },
194 { JUNIPER_IFML_CISCOHDLC_CCC
, "Cisco-HDLC-CCC" },
195 { JUNIPER_IFML_VLAN_CCC
, "VLAN-CCC" },
196 { JUNIPER_IFML_EXTENDED_VLAN_CCC
, "Extended-VLAN-CCC" },
197 { JUNIPER_IFML_MLPPP
, "Multilink-PPP" },
198 { JUNIPER_IFML_MLFR
, "Multilink-FR" },
199 { JUNIPER_IFML_MFR
, "Multilink-FR-UNI-NNI" },
200 { JUNIPER_IFML_ML
, "Multilink" },
201 { JUNIPER_IFML_LS
, "LinkService" },
202 { JUNIPER_IFML_LSI
, "LSI" },
203 { JUNIPER_IFML_ATM_CELLRELAY_CCC
, "ATM-CCC-Cell-Relay" },
204 { JUNIPER_IFML_CRYPTO
, "IPSEC-over-IP" },
205 { JUNIPER_IFML_GGSN
, "GGSN" },
206 { JUNIPER_IFML_PPP_TCC
, "PPP-TCC" },
207 { JUNIPER_IFML_FRAMERELAY_TCC
, "Frame-Relay-TCC" },
208 { JUNIPER_IFML_FRAMERELAY_EXT_TCC
, "Extended FR-TCC" },
209 { JUNIPER_IFML_CISCOHDLC_TCC
, "Cisco-HDLC-TCC" },
210 { JUNIPER_IFML_ETHERNET_CCC
, "Ethernet-CCC" },
211 { JUNIPER_IFML_VT
, "VPN-Loopback-tunnel" },
212 { JUNIPER_IFML_ETHER_OVER_ATM
, "Ethernet-over-ATM" },
213 { JUNIPER_IFML_ETHER_VPLS_OVER_ATM
, "Ethernet-VPLS-over-ATM" },
214 { JUNIPER_IFML_MONITOR
, "Monitor" },
215 { JUNIPER_IFML_ETHERNET_TCC
, "Ethernet-TCC" },
216 { JUNIPER_IFML_VLAN_TCC
, "VLAN-TCC" },
217 { JUNIPER_IFML_EXTENDED_VLAN_TCC
, "Extended-VLAN-TCC" },
218 { JUNIPER_IFML_CONTROLLER
, "Controller" },
219 { JUNIPER_IFML_ETHERNET_VPLS
, "VPLS" },
220 { JUNIPER_IFML_ETHERNET_VLAN_VPLS
, "VLAN-VPLS" },
221 { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended-VLAN-VPLS" },
222 { JUNIPER_IFML_LT
, "Logical-tunnel" },
223 { JUNIPER_IFML_SERVICES
, "General-Services" },
224 { JUNIPER_IFML_PPPOE
, "PPPoE" },
225 { JUNIPER_IFML_ETHERNET_FLEX
, "Flexible-Ethernet-Services" },
226 { JUNIPER_IFML_FRAMERELAY_FLEX
, "Flexible-FrameRelay" },
227 { JUNIPER_IFML_COLLECTOR
, "Flow-collection" },
228 { JUNIPER_IFML_PICPEER
, "PIC Peer" },
229 { JUNIPER_IFML_DFC
, "Dynamic-Flow-Capture" },
233 #define JUNIPER_IFLE_ATM_SNAP 2
234 #define JUNIPER_IFLE_ATM_NLPID 3
235 #define JUNIPER_IFLE_ATM_VCMUX 4
236 #define JUNIPER_IFLE_ATM_LLC 5
237 #define JUNIPER_IFLE_ATM_PPP_VCMUX 6
238 #define JUNIPER_IFLE_ATM_PPP_LLC 7
239 #define JUNIPER_IFLE_ATM_PPP_FUNI 8
240 #define JUNIPER_IFLE_ATM_CCC 9
241 #define JUNIPER_IFLE_FR_NLPID 10
242 #define JUNIPER_IFLE_FR_SNAP 11
243 #define JUNIPER_IFLE_FR_PPP 12
244 #define JUNIPER_IFLE_FR_CCC 13
245 #define JUNIPER_IFLE_ENET2 14
246 #define JUNIPER_IFLE_IEEE8023_SNAP 15
247 #define JUNIPER_IFLE_IEEE8023_LLC 16
248 #define JUNIPER_IFLE_PPP 17
249 #define JUNIPER_IFLE_CISCOHDLC 18
250 #define JUNIPER_IFLE_PPP_CCC 19
251 #define JUNIPER_IFLE_IPIP_NULL 20
252 #define JUNIPER_IFLE_PIM_NULL 21
253 #define JUNIPER_IFLE_GRE_NULL 22
254 #define JUNIPER_IFLE_GRE_PPP 23
255 #define JUNIPER_IFLE_PIMD_DECAPS 24
256 #define JUNIPER_IFLE_CISCOHDLC_CCC 25
257 #define JUNIPER_IFLE_ATM_CISCO_NLPID 26
258 #define JUNIPER_IFLE_VLAN_CCC 27
259 #define JUNIPER_IFLE_MLPPP 28
260 #define JUNIPER_IFLE_MLFR 29
261 #define JUNIPER_IFLE_LSI_NULL 30
262 #define JUNIPER_IFLE_AGGREGATE_UNUSED 31
263 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC 32
264 #define JUNIPER_IFLE_CRYPTO 33
265 #define JUNIPER_IFLE_GGSN 34
266 #define JUNIPER_IFLE_ATM_TCC 35
267 #define JUNIPER_IFLE_FR_TCC 36
268 #define JUNIPER_IFLE_PPP_TCC 37
269 #define JUNIPER_IFLE_CISCOHDLC_TCC 38
270 #define JUNIPER_IFLE_ETHERNET_CCC 39
271 #define JUNIPER_IFLE_VT 40
272 #define JUNIPER_IFLE_ATM_EOA_LLC 41
273 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC 42
274 #define JUNIPER_IFLE_ATM_SNAP_TCC 43
275 #define JUNIPER_IFLE_MONITOR 44
276 #define JUNIPER_IFLE_ETHERNET_TCC 45
277 #define JUNIPER_IFLE_VLAN_TCC 46
278 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC 47
279 #define JUNIPER_IFLE_MFR 48
280 #define JUNIPER_IFLE_ETHERNET_VPLS 49
281 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50
282 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51
283 #define JUNIPER_IFLE_SERVICES 52
284 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC 53
285 #define JUNIPER_IFLE_FR_PORT_CCC 54
286 #define JUNIPER_IFLE_ATM_MLPPP_LLC 55
287 #define JUNIPER_IFLE_ATM_EOA_CCC 56
288 #define JUNIPER_IFLE_LT_VLAN 57
289 #define JUNIPER_IFLE_COLLECTOR 58
290 #define JUNIPER_IFLE_AGGREGATOR 59
291 #define JUNIPER_IFLE_LAPD 60
292 #define JUNIPER_IFLE_ATM_PPPOE_LLC 61
293 #define JUNIPER_IFLE_ETHERNET_PPPOE 62
294 #define JUNIPER_IFLE_PPPOE 63
295 #define JUNIPER_IFLE_PPP_SUBORDINATE 64
296 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE 65
297 #define JUNIPER_IFLE_DFC 66
298 #define JUNIPER_IFLE_PICPEER 67
300 static const struct tok juniper_ifle_values
[] = {
301 { JUNIPER_IFLE_AGGREGATOR
, "Aggregator" },
302 { JUNIPER_IFLE_ATM_CCC
, "CCC over ATM" },
303 { JUNIPER_IFLE_ATM_CELLRELAY_CCC
, "ATM CCC Cell Relay" },
304 { JUNIPER_IFLE_ATM_CISCO_NLPID
, "CISCO compatible NLPID" },
305 { JUNIPER_IFLE_ATM_EOA_CCC
, "Ethernet over ATM CCC" },
306 { JUNIPER_IFLE_ATM_EOA_LLC
, "Ethernet over ATM LLC" },
307 { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC
, "Ethernet VPLS over ATM LLC" },
308 { JUNIPER_IFLE_ATM_LLC
, "ATM LLC" },
309 { JUNIPER_IFLE_ATM_MLPPP_LLC
, "MLPPP over ATM LLC" },
310 { JUNIPER_IFLE_ATM_NLPID
, "ATM NLPID" },
311 { JUNIPER_IFLE_ATM_PPPOE_LLC
, "PPPoE over ATM LLC" },
312 { JUNIPER_IFLE_ATM_PPP_FUNI
, "PPP over FUNI" },
313 { JUNIPER_IFLE_ATM_PPP_LLC
, "PPP over ATM LLC" },
314 { JUNIPER_IFLE_ATM_PPP_VCMUX
, "PPP over ATM VCMUX" },
315 { JUNIPER_IFLE_ATM_SNAP
, "ATM SNAP" },
316 { JUNIPER_IFLE_ATM_SNAP_TCC
, "ATM SNAP TCC" },
317 { JUNIPER_IFLE_ATM_TCC
, "ATM VCMUX TCC" },
318 { JUNIPER_IFLE_ATM_VCMUX
, "ATM VCMUX" },
319 { JUNIPER_IFLE_CISCOHDLC
, "C-HDLC" },
320 { JUNIPER_IFLE_CISCOHDLC_CCC
, "C-HDLC CCC" },
321 { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE
, "C-HDLC via dialer" },
322 { JUNIPER_IFLE_CISCOHDLC_TCC
, "C-HDLC TCC" },
323 { JUNIPER_IFLE_COLLECTOR
, "Collector" },
324 { JUNIPER_IFLE_CRYPTO
, "Crypto" },
325 { JUNIPER_IFLE_ENET2
, "Ethernet" },
326 { JUNIPER_IFLE_ETHERNET_CCC
, "Ethernet CCC" },
327 { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended VLAN VPLS" },
328 { JUNIPER_IFLE_ETHERNET_PPPOE
, "PPPoE over Ethernet" },
329 { JUNIPER_IFLE_ETHERNET_TCC
, "Ethernet TCC" },
330 { JUNIPER_IFLE_ETHERNET_VLAN_VPLS
, "VLAN VPLS" },
331 { JUNIPER_IFLE_ETHERNET_VPLS
, "VPLS" },
332 { JUNIPER_IFLE_EXTENDED_VLAN_CCC
, "Extended VLAN CCC" },
333 { JUNIPER_IFLE_EXTENDED_VLAN_TCC
, "Extended VLAN TCC" },
334 { JUNIPER_IFLE_FR_CCC
, "FR CCC" },
335 { JUNIPER_IFLE_FR_NLPID
, "FR NLPID" },
336 { JUNIPER_IFLE_FR_PORT_CCC
, "FR CCC" },
337 { JUNIPER_IFLE_FR_PPP
, "FR PPP" },
338 { JUNIPER_IFLE_FR_SNAP
, "FR SNAP" },
339 { JUNIPER_IFLE_FR_TCC
, "FR TCC" },
340 { JUNIPER_IFLE_GGSN
, "GGSN" },
341 { JUNIPER_IFLE_GRE_NULL
, "GRE NULL" },
342 { JUNIPER_IFLE_GRE_PPP
, "PPP over GRE" },
343 { JUNIPER_IFLE_IPIP_NULL
, "IPIP" },
344 { JUNIPER_IFLE_LAPD
, "LAPD" },
345 { JUNIPER_IFLE_LSI_NULL
, "LSI Null" },
346 { JUNIPER_IFLE_LT_VLAN
, "LT VLAN" },
347 { JUNIPER_IFLE_MFR
, "MFR" },
348 { JUNIPER_IFLE_MLFR
, "MLFR" },
349 { JUNIPER_IFLE_MLPPP
, "MLPPP" },
350 { JUNIPER_IFLE_MONITOR
, "Monitor" },
351 { JUNIPER_IFLE_PIMD_DECAPS
, "PIMd" },
352 { JUNIPER_IFLE_PIM_NULL
, "PIM Null" },
353 { JUNIPER_IFLE_PPP
, "PPP" },
354 { JUNIPER_IFLE_PPPOE
, "PPPoE" },
355 { JUNIPER_IFLE_PPP_CCC
, "PPP CCC" },
356 { JUNIPER_IFLE_PPP_SUBORDINATE
, "" },
357 { JUNIPER_IFLE_PPP_TCC
, "PPP TCC" },
358 { JUNIPER_IFLE_SERVICES
, "General Services" },
359 { JUNIPER_IFLE_VLAN_CCC
, "VLAN CCC" },
360 { JUNIPER_IFLE_VLAN_TCC
, "VLAN TCC" },
361 { JUNIPER_IFLE_VT
, "VT" },
365 struct juniper_cookie_table_t
{
366 u_int32_t pictype
; /* pic type */
367 u_int8_t cookie_len
; /* cookie len */
368 const char *s
; /* pic name */
371 static const struct juniper_cookie_table_t juniper_cookie_table
[] = {
372 #ifdef DLT_JUNIPER_ATM1
373 { DLT_JUNIPER_ATM1
, 4, "ATM1"},
375 #ifdef DLT_JUNIPER_ATM2
376 { DLT_JUNIPER_ATM2
, 8, "ATM2"},
378 #ifdef DLT_JUNIPER_MLPPP
379 { DLT_JUNIPER_MLPPP
, 2, "MLPPP"},
381 #ifdef DLT_JUNIPER_MLFR
382 { DLT_JUNIPER_MLFR
, 2, "MLFR"},
384 #ifdef DLT_JUNIPER_MFR
385 { DLT_JUNIPER_MFR
, 4, "MFR"},
387 #ifdef DLT_JUNIPER_PPPOE
388 { DLT_JUNIPER_PPPOE
, 0, "PPPoE"},
390 #ifdef DLT_JUNIPER_PPPOE_ATM
391 { DLT_JUNIPER_PPPOE_ATM
, 0, "PPPoE ATM"},
393 #ifdef DLT_JUNIPER_GGSN
394 { DLT_JUNIPER_GGSN
, 8, "GGSN"},
396 #ifdef DLT_JUNIPER_MONITOR
397 { DLT_JUNIPER_MONITOR
, 8, "MONITOR"},
399 #ifdef DLT_JUNIPER_SERVICES
400 { DLT_JUNIPER_SERVICES
, 8, "AS"},
402 #ifdef DLT_JUNIPER_ES
403 { DLT_JUNIPER_ES
, 0, "ES"},
408 struct juniper_l2info_t
{
415 u_int8_t cookie_type
;
422 #define LS_COOKIE_ID 0x54
423 #define AS_COOKIE_ID 0x47
424 #define LS_MLFR_COOKIE_LEN 4
425 #define ML_MLFR_COOKIE_LEN 2
426 #define LS_MFR_COOKIE_LEN 6
427 #define ATM1_COOKIE_LEN 4
428 #define ATM2_COOKIE_LEN 8
430 #define ATM2_PKT_TYPE_MASK 0x70
431 #define ATM2_GAP_COUNT_MASK 0x3F
433 #define JUNIPER_PROTO_NULL 1
434 #define JUNIPER_PROTO_IPV4 2
435 #define JUNIPER_PROTO_IPV6 6
437 #define MFR_BE_MASK 0xc0
439 static const struct tok juniper_protocol_values
[] = {
440 { JUNIPER_PROTO_NULL
, "Null" },
441 { JUNIPER_PROTO_IPV4
, "IPv4" },
442 { JUNIPER_PROTO_IPV6
, "IPv6" },
446 int ip_heuristic_guess(register const u_char
*, u_int
);
447 int juniper_ppp_heuristic_guess(register const u_char
*, u_int
);
448 int juniper_read_tlv_value(const u_char
*, u_int
, u_int
);
449 static int juniper_parse_header (const u_char
*, const struct pcap_pkthdr
*, struct juniper_l2info_t
*);
451 #ifdef DLT_JUNIPER_GGSN
453 juniper_ggsn_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
455 struct juniper_l2info_t l2info
;
456 struct juniper_ggsn_header
{
464 const struct juniper_ggsn_header
*gh
;
466 l2info
.pictype
= DLT_JUNIPER_GGSN
;
467 if(juniper_parse_header(p
, h
, &l2info
) == 0)
468 return l2info
.header_len
;
470 p
+=l2info
.header_len
;
471 gh
= (struct juniper_ggsn_header
*)&l2info
.cookie
;
474 printf("proto %s (%u), vlan %u: ",
475 tok2str(juniper_protocol_values
,"Unknown",gh
->proto
),
477 EXTRACT_16BITS(&gh
->vlan_id
[0]));
481 case JUNIPER_PROTO_IPV4
:
482 ip_print(gndo
, p
, l2info
.length
);
485 case JUNIPER_PROTO_IPV6
:
486 ip6_print(gndo
, p
, l2info
.length
);
491 printf("unknown GGSN proto (%u)", gh
->proto
);
494 return l2info
.header_len
;
498 #ifdef DLT_JUNIPER_ES
500 juniper_es_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
502 struct juniper_l2info_t l2info
;
503 struct juniper_ipsec_header
{
504 u_int8_t sa_index
[2];
511 u_int rewrite_len
,es_type_bundle
;
512 const struct juniper_ipsec_header
*ih
;
514 l2info
.pictype
= DLT_JUNIPER_ES
;
515 if(juniper_parse_header(p
, h
, &l2info
) == 0)
516 return l2info
.header_len
;
518 p
+=l2info
.header_len
;
519 ih
= (struct juniper_ipsec_header
*)p
;
522 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
523 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
527 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
528 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
529 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
533 printf("ES Invalid type %u, length %u",
536 return l2info
.header_len
;
539 l2info
.length
-=rewrite_len
;
543 if (!es_type_bundle
) {
544 printf("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
545 EXTRACT_16BITS(&ih
->sa_index
),
547 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
549 EXTRACT_32BITS(&ih
->spi
),
550 ipaddr_string(&ih
->src_ip
),
551 ipaddr_string(&ih
->dst_ip
),
554 printf("ES SA, index %u, ttl %u type %s (%u), length %u\n",
555 EXTRACT_16BITS(&ih
->sa_index
),
557 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
563 ip_print(gndo
, p
, l2info
.length
);
564 return l2info
.header_len
;
568 #ifdef DLT_JUNIPER_MONITOR
570 juniper_monitor_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
572 struct juniper_l2info_t l2info
;
573 struct juniper_monitor_header
{
577 u_int8_t service_id
[4];
579 const struct juniper_monitor_header
*mh
;
581 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
582 if(juniper_parse_header(p
, h
, &l2info
) == 0)
583 return l2info
.header_len
;
585 p
+=l2info
.header_len
;
586 mh
= (struct juniper_monitor_header
*)p
;
589 printf("service-id %u, iif %u, pkt-type %u: ",
590 EXTRACT_32BITS(&mh
->service_id
),
591 EXTRACT_16BITS(&mh
->iif
),
594 /* no proto field - lets guess by first byte of IP header*/
595 ip_heuristic_guess(p
, l2info
.length
);
597 return l2info
.header_len
;
601 #ifdef DLT_JUNIPER_SERVICES
603 juniper_services_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
605 struct juniper_l2info_t l2info
;
606 struct juniper_services_header
{
609 u_int8_t svc_set_id
[2];
612 const struct juniper_services_header
*sh
;
614 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
615 if(juniper_parse_header(p
, h
, &l2info
) == 0)
616 return l2info
.header_len
;
618 p
+=l2info
.header_len
;
619 sh
= (struct juniper_services_header
*)p
;
622 printf("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
625 EXTRACT_16BITS(&sh
->svc_set_id
),
626 EXTRACT_24BITS(&sh
->dir_iif
[1]));
628 /* no proto field - lets guess by first byte of IP header*/
629 ip_heuristic_guess(p
, l2info
.length
);
631 return l2info
.header_len
;
635 #ifdef DLT_JUNIPER_PPPOE
637 juniper_pppoe_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
639 struct juniper_l2info_t l2info
;
641 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
642 if(juniper_parse_header(p
, h
, &l2info
) == 0)
643 return l2info
.header_len
;
645 p
+=l2info
.header_len
;
646 /* this DLT contains nothing but raw ethernet frames */
647 ether_print(gndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
648 return l2info
.header_len
;
652 #ifdef DLT_JUNIPER_ETHER
654 juniper_ether_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
656 struct juniper_l2info_t l2info
;
658 l2info
.pictype
= DLT_JUNIPER_ETHER
;
659 if(juniper_parse_header(p
, h
, &l2info
) == 0)
660 return l2info
.header_len
;
662 p
+=l2info
.header_len
;
663 /* this DLT contains nothing but raw Ethernet frames */
664 ether_print(gndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
665 return l2info
.header_len
;
669 #ifdef DLT_JUNIPER_PPP
671 juniper_ppp_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
673 struct juniper_l2info_t l2info
;
675 l2info
.pictype
= DLT_JUNIPER_PPP
;
676 if(juniper_parse_header(p
, h
, &l2info
) == 0)
677 return l2info
.header_len
;
679 p
+=l2info
.header_len
;
680 /* this DLT contains nothing but raw ppp frames */
681 ppp_print(p
, l2info
.length
);
682 return l2info
.header_len
;
686 #ifdef DLT_JUNIPER_FRELAY
688 juniper_frelay_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
690 struct juniper_l2info_t l2info
;
692 l2info
.pictype
= DLT_JUNIPER_FRELAY
;
693 if(juniper_parse_header(p
, h
, &l2info
) == 0)
694 return l2info
.header_len
;
696 p
+=l2info
.header_len
;
697 /* this DLT contains nothing but raw frame-relay frames */
698 fr_print(p
, l2info
.length
);
699 return l2info
.header_len
;
703 #ifdef DLT_JUNIPER_CHDLC
705 juniper_chdlc_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
707 struct juniper_l2info_t l2info
;
709 l2info
.pictype
= DLT_JUNIPER_CHDLC
;
710 if(juniper_parse_header(p
, h
, &l2info
) == 0)
711 return l2info
.header_len
;
713 p
+=l2info
.header_len
;
714 /* this DLT contains nothing but raw c-hdlc frames */
715 chdlc_print(p
, l2info
.length
);
716 return l2info
.header_len
;
720 #ifdef DLT_JUNIPER_PPPOE_ATM
722 juniper_pppoe_atm_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
724 struct juniper_l2info_t l2info
;
725 u_int16_t extracted_ethertype
;
727 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
728 if(juniper_parse_header(p
, h
, &l2info
) == 0)
729 return l2info
.header_len
;
731 p
+=l2info
.header_len
;
733 extracted_ethertype
= EXTRACT_16BITS(p
);
734 /* this DLT contains nothing but raw PPPoE frames,
735 * prepended with a type field*/
736 if (ethertype_print(gndo
, extracted_ethertype
,
738 l2info
.length
-ETHERTYPE_LEN
,
739 l2info
.caplen
-ETHERTYPE_LEN
) == 0)
740 /* ether_type not known, probably it wasn't one */
741 printf("unknown ethertype 0x%04x", extracted_ethertype
);
743 return l2info
.header_len
;
747 #ifdef DLT_JUNIPER_MLPPP
749 juniper_mlppp_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
751 struct juniper_l2info_t l2info
;
753 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
754 if(juniper_parse_header(p
, h
, &l2info
) == 0)
755 return l2info
.header_len
;
757 /* suppress Bundle-ID if frame was captured on a child-link
758 * best indicator if the cookie looks like a proto */
760 EXTRACT_16BITS(&l2info
.cookie
) != PPP_OSI
&&
761 EXTRACT_16BITS(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
762 printf("Bundle-ID %u: ",l2info
.bundle
);
764 p
+=l2info
.header_len
;
766 /* first try the LSQ protos */
767 switch(l2info
.proto
) {
768 case JUNIPER_LSQ_L3_PROTO_IPV4
:
769 /* IP traffic going to the RE would not have a cookie
770 * -> this must be incoming IS-IS over PPP
772 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
773 ppp_print(p
, l2info
.length
);
775 ip_print(gndo
, p
, l2info
.length
);
776 return l2info
.header_len
;
778 case JUNIPER_LSQ_L3_PROTO_IPV6
:
779 ip6_print(gndo
, p
,l2info
.length
);
780 return l2info
.header_len
;
782 case JUNIPER_LSQ_L3_PROTO_MPLS
:
783 mpls_print(p
,l2info
.length
);
784 return l2info
.header_len
;
785 case JUNIPER_LSQ_L3_PROTO_ISO
:
786 isoclns_print(p
,l2info
.length
,l2info
.caplen
);
787 return l2info
.header_len
;
792 /* zero length cookie ? */
793 switch (EXTRACT_16BITS(&l2info
.cookie
)) {
795 ppp_print(p
-2,l2info
.length
+2);
797 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
799 ppp_print(p
,l2info
.length
);
803 return l2info
.header_len
;
808 #ifdef DLT_JUNIPER_MFR
810 juniper_mfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
812 struct juniper_l2info_t l2info
;
814 l2info
.pictype
= DLT_JUNIPER_MFR
;
815 if(juniper_parse_header(p
, h
, &l2info
) == 0)
816 return l2info
.header_len
;
818 p
+=l2info
.header_len
;
821 if (l2info
.cookie_len
== 0) {
822 mfr_print(p
,l2info
.length
);
823 return l2info
.header_len
;
826 /* first try the LSQ protos */
827 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
828 switch(l2info
.proto
) {
829 case JUNIPER_LSQ_L3_PROTO_IPV4
:
830 ip_print(gndo
, p
, l2info
.length
);
831 return l2info
.header_len
;
833 case JUNIPER_LSQ_L3_PROTO_IPV6
:
834 ip6_print(gndo
, p
,l2info
.length
);
835 return l2info
.header_len
;
837 case JUNIPER_LSQ_L3_PROTO_MPLS
:
838 mpls_print(p
,l2info
.length
);
839 return l2info
.header_len
;
840 case JUNIPER_LSQ_L3_PROTO_ISO
:
841 isoclns_print(p
,l2info
.length
,l2info
.caplen
);
842 return l2info
.header_len
;
846 return l2info
.header_len
;
849 /* suppress Bundle-ID if frame was captured on a child-link */
850 if (eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1) printf("Bundle-ID %u, ",l2info
.bundle
);
851 switch (l2info
.proto
) {
852 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
853 isoclns_print(p
+1, l2info
.length
-1, l2info
.caplen
-1);
855 case (LLC_UI
<<8 | NLPID_Q933
):
856 case (LLC_UI
<<8 | NLPID_IP
):
857 case (LLC_UI
<<8 | NLPID_IP6
):
858 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
859 isoclns_print(p
-1, l2info
.length
+1, l2info
.caplen
+1);
862 printf("unknown protocol 0x%04x, length %u",l2info
.proto
, l2info
.length
);
865 return l2info
.header_len
;
869 #ifdef DLT_JUNIPER_MLFR
871 juniper_mlfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
873 struct juniper_l2info_t l2info
;
875 l2info
.pictype
= DLT_JUNIPER_MLFR
;
876 if(juniper_parse_header(p
, h
, &l2info
) == 0)
877 return l2info
.header_len
;
879 p
+=l2info
.header_len
;
881 /* suppress Bundle-ID if frame was captured on a child-link */
882 if (eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1) printf("Bundle-ID %u, ",l2info
.bundle
);
883 switch (l2info
.proto
) {
886 isoclns_print(p
, l2info
.length
, l2info
.caplen
);
888 case (LLC_UI
<<8 | NLPID_Q933
):
889 case (LLC_UI
<<8 | NLPID_IP
):
890 case (LLC_UI
<<8 | NLPID_IP6
):
891 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
892 isoclns_print(p
-1, l2info
.length
+1, l2info
.caplen
+1);
895 printf("unknown protocol 0x%04x, length %u",l2info
.proto
, l2info
.length
);
898 return l2info
.header_len
;
903 * ATM1 PIC cookie format
905 * +-----+-------------------------+-------------------------------+
906 * |fmtid| vc index | channel ID |
907 * +-----+-------------------------+-------------------------------+
910 #ifdef DLT_JUNIPER_ATM1
912 juniper_atm1_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
914 u_int16_t extracted_ethertype
;
916 struct juniper_l2info_t l2info
;
918 l2info
.pictype
= DLT_JUNIPER_ATM1
;
919 if(juniper_parse_header(p
, h
, &l2info
) == 0)
920 return l2info
.header_len
;
922 p
+=l2info
.header_len
;
924 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
925 oam_print(p
,l2info
.length
,ATM_OAM_NOHEC
);
926 return l2info
.header_len
;
929 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
930 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
932 if (llc_print(p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
,
933 &extracted_ethertype
) != 0)
934 return l2info
.header_len
;
937 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
938 isoclns_print(p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
939 /* FIXME check if frame was recognized */
940 return l2info
.header_len
;
943 if(ip_heuristic_guess(p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
944 return l2info
.header_len
;
946 return l2info
.header_len
;
951 * ATM2 PIC cookie format
953 * +-------------------------------+---------+---+-----+-----------+
954 * | channel ID | reserv |AAL| CCRQ| gap cnt |
955 * +-------------------------------+---------+---+-----+-----------+
958 #ifdef DLT_JUNIPER_ATM2
960 juniper_atm2_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
962 u_int16_t extracted_ethertype
;
964 struct juniper_l2info_t l2info
;
966 l2info
.pictype
= DLT_JUNIPER_ATM2
;
967 if(juniper_parse_header(p
, h
, &l2info
) == 0)
968 return l2info
.header_len
;
970 p
+=l2info
.header_len
;
972 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
973 oam_print(p
,l2info
.length
,ATM_OAM_NOHEC
);
974 return l2info
.header_len
;
977 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
978 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
980 if (llc_print(p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
,
981 &extracted_ethertype
) != 0)
982 return l2info
.header_len
;
985 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
986 (EXTRACT_32BITS(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
987 ether_print(gndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
988 return l2info
.header_len
;
991 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
992 isoclns_print(p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
993 /* FIXME check if frame was recognized */
994 return l2info
.header_len
;
997 if(juniper_ppp_heuristic_guess(p
, l2info
.length
) != 0) /* PPPoA vcmux encaps ? */
998 return l2info
.header_len
;
1000 if(ip_heuristic_guess(p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
1001 return l2info
.header_len
;
1003 return l2info
.header_len
;
1008 /* try to guess, based on all PPP protos that are supported in
1009 * a juniper router if the payload data is encapsulated using PPP */
1011 juniper_ppp_heuristic_guess(register const u_char
*p
, u_int length
) {
1013 switch(EXTRACT_16BITS(p
)) {
1016 case PPP_MPLS_UCAST
:
1017 case PPP_MPLS_MCAST
:
1029 ppp_print(p
, length
);
1033 return 0; /* did not find a ppp header */
1036 return 1; /* we printed a ppp packet */
1040 ip_heuristic_guess(register const u_char
*p
, u_int length
) {
1054 ip_print(gndo
, p
, length
);
1073 ip6_print(gndo
, p
, length
);
1077 return 0; /* did not find a ip header */
1080 return 1; /* we printed an v4/v6 packet */
1084 juniper_read_tlv_value(const u_char
*p
, u_int tlv_type
, u_int tlv_len
) {
1088 /* TLVs < 128 are little endian encoded */
1089 if (tlv_type
< 128) {
1095 tlv_value
= EXTRACT_LE_16BITS(p
);
1098 tlv_value
= EXTRACT_LE_24BITS(p
);
1101 tlv_value
= EXTRACT_LE_32BITS(p
);
1108 /* TLVs >= 128 are big endian encoded */
1114 tlv_value
= EXTRACT_16BITS(p
);
1117 tlv_value
= EXTRACT_24BITS(p
);
1120 tlv_value
= EXTRACT_32BITS(p
);
1131 juniper_parse_header (const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
) {
1133 const struct juniper_cookie_table_t
*lp
= juniper_cookie_table
;
1134 u_int idx
, jnx_ext_len
, jnx_header_len
= 0;
1135 u_int8_t tlv_type
,tlv_len
;
1136 u_int32_t control_word
;
1141 l2info
->header_len
= 0;
1142 l2info
->cookie_len
= 0;
1146 l2info
->length
= h
->len
;
1147 l2info
->caplen
= h
->caplen
;
1149 l2info
->flags
= p
[3];
1150 l2info
->direction
= p
[3]&JUNIPER_BPF_PKT_IN
;
1152 if (EXTRACT_24BITS(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
1153 printf("no magic-number found!");
1157 if (eflag
) /* print direction */
1158 printf("%3s ",tok2str(juniper_direction_values
,"---",l2info
->direction
));
1160 /* magic number + flags */
1164 printf("\n\tJuniper PCAP Flags [%s]",
1165 bittok2str(jnx_flag_values
, "none", l2info
->flags
));
1167 /* extensions present ? - calculate how much bytes to skip */
1168 if ((l2info
->flags
& JUNIPER_BPF_EXT
) == JUNIPER_BPF_EXT
) {
1170 tptr
= p
+jnx_header_len
;
1172 /* ok to read extension length ? */
1173 TCHECK2(tptr
[0], 2);
1174 jnx_ext_len
= EXTRACT_16BITS(tptr
);
1175 jnx_header_len
+= 2;
1178 /* nail up the total length -
1179 * just in case something goes wrong
1180 * with TLV parsing */
1181 jnx_header_len
+= jnx_ext_len
;
1184 printf(", PCAP Extension(s) total length %u",
1187 TCHECK2(tptr
[0], jnx_ext_len
);
1188 while (jnx_ext_len
> JUNIPER_EXT_TLV_OVERHEAD
) {
1189 tlv_type
= *(tptr
++);
1190 tlv_len
= *(tptr
++);
1194 if (tlv_type
== 0 || tlv_len
== 0)
1198 printf("\n\t %s Extension TLV #%u, length %u, value ",
1199 tok2str(jnx_ext_tlv_values
,"Unknown",tlv_type
),
1203 tlv_value
= juniper_read_tlv_value(tptr
, tlv_type
, tlv_len
);
1205 case JUNIPER_EXT_TLV_IFD_NAME
:
1208 case JUNIPER_EXT_TLV_IFD_MEDIATYPE
:
1209 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
:
1210 if (tlv_value
!= -1) {
1213 tok2str(juniper_ifmt_values
, "Unknown", tlv_value
),
1217 case JUNIPER_EXT_TLV_IFL_ENCAPS
:
1218 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
:
1219 if (tlv_value
!= -1) {
1222 tok2str(juniper_ifle_values
, "Unknown", tlv_value
),
1226 case JUNIPER_EXT_TLV_IFL_IDX
: /* fall through */
1227 case JUNIPER_EXT_TLV_IFL_UNIT
:
1228 case JUNIPER_EXT_TLV_IFD_IDX
:
1230 if (tlv_value
!= -1) {
1232 printf("%u",tlv_value
);
1238 jnx_ext_len
-= tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
;
1242 printf("\n\t-----original packet-----\n\t");
1245 if ((l2info
->flags
& JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
1247 printf("no-L2-hdr, ");
1249 /* there is no link-layer present -
1250 * perform the v4/v6 heuristics
1251 * to figure out what it is
1253 TCHECK2(p
[jnx_header_len
+4],1);
1254 if(ip_heuristic_guess(p
+jnx_header_len
+4,l2info
->length
-(jnx_header_len
+4)) == 0)
1255 printf("no IP-hdr found!");
1257 l2info
->header_len
=jnx_header_len
+4;
1258 return 0; /* stop parsing the output further */
1261 l2info
->header_len
= jnx_header_len
;
1262 p
+=l2info
->header_len
;
1263 l2info
->length
-= l2info
->header_len
;
1264 l2info
->caplen
-= l2info
->header_len
;
1266 /* search through the cookie table and copy values matching for our PIC type */
1267 while (lp
->s
!= NULL
) {
1268 if (lp
->pictype
== l2info
->pictype
) {
1270 l2info
->cookie_len
+= lp
->cookie_len
;
1274 l2info
->cookie_type
= LS_COOKIE_ID
;
1275 l2info
->cookie_len
+= 2;
1278 l2info
->cookie_type
= AS_COOKIE_ID
;
1279 l2info
->cookie_len
= 8;
1283 l2info
->bundle
= l2info
->cookie
[0];
1288 #ifdef DLT_JUNIPER_MFR
1289 /* MFR child links don't carry cookies */
1290 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
1291 (p
[0] & MFR_BE_MASK
) == MFR_BE_MASK
) {
1292 l2info
->cookie_len
= 0;
1296 l2info
->header_len
+= l2info
->cookie_len
;
1297 l2info
->length
-= l2info
->cookie_len
;
1298 l2info
->caplen
-= l2info
->cookie_len
;
1301 printf("%s-PIC, cookie-len %u",
1303 l2info
->cookie_len
);
1305 if (l2info
->cookie_len
> 0) {
1306 TCHECK2(p
[0],l2info
->cookie_len
);
1308 printf(", cookie 0x");
1309 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
1310 l2info
->cookie
[idx
] = p
[idx
]; /* copy cookie data */
1311 if (eflag
) printf("%02x",p
[idx
]);
1315 if (eflag
) printf(": "); /* print demarc b/w L2/L3*/
1318 l2info
->proto
= EXTRACT_16BITS(p
+l2info
->cookie_len
);
1323 p
+=l2info
->cookie_len
;
1325 /* DLT_ specific parsing */
1326 switch(l2info
->pictype
) {
1327 #ifdef DLT_JUNIPER_MLPPP
1328 case DLT_JUNIPER_MLPPP
:
1329 switch (l2info
->cookie_type
) {
1331 l2info
->bundle
= l2info
->cookie
[1];
1334 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1335 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1338 l2info
->bundle
= l2info
->cookie
[0];
1343 #ifdef DLT_JUNIPER_MLFR
1344 case DLT_JUNIPER_MLFR
:
1345 switch (l2info
->cookie_type
) {
1347 l2info
->bundle
= l2info
->cookie
[1];
1348 l2info
->proto
= EXTRACT_16BITS(p
);
1349 l2info
->header_len
+= 2;
1350 l2info
->length
-= 2;
1351 l2info
->caplen
-= 2;
1354 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1355 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1358 l2info
->bundle
= l2info
->cookie
[0];
1359 l2info
->header_len
+= 2;
1360 l2info
->length
-= 2;
1361 l2info
->caplen
-= 2;
1366 #ifdef DLT_JUNIPER_MFR
1367 case DLT_JUNIPER_MFR
:
1368 switch (l2info
->cookie_type
) {
1370 l2info
->bundle
= l2info
->cookie
[1];
1371 l2info
->proto
= EXTRACT_16BITS(p
);
1372 l2info
->header_len
+= 2;
1373 l2info
->length
-= 2;
1374 l2info
->caplen
-= 2;
1377 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1378 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1381 l2info
->bundle
= l2info
->cookie
[0];
1386 #ifdef DLT_JUNIPER_ATM2
1387 case DLT_JUNIPER_ATM2
:
1389 /* ATM cell relay control word present ? */
1390 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
) {
1391 control_word
= EXTRACT_32BITS(p
);
1392 /* some control word heuristics */
1393 switch(control_word
) {
1394 case 0: /* zero control word */
1395 case 0x08000000: /* < JUNOS 7.4 control-word */
1396 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1397 l2info
->header_len
+= 4;
1404 printf("control-word 0x%08x ", control_word
);
1408 #ifdef DLT_JUNIPER_GGSN
1409 case DLT_JUNIPER_GGSN
:
1412 #ifdef DLT_JUNIPER_ATM1
1413 case DLT_JUNIPER_ATM1
:
1416 #ifdef DLT_JUNIPER_PPP
1417 case DLT_JUNIPER_PPP
:
1420 #ifdef DLT_JUNIPER_CHDLC
1421 case DLT_JUNIPER_CHDLC
:
1424 #ifdef DLT_JUNIPER_ETHER
1425 case DLT_JUNIPER_ETHER
:
1428 #ifdef DLT_JUNIPER_FRELAY
1429 case DLT_JUNIPER_FRELAY
:
1434 printf("Unknown Juniper DLT_ type %u: ", l2info
->pictype
);
1439 printf("hlen %u, proto 0x%04x, ",l2info
->header_len
,l2info
->proto
);
1441 return 1; /* everything went ok so far. continue parsing */
1443 printf("[|juniper_hdr], length %u",h
->len
);
1450 * c-style: whitesmith