Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

eapol.c 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. *
  38. * This function takes ownership of the I/O buffer passed to it.
  39. */
  40. static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
  41. const void *ll_dest, const void *ll_source ) {
  42. struct eapol_frame *eapol = iob->data;
  43. struct eapol_handler *handler;
  44. if ( iob_len ( iob ) < EAPOL_HDR_LEN ) {
  45. free_iob ( iob );
  46. return -EINVAL;
  47. }
  48. for_each_table_entry ( handler, EAPOL_HANDLERS ) {
  49. if ( handler->type == eapol->type ) {
  50. iob_pull ( iob, EAPOL_HDR_LEN );
  51. return handler->rx ( iob, netdev, ll_dest, ll_source );
  52. }
  53. }
  54. free_iob ( iob );
  55. return -( ENOTSUP | ( ( eapol->type & 0x1f ) << 8 ) );
  56. }
  57. /**
  58. * Transcribe EAPOL network-layer address
  59. *
  60. * @v net_addr Network-layer address
  61. * @ret str String representation of network-layer address
  62. *
  63. * EAPOL doesn't have network-layer addresses, so we just return the
  64. * string @c "<EAPOL>".
  65. */
  66. static const char * eapol_ntoa ( const void *net_addr __unused )
  67. {
  68. return "<EAPOL>";
  69. }
  70. /** EAPOL network protocol */
  71. struct net_protocol eapol_protocol __net_protocol = {
  72. .name = "EAPOL",
  73. .rx = eapol_rx,
  74. .ntoa = eapol_ntoa,
  75. .net_proto = htons ( ETH_P_EAPOL ),
  76. };