git: 6a31fd27fae1 - main - if_vxlan: Fix nexthop reference imbalance on output

From: R. Christian McDonald <rcm_at_FreeBSD.org>
Date: Thu, 26 Nov 2026 02:14:28 UTC
The branch main has been updated by rcm:

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

commit 6a31fd27fae1fe56158d8262266fb337ebb6cfb7
Author:     R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2026-11-26 02:12:43 +0000
Commit:     R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2026-11-26 02:12:43 +0000

    if_vxlan: Fix nexthop reference imbalance on output
    
    When the inner frame asks for checksum offload or TSO, vxlan_encap4()
    and vxlan_encap6() look up the nexthop of the outer packet without a
    reference, to check the capabilities of the outgoing interface, and
    pass it to ip_output() or ip6_output() in a route on the stack.  When
    the output routine drops the nexthop of that route, because a pfil
    hook asked for a new lookup or the nexthop is no longer valid, it
    releases a reference that was never taken.  It then stores a
    referenced nexthop in the route, which the caller never releases.
    
    Set RT_NH_NOREF on these routes, so that ip_output() and ip6_output()
    neither release nor reference a nexthop for them.
    
    Reviewed by:            pouria, zlei
    Fixes:                  b092fd6c973d ("if_vxlan(4): add support for...")
    MFC after:              2 weeks
    Sponsored by:           Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D61958
---
 sys/net/if_vxlan.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c
index 5a23c316f202..7050f036482a 100644
--- a/sys/net/if_vxlan.c
+++ b/sys/net/if_vxlan.c
@@ -2571,6 +2571,7 @@ vxlan_encap4(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 		 */
 		bzero(&route, sizeof(route));
 		ro = &route;
+		ro->ro_flags = RT_NH_NOREF;
 		sin = (struct sockaddr_in *)&ro->ro_dst;
 		sin->sin_family = AF_INET;
 		sin->sin_len = sizeof(*sin);
@@ -2682,6 +2683,7 @@ vxlan_encap6(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 		 */
 		bzero(&route, sizeof(route));
 		ro = &route;
+		ro->ro_flags = RT_NH_NOREF;
 		sin6 = (struct sockaddr_in6 *)&ro->ro_dst;
 		sin6->sin6_family = AF_INET6;
 		sin6->sin6_len = sizeof(*sin6);