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
68 static const struct tok juniper_ipsec_type_values
[] = {
69 { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
, "ESP ENCR-AUTH" },
70 { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
, "ESP ENCR-AH AUTH" },
71 { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
, "ESP AUTH" },
72 { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
, "AH AUTH" },
73 { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
, "ESP ENCR" },
78 static const struct tok juniper_direction_values
[] = {
79 { JUNIPER_BPF_IN
, "In"},
80 { JUNIPER_BPF_OUT
, "Out"},
84 /* codepoints for encoding extensions to a .pcap file */
86 JUNIPER_EXT_TLV_IFD_IDX
= 1,
87 JUNIPER_EXT_TLV_IFD_NAME
= 2,
88 JUNIPER_EXT_TLV_IFD_MEDIATYPE
= 3,
89 JUNIPER_EXT_TLV_IFL_IDX
= 4,
90 JUNIPER_EXT_TLV_IFL_UNIT
= 5,
91 JUNIPER_EXT_TLV_IFL_ENCAPS
= 6,
92 JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
= 7,
93 JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
= 8
96 /* 1 byte type and 1-byte length */
97 #define JUNIPER_EXT_TLV_OVERHEAD 2U
99 static const struct tok jnx_ext_tlv_values
[] = {
100 { JUNIPER_EXT_TLV_IFD_IDX
, "Device Interface Index" },
101 { JUNIPER_EXT_TLV_IFD_NAME
,"Device Interface Name" },
102 { JUNIPER_EXT_TLV_IFD_MEDIATYPE
, "Device Media Type" },
103 { JUNIPER_EXT_TLV_IFL_IDX
, "Logical Interface Index" },
104 { JUNIPER_EXT_TLV_IFL_UNIT
,"Logical Unit Number" },
105 { JUNIPER_EXT_TLV_IFL_ENCAPS
, "Logical Interface Encapsulation" },
106 { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
, "TTP derived Device Media Type" },
107 { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
, "TTP derived Logical Interface Encapsulation" },
111 static const struct tok jnx_flag_values
[] = {
112 { JUNIPER_BPF_EXT
, "Ext" },
113 { JUNIPER_BPF_FILTER
, "Filter" },
114 { JUNIPER_BPF_IIF
, "IIF" },
115 { JUNIPER_BPF_NO_L2
, "no-L2" },
116 { JUNIPER_BPF_PKT_IN
, "In" },
120 #define JUNIPER_IFML_ETHER 1
121 #define JUNIPER_IFML_FDDI 2
122 #define JUNIPER_IFML_TOKENRING 3
123 #define JUNIPER_IFML_PPP 4
124 #define JUNIPER_IFML_FRAMERELAY 5
125 #define JUNIPER_IFML_CISCOHDLC 6
126 #define JUNIPER_IFML_SMDSDXI 7
127 #define JUNIPER_IFML_ATMPVC 8
128 #define JUNIPER_IFML_PPP_CCC 9
129 #define JUNIPER_IFML_FRAMERELAY_CCC 10
130 #define JUNIPER_IFML_IPIP 11
131 #define JUNIPER_IFML_GRE 12
132 #define JUNIPER_IFML_PIM 13
133 #define JUNIPER_IFML_PIMD 14
134 #define JUNIPER_IFML_CISCOHDLC_CCC 15
135 #define JUNIPER_IFML_VLAN_CCC 16
136 #define JUNIPER_IFML_MLPPP 17
137 #define JUNIPER_IFML_MLFR 18
138 #define JUNIPER_IFML_ML 19
139 #define JUNIPER_IFML_LSI 20
140 #define JUNIPER_IFML_DFE 21
141 #define JUNIPER_IFML_ATM_CELLRELAY_CCC 22
142 #define JUNIPER_IFML_CRYPTO 23
143 #define JUNIPER_IFML_GGSN 24
144 #define JUNIPER_IFML_LSI_PPP 25
145 #define JUNIPER_IFML_LSI_CISCOHDLC 26
146 #define JUNIPER_IFML_PPP_TCC 27
147 #define JUNIPER_IFML_FRAMERELAY_TCC 28
148 #define JUNIPER_IFML_CISCOHDLC_TCC 29
149 #define JUNIPER_IFML_ETHERNET_CCC 30
150 #define JUNIPER_IFML_VT 31
151 #define JUNIPER_IFML_EXTENDED_VLAN_CCC 32
152 #define JUNIPER_IFML_ETHER_OVER_ATM 33
153 #define JUNIPER_IFML_MONITOR 34
154 #define JUNIPER_IFML_ETHERNET_TCC 35
155 #define JUNIPER_IFML_VLAN_TCC 36
156 #define JUNIPER_IFML_EXTENDED_VLAN_TCC 37
157 #define JUNIPER_IFML_CONTROLLER 38
158 #define JUNIPER_IFML_MFR 39
159 #define JUNIPER_IFML_LS 40
160 #define JUNIPER_IFML_ETHERNET_VPLS 41
161 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42
162 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43
163 #define JUNIPER_IFML_LT 44
164 #define JUNIPER_IFML_SERVICES 45
165 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46
166 #define JUNIPER_IFML_FR_PORT_CCC 47
167 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48
168 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49
169 #define JUNIPER_IFML_FRAMERELAY_FLEX 50
170 #define JUNIPER_IFML_GGSNI 51
171 #define JUNIPER_IFML_ETHERNET_FLEX 52
172 #define JUNIPER_IFML_COLLECTOR 53
173 #define JUNIPER_IFML_AGGREGATOR 54
174 #define JUNIPER_IFML_LAPD 55
175 #define JUNIPER_IFML_PPPOE 56
176 #define JUNIPER_IFML_PPP_SUBORDINATE 57
177 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE 58
178 #define JUNIPER_IFML_DFC 59
179 #define JUNIPER_IFML_PICPEER 60
181 static const struct tok juniper_ifmt_values
[] = {
182 { JUNIPER_IFML_ETHER
, "Ethernet" },
183 { JUNIPER_IFML_FDDI
, "FDDI" },
184 { JUNIPER_IFML_TOKENRING
, "Token-Ring" },
185 { JUNIPER_IFML_PPP
, "PPP" },
186 { JUNIPER_IFML_PPP_SUBORDINATE
, "PPP-Subordinate" },
187 { JUNIPER_IFML_FRAMERELAY
, "Frame-Relay" },
188 { JUNIPER_IFML_CISCOHDLC
, "Cisco-HDLC" },
189 { JUNIPER_IFML_SMDSDXI
, "SMDS-DXI" },
190 { JUNIPER_IFML_ATMPVC
, "ATM-PVC" },
191 { JUNIPER_IFML_PPP_CCC
, "PPP-CCC" },
192 { JUNIPER_IFML_FRAMERELAY_CCC
, "Frame-Relay-CCC" },
193 { JUNIPER_IFML_FRAMERELAY_EXT_CCC
, "Extended FR-CCC" },
194 { JUNIPER_IFML_IPIP
, "IP-over-IP" },
195 { JUNIPER_IFML_GRE
, "GRE" },
196 { JUNIPER_IFML_PIM
, "PIM-Encapsulator" },
197 { JUNIPER_IFML_PIMD
, "PIM-Decapsulator" },
198 { JUNIPER_IFML_CISCOHDLC_CCC
, "Cisco-HDLC-CCC" },
199 { JUNIPER_IFML_VLAN_CCC
, "VLAN-CCC" },
200 { JUNIPER_IFML_EXTENDED_VLAN_CCC
, "Extended-VLAN-CCC" },
201 { JUNIPER_IFML_MLPPP
, "Multilink-PPP" },
202 { JUNIPER_IFML_MLFR
, "Multilink-FR" },
203 { JUNIPER_IFML_MFR
, "Multilink-FR-UNI-NNI" },
204 { JUNIPER_IFML_ML
, "Multilink" },
205 { JUNIPER_IFML_LS
, "LinkService" },
206 { JUNIPER_IFML_LSI
, "LSI" },
207 { JUNIPER_IFML_ATM_CELLRELAY_CCC
, "ATM-CCC-Cell-Relay" },
208 { JUNIPER_IFML_CRYPTO
, "IPSEC-over-IP" },
209 { JUNIPER_IFML_GGSN
, "GGSN" },
210 { JUNIPER_IFML_PPP_TCC
, "PPP-TCC" },
211 { JUNIPER_IFML_FRAMERELAY_TCC
, "Frame-Relay-TCC" },
212 { JUNIPER_IFML_FRAMERELAY_EXT_TCC
, "Extended FR-TCC" },
213 { JUNIPER_IFML_CISCOHDLC_TCC
, "Cisco-HDLC-TCC" },
214 { JUNIPER_IFML_ETHERNET_CCC
, "Ethernet-CCC" },
215 { JUNIPER_IFML_VT
, "VPN-Loopback-tunnel" },
216 { JUNIPER_IFML_ETHER_OVER_ATM
, "Ethernet-over-ATM" },
217 { JUNIPER_IFML_ETHER_VPLS_OVER_ATM
, "Ethernet-VPLS-over-ATM" },
218 { JUNIPER_IFML_MONITOR
, "Monitor" },
219 { JUNIPER_IFML_ETHERNET_TCC
, "Ethernet-TCC" },
220 { JUNIPER_IFML_VLAN_TCC
, "VLAN-TCC" },
221 { JUNIPER_IFML_EXTENDED_VLAN_TCC
, "Extended-VLAN-TCC" },
222 { JUNIPER_IFML_CONTROLLER
, "Controller" },
223 { JUNIPER_IFML_ETHERNET_VPLS
, "VPLS" },
224 { JUNIPER_IFML_ETHERNET_VLAN_VPLS
, "VLAN-VPLS" },
225 { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended-VLAN-VPLS" },
226 { JUNIPER_IFML_LT
, "Logical-tunnel" },
227 { JUNIPER_IFML_SERVICES
, "General-Services" },
228 { JUNIPER_IFML_PPPOE
, "PPPoE" },
229 { JUNIPER_IFML_ETHERNET_FLEX
, "Flexible-Ethernet-Services" },
230 { JUNIPER_IFML_FRAMERELAY_FLEX
, "Flexible-FrameRelay" },
231 { JUNIPER_IFML_COLLECTOR
, "Flow-collection" },
232 { JUNIPER_IFML_PICPEER
, "PIC Peer" },
233 { JUNIPER_IFML_DFC
, "Dynamic-Flow-Capture" },
237 #define JUNIPER_IFLE_ATM_SNAP 2
238 #define JUNIPER_IFLE_ATM_NLPID 3
239 #define JUNIPER_IFLE_ATM_VCMUX 4
240 #define JUNIPER_IFLE_ATM_LLC 5
241 #define JUNIPER_IFLE_ATM_PPP_VCMUX 6
242 #define JUNIPER_IFLE_ATM_PPP_LLC 7
243 #define JUNIPER_IFLE_ATM_PPP_FUNI 8
244 #define JUNIPER_IFLE_ATM_CCC 9
245 #define JUNIPER_IFLE_FR_NLPID 10
246 #define JUNIPER_IFLE_FR_SNAP 11
247 #define JUNIPER_IFLE_FR_PPP 12
248 #define JUNIPER_IFLE_FR_CCC 13
249 #define JUNIPER_IFLE_ENET2 14
250 #define JUNIPER_IFLE_IEEE8023_SNAP 15
251 #define JUNIPER_IFLE_IEEE8023_LLC 16
252 #define JUNIPER_IFLE_PPP 17
253 #define JUNIPER_IFLE_CISCOHDLC 18
254 #define JUNIPER_IFLE_PPP_CCC 19
255 #define JUNIPER_IFLE_IPIP_NULL 20
256 #define JUNIPER_IFLE_PIM_NULL 21
257 #define JUNIPER_IFLE_GRE_NULL 22
258 #define JUNIPER_IFLE_GRE_PPP 23
259 #define JUNIPER_IFLE_PIMD_DECAPS 24
260 #define JUNIPER_IFLE_CISCOHDLC_CCC 25
261 #define JUNIPER_IFLE_ATM_CISCO_NLPID 26
262 #define JUNIPER_IFLE_VLAN_CCC 27
263 #define JUNIPER_IFLE_MLPPP 28
264 #define JUNIPER_IFLE_MLFR 29
265 #define JUNIPER_IFLE_LSI_NULL 30
266 #define JUNIPER_IFLE_AGGREGATE_UNUSED 31
267 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC 32
268 #define JUNIPER_IFLE_CRYPTO 33
269 #define JUNIPER_IFLE_GGSN 34
270 #define JUNIPER_IFLE_ATM_TCC 35
271 #define JUNIPER_IFLE_FR_TCC 36
272 #define JUNIPER_IFLE_PPP_TCC 37
273 #define JUNIPER_IFLE_CISCOHDLC_TCC 38
274 #define JUNIPER_IFLE_ETHERNET_CCC 39
275 #define JUNIPER_IFLE_VT 40
276 #define JUNIPER_IFLE_ATM_EOA_LLC 41
277 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC 42
278 #define JUNIPER_IFLE_ATM_SNAP_TCC 43
279 #define JUNIPER_IFLE_MONITOR 44
280 #define JUNIPER_IFLE_ETHERNET_TCC 45
281 #define JUNIPER_IFLE_VLAN_TCC 46
282 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC 47
283 #define JUNIPER_IFLE_MFR 48
284 #define JUNIPER_IFLE_ETHERNET_VPLS 49
285 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50
286 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51
287 #define JUNIPER_IFLE_SERVICES 52
288 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC 53
289 #define JUNIPER_IFLE_FR_PORT_CCC 54
290 #define JUNIPER_IFLE_ATM_MLPPP_LLC 55
291 #define JUNIPER_IFLE_ATM_EOA_CCC 56
292 #define JUNIPER_IFLE_LT_VLAN 57
293 #define JUNIPER_IFLE_COLLECTOR 58
294 #define JUNIPER_IFLE_AGGREGATOR 59
295 #define JUNIPER_IFLE_LAPD 60
296 #define JUNIPER_IFLE_ATM_PPPOE_LLC 61
297 #define JUNIPER_IFLE_ETHERNET_PPPOE 62
298 #define JUNIPER_IFLE_PPPOE 63
299 #define JUNIPER_IFLE_PPP_SUBORDINATE 64
300 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE 65
301 #define JUNIPER_IFLE_DFC 66
302 #define JUNIPER_IFLE_PICPEER 67
304 static const struct tok juniper_ifle_values
[] = {
305 { JUNIPER_IFLE_AGGREGATOR
, "Aggregator" },
306 { JUNIPER_IFLE_ATM_CCC
, "CCC over ATM" },
307 { JUNIPER_IFLE_ATM_CELLRELAY_CCC
, "ATM CCC Cell Relay" },
308 { JUNIPER_IFLE_ATM_CISCO_NLPID
, "CISCO compatible NLPID" },
309 { JUNIPER_IFLE_ATM_EOA_CCC
, "Ethernet over ATM CCC" },
310 { JUNIPER_IFLE_ATM_EOA_LLC
, "Ethernet over ATM LLC" },
311 { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC
, "Ethernet VPLS over ATM LLC" },
312 { JUNIPER_IFLE_ATM_LLC
, "ATM LLC" },
313 { JUNIPER_IFLE_ATM_MLPPP_LLC
, "MLPPP over ATM LLC" },
314 { JUNIPER_IFLE_ATM_NLPID
, "ATM NLPID" },
315 { JUNIPER_IFLE_ATM_PPPOE_LLC
, "PPPoE over ATM LLC" },
316 { JUNIPER_IFLE_ATM_PPP_FUNI
, "PPP over FUNI" },
317 { JUNIPER_IFLE_ATM_PPP_LLC
, "PPP over ATM LLC" },
318 { JUNIPER_IFLE_ATM_PPP_VCMUX
, "PPP over ATM VCMUX" },
319 { JUNIPER_IFLE_ATM_SNAP
, "ATM SNAP" },
320 { JUNIPER_IFLE_ATM_SNAP_TCC
, "ATM SNAP TCC" },
321 { JUNIPER_IFLE_ATM_TCC
, "ATM VCMUX TCC" },
322 { JUNIPER_IFLE_ATM_VCMUX
, "ATM VCMUX" },
323 { JUNIPER_IFLE_CISCOHDLC
, "C-HDLC" },
324 { JUNIPER_IFLE_CISCOHDLC_CCC
, "C-HDLC CCC" },
325 { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE
, "C-HDLC via dialer" },
326 { JUNIPER_IFLE_CISCOHDLC_TCC
, "C-HDLC TCC" },
327 { JUNIPER_IFLE_COLLECTOR
, "Collector" },
328 { JUNIPER_IFLE_CRYPTO
, "Crypto" },
329 { JUNIPER_IFLE_ENET2
, "Ethernet" },
330 { JUNIPER_IFLE_ETHERNET_CCC
, "Ethernet CCC" },
331 { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended VLAN VPLS" },
332 { JUNIPER_IFLE_ETHERNET_PPPOE
, "PPPoE over Ethernet" },
333 { JUNIPER_IFLE_ETHERNET_TCC
, "Ethernet TCC" },
334 { JUNIPER_IFLE_ETHERNET_VLAN_VPLS
, "VLAN VPLS" },
335 { JUNIPER_IFLE_ETHERNET_VPLS
, "VPLS" },
336 { JUNIPER_IFLE_EXTENDED_VLAN_CCC
, "Extended VLAN CCC" },
337 { JUNIPER_IFLE_EXTENDED_VLAN_TCC
, "Extended VLAN TCC" },
338 { JUNIPER_IFLE_FR_CCC
, "FR CCC" },
339 { JUNIPER_IFLE_FR_NLPID
, "FR NLPID" },
340 { JUNIPER_IFLE_FR_PORT_CCC
, "FR CCC" },
341 { JUNIPER_IFLE_FR_PPP
, "FR PPP" },
342 { JUNIPER_IFLE_FR_SNAP
, "FR SNAP" },
343 { JUNIPER_IFLE_FR_TCC
, "FR TCC" },
344 { JUNIPER_IFLE_GGSN
, "GGSN" },
345 { JUNIPER_IFLE_GRE_NULL
, "GRE NULL" },
346 { JUNIPER_IFLE_GRE_PPP
, "PPP over GRE" },
347 { JUNIPER_IFLE_IPIP_NULL
, "IPIP" },
348 { JUNIPER_IFLE_LAPD
, "LAPD" },
349 { JUNIPER_IFLE_LSI_NULL
, "LSI Null" },
350 { JUNIPER_IFLE_LT_VLAN
, "LT VLAN" },
351 { JUNIPER_IFLE_MFR
, "MFR" },
352 { JUNIPER_IFLE_MLFR
, "MLFR" },
353 { JUNIPER_IFLE_MLPPP
, "MLPPP" },
354 { JUNIPER_IFLE_MONITOR
, "Monitor" },
355 { JUNIPER_IFLE_PIMD_DECAPS
, "PIMd" },
356 { JUNIPER_IFLE_PIM_NULL
, "PIM Null" },
357 { JUNIPER_IFLE_PPP
, "PPP" },
358 { JUNIPER_IFLE_PPPOE
, "PPPoE" },
359 { JUNIPER_IFLE_PPP_CCC
, "PPP CCC" },
360 { JUNIPER_IFLE_PPP_SUBORDINATE
, "" },
361 { JUNIPER_IFLE_PPP_TCC
, "PPP TCC" },
362 { JUNIPER_IFLE_SERVICES
, "General Services" },
363 { JUNIPER_IFLE_VLAN_CCC
, "VLAN CCC" },
364 { JUNIPER_IFLE_VLAN_TCC
, "VLAN TCC" },
365 { JUNIPER_IFLE_VT
, "VT" },
369 struct juniper_cookie_table_t
{
370 uint32_t pictype
; /* pic type */
371 uint8_t cookie_len
; /* cookie len */
372 const char *s
; /* pic name */
375 static const struct juniper_cookie_table_t juniper_cookie_table
[] = {
376 #ifdef DLT_JUNIPER_ATM1
377 { DLT_JUNIPER_ATM1
, 4, "ATM1"},
379 #ifdef DLT_JUNIPER_ATM2
380 { DLT_JUNIPER_ATM2
, 8, "ATM2"},
382 #ifdef DLT_JUNIPER_MLPPP
383 { DLT_JUNIPER_MLPPP
, 2, "MLPPP"},
385 #ifdef DLT_JUNIPER_MLFR
386 { DLT_JUNIPER_MLFR
, 2, "MLFR"},
388 #ifdef DLT_JUNIPER_MFR
389 { DLT_JUNIPER_MFR
, 4, "MFR"},
391 #ifdef DLT_JUNIPER_PPPOE
392 { DLT_JUNIPER_PPPOE
, 0, "PPPoE"},
394 #ifdef DLT_JUNIPER_PPPOE_ATM
395 { DLT_JUNIPER_PPPOE_ATM
, 0, "PPPoE ATM"},
397 #ifdef DLT_JUNIPER_GGSN
398 { DLT_JUNIPER_GGSN
, 8, "GGSN"},
400 #ifdef DLT_JUNIPER_MONITOR
401 { DLT_JUNIPER_MONITOR
, 8, "MONITOR"},
403 #ifdef DLT_JUNIPER_SERVICES
404 { DLT_JUNIPER_SERVICES
, 8, "AS"},
406 #ifdef DLT_JUNIPER_ES
407 { DLT_JUNIPER_ES
, 0, "ES"},
412 struct juniper_l2info_t
{
426 #define LS_COOKIE_ID 0x54
427 #define AS_COOKIE_ID 0x47
428 #define LS_MLFR_COOKIE_LEN 4
429 #define ML_MLFR_COOKIE_LEN 2
430 #define LS_MFR_COOKIE_LEN 6
431 #define ATM1_COOKIE_LEN 4
432 #define ATM2_COOKIE_LEN 8
434 #define ATM2_PKT_TYPE_MASK 0x70
435 #define ATM2_GAP_COUNT_MASK 0x3F
437 #define JUNIPER_PROTO_NULL 1
438 #define JUNIPER_PROTO_IPV4 2
439 #define JUNIPER_PROTO_IPV6 6
441 #define MFR_BE_MASK 0xc0
443 #ifdef DLT_JUNIPER_GGSN
444 static const struct tok juniper_protocol_values
[] = {
445 { JUNIPER_PROTO_NULL
, "Null" },
446 { JUNIPER_PROTO_IPV4
, "IPv4" },
447 { JUNIPER_PROTO_IPV6
, "IPv6" },
452 static int ip_heuristic_guess(netdissect_options
*, const u_char
*, u_int
);
453 #ifdef DLT_JUNIPER_ATM2
454 static int juniper_ppp_heuristic_guess(netdissect_options
*, const u_char
*, u_int
);
456 #if defined(DLT_JUNIPER_GGSN) || defined(DLT_JUNIPER_ES) || \
457 defined(DLT_JUNIPER_MONITOR) || defined(DLT_JUNIPER_SERVICES) || \
458 defined(DLT_JUNIPER_PPPOE) || defined(DLT_JUNIPER_ETHER) || \
459 defined(DLT_JUNIPER_PPP) || defined(DLT_JUNIPER_FRELAY) || \
460 defined(DLT_JUNIPER_CHDLC) || defined(DLT_JUNIPER_PPPOE_ATM) || \
461 defined(DLT_JUNIPER_MLPPP) || defined(DLT_JUNIPER_MFR) || \
462 defined(DLT_JUNIPER_MLFR) || defined(DLT_JUNIPER_ATM1) || \
463 defined(DLT_JUNIPER_ATM2)
464 static int juniper_parse_header(netdissect_options
*, const u_char
*, const struct pcap_pkthdr
*, struct juniper_l2info_t
*);
467 #ifdef DLT_JUNIPER_GGSN
469 juniper_ggsn_if_print(netdissect_options
*ndo
,
470 const struct pcap_pkthdr
*h
, const u_char
*p
)
472 struct juniper_l2info_t l2info
;
473 struct juniper_ggsn_header
{
475 nd_uint8_t flags_len
;
481 const struct juniper_ggsn_header
*gh
;
484 ndo
->ndo_protocol
= "juniper_ggsn_if";
485 l2info
.pictype
= DLT_JUNIPER_GGSN
;
486 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
487 return l2info
.header_len
;
489 p
+=l2info
.header_len
;
490 gh
= (struct juniper_ggsn_header
*)&l2info
.cookie
;
493 proto
= EXTRACT_U_1(gh
->proto
);
494 if (ndo
->ndo_eflag
) {
495 ND_PRINT("proto %s (%u), vlan %u: ",
496 tok2str(juniper_protocol_values
,"Unknown",proto
),
498 EXTRACT_BE_U_2(gh
->vlan_id
));
502 case JUNIPER_PROTO_IPV4
:
503 ip_print(ndo
, p
, l2info
.length
);
505 case JUNIPER_PROTO_IPV6
:
506 ip6_print(ndo
, p
, l2info
.length
);
510 ND_PRINT("unknown GGSN proto (%u)", proto
);
513 return l2info
.header_len
;
517 return 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_if";
539 l2info
.pictype
= DLT_JUNIPER_ES
;
540 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
541 return l2info
.header_len
;
543 p
+=l2info
.header_len
;
544 ih
= (const struct juniper_ipsec_header
*)p
;
547 switch (EXTRACT_U_1(ih
->type
)) {
548 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
549 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
553 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
554 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
555 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
560 ND_PRINT("ES Invalid type %u, length %u",
561 EXTRACT_U_1(ih
->type
),
563 return l2info
.header_len
;
566 l2info
.length
-=rewrite_len
;
569 if (ndo
->ndo_eflag
) {
570 if (!es_type_bundle
) {
571 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
572 EXTRACT_BE_U_2(ih
->sa_index
),
573 EXTRACT_U_1(ih
->ttl
),
574 tok2str(juniper_ipsec_type_values
,"Unknown",EXTRACT_U_1(ih
->type
)),
575 EXTRACT_U_1(ih
->type
),
576 EXTRACT_BE_U_4(ih
->spi
),
577 ipaddr_string(ndo
, ih
->src_ip
),
578 ipaddr_string(ndo
, ih
->dst_ip
),
581 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), length %u\n",
582 EXTRACT_BE_U_2(ih
->sa_index
),
583 EXTRACT_U_1(ih
->ttl
),
584 tok2str(juniper_ipsec_type_values
,"Unknown",EXTRACT_U_1(ih
->type
)),
585 EXTRACT_U_1(ih
->type
),
590 ip_print(ndo
, p
, l2info
.length
);
591 return l2info
.header_len
;
595 return 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_if";
614 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
615 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
616 return l2info
.header_len
;
618 p
+=l2info
.header_len
;
619 mh
= (const struct juniper_monitor_header
*)p
;
623 ND_PRINT("service-id %u, iif %u, pkt-type %u: ",
624 EXTRACT_BE_U_4(mh
->service_id
),
625 EXTRACT_BE_U_2(mh
->iif
),
626 EXTRACT_U_1(mh
->pkt_type
));
628 /* no proto field - lets guess by first byte of IP header*/
629 ip_heuristic_guess (ndo
, p
, l2info
.length
);
631 return l2info
.header_len
;
635 return l2info
.header_len
;
639 #ifdef DLT_JUNIPER_SERVICES
641 juniper_services_if_print(netdissect_options
*ndo
,
642 const struct pcap_pkthdr
*h
, const u_char
*p
)
644 struct juniper_l2info_t l2info
;
645 struct juniper_services_header
{
647 nd_uint8_t flags_len
;
648 nd_uint16_t svc_set_id
;
652 const struct juniper_services_header
*sh
;
654 ndo
->ndo_protocol
= "juniper_services_if";
655 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
656 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
657 return l2info
.header_len
;
659 p
+=l2info
.header_len
;
660 sh
= (const struct juniper_services_header
*)p
;
664 ND_PRINT("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
665 EXTRACT_U_1(sh
->svc_id
),
666 EXTRACT_U_1(sh
->flags_len
),
667 EXTRACT_BE_U_2(sh
->svc_set_id
),
668 EXTRACT_BE_U_3(sh
->dir_iif
));
670 /* no proto field - lets guess by first byte of IP header*/
671 ip_heuristic_guess (ndo
, p
, l2info
.length
);
673 return l2info
.header_len
;
677 return l2info
.header_len
;
681 #ifdef DLT_JUNIPER_PPPOE
683 juniper_pppoe_if_print(netdissect_options
*ndo
,
684 const struct pcap_pkthdr
*h
, const u_char
*p
)
686 struct juniper_l2info_t l2info
;
688 ndo
->ndo_protocol
= "juniper_pppoe_if";
689 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
690 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
691 return l2info
.header_len
;
693 p
+=l2info
.header_len
;
694 /* this DLT contains nothing but raw ethernet frames */
695 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
696 return l2info
.header_len
;
700 #ifdef DLT_JUNIPER_ETHER
702 juniper_ether_if_print(netdissect_options
*ndo
,
703 const struct pcap_pkthdr
*h
, const u_char
*p
)
705 struct juniper_l2info_t l2info
;
707 ndo
->ndo_protocol
= "juniper_ether_if";
708 l2info
.pictype
= DLT_JUNIPER_ETHER
;
709 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
710 return l2info
.header_len
;
712 p
+=l2info
.header_len
;
713 /* this DLT contains nothing but raw Ethernet frames */
714 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
715 return l2info
.header_len
;
719 #ifdef DLT_JUNIPER_PPP
721 juniper_ppp_if_print(netdissect_options
*ndo
,
722 const struct pcap_pkthdr
*h
, const u_char
*p
)
724 struct juniper_l2info_t l2info
;
726 ndo
->ndo_protocol
= "juniper_ppp_if";
727 l2info
.pictype
= DLT_JUNIPER_PPP
;
728 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
729 return l2info
.header_len
;
731 p
+=l2info
.header_len
;
732 /* this DLT contains nothing but raw ppp frames */
733 ppp_print(ndo
, p
, l2info
.length
);
734 return l2info
.header_len
;
738 #ifdef DLT_JUNIPER_FRELAY
740 juniper_frelay_if_print(netdissect_options
*ndo
,
741 const struct pcap_pkthdr
*h
, const u_char
*p
)
743 struct juniper_l2info_t l2info
;
745 ndo
->ndo_protocol
= "juniper_frelay_if";
746 l2info
.pictype
= DLT_JUNIPER_FRELAY
;
747 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
748 return l2info
.header_len
;
750 p
+=l2info
.header_len
;
751 /* this DLT contains nothing but raw frame-relay frames */
752 fr_print(ndo
, p
, l2info
.length
);
753 return l2info
.header_len
;
757 #ifdef DLT_JUNIPER_CHDLC
759 juniper_chdlc_if_print(netdissect_options
*ndo
,
760 const struct pcap_pkthdr
*h
, const u_char
*p
)
762 struct juniper_l2info_t l2info
;
764 ndo
->ndo_protocol
= "juniper_chdlc_if";
765 l2info
.pictype
= DLT_JUNIPER_CHDLC
;
766 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
767 return l2info
.header_len
;
769 p
+=l2info
.header_len
;
770 /* this DLT contains nothing but raw c-hdlc frames */
771 chdlc_print(ndo
, p
, l2info
.length
);
772 return l2info
.header_len
;
776 #ifdef DLT_JUNIPER_PPPOE_ATM
778 juniper_pppoe_atm_if_print(netdissect_options
*ndo
,
779 const struct pcap_pkthdr
*h
, const u_char
*p
)
781 struct juniper_l2info_t l2info
;
782 uint16_t extracted_ethertype
;
784 ndo
->ndo_protocol
= "juniper_pppoe_atm_if";
785 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
786 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
787 return l2info
.header_len
;
789 p
+=l2info
.header_len
;
792 extracted_ethertype
= EXTRACT_BE_U_2(p
);
793 /* this DLT contains nothing but raw PPPoE frames,
794 * prepended with a type field*/
795 if (ethertype_print(ndo
, extracted_ethertype
,
797 l2info
.length
-ETHERTYPE_LEN
,
798 l2info
.caplen
-ETHERTYPE_LEN
,
800 /* ether_type not known, probably it wasn't one */
801 ND_PRINT("unknown ethertype 0x%04x", extracted_ethertype
);
803 return l2info
.header_len
;
807 return l2info
.header_len
;
811 #ifdef DLT_JUNIPER_MLPPP
813 juniper_mlppp_if_print(netdissect_options
*ndo
,
814 const struct pcap_pkthdr
*h
, const u_char
*p
)
816 struct juniper_l2info_t l2info
;
818 ndo
->ndo_protocol
= "juniper_mlppp_if";
819 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
820 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
821 return l2info
.header_len
;
823 /* suppress Bundle-ID if frame was captured on a child-link
824 * best indicator if the cookie looks like a proto */
825 if (ndo
->ndo_eflag
&&
826 EXTRACT_BE_U_2(&l2info
.cookie
) != PPP_OSI
&&
827 EXTRACT_BE_U_2(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
828 ND_PRINT("Bundle-ID %u: ", l2info
.bundle
);
830 p
+=l2info
.header_len
;
832 /* first try the LSQ protos */
833 switch(l2info
.proto
) {
834 case JUNIPER_LSQ_L3_PROTO_IPV4
:
835 /* IP traffic going to the RE would not have a cookie
836 * -> this must be incoming IS-IS over PPP
838 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
839 ppp_print(ndo
, p
, l2info
.length
);
841 ip_print(ndo
, p
, l2info
.length
);
842 return l2info
.header_len
;
843 case JUNIPER_LSQ_L3_PROTO_IPV6
:
844 ip6_print(ndo
, p
,l2info
.length
);
845 return l2info
.header_len
;
846 case JUNIPER_LSQ_L3_PROTO_MPLS
:
847 mpls_print(ndo
, p
, l2info
.length
);
848 return l2info
.header_len
;
849 case JUNIPER_LSQ_L3_PROTO_ISO
:
850 isoclns_print(ndo
, p
, l2info
.length
);
851 return l2info
.header_len
;
856 /* zero length cookie ? */
857 switch (EXTRACT_BE_U_2(&l2info
.cookie
)) {
859 ppp_print(ndo
, p
- 2, l2info
.length
+ 2);
861 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
863 ppp_print(ndo
, p
, l2info
.length
);
867 return l2info
.header_len
;
872 #ifdef DLT_JUNIPER_MFR
874 juniper_mfr_if_print(netdissect_options
*ndo
,
875 const struct pcap_pkthdr
*h
, const u_char
*p
)
877 struct juniper_l2info_t l2info
;
879 ndo
->ndo_protocol
= "juniper_mfr_if";
880 memset(&l2info
, 0, sizeof(l2info
));
881 l2info
.pictype
= DLT_JUNIPER_MFR
;
882 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
883 return l2info
.header_len
;
885 p
+=l2info
.header_len
;
888 if (l2info
.cookie_len
== 0) {
889 mfr_print(ndo
, p
, l2info
.length
);
890 return l2info
.header_len
;
893 /* first try the LSQ protos */
894 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
895 switch(l2info
.proto
) {
896 case JUNIPER_LSQ_L3_PROTO_IPV4
:
897 ip_print(ndo
, p
, l2info
.length
);
898 return l2info
.header_len
;
899 case JUNIPER_LSQ_L3_PROTO_IPV6
:
900 ip6_print(ndo
, p
,l2info
.length
);
901 return l2info
.header_len
;
902 case JUNIPER_LSQ_L3_PROTO_MPLS
:
903 mpls_print(ndo
, p
, l2info
.length
);
904 return l2info
.header_len
;
905 case JUNIPER_LSQ_L3_PROTO_ISO
:
906 isoclns_print(ndo
, p
, l2info
.length
);
907 return l2info
.header_len
;
911 return l2info
.header_len
;
914 /* suppress Bundle-ID if frame was captured on a child-link */
915 if (ndo
->ndo_eflag
&& EXTRACT_BE_U_4(l2info
.cookie
) != 1)
916 ND_PRINT("Bundle-ID %u, ", l2info
.bundle
);
917 switch (l2info
.proto
) {
918 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
919 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
921 case (LLC_UI
<<8 | NLPID_Q933
):
922 case (LLC_UI
<<8 | NLPID_IP
):
923 case (LLC_UI
<<8 | NLPID_IP6
):
924 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
925 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1);
928 ND_PRINT("unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
);
931 return l2info
.header_len
;
935 #ifdef DLT_JUNIPER_MLFR
937 juniper_mlfr_if_print(netdissect_options
*ndo
,
938 const struct pcap_pkthdr
*h
, const u_char
*p
)
940 struct juniper_l2info_t l2info
;
942 ndo
->ndo_protocol
= "juniper_mlfr_if";
943 l2info
.pictype
= DLT_JUNIPER_MLFR
;
944 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
945 return l2info
.header_len
;
947 p
+=l2info
.header_len
;
949 /* suppress Bundle-ID if frame was captured on a child-link */
950 if (ndo
->ndo_eflag
&& EXTRACT_BE_U_4(l2info
.cookie
) != 1)
951 ND_PRINT("Bundle-ID %u, ", l2info
.bundle
);
952 switch (l2info
.proto
) {
955 isoclns_print(ndo
, p
, l2info
.length
);
957 case (LLC_UI
<<8 | NLPID_Q933
):
958 case (LLC_UI
<<8 | NLPID_IP
):
959 case (LLC_UI
<<8 | NLPID_IP6
):
960 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
961 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1);
964 ND_PRINT("unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
);
967 return l2info
.header_len
;
972 * ATM1 PIC cookie format
974 * +-----+-------------------------+-------------------------------+
975 * |fmtid| vc index | channel ID |
976 * +-----+-------------------------+-------------------------------+
979 #ifdef DLT_JUNIPER_ATM1
981 juniper_atm1_if_print(netdissect_options
*ndo
,
982 const struct pcap_pkthdr
*h
, const u_char
*p
)
986 struct juniper_l2info_t l2info
;
988 ndo
->ndo_protocol
= "juniper_atm1_if";
989 l2info
.pictype
= DLT_JUNIPER_ATM1
;
990 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
991 return l2info
.header_len
;
993 p
+=l2info
.header_len
;
995 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
996 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
997 return l2info
.header_len
;
1001 if (EXTRACT_BE_U_3(p
) == 0xfefe03 || /* NLPID encaps ? */
1002 EXTRACT_BE_U_3(p
) == 0xaaaa03) { /* SNAP encaps ? */
1004 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1006 return l2info
.header_len
;
1009 if (EXTRACT_U_1(p
) == 0x03) { /* Cisco style NLPID encaps ? */
1010 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
1011 /* FIXME check if frame was recognized */
1012 return l2info
.header_len
;
1015 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
1016 return l2info
.header_len
;
1018 return l2info
.header_len
;
1021 nd_print_trunc(ndo
);
1022 return l2info
.header_len
;
1027 * ATM2 PIC cookie format
1029 * +-------------------------------+---------+---+-----+-----------+
1030 * | channel ID | reserv |AAL| CCRQ| gap cnt |
1031 * +-------------------------------+---------+---+-----+-----------+
1034 #ifdef DLT_JUNIPER_ATM2
1036 juniper_atm2_if_print(netdissect_options
*ndo
,
1037 const struct pcap_pkthdr
*h
, const u_char
*p
)
1041 struct juniper_l2info_t l2info
;
1043 ndo
->ndo_protocol
= "juniper_atm2_if";
1044 l2info
.pictype
= DLT_JUNIPER_ATM2
;
1045 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
1046 return l2info
.header_len
;
1048 p
+=l2info
.header_len
;
1050 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
1051 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
1052 return l2info
.header_len
;
1056 if (EXTRACT_BE_U_3(p
) == 0xfefe03 || /* NLPID encaps ? */
1057 EXTRACT_BE_U_3(p
) == 0xaaaa03) { /* SNAP encaps ? */
1059 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1061 return l2info
.header_len
;
1064 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
1065 (EXTRACT_BE_U_4(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
1066 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
1067 return l2info
.header_len
;
1070 if (EXTRACT_U_1(p
) == 0x03) { /* Cisco style NLPID encaps ? */
1071 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1);
1072 /* FIXME check if frame was recognized */
1073 return l2info
.header_len
;
1076 if(juniper_ppp_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* PPPoA vcmux encaps ? */
1077 return l2info
.header_len
;
1079 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
1080 return l2info
.header_len
;
1082 return l2info
.header_len
;
1085 nd_print_trunc(ndo
);
1086 return l2info
.header_len
;
1090 #ifdef DLT_JUNIPER_ATM2
1091 /* try to guess, based on all PPP protos that are supported in
1092 * a juniper router if the payload data is encapsulated using PPP */
1094 juniper_ppp_heuristic_guess(netdissect_options
*ndo
,
1095 const u_char
*p
, u_int length
)
1097 switch(EXTRACT_BE_U_2(p
)) {
1100 case PPP_MPLS_UCAST
:
1101 case PPP_MPLS_MCAST
:
1111 ppp_print(ndo
, p
, length
);
1115 return 0; /* did not find a ppp header */
1118 return 1; /* we printed a ppp packet */
1123 ip_heuristic_guess(netdissect_options
*ndo
,
1124 const u_char
*p
, u_int length
)
1126 switch(EXTRACT_U_1(p
)) {
1138 ip_print(ndo
, p
, length
);
1156 ip6_print(ndo
, p
, length
);
1159 return 0; /* did not find a ip header */
1162 return 1; /* we printed an v4/v6 packet */
1166 juniper_read_tlv_value(const u_char
*p
, u_int tlv_type
, u_int tlv_len
)
1170 /* TLVs < 128 are little endian encoded */
1171 if (tlv_type
< 128) {
1174 tlv_value
= EXTRACT_U_1(p
);
1177 tlv_value
= EXTRACT_LE_U_2(p
);
1180 tlv_value
= EXTRACT_LE_U_3(p
);
1183 tlv_value
= EXTRACT_LE_U_4(p
);
1190 /* TLVs >= 128 are big endian encoded */
1193 tlv_value
= EXTRACT_U_1(p
);
1196 tlv_value
= EXTRACT_BE_U_2(p
);
1199 tlv_value
= EXTRACT_BE_U_3(p
);
1202 tlv_value
= EXTRACT_BE_U_4(p
);
1212 #if defined(DLT_JUNIPER_GGSN) || defined(DLT_JUNIPER_ES) || \
1213 defined(DLT_JUNIPER_MONITOR) || defined(DLT_JUNIPER_SERVICES) || \
1214 defined(DLT_JUNIPER_PPPOE) || defined(DLT_JUNIPER_ETHER) || \
1215 defined(DLT_JUNIPER_PPP) || defined(DLT_JUNIPER_FRELAY) || \
1216 defined(DLT_JUNIPER_CHDLC) || defined(DLT_JUNIPER_PPPOE_ATM) || \
1217 defined(DLT_JUNIPER_MLPPP) || defined(DLT_JUNIPER_MFR) || \
1218 defined(DLT_JUNIPER_MLFR) || defined(DLT_JUNIPER_ATM1) || \
1219 defined(DLT_JUNIPER_ATM2)
1221 juniper_parse_header(netdissect_options
*ndo
,
1222 const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
)
1224 const struct juniper_cookie_table_t
*lp
= juniper_cookie_table
;
1225 u_int idx
, jnx_ext_len
, jnx_header_len
= 0;
1226 uint8_t tlv_type
,tlv_len
;
1227 #ifdef DLT_JUNIPER_ATM2
1228 uint32_t control_word
;
1234 l2info
->header_len
= 0;
1235 l2info
->cookie_len
= 0;
1239 l2info
->length
= h
->len
;
1240 l2info
->caplen
= h
->caplen
;
1242 l2info
->flags
= EXTRACT_U_1(p
+ 3);
1243 l2info
->direction
= EXTRACT_U_1(p
+ 3) & JUNIPER_BPF_PKT_IN
;
1245 if (EXTRACT_BE_U_3(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
1246 ND_PRINT("no magic-number found!");
1250 if (ndo
->ndo_eflag
) /* print direction */
1251 ND_PRINT("%3s ", tok2str(juniper_direction_values
, "---", l2info
->direction
));
1253 /* magic number + flags */
1256 if (ndo
->ndo_vflag
> 1)
1257 ND_PRINT("\n\tJuniper PCAP Flags [%s]",
1258 bittok2str(jnx_flag_values
, "none", l2info
->flags
));
1260 /* extensions present ? - calculate how much bytes to skip */
1261 if ((l2info
->flags
& JUNIPER_BPF_EXT
) == JUNIPER_BPF_EXT
) {
1263 tptr
= p
+jnx_header_len
;
1265 /* ok to read extension length ? */
1267 jnx_ext_len
= EXTRACT_BE_U_2(tptr
);
1268 jnx_header_len
+= 2;
1271 /* nail up the total length -
1272 * just in case something goes wrong
1273 * with TLV parsing */
1274 jnx_header_len
+= jnx_ext_len
;
1276 if (ndo
->ndo_vflag
> 1)
1277 ND_PRINT(", PCAP Extension(s) total length %u", jnx_ext_len
);
1279 ND_TCHECK_LEN(tptr
, jnx_ext_len
);
1280 while (jnx_ext_len
> JUNIPER_EXT_TLV_OVERHEAD
) {
1281 tlv_type
= EXTRACT_U_1(tptr
);
1283 tlv_len
= EXTRACT_U_1(tptr
);
1288 if (tlv_type
== 0 || tlv_len
== 0)
1290 if (tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
> jnx_ext_len
)
1293 if (ndo
->ndo_vflag
> 1)
1294 ND_PRINT("\n\t %s Extension TLV #%u, length %u, value ",
1295 tok2str(jnx_ext_tlv_values
,"Unknown",tlv_type
),
1299 tlv_value
= juniper_read_tlv_value(tptr
, tlv_type
, tlv_len
);
1301 case JUNIPER_EXT_TLV_IFD_NAME
:
1304 case JUNIPER_EXT_TLV_IFD_MEDIATYPE
:
1305 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
:
1306 if (tlv_value
!= -1) {
1307 if (ndo
->ndo_vflag
> 1)
1309 tok2str(juniper_ifmt_values
, "Unknown", tlv_value
),
1313 case JUNIPER_EXT_TLV_IFL_ENCAPS
:
1314 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
:
1315 if (tlv_value
!= -1) {
1316 if (ndo
->ndo_vflag
> 1)
1318 tok2str(juniper_ifle_values
, "Unknown", tlv_value
),
1322 case JUNIPER_EXT_TLV_IFL_IDX
: /* fall through */
1323 case JUNIPER_EXT_TLV_IFL_UNIT
:
1324 case JUNIPER_EXT_TLV_IFD_IDX
:
1326 if (tlv_value
!= -1) {
1327 if (ndo
->ndo_vflag
> 1)
1328 ND_PRINT("%u", tlv_value
);
1334 jnx_ext_len
-= tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
;
1337 if (ndo
->ndo_vflag
> 1)
1338 ND_PRINT("\n\t-----original packet-----\n\t");
1341 if ((l2info
->flags
& JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
1343 ND_PRINT("no-L2-hdr, ");
1345 /* there is no link-layer present -
1346 * perform the v4/v6 heuristics
1347 * to figure out what it is
1349 ND_TCHECK_1(p
+ (jnx_header_len
+ 4));
1350 if (ip_heuristic_guess(ndo
, p
+ jnx_header_len
+ 4,
1351 l2info
->length
- (jnx_header_len
+ 4)) == 0)
1352 ND_PRINT("no IP-hdr found!");
1354 l2info
->header_len
=jnx_header_len
+4;
1355 return 0; /* stop parsing the output further */
1358 l2info
->header_len
= jnx_header_len
;
1359 p
+=l2info
->header_len
;
1360 l2info
->length
-= l2info
->header_len
;
1361 l2info
->caplen
-= l2info
->header_len
;
1363 /* search through the cookie table and copy values matching for our PIC type */
1365 while (lp
->s
!= NULL
) {
1366 if (lp
->pictype
== l2info
->pictype
) {
1368 l2info
->cookie_len
+= lp
->cookie_len
;
1370 switch (EXTRACT_U_1(p
)) {
1372 l2info
->cookie_type
= LS_COOKIE_ID
;
1373 l2info
->cookie_len
+= 2;
1376 l2info
->cookie_type
= AS_COOKIE_ID
;
1377 l2info
->cookie_len
= 8;
1381 l2info
->bundle
= l2info
->cookie
[0];
1386 #ifdef DLT_JUNIPER_MFR
1387 /* MFR child links don't carry cookies */
1388 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
1389 (EXTRACT_U_1(p
) & MFR_BE_MASK
) == MFR_BE_MASK
) {
1390 l2info
->cookie_len
= 0;
1394 l2info
->header_len
+= l2info
->cookie_len
;
1395 l2info
->length
-= l2info
->cookie_len
;
1396 l2info
->caplen
-= l2info
->cookie_len
;
1399 ND_PRINT("%s-PIC, cookie-len %u",
1401 l2info
->cookie_len
);
1403 if (l2info
->cookie_len
> 0) {
1404 ND_TCHECK_LEN(p
, l2info
->cookie_len
);
1406 ND_PRINT(", cookie 0x");
1407 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
1408 l2info
->cookie
[idx
] = EXTRACT_U_1(p
+ idx
); /* copy cookie data */
1409 if (ndo
->ndo_eflag
) ND_PRINT("%02x", EXTRACT_U_1(p
+ idx
));
1413 if (ndo
->ndo_eflag
) ND_PRINT(": "); /* print demarc b/w L2/L3*/
1416 ND_TCHECK_2(p
+ l2info
->cookie_len
);
1417 l2info
->proto
= EXTRACT_BE_U_2(p
+ l2info
->cookie_len
);
1422 p
+=l2info
->cookie_len
;
1424 /* DLT_ specific parsing */
1425 switch(l2info
->pictype
) {
1426 #ifdef DLT_JUNIPER_MLPPP
1427 case DLT_JUNIPER_MLPPP
:
1428 switch (l2info
->cookie_type
) {
1430 l2info
->bundle
= l2info
->cookie
[1];
1433 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1434 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1437 l2info
->bundle
= l2info
->cookie
[0];
1442 #ifdef DLT_JUNIPER_MLFR
1443 case DLT_JUNIPER_MLFR
:
1444 switch (l2info
->cookie_type
) {
1447 l2info
->bundle
= l2info
->cookie
[1];
1448 l2info
->proto
= EXTRACT_BE_U_2(p
);
1449 l2info
->header_len
+= 2;
1450 l2info
->length
-= 2;
1451 l2info
->caplen
-= 2;
1454 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1455 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1458 l2info
->bundle
= l2info
->cookie
[0];
1459 l2info
->header_len
+= 2;
1460 l2info
->length
-= 2;
1461 l2info
->caplen
-= 2;
1466 #ifdef DLT_JUNIPER_MFR
1467 case DLT_JUNIPER_MFR
:
1468 switch (l2info
->cookie_type
) {
1471 l2info
->bundle
= l2info
->cookie
[1];
1472 l2info
->proto
= EXTRACT_BE_U_2(p
);
1473 l2info
->header_len
+= 2;
1474 l2info
->length
-= 2;
1475 l2info
->caplen
-= 2;
1478 l2info
->bundle
= (EXTRACT_BE_U_2(&l2info
->cookie
[6])>>3)&0xfff;
1479 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1482 l2info
->bundle
= l2info
->cookie
[0];
1487 #ifdef DLT_JUNIPER_ATM2
1488 case DLT_JUNIPER_ATM2
:
1490 /* ATM cell relay control word present ? */
1491 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
) {
1492 control_word
= EXTRACT_BE_U_4(p
);
1493 /* some control word heuristics */
1494 switch(control_word
) {
1495 case 0: /* zero control word */
1496 case 0x08000000: /* < JUNOS 7.4 control-word */
1497 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1498 l2info
->header_len
+= 4;
1505 ND_PRINT("control-word 0x%08x ", control_word
);
1509 #ifdef DLT_JUNIPER_GGSN
1510 case DLT_JUNIPER_GGSN
:
1513 #ifdef DLT_JUNIPER_ATM1
1514 case DLT_JUNIPER_ATM1
:
1517 #ifdef DLT_JUNIPER_PPP
1518 case DLT_JUNIPER_PPP
:
1521 #ifdef DLT_JUNIPER_CHDLC
1522 case DLT_JUNIPER_CHDLC
:
1525 #ifdef DLT_JUNIPER_ETHER
1526 case DLT_JUNIPER_ETHER
:
1529 #ifdef DLT_JUNIPER_FRELAY
1530 case DLT_JUNIPER_FRELAY
:
1535 ND_PRINT("Unknown Juniper DLT_ type %u: ", l2info
->pictype
);
1539 if (ndo
->ndo_eflag
> 1)
1540 ND_PRINT("hlen %u, proto 0x%04x, ", l2info
->header_len
, l2info
->proto
);
1542 return 1; /* everything went ok so far. continue parsing */
1544 nd_print_trunc(ndo
);