Ethereal-dev: [Ethereal-dev] Patch for IEEE 802.1x aka EAPOL + EAP

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

From: Pekka Nikander <pekka.nikander@xxxxxxxxxxxxxx>
Date: Tue, 06 Nov 2001 14:11:51 +0200
Enclosed a patch to add IEEE 802.1x aka EAPOL
plus PPP/EAPOL EAP support to Ethereal.
This has been tested only with EAPOL, I don't
have the ability to test PPP/EAP to see if
that works.

I hope somebody with commit access to the
CVS tree can commit this into the tree.
I am personally not on the list, so mail
me directly if you have something to ask.

--Pekka Nikander
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ethereal/Makefile.am,v
retrieving revision 1.375
diff -u -r1.375 Makefile.am
--- Makefile.am	2001/11/04 22:19:22	1.375
+++ Makefile.am	2001/11/06 12:00:55
@@ -108,6 +108,8 @@
 	packet-dns.c   \
 	packet-dsi.c   \
 	packet-dvmrp.c \
+	packet-eap.c \
+	packet-eapol.c \
 	packet-eigrp.c \
 	packet-esis.c  \
 	packet-eth.c   \
Index: Makefile.nmake
===================================================================
RCS file: /cvsroot/ethereal/Makefile.nmake,v
retrieving revision 1.136
diff -u -r1.136 Makefile.nmake
--- Makefile.nmake	2001/11/04 22:19:22	1.136
+++ Makefile.nmake	2001/11/06 12:00:55
@@ -59,6 +59,8 @@
 	packet-dns.c   \
 	packet-dsi.c   \
 	packet-dvmrp.c \
+	packet-eapol.c \
+	packet-eap.c \
 	packet-eigrp.c \
 	packet-esis.c  \
 	packet-eth.c   \
Index: etypes.h
===================================================================
RCS file: /cvsroot/ethereal/etypes.h,v
retrieving revision 1.21
diff -u -r1.21 etypes.h
--- etypes.h	2001/06/14 20:37:07	1.21
+++ etypes.h	2001/11/06 12:00:55
@@ -164,6 +164,10 @@
 #define ETHERTYPE_PPPOES	0x8864	/* PPPoE Session Protocol */
 #endif
 
+#ifndef ETHERTYPE_EAPOL
+#define ETHERTYPE_EAPOL 	0x888e  /* 802.1x Authentication */
+#endif
+
 #ifndef ETHERTYPE_LOOP
 #define ETHERTYPE_LOOP		0x9000 	/* used for layer 2 testing (do i see my own frames on the wire) */
 #endif
Index: packet-ethertype.c
===================================================================
RCS file: /cvsroot/ethereal/packet-ethertype.c,v
retrieving revision 1.18
diff -u -r1.18 packet-ethertype.c
--- packet-ethertype.c	2001/06/16 00:54:33	1.18
+++ packet-ethertype.c	2001/11/06 12:00:56
@@ -61,6 +61,7 @@
     {ETHERTYPE_PPPOED,		"PPPoE Discovery"		}, 
     {ETHERTYPE_PPPOES,		"PPPoE Session"			}, 
     {ETHERTYPE_VLAN,		"802.1Q Virtual LAN"		},
+    {ETHERTYPE_EAPOL,		"802.1X Authentication"         },
     {ETHERTYPE_MPLS,		"MPLS label switched packet"	},
     {ETHERTYPE_MPLS_MULTI,	"MPLS multicast label switched packet" },
     {ETHERTYPE_3C_NBP_DGRAM,	"3Com NBP Datagram"		},
Index: packet-eapol.c
===================================================================
diff -u packet-eapol.c
--- packet-eapol.c	Tue Nov  6 13:56:17 2001
+++ packet-eapol.c	Tue Nov  6 13:55:54 2001
@@ -0,0 +1,141 @@
+/* packet-eapol.c
+ * Routines for EAPOL 802.1X authentication header disassembly
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@xxxxxxxx>
+ * 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
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+
+#include <glib.h>
+#include "packet.h"
+#include "packet-ieee8023.h"
+#include "packet-ipx.h"
+#include "packet-llc.h"
+#include "etypes.h"
+
+static int proto_eapol = -1;
+static int hf_eapol_version = -1;
+static int hf_eapol_type = -1;
+static int hf_eapol_len = -1;
+
+static gint ett_eapol = -1;
+
+typedef struct _e_eapol
+{
+    guint8 eapol_ver;
+    guint8 eapol_type;
+    guint16 eapol_len;
+} e_eapol;
+
+static const char *eapol_type_name[] = { 
+    "EAP",
+    "Start",
+    "Logoff",
+    "Key",
+    "Encapsulated ASF Alert"
+};
+#define EAPOL_TYPE_COUNT (sizeof(eapol_type_name)/sizeof(eapol_type_name[0]))
+
+extern void dissect_eap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
+
+static void
+dissect_eapol(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+  e_eapol     eapolh;
+  guint       len;
+  proto_tree *ti;
+  proto_tree *volatile eapol_tree;
+  tvbuff_t   *next_tvb;
+
+  if (check_col(pinfo->fd, COL_PROTOCOL))
+    col_set_str(pinfo->fd, COL_PROTOCOL, "EAPOL");
+  if (check_col(pinfo->fd, COL_INFO))
+    col_clear(pinfo->fd, COL_INFO);
+
+  tvb_memcpy(tvb, (guint8 *)&eapolh, 0, sizeof(eapolh));
+  eapolh.eapol_len = ntohs(eapolh.eapol_len);
+
+  len = sizeof(eapolh) + eapolh.eapol_len;
+
+  set_actual_length(tvb, pinfo, len);
+
+  eapol_tree = NULL;
+
+  if (tree) {
+    ti = proto_tree_add_item(tree, proto_eapol, tvb, 0, len, FALSE);
+    eapol_tree = proto_item_add_subtree(ti, ett_eapol);
+
+    proto_tree_add_uint(eapol_tree, hf_eapol_version, tvb, 0, 1, eapolh.eapol_ver);
+    proto_tree_add_text(eapol_tree, tvb, 1, 1, "Type: %s (%d)", 
+			eapolh.eapol_type > EAPOL_TYPE_COUNT?
+			"Unknown" : eapol_type_name[eapolh.eapol_type],
+			eapolh.eapol_type);
+    proto_tree_add_uint(eapol_tree, hf_eapol_len,    tvb, 2, 2, eapolh.eapol_len);
+  }
+
+  next_tvb = tvb_new_subset(tvb, 4, -1, -1);
+
+  if (eapolh.eapol_type == 0 && next_tvb != NULL) 
+      dissect_eap(next_tvb, pinfo, eapol_tree);
+  else
+      dissect_data(tvb, 4, pinfo, tree);
+}
+
+void
+proto_register_eapol(void)
+{
+  static hf_register_info hf[] = {
+	{ &hf_eapol_version, { 
+		"Version", "eapol.version", FT_UINT8, BASE_DEC, 
+		NULL, 0x0, "", HFILL }},
+	{ &hf_eapol_type, { 
+		"Type", "eapol.type", FT_UINT8, BASE_DEC, 
+		0, 0x0, "", HFILL }},
+	{ &hf_eapol_len, {
+		"Length", "eapol.len", FT_UINT16, BASE_DEC,
+		NULL, 0x0, "Length", HFILL }},
+  };
+  static gint *ett[] = {
+	&ett_eapol,
+  };
+
+  proto_eapol = proto_register_protocol("802.1x Authentication", "EAPOL", "eapol");
+  proto_register_field_array(proto_eapol, hf, array_length(hf));
+  proto_register_subtree_array(ett, array_length(ett));
+}
+
+void
+proto_reg_handoff_eapol(void)
+{
+  dissector_add("ethertype", ETHERTYPE_EAPOL, dissect_eapol, proto_eapol);
+}
+
Index: packet-eap.c
===================================================================
diff -u packet-eap.c
--- packet-eap.c	Tue Nov  6 13:56:17 2001
+++ packet-eap.c	Tue Nov  6 13:55:33 2001
@@ -0,0 +1,157 @@
+/* packet-eap.c
+ * Routines for EAP Extensible Authentication Protocol header disassembly
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@xxxxxxxx>
+ * 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
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+
+#include <glib.h>
+#include "packet.h"
+#include "packet-ieee8023.h"
+#include "packet-ipx.h"
+#include "packet-llc.h"
+#include "etypes.h"
+#include "ppptypes.h"
+
+static int proto_eap = -1;
+static int hf_eap_code = -1;
+static int hf_eap_identifier = -1;
+static int hf_eap_len = -1;
+static int hf_eap_type = -1;
+
+static gint ett_eap = -1;
+
+typedef struct _e_eap {
+    guint8 eap_code;
+    guint8 eap_id;
+    guint16 eap_len;
+} e_eap;
+
+static const char *eap_code_name[] = { 
+    "Undefined",
+    "Request",
+    "Response",
+    "Success",
+    "Failure",
+};
+#define EAP_CODE_COUNT (sizeof(eap_code_name)/sizeof(eap_code_name[0]))
+
+static const char *eap_type_name[] = { 
+    "Undefined",
+    "Identity",
+    "Nak (Response only)",
+    "MD5-Challenge",
+    "One-Time Password",
+    "Generic Token Card",
+};
+#define EAP_TYPE_COUNT (sizeof(eap_type_name)/sizeof(eap_type_name[0]))
+
+
+void
+dissect_eap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+  e_eap       eaph;
+  guint       len;
+  proto_tree *ti;
+  proto_tree *volatile eap_tree;
+
+  if (check_col(pinfo->fd, COL_PROTOCOL))
+    col_set_str(pinfo->fd, COL_PROTOCOL, "EAP");
+  if (check_col(pinfo->fd, COL_INFO))
+    col_clear(pinfo->fd, COL_INFO);
+
+  tvb_memcpy(tvb, (guint8 *)&eaph, 0, sizeof(eaph));
+  eaph.eap_len = ntohs(eaph.eap_len);
+
+  len = eaph.eap_len;
+
+  set_actual_length(tvb, pinfo, len);
+
+  eap_tree = NULL;
+
+  if (tree) {
+    ti = proto_tree_add_item(tree, proto_eap, tvb, 0, len, FALSE);
+    eap_tree = proto_item_add_subtree(ti, ett_eap);
+
+    proto_tree_add_text(eap_tree, tvb, 0, 0, "Code: %s (%d) ", 
+			eaph.eap_code > EAP_CODE_COUNT?
+			"Unknown": eap_code_name[eaph.eap_code],
+			eaph.eap_code);
+
+    proto_tree_add_uint(eap_tree, hf_eap_identifier, tvb, 1, 1, eaph.eap_id);
+    proto_tree_add_uint(eap_tree, hf_eap_len,    tvb, 2, 2, eaph.eap_len);
+
+    if (len > 4) {
+	guint8 eap_type = tvb_get_guint8(tvb, 4);
+	proto_tree_add_text(eap_tree, tvb, 4, 1, "Type: %s (%d)", 
+			    eap_type > EAP_TYPE_COUNT?
+			    "Unknown" : eap_type_name[eap_type],
+			    eap_type);
+    }
+    if (len > 5)
+      dissect_data(tvb, 5, pinfo, tree);
+  }
+}
+
+void
+proto_register_eap(void)
+{
+  static hf_register_info hf[] = {
+	{ &hf_eap_code, { 
+		"Code", "eap.code", FT_UINT8, BASE_DEC, 
+		NULL, 0x0, "", HFILL }},
+	{ &hf_eap_identifier, {
+		"Id", "eap.id", FT_UINT8, BASE_DEC,
+		NULL, 0x0, "", HFILL }},
+	{ &hf_eap_len, {
+		"Length", "eap.len", FT_UINT16, BASE_DEC,
+		NULL, 0x0, "", HFILL }},
+	{ &hf_eap_type, { 
+		"Type", "eap.type", FT_UINT8, BASE_DEC, 
+		NULL, 0x0, "", HFILL }},
+  };
+  static gint *ett[] = {
+	&ett_eap,
+  };
+
+  proto_eap = proto_register_protocol("Extensible Authentication Protocol", 
+				      "EAP", "eap");
+  proto_register_field_array(proto_eap, hf, array_length(hf));
+  proto_register_subtree_array(ett, array_length(ett));
+}
+
+void
+proto_reg_handoff_eap(void)
+{
+  dissector_add("ppp.protocol", PPP_EAP, dissect_eap, proto_eap);
+}