1 /* NetBSD: print-juniper.c,v 1.2 2007/07/24 11:53:45 drochner Exp */
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.
15 * Original code by Hannes Gredler (hannes@gredler.at)
18 /* \summary: DLT_JUNIPER_* printers */
22 __RCSID("NetBSD: print-juniper.c,v 1.3 2007/07/25 06:31:32 dogcow Exp ");
27 #include "netdissect-stdinc.h"
31 #define ND_LONGJMP_FROM_TCHECK
32 #include "netdissect.h"
33 #include "addrtoname.h"
38 #include "ethertype.h"
42 * If none of the Juniper DLT_s are defined, there's nothing to do.
44 #if defined(DLT_JUNIPER_GGSN) || defined(DLT_JUNIPER_ES) || \
45 defined(DLT_JUNIPER_MONITOR) || defined(DLT_JUNIPER_SERVICES) || \
46 defined(DLT_JUNIPER_PPPOE) || defined(DLT_JUNIPER_ETHER) || \
47 defined(DLT_JUNIPER_PPP) || defined(DLT_JUNIPER_FRELAY) || \
48 defined(DLT_JUNIPER_CHDLC) || defined(DLT_JUNIPER_PPPOE_ATM) || \
49 defined(DLT_JUNIPER_MLPPP) || defined(DLT_JUNIPER_MFR) || \
50 defined(DLT_JUNIPER_MLFR) || defined(DLT_JUNIPER_ATM1) || \
51 defined(DLT_JUNIPER_ATM2)
52 #define JUNIPER_BPF_OUT 0 /* Outgoing packet */
53 #define JUNIPER_BPF_IN 1 /* Incoming packet */
54 #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */
55 #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */
56 #define JUNIPER_BPF_IIF 0x4 /* IIF is valid */
57 #define JUNIPER_BPF_FILTER 0x40 /* BPF filtering is supported */
58 #define JUNIPER_BPF_EXT 0x80 /* extensions present */
59 #define JUNIPER_MGC_NUMBER 0x4d4743 /* = "MGC" */
61 #define JUNIPER_LSQ_COOKIE_RE (1 << 3)
62 #define JUNIPER_LSQ_COOKIE_DIR (1 << 2)
63 #define JUNIPER_LSQ_L3_PROTO_SHIFT 4
64 #define JUNIPER_LSQ_L3_PROTO_MASK (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT)
65 #define JUNIPER_LSQ_L3_PROTO_IPV4 (0 << JUNIPER_LSQ_L3_PROTO_SHIFT)
66 #define JUNIPER_LSQ_L3_PROTO_IPV6 (1 << JUNIPER_LSQ_L3_PROTO_SHIFT)
67 #define JUNIPER_LSQ_L3_PROTO_MPLS (2 << JUNIPER_LSQ_L3_PROTO_SHIFT)
68 #define JUNIPER_LSQ_L3_PROTO_ISO (3 << JUNIPER_LSQ_L3_PROTO_SHIFT)
69 #define AS_PIC_COOKIE_LEN 8
71 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1
72 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2
73 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3
74 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4
75 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5
78 static const struct tok juniper_ipsec_type_values
[] = {
79 { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
, "ESP ENCR-AUTH" },
80 { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
, "ESP ENCR-AH AUTH" },
81 { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
, "ESP AUTH" },
82 { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
, "AH AUTH" },
83 { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
, "ESP ENCR" },
88 static const struct tok juniper_direction_values
[] = {
89 { JUNIPER_BPF_IN
, "In"},
90 { JUNIPER_BPF_OUT
, "Out"},
94 /* codepoints for encoding extensions to a .pcap file */
96 JUNIPER_EXT_TLV_IFD_IDX
= 1,
97 JUNIPER_EXT_TLV_IFD_NAME
= 2,
98 JUNIPER_EXT_TLV_IFD_MEDIATYPE
= 3,
99 JUNIPER_EXT_TLV_IFL_IDX
= 4,
100 JUNIPER_EXT_TLV_IFL_UNIT
= 5,
101 JUNIPER_EXT_TLV_IFL_ENCAPS
= 6,
102 JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
= 7,
103 JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
= 8
106 /* 1 byte type and 1-byte length */
107 #define JUNIPER_EXT_TLV_OVERHEAD 2U
109 static const struct tok jnx_ext_tlv_values
[] = {
110 { JUNIPER_EXT_TLV_IFD_IDX
, "Device Interface Index" },
111 { JUNIPER_EXT_TLV_IFD_NAME
,"Device Interface Name" },
112 { JUNIPER_EXT_TLV_IFD_MEDIATYPE
, "Device Media Type" },
113 { JUNIPER_EXT_TLV_IFL_IDX
, "Logical Interface Index" },
114 { JUNIPER_EXT_TLV_IFL_UNIT
,"Logical Unit Number" },
115 { JUNIPER_EXT_TLV_IFL_ENCAPS
, "Logical Interface Encapsulation" },
116 { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
, "TTP derived Device Media Type" },
117 { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
, "TTP derived Logical Interface Encapsulation" },
121 static const struct tok jnx_flag_values
[] = {
122 { JUNIPER_BPF_EXT
, "Ext" },
123 { JUNIPER_BPF_FILTER
, "Filter" },
124 { JUNIPER_BPF_IIF
, "IIF" },
125 { JUNIPER_BPF_NO_L2
, "no-L2" },
126 { JUNIPER_BPF_PKT_IN
, "In" },
130 #define JUNIPER_IFML_ETHER 1
131 #define JUNIPER_IFML_FDDI 2
132 #define JUNIPER_IFML_TOKENRING 3
133 #define JUNIPER_IFML_PPP 4
134 #define JUNIPER_IFML_FRAMERELAY 5
135 #define JUNIPER_IFML_CISCOHDLC 6
136 #define JUNIPER_IFML_SMDSDXI 7
137 #define JUNIPER_IFML_ATMPVC 8
138 #define JUNIPER_IFML_PPP_CCC 9
139 #define JUNIPER_IFML_FRAMERELAY_CCC 10
140 #define JUNIPER_IFML_IPIP 11
141 #define JUNIPER_IFML_GRE 12
142 #define JUNIPER_IFML_PIM 13
143 #define JUNIPER_IFML_PIMD 14
144 #define JUNIPER_IFML_CISCOHDLC_CCC 15
145 #define JUNIPER_IFML_VLAN_CCC 16
146 #define JUNIPER_IFML_MLPPP 17
147 #define JUNIPER_IFML_MLFR 18
148 #define JUNIPER_IFML_ML 19
149 #define JUNIPER_IFML_LSI 20
150 #define JUNIPER_IFML_DFE 21
151 #define JUNIPER_IFML_ATM_CELLRELAY_CCC 22
152 #define JUNIPER_IFML_CRYPTO 23
153 #define JUNIPER_IFML_GGSN 24
154 #define JUNIPER_IFML_LSI_PPP 25
155 #define JUNIPER_IFML_LSI_CISCOHDLC 26
156 #define JUNIPER_IFML_PPP_TCC 27
157 #define JUNIPER_IFML_FRAMERELAY_TCC 28
158 #define JUNIPER_IFML_CISCOHDLC_TCC 29
159 #define JUNIPER_IFML_ETHERNET_CCC 30
160 #define JUNIPER_IFML_VT 31
161 #define JUNIPER_IFML_EXTENDED_VLAN_CCC 32
162 #define JUNIPER_IFML_ETHER_OVER_ATM 33
163 #define JUNIPER_IFML_MONITOR 34
164 #define JUNIPER_IFML_ETHERNET_TCC 35
165 #define JUNIPER_IFML_VLAN_TCC 36
166 #define JUNIPER_IFML_EXTENDED_VLAN_TCC 37
167 #define JUNIPER_IFML_CONTROLLER 38
168 #define JUNIPER_IFML_MFR 39
169 #define JUNIPER_IFML_LS 40
170 #define JUNIPER_IFML_ETHERNET_VPLS 41
171 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42
172 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43
173 #define JUNIPER_IFML_LT 44
174 #define JUNIPER_IFML_SERVICES 45
175 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46
176 #define JUNIPER_IFML_FR_PORT_CCC 47
177 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48
178 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49
179 #define JUNIPER_IFML_FRAMERELAY_FLEX 50
180 #define JUNIPER_IFML_GGSNI 51
181 #define JUNIPER_IFML_ETHERNET_FLEX 52
182 #define JUNIPER_IFML_COLLECTOR 53
183 #define JUNIPER_IFML_AGGREGATOR 54
184 #define JUNIPER_IFML_LAPD 55
185 #define JUNIPER_IFML_PPPOE 56
186 #define JUNIPER_IFML_PPP_SUBORDINATE 57
187 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE 58
188 #define JUNIPER_IFML_DFC 59
189 #define JUNIPER_IFML_PICPEER 60
191 static const struct tok juniper_ifmt_values
[] = {
192 { JUNIPER_IFML_ETHER
, "Ethernet" },
193 { JUNIPER_IFML_FDDI
, "FDDI" },
194 { JUNIPER_IFML_TOKENRING
, "Token-Ring" },
195 { JUNIPER_IFML_PPP
, "PPP" },
196 { JUNIPER_IFML_PPP_SUBORDINATE
, "PPP-Subordinate" },
197 { JUNIPER_IFML_FRAMERELAY
, "Frame-Relay" },
198 { JUNIPER_IFML_CISCOHDLC
, "Cisco-HDLC" },
199 { JUNIPER_IFML_SMDSDXI
, "SMDS-DXI" },
200 { JUNIPER_IFML_ATMPVC
, "ATM-PVC" },
201 { JUNIPER_IFML_PPP_CCC
, "PPP-CCC" },
202 { JUNIPER_IFML_FRAMERELAY_CCC
, "Frame-Relay-CCC" },
203 { JUNIPER_IFML_FRAMERELAY_EXT_CCC
, "Extended FR-CCC" },
204 { JUNIPER_IFML_IPIP
, "IP-over-IP" },
205 { JUNIPER_IFML_GRE
, "GRE" },
206 { JUNIPER_IFML_PIM
, "PIM-Encapsulator" },
207 { JUNIPER_IFML_PIMD
, "PIM-Decapsulator" },
208 { JUNIPER_IFML_CISCOHDLC_CCC
, "Cisco-HDLC-CCC" },
209 { JUNIPER_IFML_VLAN_CCC
, "VLAN-CCC" },
210 { JUNIPER_IFML_EXTENDED_VLAN_CCC
, "Extended-VLAN-CCC" },
211 { JUNIPER_IFML_MLPPP
, "Multilink-PPP" },
212 { JUNIPER_IFML_MLFR
, "Multilink-FR" },
213 { JUNIPER_IFML_MFR
, "Multilink-FR-UNI-NNI" },
214 { JUNIPER_IFML_ML
, "Multilink" },
215 { JUNIPER_IFML_LS
, "LinkService" },
216 { JUNIPER_IFML_LSI
, "LSI" },
217 { JUNIPER_IFML_ATM_CELLRELAY_CCC
, "ATM-CCC-Cell-Relay" },
218 { JUNIPER_IFML_CRYPTO
, "IPSEC-over-IP" },
219 { JUNIPER_IFML_GGSN
, "GGSN" },
220 { JUNIPER_IFML_PPP_TCC
, "PPP-TCC" },
221 { JUNIPER_IFML_FRAMERELAY_TCC
, "Frame-Relay-TCC" },
222 { JUNIPER_IFML_FRAMERELAY_EXT_TCC
, "Extended FR-TCC" },
223 { JUNIPER_IFML_CISCOHDLC_TCC
, "Cisco-HDLC-TCC" },
224 { JUNIPER_IFML_ETHERNET_CCC
, "Ethernet-CCC" },
225 { JUNIPER_IFML_VT
, "VPN-Loopback-tunnel" },
226 { JUNIPER_IFML_ETHER_OVER_ATM
, "Ethernet-over-ATM" },
227 { JUNIPER_IFML_ETHER_VPLS_OVER_ATM
, "Ethernet-VPLS-over-ATM" },
228 { JUNIPER_IFML_MONITOR
, "Monitor" },
229 { JUNIPER_IFML_ETHERNET_TCC
, "Ethernet-TCC" },
230 { JUNIPER_IFML_VLAN_TCC
, "VLAN-TCC" },
231 { JUNIPER_IFML_EXTENDED_VLAN_TCC
, "Extended-VLAN-TCC" },
232 { JUNIPER_IFML_CONTROLLER
, "Controller" },
233 { JUNIPER_IFML_ETHERNET_VPLS
, "VPLS" },
234 { JUNIPER_IFML_ETHERNET_VLAN_VPLS
, "VLAN-VPLS" },
235 { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended-VLAN-VPLS" },
236 { JUNIPER_IFML_LT
, "Logical-tunnel" },
237 { JUNIPER_IFML_SERVICES
, "General-Services" },
238 { JUNIPER_IFML_PPPOE
, "PPPoE" },
239 { JUNIPER_IFML_ETHERNET_FLEX
, "Flexible-Ethernet-Services" },
240 { JUNIPER_IFML_FRAMERELAY_FLEX
, "Flexible-FrameRelay" },
241 { JUNIPER_IFML_COLLECTOR
, "Flow-collection" },
242 { JUNIPER_IFML_PICPEER
, "PIC Peer" },
243 { JUNIPER_IFML_DFC
, "Dynamic-Flow-Capture" },
247 #define JUNIPER_IFLE_ATM_SNAP 2
248 #define JUNIPER_IFLE_ATM_NLPID 3
249 #define JUNIPER_IFLE_ATM_VCMUX 4
250 #define JUNIPER_IFLE_ATM_LLC 5
251 #define JUNIPER_IFLE_ATM_PPP_VCMUX 6
252 #define JUNIPER_IFLE_ATM_PPP_LLC 7
253 #define JUNIPER_IFLE_ATM_PPP_FUNI 8
254 #define JUNIPER_IFLE_ATM_CCC 9
255 #define JUNIPER_IFLE_FR_NLPID 10
256 #define JUNIPER_IFLE_FR_SNAP 11
257 #define JUNIPER_IFLE_FR_PPP 12
258 #define JUNIPER_IFLE_FR_CCC 13
259 #define JUNIPER_IFLE_ENET2 14
260 #define JUNIPER_IFLE_IEEE8023_SNAP 15
261 #define JUNIPER_IFLE_IEEE8023_LLC 16
262 #define JUNIPER_IFLE_PPP 17
263 #define JUNIPER_IFLE_CISCOHDLC 18
264 #define JUNIPER_IFLE_PPP_CCC 19
265 #define JUNIPER_IFLE_IPIP_NULL 20
266 #define JUNIPER_IFLE_PIM_NULL 21
267 #define JUNIPER_IFLE_GRE_NULL 22
268 #define JUNIPER_IFLE_GRE_PPP 23
269 #define JUNIPER_IFLE_PIMD_DECAPS 24
270 #define JUNIPER_IFLE_CISCOHDLC_CCC 25
271 #define JUNIPER_IFLE_ATM_CISCO_NLPID 26
272 #define JUNIPER_IFLE_VLAN_CCC 27
273 #define JUNIPER_IFLE_MLPPP 28
274 #define JUNIPER_IFLE_MLFR 29
275 #define JUNIPER_IFLE_LSI_NULL 30
276 #define JUNIPER_IFLE_AGGREGATE_UNUSED 31
277 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC 32
278 #define JUNIPER_IFLE_CRYPTO 33
279 #define JUNIPER_IFLE_GGSN 34
280 #define JUNIPER_IFLE_ATM_TCC 35
281 #define JUNIPER_IFLE_FR_TCC 36
282 #define JUNIPER_IFLE_PPP_TCC 37
283 #define JUNIPER_IFLE_CISCOHDLC_TCC 38
284 #define JUNIPER_IFLE_ETHERNET_CCC 39
285 #define JUNIPER_IFLE_VT 40
286 #define JUNIPER_IFLE_ATM_EOA_LLC 41
287 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC 42
288 #define JUNIPER_IFLE_ATM_SNAP_TCC 43
289 #define JUNIPER_IFLE_MONITOR 44
290 #define JUNIPER_IFLE_ETHERNET_TCC 45
291 #define JUNIPER_IFLE_VLAN_TCC 46
292 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC 47
293 #define JUNIPER_IFLE_MFR 48
294 #define JUNIPER_IFLE_ETHERNET_VPLS 49
295 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50
296 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51
297 #define JUNIPER_IFLE_SERVICES 52
298 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC 53
299 #define JUNIPER_IFLE_FR_PORT_CCC 54
300 #define JUNIPER_IFLE_ATM_MLPPP_LLC 55
301 #define JUNIPER_IFLE_ATM_EOA_CCC 56
302 #define JUNIPER_IFLE_LT_VLAN 57
303 #define JUNIPER_IFLE_COLLECTOR 58
304 #define JUNIPER_IFLE_AGGREGATOR 59
305 #define JUNIPER_IFLE_LAPD 60
306 #define JUNIPER_IFLE_ATM_PPPOE_LLC 61
307 #define JUNIPER_IFLE_ETHERNET_PPPOE 62
308 #define JUNIPER_IFLE_PPPOE 63
309 #define JUNIPER_IFLE_PPP_SUBORDINATE 64
310 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE 65
311 #define JUNIPER_IFLE_DFC 66
312 #define JUNIPER_IFLE_PICPEER 67
314 static const struct tok juniper_ifle_values
[] = {
315 { JUNIPER_IFLE_AGGREGATOR
, "Aggregator" },
316 { JUNIPER_IFLE_ATM_CCC
, "CCC over ATM" },
317 { JUNIPER_IFLE_ATM_CELLRELAY_CCC
, "ATM CCC Cell Relay" },
318 { JUNIPER_IFLE_ATM_CISCO_NLPID
, "CISCO compatible NLPID" },
319 { JUNIPER_IFLE_ATM_EOA_CCC
, "Ethernet over ATM CCC" },
320 { JUNIPER_IFLE_ATM_EOA_LLC
, "Ethernet over ATM LLC" },
321 { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC
, "Ethernet VPLS over ATM LLC" },
322 { JUNIPER_IFLE_ATM_LLC
, "ATM LLC" },
323 { JUNIPER_IFLE_ATM_MLPPP_LLC
, "MLPPP over ATM LLC" },
324 { JUNIPER_IFLE_ATM_NLPID
, "ATM NLPID" },
325 { JUNIPER_IFLE_ATM_PPPOE_LLC
, "PPPoE over ATM LLC" },
326 { JUNIPER_IFLE_ATM_PPP_FUNI
, "PPP over FUNI" },
327 { JUNIPER_IFLE_ATM_PPP_LLC
, "PPP over ATM LLC" },
328 { JUNIPER_IFLE_ATM_PPP_VCMUX
, "PPP over ATM VCMUX" },
329 { JUNIPER_IFLE_ATM_SNAP
, "ATM SNAP" },
330 { JUNIPER_IFLE_ATM_SNAP_TCC
, "ATM SNAP TCC" },
331 { JUNIPER_IFLE_ATM_TCC
, "ATM VCMUX TCC" },
332 { JUNIPER_IFLE_ATM_VCMUX
, "ATM VCMUX" },
333 { JUNIPER_IFLE_CISCOHDLC
, "C-HDLC" },
334 { JUNIPER_IFLE_CISCOHDLC_CCC
, "C-HDLC CCC" },
335 { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE
, "C-HDLC via dialer" },
336 { JUNIPER_IFLE_CISCOHDLC_TCC
, "C-HDLC TCC" },
337 { JUNIPER_IFLE_COLLECTOR
, "Collector" },
338 { JUNIPER_IFLE_CRYPTO
, "Crypto" },
339 { JUNIPER_IFLE_ENET2
, "Ethernet" },
340 { JUNIPER_IFLE_ETHERNET_CCC
, "Ethernet CCC" },
341 { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended VLAN VPLS" },
342 { JUNIPER_IFLE_ETHERNET_PPPOE
, "PPPoE over Ethernet" },
343 { JUNIPER_IFLE_ETHERNET_TCC
, "Ethernet TCC" },
344 { JUNIPER_IFLE_ETHERNET_VLAN_VPLS
, "VLAN VPLS" },
345 { JUNIPER_IFLE_ETHERNET_VPLS
, "VPLS" },
346 { JUNIPER_IFLE_EXTENDED_VLAN_CCC
, "Extended VLAN CCC" },
347 { JUNIPER_IFLE_EXTENDED_VLAN_TCC
, "Extended VLAN TCC" },
348 { JUNIPER_IFLE_FR_CCC
, "FR CCC" },
349 { JUNIPER_IFLE_FR_NLPID
, "FR NLPID" },
350 { JUNIPER_IFLE_FR_PORT_CCC
, "FR CCC" },
351 { JUNIPER_IFLE_FR_PPP
, "FR PPP" },
352 { JUNIPER_IFLE_FR_SNAP
, "FR SNAP" },
353 { JUNIPER_IFLE_FR_TCC
, "FR TCC" },
354 { JUNIPER_IFLE_GGSN
, "GGSN" },
355 { JUNIPER_IFLE_GRE_NULL
, "GRE NULL" },
356 { JUNIPER_IFLE_GRE_PPP
, "PPP over GRE" },
357 { JUNIPER_IFLE_IPIP_NULL
, "IPIP" },
358 { JUNIPER_IFLE_LAPD
, "LAPD" },
359 { JUNIPER_IFLE_LSI_NULL
, "LSI Null" },
360 { JUNIPER_IFLE_LT_VLAN
, "LT VLAN" },
361 { JUNIPER_IFLE_MFR
, "MFR" },
362 { JUNIPER_IFLE_MLFR
, "MLFR" },
363 { JUNIPER_IFLE_MLPPP
, "MLPPP" },
364 { JUNIPER_IFLE_MONITOR
, "Monitor" },
365 { JUNIPER_IFLE_PIMD_DECAPS
, "PIMd" },
366 { JUNIPER_IFLE_PIM_NULL
, "PIM Null" },
367 { JUNIPER_IFLE_PPP
, "PPP" },
368 { JUNIPER_IFLE_PPPOE
, "PPPoE" },
369 { JUNIPER_IFLE_PPP_CCC
, "PPP CCC" },
370 { JUNIPER_IFLE_PPP_SUBORDINATE
, "" },
371 { JUNIPER_IFLE_PPP_TCC
, "PPP TCC" },
372 { JUNIPER_IFLE_SERVICES
, "General Services" },
373 { JUNIPER_IFLE_VLAN_CCC
, "VLAN CCC" },
374 { JUNIPER_IFLE_VLAN_TCC
, "VLAN TCC" },
375 { JUNIPER_IFLE_VT
, "VT" },
379 struct juniper_cookie_table_t
{
380 uint32_t pictype
; /* pic type */
381 uint8_t cookie_len
; /* cookie len */
382 const char *s
; /* pic name */
385 static const struct juniper_cookie_table_t juniper_cookie_table
[] = {
386 #ifdef DLT_JUNIPER_ATM1
387 { DLT_JUNIPER_ATM1
, 4, "ATM1"},
389 #ifdef DLT_JUNIPER_ATM2
390 { DLT_JUNIPER_ATM2
, 8, "ATM2"},
392 #ifdef DLT_JUNIPER_MLPPP
393 { DLT_JUNIPER_MLPPP
, 2, "MLPPP"},
395 #ifdef DLT_JUNIPER_MLFR
396 { DLT_JUNIPER_MLFR
, 2, "MLFR"},
398 #ifdef DLT_JUNIPER_MFR
399 { DLT_JUNIPER_MFR
, 4, "MFR"},
401 #ifdef DLT_JUNIPER_PPPOE
402 { DLT_JUNIPER_PPPOE
, 0, "PPPoE"},
404 #ifdef DLT_JUNIPER_PPPOE_ATM
405 { DLT_JUNIPER_PPPOE_ATM
, 0, "PPPoE ATM"},
407 #ifdef DLT_JUNIPER_GGSN
408 { DLT_JUNIPER_GGSN
, 8, "GGSN"},
410 #ifdef DLT_JUNIPER_MONITOR
411 { DLT_JUNIPER_MONITOR
, 8, "MONITOR"},
413 #ifdef DLT_JUNIPER_SERVICES
414 { DLT_JUNIPER_SERVICES
, 8, "AS"},
416 #ifdef DLT_JUNIPER_ES
417 { DLT_JUNIPER_ES
, 0, "ES"},
422 struct juniper_l2info_t
{
436 #define LS_COOKIE_ID 0x54
437 #define AS_COOKIE_ID 0x47
438 #define LS_MLFR_COOKIE_LEN 4
439 #define ML_MLFR_COOKIE_LEN 2
440 #define LS_MFR_COOKIE_LEN 6
441 #define ATM1_COOKIE_LEN 4
442 #define ATM2_COOKIE_LEN 8
444 #define ATM2_PKT_TYPE_MASK 0x70
445 #define ATM2_GAP_COUNT_MASK 0x3F
447 #define JUNIPER_PROTO_NULL 1
448 #define JUNIPER_PROTO_IPV4 2
449 #define JUNIPER_PROTO_IPV6 6
451 #define MFR_BE_MASK 0xc0
453 #ifdef DLT_JUNIPER_GGSN
454 static const struct tok juniper_protocol_values
[] = {
455 { JUNIPER_PROTO_NULL
, "Null" },
456 { JUNIPER_PROTO_IPV4
, "IPv4" },
457 { JUNIPER_PROTO_IPV6
, "IPv6" },
462 static int ip_heuristic_guess(netdissect_options
*, const u_char
*, u_int
);
463 #ifdef DLT_JUNIPER_ATM2
464 static int juniper_ppp_heuristic_guess(netdissect_options
*, const u_char
*, u_int
);
466 static int juniper_parse_header(netdissect_options
*, const u_char
*, const struct pcap_pkthdr
*, struct juniper_l2info_t
*);
468 #ifdef DLT_JUNIPER_GGSN
470 juniper_ggsn_if_print(netdissect_options
*ndo
,
471 const struct pcap_pkthdr
*h
, const u_char
*p
)
473 struct juniper_l2info_t l2info
;
474 struct juniper_ggsn_header
{
476 nd_uint8_t flags_len
;
482 const struct juniper_ggsn_header
*gh
;
485 ndo
->ndo_protocol
= "juniper_ggsn";
486 memset(&l2info
, 0, sizeof(l2info
));
487 l2info
.pictype
= DLT_JUNIPER_GGSN
;
488 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
489 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
493 p
+=l2info
.header_len
;
494 gh
= (struct juniper_ggsn_header
*)&l2info
.cookie
;
496 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
497 proto
= EXTRACT_U_1(gh
->proto
);
498 if (ndo
->ndo_eflag
) {
499 ND_PRINT("proto %s (%u), vlan %u: ",
500 tok2str(juniper_protocol_values
,"Unknown",proto
),
502 EXTRACT_BE_U_2(gh
->vlan_id
));
506 case JUNIPER_PROTO_IPV4
:
507 ip_print(ndo
, p
, l2info
.length
);
509 case JUNIPER_PROTO_IPV6
:
510 ip6_print(ndo
, p
, l2info
.length
);
514 ND_PRINT("unknown GGSN proto (%u)", proto
);
517 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
521 #ifdef DLT_JUNIPER_ES
523 juniper_es_if_print(netdissect_options
*ndo
,
524 const struct pcap_pkthdr
*h
, const u_char
*p
)
526 struct juniper_l2info_t l2info
;
527 struct juniper_ipsec_header
{
528 nd_uint16_t sa_index
;
535 u_int rewrite_len
,es_type_bundle
;
536 const struct juniper_ipsec_header
*ih
;
538 ndo
->ndo_protocol
= "juniper_es";
539 memset(&l2info
, 0, sizeof(l2info
));
540 l2info
.pictype
= DLT_JUNIPER_ES
;
541 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
542 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
546 p
+=l2info
.header_len
;
547 ih
= (const struct juniper_ipsec_header
*)p
;
550 switch (GET_U_1(ih
->type
)) {
551 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
552 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
556 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
557 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
558 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
563 ND_PRINT("ES Invalid type %u, length %u",
566 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
570 l2info
.length
-=rewrite_len
;
573 if (ndo
->ndo_eflag
) {
574 if (!es_type_bundle
) {
575 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
576 GET_BE_U_2(ih
->sa_index
),
578 tok2str(juniper_ipsec_type_values
,"Unknown",GET_U_1(ih
->type
)),
581 GET_IPADDR_STRING(ih
->src_ip
),
582 GET_IPADDR_STRING(ih
->dst_ip
),
585 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), length %u\n",
586 GET_BE_U_2(ih
->sa_index
),
588 tok2str(juniper_ipsec_type_values
,"Unknown",GET_U_1(ih
->type
)),
594 ip_print(ndo
, p
, l2info
.length
);
595 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
599 #ifdef DLT_JUNIPER_MONITOR
601 juniper_monitor_if_print(netdissect_options
*ndo
,
602 const struct pcap_pkthdr
*h
, const u_char
*p
)
604 struct juniper_l2info_t l2info
;
605 struct juniper_monitor_header
{
609 nd_uint32_t service_id
;
611 const struct juniper_monitor_header
*mh
;
613 ndo
->ndo_protocol
= "juniper_monitor";
614 memset(&l2info
, 0, sizeof(l2info
));
615 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
616 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
617 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
621 p
+=l2info
.header_len
;
622 mh
= (const struct juniper_monitor_header
*)p
;
626 ND_PRINT("service-id %u, iif %u, pkt-type %u: ",
627 GET_BE_U_4(mh
->service_id
),
629 GET_U_1(mh
->pkt_type
));
631 /* no proto field - lets guess by first byte of IP header*/
632 ip_heuristic_guess (ndo
, p
, l2info
.length
);
634 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
638 #ifdef DLT_JUNIPER_SERVICES
640 juniper_services_if_print(netdissect_options
*ndo
,
641 const struct pcap_pkthdr
*h
, const u_char
*p
)
643 struct juniper_l2info_t l2info
;
644 struct juniper_services_header
{
646 nd_uint8_t flags_len
;
647 nd_uint16_t svc_set_id
;
651 const struct juniper_services_header
*sh
;
653 ndo
->ndo_protocol
= "juniper_services";
654 memset(&l2info
, 0, sizeof(l2info
));
655 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
656 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
657 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
661 p
+=l2info
.header_len
;
662 sh
= (const struct juniper_services_header
*)p
;
666 ND_PRINT("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
668 GET_U_1(sh
->flags_len
),
669 GET_BE_U_2(sh
->svc_set_id
),
670 GET_BE_U_3(sh
->dir_iif
));
672 /* no proto field - lets guess by first byte of IP header*/
673 ip_heuristic_guess (ndo
, p
, l2info
.length
);
675 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
679 #ifdef DLT_JUNIPER_PPPOE
681 juniper_pppoe_if_print(netdissect_options
*ndo
,
682 const struct pcap_pkthdr
*h
, const u_char
*p
)
684 struct juniper_l2info_t l2info
;
686 ndo
->ndo_protocol
= "juniper_pppoe";
687 memset(&l2info
, 0, sizeof(l2info
));
688 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
689 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
690 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
694 p
+=l2info
.header_len
;
695 /* this DLT contains nothing but raw ethernet frames */
696 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
697 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
701 #ifdef DLT_JUNIPER_ETHER
703 juniper_ether_if_print(netdissect_options
*ndo
,
704 const struct pcap_pkthdr
*h
, const u_char
*p
)
706 struct juniper_l2info_t l2info
;
708 ndo
->ndo_protocol
= "juniper_ether";
709 memset(&l2info
, 0, sizeof(l2info
));
710 l2info
.pictype
= DLT_JUNIPER_ETHER
;
711 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
712 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
716 p
+=l2info
.header_len
;
717 /* this DLT contains nothing but raw Ethernet frames */
718 ndo
->ndo_ll_hdr_len
+=
720 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
724 #ifdef DLT_JUNIPER_PPP
726 juniper_ppp_if_print(netdissect_options
*ndo
,
727 const struct pcap_pkthdr
*h
, const u_char
*p
)
729 struct juniper_l2info_t l2info
;
731 ndo
->ndo_protocol
= "juniper_ppp";
732 memset(&l2info
, 0, sizeof(l2info
));
733 l2info
.pictype
= DLT_JUNIPER_PPP
;
734 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
735 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
739 p
+=l2info
.header_len
;
740 /* this DLT contains nothing but raw ppp frames */
741 ppp_print(ndo
, p
, l2info
.length
);
742 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
746 #ifdef DLT_JUNIPER_FRELAY
748 juniper_frelay_if_print(netdissect_options
*ndo
,
749 const struct pcap_pkthdr
*h
, const u_char
*p
)
751 struct juniper_l2info_t l2info
;
753 ndo
->ndo_protocol
= "juniper_frelay";
754 memset(&l2info
, 0, sizeof(l2info
));
755 l2info
.pictype
= DLT_JUNIPER_FRELAY
;
756 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
757 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
761 p
+=l2info
.header_len
;
762 /* this DLT contains nothing but raw frame-relay frames */
763 fr_print(ndo
, p
, l2info
.length
);
764 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
768 #ifdef DLT_JUNIPER_CHDLC
770 juniper_chdlc_if_print(netdissect_options
*ndo
,
771 const struct pcap_pkthdr
*h
, const u_char
*p
)
773 struct juniper_l2info_t l2info
;
775 ndo
->ndo_protocol
= "juniper_chdlc";
776 memset(&l2info
, 0, sizeof(l2info
));
777 l2info
.pictype
= DLT_JUNIPER_CHDLC
;
778 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
779 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
783 p
+=l2info
.header_len
;
784 /* this DLT contains nothing but raw c-hdlc frames */
785 chdlc_print(ndo
, p
, l2info
.length
);
786 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
790 #ifdef DLT_JUNIPER_PPPOE_ATM
792 juniper_pppoe_atm_if_print(netdissect_options
*ndo
,
793 const struct pcap_pkthdr
*h
, const u_char
*p
)
795 struct juniper_l2info_t l2info
;
796 uint16_t extracted_ethertype
;
798 ndo
->ndo_protocol
= "juniper_pppoe_atm";
799 memset(&l2info
, 0, sizeof(l2info
));
800 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
801 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
802 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
806 p
+=l2info
.header_len
;
808 extracted_ethertype
= GET_BE_U_2(p
);
809 /* this DLT contains nothing but raw PPPoE frames,
810 * prepended with a type field*/
811 if (ethertype_print(ndo
, extracted_ethertype
,
813 l2info
.length
-ETHERTYPE_LEN
,
814 l2info
.caplen
-ETHERTYPE_LEN
,
816 /* ether_type not known, probably it wasn't one */
817 ND_PRINT("unknown ethertype 0x%04x", extracted_ethertype
);
819 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
823 #ifdef DLT_JUNIPER_MLPPP
825 juniper_mlppp_if_print(netdissect_options
*ndo
,
826 const struct pcap_pkthdr
*h
, const u_char
*p
)
828 struct juniper_l2info_t l2info
;
830 ndo
->ndo_protocol
= "juniper_mlppp";
831 memset(&l2info
, 0, sizeof(l2info
));
832 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
833 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
834 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
838 /* suppress Bundle-ID if frame was captured on a child-link
839 * best indicator if the cookie looks like a proto */
840 if (ndo
->ndo_eflag
&&
841 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
842 EXTRACT_BE_U_2(&l2info
.cookie
) != PPP_OSI
&&
843 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
844 EXTRACT_BE_U_2(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
845 ND_PRINT("Bundle-ID %u: ", l2info
.bundle
);
847 p
+=l2info
.header_len
;
849 /* first try the LSQ protos */
850 switch(l2info
.proto
) {
851 case JUNIPER_LSQ_L3_PROTO_IPV4
:
852 /* IP traffic going to the RE would not have a cookie
853 * -> this must be incoming IS-IS over PPP
855 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
856 ppp_print(ndo
, p
, l2info
.length
);
858 ip_print(ndo
, p
, l2info
.length
);
859 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
861 case JUNIPER_LSQ_L3_PROTO_IPV6
:
862 ip6_print(ndo
, p
,l2info
.length
);
863 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
865 case JUNIPER_LSQ_L3_PROTO_MPLS
:
866 mpls_print(ndo
, p
, l2info
.length
);
867 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
869 case JUNIPER_LSQ_L3_PROTO_ISO
:
870 isoclns_print(ndo
, p
, l2info
.length
);
871 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
877 /* zero length cookie ? */
878 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
879 switch (EXTRACT_BE_U_2(&l2info
.cookie
)) {
881 ppp_print(ndo
, p
- 2, l2info
.length
+ 2);
883 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
885 ppp_print(ndo
, p
, l2info
.length
);
889 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
894 #ifdef DLT_JUNIPER_MFR
896 juniper_mfr_if_print(netdissect_options
*ndo
,
897 const struct pcap_pkthdr
*h
, const u_char
*p
)
899 struct juniper_l2info_t l2info
;
901 ndo
->ndo_protocol
= "juniper_mfr";
902 memset(&l2info
, 0, sizeof(l2info
));
903 l2info
.pictype
= DLT_JUNIPER_MFR
;
904 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
905 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
909 p
+=l2info
.header_len
;
912 if (l2info
.cookie_len
== 0) {
913 mfr_print(ndo
, p
, l2info
.length
);
914 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
918 /* first try the LSQ protos */
919 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
920 switch(l2info
.proto
) {
921 case JUNIPER_LSQ_L3_PROTO_IPV4
:
922 ip_print(ndo
, p
, l2info
.length
);
923 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
925 case JUNIPER_LSQ_L3_PROTO_IPV6
:
926 ip6_print(ndo
, p
,l2info
.length
);
927 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
929 case JUNIPER_LSQ_L3_PROTO_MPLS
:
930 mpls_print(ndo
, p
, l2info
.length
);
931 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
933 case JUNIPER_LSQ_L3_PROTO_ISO
:
934 isoclns_print(ndo
, p
, l2info
.length
);
935 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
940 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
944 /* suppress Bundle-ID if frame was captured on a child-link */
945 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
946 if (ndo
->ndo_eflag
&& EXTRACT_BE_U_4(l2info
.cookie
) != 1)
947 ND_PRINT("Bundle-ID %u, ", l2info
.bundle
);
948 switch (l2info
.proto
) {
949 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
950 /* At least one byte is required */
952 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
954 case (LLC_UI
<<8 | NLPID_Q933
):
955 case (LLC_UI
<<8 | NLPID_IP
):
956 case (LLC_UI
<<8 | NLPID_IP6
):
957 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
958 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1);
961 ND_PRINT("unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
);
964 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
968 #ifdef DLT_JUNIPER_MLFR
970 juniper_mlfr_if_print(netdissect_options
*ndo
,
971 const struct pcap_pkthdr
*h
, const u_char
*p
)
973 struct juniper_l2info_t l2info
;
975 ndo
->ndo_protocol
= "juniper_mlfr";
976 memset(&l2info
, 0, sizeof(l2info
));
977 l2info
.pictype
= DLT_JUNIPER_MLFR
;
978 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
979 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
983 p
+=l2info
.header_len
;
985 /* suppress Bundle-ID if frame was captured on a child-link */
986 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
987 if (ndo
->ndo_eflag
&& EXTRACT_BE_U_4(l2info
.cookie
) != 1)
988 ND_PRINT("Bundle-ID %u, ", l2info
.bundle
);
989 switch (l2info
.proto
) {
992 isoclns_print(ndo
, p
, l2info
.length
);
994 case (LLC_UI
<<8 | NLPID_Q933
):
995 case (LLC_UI
<<8 | NLPID_IP
):
996 case (LLC_UI
<<8 | NLPID_IP6
):
997 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
998 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1);
1001 ND_PRINT("unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
);
1004 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1009 * ATM1 PIC cookie format
1011 * +-----+-------------------------+-------------------------------+
1012 * |fmtid| vc index | channel ID |
1013 * +-----+-------------------------+-------------------------------+
1016 #ifdef DLT_JUNIPER_ATM1
1018 juniper_atm1_if_print(netdissect_options
*ndo
,
1019 const struct pcap_pkthdr
*h
, const u_char
*p
)
1023 struct juniper_l2info_t l2info
;
1025 ndo
->ndo_protocol
= "juniper_atm1";
1026 memset(&l2info
, 0, sizeof(l2info
));
1027 l2info
.pictype
= DLT_JUNIPER_ATM1
;
1028 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
1029 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1033 p
+=l2info
.header_len
;
1035 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
1036 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
1037 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1041 if (GET_BE_U_3(p
) == 0xfefe03 || /* NLPID encaps ? */
1042 GET_BE_U_3(p
) == 0xaaaa03) { /* SNAP encaps ? */
1044 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1045 if (llc_hdrlen
> 0) {
1046 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1051 if (GET_U_1(p
) == 0x03) { /* Cisco style NLPID encaps ? */
1052 /* At least one byte is required */
1054 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
1055 /* FIXME check if frame was recognized */
1056 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1060 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) { /* last try - vcmux encaps ? */
1061 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1065 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1070 * ATM2 PIC cookie format
1072 * +-------------------------------+---------+---+-----+-----------+
1073 * | channel ID |reserved |AAL| CCRQ| gap count |
1074 * +-------------------------------+---------+---+-----+-----------+
1077 #ifdef DLT_JUNIPER_ATM2
1079 juniper_atm2_if_print(netdissect_options
*ndo
,
1080 const struct pcap_pkthdr
*h
, const u_char
*p
)
1084 struct juniper_l2info_t l2info
;
1086 ndo
->ndo_protocol
= "juniper_atm2";
1087 memset(&l2info
, 0, sizeof(l2info
));
1088 l2info
.pictype
= DLT_JUNIPER_ATM2
;
1089 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0) {
1090 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1094 p
+=l2info
.header_len
;
1096 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
1097 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
1098 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1102 if (GET_BE_U_3(p
) == 0xfefe03 || /* NLPID encaps ? */
1103 GET_BE_U_3(p
) == 0xaaaa03) { /* SNAP encaps ? */
1105 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1106 if (llc_hdrlen
> 0) {
1107 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1112 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
1113 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
1114 (EXTRACT_BE_U_4(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
1115 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1116 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1120 if (GET_U_1(p
) == 0x03) { /* Cisco style NLPID encaps ? */
1121 /* At least one byte is required */
1123 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
1124 /* FIXME check if frame was recognized */
1125 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1129 if(juniper_ppp_heuristic_guess(ndo
, p
, l2info
.length
) != 0) { /* PPPoA vcmux encaps ? */
1130 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1134 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) { /* last try - vcmux encaps ? */
1135 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1139 ndo
->ndo_ll_hdr_len
+= l2info
.header_len
;
1142 /* try to guess, based on all PPP protos that are supported in
1143 * a juniper router if the payload data is encapsulated using PPP */
1145 juniper_ppp_heuristic_guess(netdissect_options
*ndo
,
1146 const u_char
*p
, u_int length
)
1148 switch(GET_BE_U_2(p
)) {
1151 case PPP_MPLS_UCAST
:
1152 case PPP_MPLS_MCAST
:
1162 ppp_print(ndo
, p
, length
);
1166 return 0; /* did not find a ppp header */
1168 return 1; /* we printed a ppp packet */
1173 ip_heuristic_guess(netdissect_options
*ndo
,
1174 const u_char
*p
, u_int length
)
1176 switch(GET_U_1(p
)) {
1188 ip_print(ndo
, p
, length
);
1206 ip6_print(ndo
, p
, length
);
1209 return 0; /* did not find a ip header */
1211 return 1; /* we printed an v4/v6 packet */
1215 juniper_read_tlv_value(netdissect_options
*ndo
,
1216 const u_char
*p
, u_int tlv_type
, u_int tlv_len
)
1220 /* TLVs < 128 are little endian encoded */
1221 if (tlv_type
< 128) {
1224 tlv_value
= GET_U_1(p
);
1227 tlv_value
= GET_LE_U_2(p
);
1230 tlv_value
= GET_LE_U_3(p
);
1233 tlv_value
= GET_LE_U_4(p
);
1240 /* TLVs >= 128 are big endian encoded */
1243 tlv_value
= GET_U_1(p
);
1246 tlv_value
= GET_BE_U_2(p
);
1249 tlv_value
= GET_BE_U_3(p
);
1252 tlv_value
= GET_BE_U_4(p
);
1263 juniper_parse_header(netdissect_options
*ndo
,
1264 const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
)
1266 const struct juniper_cookie_table_t
*lp
;
1267 u_int idx
, extension_length
, jnx_header_len
= 0;
1268 uint8_t tlv_type
,tlv_len
;
1269 #ifdef DLT_JUNIPER_ATM2
1270 uint32_t control_word
;
1276 l2info
->header_len
= 0;
1277 l2info
->cookie_len
= 0;
1281 l2info
->length
= h
->len
;
1282 l2info
->caplen
= h
->caplen
;
1283 l2info
->flags
= GET_U_1(p
+ 3);
1284 l2info
->direction
= GET_U_1(p
+ 3) & JUNIPER_BPF_PKT_IN
;
1286 if (GET_BE_U_3(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
1287 ND_PRINT("no magic-number found!");
1291 if (ndo
->ndo_eflag
) /* print direction */
1292 ND_PRINT("%3s ", tok2str(juniper_direction_values
, "---", l2info
->direction
));
1294 /* magic number + flags */
1297 if (ndo
->ndo_vflag
> 1)
1298 ND_PRINT("\n\tJuniper PCAP Flags [%s]",
1299 bittok2str(jnx_flag_values
, "none", l2info
->flags
));
1301 /* extensions present ? - calculate how much bytes to skip */
1302 if ((l2info
->flags
& JUNIPER_BPF_EXT
) == JUNIPER_BPF_EXT
) {
1304 tptr
= p
+jnx_header_len
;
1306 /* ok to read extension length ? */
1307 extension_length
= GET_BE_U_2(tptr
);
1308 jnx_header_len
+= 2;
1311 /* nail up the total length -
1312 * just in case something goes wrong
1313 * with TLV parsing */
1314 jnx_header_len
+= extension_length
;
1316 if (ndo
->ndo_vflag
> 1)
1317 ND_PRINT(", PCAP Extension(s) total length %u", extension_length
);
1319 ND_TCHECK_LEN(tptr
, extension_length
);
1320 while (extension_length
> JUNIPER_EXT_TLV_OVERHEAD
) {
1321 tlv_type
= GET_U_1(tptr
);
1323 tlv_len
= GET_U_1(tptr
);
1328 if (tlv_type
== 0 || tlv_len
== 0)
1330 ND_ICHECK_U(extension_length
, <,
1331 tlv_len
+ JUNIPER_EXT_TLV_OVERHEAD
);
1333 if (ndo
->ndo_vflag
> 1)
1334 ND_PRINT("\n\t %s Extension TLV #%u, length %u, value ",
1335 tok2str(jnx_ext_tlv_values
,"Unknown",tlv_type
),
1339 tlv_value
= juniper_read_tlv_value(ndo
, tptr
, tlv_type
, tlv_len
);
1341 case JUNIPER_EXT_TLV_IFD_NAME
:
1344 case JUNIPER_EXT_TLV_IFD_MEDIATYPE
:
1345 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
:
1346 if (tlv_value
!= -1) {
1347 if (ndo
->ndo_vflag
> 1)
1349 tok2str(juniper_ifmt_values
, "Unknown", tlv_value
),
1353 case JUNIPER_EXT_TLV_IFL_ENCAPS
:
1354 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
:
1355 if (tlv_value
!= -1) {
1356 if (ndo
->ndo_vflag
> 1)
1358 tok2str(juniper_ifle_values
, "Unknown", tlv_value
),
1362 case JUNIPER_EXT_TLV_IFL_IDX
: /* fall through */
1363 case JUNIPER_EXT_TLV_IFL_UNIT
:
1364 case JUNIPER_EXT_TLV_IFD_IDX
:
1366 if (tlv_value
!= -1) {
1367 if (ndo
->ndo_vflag
> 1)
1368 ND_PRINT("%u", tlv_value
);
1374 extension_length
-= tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
;
1377 if (ndo
->ndo_vflag
> 1)
1378 ND_PRINT("\n\t-----original packet-----\n\t");
1381 if ((l2info
->flags
& JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
1383 ND_PRINT("no-L2-hdr, ");
1385 /* there is no link-layer present -
1386 * perform the v4/v6 heuristics
1387 * to figure out what it is
1389 ND_TCHECK_1(p
+ (jnx_header_len
+ 4));
1390 if (ip_heuristic_guess(ndo
, p
+ jnx_header_len
+ 4,
1391 l2info
->length
- (jnx_header_len
+ 4)) == 0)
1392 ND_PRINT("no IP-hdr found!");
1394 l2info
->header_len
=jnx_header_len
+4;
1395 return 0; /* stop parsing the output further */
1398 l2info
->header_len
= jnx_header_len
;
1399 p
+=l2info
->header_len
;
1400 l2info
->length
-= l2info
->header_len
;
1401 l2info
->caplen
-= l2info
->header_len
;
1403 /* search through the cookie table for one matching our PIC type */
1405 for (const struct juniper_cookie_table_t
*table_lp
= juniper_cookie_table
;
1406 table_lp
->s
!= NULL
; table_lp
++) {
1407 if (table_lp
->pictype
== l2info
->pictype
) {
1413 /* If we found one matching our PIC type, copy its values */
1415 l2info
->cookie_len
+= lp
->cookie_len
;
1417 switch (GET_U_1(p
)) {
1419 l2info
->cookie_type
= LS_COOKIE_ID
;
1420 l2info
->cookie_len
+= 2;
1423 l2info
->cookie_type
= AS_COOKIE_ID
;
1424 l2info
->cookie_len
= 8;
1428 l2info
->bundle
= l2info
->cookie
[0];
1433 #ifdef DLT_JUNIPER_MFR
1434 /* MFR child links don't carry cookies */
1435 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
1436 (GET_U_1(p
) & MFR_BE_MASK
) == MFR_BE_MASK
) {
1437 l2info
->cookie_len
= 0;
1441 l2info
->header_len
+= l2info
->cookie_len
;
1442 l2info
->length
-= l2info
->cookie_len
;
1443 l2info
->caplen
-= l2info
->cookie_len
;
1446 ND_PRINT("%s-PIC, cookie-len %u",
1448 l2info
->cookie_len
);
1450 if (l2info
->cookie_len
> 8) {
1451 nd_print_invalid(ndo
);
1455 if (l2info
->cookie_len
> 0) {
1456 ND_TCHECK_LEN(p
, l2info
->cookie_len
);
1458 ND_PRINT(", cookie 0x");
1459 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
1460 l2info
->cookie
[idx
] = GET_U_1(p
+ idx
); /* copy cookie data */
1461 if (ndo
->ndo_eflag
) ND_PRINT("%02x", GET_U_1(p
+ idx
));
1465 if (ndo
->ndo_eflag
) ND_PRINT(": "); /* print demarc b/w L2/L3*/
1468 l2info
->proto
= GET_BE_U_2(p
+ l2info
->cookie_len
);
1470 p
+=l2info
->cookie_len
;
1472 /* DLT_ specific parsing */
1473 switch(l2info
->pictype
) {
1474 #ifdef DLT_JUNIPER_MLPPP
1475 case DLT_JUNIPER_MLPPP
:
1476 switch (l2info
->cookie_type
) {
1478 l2info
->bundle
= l2info
->cookie
[1];
1481 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
1482 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1483 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1486 l2info
->bundle
= l2info
->cookie
[0];
1491 #ifdef DLT_JUNIPER_MLFR
1492 case DLT_JUNIPER_MLFR
:
1493 switch (l2info
->cookie_type
) {
1495 l2info
->bundle
= l2info
->cookie
[1];
1496 l2info
->proto
= GET_BE_U_2(p
);
1497 l2info
->header_len
+= 2;
1498 l2info
->length
-= 2;
1499 l2info
->caplen
-= 2;
1502 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
1503 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1504 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1507 l2info
->bundle
= l2info
->cookie
[0];
1508 l2info
->header_len
+= 2;
1509 l2info
->length
-= 2;
1510 l2info
->caplen
-= 2;
1515 #ifdef DLT_JUNIPER_MFR
1516 case DLT_JUNIPER_MFR
:
1517 switch (l2info
->cookie_type
) {
1519 l2info
->bundle
= l2info
->cookie
[1];
1520 l2info
->proto
= GET_BE_U_2(p
);
1521 l2info
->header_len
+= 2;
1522 l2info
->length
-= 2;
1523 l2info
->caplen
-= 2;
1526 /* use EXTRACT_, not GET_ (not packet buffer pointer) */
1527 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1528 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1531 l2info
->bundle
= l2info
->cookie
[0];
1536 #ifdef DLT_JUNIPER_ATM2
1537 case DLT_JUNIPER_ATM2
:
1539 /* ATM cell relay control word present ? */
1540 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
) {
1541 control_word
= GET_BE_U_4(p
);
1542 /* some control word heuristics */
1543 switch(control_word
) {
1544 case 0: /* zero control word */
1545 case 0x08000000: /* < JUNOS 7.4 control-word */
1546 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1547 l2info
->header_len
+= 4;
1554 ND_PRINT("control-word 0x%08x ", control_word
);
1558 #ifdef DLT_JUNIPER_ES
1559 case DLT_JUNIPER_ES
:
1562 #ifdef DLT_JUNIPER_GGSN
1563 case DLT_JUNIPER_GGSN
:
1566 #ifdef DLT_JUNIPER_SERVICES
1567 case DLT_JUNIPER_SERVICES
:
1570 #ifdef DLT_JUNIPER_ATM1
1571 case DLT_JUNIPER_ATM1
:
1574 #ifdef DLT_JUNIPER_PPP
1575 case DLT_JUNIPER_PPP
:
1578 #ifdef DLT_JUNIPER_CHDLC
1579 case DLT_JUNIPER_CHDLC
:
1582 #ifdef DLT_JUNIPER_ETHER
1583 case DLT_JUNIPER_ETHER
:
1586 #ifdef DLT_JUNIPER_FRELAY
1587 case DLT_JUNIPER_FRELAY
:
1590 #ifdef DLT_JUNIPER_MONITOR
1591 case DLT_JUNIPER_MONITOR
:
1594 #ifdef DLT_JUNIPER_PPPOE
1595 case DLT_JUNIPER_PPPOE
:
1598 #ifdef DLT_JUNIPER_PPPOE_ATM
1599 case DLT_JUNIPER_PPPOE_ATM
:
1604 ND_PRINT("Unknown Juniper DLT_ type %u: ", l2info
->pictype
);
1609 ND_PRINT("hlen %u, proto 0x%04x, ", l2info
->header_len
, l2info
->proto
);
1611 return 1; /* everything went ok so far. continue parsing */
1613 nd_print_invalid(ndo
);
1616 #endif /* defined(DLT_JUNIPER_GGSN) || defined(DLT_JUNIPER_ES) || \
1617 defined(DLT_JUNIPER_MONITOR) || defined(DLT_JUNIPER_SERVICES) || \
1618 defined(DLT_JUNIPER_PPPOE) || defined(DLT_JUNIPER_ETHER) || \
1619 defined(DLT_JUNIPER_PPP) || defined(DLT_JUNIPER_FRELAY) || \
1620 defined(DLT_JUNIPER_CHDLC) || defined(DLT_JUNIPER_PPPOE_ATM) || \
1621 defined(DLT_JUNIPER_MLPPP) || defined(DLT_JUNIPER_MFR) || \
1622 defined(DLT_JUNIPER_MLFR) || defined(DLT_JUNIPER_ATM1) || \
1623 defined(DLT_JUNIPER_ATM2) */