HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-juniper.c
blobb71e6f08d78bba2e9e8c92c0e0039a4ec6df37cb
1 /* packet-juniper.c
2 * Routines for Juniper Networks, Inc. packet disassembly
3 * Copyright 2005 Hannes Gredler <hannes@juniper.net>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
29 #include <epan/packet.h>
30 #include <epan/etypes.h>
31 #include <epan/prefs.h>
32 #include <epan/addr_resolv.h>
33 #include <epan/ppptypes.h>
34 #include "packet-ppp.h"
35 #include "packet-ip.h"
36 #include <epan/nlpid.h>
38 #define JUNIPER_FLAG_PKT_OUT 0x00 /* Outgoing packet */
39 #define JUNIPER_FLAG_PKT_IN 0x01 /* Incoming packet */
40 #define JUNIPER_FLAG_NO_L2 0x02 /* L2 header stripped */
41 #define JUNIPER_FLAG_EXT 0x80 /* extensions present */
42 #define EXT_TLV_HEADER_SIZE 2
43 #define JUNIPER_ATM2_PKT_TYPE_MASK 0x70
44 #define JUNIPER_ATM2_GAP_COUNT_MASK 0x3F
45 #define JUNIPER_PCAP_MAGIC 0x4d4743
47 #define JUNIPER_PIC_ATM1 1
48 #define JUNIPER_PIC_ATM2 2
49 #define JUNIPER_PIC_MLPPP 3
50 #define JUNIPER_PIC_MLFR 4
52 #define JUNIPER_HDR_SNAP 0xaaaa03
53 #define JUNIPER_HDR_NLPID 0xfefe03
54 #define JUNIPER_HDR_LLC_UI 0x03
55 #define JUNIPER_HDR_PPP 0xff03
57 #define ML_PIC_COOKIE_LEN 2
58 #define LS_PIC_COOKIE_LEN 4
59 #define AS_PIC_COOKIE_LEN 8
61 #define GSP_SVC_REQ_APOLLO 0x40
62 #define GSP_SVC_REQ_LSQ 0x47
64 #define LSQ_COOKIE_RE 0x2
65 #define LSQ_COOKIE_DIR 0x1
66 #define LSQ_L3_PROTO_SHIFT 4
67 #define LSQ_L3_PROTO_MASK 0xf0
68 #define LSQ_L3_PROTO_IPV4 (0 << LSQ_L3_PROTO_SHIFT)
69 #define LSQ_L3_PROTO_IPV6 (1 << LSQ_L3_PROTO_SHIFT)
70 #define LSQ_L3_PROTO_MPLS (2 << LSQ_L3_PROTO_SHIFT)
71 #define LSQ_L3_PROTO_ISO (3 << LSQ_L3_PROTO_SHIFT)
73 #define EXT_TLV_IFD_IDX 1
74 #define EXT_TLV_IFD_NAME 2
75 #define EXT_TLV_IFD_MEDIATYPE 3
76 #define EXT_TLV_IFL_IDX 4
77 #define EXT_TLV_IFL_UNIT 5
78 #define EXT_TLV_IFL_ENCAPS 6
79 #define EXT_TLV_TTP_IFD_MEDIATYPE 7
80 #define EXT_TLV_TTP_IFL_ENCAPS 8
82 static const value_string ext_tlv_vals[] = {
83 { EXT_TLV_IFD_IDX, "Device Interface Index" },
84 { EXT_TLV_IFD_NAME, "Device Interface Name" },
85 { EXT_TLV_IFD_MEDIATYPE, "Device Media Type" },
86 { EXT_TLV_IFL_IDX, "Logical Interface Index" },
87 { EXT_TLV_IFL_UNIT, "Logical Unit Number" },
88 { EXT_TLV_IFL_ENCAPS, "Logical Interface Encapsulation" },
89 { EXT_TLV_TTP_IFD_MEDIATYPE, "TTP derived Device Media Type" },
90 { EXT_TLV_TTP_IFL_ENCAPS, "TTP derived Logical Interface Encapsulation" },
91 { 0, NULL }
94 static const value_string juniper_direction_vals[] = {
95 {JUNIPER_FLAG_PKT_OUT, "Out"},
96 {JUNIPER_FLAG_PKT_IN, "In"},
97 {0, NULL}
100 static const value_string juniper_l2hdr_presence_vals[] = {
101 { 0, "Present"},
102 { 2, "none"},
103 {0, NULL}
106 #define JUNIPER_IFML_ETHER 1
107 #define JUNIPER_IFML_FDDI 2
108 #define JUNIPER_IFML_TOKENRING 3
109 #define JUNIPER_IFML_PPP 4
110 #define JUNIPER_IFML_FRAMERELAY 5
111 #define JUNIPER_IFML_CISCOHDLC 6
112 #define JUNIPER_IFML_SMDSDXI 7
113 #define JUNIPER_IFML_ATMPVC 8
114 #define JUNIPER_IFML_PPP_CCC 9
115 #define JUNIPER_IFML_FRAMERELAY_CCC 10
116 #define JUNIPER_IFML_IPIP 11
117 #define JUNIPER_IFML_GRE 12
118 #define JUNIPER_IFML_PIM 13
119 #define JUNIPER_IFML_PIMD 14
120 #define JUNIPER_IFML_CISCOHDLC_CCC 15
121 #define JUNIPER_IFML_VLAN_CCC 16
122 #define JUNIPER_IFML_MLPPP 17
123 #define JUNIPER_IFML_MLFR 18
124 #define JUNIPER_IFML_ML 19
125 #define JUNIPER_IFML_LSI 20
126 #define JUNIPER_IFML_DFE 21
127 #define JUNIPER_IFML_ATM_CELLRELAY_CCC 22
128 #define JUNIPER_IFML_CRYPTO 23
129 #define JUNIPER_IFML_GGSN 24
130 #define JUNIPER_IFML_LSI_PPP 25
131 #define JUNIPER_IFML_LSI_CISCOHDLC 26
132 #define JUNIPER_IFML_PPP_TCC 27
133 #define JUNIPER_IFML_FRAMERELAY_TCC 28
134 #define JUNIPER_IFML_CISCOHDLC_TCC 29
135 #define JUNIPER_IFML_ETHERNET_CCC 30
136 #define JUNIPER_IFML_VT 31
137 #define JUNIPER_IFML_EXTENDED_VLAN_CCC 32
138 #define JUNIPER_IFML_ETHER_OVER_ATM 33
139 #define JUNIPER_IFML_MONITOR 34
140 #define JUNIPER_IFML_ETHERNET_TCC 35
141 #define JUNIPER_IFML_VLAN_TCC 36
142 #define JUNIPER_IFML_EXTENDED_VLAN_TCC 37
143 #define JUNIPER_IFML_CONTROLLER 38
144 #define JUNIPER_IFML_MFR 39
145 #define JUNIPER_IFML_LS 40
146 #define JUNIPER_IFML_ETHERNET_VPLS 41
147 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42
148 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43
149 #define JUNIPER_IFML_LT 44
150 #define JUNIPER_IFML_SERVICES 45
151 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46
152 #define JUNIPER_IFML_FR_PORT_CCC 47
153 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48
154 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49
155 #define JUNIPER_IFML_FRAMERELAY_FLEX 50
156 #define JUNIPER_IFML_GGSNI 51
157 #define JUNIPER_IFML_ETHERNET_FLEX 52
158 #define JUNIPER_IFML_COLLECTOR 53
159 #define JUNIPER_IFML_AGGREGATOR 54
160 #define JUNIPER_IFML_LAPD 55
161 #define JUNIPER_IFML_PPPOE 56
162 #define JUNIPER_IFML_PPP_SUBORDINATE 57
163 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE 58
164 #define JUNIPER_IFML_DFC 59
165 #define JUNIPER_IFML_PICPEER 60
167 static const value_string juniper_ifmt_vals[] = {
168 { JUNIPER_IFML_ETHER, "Ethernet" },
169 { JUNIPER_IFML_FDDI, "FDDI" },
170 { JUNIPER_IFML_TOKENRING, "Token-Ring" },
171 { JUNIPER_IFML_PPP, "PPP" },
172 { JUNIPER_IFML_PPP_SUBORDINATE, "PPP-Subordinate" },
173 { JUNIPER_IFML_FRAMERELAY, "Frame-Relay" },
174 { JUNIPER_IFML_CISCOHDLC, "Cisco-HDLC" },
175 { JUNIPER_IFML_SMDSDXI, "SMDS-DXI" },
176 { JUNIPER_IFML_ATMPVC, "ATM-PVC" },
177 { JUNIPER_IFML_PPP_CCC, "PPP-CCC" },
178 { JUNIPER_IFML_FRAMERELAY_CCC, "Frame-Relay-CCC" },
179 { JUNIPER_IFML_FRAMERELAY_EXT_CCC, "Extended FR-CCC" },
180 { JUNIPER_IFML_IPIP, "IP-over-IP" },
181 { JUNIPER_IFML_GRE, "GRE" },
182 { JUNIPER_IFML_PIM, "PIM-Encapsulator" },
183 { JUNIPER_IFML_PIMD, "PIM-Decapsulator" },
184 { JUNIPER_IFML_CISCOHDLC_CCC, "Cisco-HDLC-CCC" },
185 { JUNIPER_IFML_VLAN_CCC, "VLAN-CCC" },
186 { JUNIPER_IFML_EXTENDED_VLAN_CCC, "Extended-VLAN-CCC" },
187 { JUNIPER_IFML_MLPPP, "Multilink-PPP" },
188 { JUNIPER_IFML_MLFR, "Multilink-FR" },
189 { JUNIPER_IFML_MFR, "Multilink-FR-UNI-NNI" },
190 { JUNIPER_IFML_ML, "Multilink" },
191 { JUNIPER_IFML_LS, "LinkService" },
192 { JUNIPER_IFML_LSI, "LSI" },
193 { JUNIPER_IFML_ATM_CELLRELAY_CCC, "ATM-CCC-Cell-Relay" },
194 { JUNIPER_IFML_CRYPTO, "IPSEC-over-IP" },
195 { JUNIPER_IFML_GGSN, "GGSN" },
196 { JUNIPER_IFML_PPP_TCC, "PPP-TCC" },
197 { JUNIPER_IFML_FRAMERELAY_TCC, "Frame-Relay-TCC" },
198 { JUNIPER_IFML_FRAMERELAY_EXT_TCC, "Extended FR-TCC" },
199 { JUNIPER_IFML_CISCOHDLC_TCC, "Cisco-HDLC-TCC" },
200 { JUNIPER_IFML_ETHERNET_CCC, "Ethernet-CCC" },
201 { JUNIPER_IFML_VT, "VPN-Loopback-tunnel" },
202 { JUNIPER_IFML_ETHER_OVER_ATM, "Ethernet-over-ATM" },
203 { JUNIPER_IFML_ETHER_VPLS_OVER_ATM, "Ethernet-VPLS-over-ATM" },
204 { JUNIPER_IFML_MONITOR, "Monitor" },
205 { JUNIPER_IFML_ETHERNET_TCC, "Ethernet-TCC" },
206 { JUNIPER_IFML_VLAN_TCC, "VLAN-TCC" },
207 { JUNIPER_IFML_EXTENDED_VLAN_TCC, "Extended-VLAN-TCC" },
208 { JUNIPER_IFML_CONTROLLER, "Controller" },
209 { JUNIPER_IFML_ETHERNET_VPLS, "VPLS" },
210 { JUNIPER_IFML_ETHERNET_VLAN_VPLS, "VLAN-VPLS" },
211 { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS, "Extended-VLAN-VPLS" },
212 { JUNIPER_IFML_LT, "Logical-tunnel" },
213 { JUNIPER_IFML_SERVICES, "General-Services" },
214 { JUNIPER_IFML_PPPOE, "PPPoE" },
215 { JUNIPER_IFML_ETHERNET_FLEX, "Flexible-Ethernet-Services" },
216 { JUNIPER_IFML_FRAMERELAY_FLEX, "Flexible-FrameRelay" },
217 { JUNIPER_IFML_COLLECTOR, "Flow-collection" },
218 { JUNIPER_IFML_PICPEER, "PIC Peer" },
219 { JUNIPER_IFML_DFC, "Dynamic-Flow-Capture" },
220 {0, NULL}
223 #define JUNIPER_IFLE_ATM_SNAP 2
224 #define JUNIPER_IFLE_ATM_NLPID 3
225 #define JUNIPER_IFLE_ATM_VCMUX 4
226 #define JUNIPER_IFLE_ATM_LLC 5
227 #define JUNIPER_IFLE_ATM_PPP_VCMUX 6
228 #define JUNIPER_IFLE_ATM_PPP_LLC 7
229 #define JUNIPER_IFLE_ATM_PPP_FUNI 8
230 #define JUNIPER_IFLE_ATM_CCC 9
231 #define JUNIPER_IFLE_FR_NLPID 10
232 #define JUNIPER_IFLE_FR_SNAP 11
233 #define JUNIPER_IFLE_FR_PPP 12
234 #define JUNIPER_IFLE_FR_CCC 13
235 #define JUNIPER_IFLE_ENET2 14
236 #define JUNIPER_IFLE_IEEE8023_SNAP 15
237 #define JUNIPER_IFLE_IEEE8023_LLC 16
238 #define JUNIPER_IFLE_PPP 17
239 #define JUNIPER_IFLE_CISCOHDLC 18
240 #define JUNIPER_IFLE_PPP_CCC 19
241 #define JUNIPER_IFLE_IPIP_NULL 20
242 #define JUNIPER_IFLE_PIM_NULL 21
243 #define JUNIPER_IFLE_GRE_NULL 22
244 #define JUNIPER_IFLE_GRE_PPP 23
245 #define JUNIPER_IFLE_PIMD_DECAPS 24
246 #define JUNIPER_IFLE_CISCOHDLC_CCC 25
247 #define JUNIPER_IFLE_ATM_CISCO_NLPID 26
248 #define JUNIPER_IFLE_VLAN_CCC 27
249 #define JUNIPER_IFLE_MLPPP 28
250 #define JUNIPER_IFLE_MLFR 29
251 #define JUNIPER_IFLE_LSI_NULL 30
252 #define JUNIPER_IFLE_AGGREGATE_UNUSED 31
253 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC 32
254 #define JUNIPER_IFLE_CRYPTO 33
255 #define JUNIPER_IFLE_GGSN 34
256 #define JUNIPER_IFLE_ATM_TCC 35
257 #define JUNIPER_IFLE_FR_TCC 36
258 #define JUNIPER_IFLE_PPP_TCC 37
259 #define JUNIPER_IFLE_CISCOHDLC_TCC 38
260 #define JUNIPER_IFLE_ETHERNET_CCC 39
261 #define JUNIPER_IFLE_VT 40
262 #define JUNIPER_IFLE_ATM_EOA_LLC 41
263 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC 42
264 #define JUNIPER_IFLE_ATM_SNAP_TCC 43
265 #define JUNIPER_IFLE_MONITOR 44
266 #define JUNIPER_IFLE_ETHERNET_TCC 45
267 #define JUNIPER_IFLE_VLAN_TCC 46
268 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC 47
269 #define JUNIPER_IFLE_MFR 48
270 #define JUNIPER_IFLE_ETHERNET_VPLS 49
271 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50
272 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51
273 #define JUNIPER_IFLE_SERVICES 52
274 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC 53
275 #define JUNIPER_IFLE_FR_PORT_CCC 54
276 #define JUNIPER_IFLE_ATM_MLPPP_LLC 55
277 #define JUNIPER_IFLE_ATM_EOA_CCC 56
278 #define JUNIPER_IFLE_LT_VLAN 57
279 #define JUNIPER_IFLE_COLLECTOR 58
280 #define JUNIPER_IFLE_AGGREGATOR 59
281 #define JUNIPER_IFLE_LAPD 60
282 #define JUNIPER_IFLE_ATM_PPPOE_LLC 61
283 #define JUNIPER_IFLE_ETHERNET_PPPOE 62
284 #define JUNIPER_IFLE_PPPOE 63
285 #define JUNIPER_IFLE_PPP_SUBORDINATE 64
286 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE 65
287 #define JUNIPER_IFLE_DFC 66
288 #define JUNIPER_IFLE_PICPEER 67
290 static const value_string juniper_ifle_vals[] = {
291 { JUNIPER_IFLE_AGGREGATOR, "Aggregator" },
292 { JUNIPER_IFLE_ATM_CCC, "CCC over ATM" },
293 { JUNIPER_IFLE_ATM_CELLRELAY_CCC, "ATM CCC Cell Relay" },
294 { JUNIPER_IFLE_ATM_CISCO_NLPID, "CISCO compatible NLPID" },
295 { JUNIPER_IFLE_ATM_EOA_CCC, "Ethernet over ATM CCC" },
296 { JUNIPER_IFLE_ATM_EOA_LLC, "Ethernet over ATM LLC" },
297 { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC, "Ethernet VPLS over ATM LLC" },
298 { JUNIPER_IFLE_ATM_LLC, "ATM LLC" },
299 { JUNIPER_IFLE_ATM_MLPPP_LLC, "MLPPP over ATM LLC" },
300 { JUNIPER_IFLE_ATM_NLPID, "ATM NLPID" },
301 { JUNIPER_IFLE_ATM_PPPOE_LLC, "PPPoE over ATM LLC" },
302 { JUNIPER_IFLE_ATM_PPP_FUNI, "PPP over FUNI" },
303 { JUNIPER_IFLE_ATM_PPP_LLC, "PPP over ATM LLC" },
304 { JUNIPER_IFLE_ATM_PPP_VCMUX, "PPP over ATM VCMUX" },
305 { JUNIPER_IFLE_ATM_SNAP, "ATM SNAP" },
306 { JUNIPER_IFLE_ATM_SNAP_TCC, "ATM SNAP TCC" },
307 { JUNIPER_IFLE_ATM_TCC, "ATM VCMUX TCC" },
308 { JUNIPER_IFLE_ATM_VCMUX, "ATM VCMUX" },
309 { JUNIPER_IFLE_CISCOHDLC, "C-HDLC" },
310 { JUNIPER_IFLE_CISCOHDLC_CCC, "C-HDLC CCC" },
311 { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE, "C-HDLC via dialer" },
312 { JUNIPER_IFLE_CISCOHDLC_TCC, "C-HDLC TCC" },
313 { JUNIPER_IFLE_COLLECTOR, "Collector" },
314 { JUNIPER_IFLE_CRYPTO, "Crypto" },
315 { JUNIPER_IFLE_ENET2, "Ethernet" },
316 { JUNIPER_IFLE_ETHERNET_CCC, "Ethernet CCC" },
317 { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS, "Extended VLAN VPLS" },
318 { JUNIPER_IFLE_ETHERNET_PPPOE, "PPPoE over Ethernet" },
319 { JUNIPER_IFLE_ETHERNET_TCC, "Ethernet TCC" },
320 { JUNIPER_IFLE_ETHERNET_VLAN_VPLS, "VLAN VPLS" },
321 { JUNIPER_IFLE_ETHERNET_VPLS, "VPLS" },
322 { JUNIPER_IFLE_EXTENDED_VLAN_CCC, "Extended VLAN CCC" },
323 { JUNIPER_IFLE_EXTENDED_VLAN_TCC, "Extended VLAN TCC" },
324 { JUNIPER_IFLE_FR_CCC, "FR CCC" },
325 { JUNIPER_IFLE_FR_NLPID, "FR NLPID" },
326 { JUNIPER_IFLE_FR_PORT_CCC, "FR CCC" },
327 { JUNIPER_IFLE_FR_PPP, "FR PPP" },
328 { JUNIPER_IFLE_FR_SNAP, "FR SNAP" },
329 { JUNIPER_IFLE_FR_TCC, "FR TCC" },
330 { JUNIPER_IFLE_GGSN, "GGSN" },
331 { JUNIPER_IFLE_GRE_NULL, "GRE NULL" },
332 { JUNIPER_IFLE_GRE_PPP, "PPP over GRE" },
333 { JUNIPER_IFLE_IPIP_NULL, "IPIP" },
334 { JUNIPER_IFLE_LAPD, "LAPD" },
335 { JUNIPER_IFLE_LSI_NULL, "LSI Null" },
336 { JUNIPER_IFLE_LT_VLAN, "LT VLAN" },
337 { JUNIPER_IFLE_MFR, "MFR" },
338 { JUNIPER_IFLE_MLFR, "MLFR" },
339 { JUNIPER_IFLE_MLPPP, "MLPPP" },
340 { JUNIPER_IFLE_MONITOR, "Monitor" },
341 { JUNIPER_IFLE_PIMD_DECAPS, "PIMd" },
342 { JUNIPER_IFLE_PIM_NULL, "PIM Null" },
343 { JUNIPER_IFLE_PPP, "PPP" },
344 { JUNIPER_IFLE_PPPOE, "PPPoE" },
345 { JUNIPER_IFLE_PPP_CCC, "PPP CCC" },
346 { JUNIPER_IFLE_PPP_SUBORDINATE, "" },
347 { JUNIPER_IFLE_PPP_TCC, "PPP TCC" },
348 { JUNIPER_IFLE_SERVICES, "General Services" },
349 { JUNIPER_IFLE_VLAN_CCC, "VLAN CCC" },
350 { JUNIPER_IFLE_VLAN_TCC, "VLAN TCC" },
351 { JUNIPER_IFLE_VT, "VT" },
352 {0, NULL}
356 static int proto_juniper = -1;
358 /* static int hf_juniper_magic = -1; */
359 static int hf_juniper_direction = -1;
360 static int hf_juniper_l2hdr_presence = -1;
361 static int hf_juniper_ext_total_len = -1;
362 static int hf_juniper_atm1_cookie = -1;
363 static int hf_juniper_atm2_cookie = -1;
364 static int hf_juniper_mlpic_cookie = -1;
365 static int hf_juniper_lspic_cookie = -1;
366 static int hf_juniper_aspic_cookie = -1;
367 static int hf_juniper_vlan = -1;
368 static int hf_juniper_proto = -1;
369 static int hf_juniper_ext_ifd = -1;
370 static int hf_juniper_ext_ifl = -1;
371 static int hf_juniper_ext_unit = -1;
372 static int hf_juniper_ext_ifmt = -1;
373 static int hf_juniper_ext_ifle = -1;
374 static int hf_juniper_ext_ttp_ifmt = -1;
375 static int hf_juniper_ext_ttp_ifle = -1;
377 static gint ett_juniper = -1;
379 static dissector_handle_t ipv4_handle;
380 static dissector_handle_t ipv6_handle;
381 static dissector_handle_t mpls_handle;
382 static dissector_handle_t llc_handle;
383 static dissector_handle_t eth_handle;
384 static dissector_handle_t ppp_handle;
385 static dissector_handle_t q933_handle;
386 static dissector_handle_t frelay_handle;
387 static dissector_handle_t chdlc_handle;
388 static dissector_handle_t data_handle;
390 static dissector_table_t osinl_incl_subdissector_table;
391 static dissector_table_t osinl_excl_subdissector_table;
393 static int dissect_juniper_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *ti, guint8 *flags);
394 static int dissect_juniper_payload_proto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,proto_item *ti, guint proto, guint offset);
395 static void dissect_juniper_atm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 atm_pictype);
396 static gboolean ppp_heuristic_guess(guint16 proto);
397 static guint ip_heuristic_guess(guint8 ip_header_byte);
398 static guint juniper_svc_cookie_len (guint64 cookie);
399 static guint juniper_svc_cookie_proto (guint64 cookie, guint16 pictype, guint8 flags);
401 /* values < 200 are JUNOS internal proto values
402 * found in frames containing no link-layer header */
403 enum {
404 PROTO_UNKNOWN = 0,
405 PROTO_IP = 2,
406 PROTO_MPLS_IP = 3,
407 PROTO_IP_MPLS = 4,
408 PROTO_MPLS = 5,
409 PROTO_IP6 = 6,
410 PROTO_MPLS_IP6 = 7,
411 PROTO_IP6_MPLS = 8,
412 PROTO_CLNP = 10,
413 PROTO_CLNP_MPLS = 32,
414 PROTO_MPLS_CLNP = 33,
415 PROTO_PPP = 200,
416 PROTO_ISO = 201,
417 PROTO_LLC = 202,
418 PROTO_LLC_SNAP = 203,
419 PROTO_ETHER = 204,
420 PROTO_OAM = 205,
421 PROTO_Q933 = 206,
422 PROTO_FRELAY = 207,
423 PROTO_CHDLC = 208
426 static const value_string juniper_proto_vals[] = {
427 {PROTO_IP, "IPv4"},
428 {PROTO_MPLS_IP, "MPLS->IPv4"},
429 {PROTO_IP_MPLS, "IPv4->MPLS"},
430 {PROTO_IP6, "IPv6"},
431 {PROTO_MPLS_IP6, "MPLS->IPv6"},
432 {PROTO_IP6_MPLS, "IPv6->MPLS"},
433 {PROTO_PPP, "PPP"},
434 {PROTO_CLNP, "CLNP"},
435 {PROTO_MPLS_CLNP, "MPLS->CLNP"},
436 {PROTO_CLNP_MPLS, "CLNP->MPLS"},
437 {PROTO_ISO, "OSI"},
438 {PROTO_MPLS, "MPLS"},
439 {PROTO_LLC, "LLC"},
440 {PROTO_LLC_SNAP, "LLC/SNAP"},
441 {PROTO_ETHER, "Ethernet"},
442 {PROTO_OAM, "ATM OAM Cell"},
443 {PROTO_Q933, "Q.933"},
444 {PROTO_FRELAY, "Frame-Relay"},
445 {PROTO_CHDLC, "C-HDLC"},
446 {0, NULL}
449 /* the first subtree is accessed by several routines */
450 static proto_tree *juniper_subtree = NULL;
452 /* return a TLV value based on TLV length and TLV type (host/network order) */
453 static int
454 juniper_ext_get_tlv_value(tvbuff_t *tvb, guint tlv_type, guint tlv_len, guint offset) {
456 int tlv_value;
458 if (tlv_type < 128) {
459 /* TLVs < 128 are little-endian / host order encoded */
460 switch (tlv_len) {
461 case 1:
462 tlv_value = tvb_get_guint8(tvb, offset);
463 break;
464 case 2:
465 tlv_value = tvb_get_letohs(tvb, offset);
466 break;
467 case 3:
468 tlv_value = tvb_get_letoh24(tvb, offset);
469 break;
470 case 4:
471 tlv_value = tvb_get_letohl(tvb, offset);
472 break;
473 default:
474 tlv_value = -1;
475 break;
477 } else {
478 /* TLVs >= 128 are big-endian / network order encoded */
479 switch (tlv_len) {
480 case 1:
481 tlv_value = tvb_get_guint8(tvb, offset);
482 break;
483 case 2:
484 tlv_value = tvb_get_ntohs(tvb, offset);
485 break;
486 case 3:
487 tlv_value = tvb_get_ntoh24(tvb, offset);
488 break;
489 case 4:
490 tlv_value = tvb_get_ntohl(tvb, offset);
491 break;
492 default:
493 tlv_value = -1;
494 break;
497 return tlv_value;
500 /* generic juniper header dissector */
501 static int
502 dissect_juniper_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *ti, guint8 *flags)
504 proto_item *tisub;
505 guint8 l2hdr_presence,proto,ext_type,ext_len;
506 guint16 ext_total_len,ext_offset=6,hdr_len;
507 guint32 magic_number,ext_val;
509 proto_tree *juniper_ext_subtree = NULL, *juniper_ext_subtree_item = NULL;
511 magic_number = tvb_get_ntoh24(tvb, 0);
512 *flags = tvb_get_guint8(tvb, 3);
513 l2hdr_presence = *flags & JUNIPER_FLAG_NO_L2;
515 juniper_subtree = proto_item_add_subtree(ti, ett_juniper);
517 /* be liberal with magic-number detection -
518 * some older JUNOS releases (e.g. 6.4),
519 * which are still in the field do not generate magic-numbers */
520 if (magic_number != JUNIPER_PCAP_MAGIC) {
521 proto_tree_add_text (juniper_subtree, tvb, 0, 0, "no Magic-Number found !");
522 return 0;
525 proto_tree_add_text (juniper_subtree, tvb, 0, 3,
526 "Magic-Number: 0x%06x", magic_number);
528 proto_tree_add_item(juniper_subtree, hf_juniper_direction, tvb, 3, 1, ENC_NA);
530 proto_tree_add_uint_format (juniper_subtree, hf_juniper_l2hdr_presence, tvb, 3, 1,
531 l2hdr_presence, "L2-header: %s",
532 val_to_str_const(l2hdr_presence,juniper_l2hdr_presence_vals,"Unknown"));
534 /* calculate hdr_len before cookie, payload */
536 /* meta-info extensions (JUNOS >= 7.5) ? */
537 if ((*flags & JUNIPER_FLAG_EXT) == JUNIPER_FLAG_EXT) {
538 ext_total_len = tvb_get_ntohs(tvb,4);
539 hdr_len = 6 + ext_total_len; /* MGC,flags,ext_total_len */
541 tisub = proto_tree_add_uint (juniper_subtree, hf_juniper_ext_total_len, tvb, 4, 2, ext_total_len);
542 juniper_ext_subtree = proto_item_add_subtree(tisub, ett_juniper);
544 while (ext_total_len > EXT_TLV_HEADER_SIZE) {
545 ext_type = tvb_get_guint8(tvb, ext_offset);
546 ext_len = tvb_get_guint8(tvb, ext_offset+1);
548 if (ext_len == 0 || ext_len > (ext_total_len - EXT_TLV_HEADER_SIZE)) /* a few sanity checks */
549 break;
551 tisub = proto_tree_add_text (juniper_ext_subtree, tvb, ext_offset, EXT_TLV_HEADER_SIZE + ext_len,
552 "%s Extension TLV #%u, length: %u",
553 val_to_str_const(ext_type, ext_tlv_vals, "Unknown"),
554 ext_type,
555 ext_len);
557 ext_val = juniper_ext_get_tlv_value(tvb, ext_type, ext_len, ext_offset+EXT_TLV_HEADER_SIZE);
558 juniper_ext_subtree_item = proto_item_add_subtree(tisub, ett_juniper);
560 switch (ext_type) {
561 case EXT_TLV_IFD_MEDIATYPE:
562 proto_tree_add_uint(juniper_ext_subtree_item, hf_juniper_ext_ifmt,
563 tvb, ext_offset+EXT_TLV_HEADER_SIZE, ext_len, ext_val);
564 break;
565 case EXT_TLV_TTP_IFD_MEDIATYPE:
566 proto_tree_add_uint(juniper_ext_subtree_item, hf_juniper_ext_ttp_ifmt,
567 tvb, ext_offset+EXT_TLV_HEADER_SIZE, ext_len, ext_val);
568 break;
569 case EXT_TLV_IFL_ENCAPS:
570 proto_tree_add_uint(juniper_ext_subtree_item, hf_juniper_ext_ifle,
571 tvb, ext_offset+EXT_TLV_HEADER_SIZE, ext_len, ext_val);
572 break;
573 case EXT_TLV_TTP_IFL_ENCAPS:
574 proto_tree_add_uint(juniper_ext_subtree_item, hf_juniper_ext_ttp_ifle,
575 tvb, ext_offset+EXT_TLV_HEADER_SIZE, ext_len, ext_val);
576 break;
578 case EXT_TLV_IFL_IDX:
579 proto_tree_add_uint(juniper_ext_subtree_item, hf_juniper_ext_ifl,
580 tvb, ext_offset+EXT_TLV_HEADER_SIZE, ext_len, ext_val);
581 break;
583 case EXT_TLV_IFL_UNIT:
584 proto_tree_add_uint(juniper_ext_subtree_item, hf_juniper_ext_unit,
585 tvb, ext_offset+EXT_TLV_HEADER_SIZE, ext_len, ext_val);
586 break;
587 case EXT_TLV_IFD_IDX:
588 proto_tree_add_uint(juniper_ext_subtree_item, hf_juniper_ext_ifd,
589 tvb, ext_offset+EXT_TLV_HEADER_SIZE, ext_len, ext_val);
590 break;
591 case EXT_TLV_IFD_NAME: /* FIXME print ifname string - lets fall-through for now */
592 default:
593 proto_item_append_text(tisub, "Unknown");
594 break;
597 ext_offset += EXT_TLV_HEADER_SIZE + ext_len;
598 ext_total_len -= EXT_TLV_HEADER_SIZE + ext_len;
601 } else
602 hdr_len = 4; /* MGC,flags */
604 if ((*flags & JUNIPER_FLAG_NO_L2) == JUNIPER_FLAG_NO_L2) { /* no link header present ? */
605 proto = tvb_get_letohl(tvb,hdr_len); /* proto is stored in host-order */
606 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, proto, hdr_len + 4);
607 return -1;
610 return hdr_len; /* bytes parsed */
614 /* print the payload protocol */
615 static int
616 dissect_juniper_payload_proto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
617 proto_item *ti _U_, guint proto, guint offset)
620 tvbuff_t *next_tvb;
621 guint8 nlpid;
623 proto_tree_add_text (juniper_subtree, tvb, offset, 0, "[Payload Type: %s]",
624 val_to_str_const(proto,juniper_proto_vals,"Unknown"));
626 next_tvb = tvb_new_subset_remaining(tvb, offset);
628 switch (proto) {
629 case PROTO_IP:
630 case PROTO_MPLS_IP:
631 call_dissector(ipv4_handle, next_tvb, pinfo, tree);
632 break;
633 case PROTO_IP6:
634 case PROTO_MPLS_IP6:
635 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
636 break;
637 case PROTO_MPLS:
638 case PROTO_IP_MPLS:
639 case PROTO_IP6_MPLS:
640 case PROTO_CLNP_MPLS:
641 call_dissector(mpls_handle, next_tvb, pinfo, tree);
642 break;
643 case PROTO_PPP:
644 call_dissector(ppp_handle, next_tvb, pinfo, tree);
645 break;
646 case PROTO_ETHER:
647 call_dissector(eth_handle, next_tvb, pinfo, tree);
648 break;
649 case PROTO_LLC:
650 case PROTO_LLC_SNAP:
651 call_dissector(llc_handle, next_tvb, pinfo, tree);
652 break;
653 case PROTO_ISO:
654 case PROTO_CLNP:
655 case PROTO_MPLS_CLNP:
656 nlpid = tvb_get_guint8(tvb, offset);
657 if(dissector_try_uint(osinl_incl_subdissector_table, nlpid, next_tvb, pinfo, tree))
658 return 0;
659 next_tvb = tvb_new_subset_remaining(tvb, offset+1);
660 if(dissector_try_uint(osinl_excl_subdissector_table, nlpid, next_tvb, pinfo, tree))
661 return 0;
662 break;
663 case PROTO_Q933:
664 call_dissector(q933_handle, next_tvb, pinfo, tree);
665 break;
666 case PROTO_FRELAY:
667 call_dissector(frelay_handle, next_tvb, pinfo, tree);
668 break;
669 case PROTO_CHDLC:
670 call_dissector(chdlc_handle, next_tvb, pinfo, tree);
671 break;
672 case 0xa248:
673 proto_tree_add_text (juniper_subtree, tvb, offset, 4,"[Unknown data]");
674 next_tvb = tvb_new_subset_remaining(tvb, offset+4);
675 call_dissector(ipv4_handle, next_tvb, pinfo, tree);
676 break;
677 case PROTO_OAM: /* FIXME call OAM disector without leading HEC byte */
678 default:
679 call_dissector(data_handle, next_tvb, pinfo, tree);
680 break;
683 return 0;
686 /* MLFR dissector */
687 static void
688 dissect_juniper_mlfr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
690 proto_item *ti;
691 guint offset;
692 int bytes_processed;
693 guint8 flags;
694 guint64 aspic_cookie;
695 guint32 lspic_cookie;
696 guint16 mlpic_cookie;
697 guint proto,cookie_len;
699 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper MLFR");
700 col_clear(pinfo->cinfo, COL_INFO);
702 offset = 0;
704 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper Multi-Link Frame-Relay (FRF.15)");
706 /* parse header, match mgc, extract flags and build first tree */
707 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
709 if(bytes_processed == -1)
710 return;
711 else
712 offset+=bytes_processed;
714 aspic_cookie = tvb_get_ntoh64(tvb,offset);
715 proto = juniper_svc_cookie_proto(aspic_cookie, JUNIPER_PIC_MLFR, flags);
716 cookie_len = juniper_svc_cookie_len(aspic_cookie);
718 if (cookie_len == AS_PIC_COOKIE_LEN)
719 proto_tree_add_uint64(juniper_subtree, hf_juniper_aspic_cookie,
720 tvb, offset, AS_PIC_COOKIE_LEN, aspic_cookie);
721 if (cookie_len == LS_PIC_COOKIE_LEN) {
722 lspic_cookie = tvb_get_ntohl(tvb,offset);
723 proto_tree_add_uint(juniper_subtree, hf_juniper_lspic_cookie,
724 tvb, offset, LS_PIC_COOKIE_LEN, lspic_cookie);
727 offset += cookie_len;
729 mlpic_cookie = tvb_get_ntohs(tvb, offset);
731 /* AS-PIC IS-IS */
732 if (cookie_len == AS_PIC_COOKIE_LEN &&
733 proto == PROTO_UNKNOWN &&
734 tvb_get_guint8(tvb,offset) == JUNIPER_HDR_LLC_UI) {
735 offset += 1;
736 proto = PROTO_ISO;
739 /* LS-PIC IS-IS */
740 if (cookie_len == LS_PIC_COOKIE_LEN) {
741 if ( tvb_get_ntohs(tvb,offset) == JUNIPER_HDR_LLC_UI ||
742 tvb_get_ntohs(tvb,offset) == (JUNIPER_HDR_LLC_UI<<8)) {
743 offset += 2;
747 /* LS-PIC ? */
748 if (cookie_len == LS_PIC_COOKIE_LEN && tvb_get_guint8(tvb,offset) == JUNIPER_HDR_LLC_UI) {
749 offset += 1;
752 /* child link of an LS-PIC bundle ? */
753 if (cookie_len == 0 && tvb_get_ntohs(tvb,offset+ML_PIC_COOKIE_LEN) ==
754 (JUNIPER_HDR_LLC_UI<<8 | NLPID_Q_933)) {
755 cookie_len = ML_PIC_COOKIE_LEN;
756 proto_tree_add_uint(juniper_subtree, hf_juniper_mlpic_cookie,
757 tvb, offset, ML_PIC_COOKIE_LEN, mlpic_cookie);
758 offset += 3;
759 proto = PROTO_Q933;
762 /* child link of an ML-, LS-, AS-PIC bundle / ML-PIC bundle ? */
763 if (cookie_len == 0) {
764 if (tvb_get_ntohs(tvb,offset+ML_PIC_COOKIE_LEN) == JUNIPER_HDR_LLC_UI ||
765 tvb_get_ntohs(tvb,offset+ML_PIC_COOKIE_LEN) == (JUNIPER_HDR_LLC_UI<<8)) {
766 cookie_len = ML_PIC_COOKIE_LEN;
767 proto_tree_add_uint(juniper_subtree, hf_juniper_mlpic_cookie,
768 tvb, offset, ML_PIC_COOKIE_LEN, mlpic_cookie);
769 offset += 4;
770 proto = PROTO_ISO;
774 /* ML-PIC bundle ? */
775 if (cookie_len == 0 && tvb_get_guint8(tvb,offset+ML_PIC_COOKIE_LEN) == JUNIPER_HDR_LLC_UI) {
776 cookie_len = ML_PIC_COOKIE_LEN;
777 proto_tree_add_uint(juniper_subtree, hf_juniper_mlpic_cookie,
778 tvb, offset, ML_PIC_COOKIE_LEN, mlpic_cookie);
779 offset += 3;
780 proto = PROTO_ISO;
783 ti = proto_tree_add_text (juniper_subtree, tvb, offset, 0, "[Cookie length: %u]",cookie_len);
784 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, proto, offset);
790 /* MLPPP dissector */
791 static void
792 dissect_juniper_mlppp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
794 proto_item *ti;
795 guint offset;
796 int bytes_processed;
797 guint8 flags;
798 guint64 aspic_cookie;
799 guint32 lspic_cookie;
800 guint16 mlpic_cookie;
801 guint proto,cookie_len;
803 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper MLPPP");
804 col_clear(pinfo->cinfo, COL_INFO);
806 offset = 0;
808 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper MLPPP");
810 /* parse header, match mgc, extract flags and build first tree */
811 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
813 if(bytes_processed == -1)
814 return;
815 else
816 offset+=bytes_processed;
818 aspic_cookie = tvb_get_ntoh64(tvb,offset);
819 proto = juniper_svc_cookie_proto(aspic_cookie, JUNIPER_PIC_MLPPP, flags);
820 cookie_len = juniper_svc_cookie_len(aspic_cookie);
822 if (cookie_len == AS_PIC_COOKIE_LEN)
823 proto_tree_add_uint64(juniper_subtree, hf_juniper_aspic_cookie,
824 tvb, offset, AS_PIC_COOKIE_LEN, aspic_cookie);
825 if (cookie_len == LS_PIC_COOKIE_LEN) {
826 lspic_cookie = tvb_get_ntohl(tvb,offset);
827 proto_tree_add_uint(juniper_subtree, hf_juniper_lspic_cookie,
828 tvb, offset, LS_PIC_COOKIE_LEN, lspic_cookie);
831 /* no cookie pattern identified - lets guess from now on */
833 /* child link of an LS-PIC bundle ? */
834 if (cookie_len == 0 && tvb_get_ntohs(tvb, offset) == JUNIPER_HDR_PPP) {
835 proto = PROTO_PPP;
836 offset += 2;
839 /* ML-PIC ? */
840 if (cookie_len == 0 && ppp_heuristic_guess(tvb_get_ntohs(tvb, offset+2))) {
841 proto = PROTO_PPP;
842 cookie_len = 2;
843 mlpic_cookie = tvb_get_ntohs(tvb, offset);
844 proto_tree_add_uint(juniper_subtree, hf_juniper_mlpic_cookie,
845 tvb, offset, ML_PIC_COOKIE_LEN, mlpic_cookie);
848 /* child link of an ML-PIC bundle ? */
849 if (cookie_len == 0 && ppp_heuristic_guess(tvb_get_ntohs(tvb, offset))) {
850 proto = PROTO_PPP;
853 ti = proto_tree_add_text (juniper_subtree, tvb, offset, 0, "[Cookie length: %u]",cookie_len);
854 offset += cookie_len;
856 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, proto, offset);
861 /* PPPoE dissector */
862 static void
863 dissect_juniper_pppoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
865 proto_item *ti;
866 guint offset;
867 int bytes_processed;
868 guint8 flags;
870 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper PPPoE");
871 col_clear(pinfo->cinfo, COL_INFO);
873 offset = 0;
875 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper PPPoE PIC");
877 /* parse header, match mgc, extract flags and build first tree */
878 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
880 if(bytes_processed == -1)
881 return;
882 else
883 offset+=bytes_processed;
885 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_ETHER, offset);
889 /* Ethernet dissector */
890 static void
891 dissect_juniper_ether(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
893 proto_item *ti;
894 guint offset;
895 int bytes_processed;
896 guint8 flags;
898 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper Ethernet");
899 col_clear(pinfo->cinfo, COL_INFO);
901 offset = 0;
903 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper Ethernet");
905 /* parse header, match mgc, extract flags and build first tree */
906 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
908 if(bytes_processed == -1)
909 return;
910 else
911 offset+=bytes_processed;
913 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_ETHER, offset);
917 /* PPP dissector */
918 static void
919 dissect_juniper_ppp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
921 proto_item *ti;
922 guint offset;
923 int bytes_processed;
924 guint8 flags;
926 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper PPP");
927 col_clear(pinfo->cinfo, COL_INFO);
929 offset = 0;
931 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper PPP");
933 /* parse header, match mgc, extract flags and build first tree */
934 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
936 if(bytes_processed == -1)
937 return;
938 else
939 offset+=bytes_processed;
941 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_PPP, offset+2);
945 /* Frame-Relay dissector */
946 static void
947 dissect_juniper_frelay(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
949 proto_item *ti;
950 guint offset;
951 int bytes_processed;
952 guint8 flags;
954 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper Frame-Relay");
955 col_clear(pinfo->cinfo, COL_INFO);
957 offset = 0;
959 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper Frame-Relay");
961 /* parse header, match mgc, extract flags and build first tree */
962 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
964 if(bytes_processed == -1)
965 return;
966 else
967 offset+=bytes_processed;
969 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_FRELAY, offset);
973 /* C-HDLC dissector */
974 static void
975 dissect_juniper_chdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
977 proto_item *ti;
978 guint offset = 0;
979 int bytes_processed;
980 guint8 flags;
982 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper C-HDLC");
983 col_clear(pinfo->cinfo, COL_INFO);
985 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper C-HDLC");
987 /* parse header, match mgc, extract flags and build first tree */
988 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
990 if(bytes_processed == -1)
991 return;
992 else
993 offset+=bytes_processed;
995 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_CHDLC, offset);
1001 /* wrapper for passing the PIC type to the generic ATM dissector */
1002 static void
1003 dissect_juniper_atm1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1005 dissect_juniper_atm(tvb,pinfo,tree, JUNIPER_PIC_ATM1);
1008 /* wrapper for passing the PIC type to the generic ATM dissector */
1009 static void
1010 dissect_juniper_atm2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1012 dissect_juniper_atm(tvb,pinfo,tree, JUNIPER_PIC_ATM2);
1015 /* generic ATM dissector */
1016 static void
1017 dissect_juniper_atm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 atm_pictype)
1019 proto_item *ti;
1020 guint8 next_proto = PROTO_UNKNOWN,atm1_header_len,atm2_header_len,flags;
1021 guint32 cookie1, proto;
1022 guint64 cookie2;
1023 guint offset = 0;
1024 int bytes_processed;
1025 tvbuff_t *next_tvb;
1027 col_clear(pinfo->cinfo, COL_INFO);
1029 switch (atm_pictype) {
1030 case JUNIPER_PIC_ATM1:
1031 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper ATM1");
1032 ti = proto_tree_add_text (tree, tvb, 0, 0 , "Juniper ATM1 PIC");
1033 break;
1034 case JUNIPER_PIC_ATM2:
1035 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper ATM2");
1036 ti = proto_tree_add_text (tree, tvb, 0, 0 , "Juniper ATM2 PIC");
1037 break;
1038 default: /* should not happen */
1039 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper ATM unknown");
1040 proto_tree_add_text (tree, tvb, 0, 0 , "Juniper unknown ATM PIC");
1041 return;
1044 /* parse header, match mgc, extract flags and build first tree */
1045 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
1046 if(bytes_processed == -1)
1047 return;
1048 else
1049 offset+=bytes_processed;
1051 if ((flags & JUNIPER_FLAG_NO_L2) == JUNIPER_FLAG_NO_L2) {
1052 atm1_header_len = 4;
1053 atm2_header_len = 4;
1055 else {
1056 atm1_header_len = 4;
1057 atm2_header_len = 8;
1060 cookie1 = tvb_get_ntohl(tvb, offset);
1061 cookie2 = tvb_get_ntoh64(tvb, offset);
1063 if (atm_pictype == JUNIPER_PIC_ATM1) {
1064 proto_tree_add_uint(juniper_subtree, hf_juniper_atm1_cookie, tvb, offset, 4, cookie1);
1065 offset += atm1_header_len;
1066 if ((cookie1 >> 24) == 0x80) /* OAM cell ? */
1067 next_proto = PROTO_OAM;
1069 else { /* JUNIPER_PIC_ATM2 */
1070 proto_tree_add_uint64(juniper_subtree, hf_juniper_atm2_cookie, tvb, offset, 8, cookie2);
1071 offset += atm2_header_len;
1072 if (cookie2 & 0x70) /* OAM cell ? */
1073 next_proto = PROTO_OAM;
1076 next_tvb = tvb_new_subset_remaining(tvb, offset);
1078 if (next_proto == PROTO_OAM) {
1079 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_OAM, offset);
1080 return;
1083 proto = tvb_get_ntoh24(tvb, offset); /* first try: 24-Bit guess */
1085 if (proto == JUNIPER_HDR_NLPID) {
1087 * This begins with something that appears to be an LLC header for
1088 * OSI; is this LLC-multiplexed traffic?
1090 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_LLC, offset);
1091 return;
1094 if (proto == JUNIPER_HDR_SNAP) {
1096 * This begins with something that appears to be an LLC header for
1097 * SNAP; is this LLC-multiplexed traffic?
1099 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_LLC_SNAP, offset);
1100 return;
1103 if ((flags & JUNIPER_FLAG_PKT_IN) != JUNIPER_FLAG_PKT_IN && /* ether-over-1483 encaps ? */
1104 (cookie1 & JUNIPER_ATM2_GAP_COUNT_MASK) &&
1105 atm_pictype != JUNIPER_PIC_ATM1) {
1106 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_ETHER, offset);
1107 return;
1110 proto = tvb_get_ntohs(tvb, offset); /* second try: 16-Bit guess */
1112 if ( ppp_heuristic_guess( (guint16) proto) &&
1113 atm_pictype != JUNIPER_PIC_ATM1) {
1115 * This begins with something that appears to be a PPP protocol
1116 * type; is this VC-multiplexed PPPoA?
1117 * That's not supported on ATM1 PICs.
1119 ti = proto_tree_add_text (juniper_subtree, tvb, offset, 0, "Encapsulation Type: VC-MUX");
1120 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_PPP , offset);
1121 return;
1124 proto = tvb_get_guint8(tvb, offset); /* third try: 8-Bit guess */
1126 if ( proto == JUNIPER_HDR_LLC_UI ) {
1128 * Cisco style NLPID encaps?
1129 * Is the 0x03 an LLC UI control field?
1131 ti = proto_tree_add_text (juniper_subtree, tvb, offset, 1, "Encapsulation Type: Cisco NLPID");
1132 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_ISO , offset+1);
1133 return;
1136 next_proto = ip_heuristic_guess( (guint8) proto);
1137 if (next_proto != PROTO_UNKNOWN) { /* last resort: VC-MUX encaps ? */
1139 * This begins with something that might be the first byte of
1140 * an IPv4 or IPv6 packet; is this VC-multiplexed IP?
1142 ti = proto_tree_add_text (juniper_subtree, tvb, offset, 0, "Encapsulation Type: VC-MUX");
1143 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, next_proto , offset);
1144 return;
1147 /* could not figure what it is */
1148 proto_tree_add_text (juniper_subtree, tvb, offset, -1, "Payload Type: unknown");
1149 call_dissector(data_handle, next_tvb, pinfo, tree);
1153 static void dissect_juniper_ggsn(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
1155 proto_item *ti;
1156 guint offset = 0;
1157 int bytes_processed;
1158 guint8 flags;
1159 guint16 proto;
1161 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper GGSN");
1162 col_clear(pinfo->cinfo, COL_INFO);
1164 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper GGSN");
1166 /* parse header, match mgc, extract flags and build first tree */
1167 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
1169 if(bytes_processed == -1)
1170 return;
1171 else
1172 offset+=bytes_processed;
1174 proto = tvb_get_letohs(tvb, offset); /* fetch protocol */
1176 proto_tree_add_uint(juniper_subtree, hf_juniper_proto, tvb, offset, 2, proto);
1177 proto_tree_add_item(juniper_subtree, hf_juniper_vlan, tvb, offset+2, 2, ENC_LITTLE_ENDIAN);
1178 offset += 4;
1180 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, proto, offset);
1184 static void dissect_juniper_vp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
1186 proto_item *ti;
1187 guint offset = 0;
1188 int bytes_processed;
1189 guint8 flags;
1191 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper Voice PIC");
1192 col_clear(pinfo->cinfo, COL_INFO);
1194 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper Voice PIC");
1196 /* parse header, match mgc, extract flags and build first tree */
1197 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
1199 if(bytes_processed == -1)
1200 return;
1201 else
1202 offset+=bytes_processed;
1205 * Right know IPv4 is the only protocol we may encounter.
1206 * For the future there should be sufficient space in the 18-byte
1207 * empty header before payload starts.
1209 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_IP, offset+18);
1212 /* Wrapper for Juniper service PIC coookie dissector */
1213 static void
1214 dissect_juniper_svcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1216 proto_item *ti;
1217 guint offset = 0;
1218 int bytes_processed = 0;
1219 guint8 flags;
1221 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper Services");
1222 col_clear(pinfo->cinfo, COL_INFO);
1224 ti = proto_tree_add_text (tree, tvb, 0, 4, "Juniper Services cookie");
1226 /* parse header, match mgc, extract flags and build first tree */
1227 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
1229 if (bytes_processed == -1)
1230 return;
1231 else
1232 offset+=bytes_processed;
1234 if (flags & JUNIPER_FLAG_PKT_IN) {
1235 proto_tree_add_uint(juniper_subtree, hf_juniper_proto, tvb, offset, 2, PROTO_IP);
1236 offset += 16;
1237 } else {
1238 offset += 12;
1241 dissect_juniper_payload_proto(tvb, pinfo, tree, ti, PROTO_IP, offset);
1244 /* list of Juniper supported PPP proto IDs */
1245 static gboolean
1246 ppp_heuristic_guess(guint16 proto) {
1248 switch(proto) {
1249 case PPP_IP :
1250 case PPP_OSI :
1251 case PPP_MPLS_UNI :
1252 case PPP_MPLS_MULTI :
1253 case PPP_IPCP :
1254 case PPP_OSINLCP :
1255 case PPP_MPLSCP :
1256 case PPP_LCP :
1257 case PPP_PAP :
1258 case PPP_CHAP :
1259 case PPP_MP :
1260 case PPP_IPV6 :
1261 case PPP_IPV6CP :
1262 return TRUE;
1264 default:
1265 return FALSE; /* did not find a ppp header */
1270 * return the IP version number based on the first byte of the IP header
1271 * returns 0 if it does not match a valid first IPv4/IPv6 header byte
1273 static guint
1274 ip_heuristic_guess(guint8 ip_header_byte) {
1276 switch(ip_header_byte) {
1277 case 0x45:
1278 case 0x46:
1279 case 0x47:
1280 case 0x48:
1281 case 0x49:
1282 case 0x4a:
1283 case 0x4b:
1284 case 0x4c:
1285 case 0x4d:
1286 case 0x4e:
1287 case 0x4f:
1288 return PROTO_IP;
1289 case 0x60:
1290 case 0x61:
1291 case 0x62:
1292 case 0x63:
1293 case 0x64:
1294 case 0x65:
1295 case 0x66:
1296 case 0x67:
1297 case 0x68:
1298 case 0x69:
1299 case 0x6a:
1300 case 0x6b:
1301 case 0x6c:
1302 case 0x6d:
1303 case 0x6e:
1304 case 0x6f:
1305 return PROTO_IP6;
1306 default:
1307 return PROTO_UNKNOWN; /* did not find a ip header */
1311 /* return cookie length dep. on cookie SVC id */
1312 static
1313 guint juniper_svc_cookie_len (guint64 cookie) {
1315 guint8 svc_cookie_id;
1316 svc_cookie_id = (guint8)(cookie >> 56) & 0xff;
1318 switch(svc_cookie_id) {
1319 case 0x54:
1320 return LS_PIC_COOKIE_LEN;
1321 case GSP_SVC_REQ_APOLLO:
1322 case GSP_SVC_REQ_LSQ:
1323 return AS_PIC_COOKIE_LEN;
1324 default:
1325 return 0;
1329 /* return the next-level protocol based on cookie input */
1330 static guint
1331 juniper_svc_cookie_proto (guint64 cookie, guint16 pictype, guint8 flags) {
1333 guint8 svc_cookie_id;
1334 guint16 lsq_proto;
1335 guint8 lsq_dir;
1337 svc_cookie_id = (guint8)(cookie >> 56) & 0xff;
1338 lsq_proto = (guint16)((cookie >> 16) & LSQ_L3_PROTO_MASK);
1339 lsq_dir = (guint8)(cookie >> 24) & 0x3;
1342 switch (svc_cookie_id) {
1343 case 0x54:
1344 switch (pictype) {
1345 case JUNIPER_PIC_MLPPP:
1346 return PROTO_PPP;
1347 case JUNIPER_PIC_MLFR:
1348 return PROTO_ISO;
1349 default:
1350 return PROTO_UNKNOWN;
1352 case GSP_SVC_REQ_APOLLO:
1353 case GSP_SVC_REQ_LSQ:
1354 switch(lsq_proto) {
1355 case LSQ_L3_PROTO_IPV4:
1356 switch(pictype) {
1357 case JUNIPER_PIC_MLPPP:
1358 /* incoming traffic would have the direction bits set
1359 * -> this must be IS-IS over PPP
1361 if ((flags & JUNIPER_FLAG_PKT_IN) == JUNIPER_FLAG_PKT_IN &&
1362 lsq_dir != (LSQ_COOKIE_RE|LSQ_COOKIE_DIR))
1363 return PROTO_PPP;
1364 else
1365 return PROTO_IP;
1366 case JUNIPER_PIC_MLFR:
1367 if (lsq_dir == (LSQ_COOKIE_RE|LSQ_COOKIE_DIR))
1368 return PROTO_UNKNOWN;
1369 else
1370 return PROTO_IP;
1371 default:
1372 return PROTO_UNKNOWN;
1374 case LSQ_L3_PROTO_IPV6:
1375 return PROTO_IP6;
1376 case LSQ_L3_PROTO_MPLS:
1377 return PROTO_MPLS;
1378 case LSQ_L3_PROTO_ISO:
1379 return PROTO_ISO;
1380 default:
1381 return PROTO_UNKNOWN;
1383 default:
1384 return PROTO_UNKNOWN;
1389 void
1390 proto_register_juniper(void)
1392 static hf_register_info hf[] = {
1393 #if 0
1394 { &hf_juniper_magic,
1395 { "Magic Number", "juniper.magic-number", FT_UINT24, BASE_HEX,
1396 NULL, 0x0, NULL, HFILL }},
1397 #endif
1398 { &hf_juniper_direction,
1399 { "Direction", "juniper.direction", FT_UINT8, BASE_HEX,
1400 VALS(juniper_direction_vals), 0x0, NULL, HFILL }},
1401 { &hf_juniper_l2hdr_presence,
1402 { "L2 header presence", "juniper.l2hdr", FT_UINT8, BASE_HEX,
1403 VALS(juniper_l2hdr_presence_vals), 0x0, NULL, HFILL }},
1404 { &hf_juniper_ext_total_len,
1405 { "Extension(s) Total length", "juniper.ext_total_len", FT_UINT16, BASE_DEC,
1406 NULL, 0x0, NULL, HFILL }},
1407 { &hf_juniper_atm2_cookie,
1408 { "Cookie", "juniper.atm2.cookie", FT_UINT64, BASE_HEX,
1409 NULL, 0x0, NULL, HFILL }},
1410 { &hf_juniper_atm1_cookie,
1411 { "Cookie", "juniper.atm1.cookie", FT_UINT32, BASE_HEX,
1412 NULL, 0x0, NULL, HFILL }},
1413 { &hf_juniper_mlpic_cookie,
1414 { "Cookie", "juniper.mlpic.cookie", FT_UINT16, BASE_HEX,
1415 NULL, 0x0, NULL, HFILL }},
1416 { &hf_juniper_lspic_cookie,
1417 { "Cookie", "juniper.lspic.cookie", FT_UINT32, BASE_HEX,
1418 NULL, 0x0, NULL, HFILL }},
1419 { &hf_juniper_aspic_cookie,
1420 { "Cookie", "juniper.aspic.cookie", FT_UINT64, BASE_HEX,
1421 NULL, 0x0, NULL, HFILL }},
1422 { &hf_juniper_vlan,
1423 { "VLan ID", "juniper.vlan", FT_UINT16, BASE_DEC,
1424 NULL, 0x0, NULL, HFILL }},
1425 { &hf_juniper_proto,
1426 { "Protocol", "juniper.proto", FT_UINT16, BASE_DEC,
1427 VALS(juniper_proto_vals), 0x0, NULL, HFILL }},
1428 { &hf_juniper_ext_ifd,
1429 /* Juniper PCAP extensions */
1430 { "Device Interface Index", "juniper.ext.ifd", FT_UINT32, BASE_DEC,
1431 NULL, 0x0, NULL, HFILL }},
1432 { &hf_juniper_ext_ifl,
1433 { "Logical Interface Index", "juniper.ext.ifl", FT_UINT32, BASE_DEC,
1434 NULL, 0x0, NULL, HFILL }},
1435 { &hf_juniper_ext_unit,
1436 { "Logical Unit Number", "juniper.ext.unit", FT_UINT32, BASE_DEC,
1437 NULL, 0x0, NULL, HFILL }},
1438 { &hf_juniper_ext_ifmt,
1439 { "Device Media Type", "juniper.ext.ifmt", FT_UINT16, BASE_DEC,
1440 VALS(juniper_ifmt_vals), 0x0, NULL, HFILL }},
1441 { &hf_juniper_ext_ifle,
1442 { "Logical Interface Encapsulation", "juniper.ext.ifle", FT_UINT16, BASE_DEC,
1443 VALS(juniper_ifle_vals), 0x0, NULL, HFILL }},
1444 { &hf_juniper_ext_ttp_ifmt,
1445 { "TTP derived Device Media Type", "juniper.ext.ttp_ifmt", FT_UINT16, BASE_DEC,
1446 VALS(juniper_ifmt_vals), 0x0, NULL, HFILL }},
1447 { &hf_juniper_ext_ttp_ifle,
1448 { "TTP derived Logical Interface Encapsulation", "juniper.ext.ttp_ifle", FT_UINT16, BASE_DEC,
1449 VALS(juniper_ifle_vals), 0x0, NULL, HFILL }},
1452 static gint *ett[] = {
1453 &ett_juniper,
1456 proto_juniper = proto_register_protocol("Juniper", "Juniper", "juniper");
1457 proto_register_field_array(proto_juniper, hf, array_length(hf));
1458 proto_register_subtree_array(ett, array_length(ett));
1462 void
1463 proto_reg_handoff_juniper(void)
1465 dissector_handle_t juniper_atm1_handle;
1466 dissector_handle_t juniper_atm2_handle;
1467 dissector_handle_t juniper_pppoe_handle;
1468 dissector_handle_t juniper_mlppp_handle;
1469 dissector_handle_t juniper_mlfr_handle;
1470 dissector_handle_t juniper_ether_handle;
1471 dissector_handle_t juniper_ppp_handle;
1472 dissector_handle_t juniper_frelay_handle;
1473 dissector_handle_t juniper_chdlc_handle;
1474 dissector_handle_t juniper_ggsn_handle;
1475 dissector_handle_t juniper_vp_handle;
1476 dissector_handle_t juniper_svcs_handle;
1478 osinl_incl_subdissector_table = find_dissector_table("osinl.incl");
1479 osinl_excl_subdissector_table = find_dissector_table("osinl.excl");
1481 eth_handle = find_dissector("eth_withoutfcs");
1482 ppp_handle = find_dissector("ppp");
1483 llc_handle = find_dissector("llc");
1484 ipv4_handle = find_dissector("ip");
1485 ipv6_handle = find_dissector("ipv6");
1486 mpls_handle = find_dissector("mpls");
1487 q933_handle = find_dissector("q933");
1488 frelay_handle = find_dissector("fr");
1489 chdlc_handle = find_dissector("chdlc");
1490 data_handle = find_dissector("data");
1492 juniper_atm2_handle = create_dissector_handle(dissect_juniper_atm2, proto_juniper);
1493 juniper_atm1_handle = create_dissector_handle(dissect_juniper_atm1, proto_juniper);
1494 juniper_pppoe_handle = create_dissector_handle(dissect_juniper_pppoe, proto_juniper);
1495 juniper_mlppp_handle = create_dissector_handle(dissect_juniper_mlppp, proto_juniper);
1496 juniper_mlfr_handle = create_dissector_handle(dissect_juniper_mlfr, proto_juniper);
1497 juniper_ether_handle = create_dissector_handle(dissect_juniper_ether, proto_juniper);
1498 juniper_ppp_handle = create_dissector_handle(dissect_juniper_ppp, proto_juniper);
1499 juniper_frelay_handle = create_dissector_handle(dissect_juniper_frelay, proto_juniper);
1500 juniper_chdlc_handle = create_dissector_handle(dissect_juniper_chdlc, proto_juniper);
1501 juniper_ggsn_handle = create_dissector_handle(dissect_juniper_ggsn, proto_juniper);
1502 juniper_vp_handle = create_dissector_handle(dissect_juniper_vp, proto_juniper);
1503 juniper_svcs_handle = create_dissector_handle(dissect_juniper_svcs, proto_juniper);
1505 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_ATM2, juniper_atm2_handle);
1506 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_ATM1, juniper_atm1_handle);
1507 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_PPPOE, juniper_pppoe_handle);
1508 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_MLPPP, juniper_mlppp_handle);
1509 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_MLFR, juniper_mlfr_handle);
1510 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_ETHER, juniper_ether_handle);
1511 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_PPP, juniper_ppp_handle);
1512 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_FRELAY, juniper_frelay_handle);
1513 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_CHDLC, juniper_chdlc_handle);
1514 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_GGSN, juniper_ggsn_handle);
1515 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_VP, juniper_vp_handle);
1516 dissector_add_uint("wtap_encap", WTAP_ENCAP_JUNIPER_SVCS, juniper_svcs_handle);