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