Browse Source

Eliminate a few warnings and some small code reorg.

Adam Ierymenko 9 years ago
parent
commit
d8d4cfbf01
3 changed files with 55 additions and 60 deletions
  1. 1 1
      ext/lwipopts.h
  2. 54 6
      netcon/NetconEthernetTap.cpp
  3. 0 53
      netcon/NetconEthernetTap.hpp

+ 1 - 1
ext/lwipopts.h

@@ -46,7 +46,7 @@
 
 #define LWIP_CHKSUM_ALGORITHM 2
 
-
+#undef TCP_MSS
 #define TCP_MSS 1460
 
 /*

+ 54 - 6
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);

+ 0 - 53
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