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>
32 #include "interface.h"
33 #include "addrtoname.h"
38 #include "ethertype.h"
41 #define JUNIPER_BPF_OUT 0 /* Outgoing packet */
42 #define JUNIPER_BPF_IN 1 /* Incoming packet */
43 #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */
44 #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */
45 #define JUNIPER_BPF_IIF 0x4 /* IIF is valid */
46 #define JUNIPER_BPF_FILTER 0x40 /* BPF filtering is supported */
47 #define JUNIPER_BPF_EXT 0x80 /* extensions present */
48 #define JUNIPER_MGC_NUMBER 0x4d4743 /* = "MGC" */
50 #define JUNIPER_LSQ_COOKIE_RE (1 << 3)
51 #define JUNIPER_LSQ_COOKIE_DIR (1 << 2)
52 #define JUNIPER_LSQ_L3_PROTO_SHIFT 4
53 #define JUNIPER_LSQ_L3_PROTO_MASK (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT)
54 #define JUNIPER_LSQ_L3_PROTO_IPV4 (0 << JUNIPER_LSQ_L3_PROTO_SHIFT)
55 #define JUNIPER_LSQ_L3_PROTO_IPV6 (1 << JUNIPER_LSQ_L3_PROTO_SHIFT)
56 #define JUNIPER_LSQ_L3_PROTO_MPLS (2 << JUNIPER_LSQ_L3_PROTO_SHIFT)
57 #define JUNIPER_LSQ_L3_PROTO_ISO (3 << JUNIPER_LSQ_L3_PROTO_SHIFT)
58 #define AS_PIC_COOKIE_LEN 8
60 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1
61 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2
62 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3
63 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4
64 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5
66 static const struct tok juniper_ipsec_type_values
[] = {
67 { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
, "ESP ENCR-AUTH" },
68 { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
, "ESP ENCR-AH AUTH" },
69 { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
, "ESP AUTH" },
70 { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
, "AH AUTH" },
71 { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
, "ESP ENCR" },
75 static const struct tok juniper_direction_values
[] = {
76 { JUNIPER_BPF_IN
, "In"},
77 { JUNIPER_BPF_OUT
, "Out"},
81 /* codepoints for encoding extensions to a .pcap file */
83 JUNIPER_EXT_TLV_IFD_IDX
= 1,
84 JUNIPER_EXT_TLV_IFD_NAME
= 2,
85 JUNIPER_EXT_TLV_IFD_MEDIATYPE
= 3,
86 JUNIPER_EXT_TLV_IFL_IDX
= 4,
87 JUNIPER_EXT_TLV_IFL_UNIT
= 5,
88 JUNIPER_EXT_TLV_IFL_ENCAPS
= 6,
89 JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
= 7,
90 JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
= 8
93 /* 1 byte type and 1-byte length */
94 #define JUNIPER_EXT_TLV_OVERHEAD 2
96 static const struct tok jnx_ext_tlv_values
[] = {
97 { JUNIPER_EXT_TLV_IFD_IDX
, "Device Interface Index" },
98 { JUNIPER_EXT_TLV_IFD_NAME
,"Device Interface Name" },
99 { JUNIPER_EXT_TLV_IFD_MEDIATYPE
, "Device Media Type" },
100 { JUNIPER_EXT_TLV_IFL_IDX
, "Logical Interface Index" },
101 { JUNIPER_EXT_TLV_IFL_UNIT
,"Logical Unit Number" },
102 { JUNIPER_EXT_TLV_IFL_ENCAPS
, "Logical Interface Encapsulation" },
103 { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
, "TTP derived Device Media Type" },
104 { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
, "TTP derived Logical Interface Encapsulation" },
108 static const struct tok jnx_flag_values
[] = {
109 { JUNIPER_BPF_EXT
, "Ext" },
110 { JUNIPER_BPF_FILTER
, "Filter" },
111 { JUNIPER_BPF_IIF
, "IIF" },
112 { JUNIPER_BPF_NO_L2
, "no-L2" },
113 { JUNIPER_BPF_PKT_IN
, "In" },
117 #define JUNIPER_IFML_ETHER 1
118 #define JUNIPER_IFML_FDDI 2
119 #define JUNIPER_IFML_TOKENRING 3
120 #define JUNIPER_IFML_PPP 4
121 #define JUNIPER_IFML_FRAMERELAY 5
122 #define JUNIPER_IFML_CISCOHDLC 6
123 #define JUNIPER_IFML_SMDSDXI 7
124 #define JUNIPER_IFML_ATMPVC 8
125 #define JUNIPER_IFML_PPP_CCC 9
126 #define JUNIPER_IFML_FRAMERELAY_CCC 10
127 #define JUNIPER_IFML_IPIP 11
128 #define JUNIPER_IFML_GRE 12
129 #define JUNIPER_IFML_PIM 13
130 #define JUNIPER_IFML_PIMD 14
131 #define JUNIPER_IFML_CISCOHDLC_CCC 15
132 #define JUNIPER_IFML_VLAN_CCC 16
133 #define JUNIPER_IFML_MLPPP 17
134 #define JUNIPER_IFML_MLFR 18
135 #define JUNIPER_IFML_ML 19
136 #define JUNIPER_IFML_LSI 20
137 #define JUNIPER_IFML_DFE 21
138 #define JUNIPER_IFML_ATM_CELLRELAY_CCC 22
139 #define JUNIPER_IFML_CRYPTO 23
140 #define JUNIPER_IFML_GGSN 24
141 #define JUNIPER_IFML_LSI_PPP 25
142 #define JUNIPER_IFML_LSI_CISCOHDLC 26
143 #define JUNIPER_IFML_PPP_TCC 27
144 #define JUNIPER_IFML_FRAMERELAY_TCC 28
145 #define JUNIPER_IFML_CISCOHDLC_TCC 29
146 #define JUNIPER_IFML_ETHERNET_CCC 30
147 #define JUNIPER_IFML_VT 31
148 #define JUNIPER_IFML_EXTENDED_VLAN_CCC 32
149 #define JUNIPER_IFML_ETHER_OVER_ATM 33
150 #define JUNIPER_IFML_MONITOR 34
151 #define JUNIPER_IFML_ETHERNET_TCC 35
152 #define JUNIPER_IFML_VLAN_TCC 36
153 #define JUNIPER_IFML_EXTENDED_VLAN_TCC 37
154 #define JUNIPER_IFML_CONTROLLER 38
155 #define JUNIPER_IFML_MFR 39
156 #define JUNIPER_IFML_LS 40
157 #define JUNIPER_IFML_ETHERNET_VPLS 41
158 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42
159 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43
160 #define JUNIPER_IFML_LT 44
161 #define JUNIPER_IFML_SERVICES 45
162 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46
163 #define JUNIPER_IFML_FR_PORT_CCC 47
164 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48
165 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49
166 #define JUNIPER_IFML_FRAMERELAY_FLEX 50
167 #define JUNIPER_IFML_GGSNI 51
168 #define JUNIPER_IFML_ETHERNET_FLEX 52
169 #define JUNIPER_IFML_COLLECTOR 53
170 #define JUNIPER_IFML_AGGREGATOR 54
171 #define JUNIPER_IFML_LAPD 55
172 #define JUNIPER_IFML_PPPOE 56
173 #define JUNIPER_IFML_PPP_SUBORDINATE 57
174 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE 58
175 #define JUNIPER_IFML_DFC 59
176 #define JUNIPER_IFML_PICPEER 60
178 static const struct tok juniper_ifmt_values
[] = {
179 { JUNIPER_IFML_ETHER
, "Ethernet" },
180 { JUNIPER_IFML_FDDI
, "FDDI" },
181 { JUNIPER_IFML_TOKENRING
, "Token-Ring" },
182 { JUNIPER_IFML_PPP
, "PPP" },
183 { JUNIPER_IFML_PPP_SUBORDINATE
, "PPP-Subordinate" },
184 { JUNIPER_IFML_FRAMERELAY
, "Frame-Relay" },
185 { JUNIPER_IFML_CISCOHDLC
, "Cisco-HDLC" },
186 { JUNIPER_IFML_SMDSDXI
, "SMDS-DXI" },
187 { JUNIPER_IFML_ATMPVC
, "ATM-PVC" },
188 { JUNIPER_IFML_PPP_CCC
, "PPP-CCC" },
189 { JUNIPER_IFML_FRAMERELAY_CCC
, "Frame-Relay-CCC" },
190 { JUNIPER_IFML_FRAMERELAY_EXT_CCC
, "Extended FR-CCC" },
191 { JUNIPER_IFML_IPIP
, "IP-over-IP" },
192 { JUNIPER_IFML_GRE
, "GRE" },
193 { JUNIPER_IFML_PIM
, "PIM-Encapsulator" },
194 { JUNIPER_IFML_PIMD
, "PIM-Decapsulator" },
195 { JUNIPER_IFML_CISCOHDLC_CCC
, "Cisco-HDLC-CCC" },
196 { JUNIPER_IFML_VLAN_CCC
, "VLAN-CCC" },
197 { JUNIPER_IFML_EXTENDED_VLAN_CCC
, "Extended-VLAN-CCC" },
198 { JUNIPER_IFML_MLPPP
, "Multilink-PPP" },
199 { JUNIPER_IFML_MLFR
, "Multilink-FR" },
200 { JUNIPER_IFML_MFR
, "Multilink-FR-UNI-NNI" },
201 { JUNIPER_IFML_ML
, "Multilink" },
202 { JUNIPER_IFML_LS
, "LinkService" },
203 { JUNIPER_IFML_LSI
, "LSI" },
204 { JUNIPER_IFML_ATM_CELLRELAY_CCC
, "ATM-CCC-Cell-Relay" },
205 { JUNIPER_IFML_CRYPTO
, "IPSEC-over-IP" },
206 { JUNIPER_IFML_GGSN
, "GGSN" },
207 { JUNIPER_IFML_PPP_TCC
, "PPP-TCC" },
208 { JUNIPER_IFML_FRAMERELAY_TCC
, "Frame-Relay-TCC" },
209 { JUNIPER_IFML_FRAMERELAY_EXT_TCC
, "Extended FR-TCC" },
210 { JUNIPER_IFML_CISCOHDLC_TCC
, "Cisco-HDLC-TCC" },
211 { JUNIPER_IFML_ETHERNET_CCC
, "Ethernet-CCC" },
212 { JUNIPER_IFML_VT
, "VPN-Loopback-tunnel" },
213 { JUNIPER_IFML_ETHER_OVER_ATM
, "Ethernet-over-ATM" },
214 { JUNIPER_IFML_ETHER_VPLS_OVER_ATM
, "Ethernet-VPLS-over-ATM" },
215 { JUNIPER_IFML_MONITOR
, "Monitor" },
216 { JUNIPER_IFML_ETHERNET_TCC
, "Ethernet-TCC" },
217 { JUNIPER_IFML_VLAN_TCC
, "VLAN-TCC" },
218 { JUNIPER_IFML_EXTENDED_VLAN_TCC
, "Extended-VLAN-TCC" },
219 { JUNIPER_IFML_CONTROLLER
, "Controller" },
220 { JUNIPER_IFML_ETHERNET_VPLS
, "VPLS" },
221 { JUNIPER_IFML_ETHERNET_VLAN_VPLS
, "VLAN-VPLS" },
222 { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended-VLAN-VPLS" },
223 { JUNIPER_IFML_LT
, "Logical-tunnel" },
224 { JUNIPER_IFML_SERVICES
, "General-Services" },
225 { JUNIPER_IFML_PPPOE
, "PPPoE" },
226 { JUNIPER_IFML_ETHERNET_FLEX
, "Flexible-Ethernet-Services" },
227 { JUNIPER_IFML_FRAMERELAY_FLEX
, "Flexible-FrameRelay" },
228 { JUNIPER_IFML_COLLECTOR
, "Flow-collection" },
229 { JUNIPER_IFML_PICPEER
, "PIC Peer" },
230 { JUNIPER_IFML_DFC
, "Dynamic-Flow-Capture" },
234 #define JUNIPER_IFLE_ATM_SNAP 2
235 #define JUNIPER_IFLE_ATM_NLPID 3
236 #define JUNIPER_IFLE_ATM_VCMUX 4
237 #define JUNIPER_IFLE_ATM_LLC 5
238 #define JUNIPER_IFLE_ATM_PPP_VCMUX 6
239 #define JUNIPER_IFLE_ATM_PPP_LLC 7
240 #define JUNIPER_IFLE_ATM_PPP_FUNI 8
241 #define JUNIPER_IFLE_ATM_CCC 9
242 #define JUNIPER_IFLE_FR_NLPID 10
243 #define JUNIPER_IFLE_FR_SNAP 11
244 #define JUNIPER_IFLE_FR_PPP 12
245 #define JUNIPER_IFLE_FR_CCC 13
246 #define JUNIPER_IFLE_ENET2 14
247 #define JUNIPER_IFLE_IEEE8023_SNAP 15
248 #define JUNIPER_IFLE_IEEE8023_LLC 16
249 #define JUNIPER_IFLE_PPP 17
250 #define JUNIPER_IFLE_CISCOHDLC 18
251 #define JUNIPER_IFLE_PPP_CCC 19
252 #define JUNIPER_IFLE_IPIP_NULL 20
253 #define JUNIPER_IFLE_PIM_NULL 21
254 #define JUNIPER_IFLE_GRE_NULL 22
255 #define JUNIPER_IFLE_GRE_PPP 23
256 #define JUNIPER_IFLE_PIMD_DECAPS 24
257 #define JUNIPER_IFLE_CISCOHDLC_CCC 25
258 #define JUNIPER_IFLE_ATM_CISCO_NLPID 26
259 #define JUNIPER_IFLE_VLAN_CCC 27
260 #define JUNIPER_IFLE_MLPPP 28
261 #define JUNIPER_IFLE_MLFR 29
262 #define JUNIPER_IFLE_LSI_NULL 30
263 #define JUNIPER_IFLE_AGGREGATE_UNUSED 31
264 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC 32
265 #define JUNIPER_IFLE_CRYPTO 33
266 #define JUNIPER_IFLE_GGSN 34
267 #define JUNIPER_IFLE_ATM_TCC 35
268 #define JUNIPER_IFLE_FR_TCC 36
269 #define JUNIPER_IFLE_PPP_TCC 37
270 #define JUNIPER_IFLE_CISCOHDLC_TCC 38
271 #define JUNIPER_IFLE_ETHERNET_CCC 39
272 #define JUNIPER_IFLE_VT 40
273 #define JUNIPER_IFLE_ATM_EOA_LLC 41
274 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC 42
275 #define JUNIPER_IFLE_ATM_SNAP_TCC 43
276 #define JUNIPER_IFLE_MONITOR 44
277 #define JUNIPER_IFLE_ETHERNET_TCC 45
278 #define JUNIPER_IFLE_VLAN_TCC 46
279 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC 47
280 #define JUNIPER_IFLE_MFR 48
281 #define JUNIPER_IFLE_ETHERNET_VPLS 49
282 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50
283 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51
284 #define JUNIPER_IFLE_SERVICES 52
285 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC 53
286 #define JUNIPER_IFLE_FR_PORT_CCC 54
287 #define JUNIPER_IFLE_ATM_MLPPP_LLC 55
288 #define JUNIPER_IFLE_ATM_EOA_CCC 56
289 #define JUNIPER_IFLE_LT_VLAN 57
290 #define JUNIPER_IFLE_COLLECTOR 58
291 #define JUNIPER_IFLE_AGGREGATOR 59
292 #define JUNIPER_IFLE_LAPD 60
293 #define JUNIPER_IFLE_ATM_PPPOE_LLC 61
294 #define JUNIPER_IFLE_ETHERNET_PPPOE 62
295 #define JUNIPER_IFLE_PPPOE 63
296 #define JUNIPER_IFLE_PPP_SUBORDINATE 64
297 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE 65
298 #define JUNIPER_IFLE_DFC 66
299 #define JUNIPER_IFLE_PICPEER 67
301 static const struct tok juniper_ifle_values
[] = {
302 { JUNIPER_IFLE_AGGREGATOR
, "Aggregator" },
303 { JUNIPER_IFLE_ATM_CCC
, "CCC over ATM" },
304 { JUNIPER_IFLE_ATM_CELLRELAY_CCC
, "ATM CCC Cell Relay" },
305 { JUNIPER_IFLE_ATM_CISCO_NLPID
, "CISCO compatible NLPID" },
306 { JUNIPER_IFLE_ATM_EOA_CCC
, "Ethernet over ATM CCC" },
307 { JUNIPER_IFLE_ATM_EOA_LLC
, "Ethernet over ATM LLC" },
308 { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC
, "Ethernet VPLS over ATM LLC" },
309 { JUNIPER_IFLE_ATM_LLC
, "ATM LLC" },
310 { JUNIPER_IFLE_ATM_MLPPP_LLC
, "MLPPP over ATM LLC" },
311 { JUNIPER_IFLE_ATM_NLPID
, "ATM NLPID" },
312 { JUNIPER_IFLE_ATM_PPPOE_LLC
, "PPPoE over ATM LLC" },
313 { JUNIPER_IFLE_ATM_PPP_FUNI
, "PPP over FUNI" },
314 { JUNIPER_IFLE_ATM_PPP_LLC
, "PPP over ATM LLC" },
315 { JUNIPER_IFLE_ATM_PPP_VCMUX
, "PPP over ATM VCMUX" },
316 { JUNIPER_IFLE_ATM_SNAP
, "ATM SNAP" },
317 { JUNIPER_IFLE_ATM_SNAP_TCC
, "ATM SNAP TCC" },
318 { JUNIPER_IFLE_ATM_TCC
, "ATM VCMUX TCC" },
319 { JUNIPER_IFLE_ATM_VCMUX
, "ATM VCMUX" },
320 { JUNIPER_IFLE_CISCOHDLC
, "C-HDLC" },
321 { JUNIPER_IFLE_CISCOHDLC_CCC
, "C-HDLC CCC" },
322 { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE
, "C-HDLC via dialer" },
323 { JUNIPER_IFLE_CISCOHDLC_TCC
, "C-HDLC TCC" },
324 { JUNIPER_IFLE_COLLECTOR
, "Collector" },
325 { JUNIPER_IFLE_CRYPTO
, "Crypto" },
326 { JUNIPER_IFLE_ENET2
, "Ethernet" },
327 { JUNIPER_IFLE_ETHERNET_CCC
, "Ethernet CCC" },
328 { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended VLAN VPLS" },
329 { JUNIPER_IFLE_ETHERNET_PPPOE
, "PPPoE over Ethernet" },
330 { JUNIPER_IFLE_ETHERNET_TCC
, "Ethernet TCC" },
331 { JUNIPER_IFLE_ETHERNET_VLAN_VPLS
, "VLAN VPLS" },
332 { JUNIPER_IFLE_ETHERNET_VPLS
, "VPLS" },
333 { JUNIPER_IFLE_EXTENDED_VLAN_CCC
, "Extended VLAN CCC" },
334 { JUNIPER_IFLE_EXTENDED_VLAN_TCC
, "Extended VLAN TCC" },
335 { JUNIPER_IFLE_FR_CCC
, "FR CCC" },
336 { JUNIPER_IFLE_FR_NLPID
, "FR NLPID" },
337 { JUNIPER_IFLE_FR_PORT_CCC
, "FR CCC" },
338 { JUNIPER_IFLE_FR_PPP
, "FR PPP" },
339 { JUNIPER_IFLE_FR_SNAP
, "FR SNAP" },
340 { JUNIPER_IFLE_FR_TCC
, "FR TCC" },
341 { JUNIPER_IFLE_GGSN
, "GGSN" },
342 { JUNIPER_IFLE_GRE_NULL
, "GRE NULL" },
343 { JUNIPER_IFLE_GRE_PPP
, "PPP over GRE" },
344 { JUNIPER_IFLE_IPIP_NULL
, "IPIP" },
345 { JUNIPER_IFLE_LAPD
, "LAPD" },
346 { JUNIPER_IFLE_LSI_NULL
, "LSI Null" },
347 { JUNIPER_IFLE_LT_VLAN
, "LT VLAN" },
348 { JUNIPER_IFLE_MFR
, "MFR" },
349 { JUNIPER_IFLE_MLFR
, "MLFR" },
350 { JUNIPER_IFLE_MLPPP
, "MLPPP" },
351 { JUNIPER_IFLE_MONITOR
, "Monitor" },
352 { JUNIPER_IFLE_PIMD_DECAPS
, "PIMd" },
353 { JUNIPER_IFLE_PIM_NULL
, "PIM Null" },
354 { JUNIPER_IFLE_PPP
, "PPP" },
355 { JUNIPER_IFLE_PPPOE
, "PPPoE" },
356 { JUNIPER_IFLE_PPP_CCC
, "PPP CCC" },
357 { JUNIPER_IFLE_PPP_SUBORDINATE
, "" },
358 { JUNIPER_IFLE_PPP_TCC
, "PPP TCC" },
359 { JUNIPER_IFLE_SERVICES
, "General Services" },
360 { JUNIPER_IFLE_VLAN_CCC
, "VLAN CCC" },
361 { JUNIPER_IFLE_VLAN_TCC
, "VLAN TCC" },
362 { JUNIPER_IFLE_VT
, "VT" },
366 struct juniper_cookie_table_t
{
367 u_int32_t pictype
; /* pic type */
368 u_int8_t cookie_len
; /* cookie len */
369 const char *s
; /* pic name */
372 static const struct juniper_cookie_table_t juniper_cookie_table
[] = {
373 #ifdef DLT_JUNIPER_ATM1
374 { DLT_JUNIPER_ATM1
, 4, "ATM1"},
376 #ifdef DLT_JUNIPER_ATM2
377 { DLT_JUNIPER_ATM2
, 8, "ATM2"},
379 #ifdef DLT_JUNIPER_MLPPP
380 { DLT_JUNIPER_MLPPP
, 2, "MLPPP"},
382 #ifdef DLT_JUNIPER_MLFR
383 { DLT_JUNIPER_MLFR
, 2, "MLFR"},
385 #ifdef DLT_JUNIPER_MFR
386 { DLT_JUNIPER_MFR
, 4, "MFR"},
388 #ifdef DLT_JUNIPER_PPPOE
389 { DLT_JUNIPER_PPPOE
, 0, "PPPoE"},
391 #ifdef DLT_JUNIPER_PPPOE_ATM
392 { DLT_JUNIPER_PPPOE_ATM
, 0, "PPPoE ATM"},
394 #ifdef DLT_JUNIPER_GGSN
395 { DLT_JUNIPER_GGSN
, 8, "GGSN"},
397 #ifdef DLT_JUNIPER_MONITOR
398 { DLT_JUNIPER_MONITOR
, 8, "MONITOR"},
400 #ifdef DLT_JUNIPER_SERVICES
401 { DLT_JUNIPER_SERVICES
, 8, "AS"},
403 #ifdef DLT_JUNIPER_ES
404 { DLT_JUNIPER_ES
, 0, "ES"},
409 struct juniper_l2info_t
{
416 u_int8_t cookie_type
;
423 #define LS_COOKIE_ID 0x54
424 #define AS_COOKIE_ID 0x47
425 #define LS_MLFR_COOKIE_LEN 4
426 #define ML_MLFR_COOKIE_LEN 2
427 #define LS_MFR_COOKIE_LEN 6
428 #define ATM1_COOKIE_LEN 4
429 #define ATM2_COOKIE_LEN 8
431 #define ATM2_PKT_TYPE_MASK 0x70
432 #define ATM2_GAP_COUNT_MASK 0x3F
434 #define JUNIPER_PROTO_NULL 1
435 #define JUNIPER_PROTO_IPV4 2
436 #define JUNIPER_PROTO_IPV6 6
438 #define MFR_BE_MASK 0xc0
440 static const struct tok juniper_protocol_values
[] = {
441 { JUNIPER_PROTO_NULL
, "Null" },
442 { JUNIPER_PROTO_IPV4
, "IPv4" },
443 { JUNIPER_PROTO_IPV6
, "IPv6" },
447 int ip_heuristic_guess(register const u_char
*, u_int
);
448 int juniper_ppp_heuristic_guess(register const u_char
*, u_int
);
449 int juniper_read_tlv_value(const u_char
*, u_int
, u_int
);
450 static int juniper_parse_header (const u_char
*, const struct pcap_pkthdr
*, struct juniper_l2info_t
*);
452 #ifdef DLT_JUNIPER_GGSN
454 juniper_ggsn_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
456 struct juniper_l2info_t l2info
;
457 struct juniper_ggsn_header
{
465 const struct juniper_ggsn_header
*gh
;
467 l2info
.pictype
= DLT_JUNIPER_GGSN
;
468 if(juniper_parse_header(p
, h
, &l2info
) == 0)
469 return l2info
.header_len
;
471 p
+=l2info
.header_len
;
472 gh
= (struct juniper_ggsn_header
*)&l2info
.cookie
;
475 printf("proto %s (%u), vlan %u: ",
476 tok2str(juniper_protocol_values
,"Unknown",gh
->proto
),
478 EXTRACT_16BITS(&gh
->vlan_id
[0]));
482 case JUNIPER_PROTO_IPV4
:
483 ip_print(gndo
, p
, l2info
.length
);
486 case JUNIPER_PROTO_IPV6
:
487 ip6_print(gndo
, p
, l2info
.length
);
492 printf("unknown GGSN proto (%u)", gh
->proto
);
495 return l2info
.header_len
;
499 #ifdef DLT_JUNIPER_ES
501 juniper_es_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
503 struct juniper_l2info_t l2info
;
504 struct juniper_ipsec_header
{
505 u_int8_t sa_index
[2];
512 u_int rewrite_len
,es_type_bundle
;
513 const struct juniper_ipsec_header
*ih
;
515 l2info
.pictype
= DLT_JUNIPER_ES
;
516 if(juniper_parse_header(p
, h
, &l2info
) == 0)
517 return l2info
.header_len
;
519 p
+=l2info
.header_len
;
520 ih
= (struct juniper_ipsec_header
*)p
;
523 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
524 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
528 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
529 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
530 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
534 printf("ES Invalid type %u, length %u",
537 return l2info
.header_len
;
540 l2info
.length
-=rewrite_len
;
544 if (!es_type_bundle
) {
545 printf("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
546 EXTRACT_16BITS(&ih
->sa_index
),
548 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
550 EXTRACT_32BITS(&ih
->spi
),
551 ipaddr_string(&ih
->src_ip
),
552 ipaddr_string(&ih
->dst_ip
),
555 printf("ES SA, index %u, ttl %u type %s (%u), length %u\n",
556 EXTRACT_16BITS(&ih
->sa_index
),
558 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
564 ip_print(gndo
, p
, l2info
.length
);
565 return l2info
.header_len
;
569 #ifdef DLT_JUNIPER_MONITOR
571 juniper_monitor_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
573 struct juniper_l2info_t l2info
;
574 struct juniper_monitor_header
{
578 u_int8_t service_id
[4];
580 const struct juniper_monitor_header
*mh
;
582 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
583 if(juniper_parse_header(p
, h
, &l2info
) == 0)
584 return l2info
.header_len
;
586 p
+=l2info
.header_len
;
587 mh
= (struct juniper_monitor_header
*)p
;
590 printf("service-id %u, iif %u, pkt-type %u: ",
591 EXTRACT_32BITS(&mh
->service_id
),
592 EXTRACT_16BITS(&mh
->iif
),
595 /* no proto field - lets guess by first byte of IP header*/
596 ip_heuristic_guess(p
, l2info
.length
);
598 return l2info
.header_len
;
602 #ifdef DLT_JUNIPER_SERVICES
604 juniper_services_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
606 struct juniper_l2info_t l2info
;
607 struct juniper_services_header
{
610 u_int8_t svc_set_id
[2];
613 const struct juniper_services_header
*sh
;
615 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
616 if(juniper_parse_header(p
, h
, &l2info
) == 0)
617 return l2info
.header_len
;
619 p
+=l2info
.header_len
;
620 sh
= (struct juniper_services_header
*)p
;
623 printf("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
626 EXTRACT_16BITS(&sh
->svc_set_id
),
627 EXTRACT_24BITS(&sh
->dir_iif
[1]));
629 /* no proto field - lets guess by first byte of IP header*/
630 ip_heuristic_guess(p
, l2info
.length
);
632 return l2info
.header_len
;
636 #ifdef DLT_JUNIPER_PPPOE
638 juniper_pppoe_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
640 struct juniper_l2info_t l2info
;
642 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
643 if(juniper_parse_header(p
, h
, &l2info
) == 0)
644 return l2info
.header_len
;
646 p
+=l2info
.header_len
;
647 /* this DLT contains nothing but raw ethernet frames */
648 ether_print(gndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
649 return l2info
.header_len
;
653 #ifdef DLT_JUNIPER_ETHER
655 juniper_ether_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
657 struct juniper_l2info_t l2info
;
659 l2info
.pictype
= DLT_JUNIPER_ETHER
;
660 if(juniper_parse_header(p
, h
, &l2info
) == 0)
661 return l2info
.header_len
;
663 p
+=l2info
.header_len
;
664 /* this DLT contains nothing but raw Ethernet frames */
665 ether_print(gndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
666 return l2info
.header_len
;
670 #ifdef DLT_JUNIPER_PPP
672 juniper_ppp_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
674 struct juniper_l2info_t l2info
;
676 l2info
.pictype
= DLT_JUNIPER_PPP
;
677 if(juniper_parse_header(p
, h
, &l2info
) == 0)
678 return l2info
.header_len
;
680 p
+=l2info
.header_len
;
681 /* this DLT contains nothing but raw ppp frames */
682 ppp_print(p
, l2info
.length
);
683 return l2info
.header_len
;
687 #ifdef DLT_JUNIPER_FRELAY
689 juniper_frelay_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
691 struct juniper_l2info_t l2info
;
693 l2info
.pictype
= DLT_JUNIPER_FRELAY
;
694 if(juniper_parse_header(p
, h
, &l2info
) == 0)
695 return l2info
.header_len
;
697 p
+=l2info
.header_len
;
698 /* this DLT contains nothing but raw frame-relay frames */
699 fr_print(p
, l2info
.length
);
700 return l2info
.header_len
;
704 #ifdef DLT_JUNIPER_CHDLC
706 juniper_chdlc_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
708 struct juniper_l2info_t l2info
;
710 l2info
.pictype
= DLT_JUNIPER_CHDLC
;
711 if(juniper_parse_header(p
, h
, &l2info
) == 0)
712 return l2info
.header_len
;
714 p
+=l2info
.header_len
;
715 /* this DLT contains nothing but raw c-hdlc frames */
716 chdlc_print(p
, l2info
.length
);
717 return l2info
.header_len
;
721 #ifdef DLT_JUNIPER_PPPOE_ATM
723 juniper_pppoe_atm_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
725 struct juniper_l2info_t l2info
;
726 u_int16_t extracted_ethertype
;
728 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
729 if(juniper_parse_header(p
, h
, &l2info
) == 0)
730 return l2info
.header_len
;
732 p
+=l2info
.header_len
;
734 extracted_ethertype
= EXTRACT_16BITS(p
);
735 /* this DLT contains nothing but raw PPPoE frames,
736 * prepended with a type field*/
737 if (ethertype_print(gndo
, extracted_ethertype
,
739 l2info
.length
-ETHERTYPE_LEN
,
740 l2info
.caplen
-ETHERTYPE_LEN
) == 0)
741 /* ether_type not known, probably it wasn't one */
742 printf("unknown ethertype 0x%04x", extracted_ethertype
);
744 return l2info
.header_len
;
748 #ifdef DLT_JUNIPER_MLPPP
750 juniper_mlppp_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
752 struct juniper_l2info_t l2info
;
754 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
755 if(juniper_parse_header(p
, h
, &l2info
) == 0)
756 return l2info
.header_len
;
758 /* suppress Bundle-ID if frame was captured on a child-link
759 * best indicator if the cookie looks like a proto */
761 EXTRACT_16BITS(&l2info
.cookie
) != PPP_OSI
&&
762 EXTRACT_16BITS(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
763 printf("Bundle-ID %u: ",l2info
.bundle
);
765 p
+=l2info
.header_len
;
767 /* first try the LSQ protos */
768 switch(l2info
.proto
) {
769 case JUNIPER_LSQ_L3_PROTO_IPV4
:
770 /* IP traffic going to the RE would not have a cookie
771 * -> this must be incoming IS-IS over PPP
773 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
774 ppp_print(p
, l2info
.length
);
776 ip_print(gndo
, p
, l2info
.length
);
777 return l2info
.header_len
;
779 case JUNIPER_LSQ_L3_PROTO_IPV6
:
780 ip6_print(gndo
, p
,l2info
.length
);
781 return l2info
.header_len
;
783 case JUNIPER_LSQ_L3_PROTO_MPLS
:
784 mpls_print(p
,l2info
.length
);
785 return l2info
.header_len
;
786 case JUNIPER_LSQ_L3_PROTO_ISO
:
787 isoclns_print(p
,l2info
.length
,l2info
.caplen
);
788 return l2info
.header_len
;
793 /* zero length cookie ? */
794 switch (EXTRACT_16BITS(&l2info
.cookie
)) {
796 ppp_print(p
-2,l2info
.length
+2);
798 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
800 ppp_print(p
,l2info
.length
);
804 return l2info
.header_len
;
809 #ifdef DLT_JUNIPER_MFR
811 juniper_mfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
813 struct juniper_l2info_t l2info
;
815 l2info
.pictype
= DLT_JUNIPER_MFR
;
816 if(juniper_parse_header(p
, h
, &l2info
) == 0)
817 return l2info
.header_len
;
819 p
+=l2info
.header_len
;
822 if (l2info
.cookie_len
== 0) {
823 mfr_print(p
,l2info
.length
);
824 return l2info
.header_len
;
827 /* first try the LSQ protos */
828 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
829 switch(l2info
.proto
) {
830 case JUNIPER_LSQ_L3_PROTO_IPV4
:
831 ip_print(gndo
, p
, l2info
.length
);
832 return l2info
.header_len
;
834 case JUNIPER_LSQ_L3_PROTO_IPV6
:
835 ip6_print(gndo
, p
,l2info
.length
);
836 return l2info
.header_len
;
838 case JUNIPER_LSQ_L3_PROTO_MPLS
:
839 mpls_print(p
,l2info
.length
);
840 return l2info
.header_len
;
841 case JUNIPER_LSQ_L3_PROTO_ISO
:
842 isoclns_print(p
,l2info
.length
,l2info
.caplen
);
843 return l2info
.header_len
;
847 return l2info
.header_len
;
850 /* suppress Bundle-ID if frame was captured on a child-link */
851 if (eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1) printf("Bundle-ID %u, ",l2info
.bundle
);
852 switch (l2info
.proto
) {
853 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
854 isoclns_print(p
+1, l2info
.length
-1, l2info
.caplen
-1);
856 case (LLC_UI
<<8 | NLPID_Q933
):
857 case (LLC_UI
<<8 | NLPID_IP
):
858 case (LLC_UI
<<8 | NLPID_IP6
):
859 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
860 isoclns_print(p
-1, l2info
.length
+1, l2info
.caplen
+1);
863 printf("unknown protocol 0x%04x, length %u",l2info
.proto
, l2info
.length
);
866 return l2info
.header_len
;
870 #ifdef DLT_JUNIPER_MLFR
872 juniper_mlfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
874 struct juniper_l2info_t l2info
;
876 l2info
.pictype
= DLT_JUNIPER_MLFR
;
877 if(juniper_parse_header(p
, h
, &l2info
) == 0)
878 return l2info
.header_len
;
880 p
+=l2info
.header_len
;
882 /* suppress Bundle-ID if frame was captured on a child-link */
883 if (eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1) printf("Bundle-ID %u, ",l2info
.bundle
);
884 switch (l2info
.proto
) {
887 isoclns_print(p
, l2info
.length
, l2info
.caplen
);
889 case (LLC_UI
<<8 | NLPID_Q933
):
890 case (LLC_UI
<<8 | NLPID_IP
):
891 case (LLC_UI
<<8 | NLPID_IP6
):
892 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
893 isoclns_print(p
-1, l2info
.length
+1, l2info
.caplen
+1);
896 printf("unknown protocol 0x%04x, length %u",l2info
.proto
, l2info
.length
);
899 return l2info
.header_len
;
904 * ATM1 PIC cookie format
906 * +-----+-------------------------+-------------------------------+
907 * |fmtid| vc index | channel ID |
908 * +-----+-------------------------+-------------------------------+
911 #ifdef DLT_JUNIPER_ATM1
913 juniper_atm1_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
915 u_int16_t extracted_ethertype
;
917 struct juniper_l2info_t l2info
;
919 l2info
.pictype
= DLT_JUNIPER_ATM1
;
920 if(juniper_parse_header(p
, h
, &l2info
) == 0)
921 return l2info
.header_len
;
923 p
+=l2info
.header_len
;
925 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
926 oam_print(p
,l2info
.length
,ATM_OAM_NOHEC
);
927 return l2info
.header_len
;
930 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
931 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
933 if (llc_print(p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
,
934 &extracted_ethertype
) != 0)
935 return l2info
.header_len
;
938 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
939 isoclns_print(p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
940 /* FIXME check if frame was recognized */
941 return l2info
.header_len
;
944 if(ip_heuristic_guess(p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
945 return l2info
.header_len
;
947 return l2info
.header_len
;
952 * ATM2 PIC cookie format
954 * +-------------------------------+---------+---+-----+-----------+
955 * | channel ID | reserv |AAL| CCRQ| gap cnt |
956 * +-------------------------------+---------+---+-----+-----------+
959 #ifdef DLT_JUNIPER_ATM2
961 juniper_atm2_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
963 u_int16_t extracted_ethertype
;
965 struct juniper_l2info_t l2info
;
967 l2info
.pictype
= DLT_JUNIPER_ATM2
;
968 if(juniper_parse_header(p
, h
, &l2info
) == 0)
969 return l2info
.header_len
;
971 p
+=l2info
.header_len
;
973 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
974 oam_print(p
,l2info
.length
,ATM_OAM_NOHEC
);
975 return l2info
.header_len
;
978 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
979 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
981 if (llc_print(p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
,
982 &extracted_ethertype
) != 0)
983 return l2info
.header_len
;
986 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
987 (EXTRACT_32BITS(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
988 ether_print(gndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
989 return l2info
.header_len
;
992 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
993 isoclns_print(p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
994 /* FIXME check if frame was recognized */
995 return l2info
.header_len
;
998 if(juniper_ppp_heuristic_guess(p
, l2info
.length
) != 0) /* PPPoA vcmux encaps ? */
999 return l2info
.header_len
;
1001 if(ip_heuristic_guess(p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
1002 return l2info
.header_len
;
1004 return l2info
.header_len
;
1009 /* try to guess, based on all PPP protos that are supported in
1010 * a juniper router if the payload data is encapsulated using PPP */
1012 juniper_ppp_heuristic_guess(register const u_char
*p
, u_int length
) {
1014 switch(EXTRACT_16BITS(p
)) {
1017 case PPP_MPLS_UCAST
:
1018 case PPP_MPLS_MCAST
:
1030 ppp_print(p
, length
);
1034 return 0; /* did not find a ppp header */
1037 return 1; /* we printed a ppp packet */
1041 ip_heuristic_guess(register const u_char
*p
, u_int length
) {
1055 ip_print(gndo
, p
, length
);
1074 ip6_print(gndo
, p
, length
);
1078 return 0; /* did not find a ip header */
1081 return 1; /* we printed an v4/v6 packet */
1085 juniper_read_tlv_value(const u_char
*p
, u_int tlv_type
, u_int tlv_len
) {
1089 /* TLVs < 128 are little endian encoded */
1090 if (tlv_type
< 128) {
1096 tlv_value
= EXTRACT_LE_16BITS(p
);
1099 tlv_value
= EXTRACT_LE_24BITS(p
);
1102 tlv_value
= EXTRACT_LE_32BITS(p
);
1109 /* TLVs >= 128 are big endian encoded */
1115 tlv_value
= EXTRACT_16BITS(p
);
1118 tlv_value
= EXTRACT_24BITS(p
);
1121 tlv_value
= EXTRACT_32BITS(p
);
1132 juniper_parse_header (const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
) {
1134 const struct juniper_cookie_table_t
*lp
= juniper_cookie_table
;
1135 u_int idx
, jnx_ext_len
, jnx_header_len
= 0;
1136 u_int8_t tlv_type
,tlv_len
;
1137 u_int32_t control_word
;
1142 l2info
->header_len
= 0;
1143 l2info
->cookie_len
= 0;
1147 l2info
->length
= h
->len
;
1148 l2info
->caplen
= h
->caplen
;
1150 l2info
->flags
= p
[3];
1151 l2info
->direction
= p
[3]&JUNIPER_BPF_PKT_IN
;
1153 if (EXTRACT_24BITS(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
1154 printf("no magic-number found!");
1158 if (eflag
) /* print direction */
1159 printf("%3s ",tok2str(juniper_direction_values
,"---",l2info
->direction
));
1161 /* magic number + flags */
1165 printf("\n\tJuniper PCAP Flags [%s]",
1166 bittok2str(jnx_flag_values
, "none", l2info
->flags
));
1168 /* extensions present ? - calculate how much bytes to skip */
1169 if ((l2info
->flags
& JUNIPER_BPF_EXT
) == JUNIPER_BPF_EXT
) {
1171 tptr
= p
+jnx_header_len
;
1173 /* ok to read extension length ? */
1174 TCHECK2(tptr
[0], 2);
1175 jnx_ext_len
= EXTRACT_16BITS(tptr
);
1176 jnx_header_len
+= 2;
1179 /* nail up the total length -
1180 * just in case something goes wrong
1181 * with TLV parsing */
1182 jnx_header_len
+= jnx_ext_len
;
1185 printf(", PCAP Extension(s) total length %u",
1188 TCHECK2(tptr
[0], jnx_ext_len
);
1189 while (jnx_ext_len
> JUNIPER_EXT_TLV_OVERHEAD
) {
1190 tlv_type
= *(tptr
++);
1191 tlv_len
= *(tptr
++);
1195 if (tlv_type
== 0 || tlv_len
== 0)
1199 printf("\n\t %s Extension TLV #%u, length %u, value ",
1200 tok2str(jnx_ext_tlv_values
,"Unknown",tlv_type
),
1204 tlv_value
= juniper_read_tlv_value(tptr
, tlv_type
, tlv_len
);
1206 case JUNIPER_EXT_TLV_IFD_NAME
:
1209 case JUNIPER_EXT_TLV_IFD_MEDIATYPE
:
1210 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
:
1211 if (tlv_value
!= -1) {
1214 tok2str(juniper_ifmt_values
, "Unknown", tlv_value
),
1218 case JUNIPER_EXT_TLV_IFL_ENCAPS
:
1219 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
:
1220 if (tlv_value
!= -1) {
1223 tok2str(juniper_ifle_values
, "Unknown", tlv_value
),
1227 case JUNIPER_EXT_TLV_IFL_IDX
: /* fall through */
1228 case JUNIPER_EXT_TLV_IFL_UNIT
:
1229 case JUNIPER_EXT_TLV_IFD_IDX
:
1231 if (tlv_value
!= -1) {
1233 printf("%u",tlv_value
);
1239 jnx_ext_len
-= tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
;
1243 printf("\n\t-----original packet-----\n\t");
1246 if ((l2info
->flags
& JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
1248 printf("no-L2-hdr, ");
1250 /* there is no link-layer present -
1251 * perform the v4/v6 heuristics
1252 * to figure out what it is
1254 TCHECK2(p
[jnx_header_len
+4],1);
1255 if(ip_heuristic_guess(p
+jnx_header_len
+4,l2info
->length
-(jnx_header_len
+4)) == 0)
1256 printf("no IP-hdr found!");
1258 l2info
->header_len
=jnx_header_len
+4;
1259 return 0; /* stop parsing the output further */
1262 l2info
->header_len
= jnx_header_len
;
1263 p
+=l2info
->header_len
;
1264 l2info
->length
-= l2info
->header_len
;
1265 l2info
->caplen
-= l2info
->header_len
;
1267 /* search through the cookie table and copy values matching for our PIC type */
1268 while (lp
->s
!= NULL
) {
1269 if (lp
->pictype
== l2info
->pictype
) {
1271 l2info
->cookie_len
+= lp
->cookie_len
;
1275 l2info
->cookie_type
= LS_COOKIE_ID
;
1276 l2info
->cookie_len
+= 2;
1279 l2info
->cookie_type
= AS_COOKIE_ID
;
1280 l2info
->cookie_len
= 8;
1284 l2info
->bundle
= l2info
->cookie
[0];
1289 #ifdef DLT_JUNIPER_MFR
1290 /* MFR child links don't carry cookies */
1291 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
1292 (p
[0] & MFR_BE_MASK
) == MFR_BE_MASK
) {
1293 l2info
->cookie_len
= 0;
1297 l2info
->header_len
+= l2info
->cookie_len
;
1298 l2info
->length
-= l2info
->cookie_len
;
1299 l2info
->caplen
-= l2info
->cookie_len
;
1302 printf("%s-PIC, cookie-len %u",
1304 l2info
->cookie_len
);
1306 if (l2info
->cookie_len
> 0) {
1307 TCHECK2(p
[0],l2info
->cookie_len
);
1309 printf(", cookie 0x");
1310 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
1311 l2info
->cookie
[idx
] = p
[idx
]; /* copy cookie data */
1312 if (eflag
) printf("%02x",p
[idx
]);
1316 if (eflag
) printf(": "); /* print demarc b/w L2/L3*/
1319 l2info
->proto
= EXTRACT_16BITS(p
+l2info
->cookie_len
);
1324 p
+=l2info
->cookie_len
;
1326 /* DLT_ specific parsing */
1327 switch(l2info
->pictype
) {
1328 #ifdef DLT_JUNIPER_MLPPP
1329 case DLT_JUNIPER_MLPPP
:
1330 switch (l2info
->cookie_type
) {
1332 l2info
->bundle
= l2info
->cookie
[1];
1335 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1336 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1339 l2info
->bundle
= l2info
->cookie
[0];
1344 #ifdef DLT_JUNIPER_MLFR
1345 case DLT_JUNIPER_MLFR
:
1346 switch (l2info
->cookie_type
) {
1348 l2info
->bundle
= l2info
->cookie
[1];
1349 l2info
->proto
= EXTRACT_16BITS(p
);
1350 l2info
->header_len
+= 2;
1351 l2info
->length
-= 2;
1352 l2info
->caplen
-= 2;
1355 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1356 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1359 l2info
->bundle
= l2info
->cookie
[0];
1360 l2info
->header_len
+= 2;
1361 l2info
->length
-= 2;
1362 l2info
->caplen
-= 2;
1367 #ifdef DLT_JUNIPER_MFR
1368 case DLT_JUNIPER_MFR
:
1369 switch (l2info
->cookie_type
) {
1371 l2info
->bundle
= l2info
->cookie
[1];
1372 l2info
->proto
= EXTRACT_16BITS(p
);
1373 l2info
->header_len
+= 2;
1374 l2info
->length
-= 2;
1375 l2info
->caplen
-= 2;
1378 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1379 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1382 l2info
->bundle
= l2info
->cookie
[0];
1387 #ifdef DLT_JUNIPER_ATM2
1388 case DLT_JUNIPER_ATM2
:
1390 /* ATM cell relay control word present ? */
1391 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
) {
1392 control_word
= EXTRACT_32BITS(p
);
1393 /* some control word heuristics */
1394 switch(control_word
) {
1395 case 0: /* zero control word */
1396 case 0x08000000: /* < JUNOS 7.4 control-word */
1397 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1398 l2info
->header_len
+= 4;
1405 printf("control-word 0x%08x ", control_word
);
1409 #ifdef DLT_JUNIPER_GGSN
1410 case DLT_JUNIPER_GGSN
:
1413 #ifdef DLT_JUNIPER_ATM1
1414 case DLT_JUNIPER_ATM1
:
1417 #ifdef DLT_JUNIPER_PPP
1418 case DLT_JUNIPER_PPP
:
1421 #ifdef DLT_JUNIPER_CHDLC
1422 case DLT_JUNIPER_CHDLC
:
1425 #ifdef DLT_JUNIPER_ETHER
1426 case DLT_JUNIPER_ETHER
:
1429 #ifdef DLT_JUNIPER_FRELAY
1430 case DLT_JUNIPER_FRELAY
:
1435 printf("Unknown Juniper DLT_ type %u: ", l2info
->pictype
);
1440 printf("hlen %u, proto 0x%04x, ",l2info
->header_len
,l2info
->proto
);
1442 return 1; /* everything went ok so far. continue parsing */
1444 printf("[|juniper_hdr], length %u",h
->len
);
1451 * c-style: whitesmith