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
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_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 */
23static 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 */
38static 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 */
50static 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 */
62static 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 */
78static inline int is_valid_ether_addr ( const void *addr ) {
79 return ( ( ! is_multicast_ether_addr ( addr ) ) &&
80 ( ! is_zero_ether_addr ( addr ) ) );
81}
82
83extern uint8_t eth_broadcast[];
84extern struct ll_protocol ethernet_protocol __ll_protocol;
85
86extern 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 );
89extern 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 );
92extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
93extern void eth_random_addr ( void *hw_addr );
94extern const char * eth_ntoa ( const void *ll_addr );
95extern int eth_mc_hash ( unsigned int af, const void *net_addr,
96 void *ll_addr );
97extern int eth_eth_addr ( const void *ll_addr, void *eth_addr );
98extern int eth_eui64 ( const void *ll_addr, void *eui64 );
99extern struct net_device * alloc_etherdev ( size_t priv_size );
100
101#endif /* _IPXE_ETHERNET_H */
unsigned short uint16_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:10
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint8_t flags
Flags.
Definition ena.h:7
uint8_t eth_broadcast[ETH_ALEN]
Ethernet broadcast MAC address.
Definition ethernet.c:48
int eth_mc_hash(unsigned int af, const void *net_addr, void *ll_addr)
Hash multicast address.
Definition ethernet.c:194
static int is_local_ether_addr(const void *addr)
Check if Ethernet address is locally assigned.
Definition ethernet.h:50
static int is_valid_ether_addr(const void *addr)
Check if Ethernet address is valid.
Definition ethernet.h:78
static int is_multicast_ether_addr(const void *addr)
Check if Ethernet address is a multicast address.
Definition ethernet.h:38
void eth_init_addr(const void *hw_addr, void *ll_addr)
Initialise Ethernet address.
Definition ethernet.c:151
int eth_eui64(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition ethernet.c:235
static int is_zero_ether_addr(const void *addr)
Check if Ethernet address is all zeroes.
Definition ethernet.h:23
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
void eth_random_addr(void *hw_addr)
Generate random Ethernet address.
Definition ethernet.c:160
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)
static int is_broadcast_ether_addr(const void *addr)
Check if Ethernet address is the broadcast address.
Definition ethernet.h:62
int eth_eth_addr(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition ethernet.c:223
int eth_push(struct net_device *netdev, struct io_buffer *iobuf, const void *ll_dest, const void *ll_source, uint16_t net_proto)
static struct net_device * netdev
Definition gdbudp.c:53
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
I/O buffers.
Network device management.
#define __ll_protocol
Declare a link-layer protocol.
Definition netdevice.h:468
A persistent I/O buffer.
Definition iobuf.h:38
A link-layer protocol.
Definition netdevice.h:115
int(* eui64)(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition netdevice.h:190
int(* eth_addr)(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition netdevice.h:182
A network device.
Definition netdevice.h:353