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 <liqinhui@xiaomi.com>
This commit is contained in:
liqinhui 2023-10-07 19:24:42 +08:00 committed by Xiang Xiao
parent 79e5d88f97
commit 3f08f32486
3 changed files with 22 additions and 4 deletions

View file

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

View file

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

View file

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