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 ndo
->ndo_protocol
= "juniper_ggsn_if";
470 l2info
.pictype
= DLT_JUNIPER_GGSN
;
471 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
472 return l2info
.header_len
;
474 p
+=l2info
.header_len
;
475 gh
= (struct juniper_ggsn_header
*)&l2info
.cookie
;
478 proto
= EXTRACT_U_1(gh
->proto
);
479 if (ndo
->ndo_eflag
) {
480 ND_PRINT("proto %s (%u), vlan %u: ",
481 tok2str(juniper_protocol_values
,"Unknown",proto
),
483 EXTRACT_BE_U_2(gh
->vlan_id
));
487 case JUNIPER_PROTO_IPV4
:
488 ip_print(ndo
, p
, l2info
.length
);
490 case JUNIPER_PROTO_IPV6
:
491 ip6_print(ndo
, p
, l2info
.length
);
495 ND_PRINT("unknown GGSN proto (%u)", proto
);
498 return l2info
.header_len
;
501 ND_PRINT("[|juniper_services]");
502 return l2info
.header_len
;
506 #ifdef DLT_JUNIPER_ES
508 juniper_es_if_print(netdissect_options
*ndo
,
509 const struct pcap_pkthdr
*h
, const u_char
*p
)
511 struct juniper_l2info_t l2info
;
512 struct juniper_ipsec_header
{
513 nd_uint16_t sa_index
;
520 u_int rewrite_len
,es_type_bundle
;
521 const struct juniper_ipsec_header
*ih
;
523 ndo
->ndo_protocol
= "juniper_es_if";
524 l2info
.pictype
= DLT_JUNIPER_ES
;
525 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
526 return l2info
.header_len
;
528 p
+=l2info
.header_len
;
529 ih
= (const struct juniper_ipsec_header
*)p
;
532 switch (EXTRACT_U_1(ih
->type
)) {
533 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
534 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
538 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
539 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
540 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
545 ND_PRINT("ES Invalid type %u, length %u",
546 EXTRACT_U_1(ih
->type
),
548 return l2info
.header_len
;
551 l2info
.length
-=rewrite_len
;
554 if (ndo
->ndo_eflag
) {
555 if (!es_type_bundle
) {
556 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
557 EXTRACT_BE_U_2(ih
->sa_index
),
558 EXTRACT_U_1(ih
->ttl
),
559 tok2str(juniper_ipsec_type_values
,"Unknown",EXTRACT_U_1(ih
->type
)),
560 EXTRACT_U_1(ih
->type
),
561 EXTRACT_BE_U_4(ih
->spi
),
562 ipaddr_string(ndo
, ih
->src_ip
),
563 ipaddr_string(ndo
, ih
->dst_ip
),
566 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), length %u\n",
567 EXTRACT_BE_U_2(ih
->sa_index
),
568 EXTRACT_U_1(ih
->ttl
),
569 tok2str(juniper_ipsec_type_values
,"Unknown",EXTRACT_U_1(ih
->type
)),
570 EXTRACT_U_1(ih
->type
),
575 ip_print(ndo
, p
, l2info
.length
);
576 return l2info
.header_len
;
579 ND_PRINT("[|juniper_services]");
580 return l2info
.header_len
;
584 #ifdef DLT_JUNIPER_MONITOR
586 juniper_monitor_if_print(netdissect_options
*ndo
,
587 const struct pcap_pkthdr
*h
, const u_char
*p
)
589 struct juniper_l2info_t l2info
;
590 struct juniper_monitor_header
{
594 nd_uint32_t service_id
;
596 const struct juniper_monitor_header
*mh
;
598 ndo
->ndo_protocol
= "juniper_monitor_if";
599 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
600 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
601 return l2info
.header_len
;
603 p
+=l2info
.header_len
;
604 mh
= (const struct juniper_monitor_header
*)p
;
608 ND_PRINT("service-id %u, iif %u, pkt-type %u: ",
609 EXTRACT_BE_U_4(mh
->service_id
),
610 EXTRACT_BE_U_2(mh
->iif
),
611 EXTRACT_U_1(mh
->pkt_type
));
613 /* no proto field - lets guess by first byte of IP header*/
614 ip_heuristic_guess (ndo
, p
, l2info
.length
);
616 return l2info
.header_len
;
619 ND_PRINT("[|juniper_services]");
620 return l2info
.header_len
;
624 #ifdef DLT_JUNIPER_SERVICES
626 juniper_services_if_print(netdissect_options
*ndo
,
627 const struct pcap_pkthdr
*h
, const u_char
*p
)
629 struct juniper_l2info_t l2info
;
630 struct juniper_services_header
{
632 nd_uint8_t flags_len
;
633 nd_uint16_t svc_set_id
;
637 const struct juniper_services_header
*sh
;
639 ndo
->ndo_protocol
= "juniper_services_if";
640 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
641 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
642 return l2info
.header_len
;
644 p
+=l2info
.header_len
;
645 sh
= (const struct juniper_services_header
*)p
;
649 ND_PRINT("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
650 EXTRACT_U_1(sh
->svc_id
),
651 EXTRACT_U_1(sh
->flags_len
),
652 EXTRACT_BE_U_2(sh
->svc_set_id
),
653 EXTRACT_BE_U_3(sh
->dir_iif
));
655 /* no proto field - lets guess by first byte of IP header*/
656 ip_heuristic_guess (ndo
, p
, l2info
.length
);
658 return l2info
.header_len
;
661 ND_PRINT("[|juniper_services]");
662 return l2info
.header_len
;
666 #ifdef DLT_JUNIPER_PPPOE
668 juniper_pppoe_if_print(netdissect_options
*ndo
,
669 const struct pcap_pkthdr
*h
, const u_char
*p
)
671 struct juniper_l2info_t l2info
;
673 ndo
->ndo_protocol
= "juniper_pppoe_if";
674 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
675 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
676 return l2info
.header_len
;
678 p
+=l2info
.header_len
;
679 /* this DLT contains nothing but raw ethernet frames */
680 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
681 return l2info
.header_len
;
685 #ifdef DLT_JUNIPER_ETHER
687 juniper_ether_if_print(netdissect_options
*ndo
,
688 const struct pcap_pkthdr
*h
, const u_char
*p
)
690 struct juniper_l2info_t l2info
;
692 ndo
->ndo_protocol
= "juniper_ether_if";
693 l2info
.pictype
= DLT_JUNIPER_ETHER
;
694 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
695 return l2info
.header_len
;
697 p
+=l2info
.header_len
;
698 /* this DLT contains nothing but raw Ethernet frames */
699 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
700 return l2info
.header_len
;
704 #ifdef DLT_JUNIPER_PPP
706 juniper_ppp_if_print(netdissect_options
*ndo
,
707 const struct pcap_pkthdr
*h
, const u_char
*p
)
709 struct juniper_l2info_t l2info
;
711 ndo
->ndo_protocol
= "juniper_ppp_if";
712 l2info
.pictype
= DLT_JUNIPER_PPP
;
713 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
714 return l2info
.header_len
;
716 p
+=l2info
.header_len
;
717 /* this DLT contains nothing but raw ppp frames */
718 ppp_print(ndo
, p
, l2info
.length
);
719 return l2info
.header_len
;
723 #ifdef DLT_JUNIPER_FRELAY
725 juniper_frelay_if_print(netdissect_options
*ndo
,
726 const struct pcap_pkthdr
*h
, const u_char
*p
)
728 struct juniper_l2info_t l2info
;
730 ndo
->ndo_protocol
= "juniper_frelay_if";
731 l2info
.pictype
= DLT_JUNIPER_FRELAY
;
732 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
733 return l2info
.header_len
;
735 p
+=l2info
.header_len
;
736 /* this DLT contains nothing but raw frame-relay frames */
737 fr_print(ndo
, p
, l2info
.length
);
738 return l2info
.header_len
;
742 #ifdef DLT_JUNIPER_CHDLC
744 juniper_chdlc_if_print(netdissect_options
*ndo
,
745 const struct pcap_pkthdr
*h
, const u_char
*p
)
747 struct juniper_l2info_t l2info
;
749 ndo
->ndo_protocol
= "juniper_chdlc_if";
750 l2info
.pictype
= DLT_JUNIPER_CHDLC
;
751 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
752 return l2info
.header_len
;
754 p
+=l2info
.header_len
;
755 /* this DLT contains nothing but raw c-hdlc frames */
756 chdlc_print(ndo
, p
, l2info
.length
);
757 return l2info
.header_len
;
761 #ifdef DLT_JUNIPER_PPPOE_ATM
763 juniper_pppoe_atm_if_print(netdissect_options
*ndo
,
764 const struct pcap_pkthdr
*h
, const u_char
*p
)
766 struct juniper_l2info_t l2info
;
767 uint16_t extracted_ethertype
;
769 ndo
->ndo_protocol
= "juniper_pppoe_atm_if";
770 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
771 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
772 return l2info
.header_len
;
774 p
+=l2info
.header_len
;
777 extracted_ethertype
= EXTRACT_BE_U_2(p
);
778 /* this DLT contains nothing but raw PPPoE frames,
779 * prepended with a type field*/
780 if (ethertype_print(ndo
, extracted_ethertype
,
782 l2info
.length
-ETHERTYPE_LEN
,
783 l2info
.caplen
-ETHERTYPE_LEN
,
785 /* ether_type not known, probably it wasn't one */
786 ND_PRINT("unknown ethertype 0x%04x", extracted_ethertype
);
788 return l2info
.header_len
;
791 ND_PRINT("[|juniper_pppoe_atm]");
792 return l2info
.header_len
;
796 #ifdef DLT_JUNIPER_MLPPP
798 juniper_mlppp_if_print(netdissect_options
*ndo
,
799 const struct pcap_pkthdr
*h
, const u_char
*p
)
801 struct juniper_l2info_t l2info
;
803 ndo
->ndo_protocol
= "juniper_mlppp_if";
804 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
805 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
806 return l2info
.header_len
;
808 /* suppress Bundle-ID if frame was captured on a child-link
809 * best indicator if the cookie looks like a proto */
810 if (ndo
->ndo_eflag
&&
811 EXTRACT_BE_U_2(&l2info
.cookie
) != PPP_OSI
&&
812 EXTRACT_BE_U_2(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
813 ND_PRINT("Bundle-ID %u: ", l2info
.bundle
);
815 p
+=l2info
.header_len
;
817 /* first try the LSQ protos */
818 switch(l2info
.proto
) {
819 case JUNIPER_LSQ_L3_PROTO_IPV4
:
820 /* IP traffic going to the RE would not have a cookie
821 * -> this must be incoming IS-IS over PPP
823 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
824 ppp_print(ndo
, p
, l2info
.length
);
826 ip_print(ndo
, p
, l2info
.length
);
827 return l2info
.header_len
;
828 case JUNIPER_LSQ_L3_PROTO_IPV6
:
829 ip6_print(ndo
, p
,l2info
.length
);
830 return l2info
.header_len
;
831 case JUNIPER_LSQ_L3_PROTO_MPLS
:
832 mpls_print(ndo
, p
, l2info
.length
);
833 return l2info
.header_len
;
834 case JUNIPER_LSQ_L3_PROTO_ISO
:
835 isoclns_print(ndo
, p
, l2info
.length
);
836 return l2info
.header_len
;
841 /* zero length cookie ? */
842 switch (EXTRACT_BE_U_2(&l2info
.cookie
)) {
844 ppp_print(ndo
, p
- 2, l2info
.length
+ 2);
846 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
848 ppp_print(ndo
, p
, l2info
.length
);
852 return l2info
.header_len
;
857 #ifdef DLT_JUNIPER_MFR
859 juniper_mfr_if_print(netdissect_options
*ndo
,
860 const struct pcap_pkthdr
*h
, const u_char
*p
)
862 struct juniper_l2info_t l2info
;
864 ndo
->ndo_protocol
= "juniper_mfr_if";
865 memset(&l2info
, 0, sizeof(l2info
));
866 l2info
.pictype
= DLT_JUNIPER_MFR
;
867 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
868 return l2info
.header_len
;
870 p
+=l2info
.header_len
;
873 if (l2info
.cookie_len
== 0) {
874 mfr_print(ndo
, p
, l2info
.length
);
875 return l2info
.header_len
;
878 /* first try the LSQ protos */
879 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
880 switch(l2info
.proto
) {
881 case JUNIPER_LSQ_L3_PROTO_IPV4
:
882 ip_print(ndo
, p
, l2info
.length
);
883 return l2info
.header_len
;
884 case JUNIPER_LSQ_L3_PROTO_IPV6
:
885 ip6_print(ndo
, p
,l2info
.length
);
886 return l2info
.header_len
;
887 case JUNIPER_LSQ_L3_PROTO_MPLS
:
888 mpls_print(ndo
, p
, l2info
.length
);
889 return l2info
.header_len
;
890 case JUNIPER_LSQ_L3_PROTO_ISO
:
891 isoclns_print(ndo
, p
, l2info
.length
);
892 return l2info
.header_len
;
896 return l2info
.header_len
;
899 /* suppress Bundle-ID if frame was captured on a child-link */
900 if (ndo
->ndo_eflag
&& EXTRACT_BE_U_4(l2info
.cookie
) != 1)
901 ND_PRINT("Bundle-ID %u, ", l2info
.bundle
);
902 switch (l2info
.proto
) {
903 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
904 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
906 case (LLC_UI
<<8 | NLPID_Q933
):
907 case (LLC_UI
<<8 | NLPID_IP
):
908 case (LLC_UI
<<8 | NLPID_IP6
):
909 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
910 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1);
913 ND_PRINT("unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
);
916 return l2info
.header_len
;
920 #ifdef DLT_JUNIPER_MLFR
922 juniper_mlfr_if_print(netdissect_options
*ndo
,
923 const struct pcap_pkthdr
*h
, const u_char
*p
)
925 struct juniper_l2info_t l2info
;
927 ndo
->ndo_protocol
= "juniper_mlfr_if";
928 l2info
.pictype
= DLT_JUNIPER_MLFR
;
929 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
930 return l2info
.header_len
;
932 p
+=l2info
.header_len
;
934 /* suppress Bundle-ID if frame was captured on a child-link */
935 if (ndo
->ndo_eflag
&& EXTRACT_BE_U_4(l2info
.cookie
) != 1)
936 ND_PRINT("Bundle-ID %u, ", l2info
.bundle
);
937 switch (l2info
.proto
) {
940 isoclns_print(ndo
, p
, l2info
.length
);
942 case (LLC_UI
<<8 | NLPID_Q933
):
943 case (LLC_UI
<<8 | NLPID_IP
):
944 case (LLC_UI
<<8 | NLPID_IP6
):
945 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
946 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1);
949 ND_PRINT("unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
);
952 return l2info
.header_len
;
957 * ATM1 PIC cookie format
959 * +-----+-------------------------+-------------------------------+
960 * |fmtid| vc index | channel ID |
961 * +-----+-------------------------+-------------------------------+
964 #ifdef DLT_JUNIPER_ATM1
966 juniper_atm1_if_print(netdissect_options
*ndo
,
967 const struct pcap_pkthdr
*h
, const u_char
*p
)
971 struct juniper_l2info_t l2info
;
973 ndo
->ndo_protocol
= "juniper_atm1_if";
974 l2info
.pictype
= DLT_JUNIPER_ATM1
;
975 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
976 return l2info
.header_len
;
978 p
+=l2info
.header_len
;
980 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
981 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
982 return l2info
.header_len
;
986 if (EXTRACT_BE_U_3(p
) == 0xfefe03 || /* NLPID encaps ? */
987 EXTRACT_BE_U_3(p
) == 0xaaaa03) { /* SNAP encaps ? */
989 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
991 return l2info
.header_len
;
994 if (EXTRACT_U_1(p
) == 0x03) { /* Cisco style NLPID encaps ? */
995 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
996 /* FIXME check if frame was recognized */
997 return l2info
.header_len
;
1000 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
1001 return l2info
.header_len
;
1003 return l2info
.header_len
;
1006 ND_PRINT("[|juniper_atm1]");
1007 return l2info
.header_len
;
1012 * ATM2 PIC cookie format
1014 * +-------------------------------+---------+---+-----+-----------+
1015 * | channel ID | reserv |AAL| CCRQ| gap cnt |
1016 * +-------------------------------+---------+---+-----+-----------+
1019 #ifdef DLT_JUNIPER_ATM2
1021 juniper_atm2_if_print(netdissect_options
*ndo
,
1022 const struct pcap_pkthdr
*h
, const u_char
*p
)
1026 struct juniper_l2info_t l2info
;
1028 ndo
->ndo_protocol
= "juniper_atm2_if";
1029 l2info
.pictype
= DLT_JUNIPER_ATM2
;
1030 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
1031 return l2info
.header_len
;
1033 p
+=l2info
.header_len
;
1035 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
1036 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
1037 return l2info
.header_len
;
1041 if (EXTRACT_BE_U_3(p
) == 0xfefe03 || /* NLPID encaps ? */
1042 EXTRACT_BE_U_3(p
) == 0xaaaa03) { /* SNAP encaps ? */
1044 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1046 return l2info
.header_len
;
1049 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
1050 (EXTRACT_BE_U_4(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
1051 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1052 return l2info
.header_len
;
1055 if (EXTRACT_U_1(p
) == 0x03) { /* Cisco style NLPID encaps ? */
1056 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
1057 /* FIXME check if frame was recognized */
1058 return l2info
.header_len
;
1061 if(juniper_ppp_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* PPPoA vcmux encaps ? */
1062 return l2info
.header_len
;
1064 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
1065 return l2info
.header_len
;
1067 return l2info
.header_len
;
1070 ND_PRINT("[|juniper_atm2]");
1071 return l2info
.header_len
;
1076 /* try to guess, based on all PPP protos that are supported in
1077 * a juniper router if the payload data is encapsulated using PPP */
1079 juniper_ppp_heuristic_guess(netdissect_options
*ndo
,
1080 const u_char
*p
, u_int length
)
1082 switch(EXTRACT_BE_U_2(p
)) {
1085 case PPP_MPLS_UCAST
:
1086 case PPP_MPLS_MCAST
:
1096 ppp_print(ndo
, p
, length
);
1100 return 0; /* did not find a ppp header */
1103 return 1; /* we printed a ppp packet */
1107 ip_heuristic_guess(netdissect_options
*ndo
,
1108 const u_char
*p
, u_int length
)
1110 switch(EXTRACT_U_1(p
)) {
1122 ip_print(ndo
, p
, length
);
1140 ip6_print(ndo
, p
, length
);
1143 return 0; /* did not find a ip header */
1146 return 1; /* we printed an v4/v6 packet */
1150 juniper_read_tlv_value(const u_char
*p
, u_int tlv_type
, u_int tlv_len
)
1154 /* TLVs < 128 are little endian encoded */
1155 if (tlv_type
< 128) {
1158 tlv_value
= EXTRACT_U_1(p
);
1161 tlv_value
= EXTRACT_LE_U_2(p
);
1164 tlv_value
= EXTRACT_LE_U_3(p
);
1167 tlv_value
= EXTRACT_LE_U_4(p
);
1174 /* TLVs >= 128 are big endian encoded */
1177 tlv_value
= EXTRACT_U_1(p
);
1180 tlv_value
= EXTRACT_BE_U_2(p
);
1183 tlv_value
= EXTRACT_BE_U_3(p
);
1186 tlv_value
= EXTRACT_BE_U_4(p
);
1197 juniper_parse_header(netdissect_options
*ndo
,
1198 const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
)
1200 const struct juniper_cookie_table_t
*lp
= juniper_cookie_table
;
1201 u_int idx
, jnx_ext_len
, jnx_header_len
= 0;
1202 uint8_t tlv_type
,tlv_len
;
1203 uint32_t control_word
;
1208 l2info
->header_len
= 0;
1209 l2info
->cookie_len
= 0;
1213 l2info
->length
= h
->len
;
1214 l2info
->caplen
= h
->caplen
;
1216 l2info
->flags
= EXTRACT_U_1(p
+ 3);
1217 l2info
->direction
= EXTRACT_U_1(p
+ 3) & JUNIPER_BPF_PKT_IN
;
1219 if (EXTRACT_BE_U_3(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
1220 ND_PRINT("no magic-number found!");
1224 if (ndo
->ndo_eflag
) /* print direction */
1225 ND_PRINT("%3s ", tok2str(juniper_direction_values
, "---", l2info
->direction
));
1227 /* magic number + flags */
1230 if (ndo
->ndo_vflag
> 1)
1231 ND_PRINT("\n\tJuniper PCAP Flags [%s]",
1232 bittok2str(jnx_flag_values
, "none", l2info
->flags
));
1234 /* extensions present ? - calculate how much bytes to skip */
1235 if ((l2info
->flags
& JUNIPER_BPF_EXT
) == JUNIPER_BPF_EXT
) {
1237 tptr
= p
+jnx_header_len
;
1239 /* ok to read extension length ? */
1241 jnx_ext_len
= EXTRACT_BE_U_2(tptr
);
1242 jnx_header_len
+= 2;
1245 /* nail up the total length -
1246 * just in case something goes wrong
1247 * with TLV parsing */
1248 jnx_header_len
+= jnx_ext_len
;
1250 if (ndo
->ndo_vflag
> 1)
1251 ND_PRINT(", PCAP Extension(s) total length %u", jnx_ext_len
);
1253 ND_TCHECK_LEN(tptr
, jnx_ext_len
);
1254 while (jnx_ext_len
> JUNIPER_EXT_TLV_OVERHEAD
) {
1255 tlv_type
= EXTRACT_U_1(tptr
);
1257 tlv_len
= EXTRACT_U_1(tptr
);
1262 if (tlv_type
== 0 || tlv_len
== 0)
1264 if (tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
> jnx_ext_len
)
1267 if (ndo
->ndo_vflag
> 1)
1268 ND_PRINT("\n\t %s Extension TLV #%u, length %u, value ",
1269 tok2str(jnx_ext_tlv_values
,"Unknown",tlv_type
),
1273 tlv_value
= juniper_read_tlv_value(tptr
, tlv_type
, tlv_len
);
1275 case JUNIPER_EXT_TLV_IFD_NAME
:
1278 case JUNIPER_EXT_TLV_IFD_MEDIATYPE
:
1279 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
:
1280 if (tlv_value
!= -1) {
1281 if (ndo
->ndo_vflag
> 1)
1283 tok2str(juniper_ifmt_values
, "Unknown", tlv_value
),
1287 case JUNIPER_EXT_TLV_IFL_ENCAPS
:
1288 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
:
1289 if (tlv_value
!= -1) {
1290 if (ndo
->ndo_vflag
> 1)
1292 tok2str(juniper_ifle_values
, "Unknown", tlv_value
),
1296 case JUNIPER_EXT_TLV_IFL_IDX
: /* fall through */
1297 case JUNIPER_EXT_TLV_IFL_UNIT
:
1298 case JUNIPER_EXT_TLV_IFD_IDX
:
1300 if (tlv_value
!= -1) {
1301 if (ndo
->ndo_vflag
> 1)
1302 ND_PRINT("%u", tlv_value
);
1308 jnx_ext_len
-= tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
;
1311 if (ndo
->ndo_vflag
> 1)
1312 ND_PRINT("\n\t-----original packet-----\n\t");
1315 if ((l2info
->flags
& JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
1317 ND_PRINT("no-L2-hdr, ");
1319 /* there is no link-layer present -
1320 * perform the v4/v6 heuristics
1321 * to figure out what it is
1323 ND_TCHECK_1(p
+ (jnx_header_len
+ 4));
1324 if (ip_heuristic_guess(ndo
, p
+ jnx_header_len
+ 4,
1325 l2info
->length
- (jnx_header_len
+ 4)) == 0)
1326 ND_PRINT("no IP-hdr found!");
1328 l2info
->header_len
=jnx_header_len
+4;
1329 return 0; /* stop parsing the output further */
1332 l2info
->header_len
= jnx_header_len
;
1333 p
+=l2info
->header_len
;
1334 l2info
->length
-= l2info
->header_len
;
1335 l2info
->caplen
-= l2info
->header_len
;
1337 /* search through the cookie table and copy values matching for our PIC type */
1339 while (lp
->s
!= NULL
) {
1340 if (lp
->pictype
== l2info
->pictype
) {
1342 l2info
->cookie_len
+= lp
->cookie_len
;
1344 switch (EXTRACT_U_1(p
)) {
1346 l2info
->cookie_type
= LS_COOKIE_ID
;
1347 l2info
->cookie_len
+= 2;
1350 l2info
->cookie_type
= AS_COOKIE_ID
;
1351 l2info
->cookie_len
= 8;
1355 l2info
->bundle
= l2info
->cookie
[0];
1360 #ifdef DLT_JUNIPER_MFR
1361 /* MFR child links don't carry cookies */
1362 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
1363 (EXTRACT_U_1(p
) & MFR_BE_MASK
) == MFR_BE_MASK
) {
1364 l2info
->cookie_len
= 0;
1368 l2info
->header_len
+= l2info
->cookie_len
;
1369 l2info
->length
-= l2info
->cookie_len
;
1370 l2info
->caplen
-= l2info
->cookie_len
;
1373 ND_PRINT("%s-PIC, cookie-len %u",
1375 l2info
->cookie_len
);
1377 if (l2info
->cookie_len
> 0) {
1378 ND_TCHECK_LEN(p
, l2info
->cookie_len
);
1380 ND_PRINT(", cookie 0x");
1381 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
1382 l2info
->cookie
[idx
] = EXTRACT_U_1(p
+ idx
); /* copy cookie data */
1383 if (ndo
->ndo_eflag
) ND_PRINT("%02x", EXTRACT_U_1(p
+ idx
));
1387 if (ndo
->ndo_eflag
) ND_PRINT(": "); /* print demarc b/w L2/L3*/
1390 ND_TCHECK_2(p
+ l2info
->cookie_len
);
1391 l2info
->proto
= EXTRACT_BE_U_2(p
+ l2info
->cookie_len
);
1396 p
+=l2info
->cookie_len
;
1398 /* DLT_ specific parsing */
1399 switch(l2info
->pictype
) {
1400 #ifdef DLT_JUNIPER_MLPPP
1401 case DLT_JUNIPER_MLPPP
:
1402 switch (l2info
->cookie_type
) {
1404 l2info
->bundle
= l2info
->cookie
[1];
1407 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1408 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1411 l2info
->bundle
= l2info
->cookie
[0];
1416 #ifdef DLT_JUNIPER_MLFR
1417 case DLT_JUNIPER_MLFR
:
1418 switch (l2info
->cookie_type
) {
1421 l2info
->bundle
= l2info
->cookie
[1];
1422 l2info
->proto
= EXTRACT_BE_U_2(p
);
1423 l2info
->header_len
+= 2;
1424 l2info
->length
-= 2;
1425 l2info
->caplen
-= 2;
1428 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1429 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1432 l2info
->bundle
= l2info
->cookie
[0];
1433 l2info
->header_len
+= 2;
1434 l2info
->length
-= 2;
1435 l2info
->caplen
-= 2;
1440 #ifdef DLT_JUNIPER_MFR
1441 case DLT_JUNIPER_MFR
:
1442 switch (l2info
->cookie_type
) {
1445 l2info
->bundle
= l2info
->cookie
[1];
1446 l2info
->proto
= EXTRACT_BE_U_2(p
);
1447 l2info
->header_len
+= 2;
1448 l2info
->length
-= 2;
1449 l2info
->caplen
-= 2;
1452 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1453 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1456 l2info
->bundle
= l2info
->cookie
[0];
1461 #ifdef DLT_JUNIPER_ATM2
1462 case DLT_JUNIPER_ATM2
:
1464 /* ATM cell relay control word present ? */
1465 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
) {
1466 control_word
= EXTRACT_BE_U_4(p
);
1467 /* some control word heuristics */
1468 switch(control_word
) {
1469 case 0: /* zero control word */
1470 case 0x08000000: /* < JUNOS 7.4 control-word */
1471 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1472 l2info
->header_len
+= 4;
1479 ND_PRINT("control-word 0x%08x ", control_word
);
1483 #ifdef DLT_JUNIPER_GGSN
1484 case DLT_JUNIPER_GGSN
:
1487 #ifdef DLT_JUNIPER_ATM1
1488 case DLT_JUNIPER_ATM1
:
1491 #ifdef DLT_JUNIPER_PPP
1492 case DLT_JUNIPER_PPP
:
1495 #ifdef DLT_JUNIPER_CHDLC
1496 case DLT_JUNIPER_CHDLC
:
1499 #ifdef DLT_JUNIPER_ETHER
1500 case DLT_JUNIPER_ETHER
:
1503 #ifdef DLT_JUNIPER_FRELAY
1504 case DLT_JUNIPER_FRELAY
:
1509 ND_PRINT("Unknown Juniper DLT_ type %u: ", l2info
->pictype
);
1513 if (ndo
->ndo_eflag
> 1)
1514 ND_PRINT("hlen %u, proto 0x%04x, ", l2info
->header_len
, l2info
->proto
);
1516 return 1; /* everything went ok so far. continue parsing */
1518 ND_PRINT("[|juniper_hdr], length %u", h
->len
);