mirror of
https://github.com/systemd/systemd.git
synced 2024-12-26 03:22:00 +03:00
ether-addr-util: split out logic to mark MAC addresses as random
This commit is contained in:
parent
32c376a46c
commit
e22ca70008
@ -270,3 +270,11 @@ int parse_ether_addr(const char *s, struct ether_addr *ret) {
|
||||
*ret = a.ether;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ether_addr_mark_random(struct ether_addr *addr) {
|
||||
assert(addr);
|
||||
|
||||
/* see eth_random_addr in the kernel */
|
||||
addr->ether_addr_octet[0] &= 0xfe; /* clear multicast bit */
|
||||
addr->ether_addr_octet[0] |= 0x02; /* set local assignment bit (IEEE802) */
|
||||
}
|
||||
|
@ -113,3 +113,5 @@ static inline bool ether_addr_is_global(const struct ether_addr *addr) {
|
||||
|
||||
extern const struct hash_ops ether_addr_hash_ops;
|
||||
extern const struct hash_ops ether_addr_hash_ops_free;
|
||||
|
||||
void ether_addr_mark_random(struct ether_addr *addr);
|
||||
|
@ -95,9 +95,7 @@ static int generate_mac(
|
||||
assert_cc(ETH_ALEN <= sizeof(result));
|
||||
memcpy(mac->ether_addr_octet, &result, ETH_ALEN);
|
||||
|
||||
/* see eth_random_addr in the kernel */
|
||||
mac->ether_addr_octet[0] &= 0xfe; /* clear multicast bit */
|
||||
mac->ether_addr_octet[0] |= 0x02; /* set local assignment bit (IEEE802) */
|
||||
ether_addr_mark_random(mac);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user