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 RTOSgeneric mbed Ethernet driverhigh performance NXP LPC1768 specific Ethernet driverMulti-threading support for mbed RTOSBerkeley sockets and integration with the New Socket APIFork of the apps running on top of the New Socket APIScheduling 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.
Diff: modules/pico_ipv4.c
- Revision:
- 51:ab4529a384a6
- Parent:
- 49:4b404dd2c97a
- Child:
- 63:97f481e33cb2
diff -r 8c79c30b48e3 -r ab4529a384a6 modules/pico_ipv4.c --- a/modules/pico_ipv4.c Tue Aug 06 08:04:03 2013 +0000 +++ b/modules/pico_ipv4.c Mon Sep 02 08:02:21 2013 +0000 @@ -33,8 +33,8 @@ #endif /* Queues */ -static struct pico_queue in = {}; -static struct pico_queue out = {}; +static struct pico_queue in = {0}; +static struct pico_queue out = {0}; /* Functions */ static int ipv4_route_compare(void *ka, void * kb); @@ -125,7 +125,7 @@ * */ for(i = 0; i < 32; i++){ - if((mask_swap << i) & (1 << 31)){ + if((mask_swap << i) & 0x80000000){ if(end) { pico_err = PICO_ERR_EINVAL; return -1; @@ -414,6 +414,7 @@ #else static inline int pico_ipv4_crc_check(struct pico_frame *f) { + IGNORE_PARAMETER(f); return 1; } #endif /* PICO_SUPPORT_CRC */ @@ -505,17 +506,16 @@ } #endif } else if (pico_ipv4_link_find(&hdr->dst)) { - 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 */ + if (pico_ipv4_nat_inbound(f, &hdr->dst) == 0) + pico_enqueue(pico_proto_ipv4.q_in, f); /* dst changed, reprocess */ + else 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 { @@ -526,7 +526,7 @@ pico_frame_discard(f); } else if (pico_ipv4_forward(f) != 0) { /* Packet is not local. Try to forward. */ - pico_frame_discard(f); + pico_ipv4_forward(f); } } return 0; @@ -537,7 +537,8 @@ static int pico_ipv4_process_out(struct pico_protocol *self, struct pico_frame *f) { - f->start = (uint8_t*) f->net_hdr; + IGNORE_PARAMETER(self); + f->start = (uint8_t*) f->net_hdr; #ifdef PICO_SUPPORT_IPFILTER if (ipfilter(f)) { /*pico_frame is discarded as result of the filtering*/ @@ -550,8 +551,10 @@ 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); - if (!f) + struct pico_frame *f = pico_frame_alloc(size + PICO_SIZE_IP4HDR + PICO_SIZE_ETHHDR); + IGNORE_PARAMETER(self); + + if (!f) return NULL; f->datalink_hdr = f->buffer; f->net_hdr = f->buffer + PICO_SIZE_ETHHDR; @@ -899,7 +902,6 @@ } 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) @@ -911,11 +913,9 @@ } 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,8 +1071,10 @@ 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; @@ -1153,8 +1155,10 @@ 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; - if (!link) { + struct pico_ipv4_route test, *found; + IGNORE_PARAMETER(gateway); + + if (!link) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -1366,13 +1370,12 @@ 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) { @@ -1381,11 +1384,8 @@ } hdr->crc++; - /* 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); + pico_ipv4_nat_outbound(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;