2017-10-24 19:23:08 +02:00
|
|
|
/****************************************************************************
|
2020-12-01 07:55:16 +01:00
|
|
|
* net/icmpv6/icmpv6_recvmsg.c
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
2024-09-11 14:39:39 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/semaphore.h>
|
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/net/icmpv6.h>
|
|
|
|
|
|
|
|
#include "devif/devif.h"
|
|
|
|
#include "socket/socket.h"
|
|
|
|
#include "icmpv6/icmpv6.h"
|
2023-04-14 12:11:12 +02:00
|
|
|
#include "utils/utils.h"
|
2017-10-24 19:23:08 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6_SOCKET
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define ICMPv6_SIZE \
|
|
|
|
((dev)->d_len - IPv6_HDRLEN)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct icmpv6_recvfrom_s
|
|
|
|
{
|
|
|
|
FAR struct devif_callback_s *recv_cb; /* Reference to callback instance */
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR struct socket *recv_sock; /* IPPROTO_ICMP6 socket structure */
|
|
|
|
sem_t recv_sem; /* Use to manage the wait for the
|
|
|
|
* response */
|
|
|
|
struct in6_addr recv_from; /* The peer we received the request
|
|
|
|
* from */
|
|
|
|
FAR uint8_t *recv_buf; /* Location to return the response */
|
|
|
|
uint16_t recv_buflen; /* Size of the response */
|
2023-04-14 12:11:12 +02:00
|
|
|
FAR struct msghdr *msg; /* Input message header */
|
2020-05-17 16:47:40 +02:00
|
|
|
int16_t recv_result; /* >=0: receive size on success;
|
|
|
|
* <0: negated errno on fail */
|
2017-10-24 19:23:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: recvfrom_eventhandler
|
|
|
|
*
|
|
|
|
* Description:
|
2018-06-23 22:09:06 +02:00
|
|
|
* This function is called with the network locked to perform the actual
|
2023-04-14 12:11:12 +02:00
|
|
|
* ICMPv6 message actions when polled by the lower, device interfacing
|
|
|
|
* layer.
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-06-23 22:09:06 +02:00
|
|
|
* dev The structure of the network driver that generated the
|
|
|
|
* event
|
2017-10-24 19:23:08 +02:00
|
|
|
* pvpriv An instance of struct icmpv6_recvfrom_s cast to void*
|
|
|
|
* flags Set of events describing why the callback was invoked
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Modified value of the input flags
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint16_t recvfrom_eventhandler(FAR struct net_driver_s *dev,
|
2022-08-25 15:17:57 +02:00
|
|
|
FAR void *pvpriv, uint16_t flags)
|
2017-10-24 19:23:08 +02:00
|
|
|
{
|
2022-08-25 15:17:57 +02:00
|
|
|
FAR struct icmpv6_recvfrom_s *pstate = pvpriv;
|
2017-10-24 19:23:08 +02:00
|
|
|
FAR struct ipv6_hdr_s *ipv6;
|
|
|
|
|
|
|
|
ninfo("flags: %04x\n", flags);
|
|
|
|
|
|
|
|
if (pstate != NULL)
|
|
|
|
{
|
|
|
|
/* Check if the network is still up */
|
|
|
|
|
|
|
|
if ((flags & NETDEV_DOWN) != 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Interface is down\n");
|
|
|
|
pstate->recv_result = -ENETUNREACH;
|
|
|
|
goto end_wait;
|
|
|
|
}
|
|
|
|
|
2023-04-14 12:11:12 +02:00
|
|
|
/* Check if we have just received a ICMPv6 message. */
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2019-11-27 15:09:51 +01:00
|
|
|
if ((flags & ICMPv6_NEWDATA) != 0) /* No incoming data */
|
2017-10-24 19:23:08 +02:00
|
|
|
{
|
2023-04-14 12:11:12 +02:00
|
|
|
#ifdef CONFIG_NET_SOCKOPTS
|
2023-08-30 08:46:41 +02:00
|
|
|
FAR struct icmpv6_conn_s *conn = pstate->recv_sock->s_conn;
|
2023-04-14 12:11:12 +02:00
|
|
|
#endif
|
2017-10-24 19:23:08 +02:00
|
|
|
unsigned int recvsize;
|
|
|
|
|
2023-04-14 12:11:12 +02:00
|
|
|
ninfo("Received ICMPv6 message\n");
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2023-04-14 12:11:12 +02:00
|
|
|
/* What should we do if the received message is larger that the
|
2017-10-24 19:23:08 +02:00
|
|
|
* buffer that the caller of sendto provided? Truncate? Error
|
|
|
|
* out?
|
|
|
|
*/
|
|
|
|
|
|
|
|
recvsize = ICMPv6_SIZE;
|
|
|
|
if (recvsize > pstate->recv_buflen)
|
|
|
|
{
|
|
|
|
recvsize = pstate->recv_buflen;
|
|
|
|
}
|
|
|
|
|
2023-04-14 12:11:12 +02:00
|
|
|
/* Copy the ICMPv6 message to the user provided buffer
|
2018-11-02 19:06:57 +01:00
|
|
|
* REVISIT: What if there are IPv6 extension headers present?
|
|
|
|
*/
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2022-10-26 06:35:08 +02:00
|
|
|
memcpy(pstate->recv_buf, IPBUF(IPv6_HDRLEN), recvsize);
|
2017-10-24 19:23:08 +02:00
|
|
|
|
|
|
|
/* Return the size of the returned data */
|
|
|
|
|
2021-05-10 12:02:32 +02:00
|
|
|
DEBUGASSERT(recvsize <= INT16_MAX);
|
2017-10-24 19:23:08 +02:00
|
|
|
pstate->recv_result = recvsize;
|
|
|
|
|
|
|
|
/* Return the IPv6 address of the sender from the IPv6 header */
|
|
|
|
|
2022-10-26 06:35:08 +02:00
|
|
|
ipv6 = IPBUF(0);
|
2017-10-24 19:23:08 +02:00
|
|
|
net_ipv6addr_hdrcopy(&pstate->recv_from, ipv6->srcipaddr);
|
|
|
|
|
2019-11-27 15:09:51 +01:00
|
|
|
/* Indicate that the data has been consumed */
|
|
|
|
|
2023-04-14 12:11:12 +02:00
|
|
|
flags &= ~ICMPv6_NEWDATA;
|
|
|
|
#ifdef CONFIG_NET_SOCKOPTS
|
|
|
|
if (_SO_GETOPT(conn->sconn.s_options, IPV6_RECVHOPLIMIT))
|
|
|
|
{
|
|
|
|
int hoplimit = ipv6->ttl;
|
|
|
|
|
|
|
|
cmsg_append(pstate->msg, SOL_IPV6, IPV6_HOPLIMIT,
|
|
|
|
&hoplimit, sizeof(hoplimit));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-05-18 15:10:03 +02:00
|
|
|
dev->d_len = 0;
|
2017-10-24 19:23:08 +02:00
|
|
|
goto end_wait;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Continue waiting */
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
|
|
end_wait:
|
|
|
|
ninfo("Resuming\n");
|
|
|
|
|
|
|
|
/* Do not allow any further callbacks */
|
|
|
|
|
|
|
|
pstate->recv_cb->flags = 0;
|
|
|
|
pstate->recv_cb->priv = NULL;
|
|
|
|
pstate->recv_cb->event = NULL;
|
|
|
|
|
|
|
|
/* Wake up the waiting thread */
|
|
|
|
|
|
|
|
nxsem_post(&pstate->recv_sem);
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: icmpv6_readahead
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Copy the buffered read-ahead data to the user buffer.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - IPPROTO_ICMP6 socket connection structure containing the read-
|
|
|
|
* ahead data.
|
2018-06-23 22:09:06 +02:00
|
|
|
* dev The structure of the network driver that generated the event.
|
2017-10-24 19:23:08 +02:00
|
|
|
* pstate recvfrom state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-02-23 09:50:23 +01:00
|
|
|
* Number of bytes copied to the user buffer
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline ssize_t icmpv6_readahead(FAR struct icmpv6_conn_s *conn,
|
2023-04-14 12:11:12 +02:00
|
|
|
FAR void *buf, size_t buflen,
|
|
|
|
FAR struct msghdr *msg)
|
2017-10-24 19:23:08 +02:00
|
|
|
{
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
ssize_t ret = -ENODATA;
|
|
|
|
|
2020-05-17 16:47:40 +02:00
|
|
|
/* Check there is any ICMPv6 replies already buffered in a read-ahead
|
|
|
|
* buffer.
|
|
|
|
*/
|
2017-10-24 19:23:08 +02:00
|
|
|
|
|
|
|
if ((iob = iob_peek_queue(&conn->readahead)) != NULL)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(iob->io_pktlen > 0);
|
|
|
|
|
|
|
|
/* Then get address */
|
|
|
|
|
2023-04-14 12:11:12 +02:00
|
|
|
if (msg->msg_name != NULL)
|
2017-10-24 19:23:08 +02:00
|
|
|
{
|
2023-04-14 12:11:12 +02:00
|
|
|
memcpy(msg->msg_name, iob->io_data, sizeof(struct sockaddr_in6));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_SOCKOPTS
|
|
|
|
if (_SO_GETOPT(conn->sconn.s_options, IPV6_RECVHOPLIMIT))
|
|
|
|
{
|
|
|
|
int hoplimit;
|
|
|
|
|
|
|
|
hoplimit = iob->io_data[sizeof(struct sockaddr_in6)];
|
|
|
|
cmsg_append(msg, SOL_IPV6, IPV6_HOPLIMIT,
|
|
|
|
&hoplimit, sizeof(hoplimit));
|
2017-10-24 19:23:08 +02:00
|
|
|
}
|
2023-04-14 12:11:12 +02:00
|
|
|
#endif
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2022-11-23 12:39:40 +01:00
|
|
|
/* Copy to user */
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2022-11-23 12:39:40 +01:00
|
|
|
ret = iob_copyout(buf, iob, buflen, 0);
|
2017-10-24 19:23:08 +02:00
|
|
|
|
|
|
|
ninfo("Received %ld bytes (of %u)\n", (long)ret, iob->io_pktlen);
|
|
|
|
|
|
|
|
/* Remove the I/O buffer chain from the head of the read-ahead
|
|
|
|
* buffer queue.
|
|
|
|
*/
|
|
|
|
|
2022-11-23 12:39:40 +01:00
|
|
|
iob_remove_queue(&conn->readahead);
|
2017-10-24 19:23:08 +02:00
|
|
|
|
|
|
|
/* And free the I/O buffer chain */
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob_free_chain(iob);
|
2017-10-24 19:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-12-01 07:55:16 +01:00
|
|
|
* Name: icmpv6_recvmsg
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Implements the socket recvfrom interface for the case of the AF_INET
|
2020-12-01 07:55:16 +01:00
|
|
|
* data gram socket with the IPPROTO_ICMP6 protocol. icmpv6_recvmsg()
|
2023-04-14 12:11:12 +02:00
|
|
|
* receives ICMPv6 message for the a socket.
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
2020-12-01 07:55:16 +01:00
|
|
|
* If msg_name is not NULL, and the underlying protocol provides the source
|
|
|
|
* address, this source address is filled in. The argument 'msg_namelen' is
|
|
|
|
* initialized to the size of the buffer associated with msg_name, and
|
2017-10-24 19:23:08 +02:00
|
|
|
* modified on return to indicate the actual size of the address stored
|
|
|
|
* there.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock A pointer to a NuttX-specific, internal socket structure
|
2020-12-01 07:55:16 +01:00
|
|
|
* msg Buffer to receive the message
|
2017-10-24 19:23:08 +02:00
|
|
|
* flags Receive flags
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-12-01 07:55:16 +01:00
|
|
|
* On success, returns the number of characters received. If no data is
|
2017-10-24 19:23:08 +02:00
|
|
|
* available to be received and the peer has performed an orderly shutdown,
|
2020-12-01 07:55:16 +01:00
|
|
|
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
|
|
|
* returned (see recvmsg() for the list of appropriate error values).
|
2017-10-24 19:23:08 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-12-01 07:55:16 +01:00
|
|
|
ssize_t icmpv6_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|
|
|
int flags)
|
2017-10-24 19:23:08 +02:00
|
|
|
{
|
2020-12-01 07:55:16 +01:00
|
|
|
FAR void *buf = msg->msg_iov->iov_base;
|
|
|
|
size_t len = msg->msg_iov->iov_len;
|
|
|
|
FAR struct sockaddr *from = msg->msg_name;
|
|
|
|
FAR socklen_t *fromlen = &msg->msg_namelen;
|
2017-10-24 19:23:08 +02:00
|
|
|
FAR struct sockaddr_in6 *inaddr;
|
|
|
|
FAR struct icmpv6_conn_s *conn;
|
2023-04-23 05:25:28 +02:00
|
|
|
FAR struct net_driver_s *dev = NULL;
|
2017-10-24 19:23:08 +02:00
|
|
|
struct icmpv6_recvfrom_s state;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
/* Some sanity checks */
|
|
|
|
|
2023-08-30 08:46:41 +02:00
|
|
|
DEBUGASSERT(buf != NULL);
|
2017-10-24 19:23:08 +02:00
|
|
|
|
|
|
|
if (len < ICMPv6_HDRLEN)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If a 'from' address has been provided, verify that it is large
|
|
|
|
* enough to hold the AF_INET address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (from != NULL)
|
|
|
|
{
|
|
|
|
if (fromlen == NULL && *fromlen < sizeof(struct sockaddr_in6))
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
net_lock();
|
|
|
|
|
2017-10-24 19:23:08 +02:00
|
|
|
conn = psock->s_conn;
|
2023-04-23 05:25:28 +02:00
|
|
|
if (psock->s_type != SOCK_RAW)
|
2017-10-24 19:23:08 +02:00
|
|
|
{
|
2023-04-23 05:25:28 +02:00
|
|
|
/* Get the device that was used to send the ICMPv6 request. */
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2023-04-23 05:25:28 +02:00
|
|
|
dev = conn->dev;
|
|
|
|
DEBUGASSERT(dev != NULL);
|
|
|
|
if (dev == NULL)
|
|
|
|
{
|
|
|
|
ret = -EPROTO;
|
|
|
|
goto errout;
|
|
|
|
}
|
2021-05-20 12:16:59 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 19:23:08 +02:00
|
|
|
/* Check if there is buffered read-ahead data for this socket. We may have
|
2020-02-22 19:31:14 +01:00
|
|
|
* already received the response to previous command.
|
2017-10-24 19:23:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!IOB_QEMPTY(&conn->readahead))
|
|
|
|
{
|
2023-04-14 12:11:12 +02:00
|
|
|
ret = icmpv6_readahead(conn, buf, len, msg);
|
2017-10-24 19:23:08 +02:00
|
|
|
}
|
2022-02-08 06:18:01 +01:00
|
|
|
else if (_SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
|
|
|
(flags & MSG_DONTWAIT) != 0)
|
2021-05-20 12:14:54 +02:00
|
|
|
{
|
2021-05-20 12:16:59 +02:00
|
|
|
/* Handle non-blocking ICMP sockets */
|
2021-05-20 12:14:54 +02:00
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
ret = -EAGAIN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Initialize the state structure */
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
memset(&state, 0, sizeof(struct icmpv6_recvfrom_s));
|
|
|
|
nxsem_init(&state.recv_sem, 0, 0);
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
state.recv_sock = psock; /* The IPPROTO_ICMP6 socket instance */
|
|
|
|
state.recv_result = -ENOMEM; /* Assume allocation failure */
|
|
|
|
state.recv_buf = buf; /* Location to return the response */
|
|
|
|
state.recv_buflen = len; /* Size of the response */
|
2023-04-14 12:11:12 +02:00
|
|
|
state.msg = msg; /* Input message header */
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
/* Set up the callback */
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
state.recv_cb = icmpv6_callback_alloc(dev, conn);
|
|
|
|
if (state.recv_cb)
|
|
|
|
{
|
|
|
|
state.recv_cb->flags = (ICMPv6_NEWDATA | NETDEV_DOWN);
|
|
|
|
state.recv_cb->priv = (FAR void *)&state;
|
|
|
|
state.recv_cb->event = recvfrom_eventhandler;
|
|
|
|
|
|
|
|
/* Wait for either the response to be received or for timeout to
|
2023-01-13 07:51:38 +01:00
|
|
|
* occur. (1) net_sem_timedwait will also terminate if a signal is
|
2021-05-20 12:16:59 +02:00
|
|
|
* received, (2) interrupts may be disabled! They will be
|
|
|
|
* re-enabled while the task sleeps and automatically re-enabled
|
|
|
|
* when the task restarts.
|
|
|
|
*/
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2023-01-13 07:51:38 +01:00
|
|
|
ret = net_sem_timedwait(&state.recv_sem,
|
2022-02-07 07:36:54 +01:00
|
|
|
_SO_TIMEOUT(conn->sconn.s_rcvtimeo));
|
2021-05-20 12:16:59 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
state.recv_result = ret;
|
|
|
|
}
|
2020-01-04 11:37:46 +01:00
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
icmpv6_callback_free(dev, conn, state.recv_cb);
|
|
|
|
}
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2022-11-20 16:11:18 +01:00
|
|
|
nxsem_destroy(&state.recv_sem);
|
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
/* Return the negated error number in the event of a failure, or the
|
|
|
|
* number of bytes received on success.
|
2017-10-24 19:23:08 +02:00
|
|
|
*/
|
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
if (state.recv_result < 0)
|
2020-01-04 11:37:46 +01:00
|
|
|
{
|
2021-05-20 12:16:59 +02:00
|
|
|
nerr("ERROR: Return error=%d\n", state.recv_result);
|
|
|
|
ret = state.recv_result;
|
|
|
|
goto errout;
|
2020-01-04 11:37:46 +01:00
|
|
|
}
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
if (from != NULL)
|
|
|
|
{
|
|
|
|
inaddr = (FAR struct sockaddr_in6 *)from;
|
|
|
|
inaddr->sin6_family = AF_INET6;
|
|
|
|
inaddr->sin6_port = 0;
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
net_ipv6addr_copy(inaddr->sin6_addr.s6_addr16,
|
|
|
|
state.recv_from.s6_addr16);
|
|
|
|
}
|
2017-10-24 19:23:08 +02:00
|
|
|
|
|
|
|
ret = state.recv_result;
|
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
/* If there a no further outstanding requests,
|
|
|
|
* make sure that the request struct is left pristine.
|
|
|
|
*/
|
2017-10-24 19:23:08 +02:00
|
|
|
|
|
|
|
errout:
|
2023-04-23 05:25:28 +02:00
|
|
|
if (ret < 0)
|
2021-05-20 12:16:59 +02:00
|
|
|
{
|
2023-04-23 05:25:28 +02:00
|
|
|
conn->id = 0;
|
|
|
|
conn->dev = NULL;
|
2017-10-24 19:23:08 +02:00
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob_free_queue(&conn->readahead);
|
2021-05-20 12:16:59 +02:00
|
|
|
}
|
2017-10-24 19:23:08 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 12:16:59 +02:00
|
|
|
net_unlock();
|
|
|
|
|
2017-10-24 19:23:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_ICMPv6_SOCKET */
|