iPXE
ethernet.h
Go to the documentation of this file.
1 #ifndef _IPXE_ETHERNET_H
2 #define _IPXE_ETHERNET_H
3 
4 /** @file
5  *
6  * Ethernet protocol
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/netdevice.h>
15 #include <ipxe/iobuf.h>
16 
17 /**
18  * Check if Ethernet address is all zeroes
19  *
20  * @v addr Ethernet address
21  * @ret is_zero Address is all zeroes
22  */
23 static inline int is_zero_ether_addr ( const void *addr ) {
24  const uint8_t *addr_bytes = addr;
25 
26  return ( ! ( addr_bytes[0] | addr_bytes[1] | addr_bytes[2] |
27  addr_bytes[3] | addr_bytes[4] | addr_bytes[5] ) );
28 }
29 
30 /**
31  * Check if Ethernet address is a multicast address
32  *
33  * @v addr Ethernet address
34  * @ret is_mcast Address is a multicast address
35  *
36  * Note that the broadcast address is also a multicast address.
37  */
38 static inline int is_multicast_ether_addr ( const void *addr ) {
39  const uint8_t *addr_bytes = addr;
40 
41  return ( addr_bytes[0] & 0x01 );
42 }
43 
44 /**
45  * Check if Ethernet address is locally assigned
46  *
47  * @v addr Ethernet address
48  * @ret is_local Address is locally assigned
49  */
50 static inline int is_local_ether_addr ( const void *addr ) {
51  const uint8_t *addr_bytes = addr;
52 
53  return ( addr_bytes[0] & 0x02 );
54 }
55 
56 /**
57  * Check if Ethernet address is the broadcast address
58  *
59  * @v addr Ethernet address
60  * @ret is_bcast Address is the broadcast address
61  */
62 static inline int is_broadcast_ether_addr ( const void *addr ) {
63  const uint8_t *addr_bytes = addr;
64 
65  return ( ( addr_bytes[0] & addr_bytes[1] & addr_bytes[2] &
66  addr_bytes[3] & addr_bytes[4] & addr_bytes[5] ) == 0xff );
67 }
68 
69 /**
70  * Check if Ethernet address is valid
71  *
72  * @v addr Ethernet address
73  * @ret is_valid Address is valid
74  *
75  * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is
76  * not a multicast address, and is not ff:ff:ff:ff:ff:ff.
77  */
78 static inline int is_valid_ether_addr ( const void *addr ) {
79  return ( ( ! is_multicast_ether_addr ( addr ) ) &&
80  ( ! is_zero_ether_addr ( addr ) ) );
81 }
82 
83 extern uint8_t eth_broadcast[];
84 extern struct ll_protocol ethernet_protocol __ll_protocol;
85 
86 extern int eth_push ( struct net_device *netdev, struct io_buffer *iobuf,
87  const void *ll_dest, const void *ll_source,
88  uint16_t net_proto );
89 extern int eth_pull ( struct net_device *netdev, struct io_buffer *iobuf,
90  const void **ll_dest, const void **ll_source,
91  uint16_t *net_proto, unsigned int *flags );
92 extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
93 extern void eth_random_addr ( void *hw_addr );
94 extern const char * eth_ntoa ( const void *ll_addr );
95 extern int eth_mc_hash ( unsigned int af, const void *net_addr,
96  void *ll_addr );
97 extern int eth_eth_addr ( const void *ll_addr, void *eth_addr );
98 extern int eth_eui64 ( const void *ll_addr, void *eui64 );
99 extern struct net_device * alloc_etherdev ( size_t priv_size );
100 
101 #endif /* _IPXE_ETHERNET_H */
void eth_random_addr(void *hw_addr)
Generate random Ethernet address.
Definition: ethernet.c:160
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:265
unsigned short uint16_t
Definition: stdint.h:11
void eth_init_addr(const void *hw_addr, void *ll_addr)
Initialise Ethernet address.
Definition: ethernet.c:151
I/O buffers.
int eth_eth_addr(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition: ethernet.c:223
struct ll_protocol ethernet_protocol __ll_protocol
Ethernet protocol.
Definition: ethernet.c:244
A link-layer protocol.
Definition: netdevice.h:115
int eth_pull(struct net_device *netdev, struct io_buffer *iobuf, const void **ll_dest, const void **ll_source, uint16_t *net_proto, unsigned int *flags)
int eth_mc_hash(unsigned int af, const void *net_addr, void *ll_addr)
Hash multicast address.
Definition: ethernet.c:194
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:176
int eth_eui64(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition: ethernet.c:235
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static int is_zero_ether_addr(const void *addr)
Check if Ethernet address is all zeroes.
Definition: ethernet.h:23
static struct net_device * netdev
Definition: gdbudp.c:52
static int is_multicast_ether_addr(const void *addr)
Check if Ethernet address is a multicast address.
Definition: ethernet.h:38
uint8_t eth_broadcast[]
Ethernet broadcast MAC address.
Definition: ethernet.c:48
uint8_t flags
Flags.
Definition: ena.h:18
int(* eui64)(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition: netdevice.h:190
uint32_t addr
Buffer address.
Definition: dwmac.h:20
A network device.
Definition: netdevice.h:353
unsigned char uint8_t
Definition: stdint.h:10
int eth_push(struct net_device *netdev, struct io_buffer *iobuf, const void *ll_dest, const void *ll_source, uint16_t net_proto)
static int is_valid_ether_addr(const void *addr)
Check if Ethernet address is valid.
Definition: ethernet.h:78
Network device management.
FILE_SECBOOT(PERMITTED)
static int is_local_ether_addr(const void *addr)
Check if Ethernet address is locally assigned.
Definition: ethernet.h:50
static int is_broadcast_ether_addr(const void *addr)
Check if Ethernet address is the broadcast address.
Definition: ethernet.h:62
int(* eth_addr)(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition: netdevice.h:182
A persistent I/O buffer.
Definition: iobuf.h:38