uip: Move the uip source into a subdirectory.

The network stack code is being refactored so that the IPV6 stack won't
conflict with the IPV4 one, aka uip.

Change-Id: Id2bcf99b8c983982fb9bf09713f58a8fe795b4d8
diff --git a/src/debug/netboot.c b/src/debug/netboot.c
index 3d620c4..10b453c 100644
--- a/src/debug/netboot.c
+++ b/src/debug/netboot.c
@@ -22,7 +22,7 @@
 #include "drivers/console/display.h"
 #include "netboot/netboot.h"
 #include "netboot/params.h"
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 /*
  * These are the real implementations for developer-build features that override
diff --git a/src/drivers/net/net.c b/src/drivers/net/net.c
index c763781..5eaa753 100644
--- a/src/drivers/net/net.c
+++ b/src/drivers/net/net.c
@@ -26,8 +26,8 @@
 
 #include "base/time.h"
 #include "drivers/net/net.h"
-#include "net/uip.h"
-#include "net/uip_arp.h"
+#include "net/uip/arp.h"
+#include "net/uip/uip.h"
 
 ListNode net_pollers;
 static ListNode net_devices;
diff --git a/src/drivers/net/net.h b/src/drivers/net/net.h
index 953f4cf..6422c53 100644
--- a/src/drivers/net/net.h
+++ b/src/drivers/net/net.h
@@ -26,7 +26,7 @@
 #include <stdint.h>
 
 #include "base/list.h"
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 typedef struct NetDevice {
 	ListNode list_node;
diff --git a/src/module/netboot.c b/src/module/netboot.c
index a0c95a8..8b41c6e 100644
--- a/src/module/netboot.c
+++ b/src/module/netboot.c
@@ -32,7 +32,7 @@
 #include "drivers/net/net.h"
 #include "drivers/timer/timer.h"
 #include "module/module.h"
-#include "net/uip.h"
+#include "net/uip/uip.h"
 #include "netboot/netboot.h"
 #include "netboot/params.h"
 #include "vboot/vbnv.h"
diff --git a/src/module/uefi/netboot.c b/src/module/uefi/netboot.c
index 80c119d..23cfbf1 100644
--- a/src/module/uefi/netboot.c
+++ b/src/module/uefi/netboot.c
@@ -27,7 +27,7 @@
 #include "drivers/timer/timer.h"
 #include "module/module.h"
 #include "module/uefi/fwdb.h"
-#include "net/uip.h"
+#include "net/uip/uip.h"
 #include "netboot/netboot.h"
 #include "netboot/params.h"
 
diff --git a/src/net/Kconfig b/src/net/Kconfig
index da9bece..50e41fe 100644
--- a/src/net/Kconfig
+++ b/src/net/Kconfig
@@ -1,373 +1,17 @@
-## Copyright (c) 2001-2003, Adam Dunkels.
-## Copyright 2013 Google Inc.
-## 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.
+## Copyright 2016 Google Inc.  All rights reserved.
 ##
-## 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.
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; version 2 of the License.
 ##
-## This file is part of the uIP TCP/IP stack.
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
-menu "Static configuration options"
-
-config UIP_IPADDR0
-	int "Default IP octet 0"
-	default 0
-
-config UIP_IPADDR1
-	int "Default IP octet 1"
-	default 0
-
-config UIP_IPADDR2
-	int "Default IP octet 2"
-	default 0
-
-config UIP_IPADDR3
-	int "Default IP octet 3"
-	default 0
-
-config UIP_DRIPADDR0
-	int "Default default router IP octet 0"
-	default 0
-
-config UIP_DRIPADDR1
-	int "Default default router IP octet 1"
-	default 0
-
-config UIP_DRIPADDR2
-	int "Default default router IP octet 2"
-	default 0
-
-config UIP_DRIPADDR3
-	int "Default default router IP octet 3"
-	default 0
-
-config UIP_NETMASK0
-	int "Default netmask octet 0"
-	default 0
-
-config UIP_NETMASK1
-	int "Default netmask octet 1"
-	default 0
-
-config UIP_NETMASK2
-	int "Default netmask octet 2"
-	default 0
-
-config UIP_NETMASK3
-	int "Default netmask octet 3"
-	default 0
-
-config UIP_PINGADDRCONF
-	bool "Ping IP address assignment"
-	default n
-	help
-	  uIP uses a "ping" packet for setting its own IP address if this
-	  option is set. If so, uIP will start with an empty IP address and
-	  the destination IP address of the first incoming "ping" (ICMP echo)
-	  packet will be used for setting the hosts IP address.
-
-	  This works only if fixed IP configuration is disabled.
-
-config UIP_ETHADDR0
-	hex "Default MAC address octet 0"
-	default 0
-
-config UIP_ETHADDR1
-	hex "Default MAC address octet 1"
-	default 0
-
-config UIP_ETHADDR2
-	hex "Default MAC address octet 2"
-	default 0
-
-config UIP_ETHADDR3
-	hex "Default MAC address octet 3"
-	default 0
-
-config UIP_ETHADDR4
-	hex "Default MAC address octet 4"
-	default 0
-
-config UIP_ETHADDR5
-	hex "Default MAC address octet 5"
-	default 0
-
-endmenu
-
-menu "IP configuration options"
-
-config UIP_TTL
-	int "IP TTL (time to live)"
-	default 64
-	help
-	  The IP TTL (time to live) of IP packets sent by uIP.
-
-	  This should normally not be changed.
-
-config UIP_REASSEMBLY
-	bool "Support for IP packet reassembly"
-	default n
-	help
-	  Turn on support for IP packet reassembly.
-
-	  uIP supports reassembly of fragmented IP packets. This features
-	  requires an additional amount of RAM to hold the reassembly buffer
-	  and the reassembly code size is approximately 700 bytes.  The
-	  reassembly buffer is of the same size as the uip_buf buffer
-	  (configured by UIP_BUFSIZE).
-
-	  IP packet reassembly is not heavily tested.
-
-config UIP_REASS_MAXAGE
-	int "IP fragment reassembly max age (seconds)"
-	depends on UIP_REASSEMBLY
-	default 60
-	help
-	  The maximum time an IP fragment should wait in the reassembly
-	  buffer before it is dropped.
-
-config UIP_LINK_MTU
-	int "Maximum transmission unit at the IP layer"
-	default 1280
-
-endmenu
-
-menu "UDP configuration options"
-
-config UIP_UDP
-	bool "UDP support"
-	default y
-
-config UIP_UDP_CHECKSUMS
-	bool "UDP checksums"
-	depends on UIP_UDP
-	default y
-	help
-	  Toggles if UDP checksums should be used or not.
-
-	  Support for UDP checksums is currently not included in uIP,
-	  so this option has no function.
-
-config UIP_UDP_CONNS
-	int "Maximum number of concurrent UDP connections"
-	depends on UIP_UDP
-	default 10
-
-endmenu
-
-menu "TCP configuration options"
-
-config UIP_TCP
-	bool "TCP support"
-	default y
-
-config UIP_ACTIVE_OPEN
-	bool "Support for opening connections"
-	depends on UIP_TCP
-	default y
-	help
-	  Determines if support for opening connections from uIP should be
-	  compiled in.
-
-	  If the applications that are running on top of uIP for this project
-	  do not need to open outgoing TCP connections, this configuration
-	  option can be turned off to reduce the code size of uIP.
-
-config UIP_CONNS
-	int "Maximum number of concurrent TCP connections"
-	depends on UIP_TCP
-	default 10
-	help
-	  The maximum number of simultaneously open TCP connections.
-
-	  Since the TCP connections are statically allocated, turning this
-	  configuration knob down results in less RAM used. Each TCP
-	  connection requires approximately 30 bytes of memory.
-
-config UIP_LISTENPORTS
-	int "Maximum number of simultaneously listening TCP ports"
-	depends on UIP_TCP
-	default 20
-	help
-	  The maximum number of simultaneously listening TCP ports.
-
-	  Each listening TCP port requires 2 bytes of memory.
-
-config UIP_RTO
-	int "Retransmission time out (timer pulses)"
-	depends on UIP_TCP
-	default 3
-	help
-	  The initial retransmission timeout counted in timer pulses.
-
-	  This should not be changed.
-
-config UIP_MAXRTX
-	int "Max segment retransmissions"
-	depends on UIP_TCP
-	default 8
-	help
-	  The maximum number of times a segment should be retransmitted
-	  before the connection should be aborted.
-
-	  This should not be changed.
-
-config UIP_MAXSYNRTX
-	int "Max SYN retransmissions"
-	depends on UIP_TCP
-	default 5
-	help
-	  The maximum number of times a SYN segment should be retransmitted
-	  before a connection request should be deemed to have been
-	  unsuccessful.
-
-	  This should not need to be changed.
-
-config UIP_MAX_TCP_MSS
-	bool "Use the largest TCP maximum segment size"
-	depends on UIP_TCP
-	default y
-	help
-	  The default is UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN
-
-config UIP_TCP_MSS
-	int "TCP maximum segment size"
-	depends on !UIP_MAX_TCP_MSS
-	help
-	  The TCP maximum segment size.
-
-	  This is should not be to set to more than
-	  UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.
-
-config UIP_DEFAULT_RECEIVE_WINDOW
-	bool "Use the default advertised receive window size"
-	depends on UIP_TCP
-	default y
-	help
-	  The default is UIP_TCP_MSS
-
-config UIP_RECEIVE_WINDOW
-	int "Advertised receive window size"
-	depends on !UIP_DEFAULT_RECEIVE_WINDOW
-	help
-	  Should be set low (i.e., to the size of the uip_buf buffer) if the
-	  application is slow to process incoming data, or high (32768 bytes)
-	  if the application processes data quickly.
-
-config UIP_TIME_WAIT_TIMEOUT
-	int "Time to be in the TIME_WAIT state"
-	depends on UIP_TCP
-	default 120
-	help
-	  How long a connection should stay in the TIME_WAIT state.
-
-	  This can be reduced for faster entry into power saving modes.
-
-endmenu
-
-menu "ARP configuration options"
-
-config UIP_ARPTAB_SIZE
-	int "Size of the ARP table"
-	default 8
-	help
-	  The size of the ARP table.
-
-	  This option should be set to a larger value if this uIP node will
-	  have many connections from the local network.
-
-config UIP_ARP_MAXAGE
-	int "Maximum age of ARP table entries in 10s of seconds"
-	default 120
-	help
-	  The maximum age of ARP table entries measured in 10s of seconds.
-
-	  An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD default).
-
-endmenu
-
-menu "General configuration options"
-
-config UIP_DEFAULT_BUFSIZE
-	bool "Use the default packet buffer size"
-	default y
-	help
-	  The default is UIP_LINK_MTU + UIP_LLH_LEN
-
-config UIP_BUFSIZE
-	int "Size of the packet buffer"
-	depends on !UIP_DEFAULT_BUFSIZE
-	help
-	  The size of the uIP packet buffer.
-
-	  The uIP packet buffer should not be smaller than 60 bytes, and does
-	  not need to be larger than 1514 bytes. Lower size results in lower
-	  TCP throughput, larger size results in higher TCP throughput.
-
-config UIP_STATISTICS
-	bool "Statistics support"
-	default n
-	help
-	  Determines if statistics support should be compiled in.
-
-	  The statistics is useful for debugging and to show the user.
-
-config UIP_LOGGING
-	bool "Log certain events"
-	default n
-	help
-	  Determines if logging of certain events should be compiled in.
-
-	  This is useful mostly for debugging. The function uip_log()
-	  must be implemented to suit the architecture of the project, if
-	  logging is turned on.
-
-config UIP_BROADCAST
-	bool "Broadcast support"
-	default n
-	help
-	  Determines if uIP will pass received broadcast/multicast IPv4 UDP
-	  packets to the application (all multicast addresses are treated as
-	  broadcast in that case, there is no IGMP support). uIP can always
-	  send outgoing broadcast packets regardless of this option.
-
-config UIP_LLH_LEN
-	int "Link level header length"
-	default 14
-	help
-	  The link level header length.
-
-	  This is the offset into the uip_buf where the IP header can be
-	  found. For Ethernet, this should be set to 14. For SLIP, this
-	  should be set to 0.
-
-	  We probably won't use this constant for other link layers than
-	  ethernet as they have variable header length (this is due to
-	  variable number and type of address fields and to optional security
-	  features)
-
-	  E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14
-	        802.11 -> 4 + (6*3/4) + 2
-
-endmenu
+source src/net/uip/Kconfig
diff --git a/src/net/Makefile.inc b/src/net/Makefile.inc
index 2b0d577..21c2df6 100644
--- a/src/net/Makefile.inc
+++ b/src/net/Makefile.inc
@@ -1,5 +1,5 @@
 ##
-## Copyright (c) 2013 Google Inc.
+## Copyright (c) 2016 Google Inc.
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -15,12 +15,6 @@
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
-uip-c-ccopts := -fno-strict-aliasing
-
-uip-y += uip_arp.c
-uip-y += uip.c
-uip-y += uip_debug.c
-uip-y += uiplib.c
-uip-$(CONFIG_UIP_UDP) += uip_udp_packet.c
+subdirs-y += uip
 
 net-y += net.c
diff --git a/src/net/uip/Kconfig b/src/net/uip/Kconfig
new file mode 100644
index 0000000..da9bece
--- /dev/null
+++ b/src/net/uip/Kconfig
@@ -0,0 +1,373 @@
+## Copyright (c) 2001-2003, Adam Dunkels.
+## Copyright 2013 Google Inc.
+## 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.
+##
+## This file is part of the uIP TCP/IP stack.
+
+menu "Static configuration options"
+
+config UIP_IPADDR0
+	int "Default IP octet 0"
+	default 0
+
+config UIP_IPADDR1
+	int "Default IP octet 1"
+	default 0
+
+config UIP_IPADDR2
+	int "Default IP octet 2"
+	default 0
+
+config UIP_IPADDR3
+	int "Default IP octet 3"
+	default 0
+
+config UIP_DRIPADDR0
+	int "Default default router IP octet 0"
+	default 0
+
+config UIP_DRIPADDR1
+	int "Default default router IP octet 1"
+	default 0
+
+config UIP_DRIPADDR2
+	int "Default default router IP octet 2"
+	default 0
+
+config UIP_DRIPADDR3
+	int "Default default router IP octet 3"
+	default 0
+
+config UIP_NETMASK0
+	int "Default netmask octet 0"
+	default 0
+
+config UIP_NETMASK1
+	int "Default netmask octet 1"
+	default 0
+
+config UIP_NETMASK2
+	int "Default netmask octet 2"
+	default 0
+
+config UIP_NETMASK3
+	int "Default netmask octet 3"
+	default 0
+
+config UIP_PINGADDRCONF
+	bool "Ping IP address assignment"
+	default n
+	help
+	  uIP uses a "ping" packet for setting its own IP address if this
+	  option is set. If so, uIP will start with an empty IP address and
+	  the destination IP address of the first incoming "ping" (ICMP echo)
+	  packet will be used for setting the hosts IP address.
+
+	  This works only if fixed IP configuration is disabled.
+
+config UIP_ETHADDR0
+	hex "Default MAC address octet 0"
+	default 0
+
+config UIP_ETHADDR1
+	hex "Default MAC address octet 1"
+	default 0
+
+config UIP_ETHADDR2
+	hex "Default MAC address octet 2"
+	default 0
+
+config UIP_ETHADDR3
+	hex "Default MAC address octet 3"
+	default 0
+
+config UIP_ETHADDR4
+	hex "Default MAC address octet 4"
+	default 0
+
+config UIP_ETHADDR5
+	hex "Default MAC address octet 5"
+	default 0
+
+endmenu
+
+menu "IP configuration options"
+
+config UIP_TTL
+	int "IP TTL (time to live)"
+	default 64
+	help
+	  The IP TTL (time to live) of IP packets sent by uIP.
+
+	  This should normally not be changed.
+
+config UIP_REASSEMBLY
+	bool "Support for IP packet reassembly"
+	default n
+	help
+	  Turn on support for IP packet reassembly.
+
+	  uIP supports reassembly of fragmented IP packets. This features
+	  requires an additional amount of RAM to hold the reassembly buffer
+	  and the reassembly code size is approximately 700 bytes.  The
+	  reassembly buffer is of the same size as the uip_buf buffer
+	  (configured by UIP_BUFSIZE).
+
+	  IP packet reassembly is not heavily tested.
+
+config UIP_REASS_MAXAGE
+	int "IP fragment reassembly max age (seconds)"
+	depends on UIP_REASSEMBLY
+	default 60
+	help
+	  The maximum time an IP fragment should wait in the reassembly
+	  buffer before it is dropped.
+
+config UIP_LINK_MTU
+	int "Maximum transmission unit at the IP layer"
+	default 1280
+
+endmenu
+
+menu "UDP configuration options"
+
+config UIP_UDP
+	bool "UDP support"
+	default y
+
+config UIP_UDP_CHECKSUMS
+	bool "UDP checksums"
+	depends on UIP_UDP
+	default y
+	help
+	  Toggles if UDP checksums should be used or not.
+
+	  Support for UDP checksums is currently not included in uIP,
+	  so this option has no function.
+
+config UIP_UDP_CONNS
+	int "Maximum number of concurrent UDP connections"
+	depends on UIP_UDP
+	default 10
+
+endmenu
+
+menu "TCP configuration options"
+
+config UIP_TCP
+	bool "TCP support"
+	default y
+
+config UIP_ACTIVE_OPEN
+	bool "Support for opening connections"
+	depends on UIP_TCP
+	default y
+	help
+	  Determines if support for opening connections from uIP should be
+	  compiled in.
+
+	  If the applications that are running on top of uIP for this project
+	  do not need to open outgoing TCP connections, this configuration
+	  option can be turned off to reduce the code size of uIP.
+
+config UIP_CONNS
+	int "Maximum number of concurrent TCP connections"
+	depends on UIP_TCP
+	default 10
+	help
+	  The maximum number of simultaneously open TCP connections.
+
+	  Since the TCP connections are statically allocated, turning this
+	  configuration knob down results in less RAM used. Each TCP
+	  connection requires approximately 30 bytes of memory.
+
+config UIP_LISTENPORTS
+	int "Maximum number of simultaneously listening TCP ports"
+	depends on UIP_TCP
+	default 20
+	help
+	  The maximum number of simultaneously listening TCP ports.
+
+	  Each listening TCP port requires 2 bytes of memory.
+
+config UIP_RTO
+	int "Retransmission time out (timer pulses)"
+	depends on UIP_TCP
+	default 3
+	help
+	  The initial retransmission timeout counted in timer pulses.
+
+	  This should not be changed.
+
+config UIP_MAXRTX
+	int "Max segment retransmissions"
+	depends on UIP_TCP
+	default 8
+	help
+	  The maximum number of times a segment should be retransmitted
+	  before the connection should be aborted.
+
+	  This should not be changed.
+
+config UIP_MAXSYNRTX
+	int "Max SYN retransmissions"
+	depends on UIP_TCP
+	default 5
+	help
+	  The maximum number of times a SYN segment should be retransmitted
+	  before a connection request should be deemed to have been
+	  unsuccessful.
+
+	  This should not need to be changed.
+
+config UIP_MAX_TCP_MSS
+	bool "Use the largest TCP maximum segment size"
+	depends on UIP_TCP
+	default y
+	help
+	  The default is UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN
+
+config UIP_TCP_MSS
+	int "TCP maximum segment size"
+	depends on !UIP_MAX_TCP_MSS
+	help
+	  The TCP maximum segment size.
+
+	  This is should not be to set to more than
+	  UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.
+
+config UIP_DEFAULT_RECEIVE_WINDOW
+	bool "Use the default advertised receive window size"
+	depends on UIP_TCP
+	default y
+	help
+	  The default is UIP_TCP_MSS
+
+config UIP_RECEIVE_WINDOW
+	int "Advertised receive window size"
+	depends on !UIP_DEFAULT_RECEIVE_WINDOW
+	help
+	  Should be set low (i.e., to the size of the uip_buf buffer) if the
+	  application is slow to process incoming data, or high (32768 bytes)
+	  if the application processes data quickly.
+
+config UIP_TIME_WAIT_TIMEOUT
+	int "Time to be in the TIME_WAIT state"
+	depends on UIP_TCP
+	default 120
+	help
+	  How long a connection should stay in the TIME_WAIT state.
+
+	  This can be reduced for faster entry into power saving modes.
+
+endmenu
+
+menu "ARP configuration options"
+
+config UIP_ARPTAB_SIZE
+	int "Size of the ARP table"
+	default 8
+	help
+	  The size of the ARP table.
+
+	  This option should be set to a larger value if this uIP node will
+	  have many connections from the local network.
+
+config UIP_ARP_MAXAGE
+	int "Maximum age of ARP table entries in 10s of seconds"
+	default 120
+	help
+	  The maximum age of ARP table entries measured in 10s of seconds.
+
+	  An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD default).
+
+endmenu
+
+menu "General configuration options"
+
+config UIP_DEFAULT_BUFSIZE
+	bool "Use the default packet buffer size"
+	default y
+	help
+	  The default is UIP_LINK_MTU + UIP_LLH_LEN
+
+config UIP_BUFSIZE
+	int "Size of the packet buffer"
+	depends on !UIP_DEFAULT_BUFSIZE
+	help
+	  The size of the uIP packet buffer.
+
+	  The uIP packet buffer should not be smaller than 60 bytes, and does
+	  not need to be larger than 1514 bytes. Lower size results in lower
+	  TCP throughput, larger size results in higher TCP throughput.
+
+config UIP_STATISTICS
+	bool "Statistics support"
+	default n
+	help
+	  Determines if statistics support should be compiled in.
+
+	  The statistics is useful for debugging and to show the user.
+
+config UIP_LOGGING
+	bool "Log certain events"
+	default n
+	help
+	  Determines if logging of certain events should be compiled in.
+
+	  This is useful mostly for debugging. The function uip_log()
+	  must be implemented to suit the architecture of the project, if
+	  logging is turned on.
+
+config UIP_BROADCAST
+	bool "Broadcast support"
+	default n
+	help
+	  Determines if uIP will pass received broadcast/multicast IPv4 UDP
+	  packets to the application (all multicast addresses are treated as
+	  broadcast in that case, there is no IGMP support). uIP can always
+	  send outgoing broadcast packets regardless of this option.
+
+config UIP_LLH_LEN
+	int "Link level header length"
+	default 14
+	help
+	  The link level header length.
+
+	  This is the offset into the uip_buf where the IP header can be
+	  found. For Ethernet, this should be set to 14. For SLIP, this
+	  should be set to 0.
+
+	  We probably won't use this constant for other link layers than
+	  ethernet as they have variable header length (this is due to
+	  variable number and type of address fields and to optional security
+	  features)
+
+	  E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14
+	        802.11 -> 4 + (6*3/4) + 2
+
+endmenu
diff --git a/src/net/uip/Makefile.inc b/src/net/uip/Makefile.inc
new file mode 100644
index 0000000..911ad13
--- /dev/null
+++ b/src/net/uip/Makefile.inc
@@ -0,0 +1,25 @@
+##
+## Copyright (c) 2013 Google Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; version 2 of the License.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+##
+
+subdirs-$(CONFIG_UIP_UDP) += udp
+
+uip-c-ccopts := -fno-strict-aliasing
+
+uip-y += arp.c
+uip-y += debug.c
+uip-y += lib.c
+uip-y += uip.c
diff --git a/src/net/uip_arch.h b/src/net/uip/arch.h
similarity index 94%
rename from src/net/uip_arch.h
rename to src/net/uip/arch.h
index fa7a3f0..a8ddb88 100644
--- a/src/net/uip_arch.h
+++ b/src/net/uip/arch.h
@@ -12,7 +12,7 @@
  *
  * The IP checksum calculation is the most computationally expensive
  * operation in the TCP/IP stack and it therefore pays off to
- * implement this in efficient assembler. The purpose of the uip_arch
+ * implement this in efficient assembler. The purpose of the arch
  * module is to let the checksum functions to be implemented in
  * architecture specific assembler.
  *
@@ -54,14 +54,14 @@
  *
  * This file is part of the uIP TCP/IP stack.
  *
- * $Id: uip_arch.h,v 1.1 2006/06/17 22:41:19 adamdunkels Exp $
+ * $Id: arch.h,v 1.1 2006/06/17 22:41:19 adamdunkels Exp $
  *
  */
 
-#ifndef __UIP_ARCH_H__
-#define __UIP_ARCH_H__
+#ifndef __NET_UIP_ARCH_H__
+#define __NET_UIP_ARCH_H__
 
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 /**
  * Carry out a 32-bit addition.
@@ -135,4 +135,4 @@
 /** @} */
 /** @} */
 
-#endif /* __UIP_ARCH_H__ */
+#endif /* __NET_UIP_ARCH_H__ */
diff --git a/src/net/uip_arp.c b/src/net/uip/arp.c
similarity index 99%
rename from src/net/uip_arp.c
rename to src/net/uip/arp.c
index 7a522f7..4070058 100644
--- a/src/net/uip_arp.c
+++ b/src/net/uip/arp.c
@@ -59,7 +59,7 @@
  */
 
 
-#include "net/uip_arp.h"
+#include "net/uip/arp.h"
 
 #include <string.h>
 
diff --git a/src/net/uip_arp.h b/src/net/uip/arp.h
similarity index 96%
rename from src/net/uip_arp.h
rename to src/net/uip/arp.h
index 3f30b16..6eb4453 100644
--- a/src/net/uip_arp.h
+++ b/src/net/uip/arp.h
@@ -45,14 +45,14 @@
  *
  * This file is part of the uIP TCP/IP stack.
  *
- * $Id: uip_arp.h,v 1.2 2006/08/26 23:58:45 oliverschmidt Exp $
+ * $Id: arp.h,v 1.2 2006/08/26 23:58:45 oliverschmidt Exp $
  *
  */
 
-#ifndef __UIP_ARP_H__
-#define __UIP_ARP_H__
+#ifndef __NET_UIP_ARP_H__
+#define __NET_UIP_ARP_H__
 
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 
 extern struct uip_eth_addr uip_ethaddr;
@@ -140,5 +140,5 @@
 /** @} */
 
 
-#endif /* __UIP_ARP_H__ */
+#endif /* __NET_UIP_ARP_H__ */
 /** @} */
diff --git a/src/net/uip_debug.c b/src/net/uip/debug.c
similarity index 98%
rename from src/net/uip_debug.c
rename to src/net/uip/debug.c
index 3eb670a..060618d 100644
--- a/src/net/uip_debug.c
+++ b/src/net/uip/debug.c
@@ -37,7 +37,7 @@
  *         Joakim Eriksson <joakime@sics.se>
  */
 
-#include "net/uip_debug.h"
+#include "net/uip/debug.h"
 
 /*---------------------------------------------------------------------------*/
 void
diff --git a/src/net/uip_debug.h b/src/net/uip/debug.h
similarity index 94%
rename from src/net/uip_debug.h
rename to src/net/uip/debug.h
index bee128f..f563859 100644
--- a/src/net/uip_debug.h
+++ b/src/net/uip/debug.h
@@ -28,7 +28,7 @@
  *
  * This file is part of the Contiki operating system.
  *
- * $Id: uip_debug.h,v 1.1 2010/04/30 13:20:57 joxe Exp $
+ * $Id: debug.h,v 1.1 2010/04/30 13:20:57 joxe Exp $
  */
 /**
  * \file
@@ -39,10 +39,10 @@
  *         Joakim Eriksson <joakime@sics.se>
  */
 
-#ifndef UIP_DEBUG_H
-#define UIP_DEBUG_H
+#ifndef __NET_UIP_DEBUG_H__
+#define __NET_UIP_DEBUG_H__
 
-#include "net/uip.h"
+#include "net/uip/uip.h"
 #include <stdio.h>
 
 void uip_debug_ipaddr_print(const uip_ipaddr_t *addr);
@@ -85,4 +85,4 @@
 #define PRINTLLADDR(lladdr)
 #endif /* (DEBUG) & DEBUG_PRINT */
 
-#endif
+#endif /* __NET_UIP_DEBUG_H__ */
diff --git a/src/net/uiplib.c b/src/net/uip/lib.c
similarity index 96%
rename from src/net/uiplib.c
rename to src/net/uip/lib.c
index 2d9b7dc..be08d57 100644
--- a/src/net/uiplib.c
+++ b/src/net/uip/lib.c
@@ -34,12 +34,12 @@
  */
 
 
-#include "net/uip.h"
-#include "net/uiplib.h"
+#include "net/uip/uip.h"
+#include "net/uip/lib.h"
 #include <string.h>
 
 #define DEBUG DEBUG_NONE
-#include "net/uip_debug.h"
+#include "net/uip/debug.h"
 
 /*---------------------------------------------------------------------------*/
 int uiplib_ipaddrconv(const char *addrstr, uip_ipaddr_t *ipaddr)
diff --git a/src/net/uiplib.h b/src/net/uip/lib.h
similarity index 95%
rename from src/net/uiplib.h
rename to src/net/uip/lib.h
index 963c43d..f5475e7 100644
--- a/src/net/uiplib.h
+++ b/src/net/uip/lib.h
@@ -40,10 +40,10 @@
  * $Id: uiplib.h,v 1.3 2010/05/31 15:22:08 nifi Exp $
  *
  */
-#ifndef __UIPLIB_H__
-#define __UIPLIB_H__
+#ifndef __NET_UIP_LIB_H__
+#define __NET_UIP_LIB_H__
 
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 /**
  * \addtogroup uipconvfunc
@@ -71,4 +71,4 @@
 
 /** @} */
 
-#endif /* __UIPLIB_H__ */
+#endif /* __NET_UIP_LIB_H__ */
diff --git a/src/net/uipopt.h b/src/net/uip/opt.h
similarity index 95%
rename from src/net/uipopt.h
rename to src/net/uip/opt.h
index f5a3716..daf8587 100644
--- a/src/net/uipopt.h
+++ b/src/net/uip/opt.h
@@ -10,7 +10,7 @@
  *
  * This file is used for tweaking various configuration options for
  * uIP. You should make a copy of this file into one of your project's
- * directories instead of editing this example "uipopt.h" file that
+ * directories instead of editing this example "opt.h" file that
  * comes with the uIP distribution.
  */
 
@@ -44,12 +44,12 @@
  *
  * This file is part of the uIP TCP/IP stack.
  *
- * $Id: uipopt.h,v 1.14 2010/12/24 00:39:04 dak664 Exp $
+ * $Id: opt.h,v 1.14 2010/12/24 00:39:04 dak664 Exp $
  *
  */
 
-#ifndef __UIPOPT_H__
-#define __UIPOPT_H__
+#ifndef __NET_UIP_OPT_H__
+#define __NET_UIP_OPT_H__
 
 #include <stdint.h>
 
@@ -161,6 +161,6 @@
 {
 } uip_udp_appstate_t;
 
-#endif /* __UIPOPT_H__ */
+#endif /* __NET_UIP_OPT_H__ */
 /** @} */
 /** @} */
diff --git a/src/net/uip/udp/Makefile.inc b/src/net/uip/udp/Makefile.inc
new file mode 100644
index 0000000..73006ea
--- /dev/null
+++ b/src/net/uip/udp/Makefile.inc
@@ -0,0 +1,18 @@
+##
+## Copyright (c) 2013 Google Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; version 2 of the License.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+##
+
+uip-y += packet.c
diff --git a/src/net/uip_udp_packet.c b/src/net/uip/udp/packet.c
similarity index 97%
rename from src/net/uip_udp_packet.c
rename to src/net/uip/udp/packet.c
index 6b85cbb..53265b0 100644
--- a/src/net/uip_udp_packet.c
+++ b/src/net/uip/udp/packet.c
@@ -43,8 +43,8 @@
 extern uint16_t uip_slen;
 
 #include "drivers/net/net.h"
-#include "net/uip_arp.h"
-#include "net/uip_udp_packet.h"
+#include "net/uip/arp.h"
+#include "net/uip/udp/packet.h"
 
 #include <string.h>
 
diff --git a/src/net/uip_udp_packet.h b/src/net/uip/udp/packet.h
similarity index 90%
rename from src/net/uip_udp_packet.h
rename to src/net/uip/udp/packet.h
index 34f469d..4d58a2b 100644
--- a/src/net/uip_udp_packet.h
+++ b/src/net/uip/udp/packet.h
@@ -28,7 +28,7 @@
  *
  * This file is part of the Contiki operating system.
  *
- * $Id: uip_udp_packet.h,v 1.3 2009/10/18 22:02:01 adamdunkels Exp $
+ * $Id: packet.h,v 1.3 2009/10/18 22:02:01 adamdunkels Exp $
  */
 
 /**
@@ -38,13 +38,13 @@
  *         Adam Dunkels <adam@sics.se>
  */
 
-#ifndef __UIP_UDP_PACKET_H__
-#define __UIP_UDP_PACKET_H__
+#ifndef __NET_UIP_UDP_PACKET_H__
+#define __NET_UIP_UDP_PACKET_H__
 
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 void uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len);
 void uip_udp_packet_sendto(struct uip_udp_conn *c, const void *data, int len,
 			   const uip_ipaddr_t *toaddr, uint16_t toport);
 
-#endif /* __UIP_UDP_PACKET_H__ */
+#endif /* __NET_UIP_UDP_PACKET_H__ */
diff --git a/src/net/uip.c b/src/net/uip/uip.c
similarity index 99%
rename from src/net/uip.c
rename to src/net/uip/uip.c
index f96b4e2..962b9cd 100644
--- a/src/net/uip.c
+++ b/src/net/uip/uip.c
@@ -74,10 +74,10 @@
 #include <string.h>
 
 #include "base/algorithm.h"
-#include "net/uip.h"
-#include "net/uipopt.h"
-#include "net/uip_arp.h"
-#include "net/uip_arch.h"
+#include "net/uip/arch.h"
+#include "net/uip/arp.h"
+#include "net/uip/opt.h"
+#include "net/uip/uip.h"
 
 /*---------------------------------------------------------------------------*/
 /* Variable definitions. */
diff --git a/src/net/uip.h b/src/net/uip/uip.h
similarity index 99%
rename from src/net/uip.h
rename to src/net/uip/uip.h
index 34d735f..976ce1d 100644
--- a/src/net/uip.h
+++ b/src/net/uip/uip.h
@@ -51,10 +51,10 @@
  *
  */
 
-#ifndef __UIP_H__
-#define __UIP_H__
+#ifndef __NET_UIP_UIP_H__
+#define __NET_UIP_UIP_H__
 
-#include "net/uipopt.h"
+#include "net/uip/opt.h"
 
 /**
  * Representation of an IP address.
@@ -1790,7 +1790,7 @@
 uint16_t uip_icmp6chksum(void);
 
 
-#endif /* __UIP_H__ */
+#endif /* __NET_UIP_UIP_H__ */
 
 
 /** @} */
diff --git a/src/netboot/dhcp.c b/src/netboot/dhcp.c
index f0e197c..721346a 100644
--- a/src/netboot/dhcp.c
+++ b/src/netboot/dhcp.c
@@ -28,9 +28,9 @@
 #include "base/xalloc.h"
 #include "drivers/net/net.h"
 #include "net/net.h"
-#include "net/uip.h"
-#include "net/uip_arp.h"
-#include "net/uip_udp_packet.h"
+#include "net/uip/arp.h"
+#include "net/uip/udp/packet.h"
+#include "net/uip/uip.h"
 #include "netboot/dhcp.h"
 
 typedef enum DhcpOpcode
diff --git a/src/netboot/dhcp.h b/src/netboot/dhcp.h
index dde59cd..408183b 100644
--- a/src/netboot/dhcp.h
+++ b/src/netboot/dhcp.h
@@ -25,7 +25,7 @@
 
 #include <stdint.h>
 
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 int dhcp_request(uip_ipaddr_t *next_ip, uip_ipaddr_t *server_ip,
 		 const char **bootfile);
diff --git a/src/netboot/netboot.c b/src/netboot/netboot.c
index f51d807..f399419 100644
--- a/src/netboot/netboot.c
+++ b/src/netboot/netboot.c
@@ -24,8 +24,8 @@
 
 #include "base/algorithm.h"
 #include "drivers/net/net.h"
-#include "net/uip.h"
-#include "net/uip_arp.h"
+#include "net/uip/arp.h"
+#include "net/uip/uip.h"
 #include "netboot/dhcp.h"
 #include "netboot/netboot.h"
 #include "netboot/params.h"
diff --git a/src/netboot/netboot.h b/src/netboot/netboot.h
index 241d3e7..314bfe7 100644
--- a/src/netboot/netboot.h
+++ b/src/netboot/netboot.h
@@ -20,7 +20,7 @@
 #ifndef __NETBOOT_NETBOOT_H__
 #define __NETBOOT_NETBOOT_H__
 
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 // argsfile takes precedence before args. All parameters can be NULL.
 void netboot(uip_ipaddr_t *tftp_ip, char *bootfile, char *argsfile, char *args);
diff --git a/src/netboot/params.c b/src/netboot/params.c
index edd4642..950a6a9 100644
--- a/src/netboot/params.c
+++ b/src/netboot/params.c
@@ -27,7 +27,7 @@
 #include "base/xalloc.h"
 #include "drivers/board/board.h"
 #include "drivers/storage/storage.h"
-#include "net/uip.h"
+#include "net/uip/uip.h"
 #include "netboot/params.h"
 
 static NetbootParam netboot_params[NetbootParamIdMax];
diff --git a/src/netboot/params.h b/src/netboot/params.h
index 26d387b..41b0367 100644
--- a/src/netboot/params.h
+++ b/src/netboot/params.h
@@ -26,7 +26,7 @@
 #include <stdint.h>
 
 #include "drivers/storage/storage.h"
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 typedef enum NetbootParamId
 {
diff --git a/src/netboot/tftp.c b/src/netboot/tftp.c
index 06b5717..4db4ed1 100644
--- a/src/netboot/tftp.c
+++ b/src/netboot/tftp.c
@@ -28,8 +28,8 @@
 #include "base/xalloc.h"
 #include "drivers/net/net.h"
 #include "net/net.h"
-#include "net/uip.h"
-#include "net/uip_udp_packet.h"
+#include "net/uip/udp/packet.h"
+#include "net/uip/uip.h"
 #include "netboot/tftp.h"
 
 typedef enum TftpStatus
diff --git a/src/netboot/tftp.h b/src/netboot/tftp.h
index 4dcfcec..8f807f1 100644
--- a/src/netboot/tftp.h
+++ b/src/netboot/tftp.h
@@ -23,7 +23,7 @@
 #ifndef __NETBOOT_TFTP_H__
 #define __NETBOOT_TFTP_H__
 
-#include "net/uip.h"
+#include "net/uip/uip.h"
 
 typedef enum TftpOpcode
 {