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