diff options
author | Joseph Henry <joseph.henry@zerotier.com> | 2015-09-11 15:26:39 -0400 |
---|---|---|
committer | Joseph Henry <joseph.henry@zerotier.com> | 2015-09-11 15:26:39 -0400 |
commit | bc666d0ab7c521b3a527b46679182dfe84b76538 (patch) | |
tree | b818c16637628fd90cf63a98f1c3cf53cd5c3c24 /netcon | |
parent | 933b47389d1e0df24570ce753b614ae66f05819f (diff) | |
download | infinitytier-bc666d0ab7c521b3a527b46679182dfe84b76538.tar.gz infinitytier-bc666d0ab7c521b3a527b46679182dfe84b76538.zip |
added pbuf alloc block
Diffstat (limited to 'netcon')
-rw-r--r-- | netcon/NetconEthernetTap.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp index 1b757665..b7cc9b1f 100644 --- a/netcon/NetconEthernetTap.cpp +++ b/netcon/NetconEthernetTap.cpp @@ -116,7 +116,7 @@ bool NetconEthernetTap::addIp(const InetAddress &ip) if (ip.isV4()) { Mutex::Lock _l2(_arp_m); - _arp.setLocal((uint32_t)(reinterpret_cast<const struct sockaddr_in *>(ip)->sin_addr.s_addr),_mac); + _arp.addLocal((uint32_t)(reinterpret_cast<const struct sockaddr_in *>(&ip)->sin_addr.s_addr),_mac); } // TODO: alloc IP in LWIP @@ -136,7 +136,7 @@ bool NetconEthernetTap::removeIp(const InetAddress &ip) if (ip.isV4()) { Mutex::Lock _l2(_arp_m); - _arp.remove((uint32_t)(reinterpret_cast<const struct sockaddr_in *>(ip)->sin_addr.s_addr)); + _arp.remove((uint32_t)(reinterpret_cast<const struct sockaddr_in *>(&ip)->sin_addr.s_addr)); } // TODO: dealloc IP from LWIP @@ -165,7 +165,28 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType if (arpReplyLen > 0) _handler(_arg,_nwid,_mac,from,ZT_ETHERTYPE_ARP,0,arpReplyBuf,arpReplyLen); } else if (etherType == ZT_ETHERTYPE_IPV4) { - // TODO: pass IPv4 packets into LWIP + + // Pass IPV4 packets to LWIP + + struct pbuf *p, *q; + u16_t len; + char *bufptr; + + // allocate a pbuf chain of pbufs from the pool + p = lwipstack->pbuf_alloc(PBUF_RAW, len, PBUF_POOL); + + if(p != NULL) { + // We iterate over the pbuf chain until we have read the entire packet into the pbuf. + bufptr = (char*)data; + for(q = p; q != NULL; q = q->next) { + // read data into(q->payload, q->len); + memcpy(q->payload, bufptr, q->len); + bufptr += q->len; + } + // acknowledge that packet has been read(); + } else { + TRACE("packet dropped"); + } } } |