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)
This commit is contained in:
Richard Kümmel 2023-12-15 12:49:45 +01:00 committed by Ed Maste
parent 6443274660
commit 3159e314f1

View file

@ -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);