You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/02/02 17:07:44 UTC
(nuttx) branch master updated: net/udp: Fix source address selection under IPv6
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 8562dd5796 net/udp: Fix source address selection under IPv6
8562dd5796 is described below
commit 8562dd5796e2d30d117f54197af4042dd0c4bebd
Author: Zhe Weng <we...@xiaomi.com>
AuthorDate: Thu Feb 1 15:31:46 2024 +0800
net/udp: Fix source address selection under IPv6
https://github.com/apache/nuttx/pull/11384 has changed the source
address selection of UDP from raddr to laddr, but not all UDP
connections have laddr set, then we need to fallback to get source from
raddr.
Signed-off-by: Zhe Weng <we...@xiaomi.com>
---
net/udp/udp_send.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c
index 2e3180af94..dc5bc8c077 100644
--- a/net/udp/udp_send.c
+++ b/net/udp/udp_send.c
@@ -86,6 +86,9 @@
void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
{
FAR struct udp_hdr_s *udp;
+#ifdef CONFIG_NET_IPv6
+ FAR const uint16_t *laddr;
+#endif
#ifdef CONFIG_NET_IPv4
in_addr_t raddr;
#endif
@@ -148,9 +151,16 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
dev->d_len = dev->d_sndlen + UDP_HDRLEN;
+ /* We use the laddr if the conn is bounded to an address, otherwise
+ * find a suitable source address corresponding to the raddr
+ */
+
+ laddr = !net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr) ?
+ conn->u.ipv6.laddr :
+ netdev_ipv6_srcaddr(dev, conn->u.ipv6.raddr);
+
ipv6_build_header(IPv6BUF, dev->d_len, IP_PROTO_UDP,
- netdev_ipv6_srcaddr(dev, conn->u.ipv6.laddr),
- conn->u.ipv6.raddr,
+ laddr, conn->u.ipv6.raddr,
conn->sconn.ttl, conn->sconn.s_tclass);
/* The total length to send is the size of the application data