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.

ethernet.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef _IPXE_ETHERNET_H
  2. #define _IPXE_ETHERNET_H
  3. /** @file
  4. *
  5. * Ethernet protocol
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/netdevice.h>
  11. #include <ipxe/iobuf.h>
  12. /**
  13. * Check if Ethernet address is all zeroes
  14. *
  15. * @v addr Ethernet address
  16. * @ret is_zero Address is all zeroes
  17. */
  18. static inline int is_zero_ether_addr ( const void *addr ) {
  19. const uint8_t *addr_bytes = addr;
  20. return ( ! ( addr_bytes[0] | addr_bytes[1] | addr_bytes[2] |
  21. addr_bytes[3] | addr_bytes[4] | addr_bytes[5] ) );
  22. }
  23. /**
  24. * Check if Ethernet address is a multicast address
  25. *
  26. * @v addr Ethernet address
  27. * @ret is_mcast Address is a multicast address
  28. *
  29. * Note that the broadcast address is also a multicast address.
  30. */
  31. static inline int is_multicast_ether_addr ( const void *addr ) {
  32. const uint8_t *addr_bytes = addr;
  33. return ( addr_bytes[0] & 0x01 );
  34. }
  35. /**
  36. * Check if Ethernet address is locally assigned
  37. *
  38. * @v addr Ethernet address
  39. * @ret is_local Address is locally assigned
  40. */
  41. static inline int is_local_ether_addr ( const void *addr ) {
  42. const uint8_t *addr_bytes = addr;
  43. return ( addr_bytes[0] & 0x02 );
  44. }
  45. /**
  46. * Check if Ethernet address is the broadcast address
  47. *
  48. * @v addr Ethernet address
  49. * @ret is_bcast Address is the broadcast address
  50. */
  51. static inline int is_broadcast_ether_addr ( const void *addr ) {
  52. const uint8_t *addr_bytes = addr;
  53. return ( ( addr_bytes[0] & addr_bytes[1] & addr_bytes[2] &
  54. addr_bytes[3] & addr_bytes[4] & addr_bytes[5] ) == 0xff );
  55. }
  56. /**
  57. * Check if Ethernet address is valid
  58. *
  59. * @v addr Ethernet address
  60. * @ret is_valid Address is valid
  61. *
  62. * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is
  63. * not a multicast address, and is not ff:ff:ff:ff:ff:ff.
  64. */
  65. static inline int is_valid_ether_addr ( const void *addr ) {
  66. return ( ( ! is_multicast_ether_addr ( addr ) ) &&
  67. ( ! is_zero_ether_addr ( addr ) ) );
  68. }
  69. extern uint8_t eth_broadcast[];
  70. extern struct ll_protocol ethernet_protocol __ll_protocol;
  71. extern int eth_push ( struct net_device *netdev, struct io_buffer *iobuf,
  72. const void *ll_dest, const void *ll_source,
  73. uint16_t net_proto );
  74. extern int eth_pull ( struct net_device *netdev, struct io_buffer *iobuf,
  75. const void **ll_dest, const void **ll_source,
  76. uint16_t *net_proto, unsigned int *flags );
  77. extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
  78. extern void eth_random_addr ( void *hw_addr );
  79. extern const char * eth_ntoa ( const void *ll_addr );
  80. extern int eth_mc_hash ( unsigned int af, const void *net_addr,
  81. void *ll_addr );
  82. extern int eth_eth_addr ( const void *ll_addr, void *eth_addr );
  83. extern int eth_eui64 ( const void *ll_addr, void *eui64 );
  84. extern struct net_device * alloc_etherdev ( size_t priv_size );
  85. #endif /* _IPXE_ETHERNET_H */