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 *, register const u_char *, u_int);
449 static int juniper_ppp_heuristic_guess(netdissect_options *, register 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_print(netdissect_options *ndo,
455 const struct pcap_pkthdr *h, register const u_char *p)
457 struct juniper_l2info_t l2info;
458 struct juniper_ggsn_header {
466 const struct juniper_ggsn_header *gh;
468 l2info.pictype = DLT_JUNIPER_GGSN;
469 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
470 return l2info.header_len;
472 p+=l2info.header_len;
473 gh = (struct juniper_ggsn_header *)&l2info.cookie;
476 if (ndo->ndo_eflag) {
477 ND_PRINT((ndo, "proto %s (%u), vlan %u: ",
478 tok2str(juniper_protocol_values,"Unknown",gh->proto),
480 EXTRACT_16BITS(&gh->vlan_id[0])));
484 case JUNIPER_PROTO_IPV4:
485 ip_print(ndo, p, l2info.length);
487 case JUNIPER_PROTO_IPV6:
488 ip6_print(ndo, p, l2info.length);
492 ND_PRINT((ndo, "unknown GGSN proto (%u)", gh->proto));
495 return l2info.header_len;
498 ND_PRINT((ndo, "[|juniper_services]"));
499 return l2info.header_len;
503 #ifdef DLT_JUNIPER_ES
505 juniper_es_print(netdissect_options *ndo,
506 const struct pcap_pkthdr *h, register const u_char *p)
508 struct juniper_l2info_t l2info;
509 struct juniper_ipsec_header {
517 u_int rewrite_len,es_type_bundle;
518 const struct juniper_ipsec_header *ih;
520 l2info.pictype = DLT_JUNIPER_ES;
521 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
522 return l2info.header_len;
524 p+=l2info.header_len;
525 ih = (const struct juniper_ipsec_header *)p;
529 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE:
530 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE:
534 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE:
535 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE:
536 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE:
541 ND_PRINT((ndo, "ES Invalid type %u, length %u",
544 return l2info.header_len;
547 l2info.length-=rewrite_len;
550 if (ndo->ndo_eflag) {
551 if (!es_type_bundle) {
552 ND_PRINT((ndo, "ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
553 EXTRACT_16BITS(&ih->sa_index),
555 tok2str(juniper_ipsec_type_values,"Unknown",ih->type),
557 EXTRACT_32BITS(&ih->spi),
558 ipaddr_string(ndo, &ih->src_ip),
559 ipaddr_string(ndo, &ih->dst_ip),
562 ND_PRINT((ndo, "ES SA, index %u, ttl %u type %s (%u), length %u\n",
563 EXTRACT_16BITS(&ih->sa_index),
565 tok2str(juniper_ipsec_type_values,"Unknown",ih->type),
571 ip_print(ndo, p, l2info.length);
572 return l2info.header_len;
575 ND_PRINT((ndo, "[|juniper_services]"));
576 return l2info.header_len;
580 #ifdef DLT_JUNIPER_MONITOR
582 juniper_monitor_print(netdissect_options *ndo,
583 const struct pcap_pkthdr *h, register const u_char *p)
585 struct juniper_l2info_t l2info;
586 struct juniper_monitor_header {
590 uint8_t service_id[4];
592 const struct juniper_monitor_header *mh;
594 l2info.pictype = DLT_JUNIPER_MONITOR;
595 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
596 return l2info.header_len;
598 p+=l2info.header_len;
599 mh = (const struct juniper_monitor_header *)p;
603 ND_PRINT((ndo, "service-id %u, iif %u, pkt-type %u: ",
604 EXTRACT_32BITS(&mh->service_id),
605 EXTRACT_16BITS(&mh->iif),
608 /* no proto field - lets guess by first byte of IP header*/
609 ip_heuristic_guess (ndo, p, l2info.length);
611 return l2info.header_len;
614 ND_PRINT((ndo, "[|juniper_services]"));
615 return l2info.header_len;
619 #ifdef DLT_JUNIPER_SERVICES
621 juniper_services_print(netdissect_options *ndo,
622 const struct pcap_pkthdr *h, register const u_char *p)
624 struct juniper_l2info_t l2info;
625 struct juniper_services_header {
628 uint8_t svc_set_id[2];
631 const struct juniper_services_header *sh;
633 l2info.pictype = DLT_JUNIPER_SERVICES;
634 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
635 return l2info.header_len;
637 p+=l2info.header_len;
638 sh = (const struct juniper_services_header *)p;
642 ND_PRINT((ndo, "service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
645 EXTRACT_16BITS(&sh->svc_set_id),
646 EXTRACT_24BITS(&sh->dir_iif[1])));
648 /* no proto field - lets guess by first byte of IP header*/
649 ip_heuristic_guess (ndo, p, l2info.length);
651 return l2info.header_len;
654 ND_PRINT((ndo, "[|juniper_services]"));
655 return l2info.header_len;
659 #ifdef DLT_JUNIPER_PPPOE
661 juniper_pppoe_print(netdissect_options *ndo,
662 const struct pcap_pkthdr *h, register const u_char *p)
664 struct juniper_l2info_t l2info;
666 l2info.pictype = DLT_JUNIPER_PPPOE;
667 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
668 return l2info.header_len;
670 p+=l2info.header_len;
671 /* this DLT contains nothing but raw ethernet frames */
672 ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
673 return l2info.header_len;
677 #ifdef DLT_JUNIPER_ETHER
679 juniper_ether_print(netdissect_options *ndo,
680 const struct pcap_pkthdr *h, register const u_char *p)
682 struct juniper_l2info_t l2info;
684 l2info.pictype = DLT_JUNIPER_ETHER;
685 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
686 return l2info.header_len;
688 p+=l2info.header_len;
689 /* this DLT contains nothing but raw Ethernet frames */
690 ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
691 return l2info.header_len;
695 #ifdef DLT_JUNIPER_PPP
697 juniper_ppp_print(netdissect_options *ndo,
698 const struct pcap_pkthdr *h, register const u_char *p)
700 struct juniper_l2info_t l2info;
702 l2info.pictype = DLT_JUNIPER_PPP;
703 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
704 return l2info.header_len;
706 p+=l2info.header_len;
707 /* this DLT contains nothing but raw ppp frames */
708 ppp_print(ndo, p, l2info.length);
709 return l2info.header_len;
713 #ifdef DLT_JUNIPER_FRELAY
715 juniper_frelay_print(netdissect_options *ndo,
716 const struct pcap_pkthdr *h, register const u_char *p)
718 struct juniper_l2info_t l2info;
720 l2info.pictype = DLT_JUNIPER_FRELAY;
721 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
722 return l2info.header_len;
724 p+=l2info.header_len;
725 /* this DLT contains nothing but raw frame-relay frames */
726 fr_print(ndo, p, l2info.length);
727 return l2info.header_len;
731 #ifdef DLT_JUNIPER_CHDLC
733 juniper_chdlc_print(netdissect_options *ndo,
734 const struct pcap_pkthdr *h, register const u_char *p)
736 struct juniper_l2info_t l2info;
738 l2info.pictype = DLT_JUNIPER_CHDLC;
739 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
740 return l2info.header_len;
742 p+=l2info.header_len;
743 /* this DLT contains nothing but raw c-hdlc frames */
744 chdlc_print(ndo, p, l2info.length);
745 return l2info.header_len;
749 #ifdef DLT_JUNIPER_PPPOE_ATM
751 juniper_pppoe_atm_print(netdissect_options *ndo,
752 const struct pcap_pkthdr *h, register const u_char *p)
754 struct juniper_l2info_t l2info;
755 uint16_t extracted_ethertype;
757 l2info.pictype = DLT_JUNIPER_PPPOE_ATM;
758 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
759 return l2info.header_len;
761 p+=l2info.header_len;
764 extracted_ethertype = EXTRACT_16BITS(p);
765 /* this DLT contains nothing but raw PPPoE frames,
766 * prepended with a type field*/
767 if (ethertype_print(ndo, extracted_ethertype,
769 l2info.length-ETHERTYPE_LEN,
770 l2info.caplen-ETHERTYPE_LEN,
772 /* ether_type not known, probably it wasn't one */
773 ND_PRINT((ndo, "unknown ethertype 0x%04x", extracted_ethertype));
775 return l2info.header_len;
778 ND_PRINT((ndo, "[|juniper_pppoe_atm]"));
779 return l2info.header_len;
783 #ifdef DLT_JUNIPER_MLPPP
785 juniper_mlppp_print(netdissect_options *ndo,
786 const struct pcap_pkthdr *h, register const u_char *p)
788 struct juniper_l2info_t l2info;
790 l2info.pictype = DLT_JUNIPER_MLPPP;
791 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
792 return l2info.header_len;
794 /* suppress Bundle-ID if frame was captured on a child-link
795 * best indicator if the cookie looks like a proto */
796 if (ndo->ndo_eflag &&
797 EXTRACT_16BITS(&l2info.cookie) != PPP_OSI &&
798 EXTRACT_16BITS(&l2info.cookie) != (PPP_ADDRESS << 8 | PPP_CONTROL))
799 ND_PRINT((ndo, "Bundle-ID %u: ", l2info.bundle));
801 p+=l2info.header_len;
803 /* first try the LSQ protos */
804 switch(l2info.proto) {
805 case JUNIPER_LSQ_L3_PROTO_IPV4:
806 /* IP traffic going to the RE would not have a cookie
807 * -> this must be incoming IS-IS over PPP
809 if (l2info.cookie[4] == (JUNIPER_LSQ_COOKIE_RE|JUNIPER_LSQ_COOKIE_DIR))
810 ppp_print(ndo, p, l2info.length);
812 ip_print(ndo, p, l2info.length);
813 return l2info.header_len;
814 case JUNIPER_LSQ_L3_PROTO_IPV6:
815 ip6_print(ndo, p,l2info.length);
816 return l2info.header_len;
817 case JUNIPER_LSQ_L3_PROTO_MPLS:
818 mpls_print(ndo, p, l2info.length);
819 return l2info.header_len;
820 case JUNIPER_LSQ_L3_PROTO_ISO:
821 isoclns_print(ndo, p, l2info.length);
822 return l2info.header_len;
827 /* zero length cookie ? */
828 switch (EXTRACT_16BITS(&l2info.cookie)) {
830 ppp_print(ndo, p - 2, l2info.length + 2);
832 case (PPP_ADDRESS << 8 | PPP_CONTROL): /* fall through */
834 ppp_print(ndo, p, l2info.length);
838 return l2info.header_len;
843 #ifdef DLT_JUNIPER_MFR
845 juniper_mfr_print(netdissect_options *ndo,
846 const struct pcap_pkthdr *h, register const u_char *p)
848 struct juniper_l2info_t l2info;
850 memset(&l2info, 0, sizeof(l2info));
851 l2info.pictype = DLT_JUNIPER_MFR;
852 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
853 return l2info.header_len;
855 p+=l2info.header_len;
858 if (l2info.cookie_len == 0) {
859 mfr_print(ndo, p, l2info.length);
860 return l2info.header_len;
863 /* first try the LSQ protos */
864 if (l2info.cookie_len == AS_PIC_COOKIE_LEN) {
865 switch(l2info.proto) {
866 case JUNIPER_LSQ_L3_PROTO_IPV4:
867 ip_print(ndo, p, l2info.length);
868 return l2info.header_len;
869 case JUNIPER_LSQ_L3_PROTO_IPV6:
870 ip6_print(ndo, p,l2info.length);
871 return l2info.header_len;
872 case JUNIPER_LSQ_L3_PROTO_MPLS:
873 mpls_print(ndo, p, l2info.length);
874 return l2info.header_len;
875 case JUNIPER_LSQ_L3_PROTO_ISO:
876 isoclns_print(ndo, p, l2info.length);
877 return l2info.header_len;
881 return l2info.header_len;
884 /* suppress Bundle-ID if frame was captured on a child-link */
885 if (ndo->ndo_eflag && EXTRACT_32BITS(l2info.cookie) != 1)
886 ND_PRINT((ndo, "Bundle-ID %u, ", l2info.bundle));
887 switch (l2info.proto) {
888 case (LLCSAP_ISONS<<8 | LLCSAP_ISONS):
889 isoclns_print(ndo, p + 1, l2info.length - 1);
891 case (LLC_UI<<8 | NLPID_Q933):
892 case (LLC_UI<<8 | NLPID_IP):
893 case (LLC_UI<<8 | NLPID_IP6):
894 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
895 isoclns_print(ndo, p - 1, l2info.length + 1);
898 ND_PRINT((ndo, "unknown protocol 0x%04x, length %u", l2info.proto, l2info.length));
901 return l2info.header_len;
905 #ifdef DLT_JUNIPER_MLFR
907 juniper_mlfr_print(netdissect_options *ndo,
908 const struct pcap_pkthdr *h, register const u_char *p)
910 struct juniper_l2info_t l2info;
912 l2info.pictype = DLT_JUNIPER_MLFR;
913 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
914 return l2info.header_len;
916 p+=l2info.header_len;
918 /* suppress Bundle-ID if frame was captured on a child-link */
919 if (ndo->ndo_eflag && EXTRACT_32BITS(l2info.cookie) != 1)
920 ND_PRINT((ndo, "Bundle-ID %u, ", l2info.bundle));
921 switch (l2info.proto) {
924 isoclns_print(ndo, p, l2info.length);
926 case (LLC_UI<<8 | NLPID_Q933):
927 case (LLC_UI<<8 | NLPID_IP):
928 case (LLC_UI<<8 | NLPID_IP6):
929 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
930 isoclns_print(ndo, p - 1, l2info.length + 1);
933 ND_PRINT((ndo, "unknown protocol 0x%04x, length %u", l2info.proto, l2info.length));
936 return l2info.header_len;
941 * ATM1 PIC cookie format
943 * +-----+-------------------------+-------------------------------+
944 * |fmtid| vc index | channel ID |
945 * +-----+-------------------------+-------------------------------+
948 #ifdef DLT_JUNIPER_ATM1
950 juniper_atm1_print(netdissect_options *ndo,
951 const struct pcap_pkthdr *h, register const u_char *p)
955 struct juniper_l2info_t l2info;
957 l2info.pictype = DLT_JUNIPER_ATM1;
958 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
959 return l2info.header_len;
961 p+=l2info.header_len;
963 if (l2info.cookie[0] == 0x80) { /* OAM cell ? */
964 oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC);
965 return l2info.header_len;
969 if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */
970 EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */
972 llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
974 return l2info.header_len;
977 if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */
978 isoclns_print(ndo, p + 1, l2info.length - 1);
979 /* FIXME check if frame was recognized */
980 return l2info.header_len;
983 if (ip_heuristic_guess(ndo, p, l2info.length) != 0) /* last try - vcmux encaps ? */
984 return l2info.header_len;
986 return l2info.header_len;
989 ND_PRINT((ndo, "[|juniper_atm1]"));
990 return l2info.header_len;
995 * ATM2 PIC cookie format
997 * +-------------------------------+---------+---+-----+-----------+
998 * | channel ID | reserv |AAL| CCRQ| gap cnt |
999 * +-------------------------------+---------+---+-----+-----------+
1002 #ifdef DLT_JUNIPER_ATM2
1004 juniper_atm2_print(netdissect_options *ndo,
1005 const struct pcap_pkthdr *h, register const u_char *p)
1009 struct juniper_l2info_t l2info;
1011 l2info.pictype = DLT_JUNIPER_ATM2;
1012 if (juniper_parse_header(ndo, p, h, &l2info) == 0)
1013 return l2info.header_len;
1015 p+=l2info.header_len;
1017 if (l2info.cookie[7] & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */
1018 oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC);
1019 return l2info.header_len;
1022 ND_TCHECK2(p[0], 3);
1023 if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */
1024 EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */
1026 llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
1028 return l2info.header_len;
1031 if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */
1032 (EXTRACT_32BITS(l2info.cookie) & ATM2_GAP_COUNT_MASK)) {
1033 ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
1034 return l2info.header_len;
1037 if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */
1038 isoclns_print(ndo, p + 1, l2info.length - 1);
1039 /* FIXME check if frame was recognized */
1040 return l2info.header_len;
1043 if(juniper_ppp_heuristic_guess(ndo, p, l2info.length) != 0) /* PPPoA vcmux encaps ? */
1044 return l2info.header_len;
1046 if (ip_heuristic_guess(ndo, p, l2info.length) != 0) /* last try - vcmux encaps ? */
1047 return l2info.header_len;
1049 return l2info.header_len;
1052 ND_PRINT((ndo, "[|juniper_atm2]"));
1053 return l2info.header_len;
1058 /* try to guess, based on all PPP protos that are supported in
1059 * a juniper router if the payload data is encapsulated using PPP */
1061 juniper_ppp_heuristic_guess(netdissect_options *ndo,
1062 register const u_char *p, u_int length)
1064 switch(EXTRACT_16BITS(p)) {
1067 case PPP_MPLS_UCAST :
1068 case PPP_MPLS_MCAST :
1078 ppp_print(ndo, p, length);
1082 return 0; /* did not find a ppp header */
1085 return 1; /* we printed a ppp packet */
1089 ip_heuristic_guess(netdissect_options *ndo,
1090 register const u_char *p, u_int length)
1104 ip_print(ndo, p, length);
1122 ip6_print(ndo, p, length);
1125 return 0; /* did not find a ip header */
1128 return 1; /* we printed an v4/v6 packet */
1132 juniper_read_tlv_value(const u_char *p, u_int tlv_type, u_int tlv_len)
1136 /* TLVs < 128 are little endian encoded */
1137 if (tlv_type < 128) {
1143 tlv_value = EXTRACT_LE_16BITS(p);
1146 tlv_value = EXTRACT_LE_24BITS(p);
1149 tlv_value = EXTRACT_LE_32BITS(p);
1156 /* TLVs >= 128 are big endian encoded */
1162 tlv_value = EXTRACT_16BITS(p);
1165 tlv_value = EXTRACT_24BITS(p);
1168 tlv_value = EXTRACT_32BITS(p);
1179 juniper_parse_header(netdissect_options *ndo,
1180 const u_char *p, const struct pcap_pkthdr *h, struct juniper_l2info_t *l2info)
1182 const struct juniper_cookie_table_t *lp = juniper_cookie_table;
1183 u_int idx, jnx_ext_len, jnx_header_len = 0;
1184 uint8_t tlv_type,tlv_len;
1185 uint32_t control_word;
1190 l2info->header_len = 0;
1191 l2info->cookie_len = 0;
1195 l2info->length = h->len;
1196 l2info->caplen = h->caplen;
1197 ND_TCHECK2(p[0], 4);
1198 l2info->flags = p[3];
1199 l2info->direction = p[3]&JUNIPER_BPF_PKT_IN;
1201 if (EXTRACT_24BITS(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */
1202 ND_PRINT((ndo, "no magic-number found!"));
1206 if (ndo->ndo_eflag) /* print direction */
1207 ND_PRINT((ndo, "%3s ", tok2str(juniper_direction_values, "---", l2info->direction)));
1209 /* magic number + flags */
1212 if (ndo->ndo_vflag > 1)
1213 ND_PRINT((ndo, "\n\tJuniper PCAP Flags [%s]",
1214 bittok2str(jnx_flag_values, "none", l2info->flags)));
1216 /* extensions present ? - calculate how much bytes to skip */
1217 if ((l2info->flags & JUNIPER_BPF_EXT ) == JUNIPER_BPF_EXT ) {
1219 tptr = p+jnx_header_len;
1221 /* ok to read extension length ? */
1222 ND_TCHECK2(tptr[0], 2);
1223 jnx_ext_len = EXTRACT_16BITS(tptr);
1224 jnx_header_len += 2;
1227 /* nail up the total length -
1228 * just in case something goes wrong
1229 * with TLV parsing */
1230 jnx_header_len += jnx_ext_len;
1232 if (ndo->ndo_vflag > 1)
1233 ND_PRINT((ndo, ", PCAP Extension(s) total length %u", jnx_ext_len));
1235 ND_TCHECK2(tptr[0], jnx_ext_len);
1236 while (jnx_ext_len > JUNIPER_EXT_TLV_OVERHEAD) {
1237 tlv_type = *(tptr++);
1238 tlv_len = *(tptr++);
1242 if (tlv_type == 0 || tlv_len == 0)
1244 if (tlv_len+JUNIPER_EXT_TLV_OVERHEAD > jnx_ext_len)
1247 if (ndo->ndo_vflag > 1)
1248 ND_PRINT((ndo, "\n\t %s Extension TLV #%u, length %u, value ",
1249 tok2str(jnx_ext_tlv_values,"Unknown",tlv_type),
1253 tlv_value = juniper_read_tlv_value(tptr, tlv_type, tlv_len);
1255 case JUNIPER_EXT_TLV_IFD_NAME:
1258 case JUNIPER_EXT_TLV_IFD_MEDIATYPE:
1259 case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE:
1260 if (tlv_value != -1) {
1261 if (ndo->ndo_vflag > 1)
1262 ND_PRINT((ndo, "%s (%u)",
1263 tok2str(juniper_ifmt_values, "Unknown", tlv_value),
1267 case JUNIPER_EXT_TLV_IFL_ENCAPS:
1268 case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS:
1269 if (tlv_value != -1) {
1270 if (ndo->ndo_vflag > 1)
1271 ND_PRINT((ndo, "%s (%u)",
1272 tok2str(juniper_ifle_values, "Unknown", tlv_value),
1276 case JUNIPER_EXT_TLV_IFL_IDX: /* fall through */
1277 case JUNIPER_EXT_TLV_IFL_UNIT:
1278 case JUNIPER_EXT_TLV_IFD_IDX:
1280 if (tlv_value != -1) {
1281 if (ndo->ndo_vflag > 1)
1282 ND_PRINT((ndo, "%u", tlv_value));
1288 jnx_ext_len -= tlv_len+JUNIPER_EXT_TLV_OVERHEAD;
1291 if (ndo->ndo_vflag > 1)
1292 ND_PRINT((ndo, "\n\t-----original packet-----\n\t"));
1295 if ((l2info->flags & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) {
1297 ND_PRINT((ndo, "no-L2-hdr, "));
1299 /* there is no link-layer present -
1300 * perform the v4/v6 heuristics
1301 * to figure out what it is
1303 ND_TCHECK2(p[jnx_header_len + 4], 1);
1304 if (ip_heuristic_guess(ndo, p + jnx_header_len + 4,
1305 l2info->length - (jnx_header_len + 4)) == 0)
1306 ND_PRINT((ndo, "no IP-hdr found!"));
1308 l2info->header_len=jnx_header_len+4;
1309 return 0; /* stop parsing the output further */
1312 l2info->header_len = jnx_header_len;
1313 p+=l2info->header_len;
1314 l2info->length -= l2info->header_len;
1315 l2info->caplen -= l2info->header_len;
1317 /* search through the cookie table and copy values matching for our PIC type */
1319 while (lp->s != NULL) {
1320 if (lp->pictype == l2info->pictype) {
1322 l2info->cookie_len += lp->cookie_len;
1326 l2info->cookie_type = LS_COOKIE_ID;
1327 l2info->cookie_len += 2;
1330 l2info->cookie_type = AS_COOKIE_ID;
1331 l2info->cookie_len = 8;
1335 l2info->bundle = l2info->cookie[0];
1340 #ifdef DLT_JUNIPER_MFR
1341 /* MFR child links don't carry cookies */
1342 if (l2info->pictype == DLT_JUNIPER_MFR &&
1343 (p[0] & MFR_BE_MASK) == MFR_BE_MASK) {
1344 l2info->cookie_len = 0;
1348 l2info->header_len += l2info->cookie_len;
1349 l2info->length -= l2info->cookie_len;
1350 l2info->caplen -= l2info->cookie_len;
1353 ND_PRINT((ndo, "%s-PIC, cookie-len %u",
1355 l2info->cookie_len));
1357 if (l2info->cookie_len > 8) {
1358 ND_PRINT((ndo, " (invalid)"));
1362 if (l2info->cookie_len > 0) {
1363 ND_TCHECK2(p[0], l2info->cookie_len);
1365 ND_PRINT((ndo, ", cookie 0x"));
1366 for (idx = 0; idx < l2info->cookie_len; idx++) {
1367 l2info->cookie[idx] = p[idx]; /* copy cookie data */
1368 if (ndo->ndo_eflag) ND_PRINT((ndo, "%02x", p[idx]));
1372 if (ndo->ndo_eflag) ND_PRINT((ndo, ": ")); /* print demarc b/w L2/L3*/
1375 ND_TCHECK_16BITS(p+l2info->cookie_len);
1376 l2info->proto = EXTRACT_16BITS(p+l2info->cookie_len);
1381 p+=l2info->cookie_len;
1383 /* DLT_ specific parsing */
1384 switch(l2info->pictype) {
1385 #ifdef DLT_JUNIPER_MLPPP
1386 case DLT_JUNIPER_MLPPP:
1387 switch (l2info->cookie_type) {
1389 l2info->bundle = l2info->cookie[1];
1392 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
1393 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1396 l2info->bundle = l2info->cookie[0];
1401 #ifdef DLT_JUNIPER_MLFR
1402 case DLT_JUNIPER_MLFR:
1403 switch (l2info->cookie_type) {
1405 ND_TCHECK2(p[0], 2);
1406 l2info->bundle = l2info->cookie[1];
1407 l2info->proto = EXTRACT_16BITS(p);
1408 l2info->header_len += 2;
1409 l2info->length -= 2;
1410 l2info->caplen -= 2;
1413 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
1414 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1417 l2info->bundle = l2info->cookie[0];
1418 l2info->header_len += 2;
1419 l2info->length -= 2;
1420 l2info->caplen -= 2;
1425 #ifdef DLT_JUNIPER_MFR
1426 case DLT_JUNIPER_MFR:
1427 switch (l2info->cookie_type) {
1429 ND_TCHECK2(p[0], 2);
1430 l2info->bundle = l2info->cookie[1];
1431 l2info->proto = EXTRACT_16BITS(p);
1432 l2info->header_len += 2;
1433 l2info->length -= 2;
1434 l2info->caplen -= 2;
1437 l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff;
1438 l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1441 l2info->bundle = l2info->cookie[0];
1446 #ifdef DLT_JUNIPER_ATM2
1447 case DLT_JUNIPER_ATM2:
1448 ND_TCHECK2(p[0], 4);
1449 /* ATM cell relay control word present ? */
1450 if (l2info->cookie[7] & ATM2_PKT_TYPE_MASK) {
1451 control_word = EXTRACT_32BITS(p);
1452 /* some control word heuristics */
1453 switch(control_word) {
1454 case 0: /* zero control word */
1455 case 0x08000000: /* < JUNOS 7.4 control-word */
1456 case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1457 l2info->header_len += 4;
1464 ND_PRINT((ndo, "control-word 0x%08x ", control_word));
1468 #ifdef DLT_JUNIPER_GGSN
1469 case DLT_JUNIPER_GGSN:
1472 #ifdef DLT_JUNIPER_ATM1
1473 case DLT_JUNIPER_ATM1:
1476 #ifdef DLT_JUNIPER_PPP
1477 case DLT_JUNIPER_PPP:
1480 #ifdef DLT_JUNIPER_CHDLC
1481 case DLT_JUNIPER_CHDLC:
1484 #ifdef DLT_JUNIPER_ETHER
1485 case DLT_JUNIPER_ETHER:
1488 #ifdef DLT_JUNIPER_FRELAY
1489 case DLT_JUNIPER_FRELAY:
1494 ND_PRINT((ndo, "Unknown Juniper DLT_ type %u: ", l2info->pictype));
1498 if (ndo->ndo_eflag > 1)
1499 ND_PRINT((ndo, "hlen %u, proto 0x%04x, ", l2info->header_len, l2info->proto));
1501 return 1; /* everything went ok so far. continue parsing */
1503 ND_PRINT((ndo, "[|juniper_hdr], length %u", h->len));
1510 * c-style: whitesmith