Free (GPLv2) TCP/IP stack developed by TASS Belgium

Dependents:   lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more

PicoTCP. Copyright (c) 2013 TASS Belgium NV.

Released under the GNU General Public License, version 2.

Different licensing models may exist, at the sole discretion of the Copyright holders.

Official homepage: http://www.picotcp.com

Bug tracker: https://github.com/tass-belgium/picotcp/issues

Development steps:

  • initial integration with mbed RTOS
  • generic mbed Ethernet driver
  • high performance NXP LPC1768 specific Ethernet driver
  • Multi-threading support for mbed RTOS
  • Berkeley sockets and integration with the New Socket API
  • Fork of the apps running on top of the New Socket API
  • Scheduling optimizations
  • Debugging/benchmarking/testing

Demo application (measuring TCP sender performance):

Import programlpc1768-picotcp-demo

A PicoTCP demo app testing the ethernet throughput on the lpc1768 mbed board.

Files at this revision

API Documentation at this revision

Comitter:
tass
Date:
Fri Sep 27 06:27:23 2013 +0000
Parent:
71:f15dc127f5f9
Child:
73:dfb737147f6e
Commit message:
Fix Issue #32

Changed in this revision

modules/pico_dhcp_client.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_ipv4.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_ipv4.h Show annotated file Show diff for this revision Revisions of this file
--- a/modules/pico_dhcp_client.c	Thu Sep 26 09:12:36 2013 +0000
+++ b/modules/pico_dhcp_client.c	Fri Sep 27 06:27:23 2013 +0000
@@ -565,7 +565,7 @@
 {
   struct pico_dhcp_hdr *hdr = (struct pico_dhcp_hdr *)buf;
   struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)hdr->options;
-  struct pico_ip4 address = {0}, netmask = {0}, inaddr_any = {0}, bcast = { .addr = 0xFFFFFFFF };
+  struct pico_ip4 address = {0}, netmask = {0}, bcast = { .addr = 0xFFFFFFFF };
 
   pico_dhcp_client_recv_params(dhcpc, opt);
   if ((dhcpc->event != PICO_DHCP_MSG_ACK) || !dhcpc->server_id.addr || !dhcpc->netmask.addr || !dhcpc->lease_timer.time)
@@ -586,7 +586,7 @@
   }
   /* delete the default route for our global broadcast messages, otherwise another interface can not rebind */
   if (dhcpc->state == DHCP_CLIENT_STATE_REBINDING)
-    pico_ipv4_route_del(bcast, netmask, inaddr_any, 1, pico_ipv4_link_get(&dhcpc->address));
+    pico_ipv4_route_del(bcast, netmask, 1);
 
   dbg("DHCP client: renewal time (T1) %u\n", dhcpc->T1_timer.time);
   dbg("DHCP client: rebinding time (T2) %u\n", dhcpc->T2_timer.time);
@@ -645,18 +645,13 @@
 
 static int reset(struct pico_dhcp_client_cookie *dhcpc, uint8_t __attribute__((unused)) *buf)
 {
-  struct pico_ip4 address = {0}, netmask = {0}, inaddr_any = {0}, bcast = { .addr = 0xFFFFFFFF };
+  struct pico_ip4 address = {0};
 
   if (dhcpc->state == DHCP_CLIENT_STATE_REQUESTING)
     address.addr = PICO_IP4_ANY;
   else
     address.addr = dhcpc->address.addr;
 
-  /* delete the default route for our global broadcast messages, otherwise another interface can not rebind */
-  if (dhcpc->state == DHCP_CLIENT_STATE_REBINDING){
-    pico_ipv4_route_del(bcast, netmask, inaddr_any, 1, pico_ipv4_link_get(&dhcpc->address));
-    pico_ipv4_route_del(inaddr_any, netmask, inaddr_any, 1, pico_ipv4_link_get(&dhcpc->address));
-  }
   /* close the socket used for address (re)acquisition */
   pico_socket_close(dhcpc->s);
   /* delete the link with the currently in use address */
--- a/modules/pico_ipv4.c	Thu Sep 26 09:12:36 2013 +0000
+++ b/modules/pico_ipv4.c	Fri Sep 27 06:27:23 2013 +0000
@@ -1139,15 +1139,10 @@
   return 0;
 }
 
-int pico_ipv4_route_del(struct pico_ip4 address, struct pico_ip4 netmask, struct pico_ip4 gateway, int metric, struct pico_ipv4_link *link)
+int pico_ipv4_route_del(struct pico_ip4 address, struct pico_ip4 netmask, int metric)
 {
-	struct pico_ipv4_route test, *found;
-	IGNORE_PARAMETER(gateway);
+  struct pico_ipv4_route test, *found;
 
-	if (!link) {
-    pico_err = PICO_ERR_EINVAL;
-    return -1;
-  }
   test.dest.addr = address.addr;
   test.netmask.addr = netmask.addr;
   test.metric = (uint32_t)metric;
@@ -1236,11 +1231,23 @@
   return 0;
 }
 
+static int pico_ipv4_cleanup_routes(struct pico_ipv4_link *link)
+{
+  struct pico_tree_node *index = NULL, *tmp = NULL;
+  struct pico_ipv4_route *route = NULL;
+
+  pico_tree_foreach_safe(index, &Routes, tmp)
+  {
+    route = index->keyValue;
+    if (link == route->link)
+      pico_ipv4_route_del(route->dest, route->netmask, route->metric);
+  }
+  return 0;
+}
 
 int pico_ipv4_link_del(struct pico_device *dev, struct pico_ip4 address)
 {
   struct pico_ipv4_link test, *found;
-  struct pico_ip4 network;
 
   if(!dev) {
     pico_err = PICO_ERR_EINVAL;
@@ -1254,19 +1261,16 @@
     return -1;
   }
 
-  network.addr = found->address.addr & found->netmask.addr;
-  pico_ipv4_route_del(network, found->netmask,pico_ipv4_route_get_gateway(&found->address), 1, found);
 #ifdef PICO_SUPPORT_MCAST
   do {
-    struct pico_ip4 mcast_all_hosts, mcast_addr, mcast_nm, mcast_gw;
+    struct pico_ip4 mcast_all_hosts, mcast_addr, mcast_nm;
     struct pico_mcast_group *g = NULL;
     struct pico_tree_node * index, * _tmp;
     if (found == mcast_default_link) {
       mcast_addr.addr = long_be(0xE0000000); /* 224.0.0.0 */
       mcast_nm.addr = long_be(0xF0000000); /* 15.0.0.0 */
-      mcast_gw.addr = long_be(0x00000000);
       mcast_default_link = NULL;
-      pico_ipv4_route_del(mcast_addr, mcast_nm, mcast_gw, 1, found);
+      pico_ipv4_route_del(mcast_addr, mcast_nm, 1);
     }
     mcast_all_hosts.addr = PICO_MCAST_ALL_HOSTS;
     pico_ipv4_mcast_leave(&address, &mcast_all_hosts, 1, PICO_IP_MULTICAST_EXCLUDE, NULL);
@@ -1279,9 +1283,10 @@
   } while(0);
 #endif
 
+  pico_ipv4_cleanup_routes(found);
   pico_tree_delete(&Tree_dev_link, found);
-  /* XXX: pico_free(found); */
-  /* XXX: cleanup all routes containing the removed link */
+  pico_free(found);
+
   return 0;
 }
 
--- a/modules/pico_ipv4.h	Thu Sep 26 09:12:36 2013 +0000
+++ b/modules/pico_ipv4.h	Fri Sep 27 06:27:23 2013 +0000
@@ -85,7 +85,7 @@
 struct pico_device *pico_ipv4_link_find(struct pico_ip4 *address);
 struct pico_ip4 *pico_ipv4_source_find(const struct pico_ip4 *dst);
 int pico_ipv4_route_add(struct pico_ip4 address, struct pico_ip4 netmask, struct pico_ip4 gateway, int metric, struct pico_ipv4_link *link);
-int pico_ipv4_route_del(struct pico_ip4 address, struct pico_ip4 netmask, struct pico_ip4 gateway, int metric, struct pico_ipv4_link *link);
+int pico_ipv4_route_del(struct pico_ip4 address, struct pico_ip4 netmask, int metric);
 struct pico_ip4 pico_ipv4_route_get_gateway(struct pico_ip4 *addr);
 void pico_ipv4_unreachable(struct pico_frame *f, int err);