mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-23 23:02:23 +00:00
Eliminate a few warnings and some small code reorg.
This commit is contained in:
parent
34404eb300
commit
d8d4cfbf01
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
#define LWIP_CHKSUM_ALGORITHM 2
|
#define LWIP_CHKSUM_ALGORITHM 2
|
||||||
|
|
||||||
|
#undef TCP_MSS
|
||||||
#define TCP_MSS 1460
|
#define TCP_MSS 1460
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -57,6 +57,54 @@
|
|||||||
|
|
||||||
namespace ZeroTier {
|
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(
|
NetconEthernetTap::NetconEthernetTap(
|
||||||
const char *homePath,
|
const char *homePath,
|
||||||
const MAC &mac,
|
const MAC &mac,
|
||||||
@ -66,11 +114,11 @@ NetconEthernetTap::NetconEthernetTap(
|
|||||||
const char *friendlyName,
|
const char *friendlyName,
|
||||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
||||||
void *arg) :
|
void *arg) :
|
||||||
_phy(this,false,true),
|
_nwid(nwid),
|
||||||
_unixListenSocket((PhySocket *)0),
|
|
||||||
_handler(handler),
|
_handler(handler),
|
||||||
_arg(arg),
|
_arg(arg),
|
||||||
_nwid(nwid),
|
_phy(this,false,true),
|
||||||
|
_unixListenSocket((PhySocket *)0),
|
||||||
_mac(mac),
|
_mac(mac),
|
||||||
_homePath(homePath),
|
_homePath(homePath),
|
||||||
_mtu(mtu),
|
_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);
|
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);
|
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;
|
unsigned char *buf = (unsigned char*)data;
|
||||||
|
|
||||||
switch(cmd)
|
switch(cmd)
|
||||||
{
|
{
|
||||||
case RPC_SOCKET:
|
case RPC_SOCKET:
|
||||||
@ -1024,7 +1072,7 @@ void NetconEthernetTap::handle_retval(PhySocket *sock, void **uptr, int rpc_coun
|
|||||||
//return;
|
//return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rpc_counter = rpc_count;
|
rpc_counter = rpc_count;
|
||||||
|
|
||||||
dwr(MSG_DEBUG, " handle_retval(): CONN:%x - Mapping [our=%d -> their=%d]\n",conn,
|
dwr(MSG_DEBUG, " handle_retval(): CONN:%x - Mapping [our=%d -> their=%d]\n",conn,
|
||||||
_phy.getDescriptor(conn->dataSock), conn->perceived_fd);
|
_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)
|
void NetconEthernetTap::handle_bind(PhySocket *sock, void **uptr, struct bind_st *bind_rpc)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct sockaddr_in *connaddr;
|
struct sockaddr_in *connaddr;
|
||||||
connaddr = (struct sockaddr_in *) &bind_rpc->addr;
|
connaddr = (struct sockaddr_in *) &bind_rpc->addr;
|
||||||
int conn_port = lwipstack->ntohs(connaddr->sin_port);
|
int conn_port = lwipstack->ntohs(connaddr->sin_port);
|
||||||
|
@ -93,7 +93,6 @@ public:
|
|||||||
void *_arg;
|
void *_arg;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// LWIP callbacks
|
// LWIP callbacks
|
||||||
static err_t nc_poll(void* arg, struct tcp_pcb *tpcb);
|
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);
|
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 phyOnUnixData(PhySocket *sock,void **uptr,void *data,unsigned long len);
|
||||||
void phyOnFileDescriptorActivity(PhySocket *sock,void **uptr,bool readable,bool writable);
|
void phyOnFileDescriptorActivity(PhySocket *sock,void **uptr,bool readable,bool writable);
|
||||||
|
|
||||||
|
|
||||||
ip_addr_t convert_ip(struct sockaddr_in * addr)
|
ip_addr_t convert_ip(struct sockaddr_in * addr)
|
||||||
{
|
{
|
||||||
ip_addr_t conn_addr;
|
ip_addr_t conn_addr;
|
||||||
@ -177,57 +175,6 @@ private:
|
|||||||
volatile bool _run;
|
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
|
} // namespace ZeroTier
|
||||||
|
|
||||||
#endif // ZT_ENABLE_NETCON
|
#endif // ZT_ENABLE_NETCON
|
||||||
|
Loading…
Reference in New Issue
Block a user