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@juniper.net)
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>
31 #include "netdissect.h"
32 #include "addrtoname.h"
37 #include "ethertype.h"
40 #define JUNIPER_BPF_OUT 0 /* Outgoing packet */
41 #define JUNIPER_BPF_IN 1 /* Incoming packet */
42 #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */
43 #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */
44 #define JUNIPER_BPF_IIF 0x4 /* IIF is valid */
45 #define JUNIPER_BPF_FILTER 0x40 /* BPF filtering is supported */
46 #define JUNIPER_BPF_EXT 0x80 /* extensions present */
47 #define JUNIPER_MGC_NUMBER 0x4d4743 /* = "MGC" */
49 #define JUNIPER_LSQ_COOKIE_RE (1 << 3)
50 #define JUNIPER_LSQ_COOKIE_DIR (1 << 2)
51 #define JUNIPER_LSQ_L3_PROTO_SHIFT 4
52 #define JUNIPER_LSQ_L3_PROTO_MASK (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT)
53 #define JUNIPER_LSQ_L3_PROTO_IPV4 (0 << JUNIPER_LSQ_L3_PROTO_SHIFT)
54 #define JUNIPER_LSQ_L3_PROTO_IPV6 (1 << JUNIPER_LSQ_L3_PROTO_SHIFT)
55 #define JUNIPER_LSQ_L3_PROTO_MPLS (2 << JUNIPER_LSQ_L3_PROTO_SHIFT)
56 #define JUNIPER_LSQ_L3_PROTO_ISO (3 << JUNIPER_LSQ_L3_PROTO_SHIFT)
57 #define AS_PIC_COOKIE_LEN 8
59 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1
60 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2
61 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3
62 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4
63 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5
65 static const struct tok juniper_ipsec_type_values
[] = {
66 { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
, "ESP ENCR-AUTH" },
67 { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
, "ESP ENCR-AH AUTH" },
68 { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
, "ESP AUTH" },
69 { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
, "AH AUTH" },
70 { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
, "ESP ENCR" },
74 static const struct tok juniper_direction_values
[] = {
75 { JUNIPER_BPF_IN
, "In"},
76 { JUNIPER_BPF_OUT
, "Out"},
80 /* codepoints for encoding extensions to a .pcap file */
82 JUNIPER_EXT_TLV_IFD_IDX
= 1,
83 JUNIPER_EXT_TLV_IFD_NAME
= 2,
84 JUNIPER_EXT_TLV_IFD_MEDIATYPE
= 3,
85 JUNIPER_EXT_TLV_IFL_IDX
= 4,
86 JUNIPER_EXT_TLV_IFL_UNIT
= 5,
87 JUNIPER_EXT_TLV_IFL_ENCAPS
= 6,
88 JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
= 7,
89 JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
= 8
92 /* 1 byte type and 1-byte length */
93 #define JUNIPER_EXT_TLV_OVERHEAD 2
95 static const struct tok jnx_ext_tlv_values
[] = {
96 { JUNIPER_EXT_TLV_IFD_IDX
, "Device Interface Index" },
97 { JUNIPER_EXT_TLV_IFD_NAME
,"Device Interface Name" },
98 { JUNIPER_EXT_TLV_IFD_MEDIATYPE
, "Device Media Type" },
99 { JUNIPER_EXT_TLV_IFL_IDX
, "Logical Interface Index" },
100 { JUNIPER_EXT_TLV_IFL_UNIT
,"Logical Unit Number" },
101 { JUNIPER_EXT_TLV_IFL_ENCAPS
, "Logical Interface Encapsulation" },
102 { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
, "TTP derived Device Media Type" },
103 { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
, "TTP derived Logical Interface Encapsulation" },
107 static const struct tok jnx_flag_values
[] = {
108 { JUNIPER_BPF_EXT
, "Ext" },
109 { JUNIPER_BPF_FILTER
, "Filter" },
110 { JUNIPER_BPF_IIF
, "IIF" },
111 { JUNIPER_BPF_NO_L2
, "no-L2" },
112 { JUNIPER_BPF_PKT_IN
, "In" },
116 #define JUNIPER_IFML_ETHER 1
117 #define JUNIPER_IFML_FDDI 2
118 #define JUNIPER_IFML_TOKENRING 3
119 #define JUNIPER_IFML_PPP 4
120 #define JUNIPER_IFML_FRAMERELAY 5
121 #define JUNIPER_IFML_CISCOHDLC 6
122 #define JUNIPER_IFML_SMDSDXI 7
123 #define JUNIPER_IFML_ATMPVC 8
124 #define JUNIPER_IFML_PPP_CCC 9
125 #define JUNIPER_IFML_FRAMERELAY_CCC 10
126 #define JUNIPER_IFML_IPIP 11
127 #define JUNIPER_IFML_GRE 12
128 #define JUNIPER_IFML_PIM 13
129 #define JUNIPER_IFML_PIMD 14
130 #define JUNIPER_IFML_CISCOHDLC_CCC 15
131 #define JUNIPER_IFML_VLAN_CCC 16
132 #define JUNIPER_IFML_MLPPP 17
133 #define JUNIPER_IFML_MLFR 18
134 #define JUNIPER_IFML_ML 19
135 #define JUNIPER_IFML_LSI 20
136 #define JUNIPER_IFML_DFE 21
137 #define JUNIPER_IFML_ATM_CELLRELAY_CCC 22
138 #define JUNIPER_IFML_CRYPTO 23
139 #define JUNIPER_IFML_GGSN 24
140 #define JUNIPER_IFML_LSI_PPP 25
141 #define JUNIPER_IFML_LSI_CISCOHDLC 26
142 #define JUNIPER_IFML_PPP_TCC 27
143 #define JUNIPER_IFML_FRAMERELAY_TCC 28
144 #define JUNIPER_IFML_CISCOHDLC_TCC 29
145 #define JUNIPER_IFML_ETHERNET_CCC 30
146 #define JUNIPER_IFML_VT 31
147 #define JUNIPER_IFML_EXTENDED_VLAN_CCC 32
148 #define JUNIPER_IFML_ETHER_OVER_ATM 33
149 #define JUNIPER_IFML_MONITOR 34
150 #define JUNIPER_IFML_ETHERNET_TCC 35
151 #define JUNIPER_IFML_VLAN_TCC 36
152 #define JUNIPER_IFML_EXTENDED_VLAN_TCC 37
153 #define JUNIPER_IFML_CONTROLLER 38
154 #define JUNIPER_IFML_MFR 39
155 #define JUNIPER_IFML_LS 40
156 #define JUNIPER_IFML_ETHERNET_VPLS 41
157 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42
158 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43
159 #define JUNIPER_IFML_LT 44
160 #define JUNIPER_IFML_SERVICES 45
161 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46
162 #define JUNIPER_IFML_FR_PORT_CCC 47
163 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48
164 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49
165 #define JUNIPER_IFML_FRAMERELAY_FLEX 50
166 #define JUNIPER_IFML_GGSNI 51
167 #define JUNIPER_IFML_ETHERNET_FLEX 52
168 #define JUNIPER_IFML_COLLECTOR 53
169 #define JUNIPER_IFML_AGGREGATOR 54
170 #define JUNIPER_IFML_LAPD 55
171 #define JUNIPER_IFML_PPPOE 56
172 #define JUNIPER_IFML_PPP_SUBORDINATE 57
173 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE 58
174 #define JUNIPER_IFML_DFC 59
175 #define JUNIPER_IFML_PICPEER 60
177 static const struct tok juniper_ifmt_values
[] = {
178 { JUNIPER_IFML_ETHER
, "Ethernet" },
179 { JUNIPER_IFML_FDDI
, "FDDI" },
180 { JUNIPER_IFML_TOKENRING
, "Token-Ring" },
181 { JUNIPER_IFML_PPP
, "PPP" },
182 { JUNIPER_IFML_PPP_SUBORDINATE
, "PPP-Subordinate" },
183 { JUNIPER_IFML_FRAMERELAY
, "Frame-Relay" },
184 { JUNIPER_IFML_CISCOHDLC
, "Cisco-HDLC" },
185 { JUNIPER_IFML_SMDSDXI
, "SMDS-DXI" },
186 { JUNIPER_IFML_ATMPVC
, "ATM-PVC" },
187 { JUNIPER_IFML_PPP_CCC
, "PPP-CCC" },
188 { JUNIPER_IFML_FRAMERELAY_CCC
, "Frame-Relay-CCC" },
189 { JUNIPER_IFML_FRAMERELAY_EXT_CCC
, "Extended FR-CCC" },
190 { JUNIPER_IFML_IPIP
, "IP-over-IP" },
191 { JUNIPER_IFML_GRE
, "GRE" },
192 { JUNIPER_IFML_PIM
, "PIM-Encapsulator" },
193 { JUNIPER_IFML_PIMD
, "PIM-Decapsulator" },
194 { JUNIPER_IFML_CISCOHDLC_CCC
, "Cisco-HDLC-CCC" },
195 { JUNIPER_IFML_VLAN_CCC
, "VLAN-CCC" },
196 { JUNIPER_IFML_EXTENDED_VLAN_CCC
, "Extended-VLAN-CCC" },
197 { JUNIPER_IFML_MLPPP
, "Multilink-PPP" },
198 { JUNIPER_IFML_MLFR
, "Multilink-FR" },
199 { JUNIPER_IFML_MFR
, "Multilink-FR-UNI-NNI" },
200 { JUNIPER_IFML_ML
, "Multilink" },
201 { JUNIPER_IFML_LS
, "LinkService" },
202 { JUNIPER_IFML_LSI
, "LSI" },
203 { JUNIPER_IFML_ATM_CELLRELAY_CCC
, "ATM-CCC-Cell-Relay" },
204 { JUNIPER_IFML_CRYPTO
, "IPSEC-over-IP" },
205 { JUNIPER_IFML_GGSN
, "GGSN" },
206 { JUNIPER_IFML_PPP_TCC
, "PPP-TCC" },
207 { JUNIPER_IFML_FRAMERELAY_TCC
, "Frame-Relay-TCC" },
208 { JUNIPER_IFML_FRAMERELAY_EXT_TCC
, "Extended FR-TCC" },
209 { JUNIPER_IFML_CISCOHDLC_TCC
, "Cisco-HDLC-TCC" },
210 { JUNIPER_IFML_ETHERNET_CCC
, "Ethernet-CCC" },
211 { JUNIPER_IFML_VT
, "VPN-Loopback-tunnel" },
212 { JUNIPER_IFML_ETHER_OVER_ATM
, "Ethernet-over-ATM" },
213 { JUNIPER_IFML_ETHER_VPLS_OVER_ATM
, "Ethernet-VPLS-over-ATM" },
214 { JUNIPER_IFML_MONITOR
, "Monitor" },
215 { JUNIPER_IFML_ETHERNET_TCC
, "Ethernet-TCC" },
216 { JUNIPER_IFML_VLAN_TCC
, "VLAN-TCC" },
217 { JUNIPER_IFML_EXTENDED_VLAN_TCC
, "Extended-VLAN-TCC" },
218 { JUNIPER_IFML_CONTROLLER
, "Controller" },
219 { JUNIPER_IFML_ETHERNET_VPLS
, "VPLS" },
220 { JUNIPER_IFML_ETHERNET_VLAN_VPLS
, "VLAN-VPLS" },
221 { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended-VLAN-VPLS" },
222 { JUNIPER_IFML_LT
, "Logical-tunnel" },
223 { JUNIPER_IFML_SERVICES
, "General-Services" },
224 { JUNIPER_IFML_PPPOE
, "PPPoE" },
225 { JUNIPER_IFML_ETHERNET_FLEX
, "Flexible-Ethernet-Services" },
226 { JUNIPER_IFML_FRAMERELAY_FLEX
, "Flexible-FrameRelay" },
227 { JUNIPER_IFML_COLLECTOR
, "Flow-collection" },
228 { JUNIPER_IFML_PICPEER
, "PIC Peer" },
229 { JUNIPER_IFML_DFC
, "Dynamic-Flow-Capture" },
233 #define JUNIPER_IFLE_ATM_SNAP 2
234 #define JUNIPER_IFLE_ATM_NLPID 3
235 #define JUNIPER_IFLE_ATM_VCMUX 4
236 #define JUNIPER_IFLE_ATM_LLC 5
237 #define JUNIPER_IFLE_ATM_PPP_VCMUX 6
238 #define JUNIPER_IFLE_ATM_PPP_LLC 7
239 #define JUNIPER_IFLE_ATM_PPP_FUNI 8
240 #define JUNIPER_IFLE_ATM_CCC 9
241 #define JUNIPER_IFLE_FR_NLPID 10
242 #define JUNIPER_IFLE_FR_SNAP 11
243 #define JUNIPER_IFLE_FR_PPP 12
244 #define JUNIPER_IFLE_FR_CCC 13
245 #define JUNIPER_IFLE_ENET2 14
246 #define JUNIPER_IFLE_IEEE8023_SNAP 15
247 #define JUNIPER_IFLE_IEEE8023_LLC 16
248 #define JUNIPER_IFLE_PPP 17
249 #define JUNIPER_IFLE_CISCOHDLC 18
250 #define JUNIPER_IFLE_PPP_CCC 19
251 #define JUNIPER_IFLE_IPIP_NULL 20
252 #define JUNIPER_IFLE_PIM_NULL 21
253 #define JUNIPER_IFLE_GRE_NULL 22
254 #define JUNIPER_IFLE_GRE_PPP 23
255 #define JUNIPER_IFLE_PIMD_DECAPS 24
256 #define JUNIPER_IFLE_CISCOHDLC_CCC 25
257 #define JUNIPER_IFLE_ATM_CISCO_NLPID 26
258 #define JUNIPER_IFLE_VLAN_CCC 27
259 #define JUNIPER_IFLE_MLPPP 28
260 #define JUNIPER_IFLE_MLFR 29
261 #define JUNIPER_IFLE_LSI_NULL 30
262 #define JUNIPER_IFLE_AGGREGATE_UNUSED 31
263 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC 32
264 #define JUNIPER_IFLE_CRYPTO 33
265 #define JUNIPER_IFLE_GGSN 34
266 #define JUNIPER_IFLE_ATM_TCC 35
267 #define JUNIPER_IFLE_FR_TCC 36
268 #define JUNIPER_IFLE_PPP_TCC 37
269 #define JUNIPER_IFLE_CISCOHDLC_TCC 38
270 #define JUNIPER_IFLE_ETHERNET_CCC 39
271 #define JUNIPER_IFLE_VT 40
272 #define JUNIPER_IFLE_ATM_EOA_LLC 41
273 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC 42
274 #define JUNIPER_IFLE_ATM_SNAP_TCC 43
275 #define JUNIPER_IFLE_MONITOR 44
276 #define JUNIPER_IFLE_ETHERNET_TCC 45
277 #define JUNIPER_IFLE_VLAN_TCC 46
278 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC 47
279 #define JUNIPER_IFLE_MFR 48
280 #define JUNIPER_IFLE_ETHERNET_VPLS 49
281 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50
282 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51
283 #define JUNIPER_IFLE_SERVICES 52
284 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC 53
285 #define JUNIPER_IFLE_FR_PORT_CCC 54
286 #define JUNIPER_IFLE_ATM_MLPPP_LLC 55
287 #define JUNIPER_IFLE_ATM_EOA_CCC 56
288 #define JUNIPER_IFLE_LT_VLAN 57
289 #define JUNIPER_IFLE_COLLECTOR 58
290 #define JUNIPER_IFLE_AGGREGATOR 59
291 #define JUNIPER_IFLE_LAPD 60
292 #define JUNIPER_IFLE_ATM_PPPOE_LLC 61
293 #define JUNIPER_IFLE_ETHERNET_PPPOE 62
294 #define JUNIPER_IFLE_PPPOE 63
295 #define JUNIPER_IFLE_PPP_SUBORDINATE 64
296 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE 65
297 #define JUNIPER_IFLE_DFC 66
298 #define JUNIPER_IFLE_PICPEER 67
300 static const struct tok juniper_ifle_values
[] = {
301 { JUNIPER_IFLE_AGGREGATOR
, "Aggregator" },
302 { JUNIPER_IFLE_ATM_CCC
, "CCC over ATM" },
303 { JUNIPER_IFLE_ATM_CELLRELAY_CCC
, "ATM CCC Cell Relay" },
304 { JUNIPER_IFLE_ATM_CISCO_NLPID
, "CISCO compatible NLPID" },
305 { JUNIPER_IFLE_ATM_EOA_CCC
, "Ethernet over ATM CCC" },
306 { JUNIPER_IFLE_ATM_EOA_LLC
, "Ethernet over ATM LLC" },
307 { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC
, "Ethernet VPLS over ATM LLC" },
308 { JUNIPER_IFLE_ATM_LLC
, "ATM LLC" },
309 { JUNIPER_IFLE_ATM_MLPPP_LLC
, "MLPPP over ATM LLC" },
310 { JUNIPER_IFLE_ATM_NLPID
, "ATM NLPID" },
311 { JUNIPER_IFLE_ATM_PPPOE_LLC
, "PPPoE over ATM LLC" },
312 { JUNIPER_IFLE_ATM_PPP_FUNI
, "PPP over FUNI" },
313 { JUNIPER_IFLE_ATM_PPP_LLC
, "PPP over ATM LLC" },
314 { JUNIPER_IFLE_ATM_PPP_VCMUX
, "PPP over ATM VCMUX" },
315 { JUNIPER_IFLE_ATM_SNAP
, "ATM SNAP" },
316 { JUNIPER_IFLE_ATM_SNAP_TCC
, "ATM SNAP TCC" },
317 { JUNIPER_IFLE_ATM_TCC
, "ATM VCMUX TCC" },
318 { JUNIPER_IFLE_ATM_VCMUX
, "ATM VCMUX" },
319 { JUNIPER_IFLE_CISCOHDLC
, "C-HDLC" },
320 { JUNIPER_IFLE_CISCOHDLC_CCC
, "C-HDLC CCC" },
321 { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE
, "C-HDLC via dialer" },
322 { JUNIPER_IFLE_CISCOHDLC_TCC
, "C-HDLC TCC" },
323 { JUNIPER_IFLE_COLLECTOR
, "Collector" },
324 { JUNIPER_IFLE_CRYPTO
, "Crypto" },
325 { JUNIPER_IFLE_ENET2
, "Ethernet" },
326 { JUNIPER_IFLE_ETHERNET_CCC
, "Ethernet CCC" },
327 { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS
, "Extended VLAN VPLS" },
328 { JUNIPER_IFLE_ETHERNET_PPPOE
, "PPPoE over Ethernet" },
329 { JUNIPER_IFLE_ETHERNET_TCC
, "Ethernet TCC" },
330 { JUNIPER_IFLE_ETHERNET_VLAN_VPLS
, "VLAN VPLS" },
331 { JUNIPER_IFLE_ETHERNET_VPLS
, "VPLS" },
332 { JUNIPER_IFLE_EXTENDED_VLAN_CCC
, "Extended VLAN CCC" },
333 { JUNIPER_IFLE_EXTENDED_VLAN_TCC
, "Extended VLAN TCC" },
334 { JUNIPER_IFLE_FR_CCC
, "FR CCC" },
335 { JUNIPER_IFLE_FR_NLPID
, "FR NLPID" },
336 { JUNIPER_IFLE_FR_PORT_CCC
, "FR CCC" },
337 { JUNIPER_IFLE_FR_PPP
, "FR PPP" },
338 { JUNIPER_IFLE_FR_SNAP
, "FR SNAP" },
339 { JUNIPER_IFLE_FR_TCC
, "FR TCC" },
340 { JUNIPER_IFLE_GGSN
, "GGSN" },
341 { JUNIPER_IFLE_GRE_NULL
, "GRE NULL" },
342 { JUNIPER_IFLE_GRE_PPP
, "PPP over GRE" },
343 { JUNIPER_IFLE_IPIP_NULL
, "IPIP" },
344 { JUNIPER_IFLE_LAPD
, "LAPD" },
345 { JUNIPER_IFLE_LSI_NULL
, "LSI Null" },
346 { JUNIPER_IFLE_LT_VLAN
, "LT VLAN" },
347 { JUNIPER_IFLE_MFR
, "MFR" },
348 { JUNIPER_IFLE_MLFR
, "MLFR" },
349 { JUNIPER_IFLE_MLPPP
, "MLPPP" },
350 { JUNIPER_IFLE_MONITOR
, "Monitor" },
351 { JUNIPER_IFLE_PIMD_DECAPS
, "PIMd" },
352 { JUNIPER_IFLE_PIM_NULL
, "PIM Null" },
353 { JUNIPER_IFLE_PPP
, "PPP" },
354 { JUNIPER_IFLE_PPPOE
, "PPPoE" },
355 { JUNIPER_IFLE_PPP_CCC
, "PPP CCC" },
356 { JUNIPER_IFLE_PPP_SUBORDINATE
, "" },
357 { JUNIPER_IFLE_PPP_TCC
, "PPP TCC" },
358 { JUNIPER_IFLE_SERVICES
, "General Services" },
359 { JUNIPER_IFLE_VLAN_CCC
, "VLAN CCC" },
360 { JUNIPER_IFLE_VLAN_TCC
, "VLAN TCC" },
361 { JUNIPER_IFLE_VT
, "VT" },
365 struct juniper_cookie_table_t
{
366 uint32_t pictype
; /* pic type */
367 uint8_t cookie_len
; /* cookie len */
368 const char *s
; /* pic name */
371 static const struct juniper_cookie_table_t juniper_cookie_table
[] = {
372 #ifdef DLT_JUNIPER_ATM1
373 { DLT_JUNIPER_ATM1
, 4, "ATM1"},
375 #ifdef DLT_JUNIPER_ATM2
376 { DLT_JUNIPER_ATM2
, 8, "ATM2"},
378 #ifdef DLT_JUNIPER_MLPPP
379 { DLT_JUNIPER_MLPPP
, 2, "MLPPP"},
381 #ifdef DLT_JUNIPER_MLFR
382 { DLT_JUNIPER_MLFR
, 2, "MLFR"},
384 #ifdef DLT_JUNIPER_MFR
385 { DLT_JUNIPER_MFR
, 4, "MFR"},
387 #ifdef DLT_JUNIPER_PPPOE
388 { DLT_JUNIPER_PPPOE
, 0, "PPPoE"},
390 #ifdef DLT_JUNIPER_PPPOE_ATM
391 { DLT_JUNIPER_PPPOE_ATM
, 0, "PPPoE ATM"},
393 #ifdef DLT_JUNIPER_GGSN
394 { DLT_JUNIPER_GGSN
, 8, "GGSN"},
396 #ifdef DLT_JUNIPER_MONITOR
397 { DLT_JUNIPER_MONITOR
, 8, "MONITOR"},
399 #ifdef DLT_JUNIPER_SERVICES
400 { DLT_JUNIPER_SERVICES
, 8, "AS"},
402 #ifdef DLT_JUNIPER_ES
403 { DLT_JUNIPER_ES
, 0, "ES"},
408 struct juniper_l2info_t
{
422 #define LS_COOKIE_ID 0x54
423 #define AS_COOKIE_ID 0x47
424 #define LS_MLFR_COOKIE_LEN 4
425 #define ML_MLFR_COOKIE_LEN 2
426 #define LS_MFR_COOKIE_LEN 6
427 #define ATM1_COOKIE_LEN 4
428 #define ATM2_COOKIE_LEN 8
430 #define ATM2_PKT_TYPE_MASK 0x70
431 #define ATM2_GAP_COUNT_MASK 0x3F
433 #define JUNIPER_PROTO_NULL 1
434 #define JUNIPER_PROTO_IPV4 2
435 #define JUNIPER_PROTO_IPV6 6
437 #define MFR_BE_MASK 0xc0
439 static const struct tok juniper_protocol_values
[] = {
440 { JUNIPER_PROTO_NULL
, "Null" },
441 { JUNIPER_PROTO_IPV4
, "IPv4" },
442 { JUNIPER_PROTO_IPV6
, "IPv6" },
446 static int ip_heuristic_guess(netdissect_options
*, register const u_char
*, u_int
);
447 static int juniper_ppp_heuristic_guess(netdissect_options
*, register const u_char
*, u_int
);
448 static int juniper_parse_header(netdissect_options
*, const u_char
*, const struct pcap_pkthdr
*, struct juniper_l2info_t
*);
450 #ifdef DLT_JUNIPER_GGSN
452 juniper_ggsn_print(netdissect_options
*ndo
,
453 const struct pcap_pkthdr
*h
, register const u_char
*p
)
455 struct juniper_l2info_t l2info
;
456 struct juniper_ggsn_header
{
464 const struct juniper_ggsn_header
*gh
;
466 l2info
.pictype
= DLT_JUNIPER_GGSN
;
467 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
468 return l2info
.header_len
;
470 p
+=l2info
.header_len
;
471 gh
= (struct juniper_ggsn_header
*)&l2info
.cookie
;
473 if (ndo
->ndo_eflag
) {
474 ND_PRINT((ndo
, "proto %s (%u), vlan %u: ",
475 tok2str(juniper_protocol_values
,"Unknown",gh
->proto
),
477 EXTRACT_16BITS(&gh
->vlan_id
[0])));
481 case JUNIPER_PROTO_IPV4
:
482 ip_print(ndo
, p
, l2info
.length
);
484 case JUNIPER_PROTO_IPV6
:
485 ip6_print(ndo
, p
, l2info
.length
);
489 ND_PRINT((ndo
, "unknown GGSN proto (%u)", gh
->proto
));
492 return l2info
.header_len
;
496 #ifdef DLT_JUNIPER_ES
498 juniper_es_print(netdissect_options
*ndo
,
499 const struct pcap_pkthdr
*h
, register const u_char
*p
)
501 struct juniper_l2info_t l2info
;
502 struct juniper_ipsec_header
{
510 u_int rewrite_len
,es_type_bundle
;
511 const struct juniper_ipsec_header
*ih
;
513 l2info
.pictype
= DLT_JUNIPER_ES
;
514 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
515 return l2info
.header_len
;
517 p
+=l2info
.header_len
;
518 ih
= (const struct juniper_ipsec_header
*)p
;
521 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
522 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
526 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
527 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
528 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
533 ND_PRINT((ndo
, "ES Invalid type %u, length %u",
536 return l2info
.header_len
;
539 l2info
.length
-=rewrite_len
;
542 if (ndo
->ndo_eflag
) {
543 if (!es_type_bundle
) {
544 ND_PRINT((ndo
, "ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
545 EXTRACT_16BITS(&ih
->sa_index
),
547 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
549 EXTRACT_32BITS(&ih
->spi
),
550 ipaddr_string(ndo
, &ih
->src_ip
),
551 ipaddr_string(ndo
, &ih
->dst_ip
),
554 ND_PRINT((ndo
, "ES SA, index %u, ttl %u type %s (%u), length %u\n",
555 EXTRACT_16BITS(&ih
->sa_index
),
557 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
563 ip_print(ndo
, p
, l2info
.length
);
564 return l2info
.header_len
;
568 #ifdef DLT_JUNIPER_MONITOR
570 juniper_monitor_print(netdissect_options
*ndo
,
571 const struct pcap_pkthdr
*h
, register const u_char
*p
)
573 struct juniper_l2info_t l2info
;
574 struct juniper_monitor_header
{
578 uint8_t service_id
[4];
580 const struct juniper_monitor_header
*mh
;
582 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
583 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
584 return l2info
.header_len
;
586 p
+=l2info
.header_len
;
587 mh
= (const struct juniper_monitor_header
*)p
;
590 ND_PRINT((ndo
, "service-id %u, iif %u, pkt-type %u: ",
591 EXTRACT_32BITS(&mh
->service_id
),
592 EXTRACT_16BITS(&mh
->iif
),
595 /* no proto field - lets guess by first byte of IP header*/
596 ip_heuristic_guess (ndo
, p
, l2info
.length
);
598 return l2info
.header_len
;
602 #ifdef DLT_JUNIPER_SERVICES
604 juniper_services_print(netdissect_options
*ndo
,
605 const struct pcap_pkthdr
*h
, register const u_char
*p
)
607 struct juniper_l2info_t l2info
;
608 struct juniper_services_header
{
611 uint8_t svc_set_id
[2];
614 const struct juniper_services_header
*sh
;
616 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
617 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
618 return l2info
.header_len
;
620 p
+=l2info
.header_len
;
621 sh
= (const struct juniper_services_header
*)p
;
624 ND_PRINT((ndo
, "service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
627 EXTRACT_16BITS(&sh
->svc_set_id
),
628 EXTRACT_24BITS(&sh
->dir_iif
[1])));
630 /* no proto field - lets guess by first byte of IP header*/
631 ip_heuristic_guess (ndo
, p
, l2info
.length
);
633 return l2info
.header_len
;
637 #ifdef DLT_JUNIPER_PPPOE
639 juniper_pppoe_print(netdissect_options
*ndo
,
640 const struct pcap_pkthdr
*h
, register const u_char
*p
)
642 struct juniper_l2info_t l2info
;
644 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
645 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
646 return l2info
.header_len
;
648 p
+=l2info
.header_len
;
649 /* this DLT contains nothing but raw ethernet frames */
650 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
651 return l2info
.header_len
;
655 #ifdef DLT_JUNIPER_ETHER
657 juniper_ether_print(netdissect_options
*ndo
,
658 const struct pcap_pkthdr
*h
, register const u_char
*p
)
660 struct juniper_l2info_t l2info
;
662 l2info
.pictype
= DLT_JUNIPER_ETHER
;
663 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
664 return l2info
.header_len
;
666 p
+=l2info
.header_len
;
667 /* this DLT contains nothing but raw Ethernet frames */
668 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
669 return l2info
.header_len
;
673 #ifdef DLT_JUNIPER_PPP
675 juniper_ppp_print(netdissect_options
*ndo
,
676 const struct pcap_pkthdr
*h
, register const u_char
*p
)
678 struct juniper_l2info_t l2info
;
680 l2info
.pictype
= DLT_JUNIPER_PPP
;
681 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
682 return l2info
.header_len
;
684 p
+=l2info
.header_len
;
685 /* this DLT contains nothing but raw ppp frames */
686 ppp_print(ndo
, p
, l2info
.length
);
687 return l2info
.header_len
;
691 #ifdef DLT_JUNIPER_FRELAY
693 juniper_frelay_print(netdissect_options
*ndo
,
694 const struct pcap_pkthdr
*h
, register const u_char
*p
)
696 struct juniper_l2info_t l2info
;
698 l2info
.pictype
= DLT_JUNIPER_FRELAY
;
699 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
700 return l2info
.header_len
;
702 p
+=l2info
.header_len
;
703 /* this DLT contains nothing but raw frame-relay frames */
704 fr_print(ndo
, p
, l2info
.length
);
705 return l2info
.header_len
;
709 #ifdef DLT_JUNIPER_CHDLC
711 juniper_chdlc_print(netdissect_options
*ndo
,
712 const struct pcap_pkthdr
*h
, register const u_char
*p
)
714 struct juniper_l2info_t l2info
;
716 l2info
.pictype
= DLT_JUNIPER_CHDLC
;
717 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
718 return l2info
.header_len
;
720 p
+=l2info
.header_len
;
721 /* this DLT contains nothing but raw c-hdlc frames */
722 chdlc_print(ndo
, p
, l2info
.length
);
723 return l2info
.header_len
;
727 #ifdef DLT_JUNIPER_PPPOE_ATM
729 juniper_pppoe_atm_print(netdissect_options
*ndo
,
730 const struct pcap_pkthdr
*h
, register const u_char
*p
)
732 struct juniper_l2info_t l2info
;
733 uint16_t extracted_ethertype
;
735 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
736 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
737 return l2info
.header_len
;
739 p
+=l2info
.header_len
;
741 extracted_ethertype
= EXTRACT_16BITS(p
);
742 /* this DLT contains nothing but raw PPPoE frames,
743 * prepended with a type field*/
744 if (ethertype_print(ndo
, extracted_ethertype
,
746 l2info
.length
-ETHERTYPE_LEN
,
747 l2info
.caplen
-ETHERTYPE_LEN
) == 0)
748 /* ether_type not known, probably it wasn't one */
749 ND_PRINT((ndo
, "unknown ethertype 0x%04x", extracted_ethertype
));
751 return l2info
.header_len
;
755 #ifdef DLT_JUNIPER_MLPPP
757 juniper_mlppp_print(netdissect_options
*ndo
,
758 const struct pcap_pkthdr
*h
, register const u_char
*p
)
760 struct juniper_l2info_t l2info
;
762 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
763 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
764 return l2info
.header_len
;
766 /* suppress Bundle-ID if frame was captured on a child-link
767 * best indicator if the cookie looks like a proto */
768 if (ndo
->ndo_eflag
&&
769 EXTRACT_16BITS(&l2info
.cookie
) != PPP_OSI
&&
770 EXTRACT_16BITS(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
771 ND_PRINT((ndo
, "Bundle-ID %u: ", l2info
.bundle
));
773 p
+=l2info
.header_len
;
775 /* first try the LSQ protos */
776 switch(l2info
.proto
) {
777 case JUNIPER_LSQ_L3_PROTO_IPV4
:
778 /* IP traffic going to the RE would not have a cookie
779 * -> this must be incoming IS-IS over PPP
781 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
782 ppp_print(ndo
, p
, l2info
.length
);
784 ip_print(ndo
, p
, l2info
.length
);
785 return l2info
.header_len
;
786 case JUNIPER_LSQ_L3_PROTO_IPV6
:
787 ip6_print(ndo
, p
,l2info
.length
);
788 return l2info
.header_len
;
789 case JUNIPER_LSQ_L3_PROTO_MPLS
:
790 mpls_print(ndo
, p
, l2info
.length
);
791 return l2info
.header_len
;
792 case JUNIPER_LSQ_L3_PROTO_ISO
:
793 isoclns_print(ndo
, p
, l2info
.length
, l2info
.caplen
);
794 return l2info
.header_len
;
799 /* zero length cookie ? */
800 switch (EXTRACT_16BITS(&l2info
.cookie
)) {
802 ppp_print(ndo
, p
- 2, l2info
.length
+ 2);
804 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
806 ppp_print(ndo
, p
, l2info
.length
);
810 return l2info
.header_len
;
815 #ifdef DLT_JUNIPER_MFR
817 juniper_mfr_print(netdissect_options
*ndo
,
818 const struct pcap_pkthdr
*h
, register const u_char
*p
)
820 struct juniper_l2info_t l2info
;
822 l2info
.pictype
= DLT_JUNIPER_MFR
;
823 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
824 return l2info
.header_len
;
826 p
+=l2info
.header_len
;
829 if (l2info
.cookie_len
== 0) {
830 mfr_print(ndo
, p
, l2info
.length
);
831 return l2info
.header_len
;
834 /* first try the LSQ protos */
835 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
836 switch(l2info
.proto
) {
837 case JUNIPER_LSQ_L3_PROTO_IPV4
:
838 ip_print(ndo
, p
, l2info
.length
);
839 return l2info
.header_len
;
840 case JUNIPER_LSQ_L3_PROTO_IPV6
:
841 ip6_print(ndo
, p
,l2info
.length
);
842 return l2info
.header_len
;
843 case JUNIPER_LSQ_L3_PROTO_MPLS
:
844 mpls_print(ndo
, p
, l2info
.length
);
845 return l2info
.header_len
;
846 case JUNIPER_LSQ_L3_PROTO_ISO
:
847 isoclns_print(ndo
, p
, l2info
.length
, l2info
.caplen
);
848 return l2info
.header_len
;
852 return l2info
.header_len
;
855 /* suppress Bundle-ID if frame was captured on a child-link */
856 if (ndo
->ndo_eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1)
857 ND_PRINT((ndo
, "Bundle-ID %u, ", l2info
.bundle
));
858 switch (l2info
.proto
) {
859 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
860 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
862 case (LLC_UI
<<8 | NLPID_Q933
):
863 case (LLC_UI
<<8 | NLPID_IP
):
864 case (LLC_UI
<<8 | NLPID_IP6
):
865 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
866 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1, l2info
.caplen
+ 1);
869 ND_PRINT((ndo
, "unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
));
872 return l2info
.header_len
;
876 #ifdef DLT_JUNIPER_MLFR
878 juniper_mlfr_print(netdissect_options
*ndo
,
879 const struct pcap_pkthdr
*h
, register const u_char
*p
)
881 struct juniper_l2info_t l2info
;
883 l2info
.pictype
= DLT_JUNIPER_MLFR
;
884 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
885 return l2info
.header_len
;
887 p
+=l2info
.header_len
;
889 /* suppress Bundle-ID if frame was captured on a child-link */
890 if (ndo
->ndo_eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1)
891 ND_PRINT((ndo
, "Bundle-ID %u, ", l2info
.bundle
));
892 switch (l2info
.proto
) {
895 isoclns_print(ndo
, p
, l2info
.length
, l2info
.caplen
);
897 case (LLC_UI
<<8 | NLPID_Q933
):
898 case (LLC_UI
<<8 | NLPID_IP
):
899 case (LLC_UI
<<8 | NLPID_IP6
):
900 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
901 isoclns_print(ndo
, p
- 1, l2info
.length
+ 1, l2info
.caplen
+ 1);
904 ND_PRINT((ndo
, "unknown protocol 0x%04x, length %u", l2info
.proto
, l2info
.length
));
907 return l2info
.header_len
;
912 * ATM1 PIC cookie format
914 * +-----+-------------------------+-------------------------------+
915 * |fmtid| vc index | channel ID |
916 * +-----+-------------------------+-------------------------------+
919 #ifdef DLT_JUNIPER_ATM1
921 juniper_atm1_print(netdissect_options
*ndo
,
922 const struct pcap_pkthdr
*h
, register const u_char
*p
)
926 struct juniper_l2info_t l2info
;
928 l2info
.pictype
= DLT_JUNIPER_ATM1
;
929 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
930 return l2info
.header_len
;
932 p
+=l2info
.header_len
;
934 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
935 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
936 return l2info
.header_len
;
939 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
940 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
942 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
944 return l2info
.header_len
;
947 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
948 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
949 /* FIXME check if frame was recognized */
950 return l2info
.header_len
;
953 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
954 return l2info
.header_len
;
956 return l2info
.header_len
;
961 * ATM2 PIC cookie format
963 * +-------------------------------+---------+---+-----+-----------+
964 * | channel ID | reserv |AAL| CCRQ| gap cnt |
965 * +-------------------------------+---------+---+-----+-----------+
968 #ifdef DLT_JUNIPER_ATM2
970 juniper_atm2_print(netdissect_options
*ndo
,
971 const struct pcap_pkthdr
*h
, register const u_char
*p
)
975 struct juniper_l2info_t l2info
;
977 l2info
.pictype
= DLT_JUNIPER_ATM2
;
978 if (juniper_parse_header(ndo
, p
, h
, &l2info
) == 0)
979 return l2info
.header_len
;
981 p
+=l2info
.header_len
;
983 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
984 oam_print(ndo
, p
, l2info
.length
, ATM_OAM_NOHEC
);
985 return l2info
.header_len
;
988 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
989 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
991 llc_hdrlen
= llc_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
993 return l2info
.header_len
;
996 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
997 (EXTRACT_32BITS(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
998 ether_print(ndo
, p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
);
999 return l2info
.header_len
;
1002 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
1003 isoclns_print(ndo
, p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
1004 /* FIXME check if frame was recognized */
1005 return l2info
.header_len
;
1008 if(juniper_ppp_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* PPPoA vcmux encaps ? */
1009 return l2info
.header_len
;
1011 if (ip_heuristic_guess(ndo
, p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
1012 return l2info
.header_len
;
1014 return l2info
.header_len
;
1019 /* try to guess, based on all PPP protos that are supported in
1020 * a juniper router if the payload data is encapsulated using PPP */
1022 juniper_ppp_heuristic_guess(netdissect_options
*ndo
,
1023 register const u_char
*p
, u_int length
)
1025 switch(EXTRACT_16BITS(p
)) {
1028 case PPP_MPLS_UCAST
:
1029 case PPP_MPLS_MCAST
:
1039 ppp_print(ndo
, p
, length
);
1043 return 0; /* did not find a ppp header */
1046 return 1; /* we printed a ppp packet */
1050 ip_heuristic_guess(netdissect_options
*ndo
,
1051 register const u_char
*p
, u_int length
)
1065 ip_print(ndo
, p
, length
);
1083 ip6_print(ndo
, p
, length
);
1086 return 0; /* did not find a ip header */
1089 return 1; /* we printed an v4/v6 packet */
1093 juniper_read_tlv_value(const u_char
*p
, u_int tlv_type
, u_int tlv_len
)
1097 /* TLVs < 128 are little endian encoded */
1098 if (tlv_type
< 128) {
1104 tlv_value
= EXTRACT_LE_16BITS(p
);
1107 tlv_value
= EXTRACT_LE_24BITS(p
);
1110 tlv_value
= EXTRACT_LE_32BITS(p
);
1117 /* TLVs >= 128 are big endian encoded */
1123 tlv_value
= EXTRACT_16BITS(p
);
1126 tlv_value
= EXTRACT_24BITS(p
);
1129 tlv_value
= EXTRACT_32BITS(p
);
1140 juniper_parse_header(netdissect_options
*ndo
,
1141 const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
)
1143 const struct juniper_cookie_table_t
*lp
= juniper_cookie_table
;
1144 u_int idx
, jnx_ext_len
, jnx_header_len
= 0;
1145 uint8_t tlv_type
,tlv_len
;
1146 uint32_t control_word
;
1151 l2info
->header_len
= 0;
1152 l2info
->cookie_len
= 0;
1156 l2info
->length
= h
->len
;
1157 l2info
->caplen
= h
->caplen
;
1158 ND_TCHECK2(p
[0], 4);
1159 l2info
->flags
= p
[3];
1160 l2info
->direction
= p
[3]&JUNIPER_BPF_PKT_IN
;
1162 if (EXTRACT_24BITS(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
1163 ND_PRINT((ndo
, "no magic-number found!"));
1167 if (ndo
->ndo_eflag
) /* print direction */
1168 ND_PRINT((ndo
, "%3s ", tok2str(juniper_direction_values
, "---", l2info
->direction
)));
1170 /* magic number + flags */
1173 if (ndo
->ndo_vflag
> 1)
1174 ND_PRINT((ndo
, "\n\tJuniper PCAP Flags [%s]",
1175 bittok2str(jnx_flag_values
, "none", l2info
->flags
)));
1177 /* extensions present ? - calculate how much bytes to skip */
1178 if ((l2info
->flags
& JUNIPER_BPF_EXT
) == JUNIPER_BPF_EXT
) {
1180 tptr
= p
+jnx_header_len
;
1182 /* ok to read extension length ? */
1183 ND_TCHECK2(tptr
[0], 2);
1184 jnx_ext_len
= EXTRACT_16BITS(tptr
);
1185 jnx_header_len
+= 2;
1188 /* nail up the total length -
1189 * just in case something goes wrong
1190 * with TLV parsing */
1191 jnx_header_len
+= jnx_ext_len
;
1193 if (ndo
->ndo_vflag
> 1)
1194 ND_PRINT((ndo
, ", PCAP Extension(s) total length %u", jnx_ext_len
));
1196 ND_TCHECK2(tptr
[0], jnx_ext_len
);
1197 while (jnx_ext_len
> JUNIPER_EXT_TLV_OVERHEAD
) {
1198 tlv_type
= *(tptr
++);
1199 tlv_len
= *(tptr
++);
1203 if (tlv_type
== 0 || tlv_len
== 0)
1206 if (ndo
->ndo_vflag
> 1)
1207 ND_PRINT((ndo
, "\n\t %s Extension TLV #%u, length %u, value ",
1208 tok2str(jnx_ext_tlv_values
,"Unknown",tlv_type
),
1212 tlv_value
= juniper_read_tlv_value(tptr
, tlv_type
, tlv_len
);
1214 case JUNIPER_EXT_TLV_IFD_NAME
:
1217 case JUNIPER_EXT_TLV_IFD_MEDIATYPE
:
1218 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE
:
1219 if (tlv_value
!= -1) {
1220 if (ndo
->ndo_vflag
> 1)
1221 ND_PRINT((ndo
, "%s (%u)",
1222 tok2str(juniper_ifmt_values
, "Unknown", tlv_value
),
1226 case JUNIPER_EXT_TLV_IFL_ENCAPS
:
1227 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS
:
1228 if (tlv_value
!= -1) {
1229 if (ndo
->ndo_vflag
> 1)
1230 ND_PRINT((ndo
, "%s (%u)",
1231 tok2str(juniper_ifle_values
, "Unknown", tlv_value
),
1235 case JUNIPER_EXT_TLV_IFL_IDX
: /* fall through */
1236 case JUNIPER_EXT_TLV_IFL_UNIT
:
1237 case JUNIPER_EXT_TLV_IFD_IDX
:
1239 if (tlv_value
!= -1) {
1240 if (ndo
->ndo_vflag
> 1)
1241 ND_PRINT((ndo
, "%u", tlv_value
));
1247 jnx_ext_len
-= tlv_len
+JUNIPER_EXT_TLV_OVERHEAD
;
1250 if (ndo
->ndo_vflag
> 1)
1251 ND_PRINT((ndo
, "\n\t-----original packet-----\n\t"));
1254 if ((l2info
->flags
& JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
1256 ND_PRINT((ndo
, "no-L2-hdr, "));
1258 /* there is no link-layer present -
1259 * perform the v4/v6 heuristics
1260 * to figure out what it is
1262 ND_TCHECK2(p
[jnx_header_len
+ 4], 1);
1263 if (ip_heuristic_guess(ndo
, p
+ jnx_header_len
+ 4,
1264 l2info
->length
- (jnx_header_len
+ 4)) == 0)
1265 ND_PRINT((ndo
, "no IP-hdr found!"));
1267 l2info
->header_len
=jnx_header_len
+4;
1268 return 0; /* stop parsing the output further */
1271 l2info
->header_len
= jnx_header_len
;
1272 p
+=l2info
->header_len
;
1273 l2info
->length
-= l2info
->header_len
;
1274 l2info
->caplen
-= l2info
->header_len
;
1276 /* search through the cookie table and copy values matching for our PIC type */
1277 while (lp
->s
!= NULL
) {
1278 if (lp
->pictype
== l2info
->pictype
) {
1280 l2info
->cookie_len
+= lp
->cookie_len
;
1284 l2info
->cookie_type
= LS_COOKIE_ID
;
1285 l2info
->cookie_len
+= 2;
1288 l2info
->cookie_type
= AS_COOKIE_ID
;
1289 l2info
->cookie_len
= 8;
1293 l2info
->bundle
= l2info
->cookie
[0];
1298 #ifdef DLT_JUNIPER_MFR
1299 /* MFR child links don't carry cookies */
1300 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
1301 (p
[0] & MFR_BE_MASK
) == MFR_BE_MASK
) {
1302 l2info
->cookie_len
= 0;
1306 l2info
->header_len
+= l2info
->cookie_len
;
1307 l2info
->length
-= l2info
->cookie_len
;
1308 l2info
->caplen
-= l2info
->cookie_len
;
1311 ND_PRINT((ndo
, "%s-PIC, cookie-len %u",
1313 l2info
->cookie_len
));
1315 if (l2info
->cookie_len
> 0) {
1316 ND_TCHECK2(p
[0], l2info
->cookie_len
);
1318 ND_PRINT((ndo
, ", cookie 0x"));
1319 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
1320 l2info
->cookie
[idx
] = p
[idx
]; /* copy cookie data */
1321 if (ndo
->ndo_eflag
) ND_PRINT((ndo
, "%02x", p
[idx
]));
1325 if (ndo
->ndo_eflag
) ND_PRINT((ndo
, ": ")); /* print demarc b/w L2/L3*/
1328 l2info
->proto
= EXTRACT_16BITS(p
+l2info
->cookie_len
);
1333 p
+=l2info
->cookie_len
;
1335 /* DLT_ specific parsing */
1336 switch(l2info
->pictype
) {
1337 #ifdef DLT_JUNIPER_MLPPP
1338 case DLT_JUNIPER_MLPPP
:
1339 switch (l2info
->cookie_type
) {
1341 l2info
->bundle
= l2info
->cookie
[1];
1344 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1345 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1348 l2info
->bundle
= l2info
->cookie
[0];
1353 #ifdef DLT_JUNIPER_MLFR
1354 case DLT_JUNIPER_MLFR
:
1355 switch (l2info
->cookie_type
) {
1357 l2info
->bundle
= l2info
->cookie
[1];
1358 l2info
->proto
= EXTRACT_16BITS(p
);
1359 l2info
->header_len
+= 2;
1360 l2info
->length
-= 2;
1361 l2info
->caplen
-= 2;
1364 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1365 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1368 l2info
->bundle
= l2info
->cookie
[0];
1369 l2info
->header_len
+= 2;
1370 l2info
->length
-= 2;
1371 l2info
->caplen
-= 2;
1376 #ifdef DLT_JUNIPER_MFR
1377 case DLT_JUNIPER_MFR
:
1378 switch (l2info
->cookie_type
) {
1380 l2info
->bundle
= l2info
->cookie
[1];
1381 l2info
->proto
= EXTRACT_16BITS(p
);
1382 l2info
->header_len
+= 2;
1383 l2info
->length
-= 2;
1384 l2info
->caplen
-= 2;
1387 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
1388 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
1391 l2info
->bundle
= l2info
->cookie
[0];
1396 #ifdef DLT_JUNIPER_ATM2
1397 case DLT_JUNIPER_ATM2
:
1398 ND_TCHECK2(p
[0], 4);
1399 /* ATM cell relay control word present ? */
1400 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
) {
1401 control_word
= EXTRACT_32BITS(p
);
1402 /* some control word heuristics */
1403 switch(control_word
) {
1404 case 0: /* zero control word */
1405 case 0x08000000: /* < JUNOS 7.4 control-word */
1406 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1407 l2info
->header_len
+= 4;
1414 ND_PRINT((ndo
, "control-word 0x%08x ", control_word
));
1418 #ifdef DLT_JUNIPER_GGSN
1419 case DLT_JUNIPER_GGSN
:
1422 #ifdef DLT_JUNIPER_ATM1
1423 case DLT_JUNIPER_ATM1
:
1426 #ifdef DLT_JUNIPER_PPP
1427 case DLT_JUNIPER_PPP
:
1430 #ifdef DLT_JUNIPER_CHDLC
1431 case DLT_JUNIPER_CHDLC
:
1434 #ifdef DLT_JUNIPER_ETHER
1435 case DLT_JUNIPER_ETHER
:
1438 #ifdef DLT_JUNIPER_FRELAY
1439 case DLT_JUNIPER_FRELAY
:
1444 ND_PRINT((ndo
, "Unknown Juniper DLT_ type %u: ", l2info
->pictype
));
1448 if (ndo
->ndo_eflag
> 1)
1449 ND_PRINT((ndo
, "hlen %u, proto 0x%04x, ", l2info
->header_len
, l2info
->proto
));
1451 return 1; /* everything went ok so far. continue parsing */
1453 ND_PRINT((ndo
, "[|juniper_hdr], length %u", h
->len
));
1460 * c-style: whitesmith