The branch main has been updated by zlei:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=db8296ff38cd149a21ce363341d401afebd75a0f

commit db8296ff38cd149a21ce363341d401afebd75a0f
Author:     Zhenlei Huang <z...@freebsd.org>
AuthorDate: 2025-07-15 15:31:19 +0000
Commit:     Zhenlei Huang <z...@freebsd.org>
CommitDate: 2025-07-15 15:31:19 +0000

    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] d54d93ac7f0f Move CTASSERT of ether header sizes out of the header file 
and into ...
    [2] ca4eddea97c5 src: Use gnu17 as the default C standard for userland 
instead of gnu99
    [3] 3a98d5701c7f 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
---
 sys/net/ethernet.h     | 6 ++++++
 sys/net/if_ethersubr.c | 5 -----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h
index cf4f75bd0b6c..01485cf26e06 100644
--- a/sys/net/ethernet.h
+++ b/sys/net/ethernet.h
@@ -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
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 7be4dfac23e7..3ae0c01c0efc 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -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) */

Reply via email to