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