diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-01-15 08:03:56 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-01-15 08:03:56 -0600 |
commit | d01102573821393af9572e96cb4edd0c8f01af84 (patch) | |
tree | b46c182ec342e351f0dc17534dd101ac93684b50 | |
parent | 475bd20ef9ae32104f844eb015ad685e2b8ccd99 (diff) | |
download | px4-nuttx-d01102573821393af9572e96cb4edd0c8f01af84.tar.gz px4-nuttx-d01102573821393af9572e96cb4edd0c8f01af84.tar.bz2 px4-nuttx-d01102573821393af9572e96cb4edd0c8f01af84.zip |
- Rename devif_input() ipv4_input()
- Copy net/devif/devif_input.c to ipv6_input.c. Remove all IPv4-specific logic.
- Rename net/devif/devif_input.c to ipv4_input.c. Remove all IPv6-specific logic
- Split IPv4 header structure out as net_ipv4hdr_s from net_iphdr_s
27 files changed, 387 insertions, 144 deletions
diff --git a/nuttx/arch/arm/src/c5471/c5471_ethernet.c b/nuttx/arch/arm/src/c5471/c5471_ethernet.c index 463bcacab..eab048188 100644 --- a/nuttx/arch/arm/src/c5471/c5471_ethernet.c +++ b/nuttx/arch/arm/src/c5471/c5471_ethernet.c @@ -1239,7 +1239,7 @@ static void c5471_receive(struct c5471_driver_s *c5471) #endif { arp_ipin(dev); - devif_input(dev); + ipv4_input(dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/kinetis/kinetis_enet.c b/nuttx/arch/arm/src/kinetis/kinetis_enet.c index 5322121e6..de015e707 100644 --- a/nuttx/arch/arm/src/kinetis/kinetis_enet.c +++ b/nuttx/arch/arm/src/kinetis/kinetis_enet.c @@ -523,7 +523,7 @@ static void kinetis_receive(FAR struct kinetis_driver_s *priv) #endif { arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c b/nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c index f63ef7b94..07717977c 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c @@ -879,7 +879,7 @@ static void lpc17_rxdone(struct lpc17_driver_s *priv) EMAC_STAT(priv, rx_ip); arp_ipin(&priv->lp_dev); - devif_input(&priv->lp_dev); + ipv4_input(&priv->lp_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the field d_len will diff --git a/nuttx/arch/arm/src/sam34/sam_emac.c b/nuttx/arch/arm/src/sam34/sam_emac.c index b599f5ba2..f43819c99 100644 --- a/nuttx/arch/arm/src/sam34/sam_emac.c +++ b/nuttx/arch/arm/src/sam34/sam_emac.c @@ -1151,7 +1151,7 @@ static void sam_receive(struct sam_emac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/sama5/sam_emaca.c b/nuttx/arch/arm/src/sama5/sam_emaca.c index b0b1f363c..a1a9c7bba 100644 --- a/nuttx/arch/arm/src/sama5/sam_emaca.c +++ b/nuttx/arch/arm/src/sama5/sam_emaca.c @@ -1191,7 +1191,7 @@ static void sam_receive(struct sam_emac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/sama5/sam_emacb.c b/nuttx/arch/arm/src/sama5/sam_emacb.c index b543f736a..922b88bf8 100644 --- a/nuttx/arch/arm/src/sama5/sam_emacb.c +++ b/nuttx/arch/arm/src/sama5/sam_emacb.c @@ -1517,7 +1517,7 @@ static void sam_receive(struct sam_emac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/sama5/sam_gmac.c b/nuttx/arch/arm/src/sama5/sam_gmac.c index 3c6468f3d..69a1a62ab 100644 --- a/nuttx/arch/arm/src/sama5/sam_gmac.c +++ b/nuttx/arch/arm/src/sama5/sam_gmac.c @@ -1121,7 +1121,7 @@ static void sam_receive(struct sam_gmac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.c b/nuttx/arch/arm/src/stm32/stm32_eth.c index 1045bcd16..4fbd1c4ab 100644 --- a/nuttx/arch/arm/src/stm32/stm32_eth.c +++ b/nuttx/arch/arm/src/stm32/stm32_eth.c @@ -1627,7 +1627,7 @@ static void stm32_receive(FAR struct stm32_ethmac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/tiva/lm3s_ethernet.c b/nuttx/arch/arm/src/tiva/lm3s_ethernet.c index 6f9736c80..059d1c34c 100644 --- a/nuttx/arch/arm/src/tiva/lm3s_ethernet.c +++ b/nuttx/arch/arm/src/tiva/lm3s_ethernet.c @@ -773,7 +773,7 @@ static void tiva_receive(struct tiva_driver_s *priv) EMAC_STAT(priv, rx_ip); arp_ipin(&priv->ld_dev); - devif_input(&priv->ld_dev); + ipv4_input(&priv->ld_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/tiva/tm4c_ethernet.c b/nuttx/arch/arm/src/tiva/tm4c_ethernet.c index 1cb980d9a..10116b0c7 100644 --- a/nuttx/arch/arm/src/tiva/tm4c_ethernet.c +++ b/nuttx/arch/arm/src/tiva/tm4c_ethernet.c @@ -1694,7 +1694,7 @@ static void tiva_receive(FAR struct tiva_ethmac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/hc/src/m9s12/m9s12_ethernet.c b/nuttx/arch/hc/src/m9s12/m9s12_ethernet.c index 4fda5e752..b0dd07106 100644 --- a/nuttx/arch/hc/src/m9s12/m9s12_ethernet.c +++ b/nuttx/arch/hc/src/m9s12/m9s12_ethernet.c @@ -265,7 +265,7 @@ static void emac_receive(FAR struct emac_driver_s *priv) #endif { arp_ipin(&priv->d_dev); - devif_input(&priv->d_dev); + ipv4_input(&priv->d_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c b/nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c index e71127dac..7e66facea 100644 --- a/nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c +++ b/nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c @@ -1436,7 +1436,7 @@ static void pic32mx_rxdone(struct pic32mx_driver_s *priv) EMAC_STAT(priv, rx_ip); arp_ipin(&priv->pd_dev); - devif_input(&priv->pd_dev); + ipv4_input(&priv->pd_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the field d_len will diff --git a/nuttx/arch/sim/src/up_netdriver.c b/nuttx/arch/sim/src/up_netdriver.c index a91052521..78431a37d 100644 --- a/nuttx/arch/sim/src/up_netdriver.c +++ b/nuttx/arch/sim/src/up_netdriver.c @@ -166,7 +166,7 @@ void netdriver_loop(void) #endif { arp_ipin(&g_sim_dev); - devif_input(&g_sim_dev); + ipv4_input(&g_sim_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the global variable diff --git a/nuttx/arch/z80/src/ez80/ez80_emac.c b/nuttx/arch/z80/src/ez80/ez80_emac.c index adbb11113..845d431fd 100644 --- a/nuttx/arch/z80/src/ez80/ez80_emac.c +++ b/nuttx/arch/z80/src/ez80/ez80_emac.c @@ -1275,7 +1275,7 @@ static int ez80emac_receive(struct ez80emac_driver_s *priv) EMAC_STAT(priv, rx_ip); arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/cs89x0.c b/nuttx/drivers/net/cs89x0.c index 069e708cd..d779d40f3 100644 --- a/nuttx/drivers/net/cs89x0.c +++ b/nuttx/drivers/net/cs89x0.c @@ -439,7 +439,7 @@ static void cs89x0_receive(struct cs89x0_driver_s *cs89x0, uint16_t isq) #endif { arp_ipin(&cs89x0->cs_dev); - devif_input(&cs89x0->cs_dev); + ipv4_input(&cs89x0->cs_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/dm90x0.c b/nuttx/drivers/net/dm90x0.c index 5c68062c3..f911a408f 100644 --- a/nuttx/drivers/net/dm90x0.c +++ b/nuttx/drivers/net/dm90x0.c @@ -987,7 +987,7 @@ static void dm9x_receive(struct dm9x_driver_s *dm9x) #endif { arp_ipin(&dm9x->dm_dev); - devif_input(&dm9x->dm_dev); + ipv4_input(&dm9x->dm_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/e1000.c b/nuttx/drivers/net/e1000.c index 474daf8f3..017df480d 100644 --- a/nuttx/drivers/net/e1000.c +++ b/nuttx/drivers/net/e1000.c @@ -574,7 +574,7 @@ static void e1000_receive(struct e1000_dev *e1000) #endif { arp_ipin(&e1000->netdev); - devif_input(&e1000->netdev); + ipv4_input(&e1000->netdev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/enc28j60.c b/nuttx/drivers/net/enc28j60.c index 73fb4f275..547a148f6 100644 --- a/nuttx/drivers/net/enc28j60.c +++ b/nuttx/drivers/net/enc28j60.c @@ -1384,7 +1384,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) { nllvdbg("IP packet received (%02x)\n", BUF->type); arp_ipin(&priv->dev); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/encx24j600.c b/nuttx/drivers/net/encx24j600.c index c8619fd9b..ae7d141d5 100644 --- a/nuttx/drivers/net/encx24j600.c +++ b/nuttx/drivers/net/encx24j600.c @@ -1504,7 +1504,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) nllvdbg("Try to process IP packet (%02x)\n", BUF->type); arp_ipin(&priv->dev); - ret = devif_input(&priv->dev); + ret = ipv4_input(&priv->dev); if (ret == OK || (clock_systimer() - descr->ts) > ENC_RXTIMEOUT) { diff --git a/nuttx/drivers/net/skeleton.c b/nuttx/drivers/net/skeleton.c index 9e0a19ebf..e61fe6111 100644 --- a/nuttx/drivers/net/skeleton.c +++ b/nuttx/drivers/net/skeleton.c @@ -293,7 +293,7 @@ static void skel_receive(FAR struct skel_driver_s *skel) #endif { arp_ipin(&skel->sk_dev); - devif_input(&skel->sk_dev); + ipv4_input(&skel->sk_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/slip.c b/nuttx/drivers/net/slip.c index 665cebaf2..0e94ce382 100644 --- a/nuttx/drivers/net/slip.c +++ b/nuttx/drivers/net/slip.c @@ -714,7 +714,7 @@ static int slip_rxtask(int argc, FAR char *argv[]) priv->dev.d_len = priv->rxlen; flags = net_lock(); - devif_input(&priv->dev); + ipv4_input(&priv->dev); /* If the above function invocation resulted in data that should * be sent out on the network, the field d_len will set to a diff --git a/nuttx/drivers/net/vnet.c b/nuttx/drivers/net/vnet.c index 161322da1..5190099a9 100644 --- a/nuttx/drivers/net/vnet.c +++ b/nuttx/drivers/net/vnet.c @@ -310,7 +310,7 @@ void rtos_vnet_recv(struct rgmp_vnet *rgmp_vnet, char *data, int len) #endif { arp_ipin(&vnet->sk_dev); - devif_input(&vnet->sk_dev); + ipv4_input(&vnet->sk_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/include/nuttx/net/ip.h b/nuttx/include/nuttx/net/ip.h index d2deb8f41..160e00fa6 100644 --- a/nuttx/include/nuttx/net/ip.h +++ b/nuttx/include/nuttx/net/ip.h @@ -101,27 +101,11 @@ typedef net_ip6addr_t net_ipaddr_t; typedef net_ip4addr_t net_ipaddr_t; #endif +#ifdef CONFIG_NET_IPv4 /* The IPv4 header */ struct net_iphdr_s { -#ifdef CONFIG_NET_IPv6 - - /* 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_ip6addr_t srcipaddr; /* 128-bit Source address */ - net_ip6addr_t destipaddr; /* 128-bit Destination address */ - -#else /* CONFIG_NET_IPv6 */ - - /* 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 */ @@ -132,9 +116,24 @@ struct net_iphdr_s 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 */ +}; +#endif + +#ifdef CONFIG_NET_IPv6 +/* The IPv6 header */ -#endif /* CONFIG_NET_IPv6 */ +struct net_ipv6hdr_s +{ + 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_ip6addr_t srcipaddr; /* 128-bit Source address */ + net_ip6addr_t destipaddr; /* 128-bit Destination address */ }; +#endif /**************************************************************************** * Public Data @@ -257,22 +256,22 @@ struct net_iphdr_s * addr2 The second IP address. */ -#define net_ipv6addr_cmp(addr1, addr2) \ +#define net_ipv4addr_cmp(addr1, addr2) \ (addr1 == addr2) -#define net_ipv6addr_hdrcmp(addr1, addr2) \ - net_ipv6addr_cmp(net_ip4addr_conv32(addr1), net_ip4addr_conv32(addr2)) +#define net_ipv4addr_hdrcmp(addr1, addr2) \ + net_ipv4addr_cmp(net_ip4addr_conv32(addr1), net_ip4addr_conv32(addr2)) -#define net_ipv4addr_cmp(addr1, addr2) \ +#define net_ipv6addr_cmp(addr1, addr2) \ (memcmp(&addr1, &addr2, sizeof(net_ip6addr_t)) == 0) -#define net_ipv4addr_hdrcmp(addr1, addr2) \ - net_ipv4addr_cmp(addr1, addr2) +#define net_ipv6addr_hdrcmp(addr1, addr2) \ + net_ipv6addr_cmp(addr1, addr2) -#ifndef CONFIG_NET_IPv6 +#if defined(CONFIG_NET_IPv4) +# define net_ipaddr_cmp(addr1, addr2) net_ipv4addr_cmp(addr1, addr2) +# define net_ipaddr_hdrcmp(addr1, addr2) net_ipv4addr_hdrcmp(addr1, addr2) +#elif defined(CONFIG_NET_IPv6) # define net_ipaddr_cmp(addr1, addr2) net_ipv6addr_cmp(addr1, addr2) # define net_ipaddr_hdrcmp(addr1, addr2) net_ipv6addr_hdrcmp(addr1, addr2) -#else -# define net_ipaddr_cmp(addr1, addr2) net_ipv4addr_cmp(addr1, addr2) -# define net_ipaddr_hdrcmp(addr1, addr2) net_ipv4addr_hdrcmp(addr1, addr2 #endif /* Compare two IP addresses under a netmask. The mask is used to mask diff --git a/nuttx/include/nuttx/net/netdev.h b/nuttx/include/nuttx/net/netdev.h index 56e2686e4..4a51f0e44 100644 --- a/nuttx/include/nuttx/net/netdev.h +++ b/nuttx/include/nuttx/net/netdev.h @@ -225,7 +225,7 @@ typedef int (*devif_poll_callback_t)(FAR struct net_driver_s *dev); * These functions are used by a network device driver for interacting * with uIP. * - * Process an incoming packet. + * Process an incoming IP packet. * * This function should be called when the device driver has received * a packet from the network. The packet from the device driver must @@ -243,7 +243,7 @@ typedef int (*devif_poll_callback_t)(FAR struct net_driver_s *dev); * dev->d_len = devicedriver_poll(); * if (dev->d_len > 0) * { - * devif_input(dev); + * ipv4_input(dev); * if (dev->d_len > 0) * { * devicedriver_send(); @@ -262,7 +262,7 @@ typedef int (*devif_poll_callback_t)(FAR struct net_driver_s *dev); * if (BUF->type == HTONS(ETHTYPE_IP)) * { * arp_ipin(); - * devif_input(dev); + * ipv4_input(dev); * if (dev->d_len > 0) * { * arp_out(); @@ -280,7 +280,13 @@ typedef int (*devif_poll_callback_t)(FAR struct net_driver_s *dev); * ****************************************************************************/ -int devif_input(FAR struct net_driver_s *dev); +#ifdef CONFIG_NET_IPv4 +int ipv4_input(FAR struct net_driver_s *dev); +#endif + +#ifdef CONFIG_NET_IPv6 +int ipv6_input(FAR struct net_driver_s *dev); +#endif /**************************************************************************** * Polling of connections diff --git a/nuttx/net/devif/Make.defs b/nuttx/net/devif/Make.defs index 19d5a8c11..743d95153 100644 --- a/nuttx/net/devif/Make.defs +++ b/nuttx/net/devif/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # net/devif/Make.defs # -# Copyright (C) 2007, 2009-2010, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2007, 2009-2010, 2014-2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without @@ -35,8 +35,18 @@ # Network device interface source files -NET_CSRCS += devif_initialize.c net_setipid.c devif_input.c devif_send.c -NET_CSRCS += devif_poll.c devif_callback.c +NET_CSRCS += devif_initialize.c net_setipid.c devif_send.c devif_poll.c +NET_CSRCS += devif_callback.c + +# Device driver IP packet receipt interfaces + +ifeq ($(CONFIG_NET_IPv4),y) +NET_CSRCS += ipv4_input.c +endif + +ifeq ($(CONFIG_NET_IPv6),y) +NET_CSRCS += ipv6_input.c +endif # I/O buffer chain support required? diff --git a/nuttx/net/devif/devif_input.c b/nuttx/net/devif/ipv4_input.c index b9673057b..c15e22f04 100644 --- a/nuttx/net/devif/devif_input.c +++ b/nuttx/net/devif/ipv4_input.c @@ -1,8 +1,8 @@ /**************************************************************************** - * net/devif/devif_input.c - * The uIP TCP/IP stack code. + * net/devif/ipv4_input.c + * Device driver IPv4 packet receipt interface * - * Copyright (C) 2007-2009, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013-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: @@ -51,7 +51,7 @@ * well as some basic ICMP stuff). The implementation couples the IP, * UDP, TCP and the application layers very tightly. To keep the size * of the compiled code down, this code frequently uses the goto - * statement. While it would be possible to break the devif_input() + * statement. While it would be possible to break the ipv4_input() * function into many smaller functions, this would increase the code * size because of the overhead of parameter passing and the fact that * the optimizer would not be as efficient. @@ -78,7 +78,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#ifdef CONFIG_NET_IPv4 #include <sys/ioctl.h> #include <stdint.h> @@ -90,17 +90,14 @@ #include <nuttx/net/netstats.h> #include <nuttx/net/ip.h> -#ifdef CONFIG_NET_IPv6 -# include "ipv6/ipv6.h" -#endif /* CONFIG_NET_IPv6 */ - -#include "devif/devif.h" #include "tcp/tcp.h" #include "udp/udp.h" #include "pkt/pkt.h" #include "icmp/icmp.h" #include "igmp/igmp.h" +#include "devif/devif.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -117,11 +114,11 @@ #define TCP_REASS_LASTFRAG 0x01 /**************************************************************************** - * Public Variables + * Public Data ****************************************************************************/ /**************************************************************************** - * Private Variables + * Private Data ****************************************************************************/ #if defined(CONFIG_NET_TCP_REASSEMBLY) && !defined(CONFIG_NET_IPv6) @@ -181,8 +178,8 @@ static uint8_t devif_reassembly(void) * fragment into the buffer. */ - if (net_ipaddr_hdrcmp(pbuf->srcipaddr, pfbuf->srcipaddr) && - net_ipaddr_hdrcmp(pbuf->destipaddr, pfbuf->destipaddr) && + if (net_ipv4addr_hdrcmp(pbuf->srcipaddr, pfbuf->srcipaddr) && + net_ipv4addr_hdrcmp(pbuf->destipaddr, pfbuf->destipaddr) && pbuf->g_ipid[0] == pfbuf->g_ipid[0] && pbuf->g_ipid[1] == pfbuf->g_ipid[1]) { len = (pbuf->len[0] << 8) + pbuf->len[1] - (pbuf->vhl & 0x0f) * 4; @@ -298,7 +295,7 @@ nullreturn: ****************************************************************************/ /**************************************************************************** - * Function: devif_input + * Function: ipv4_input * * Description: * @@ -312,7 +309,7 @@ nullreturn: * ****************************************************************************/ -int devif_input(FAR struct net_driver_s *dev) +int ipv4_input(FAR struct net_driver_s *dev) { FAR struct net_iphdr_s *pbuf = BUF; uint16_t iplen; @@ -324,23 +321,6 @@ int devif_input(FAR struct net_driver_s *dev) #endif /* Start of IP input header processing code. */ - -#ifdef CONFIG_NET_IPv6 - /* Check validity of the IP header. */ - - if ((pbuf->vtc & 0xf0) != 0x60) - { - /* IP version and header length. */ - -#ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; - g_netstats.ip.vhlerr++; -#endif - nlldbg("Invalid IPv6 version: %d\n", pbuf->vtc >> 4); - goto drop; - } - -#else /* CONFIG_NET_IPv6 */ /* Check validity of the IP header. */ if (pbuf->vhl != 0x45) @@ -354,7 +334,6 @@ int devif_input(FAR struct net_driver_s *dev) nlldbg("Invalid IP version or header length: %02x\n", pbuf->vhl); goto drop; } -#endif /* CONFIG_NET_IPv6 */ /* Check the size of the packet. If the size reported to us in d_len is * smaller the size reported in the IP header, we assume that the packet @@ -363,20 +342,7 @@ int devif_input(FAR struct net_driver_s *dev) * we set d_len to the correct value. */ -#ifdef CONFIG_NET_IPv6 - /* The length reported in the IPv6 header is the length of the payload - * that follows the header. However, uIP uses the d_len variable for - * holding the size of the entire packet, including the IP header. For - * IPv4 this is not a problem as the length field in the IPv4 header - * contains the length of the entire packet. But for IPv6 we need to add - * the size of the IPv6 header (40 bytes). - */ - - iplen = (pbuf->len[0] << 8) + pbuf->len[1] + IPv6_HDRLEN; -#else iplen = (pbuf->len[0] << 8) + pbuf->len[1]; -#endif /* CONFIG_NET_IPv6 */ - if (iplen <= dev->d_len) { dev->d_len = iplen; @@ -387,7 +353,6 @@ int devif_input(FAR struct net_driver_s *dev) goto drop; } -#ifndef CONFIG_NET_IPv6 /* Check the fragment flag. */ if ((pbuf->ipoffset[0] & 0x3f) != 0 || pbuf->ipoffset[1] != 0) @@ -407,7 +372,6 @@ int devif_input(FAR struct net_driver_s *dev) goto drop; #endif /* CONFIG_NET_TCP_REASSEMBLY */ } -#endif /* CONFIG_NET_IPv6 */ /* If IP broadcast support is configured, we check for a broadcast * UDP packet, which may be destined to us (even if there is no IP @@ -417,11 +381,7 @@ int devif_input(FAR struct net_driver_s *dev) #if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP) if (pbuf->proto == IP_PROTO_UDP && -#ifndef CONFIG_NET_IPv6 - net_ipaddr_cmp(net_ip4addr_conv32(pbuf->destipaddr), g_alloneaddr)) -#else - net_ipaddr_cmp(pbuf->destipaddr, g_alloneaddr)) -#endif + net_ipv4addr_cmp(net_ip4addr_conv32(pbuf->destipaddr), g_alloneaddr)) { return udp_input(dev); } @@ -434,14 +394,14 @@ int devif_input(FAR struct net_driver_s *dev) else #endif #ifdef CONFIG_NET_ICMP - if (net_ipaddr_cmp(dev->d_ipaddr, g_allzeroaddr)) + if (net_ipv4addr_cmp(dev->d_ipaddr, g_allzeroaddr)) { /* If we are configured to use ping IP address configuration and * hasn't been assigned an IP address yet, we accept all ICMP * packets. */ -#if defined(CONFIG_NET_PINGADDRCONF) && !defined(CONFIG_NET_IPv6) +#ifdef CONFIG_NET_PINGADDRCONF if (pbuf->proto == IP_PROTO_ICMP) { nlldbg("Possible ping config packet received\n"); @@ -461,11 +421,11 @@ int devif_input(FAR struct net_driver_s *dev) #endif { /* Check if the packet is destined for our IP address. */ -#ifndef CONFIG_NET_IPv6 - if (!net_ipaddr_cmp(net_ip4addr_conv32(pbuf->destipaddr), dev->d_ipaddr)) + + if (!net_ipv4addr_cmp(net_ip4addr_conv32(pbuf->destipaddr), dev->d_ipaddr)) { #ifdef CONFIG_NET_IGMP - net_ipaddr_t destip = net_ip4addr_conv32(pbuf->destipaddr); + net_ipv4addr_t destip = net_ip4addr_conv32(pbuf->destipaddr); if (igmp_grpfind(dev, &destip) == NULL) #endif { @@ -475,27 +435,8 @@ int devif_input(FAR struct net_driver_s *dev) goto drop; } } - -#else /* CONFIG_NET_IPv6 */ - /* For IPv6, packet reception is a little trickier as we need to - * make sure that we listen to certain multicast addresses (all - * hosts multicast address, and the solicited-node multicast - * address) as well. However, we will cheat here and accept all - * multicast packets that are sent to the ff02::/16 addresses. - */ - - if (!net_ipaddr_cmp(pbuf->destipaddr, dev->d_ipaddr) && - pbuf->destipaddr[0] != 0xff02) - { -#ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; -#endif - goto drop; - } -#endif /* CONFIG_NET_IPv6 */ } -#ifndef CONFIG_NET_IPv6 if (ipv4_chksum(dev) != 0xffff) { /* Compute and check the IP header checksum. */ @@ -507,7 +448,6 @@ int devif_input(FAR struct net_driver_s *dev) nlldbg("Bad IP checksum\n"); goto drop; } -#endif /* CONFIG_NET_IPv6 */ /* Everything looks good so far. Now process the incoming packet * according to the protocol. @@ -530,24 +470,18 @@ int devif_input(FAR struct net_driver_s *dev) /* Check for ICMP input */ #ifdef CONFIG_NET_ICMP -#ifndef CONFIG_NET_IPv6 case IP_PROTO_ICMP: /* ICMP input */ -#else - case IP_PROTO_ICMP6: /* ICMP6 input */ -#endif icmp_input(dev); break; #endif - /* Check for ICMP input */ + /* Check for IGMP input */ #ifdef CONFIG_NET_IGMP -#ifndef CONFIG_NET_IPv6 case IP_PROTO_IGMP: /* IGMP input */ igmp_input(dev); break; #endif -#endif default: /* Unrecognized/unsupported protocol */ #ifdef CONFIG_NET_STATISTICS @@ -571,4 +505,4 @@ drop: dev->d_len = 0; return OK; } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET_IPv4 */ diff --git a/nuttx/net/devif/ipv6_input.c b/nuttx/net/devif/ipv6_input.c new file mode 100644 index 000000000..c02db74c1 --- /dev/null +++ b/nuttx/net/devif/ipv6_input.c @@ -0,0 +1,294 @@ +/**************************************************************************** + * net/devif/ipv6_input.c + * Device driver IPv6 packet receipt interface + * + * Copyright (C) 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: + * + * uIP is an implementation of the TCP/IP protocol stack intended for + * small 8-bit and 16-bit microcontrollers. + * + * uIP provides the necessary protocols for Internet communication, + * with a very small code footprint and RAM requirements - the uIP + * code size is on the order of a few kilobytes and RAM usage is on + * the order of a few hundred bytes. + * + * Original author Adam Dunkels <adam@dunkels.com> + * Copyright () 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * uIP is a small implementation of the IP, UDP and TCP protocols (as + * well as some basic ICMP stuff). The implementation couples the IP, + * UDP, TCP and the application layers very tightly. To keep the size + * of the compiled code down, this code frequently uses the goto + * statement. While it would be possible to break the ipv6_input() + * function into many smaller functions, this would increase the code + * size because of the overhead of parameter passing and the fact that + * the optimizer would not be as efficient. + * + * The principle is that we have a small buffer, called the d_buf, + * in which the device driver puts an incoming packet. The TCP/IP + * stack parses the headers in the packet, and calls the + * application. If the remote host has sent data to the application, + * this data is present in the d_buf and the application read the + * data from there. It is up to the application to put this data into + * a byte stream if needed. The application will not be fed with data + * that is out of sequence. + * + * If the application wishes to send data to the peer, it should put + * its data into the d_buf. The d_appdata pointer points to the + * first available byte. The TCP/IP stack will calculate the + * checksums, and fill in the necessary header fields and finally send + * the packet back to the peer. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#ifdef CONFIG_NET_IPv6 + +#include <sys/ioctl.h> +#include <stdint.h> +#include <debug.h> +#include <string.h> + +#include <nuttx/net/netconfig.h> +#include <nuttx/net/netdev.h> +#include <nuttx/net/netstats.h> +#include <nuttx/net/ip.h> + +#include "ipv6/ipv6.h" +#include "tcp/tcp.h" +#include "udp/udp.h" +#include "pkt/pkt.h" +#include "icmpv6/icmpv6.h" + +#include "devif/devif.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Macros */ + +#define BUF ((FAR struct net_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: ipv6_input + * + * Description: + * + * Returned Value: + * OK The packet was processed (or dropped) and can be discarded. + * ERROR There is a matching connection, but could not dispatch the packet + * yet. Currently useful for UDP when a packet arrives before a recv + * call is in place. + * + * Assumptions: + * + ****************************************************************************/ + +int ipv6_input(FAR struct net_driver_s *dev) +{ + FAR struct net_ipv6hdr_s *pbuf = BUF; + uint16_t iplen; + + /* This is where the input processing starts. */ + +#ifdef CONFIG_NET_STATISTICS + g_netstats.ip.recv++; +#endif + + /* Start of IP input header processing code. */ + /* Check validity of the IP header. */ + + if ((pbuf->vtc & 0xf0) != 0x60) + { + /* IP version and header length. */ + +#ifdef CONFIG_NET_STATISTICS + g_netstats.ip.drop++; + g_netstats.ip.vhlerr++; +#endif + nlldbg("Invalid IPv6 version: %d\n", pbuf->vtc >> 4); + goto drop; + } + + /* Check the size of the packet. If the size reported to us in d_len is + * smaller the size reported in the IP header, we assume that the packet + * has been corrupted in transit. If the size of d_len is larger than the + * size reported in the IP packet header, the packet has been padded and + * we set d_len to the correct value. + * + * The length reported in the IPv6 header is the length of the payload + * that follows the header. However, uIP uses the d_len variable for + * holding the size of the entire packet, including the IP header. For + * IPv4 this is not a problem as the length field in the IPv4 header + * contains the length of the entire packet. But for IPv6 we need to add + * the size of the IPv6 header (40 bytes). + */ + + iplen = (pbuf->len[0] << 8) + pbuf->len[1] + IPv6_HDRLEN; + if (iplen <= dev->d_len) + { + dev->d_len = iplen; + } + else + { + nlldbg("IP packet shorter than length in IP header\n"); + goto drop; + } + + /* If IP broadcast support is configured, we check for a broadcast + * UDP packet, which may be destined to us (even if there is no IP + * address yet assigned to the device as is the case when we are + * negotiating over DHCP for an address). + */ + +#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP) + if (pbuf->proto == IP_PROTO_UDP && + net_ipv6addr_cmp(pbuf->destipaddr, g_alloneaddr)) + { + return udp_input(dev); + } + + /* In most other cases, the device must be assigned a non-zero IP + * address. Another exception is when CONFIG_NET_PINGADDRCONF is + * enabled... + */ + + else +#endif +#ifdef CONFIG_NET_ICMPv6 + if (net_ipv6addr_cmp(dev->d_ipaddr, g_allzeroaddr)) + { + /* If we are configured to use ping IP address configuration and + * hasn't been assigned an IP address yet, we accept all ICMP + * packets. + */ + + nlldbg("No IP address assigned\n"); + goto drop; + } + + /* Check if the packet is destined for out IP address */ + else +#endif + { + /* Check if the packet is destined for our IP address. + * + * For IPv6, packet reception is a little trickier as we need to + * make sure that we listen to certain multicast addresses (all + * hosts multicast address, and the solicited-node multicast + * address) as well. However, we will cheat here and accept all + * multicast packets that are sent to the ff02::/16 addresses. + */ + + if (!net_ipv6addr_cmp(pbuf->destipaddr, dev->d_ipaddr) && + pbuf->destipaddr[0] != 0xff02) + { +#ifdef CONFIG_NET_STATISTICS + g_netstats.ip.drop++; +#endif + goto drop; + } + } + + /* Everything looks good so far. Now process the incoming packet + * according to the protocol. + */ + + switch (pbuf->proto) + { +#ifdef CONFIG_NET_TCP + case IP_PROTO_TCP: /* TCP input */ + tcp_input(dev); + break; +#endif + +#ifdef CONFIG_NET_UDP + case IP_PROTO_UDP: /* UDP input */ + udp_input(dev); + break; +#endif + + /* Check for ICMP input */ + +#ifdef CONFIG_NET_ICMPv6 + case IP_PROTO_ICMP6: /* ICMP6 input */ + icmpv6_input(dev); + break; +#endif + + default: /* Unrecognized/unsupported protocol */ +#ifdef CONFIG_NET_STATISTICS + g_netstats.ip.drop++; + g_netstats.ip.protoerr++; +#endif + + nlldbg("Unrecognized IP protocol\n"); + goto drop; + } + + /* Return and let the caller do any pending transmission. */ + + return OK; + + /* Drop the packet. NOTE that OK is returned meaning that the + * packet has been processed (although processed unsuccessfully). + */ + +drop: + dev->d_len = 0; + return OK; +} +#endif /* CONFIG_NET_IPv6 */ |