aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLexi Winter <ivy@FreeBSD.org>2025-08-05 17:58:36 +0100
committerLexi Winter <ivy@FreeBSD.org>2025-08-05 18:38:40 +0100
commit03ef12653dc128a6431e85bc69530d2d6391bcf4 (patch)
tree87afc234558c2918ef04f94d812b3988d7c6d332
parent9a726ef241344d5a67bb0c465a43fcf79f94a33f (diff)
net/ethernet.h: Add make_ether_addr()lf/dev/make_ether_addr
This function turns an array of octets into a struct ether_addr, which is useful when type-safe code (which uses ether_addr) wants to interoperate with the many parts of the kernel where addresses are stored as plain byte arrays. To avoid sacrificing performance for safety, make the function static inline.
-rw-r--r--sys/net/ethernet.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h
index 01485cf26e06..3c296852e3d6 100644
--- a/sys/net/ethernet.h
+++ b/sys/net/ethernet.h
@@ -447,6 +447,7 @@ void ether_bpf_mtap_if(struct ifnet *ifp, struct mbuf *m);
#ifdef _KERNEL
#include <sys/_eventhandler.h>
+#include <sys/systm.h>
struct ifnet;
struct mbuf;
@@ -479,10 +480,18 @@ void ether_gen_addr_byname(const char *nameunit, struct ether_addr *hwaddr);
static __inline struct mbuf *ether_vlanencap(struct mbuf *m, uint16_t tag)
{
-
return ether_vlanencap_proto(m, tag, ETHERTYPE_VLAN);
}
+/* Create an ether_addr from an array of u_char (or uint8_t). */
+__nodiscard static __inline __unused struct ether_addr
+make_ether_addr(const u_char *__octets)
+{
+ struct ether_addr __ret;
+ memcpy(&__ret.octet[0], __octets, ETHER_ADDR_LEN);
+ return (__ret);
+}
+
/* new ethernet interface attached event */
typedef void (*ether_ifattach_event_handler_t)(void *, struct ifnet *);
EVENTHANDLER_DECLARE(ether_ifattach_event, ether_ifattach_event_handler_t);