net/local: bypass the message field to support SCM further

Change-Id: I51028036db049788d7db4289e26821a3bf1e1dd0
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an
2021-09-02 11:20:12 +08:00
parent 09a752e602
commit 2394394401
4 changed files with 58 additions and 80 deletions
+4 -5
View File
@@ -406,9 +406,8 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
* Send a packet on the write-only FIFO.
*
* Input Parameters:
* filep File structure of write-only FIFO.
* buf Data to send
* len Length of data to send
* conn The connection
* msg Message to send
* preamble Flag to indicate the preamble sync header assembly
*
* Returned Value:
@@ -417,8 +416,8 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
*
****************************************************************************/
int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
size_t len, bool preamble);
int local_send_packet(FAR struct local_conn_s *conn,
FAR struct msghdr *msg, bool preamble);
/****************************************************************************
* Name: local_recvmsg
+23 -35
View File
@@ -106,18 +106,15 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf,
}
/****************************************************************************
* Name: psock_stream_recvfrom
* Name: psock_stream_recvmsg
*
* Description:
* psock_stream_recvfrom() receives messages from a local stream socket.
* psock_stream_recvmsg() receives messages from a local stream socket.
*
* Input Parameters:
* psock A pointer to a NuttX-specific, internal socket structure
* buf Buffer to receive data
* len Length of buffer
* msg Buffer to receive the message
* flags Receive flags
* from Address of source (may be NULL)
* fromlen The length of the address structure
*
* Returned Value:
* On success, returns the number of characters received. If no data is
@@ -129,12 +126,11 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf,
#ifdef CONFIG_NET_LOCAL_STREAM
static inline ssize_t
psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
int flags, FAR struct sockaddr *from,
FAR socklen_t *fromlen)
psock_stream_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
int flags)
{
FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
size_t readlen = len;
size_t readlen;
int ret;
/* Verify that this is a connected peer socket */
@@ -156,7 +152,8 @@ psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Read the packet */
ret = psock_fifo_read(psock, buf, &readlen, true);
readlen = msg->msg_iov->iov_len;
ret = psock_fifo_read(psock, msg->msg_iov->iov_base, &readlen, true);
if (ret < 0)
{
return ret;
@@ -164,9 +161,9 @@ psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Return the address family */
if (from)
if (msg->msg_name)
{
ret = local_getaddr(conn, from, fromlen);
ret = local_getaddr(conn, msg->msg_name, &msg->msg_namelen);
if (ret < 0)
{
return ret;
@@ -178,18 +175,15 @@ psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
#endif /* CONFIG_NET_LOCAL_STREAM */
/****************************************************************************
* Name: psock_dgram_recvfrom
* Name: psock_dgram_recvmsg
*
* Description:
* psock_dgram_recvfrom() receives messages from a local datagram socket.
* psock_dgram_recvmsg() receives messages from a local datagram socket.
*
* Input Parameters:
* psock A pointer to a NuttX-specific, internal socket structure
* buf Buffer to receive data
* len Length of buffer
* msg Buffer to receive the message
* flags Receive flags
* from Address of source (may be NULL)
* fromlen The length of the address structure
*
* Returned Value:
* On success, returns the number of characters received. Otherwise, on
@@ -200,9 +194,8 @@ psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
#ifdef CONFIG_NET_LOCAL_DGRAM
static inline ssize_t
psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
int flags, FAR struct sockaddr *from,
FAR socklen_t *fromlen)
psock_dgram_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
int flags)
{
FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
uint16_t pktlen;
@@ -213,7 +206,7 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
* 'len' that can be supported.
*/
DEBUGASSERT(len <= UINT16_MAX);
DEBUGASSERT(msg->msg_iov->iov_len <= UINT16_MAX);
/* Verify that this is a bound, un-connected peer socket */
@@ -270,8 +263,8 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Read the packet */
readlen = MIN(pktlen, len);
ret = psock_fifo_read(psock, buf, &readlen, false);
readlen = MIN(pktlen, msg->msg_iov->iov_len);
ret = psock_fifo_read(psock, msg->msg_iov->iov_base, &readlen, false);
if (ret < 0)
{
goto errout_with_infd;
@@ -321,9 +314,9 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Return the address family */
if (from)
if (msg->msg_name)
{
ret = local_getaddr(conn, from, fromlen);
ret = local_getaddr(conn, msg->msg_name, &msg->msg_namelen);
if (ret < 0)
{
return ret;
@@ -380,19 +373,14 @@ errout_with_halfduplex:
ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
int flags)
{
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;
DEBUGASSERT(psock && psock->s_conn && buf);
DEBUGASSERT(psock && psock->s_conn && msg);
/* Check for a stream socket */
#ifdef CONFIG_NET_LOCAL_STREAM
if (psock->s_type == SOCK_STREAM)
{
return psock_stream_recvfrom(psock, buf, len, flags, from, fromlen);
return psock_stream_recvmsg(psock, msg, flags);
}
else
#endif
@@ -400,7 +388,7 @@ ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
#ifdef CONFIG_NET_LOCAL_DGRAM
if (psock->s_type == SOCK_DGRAM)
{
return psock_dgram_recvfrom(psock, buf, len, flags, from, fromlen);
return psock_dgram_recvmsg(psock, msg, flags);
}
else
#endif
+17 -29
View File
@@ -49,8 +49,7 @@
*
* Input Parameters:
* psock An instance of the internal socket structure.
* buf Data to send
* len Length of data to send
* msg Message to send
* flags Send flags (ignored for now)
*
* Returned Value:
@@ -60,9 +59,8 @@
*
****************************************************************************/
static ssize_t local_send(FAR struct socket *psock,
FAR const struct iovec *buf,
size_t len, int flags)
static ssize_t psock_local_send(FAR struct socket *psock,
FAR struct msghdr *msg, int flags)
{
ssize_t ret;
@@ -75,7 +73,7 @@ static ssize_t local_send(FAR struct socket *psock,
/* Local TCP packet send */
DEBUGASSERT(psock && psock->s_conn && buf);
DEBUGASSERT(psock && psock->s_conn && msg);
peer = (FAR struct local_conn_s *)psock->s_conn;
/* Verify that this is a connected peer socket and that it has
@@ -96,7 +94,7 @@ static ssize_t local_send(FAR struct socket *psock,
/* Send the packet */
ret = local_send_packet(&peer->lc_outfile, buf, len, false);
ret = local_send_packet(peer, msg, false);
}
break;
#endif /* CONFIG_NET_LOCAL_STREAM */
@@ -136,11 +134,8 @@ static ssize_t local_send(FAR struct socket *psock,
*
* Input Parameters:
* psock A pointer to a NuttX-specific, internal socket structure
* buf Data to send
* len Length of data to send
* msg Message to send
* flags Send flags
* to Address of recipient
* tolen The length of the address structure
*
* NOTE: All input parameters were verified by sendto() before this
* function was called.
@@ -152,23 +147,21 @@ static ssize_t local_send(FAR struct socket *psock,
*
****************************************************************************/
static ssize_t local_sendto(FAR struct socket *psock,
FAR const struct iovec *buf,
size_t len, int flags,
FAR const struct sockaddr *to,
socklen_t tolen)
static ssize_t psock_local_sendto(FAR struct socket *psock,
FAR struct msghdr *msg, int flags)
{
#ifdef CONFIG_NET_LOCAL_DGRAM
FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)to;
FAR struct sockaddr_un *unaddr = msg->msg_name;
ssize_t ret;
/* Verify that a valid address has been provided */
if (to->sa_family != AF_LOCAL || tolen < sizeof(sa_family_t))
if (unaddr->sun_family != AF_LOCAL ||
msg->msg_namelen < sizeof(sa_family_t))
{
nerr("ERROR: Unrecognized address family: %d\n",
to->sa_family);
unaddr->sun_family);
return -EAFNOSUPPORT;
}
@@ -200,7 +193,7 @@ static ssize_t local_sendto(FAR struct socket *psock,
/* At present, only standard pathname type address are support */
if (tolen < sizeof(sa_family_t) + 2)
if (msg->msg_namelen < sizeof(sa_family_t) + 2)
{
/* EFAULT
* - An invalid user space address was specified for a parameter
@@ -236,7 +229,7 @@ static ssize_t local_sendto(FAR struct socket *psock,
/* Send the packet */
ret = local_send_packet(&conn->lc_outfile, buf, len, true);
ret = local_send_packet(conn, msg, true);
if (ret < 0)
{
nerr("ERROR: Failed to send the packet: %zd\n", ret);
@@ -271,7 +264,7 @@ errout_with_halfduplex:
*
* Input Parameters:
* psock A pointer to a NuttX-specific, internal socket structure
* msg msg to send
* msg Message to send
* flags Send flags
*
* Returned Value:
@@ -284,13 +277,8 @@ errout_with_halfduplex:
ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
int flags)
{
FAR const struct iovec *buf = msg->msg_iov;
size_t len = msg->msg_iovlen;
FAR const struct sockaddr *to = msg->msg_name;
socklen_t tolen = msg->msg_namelen;
return to ? local_sendto(psock, buf, len, flags, to, tolen) :
local_send(psock, buf, len, flags);
return msg->msg_name ? psock_local_sendto(psock, msg, flags) :
psock_local_send(psock, msg, flags);
}
#endif /* CONFIG_NET && CONFIG_NET_LOCAL */
+14 -11
View File
@@ -34,6 +34,7 @@
#include <nuttx/fs/fs.h>
#include "devif/devif.h"
#include "socket/socket.h"
#include "local/local.h"
#if defined(CONFIG_NET) && defined(CONFIG_NET_LOCAL)
@@ -112,9 +113,8 @@ static int local_fifo_write(FAR struct file *filep, FAR const uint8_t *buf,
* Send a packet on the write-only FIFO.
*
* Input Parameters:
* filep File structure of write-only FIFO.
* buf Data to send
* len Length of data to send
* conn The connection
* msg Message to send
* preamble Flag to indicate the preamble sync header assembly
*
* Returned Value:
@@ -123,11 +123,12 @@ static int local_fifo_write(FAR struct file *filep, FAR const uint8_t *buf,
*
****************************************************************************/
int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
size_t len, bool preamble)
int local_send_packet(FAR struct local_conn_s *conn,
FAR struct msghdr *msg, bool preamble)
{
FAR const struct iovec *end = buf + len;
FAR const struct iovec *iov;
FAR struct iovec *end = msg->msg_iov + msg->msg_iovlen;
FAR struct file *filep = &conn->lc_outfile;
FAR struct iovec *iov;
int ret = -EINVAL;
uint16_t len16;
@@ -141,13 +142,13 @@ int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
return ret;
}
/* Send the packet length */
for (len16 = 0, iov = buf; iov != end; iov++)
for (len16 = 0, iov = msg->msg_iov; iov != end; iov++)
{
len16 += iov->iov_len;
}
/* Send the data packet length */
ret = local_fifo_write(filep, (FAR const uint8_t *)&len16,
sizeof(uint16_t));
if (ret != sizeof(uint16_t))
@@ -156,7 +157,9 @@ int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
}
}
for (len16 = 0, iov = buf; iov != end; iov++)
/* Send the packet data */
for (len16 = 0, iov = msg->msg_iov; iov != end; iov++)
{
ret = local_fifo_write(filep, iov->iov_base, iov->iov_len);
if (ret < 0)