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