Networking: Final detangle off IPv4 and IPv6 TCP/UDP send logic. The Networking subsystem now compiles with IPv6 enabled

This commit is contained in:
Gregory Nutt
2015-01-18 08:56:05 -06:00
parent ea52bda8f9
commit f7663ef0ab
18 changed files with 637 additions and 382 deletions
+2 -2
View File
@@ -143,7 +143,7 @@ union ip_binding_u
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
/* The IPv4 header */ /* The IPv4 header */
struct net_iphdr_s struct ipv4_hdr_s
{ {
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */ uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */ uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
@@ -161,7 +161,7 @@ struct net_iphdr_s
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
/* The IPv6 header */ /* The IPv6 header */
struct net_ipv6hdr_s struct ipv6_hdr_s
{ {
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */ uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */ uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
-62
View File
@@ -156,68 +156,6 @@ struct tcp_hdr_s
uint8_t optdata[4]; uint8_t optdata[4];
}; };
/* The TCP and IP headers */
#ifdef CONFIG_NET_IPv4
struct tcp_iphdr_s
{
/* IPv4 IP header */
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
/* TCP header */
uint16_t srcport;
uint16_t destport;
uint8_t seqno[4];
uint8_t ackno[4];
uint8_t tcpoffset;
uint8_t flags;
uint8_t wnd[2];
uint16_t tcpchksum;
uint8_t urgp[2];
uint8_t optdata[4];
};
#endif
#ifdef CONFIG_NET_IPv6
struct tcp_ipv6hdr_s
{
/* IPv6 IP header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ipv6addr_t srcipaddr; /* 128-bit Source address */
net_ipv6addr_t destipaddr; /* 128-bit Destination address */
/* TCP header */
uint16_t srcport;
uint16_t destport;
uint8_t seqno[4];
uint8_t ackno[4];
uint8_t tcpoffset;
uint8_t flags;
uint8_t wnd[2];
uint16_t tcpchksum;
uint8_t urgp[2];
uint8_t optdata[4];
};
#endif
/* The structure holding the TCP/IP statistics that are gathered if /* The structure holding the TCP/IP statistics that are gathered if
* CONFIG_NET_STATISTICS is defined. * CONFIG_NET_STATISTICS is defined.
*/ */
-50
View File
@@ -86,56 +86,6 @@ struct udp_hdr_s
uint16_t udpchksum; uint16_t udpchksum;
}; };
/* The UDP and IP headers */
#ifdef CONFIG_NET_IPv4
struct udp_iphdr_s
{
/* IPv4 header */
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
/* UDP header */
uint16_t srcport;
uint16_t destport;
uint16_t udplen;
uint16_t udpchksum;
};
#endif
#ifdef CONFIG_NET_IPv6
struct udp_ipv6hdr_s
{
/* IPv6 Ip header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ipv6addr_t srcipaddr; /* 128-bit Source address */
net_ipv6addr_t destipaddr; /* 128-bit Destination address */
/* UDP header */
uint16_t srcport;
uint16_t destport;
uint16_t udplen;
uint16_t udpchksum;
};
#endif
/* The structure holding the UDP statistics that are gathered if /* The structure holding the UDP statistics that are gathered if
* CONFIG_NET_STATISTICS is defined. * CONFIG_NET_STATISTICS is defined.
*/ */
+5 -5
View File
@@ -104,8 +104,8 @@
/* Macros */ /* Macros */
#define BUF ((FAR struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define BUF ((FAR struct ipv4_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#define FBUF ((FAR struct net_iphdr_s *)&g_reassembly_buffer[0]) #define FBUF ((FAR struct ipv4_hdr_s *)&g_reassembly_buffer[0])
/* IP fragment re-assembly */ /* IP fragment re-assembly */
@@ -151,8 +151,8 @@ static uint8_t g_reassembly_flags;
#if defined(CONFIG_NET_TCP_REASSEMBLY) && !defined(CONFIG_NET_IPv6) #if defined(CONFIG_NET_TCP_REASSEMBLY) && !defined(CONFIG_NET_IPv6)
static uint8_t devif_reassembly(void) static uint8_t devif_reassembly(void)
{ {
FAR struct net_iphdr_s *pbuf = BUF; FAR struct ipv4_hdr_s *pbuf = BUF;
FAR struct net_iphdr_s *pfbuf = FBUF; FAR struct ipv4_hdr_s *pfbuf = FBUF;
uint16_t offset; uint16_t offset;
uint16_t len; uint16_t len;
uint16_t i; uint16_t i;
@@ -311,7 +311,7 @@ nullreturn:
int ipv4_input(FAR struct net_driver_s *dev) int ipv4_input(FAR struct net_driver_s *dev)
{ {
FAR struct net_iphdr_s *pbuf = BUF; FAR struct ipv4_hdr_s *pbuf = BUF;
uint16_t iplen; uint16_t iplen;
/* This is where the input processing starts. */ /* This is where the input processing starts. */
+2 -2
View File
@@ -104,7 +104,7 @@
/* Macros */ /* Macros */
#define BUF ((FAR struct net_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define BUF ((FAR struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
@@ -139,7 +139,7 @@
int ipv6_input(FAR struct net_driver_s *dev) int ipv6_input(FAR struct net_driver_s *dev)
{ {
FAR struct net_ipv6hdr_s *pbuf = BUF; FAR struct ipv6_hdr_s *pbuf = BUF;
uint16_t iplen; uint16_t iplen;
/* This is where the input processing starts. */ /* This is where the input processing starts. */
+27 -2
View File
@@ -2,7 +2,7 @@
* net/socket/net_sendfile.c * net/socket/net_sendfile.c
* *
* Copyright (C) 2013 UVC Ingenieure. All rights reserved. * Copyright (C) 2013 UVC Ingenieure. All rights reserved.
* Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2015 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org> * Authors: Gregory Nutt <gnutt@nuttx.org>
* Max Holtzberg <mh@uvc.de> * Max Holtzberg <mh@uvc.de>
* *
@@ -77,7 +77,8 @@
# define CONFIG_NET_TCP_SPLIT_SIZE 40 # define CONFIG_NET_TCP_SPLIT_SIZE 40
#endif #endif
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define TCPIPv4BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN])
#define TCPIPv6BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
@@ -157,12 +158,36 @@ static uint16_t ack_interrupt(FAR struct net_driver_s *dev, FAR void *pvconn,
if ((flags & TCP_ACKDATA) != 0) if ((flags & TCP_ACKDATA) != 0)
{ {
FAR struct tcp_hdr_s *tcp;
#ifdef CONFIG_NET_SOCKOPTS #ifdef CONFIG_NET_SOCKOPTS
/* Update the timeout */ /* Update the timeout */
pstate->snd_time = clock_systimer(); pstate->snd_time = clock_systimer();
#endif #endif
/* Get the offset address of the TCP header */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
if (IFF_IS_IPv6(dev->d_flags))
#endif
{
DEBUGASSERT(pstate->snd_sock == PF_INET6);
tcp = TCPIPv6BUF;
}
#endif /* CONFIG_NET_IPv6 */
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
else
#endif
{
DEBUGASSERT(pstate->snd_sock == PF_INET);
tcp = TCPIPv4BUF;
}
#endif /* CONFIG_NET_IPv4 */
/* The current acknowledgement number number is the (relative) offset /* The current acknowledgement number number is the (relative) offset
* of the of the next byte needed by the receiver. The snd_isn is the * of the of the next byte needed by the receiver. The snd_isn is the
* offset of the first byte to send to the receiver. The difference * offset of the first byte to send to the receiver. The difference
+91 -38
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* net/socket/recvfrom.c * net/socket/recvfrom.c
* *
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -74,13 +74,14 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_NET_IPv4) #define IPv4BUF ((struct ipv4_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
# define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define IPv6BUF ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
# define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#elif defined(CONFIG_NET_IPv6) #define UDPIPv4BUF ((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN])
# define UDPBUF ((struct udp_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define UDPIPv6BUF ((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
# define TCPBUF ((struct tcp_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#endif #define TCPIPv4BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN])
#define TCPIPv6BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
@@ -572,26 +573,52 @@ static uint16_t recvfrom_pktinterrupt(FAR struct net_driver_s *dev,
static inline void recvfrom_tcpsender(FAR struct net_driver_s *dev, static inline void recvfrom_tcpsender(FAR struct net_driver_s *dev,
FAR struct recvfrom_s *pstate) FAR struct recvfrom_s *pstate)
{ {
#ifdef CONFIG_NET_IPv6 /* Get the family from the packet type, IP address from the IP header, and
FAR struct sockaddr_in6 *infrom = pstate->rf_from; * the port number from the TCP header.
#else */
FAR struct sockaddr_in *infrom = pstate->rf_from;
#endif
if (infrom) #ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
if (IFF_IS_IPv6(dev->d_flags))
#endif
{ {
infrom->sin_family = AF_INET; FAR struct sockaddr_in6 *infrom = pstate->rf_from;
infrom->sin_port = TCPBUF->srcport;
#ifdef CONFIG_NET_IPv6 if (infrom)
net_ipv6addr_copy(infrom->sin6_addr.s6_addr, TCPBUF->srcipaddr); {
#else FAR struct tcp_hdr_s *tcp = TCPIPv6BUF;
net_ipv4addr_copy(infrom->sin_addr.s_addr, FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
net_ip4addr_conv32(TCPBUF->srcipaddr));
#endif infrom->sin_family = AF_INET6;
infrom->sin_port = tcp->srcport;
net_ipv6addr_copy(infrom->sin6_addr.s6_addr, ipv6->srcipaddr);
}
} }
} #endif /* CONFIG_NET_IPv6 */
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
else
#endif #endif
{
FAR struct sockaddr_in *infrom = pstate->rf_from;
if (infrom)
{
FAR struct tcp_hdr_s *tcp = TCPIPv4BUF;
FAR struct ipv4_hdr_s *ipv4 = IPv4BUF;
infrom->sin_family = AF_INET;
infrom->sin_port = tcp->srcport;
net_ipv4addr_copy(infrom->sin_addr.s_addr,
net_ip4addr_conv32(ipv4->srcipaddr));
}
}
#endif /* CONFIG_NET_IPv4 */
}
#endif /* CONFIG_NET_TCP */
/**************************************************************************** /****************************************************************************
* Function: recvfrom_tcpinterrupt * Function: recvfrom_tcpinterrupt
@@ -819,26 +846,52 @@ static uint16_t recvfrom_tcpinterrupt(FAR struct net_driver_s *dev,
#ifdef CONFIG_NET_UDP #ifdef CONFIG_NET_UDP
static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_s *pstate) static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_s *pstate)
{ {
#ifdef CONFIG_NET_IPv6 /* Get the family from the packet type, IP address from the IP header, and
FAR struct sockaddr_in6 *infrom = pstate->rf_from; * the port number from the UDP header.
#else */
FAR struct sockaddr_in *infrom = pstate->rf_from;
#endif
if (infrom) #ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
if (IFF_IS_IPv6(dev->d_flags))
#endif
{ {
infrom->sin_family = AF_INET; FAR struct sockaddr_in6 *infrom = pstate->rf_from;
infrom->sin_port = UDPBUF->srcport;
#ifdef CONFIG_NET_IPv6 if (infrom)
net_ipv6addr_copy(infrom->sin6_addr.s6_addr, UDPBUF->srcipaddr); {
#else FAR struct udp_hdr_s *udp = UDPIPv6BUF;
net_ipv4addr_copy(infrom->sin_addr.s_addr, FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
net_ip4addr_conv32(UDPBUF->srcipaddr));
#endif infrom->sin_family = AF_INET6;
infrom->sin_port = udp->srcport;
net_ipv6addr_copy(infrom->sin6_addr.s6_addr, ipv6->srcipaddr);
}
} }
} #endif /* CONFIG_NET_IPv6 */
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
else
#endif #endif
{
FAR struct sockaddr_in *infrom = pstate->rf_from;
if (infrom)
{
FAR struct udp_hdr_s *udp = UDPIPv4BUF;
FAR struct ipv4_hdr_s *ipv4 = IPv4BUF;
infrom->sin_family = AF_INET;
infrom->sin_port = udp->srcport;
net_ipv4addr_copy(infrom->sin_addr.s_addr,
net_ip4addr_conv32(ipv4->srcipaddr));
}
}
#endif /* CONFIG_NET_IPv4 */
}
#endif /* CONFIG_NET_UDP */
/**************************************************************************** /****************************************************************************
* Function: recvfrom_udpinterrupt * Function: recvfrom_udpinterrupt
-1
View File
@@ -270,7 +270,6 @@ extern "C"
/* Defined in tcp_conn.c ****************************************************/ /* Defined in tcp_conn.c ****************************************************/
struct sockaddr; /* Forward reference */ struct sockaddr; /* Forward reference */
struct tcp_iphdr_s; /* Forward reference */
/**************************************************************************** /****************************************************************************
* Name: tcp_initialize * Name: tcp_initialize
+6 -6
View File
@@ -64,8 +64,8 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define IPv4BUF ((struct net_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 net_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define IPv6BUF ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@@ -357,7 +357,7 @@ static int tcp_selectport(uint16_t portno)
static inline FAR struct tcp_conn_s * static inline FAR struct tcp_conn_s *
tcp_ipv4_active(FAR struct net_driver_s *dev, FAR struct tcp_hdr_s *tcp) tcp_ipv4_active(FAR struct net_driver_s *dev, FAR struct tcp_hdr_s *tcp)
{ {
FAR struct net_iphdr_s *ip = IPv4BUF; FAR struct ipv4_hdr_s *ip = IPv4BUF;
FAR struct tcp_conn_s *conn; FAR struct tcp_conn_s *conn;
in_addr_t srcipaddr; in_addr_t srcipaddr;
#ifdef CONFIG_NETDEV_MULTINIC #ifdef CONFIG_NETDEV_MULTINIC
@@ -432,7 +432,7 @@ static inline FAR struct tcp_conn_s *
static inline FAR struct tcp_conn_s * static inline FAR struct tcp_conn_s *
tcp_ipv6_active(FAR struct net_driver_s *dev, FAR struct tcp_hdr_s *tcp) tcp_ipv6_active(FAR struct net_driver_s *dev, FAR struct tcp_hdr_s *tcp)
{ {
FAR struct net_ipv6hdr_s *ip = IPv6BUF; FAR struct ipv6_hdr_s *ip = IPv6BUF;
FAR struct tcp_conn_s *conn; FAR struct tcp_conn_s *conn;
net_ipv6addr_t *srcipaddr; net_ipv6addr_t *srcipaddr;
#ifdef CONFIG_NETDEV_MULTINIC #ifdef CONFIG_NETDEV_MULTINIC
@@ -952,7 +952,7 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
if (ipv6) if (ipv6)
#endif #endif
{ {
FAR struct net_ipv6hdr_s *ip = IPv6BUF; FAR struct ipv6_hdr_s *ip = IPv6BUF;
conn->mss = TCP_IPv6_INITIAL_MSS(dev); conn->mss = TCP_IPv6_INITIAL_MSS(dev);
net_ipv6addr_copy(conn->u.ipv6.raddr, ip->srcipaddr); net_ipv6addr_copy(conn->u.ipv6.raddr, ip->srcipaddr);
@@ -967,7 +967,7 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
else else
#endif #endif
{ {
FAR struct net_iphdr_s *ip = IPv4BUF; FAR struct ipv4_hdr_s *ip = IPv4BUF;
conn->mss = TCP_IPv4_INITIAL_MSS(dev); conn->mss = TCP_IPv4_INITIAL_MSS(dev);
net_ipv4addr_copy(conn->u.ipv4.raddr, net_ipv4addr_copy(conn->u.ipv4.raddr,
+317 -107
View File
File diff suppressed because it is too large Load Diff
+28 -6
View File
@@ -86,11 +86,8 @@
# define NEED_IPDOMAIN_SUPPORT 1 # define NEED_IPDOMAIN_SUPPORT 1
#endif #endif
#if defined(CONFIG_NET_IPv4) #define TCPIPv4BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN])
# define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define TCPIPv6BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
#elif defined(CONFIG_NET_IPv6)
# define TCPBUF ((struct tcp_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#endif
/* Debug */ /* Debug */
@@ -285,11 +282,36 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev,
if ((flags & TCP_ACKDATA) != 0) if ((flags & TCP_ACKDATA) != 0)
{ {
FAR struct tcp_wrbuffer_s *wrb; FAR struct tcp_wrbuffer_s *wrb;
FAR struct tcp_hdr_s *tcp;
FAR sq_entry_t *entry; FAR sq_entry_t *entry;
FAR sq_entry_t *next; FAR sq_entry_t *next;
uint32_t ackno; uint32_t ackno;
ackno = tcp_getsequence(TCPBUF->ackno); /* Get the offset address of the TCP header */
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET))
#endif
{
DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
tcp = TCPIPv4BUF;
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
DEBUGASSERT(IFF_IS_IPv6(dev->d_flags));
tcp = TCPIPv6BUF;
}
#endif /* CONFIG_NET_IPv6 */
/* Get the ACK number from the TCP header */
ackno = tcp_getsequence(tcp->ackno);
nllvdbg("ACK: ackno=%u flags=%04x\n", ackno, flags); nllvdbg("ACK: ackno=%u flags=%04x\n", ackno, flags);
/* Look at every write buffer in the unacked_q. The unacked_q /* Look at every write buffer in the unacked_q. The unacked_q
+27 -2
View File
@@ -78,7 +78,8 @@
# define CONFIG_NET_TCP_SPLIT_SIZE 40 # define CONFIG_NET_TCP_SPLIT_SIZE 40
#endif #endif
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define TCPIPv4BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN])
#define TCPIPv6BUF ((struct tcp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
@@ -232,19 +233,43 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev,
if ((flags & TCP_ACKDATA) != 0) if ((flags & TCP_ACKDATA) != 0)
{ {
FAR struct tcp_hdr_s *tcp;
/* Update the timeout */ /* Update the timeout */
#ifdef CONFIG_NET_SOCKOPTS #ifdef CONFIG_NET_SOCKOPTS
pstate->snd_time = clock_systimer(); pstate->snd_time = clock_systimer();
#endif #endif
/* Get the offset address of the TCP header */
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET))
#endif
{
DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
tcp = TCPIPv4BUF;
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
DEBUGASSERT(IFF_IS_IPv6(dev->d_flags));
tcp = TCPIPv6BUF;
}
#endif /* CONFIG_NET_IPv6 */
/* The current acknowledgement number number is the (relative) offset /* The current acknowledgement number number is the (relative) offset
* of the of the next byte needed by the receiver. The snd_isn is the * of the of the next byte needed by the receiver. The snd_isn is the
* offset of the first byte to send to the receiver. The difference * offset of the first byte to send to the receiver. The difference
* is the number of bytes to be acknowledged. * is the number of bytes to be acknowledged.
*/ */
pstate->snd_acked = tcp_getsequence(TCPBUF->ackno) - pstate->snd_isn; pstate->snd_acked = tcp_getsequence(tcp->ackno) - pstate->snd_isn;
nllvdbg("ACK: acked=%d sent=%d buflen=%d\n", nllvdbg("ACK: acked=%d sent=%d buflen=%d\n",
pstate->snd_acked, pstate->snd_sent, pstate->snd_buflen); pstate->snd_acked, pstate->snd_sent, pstate->snd_buflen);
-1
View File
@@ -96,7 +96,6 @@ extern "C"
****************************************************************************/ ****************************************************************************/
struct net_driver_s; /* Forward reference */ struct net_driver_s; /* Forward reference */
struct udp_iphdr_s; /* Forward reference */
/* Defined in udp_conn.c ****************************************************/ /* Defined in udp_conn.c ****************************************************/
/**************************************************************************** /****************************************************************************
+4 -4
View File
@@ -66,8 +66,8 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define IPv4BUF ((struct net_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 net_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define IPv6BUF ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@@ -274,7 +274,7 @@ static uint16_t udp_select_port(void)
static inline FAR struct udp_conn_s * static inline FAR struct udp_conn_s *
udp_ipv4_active(FAR struct net_driver_s *dev, FAR struct udp_hdr_s *udp) 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; FAR struct udp_conn_s *conn;
conn = (FAR struct udp_conn_s *)g_active_udp_connections.head; 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 * static inline FAR struct udp_conn_s *
udp_ipv6_active(FAR struct net_driver_s *dev, FAR struct udp_hdr_s *udp) 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; FAR struct udp_conn_s *conn;
conn = (FAR struct udp_conn_s *)g_active_udp_connections.head; conn = (FAR struct udp_conn_s *)g_active_udp_connections.head;
+85 -48
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* net/udp/udp_send.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Adapted for NuttX from logic in uIP which also has a BSD-like license: * Adapted for NuttX from logic in uIP which also has a BSD-like license:
@@ -63,7 +63,11 @@
* Pre-processor Definitions * 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 * 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) if (dev->d_sndlen > 0)
{ {
/* The total length to send is the size of the application data plus /* Initialize the IP header. */
* the IP and UDP headers (and, eventually, the Ethernet 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 FAR struct ipv4_hdr_s *ipv4 = IPv4BUF;
* does not include the IPv6 IP header length.
*/ 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. */
ipv4->ipchksum = 0;
ipv4->ipchksum = ~ipv4_chksum(dev);
/* 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 + IPv4UDP_HDRLEN;
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
/* Get pointers to the IPv6 header and the offset TCP header */
pudpbuf->vtc = 0x60; FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
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;
net_ipv6addr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr); DEBUGASSERT(IFF_IS_IPv6(dev->d_flags));
net_ipav6ddr_copy(pudpbuf->destipaddr, &conn->u.ipv4.raddr); udp = UDPIPv6BUF;
#else /* CONFIG_NET_IPv6 */ /* Initialize the IPv6 header. Note that the IP length field
* does not include the IPv6 IP header length.
*/
pudpbuf->vhl = 0x45; ipv6->vtc = 0x60;
pudpbuf->tos = 0; ipv6->tcf = 0x00;
pudpbuf->len[0] = (dev->d_len >> 8); ipv6->flow = 0x00;
pudpbuf->len[1] = (dev->d_len & 0xff); ipv6->len[0] = (dev->d_sndlen >> 8);
++g_ipid; ipv6->len[1] = (dev->d_sndlen & 0xff);
pudpbuf->ipid[0] = g_ipid >> 8; ipv6->proto = IP_PROTO_UDP;
pudpbuf->ipid[1] = g_ipid & 0xff; ipv6->ttl = conn->ttl;
pudpbuf->ipoffset[0] = 0;
pudpbuf->ipoffset[1] = 0;
pudpbuf->ttl = conn->ttl;
pudpbuf->proto = IP_PROTO_UDP;
net_ipv4addr_hdrcopy(pudpbuf->srcipaddr, &dev->d_ipaddr); net_ipv6addr_copy(ipv6->srcipaddr, dev->d_ipv6addr);
net_ipv4addr_hdrcopy(pudpbuf->destipaddr, &conn->u.ipv4.raddr); net_ipv6addr_copy(ipv6->destipaddr, conn->u.ipv6.raddr);
/* Calculate IP checksum. */ /* The total length to send is the size of the application data
* plus the IPv4 and UDP headers (and, eventually, the link layer
pudpbuf->ipchksum = 0; * header)
pudpbuf->ipchksum = ~(ipv4_chksum(dev)); */
dev->d_len = dev->d_sndlen + IPv6UDP_HDRLEN;
}
#endif /* CONFIG_NET_IPv6 */ #endif /* CONFIG_NET_IPv6 */
/* Initialize the UDP header */ /* Initialize the UDP header */
pudpbuf->srcport = conn->lport; udp->srcport = conn->lport;
pudpbuf->destport = conn->rport; udp->destport = conn->rport;
pudpbuf->udplen = HTONS(dev->d_sndlen + UDP_HDRLEN); udp->udplen = HTONS(dev->d_sndlen + UDP_HDRLEN);
#ifdef CONFIG_NET_UDP_CHECKSUMS #ifdef CONFIG_NET_UDP_CHECKSUMS
/* Calculate UDP checksum. */ /* Calculate UDP checksum. */
pudpbuf->udpchksum = 0; udp->udpchksum = 0;
pudpbuf->udpchksum = ~(udp_chksum(dev)); udp->udpchksum = ~(udp_chksum(dev));
if (pudpbuf->udpchksum == 0) if (udp->udpchksum == 0)
{ {
pudpbuf->udpchksum = 0xffff; udp->udpchksum = 0xffff;
} }
#else #else
pudpbuf->udpchksum = 0; udp->udpchksum = 0;
#endif #endif
nllvdbg("Outgoing UDP packet length: %d (%d)\n", 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 #ifdef CONFIG_NET_STATISTICS
g_netstats.udp.sent++; g_netstats.udp.sent++;
@@ -180,5 +218,4 @@ void udp_send(struct net_driver_s *dev, struct udp_conn_s *conn)
#endif #endif
} }
} }
#endif /* CONFIG_NET && CONFIG_NET_UDP */ #endif /* CONFIG_NET && CONFIG_NET_UDP */
+2 -2
View File
@@ -21,6 +21,6 @@ config NET_ARCH_CHKSUM
uint16_t net_chksum(FAR uint16_t *data, uint16_t len) uint16_t net_chksum(FAR uint16_t *data, uint16_t len)
uint16_t ipv4_chksum(FAR struct net_driver_s *dev) uint16_t ipv4_chksum(FAR struct net_driver_s *dev)
uint16_t ipv6_chksum(FAR struct net_driver_s *dev) uint16_t tcp_ipv4_chksum(FAR struct net_driver_s *dev);
uint16_t tcp_chksum(FAR struct net_driver_s *dev); uint16_t tcp_ipv6_chksum(FAR struct net_driver_s *dev);
uint16_t udp_chksum(FAR struct net_driver_s *dev); uint16_t udp_chksum(FAR struct net_driver_s *dev);
+24 -43
View File
@@ -54,8 +54,8 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define IPv4BUF ((struct net_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 net_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define IPv6BUF ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#define ICMPv6BUF ((struct icmp_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) #define ICMPv6BUF ((struct icmp_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
@@ -119,7 +119,7 @@ static uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len)
static uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev, static uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev,
uint8_t proto) uint8_t proto)
{ {
FAR struct net_iphdr_s *pbuf = IPv4BUF; FAR struct ipv4_hdr_s *pbuf = IPv4BUF;
uint16_t upperlen; uint16_t upperlen;
uint16_t sum; uint16_t sum;
@@ -157,7 +157,7 @@ static uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev,
static uint16_t ipv6_upperlayer_chksum(FAR struct net_driver_s *dev, static uint16_t ipv6_upperlayer_chksum(FAR struct net_driver_s *dev,
uint8_t proto) uint8_t proto)
{ {
FAR struct net_ipv6hdr_s *pbuf = IPv6BUF; FAR struct ipv6_hdr_s *pbuf = IPv6BUF;
uint16_t upperlen; uint16_t upperlen;
uint16_t sum; uint16_t sum;
@@ -314,34 +314,7 @@ uint16_t ipv4_chksum(FAR struct net_driver_s *dev)
#endif /* CONFIG_NET_ARCH_CHKSUM */ #endif /* CONFIG_NET_ARCH_CHKSUM */
/**************************************************************************** /****************************************************************************
* Name: ipv6_chksum * Name: tcp_chksum, tcp_ipv4_chksum, and tcp_ipv6_chksum
*
* Description:
* Calculate the IPv6 header checksum of the packet header in d_buf.
*
* The IPv6 header checksum is the Internet checksum of the 40 bytes of
* the IPv6 header.
*
* If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
* provided by architecture-specific logic.
*
* Returned Value:
* The IPv6 header checksum of the IPv6 header in the d_buf buffer.
*
****************************************************************************/
#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NET_ARCH_CHKSUM)
uint16_t ipv6_chksum(FAR struct net_driver_s *dev)
{
uint16_t sum;
sum = chksum(0, &dev->d_buf[NET_LL_HDRLEN(dev)], IPv6_HDRLEN);
return (sum == 0) ? 0xffff : htons(sum);
}
#endif /* CONFIG_NET_ARCH_CHKSUM */
/****************************************************************************
* Name: tcp_chksum
* *
* Description: * Description:
* Calculate the TCP checksum of the packet in d_buf and d_appdata. * Calculate the TCP checksum of the packet in d_buf and d_appdata.
@@ -360,26 +333,34 @@ uint16_t ipv6_chksum(FAR struct net_driver_s *dev)
****************************************************************************/ ****************************************************************************/
#if !CONFIG_NET_ARCH_CHKSUM #if !CONFIG_NET_ARCH_CHKSUM
#ifdef CONFIG_NET_IPv4
uint16_t tcp_ipv4_chksum(FAR struct net_driver_s *dev)
{
return ipv4_upperlayer_chksum(dev, IP_PROTO_TCP);
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
uint16_t tcp_ipv6_chksum(FAR struct net_driver_s *dev)
{
return ipv6_upperlayer_chksum(dev, IP_PROTO_TCP);
}
#endif /* CONFIG_NET_IPv6 */
#endif /* !CONFIG_NET_ARCH_CHKSUM */
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
uint16_t tcp_chksum(FAR struct net_driver_s *dev) uint16_t tcp_chksum(FAR struct net_driver_s *dev)
{ {
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
if (IFF_IS_IPv6(dev->d_flags)) if (IFF_IS_IPv6(dev->d_flags))
{ {
return ipv6_upperlayer_chksum(dev, IP_PROTO_TCP); return tcp_ipv6_chksum(dev);
} }
else else
{ {
return ipv4_upperlayer_chksum(dev, IP_PROTO_TCP); return tcp_ipv4_chksum(dev);
} }
#elif defined(CONFIG_NET_IPv4)
return ipv4_upperlayer_chksum(dev, IP_PROTO_TCP);
#else /* if defined(CONFIG_NET_IPv6) */
return ipv6_upperlayer_chksum(dev, IP_PROTO_TCP);
#endif
} }
#endif /* CONFIG_NET_ARCH_CHKSUM */ #endif
/**************************************************************************** /****************************************************************************
* Name: udp_chksum * Name: udp_chksum
+17 -1
View File
@@ -139,7 +139,7 @@ unsigned int net_dsec2tick(int dsec);
unsigned int net_timeval2dsec(FAR struct timeval *tv); unsigned int net_timeval2dsec(FAR struct timeval *tv);
/**************************************************************************** /****************************************************************************
* Name: tcp_chksum * Name: tcp_chksum, tcp_ipv4_chksum, and tcp_ipv6_chksum
* *
* Description: * Description:
* Calculate the TCP checksum of the packet in d_buf and d_appdata. * Calculate the TCP checksum of the packet in d_buf and d_appdata.
@@ -157,7 +157,23 @@ unsigned int net_timeval2dsec(FAR struct timeval *tv);
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4
uint16_t tcp_ipv4_chksum(FAR struct net_driver_s *dev);
#endif
#ifdef CONFIG_NET_IPv6
/* REVIST: Is this used? */
uint16_t tcp_ipv6_chksum(FAR struct net_driver_s *dev);
#endif
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
uint16_t tcp_chksum(FAR struct net_driver_s *dev); uint16_t tcp_chksum(FAR struct net_driver_s *dev);
#elif defined(CONFIG_NET_IPv4)
# define tcp_chksum(d) tcp_ipv4_chksum(d)
#else /* if defined(CONFIG_NET_IPv6) */
# define tcp_chksum(d) tcp_ipv6_chksum(d)
#endif
/**************************************************************************** /****************************************************************************
* Name: udp_chksum * Name: udp_chksum