git: c34a903c21cf - main - if_geneve: Fix nexthop reference imbalance on output

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

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

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

    if_geneve: Fix nexthop reference imbalance on output
    
    geneve_encap4() and geneve_encap6() look up the nexthop of the outer
    packet without a reference 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:                  e44d2e941e8e ("if_geneve: Add Support for Geneve...")
    Sponsored by:           Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D61952
---
 sys/net/if_geneve.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/net/if_geneve.c b/sys/net/if_geneve.c
index f08c0f5e1ebf..cf6d8e37fce9 100644
--- a/sys/net/if_geneve.c
+++ b/sys/net/if_geneve.c
@@ -2586,6 +2586,7 @@ geneve_encap4(struct geneve_softc *sc, const union sockaddr_union *funsa,
 		 */
 		memset(&route, 0, 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);
@@ -2721,6 +2722,7 @@ geneve_encap6(struct geneve_softc *sc, const union sockaddr_union *funsa,
 		 */
 		memset(&route, 0, 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);