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