1 #ifndef _IPXE_ETHERNET_H
2 #define _IPXE_ETHERNET_H
10 FILE_LICENCE ( GPL2_OR_LATER );
13 #include <ipxe/netdevice.h>
14 #include <ipxe/iobuf.h>
17 * Check if Ethernet address is all zeroes
19 * @v addr Ethernet address
20 * @ret is_zero Address is all zeroes
22 static inline int is_zero_ether_addr ( const void *addr ) {
23 const uint8_t *addr_bytes = addr;
25 return ( ! ( addr_bytes[0] | addr_bytes[1] | addr_bytes[2] |
26 addr_bytes[3] | addr_bytes[4] | addr_bytes[5] ) );
30 * Check if Ethernet address is a multicast address
32 * @v addr Ethernet address
33 * @ret is_mcast Address is a multicast address
35 * Note that the broadcast address is also a multicast address.
37 static inline int is_multicast_ether_addr ( const void *addr ) {
38 const uint8_t *addr_bytes = addr;
40 return ( addr_bytes[0] & 0x01 );
44 * Check if Ethernet address is locally assigned
46 * @v addr Ethernet address
47 * @ret is_local Address is locally assigned
49 static inline int is_local_ether_addr ( const void *addr ) {
50 const uint8_t *addr_bytes = addr;
52 return ( addr_bytes[0] & 0x02 );
56 * Check if Ethernet address is the broadcast address
58 * @v addr Ethernet address
59 * @ret is_bcast Address is the broadcast address
61 static inline int is_broadcast_ether_addr ( const void *addr ) {
62 const uint8_t *addr_bytes = addr;
64 return ( ( addr_bytes[0] & addr_bytes[1] & addr_bytes[2] &
65 addr_bytes[3] & addr_bytes[4] & addr_bytes[5] ) == 0xff );
69 * Check if Ethernet address is valid
71 * @v addr Ethernet address
72 * @ret is_valid Address is valid
74 * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is
75 * not a multicast address, and is not ff:ff:ff:ff:ff:ff.
77 static inline int is_valid_ether_addr ( const void *addr ) {
78 return ( ( ! is_multicast_ether_addr ( addr ) ) &&
79 ( ! is_zero_ether_addr ( addr ) ) );
82 extern uint8_t eth_broadcast[];
83 extern struct ll_protocol ethernet_protocol __ll_protocol;
85 extern int eth_push ( struct net_device *netdev, struct io_buffer *iobuf,
86 const void *ll_dest, const void *ll_source,
88 extern int eth_pull ( struct net_device *netdev, struct io_buffer *iobuf,
89 const void **ll_dest, const void **ll_source,
90 uint16_t *net_proto, unsigned int *flags );
91 extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
92 extern void eth_random_addr ( void *hw_addr );
93 extern const char * eth_ntoa ( const void *ll_addr );
94 extern int eth_mc_hash ( unsigned int af, const void *net_addr,
96 extern int eth_eth_addr ( const void *ll_addr, void *eth_addr );
97 extern int eth_eui64 ( const void *ll_addr, void *eui64 );
98 extern struct net_device * alloc_etherdev ( size_t priv_size );
100 #endif /* _IPXE_ETHERNET_H */