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 
12 #include <stdint.h>
13 #include <ipxe/netdevice.h>
14 #include <ipxe/iobuf.h>
15 
16 /**
17  * Check if Ethernet address is all zeroes
18  *
19  * @v addr Ethernet address
20  * @ret is_zero Address is all zeroes
21  */
22 static inline int is_zero_ether_addr ( const void *addr ) {
23  const uint8_t *addr_bytes = addr;
24 
25  return ( ! ( addr_bytes[0] | addr_bytes[1] | addr_bytes[2] |
26  addr_bytes[3] | addr_bytes[4] | addr_bytes[5] ) );
27 }
28 
29 /**
30  * Check if Ethernet address is a multicast address
31  *
32  * @v addr Ethernet address
33  * @ret is_mcast Address is a multicast address
34  *
35  * Note that the broadcast address is also a multicast address.
36  */
37 static inline int is_multicast_ether_addr ( const void *addr ) {
38  const uint8_t *addr_bytes = addr;
39 
40  return ( addr_bytes[0] & 0x01 );
41 }
42 
43 /**
44  * Check if Ethernet address is locally assigned
45  *
46  * @v addr Ethernet address
47  * @ret is_local Address is locally assigned
48  */
49 static inline int is_local_ether_addr ( const void *addr ) {
50  const uint8_t *addr_bytes = addr;
51 
52  return ( addr_bytes[0] & 0x02 );
53 }
54 
55 /**
56  * Check if Ethernet address is the broadcast address
57  *
58  * @v addr Ethernet address
59  * @ret is_bcast Address is the broadcast address
60  */
61 static inline int is_broadcast_ether_addr ( const void *addr ) {
62  const uint8_t *addr_bytes = addr;
63 
64  return ( ( addr_bytes[0] & addr_bytes[1] & addr_bytes[2] &
65  addr_bytes[3] & addr_bytes[4] & addr_bytes[5] ) == 0xff );
66 }
67 
68 /**
69  * Check if Ethernet address is valid
70  *
71  * @v addr Ethernet address
72  * @ret is_valid Address is valid
73  *
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.
76  */
77 static inline int is_valid_ether_addr ( const void *addr ) {
78  return ( ( ! is_multicast_ether_addr ( addr ) ) &&
79  ( ! is_zero_ether_addr ( addr ) ) );
80 }
81 
82 extern uint8_t eth_broadcast[];
83 extern struct ll_protocol ethernet_protocol __ll_protocol;
84 
85 extern int eth_push ( struct net_device *netdev, struct io_buffer *iobuf,
86  const void *ll_dest, const void *ll_source,
87  uint16_t net_proto );
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,
95  void *ll_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 );
99 
100 #endif /* _IPXE_ETHERNET_H */
void eth_random_addr(void *hw_addr)
Generate random Ethernet address.
Definition: ethernet.c:159
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
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:150
I/O buffers.
int eth_eth_addr(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition: ethernet.c:222
struct ll_protocol ethernet_protocol __ll_protocol
Ethernet protocol.
Definition: ethernet.c:243
A link-layer protocol.
Definition: netdevice.h:114
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:193
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
int eth_eui64(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition: ethernet.c:234
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:22
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:37
uint8_t eth_broadcast[]
Ethernet broadcast MAC address.
Definition: ethernet.c:47
int(* eui64)(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition: netdevice.h:189
A network device.
Definition: netdevice.h:348
u32 addr
Definition: sky2.h:8
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:77
Network device management.
static int is_local_ether_addr(const void *addr)
Check if Ethernet address is locally assigned.
Definition: ethernet.h:49
static int is_broadcast_ether_addr(const void *addr)
Check if Ethernet address is the broadcast address.
Definition: ethernet.h:61
int(* eth_addr)(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition: netdevice.h:181
A persistent I/O buffer.
Definition: iobuf.h:32
uint8_t flags
Flags.
Definition: ena.h:18