ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Ethereal-dev: [Ethereal-dev] Add dissector for 802.1QinQ

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "杜丙尧" <dubingyao@xxxxxxxxx>
Date: Fri, 30 Jun 2006 02:07:54 +0800
Hi list,

I write a dessector for 802.1QinQ packets,whose ethertype field values is 0x9100 (default).
I hope it will be added in the next version.

This attachments  are source files.
 
Some Requirement:
 
 * The IEEE 802.1Q-in-Q VLAN Tag is purpose to expand the VLAN space
 * by tagging the tagged packets,thus producing a "double-tagged" frame.
 * The expanded VLAN space allows the service provider to provide certain
 * services,such as Internet access on specific VLANs for specific customers,
 * and yet still allows the service provider to provide other types of
 * services for their other customers on other VLANs.
 
 
Thanks.
DuBingyao
/* packet-qinq.c
 * Routines for VLAN 802.1QinQ ethernet header disassembly
 * (c) Copyright DuBingyao <dubingyao@xxxxxxxxx>
 *
 * $Id$
 *
 * The IEEE 802.1Q-in-Q VLAN Tag is purpose to expand the VLAN space 
 * by tagging the tagged packets,thus producing a "double-tagged" frame.
 * The expanded VLAN space allows the service provider to provide certain
 * services,such as Internet access on specific VLANs for specific customers,
 * and yet still allows the service provider to provide other types of 
 * services for their other customers on other VLANs.
 * 
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@xxxxxxxxxxxx>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <glib.h>
#include <epan/packet.h>
#include "packet-ieee8023.h"
#include "packet-ipx.h"
#include "packet-llc.h"
#include "packet-qinq.h"
#include <epan/etypes.h>

static int proto_qinq = -1;
static int hf_qinq_priority = -1;
static int hf_qinq_cfi = -1;
static int hf_qinq_id = -1;
static int hf_qinq_etype = -1;
static int hf_qinq_len = -1;
static int hf_qinq_trailer = -1;

static gint ett_qinq = -1;

void
capture_qinq(const guchar *pd, int offset, int len, packet_counts *ld ) {
  guint16 encap_proto;
  if ( !BYTES_ARE_IN_FRAME(offset,len,5) ) {
    ld->other++;
    return;
  }
  encap_proto = pntohs( &pd[offset+2] );
  if ( encap_proto <= IEEE_802_3_MAX_LEN) {
    if ( pd[offset+4] == 0xff && pd[offset+5] == 0xff ) {
      capture_ipx(ld);
    } else {
      capture_llc(pd,offset+4,len,ld);
    }
  } else {
    capture_ethertype(encap_proto, pd, offset+4, len, ld);
  }
}

static void
dissect_qinq(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_tree *ti;
  guint16 tci,encap_proto;
  volatile gboolean is_802_2;
  proto_tree *volatile qinq_tree;

  if (check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "QINQ");
  if (check_col(pinfo->cinfo, COL_INFO))
    col_clear(pinfo->cinfo, COL_INFO);

  tci = tvb_get_ntohs( tvb, 0 );

  if (check_col(pinfo->cinfo, COL_INFO)) {
    col_add_fstr(pinfo->cinfo, COL_INFO, "PRI: %d  CFI: %d  ID: %d",
      (tci >> 13), ((tci >> 12) & 1), (tci & 0xFFF));
  }
  if ( check_col(pinfo->cinfo, COL_8021Q_VLAN_ID)) {
      col_add_fstr(pinfo->cinfo, COL_8021Q_VLAN_ID, "%u", (tci & 0xFFF));
  }

  qinq_tree = NULL;

  if (tree) {
    ti = proto_tree_add_item(tree, proto_qinq, tvb, 0, 4, FALSE);
    qinq_tree = proto_item_add_subtree(ti, ett_qinq);

    proto_tree_add_uint(qinq_tree, hf_qinq_priority, tvb, 0, 2, tci);
    proto_tree_add_uint(qinq_tree, hf_qinq_cfi, tvb, 0, 2, tci);
    proto_tree_add_uint(qinq_tree, hf_qinq_id, tvb, 0, 2, tci);
  }

  encap_proto = tvb_get_ntohs(tvb, 2);
  if (encap_proto <= IEEE_802_3_MAX_LEN) {
    /* Is there an 802.2 layer? I can tell by looking at the first 2
       bytes after the VLAN header. If they are 0xffff, then what
       follows the VLAN header is an IPX payload, meaning no 802.2.
       (IPX/SPX is they only thing that can be contained inside a
       straight 802.3 packet, so presumably the same applies for
       Ethernet VLAN packets). A non-0xffff value means that there's an
       802.2 layer inside the VLAN layer */
    is_802_2 = TRUE;
    TRY {
	    if (tvb_get_ntohs(tvb, 4) == 0xffff) {
	      is_802_2 = FALSE;
	    }
    }
    CATCH2(BoundsError, ReportedBoundsError) {
	    ; /* do nothing */

    }
    ENDTRY;

    dissect_802_3(encap_proto, is_802_2, tvb, 4, pinfo, tree, qinq_tree,
		  hf_qinq_len, hf_qinq_trailer, 0);
  } else {
    ethertype(encap_proto, tvb, 4, pinfo, tree, qinq_tree,
		       hf_qinq_etype, hf_qinq_trailer, 0);
  }
}

void
proto_register_qinq(void)
{
  static hf_register_info hf[] = {
	{ &hf_qinq_priority, {
		"Priority", "qinq.priority", FT_UINT16, BASE_DEC,
		0, 0xE000, "Priority", HFILL }},
	{ &hf_qinq_cfi, {
		"CFI", "qinq.cfi", FT_UINT16, BASE_DEC,
		0, 0x1000, "CFI", HFILL }},	/* XXX - Boolean? */
	{ &hf_qinq_id, {
		"ID", "qinq.id", FT_UINT16, BASE_DEC,
		0, 0x0FFF, "ID", HFILL }},
	{ &hf_qinq_etype, {
		"Type", "qinq.etype", FT_UINT16, BASE_HEX,
		VALS(etype_vals), 0x0, "Type", HFILL }},
	{ &hf_qinq_len, {
		"Length", "qinq.len", FT_UINT16, BASE_DEC,
		NULL, 0x0, "Length", HFILL }},
	{ &hf_qinq_trailer, {
		"Trailer", "qinq.trailer", FT_BYTES, BASE_NONE,
		NULL, 0x0, "QinQ Trailer", HFILL }}
  };
  static gint *ett[] = {
	&ett_qinq,
  };

  proto_qinq = proto_register_protocol("802.1QinQ Virtual LAN", "QinQ", "qinq");
  proto_register_field_array(proto_qinq, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_qinq(void)
{
  dissector_handle_t qinq_handle;

  qinq_handle = create_dissector_handle(dissect_qinq, proto_qinq);
  dissector_add("ethertype", ETHERTYPE_QINQ, qinq_handle);
}
/* packet-qinq.h
 *
 * $Id$
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@xxxxxxxxxxxx>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifndef __PACKET_QINQ_H__
#define __PACKET_QINQ_H__

void capture_qinq(const guchar *, int, int, packet_counts *);

#endif
505a506
> 	packet-qinq.c	\
74a75
>     {ETHERTYPE_QINQ,				"802.1QinQ Virtual LAN"		},
150a152,154
>     case ETHERTYPE_QINQ:
>       capture_qinq(pd, offset, len, ld);
>       break;
170a171,174
> #ifndef ETHERTYPE_QINQ
> #define ETHERTYPE_QINQ		0x9100	/* 802.1QinQ Virtual LAN */
> #endif
> 
2446a2447
> 	802.1QinQ dissection
_______________________________________________
Ethereal-dev mailing list
Ethereal-dev@xxxxxxxxxxxx
http://www.ethereal.com/mailman/listinfo/ethereal-dev