git: ff54b680383b - stable/14 - if_vlan: Fix up if_type before attaching the interface

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Mon, 07 Jul 2025 10:07:04 UTC
The branch stable/14 has been updated by zlei:

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

commit ff54b680383bb0f212e813b74e7a3f76423d2238
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-06-26 16:37:13 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-07-07 10:05:10 +0000

    if_vlan: Fix up if_type before attaching the interface
    
    ether_ifattach() does not touch if_type, so it is not mandatory to fix
    the if_type after ether_ifattach(). Without this change, the event
    listeners, e.g. netlink, will see wrong interface type IFT_ETHER rather
    than the correct one IFT_L2VLAN. There is also a potential race that
    other threads see inconsistent interface type, i.e. initially IFT_ETHER
    and eventually IFT_L2VLAN.
    
    As a nice effect, this change eliminates the memory allocation for
    if_hw_addr, as vlan(4) interfaces do not support setting or retrieving
    the hardware MAC address yet [1].
    
    [1] ddae57504b79 Persistently store NIC's hardware MAC address, and add a way to retrive it
    
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D50914
    
    (cherry picked from commit a19b353d354d4ef808965c53253103cb6e7e6708)
---
 sys/net/if_vlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index dce1cff5bc69..6a0d9331324e 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -1185,10 +1185,10 @@ vlan_clone_create(struct if_clone *ifc, char *name, size_t len,
 	ifp->if_ratelimit_query = vlan_ratelimit_query;
 #endif
 	ifp->if_flags = VLAN_IFFLAGS;
+	ifp->if_type = IFT_L2VLAN;
 	ether_ifattach(ifp, eaddr);
 	/* Now undo some of the damage... */
 	ifp->if_baudrate = 0;
-	ifp->if_type = IFT_L2VLAN;
 	ifp->if_hdrlen = ETHER_VLAN_ENCAP_LEN;
 	ifa = ifp->if_addr;
 	sdl = (struct sockaddr_dl *)ifa->ifa_addr;