summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-11-23 12:43:42 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-11-23 12:43:42 -0800
commitd8d4cfbf0150de930504b02ee0dd8854afa558b0 (patch)
tree73d0bc375467076737579512a70d57b6b9642bba
parent34404eb3003461c4c58f537f1c9f293a989694cf (diff)
downloadinfinitytier-d8d4cfbf0150de930504b02ee0dd8854afa558b0.tar.gz
infinitytier-d8d4cfbf0150de930504b02ee0dd8854afa558b0.zip
Eliminate a few warnings and some small code reorg.
-rw-r--r--ext/lwipopts.h2
-rw-r--r--netcon/NetconEthernetTap.cpp60
-rw-r--r--netcon/NetconEthernetTap.hpp53
3 files changed, 55 insertions, 60 deletions
diff --git a/ext/lwipopts.h b/ext/lwipopts.h
index 577e155f..6d2b0c22 100644
--- a/ext/lwipopts.h
+++ b/ext/lwipopts.h
@@ -46,7 +46,7 @@
#define LWIP_CHKSUM_ALGORITHM 2
-
+#undef TCP_MSS
#define TCP_MSS 1460
/*
diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp
index 4fbde464..7d76b0b9 100644
--- a/netcon/NetconEthernetTap.cpp
+++ b/netcon/NetconEthernetTap.cpp
@@ -57,6 +57,54 @@
namespace ZeroTier {
+namespace {
+
+static err_t tapif_init(struct netif *netif)
+{
+ // Actual init functionality is in addIp() of tap
+ return ERR_OK;
+}
+
+static err_t low_level_output(struct netif *netif, struct pbuf *p)
+{
+ struct pbuf *q;
+ char buf[ZT_MAX_MTU+32];
+ char *bufptr;
+ int tot_len = 0;
+
+ ZeroTier::NetconEthernetTap *tap = (ZeroTier::NetconEthernetTap*)netif->state;
+
+ /* initiate transfer(); */
+ bufptr = buf;
+
+ for(q = p; q != NULL; q = q->next) {
+ /* Send the data from the pbuf to the interface, one pbuf at a
+ time. The size of the data in each pbuf is kept in the ->len
+ variable. */
+ /* send data from(q->payload, q->len); */
+ memcpy(bufptr, q->payload, q->len);
+ bufptr += q->len;
+ tot_len += q->len;
+ }
+
+ // [Send packet to network]
+ // Split ethernet header and feed into handler
+ struct eth_hdr *ethhdr;
+ ethhdr = (struct eth_hdr *)buf;
+
+ ZeroTier::MAC src_mac;
+ ZeroTier::MAC dest_mac;
+
+ src_mac.setTo(ethhdr->src.addr, 6);
+ dest_mac.setTo(ethhdr->dest.addr, 6);
+
+ tap->_handler(tap->_arg,tap->_nwid,src_mac,dest_mac,
+ Utils::ntoh((uint16_t)ethhdr->type),0,buf + sizeof(struct eth_hdr),tot_len - sizeof(struct eth_hdr));
+ return ERR_OK;
+}
+
+} // anonymous namespace
+
NetconEthernetTap::NetconEthernetTap(
const char *homePath,
const MAC &mac,
@@ -66,11 +114,11 @@ NetconEthernetTap::NetconEthernetTap(
const char *friendlyName,
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
void *arg) :
- _phy(this,false,true),
- _unixListenSocket((PhySocket *)0),
+ _nwid(nwid),
_handler(handler),
_arg(arg),
- _nwid(nwid),
+ _phy(this,false,true),
+ _unixListenSocket((PhySocket *)0),
_mac(mac),
_homePath(homePath),
_mtu(mtu),
@@ -570,7 +618,7 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock,void **uptr,void *data,uns
unload_rpc(data, pid, tid, rpc_count, timestamp, cmd, payload);
dwr(MSG_DEBUG, "\n\nRPC: (pid=%d, tid=%d, rpc_count=%d, timestamp=%s, cmd=%d\n", pid, tid, rpc_count, timestamp, cmd);
unsigned char *buf = (unsigned char*)data;
-
+
switch(cmd)
{
case RPC_SOCKET:
@@ -1024,7 +1072,7 @@ void NetconEthernetTap::handle_retval(PhySocket *sock, void **uptr, int rpc_coun
//return;
}
else
- rpc_counter = rpc_count;
+ rpc_counter = rpc_count;
dwr(MSG_DEBUG, " handle_retval(): CONN:%x - Mapping [our=%d -> their=%d]\n",conn,
_phy.getDescriptor(conn->dataSock), conn->perceived_fd);
@@ -1091,7 +1139,7 @@ void NetconEthernetTap::handle_retval(PhySocket *sock, void **uptr, int rpc_coun
*/
void NetconEthernetTap::handle_bind(PhySocket *sock, void **uptr, struct bind_st *bind_rpc)
{
-
+
struct sockaddr_in *connaddr;
connaddr = (struct sockaddr_in *) &bind_rpc->addr;
int conn_port = lwipstack->ntohs(connaddr->sin_port);
diff --git a/netcon/NetconEthernetTap.hpp b/netcon/NetconEthernetTap.hpp
index 00f8ac30..17b9975f 100644
--- a/netcon/NetconEthernetTap.hpp
+++ b/netcon/NetconEthernetTap.hpp
@@ -93,7 +93,6 @@ public:
void *_arg;
private:
-
// LWIP callbacks
static err_t nc_poll(void* arg, struct tcp_pcb *tpcb);
static err_t nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err);
@@ -129,7 +128,6 @@ private:
void phyOnUnixData(PhySocket *sock,void **uptr,void *data,unsigned long len);
void phyOnFileDescriptorActivity(PhySocket *sock,void **uptr,bool readable,bool writable);
-
ip_addr_t convert_ip(struct sockaddr_in * addr)
{
ip_addr_t conn_addr;
@@ -177,57 +175,6 @@ private:
volatile bool _run;
};
-
-/*------------------------------------------------------------------------------
------------------------- low-level Interface functions -------------------------
-------------------------------------------------------------------------------*/
-
-static err_t low_level_output(struct netif *netif, struct pbuf *p);
-
-static err_t tapif_init(struct netif *netif)
-{
- // Actual init functionality is in addIp() of tap
- return ERR_OK;
-}
-
-static err_t low_level_output(struct netif *netif, struct pbuf *p)
-{
- struct pbuf *q;
- char buf[ZT_MAX_MTU+32];
- char *bufptr;
- int tot_len = 0;
-
- ZeroTier::NetconEthernetTap *tap = (ZeroTier::NetconEthernetTap*)netif->state;
-
- /* initiate transfer(); */
- bufptr = buf;
-
- for(q = p; q != NULL; q = q->next) {
- /* Send the data from the pbuf to the interface, one pbuf at a
- time. The size of the data in each pbuf is kept in the ->len
- variable. */
- /* send data from(q->payload, q->len); */
- memcpy(bufptr, q->payload, q->len);
- bufptr += q->len;
- tot_len += q->len;
- }
-
- // [Send packet to network]
- // Split ethernet header and feed into handler
- struct eth_hdr *ethhdr;
- ethhdr = (struct eth_hdr *)buf;
-
- ZeroTier::MAC src_mac;
- ZeroTier::MAC dest_mac;
-
- src_mac.setTo(ethhdr->src.addr, 6);
- dest_mac.setTo(ethhdr->dest.addr, 6);
-
- tap->_handler(tap->_arg,tap->_nwid,src_mac,dest_mac,
- Utils::ntoh((uint16_t)ethhdr->type),0,buf + sizeof(struct eth_hdr),tot_len - sizeof(struct eth_hdr));
- return ERR_OK;
-}
-
} // namespace ZeroTier
#endif // ZT_ENABLE_NETCON