2 * Routines for Juniper Networks, Inc. packet disassembly
3 * Copyright 2005 Hannes Gredler <hannes@juniper.net>
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/packet.h>
33 #include <epan/prefs.h>
34 #include <epan/addr_resolv.h>
36 #include "packet-ppp.h"
37 #include "packet-ip.h"
39 #define JUNIPER_FLAG_PKT_OUT 0x00 /* Outgoing packet */
40 #define JUNIPER_FLAG_PKT_IN 0x01 /* Incoming packet */
41 #define JUNIPER_FLAG_NO_L2 0x02 /* L2 header stripped */
42 #define JUNIPER_ATM2_PKT_TYPE_MASK 0x70
43 #define JUNIPER_ATM2_GAP_COUNT_MASK 0x3F
44 #define JUNIPER_PCAP_MAGIC 0x4d4743
46 #define JUNIPER_ATM1 1
47 #define JUNIPER_ATM2 2
49 #define JUNIPER_HDR_SNAP 0xaaaa03
50 #define JUNIPER_HDR_NLPID 0xfefe03
51 #define JUNIPER_HDR_CNLPID 0x03
53 static const value_string juniper_direction_vals[] = {
54 {JUNIPER_FLAG_PKT_OUT, "Out"},
55 {JUNIPER_FLAG_PKT_IN, "In"},
59 static const value_string juniper_l2hdr_presence_vals[] = {
65 static int proto_juniper = -1;
67 static int hf_juniper_magic = -1;
68 static int hf_juniper_direction = -1;
69 static int hf_juniper_l2hdr_presence = -1;
70 static int hf_juniper_atm1_cookie = -1;
71 static int hf_juniper_atm2_cookie = -1;
73 static gint ett_juniper = -1;
75 static dissector_handle_t ipv4_handle;
76 static dissector_handle_t ipv6_handle;
77 static dissector_handle_t llc_handle;
78 static dissector_handle_t eth_handle;
79 static dissector_handle_t ppp_handle;
80 static dissector_handle_t data_handle;
82 static dissector_table_t osinl_subdissector_table;
83 static dissector_table_t osinl_excl_subdissector_table;
85 int dissect_juniper_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *ti, guint8 *flags);
86 static void dissect_juniper_atm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 atm_pictype);
87 static gboolean ppp_heuristic_guess(guint16 proto);
88 static guint ip_heuristic_guess(guint8 ip_header_byte);
90 /* generic juniper header dissector */
92 dissect_juniper_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *ti, guint8 *flags)
95 proto_tree *subtree = NULL;
96 guint8 direction,l2hdr_presence,ipvers;
101 magic_number = tvb_get_ntoh24(tvb, 0);
102 *flags = tvb_get_guint8(tvb, 3);
103 direction = *flags & JUNIPER_FLAG_PKT_IN;
104 l2hdr_presence = *flags & JUNIPER_FLAG_NO_L2;
106 subtree = proto_item_add_subtree(ti, ett_juniper);
107 tisub = proto_tree_add_text (subtree, tvb, 0, 3,
108 "Magic-Number: 0x%06x (%scorrect)",
110 (magic_number == JUNIPER_PCAP_MAGIC) ? "" : "in" );
112 if (magic_number != JUNIPER_PCAP_MAGIC)
115 tisub = proto_tree_add_uint_format (subtree, hf_juniper_direction, tvb, 3, 1,
116 direction, "Direction: %s",
117 val_to_str(direction,juniper_direction_vals,"Unknown"));
119 tisub = proto_tree_add_uint_format (subtree, hf_juniper_l2hdr_presence, tvb, 3, 1,
120 l2hdr_presence, "L2-header: %s",
121 val_to_str(l2hdr_presence,juniper_l2hdr_presence_vals,"Unknown"));
123 if ((*flags & JUNIPER_FLAG_NO_L2) == JUNIPER_FLAG_NO_L2) { /* no link header present ? */
124 next_tvb = tvb_new_subset(tvb, 8, -1, -1);
125 ipvers = ip_heuristic_guess(tvb_get_guint8(tvb, 8)); /* try IP */
127 ti = proto_tree_add_text (subtree, tvb, 8, 0,
128 "Payload Type: Null encapsulation IPv%u",
132 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
135 call_dissector(ipv4_handle, next_tvb, pinfo, tree);
142 return 4; /* 4 bytes parsed */
147 /* PPPoE dissector */
149 dissect_juniper_pppoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
152 proto_tree *subtree = NULL;
158 if (check_col(pinfo->cinfo, COL_PROTOCOL))
159 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper PPPoE");
160 if (check_col(pinfo->cinfo, COL_INFO))
161 col_clear(pinfo->cinfo, COL_INFO);
165 ti = proto_tree_add_text (tree, tvb, offset, 4, "Juniper PPPoE PIC");
166 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
168 /* parse header, match mgc, extract flags and build first tree */
169 if(bytes_processed == -1)
172 offset+=bytes_processed;
174 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
176 ti = proto_tree_add_text (subtree, tvb, offset, 0, "Payload Type: Ethernet");
177 call_dissector(eth_handle, next_tvb, pinfo, tree);
182 /* wrapper for passing the PIC type to the generic ATM dissector */
184 dissect_juniper_atm1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
186 dissect_juniper_atm(tvb,pinfo,tree, JUNIPER_ATM1);
189 /* wrapper for passing the PIC type to the generic ATM dissector */
191 dissect_juniper_atm2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
193 dissect_juniper_atm(tvb,pinfo,tree, JUNIPER_ATM2);
196 /* generic ATM dissector */
198 dissect_juniper_atm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 atm_pictype)
200 proto_item *ti,*tisub;
201 proto_tree *subtree = NULL;
202 guint8 ipvers,atm1_header_len,atm2_header_len,flags;
203 guint32 cookie1, proto;
209 switch (atm_pictype) {
211 if (check_col(pinfo->cinfo, COL_PROTOCOL))
212 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper ATM1");
215 if (check_col(pinfo->cinfo, COL_PROTOCOL))
216 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper ATM2");
218 default: /* should not happen */
219 if (check_col(pinfo->cinfo, COL_PROTOCOL))
220 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Juniper ATM unknown");
225 if (check_col(pinfo->cinfo, COL_INFO))
226 col_clear(pinfo->cinfo, COL_INFO);
228 switch (atm_pictype) {
230 ti = proto_tree_add_text (tree, tvb, 0, 4 , "Juniper ATM1 PIC");
233 ti = proto_tree_add_text (tree, tvb, 0, 4 , "Juniper ATM2 PIC");
235 default: /* should not happen */
236 ti = proto_tree_add_text (tree, tvb, 0, 0 , "Juniper unknown ATM PIC");
240 subtree = proto_item_add_subtree(ti, ett_juniper);
241 /* parse header, match mgc, extract flags and build first tree */
242 bytes_processed = dissect_juniper_header(tvb, pinfo, tree, ti, &flags);
243 if(bytes_processed == -1)
246 offset+=bytes_processed;
248 if ((flags & JUNIPER_FLAG_NO_L2) == JUNIPER_FLAG_NO_L2) {
257 cookie1 = tvb_get_ntohl(tvb,4);
258 cookie2 = tvb_get_ntoh64(tvb,4);
260 switch (atm_pictype) {
262 tisub = proto_tree_add_uint(subtree, hf_juniper_atm1_cookie, tvb, 4, 4, cookie1);
263 offset += atm1_header_len;
266 tisub = proto_tree_add_uint64(subtree, hf_juniper_atm2_cookie, tvb, 4, 8, cookie2);
267 offset += atm2_header_len;
269 default: /* should not happen */
273 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
275 /* FIXME OAM cells */
277 proto = tvb_get_ntoh24(tvb, offset); /* first try: 24-Bit guess */
279 if (proto == JUNIPER_HDR_NLPID) {
281 * This begins with something that appears to be an LLC header for
282 * OSI; is this LLC-multiplexed traffic?
284 ti = proto_tree_add_text (subtree, tvb, offset, 0, "Payload Type: LLC/NLPID ");
285 call_dissector(llc_handle, next_tvb, pinfo, tree);
289 if (proto == JUNIPER_HDR_SNAP) {
291 * This begins with something that appears to be an LLC header for
292 * SNAP; is this LLC-multiplexed traffic?
294 ti = proto_tree_add_text (subtree, tvb, offset, 0, "Payload Type: LLC/SNAP ");
295 call_dissector(llc_handle, next_tvb, pinfo, tree);
299 if ((flags & JUNIPER_FLAG_PKT_IN) != JUNIPER_FLAG_PKT_IN && /* ether-over-1483 encaps ? */
300 (cookie1 & JUNIPER_ATM2_GAP_COUNT_MASK) &&
301 atm_pictype != JUNIPER_ATM1) {
302 ti = proto_tree_add_text (subtree, tvb, offset, 0, "Payload Type: Ethernet");
303 call_dissector(eth_handle, next_tvb, pinfo, tree);
307 proto = tvb_get_ntohs(tvb, offset); /* second try: 16-Bit guess */
309 if ( ppp_heuristic_guess( (guint16) proto) &&
310 atm_pictype != JUNIPER_ATM1) {
312 * This begins with something that appears to be a PPP protocol
313 * type; is this VC-multiplexed PPPoA?
314 * That's not supported on ATM1 PICs.
316 ti = proto_tree_add_text (subtree, tvb, offset, 0, "Payload Type: VC-MUX PPP");
317 call_dissector(ppp_handle, next_tvb, pinfo, tree);
321 proto = tvb_get_guint8(tvb, offset); /* third try: 8-Bit guess */
323 if ( proto == JUNIPER_HDR_CNLPID ) {
325 * Cisco style NLPID encaps?
326 * Is the 0x03 an LLC UI control field?
328 ti = proto_tree_add_text (subtree, tvb, offset, 1, "Payload Type: Cisco NLPID");
329 proto = tvb_get_guint8(tvb, offset+1);
330 if(dissector_try_port(osinl_subdissector_table, proto, next_tvb, pinfo, tree))
332 next_tvb = tvb_new_subset(tvb, offset+2, -1, -1);
333 if(dissector_try_port(osinl_excl_subdissector_table, proto, next_tvb, pinfo, tree))
337 ipvers = ip_heuristic_guess( (guint8) proto);
338 if (ipvers != 0) { /* last resort: VC-MUX encaps ? */
340 * This begins with something that might be the first byte of
341 * an IPv4 or IPv6 packet; is this VC-multiplexed IP?
343 ti = proto_tree_add_text (subtree, tvb, offset, 0,
344 "Payload Type: VC-MUX IPv%u",
348 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
351 call_dissector(ipv4_handle, next_tvb, pinfo, tree);
357 /* could not figure what it is */
358 ti = proto_tree_add_text (subtree, tvb, offset, -1, "Payload Type: unknown");
359 call_dissector(data_handle, next_tvb, pinfo, tree);
362 /* list of Juniper supported PPP proto IDs */
364 ppp_heuristic_guess(guint16 proto) {
370 case PPP_MPLS_MULTI :
384 return FALSE; /* did not find a ppp header */
390 * return the IP version number based on the first byte of the IP header
391 * returns 0 if it does not match a valid first IPv4/IPv6 header byte
394 ip_heuristic_guess(guint8 ip_header_byte) {
396 switch(ip_header_byte) {
429 return 0; /* did not find a ip header */
434 proto_register_juniper(void)
436 static hf_register_info hf[] = {
438 { "Magic Number", "juniper.magic-number", FT_UINT24, BASE_HEX,
439 NULL, 0x0, "", HFILL }},
440 { &hf_juniper_direction,
441 { "Direction", "juniper.direction", FT_UINT8, BASE_HEX,
442 VALS(juniper_direction_vals), 0x0, "", HFILL }},
443 { &hf_juniper_l2hdr_presence,
444 { "L2 header presence", "juniper.l2hdr", FT_UINT8, BASE_HEX,
445 VALS(juniper_l2hdr_presence_vals), 0x0, "", HFILL }},
446 { &hf_juniper_atm2_cookie,
447 { "Cookie", "juniper.atm2.cookie", FT_UINT64, BASE_HEX,
448 NULL, 0x0, "", HFILL }},
449 { &hf_juniper_atm1_cookie,
450 { "Cookie", "juniper.atm1.cookie", FT_UINT32, BASE_HEX,
451 NULL, 0x0, "", HFILL }},
454 static gint *ett[] = {
458 proto_juniper = proto_register_protocol("Juniper", "Juniper", "juniper");
459 proto_register_field_array(proto_juniper, hf, array_length(hf));
460 proto_register_subtree_array(ett, array_length(ett));
465 proto_reg_handoff_juniper(void)
467 dissector_handle_t juniper_atm1_handle;
468 dissector_handle_t juniper_atm2_handle;
469 dissector_handle_t juniper_pppoe_handle;
471 osinl_subdissector_table = find_dissector_table("osinl");
472 osinl_excl_subdissector_table = find_dissector_table("osinl.excl");
473 eth_handle = find_dissector("eth_withoutfcs");
474 ppp_handle = find_dissector("ppp");
475 llc_handle = find_dissector("llc");
476 ipv4_handle = find_dissector("ip");
477 ipv6_handle = find_dissector("ipv6");
478 data_handle = find_dissector("data");
480 juniper_atm2_handle = create_dissector_handle(dissect_juniper_atm2, proto_juniper);
481 juniper_atm1_handle = create_dissector_handle(dissect_juniper_atm1, proto_juniper);
482 juniper_pppoe_handle = create_dissector_handle(dissect_juniper_pppoe, proto_juniper);
483 dissector_add("wtap_encap", WTAP_ENCAP_JUNIPER_ATM2, juniper_atm2_handle);
484 dissector_add("wtap_encap", WTAP_ENCAP_JUNIPER_ATM1, juniper_atm1_handle);
485 dissector_add("wtap_encap", WTAP_ENCAP_JUNIPER_PPPOE, juniper_pppoe_handle);