blob: 83ac372f4078a858cc3217b1ded3759f614aa3bf [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/* NetBSD: print-juniper.c,v 1.2 2007/07/24 11:53:45 drochner Exp */
2
Elliott Hughes892a68b2015-10-19 14:43:53 -07003/*
The Android Open Source Project2949f582009-03-03 19:30:46 -08004 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
15 * Original code by Hannes Gredler (hannes@juniper.net)
16 */
17
Elliott Hughese2e3bd12017-05-15 10:59:29 -070018/* \summary: DLT_JUNIPER_* printers */
19
The Android Open Source Project2949f582009-03-03 19:30:46 -080020#ifndef lint
JP Abgrall53f17a92014-02-12 14:02:41 -080021#else
22__RCSID("NetBSD: print-juniper.c,v 1.3 2007/07/25 06:31:32 dogcow Exp ");
The Android Open Source Project2949f582009-03-03 19:30:46 -080023#endif
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
Elliott Hughese2e3bd12017-05-15 10:59:29 -070029#include <netdissect-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080030
Elliott Hughese2e3bd12017-05-15 10:59:29 -070031#include <string.h>
32
33#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080034#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 */
JP Abgrall53f17a92014-02-12 14:02:41 -080046#define JUNIPER_BPF_IIF 0x4 /* IIF is valid */
47#define JUNIPER_BPF_FILTER 0x40 /* BPF filtering is supported */
The Android Open Source Project2949f582009-03-03 19:30:46 -080048#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
JP Abgrall53f17a92014-02-12 14:02:41 -080067static const struct tok juniper_ipsec_type_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080068 { 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
JP Abgrall53f17a92014-02-12 14:02:41 -080076static const struct tok juniper_direction_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080077 { JUNIPER_BPF_IN, "In"},
78 { JUNIPER_BPF_OUT, "Out"},
79 { 0, NULL}
80};
81
JP Abgrall53f17a92014-02-12 14:02:41 -080082/* codepoints for encoding extensions to a .pcap file */
83enum {
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,
Elliott Hughes892a68b2015-10-19 14:43:53 -070089 JUNIPER_EXT_TLV_IFL_ENCAPS = 6,
90 JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE = 7,
JP Abgrall53f17a92014-02-12 14:02:41 -080091 JUNIPER_EXT_TLV_TTP_IFL_ENCAPS = 8
92};
93
94/* 1 byte type and 1-byte length */
Elliott Hughese2e3bd12017-05-15 10:59:29 -070095#define JUNIPER_EXT_TLV_OVERHEAD 2U
JP Abgrall53f17a92014-02-12 14:02:41 -080096
97static 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
109static 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
179static 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
302static 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
The Android Open Source Project2949f582009-03-03 19:30:46 -0800367struct juniper_cookie_table_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700368 uint32_t pictype; /* pic type */
369 uint8_t cookie_len; /* cookie len */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800370 const char *s; /* pic name */
371};
372
Elliott Hughes892a68b2015-10-19 14:43:53 -0700373static const struct juniper_cookie_table_t juniper_cookie_table[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800374#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
410struct juniper_l2info_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700411 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;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800422};
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
JP Abgrall53f17a92014-02-12 14:02:41 -0800441static const struct tok juniper_protocol_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800442 { JUNIPER_PROTO_NULL, "Null" },
443 { JUNIPER_PROTO_IPV4, "IPv4" },
444 { JUNIPER_PROTO_IPV6, "IPv6" },
445 { 0, NULL}
446};
447
Elliott Hughes892a68b2015-10-19 14:43:53 -0700448static int ip_heuristic_guess(netdissect_options *, register const u_char *, u_int);
449static int juniper_ppp_heuristic_guess(netdissect_options *, register const u_char *, u_int);
450static int juniper_parse_header(netdissect_options *, const u_char *, const struct pcap_pkthdr *, struct juniper_l2info_t *);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800451
452#ifdef DLT_JUNIPER_GGSN
453u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700454juniper_ggsn_print(netdissect_options *ndo,
455 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800456{
457 struct juniper_l2info_t l2info;
458 struct juniper_ggsn_header {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700459 uint8_t svc_id;
460 uint8_t flags_len;
461 uint8_t proto;
462 uint8_t flags;
463 uint8_t vlan_id[2];
464 uint8_t res[2];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800465 };
466 const struct juniper_ggsn_header *gh;
467
468 l2info.pictype = DLT_JUNIPER_GGSN;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700469 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800470 return l2info.header_len;
471
472 p+=l2info.header_len;
JP Abgrall53f17a92014-02-12 14:02:41 -0800473 gh = (struct juniper_ggsn_header *)&l2info.cookie;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800474
Elliott Hughes892a68b2015-10-19 14:43:53 -0700475 if (ndo->ndo_eflag) {
476 ND_PRINT((ndo, "proto %s (%u), vlan %u: ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800477 tok2str(juniper_protocol_values,"Unknown",gh->proto),
478 gh->proto,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700479 EXTRACT_16BITS(&gh->vlan_id[0])));
JP Abgrall53f17a92014-02-12 14:02:41 -0800480 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800481
482 switch (gh->proto) {
483 case JUNIPER_PROTO_IPV4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700484 ip_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800485 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800486 case JUNIPER_PROTO_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700487 ip6_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800488 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800489 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700490 if (!ndo->ndo_eflag)
491 ND_PRINT((ndo, "unknown GGSN proto (%u)", gh->proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800492 }
493
494 return l2info.header_len;
495}
496#endif
497
498#ifdef DLT_JUNIPER_ES
499u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700500juniper_es_print(netdissect_options *ndo,
501 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800502{
503 struct juniper_l2info_t l2info;
504 struct juniper_ipsec_header {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700505 uint8_t sa_index[2];
506 uint8_t ttl;
507 uint8_t type;
508 uint8_t spi[4];
509 uint8_t src_ip[4];
510 uint8_t dst_ip[4];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800511 };
512 u_int rewrite_len,es_type_bundle;
513 const struct juniper_ipsec_header *ih;
514
515 l2info.pictype = DLT_JUNIPER_ES;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700516 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800517 return l2info.header_len;
518
519 p+=l2info.header_len;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700520 ih = (const struct juniper_ipsec_header *)p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800521
522 switch (ih->type) {
523 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE:
524 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE:
525 rewrite_len = 0;
526 es_type_bundle = 1;
527 break;
528 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE:
529 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE:
530 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE:
531 rewrite_len = 16;
532 es_type_bundle = 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700533 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800534 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700535 ND_PRINT((ndo, "ES Invalid type %u, length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800536 ih->type,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700537 l2info.length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800538 return l2info.header_len;
539 }
540
541 l2info.length-=rewrite_len;
542 p+=rewrite_len;
543
Elliott Hughes892a68b2015-10-19 14:43:53 -0700544 if (ndo->ndo_eflag) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800545 if (!es_type_bundle) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700546 ND_PRINT((ndo, "ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800547 EXTRACT_16BITS(&ih->sa_index),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700548 ih->ttl,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800549 tok2str(juniper_ipsec_type_values,"Unknown",ih->type),
550 ih->type,
551 EXTRACT_32BITS(&ih->spi),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700552 ipaddr_string(ndo, &ih->src_ip),
553 ipaddr_string(ndo, &ih->dst_ip),
554 l2info.length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800555 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700556 ND_PRINT((ndo, "ES SA, index %u, ttl %u type %s (%u), length %u\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800557 EXTRACT_16BITS(&ih->sa_index),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700558 ih->ttl,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800559 tok2str(juniper_ipsec_type_values,"Unknown",ih->type),
560 ih->type,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700561 l2info.length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800562 }
563 }
564
Elliott Hughes892a68b2015-10-19 14:43:53 -0700565 ip_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800566 return l2info.header_len;
567}
568#endif
569
570#ifdef DLT_JUNIPER_MONITOR
571u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700572juniper_monitor_print(netdissect_options *ndo,
573 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800574{
575 struct juniper_l2info_t l2info;
576 struct juniper_monitor_header {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700577 uint8_t pkt_type;
578 uint8_t padding;
579 uint8_t iif[2];
580 uint8_t service_id[4];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800581 };
582 const struct juniper_monitor_header *mh;
583
584 l2info.pictype = DLT_JUNIPER_MONITOR;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700585 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800586 return l2info.header_len;
587
588 p+=l2info.header_len;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700589 mh = (const struct juniper_monitor_header *)p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800590
Elliott Hughes892a68b2015-10-19 14:43:53 -0700591 if (ndo->ndo_eflag)
592 ND_PRINT((ndo, "service-id %u, iif %u, pkt-type %u: ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800593 EXTRACT_32BITS(&mh->service_id),
594 EXTRACT_16BITS(&mh->iif),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700595 mh->pkt_type));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800596
597 /* no proto field - lets guess by first byte of IP header*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700598 ip_heuristic_guess (ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800599
600 return l2info.header_len;
601}
602#endif
603
604#ifdef DLT_JUNIPER_SERVICES
605u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700606juniper_services_print(netdissect_options *ndo,
607 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800608{
609 struct juniper_l2info_t l2info;
610 struct juniper_services_header {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700611 uint8_t svc_id;
612 uint8_t flags_len;
613 uint8_t svc_set_id[2];
614 uint8_t dir_iif[4];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800615 };
616 const struct juniper_services_header *sh;
617
618 l2info.pictype = DLT_JUNIPER_SERVICES;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700619 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800620 return l2info.header_len;
621
622 p+=l2info.header_len;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700623 sh = (const struct juniper_services_header *)p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800624
Elliott Hughes892a68b2015-10-19 14:43:53 -0700625 if (ndo->ndo_eflag)
626 ND_PRINT((ndo, "service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800627 sh->svc_id,
628 sh->flags_len,
629 EXTRACT_16BITS(&sh->svc_set_id),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700630 EXTRACT_24BITS(&sh->dir_iif[1])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800631
632 /* no proto field - lets guess by first byte of IP header*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700633 ip_heuristic_guess (ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800634
635 return l2info.header_len;
636}
637#endif
638
639#ifdef DLT_JUNIPER_PPPOE
640u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700641juniper_pppoe_print(netdissect_options *ndo,
642 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800643{
644 struct juniper_l2info_t l2info;
645
646 l2info.pictype = DLT_JUNIPER_PPPOE;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700647 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800648 return l2info.header_len;
649
650 p+=l2info.header_len;
651 /* this DLT contains nothing but raw ethernet frames */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700652 ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800653 return l2info.header_len;
654}
655#endif
656
657#ifdef DLT_JUNIPER_ETHER
658u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700659juniper_ether_print(netdissect_options *ndo,
660 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800661{
662 struct juniper_l2info_t l2info;
663
664 l2info.pictype = DLT_JUNIPER_ETHER;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700665 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800666 return l2info.header_len;
667
668 p+=l2info.header_len;
669 /* this DLT contains nothing but raw Ethernet frames */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700670 ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800671 return l2info.header_len;
672}
673#endif
674
675#ifdef DLT_JUNIPER_PPP
676u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700677juniper_ppp_print(netdissect_options *ndo,
678 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800679{
680 struct juniper_l2info_t l2info;
681
682 l2info.pictype = DLT_JUNIPER_PPP;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700683 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800684 return l2info.header_len;
685
686 p+=l2info.header_len;
687 /* this DLT contains nothing but raw ppp frames */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700688 ppp_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800689 return l2info.header_len;
690}
691#endif
692
693#ifdef DLT_JUNIPER_FRELAY
694u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700695juniper_frelay_print(netdissect_options *ndo,
696 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800697{
698 struct juniper_l2info_t l2info;
699
700 l2info.pictype = DLT_JUNIPER_FRELAY;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700701 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800702 return l2info.header_len;
703
704 p+=l2info.header_len;
705 /* this DLT contains nothing but raw frame-relay frames */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700706 fr_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800707 return l2info.header_len;
708}
709#endif
710
711#ifdef DLT_JUNIPER_CHDLC
712u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700713juniper_chdlc_print(netdissect_options *ndo,
714 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800715{
716 struct juniper_l2info_t l2info;
717
718 l2info.pictype = DLT_JUNIPER_CHDLC;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700719 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800720 return l2info.header_len;
721
722 p+=l2info.header_len;
723 /* this DLT contains nothing but raw c-hdlc frames */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700724 chdlc_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800725 return l2info.header_len;
726}
727#endif
728
729#ifdef DLT_JUNIPER_PPPOE_ATM
730u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700731juniper_pppoe_atm_print(netdissect_options *ndo,
732 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800733{
734 struct juniper_l2info_t l2info;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700735 uint16_t extracted_ethertype;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800736
737 l2info.pictype = DLT_JUNIPER_PPPOE_ATM;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700738 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800739 return l2info.header_len;
740
741 p+=l2info.header_len;
742
743 extracted_ethertype = EXTRACT_16BITS(p);
744 /* this DLT contains nothing but raw PPPoE frames,
745 * prepended with a type field*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700746 if (ethertype_print(ndo, extracted_ethertype,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800747 p+ETHERTYPE_LEN,
748 l2info.length-ETHERTYPE_LEN,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700749 l2info.caplen-ETHERTYPE_LEN,
750 NULL, NULL) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800751 /* ether_type not known, probably it wasn't one */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700752 ND_PRINT((ndo, "unknown ethertype 0x%04x", extracted_ethertype));
753
The Android Open Source Project2949f582009-03-03 19:30:46 -0800754 return l2info.header_len;
755}
756#endif
757
758#ifdef DLT_JUNIPER_MLPPP
759u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700760juniper_mlppp_print(netdissect_options *ndo,
761 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800762{
763 struct juniper_l2info_t l2info;
764
765 l2info.pictype = DLT_JUNIPER_MLPPP;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700766 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800767 return l2info.header_len;
768
769 /* suppress Bundle-ID if frame was captured on a child-link
770 * best indicator if the cookie looks like a proto */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700771 if (ndo->ndo_eflag &&
The Android Open Source Project2949f582009-03-03 19:30:46 -0800772 EXTRACT_16BITS(&l2info.cookie) != PPP_OSI &&
773 EXTRACT_16BITS(&l2info.cookie) != (PPP_ADDRESS << 8 | PPP_CONTROL))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700774 ND_PRINT((ndo, "Bundle-ID %u: ", l2info.bundle));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800775
776 p+=l2info.header_len;
777
778 /* first try the LSQ protos */
779 switch(l2info.proto) {
780 case JUNIPER_LSQ_L3_PROTO_IPV4:
781 /* IP traffic going to the RE would not have a cookie
782 * -> this must be incoming IS-IS over PPP
783 */
784 if (l2info.cookie[4] == (JUNIPER_LSQ_COOKIE_RE|JUNIPER_LSQ_COOKIE_DIR))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700785 ppp_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800786 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700787 ip_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800788 return l2info.header_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800789 case JUNIPER_LSQ_L3_PROTO_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700790 ip6_print(ndo, p,l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800791 return l2info.header_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800792 case JUNIPER_LSQ_L3_PROTO_MPLS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700793 mpls_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800794 return l2info.header_len;
795 case JUNIPER_LSQ_L3_PROTO_ISO:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700796 isoclns_print(ndo, p, l2info.length, l2info.caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800797 return l2info.header_len;
798 default:
799 break;
800 }
801
802 /* zero length cookie ? */
803 switch (EXTRACT_16BITS(&l2info.cookie)) {
804 case PPP_OSI:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700805 ppp_print(ndo, p - 2, l2info.length + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800806 break;
807 case (PPP_ADDRESS << 8 | PPP_CONTROL): /* fall through */
808 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700809 ppp_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800810 break;
811 }
812
813 return l2info.header_len;
814}
815#endif
816
817
818#ifdef DLT_JUNIPER_MFR
819u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700820juniper_mfr_print(netdissect_options *ndo,
821 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800822{
823 struct juniper_l2info_t l2info;
824
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700825 memset(&l2info, 0, sizeof(l2info));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800826 l2info.pictype = DLT_JUNIPER_MFR;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700827 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800828 return l2info.header_len;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700829
The Android Open Source Project2949f582009-03-03 19:30:46 -0800830 p+=l2info.header_len;
831
832 /* child-link ? */
833 if (l2info.cookie_len == 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700834 mfr_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800835 return l2info.header_len;
836 }
837
838 /* first try the LSQ protos */
839 if (l2info.cookie_len == AS_PIC_COOKIE_LEN) {
840 switch(l2info.proto) {
841 case JUNIPER_LSQ_L3_PROTO_IPV4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700842 ip_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800843 return l2info.header_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800844 case JUNIPER_LSQ_L3_PROTO_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700845 ip6_print(ndo, p,l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800846 return l2info.header_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800847 case JUNIPER_LSQ_L3_PROTO_MPLS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700848 mpls_print(ndo, p, l2info.length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800849 return l2info.header_len;
850 case JUNIPER_LSQ_L3_PROTO_ISO:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700851 isoclns_print(ndo, p, l2info.length, l2info.caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800852 return l2info.header_len;
853 default:
854 break;
855 }
856 return l2info.header_len;
857 }
858
859 /* suppress Bundle-ID if frame was captured on a child-link */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700860 if (ndo->ndo_eflag && EXTRACT_32BITS(l2info.cookie) != 1)
861 ND_PRINT((ndo, "Bundle-ID %u, ", l2info.bundle));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800862 switch (l2info.proto) {
863 case (LLCSAP_ISONS<<8 | LLCSAP_ISONS):
Elliott Hughes892a68b2015-10-19 14:43:53 -0700864 isoclns_print(ndo, p + 1, l2info.length - 1, l2info.caplen - 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800865 break;
866 case (LLC_UI<<8 | NLPID_Q933):
867 case (LLC_UI<<8 | NLPID_IP):
868 case (LLC_UI<<8 | NLPID_IP6):
869 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700870 isoclns_print(ndo, p - 1, l2info.length + 1, l2info.caplen + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800871 break;
872 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700873 ND_PRINT((ndo, "unknown protocol 0x%04x, length %u", l2info.proto, l2info.length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800874 }
875
876 return l2info.header_len;
877}
878#endif
879
880#ifdef DLT_JUNIPER_MLFR
881u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700882juniper_mlfr_print(netdissect_options *ndo,
883 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800884{
885 struct juniper_l2info_t l2info;
886
887 l2info.pictype = DLT_JUNIPER_MLFR;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700888 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800889 return l2info.header_len;
890
891 p+=l2info.header_len;
892
893 /* suppress Bundle-ID if frame was captured on a child-link */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700894 if (ndo->ndo_eflag && EXTRACT_32BITS(l2info.cookie) != 1)
895 ND_PRINT((ndo, "Bundle-ID %u, ", l2info.bundle));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800896 switch (l2info.proto) {
897 case (LLC_UI):
898 case (LLC_UI<<8):
Elliott Hughes892a68b2015-10-19 14:43:53 -0700899 isoclns_print(ndo, p, l2info.length, l2info.caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800900 break;
901 case (LLC_UI<<8 | NLPID_Q933):
902 case (LLC_UI<<8 | NLPID_IP):
903 case (LLC_UI<<8 | NLPID_IP6):
904 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700905 isoclns_print(ndo, p - 1, l2info.length + 1, l2info.caplen + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800906 break;
907 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700908 ND_PRINT((ndo, "unknown protocol 0x%04x, length %u", l2info.proto, l2info.length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800909 }
910
911 return l2info.header_len;
912}
913#endif
914
915/*
916 * ATM1 PIC cookie format
917 *
918 * +-----+-------------------------+-------------------------------+
919 * |fmtid| vc index | channel ID |
920 * +-----+-------------------------+-------------------------------+
921 */
922
923#ifdef DLT_JUNIPER_ATM1
924u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700925juniper_atm1_print(netdissect_options *ndo,
926 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800927{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700928 int llc_hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800929
930 struct juniper_l2info_t l2info;
931
932 l2info.pictype = DLT_JUNIPER_ATM1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700933 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800934 return l2info.header_len;
935
936 p+=l2info.header_len;
937
938 if (l2info.cookie[0] == 0x80) { /* OAM cell ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700939 oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800940 return l2info.header_len;
941 }
942
943 if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */
944 EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */
945
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700946 llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
947 if (llc_hdrlen > 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800948 return l2info.header_len;
949 }
950
951 if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700952 isoclns_print(ndo, p + 1, l2info.length - 1, l2info.caplen - 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800953 /* FIXME check if frame was recognized */
954 return l2info.header_len;
955 }
956
Elliott Hughes892a68b2015-10-19 14:43:53 -0700957 if (ip_heuristic_guess(ndo, p, l2info.length) != 0) /* last try - vcmux encaps ? */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800958 return l2info.header_len;
959
960 return l2info.header_len;
961}
962#endif
963
964/*
965 * ATM2 PIC cookie format
966 *
967 * +-------------------------------+---------+---+-----+-----------+
968 * | channel ID | reserv |AAL| CCRQ| gap cnt |
969 * +-------------------------------+---------+---+-----+-----------+
970 */
971
972#ifdef DLT_JUNIPER_ATM2
973u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700974juniper_atm2_print(netdissect_options *ndo,
975 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800976{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700977 int llc_hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800978
979 struct juniper_l2info_t l2info;
980
981 l2info.pictype = DLT_JUNIPER_ATM2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700982 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800983 return l2info.header_len;
984
985 p+=l2info.header_len;
986
987 if (l2info.cookie[7] & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700988 oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800989 return l2info.header_len;
990 }
991
992 if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */
993 EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */
994
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700995 llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
996 if (llc_hdrlen > 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800997 return l2info.header_len;
998 }
999
1000 if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */
1001 (EXTRACT_32BITS(l2info.cookie) & ATM2_GAP_COUNT_MASK)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001002 ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001003 return l2info.header_len;
1004 }
1005
1006 if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001007 isoclns_print(ndo, p + 1, l2info.length - 1, l2info.caplen - 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001008 /* FIXME check if frame was recognized */
1009 return l2info.header_len;
1010 }
1011
Elliott Hughes892a68b2015-10-19 14:43:53 -07001012 if(juniper_ppp_heuristic_guess(ndo, p, l2info.length) != 0) /* PPPoA vcmux encaps ? */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001013 return l2info.header_len;
1014
Elliott Hughes892a68b2015-10-19 14:43:53 -07001015 if (ip_heuristic_guess(ndo, p, l2info.length) != 0) /* last try - vcmux encaps ? */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001016 return l2info.header_len;
1017
1018 return l2info.header_len;
1019}
1020#endif
1021
1022
1023/* try to guess, based on all PPP protos that are supported in
1024 * a juniper router if the payload data is encapsulated using PPP */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001025static int
1026juniper_ppp_heuristic_guess(netdissect_options *ndo,
1027 register const u_char *p, u_int length)
1028{
The Android Open Source Project2949f582009-03-03 19:30:46 -08001029 switch(EXTRACT_16BITS(p)) {
1030 case PPP_IP :
1031 case PPP_OSI :
1032 case PPP_MPLS_UCAST :
1033 case PPP_MPLS_MCAST :
1034 case PPP_IPCP :
1035 case PPP_OSICP :
1036 case PPP_MPLSCP :
1037 case PPP_LCP :
1038 case PPP_PAP :
1039 case PPP_CHAP :
1040 case PPP_ML :
The Android Open Source Project2949f582009-03-03 19:30:46 -08001041 case PPP_IPV6 :
1042 case PPP_IPV6CP :
Elliott Hughes892a68b2015-10-19 14:43:53 -07001043 ppp_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001044 break;
1045
1046 default:
1047 return 0; /* did not find a ppp header */
1048 break;
1049 }
1050 return 1; /* we printed a ppp packet */
1051}
1052
Elliott Hughes892a68b2015-10-19 14:43:53 -07001053static int
1054ip_heuristic_guess(netdissect_options *ndo,
1055 register const u_char *p, u_int length)
1056{
The Android Open Source Project2949f582009-03-03 19:30:46 -08001057 switch(p[0]) {
1058 case 0x45:
1059 case 0x46:
1060 case 0x47:
1061 case 0x48:
1062 case 0x49:
1063 case 0x4a:
1064 case 0x4b:
1065 case 0x4c:
1066 case 0x4d:
1067 case 0x4e:
1068 case 0x4f:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001069 ip_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001070 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001071 case 0x60:
1072 case 0x61:
1073 case 0x62:
1074 case 0x63:
1075 case 0x64:
1076 case 0x65:
1077 case 0x66:
1078 case 0x67:
1079 case 0x68:
1080 case 0x69:
1081 case 0x6a:
1082 case 0x6b:
1083 case 0x6c:
1084 case 0x6d:
1085 case 0x6e:
1086 case 0x6f:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001087 ip6_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001088 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001089 default:
1090 return 0; /* did not find a ip header */
1091 break;
1092 }
1093 return 1; /* we printed an v4/v6 packet */
1094}
1095
Elliott Hughes892a68b2015-10-19 14:43:53 -07001096static int
1097juniper_read_tlv_value(const u_char *p, u_int tlv_type, u_int tlv_len)
1098{
JP Abgrall53f17a92014-02-12 14:02:41 -08001099 int tlv_value;
1100
1101 /* TLVs < 128 are little endian encoded */
1102 if (tlv_type < 128) {
1103 switch (tlv_len) {
1104 case 1:
1105 tlv_value = *p;
1106 break;
1107 case 2:
1108 tlv_value = EXTRACT_LE_16BITS(p);
1109 break;
1110 case 3:
1111 tlv_value = EXTRACT_LE_24BITS(p);
1112 break;
1113 case 4:
1114 tlv_value = EXTRACT_LE_32BITS(p);
1115 break;
1116 default:
1117 tlv_value = -1;
1118 break;
1119 }
1120 } else {
1121 /* TLVs >= 128 are big endian encoded */
1122 switch (tlv_len) {
1123 case 1:
1124 tlv_value = *p;
1125 break;
1126 case 2:
1127 tlv_value = EXTRACT_16BITS(p);
1128 break;
1129 case 3:
1130 tlv_value = EXTRACT_24BITS(p);
1131 break;
1132 case 4:
1133 tlv_value = EXTRACT_32BITS(p);
1134 break;
1135 default:
1136 tlv_value = -1;
1137 break;
1138 }
1139 }
1140 return tlv_value;
1141}
1142
The Android Open Source Project2949f582009-03-03 19:30:46 -08001143static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001144juniper_parse_header(netdissect_options *ndo,
1145 const u_char *p, const struct pcap_pkthdr *h, struct juniper_l2info_t *l2info)
1146{
1147 const struct juniper_cookie_table_t *lp = juniper_cookie_table;
JP Abgrall53f17a92014-02-12 14:02:41 -08001148 u_int idx, jnx_ext_len, jnx_header_len = 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001149 uint8_t tlv_type,tlv_len;
1150 uint32_t control_word;
JP Abgrall53f17a92014-02-12 14:02:41 -08001151 int tlv_value;
1152 const u_char *tptr;
1153
The Android Open Source Project2949f582009-03-03 19:30:46 -08001154
1155 l2info->header_len = 0;
1156 l2info->cookie_len = 0;
1157 l2info->proto = 0;
1158
1159
1160 l2info->length = h->len;
1161 l2info->caplen = h->caplen;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001162 ND_TCHECK2(p[0], 4);
JP Abgrall53f17a92014-02-12 14:02:41 -08001163 l2info->flags = p[3];
The Android Open Source Project2949f582009-03-03 19:30:46 -08001164 l2info->direction = p[3]&JUNIPER_BPF_PKT_IN;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001165
Elliott Hughes892a68b2015-10-19 14:43:53 -07001166 if (EXTRACT_24BITS(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */
1167 ND_PRINT((ndo, "no magic-number found!"));
1168 return 0;
1169 }
1170
1171 if (ndo->ndo_eflag) /* print direction */
1172 ND_PRINT((ndo, "%3s ", tok2str(juniper_direction_values, "---", l2info->direction)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001173
JP Abgrall53f17a92014-02-12 14:02:41 -08001174 /* magic number + flags */
1175 jnx_header_len = 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001176
Elliott Hughes892a68b2015-10-19 14:43:53 -07001177 if (ndo->ndo_vflag > 1)
1178 ND_PRINT((ndo, "\n\tJuniper PCAP Flags [%s]",
1179 bittok2str(jnx_flag_values, "none", l2info->flags)));
JP Abgrall53f17a92014-02-12 14:02:41 -08001180
1181 /* extensions present ? - calculate how much bytes to skip */
1182 if ((l2info->flags & JUNIPER_BPF_EXT ) == JUNIPER_BPF_EXT ) {
1183
1184 tptr = p+jnx_header_len;
1185
1186 /* ok to read extension length ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001187 ND_TCHECK2(tptr[0], 2);
JP Abgrall53f17a92014-02-12 14:02:41 -08001188 jnx_ext_len = EXTRACT_16BITS(tptr);
1189 jnx_header_len += 2;
1190 tptr +=2;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001191
JP Abgrall53f17a92014-02-12 14:02:41 -08001192 /* nail up the total length -
1193 * just in case something goes wrong
1194 * with TLV parsing */
1195 jnx_header_len += jnx_ext_len;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001196
1197 if (ndo->ndo_vflag > 1)
1198 ND_PRINT((ndo, ", PCAP Extension(s) total length %u", jnx_ext_len));
1199
1200 ND_TCHECK2(tptr[0], jnx_ext_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001201 while (jnx_ext_len > JUNIPER_EXT_TLV_OVERHEAD) {
1202 tlv_type = *(tptr++);
1203 tlv_len = *(tptr++);
1204 tlv_value = 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001205
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001206 /* sanity checks */
JP Abgrall53f17a92014-02-12 14:02:41 -08001207 if (tlv_type == 0 || tlv_len == 0)
1208 break;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001209 if (tlv_len+JUNIPER_EXT_TLV_OVERHEAD > jnx_ext_len)
1210 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001211
1212 if (ndo->ndo_vflag > 1)
1213 ND_PRINT((ndo, "\n\t %s Extension TLV #%u, length %u, value ",
JP Abgrall53f17a92014-02-12 14:02:41 -08001214 tok2str(jnx_ext_tlv_values,"Unknown",tlv_type),
1215 tlv_type,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001216 tlv_len));
1217
JP Abgrall53f17a92014-02-12 14:02:41 -08001218 tlv_value = juniper_read_tlv_value(tptr, tlv_type, tlv_len);
1219 switch (tlv_type) {
1220 case JUNIPER_EXT_TLV_IFD_NAME:
1221 /* FIXME */
1222 break;
1223 case JUNIPER_EXT_TLV_IFD_MEDIATYPE:
1224 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE:
1225 if (tlv_value != -1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001226 if (ndo->ndo_vflag > 1)
1227 ND_PRINT((ndo, "%s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -08001228 tok2str(juniper_ifmt_values, "Unknown", tlv_value),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001229 tlv_value));
JP Abgrall53f17a92014-02-12 14:02:41 -08001230 }
1231 break;
1232 case JUNIPER_EXT_TLV_IFL_ENCAPS:
1233 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS:
1234 if (tlv_value != -1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001235 if (ndo->ndo_vflag > 1)
1236 ND_PRINT((ndo, "%s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -08001237 tok2str(juniper_ifle_values, "Unknown", tlv_value),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001238 tlv_value));
JP Abgrall53f17a92014-02-12 14:02:41 -08001239 }
1240 break;
1241 case JUNIPER_EXT_TLV_IFL_IDX: /* fall through */
1242 case JUNIPER_EXT_TLV_IFL_UNIT:
1243 case JUNIPER_EXT_TLV_IFD_IDX:
1244 default:
1245 if (tlv_value != -1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001246 if (ndo->ndo_vflag > 1)
1247 ND_PRINT((ndo, "%u", tlv_value));
JP Abgrall53f17a92014-02-12 14:02:41 -08001248 }
1249 break;
1250 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001251
JP Abgrall53f17a92014-02-12 14:02:41 -08001252 tptr+=tlv_len;
1253 jnx_ext_len -= tlv_len+JUNIPER_EXT_TLV_OVERHEAD;
1254 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001255
1256 if (ndo->ndo_vflag > 1)
1257 ND_PRINT((ndo, "\n\t-----original packet-----\n\t"));
1258 }
1259
1260 if ((l2info->flags & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) {
1261 if (ndo->ndo_eflag)
1262 ND_PRINT((ndo, "no-L2-hdr, "));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001263
1264 /* there is no link-layer present -
1265 * perform the v4/v6 heuristics
1266 * to figure out what it is
1267 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001268 ND_TCHECK2(p[jnx_header_len + 4], 1);
1269 if (ip_heuristic_guess(ndo, p + jnx_header_len + 4,
1270 l2info->length - (jnx_header_len + 4)) == 0)
1271 ND_PRINT((ndo, "no IP-hdr found!"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001272
JP Abgrall53f17a92014-02-12 14:02:41 -08001273 l2info->header_len=jnx_header_len+4;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001274 return 0; /* stop parsing the output further */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001275
The Android Open Source Project2949f582009-03-03 19:30:46 -08001276 }
JP Abgrall53f17a92014-02-12 14:02:41 -08001277 l2info->header_len = jnx_header_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001278 p+=l2info->header_len;
1279 l2info->length -= l2info->header_len;
1280 l2info->caplen -= l2info->header_len;
1281
1282 /* search through the cookie table and copy values matching for our PIC type */
1283 while (lp->s != NULL) {
1284 if (lp->pictype == l2info->pictype) {
1285
1286 l2info->cookie_len += lp->cookie_len;
1287
1288 switch (p[0]) {
1289 case LS_COOKIE_ID:
1290 l2info->cookie_type = LS_COOKIE_ID;
1291 l2info->cookie_len += 2;
1292 break;
1293 case AS_COOKIE_ID:
1294 l2info->cookie_type = AS_COOKIE_ID;
1295 l2info->cookie_len = 8;
1296 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001297
The Android Open Source Project2949f582009-03-03 19:30:46 -08001298 default:
1299 l2info->bundle = l2info->cookie[0];
1300 break;
1301 }
1302
1303
1304#ifdef DLT_JUNIPER_MFR
1305 /* MFR child links don't carry cookies */
1306 if (l2info->pictype == DLT_JUNIPER_MFR &&
1307 (p[0] & MFR_BE_MASK) == MFR_BE_MASK) {
1308 l2info->cookie_len = 0;
1309 }
1310#endif
1311
1312 l2info->header_len += l2info->cookie_len;
1313 l2info->length -= l2info->cookie_len;
1314 l2info->caplen -= l2info->cookie_len;
1315
Elliott Hughes892a68b2015-10-19 14:43:53 -07001316 if (ndo->ndo_eflag)
1317 ND_PRINT((ndo, "%s-PIC, cookie-len %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001318 lp->s,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001319 l2info->cookie_len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001320
1321 if (l2info->cookie_len > 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001322 ND_TCHECK2(p[0], l2info->cookie_len);
1323 if (ndo->ndo_eflag)
1324 ND_PRINT((ndo, ", cookie 0x"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001325 for (idx = 0; idx < l2info->cookie_len; idx++) {
1326 l2info->cookie[idx] = p[idx]; /* copy cookie data */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001327 if (ndo->ndo_eflag) ND_PRINT((ndo, "%02x", p[idx]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001328 }
1329 }
1330
Elliott Hughes892a68b2015-10-19 14:43:53 -07001331 if (ndo->ndo_eflag) ND_PRINT((ndo, ": ")); /* print demarc b/w L2/L3*/
The Android Open Source Project2949f582009-03-03 19:30:46 -08001332
Elliott Hughes892a68b2015-10-19 14:43:53 -07001333
1334 l2info->proto = EXTRACT_16BITS(p+l2info->cookie_len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001335 break;
1336 }
1337 ++lp;
1338 }
1339 p+=l2info->cookie_len;
1340
1341 /* DLT_ specific parsing */
1342 switch(l2info->pictype) {
1343#ifdef DLT_JUNIPER_MLPPP
1344 case DLT_JUNIPER_MLPPP:
1345 switch (l2info->cookie_type) {
1346 case LS_COOKIE_ID:
1347 l2info->bundle = l2info->cookie[1];
1348 break;
1349 case AS_COOKIE_ID:
1350 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001351 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001352 break;
1353 default:
1354 l2info->bundle = l2info->cookie[0];
1355 break;
1356 }
1357 break;
1358#endif
1359#ifdef DLT_JUNIPER_MLFR
1360 case DLT_JUNIPER_MLFR:
1361 switch (l2info->cookie_type) {
1362 case LS_COOKIE_ID:
1363 l2info->bundle = l2info->cookie[1];
Elliott Hughes892a68b2015-10-19 14:43:53 -07001364 l2info->proto = EXTRACT_16BITS(p);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001365 l2info->header_len += 2;
1366 l2info->length -= 2;
1367 l2info->caplen -= 2;
1368 break;
1369 case AS_COOKIE_ID:
1370 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
1371 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1372 break;
1373 default:
1374 l2info->bundle = l2info->cookie[0];
1375 l2info->header_len += 2;
1376 l2info->length -= 2;
1377 l2info->caplen -= 2;
1378 break;
1379 }
1380 break;
1381#endif
1382#ifdef DLT_JUNIPER_MFR
1383 case DLT_JUNIPER_MFR:
1384 switch (l2info->cookie_type) {
1385 case LS_COOKIE_ID:
1386 l2info->bundle = l2info->cookie[1];
Elliott Hughes892a68b2015-10-19 14:43:53 -07001387 l2info->proto = EXTRACT_16BITS(p);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001388 l2info->header_len += 2;
1389 l2info->length -= 2;
1390 l2info->caplen -= 2;
1391 break;
1392 case AS_COOKIE_ID:
1393 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
1394 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1395 break;
1396 default:
1397 l2info->bundle = l2info->cookie[0];
1398 break;
1399 }
1400 break;
1401#endif
1402#ifdef DLT_JUNIPER_ATM2
1403 case DLT_JUNIPER_ATM2:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001404 ND_TCHECK2(p[0], 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001405 /* ATM cell relay control word present ? */
1406 if (l2info->cookie[7] & ATM2_PKT_TYPE_MASK) {
1407 control_word = EXTRACT_32BITS(p);
1408 /* some control word heuristics */
1409 switch(control_word) {
1410 case 0: /* zero control word */
1411 case 0x08000000: /* < JUNOS 7.4 control-word */
1412 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1413 l2info->header_len += 4;
1414 break;
1415 default:
1416 break;
1417 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001418
1419 if (ndo->ndo_eflag)
1420 ND_PRINT((ndo, "control-word 0x%08x ", control_word));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001421 }
1422 break;
1423#endif
JP Abgrall53f17a92014-02-12 14:02:41 -08001424#ifdef DLT_JUNIPER_GGSN
1425 case DLT_JUNIPER_GGSN:
1426 break;
1427#endif
The Android Open Source Project2949f582009-03-03 19:30:46 -08001428#ifdef DLT_JUNIPER_ATM1
1429 case DLT_JUNIPER_ATM1:
1430 break;
1431#endif
1432#ifdef DLT_JUNIPER_PPP
1433 case DLT_JUNIPER_PPP:
1434 break;
1435#endif
1436#ifdef DLT_JUNIPER_CHDLC
1437 case DLT_JUNIPER_CHDLC:
1438 break;
1439#endif
1440#ifdef DLT_JUNIPER_ETHER
1441 case DLT_JUNIPER_ETHER:
1442 break;
1443#endif
1444#ifdef DLT_JUNIPER_FRELAY
1445 case DLT_JUNIPER_FRELAY:
1446 break;
1447#endif
1448
1449 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001450 ND_PRINT((ndo, "Unknown Juniper DLT_ type %u: ", l2info->pictype));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001451 break;
1452 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001453
1454 if (ndo->ndo_eflag > 1)
1455 ND_PRINT((ndo, "hlen %u, proto 0x%04x, ", l2info->header_len, l2info->proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001456
1457 return 1; /* everything went ok so far. continue parsing */
1458 trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001459 ND_PRINT((ndo, "[|juniper_hdr], length %u", h->len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001460 return 0;
1461}
1462
1463
1464/*
1465 * Local Variables:
1466 * c-style: whitesmith
1467 * c-basic-offset: 4
1468 * End:
1469 */