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 2023/01/13 08:41:18 UTC
[nuttx] 01/02: net/devif: reuse devif_send() for can/pkt/icmp stack
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
commit 0cbbbb92153283f2727dbd2c0077443c7cdda85d
Author: chao an <an...@xiaomi.com>
AuthorDate: Wed Jan 11 13:57:05 2023 +0800
net/devif: reuse devif_send() for can/pkt/icmp stack
Signed-off-by: chao an <an...@xiaomi.com>
---
net/can/can_sendmsg.c | 2 +-
net/devif/Make.defs | 9 -----
net/devif/devif.h | 42 ---------------------
net/devif/devif_cansend.c | 91 ---------------------------------------------
net/devif/devif_pktsend.c | 91 ---------------------------------------------
net/icmp/icmp_sendmsg.c | 36 +++++++++---------
net/icmpv6/icmpv6_sendmsg.c | 26 +++++++------
net/pkt/pkt_sendmsg.c | 2 +-
8 files changed, 35 insertions(+), 264 deletions(-)
diff --git a/net/can/can_sendmsg.c b/net/can/can_sendmsg.c
index c07742639a..e86f82afed 100644
--- a/net/can/can_sendmsg.c
+++ b/net/can/can_sendmsg.c
@@ -106,7 +106,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
{
/* Copy the packet data into the device packet buffer and send it */
- devif_can_send(dev, pstate->snd_buffer, pstate->snd_buflen);
+ devif_send(dev, pstate->snd_buffer, pstate->snd_buflen, 0);
if (dev->d_sndlen == 0)
{
return flags;
diff --git a/net/devif/Make.defs b/net/devif/Make.defs
index 89460d80c5..c95b585d65 100644
--- a/net/devif/Make.defs
+++ b/net/devif/Make.defs
@@ -49,15 +49,6 @@ ifeq ($(CONFIG_MM_IOB),y)
NET_CSRCS += devif_poll.c
NET_CSRCS += devif_iobsend.c
- # Raw packet socket support
-
- ifeq ($(CONFIG_NET_PKT),y)
- NET_CSRCS += devif_pktsend.c
- endif
-
- ifeq ($(CONFIG_NET_CAN),y)
- NET_CSRCS += devif_cansend.c
- endif
endif
# Include network device interface build support
diff --git a/net/devif/devif.h b/net/devif/devif.h
index e820c523c3..2378b76ee1 100644
--- a/net/devif/devif.h
+++ b/net/devif/devif.h
@@ -482,48 +482,6 @@ void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *buf,
unsigned int target_offset);
#endif
-/****************************************************************************
- * Name: devif_pkt_send
- *
- * Description:
- * Called from socket logic in order to send a raw packet in response to
- * an xmit or poll request from the network interface driver.
- *
- * This is almost identical to calling devif_send() except that the data to
- * be sent is copied into dev->d_buf (vs. dev->d_appdata), since there is
- * no header on the data.
- *
- * Assumptions:
- * This function must be called with the network locked.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_NET_PKT)
-void devif_pkt_send(FAR struct net_driver_s *dev, FAR const void *buf,
- unsigned int len);
-#endif
-
-/****************************************************************************
- * Name: devif_can_send
- *
- * Description:
- * Called from socket logic in order to send a raw packet in response to
- * an xmit or poll request from the network interface driver.
- *
- * This is almost identical to calling devif_send() except that the data to
- * be sent is copied into dev->d_buf (vs. dev->d_appdata), since there is
- * no header on the data.
- *
- * Assumptions:
- * This function must be called with the network locked.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_NET_CAN)
-void devif_can_send(FAR struct net_driver_s *dev, FAR const void *buf,
- unsigned int len);
-#endif
-
/****************************************************************************
* Name: devif_out
*
diff --git a/net/devif/devif_cansend.c b/net/devif/devif_cansend.c
deleted file mode 100644
index 9d80dda3c3..0000000000
--- a/net/devif/devif_cansend.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
- * net/devif/devif_cansend.c
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <string.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/net/netdev.h>
-
-#if defined(CONFIG_NET_CAN)
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: devif_can_send
- *
- * Description:
- * Called from socket logic in order to send a can packet in response to
- * an xmit or poll request from the network interface driver.
- *
- * This is almost identical to calling devif_send() except that the data to
- * be sent is copied into dev->d_buf (vs. dev->d_appdata), since there is
- * no header on the data.
- *
- * Assumptions:
- * Called with the network locked.
- *
- ****************************************************************************/
-
-void devif_can_send(FAR struct net_driver_s *dev, FAR const void *buf,
- unsigned int len)
-{
- unsigned int limit = NETDEV_PKTSIZE(dev) - NET_LL_HDRLEN(dev);
-
- if (dev == NULL || len == 0 || len > limit)
- {
- nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
- dev, len, limit);
- return;
- }
-
- iob_update_pktlen(dev->d_iob, 0);
-
- /* Copy the data into the device packet buffer and set the number of
- * bytes to send
- */
-
- if (len <= iob_navail(false) * CONFIG_IOB_BUFSIZE)
- {
- dev->d_sndlen = iob_trycopyin(dev->d_iob, buf, len, 0, false);
- }
- else
- {
- dev->d_sndlen = 0;
- }
-
- if (dev->d_sndlen != len)
- {
- netdev_iob_release(dev);
- dev->d_sndlen = 0;
- }
-
- dev->d_len = dev->d_sndlen;
-}
-
-#endif /* CONFIG_NET_CAN */
diff --git a/net/devif/devif_pktsend.c b/net/devif/devif_pktsend.c
deleted file mode 100644
index 28f8e8308e..0000000000
--- a/net/devif/devif_pktsend.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
- * net/devif/devif_pktsend.c
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <string.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/net/netdev.h>
-
-#ifdef CONFIG_NET_PKT
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: devif_pkt_send
- *
- * Description:
- * Called from socket logic in order to send a raw packet in response to
- * an xmit or poll request from the network interface driver.
- *
- * This is almost identical to calling devif_send() except that the data to
- * be sent is copied into dev->d_buf (vs. dev->d_appdata), since there is
- * no header on the data.
- *
- * Assumptions:
- * Called with the network locked.
- *
- ****************************************************************************/
-
-void devif_pkt_send(FAR struct net_driver_s *dev, FAR const void *buf,
- unsigned int len)
-{
- unsigned int limit = NETDEV_PKTSIZE(dev) - NET_LL_HDRLEN(dev);
-
- if (dev == NULL || len == 0 || len > limit)
- {
- nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
- dev, len, limit);
- return;
- }
-
- iob_update_pktlen(dev->d_iob, 0);
-
- /* Copy the data into the device packet buffer and set the number of
- * bytes to send
- */
-
- if (len <= iob_navail(false) * CONFIG_IOB_BUFSIZE)
- {
- dev->d_sndlen = iob_trycopyin(dev->d_iob, buf, len, 0, false);
- }
- else
- {
- dev->d_sndlen = 0;
- }
-
- if (dev->d_sndlen != len)
- {
- netdev_iob_release(dev);
- dev->d_sndlen = 0;
- }
-
- dev->d_len = dev->d_sndlen;
-}
-
-#endif /* CONFIG_NET_PKT */
diff --git a/net/icmp/icmp_sendmsg.c b/net/icmp/icmp_sendmsg.c
index 7e50f92774..97ad179af2 100644
--- a/net/icmp/icmp_sendmsg.c
+++ b/net/icmp/icmp_sendmsg.c
@@ -99,6 +99,14 @@ static void sendto_request(FAR struct net_driver_s *dev,
{
FAR struct icmp_hdr_s *icmp;
+ /* Set-up to send that amount of data. */
+
+ devif_send(dev, pstate->snd_buf, pstate->snd_buflen, IPv4_HDRLEN);
+ if (dev->d_sndlen != pstate->snd_buflen)
+ {
+ return;
+ }
+
IFF_SET_IPv4(dev->d_flags);
/* The total length to send is the size of the application data plus the
@@ -107,29 +115,20 @@ static void sendto_request(FAR struct net_driver_s *dev,
dev->d_len = IPv4_HDRLEN + pstate->snd_buflen;
- /* The total size of the data (including the size of the ICMP header) */
-
- dev->d_sndlen += pstate->snd_buflen;
-
- /* Copy the ICMP header and payload into place after the IPv4 header */
-
- icmp = IPBUF(IPv4_HDRLEN);
-
- iob_update_pktlen(dev->d_iob, IPv4_HDRLEN);
-
- iob_copyin(dev->d_iob, pstate->snd_buf,
- pstate->snd_buflen, IPv4_HDRLEN, false);
-
/* Initialize the IP header. */
ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_ICMP,
&dev->d_ipaddr, &pstate->snd_toaddr,
IP_TTL_DEFAULT, NULL);
+ /* Copy the ICMP header and payload into place after the IPv4 header */
+
+ icmp = IPBUF(IPv4_HDRLEN);
+
/* Calculate the ICMP checksum. */
- icmp->icmpchksum = 0;
- icmp->icmpchksum = ~icmp_chksum_iob(dev->d_iob);
+ icmp->icmpchksum = 0;
+ icmp->icmpchksum = ~icmp_chksum_iob(dev->d_iob);
if (icmp->icmpchksum == 0)
{
icmp->icmpchksum = 0xffff;
@@ -204,8 +203,11 @@ static uint16_t sendto_eventhandler(FAR struct net_driver_s *dev,
ninfo("Send ICMP request\n");
sendto_request(dev, pstate);
- pstate->snd_result = OK;
- goto end_wait;
+ if (dev->d_sndlen > 0)
+ {
+ pstate->snd_result = OK;
+ goto end_wait;
+ }
}
/* Continue waiting */
diff --git a/net/icmpv6/icmpv6_sendmsg.c b/net/icmpv6/icmpv6_sendmsg.c
index 70bd8eefa1..fe291359b2 100644
--- a/net/icmpv6/icmpv6_sendmsg.c
+++ b/net/icmpv6/icmpv6_sendmsg.c
@@ -98,6 +98,14 @@ static void sendto_request(FAR struct net_driver_s *dev,
{
FAR struct icmpv6_echo_request_s *icmpv6;
+ /* Set-up to send that amount of data. */
+
+ devif_send(dev, pstate->snd_buf, pstate->snd_buflen, IPv6_HDRLEN);
+ if (dev->d_sndlen != pstate->snd_buflen)
+ {
+ return;
+ }
+
IFF_SET_IPv6(dev->d_flags);
/* The total length to send is the size of the application data plus the
@@ -106,21 +114,12 @@ static void sendto_request(FAR struct net_driver_s *dev,
dev->d_len = IPv6_HDRLEN + pstate->snd_buflen;
- /* The total size of the data (including the size of the ICMPv6 header) */
-
- dev->d_sndlen += pstate->snd_buflen;
-
ipv6_build_header(IPv6BUF, pstate->snd_buflen, IP_PROTO_ICMP6,
dev->d_ipv6addr, pstate->snd_toaddr.s6_addr16, 255);
/* Copy the ICMPv6 request and payload into place after the IPv6 header */
- icmpv6 = IPBUF(IPv6_HDRLEN);
-
- iob_update_pktlen(dev->d_iob, IPv6_HDRLEN);
-
- iob_copyin(dev->d_iob, pstate->snd_buf,
- pstate->snd_buflen, IPv6_HDRLEN, false);
+ icmpv6 = IPBUF(IPv6_HDRLEN);
/* Calculate the ICMPv6 checksum over the ICMPv6 header and payload. */
@@ -200,8 +199,11 @@ static uint16_t sendto_eventhandler(FAR struct net_driver_s *dev,
ninfo("Send ICMPv6 ECHO request\n");
sendto_request(dev, pstate);
- pstate->snd_result = OK;
- goto end_wait;
+ if (dev->d_sndlen > 0)
+ {
+ pstate->snd_result = OK;
+ goto end_wait;
+ }
}
/* Continue waiting */
diff --git a/net/pkt/pkt_sendmsg.c b/net/pkt/pkt_sendmsg.c
index 1e1a500077..f7618c97bd 100644
--- a/net/pkt/pkt_sendmsg.c
+++ b/net/pkt/pkt_sendmsg.c
@@ -105,7 +105,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
{
/* Copy the packet data into the device packet buffer and send it */
- devif_pkt_send(dev, pstate->snd_buffer, pstate->snd_buflen);
+ devif_send(dev, pstate->snd_buffer, pstate->snd_buflen, 0);
if (dev->d_sndlen == 0)
{
return flags;