ethernet: Move the assertion of ether header sizes back into ethernet.h

There're lots of consumers, Ethernet drivers, libraries and applications.
It is more promising to assert the sizes in every compilation units
rather than in if_ethersubr.c only.

Those assertions were in the header file but were moved to if_ethersubr.c
due to possible conflict of the implementation of CTASSERT [1]. Now that
the default C standard is now gnu17 [2] [3] which supports _Static_assert
natively, use _Static_assert instead of CTASSERT to avoid possible
conflicts.

While here, add an extra assertion for the size of struct ether_vlan_header.

[1] d54d93ac7f Move CTASSERT of ether header sizes out of the header file and into ...
[2] ca4eddea97 src: Use gnu17 as the default C standard for userland instead of gnu99
[3] 3a98d5701c sys: Use gnu17 as the default C standard for the kernel

PR:		287761 (exp-run)
Reviewed by:	glebius
Differential Revision:	https://reviews.freebsd.org/D50947
This commit is contained in:
Zhenlei Huang 2025-07-15 23:31:19 +08:00
parent 5c76e9f457
commit db8296ff38
2 changed files with 6 additions and 5 deletions

View file

@ -62,6 +62,8 @@ struct ether_header {
u_char ether_shost[ETHER_ADDR_LEN];
u_short ether_type;
} __packed;
_Static_assert(sizeof(struct ether_header) == ETHER_HDR_LEN,
"size of struct ether_header is wrong");
/*
* Structure of a 48-bit Ethernet address.
@ -69,6 +71,8 @@ struct ether_header {
struct ether_addr {
u_char octet[ETHER_ADDR_LEN];
} __packed;
_Static_assert(sizeof(struct ether_addr) == ETHER_ADDR_LEN,
"size of struct ether_addr is wrong");
#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
#define ETHER_IS_IPV6_MULTICAST(addr) \
@ -112,6 +116,8 @@ struct ether_vlan_header {
uint16_t evl_tag;
uint16_t evl_proto;
} __packed;
_Static_assert(sizeof(struct ether_vlan_header) == ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN,
"size of struct ether_vlan_header is wrong");
#define EVL_VLID_MASK 0x0FFF
#define EVL_PRI_MASK 0xE000

View file

@ -92,11 +92,6 @@
#include <crypto/sha1.h>
#ifdef CTASSERT
CTASSERT(sizeof (struct ether_header) == ETHER_ADDR_LEN * 2 + 2);
CTASSERT(sizeof (struct ether_addr) == ETHER_ADDR_LEN);
#endif
VNET_DEFINE(pfil_head_t, link_pfil_head); /* Packet filter hooks */
/* netgraph node hooks for ng_ether(4) */