You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

eapol.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. FILE_LICENCE ( GPL2_OR_LATER );
  19. /** @file
  20. *
  21. * 802.1X Extensible Authentication Protocol over LANs demultiplexer
  22. *
  23. */
  24. #include <ipxe/netdevice.h>
  25. #include <ipxe/iobuf.h>
  26. #include <ipxe/if_ether.h>
  27. #include <ipxe/eapol.h>
  28. #include <errno.h>
  29. #include <byteswap.h>
  30. /**
  31. * Receive EAPOL network-layer packet
  32. *
  33. * @v iob I/O buffer
  34. * @v netdev Network device
  35. * @v ll_dest Link-layer destination address
  36. * @v ll_source Link-layer source address
  37. * @v flags Packet flags
  38. *
  39. * This function takes ownership of the I/O buffer passed to it.
  40. */
  41. static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
  42. const void *ll_dest, const void *ll_source,
  43. unsigned int flags __unused ) {
  44. struct eapol_frame *eapol = iob->data;
  45. struct eapol_handler *handler;
  46. if ( iob_len ( iob ) < EAPOL_HDR_LEN ) {
  47. free_iob ( iob );
  48. return -EINVAL;
  49. }
  50. for_each_table_entry ( handler, EAPOL_HANDLERS ) {
  51. if ( handler->type == eapol->type ) {
  52. iob_pull ( iob, EAPOL_HDR_LEN );
  53. return handler->rx ( iob, netdev, ll_dest, ll_source );
  54. }
  55. }
  56. free_iob ( iob );
  57. return -( ENOTSUP | ( ( eapol->type & 0x1f ) << 8 ) );
  58. }
  59. /**
  60. * Transcribe EAPOL network-layer address
  61. *
  62. * @v net_addr Network-layer address
  63. * @ret str String representation of network-layer address
  64. *
  65. * EAPOL doesn't have network-layer addresses, so we just return the
  66. * string @c "<EAPOL>".
  67. */
  68. static const char * eapol_ntoa ( const void *net_addr __unused )
  69. {
  70. return "<EAPOL>";
  71. }
  72. /** EAPOL network protocol */
  73. struct net_protocol eapol_protocol __net_protocol = {
  74. .name = "EAPOL",
  75. .rx = eapol_rx,
  76. .ntoa = eapol_ntoa,
  77. .net_proto = htons ( ETH_P_EAPOL ),
  78. };