Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Jan 2024 18:44:37 GMT
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 3159e314f194 - stable/14 - Fix udp IPv4-mapped address
Message-ID:  <202401101844.40AIibCk093670@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by emaste:

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

commit 3159e314f194bd8db98dd4516f46350b2fbe44f0
Author:     Richard Kümmel <R.Kuemmel@beckhoff.com>
AuthorDate: 2023-12-15 11:49:45 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-01-10 16:37:44 +0000

    Fix udp IPv4-mapped address
    
    Do not use the cached route if the destination isn't the same.
    This fix a problem where an UDP packet will be sent via the wrong route
    and interface if a previous one was sent via them.
    
    PR:     275774
    Reviewed by:    glebius, tuexen
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    
    (cherry picked from commit 7df9da47e8f04267330e1baa751f07c0c4aaf2ac)
---
 sys/netinet/udp_usrreq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 708a4e6b730d..75dec9d5f5aa 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1055,6 +1055,7 @@ udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
 	uint16_t cscov = 0;
 	uint32_t flowid = 0;
 	uint8_t flowtype = M_HASHTYPE_NONE;
+	bool use_cached_route;
 
 	inp = sotoinpcb(so);
 	KASSERT(inp != NULL, ("udp_send: inp == NULL"));
@@ -1091,9 +1092,8 @@ udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
 	 * We will need network epoch in either case, to safely lookup into
 	 * pcb hash.
 	 */
-	if (sin == NULL ||
-	    (inp->inp_laddr.s_addr == INADDR_ANY && inp->inp_lport == 0) ||
-	    (flags & PRUS_IPV6) != 0)
+	use_cached_route = sin == NULL || (inp->inp_laddr.s_addr == INADDR_ANY && inp->inp_lport == 0);
+	if (use_cached_route || (flags & PRUS_IPV6) != 0)
 		INP_WLOCK(inp);
 	else
 		INP_RLOCK(inp);
@@ -1443,7 +1443,7 @@ udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
 	else
 		UDP_PROBE(send, NULL, inp, &ui->ui_i, inp, &ui->ui_u);
 	error = ip_output(m, inp->inp_options,
-	    INP_WLOCKED(inp) ? &inp->inp_route : NULL, ipflags,
+	    use_cached_route ? &inp->inp_route : NULL, ipflags,
 	    inp->inp_moptions, inp);
 	INP_UNLOCK(inp);
 	NET_EPOCH_EXIT(et);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401101844.40AIibCk093670>