• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*     NetBSD: print-juniper.c,v 1.2 2007/07/24 11:53:45 drochner Exp        */
2 
3 /*
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.
14  *
15  * Original code by Hannes Gredler (hannes@gredler.at)
16  */
17 
18 /* \summary: DLT_JUNIPER_* printers */
19 
20 #ifndef lint
21 #else
22 __RCSID("NetBSD: print-juniper.c,v 1.3 2007/07/25 06:31:32 dogcow Exp ");
23 #endif
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 
29 #include "netdissect-stdinc.h"
30 
31 #include <string.h>
32 
33 #define ND_LONGJMP_FROM_TCHECK
34 #include "netdissect.h"
35 #include "addrtoname.h"
36 #include "extract.h"
37 #include "ppp.h"
38 #include "llc.h"
39 #include "nlpid.h"
40 #include "ethertype.h"
41 #include "atm.h"
42 
43 /*
44  * If none of the Juniper DLT_s are defined, there's nothing to do.
45  */
46 #if defined(DLT_JUNIPER_GGSN) || defined(DLT_JUNIPER_ES) || \
47     defined(DLT_JUNIPER_MONITOR) || defined(DLT_JUNIPER_SERVICES) || \
48     defined(DLT_JUNIPER_PPPOE) || defined(DLT_JUNIPER_ETHER) || \
49     defined(DLT_JUNIPER_PPP) || defined(DLT_JUNIPER_FRELAY) || \
50     defined(DLT_JUNIPER_CHDLC) || defined(DLT_JUNIPER_PPPOE_ATM) || \
51     defined(DLT_JUNIPER_MLPPP) || defined(DLT_JUNIPER_MFR) || \
52     defined(DLT_JUNIPER_MLFR) || defined(DLT_JUNIPER_ATM1) || \
53     defined(DLT_JUNIPER_ATM2)
54 #define JUNIPER_BPF_OUT           0       /* Outgoing packet */
55 #define JUNIPER_BPF_IN            1       /* Incoming packet */
56 #define JUNIPER_BPF_PKT_IN        0x1     /* Incoming packet */
57 #define JUNIPER_BPF_NO_L2         0x2     /* L2 header stripped */
58 #define JUNIPER_BPF_IIF           0x4     /* IIF is valid */
59 #define JUNIPER_BPF_FILTER        0x40    /* BPF filtering is supported */
60 #define JUNIPER_BPF_EXT           0x80    /* extensions present */
61 #define JUNIPER_MGC_NUMBER        0x4d4743 /* = "MGC" */
62 
63 #define JUNIPER_LSQ_COOKIE_RE         (1 << 3)
64 #define JUNIPER_LSQ_COOKIE_DIR        (1 << 2)
65 #define JUNIPER_LSQ_L3_PROTO_SHIFT     4
66 #define JUNIPER_LSQ_L3_PROTO_MASK     (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT)
67 #define JUNIPER_LSQ_L3_PROTO_IPV4     (0 << JUNIPER_LSQ_L3_PROTO_SHIFT)
68 #define JUNIPER_LSQ_L3_PROTO_IPV6     (1 << JUNIPER_LSQ_L3_PROTO_SHIFT)
69 #define JUNIPER_LSQ_L3_PROTO_MPLS     (2 << JUNIPER_LSQ_L3_PROTO_SHIFT)
70 #define JUNIPER_LSQ_L3_PROTO_ISO      (3 << JUNIPER_LSQ_L3_PROTO_SHIFT)
71 #define AS_PIC_COOKIE_LEN 8
72 
73 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1
74 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2
75 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3
76 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4
77 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5
78 
79 #ifdef DLT_JUNIPER_ES
80 static const struct tok juniper_ipsec_type_values[] = {
81     { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE, "ESP ENCR-AUTH" },
82     { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE, "ESP ENCR-AH AUTH" },
83     { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE, "ESP AUTH" },
84     { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE, "AH AUTH" },
85     { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE, "ESP ENCR" },
86     { 0, NULL}
87 };
88 #endif
89 
90 static const struct tok juniper_direction_values[] = {
91     { JUNIPER_BPF_IN,  "In"},
92     { JUNIPER_BPF_OUT, "Out"},
93     { 0, NULL}
94 };
95 
96 /* codepoints for encoding extensions to a .pcap file */
97 enum {
98     JUNIPER_EXT_TLV_IFD_IDX = 1,
99     JUNIPER_EXT_TLV_IFD_NAME = 2,
100     JUNIPER_EXT_TLV_IFD_MEDIATYPE = 3,
101     JUNIPER_EXT_TLV_IFL_IDX = 4,
102     JUNIPER_EXT_TLV_IFL_UNIT = 5,
103     JUNIPER_EXT_TLV_IFL_ENCAPS = 6,
104     JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE = 7,
105     JUNIPER_EXT_TLV_TTP_IFL_ENCAPS = 8
106 };
107 
108 /* 1 byte type and 1-byte length */
109 #define JUNIPER_EXT_TLV_OVERHEAD 2U
110 
111 static const struct tok jnx_ext_tlv_values[] = {
112     { JUNIPER_EXT_TLV_IFD_IDX, "Device Interface Index" },
113     { JUNIPER_EXT_TLV_IFD_NAME,"Device Interface Name" },
114     { JUNIPER_EXT_TLV_IFD_MEDIATYPE, "Device Media Type" },
115     { JUNIPER_EXT_TLV_IFL_IDX, "Logical Interface Index" },
116     { JUNIPER_EXT_TLV_IFL_UNIT,"Logical Unit Number" },
117     { JUNIPER_EXT_TLV_IFL_ENCAPS, "Logical Interface Encapsulation" },
118     { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE, "TTP derived Device Media Type" },
119     { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS, "TTP derived Logical Interface Encapsulation" },
120     { 0, NULL }
121 };
122 
123 static const struct tok jnx_flag_values[] = {
124     { JUNIPER_BPF_EXT, "Ext" },
125     { JUNIPER_BPF_FILTER, "Filter" },
126     { JUNIPER_BPF_IIF, "IIF" },
127     { JUNIPER_BPF_NO_L2, "no-L2" },
128     { JUNIPER_BPF_PKT_IN, "In" },
129     { 0, NULL }
130 };
131 
132 #define JUNIPER_IFML_ETHER              1
133 #define JUNIPER_IFML_FDDI               2
134 #define JUNIPER_IFML_TOKENRING          3
135 #define JUNIPER_IFML_PPP                4
136 #define JUNIPER_IFML_FRAMERELAY         5
137 #define JUNIPER_IFML_CISCOHDLC          6
138 #define JUNIPER_IFML_SMDSDXI            7
139 #define JUNIPER_IFML_ATMPVC             8
140 #define JUNIPER_IFML_PPP_CCC            9
141 #define JUNIPER_IFML_FRAMERELAY_CCC     10
142 #define JUNIPER_IFML_IPIP               11
143 #define JUNIPER_IFML_GRE                12
144 #define JUNIPER_IFML_PIM                13
145 #define JUNIPER_IFML_PIMD               14
146 #define JUNIPER_IFML_CISCOHDLC_CCC      15
147 #define JUNIPER_IFML_VLAN_CCC           16
148 #define JUNIPER_IFML_MLPPP              17
149 #define JUNIPER_IFML_MLFR               18
150 #define JUNIPER_IFML_ML                 19
151 #define JUNIPER_IFML_LSI                20
152 #define JUNIPER_IFML_DFE                21
153 #define JUNIPER_IFML_ATM_CELLRELAY_CCC  22
154 #define JUNIPER_IFML_CRYPTO             23
155 #define JUNIPER_IFML_GGSN               24
156 #define JUNIPER_IFML_LSI_PPP            25
157 #define JUNIPER_IFML_LSI_CISCOHDLC      26
158 #define JUNIPER_IFML_PPP_TCC            27
159 #define JUNIPER_IFML_FRAMERELAY_TCC     28
160 #define JUNIPER_IFML_CISCOHDLC_TCC      29
161 #define JUNIPER_IFML_ETHERNET_CCC       30
162 #define JUNIPER_IFML_VT                 31
163 #define JUNIPER_IFML_EXTENDED_VLAN_CCC  32
164 #define JUNIPER_IFML_ETHER_OVER_ATM     33
165 #define JUNIPER_IFML_MONITOR            34
166 #define JUNIPER_IFML_ETHERNET_TCC       35
167 #define JUNIPER_IFML_VLAN_TCC           36
168 #define JUNIPER_IFML_EXTENDED_VLAN_TCC  37
169 #define JUNIPER_IFML_CONTROLLER         38
170 #define JUNIPER_IFML_MFR                39
171 #define JUNIPER_IFML_LS                 40
172 #define JUNIPER_IFML_ETHERNET_VPLS      41
173 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42
174 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43
175 #define JUNIPER_IFML_LT                 44
176 #define JUNIPER_IFML_SERVICES           45
177 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46
178 #define JUNIPER_IFML_FR_PORT_CCC        47
179 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48
180 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49
181 #define JUNIPER_IFML_FRAMERELAY_FLEX    50
182 #define JUNIPER_IFML_GGSNI              51
183 #define JUNIPER_IFML_ETHERNET_FLEX      52
184 #define JUNIPER_IFML_COLLECTOR          53
185 #define JUNIPER_IFML_AGGREGATOR         54
186 #define JUNIPER_IFML_LAPD               55
187 #define JUNIPER_IFML_PPPOE              56
188 #define JUNIPER_IFML_PPP_SUBORDINATE    57
189 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE  58
190 #define JUNIPER_IFML_DFC                59
191 #define JUNIPER_IFML_PICPEER            60
192 
193 static const struct tok juniper_ifmt_values[] = {
194     { JUNIPER_IFML_ETHER, "Ethernet" },
195     { JUNIPER_IFML_FDDI, "FDDI" },
196     { JUNIPER_IFML_TOKENRING, "Token-Ring" },
197     { JUNIPER_IFML_PPP, "PPP" },
198     { JUNIPER_IFML_PPP_SUBORDINATE, "PPP-Subordinate" },
199     { JUNIPER_IFML_FRAMERELAY, "Frame-Relay" },
200     { JUNIPER_IFML_CISCOHDLC, "Cisco-HDLC" },
201     { JUNIPER_IFML_SMDSDXI, "SMDS-DXI" },
202     { JUNIPER_IFML_ATMPVC, "ATM-PVC" },
203     { JUNIPER_IFML_PPP_CCC, "PPP-CCC" },
204     { JUNIPER_IFML_FRAMERELAY_CCC, "Frame-Relay-CCC" },
205     { JUNIPER_IFML_FRAMERELAY_EXT_CCC, "Extended FR-CCC" },
206     { JUNIPER_IFML_IPIP, "IP-over-IP" },
207     { JUNIPER_IFML_GRE, "GRE" },
208     { JUNIPER_IFML_PIM, "PIM-Encapsulator" },
209     { JUNIPER_IFML_PIMD, "PIM-Decapsulator" },
210     { JUNIPER_IFML_CISCOHDLC_CCC, "Cisco-HDLC-CCC" },
211     { JUNIPER_IFML_VLAN_CCC, "VLAN-CCC" },
212     { JUNIPER_IFML_EXTENDED_VLAN_CCC, "Extended-VLAN-CCC" },
213     { JUNIPER_IFML_MLPPP, "Multilink-PPP" },
214     { JUNIPER_IFML_MLFR, "Multilink-FR" },
215     { JUNIPER_IFML_MFR, "Multilink-FR-UNI-NNI" },
216     { JUNIPER_IFML_ML, "Multilink" },
217     { JUNIPER_IFML_LS, "LinkService" },
218     { JUNIPER_IFML_LSI, "LSI" },
219     { JUNIPER_IFML_ATM_CELLRELAY_CCC, "ATM-CCC-Cell-Relay" },
220     { JUNIPER_IFML_CRYPTO, "IPSEC-over-IP" },
221     { JUNIPER_IFML_GGSN, "GGSN" },
222     { JUNIPER_IFML_PPP_TCC, "PPP-TCC" },
223     { JUNIPER_IFML_FRAMERELAY_TCC, "Frame-Relay-TCC" },
224     { JUNIPER_IFML_FRAMERELAY_EXT_TCC, "Extended FR-TCC" },
225     { JUNIPER_IFML_CISCOHDLC_TCC, "Cisco-HDLC-TCC" },
226     { JUNIPER_IFML_ETHERNET_CCC, "Ethernet-CCC" },
227     { JUNIPER_IFML_VT, "VPN-Loopback-tunnel" },
228     { JUNIPER_IFML_ETHER_OVER_ATM, "Ethernet-over-ATM" },
229     { JUNIPER_IFML_ETHER_VPLS_OVER_ATM, "Ethernet-VPLS-over-ATM" },
230     { JUNIPER_IFML_MONITOR, "Monitor" },
231     { JUNIPER_IFML_ETHERNET_TCC, "Ethernet-TCC" },
232     { JUNIPER_IFML_VLAN_TCC, "VLAN-TCC" },
233     { JUNIPER_IFML_EXTENDED_VLAN_TCC, "Extended-VLAN-TCC" },
234     { JUNIPER_IFML_CONTROLLER, "Controller" },
235     { JUNIPER_IFML_ETHERNET_VPLS, "VPLS" },
236     { JUNIPER_IFML_ETHERNET_VLAN_VPLS, "VLAN-VPLS" },
237     { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS, "Extended-VLAN-VPLS" },
238     { JUNIPER_IFML_LT, "Logical-tunnel" },
239     { JUNIPER_IFML_SERVICES, "General-Services" },
240     { JUNIPER_IFML_PPPOE, "PPPoE" },
241     { JUNIPER_IFML_ETHERNET_FLEX, "Flexible-Ethernet-Services" },
242     { JUNIPER_IFML_FRAMERELAY_FLEX, "Flexible-FrameRelay" },
243     { JUNIPER_IFML_COLLECTOR, "Flow-collection" },
244     { JUNIPER_IFML_PICPEER, "PIC Peer" },
245     { JUNIPER_IFML_DFC, "Dynamic-Flow-Capture" },
246     {0,                    NULL}
247 };
248 
249 #define JUNIPER_IFLE_ATM_SNAP           2
250 #define JUNIPER_IFLE_ATM_NLPID          3
251 #define JUNIPER_IFLE_ATM_VCMUX          4
252 #define JUNIPER_IFLE_ATM_LLC            5
253 #define JUNIPER_IFLE_ATM_PPP_VCMUX      6
254 #define JUNIPER_IFLE_ATM_PPP_LLC        7
255 #define JUNIPER_IFLE_ATM_PPP_FUNI       8
256 #define JUNIPER_IFLE_ATM_CCC            9
257 #define JUNIPER_IFLE_FR_NLPID           10
258 #define JUNIPER_IFLE_FR_SNAP            11
259 #define JUNIPER_IFLE_FR_PPP             12
260 #define JUNIPER_IFLE_FR_CCC             13
261 #define JUNIPER_IFLE_ENET2              14
262 #define JUNIPER_IFLE_IEEE8023_SNAP      15
263 #define JUNIPER_IFLE_IEEE8023_LLC       16
264 #define JUNIPER_IFLE_PPP                17
265 #define JUNIPER_IFLE_CISCOHDLC          18
266 #define JUNIPER_IFLE_PPP_CCC            19
267 #define JUNIPER_IFLE_IPIP_NULL          20
268 #define JUNIPER_IFLE_PIM_NULL           21
269 #define JUNIPER_IFLE_GRE_NULL           22
270 #define JUNIPER_IFLE_GRE_PPP            23
271 #define JUNIPER_IFLE_PIMD_DECAPS        24
272 #define JUNIPER_IFLE_CISCOHDLC_CCC      25
273 #define JUNIPER_IFLE_ATM_CISCO_NLPID    26
274 #define JUNIPER_IFLE_VLAN_CCC           27
275 #define JUNIPER_IFLE_MLPPP              28
276 #define JUNIPER_IFLE_MLFR               29
277 #define JUNIPER_IFLE_LSI_NULL           30
278 #define JUNIPER_IFLE_AGGREGATE_UNUSED   31
279 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC  32
280 #define JUNIPER_IFLE_CRYPTO             33
281 #define JUNIPER_IFLE_GGSN               34
282 #define JUNIPER_IFLE_ATM_TCC            35
283 #define JUNIPER_IFLE_FR_TCC             36
284 #define JUNIPER_IFLE_PPP_TCC            37
285 #define JUNIPER_IFLE_CISCOHDLC_TCC      38
286 #define JUNIPER_IFLE_ETHERNET_CCC       39
287 #define JUNIPER_IFLE_VT                 40
288 #define JUNIPER_IFLE_ATM_EOA_LLC        41
289 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC          42
290 #define JUNIPER_IFLE_ATM_SNAP_TCC       43
291 #define JUNIPER_IFLE_MONITOR            44
292 #define JUNIPER_IFLE_ETHERNET_TCC       45
293 #define JUNIPER_IFLE_VLAN_TCC           46
294 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC  47
295 #define JUNIPER_IFLE_MFR                48
296 #define JUNIPER_IFLE_ETHERNET_VPLS      49
297 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50
298 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51
299 #define JUNIPER_IFLE_SERVICES           52
300 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC                53
301 #define JUNIPER_IFLE_FR_PORT_CCC        54
302 #define JUNIPER_IFLE_ATM_MLPPP_LLC      55
303 #define JUNIPER_IFLE_ATM_EOA_CCC        56
304 #define JUNIPER_IFLE_LT_VLAN            57
305 #define JUNIPER_IFLE_COLLECTOR          58
306 #define JUNIPER_IFLE_AGGREGATOR         59
307 #define JUNIPER_IFLE_LAPD               60
308 #define JUNIPER_IFLE_ATM_PPPOE_LLC          61
309 #define JUNIPER_IFLE_ETHERNET_PPPOE         62
310 #define JUNIPER_IFLE_PPPOE                  63
311 #define JUNIPER_IFLE_PPP_SUBORDINATE        64
312 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE  65
313 #define JUNIPER_IFLE_DFC                    66
314 #define JUNIPER_IFLE_PICPEER                67
315 
316 static const struct tok juniper_ifle_values[] = {
317     { JUNIPER_IFLE_AGGREGATOR, "Aggregator" },
318     { JUNIPER_IFLE_ATM_CCC, "CCC over ATM" },
319     { JUNIPER_IFLE_ATM_CELLRELAY_CCC, "ATM CCC Cell Relay" },
320     { JUNIPER_IFLE_ATM_CISCO_NLPID, "CISCO compatible NLPID" },
321     { JUNIPER_IFLE_ATM_EOA_CCC, "Ethernet over ATM CCC" },
322     { JUNIPER_IFLE_ATM_EOA_LLC, "Ethernet over ATM LLC" },
323     { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC, "Ethernet VPLS over ATM LLC" },
324     { JUNIPER_IFLE_ATM_LLC, "ATM LLC" },
325     { JUNIPER_IFLE_ATM_MLPPP_LLC, "MLPPP over ATM LLC" },
326     { JUNIPER_IFLE_ATM_NLPID, "ATM NLPID" },
327     { JUNIPER_IFLE_ATM_PPPOE_LLC, "PPPoE over ATM LLC" },
328     { JUNIPER_IFLE_ATM_PPP_FUNI, "PPP over FUNI" },
329     { JUNIPER_IFLE_ATM_PPP_LLC, "PPP over ATM LLC" },
330     { JUNIPER_IFLE_ATM_PPP_VCMUX, "PPP over ATM VCMUX" },
331     { JUNIPER_IFLE_ATM_SNAP, "ATM SNAP" },
332     { JUNIPER_IFLE_ATM_SNAP_TCC, "ATM SNAP TCC" },
333     { JUNIPER_IFLE_ATM_TCC, "ATM VCMUX TCC" },
334     { JUNIPER_IFLE_ATM_VCMUX, "ATM VCMUX" },
335     { JUNIPER_IFLE_CISCOHDLC, "C-HDLC" },
336     { JUNIPER_IFLE_CISCOHDLC_CCC, "C-HDLC CCC" },
337     { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE, "C-HDLC via dialer" },
338     { JUNIPER_IFLE_CISCOHDLC_TCC, "C-HDLC TCC" },
339     { JUNIPER_IFLE_COLLECTOR, "Collector" },
340     { JUNIPER_IFLE_CRYPTO, "Crypto" },
341     { JUNIPER_IFLE_ENET2, "Ethernet" },
342     { JUNIPER_IFLE_ETHERNET_CCC, "Ethernet CCC" },
343     { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS, "Extended VLAN VPLS" },
344     { JUNIPER_IFLE_ETHERNET_PPPOE, "PPPoE over Ethernet" },
345     { JUNIPER_IFLE_ETHERNET_TCC, "Ethernet TCC" },
346     { JUNIPER_IFLE_ETHERNET_VLAN_VPLS, "VLAN VPLS" },
347     { JUNIPER_IFLE_ETHERNET_VPLS, "VPLS" },
348     { JUNIPER_IFLE_EXTENDED_VLAN_CCC, "Extended VLAN CCC" },
349     { JUNIPER_IFLE_EXTENDED_VLAN_TCC, "Extended VLAN TCC" },
350     { JUNIPER_IFLE_FR_CCC, "FR CCC" },
351     { JUNIPER_IFLE_FR_NLPID, "FR NLPID" },
352     { JUNIPER_IFLE_FR_PORT_CCC, "FR CCC" },
353     { JUNIPER_IFLE_FR_PPP, "FR PPP" },
354     { JUNIPER_IFLE_FR_SNAP, "FR SNAP" },
355     { JUNIPER_IFLE_FR_TCC, "FR TCC" },
356     { JUNIPER_IFLE_GGSN, "GGSN" },
357     { JUNIPER_IFLE_GRE_NULL, "GRE NULL" },
358     { JUNIPER_IFLE_GRE_PPP, "PPP over GRE" },
359     { JUNIPER_IFLE_IPIP_NULL, "IPIP" },
360     { JUNIPER_IFLE_LAPD, "LAPD" },
361     { JUNIPER_IFLE_LSI_NULL, "LSI Null" },
362     { JUNIPER_IFLE_LT_VLAN, "LT VLAN" },
363     { JUNIPER_IFLE_MFR, "MFR" },
364     { JUNIPER_IFLE_MLFR, "MLFR" },
365     { JUNIPER_IFLE_MLPPP, "MLPPP" },
366     { JUNIPER_IFLE_MONITOR, "Monitor" },
367     { JUNIPER_IFLE_PIMD_DECAPS, "PIMd" },
368     { JUNIPER_IFLE_PIM_NULL, "PIM Null" },
369     { JUNIPER_IFLE_PPP, "PPP" },
370     { JUNIPER_IFLE_PPPOE, "PPPoE" },
371     { JUNIPER_IFLE_PPP_CCC, "PPP CCC" },
372     { JUNIPER_IFLE_PPP_SUBORDINATE, "" },
373     { JUNIPER_IFLE_PPP_TCC, "PPP TCC" },
374     { JUNIPER_IFLE_SERVICES, "General Services" },
375     { JUNIPER_IFLE_VLAN_CCC, "VLAN CCC" },
376     { JUNIPER_IFLE_VLAN_TCC, "VLAN TCC" },
377     { JUNIPER_IFLE_VT, "VT" },
378     {0,                    NULL}
379 };
380 
381 struct juniper_cookie_table_t {
382     uint32_t pictype;		/* pic type */
383     uint8_t  cookie_len;	/* cookie len */
384     const char *s;		/* pic name */
385 };
386 
387 static const struct juniper_cookie_table_t juniper_cookie_table[] = {
388 #ifdef DLT_JUNIPER_ATM1
389     { DLT_JUNIPER_ATM1,  4, "ATM1"},
390 #endif
391 #ifdef DLT_JUNIPER_ATM2
392     { DLT_JUNIPER_ATM2,  8, "ATM2"},
393 #endif
394 #ifdef DLT_JUNIPER_MLPPP
395     { DLT_JUNIPER_MLPPP, 2, "MLPPP"},
396 #endif
397 #ifdef DLT_JUNIPER_MLFR
398     { DLT_JUNIPER_MLFR,  2, "MLFR"},
399 #endif
400 #ifdef DLT_JUNIPER_MFR
401     { DLT_JUNIPER_MFR,   4, "MFR"},
402 #endif
403 #ifdef DLT_JUNIPER_PPPOE
404     { DLT_JUNIPER_PPPOE, 0, "PPPoE"},
405 #endif
406 #ifdef DLT_JUNIPER_PPPOE_ATM
407     { DLT_JUNIPER_PPPOE_ATM, 0, "PPPoE ATM"},
408 #endif
409 #ifdef DLT_JUNIPER_GGSN
410     { DLT_JUNIPER_GGSN, 8, "GGSN"},
411 #endif
412 #ifdef DLT_JUNIPER_MONITOR
413     { DLT_JUNIPER_MONITOR, 8, "MONITOR"},
414 #endif
415 #ifdef DLT_JUNIPER_SERVICES
416     { DLT_JUNIPER_SERVICES, 8, "AS"},
417 #endif
418 #ifdef DLT_JUNIPER_ES
419     { DLT_JUNIPER_ES, 0, "ES"},
420 #endif
421     { 0, 0, NULL }
422 };
423 
424 struct juniper_l2info_t {
425     uint32_t length;
426     uint32_t caplen;
427     uint32_t pictype;
428     uint8_t direction;
429     u_int header_len;
430     uint8_t cookie_len;
431     uint8_t cookie_type;
432     uint8_t cookie[8];
433     u_int bundle;
434     uint16_t proto;
435     uint8_t flags;
436 };
437 
438 #define LS_COOKIE_ID            0x54
439 #define AS_COOKIE_ID            0x47
440 #define LS_MLFR_COOKIE_LEN	4
441 #define ML_MLFR_COOKIE_LEN	2
442 #define LS_MFR_COOKIE_LEN	6
443 #define ATM1_COOKIE_LEN         4
444 #define ATM2_COOKIE_LEN         8
445 
446 #define ATM2_PKT_TYPE_MASK  0x70
447 #define ATM2_GAP_COUNT_MASK 0x3F
448 
449 #define JUNIPER_PROTO_NULL          1
450 #define JUNIPER_PROTO_IPV4          2
451 #define JUNIPER_PROTO_IPV6          6
452 
453 #define MFR_BE_MASK 0xc0
454 
455 #ifdef DLT_JUNIPER_GGSN
456 static const struct tok juniper_protocol_values[] = {
457     { JUNIPER_PROTO_NULL, "Null" },
458     { JUNIPER_PROTO_IPV4, "IPv4" },
459     { JUNIPER_PROTO_IPV6, "IPv6" },
460     { 0, NULL}
461 };
462 #endif
463 
464 static int ip_heuristic_guess(netdissect_options *, const u_char *, u_int);
465 #ifdef DLT_JUNIPER_ATM2
466 static int juniper_ppp_heuristic_guess(netdissect_options *, const u_char *, u_int);
467 #endif
468 static int juniper_parse_header(netdissect_options *, const u_char *, const struct pcap_pkthdr *, struct juniper_l2info_t *);
469 
470 #ifdef DLT_JUNIPER_GGSN
471 void
juniper_ggsn_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)472 juniper_ggsn_if_print(netdissect_options *ndo,
473                       const struct pcap_pkthdr *h, const u_char *p)
474 {
475         struct juniper_l2info_t l2info;
476         struct juniper_ggsn_header {
477             nd_uint8_t  svc_id;
478             nd_uint8_t  flags_len;
479             nd_uint8_t  proto;
480             nd_uint8_t  flags;
481             nd_uint16_t vlan_id;
482             nd_byte     res[2];
483         };
484         const struct juniper_ggsn_header *gh;
485         uint8_t proto;
486 
487         ndo->ndo_protocol = "juniper_ggsn";
488         memset(&l2info, 0, sizeof(l2info));
489         l2info.pictype = DLT_JUNIPER_GGSN;
490         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
491             ndo->ndo_ll_hdr_len += l2info.header_len;
492             return;
493         }
494 
495         p+=l2info.header_len;
496         gh = (struct juniper_ggsn_header *)&l2info.cookie;
497 
498         /* use EXTRACT_, not GET_ (not packet buffer pointer) */
499         proto = EXTRACT_U_1(gh->proto);
500         if (ndo->ndo_eflag) {
501             ND_PRINT("proto %s (%u), vlan %u: ",
502                    tok2str(juniper_protocol_values,"Unknown",proto),
503                    proto,
504                    EXTRACT_BE_U_2(gh->vlan_id));
505         }
506 
507         switch (proto) {
508         case JUNIPER_PROTO_IPV4:
509             ip_print(ndo, p, l2info.length);
510             break;
511         case JUNIPER_PROTO_IPV6:
512             ip6_print(ndo, p, l2info.length);
513             break;
514         default:
515             if (!ndo->ndo_eflag)
516                 ND_PRINT("unknown GGSN proto (%u)", proto);
517         }
518 
519         ndo->ndo_ll_hdr_len += l2info.header_len;
520 }
521 #endif
522 
523 #ifdef DLT_JUNIPER_ES
524 void
juniper_es_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)525 juniper_es_if_print(netdissect_options *ndo,
526                     const struct pcap_pkthdr *h, const u_char *p)
527 {
528         struct juniper_l2info_t l2info;
529         struct juniper_ipsec_header {
530             nd_uint16_t sa_index;
531             nd_uint8_t  ttl;
532             nd_uint8_t  type;
533             nd_uint32_t spi;
534             nd_ipv4     src_ip;
535             nd_ipv4     dst_ip;
536         };
537         u_int rewrite_len,es_type_bundle;
538         const struct juniper_ipsec_header *ih;
539 
540         ndo->ndo_protocol = "juniper_es";
541         memset(&l2info, 0, sizeof(l2info));
542         l2info.pictype = DLT_JUNIPER_ES;
543         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
544             ndo->ndo_ll_hdr_len += l2info.header_len;
545             return;
546         }
547 
548         p+=l2info.header_len;
549         ih = (const struct juniper_ipsec_header *)p;
550 
551         ND_TCHECK_SIZE(ih);
552         switch (GET_U_1(ih->type)) {
553         case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE:
554         case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE:
555             rewrite_len = 0;
556             es_type_bundle = 1;
557             break;
558         case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE:
559         case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE:
560         case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE:
561             rewrite_len = 16;
562             es_type_bundle = 0;
563             break;
564         default:
565             ND_PRINT("ES Invalid type %u, length %u",
566                    GET_U_1(ih->type),
567                    l2info.length);
568             ndo->ndo_ll_hdr_len += l2info.header_len;
569             return;
570         }
571 
572         l2info.length-=rewrite_len;
573         p+=rewrite_len;
574 
575         if (ndo->ndo_eflag) {
576             if (!es_type_bundle) {
577                 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
578                        GET_BE_U_2(ih->sa_index),
579                        GET_U_1(ih->ttl),
580                        tok2str(juniper_ipsec_type_values,"Unknown",GET_U_1(ih->type)),
581                        GET_U_1(ih->type),
582                        GET_BE_U_4(ih->spi),
583                        GET_IPADDR_STRING(ih->src_ip),
584                        GET_IPADDR_STRING(ih->dst_ip),
585                        l2info.length);
586             } else {
587                 ND_PRINT("ES SA, index %u, ttl %u type %s (%u), length %u\n",
588                        GET_BE_U_2(ih->sa_index),
589                        GET_U_1(ih->ttl),
590                        tok2str(juniper_ipsec_type_values,"Unknown",GET_U_1(ih->type)),
591                        GET_U_1(ih->type),
592                        l2info.length);
593             }
594         }
595 
596         ip_print(ndo, p, l2info.length);
597         ndo->ndo_ll_hdr_len += l2info.header_len;
598 }
599 #endif
600 
601 #ifdef DLT_JUNIPER_MONITOR
602 void
juniper_monitor_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)603 juniper_monitor_if_print(netdissect_options *ndo,
604                          const struct pcap_pkthdr *h, const u_char *p)
605 {
606         struct juniper_l2info_t l2info;
607         struct juniper_monitor_header {
608             nd_uint8_t  pkt_type;
609             nd_byte     padding;
610             nd_uint16_t iif;
611             nd_uint32_t service_id;
612         };
613         const struct juniper_monitor_header *mh;
614 
615         ndo->ndo_protocol = "juniper_monitor";
616         memset(&l2info, 0, sizeof(l2info));
617         l2info.pictype = DLT_JUNIPER_MONITOR;
618         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
619             ndo->ndo_ll_hdr_len += l2info.header_len;
620             return;
621         }
622 
623         p+=l2info.header_len;
624         mh = (const struct juniper_monitor_header *)p;
625 
626         ND_TCHECK_SIZE(mh);
627         if (ndo->ndo_eflag)
628             ND_PRINT("service-id %u, iif %u, pkt-type %u: ",
629                    GET_BE_U_4(mh->service_id),
630                    GET_BE_U_2(mh->iif),
631                    GET_U_1(mh->pkt_type));
632 
633         /* no proto field - lets guess by first byte of IP header*/
634         ip_heuristic_guess (ndo, p, l2info.length);
635 
636         ndo->ndo_ll_hdr_len += l2info.header_len;
637 }
638 #endif
639 
640 #ifdef DLT_JUNIPER_SERVICES
641 void
juniper_services_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)642 juniper_services_if_print(netdissect_options *ndo,
643                           const struct pcap_pkthdr *h, const u_char *p)
644 {
645         struct juniper_l2info_t l2info;
646         struct juniper_services_header {
647             nd_uint8_t  svc_id;
648             nd_uint8_t  flags_len;
649             nd_uint16_t svc_set_id;
650             nd_byte     pad;
651             nd_uint24_t dir_iif;
652         };
653         const struct juniper_services_header *sh;
654 
655         ndo->ndo_protocol = "juniper_services";
656         memset(&l2info, 0, sizeof(l2info));
657         l2info.pictype = DLT_JUNIPER_SERVICES;
658         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
659             ndo->ndo_ll_hdr_len += l2info.header_len;
660             return;
661         }
662 
663         p+=l2info.header_len;
664         sh = (const struct juniper_services_header *)p;
665 
666         ND_TCHECK_SIZE(sh);
667         if (ndo->ndo_eflag)
668             ND_PRINT("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
669                    GET_U_1(sh->svc_id),
670                    GET_U_1(sh->flags_len),
671                    GET_BE_U_2(sh->svc_set_id),
672                    GET_BE_U_3(sh->dir_iif));
673 
674         /* no proto field - lets guess by first byte of IP header*/
675         ip_heuristic_guess (ndo, p, l2info.length);
676 
677         ndo->ndo_ll_hdr_len += l2info.header_len;
678 }
679 #endif
680 
681 #ifdef DLT_JUNIPER_PPPOE
682 void
juniper_pppoe_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)683 juniper_pppoe_if_print(netdissect_options *ndo,
684                        const struct pcap_pkthdr *h, const u_char *p)
685 {
686         struct juniper_l2info_t l2info;
687 
688         ndo->ndo_protocol = "juniper_pppoe";
689         memset(&l2info, 0, sizeof(l2info));
690         l2info.pictype = DLT_JUNIPER_PPPOE;
691         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
692             ndo->ndo_ll_hdr_len += l2info.header_len;
693             return;
694         }
695 
696         p+=l2info.header_len;
697         /* this DLT contains nothing but raw ethernet frames */
698         ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
699         ndo->ndo_ll_hdr_len += l2info.header_len;
700 }
701 #endif
702 
703 #ifdef DLT_JUNIPER_ETHER
704 void
juniper_ether_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)705 juniper_ether_if_print(netdissect_options *ndo,
706                        const struct pcap_pkthdr *h, const u_char *p)
707 {
708         struct juniper_l2info_t l2info;
709 
710         ndo->ndo_protocol = "juniper_ether";
711         memset(&l2info, 0, sizeof(l2info));
712         l2info.pictype = DLT_JUNIPER_ETHER;
713         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
714             ndo->ndo_ll_hdr_len += l2info.header_len;
715             return;
716         }
717 
718         p+=l2info.header_len;
719         /* this DLT contains nothing but raw Ethernet frames */
720         ndo->ndo_ll_hdr_len +=
721 		l2info.header_len +
722 		ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
723 }
724 #endif
725 
726 #ifdef DLT_JUNIPER_PPP
727 void
juniper_ppp_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)728 juniper_ppp_if_print(netdissect_options *ndo,
729                      const struct pcap_pkthdr *h, const u_char *p)
730 {
731         struct juniper_l2info_t l2info;
732 
733         ndo->ndo_protocol = "juniper_ppp";
734         memset(&l2info, 0, sizeof(l2info));
735         l2info.pictype = DLT_JUNIPER_PPP;
736         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
737             ndo->ndo_ll_hdr_len += l2info.header_len;
738             return;
739         }
740 
741         p+=l2info.header_len;
742         /* this DLT contains nothing but raw ppp frames */
743         ppp_print(ndo, p, l2info.length);
744         ndo->ndo_ll_hdr_len += l2info.header_len;
745 }
746 #endif
747 
748 #ifdef DLT_JUNIPER_FRELAY
749 void
juniper_frelay_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)750 juniper_frelay_if_print(netdissect_options *ndo,
751                         const struct pcap_pkthdr *h, const u_char *p)
752 {
753         struct juniper_l2info_t l2info;
754 
755         ndo->ndo_protocol = "juniper_frelay";
756         memset(&l2info, 0, sizeof(l2info));
757         l2info.pictype = DLT_JUNIPER_FRELAY;
758         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
759             ndo->ndo_ll_hdr_len += l2info.header_len;
760             return;
761         }
762 
763         p+=l2info.header_len;
764         /* this DLT contains nothing but raw frame-relay frames */
765         fr_print(ndo, p, l2info.length);
766         ndo->ndo_ll_hdr_len += l2info.header_len;
767 }
768 #endif
769 
770 #ifdef DLT_JUNIPER_CHDLC
771 void
juniper_chdlc_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)772 juniper_chdlc_if_print(netdissect_options *ndo,
773                        const struct pcap_pkthdr *h, const u_char *p)
774 {
775         struct juniper_l2info_t l2info;
776 
777         ndo->ndo_protocol = "juniper_chdlc";
778         memset(&l2info, 0, sizeof(l2info));
779         l2info.pictype = DLT_JUNIPER_CHDLC;
780         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
781             ndo->ndo_ll_hdr_len += l2info.header_len;
782             return;
783         }
784 
785         p+=l2info.header_len;
786         /* this DLT contains nothing but raw c-hdlc frames */
787         chdlc_print(ndo, p, l2info.length);
788         ndo->ndo_ll_hdr_len += l2info.header_len;
789 }
790 #endif
791 
792 #ifdef DLT_JUNIPER_PPPOE_ATM
793 void
juniper_pppoe_atm_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)794 juniper_pppoe_atm_if_print(netdissect_options *ndo,
795                            const struct pcap_pkthdr *h, const u_char *p)
796 {
797         struct juniper_l2info_t l2info;
798         uint16_t extracted_ethertype;
799 
800         ndo->ndo_protocol = "juniper_pppoe_atm";
801         memset(&l2info, 0, sizeof(l2info));
802         l2info.pictype = DLT_JUNIPER_PPPOE_ATM;
803         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
804             ndo->ndo_ll_hdr_len += l2info.header_len;
805             return;
806         }
807 
808         p+=l2info.header_len;
809 
810         extracted_ethertype = GET_BE_U_2(p);
811         /* this DLT contains nothing but raw PPPoE frames,
812          * prepended with a type field*/
813         if (ethertype_print(ndo, extracted_ethertype,
814                               p+ETHERTYPE_LEN,
815                               l2info.length-ETHERTYPE_LEN,
816                               l2info.caplen-ETHERTYPE_LEN,
817                               NULL, NULL) == 0)
818             /* ether_type not known, probably it wasn't one */
819             ND_PRINT("unknown ethertype 0x%04x", extracted_ethertype);
820 
821         ndo->ndo_ll_hdr_len += l2info.header_len;
822 }
823 #endif
824 
825 #ifdef DLT_JUNIPER_MLPPP
826 void
juniper_mlppp_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)827 juniper_mlppp_if_print(netdissect_options *ndo,
828                        const struct pcap_pkthdr *h, const u_char *p)
829 {
830         struct juniper_l2info_t l2info;
831 
832         ndo->ndo_protocol = "juniper_mlppp";
833         memset(&l2info, 0, sizeof(l2info));
834         l2info.pictype = DLT_JUNIPER_MLPPP;
835         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
836             ndo->ndo_ll_hdr_len += l2info.header_len;
837             return;
838         }
839 
840         /* suppress Bundle-ID if frame was captured on a child-link
841          * best indicator if the cookie looks like a proto */
842         if (ndo->ndo_eflag &&
843             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
844             EXTRACT_BE_U_2(&l2info.cookie) != PPP_OSI &&
845             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
846             EXTRACT_BE_U_2(&l2info.cookie) !=  (PPP_ADDRESS << 8 | PPP_CONTROL))
847             ND_PRINT("Bundle-ID %u: ", l2info.bundle);
848 
849         p+=l2info.header_len;
850 
851         /* first try the LSQ protos */
852         switch(l2info.proto) {
853         case JUNIPER_LSQ_L3_PROTO_IPV4:
854             /* IP traffic going to the RE would not have a cookie
855              * -> this must be incoming IS-IS over PPP
856              */
857             if (l2info.cookie[4] == (JUNIPER_LSQ_COOKIE_RE|JUNIPER_LSQ_COOKIE_DIR))
858                 ppp_print(ndo, p, l2info.length);
859             else
860                 ip_print(ndo, p, l2info.length);
861             ndo->ndo_ll_hdr_len += l2info.header_len;
862             return;
863         case JUNIPER_LSQ_L3_PROTO_IPV6:
864             ip6_print(ndo, p,l2info.length);
865             ndo->ndo_ll_hdr_len += l2info.header_len;
866             return;
867         case JUNIPER_LSQ_L3_PROTO_MPLS:
868             mpls_print(ndo, p, l2info.length);
869             ndo->ndo_ll_hdr_len += l2info.header_len;
870             return;
871         case JUNIPER_LSQ_L3_PROTO_ISO:
872             isoclns_print(ndo, p, l2info.length);
873             ndo->ndo_ll_hdr_len += l2info.header_len;
874             return;
875         default:
876             break;
877         }
878 
879         /* zero length cookie ? */
880         /* use EXTRACT_, not GET_ (not packet buffer pointer) */
881         switch (EXTRACT_BE_U_2(&l2info.cookie)) {
882         case PPP_OSI:
883             ppp_print(ndo, p - 2, l2info.length + 2);
884             break;
885         case (PPP_ADDRESS << 8 | PPP_CONTROL): /* fall through */
886         default:
887             ppp_print(ndo, p, l2info.length);
888             break;
889         }
890 
891         ndo->ndo_ll_hdr_len += l2info.header_len;
892 }
893 #endif
894 
895 
896 #ifdef DLT_JUNIPER_MFR
897 void
juniper_mfr_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)898 juniper_mfr_if_print(netdissect_options *ndo,
899                      const struct pcap_pkthdr *h, const u_char *p)
900 {
901         struct juniper_l2info_t l2info;
902 
903         ndo->ndo_protocol = "juniper_mfr";
904         memset(&l2info, 0, sizeof(l2info));
905         l2info.pictype = DLT_JUNIPER_MFR;
906         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
907             ndo->ndo_ll_hdr_len += l2info.header_len;
908             return;
909         }
910 
911         p+=l2info.header_len;
912 
913         /* child-link ? */
914         if (l2info.cookie_len == 0) {
915             mfr_print(ndo, p, l2info.length);
916             ndo->ndo_ll_hdr_len += l2info.header_len;
917             return;
918         }
919 
920         /* first try the LSQ protos */
921         if (l2info.cookie_len == AS_PIC_COOKIE_LEN) {
922             switch(l2info.proto) {
923             case JUNIPER_LSQ_L3_PROTO_IPV4:
924                 ip_print(ndo, p, l2info.length);
925                 ndo->ndo_ll_hdr_len += l2info.header_len;
926                 return;
927             case JUNIPER_LSQ_L3_PROTO_IPV6:
928                 ip6_print(ndo, p,l2info.length);
929                 ndo->ndo_ll_hdr_len += l2info.header_len;
930                 return;
931             case JUNIPER_LSQ_L3_PROTO_MPLS:
932                 mpls_print(ndo, p, l2info.length);
933                 ndo->ndo_ll_hdr_len += l2info.header_len;
934                 return;
935             case JUNIPER_LSQ_L3_PROTO_ISO:
936                 isoclns_print(ndo, p, l2info.length);
937                 ndo->ndo_ll_hdr_len += l2info.header_len;
938                 return;
939             default:
940                 break;
941             }
942             ndo->ndo_ll_hdr_len += l2info.header_len;
943             return;
944         }
945 
946         /* suppress Bundle-ID if frame was captured on a child-link */
947         /* use EXTRACT_, not GET_ (not packet buffer pointer) */
948         if (ndo->ndo_eflag && EXTRACT_BE_U_4(l2info.cookie) != 1)
949             ND_PRINT("Bundle-ID %u, ", l2info.bundle);
950         switch (l2info.proto) {
951         case (LLCSAP_ISONS<<8 | LLCSAP_ISONS):
952             /* At least one byte is required */
953             ND_TCHECK_LEN(p, 1);
954             isoclns_print(ndo, p + 1, l2info.length - 1);
955             break;
956         case (LLC_UI<<8 | NLPID_Q933):
957         case (LLC_UI<<8 | NLPID_IP):
958         case (LLC_UI<<8 | NLPID_IP6):
959             /* pass IP{4,6} to the OSI layer for proper link-layer printing */
960             isoclns_print(ndo, p - 1, l2info.length + 1);
961             break;
962         default:
963             ND_PRINT("unknown protocol 0x%04x, length %u", l2info.proto, l2info.length);
964         }
965 
966         ndo->ndo_ll_hdr_len += l2info.header_len;
967 }
968 #endif
969 
970 #ifdef DLT_JUNIPER_MLFR
971 void
juniper_mlfr_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)972 juniper_mlfr_if_print(netdissect_options *ndo,
973                       const struct pcap_pkthdr *h, const u_char *p)
974 {
975         struct juniper_l2info_t l2info;
976 
977         ndo->ndo_protocol = "juniper_mlfr";
978         memset(&l2info, 0, sizeof(l2info));
979         l2info.pictype = DLT_JUNIPER_MLFR;
980         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
981             ndo->ndo_ll_hdr_len += l2info.header_len;
982             return;
983         }
984 
985         p+=l2info.header_len;
986 
987         /* suppress Bundle-ID if frame was captured on a child-link */
988         /* use EXTRACT_, not GET_ (not packet buffer pointer) */
989         if (ndo->ndo_eflag && EXTRACT_BE_U_4(l2info.cookie) != 1)
990             ND_PRINT("Bundle-ID %u, ", l2info.bundle);
991         switch (l2info.proto) {
992         case (LLC_UI):
993         case (LLC_UI<<8):
994             isoclns_print(ndo, p, l2info.length);
995             break;
996         case (LLC_UI<<8 | NLPID_Q933):
997         case (LLC_UI<<8 | NLPID_IP):
998         case (LLC_UI<<8 | NLPID_IP6):
999             /* pass IP{4,6} to the OSI layer for proper link-layer printing */
1000             isoclns_print(ndo, p - 1, l2info.length + 1);
1001             break;
1002         default:
1003             ND_PRINT("unknown protocol 0x%04x, length %u", l2info.proto, l2info.length);
1004         }
1005 
1006         ndo->ndo_ll_hdr_len += l2info.header_len;
1007 }
1008 #endif
1009 
1010 /*
1011  *     ATM1 PIC cookie format
1012  *
1013  *     +-----+-------------------------+-------------------------------+
1014  *     |fmtid|     vc index            |  channel  ID                  |
1015  *     +-----+-------------------------+-------------------------------+
1016  */
1017 
1018 #ifdef DLT_JUNIPER_ATM1
1019 void
juniper_atm1_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)1020 juniper_atm1_if_print(netdissect_options *ndo,
1021                       const struct pcap_pkthdr *h, const u_char *p)
1022 {
1023         int llc_hdrlen;
1024 
1025         struct juniper_l2info_t l2info;
1026 
1027         ndo->ndo_protocol = "juniper_atm1";
1028         memset(&l2info, 0, sizeof(l2info));
1029         l2info.pictype = DLT_JUNIPER_ATM1;
1030         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
1031             ndo->ndo_ll_hdr_len += l2info.header_len;
1032             return;
1033         }
1034 
1035         p+=l2info.header_len;
1036 
1037         if (l2info.cookie[0] == 0x80) { /* OAM cell ? */
1038             oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC);
1039             ndo->ndo_ll_hdr_len += l2info.header_len;
1040             return;
1041         }
1042 
1043         if (GET_BE_U_3(p) == 0xfefe03 || /* NLPID encaps ? */
1044             GET_BE_U_3(p) == 0xaaaa03) { /* SNAP encaps ? */
1045 
1046             llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
1047             if (llc_hdrlen > 0) {
1048                 ndo->ndo_ll_hdr_len += l2info.header_len;
1049                 return;
1050             }
1051         }
1052 
1053         if (GET_U_1(p) == 0x03) { /* Cisco style NLPID encaps ? */
1054             /* At least one byte is required */
1055             ND_TCHECK_LEN(p, 1);
1056             isoclns_print(ndo, p + 1, l2info.length - 1);
1057             /* FIXME check if frame was recognized */
1058             ndo->ndo_ll_hdr_len += l2info.header_len;
1059             return;
1060         }
1061 
1062         if (ip_heuristic_guess(ndo, p, l2info.length) != 0) { /* last try - vcmux encaps ? */
1063             ndo->ndo_ll_hdr_len += l2info.header_len;
1064             return;
1065         }
1066 
1067         ndo->ndo_ll_hdr_len += l2info.header_len;
1068 }
1069 #endif
1070 
1071 /*
1072  *     ATM2 PIC cookie format
1073  *
1074  *     +-------------------------------+---------+---+-----+-----------+
1075  *     |     channel ID                |  reserv |AAL| CCRQ| gap cnt   |
1076  *     +-------------------------------+---------+---+-----+-----------+
1077  */
1078 
1079 #ifdef DLT_JUNIPER_ATM2
1080 void
juniper_atm2_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)1081 juniper_atm2_if_print(netdissect_options *ndo,
1082                       const struct pcap_pkthdr *h, const u_char *p)
1083 {
1084         int llc_hdrlen;
1085 
1086         struct juniper_l2info_t l2info;
1087 
1088         ndo->ndo_protocol = "juniper_atm2";
1089         memset(&l2info, 0, sizeof(l2info));
1090         l2info.pictype = DLT_JUNIPER_ATM2;
1091         if (juniper_parse_header(ndo, p, h, &l2info) == 0) {
1092             ndo->ndo_ll_hdr_len += l2info.header_len;
1093             return;
1094         }
1095 
1096         p+=l2info.header_len;
1097 
1098         if (l2info.cookie[7] & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */
1099             oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC);
1100             ndo->ndo_ll_hdr_len += l2info.header_len;
1101             return;
1102         }
1103 
1104         if (GET_BE_U_3(p) == 0xfefe03 || /* NLPID encaps ? */
1105             GET_BE_U_3(p) == 0xaaaa03) { /* SNAP encaps ? */
1106 
1107             llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
1108             if (llc_hdrlen > 0) {
1109                 ndo->ndo_ll_hdr_len += l2info.header_len;
1110                 return;
1111             }
1112         }
1113 
1114         if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */
1115             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
1116             (EXTRACT_BE_U_4(l2info.cookie) & ATM2_GAP_COUNT_MASK)) {
1117             ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL);
1118             ndo->ndo_ll_hdr_len += l2info.header_len;
1119             return;
1120         }
1121 
1122         if (GET_U_1(p) == 0x03) { /* Cisco style NLPID encaps ? */
1123             /* At least one byte is required */
1124             ND_TCHECK_LEN(p, 1);
1125             isoclns_print(ndo, p + 1, l2info.length - 1);
1126             /* FIXME check if frame was recognized */
1127             ndo->ndo_ll_hdr_len += l2info.header_len;
1128             return;
1129         }
1130 
1131         if(juniper_ppp_heuristic_guess(ndo, p, l2info.length) != 0) { /* PPPoA vcmux encaps ? */
1132             ndo->ndo_ll_hdr_len += l2info.header_len;
1133             return;
1134         }
1135 
1136         if (ip_heuristic_guess(ndo, p, l2info.length) != 0) { /* last try - vcmux encaps ? */
1137             ndo->ndo_ll_hdr_len += l2info.header_len;
1138             return;
1139         }
1140 
1141         ndo->ndo_ll_hdr_len += l2info.header_len;
1142 }
1143 
1144 /* try to guess, based on all PPP protos that are supported in
1145  * a juniper router if the payload data is encapsulated using PPP */
1146 static int
juniper_ppp_heuristic_guess(netdissect_options * ndo,const u_char * p,u_int length)1147 juniper_ppp_heuristic_guess(netdissect_options *ndo,
1148                             const u_char *p, u_int length)
1149 {
1150     switch(GET_BE_U_2(p)) {
1151     case PPP_IP :
1152     case PPP_OSI :
1153     case PPP_MPLS_UCAST :
1154     case PPP_MPLS_MCAST :
1155     case PPP_IPCP :
1156     case PPP_OSICP :
1157     case PPP_MPLSCP :
1158     case PPP_LCP :
1159     case PPP_PAP :
1160     case PPP_CHAP :
1161     case PPP_ML :
1162     case PPP_IPV6 :
1163     case PPP_IPV6CP :
1164         ppp_print(ndo, p, length);
1165         break;
1166 
1167     default:
1168         return 0; /* did not find a ppp header */
1169         break;
1170     }
1171     return 1; /* we printed a ppp packet */
1172 }
1173 #endif
1174 
1175 static int
ip_heuristic_guess(netdissect_options * ndo,const u_char * p,u_int length)1176 ip_heuristic_guess(netdissect_options *ndo,
1177                    const u_char *p, u_int length)
1178 {
1179     switch(GET_U_1(p)) {
1180     case 0x45:
1181     case 0x46:
1182     case 0x47:
1183     case 0x48:
1184     case 0x49:
1185     case 0x4a:
1186     case 0x4b:
1187     case 0x4c:
1188     case 0x4d:
1189     case 0x4e:
1190     case 0x4f:
1191         ip_print(ndo, p, length);
1192         break;
1193     case 0x60:
1194     case 0x61:
1195     case 0x62:
1196     case 0x63:
1197     case 0x64:
1198     case 0x65:
1199     case 0x66:
1200     case 0x67:
1201     case 0x68:
1202     case 0x69:
1203     case 0x6a:
1204     case 0x6b:
1205     case 0x6c:
1206     case 0x6d:
1207     case 0x6e:
1208     case 0x6f:
1209         ip6_print(ndo, p, length);
1210         break;
1211     default:
1212         return 0; /* did not find a ip header */
1213         break;
1214     }
1215     return 1; /* we printed an v4/v6 packet */
1216 }
1217 
1218 static int
juniper_read_tlv_value(netdissect_options * ndo,const u_char * p,u_int tlv_type,u_int tlv_len)1219 juniper_read_tlv_value(netdissect_options *ndo,
1220 		       const u_char *p, u_int tlv_type, u_int tlv_len)
1221 {
1222    int tlv_value;
1223 
1224    /* TLVs < 128 are little endian encoded */
1225    if (tlv_type < 128) {
1226        switch (tlv_len) {
1227        case 1:
1228            tlv_value = GET_U_1(p);
1229            break;
1230        case 2:
1231            tlv_value = GET_LE_U_2(p);
1232            break;
1233        case 3:
1234            tlv_value = GET_LE_U_3(p);
1235            break;
1236        case 4:
1237            tlv_value = GET_LE_U_4(p);
1238            break;
1239        default:
1240            tlv_value = -1;
1241            break;
1242        }
1243    } else {
1244        /* TLVs >= 128 are big endian encoded */
1245        switch (tlv_len) {
1246        case 1:
1247            tlv_value = GET_U_1(p);
1248            break;
1249        case 2:
1250            tlv_value = GET_BE_U_2(p);
1251            break;
1252        case 3:
1253            tlv_value = GET_BE_U_3(p);
1254            break;
1255        case 4:
1256            tlv_value = GET_BE_U_4(p);
1257            break;
1258        default:
1259            tlv_value = -1;
1260            break;
1261        }
1262    }
1263    return tlv_value;
1264 }
1265 
1266 static int
juniper_parse_header(netdissect_options * ndo,const u_char * p,const struct pcap_pkthdr * h,struct juniper_l2info_t * l2info)1267 juniper_parse_header(netdissect_options *ndo,
1268                      const u_char *p, const struct pcap_pkthdr *h, struct juniper_l2info_t *l2info)
1269 {
1270     const struct juniper_cookie_table_t *lp;
1271     u_int idx, extension_length, jnx_header_len = 0;
1272     uint8_t tlv_type,tlv_len;
1273 #ifdef DLT_JUNIPER_ATM2
1274     uint32_t control_word;
1275 #endif
1276     int tlv_value;
1277     const u_char *tptr;
1278 
1279 
1280     l2info->header_len = 0;
1281     l2info->cookie_len = 0;
1282     l2info->proto = 0;
1283 
1284 
1285     l2info->length = h->len;
1286     l2info->caplen = h->caplen;
1287     l2info->flags = GET_U_1(p + 3);
1288     l2info->direction = GET_U_1(p + 3) & JUNIPER_BPF_PKT_IN;
1289 
1290     if (GET_BE_U_3(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */
1291         ND_PRINT("no magic-number found!");
1292         return 0;
1293     }
1294 
1295     if (ndo->ndo_eflag) /* print direction */
1296         ND_PRINT("%3s ", tok2str(juniper_direction_values, "---", l2info->direction));
1297 
1298     /* magic number + flags */
1299     jnx_header_len = 4;
1300 
1301     if (ndo->ndo_vflag > 1)
1302         ND_PRINT("\n\tJuniper PCAP Flags [%s]",
1303                bittok2str(jnx_flag_values, "none", l2info->flags));
1304 
1305     /* extensions present ?  - calculate how much bytes to skip */
1306     if ((l2info->flags & JUNIPER_BPF_EXT ) == JUNIPER_BPF_EXT ) {
1307 
1308         tptr = p+jnx_header_len;
1309 
1310         /* ok to read extension length ? */
1311         extension_length = GET_BE_U_2(tptr);
1312         jnx_header_len += 2;
1313         tptr +=2;
1314 
1315         /* nail up the total length -
1316          * just in case something goes wrong
1317          * with TLV parsing */
1318         jnx_header_len += extension_length;
1319 
1320         if (ndo->ndo_vflag > 1)
1321             ND_PRINT(", PCAP Extension(s) total length %u", extension_length);
1322 
1323         ND_TCHECK_LEN(tptr, extension_length);
1324         while (extension_length > JUNIPER_EXT_TLV_OVERHEAD) {
1325             tlv_type = GET_U_1(tptr);
1326             tptr++;
1327             tlv_len = GET_U_1(tptr);
1328             tptr++;
1329             tlv_value = 0;
1330 
1331             /* sanity checks */
1332             if (tlv_type == 0 || tlv_len == 0)
1333                 break;
1334             ND_LCHECK_U(extension_length, tlv_len + JUNIPER_EXT_TLV_OVERHEAD);
1335 
1336             if (ndo->ndo_vflag > 1)
1337                 ND_PRINT("\n\t  %s Extension TLV #%u, length %u, value ",
1338                        tok2str(jnx_ext_tlv_values,"Unknown",tlv_type),
1339                        tlv_type,
1340                        tlv_len);
1341 
1342             tlv_value = juniper_read_tlv_value(ndo, tptr, tlv_type, tlv_len);
1343             switch (tlv_type) {
1344             case JUNIPER_EXT_TLV_IFD_NAME:
1345                 /* FIXME */
1346                 break;
1347             case JUNIPER_EXT_TLV_IFD_MEDIATYPE:
1348             case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE:
1349                 if (tlv_value != -1) {
1350                     if (ndo->ndo_vflag > 1)
1351                         ND_PRINT("%s (%u)",
1352                                tok2str(juniper_ifmt_values, "Unknown", tlv_value),
1353                                tlv_value);
1354                 }
1355                 break;
1356             case JUNIPER_EXT_TLV_IFL_ENCAPS:
1357             case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS:
1358                 if (tlv_value != -1) {
1359                     if (ndo->ndo_vflag > 1)
1360                         ND_PRINT("%s (%u)",
1361                                tok2str(juniper_ifle_values, "Unknown", tlv_value),
1362                                tlv_value);
1363                 }
1364                 break;
1365             case JUNIPER_EXT_TLV_IFL_IDX: /* fall through */
1366             case JUNIPER_EXT_TLV_IFL_UNIT:
1367             case JUNIPER_EXT_TLV_IFD_IDX:
1368             default:
1369                 if (tlv_value != -1) {
1370                     if (ndo->ndo_vflag > 1)
1371                         ND_PRINT("%u", tlv_value);
1372                 }
1373                 break;
1374             }
1375 
1376             tptr+=tlv_len;
1377             extension_length -= tlv_len+JUNIPER_EXT_TLV_OVERHEAD;
1378         }
1379 
1380         if (ndo->ndo_vflag > 1)
1381             ND_PRINT("\n\t-----original packet-----\n\t");
1382     }
1383 
1384     if ((l2info->flags & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) {
1385         if (ndo->ndo_eflag)
1386             ND_PRINT("no-L2-hdr, ");
1387 
1388         /* there is no link-layer present -
1389          * perform the v4/v6 heuristics
1390          * to figure out what it is
1391          */
1392         ND_TCHECK_1(p + (jnx_header_len + 4));
1393         if (ip_heuristic_guess(ndo, p + jnx_header_len + 4,
1394                                l2info->length - (jnx_header_len + 4)) == 0)
1395             ND_PRINT("no IP-hdr found!");
1396 
1397         l2info->header_len=jnx_header_len+4;
1398         return 0; /* stop parsing the output further */
1399 
1400     }
1401     l2info->header_len = jnx_header_len;
1402     p+=l2info->header_len;
1403     l2info->length -= l2info->header_len;
1404     l2info->caplen -= l2info->header_len;
1405 
1406     /* search through the cookie table for one matching our PIC type */
1407     lp = NULL;
1408     for (const struct juniper_cookie_table_t *table_lp = juniper_cookie_table;
1409          table_lp->s != NULL; table_lp++) {
1410         if (table_lp->pictype == l2info->pictype) {
1411             lp = table_lp;
1412             break;
1413         }
1414     }
1415 
1416     /* If we found one matching our PIC type, copy its values */
1417     if (lp != NULL) {
1418         l2info->cookie_len += lp->cookie_len;
1419 
1420         switch (GET_U_1(p)) {
1421         case LS_COOKIE_ID:
1422             l2info->cookie_type = LS_COOKIE_ID;
1423             l2info->cookie_len += 2;
1424             break;
1425         case AS_COOKIE_ID:
1426             l2info->cookie_type = AS_COOKIE_ID;
1427             l2info->cookie_len = 8;
1428             break;
1429 
1430         default:
1431             l2info->bundle = l2info->cookie[0];
1432             break;
1433         }
1434 
1435 
1436 #ifdef DLT_JUNIPER_MFR
1437         /* MFR child links don't carry cookies */
1438         if (l2info->pictype == DLT_JUNIPER_MFR &&
1439             (GET_U_1(p) & MFR_BE_MASK) == MFR_BE_MASK) {
1440             l2info->cookie_len = 0;
1441         }
1442 #endif
1443 
1444         l2info->header_len += l2info->cookie_len;
1445         l2info->length -= l2info->cookie_len;
1446         l2info->caplen -= l2info->cookie_len;
1447 
1448         if (ndo->ndo_eflag)
1449             ND_PRINT("%s-PIC, cookie-len %u",
1450                    lp->s,
1451                    l2info->cookie_len);
1452 
1453         if (l2info->cookie_len > 8) {
1454             nd_print_invalid(ndo);
1455             return 0;
1456         }
1457 
1458         if (l2info->cookie_len > 0) {
1459             ND_TCHECK_LEN(p, l2info->cookie_len);
1460             if (ndo->ndo_eflag)
1461                 ND_PRINT(", cookie 0x");
1462             for (idx = 0; idx < l2info->cookie_len; idx++) {
1463                 l2info->cookie[idx] = GET_U_1(p + idx); /* copy cookie data */
1464                 if (ndo->ndo_eflag) ND_PRINT("%02x", GET_U_1(p + idx));
1465             }
1466         }
1467 
1468         if (ndo->ndo_eflag) ND_PRINT(": "); /* print demarc b/w L2/L3*/
1469 
1470 
1471         l2info->proto = GET_BE_U_2(p + l2info->cookie_len);
1472     }
1473     p+=l2info->cookie_len;
1474 
1475     /* DLT_ specific parsing */
1476     switch(l2info->pictype) {
1477 #ifdef DLT_JUNIPER_MLPPP
1478     case DLT_JUNIPER_MLPPP:
1479         switch (l2info->cookie_type) {
1480         case LS_COOKIE_ID:
1481             l2info->bundle = l2info->cookie[1];
1482             break;
1483         case AS_COOKIE_ID:
1484             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
1485             l2info->bundle = (EXTRACT_BE_U_2(&l2info->cookie[6])>>3)&0xfff;
1486             l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1487             break;
1488         default:
1489             l2info->bundle = l2info->cookie[0];
1490             break;
1491         }
1492         break;
1493 #endif
1494 #ifdef DLT_JUNIPER_MLFR
1495     case DLT_JUNIPER_MLFR:
1496         switch (l2info->cookie_type) {
1497         case LS_COOKIE_ID:
1498             l2info->bundle = l2info->cookie[1];
1499             l2info->proto = GET_BE_U_2(p);
1500             l2info->header_len += 2;
1501             l2info->length -= 2;
1502             l2info->caplen -= 2;
1503             break;
1504         case AS_COOKIE_ID:
1505             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
1506             l2info->bundle = (EXTRACT_BE_U_2(&l2info->cookie[6])>>3)&0xfff;
1507             l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1508             break;
1509         default:
1510             l2info->bundle = l2info->cookie[0];
1511             l2info->header_len += 2;
1512             l2info->length -= 2;
1513             l2info->caplen -= 2;
1514             break;
1515         }
1516         break;
1517 #endif
1518 #ifdef DLT_JUNIPER_MFR
1519     case DLT_JUNIPER_MFR:
1520         switch (l2info->cookie_type) {
1521         case LS_COOKIE_ID:
1522             l2info->bundle = l2info->cookie[1];
1523             l2info->proto = GET_BE_U_2(p);
1524             l2info->header_len += 2;
1525             l2info->length -= 2;
1526             l2info->caplen -= 2;
1527             break;
1528         case AS_COOKIE_ID:
1529             /* use EXTRACT_, not GET_ (not packet buffer pointer) */
1530             l2info->bundle = (EXTRACT_BE_U_2(&l2info->cookie[6])>>3)&0xfff;
1531             l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK;
1532             break;
1533         default:
1534             l2info->bundle = l2info->cookie[0];
1535             break;
1536         }
1537         break;
1538 #endif
1539 #ifdef DLT_JUNIPER_ATM2
1540     case DLT_JUNIPER_ATM2:
1541         ND_TCHECK_4(p);
1542         /* ATM cell relay control word present ? */
1543         if (l2info->cookie[7] & ATM2_PKT_TYPE_MASK) {
1544             control_word = GET_BE_U_4(p);
1545             /* some control word heuristics */
1546             switch(control_word) {
1547             case 0: /* zero control word */
1548             case 0x08000000: /* < JUNOS 7.4 control-word */
1549             case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
1550                 l2info->header_len += 4;
1551                 break;
1552             default:
1553                 break;
1554             }
1555 
1556             if (ndo->ndo_eflag)
1557                 ND_PRINT("control-word 0x%08x ", control_word);
1558         }
1559         break;
1560 #endif
1561 #ifdef DLT_JUNIPER_ES
1562     case DLT_JUNIPER_ES:
1563         break;
1564 #endif
1565 #ifdef DLT_JUNIPER_GGSN
1566     case DLT_JUNIPER_GGSN:
1567         break;
1568 #endif
1569 #ifdef DLT_JUNIPER_SERVICES
1570     case DLT_JUNIPER_SERVICES:
1571         break;
1572 #endif
1573 #ifdef DLT_JUNIPER_ATM1
1574     case DLT_JUNIPER_ATM1:
1575         break;
1576 #endif
1577 #ifdef DLT_JUNIPER_PPP
1578     case DLT_JUNIPER_PPP:
1579         break;
1580 #endif
1581 #ifdef DLT_JUNIPER_CHDLC
1582     case DLT_JUNIPER_CHDLC:
1583         break;
1584 #endif
1585 #ifdef DLT_JUNIPER_ETHER
1586     case DLT_JUNIPER_ETHER:
1587         break;
1588 #endif
1589 #ifdef DLT_JUNIPER_FRELAY
1590     case DLT_JUNIPER_FRELAY:
1591         break;
1592 #endif
1593 #ifdef DLT_JUNIPER_MONITOR
1594     case DLT_JUNIPER_MONITOR:
1595         break;
1596 #endif
1597 #ifdef DLT_JUNIPER_PPPOE
1598     case DLT_JUNIPER_PPPOE:
1599         break;
1600 #endif
1601 #ifdef DLT_JUNIPER_PPPOE_ATM
1602     case DLT_JUNIPER_PPPOE_ATM:
1603         break;
1604 #endif
1605 
1606     default:
1607         ND_PRINT("Unknown Juniper DLT_ type %u: ", l2info->pictype);
1608         break;
1609     }
1610 
1611     if (ndo->ndo_eflag)
1612         ND_PRINT("hlen %u, proto 0x%04x, ", l2info->header_len, l2info->proto);
1613 
1614     return 1; /* everything went ok so far. continue parsing */
1615 invalid:
1616     nd_print_invalid(ndo);
1617     return 0;
1618 }
1619 #endif /* defined(DLT_JUNIPER_GGSN) || defined(DLT_JUNIPER_ES) || \
1620           defined(DLT_JUNIPER_MONITOR) || defined(DLT_JUNIPER_SERVICES) || \
1621           defined(DLT_JUNIPER_PPPOE) || defined(DLT_JUNIPER_ETHER) || \
1622           defined(DLT_JUNIPER_PPP) || defined(DLT_JUNIPER_FRELAY) || \
1623           defined(DLT_JUNIPER_CHDLC) || defined(DLT_JUNIPER_PPPOE_ATM) || \
1624           defined(DLT_JUNIPER_MLPPP) || defined(DLT_JUNIPER_MFR) || \
1625           defined(DLT_JUNIPER_MLFR) || defined(DLT_JUNIPER_ATM1) || \
1626           defined(DLT_JUNIPER_ATM2) */
1627