Network: All logic will now handle varialbe length link layer protocol headers within incoming packets. This permits use of multiple network interfaces with differing data links. For example, ETHERNET + SLIP

This commit is contained in:
Gregory Nutt
2014-11-15 13:13:23 -06:00
parent 5d05b00fda
commit 2e55db369d
28 changed files with 144 additions and 90 deletions
+2 -2
View File
@@ -107,13 +107,13 @@
/* Macros */
#define BUF ((FAR struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define BUF ((FAR struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#define FBUF ((FAR struct net_iphdr_s *)&g_reassembly_buffer[0])
/* IP fragment re-assembly */
#define IP_MF 0x20
#define TCP_REASS_BUFSIZE (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN)
#define TCP_REASS_BUFSIZE (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(dev))
#define TCP_REASS_LASTFRAG 0x01
/****************************************************************************
+1 -1
View File
@@ -66,7 +66,7 @@
* Pre-processor Definitions
****************************************************************************/
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
+2 -2
View File
@@ -65,8 +65,8 @@
* Pre-processor Definitions
****************************************************************************/
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define ICMPDAT (&dev->d_buf[NET_LL_HDRLEN + sizeof(struct icmp_iphdr_s)])
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#define ICMPDAT (&dev->d_buf[NET_LL_HDRLEN(dev) + sizeof(struct icmp_iphdr_s)])
/* Allocate a new ICMP data callback */
+2 -2
View File
@@ -90,8 +90,8 @@ void icmp_poll(FAR struct net_driver_s *dev)
{
/* Setup for the application callback */
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPICMP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPICMP_HDRLEN];
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPICMP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPICMP_HDRLEN];
dev->d_len = 0;
dev->d_sndlen = 0;
+1 -1
View File
@@ -57,7 +57,7 @@
* Pre-processor Definitions
****************************************************************************/
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
+2 -2
View File
@@ -62,7 +62,7 @@
* Pre-processor Definitions
****************************************************************************/
#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Functions
@@ -125,7 +125,7 @@ void igmp_input(struct net_driver_s *dev)
/* Verify the message length */
if (dev->d_len < NET_LL_HDRLEN+IPIGMP_HDRLEN)
if (dev->d_len < NET_LL_HDRLEN(dev) + IPIGMP_HDRLEN)
{
IGMP_STATINCR(g_netstats.igmp.length_errors);
nlldbg("Length error\n");
+2 -2
View File
@@ -151,8 +151,8 @@ void igmp_poll(FAR struct net_driver_s *dev)
/* Setup the poll operation */
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPIGMP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPIGMP_HDRLEN];
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPIGMP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPIGMP_HDRLEN];
dev->d_len = 0;
dev->d_sndlen = 0;
+1 -1
View File
@@ -76,7 +76,7 @@
/* Buffer layout */
#define RASIZE (4)
#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
+2 -2
View File
@@ -102,8 +102,8 @@ void pkt_poll(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn)
{
/* Setup for the application callback */
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_len = 0;
dev->d_sndlen = 0;
+13 -2
View File
@@ -169,7 +169,7 @@ static inline void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
* connection operation via by the lower, device interfacing layer.
*
* Parameters:
* dev The sructure of the network driver that caused the interrupt
* dev The structure of the network driver that caused the interrupt
* pvconn The connection structure associated with the socket
* flags Set of events describing why the callback was invoked
*
@@ -250,6 +250,17 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
psock_teardown_callbacks(pstate, pstate->tc_result);
#ifdef CONFIG_NET_MULTILINK
/* When we set up the connection structure, we did not know the size
* of the initial MSS. Now that the connection is associated with a
* network device, we now know the size of link layer header and can
* determine the correct initial MSS.
*/
DEBUGASSERT(psock->s_conn);
psock->s_conn->mss = TCP_INITIAL_MSS(dev);
#endif
/* Wake up the waiting thread */
sem_post(&pstate->tc_sem);
@@ -305,7 +316,7 @@ static inline int psock_tcp_connect(FAR struct socket *psock,
}
else
{
/* Perform the uIP connection operation */
/* Perform the TCP connection operation */
ret = tcp_connect(psock->s_conn, inaddr);
}
+2 -2
View File
@@ -70,14 +70,14 @@
#include "socket/socket.h"
/****************************************************************************
* Definitions
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_NET_TCP_SPLIT) && !defined(CONFIG_NET_TCP_SPLIT_SIZE)
# define CONFIG_NET_TCP_SPLIT_SIZE 40
#endif
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Types
+3 -3
View File
@@ -71,11 +71,11 @@
#include "socket/socket.h"
/****************************************************************************
* Definitions
* Pre-processor Definitions
****************************************************************************/
#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Types
+2 -1
View File
@@ -358,7 +358,8 @@ FAR struct tcp_conn_s *tcp_listener(uint16_t portno);
*
****************************************************************************/
FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct tcp_iphdr_s *buf);
FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
FAR struct tcp_iphdr_s *buf);
/****************************************************************************
* Name: tcp_bind()
+9 -4
View File
@@ -508,7 +508,8 @@ FAR struct tcp_conn_s *tcp_listener(uint16_t portno)
*
****************************************************************************/
FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct tcp_iphdr_s *buf)
FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
FAR struct tcp_iphdr_s *buf)
{
FAR struct tcp_conn_s *conn = tcp_alloc();
if (conn)
@@ -522,7 +523,7 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct tcp_iphdr_s *buf)
conn->nrtx = 0;
conn->lport = buf->destport;
conn->rport = buf->srcport;
conn->mss = TCP_INITIAL_MSS;
conn->mss = TCP_INITIAL_MSS(dev);
net_ipaddr_copy(conn->ripaddr, net_ip4addr_conv32(buf->srcipaddr));
conn->tcpstateflags = TCP_SYN_RCVD;
@@ -670,12 +671,16 @@ int tcp_connect(FAR struct tcp_conn_s *conn,
return port;
}
/* Initialize and return the connection structure, bind it to the port number */
/* Initialize and return the connection structure, bind it to the port
* number. At this point, we do not know the size of the initial MSS We
* know the total size of the packet buffer, but we don't yet know the
* size of link layer header.
*/
conn->tcpstateflags = TCP_SYN_SENT;
tcp_initsequence(conn->sndseq);
conn->mss = TCP_INITIAL_MSS;
conn->mss = MIN_TCP_INITIAL_MSS;
conn->unacked = 1; /* TCP length of the SYN is one. */
conn->nrtx = 0;
conn->timer = 1; /* Send the SYN next time around. */
+20 -20
View File
@@ -64,7 +64,7 @@
* Pre-processor Definitions
****************************************************************************/
#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
@@ -110,8 +110,8 @@ void tcp_input(FAR struct net_driver_s *dev)
int len;
int i;
dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
#ifdef CONFIG_NET_STATISTICS
g_netstats.tcp.recv++;
@@ -177,7 +177,7 @@ void tcp_input(FAR struct net_driver_s *dev)
* user application to accept it.
*/
conn = tcp_alloc_accept(pbuf);
conn = tcp_alloc_accept(dev, pbuf);
if (conn)
{
/* The connection structure was successfully allocated. Now see if
@@ -219,7 +219,7 @@ void tcp_input(FAR struct net_driver_s *dev)
{
for (i = 0; i < ((pbuf->tcpoffset >> 4) - 5) << 2 ;)
{
opt = dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + i];
opt = dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + i];
if (opt == TCP_OPT_END)
{
/* End of options. */
@@ -233,13 +233,13 @@ void tcp_input(FAR struct net_driver_s *dev)
++i;
}
else if (opt == TCP_OPT_MSS &&
dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i] == TCP_OPT_MSS_LEN)
dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i] == TCP_OPT_MSS_LEN)
{
/* An MSS option with the right option length. */
tmp16 = ((uint16_t)dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 2 + i] << 8) |
(uint16_t)dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 3 + i];
conn->mss = tmp16 > TCP_MSS ? TCP_MSS : tmp16;
tmp16 = ((uint16_t)dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 2 + i] << 8) |
(uint16_t)dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 3 + i];
conn->mss = tmp16 > TCP_MSS(dev) ? TCP_MSS(dev) : tmp16;
/* And we are done processing options. */
@@ -251,7 +251,7 @@ void tcp_input(FAR struct net_driver_s *dev)
* can skip past them.
*/
if (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i] == 0)
if (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i] == 0)
{
/* If the length field is zero, the options are malformed
* and we don't process them further.
@@ -259,7 +259,7 @@ void tcp_input(FAR struct net_driver_s *dev)
break;
}
i += dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i];
i += dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i];
}
}
}
@@ -509,7 +509,7 @@ found:
{
for (i = 0; i < ((pbuf->tcpoffset >> 4) - 5) << 2 ;)
{
opt = dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + i];
opt = dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + i];
if (opt == TCP_OPT_END)
{
/* End of options. */
@@ -523,14 +523,14 @@ found:
++i;
}
else if (opt == TCP_OPT_MSS &&
dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i] == TCP_OPT_MSS_LEN)
dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i] == TCP_OPT_MSS_LEN)
{
/* An MSS option with the right option length. */
tmp16 =
(dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 2 + i] << 8) |
dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 3 + i];
conn->mss = tmp16 > TCP_MSS ? TCP_MSS : tmp16;
(dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 2 + i] << 8) |
dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 3 + i];
conn->mss = tmp16 > TCP_MSS(dev) ? TCP_MSS(dev) : tmp16;
/* And we are done processing options. */
@@ -542,7 +542,7 @@ found:
* easily can skip past them.
*/
if (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i] == 0)
if (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i] == 0)
{
/* If the length field is zero, the options are
* malformed and we don't process them further.
@@ -550,7 +550,7 @@ found:
break;
}
i += dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i];
i += dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i];
}
}
}
@@ -692,8 +692,8 @@ found:
* When the application is called, the d_len field
* contains the length of the incoming data. The application can
* access the incoming data through the global pointer
* d_appdata, which usually points IPTCP_HDRLEN + NET_LL_HDRLEN
* bytes into the d_buf array.
* d_appdata, which usually points IPTCP_HDRLEN + NET_LL_HDRLEN(dev)
* bytes into the d_buf array.
*
* If the application wishes to send any data, this data should be
* put into the d_appdata and the length of the data should be
+2 -2
View File
@@ -103,8 +103,8 @@ void tcp_poll(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
{
/* Set up for the callback */
dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
dev->d_len = 0;
dev->d_sndlen = 0;
+3 -3
View File
@@ -62,7 +62,7 @@
* Pre-processor Definitions
****************************************************************************/
#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
@@ -360,8 +360,8 @@ void tcp_ack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
pbuf->optdata[0] = TCP_OPT_MSS;
pbuf->optdata[1] = TCP_OPT_MSS_LEN;
pbuf->optdata[2] = (TCP_MSS) / 256;
pbuf->optdata[3] = (TCP_MSS) & 255;
pbuf->optdata[2] = TCP_MSS(dev) / 256;
pbuf->optdata[3] = TCP_MSS(dev) & 255;
dev->d_len = IPTCP_HDRLEN + TCP_OPT_MSS_LEN;
pbuf->tcpoffset = ((TCP_HDRLEN + TCP_OPT_MSS_LEN) / 4) << 4;
+1 -1
View File
@@ -79,7 +79,7 @@
* Pre-processor Definitions
****************************************************************************/
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/* Debug */
+1 -1
View File
@@ -71,7 +71,7 @@
# define CONFIG_NET_TCP_SPLIT_SIZE 40
#endif
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Types
+2 -2
View File
@@ -100,8 +100,8 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
{
uint8_t result;
dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
/* Increase the TCP sequence number */
+4 -4
View File
@@ -60,7 +60,7 @@
* Pre-processor Definitions
****************************************************************************/
#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
@@ -114,7 +114,7 @@ int udp_input(FAR struct net_driver_s *dev)
dev->d_len -= IPUDP_HDRLEN;
#ifdef CONFIG_NET_UDP_CHECKSUMS
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
if (pbuf->udpchksum != 0 && udp_chksum(dev) != 0xffff)
{
#ifdef CONFIG_NET_STATISTICS
@@ -136,8 +136,8 @@ int udp_input(FAR struct net_driver_s *dev)
/* Set-up for the application callback */
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_sndlen = 0;
/* Perform the application callback */
+2 -2
View File
@@ -100,8 +100,8 @@ void udp_poll(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
{
/* Set-up for the application callback */
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_len = 0;
dev->d_sndlen = 0;
+1 -1
View File
@@ -62,7 +62,7 @@
* Pre-processor Definitions
****************************************************************************/
#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
+4 -4
View File
@@ -54,8 +54,8 @@
* Pre-processor Definitions
****************************************************************************/
#define BUF ((struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define BUF ((struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Data
@@ -145,7 +145,7 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
/* Sum TCP header and data. */
sum = chksum(sum, &dev->d_buf[IP_HDRLEN + NET_LL_HDRLEN], upper_layer_len);
sum = chksum(sum, &dev->d_buf[IP_HDRLEN + NET_LL_HDRLEN(dev)], upper_layer_len);
return (sum == 0) ? 0xffff : htons(sum);
}
@@ -285,7 +285,7 @@ uint16_t ip_chksum(FAR struct net_driver_s *dev)
{
uint16_t sum;
sum = chksum(0, &dev->d_buf[NET_LL_HDRLEN], IP_HDRLEN);
sum = chksum(0, &dev->d_buf[NET_LL_HDRLEN(dev)], IP_HDRLEN);
return (sum == 0) ? 0xffff : htons(sum);
}
#endif /* CONFIG_NET_ARCH_CHKSUM */