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