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