From 3f08f3248667076c25ecdb72461c37cb1963b7dc Mon Sep 17 00:00:00 2001 From: liqinhui Date: Sat, 7 Oct 2023 19:24:42 +0800 Subject: [PATCH] net: allow icmpv6 and udp to find the dev by the ifindex with s_boundto. In order to support the dhcpv6c. Signed-off-by: liqinhui --- net/icmpv6/icmpv6_sendmsg.c | 14 ++++++++++++-- net/inet/inet_sockif.c | 5 +++++ net/udp/udp_finddev.c | 7 +++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/net/icmpv6/icmpv6_sendmsg.c b/net/icmpv6/icmpv6_sendmsg.c index 0e39796237..e238e82fcb 100644 --- a/net/icmpv6/icmpv6_sendmsg.c +++ b/net/icmpv6/icmpv6_sendmsg.c @@ -298,8 +298,18 @@ ssize_t icmpv6_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg, /* Get the device that will be used to route this ICMPv6 ECHO request */ - dev = netdev_findby_ripv6addr(g_ipv6_unspecaddr, - inaddr->sin6_addr.s6_addr16); +#ifdef CONFIG_NET_BINDTODEVICE + if (conn->sconn.s_boundto != 0) + { + dev = netdev_findbyindex(conn->sconn.s_boundto); + } + else +#endif + { + dev = netdev_findby_ripv6addr(g_ipv6_unspecaddr, + inaddr->sin6_addr.s6_addr16); + } + if (dev == NULL) { nerr("ERROR: Not reachable\n"); diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c index 2f63f94751..8e6f8bd91c 100644 --- a/net/inet/inet_sockif.c +++ b/net/inet/inet_sockif.c @@ -1909,6 +1909,11 @@ static ssize_t inet_sendmsg(FAR struct socket *psock, for (len = 0, iov = msg->msg_iov; iov != end; iov++) { + if (iov->iov_len == 0 || iov->iov_base == NULL) + { + continue; + } + memcpy(((unsigned char *)buf) + len, iov->iov_base, iov->iov_len); len += iov->iov_len; } diff --git a/net/udp/udp_finddev.c b/net/udp/udp_finddev.c index 2240ac05ba..b4c2d92b50 100644 --- a/net/udp/udp_finddev.c +++ b/net/udp/udp_finddev.c @@ -215,11 +215,14 @@ udp_find_raddr_device(FAR struct udp_conn_s *conn, #if defined(CONFIG_NET_MLD) && defined(CONFIG_NET_BINDTODEVICE) if (IN6_IS_ADDR_MULTICAST(&raddr)) { - if ((conn->sconn.s_boundto == 0) && - (conn->mreq.imr_ifindex != 0)) + if (conn->mreq.imr_ifindex != 0) { return netdev_findbyindex(conn->mreq.imr_ifindex); } + else if (conn->sconn.s_boundto != 0) + { + return netdev_findbyindex(conn->sconn.s_boundto); + } } else #endif