iPXE
eapol.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  */
00019 
00020 FILE_LICENCE ( GPL2_OR_LATER );
00021 
00022 /** @file
00023  *
00024  * 802.1X Extensible Authentication Protocol over LANs demultiplexer
00025  *
00026  */
00027 
00028 #include <ipxe/netdevice.h>
00029 #include <ipxe/iobuf.h>
00030 #include <ipxe/if_ether.h>
00031 #include <ipxe/eapol.h>
00032 #include <errno.h>
00033 #include <byteswap.h>
00034 
00035 /**
00036  * Receive EAPOL network-layer packet
00037  *
00038  * @v iob       I/O buffer
00039  * @v netdev    Network device
00040  * @v ll_dest   Link-layer destination address
00041  * @v ll_source Link-layer source address
00042  * @v flags     Packet flags
00043  *
00044  * This function takes ownership of the I/O buffer passed to it.
00045  */
00046 static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
00047                       const void *ll_dest, const void *ll_source,
00048                       unsigned int flags __unused ) {
00049         struct eapol_frame *eapol = iob->data;
00050         struct eapol_handler *handler;
00051 
00052         if ( iob_len ( iob ) < EAPOL_HDR_LEN ) {
00053                 free_iob ( iob );
00054                 return -EINVAL;
00055         }
00056 
00057         for_each_table_entry ( handler, EAPOL_HANDLERS ) {
00058                 if ( handler->type == eapol->type ) {
00059                         iob_pull ( iob, EAPOL_HDR_LEN );
00060                         return handler->rx ( iob, netdev, ll_dest, ll_source );
00061                 }
00062         }
00063 
00064         free_iob ( iob );
00065         return -( ENOTSUP | ( ( eapol->type & 0x1f ) << 8 ) );
00066 }
00067 
00068 /**
00069  * Transcribe EAPOL network-layer address
00070  *
00071  * @v net_addr  Network-layer address
00072  * @ret str     String representation of network-layer address
00073  *
00074  * EAPOL doesn't have network-layer addresses, so we just return the
00075  * string @c "<EAPOL>".
00076  */
00077 static const char * eapol_ntoa ( const void *net_addr __unused )
00078 {
00079         return "<EAPOL>";
00080 }
00081 
00082 /** EAPOL network protocol */
00083 struct net_protocol eapol_protocol __net_protocol = {
00084         .name = "EAPOL",
00085         .rx = eapol_rx,
00086         .ntoa = eapol_ntoa,
00087         .net_proto = htons ( ETH_P_EAPOL ),
00088 };