iPXE
eapol.c
Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 FILE_LICENCE ( GPL2_OR_LATER );
21 
22 /** @file
23  *
24  * 802.1X Extensible Authentication Protocol over LANs demultiplexer
25  *
26  */
27 
28 #include <ipxe/netdevice.h>
29 #include <ipxe/iobuf.h>
30 #include <ipxe/if_ether.h>
31 #include <ipxe/eapol.h>
32 #include <errno.h>
33 #include <byteswap.h>
34 
35 /**
36  * Receive EAPOL network-layer packet
37  *
38  * @v iob I/O buffer
39  * @v netdev Network device
40  * @v ll_dest Link-layer destination address
41  * @v ll_source Link-layer source address
42  * @v flags Packet flags
43  *
44  * This function takes ownership of the I/O buffer passed to it.
45  */
46 static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
47  const void *ll_dest, const void *ll_source,
48  unsigned int flags __unused ) {
49  struct eapol_frame *eapol = iob->data;
50  struct eapol_handler *handler;
51 
52  if ( iob_len ( iob ) < EAPOL_HDR_LEN ) {
53  free_iob ( iob );
54  return -EINVAL;
55  }
56 
58  if ( handler->type == eapol->type ) {
59  iob_pull ( iob, EAPOL_HDR_LEN );
60  return handler->rx ( iob, netdev, ll_dest, ll_source );
61  }
62  }
63 
64  free_iob ( iob );
65  return -( ENOTSUP | ( ( eapol->type & 0x1f ) << 8 ) );
66 }
67 
68 /**
69  * Transcribe EAPOL network-layer address
70  *
71  * @v net_addr Network-layer address
72  * @ret str String representation of network-layer address
73  *
74  * EAPOL doesn't have network-layer addresses, so we just return the
75  * string @c "<EAPOL>".
76  */
77 static const char * eapol_ntoa ( const void *net_addr __unused )
78 {
79  return "<EAPOL>";
80 }
81 
82 /** EAPOL network protocol */
83 struct net_protocol eapol_protocol __net_protocol = {
84  .name = "EAPOL",
85  .rx = eapol_rx,
86  .ntoa = eapol_ntoa,
87  .net_proto = htons ( ETH_P_EAPOL ),
88 };
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
#define EINVAL
Invalid argument.
Definition: errno.h:428
const char * name
Protocol name.
Definition: netdevice.h:66
struct net_protocol eapol_protocol __net_protocol
EAPOL network protocol.
Definition: eapol.c:83
An EAPOL frame.
Definition: eapol.h:63
Error codes.
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
static int eapol_rx(struct io_buffer *iob, struct net_device *netdev, const void *ll_dest, const void *ll_source, unsigned int flags __unused)
Receive EAPOL network-layer packet.
Definition: eapol.c:46
#define EAPOL_HANDLERS
Definition: eapol.h:107
#define EAPOL_HDR_LEN
Length of an EAPOL frame header.
Definition: eapol.h:55
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
int(* rx)(struct io_buffer *iob, struct net_device *netdev, const void *ll_dest, const void *ll_source)
Receive EAPOL-encapsulated packet of specified type.
Definition: eapol.h:103
static struct net_device * netdev
Definition: gdbudp.c:52
Definitions for EAPOL (Extensible Authentication Protocol over LANs) frames.
FILE_LICENCE(GPL2_OR_LATER)
An EAPOL frame type handler.
Definition: eapol.h:85
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
A network device.
Definition: netdevice.h:348
u8 type
EAPOL archetype identifier indicating format of payload.
Definition: eapol.h:69
A network-layer protocol.
Definition: netdevice.h:64
Network device management.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
static const char * eapol_ntoa(const void *net_addr __unused)
Transcribe EAPOL network-layer address.
Definition: eapol.c:77
void * data
Start of data.
Definition: iobuf.h:44
#define ETH_P_EAPOL
Definition: if_ether.h:24
#define htons(value)
Definition: byteswap.h:135
A persistent I/O buffer.
Definition: iobuf.h:32
uint8_t flags
Flags.
Definition: ena.h:18
u8 type
EAPOL archetype identifier for payload this handler will handle.
Definition: eapol.h:88