From 0b9bed66989fa83407a41eeb7102b6783fb53949 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 5 Mar 2009 00:05:30 +0000 Subject: got rid of ThreadParam --- src/anytun.cpp | 55 ++++++++++++++++++++++++------------------------- src/anytun.vcproj | 4 ---- src/bsd/tunDevice.cpp | 6 +++--- src/linux/tunDevice.cpp | 6 +++--- src/threadParam.h | 52 ---------------------------------------------- src/tunDevice.h | 14 ++++++------- 6 files changed, 40 insertions(+), 97 deletions(-) delete mode 100644 src/threadParam.h (limited to 'src') diff --git a/src/anytun.cpp b/src/anytun.cpp index 98bebb0..b0997d4 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -74,7 +74,6 @@ #include "syncOnConnect.hpp" #endif -#include "threadParam.h" #define MAX_PACKET_LENGTH 1600 #include "cryptinit.hpp" @@ -101,11 +100,9 @@ void createConnection(const PacketSourceEndpoint & remote_end, window_size_t seq } #ifndef ANYTUN_NOSYNC -void syncConnector(void* p ) +void syncConnector(const OptionHost& connto) { - ThreadParam* param = reinterpret_cast(p); - - SyncClient sc ( param->connto.addr, param->connto.port); + SyncClient sc(connto.addr, connto.port); sc.run(); } @@ -141,12 +138,15 @@ void syncListener() } #endif -void sender(void* p) +void sender(const TunDevice* dev, PacketSource* src) { + if(!dev || !src) { + cLog.msg(Log::PRIO_ERROR) << "sender thread died becaause either dev or src pointer is null"; + return; + } + try { - ThreadParam* param = reinterpret_cast(p); - std::auto_ptr c(CipherFactory::create(gOpt.getCipher(), KD_OUTBOUND, gOpt.getAnytun02Compat())); std::auto_ptr a(AuthAlgoFactory::create(gOpt.getAuthAlgo(), KD_OUTBOUND) ); @@ -161,7 +161,7 @@ void sender(void* p) encrypted_packet.setLength(MAX_PACKET_LENGTH); // read packet from device - int len = param->dev.read(plain_packet.getPayload(), plain_packet.getPayloadLength()); + int len = dev->read(plain_packet.getPayload(), plain_packet.getPayloadLength()); if(len < 0) continue; // silently ignore device read errors, this is probably no good idea... @@ -169,9 +169,9 @@ void sender(void* p) continue; // ignore short packets plain_packet.setPayloadLength(len); // set payload type - if(param->dev.getType() == TYPE_TUN) + if(dev->getType() == TYPE_TUN) plain_packet.setPayloadType(PAYLOAD_TYPE_TUN); - else if(param->dev.getType() == TYPE_TAP) + else if(dev->getType() == TYPE_TAP) plain_packet.setPayloadType(PAYLOAD_TYPE_TAP); else plain_packet.setPayloadType(0); @@ -212,7 +212,7 @@ void sender(void* p) a->generate(conn.kd_, encrypted_packet); try { - param->src.send(encrypted_packet.getBuf(), encrypted_packet.getLength(), conn.remote_end_); + src->send(encrypted_packet.getBuf(), encrypted_packet.getLength(), conn.remote_end_); } catch (std::exception& /*e*/) { //TODO: do something here //cLog.msg(Log::PRIO_ERROR) << "could not send data: " << e.what(); @@ -227,12 +227,15 @@ void sender(void* p) } } -void receiver(void* p) +void receiver(const TunDevice* dev, PacketSource* src) { + if(!dev || !src) { + cLog.msg(Log::PRIO_ERROR) << "receiver thread died becaause either dev or src pointer is null"; + return; + } + try { - ThreadParam* param = reinterpret_cast(p); - std::auto_ptr c(CipherFactory::create(gOpt.getCipher(), KD_INBOUND, gOpt.getAnytun02Compat())); std::auto_ptr a(AuthAlgoFactory::create(gOpt.getAuthAlgo(), KD_INBOUND)); @@ -249,7 +252,7 @@ void receiver(void* p) // read packet from socket int len; try { - len = param->src.recv(encrypted_packet.getBuf(), encrypted_packet.getLength(), remote_end); + len = src->recv(encrypted_packet.getBuf(), encrypted_packet.getLength(), remote_end); } catch (std::exception& /*e*/) { //TODO: do something here //cLog.msg(Log::PRIO_ERROR) << "could not recive packet "<< e.what(); @@ -305,13 +308,13 @@ void receiver(void* p) c->decrypt(conn.kd_, encrypted_packet, plain_packet); // check payload_type - if((param->dev.getType() == TYPE_TUN && plain_packet.getPayloadType() != PAYLOAD_TYPE_TUN4 && + if((dev->getType() == TYPE_TUN && plain_packet.getPayloadType() != PAYLOAD_TYPE_TUN4 && plain_packet.getPayloadType() != PAYLOAD_TYPE_TUN6) || - (param->dev.getType() == TYPE_TAP && plain_packet.getPayloadType() != PAYLOAD_TYPE_TAP)) + (dev->getType() == TYPE_TAP && plain_packet.getPayloadType() != PAYLOAD_TYPE_TAP)) continue; // write it on the device - param->dev.write(plain_packet.getPayload(), plain_packet.getLength()); + dev->write(plain_packet.getPayload(), plain_packet.getLength()); } } catch(std::runtime_error& e) { @@ -482,12 +485,9 @@ int main(int argc, char* argv[]) } #endif - OptionHost* connTo = new OptionHost(); - ThreadParam p(dev, *src, *connTo); - - boost::thread senderThread(boost::bind(sender,&p)); + boost::thread senderThread(boost::bind(sender, &dev, src)); #if defined(WIN_SERVICE) || !defined(NO_SIGNALCONTROLLER) - boost::thread receiverThread(boost::bind(receiver,&p)); + boost::thread receiverThread(boost::bind(receiver, &dev, src)); #endif #ifndef ANYTUN_NOSYNC boost::thread * syncListenerThread; @@ -495,9 +495,8 @@ int main(int argc, char* argv[]) syncListenerThread = new boost::thread(boost::bind(syncListener)); std::list connectThreads; - for(HostList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) { - ThreadParam * point = new ThreadParam(dev, *src, *it); - connectThreads.push_back(new boost::thread(boost::bind(syncConnector,point))); + for(HostList::const_iterator it = connect_to.begin() ;it != connect_to.end(); ++it) { + connectThreads.push_back(new boost::thread(boost::bind(syncConnector, *it))); } #endif @@ -507,7 +506,7 @@ int main(int argc, char* argv[]) #elif !defined(NO_SIGNALCONTROLLER) int ret = gSignalController.run(); #else - receiver(&p); + receiver(dev, *src); int ret = 0; #endif // TODO cleanup threads here! diff --git a/src/anytun.vcproj b/src/anytun.vcproj index 4bd6d85..57b141a 100644 --- a/src/anytun.vcproj +++ b/src/anytun.vcproj @@ -479,10 +479,6 @@ RelativePath=".\syncTcpConnection.h" > - - diff --git a/src/bsd/tunDevice.cpp b/src/bsd/tunDevice.cpp index 4e344a8..240e46c 100644 --- a/src/bsd/tunDevice.cpp +++ b/src/bsd/tunDevice.cpp @@ -192,7 +192,7 @@ void TunDevice::init_post() #error This Device works just for OpenBSD, FreeBSD or NetBSD #endif -int TunDevice::fix_return(int ret, size_t pi_length) +int TunDevice::fix_return(int ret, size_t pi_length) const { if(ret < 0) return ret; @@ -200,7 +200,7 @@ int TunDevice::fix_return(int ret, size_t pi_length) return (static_cast(ret) > type_length ? (ret - type_length) : 0); } -int TunDevice::read(u_int8_t* buf, u_int32_t len) +int TunDevice::read(u_int8_t* buf, u_int32_t len) const { if(fd_ < 0) return -1; @@ -219,7 +219,7 @@ int TunDevice::read(u_int8_t* buf, u_int32_t len) return(::read(fd_, buf, len)); } -int TunDevice::write(u_int8_t* buf, u_int32_t len) +int TunDevice::write(u_int8_t* buf, u_int32_t len) const { if(fd_ < 0) return -1; diff --git a/src/linux/tunDevice.cpp b/src/linux/tunDevice.cpp index e9056b3..b221ebb 100644 --- a/src/linux/tunDevice.cpp +++ b/src/linux/tunDevice.cpp @@ -90,7 +90,7 @@ TunDevice::~TunDevice() ::close(fd_); } -int TunDevice::fix_return(int ret, size_t pi_length) +int TunDevice::fix_return(int ret, size_t pi_length) const { if(ret < 0) return ret; @@ -98,7 +98,7 @@ int TunDevice::fix_return(int ret, size_t pi_length) return (static_cast(ret) > pi_length ? (ret - pi_length) : 0); } -int TunDevice::read(u_int8_t* buf, u_int32_t len) +int TunDevice::read(u_int8_t* buf, u_int32_t len) const { if(fd_ < 0) return -1; @@ -118,7 +118,7 @@ int TunDevice::read(u_int8_t* buf, u_int32_t len) return(::read(fd_, buf, len)); } -int TunDevice::write(u_int8_t* buf, u_int32_t len) +int TunDevice::write(u_int8_t* buf, u_int32_t len) const { if(fd_ < 0) return -1; diff --git a/src/threadParam.h b/src/threadParam.h deleted file mode 100644 index 60741d4..0000000 --- a/src/threadParam.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl, - * Christian Pointner - * - * This file is part of Anytun. - * - * Anytun is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * Anytun is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with anytun. If not, see . - */ - -#ifndef _THREAD_PARAM_H -#define _THREAD_PARAM_H - -#include "threadUtils.hpp" -#include "datatypes.h" -#include "tunDevice.h" -#include "connectionList.h" -#include "syncQueue.h" - -class ThreadParam -{ -public: - ThreadParam(TunDevice& dev_,PacketSource& src_,OptionHost & connto_) - : dev(dev_),src(src_),connto(connto_) - {}; - TunDevice& dev; - PacketSource& src; - OptionHost & connto; -}; - -#endif diff --git a/src/tunDevice.h b/src/tunDevice.h index c470b9c..2443663 100644 --- a/src/tunDevice.h +++ b/src/tunDevice.h @@ -46,13 +46,13 @@ public: TunDevice(std::string dev,std::string dev_type, std::string ifcfg_addr, u_int16_t ifcfg_prefix); ~TunDevice(); - int read(u_int8_t* buf, u_int32_t len); - int write(u_int8_t* buf, u_int32_t len); + int read(u_int8_t* buf, u_int32_t len) const; + int write(u_int8_t* buf, u_int32_t len) const; - std::string getActualName() { return actual_name_; } - std::string getActualNode() { return actual_node_; } - device_type_t getType() { return conf_.type_; } - std::string getTypeString() + const char* getActualName() const { return actual_name_.c_str(); } + const char* getActualNode() const { return actual_node_.c_str(); } + device_type_t getType() const { return conf_.type_; } + const char* getTypeString() const { #ifndef _MSC_VER if(fd_ < 0) @@ -77,7 +77,7 @@ private: void init_post(); void do_ifconfig(); - int fix_return(int ret, size_t pi_length); + int fix_return(int ret, size_t pi_length) const; #ifndef _MSC_VER int fd_; -- cgit v1.2.3