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