Merge pull request #21271 from yuwata/ether-addr-util-helper-functions

ether-addr-util: introduce several helper functions
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-11-09 10:02:55 +01:00
committed by GitHub
3 changed files with 26 additions and 3 deletions
+24 -1
View File
@@ -6,6 +6,8 @@
#include <stdbool.h>
#include "hash-funcs.h"
#include "macro.h"
#include "memory-util.h"
/* This is MAX_ADDR_LEN as defined in linux/netdevice.h, but net/if_arp.h
* defines a macro of the same name with a much lower size. */
@@ -35,7 +37,8 @@ static inline bool hw_addr_equal(const struct hw_addr_data *a, const struct hw_a
return hw_addr_compare(a, b) == 0;
}
static inline bool hw_addr_is_null(const struct hw_addr_data *addr) {
return hw_addr_equal(addr, &HW_ADDR_NULL);
assert(addr);
return addr->length == 0 || memeqzero(addr->bytes, addr->length);
}
extern const struct hash_ops hw_addr_hash_ops;
@@ -60,6 +63,26 @@ static inline bool ether_addr_is_null(const struct ether_addr *addr) {
return ether_addr_equal(addr, &ETHER_ADDR_NULL);
}
static inline bool ether_addr_is_broadcast(const struct ether_addr *addr) {
assert(addr);
return memeqbyte(0xff, addr->ether_addr_octet, ETH_ALEN);
}
static inline bool ether_addr_is_multicast(const struct ether_addr *addr) {
assert(addr);
return FLAGS_SET(addr->ether_addr_octet[0], 0x01);
}
static inline bool ether_addr_is_unicast(const struct ether_addr *addr) {
return !ether_addr_is_multicast(addr);
}
static inline bool ether_addr_is_local(const struct ether_addr *addr) {
/* Determine if the Ethernet address is locally-assigned one (IEEE 802) */
assert(addr);
return !FLAGS_SET(addr->ether_addr_octet[0], 0x02);
}
int ether_addr_from_string(const char *s, struct ether_addr *ret);
extern const struct hash_ops ether_addr_hash_ops;