]> The Tcpdump Group git mirrors - tcpdump/blob - print-juniper.c
remove redundant TRUE|FALSE defs
[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.33 2006-06-14 21:40:00 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 *)&l2info.cookie;
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
479 switch (gh->proto) {
480 case JUNIPER_PROTO_IPV4:
481 ip_print(gndo, p, l2info.length);
482 break;
483 #ifdef INET6
484 case JUNIPER_PROTO_IPV6:
485 ip6_print(p, l2info.length);
486 break;
487 #endif /* INET6 */
488 default:
489 if (!eflag)
490 printf("unknown GGSN proto (%u)", gh->proto);
491 }
492
493 return l2info.header_len;
494 }
495 #endif
496
497 #ifdef DLT_JUNIPER_ES
498 u_int
499 juniper_es_print(const struct pcap_pkthdr *h, register const u_char *p)
500 {
501 struct juniper_l2info_t l2info;
502 struct juniper_ipsec_header {
503 u_int8_t sa_index[2];
504 u_int8_t ttl;
505 u_int8_t type;
506 u_int8_t spi[4];
507 u_int8_t src_ip[4];
508 u_int8_t dst_ip[4];
509 };
510 u_int rewrite_len,es_type_bundle;
511 const struct juniper_ipsec_header *ih;
512
513 l2info.pictype = DLT_JUNIPER_ES;
514 if(juniper_parse_header(p, h, &l2info) == 0)
515 return l2info.header_len;
516
517 p+=l2info.header_len;
518 ih = (struct juniper_ipsec_header *)p;
519
520 switch (ih->type) {
521 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE:
522 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE:
523 rewrite_len = 0;
524 es_type_bundle = 1;
525 break;
526 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE:
527 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE:
528 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE:
529 rewrite_len = 16;
530 es_type_bundle = 0;
531 default:
532 printf("ES Invalid type %u, length %u",
533 ih->type,
534 l2info.length);
535 return l2info.header_len;
536 }
537
538 l2info.length-=rewrite_len;
539 p+=rewrite_len;
540
541 if (eflag) {
542 if (!es_type_bundle) {
543 printf("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
544 EXTRACT_16BITS(&ih->sa_index),
545 ih->ttl,
546 tok2str(juniper_ipsec_type_values,"Unknown",ih->type),
547 ih->type,
548 EXTRACT_32BITS(&ih->spi),
549 ipaddr_string(EXTRACT_32BITS(&ih->src_ip)),
550 ipaddr_string(EXTRACT_32BITS(&ih->dst_ip)),
551 l2info.length);
552 } else {
553 printf("ES SA, index %u, ttl %u type %s (%u), length %u\n",
554 EXTRACT_16BITS(&ih->sa_index),
555 ih->ttl,
556 tok2str(juniper_ipsec_type_values,"Unknown",ih->type),
557 ih->type,
558 l2info.length);
559 }
560 }
561
562 ip_print(gndo, p, l2info.length);
563 return l2info.header_len;
564 }
565 #endif
566
567 #ifdef DLT_JUNIPER_MONITOR
568 u_int
569 juniper_monitor_print(const struct pcap_pkthdr *h, register const u_char *p)
570 {
571 struct juniper_l2info_t l2info;
572 struct juniper_monitor_header {
573 u_int8_t pkt_type;
574 u_int8_t padding;
575 u_int8_t iif[2];
576 u_int8_t service_id[4];
577 };
578 const struct juniper_monitor_header *mh;
579
580 l2info.pictype = DLT_JUNIPER_MONITOR;
581 if(juniper_parse_header(p, h, &l2info) == 0)
582 return l2info.header_len;
583
584 p+=l2info.header_len;
585 mh = (struct juniper_monitor_header *)p;
586
587 if (eflag)
588 printf("service-id %u, iif %u, pkt-type %u: ",
589 EXTRACT_32BITS(&mh->service_id),
590 EXTRACT_16BITS(&mh->iif),
591 mh->pkt_type);
592
593 /* no proto field - lets guess by first byte of IP header*/
594 ip_heuristic_guess(p, l2info.length);
595
596 return l2info.header_len;
597 }
598 #endif
599
600 #ifdef DLT_JUNIPER_SERVICES
601 u_int
602 juniper_services_print(const struct pcap_pkthdr *h, register const u_char *p)
603 {
604 struct juniper_l2info_t l2info;
605 struct juniper_services_header {
606 u_int8_t svc_id;
607 u_int8_t flags_len;
608 u_int8_t svc_set_id[2];
609 u_int8_t dir_iif[4];
610 };
611 const struct juniper_services_header *sh;
612
613 l2info.pictype = DLT_JUNIPER_SERVICES;
614 if(juniper_parse_header(p, h, &l2info) == 0)
615 return l2info.header_len;
616
617 p+=l2info.header_len;
618 sh = (struct juniper_services_header *)p;
619
620 if (eflag)
621 printf("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
622 sh->svc_id,
623 sh->flags_len,
624 EXTRACT_16BITS(&sh->svc_set_id),
625 EXTRACT_24BITS(&sh->dir_iif[1]));
626
627 /* no proto field - lets guess by first byte of IP header*/
628 ip_heuristic_guess(p, l2info.length);
629
630 return l2info.header_len;
631 }
632 #endif
633
634 #ifdef DLT_JUNIPER_PPPOE
635 u_int
636 juniper_pppoe_print(const struct pcap_pkthdr *h, register const u_char *p)
637 {
638 struct juniper_l2info_t l2info;
639
640 l2info.pictype = DLT_JUNIPER_PPPOE;
641 if(juniper_parse_header(p, h, &l2info) == 0)
642 return l2info.header_len;
643
644 p+=l2info.header_len;
645 /* this DLT contains nothing but raw ethernet frames */
646 ether_print(p, l2info.length, l2info.caplen);
647 return l2info.header_len;
648 }
649 #endif
650
651 #ifdef DLT_JUNIPER_ETHER
652 u_int
653 juniper_ether_print(const struct pcap_pkthdr *h, register const u_char *p)
654 {
655 struct juniper_l2info_t l2info;
656
657 l2info.pictype = DLT_JUNIPER_ETHER;
658 if(juniper_parse_header(p, h, &l2info) == 0)
659 return l2info.header_len;
660
661 p+=l2info.header_len;
662 /* this DLT contains nothing but raw Ethernet frames */
663 ether_print(p, l2info.length, l2info.caplen);
664 return l2info.header_len;
665 }
666 #endif
667
668 #ifdef DLT_JUNIPER_PPP
669 u_int
670 juniper_ppp_print(const struct pcap_pkthdr *h, register const u_char *p)
671 {
672 struct juniper_l2info_t l2info;
673
674 l2info.pictype = DLT_JUNIPER_PPP;
675 if(juniper_parse_header(p, h, &l2info) == 0)
676 return l2info.header_len;
677
678 p+=l2info.header_len;
679 /* this DLT contains nothing but raw ppp frames */
680 ppp_print(p, l2info.length);
681 return l2info.header_len;
682 }
683 #endif
684
685 #ifdef DLT_JUNIPER_FRELAY
686 u_int
687 juniper_frelay_print(const struct pcap_pkthdr *h, register const u_char *p)
688 {
689 struct juniper_l2info_t l2info;
690
691 l2info.pictype = DLT_JUNIPER_FRELAY;
692 if(juniper_parse_header(p, h, &l2info) == 0)
693 return l2info.header_len;
694
695 p+=l2info.header_len;
696 /* this DLT contains nothing but raw frame-relay frames */
697 fr_print(p, l2info.length);
698 return l2info.header_len;
699 }
700 #endif
701
702 #ifdef DLT_JUNIPER_CHDLC
703 u_int
704 juniper_chdlc_print(const struct pcap_pkthdr *h, register const u_char *p)
705 {
706 struct juniper_l2info_t l2info;
707
708 l2info.pictype = DLT_JUNIPER_CHDLC;
709 if(juniper_parse_header(p, h, &l2info) == 0)
710 return l2info.header_len;
711
712 p+=l2info.header_len;
713 /* this DLT contains nothing but raw c-hdlc frames */
714 chdlc_print(p, l2info.length);
715 return l2info.header_len;
716 }
717 #endif
718
719 #ifdef DLT_JUNIPER_PPPOE_ATM
720 u_int
721 juniper_pppoe_atm_print(const struct pcap_pkthdr *h, register const u_char *p)
722 {
723 struct juniper_l2info_t l2info;
724 u_int16_t extracted_ethertype;
725
726 l2info.pictype = DLT_JUNIPER_PPPOE_ATM;
727 if(juniper_parse_header(p, h, &l2info) == 0)
728 return l2info.header_len;
729
730 p+=l2info.header_len;
731
732 extracted_ethertype = EXTRACT_16BITS(p);
733 /* this DLT contains nothing but raw PPPoE frames,
734 * prepended with a type field*/
735 if (ether_encap_print(extracted_ethertype,
736 p+ETHERTYPE_LEN,
737 l2info.length-ETHERTYPE_LEN,
738 l2info.caplen-ETHERTYPE_LEN,
739 &extracted_ethertype) == 0)
740 /* ether_type not known, probably it wasn't one */
741 printf("unknown ethertype 0x%04x", extracted_ethertype);
742
743 return l2info.header_len;
744 }
745 #endif
746
747 #ifdef DLT_JUNIPER_MLPPP
748 u_int
749 juniper_mlppp_print(const struct pcap_pkthdr *h, register const u_char *p)
750 {
751 struct juniper_l2info_t l2info;
752
753 l2info.pictype = DLT_JUNIPER_MLPPP;
754 if(juniper_parse_header(p, h, &l2info) == 0)
755 return l2info.header_len;
756
757 /* suppress Bundle-ID if frame was captured on a child-link
758 * best indicator if the cookie looks like a proto */
759 if (eflag &&
760 EXTRACT_16BITS(&l2info.cookie) != PPP_OSI &&
761 EXTRACT_16BITS(&l2info.cookie) != (PPP_ADDRESS << 8 | PPP_CONTROL))
762 printf("Bundle-ID %u: ",l2info.bundle);
763
764 p+=l2info.header_len;
765
766 /* first try the LSQ protos */
767 switch(l2info.proto) {
768 case JUNIPER_LSQ_L3_PROTO_IPV4:
769 /* IP traffic going to the RE would not have a cookie
770 * -> this must be incoming IS-IS over PPP
771 */
772 if (l2info.cookie[4] == (JUNIPER_LSQ_COOKIE_RE|JUNIPER_LSQ_COOKIE_DIR))
773 ppp_print(p, l2info.length);
774 else
775 ip_print(gndo, p, l2info.length);
776 return l2info.header_len;
777 #ifdef INET6
778 case JUNIPER_LSQ_L3_PROTO_IPV6:
779 ip6_print(p,l2info.length);
780 return l2info.header_len;
781 #endif
782 case JUNIPER_LSQ_L3_PROTO_MPLS:
783 mpls_print(p,l2info.length);
784 return l2info.header_len;
785 case JUNIPER_LSQ_L3_PROTO_ISO:
786 isoclns_print(p,l2info.length,l2info.caplen);
787 return l2info.header_len;
788 default:
789 break;
790 }
791
792 /* zero length cookie ? */
793 switch (EXTRACT_16BITS(&l2info.cookie)) {
794 case PPP_OSI:
795 ppp_print(p-2,l2info.length+2);
796 break;
797 case (PPP_ADDRESS << 8 | PPP_CONTROL): /* fall through */
798 default:
799 ppp_print(p,l2info.length);
800 break;
801 }
802
803 return l2info.header_len;
804 }
805 #endif
806
807
808 #ifdef DLT_JUNIPER_MFR
809 u_int
810 juniper_mfr_print(const struct pcap_pkthdr *h, register const u_char *p)
811 {
812 struct juniper_l2info_t l2info;
813
814 l2info.pictype = DLT_JUNIPER_MFR;
815 if(juniper_parse_header(p, h, &l2info) == 0)
816 return l2info.header_len;
817
818 p+=l2info.header_len;
819
820 /* child-link ? */
821 if (l2info.cookie_len == 0) {
822 mfr_print(p,l2info.length);
823 return l2info.header_len;
824 }
825
826 /* first try the LSQ protos */
827 if (l2info.cookie_len == AS_PIC_COOKIE_LEN) {
828 switch(l2info.proto) {
829 case JUNIPER_LSQ_L3_PROTO_IPV4:
830 ip_print(gndo, p, l2info.length);
831 return l2info.header_len;
832 #ifdef INET6
833 case JUNIPER_LSQ_L3_PROTO_IPV6:
834 ip6_print(p,l2info.length);
835 return l2info.header_len;
836 #endif
837 case JUNIPER_LSQ_L3_PROTO_MPLS:
838 mpls_print(p,l2info.length);
839 return l2info.header_len;
840 case JUNIPER_LSQ_L3_PROTO_ISO:
841 isoclns_print(p,l2info.length,l2info.caplen);
842 return l2info.header_len;
843 default:
844 break;
845 }
846 return l2info.header_len;
847 }
848
849 /* suppress Bundle-ID if frame was captured on a child-link */
850 if (eflag && EXTRACT_32BITS(l2info.cookie) != 1) printf("Bundle-ID %u, ",l2info.bundle);
851 switch (l2info.proto) {
852 case (LLCSAP_ISONS<<8 | LLCSAP_ISONS):
853 isoclns_print(p+1, l2info.length-1, l2info.caplen-1);
854 break;
855 case (LLC_UI<<8 | NLPID_Q933):
856 case (LLC_UI<<8 | NLPID_IP):
857 case (LLC_UI<<8 | NLPID_IP6):
858 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
859 isoclns_print(p-1, l2info.length+1, l2info.caplen+1);
860 break;
861 default:
862 printf("unknown protocol 0x%04x, length %u",l2info.proto, l2info.length);
863 }
864
865 return l2info.header_len;
866 }
867 #endif
868
869 #ifdef DLT_JUNIPER_MLFR
870 u_int
871 juniper_mlfr_print(const struct pcap_pkthdr *h, register const u_char *p)
872 {
873 struct juniper_l2info_t l2info;
874
875 l2info.pictype = DLT_JUNIPER_MLFR;
876 if(juniper_parse_header(p, h, &l2info) == 0)
877 return l2info.header_len;
878
879 p+=l2info.header_len;
880
881 /* suppress Bundle-ID if frame was captured on a child-link */
882 if (eflag && EXTRACT_32BITS(l2info.cookie) != 1) printf("Bundle-ID %u, ",l2info.bundle);
883 switch (l2info.proto) {
884 case (LLC_UI):
885 case (LLC_UI<<8):
886 isoclns_print(p, l2info.length, l2info.caplen);
887 break;
888 case (LLC_UI<<8 | NLPID_Q933):
889 case (LLC_UI<<8 | NLPID_IP):
890 case (LLC_UI<<8 | NLPID_IP6):
891 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
892 isoclns_print(p-1, l2info.length+1, l2info.caplen+1);
893 break;
894 default:
895 printf("unknown protocol 0x%04x, length %u",l2info.proto, l2info.length);
896 }
897
898 return l2info.header_len;
899 }
900 #endif
901
902 /*
903 * ATM1 PIC cookie format
904 *
905 * +-----+-------------------------+-------------------------------+
906 * |fmtid| vc index | channel ID |
907 * +-----+-------------------------+-------------------------------+
908 */
909
910 #ifdef DLT_JUNIPER_ATM1
911 u_int
912 juniper_atm1_print(const struct pcap_pkthdr *h, register const u_char *p)
913 {
914 u_int16_t extracted_ethertype;
915
916 struct juniper_l2info_t l2info;
917
918 l2info.pictype = DLT_JUNIPER_ATM1;
919 if(juniper_parse_header(p, h, &l2info) == 0)
920 return l2info.header_len;
921
922 p+=l2info.header_len;
923
924 if (l2info.cookie[0] == 0x80) { /* OAM cell ? */
925 oam_print(p,l2info.length,ATM_OAM_NOHEC);
926 return l2info.header_len;
927 }
928
929 if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */
930 EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */
931
932 if (llc_print(p, l2info.length, l2info.caplen, NULL, NULL,
933 &extracted_ethertype) != 0)
934 return l2info.header_len;
935 }
936
937 if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */
938 isoclns_print(p + 1, l2info.length - 1, l2info.caplen - 1);
939 /* FIXME check if frame was recognized */
940 return l2info.header_len;
941 }
942
943 if(ip_heuristic_guess(p, l2info.length) != 0) /* last try - vcmux encaps ? */
944 return l2info.header_len;
945
946 return l2info.header_len;
947 }
948 #endif
949
950 /*
951 * ATM2 PIC cookie format
952 *
953 * +-------------------------------+---------+---+-----+-----------+
954 * | channel ID | reserv |AAL| CCRQ| gap cnt |
955 * +-------------------------------+---------+---+-----+-----------+
956 */
957
958 #ifdef DLT_JUNIPER_ATM2
959 u_int
960 juniper_atm2_print(const struct pcap_pkthdr *h, register const u_char *p)
961 {
962 u_int16_t extracted_ethertype;
963
964 struct juniper_l2info_t l2info;
965
966 l2info.pictype = DLT_JUNIPER_ATM2;
967 if(juniper_parse_header(p, h, &l2info) == 0)
968 return l2info.header_len;
969
970 p+=l2info.header_len;
971
972 if (l2info.cookie[7] & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */
973 oam_print(p,l2info.length,ATM_OAM_NOHEC);
974 return l2info.header_len;
975 }
976
977 if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */
978 EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */
979
980 if (llc_print(p, l2info.length, l2info.caplen, NULL, NULL,
981 &extracted_ethertype) != 0)
982 return l2info.header_len;
983 }
984
985 if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */
986 (EXTRACT_32BITS(l2info.cookie) & ATM2_GAP_COUNT_MASK)) {
987 ether_print(p, l2info.length, l2info.caplen);
988 return l2info.header_len;
989 }
990
991 if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */
992 isoclns_print(p + 1, l2info.length - 1, l2info.caplen - 1);
993 /* FIXME check if frame was recognized */
994 return l2info.header_len;
995 }
996
997 if(juniper_ppp_heuristic_guess(p, l2info.length) != 0) /* PPPoA vcmux encaps ? */
998 return l2info.header_len;
999
1000 if(ip_heuristic_guess(p, l2info.length) != 0) /* last try - vcmux encaps ? */
1001 return l2info.header_len;
1002
1003 return l2info.header_len;
1004 }
1005 #endif
1006
1007
1008 /* try to guess, based on all PPP protos that are supported in
1009 * a juniper router if the payload data is encapsulated using PPP */
1010 int
1011 juniper_ppp_heuristic_guess(register const u_char *p, u_int length) {
1012
1013 switch(EXTRACT_16BITS(p)) {
1014 case PPP_IP :
1015 case PPP_OSI :
1016 case PPP_MPLS_UCAST :
1017 case PPP_MPLS_MCAST :
1018 case PPP_IPCP :
1019 case PPP_OSICP :
1020 case PPP_MPLSCP :
1021 case PPP_LCP :
1022 case PPP_PAP :
1023 case PPP_CHAP :
1024 case PPP_ML :
1025 #ifdef INET6
1026 case PPP_IPV6 :
1027 case PPP_IPV6CP :
1028 #endif
1029 ppp_print(p, length);
1030 break;
1031
1032 default:
1033 return 0; /* did not find a ppp header */
1034 break;
1035 }
1036 return 1; /* we printed a ppp packet */
1037 }
1038
1039 int
1040 ip_heuristic_guess(register const u_char *p, u_int length) {
1041
1042 switch(p[0]) {
1043 case 0x45:
1044 case 0x46:
1045 case 0x47:
1046 case 0x48:
1047 case 0x49:
1048 case 0x4a:
1049 case 0x4b:
1050 case 0x4c:
1051 case 0x4d:
1052 case 0x4e:
1053 case 0x4f:
1054 ip_print(gndo, p, length);
1055 break;
1056 #ifdef INET6
1057 case 0x60:
1058 case 0x61:
1059 case 0x62:
1060 case 0x63:
1061 case 0x64:
1062 case 0x65:
1063 case 0x66:
1064 case 0x67:
1065 case 0x68:
1066 case 0x69:
1067 case 0x6a:
1068 case 0x6b:
1069 case 0x6c:
1070 case 0x6d:
1071 case 0x6e:
1072 case 0x6f:
1073 ip6_print(p, length);
1074 break;
1075 #endif
1076 default:
1077 return 0; /* did not find a ip header */
1078 break;
1079 }
1080 return 1; /* we printed an v4/v6 packet */
1081 }
1082
1083 int
1084 juniper_read_tlv_value(const u_char *p, u_int tlv_type, u_int tlv_len) {
1085
1086 int tlv_value;
1087
1088 /* TLVs < 128 are little endian encoded */
1089 if (tlv_type < 128) {
1090 switch (tlv_len) {
1091 case 1:
1092 tlv_value = *p;
1093 break;
1094 case 2:
1095 tlv_value = EXTRACT_LE_16BITS(p);
1096 break;
1097 case 3:
1098 tlv_value = EXTRACT_LE_24BITS(p);
1099 break;
1100 case 4:
1101 tlv_value = EXTRACT_LE_32BITS(p);
1102 break;
1103 default:
1104 tlv_value = -1;
1105 break;
1106 }
1107 } else {
1108 /* TLVs >= 128 are big endian encoded */
1109 switch (tlv_len) {
1110 case 1:
1111 tlv_value = *p;
1112 break;
1113 case 2:
1114 tlv_value = EXTRACT_16BITS(p);
1115 break;
1116 case 3:
1117 tlv_value = EXTRACT_24BITS(p);
1118 break;
1119 case 4:
1120 tlv_value = EXTRACT_32BITS(p);
1121 break;
1122 default:
1123 tlv_value = -1;
1124 break;
1125 }
1126 }
1127 return tlv_value;
1128 }
1129
1130 static int
1131 juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct juniper_l2info_t *l2info) {
1132
1133 struct juniper_cookie_table_t *lp = juniper_cookie_table;
1134 u_int idx, jnx_ext_len, jnx_header_len = 0;
1135 u_int8_t tlv_type,tlv_len;
1136 u_int32_t control_word;
1137 int tlv_value;
1138 const u_char *tptr;
1139
1140
1141 l2info->header_len = 0;
1142 l2info->cookie_len = 0;
1143 l2info->proto = 0;
1144
1145
1146 l2info->length = h->len;
1147 l2info->caplen = h->caplen;
1148 TCHECK2(p[0],4);
1149 l2info->flags = p[3];
1150 l2info->direction = p[3]&JUNIPER_BPF_PKT_IN;
1151
1152 if (EXTRACT_24BITS(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */
1153 printf("no magic-number found!");
1154 return 0;
1155 }
1156
1157 if (eflag) /* print direction */
1158 printf("%3s ",tok2str(juniper_direction_values,"---",l2info->direction));
1159
1160 /* magic number + flags */
1161 jnx_header_len = 4;
1162
1163 if (vflag>1)
1164 printf("\n\tJuniper PCAP Flags [%s]",
1165 bittok2str(jnx_flag_values, "none", l2info->flags));
1166
1167 /* extensions present ? - calculate how much bytes to skip */
1168 if ((l2info->flags & JUNIPER_BPF_EXT ) == JUNIPER_BPF_EXT ) {
1169
1170 tptr = p+jnx_header_len;
1171
1172 /* ok to read extension length ? */
1173 TCHECK2(tptr[0], 2);
1174 jnx_ext_len = EXTRACT_16BITS(tptr);
1175 jnx_header_len += 2;
1176 tptr +=2;
1177
1178 /* nail up the total length -
1179 * just in case something goes wrong
1180 * with TLV parsing */
1181 jnx_header_len += jnx_ext_len;
1182
1183 if (vflag>1)
1184 printf(", PCAP Extension(s) total length %u",
1185 jnx_ext_len);
1186
1187 TCHECK2(tptr[0], jnx_ext_len);
1188 while (jnx_ext_len > JUNIPER_EXT_TLV_OVERHEAD) {
1189 tlv_type = *(tptr++);
1190 tlv_len = *(tptr++);
1191 tlv_value = 0;
1192
1193 /* sanity check */
1194 if (tlv_type == 0 || tlv_len == 0)
1195 break;
1196
1197 if (vflag>1)
1198 printf("\n\t %s Extension TLV #%u, length %u, value ",
1199 tok2str(jnx_ext_tlv_values,"Unknown",tlv_type),
1200 tlv_type,
1201 tlv_len);
1202
1203 tlv_value = juniper_read_tlv_value(tptr, tlv_type, tlv_len);
1204 switch (tlv_type) {
1205 case JUNIPER_EXT_TLV_IFD_NAME:
1206 /* FIXME */
1207 break;
1208 case JUNIPER_EXT_TLV_IFD_MEDIATYPE:
1209 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE:
1210 if (tlv_value != -1) {
1211 if (vflag>1)
1212 printf("%s (%u)",
1213 tok2str(juniper_ifmt_values, "Unknown", tlv_value),
1214 tlv_value);
1215 }
1216 break;
1217 case JUNIPER_EXT_TLV_IFL_ENCAPS:
1218 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS:
1219 if (tlv_value != -1) {
1220 if (vflag>1)
1221 printf("%s (%u)",
1222 tok2str(juniper_ifle_values, "Unknown", tlv_value),
1223 tlv_value);
1224 }
1225 break;
1226 case JUNIPER_EXT_TLV_IFL_IDX: /* fall through */
1227 case JUNIPER_EXT_TLV_IFL_UNIT:
1228 case JUNIPER_EXT_TLV_IFD_IDX:
1229 default:
1230 if (tlv_value != -1) {
1231 if (vflag>1)
1232 printf("%u",tlv_value);
1233 }
1234 break;
1235 }
1236
1237 tptr+=tlv_len;
1238 jnx_ext_len -= tlv_len+JUNIPER_EXT_TLV_OVERHEAD;
1239 }
1240
1241 if (vflag>1)
1242 printf("\n\t-----original packet-----\n\t");
1243 }
1244
1245 if ((l2info->flags & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) {
1246 if (eflag)
1247 printf("no-L2-hdr, ");
1248
1249 /* there is no link-layer present -
1250 * perform the v4/v6 heuristics
1251 * to figure out what it is
1252 */
1253 TCHECK2(p[jnx_header_len+4],1);
1254 if(ip_heuristic_guess(p+jnx_header_len+4,l2info->length-(jnx_header_len+4)) == 0)
1255 printf("no IP-hdr found!");
1256
1257 l2info->header_len=jnx_header_len+4;
1258 return 0; /* stop parsing the output further */
1259
1260 }
1261 l2info->header_len = jnx_header_len;
1262 p+=l2info->header_len;
1263 l2info->length -= l2info->header_len;
1264 l2info->caplen -= l2info->header_len;
1265
1266 /* search through the cookie table and copy values matching for our PIC type */
1267 while (lp->s != NULL) {
1268 if (lp->pictype == l2info->pictype) {
1269
1270 l2info->cookie_len += lp->cookie_len;
1271
1272 switch (p[0]) {
1273 case LS_COOKIE_ID:
1274 l2info->cookie_type = LS_COOKIE_ID;
1275 l2info->cookie_len += 2;
1276 break;
1277 case AS_COOKIE_ID:
1278 l2info->cookie_type = AS_COOKIE_ID;
1279 l2info->cookie_len = 8;
1280 break;
1281
1282 default:
1283 l2info->bundle = l2info->cookie[0];
1284 break;
1285 }
1286
1287
1288 #ifdef DLT_JUNIPER_MFR
1289 /* MFR child links don't carry cookies */
1290 if (l2info->pictype == DLT_JUNIPER_MFR &&
1291 (p[0] & MFR_BE_MASK) == MFR_BE_MASK) {
1292 l2info->cookie_len = 0;
1293 }
1294 #endif
1295
1296 l2info->header_len += l2info->cookie_len;
1297 l2info->length -= l2info->cookie_len;
1298 l2info->caplen -= l2info->cookie_len;
1299
1300 if (eflag)
1301 printf("%s-PIC, cookie-len %u",
1302 lp->s,
1303 l2info->cookie_len);
1304
1305 if (l2info->cookie_len > 0) {
1306 TCHECK2(p[0],l2info->cookie_len);
1307 if (eflag)
1308 printf(", cookie 0x");
1309 for (idx = 0; idx < l2info->cookie_len; idx++) {
1310 l2info->cookie[idx] = p[idx]; /* copy cookie data */
1311 if (eflag) printf("%02x",p[idx]);
1312 }
1313 }
1314
1315 if (eflag) printf(": "); /* print demarc b/w L2/L3*/
1316
1317
1318 l2info->proto = EXTRACT_16BITS(p+l2info->cookie_len);
1319 break;
1320 }
1321 ++lp;
1322 }
1323 p+=l2info->cookie_len;
1324
1325 /* DLT_ specific parsing */
1326 switch(l2info->pictype) {
1327 #ifdef DLT_JUNIPER_MLPPP
1328 case DLT_JUNIPER_MLPPP:
1329 switch (l2info->cookie_type) {
1330 case LS_COOKIE_ID:
1331 l2info->bundle = l2info->cookie[1];
1332 break;
1333 case AS_COOKIE_ID:
1334 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
1335 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1336 break;
1337 default:
1338 l2info->bundle = l2info->cookie[0];
1339 break;
1340 }
1341 break;
1342 #endif
1343 #ifdef DLT_JUNIPER_MLFR
1344 case DLT_JUNIPER_MLFR:
1345 switch (l2info->cookie_type) {
1346 case LS_COOKIE_ID:
1347 l2info->bundle = l2info->cookie[1];
1348 l2info->proto = EXTRACT_16BITS(p);
1349 l2info->header_len += 2;
1350 l2info->length -= 2;
1351 l2info->caplen -= 2;
1352 break;
1353 case AS_COOKIE_ID:
1354 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
1355 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1356 break;
1357 default:
1358 l2info->bundle = l2info->cookie[0];
1359 l2info->header_len += 2;
1360 l2info->length -= 2;
1361 l2info->caplen -= 2;
1362 break;
1363 }
1364 break;
1365 #endif
1366 #ifdef DLT_JUNIPER_MFR
1367 case DLT_JUNIPER_MFR:
1368 switch (l2info->cookie_type) {
1369 case LS_COOKIE_ID:
1370 l2info->bundle = l2info->cookie[1];
1371 l2info->proto = EXTRACT_16BITS(p);
1372 l2info->header_len += 2;
1373 l2info->length -= 2;
1374 l2info->caplen -= 2;
1375 break;
1376 case AS_COOKIE_ID:
1377 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
1378 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1379 break;
1380 default:
1381 l2info->bundle = l2info->cookie[0];
1382 break;
1383 }
1384 break;
1385 #endif
1386 #ifdef DLT_JUNIPER_ATM2
1387 case DLT_JUNIPER_ATM2:
1388 TCHECK2(p[0],4);
1389 /* ATM cell relay control word present ? */
1390 if (l2info->cookie[7] & ATM2_PKT_TYPE_MASK) {
1391 control_word = EXTRACT_32BITS(p);
1392 /* some control word heuristics */
1393 switch(control_word) {
1394 case 0: /* zero control word */
1395 case 0x08000000: /* < JUNOS 7.4 control-word */
1396 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1397 l2info->header_len += 4;
1398 break;
1399 default:
1400 break;
1401 }
1402
1403 if (eflag)
1404 printf("control-word 0x%08x ", control_word);
1405 }
1406 break;
1407 #endif
1408 #ifdef DLT_JUNIPER_GGSN
1409 case DLT_JUNIPER_GGSN:
1410 break;
1411 #endif
1412 #ifdef DLT_JUNIPER_ATM1
1413 case DLT_JUNIPER_ATM1:
1414 break;
1415 #endif
1416 #ifdef DLT_JUNIPER_PPP
1417 case DLT_JUNIPER_PPP:
1418 break;
1419 #endif
1420 #ifdef DLT_JUNIPER_CHDLC
1421 case DLT_JUNIPER_CHDLC:
1422 break;
1423 #endif
1424 #ifdef DLT_JUNIPER_ETHER
1425 case DLT_JUNIPER_ETHER:
1426 break;
1427 #endif
1428 #ifdef DLT_JUNIPER_FRELAY
1429 case DLT_JUNIPER_FRELAY:
1430 break;
1431 #endif
1432
1433 default:
1434 printf("Unknown Juniper DLT_ type %u: ", l2info->pictype);
1435 break;
1436 }
1437
1438 if (eflag > 1)
1439 printf("hlen %u, proto 0x%04x, ",l2info->header_len,l2info->proto);
1440
1441 return 1; /* everything went ok so far. continue parsing */
1442 trunc:
1443 printf("[|juniper_hdr], length %u",h->len);
1444 return 0;
1445 }
1446
1447
1448 /*
1449 * Local Variables:
1450 * c-style: whitesmith
1451 * c-basic-offset: 4
1452 * End:
1453 */