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.

Revision:
63:97f481e33cb2
Parent:
51:ab4529a384a6
diff -r 357cc2460285 -r 97f481e33cb2 modules/pico_ipv4.c
--- a/modules/pico_ipv4.c	Mon Sep 16 12:07:35 2013 +0000
+++ b/modules/pico_ipv4.c	Thu Sep 19 12:38:53 2013 +0000
@@ -33,8 +33,8 @@
 #endif
 
 /* Queues */
-static struct pico_queue in = {0};
-static struct pico_queue out = {0};
+static struct pico_queue in = {};
+static struct pico_queue out = {};
 
 /* Functions */
 static int ipv4_route_compare(void *ka, void * kb);
@@ -125,7 +125,7 @@
    * */
 
   for(i = 0; i < 32; i++){
-    if((mask_swap << i) & 0x80000000){
+    if((mask_swap << i) & (1 << 31)){
       if(end) {
         pico_err = PICO_ERR_EINVAL;
         return -1;
@@ -414,7 +414,6 @@
 #else
 static inline int pico_ipv4_crc_check(struct pico_frame *f)
 {
-	IGNORE_PARAMETER(f);
   return 1;
 }
 #endif /* PICO_SUPPORT_CRC */
@@ -506,27 +505,23 @@
     }
 #endif
   } else if (pico_ipv4_link_find(&hdr->dst)) {
-    if (pico_ipv4_nat_inbound(f, &hdr->dst) == 0)
-      pico_enqueue(pico_proto_ipv4.q_in, f); /* dst changed, reprocess */
-    else 
+   if (pico_ipv4_nat_isenabled_in(f) == 0) {  /* if NAT enabled (dst port registerd), do NAT */
+      if(pico_ipv4_nat(f, hdr->dst) != 0) {
+        return -1;
+      }
+      pico_ipv4_forward(f); /* Local packet became forward packet after NAT */
+    } else {                              /* no NAT so enqueue to next layer */
       pico_transport_receive(f, hdr->proto);
+    }
   } else if (pico_tree_findKey(&Tree_dev_link, &test)){
 #ifdef PICO_SUPPORT_UDP
     //address of this device is apparently 0.0.0.0; might be a DHCP packet
-    /* XXX KRO: is obsolete. Broadcast flag is set on outgoing DHCP messages.
-     * incomming DHCP messages are to be broadcasted. Our current DHCP server
-     * implementation does not take this flag into account yet though ... */
     pico_enqueue(pico_proto_udp.q_in, f);
 #endif
   } else {
-    
-    if((pico_ipv4_is_broadcast(hdr->dst.addr)))
-    {
-      /* don't forward broadcast frame, discard! */
+    /* Packet is not local. Try to forward. */
+    if (pico_ipv4_forward(f) != 0) {
       pico_frame_discard(f);
-    } else if (pico_ipv4_forward(f) != 0) {
-        /* Packet is not local. Try to forward. */
-        pico_ipv4_forward(f);
     }
   }
   return 0;
@@ -537,8 +532,7 @@
 
 static int pico_ipv4_process_out(struct pico_protocol *self, struct pico_frame *f)
 {
-	IGNORE_PARAMETER(self);
-	f->start = (uint8_t*) f->net_hdr;
+  f->start = (uint8_t*) f->net_hdr;
   #ifdef PICO_SUPPORT_IPFILTER
   if (ipfilter(f)) {
     /*pico_frame is discarded as result of the filtering*/
@@ -551,10 +545,8 @@
 
 static struct pico_frame *pico_ipv4_alloc(struct pico_protocol *self, int size)
 {
-	struct pico_frame *f =  pico_frame_alloc(size + PICO_SIZE_IP4HDR + PICO_SIZE_ETHHDR);
-	IGNORE_PARAMETER(self);
-
-	if (!f)
+  struct pico_frame *f =  pico_frame_alloc(size + PICO_SIZE_IP4HDR + PICO_SIZE_ETHHDR);
+  if (!f)
     return NULL;
   f->datalink_hdr = f->buffer;
   f->net_hdr = f->buffer + PICO_SIZE_ETHHDR;
@@ -902,6 +894,7 @@
             }
             ip_mcast_dbg("MCAST: IP %08X NOT in included interface source list\n", hdr->src.addr);
             return -1;
+            break;
 
           case PICO_IP_MULTICAST_EXCLUDE:
             pico_tree_foreach(index2, &g->MCASTSources)
@@ -913,9 +906,11 @@
             }
             ip_mcast_dbg("MCAST: IP %08X NOT in excluded interface source list\n", hdr->src.addr);
             return 0;
+            break;
 
           default:
             return -1;
+            break;
         }
       } else {
         ip_mcast_dbg("MCAST: IP %08X is group member of different link %s\n", hdr->dst.addr, link->dev->name);
@@ -1071,10 +1066,8 @@
 
 static int pico_ipv4_frame_sock_push(struct pico_protocol *self, struct pico_frame *f)
 {
-	struct pico_ip4 *dst;
+  struct pico_ip4 *dst;
   struct pico_remote_duple *remote_duple = (struct pico_remote_duple *) f->info;
-  IGNORE_PARAMETER(self);
-
   if (!f->sock) {
     pico_frame_discard(f);
     return -1;
@@ -1155,10 +1148,8 @@
 
 int pico_ipv4_route_del(struct pico_ip4 address, struct pico_ip4 netmask, struct pico_ip4 gateway, int metric, struct pico_ipv4_link *link)
 {
-	struct pico_ipv4_route test, *found;
-	IGNORE_PARAMETER(gateway);
-
-	if (!link) {
+  struct pico_ipv4_route test, *found;
+  if (!link) {
     pico_err = PICO_ERR_EINVAL;
     return -1;
   }
@@ -1370,12 +1361,13 @@
     return -1;
   }
 
+  //dbg("IP> FORWARDING.\n");
   rt = route_find(&hdr->dst);
   if (!rt) {
     pico_notify_dest_unreachable(f);
     return -1;
   }
-
+  //dbg("ROUTE: valid..\n");
   f->dev = rt->link->dev;
   hdr->ttl-=1;
   if (hdr->ttl < 1) {
@@ -1384,8 +1376,11 @@
   }
   hdr->crc++;
 
-  pico_ipv4_nat_outbound(f, &rt->link->address);
+  /* check if NAT enbled on link and do NAT if so */
+  if (pico_ipv4_nat_isenabled_out(rt->link) == 0)
+    pico_ipv4_nat(f, rt->link->address);
 
+  //dbg("Routing towards %s\n", f->dev->name);
   f->start = f->net_hdr;
   if(f->dev->eth != NULL)
     f->len -= PICO_SIZE_ETHHDR;