iPXE
ethernet.h
Go to the documentation of this file.
00001 #ifndef _IPXE_ETHERNET_H
00002 #define _IPXE_ETHERNET_H
00003 
00004 /** @file
00005  *
00006  * Ethernet protocol
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/netdevice.h>
00014 #include <ipxe/iobuf.h>
00015 
00016 /**
00017  * Check if Ethernet address is all zeroes
00018  *
00019  * @v addr              Ethernet address
00020  * @ret is_zero         Address is all zeroes
00021  */
00022 static inline int is_zero_ether_addr ( const void *addr ) {
00023         const uint8_t *addr_bytes = addr;
00024 
00025         return ( ! ( addr_bytes[0] | addr_bytes[1] | addr_bytes[2] |
00026                      addr_bytes[3] | addr_bytes[4] | addr_bytes[5] ) );
00027 }
00028 
00029 /**
00030  * Check if Ethernet address is a multicast address
00031  *
00032  * @v addr              Ethernet address
00033  * @ret is_mcast        Address is a multicast address
00034  *
00035  * Note that the broadcast address is also a multicast address.
00036  */
00037 static inline int is_multicast_ether_addr ( const void *addr ) {
00038         const uint8_t *addr_bytes = addr;
00039 
00040         return ( addr_bytes[0] & 0x01 );
00041 }
00042 
00043 /**
00044  * Check if Ethernet address is locally assigned
00045  *
00046  * @v addr              Ethernet address
00047  * @ret is_local        Address is locally assigned
00048  */
00049 static inline int is_local_ether_addr ( const void *addr ) {
00050         const uint8_t *addr_bytes = addr;
00051 
00052         return ( addr_bytes[0] & 0x02 );
00053 }
00054 
00055 /**
00056  * Check if Ethernet address is the broadcast address
00057  *
00058  * @v addr              Ethernet address
00059  * @ret is_bcast        Address is the broadcast address
00060  */
00061 static inline int is_broadcast_ether_addr ( const void *addr ) {
00062         const uint8_t *addr_bytes = addr;
00063 
00064         return ( ( addr_bytes[0] & addr_bytes[1] & addr_bytes[2] &
00065                    addr_bytes[3] & addr_bytes[4] & addr_bytes[5] ) == 0xff );
00066 }
00067 
00068 /**
00069  * Check if Ethernet address is valid
00070  *
00071  * @v addr              Ethernet address
00072  * @ret is_valid        Address is valid
00073  *
00074  * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is
00075  * not a multicast address, and is not ff:ff:ff:ff:ff:ff.
00076  */
00077 static inline int is_valid_ether_addr ( const void *addr ) {
00078         return ( ( ! is_multicast_ether_addr ( addr ) ) &&
00079                  ( ! is_zero_ether_addr ( addr ) ) );
00080 }
00081 
00082 extern uint8_t eth_broadcast[];
00083 extern struct ll_protocol ethernet_protocol __ll_protocol;
00084 
00085 extern int eth_push ( struct net_device *netdev, struct io_buffer *iobuf,
00086                       const void *ll_dest, const void *ll_source,
00087                       uint16_t net_proto );
00088 extern int eth_pull ( struct net_device *netdev, struct io_buffer *iobuf,
00089                       const void **ll_dest, const void **ll_source,
00090                       uint16_t *net_proto, unsigned int *flags );
00091 extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
00092 extern void eth_random_addr ( void *hw_addr );
00093 extern const char * eth_ntoa ( const void *ll_addr );
00094 extern int eth_mc_hash ( unsigned int af, const void *net_addr,
00095                          void *ll_addr );
00096 extern int eth_eth_addr ( const void *ll_addr, void *eth_addr );
00097 extern int eth_eui64 ( const void *ll_addr, void *eui64 );
00098 extern struct net_device * alloc_etherdev ( size_t priv_size );
00099 
00100 #endif /* _IPXE_ETHERNET_H */