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., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 /** @file
00022  *
00023  * 802.1X Extensible Authentication Protocol over LANs demultiplexer
00024  *
00025  */
00026 
00027 #include <gpxe/netdevice.h>
00028 #include <gpxe/iobuf.h>
00029 #include <gpxe/if_ether.h>
00030 #include <gpxe/eapol.h>
00031 #include <errno.h>
00032 #include <byteswap.h>
00033 
00034 /**
00035  * Receive EAPOL network-layer packet
00036  *
00037  * @v iob       I/O buffer
00038  * @v netdev    Network device
00039  * @v ll_source Link-layer source address
00040  *
00041  * This function takes ownership of the I/O buffer passed to it.
00042  */
00043 static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
00044                       const void *ll_source )
00045 {
00046         struct eapol_frame *eapol = iob->data;
00047         struct eapol_handler *handler;
00048 
00049         if ( iob_len ( iob ) < EAPOL_HDR_LEN ) {
00050                 free_iob ( iob );
00051                 return -EINVAL;
00052         }
00053 
00054         for_each_table_entry ( handler, EAPOL_HANDLERS ) {
00055                 if ( handler->type == eapol->type ) {
00056                         iob_pull ( iob, EAPOL_HDR_LEN );
00057                         return handler->rx ( iob, netdev, ll_source );
00058                 }
00059         }
00060 
00061         free_iob ( iob );
00062         return -( ENOTSUP | ( ( eapol->type & 0x1f ) << 8 ) );
00063 }
00064 
00065 /**
00066  * Transcribe EAPOL network-layer address
00067  *
00068  * @v net_addr  Network-layer address
00069  * @ret str     String representation of network-layer address
00070  *
00071  * EAPOL doesn't have network-layer addresses, so we just return the
00072  * string @c "<EAPOL>".
00073  */
00074 static const char * eapol_ntoa ( const void *net_addr __unused )
00075 {
00076         return "<EAPOL>";
00077 }
00078 
00079 /** EAPOL network protocol */
00080 struct net_protocol eapol_protocol __net_protocol = {
00081         .name = "EAPOL",
00082         .rx = eapol_rx,
00083         .ntoa = eapol_ntoa,
00084         .net_proto = htons ( ETH_P_EAPOL ),
00085 };

Generated on Tue Apr 6 20:01:10 2010 for gPXE by  doxygen 1.5.7.1