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