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