summaryrefslogtreecommitdiff
path: root/nuttx/net/udp
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-18 08:56:05 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-18 08:56:05 -0600
commit0be3b3cd6dc53769b66c511e40e15be07f0a6ff9 (patch)
tree8133f9dd6247e0e0afebfff8184f408ff01f2b64 /nuttx/net/udp
parent189b5eddca2641e86e7e9d9ab6ce3876cc68c7c9 (diff)
downloadpx4-nuttx-0be3b3cd6dc53769b66c511e40e15be07f0a6ff9.tar.gz
px4-nuttx-0be3b3cd6dc53769b66c511e40e15be07f0a6ff9.tar.bz2
px4-nuttx-0be3b3cd6dc53769b66c511e40e15be07f0a6ff9.zip
Networking: Final detangle off IPv4 and IPv6 TCP/UDP send logic. The Networking subsystem now compiles with IPv6 enabled
Diffstat (limited to 'nuttx/net/udp')
-rw-r--r--nuttx/net/udp/udp.h1
-rw-r--r--nuttx/net/udp/udp_conn.c8
-rw-r--r--nuttx/net/udp/udp_send.c133
3 files changed, 89 insertions, 53 deletions
diff --git a/nuttx/net/udp/udp.h b/nuttx/net/udp/udp.h
index 2b5c0dba1..f20ebf377 100644
--- a/nuttx/net/udp/udp.h
+++ b/nuttx/net/udp/udp.h
@@ -96,7 +96,6 @@ extern "C"
****************************************************************************/
struct net_driver_s; /* Forward reference */
-struct udp_iphdr_s; /* Forward reference */
/* Defined in udp_conn.c ****************************************************/
/****************************************************************************
diff --git a/nuttx/net/udp/udp_conn.c b/nuttx/net/udp/udp_conn.c
index 5895b98ed..acce00d24 100644
--- a/nuttx/net/udp/udp_conn.c
+++ b/nuttx/net/udp/udp_conn.c
@@ -66,8 +66,8 @@
* Pre-processor Definitions
****************************************************************************/
-#define IPv4BUF ((struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
-#define IPv6BUF ((struct net_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define IPv4BUF ((struct ipv4_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define IPv6BUF ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Data
@@ -274,7 +274,7 @@ static uint16_t udp_select_port(void)
static inline FAR struct udp_conn_s *
udp_ipv4_active(FAR struct net_driver_s *dev, FAR struct udp_hdr_s *udp)
{
- FAR struct net_iphdr_s *ip = IPv4BUF;
+ FAR struct ipv4_hdr_s *ip = IPv4BUF;
FAR struct udp_conn_s *conn;
conn = (FAR struct udp_conn_s *)g_active_udp_connections.head;
@@ -342,7 +342,7 @@ static inline FAR struct udp_conn_s *
static inline FAR struct udp_conn_s *
udp_ipv6_active(FAR struct net_driver_s *dev, FAR struct udp_hdr_s *udp)
{
- FAR struct net_ipv6hdr_s *ip = IPv6BUF;
+ FAR struct ipv6_hdr_s *ip = IPv6BUF;
FAR struct udp_conn_s *conn;
conn = (FAR struct udp_conn_s *)g_active_udp_connections.head;
diff --git a/nuttx/net/udp/udp_send.c b/nuttx/net/udp/udp_send.c
index 8ceff0710..7a640888c 100644
--- a/nuttx/net/udp/udp_send.c
+++ b/nuttx/net/udp/udp_send.c
@@ -1,7 +1,7 @@
/****************************************************************************
* net/udp/udp_send.c
*
- * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
@@ -63,7 +63,11 @@
* Pre-processor Definitions
****************************************************************************/
-#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define IPv4BUF ((struct ipv4_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define IPv6BUF ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+
+#define UDPIPv4BUF ((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN])
+#define UDPIPv6BUF ((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
/****************************************************************************
* Public Variables
@@ -99,80 +103,114 @@
*
****************************************************************************/
-void udp_send(struct net_driver_s *dev, struct udp_conn_s *conn)
+void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
{
- FAR struct udp_iphdr_s *pudpbuf = UDPBUF;
+ FAR struct udp_hdr_s *udp;
if (dev->d_sndlen > 0)
{
- /* The total length to send is the size of the application data plus
- * the IP and UDP headers (and, eventually, the Ethernet header)
- */
+ /* Initialize the IP header. */
- dev->d_len = dev->d_sndlen + IPv4UDP_HDRLEN;
+#ifdef CONFIG_NET_IPv4
+#ifdef CONFIG_NET_IPv6
+ if (conn->domain == PF_INET)
+#endif
+ {
+ /* Get pointers to the IPv4 header and the offset TCP header */
- /* Initialize the IP header. Note that for IPv6, the IP length field
- * does not include the IPv6 IP header length.
- */
+ FAR struct ipv4_hdr_s *ipv4 = IPv4BUF;
-#ifdef CONFIG_NET_IPv6
+ DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
+ udp = UDPIPv4BUF;
+
+ /* Initialize the IPv4 header. */
+
+ ipv4->vhl = 0x45;
+ ipv4->tos = 0;
+ ipv4->len[0] = (dev->d_len >> 8);
+ ipv4->len[1] = (dev->d_len & 0xff);
+ ++g_ipid;
+ ipv4->ipid[0] = g_ipid >> 8;
+ ipv4->ipid[1] = g_ipid & 0xff;
+ ipv4->ipoffset[0] = 0;
+ ipv4->ipoffset[1] = 0;
+ ipv4->ttl = conn->ttl;
+ ipv4->proto = IP_PROTO_UDP;
+
+ net_ipv4addr_hdrcopy(ipv4->srcipaddr, &dev->d_ipaddr);
+ net_ipv4addr_hdrcopy(ipv4->destipaddr, &conn->u.ipv4.raddr);
+
+ /* Calculate IP checksum. */
- pudpbuf->vtc = 0x60;
- pudpbuf->tcf = 0x00;
- pudpbuf->flow = 0x00;
- pudpbuf->len[0] = (dev->d_sndlen >> 8);
- pudpbuf->len[1] = (dev->d_sndlen & 0xff);
- pudpbuf->proto = IP_PROTO_UDP;
- pudpbuf->ttl = conn->ttl;
+ ipv4->ipchksum = 0;
+ ipv4->ipchksum = ~ipv4_chksum(dev);
- net_ipv6addr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr);
- net_ipav6ddr_copy(pudpbuf->destipaddr, &conn->u.ipv4.raddr);
+ /* The total length to send is the size of the application data
+ * plus the IPv4 and UDP headers (and, eventually, the link layer
+ * header)
+ */
-#else /* CONFIG_NET_IPv6 */
+ dev->d_len = dev->d_sndlen + IPv4UDP_HDRLEN;
+ }
+#endif /* CONFIG_NET_IPv4 */
+
+#ifdef CONFIG_NET_IPv6
+#ifdef CONFIG_NET_IPv4
+ else
+#endif
+ {
+ /* Get pointers to the IPv6 header and the offset TCP header */
- pudpbuf->vhl = 0x45;
- pudpbuf->tos = 0;
- pudpbuf->len[0] = (dev->d_len >> 8);
- pudpbuf->len[1] = (dev->d_len & 0xff);
- ++g_ipid;
- pudpbuf->ipid[0] = g_ipid >> 8;
- pudpbuf->ipid[1] = g_ipid & 0xff;
- pudpbuf->ipoffset[0] = 0;
- pudpbuf->ipoffset[1] = 0;
- pudpbuf->ttl = conn->ttl;
- pudpbuf->proto = IP_PROTO_UDP;
+ FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
- net_ipv4addr_hdrcopy(pudpbuf->srcipaddr, &dev->d_ipaddr);
- net_ipv4addr_hdrcopy(pudpbuf->destipaddr, &conn->u.ipv4.raddr);
+ DEBUGASSERT(IFF_IS_IPv6(dev->d_flags));
+ udp = UDPIPv6BUF;
- /* Calculate IP checksum. */
+ /* Initialize the IPv6 header. Note that the IP length field
+ * does not include the IPv6 IP header length.
+ */
- pudpbuf->ipchksum = 0;
- pudpbuf->ipchksum = ~(ipv4_chksum(dev));
+ ipv6->vtc = 0x60;
+ ipv6->tcf = 0x00;
+ ipv6->flow = 0x00;
+ ipv6->len[0] = (dev->d_sndlen >> 8);
+ ipv6->len[1] = (dev->d_sndlen & 0xff);
+ ipv6->proto = IP_PROTO_UDP;
+ ipv6->ttl = conn->ttl;
+ net_ipv6addr_copy(ipv6->srcipaddr, dev->d_ipv6addr);
+ net_ipv6addr_copy(ipv6->destipaddr, conn->u.ipv6.raddr);
+
+ /* The total length to send is the size of the application data
+ * plus the IPv4 and UDP headers (and, eventually, the link layer
+ * header)
+ */
+
+ dev->d_len = dev->d_sndlen + IPv6UDP_HDRLEN;
+ }
#endif /* CONFIG_NET_IPv6 */
/* Initialize the UDP header */
- pudpbuf->srcport = conn->lport;
- pudpbuf->destport = conn->rport;
- pudpbuf->udplen = HTONS(dev->d_sndlen + UDP_HDRLEN);
+ udp->srcport = conn->lport;
+ udp->destport = conn->rport;
+ udp->udplen = HTONS(dev->d_sndlen + UDP_HDRLEN);
#ifdef CONFIG_NET_UDP_CHECKSUMS
/* Calculate UDP checksum. */
- pudpbuf->udpchksum = 0;
- pudpbuf->udpchksum = ~(udp_chksum(dev));
- if (pudpbuf->udpchksum == 0)
+ udp->udpchksum = 0;
+ udp->udpchksum = ~(udp_chksum(dev));
+ if (udp->udpchksum == 0)
{
- pudpbuf->udpchksum = 0xffff;
+ udp->udpchksum = 0xffff;
}
#else
- pudpbuf->udpchksum = 0;
+ udp->udpchksum = 0;
#endif
nllvdbg("Outgoing UDP packet length: %d (%d)\n",
- dev->d_len, (pudpbuf->len[0] << 8) | pudpbuf->len[1]);
+ dev->d_len, (udp->len[0] << 8) | udp->len[1]);
#ifdef CONFIG_NET_STATISTICS
g_netstats.udp.sent++;
@@ -180,5 +218,4 @@ void udp_send(struct net_driver_s *dev, struct udp_conn_s *conn)
#endif
}
}
-
#endif /* CONFIG_NET && CONFIG_NET_UDP */