Browse Source

[eapol] Add basic support for 802.1X EAP over LANs

EAPOL is a container protocol that can wrap either EAP packets or
802.11 EAPOL-Key frames. For cleanliness' sake, add a stub that strips
the framing and sends packets off to the appropriate handler if it
is compiled in.

Signed-off-by: Marty Connor <mdc@etherboot.org>
tags/v1.0.0-rc1
Joshua Oreman 15 years ago
parent
commit
432cc6d1d8
4 changed files with 199 additions and 0 deletions
  1. 112
    0
      src/include/gpxe/eapol.h
  2. 1
    0
      src/include/gpxe/errfile.h
  3. 1
    0
      src/include/gpxe/if_ether.h
  4. 85
    0
      src/net/eapol.c

+ 112
- 0
src/include/gpxe/eapol.h View File

@@ -0,0 +1,112 @@
1
+/*
2
+ * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef _GPXE_EAPOL_H
20
+#define _GPXE_EAPOL_H
21
+
22
+/** @file
23
+ *
24
+ * Definitions for EAPOL (Extensible Authentication Protocol over
25
+ * LANs) frames. Definitions for the packets usually encapsulated in
26
+ * them are elsewhere.
27
+ */
28
+
29
+#include <gpxe/tables.h>
30
+#include <stdint.h>
31
+
32
+FILE_LICENCE ( GPL2_OR_LATER );
33
+
34
+
35
+/**
36
+ * @defgroup eapol_type EAPOL archetype identifiers
37
+ * @{
38
+ */
39
+#define EAPOL_TYPE_EAP		0 /**< EAP authentication handshake packet */
40
+#define EAPOL_TYPE_START	1 /**< Request by Peer to begin (no data) */
41
+#define EAPOL_TYPE_LOGOFF	2 /**< Request by Peer to terminate (no data) */
42
+#define EAPOL_TYPE_KEY		3 /**< EAPOL-Key packet */
43
+/** @} */
44
+
45
+/** Expected EAPOL version field value
46
+ *
47
+ * Version 2 is often seen and has no format differences from version 1;
48
+ * however, many older APs will completely drop version-2 packets, so
49
+ * we advertise ourselves as version 1.
50
+ */
51
+#define EAPOL_THIS_VERSION	1
52
+
53
+/** Length of an EAPOL frame header */
54
+#define EAPOL_HDR_LEN		4
55
+
56
+/** An EAPOL frame
57
+ *
58
+ * This may encapsulate an eap_pkt, an eapol_key_pkt, or a Start or
59
+ * Logoff request with no data attached. It is transmitted directly in
60
+ * an Ethernet frame, with no IP packet header.
61
+ */
62
+struct eapol_frame
63
+{
64
+	/** EAPOL version identifier, always 1 */
65
+	u8 version;
66
+
67
+	/** EAPOL archetype identifier indicating format of payload */
68
+	u8 type;
69
+
70
+	/** Length of payload, in network byte order */
71
+	u16 length;
72
+
73
+	/** Payload, if @a type is EAP or EAPOL-Key */
74
+	u8 data[0];
75
+} __attribute__ (( packed ));
76
+
77
+
78
+/** An EAPOL frame type handler
79
+ *
80
+ * Normally there will be at most two of these, one for EAP and one
81
+ * for EAPOL-Key frames. The EAPOL interface code handles Start and
82
+ * Logoff directly.
83
+ */
84
+struct eapol_handler
85
+{
86
+	/** EAPOL archetype identifier for payload this handler will handle */
87
+	u8 type;
88
+
89
+	/** Receive EAPOL-encapsulated packet of specified type
90
+	 *
91
+	 * @v iob	I/O buffer containing packet payload
92
+	 * @v netdev	Network device from which packet was received
93
+	 * @v ll_source	Source link-layer address from which packet was received
94
+	 * @ret rc	Return status code
95
+	 *
96
+	 * The I/O buffer will have the EAPOL header pulled off it, so
97
+	 * @c iob->data points to the first byte of the payload.
98
+	 *
99
+	 * This function takes ownership of the I/O buffer passed to it.
100
+	 */
101
+	int ( * rx ) ( struct io_buffer *iob, struct net_device *netdev,
102
+		       const void *ll_source );
103
+};
104
+
105
+#define EAPOL_HANDLERS	__table ( struct eapol_handler, "eapol_handlers" )
106
+#define __eapol_handler	__table_entry ( EAPOL_HANDLERS, 01 )
107
+
108
+
109
+extern struct net_protocol eapol_protocol __net_protocol;
110
+
111
+
112
+#endif /* _GPXE_EAPOL_H */

+ 1
- 0
src/include/gpxe/errfile.h View File

@@ -160,6 +160,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
160 160
 #define ERRFILE_ib_srp			( ERRFILE_NET | 0x00220000 )
161 161
 #define ERRFILE_sec80211		( ERRFILE_NET | 0x00230000 )
162 162
 #define ERRFILE_wep			( ERRFILE_NET | 0x00240000 )
163
+#define ERRFILE_eapol			( ERRFILE_NET | 0x00250000 )
163 164
 
164 165
 #define ERRFILE_image		      ( ERRFILE_IMAGE | 0x00000000 )
165 166
 #define ERRFILE_elf		      ( ERRFILE_IMAGE | 0x00010000 )

+ 1
- 0
src/include/gpxe/if_ether.h View File

@@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
20 20
 #define ETH_P_RARP	0x8035	/* Reverse Address resolution Protocol */
21 21
 #define ETH_P_IPV6	0x86DD	/* IPv6 over blueblook */
22 22
 #define ETH_P_SLOW	0x8809	/* Ethernet slow protocols */
23
+#define ETH_P_EAPOL	0x888E	/* 802.1X EAP over LANs */
23 24
 #define ETH_P_AOE	0x88A2	/* ATA over Ethernet */
24 25
 
25 26
 /** An Ethernet link-layer header */

+ 85
- 0
src/net/eapol.c View File

@@ -0,0 +1,85 @@
1
+/*
2
+ * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+/** @file
22
+ *
23
+ * 802.1X Extensible Authentication Protocol over LANs demultiplexer
24
+ *
25
+ */
26
+
27
+#include <gpxe/netdevice.h>
28
+#include <gpxe/iobuf.h>
29
+#include <gpxe/if_ether.h>
30
+#include <gpxe/eapol.h>
31
+#include <errno.h>
32
+#include <byteswap.h>
33
+
34
+/**
35
+ * Receive EAPOL network-layer packet
36
+ *
37
+ * @v iob	I/O buffer
38
+ * @v netdev	Network device
39
+ * @v ll_source	Link-layer source address
40
+ *
41
+ * This function takes ownership of the I/O buffer passed to it.
42
+ */
43
+static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
44
+		      const void *ll_source )
45
+{
46
+	struct eapol_frame *eapol = iob->data;
47
+	struct eapol_handler *handler;
48
+
49
+	if ( iob_len ( iob ) < EAPOL_HDR_LEN ) {
50
+		free_iob ( iob );
51
+		return -EINVAL;
52
+	}
53
+
54
+	for_each_table_entry ( handler, EAPOL_HANDLERS ) {
55
+		if ( handler->type == eapol->type ) {
56
+			iob_pull ( iob, EAPOL_HDR_LEN );
57
+			return handler->rx ( iob, netdev, ll_source );
58
+		}
59
+	}
60
+
61
+	free_iob ( iob );
62
+	return -( ENOTSUP | ( ( eapol->type & 0x1f ) << 8 ) );
63
+}
64
+
65
+/**
66
+ * Transcribe EAPOL network-layer address
67
+ *
68
+ * @v net_addr	Network-layer address
69
+ * @ret str	String representation of network-layer address
70
+ *
71
+ * EAPOL doesn't have network-layer addresses, so we just return the
72
+ * string @c "<EAPOL>".
73
+ */
74
+static const char * eapol_ntoa ( const void *net_addr __unused )
75
+{
76
+	return "<EAPOL>";
77
+}
78
+
79
+/** EAPOL network protocol */
80
+struct net_protocol eapol_protocol __net_protocol = {
81
+	.name = "EAPOL",
82
+	.rx = eapol_rx,
83
+	.ntoa = eapol_ntoa,
84
+	.net_proto = htons ( ETH_P_EAPOL ),
85
+};

Loading…
Cancel
Save