Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / net / eapol.c
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
57         for_each_table_entry ( handler, EAPOL_HANDLERS ) {
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 };