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 ");
29 #include <netdissect-stdinc.h>
33 #include "netdissect.h"
34 #include "addrtoname.h"
39 #include "ethertype.h"
42 #define JUNIPER_BPF_OUT 0 /* Outgoing packet */
43 #define JUNIPER_BPF_IN 1 /* Incoming packet */
44 #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */
45 #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */
46 #define JUNIPER_BPF_IIF 0x4 /* IIF is valid */
47 #define JUNIPER_BPF_FILTER 0x40 /* BPF filtering is supported */
48 #define JUNIPER_BPF_EXT 0x80 /* extensions present */
49 #define JUNIPER_MGC_NUMBER 0x4d4743 /* = "MGC" */
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
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
67 static const struct tok juniper_ipsec_type_values
[] = {
68 { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
, "ESP ENCR-AUTH" },
69 { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
, "ESP ENCR-AH AUTH" },
70 { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
, "ESP AUTH" },
71 { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
, "AH AUTH" },
72 { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
, "ESP ENCR" },
76 static const struct tok juniper_direction_values
[] = {
77 { JUNIPER_BPF_IN
, "In"},
78 { JUNIPER_BPF_OUT
, "Out"},
82 /* codepoints for encoding extensions to a .pcap file */
84 JUNIPER_EXT_TLV_IFD_IDX
= 1,
85 JUNIPER_EXT_TLV_IFD_NAME
= 2,
86 JUNIPER_EXT_TLV_IFD_MEDIATYPE
= 3,
87 JUNIPER_EXT_TLV_IFL_IDX
= 4,
88 JUNIPER_EXT_TLV_IFL_UNIT
= 5,
89 JUNIPER_EXT_TLV_IFL_ENCAPS
= 6,
90 JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
= 7,
91 JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
= 8
94 /* 1 byte type and 1-byte length */
95 #define JUNIPER_EXT_TLV_OVERHEAD 2U
97 static const struct tok jnx_ext_tlv_values
[] = {
98 { JUNIPER_EXT_TLV_IFD_IDX
, "Device Interface Index" },
99 { JUNIPER_EXT_TLV_IFD_NAME
,"Device Interface Name" },
100 { JUNIPER_EXT_TLV_IFD_MEDIATYPE
, "Device Media Type" },
101 { JUNIPER_EXT_TLV_IFL_IDX
, "Logical Interface Index" },
102 { JUNIPER_EXT_TLV_IFL_UNIT
,"Logical Unit Number" },
103 { JUNIPER_EXT_TLV_IFL_ENCAPS
, "Logical Interface Encapsulation" },
104 { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
, "TTP derived Device Media Type" },
105 { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
, "TTP derived Logical Interface Encapsulation" },
109 static const struct tok jnx_flag_values
[] = {
110 { JUNIPER_BPF_EXT
, "Ext" },
111 { JUNIPER_BPF_FILTER
, "Filter" },
112 { JUNIPER_BPF_IIF
, "IIF" },
113 { JUNIPER_BPF_NO_L2
, "no-L2" },
114 { JUNIPER_BPF_PKT_IN
, "In" },
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
179 static const struct tok juniper_ifmt_values
[] = {
180 { JUNIPER_IFML_ETHER
, "Ethernet" },
181 { JUNIPER_IFML_FDDI
, "FDDI" },
182 { JUNIPER_IFML_TOKENRING
, "Token-Ring" },
183 { JUNIPER_IFML_PPP
, "PPP" },
184 { JUNIPER_IFML_PPP_SUBORDINATE
, "PPP-Subordinate" },
185 { JUNIPER_IFML_FRAMERELAY
, "Frame-Relay" },
186 { JUNIPER_IFML_CISCOHDLC
, "Cisco-HDLC" },
187 { JUNIPER_IFML_SMDSDXI
, "SMDS-DXI" },
188 { JUNIPER_IFML_ATMPVC
, "ATM-PVC" },
189 { JUNIPER_IFML_PPP_CCC
, "PPP-CCC" },
190 { JUNIPER_IFML_FRAMERELAY_CCC
, "Frame-Relay-CCC" },
191 { JUNIPER_IFML_FRAMERELAY_EXT_CCC
, "Extended FR-CCC" },
192 { JUNIPER_IFML_IPIP
, "IP-over-IP" },
193 { JUNIPER_IFML_GRE
, "GRE" },
194 { JUNIPER_IFML_PIM
, "PIM-Encapsulator" },
195 { JUNIPER_IFML_PIMD
, "PIM-Decapsulator" },
196 { JUNIPER_IFML_CISCOHDLC_CCC
, "Cisco-HDLC-CCC" },
197 { JUNIPER_IFML_VLAN_CCC
, "VLAN-CCC" },
198 { JUNIPER_IFML_EXTENDED_VLAN_CCC
, "Extended-VLAN-CCC" },
199 { JUNIPER_IFML_MLPPP
, "Multilink-PPP" },
200 { JUNIPER_IFML_MLFR
, "Multilink-FR" },
201 { JUNIPER_IFML_MFR
, "Multilink-FR-UNI-NNI" },
202 { JUNIPER_IFML_ML
, "Multilink" },
203 { JUNIPER_IFML_LS
, "LinkService" },
204 { JUNIPER_IFML_LSI
, "LSI" },
205 { JUNIPER_IFML_ATM_CELLRELAY_CCC
, "ATM-CCC-Cell-Relay" },
206 { JUNIPER_IFML_CRYPTO
, "IPSEC-over-IP" },
207 { JUNIPER_IFML_GGSN
, "GGSN" },
208 { JUNIPER_IFML_PPP_TCC
, "PPP-TCC" },
209 { JUNIPER_IFML_FRAMERELAY_TCC
, "Frame-Relay-TCC" },
210 { JUNIPER_IFML_FRAMERELAY_EXT_TCC
, "Extended FR-TCC" },
211 { JUNIPER_IFML_CISCOHDLC_TCC
, "Cisco-HDLC-TCC" },
212 { JUNIPER_IFML_ETHERNET_CCC
, "Ethernet-CCC" },
213 { JUNIPER_IFML_VT
, "VPN-Loopback-tunnel" },
214 { JUNIPER_IFML_ETHER_OVER_ATM
, "Ethernet-over-ATM" },
215 { JUNIPER_IFML_ETHER_VPLS_OVER_ATM
, "Ethernet-VPLS-over-ATM" },
216 { JUNIPER_IFML_MONITOR
, "Monitor" },
217 { JUNIPER_IFML_ETHERNET_TCC
, "Ethernet-TCC" },
218 { JUNIPER_IFML_VLAN_TCC
, "VLAN-TCC" },
219 { JUNIPER_IFML_EXTENDED_VLAN_TCC
, "Extended-VLAN-TCC" },
220 { JUNIPER_IFML_CONTROLLER
, "Controller" },
221 { JUNIPER_IFML_ETHERNET_VPLS
, "VPLS" },
222 { JUNIPER_IFML_ETHERNET_VLAN_VPLS
, "VLAN-VPLS" },
223 { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended-VLAN-VPLS" },
224 { JUNIPER_IFML_LT
, "Logical-tunnel" },
225 { JUNIPER_IFML_SERVICES
, "General-Services" },
226 { JUNIPER_IFML_PPPOE
, "PPPoE" },
227 { JUNIPER_IFML_ETHERNET_FLEX
, "Flexible-Ethernet-Services" },
228 { JUNIPER_IFML_FRAMERELAY_FLEX
, "Flexible-FrameRelay" },
229 { JUNIPER_IFML_COLLECTOR
, "Flow-collection" },
230 { JUNIPER_IFML_PICPEER
, "PIC Peer" },
231 { JUNIPER_IFML_DFC
, "Dynamic-Flow-Capture" },
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
302 static const struct tok juniper_ifle_values
[] = {
303 { JUNIPER_IFLE_AGGREGATOR
, "Aggregator" },
304 { JUNIPER_IFLE_ATM_CCC
, "CCC over ATM" },
305 { JUNIPER_IFLE_ATM_CELLRELAY_CCC
, "ATM CCC Cell Relay" },
306 { JUNIPER_IFLE_ATM_CISCO_NLPID
, "CISCO compatible NLPID" },
307 { JUNIPER_IFLE_ATM_EOA_CCC
, "Ethernet over ATM CCC" },
308 { JUNIPER_IFLE_ATM_EOA_LLC
, "Ethernet over ATM LLC" },
309 { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC
, "Ethernet VPLS over ATM LLC" },
310 { JUNIPER_IFLE_ATM_LLC
, "ATM LLC" },
311 { JUNIPER_IFLE_ATM_MLPPP_LLC
, "MLPPP over ATM LLC" },
312 { JUNIPER_IFLE_ATM_NLPID
, "ATM NLPID" },
313 { JUNIPER_IFLE_ATM_PPPOE_LLC
, "PPPoE over ATM LLC" },
314 { JUNIPER_IFLE_ATM_PPP_FUNI
, "PPP over FUNI" },
315 { JUNIPER_IFLE_ATM_PPP_LLC
, "PPP over ATM LLC" },
316 { JUNIPER_IFLE_ATM_PPP_VCMUX
, "PPP over ATM VCMUX" },
317 { JUNIPER_IFLE_ATM_SNAP
, "ATM SNAP" },
318 { JUNIPER_IFLE_ATM_SNAP_TCC
, "ATM SNAP TCC" },
319 { JUNIPER_IFLE_ATM_TCC
, "ATM VCMUX TCC" },
320 { JUNIPER_IFLE_ATM_VCMUX
, "ATM VCMUX" },
321 { JUNIPER_IFLE_CISCOHDLC
, "C-HDLC" },
322 { JUNIPER_IFLE_CISCOHDLC_CCC
, "C-HDLC CCC" },
323 { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE
, "C-HDLC via dialer" },
324 { JUNIPER_IFLE_CISCOHDLC_TCC
, "C-HDLC TCC" },
325 { JUNIPER_IFLE_COLLECTOR
, "Collector" },
326 { JUNIPER_IFLE_CRYPTO
, "Crypto" },
327 { JUNIPER_IFLE_ENET2
, "Ethernet" },
328 { JUNIPER_IFLE_ETHERNET_CCC
, "Ethernet CCC" },
329 { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended VLAN VPLS" },
330 { JUNIPER_IFLE_ETHERNET_PPPOE
, "PPPoE over Ethernet" },
331 { JUNIPER_IFLE_ETHERNET_TCC
, "Ethernet TCC" },
332 { JUNIPER_IFLE_ETHERNET_VLAN_VPLS
, "VLAN VPLS" },
333 { JUNIPER_IFLE_ETHERNET_VPLS
, "VPLS" },
334 { JUNIPER_IFLE_EXTENDED_VLAN_CCC
, "Extended VLAN CCC" },
335 { JUNIPER_IFLE_EXTENDED_VLAN_TCC
, "Extended VLAN TCC" },
336 { JUNIPER_IFLE_FR_CCC
, "FR CCC" },
337 { JUNIPER_IFLE_FR_NLPID
, "FR NLPID" },
338 { JUNIPER_IFLE_FR_PORT_CCC
, "FR CCC" },
339 { JUNIPER_IFLE_FR_PPP
, "FR PPP" },
340 { JUNIPER_IFLE_FR_SNAP
, "FR SNAP" },
341 { JUNIPER_IFLE_FR_TCC
, "FR TCC" },
342 { JUNIPER_IFLE_GGSN
, "GGSN" },
343 { JUNIPER_IFLE_GRE_NULL
, "GRE NULL" },
344 { JUNIPER_IFLE_GRE_PPP
, "PPP over GRE" },
345 { JUNIPER_IFLE_IPIP_NULL
, "IPIP" },
346 { JUNIPER_IFLE_LAPD
, "LAPD" },
347 { JUNIPER_IFLE_LSI_NULL
, "LSI Null" },
348 { JUNIPER_IFLE_LT_VLAN
, "LT VLAN" },
349 { JUNIPER_IFLE_MFR
, "MFR" },
350 { JUNIPER_IFLE_MLFR
, "MLFR" },
351 { JUNIPER_IFLE_MLPPP
, "MLPPP" },
352 { JUNIPER_IFLE_MONITOR
, "Monitor" },
353 { JUNIPER_IFLE_PIMD_DECAPS
, "PIMd" },
354 { JUNIPER_IFLE_PIM_NULL
, "PIM Null" },
355 { JUNIPER_IFLE_PPP
, "PPP" },
356 { JUNIPER_IFLE_PPPOE
, "PPPoE" },
357 { JUNIPER_IFLE_PPP_CCC
, "PPP CCC" },
358 { JUNIPER_IFLE_PPP_SUBORDINATE
, "" },
359 { JUNIPER_IFLE_PPP_TCC
, "PPP TCC" },
360 { JUNIPER_IFLE_SERVICES
, "General Services" },
361 { JUNIPER_IFLE_VLAN_CCC
, "VLAN CCC" },
362 { JUNIPER_IFLE_VLAN_TCC
, "VLAN TCC" },
363 { JUNIPER_IFLE_VT
, "VT" },
367 struct juniper_cookie_table_t
{
368 uint32_t pictype
; /* pic type */
369 uint8_t cookie_len
; /* cookie len */
370 const char *s
; /* pic name */
373 static const struct juniper_cookie_table_t juniper_cookie_table
[] = {
374 #ifdef DLT_JUNIPER_ATM1
375 { DLT_JUNIPER_ATM1
, 4, "ATM1"},
377 #ifdef DLT_JUNIPER_ATM2
378 { DLT_JUNIPER_ATM2
, 8, "ATM2"},
380 #ifdef DLT_JUNIPER_MLPPP
381 { DLT_JUNIPER_MLPPP
, 2, "MLPPP"},
383 #ifdef DLT_JUNIPER_MLFR
384 { DLT_JUNIPER_MLFR
, 2, "MLFR"},
386 #ifdef DLT_JUNIPER_MFR
387 { DLT_JUNIPER_MFR
, 4, "MFR"},
389 #ifdef DLT_JUNIPER_PPPOE
390 { DLT_JUNIPER_PPPOE
, 0, "PPPoE"},
392 #ifdef DLT_JUNIPER_PPPOE_ATM
393 { DLT_JUNIPER_PPPOE_ATM
, 0, "PPPoE ATM"},
395 #ifdef DLT_JUNIPER_GGSN
396 { DLT_JUNIPER_GGSN
, 8, "GGSN"},
398 #ifdef DLT_JUNIPER_MONITOR
399 { DLT_JUNIPER_MONITOR
, 8, "MONITOR"},
401 #ifdef DLT_JUNIPER_SERVICES
402 { DLT_JUNIPER_SERVICES
, 8, "AS"},
404 #ifdef DLT_JUNIPER_ES
405 { DLT_JUNIPER_ES
, 0, "ES"},
410 struct juniper_l2info_t
{
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
432 #define ATM2_PKT_TYPE_MASK 0x70
433 #define ATM2_GAP_COUNT_MASK 0x3F
435 #define JUNIPER_PROTO_NULL 1
436 #define JUNIPER_PROTO_IPV4 2
437 #define JUNIPER_PROTO_IPV6 6
439 #define MFR_BE_MASK 0xc0
441 static const struct tok juniper_protocol_values
[] = {
442 { JUNIPER_PROTO_NULL
, "Null" },
443 { JUNIPER_PROTO_IPV4
, "IPv4" },
444 { JUNIPER_PROTO_IPV6
, "IPv6" },
448 static int ip_heuristic_guess(netdissect_options
*, const u_char
*, u_int
);
449 static int juniper_ppp_heuristic_guess(netdissect_options
*, const u_char
*, u_int
);
450 static int juniper_parse_header(netdissect_options
*, const u_char
*, const struct pcap_pkthdr
*, struct juniper_l2info_t
*);
452 #ifdef DLT_JUNIPER_GGSN
454 juniper_ggsn_if_print(netdissect_options
*ndo
,
455 const struct pcap_pkthdr
*h
, const u_char
*p
)
457 struct juniper_l2info_t l2info
;
458 struct juniper_ggsn_header
{
460 nd_uint8_t flags_len
;
466 const struct juniper_ggsn_header
*gh
;
469 l2info
.pictype
= DLT_JUNIPER_GGSN
;
470 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
471 return l2info
.header_len
;
473 p
+=l2info
.header_len
;
474 gh
= (struct juniper_ggsn_header
*)&l2info
.cookie
;
477 proto
= EXTRACT_U_1(gh
->proto
);
478 if (ndo
->ndo_eflag
) {
479 ND_PRINT("proto %s (%u), vlan %u: ",
480 tok2str(juniper_protocol_values
,"Unknown",proto
),
482 EXTRACT_BE_U_2(gh
->vlan_id
));
486 case JUNIPER_PROTO_IPV4
:
487 ip_print(ndo
, p
, l2info
.length
);
489 case JUNIPER_PROTO_IPV6
:
490 ip6_print(ndo
, p
, l2info
.length
);
494 ND_PRINT("unknown GGSN proto (%u)", proto
);
497 return l2info
.header_len
;
500 ND_PRINT("[|juniper_services]");
501 return l2info
.header_len
;
505 #ifdef DLT_JUNIPER_ES
507 juniper_es_if_print(netdissect_options
*ndo
,
508 const struct pcap_pkthdr
*h
, const u_char
*p
)
510 struct juniper_l2info_t l2info
;
511 struct juniper_ipsec_header
{
512 nd_uint16_t sa_index
;
519 u_int rewrite_len
,es_type_bundle
;
520 const struct juniper_ipsec_header
*ih
;
522 l2info
.pictype
= DLT_JUNIPER_ES
;
523 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
524 return l2info
.header_len
;
526 p
+=l2info
.header_len
;
527 ih
= (const struct juniper_ipsec_header
*)p
;
530 switch (EXTRACT_U_1(ih
->type
)) {
531 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
532 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
536 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
537 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
538 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
543 ND_PRINT("ES Invalid type %u, length %u",
544 EXTRACT_U_1(ih
->type
),
546 return l2info
.header_len
;
549 l2info
.length
-=rewrite_len
;
552 if (ndo
->ndo_eflag
) {
553 if (!es_type_bundle
) {
554 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
555 EXTRACT_BE_U_2(ih
->sa_index
),
556 EXTRACT_U_1(ih
->ttl
),
557 tok2str(juniper_ipsec_type_values
,"Unknown",EXTRACT_U_1(ih
->type
)),
558 EXTRACT_U_1(ih
->type
),
559 EXTRACT_BE_U_4(ih
->spi
),
560 ipaddr_string(ndo
, &ih
->src_ip
),
561 ipaddr_string(ndo
, &ih
->dst_ip
),
564 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), length %u\n",
565 EXTRACT_BE_U_2(ih
->sa_index
),
566 EXTRACT_U_1(ih
->ttl
),
567 tok2str(juniper_ipsec_type_values
,"Unknown",EXTRACT_U_1(ih
->type
)),
568 EXTRACT_U_1(ih
->type
),
573 ip_print(ndo
, p
, l2info
.length
);
574 return l2info
.header_len
;
577 ND_PRINT("[|juniper_services]");
578 return l2info
.header_len
;
582 #ifdef DLT_JUNIPER_MONITOR
584 juniper_monitor_if_print(netdissect_options
*ndo
,
585 const struct pcap_pkthdr
*h
, const u_char
*p
)
587 struct juniper_l2info_t l2info
;
588 struct juniper_monitor_header
{
592 nd_uint32_t service_id
;
594 const struct juniper_monitor_header
*mh
;
596 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
597 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
598 return l2info
.header_len
;
600 p
+=l2info
.header_len
;
601 mh
= (const struct juniper_monitor_header
*)p
;
605 ND_PRINT("service-id %u, iif %u, pkt-type %u: ",
606 EXTRACT_BE_U_4(mh
->service_id
),
607 EXTRACT_BE_U_2(mh
->iif
),
608 EXTRACT_U_1(mh
->pkt_type
));
610 /* no proto field - lets guess by first byte of IP header*/
611 ip_heuristic_guess (ndo
, p
, l2info
.length
);
613 return l2info
.header_len
;
616 ND_PRINT("[|juniper_services]");
617 return l2info
.header_len
;
621 #ifdef DLT_JUNIPER_SERVICES
623 juniper_services_if_print(netdissect_options
*ndo
,
624 const struct pcap_pkthdr
*h
, const u_char
*p
)
626 struct juniper_l2info_t l2info
;
627 struct juniper_services_header
{
629 nd_uint8_t flags_len
;
630 nd_uint16_t svc_set_id
;
634 const struct juniper_services_header
*sh
;
636 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
637 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
638 return l2info
.header_len
;
640 p
+=l2info
.header_len
;
641 sh
= (const struct juniper_services_header
*)p
;
645 ND_PRINT("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
646 EXTRACT_U_1(sh
->svc_id
),
647 EXTRACT_U_1(sh
->flags_len
),
648 EXTRACT_BE_U_2(sh
->svc_set_id
),
649 EXTRACT_BE_U_3(sh
->dir_iif
));
651 /* no proto field - lets guess by first byte of IP header*/
652 ip_heuristic_guess (ndo
, p
, l2info
.length
);
654 return l2info
.header_len
;
657 ND_PRINT("[|juniper_services]");
658 return l2info
.header_len
;
662 #ifdef DLT_JUNIPER_PPPOE
664 juniper_pppoe_if_print(netdissect_options
*ndo
,
665 const struct pcap_pkthdr
*h
, const u_char
*p
)
667 struct juniper_l2info_t l2info
;
669 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
670 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
671 return l2info
.header_len
;
673 p
+=l2info
.header_len
;
674 /* this DLT contains nothing but raw ethernet frames */
675 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
676 return l2info
.header_len
;
680 #ifdef DLT_JUNIPER_ETHER
682 juniper_ether_if_print(netdissect_options
*ndo
,
683 const struct pcap_pkthdr
*h
, const u_char
*p
)
685 struct juniper_l2info_t l2info
;
687 l2info
.pictype
= DLT_JUNIPER_ETHER
;
688 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
689 return l2info
.header_len
;
691 p
+=l2info
.header_len
;
692 /* this DLT contains nothing but raw Ethernet frames */
693 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
694 return l2info
.header_len
;
698 #ifdef DLT_JUNIPER_PPP
700 juniper_ppp_if_print(netdissect_options
*ndo
,
701 const struct pcap_pkthdr
*h
, const u_char
*p
)
703 struct juniper_l2info_t l2info
;
705 l2info
.pictype
= DLT_JUNIPER_PPP
;
706 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
707 return l2info
.header_len
;
709 p
+=l2info
.header_len
;
710 /* this DLT contains nothing but raw ppp frames */
711 ppp_print(ndo
, p
, l2info
.length
);
712 return l2info
.header_len
;
716 #ifdef DLT_JUNIPER_FRELAY
718 juniper_frelay_if_print(netdissect_options
*ndo
,
719 const struct pcap_pkthdr
*h
, const u_char
*p
)
721 struct juniper_l2info_t l2info
;
723 l2info
.pictype
= DLT_JUNIPER_FRELAY
;
724 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
725 return l2info
.header_len
;
727 p
+=l2info
.header_len
;
728 /* this DLT contains nothing but raw frame-relay frames */
729 fr_print(ndo
, p
, l2info
.length
);
730 return l2info
.header_len
;
734 #ifdef DLT_JUNIPER_CHDLC
736 juniper_chdlc_if_print(netdissect_options
*ndo
,
737 const struct pcap_pkthdr
*h
, const u_char
*p
)
739 struct juniper_l2info_t l2info
;
741 l2info
.pictype
= DLT_JUNIPER_CHDLC
;
742 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
743 return l2info
.header_len
;
745 p
+=l2info
.header_len
;
746 /* this DLT contains nothing but raw c-hdlc frames */
747 chdlc_print(ndo
, p
, l2info
.length
);
748 return l2info
.header_len
;
752 #ifdef DLT_JUNIPER_PPPOE_ATM
754 juniper_pppoe_atm_if_print(netdissect_options
*ndo
,
755 const struct pcap_pkthdr
*h
, const u_char
*p
)
757 struct juniper_l2info_t l2info
;
758 uint16_t extracted_ethertype
;
760 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
761 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
762 return l2info
.header_len
;
764 p
+=l2info
.header_len
;
767 extracted_ethertype
= EXTRACT_BE_U_2(p
);
768 /* this DLT contains nothing but raw PPPoE frames,
769 * prepended with a type field*/
770 if (ethertype_print(ndo
, extracted_ethertype
,
772 l2info
.length
-ETHERTYPE_LEN
,
773 l2info
.caplen
-ETHERTYPE_LEN
,
775 /* ether_type not known, probably it wasn't one */
776 ND_PRINT("unknown ethertype 0x%04x", extracted_ethertype
);
778 return l2info
.header_len
;
781 ND_PRINT("[|juniper_pppoe_atm]");
782 return l2info
.header_len
;
786 #ifdef DLT_JUNIPER_MLPPP
788 juniper_mlppp_if_print(netdissect_options
*ndo
,
789 const struct pcap_pkthdr
*h
, const u_char
*p
)
791 struct juniper_l2info_t l2info
;
793 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
794 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
795 return l2info
.header_len
;
797 /* suppress Bundle-ID if frame was captured on a child-link
798 * best indicator if the cookie looks like a proto */
799 if (ndo
->ndo_eflag
&&
800 EXTRACT_BE_U_2(&l2info
.cookie
) != PPP_OSI
&&
801 EXTRACT_BE_U_2(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
802 ND_PRINT("Bundle-ID %u: ", l2info
.bundle
);
804 p
+=l2info
.header_len
;
806 /* first try the LSQ protos */
807 switch(l2info
.proto
) {
808 case JUNIPER_LSQ_L3_PROTO_IPV4
:
809 /* IP traffic going to the RE would not have a cookie
810 * -> this must be incoming IS-IS over PPP
812 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
813 ppp_print(ndo
, p
, l2info
.length
);
815 ip_print(ndo
, p
, l2info
.length
);
816 return l2info
.header_len
;
817 case JUNIPER_LSQ_L3_PROTO_IPV6
:
818 ip6_print(ndo
, p
,l2info
.length
);
819 return l2info
.header_len
;
820 case JUNIPER_LSQ_L3_PROTO_MPLS
:
821 mpls_print(ndo
, p
, l2info
.length
);
822 return l2info
.header_len
;
823 case JUNIPER_LSQ_L3_PROTO_ISO
:
824 isoclns_print(ndo
, p
, l2info
.length
);
825 return l2info
.header_len
;
830 /* zero length cookie ? */
831 switch (EXTRACT_BE_U_2(&l2info
.cookie
)) {
833 ppp_print(ndo
, p
- 2, l2info
.length
+ 2);
835 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
837 ppp_print(ndo
, p
, l2info
.length
);
841 return l2info
.header_len
;
846 #ifdef DLT_JUNIPER_MFR
848 juniper_mfr_if_print(netdissect_options
*ndo
,
849 const struct pcap_pkthdr
*h
, const u_char
*p
)
851 struct juniper_l2info_t l2info
;
853 memset(&l2info
, 0, sizeof(l2info
));
854 l2info
.pictype
= DLT_JUNIPER_MFR
;
855 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
856 return l2info
.header_len
;
858 p
+=l2info
.header_len
;
861 if (l2info
.cookie_len
== 0) {
862 mfr_print(ndo
, p
, l2info
.length
);
863 return l2info
.header_len
;
866 /* first try the LSQ protos */
867 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
868 switch(l2info
.proto
) {
869 case JUNIPER_LSQ_L3_PROTO_IPV4
:
870 ip_print(ndo
, p
, l2info
.length
);
871 return l2info
.header_len
;
872 case JUNIPER_LSQ_L3_PROTO_IPV6
:
873 ip6_print(ndo
, p
,l2info
.length
);
874 return l2info
.header_len
;
875 case JUNIPER_LSQ_L3_PROTO_MPLS
:
876 mpls_print(ndo
, p
, l2info
.length
);
877 return l2info
.header_len
;
878 case JUNIPER_LSQ_L3_PROTO_ISO
:
879 isoclns_print(ndo
, p
, l2info
.length
);
880 return l2info
.header_len
;
884 return l2info
.header_len
;
887 /* suppress Bundle-ID if frame was captured on a child-link */
888 if (ndo
->ndo_eflag
&& EXTRACT_BE_U_4(l2info
.cookie
) != 1)
889 ND_PRINT("Bundle-ID %u, ", l2info
.bundle
);
890 switch (l2info
.proto
) {
891 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
892 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
894 case (LLC_UI
<<8 | NLPID_Q933
):
895 case (LLC_UI
<<8 | NLPID_IP
):
896 case (LLC_UI
<<8 | NLPID_IP6
):
897 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
898 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1);
901 ND_PRINT("unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
);
904 return l2info
.header_len
;
908 #ifdef DLT_JUNIPER_MLFR
910 juniper_mlfr_if_print(netdissect_options
*ndo
,
911 const struct pcap_pkthdr
*h
, const u_char
*p
)
913 struct juniper_l2info_t l2info
;
915 l2info
.pictype
= DLT_JUNIPER_MLFR
;
916 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
917 return l2info
.header_len
;
919 p
+=l2info
.header_len
;
921 /* suppress Bundle-ID if frame was captured on a child-link */
922 if (ndo
->ndo_eflag
&& EXTRACT_BE_U_4(l2info
.cookie
) != 1)
923 ND_PRINT("Bundle-ID %u, ", l2info
.bundle
);
924 switch (l2info
.proto
) {
927 isoclns_print(ndo
, p
, l2info
.length
);
929 case (LLC_UI
<<8 | NLPID_Q933
):
930 case (LLC_UI
<<8 | NLPID_IP
):
931 case (LLC_UI
<<8 | NLPID_IP6
):
932 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
933 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1);
936 ND_PRINT("unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
);
939 return l2info
.header_len
;
944 * ATM1 PIC cookie format
946 * +-----+-------------------------+-------------------------------+
947 * |fmtid| vc index | channel ID |
948 * +-----+-------------------------+-------------------------------+
951 #ifdef DLT_JUNIPER_ATM1
953 juniper_atm1_if_print(netdissect_options
*ndo
,
954 const struct pcap_pkthdr
*h
, const u_char
*p
)
958 struct juniper_l2info_t l2info
;
960 l2info
.pictype
= DLT_JUNIPER_ATM1
;
961 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
962 return l2info
.header_len
;
964 p
+=l2info
.header_len
;
966 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
967 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
968 return l2info
.header_len
;
972 if (EXTRACT_BE_U_3(p
) == 0xfefe03 || /* NLPID encaps ? */
973 EXTRACT_BE_U_3(p
) == 0xaaaa03) { /* SNAP encaps ? */
975 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
977 return l2info
.header_len
;
980 if (EXTRACT_U_1(p
) == 0x03) { /* Cisco style NLPID encaps ? */
981 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
982 /* FIXME check if frame was recognized */
983 return l2info
.header_len
;
986 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
987 return l2info
.header_len
;
989 return l2info
.header_len
;
992 ND_PRINT("[|juniper_atm1]");
993 return l2info
.header_len
;
998 * ATM2 PIC cookie format
1000 * +-------------------------------+---------+---+-----+-----------+
1001 * | channel ID | reserv |AAL| CCRQ| gap cnt |
1002 * +-------------------------------+---------+---+-----+-----------+
1005 #ifdef DLT_JUNIPER_ATM2
1007 juniper_atm2_if_print(netdissect_options
*ndo
,
1008 const struct pcap_pkthdr
*h
, const u_char
*p
)
1012 struct juniper_l2info_t l2info
;
1014 l2info
.pictype
= DLT_JUNIPER_ATM2
;
1015 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
1016 return l2info
.header_len
;
1018 p
+=l2info
.header_len
;
1020 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
1021 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
1022 return l2info
.header_len
;
1026 if (EXTRACT_BE_U_3(p
) == 0xfefe03 || /* NLPID encaps ? */
1027 EXTRACT_BE_U_3(p
) == 0xaaaa03) { /* SNAP encaps ? */
1029 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1031 return l2info
.header_len
;
1034 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
1035 (EXTRACT_BE_U_4(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
1036 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1037 return l2info
.header_len
;
1040 if (EXTRACT_U_1(p
) == 0x03) { /* Cisco style NLPID encaps ? */
1041 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
1042 /* FIXME check if frame was recognized */
1043 return l2info
.header_len
;
1046 if(juniper_ppp_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* PPPoA vcmux encaps ? */
1047 return l2info
.header_len
;
1049 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
1050 return l2info
.header_len
;
1052 return l2info
.header_len
;
1055 ND_PRINT("[|juniper_atm2]");
1056 return l2info
.header_len
;
1061 /* try to guess, based on all PPP protos that are supported in
1062 * a juniper router if the payload data is encapsulated using PPP */
1064 juniper_ppp_heuristic_guess(netdissect_options
*ndo
,
1065 const u_char
*p
, u_int length
)
1067 switch(EXTRACT_BE_U_2(p
)) {
1070 case PPP_MPLS_UCAST
:
1071 case PPP_MPLS_MCAST
:
1081 ppp_print(ndo
, p
, length
);
1085 return 0; /* did not find a ppp header */
1088 return 1; /* we printed a ppp packet */
1092 ip_heuristic_guess(netdissect_options
*ndo
,
1093 const u_char
*p
, u_int length
)
1095 switch(EXTRACT_U_1(p
)) {
1107 ip_print(ndo
, p
, length
);
1125 ip6_print(ndo
, p
, length
);
1128 return 0; /* did not find a ip header */
1131 return 1; /* we printed an v4/v6 packet */
1135 juniper_read_tlv_value(const u_char
*p
, u_int tlv_type
, u_int tlv_len
)
1139 /* TLVs < 128 are little endian encoded */
1140 if (tlv_type
< 128) {
1143 tlv_value
= EXTRACT_U_1(p
);
1146 tlv_value
= EXTRACT_LE_U_2(p
);
1149 tlv_value
= EXTRACT_LE_U_3(p
);
1152 tlv_value
= EXTRACT_LE_U_4(p
);
1159 /* TLVs >= 128 are big endian encoded */
1162 tlv_value
= EXTRACT_U_1(p
);
1165 tlv_value
= EXTRACT_BE_U_2(p
);
1168 tlv_value
= EXTRACT_BE_U_3(p
);
1171 tlv_value
= EXTRACT_BE_U_4(p
);
1182 juniper_parse_header(netdissect_options
*ndo
,
1183 const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
)
1185 const struct juniper_cookie_table_t
*lp
= juniper_cookie_table
;
1186 u_int idx
, jnx_ext_len
, jnx_header_len
= 0;
1187 uint8_t tlv_type
,tlv_len
;
1188 uint32_t control_word
;
1193 l2info
->header_len
= 0;
1194 l2info
->cookie_len
= 0;
1198 l2info
->length
= h
->len
;
1199 l2info
->caplen
= h
->caplen
;
1201 l2info
->flags
= EXTRACT_U_1(p
+ 3);
1202 l2info
->direction
= EXTRACT_U_1(p
+ 3) & JUNIPER_BPF_PKT_IN
;
1204 if (EXTRACT_BE_U_3(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
1205 ND_PRINT("no magic-number found!");
1209 if (ndo
->ndo_eflag
) /* print direction */
1210 ND_PRINT("%3s ", tok2str(juniper_direction_values
, "---", l2info
->direction
));
1212 /* magic number + flags */
1215 if (ndo
->ndo_vflag
> 1)
1216 ND_PRINT("\n\tJuniper PCAP Flags [%s]",
1217 bittok2str(jnx_flag_values
, "none", l2info
->flags
));
1219 /* extensions present ? - calculate how much bytes to skip */
1220 if ((l2info
->flags
& JUNIPER_BPF_EXT
) == JUNIPER_BPF_EXT
) {
1222 tptr
= p
+jnx_header_len
;
1224 /* ok to read extension length ? */
1226 jnx_ext_len
= EXTRACT_BE_U_2(tptr
);
1227 jnx_header_len
+= 2;
1230 /* nail up the total length -
1231 * just in case something goes wrong
1232 * with TLV parsing */
1233 jnx_header_len
+= jnx_ext_len
;
1235 if (ndo
->ndo_vflag
> 1)
1236 ND_PRINT(", PCAP Extension(s) total length %u", jnx_ext_len
);
1238 ND_TCHECK_LEN(tptr
, jnx_ext_len
);
1239 while (jnx_ext_len
> JUNIPER_EXT_TLV_OVERHEAD
) {
1240 tlv_type
= EXTRACT_U_1(tptr
);
1242 tlv_len
= EXTRACT_U_1(tptr
);
1247 if (tlv_type
== 0 || tlv_len
== 0)
1249 if (tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
> jnx_ext_len
)
1252 if (ndo
->ndo_vflag
> 1)
1253 ND_PRINT("\n\t %s Extension TLV #%u, length %u, value ",
1254 tok2str(jnx_ext_tlv_values
,"Unknown",tlv_type
),
1258 tlv_value
= juniper_read_tlv_value(tptr
, tlv_type
, tlv_len
);
1260 case JUNIPER_EXT_TLV_IFD_NAME
:
1263 case JUNIPER_EXT_TLV_IFD_MEDIATYPE
:
1264 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
:
1265 if (tlv_value
!= -1) {
1266 if (ndo
->ndo_vflag
> 1)
1268 tok2str(juniper_ifmt_values
, "Unknown", tlv_value
),
1272 case JUNIPER_EXT_TLV_IFL_ENCAPS
:
1273 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
:
1274 if (tlv_value
!= -1) {
1275 if (ndo
->ndo_vflag
> 1)
1277 tok2str(juniper_ifle_values
, "Unknown", tlv_value
),
1281 case JUNIPER_EXT_TLV_IFL_IDX
: /* fall through */
1282 case JUNIPER_EXT_TLV_IFL_UNIT
:
1283 case JUNIPER_EXT_TLV_IFD_IDX
:
1285 if (tlv_value
!= -1) {
1286 if (ndo
->ndo_vflag
> 1)
1287 ND_PRINT("%u", tlv_value
);
1293 jnx_ext_len
-= tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
;
1296 if (ndo
->ndo_vflag
> 1)
1297 ND_PRINT("\n\t-----original packet-----\n\t");
1300 if ((l2info
->flags
& JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
1302 ND_PRINT("no-L2-hdr, ");
1304 /* there is no link-layer present -
1305 * perform the v4/v6 heuristics
1306 * to figure out what it is
1308 ND_TCHECK_1(p
+ (jnx_header_len
+ 4));
1309 if (ip_heuristic_guess(ndo
, p
+ jnx_header_len
+ 4,
1310 l2info
->length
- (jnx_header_len
+ 4)) == 0)
1311 ND_PRINT("no IP-hdr found!");
1313 l2info
->header_len
=jnx_header_len
+4;
1314 return 0; /* stop parsing the output further */
1317 l2info
->header_len
= jnx_header_len
;
1318 p
+=l2info
->header_len
;
1319 l2info
->length
-= l2info
->header_len
;
1320 l2info
->caplen
-= l2info
->header_len
;
1322 /* search through the cookie table and copy values matching for our PIC type */
1324 while (lp
->s
!= NULL
) {
1325 if (lp
->pictype
== l2info
->pictype
) {
1327 l2info
->cookie_len
+= lp
->cookie_len
;
1329 switch (EXTRACT_U_1(p
)) {
1331 l2info
->cookie_type
= LS_COOKIE_ID
;
1332 l2info
->cookie_len
+= 2;
1335 l2info
->cookie_type
= AS_COOKIE_ID
;
1336 l2info
->cookie_len
= 8;
1340 l2info
->bundle
= l2info
->cookie
[0];
1345 #ifdef DLT_JUNIPER_MFR
1346 /* MFR child links don't carry cookies */
1347 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
1348 (EXTRACT_U_1(p
) & MFR_BE_MASK
) == MFR_BE_MASK
) {
1349 l2info
->cookie_len
= 0;
1353 l2info
->header_len
+= l2info
->cookie_len
;
1354 l2info
->length
-= l2info
->cookie_len
;
1355 l2info
->caplen
-= l2info
->cookie_len
;
1358 ND_PRINT("%s-PIC, cookie-len %u",
1360 l2info
->cookie_len
);
1362 if (l2info
->cookie_len
> 0) {
1363 ND_TCHECK_LEN(p
, l2info
->cookie_len
);
1365 ND_PRINT(", cookie 0x");
1366 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
1367 l2info
->cookie
[idx
] = EXTRACT_U_1(p
+ idx
); /* copy cookie data */
1368 if (ndo
->ndo_eflag
) ND_PRINT("%02x", EXTRACT_U_1(p
+ idx
));
1372 if (ndo
->ndo_eflag
) ND_PRINT(": "); /* print demarc b/w L2/L3*/
1375 ND_TCHECK_2(p
+ l2info
->cookie_len
);
1376 l2info
->proto
= EXTRACT_BE_U_2(p
+ l2info
->cookie_len
);
1381 p
+=l2info
->cookie_len
;
1383 /* DLT_ specific parsing */
1384 switch(l2info
->pictype
) {
1385 #ifdef DLT_JUNIPER_MLPPP
1386 case DLT_JUNIPER_MLPPP
:
1387 switch (l2info
->cookie_type
) {
1389 l2info
->bundle
= l2info
->cookie
[1];
1392 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1393 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1396 l2info
->bundle
= l2info
->cookie
[0];
1401 #ifdef DLT_JUNIPER_MLFR
1402 case DLT_JUNIPER_MLFR
:
1403 switch (l2info
->cookie_type
) {
1406 l2info
->bundle
= l2info
->cookie
[1];
1407 l2info
->proto
= EXTRACT_BE_U_2(p
);
1408 l2info
->header_len
+= 2;
1409 l2info
->length
-= 2;
1410 l2info
->caplen
-= 2;
1413 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1414 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1417 l2info
->bundle
= l2info
->cookie
[0];
1418 l2info
->header_len
+= 2;
1419 l2info
->length
-= 2;
1420 l2info
->caplen
-= 2;
1425 #ifdef DLT_JUNIPER_MFR
1426 case DLT_JUNIPER_MFR
:
1427 switch (l2info
->cookie_type
) {
1430 l2info
->bundle
= l2info
->cookie
[1];
1431 l2info
->proto
= EXTRACT_BE_U_2(p
);
1432 l2info
->header_len
+= 2;
1433 l2info
->length
-= 2;
1434 l2info
->caplen
-= 2;
1437 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1438 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1441 l2info
->bundle
= l2info
->cookie
[0];
1446 #ifdef DLT_JUNIPER_ATM2
1447 case DLT_JUNIPER_ATM2
:
1449 /* ATM cell relay control word present ? */
1450 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
) {
1451 control_word
= EXTRACT_BE_U_4(p
);
1452 /* some control word heuristics */
1453 switch(control_word
) {
1454 case 0: /* zero control word */
1455 case 0x08000000: /* < JUNOS 7.4 control-word */
1456 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1457 l2info
->header_len
+= 4;
1464 ND_PRINT("control-word 0x%08x ", control_word
);
1468 #ifdef DLT_JUNIPER_GGSN
1469 case DLT_JUNIPER_GGSN
:
1472 #ifdef DLT_JUNIPER_ATM1
1473 case DLT_JUNIPER_ATM1
:
1476 #ifdef DLT_JUNIPER_PPP
1477 case DLT_JUNIPER_PPP
:
1480 #ifdef DLT_JUNIPER_CHDLC
1481 case DLT_JUNIPER_CHDLC
:
1484 #ifdef DLT_JUNIPER_ETHER
1485 case DLT_JUNIPER_ETHER
:
1488 #ifdef DLT_JUNIPER_FRELAY
1489 case DLT_JUNIPER_FRELAY
:
1494 ND_PRINT("Unknown Juniper DLT_ type %u: ", l2info
->pictype
);
1498 if (ndo
->ndo_eflag
> 1)
1499 ND_PRINT("hlen %u, proto 0x%04x, ", l2info
->header_len
, l2info
->proto
);
1501 return 1; /* everything went ok so far. continue parsing */
1503 ND_PRINT("[|juniper_hdr], length %u", h
->len
);
1510 * c-style: whitesmith