From 5cf7604389d8846f9c1c21dbb6915f7639659c4c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 15:19:05 +0300 Subject: [PATCH 01/16] Traffcounter divided into interface and implementation --- include/traffcounter.h | 31 +++++ projects/stargazer/Makefile | 2 +- ...traffcounter.cpp => traffcounter_impl.cpp} | 56 ++++----- .../{traffcounter.h => traffcounter_impl.h} | 109 +++++++++--------- 4 files changed, 113 insertions(+), 85 deletions(-) create mode 100644 include/traffcounter.h rename projects/stargazer/{traffcounter.cpp => traffcounter_impl.cpp} (94%) rename projects/stargazer/{traffcounter.h => traffcounter_impl.h} (78%) diff --git a/include/traffcounter.h b/include/traffcounter.h new file mode 100644 index 00000000..1962ee7a --- /dev/null +++ b/include/traffcounter.h @@ -0,0 +1,31 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : maxim Mamontov + */ + +#ifndef TRAFFCOUNTER_H +#define TRAFFCOUNTER_H + +#include "raw_ip_packet.h" + +class TRAFFCOUNTER { +public: + virtual void Process(const RAW_PACKET & rawPacket) = 0; +}; + +#endif diff --git a/projects/stargazer/Makefile b/projects/stargazer/Makefile index 9f7dd869..5aa4687f 100644 --- a/projects/stargazer/Makefile +++ b/projects/stargazer/Makefile @@ -17,7 +17,7 @@ SRCS = ./admin_impl.cpp \ ./store_loader.cpp \ ./tariff_impl.cpp \ ./tariffs_impl.cpp \ - ./traffcounter.cpp \ + ./traffcounter_impl.cpp \ ./user_impl.cpp \ ./user_property.cpp \ ./users_impl.cpp diff --git a/projects/stargazer/traffcounter.cpp b/projects/stargazer/traffcounter_impl.cpp similarity index 94% rename from projects/stargazer/traffcounter.cpp rename to projects/stargazer/traffcounter_impl.cpp index dd672f37..f410b109 100644 --- a/projects/stargazer/traffcounter.cpp +++ b/projects/stargazer/traffcounter_impl.cpp @@ -35,9 +35,9 @@ #include #include -#include // Functions fopen and similar +#include // fopen and similar -#include "traffcounter.h" +#include "traffcounter_impl.h" #include "common.h" #include "stg_locker.h" #include "stg_timer.h" @@ -49,12 +49,12 @@ const char protoName[PROTOMAX][8] = {"TCP", "UDP", "ICMP", "TCP_UDP", "ALL"}; enum protoNum - { - tcp = 0, udp, icmp, tcp_udp, all - }; +{ +tcp = 0, udp, icmp, tcp_udp, all +}; //----------------------------------------------------------------------------- -TRAFFCOUNTER::TRAFFCOUNTER(USERS * u, const TARIFFS *, const std::string & fn) +TRAFFCOUNTER_IMPL::TRAFFCOUNTER_IMPL(USERS * u, const TARIFFS *, const std::string & fn) : WriteServLog(GetStgLogger()), rulesFileName(fn), monitoring(false), @@ -75,12 +75,12 @@ users->AddNotifierUserDel(&delUserNotifier); pthread_mutex_init(&mutex, NULL); } //----------------------------------------------------------------------------- -TRAFFCOUNTER::~TRAFFCOUNTER() +TRAFFCOUNTER_IMPL::~TRAFFCOUNTER_IMPL() { pthread_mutex_destroy(&mutex); } //----------------------------------------------------------------------------- -int TRAFFCOUNTER::Start() +int TRAFFCOUNTER_IMPL::Start() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -117,7 +117,7 @@ if (pthread_create(&thread, NULL, Run, this)) return 0; } //----------------------------------------------------------------------------- -int TRAFFCOUNTER::Stop() +int TRAFFCOUNTER_IMPL::Stop() { if (stopped) return 0; @@ -160,9 +160,9 @@ printfd(__FILE__, "TRAFFCOUNTER::Stop()\n"); return 0; } //----------------------------------------------------------------------------- -void * TRAFFCOUNTER::Run(void * data) +void * TRAFFCOUNTER_IMPL::Run(void * data) { -TRAFFCOUNTER * tc = static_cast(data); +TRAFFCOUNTER_IMPL * tc = static_cast(data); tc->stopped = false; int c = 0; @@ -193,7 +193,7 @@ tc->stopped = true; return NULL; } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::Process(const RAW_PACKET & rawPacket) +void TRAFFCOUNTER_IMPL::Process(const RAW_PACKET & rawPacket) { if (!running) return; @@ -284,7 +284,7 @@ if (ed.userUPresent || } } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::FlushAndRemove() +void TRAFFCOUNTER_IMPL::FlushAndRemove() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -410,7 +410,7 @@ printfd(__FILE__, "FlushAndRemove() packets: %d(rem %d) ip2packets: %d(rem %d)\n } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::AddUser(USER_PTR user) +void TRAFFCOUNTER_IMPL::AddUser(USER_PTR user) { printfd(__FILE__, "AddUser: %s\n", user->GetLogin().c_str()); uint32_t uip = user->GetCurrIP(); @@ -448,7 +448,7 @@ while (pi.first != pi.second) } } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::DelUser(uint32_t uip) +void TRAFFCOUNTER_IMPL::DelUser(uint32_t uip) { printfd(__FILE__, "DelUser: %s \n", inet_ntostring(uip).c_str()); std::pair pi; @@ -501,7 +501,7 @@ while (pi.first != pi.second) ip2packets.erase(pi.first, pi.second); } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::SetUserNotifiers(USER_PTR user) +void TRAFFCOUNTER_IMPL::SetUserNotifiers(USER_PTR user) { // Adding user. Adding notifiers to user. TRF_IP_BEFORE ipBNotifier(*this, user); @@ -513,7 +513,7 @@ ipAfterNotifiers.push_front(ipANotifier); user->AddCurrIPAfterNotifier(&(*ipAfterNotifiers.begin())); } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::UnSetUserNotifiers(USER_PTR user) +void TRAFFCOUNTER_IMPL::UnSetUserNotifiers(USER_PTR user) { // Removing user. Removing notifiers from user. std::list::iterator bi; @@ -544,9 +544,9 @@ while (ai != ipAfterNotifiers.end()) } } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::DeterminateDir(const RAW_PACKET & packet, - int * dirU, // Direction for incoming packet - int * dirD) const // Direction for outgoing packet +void TRAFFCOUNTER_IMPL::DeterminateDir(const RAW_PACKET & packet, + int * dirU, // Direction for incoming packet + int * dirD) const // Direction for outgoing packet { bool addrMatchU; bool portMatchU; @@ -668,12 +668,12 @@ if (!foundD) return; }; //----------------------------------------------------------------------------- -void TRAFFCOUNTER::SetRulesFile(const std::string & fn) +void TRAFFCOUNTER_IMPL::SetRulesFile(const std::string & fn) { rulesFileName = fn; } //----------------------------------------------------------------------------- -bool TRAFFCOUNTER::ReadRules(bool test) +bool TRAFFCOUNTER_IMPL::ReadRules(bool test) { //printfd(__FILE__, "TRAFFCOUNTER::ReadRules()\n"); @@ -762,7 +762,7 @@ if (!test) return false; } //----------------------------------------------------------------------------- -int TRAFFCOUNTER::Reload() +int TRAFFCOUNTER_IMPL::Reload() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -778,7 +778,7 @@ WriteServLog("TRAFFCOUNTER: Reload rules successfull."); return 0; } //----------------------------------------------------------------------------- -bool TRAFFCOUNTER::ParseAddress(const char * ta, RULE * rule) const +bool TRAFFCOUNTER_IMPL::ParseAddress(const char * ta, RULE * rule) const { char addr[50], mask[20], port1[20], port2[20], ports[40]; @@ -896,19 +896,19 @@ rule->port2 = prt2; return false; } //----------------------------------------------------------------------------- -uint32_t TRAFFCOUNTER::CalcMask(uint32_t msk) const +uint32_t TRAFFCOUNTER_IMPL::CalcMask(uint32_t msk) const { if (msk >= 32) return 0xFFffFFff; if (msk == 0) return 0; return htonl(0xFFffFFff << (32 - msk)); } //--------------------------------------------------------------------------- -void TRAFFCOUNTER::FreeRules() +void TRAFFCOUNTER_IMPL::FreeRules() { rules.clear(); } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::PrintRule(RULE rule) const +void TRAFFCOUNTER_IMPL::PrintRule(RULE rule) const { printf("%15s ", inet_ntostring(rule.ip).c_str()); printf("mask=%08X ", rule.mask); @@ -936,7 +936,7 @@ printf("dir=%d \n", rule.dir); return; } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::SetMonitorDir(const std::string & monitorDir) +void TRAFFCOUNTER_IMPL::SetMonitorDir(const std::string & monitorDir) { TRAFFCOUNTER::monitorDir = monitorDir; monitoring = (monitorDir != ""); diff --git a/projects/stargazer/traffcounter.h b/projects/stargazer/traffcounter_impl.h similarity index 78% rename from projects/stargazer/traffcounter.h rename to projects/stargazer/traffcounter_impl.h index d6a56881..eb476239 100644 --- a/projects/stargazer/traffcounter.h +++ b/projects/stargazer/traffcounter_impl.h @@ -25,15 +25,17 @@ */ -#ifndef TRAFFCOUNTER_H -#define TRAFFCOUNTER_H +#ifndef TRAFFCOUNTER_IMPL_H +#define TRAFFCOUNTER_IMPL_H #include + #include #include #include #include +#include "traffcounter.h" #include "os_int.h" #include "stg_logger.h" #include "raw_ip_packet.h" @@ -47,8 +49,7 @@ class TARIFFS; //----------------------------------------------------------------------------- -struct RULE -{ +struct RULE { uint32_t ip; // IP uint32_t mask; // Network mask uint16_t port1; // Min port @@ -57,8 +58,7 @@ uint8_t proto; // Protocol uint32_t dir; // Direction }; //----------------------------------------------------------------------------- -struct PACKET_EXTRA_DATA -{ +struct PACKET_EXTRA_DATA { PACKET_EXTRA_DATA() : flushTime(0), updateTime(0), @@ -70,7 +70,7 @@ PACKET_EXTRA_DATA() dirD(DIR_NUM), lenU(0), lenD(0) -{}; +{} PACKET_EXTRA_DATA(const PACKET_EXTRA_DATA & pp) : flushTime(pp.flushTime), @@ -83,7 +83,7 @@ PACKET_EXTRA_DATA(const PACKET_EXTRA_DATA & pp) dirD(pp.dirD), lenU(pp.lenU), lenD(pp.lenD) -{}; +{} time_t flushTime; // Last flush time time_t updateTime; // Last update time @@ -97,74 +97,71 @@ uint32_t lenU; // Upload length uint32_t lenD; // Download length }; //----------------------------------------------------------------------------- -class TRAFFCOUNTER; +class TRAFFCOUNTER_IMPL; //----------------------------------------------------------------------------- -class TRF_IP_BEFORE: public PROPERTY_NOTIFIER_BASE -{ +class TRF_IP_BEFORE: public PROPERTY_NOTIFIER_BASE { public: - TRF_IP_BEFORE(TRAFFCOUNTER & t, USER_PTR u) + TRF_IP_BEFORE(TRAFFCOUNTER_IMPL & t, USER_PTR u) : PROPERTY_NOTIFIER_BASE(), traffCnt(t), user(u) - {}; + {} void Notify(const uint32_t & oldValue, const uint32_t & newValue); void SetUser(USER_PTR u) { user = u; } USER_PTR GetUser() const { return user; } private: - TRAFFCOUNTER & traffCnt; - USER_PTR user; + TRAFFCOUNTER_IMPL & traffCnt; + USER_PTR user; }; //----------------------------------------------------------------------------- -class TRF_IP_AFTER: public PROPERTY_NOTIFIER_BASE -{ +class TRF_IP_AFTER: public PROPERTY_NOTIFIER_BASE { public: - TRF_IP_AFTER(TRAFFCOUNTER & t, USER_PTR u) + TRF_IP_AFTER(TRAFFCOUNTER_IMPL & t, USER_PTR u) : PROPERTY_NOTIFIER_BASE(), traffCnt(t), user(u) - {}; + {} void Notify(const uint32_t & oldValue, const uint32_t & newValue); void SetUser(USER_PTR u) { user = u; } USER_PTR GetUser() const { return user; } private: - TRAFFCOUNTER & traffCnt; - USER_PTR user; + TRAFFCOUNTER_IMPL & traffCnt; + USER_PTR user; }; //----------------------------------------------------------------------------- -class ADD_USER_NONIFIER: public NOTIFIER_BASE -{ +class ADD_USER_NONIFIER: public NOTIFIER_BASE { public: - ADD_USER_NONIFIER(TRAFFCOUNTER & t) : + ADD_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) : NOTIFIER_BASE(), - traffCnt(t) {}; - virtual ~ADD_USER_NONIFIER(){}; + traffCnt(t) + {} + virtual ~ADD_USER_NONIFIER() {} void Notify(const USER_PTR & user); private: - TRAFFCOUNTER & traffCnt; + TRAFFCOUNTER_IMPL & traffCnt; }; //----------------------------------------------------------------------------- -class DEL_USER_NONIFIER: public NOTIFIER_BASE -{ +class DEL_USER_NONIFIER: public NOTIFIER_BASE { public: - DEL_USER_NONIFIER(TRAFFCOUNTER & t) : + DEL_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) : NOTIFIER_BASE(), - traffCnt(t) {}; - virtual ~DEL_USER_NONIFIER(){}; + traffCnt(t) + {} + virtual ~DEL_USER_NONIFIER() {} void Notify(const USER_PTR & user); private: - TRAFFCOUNTER & traffCnt; + TRAFFCOUNTER_IMPL & traffCnt; }; //----------------------------------------------------------------------------- -class TRAFFCOUNTER : private NONCOPYABLE -{ +class TRAFFCOUNTER : public TRAFFCOUNTER, private NONCOPYABLE { friend class ADD_USER_NONIFIER; friend class DEL_USER_NONIFIER; friend class TRF_IP_BEFORE; friend class TRF_IP_AFTER; public: - TRAFFCOUNTER(USERS * users, const TARIFFS * tariffs, const std::string & rulesFileName); - ~TRAFFCOUNTER(); + TRAFFCOUNTER_IMPL(USERS * users, const TARIFFS * tariffs, const std::string & rulesFileName); + ~TRAFFCOUNTER_IMPL(); void SetRulesFile(const std::string & rulesFileName); @@ -195,37 +192,37 @@ private: void SetUserNotifiers(USER_PTR user); void UnSetUserNotifiers(USER_PTR user); - std::list rules; typedef std::list::iterator rule_iter; + typedef std::map::iterator pp_iter; + typedef std::multimap::iterator ip2p_iter; + typedef std::multimap::const_iterator ip2p_citer; + + std::list rules; std::map packets; // Packets tree - typedef std::map::iterator pp_iter; std::multimap ip2packets; // IP-to-Packet index - typedef std::multimap::iterator ip2p_iter; - typedef std::multimap::const_iterator ip2p_citer; - - std::string dirName[DIR_NUM + 1]; + std::string dirName[DIR_NUM + 1]; - STG_LOGGER & WriteServLog; - std::string rulesFileName; + STG_LOGGER & WriteServLog; + std::string rulesFileName; - std::string monitorDir; - bool monitoring; + std::string monitorDir; + bool monitoring; - USERS * users; + USERS * users; - bool running; - bool stopped; - pthread_mutex_t mutex; - pthread_t thread; + bool running; + bool stopped; + pthread_mutex_t mutex; + pthread_t thread; - std::list ipBeforeNotifiers; - std::list ipAfterNotifiers; + std::list ipBeforeNotifiers; + std::list ipAfterNotifiers; - ADD_USER_NONIFIER addUserNotifier; - DEL_USER_NONIFIER delUserNotifier; + ADD_USER_NONIFIER addUserNotifier; + DEL_USER_NONIFIER delUserNotifier; }; //----------------------------------------------------------------------------- inline -- 2.44.2 From 9faa3c51da5965b95d165ade36120a74a69521f4 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 15:58:36 +0300 Subject: [PATCH 02/16] Fix TRAFFCOUNTER in plugins --- .../plugins/capture/cap_nf/cap_nf.cpp | 23 +---- .../stargazer/plugins/capture/cap_nf/cap_nf.h | 4 +- .../capture/divert_freebsd/divert_cap.cpp | 68 +------------ .../capture/divert_freebsd/divert_cap.h | 13 ++- .../capture/ether_freebsd/ether_cap.cpp | 95 ++----------------- .../plugins/capture/ether_freebsd/ether_cap.h | 38 ++++---- .../plugins/capture/ether_linux/ether_cap.cpp | 35 +------ .../plugins/capture/ether_linux/ether_cap.h | 15 +-- .../plugins/capture/ipq_linux/ipq_cap.cpp | 46 ++------- .../plugins/capture/ipq_linux/ipq_cap.h | 12 +-- 10 files changed, 70 insertions(+), 279 deletions(-) diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp index 0e0204da..1b84d460 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp @@ -42,23 +42,21 @@ $Author: faust $ #include "common.h" #include "cap_nf.h" #include "raw_ip_packet.h" +#include "traffcounter.h" -#include "../../../traffcounter.h" - -class CAP_NF_CREATOR -{ +class CAP_NF_CREATOR { public: CAP_NF_CREATOR() : nf(new NF_CAP()) { - }; + } ~CAP_NF_CREATOR() { delete nf; - }; + } - NF_CAP * GetCapturer() { return nf; }; + NF_CAP * GetCapturer() { return nf; } private: NF_CAP * nf; } cnc; @@ -280,9 +278,6 @@ while (cap->runningUDP) continue; } - - // Wrong logic! - // Need to check actual data length and wait all data to receive if (res < 24) { if (errno != EINTR) @@ -392,14 +387,6 @@ for (int i = 0; i < packets; ++i) { NF_DATA * data = reinterpret_cast(buf + 24 + i * 48); - /*ip.pckt[0] = 4 << 4; - ip.pckt[0] |= 5; - ip.pckt[9] = data->proto; - ip.dataLen = ntohl(data->octets); - *(uint32_t *)(ip.pckt + 12) = data->srcAddr; - *(uint32_t *)(ip.pckt + 16) = data->dstAddr; - *(uint16_t *)(ip.pckt + 20) = data->srcPort; - *(uint16_t *)(ip.pckt + 22) = data->dstPort;*/ ip.header.ipHeader.ip_v = 4; ip.header.ipHeader.ip_hl = 5; ip.header.ipHeader.ip_p = data->proto; diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h index 786be396..7712f761 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h @@ -39,8 +39,8 @@ $Author: faust $ #include "module_settings.h" #define VERSION "CAP_NF v. 0.4" -#define START_POS 0 -#define STOP_POS 0 +#define START_POS 10 +#define STOP_POS 10 class USERS; class USER; diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 2bc83cad..5c7ec364 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -41,6 +41,7 @@ $Date: 2010/09/10 06:43:03 $ #include "common.h" #include "divert_cap.h" +#include "traffcounter.h" #define BUFF_LEN (16384) /* max mtu -> lo=16436 TODO why?*/ @@ -63,16 +64,16 @@ public: DIVERT_CAP_CREATOR() : divc(new DIVERT_CAP()) { - }; + } ~DIVERT_CAP_CREATOR() { delete divc; - }; + } DIVERT_CAP * GetCapturer() { return divc; - }; + } }; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -101,16 +102,6 @@ DIVERT_CAP::DIVERT_CAP() { } //----------------------------------------------------------------------------- -void DIVERT_CAP::SetTraffcounter(TRAFFCOUNTER * tc) -{ -traffCnt = tc; -} -//----------------------------------------------------------------------------- -const std::string & DIVERT_CAP::GetStrError() const -{ -return errorStr; -} -//----------------------------------------------------------------------------- int DIVERT_CAP::Start() { if (isRunning) @@ -168,51 +159,22 @@ if (isRunning) return 0; } //----------------------------------------------------------------------------- -bool DIVERT_CAP::IsRunning() -{ -return isRunning; -} -//----------------------------------------------------------------------------- void * DIVERT_CAP::Run(void * d) { DIVERT_CAP * dc = (DIVERT_CAP *)d; dc->isRunning = true; -/*struct ETH_IP -{ -uint16_t ethHdr[8]; -RAW_PACKET rp; -char padding[4]; -char padding1[8]; -}; - -ETH_IP * ethIP; - -char ethip[sizeof(ETH_IP)]; - -//memset(ðIP, 0, sizeof(ethIP)); -memset(ðip, 0, sizeof(ETH_IP)); - -ethIP = (ETH_IP *)ðip; -ethIP->rp.dataLen = -1; -*/ -//char * iface = NULL; char buffer[64]; while (dc->nonstop) { RAW_PACKET rp; dc->DivertCapRead(buffer, 64, NULL); - //printf("%x %x %x %x \n", buffer[0], buffer[4], buffer[8], buffer[12]); - //printf("%x %x %x %x \n", buffer[16], buffer[20], buffer[24], buffer[28]); - //printf("%x %x %x %x \n", buffer[32], buffer[36], buffer[40], buffer[44]); - if (buffer[12] != 0x8) continue; memcpy(rp.pckt, &buffer[14], pcktSize); - //dc->traffCnt->Process(*((RAW_PACKET*)( &buffer[14] ))); // - too dirty! dc->traffCnt->Process(rp); } @@ -220,22 +182,6 @@ dc->isRunning = false; return NULL; } //----------------------------------------------------------------------------- -uint16_t DIVERT_CAP::GetStartPosition() const -{ -return 10; -} -//----------------------------------------------------------------------------- -uint16_t DIVERT_CAP::GetStopPosition() const -{ -return 10; -} -//----------------------------------------------------------------------------- -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -//----------------------------------------------------------------------------- int DIVERT_CAP::DivertCapOpen() { memset(&pollddiv, 0, sizeof(pollddiv)); @@ -365,9 +311,3 @@ if (*val < min || *val > max) return 0; } //----------------------------------------------------------------------------- -void DIVERT_CAP::SetSettings(const MODULE_SETTINGS & s) -{ -settings = s; -} -//----------------------------------------------------------------------------- - diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h index e34fcf32..b463e328 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h @@ -33,7 +33,6 @@ $Date: 2009/06/23 11:32:27 $ #include "plugin.h" #include "module_settings.h" -#include "../../../traffcounter.h" class USERS; class TARIFFS; @@ -52,21 +51,21 @@ public: void SetUsers(USERS *) {} void SetTariffs(TARIFFS *) {} void SetAdmins(ADMINS *) {} - void SetTraffcounter(TRAFFCOUNTER * tc); + void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; } void SetStore(STORE *) {} void SetStgSettings(const SETTINGS *) {} int Start(); int Stop(); int Reload() { return 0; } - bool IsRunning(); + bool IsRunning() { return isRunning; } - void SetSettings(const MODULE_SETTINGS & s); + void SetSettings(const MODULE_SETTINGS & s) { settings = s; } int ParseSettings(); - const std::string & GetStrError() const; + const std::string & GetStrError() const { return errorStr; } const std::string GetVersion() const; - uint16_t GetStartPosition() const; - uint16_t GetStopPosition() const; + uint16_t GetStartPosition() const { return 10; } + uint16_t GetStopPosition() const { return 10; } private: static void * Run(void *); diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp index 0f6cb98c..26dca8e0 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp @@ -51,6 +51,7 @@ $Author: faust $ #include "ether_cap.h" #include "common.h" #include "raw_ip_packet.h" +#include "traffcounter.h" //#define CAP_DEBUG 1 //----------------------------------------------------------------------------- @@ -64,16 +65,16 @@ public: BPF_CAP_CREATOR() : bpfc(new BPF_CAP()) { - }; + } ~BPF_CAP_CREATOR() { delete bpfc; - }; + } BPF_CAP * GetCapturer() { return bpfc; - }; + } }; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -91,18 +92,10 @@ return bcc.GetCapturer(); //----------------------------------------------------------------------------- int BPF_CAP_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) { -//char sep[]= ", \t\n\r"; -//char *s; std::string ifaces; -//char * str; -//char *p; iface.erase(iface.begin(), iface.end()); -//PARAM_VALUE pv; -//pv.param = "WorkDir"; -//vector::const_iterator pvi; - if (s.moduleParams.empty()) { errorStr = "Parameter \'iface\' not found."; @@ -124,32 +117,6 @@ for (unsigned i = 0; i < s.moduleParams.size(); i++) } } -/*if (cf.ReadString("Iface", &ifaces, "NoIface") < 0) - { - errorStr = "Cannot read parameter \'Iface\' from " + cf.GetFileName(); - return -1; - } - -str = new char[ifaces.size() + 1]; -strcpy(str, ifaces.c_str()); -p = str; - -while((s = strtok(p, sep))) - { - printfd(__FILE__, "iface[] = %s\n", s); - p = NULL; - iface.push_back(s); - //strncpy(iface[i++], s, DEV_NAME_LEN); - //devNum++; - } - -delete[] str; -if (!ifaces.size()) - { - errorStr = "Error read parameter \'Iface\' from " + cf.GetFileName(); - return -1; - }*/ - return 0; } //----------------------------------------------------------------------------- @@ -177,11 +144,6 @@ BPF_CAP::BPF_CAP() { } //----------------------------------------------------------------------------- -void BPF_CAP::SetSettings(const MODULE_SETTINGS & s) -{ -settings = s; -} -//----------------------------------------------------------------------------- int BPF_CAP::ParseSettings() { int ret = capSettings.ParseSettings(settings); @@ -193,16 +155,6 @@ if (ret) return 0; } //----------------------------------------------------------------------------- -void BPF_CAP::SetTraffcounter(TRAFFCOUNTER * tc) -{ -traffCnt = tc; -} -//----------------------------------------------------------------------------- -const std::string & BPF_CAP::GetStrError() const -{ -return errorStr; -} -//----------------------------------------------------------------------------- int BPF_CAP::Start() { if (isRunning) @@ -260,11 +212,6 @@ if (isRunning) return 0; } //----------------------------------------------------------------------------- -bool BPF_CAP::IsRunning() -{ -return isRunning; -} -//----------------------------------------------------------------------------- void * BPF_CAP::Run(void * d) { BPF_CAP * dc = (BPF_CAP *)d; @@ -294,19 +241,8 @@ dc->isRunning = false; return NULL; } //----------------------------------------------------------------------------- -uint16_t BPF_CAP::GetStartPosition() const -{ -return 0; -} -//----------------------------------------------------------------------------- -uint16_t BPF_CAP::GetStopPosition() const -{ -return 0; -} -//----------------------------------------------------------------------------- int BPF_CAP::BPFCapOpen() { -//for (int i = 0; i < settings->devNum; i++) int i = 0; BPF_DATA bd; pollfd pd; @@ -315,9 +251,9 @@ while ((bd.iface = capSettings.GetIface(i)) != "") { bpfData.push_back(bd); if (BPFCapOpen(&bpfData[i]) < 0) - { - return -1; - } + { + return -1; + } pd.events = POLLIN; pd.fd = bpfData[i].fd; @@ -328,7 +264,6 @@ while ((bd.iface = capSettings.GetIface(i)) != "") return 0; } //----------------------------------------------------------------------------- -//int BPF_CAP::BPFCapOpen(string ifaceToOpen) int BPF_CAP::BPFCapOpen(BPF_DATA * bd) { char devbpf[20]; @@ -337,15 +272,13 @@ int l = BUFF_LEN; int im = 1; struct ifreq ifr; -do { +do + { sprintf(devbpf, "/dev/bpf%d", i); i++; bd->fd = open(devbpf, O_RDONLY); - //cd[n].fd = open(devbpf, O_RDONLY); } while(bd->fd < 0 && errno == EBUSY); - //while(cd[n].fd < 0 && errno == EBUSY); -//if (cd[n].fd < 0) if (bd->fd < 0) { errorStr = "Can't capture packets. Open bpf device for " + bd->iface + " error."; @@ -353,10 +286,8 @@ if (bd->fd < 0) return -1; } -//strncpy(ifr.ifr_name, settings->iface[n], sizeof(ifr.ifr_name)); strncpy(ifr.ifr_name, bd->iface.c_str(), sizeof(ifr.ifr_name)); -//if (ioctl(cd[n].fd, BIOCSBLEN, (caddr_t)&l) < 0) if (ioctl(bd->fd, BIOCSBLEN, (caddr_t)&l) < 0) { errorStr = bd->iface + " BIOCSBLEN " + std::string(strerror(errno)); @@ -364,7 +295,6 @@ if (ioctl(bd->fd, BIOCSBLEN, (caddr_t)&l) < 0) return -1; } -//if (ioctl(cd[n].fd, BIOCSETIF, (caddr_t)&ifr) < 0 ) if (ioctl(bd->fd, BIOCSETIF, (caddr_t)&ifr) < 0) { errorStr = bd->iface + " BIOCSETIF " + std::string(strerror(errno)); @@ -372,7 +302,6 @@ if (ioctl(bd->fd, BIOCSETIF, (caddr_t)&ifr) < 0) return -1; } -//if (ioctl(cd[n].fd, BIOCIMMEDIATE, &im) < 0 ) if (ioctl(bd->fd, BIOCIMMEDIATE, &im) < 0) { errorStr = bd->iface + " BIOCIMMEDIATE " + std::string(strerror(errno)); @@ -381,13 +310,12 @@ if (ioctl(bd->fd, BIOCIMMEDIATE, &im) < 0) } return bd->fd; -//return 0; } //----------------------------------------------------------------------------- int BPF_CAP::BPFCapClose() { for (unsigned int i = 0; i < bpfData.size(); i++) - close(bpfData[i].fd); + close(bpfData[i].fd); return 0; } //----------------------------------------------------------------------------- @@ -426,8 +354,6 @@ if (bd->canRead) if(bd->r > bd->sum) { memcpy(buffer, (char*)(bd->p) + bd->bh->bh_hdrlen, blen); - //strncpy(iface, settings->iface[n], 9); - //*iface = settings->iface[n]; bd->sum += BPF_WORDALIGN(bd->bh->bh_hdrlen + bd->bh->bh_caplen); bd->p = bd->p + BPF_WORDALIGN(bd->bh->bh_hdrlen + bd->bh->bh_caplen); @@ -443,4 +369,3 @@ if(bd->r <= bd->sum) return 0; } //----------------------------------------------------------------------------- - diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h index 7097c280..aeb3be7f 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h @@ -32,22 +32,16 @@ #include #include -#ifdef FREE_BSD5 -#include -#endif - -#ifdef FREE_BSD -#include -#endif - +#include "os_int.h" #include "plugin.h" #include "module_settings.h" -#include "../../../traffcounter.h" extern "C" PLUGIN * GetPlugin(); #define BUFF_LEN (128) +class TRAFFCOUNTER; + //----------------------------------------------------------------------------- struct BPF_DATA { BPF_DATA() @@ -74,14 +68,14 @@ struct BPF_DATA { iface = bd.iface; }; -int fd; -uint8_t * p; -int r; -int sum; -uint8_t buffer[BUFF_LEN]; +int fd; +uint8_t * p; +int r; +int sum; +uint8_t buffer[BUFF_LEN]; struct bpf_hdr * bh; -int canRead; -std::string iface; +int canRead; +std::string iface; }; //----------------------------------------------------------------------------- class BPF_CAP_SETTINGS { @@ -104,22 +98,22 @@ public: void SetUsers(USERS *) {} void SetTariffs(TARIFFS *) {} void SetAdmins(ADMINS *) {} - void SetTraffcounter(TRAFFCOUNTER * tc); + void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; } void SetStore(STORE *) {} void SetStgSettings(const SETTINGS *) {} int Start(); int Stop(); int Reload() { return 0; } - bool IsRunning(); + bool IsRunning() { return isRunning; } - void SetSettings(const MODULE_SETTINGS & s); + void SetSettings(const MODULE_SETTINGS & s) { settings = s; } int ParseSettings(); - const std::string & GetStrError() const; + const std::string & GetStrError() const { return errorStr; } const std::string GetVersion() const; - uint16_t GetStartPosition() const; - uint16_t GetStopPosition() const; + uint16_t GetStartPosition() const { return 10; } + uint16_t GetStopPosition() const { return 10; } private: static void * Run(void *); diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp index ba9dce06..dfaf4754 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp @@ -47,12 +47,12 @@ $Date: 2009/12/13 13:45:13 $ #include "ether_cap.h" #include "common.h" #include "raw_ip_packet.h" +#include "traffcounter.h" //#define CAP_DEBUG 1 //----------------------------------------------------------------------------- -class ETHER_CAP_CREATOR -{ +class ETHER_CAP_CREATOR { private: ETHER_CAP * ec; @@ -60,16 +60,16 @@ public: ETHER_CAP_CREATOR() : ec(new ETHER_CAP()) { - }; + } ~ETHER_CAP_CREATOR() { delete ec; - }; + } ETHER_CAP * GetCapturer() { return ec; - }; + } }; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -98,16 +98,6 @@ ETHER_CAP::ETHER_CAP() { } //----------------------------------------------------------------------------- -void ETHER_CAP::SetTraffcounter(TRAFFCOUNTER * tc) -{ -traffCnt = tc; -} -//----------------------------------------------------------------------------- -const std::string & ETHER_CAP::GetStrError() const -{ -return errorStr; -} -//----------------------------------------------------------------------------- int ETHER_CAP::Start() { if (isRunning) @@ -170,11 +160,6 @@ EthCapClose(); return 0; } //----------------------------------------------------------------------------- -bool ETHER_CAP::IsRunning() -{ -return isRunning; -} -//----------------------------------------------------------------------------- void * ETHER_CAP::Run(void * d) { ETHER_CAP * dc = (ETHER_CAP *)d; @@ -216,16 +201,6 @@ dc->isRunning = false; return NULL; } //----------------------------------------------------------------------------- -uint16_t ETHER_CAP::GetStartPosition() const -{ -return 10; -} -//----------------------------------------------------------------------------- -uint16_t ETHER_CAP::GetStopPosition() const -{ -return 10; -} -//----------------------------------------------------------------------------- int ETHER_CAP::EthCapOpen() { capSock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h index 09888200..05f89c9a 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h @@ -32,7 +32,6 @@ #include "plugin.h" #include "module_settings.h" -#include "../../../traffcounter.h" class USERS; class TARIFFS; @@ -42,8 +41,10 @@ class SETTINGS; extern "C" PLUGIN * GetPlugin(); +class TRAFFCOUNTER; + //----------------------------------------------------------------------------- -class ETHER_CAP :public PLUGIN { +class ETHER_CAP : public PLUGIN { public: ETHER_CAP(); virtual ~ETHER_CAP() {} @@ -51,21 +52,21 @@ public: void SetUsers(USERS *) {} void SetTariffs(TARIFFS *) {} void SetAdmins(ADMINS *) {} - void SetTraffcounter(TRAFFCOUNTER * tc); + void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; } void SetStore(STORE *) {} void SetStgSettings(const SETTINGS *) {} int Start(); int Stop(); int Reload() { return 0; } - bool IsRunning(); + bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS &) {} int ParseSettings() { return 0; } - const std::string & GetStrError() const; + const std::string & GetStrError() const { return errorStr; } const std::string GetVersion() const; - uint16_t GetStartPosition() const; - uint16_t GetStopPosition() const; + uint16_t GetStartPosition() const { return 10; } + uint16_t GetStopPosition() const { return 10; } private: static void * Run(void *); diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp index fbf35894..e0beba9c 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp @@ -5,6 +5,7 @@ #include "ipq_cap.h" #include "raw_ip_packet.h" +#include "../../../traffcounter.h" extern "C" { @@ -19,16 +20,16 @@ public: IPQ_CAP_CREATOR() : ic(new IPQ_CAP()) { - }; + } ~IPQ_CAP_CREATOR() { delete ic; - }; + } IPQ_CAP * GetCapturer() { return ic; - }; + } }; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -59,16 +60,6 @@ IPQ_CAP::IPQ_CAP() memset(buf, 0, BUFSIZE); } //----------------------------------------------------------------------------- -void IPQ_CAP::SetTraffcounter(TRAFFCOUNTER * tc) -{ -traffCnt = tc; -} -//----------------------------------------------------------------------------- -const std::string & IPQ_CAP::GetStrError() const -{ -return errorStr; -} -//----------------------------------------------------------------------------- int IPQ_CAP::Start() { if (isRunning) @@ -126,15 +117,9 @@ IPQCapClose(); return 0; } //----------------------------------------------------------------------------- -bool IPQ_CAP::IsRunning() -{ -return isRunning; -} -//----------------------------------------------------------------------------- void * IPQ_CAP::Run(void * d) { RAW_PACKET raw_packet; -int status; IPQ_CAP * dc = (IPQ_CAP *)d; dc->isRunning = true; @@ -142,7 +127,7 @@ memset(&raw_packet, 0, sizeof(raw_packet)); raw_packet.dataLen = -1; while (dc->nonstop) { - status = dc->IPQCapRead(&raw_packet, 68); + int status = dc->IPQCapRead(&raw_packet, 68); if (status == -1 || status == -2 || status == -3 || @@ -154,20 +139,8 @@ dc->isRunning = false; return NULL; } //----------------------------------------------------------------------------- -uint16_t IPQ_CAP::GetStartPosition() const -{ -return 0; -} -//----------------------------------------------------------------------------- -uint16_t IPQ_CAP::GetStopPosition() const -{ -return 0; -} -//----------------------------------------------------------------------------- int IPQ_CAP::IPQCapOpen() { -int status; - ipq_h = ipq_create_handle(0, PF_INET); if (ipq_h == NULL) { @@ -175,7 +148,7 @@ if (ipq_h == NULL) errorStr = "Cannot create ipq handle!"; return -1; } -status = ipq_set_mode(ipq_h, IPQ_COPY_PACKET, PAYLOAD_LEN); +int status = ipq_set_mode(ipq_h, IPQ_COPY_PACKET, PAYLOAD_LEN); if (status < 0) { ipq_destroy_handle(ipq_h); @@ -193,11 +166,8 @@ return 0; //----------------------------------------------------------------------------- int IPQ_CAP::IPQCapRead(void * buffer, int blen) { -int status; -static ipq_packet_msg_t *m; - memset(buf, 0, BUFSIZE); -status = ipq_read(ipq_h, buf, BUFSIZE, 1); +int status = ipq_read(ipq_h, buf, BUFSIZE, 1); if (status == 0) return -4; if (errno == EINTR) @@ -206,7 +176,7 @@ if (status < 0) return -1; if (ipq_message_type(buf) != IPQM_PACKET) return -2; -m = ipq_get_packet(buf); +static ipq_packet_msg_t * m = ipq_get_packet(buf); memcpy(buffer, m->payload, blen); ipq_set_verdict(ipq_h, m->packet_id, NF_ACCEPT, 0, NULL); return 0; diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h index 9c16f4fb..61f44332 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h @@ -5,7 +5,7 @@ #include "plugin.h" #include "module_settings.h" -#include "../../../traffcounter.h" +#include "os_int.h" #define BUFSIZE (256) #define PAYLOAD_LEN (96) @@ -27,21 +27,21 @@ public: void SetUsers(USERS *) {} void SetTariffs(TARIFFS *) {} void SetAdmins(ADMINS *) {} - void SetTraffcounter(TRAFFCOUNTER * tc); + void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; } void SetStore(STORE *) {} void SetStgSettings(const SETTINGS *) {} int Start(); int Stop(); int Reload() { return 0; } - bool IsRunning(); + bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS &) {} int ParseSettings() { return 0; } - const std::string & GetStrError() const; + const std::string & GetStrError() const { return errorStr; } const std::string GetVersion() const; - uint16_t GetStartPosition() const; - uint16_t GetStopPosition() const; + uint16_t GetStartPosition() const { return 10; } + uint16_t GetStopPosition() const { return 10; } private: static void * Run(void *); -- 2.44.2 From b1d5e2ed9bea8cc71569052f80a1aa98e133c397 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:04:17 +0300 Subject: [PATCH 03/16] Fix traffcounter include path for ipq cap plugin --- projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp index e0beba9c..f9666192 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp @@ -5,7 +5,7 @@ #include "ipq_cap.h" #include "raw_ip_packet.h" -#include "../../../traffcounter.h" +#include "traffcounter.h" extern "C" { -- 2.44.2 From 1825b28b15bba685a406e45f06b2ff7c9147466a Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:04:45 +0300 Subject: [PATCH 04/16] Create TRAFFCOUNTER_IMPL in main.cpp --- projects/stargazer/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 2c789ff6..26176bfc 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -50,7 +50,7 @@ #include "admins_impl.h" #include "tariffs_impl.h" #include "common.h" -#include "traffcounter.h" +#include "traffcounter_impl.h" #include "plugin.h" #include "stg_logger.h" #include "stg_timer.h" @@ -448,7 +448,7 @@ STORE * dataStore = NULL; TARIFFS_IMPL * tariffs = NULL; ADMINS_IMPL * admins = NULL; USERS_IMPL * users = NULL; -TRAFFCOUNTER * traffCnt = NULL; +TRAFFCOUNTER_IMPL * traffCnt = NULL; int msgID = -11; { @@ -545,7 +545,7 @@ WriteServLog("Storage plugin: %s. Loading successfull.", dataStore->GetVersion() tariffs = new TARIFFS_IMPL(dataStore); admins = new ADMINS_IMPL(dataStore); users = new USERS_IMPL(settings, dataStore, tariffs, admins->GetSysAdmin()); -traffCnt = new TRAFFCOUNTER(users, tariffs, settings->GetRulesFileName()); +traffCnt = new TRAFFCOUNTER_IMPL(users, tariffs, settings->GetRulesFileName()); traffCnt->SetMonitorDir(settings->GetMonitorDir()); modSettings = settings->GetModulesSettings(); -- 2.44.2 From bccb08f374dba862369712669c4ca73ccbfb2170 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:08:02 +0300 Subject: [PATCH 05/16] Fix compilation errors --- projects/stargazer/traffcounter_impl.cpp | 2 +- projects/stargazer/traffcounter_impl.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/stargazer/traffcounter_impl.cpp b/projects/stargazer/traffcounter_impl.cpp index f410b109..83554e27 100644 --- a/projects/stargazer/traffcounter_impl.cpp +++ b/projects/stargazer/traffcounter_impl.cpp @@ -938,7 +938,7 @@ return; //----------------------------------------------------------------------------- void TRAFFCOUNTER_IMPL::SetMonitorDir(const std::string & monitorDir) { -TRAFFCOUNTER::monitorDir = monitorDir; +TRAFFCOUNTER_IMPL::monitorDir = monitorDir; monitoring = (monitorDir != ""); } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/traffcounter_impl.h b/projects/stargazer/traffcounter_impl.h index eb476239..feeb7a3d 100644 --- a/projects/stargazer/traffcounter_impl.h +++ b/projects/stargazer/traffcounter_impl.h @@ -154,7 +154,7 @@ private: TRAFFCOUNTER_IMPL & traffCnt; }; //----------------------------------------------------------------------------- -class TRAFFCOUNTER : public TRAFFCOUNTER, private NONCOPYABLE { +class TRAFFCOUNTER_IMPL : public TRAFFCOUNTER, private NONCOPYABLE { friend class ADD_USER_NONIFIER; friend class DEL_USER_NONIFIER; friend class TRF_IP_BEFORE; @@ -232,7 +232,7 @@ void TRF_IP_BEFORE::Notify(const uint32_t & oldValue, const uint32_t &) if (!oldValue) return; -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::DelUser, oldValue); +EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::DelUser, oldValue); } //----------------------------------------------------------------------------- inline @@ -242,20 +242,20 @@ void TRF_IP_AFTER::Notify(const uint32_t &, const uint32_t & newValue) if (!newValue) return; -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::AddUser, user); +EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::AddUser, user); } //----------------------------------------------------------------------------- inline void ADD_USER_NONIFIER::Notify(const USER_PTR & user) { -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::SetUserNotifiers, user); +EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::SetUserNotifiers, user); } //----------------------------------------------------------------------------- inline void DEL_USER_NONIFIER::Notify(const USER_PTR & user) { -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::UnSetUserNotifiers, user); -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::DelUser, user->GetCurrIP()); +EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::UnSetUserNotifiers, user); +EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::DelUser, user->GetCurrIP()); } //----------------------------------------------------------------------------- #endif //TRAFFCOUNTER_H -- 2.44.2 From 1e1cf97f68d0c6aec24c640ca270b902fb75c923 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:17:03 +0300 Subject: [PATCH 06/16] Include header for select in inetaccess.cpp --- .../stargazer/plugins/authorization/inetaccess/inetaccess.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 7062966f..23b1a1c9 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include -- 2.44.2 From e030545ed5dfe91a01df42a599de56cd24a19455 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:23:02 +0300 Subject: [PATCH 07/16] Include unistd.h for close and usleep --- .../stargazer/plugins/authorization/inetaccess/inetaccess.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 23b1a1c9..6f200567 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -31,6 +31,7 @@ #include #include #include +#include // usleep, close #include #include -- 2.44.2 From 7efaa3ceb1b98d428a3b56e5d377e9330d49aa30 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:23:32 +0300 Subject: [PATCH 08/16] Make DEL_USER_NOTIFIER a friend class for AUTH_IA --- projects/stargazer/plugins/authorization/inetaccess/inetaccess.h | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index 453ce382..7bc704db 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -186,6 +186,7 @@ private: }; //----------------------------------------------------------------------------- class AUTH_IA :public AUTH { +friend class DEL_USER_NONIFIER; public: AUTH_IA(); virtual ~AUTH_IA(); -- 2.44.2 From cb15e9caaef278f6191220ffa4e7f4302b09033f Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:25:08 +0300 Subject: [PATCH 09/16] DEL_USER_NONIFIER -> DEL_USER_NOTIFIER --- .../plugins/authorization/inetaccess/inetaccess.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index 7bc704db..68c9e87a 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -186,7 +186,7 @@ private: }; //----------------------------------------------------------------------------- class AUTH_IA :public AUTH { -friend class DEL_USER_NONIFIER; +friend class DEL_USER_NOTIFIER; public: AUTH_IA(); virtual ~AUTH_IA(); @@ -316,10 +316,10 @@ private: uint32_t enabledDirs; - class DEL_USER_NONIFIER: public NOTIFIER_BASE { + class DEL_USER_NOTIFIER: public NOTIFIER_BASE { public: - DEL_USER_NONIFIER(AUTH_IA & a) : auth(a) {} - virtual ~DEL_USER_NONIFIER() {} + DEL_USER_NOTIFIER(AUTH_IA & a) : auth(a) {} + virtual ~DEL_USER_NOTIFIER() {} void Notify(const USER_PTR & user) { -- 2.44.2 From a1049689fc6ed5d9c232278176fcddf2db3000da Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:32:13 +0300 Subject: [PATCH 10/16] Exclude DEL_USER_NOTIFIER from AUTH_IA (possible freandship fix) --- .../authorization/inetaccess/inetaccess.h | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index 68c9e87a..e28aad8f 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -185,6 +185,18 @@ private: FREEMB freeMbShowType; }; //----------------------------------------------------------------------------- +class AUTH_IA; +//----------------------------------------------------------------------------- +class DEL_USER_NOTIFIER: public NOTIFIER_BASE { +public: + DEL_USER_NOTIFIER(AUTH_IA & a) : auth(a) {} + virtual ~DEL_USER_NOTIFIER() {} + + void Notify(const USER_PTR & user); +private: + AUTH_IA & auth; +}; +//----------------------------------------------------------------------------- class AUTH_IA :public AUTH { friend class DEL_USER_NOTIFIER; public: @@ -316,19 +328,7 @@ private: uint32_t enabledDirs; - class DEL_USER_NOTIFIER: public NOTIFIER_BASE { - public: - DEL_USER_NOTIFIER(AUTH_IA & a) : auth(a) {} - virtual ~DEL_USER_NOTIFIER() {} - - void Notify(const USER_PTR & user) - { - auth.DelUser(user); - } - - private: - AUTH_IA & auth; - } onDelUserNotifier; + DEL_USER_NOTIFIER onDelUserNotifier; class UnauthorizeUser : std::unary_function &, void> { public: @@ -343,5 +343,10 @@ private: }; //----------------------------------------------------------------------------- +inline +void DEL_USER_NOTIFIER::Notify(const USER_PTR & user) +{ + auth.DelUser(user); +} #endif -- 2.44.2 From 3fc5aa9ace37067af19ee3c1a1a0da2473cd9455 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:53:24 +0300 Subject: [PATCH 11/16] Add unistd.h to rsconf.cpp --- projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp index 028ef808..98128832 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp @@ -26,6 +26,8 @@ * *******************************************************************/ +#include // cloase, usleep + #include #include #include // snprintf -- 2.44.2 From 97ca31c43dab24a57115904fb6688bcc060e052b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:55:09 +0300 Subject: [PATCH 12/16] Include unsitd.h in user_property.h for access function --- include/user_property.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/user_property.h b/include/user_property.h index 402f69fb..3075d8f9 100644 --- a/include/user_property.h +++ b/include/user_property.h @@ -7,6 +7,8 @@ $Author: faust $ #ifndef USER_PROPERTY_H #define USER_PROPERTY_H +#include // access + #include #include #include -- 2.44.2 From 65a386030a3bbe5edf34da97ce9e5cfa1ee063c7 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 16:58:59 +0300 Subject: [PATCH 13/16] Include algorithm in divert_cap.cpp for find --- .../plugins/capture/divert_freebsd/divert_cap.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 5c7ec364..5d49f692 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -22,23 +22,26 @@ $Revision: 1.13 $ $Date: 2010/09/10 06:43:03 $ */ -#include #include #include #include -#include #include #include #include #include -#include #include -#include -#include #include +#include +#include +#include +#include +#include + +#include + #include "common.h" #include "divert_cap.h" #include "traffcounter.h" @@ -277,7 +280,7 @@ PARAM_VALUE pv; vector::const_iterator pvi; pv.param = "Port"; -pvi = find(settings.moduleParams.begin(), settings.moduleParams.end(), pv); +pvi = std::find(settings.moduleParams.begin(), settings.moduleParams.end(), pv); if (pvi == settings.moduleParams.end()) { port = 15701; -- 2.44.2 From de0e6ac625e420f564ccd509d84daec2c632d164 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 17:04:46 +0300 Subject: [PATCH 14/16] Include cstdio in main.cpp for printf --- projects/stargazer/main.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 26176bfc..203c6c4e 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -24,21 +24,15 @@ $Author: faust $ */ -/*#include -#include -#include -#include */ #include #include #include #include #include -/*#include -#include -#include */ #include #include +#include #include #include #include -- 2.44.2 From 13c0311334b625cb0e7f77c26615a0efe5231eaa Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 17:05:08 +0300 Subject: [PATCH 15/16] Add sys/types.h for FreeBSD --- projects/stargazer/traffcounter_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/stargazer/traffcounter_impl.cpp b/projects/stargazer/traffcounter_impl.cpp index 83554e27..e056a7a6 100644 --- a/projects/stargazer/traffcounter_impl.cpp +++ b/projects/stargazer/traffcounter_impl.cpp @@ -29,6 +29,7 @@ */ /* inet_aton */ +#include #include #include #include -- 2.44.2 From 675f54bb620f9457bf45450308e0ee0659c8e46a Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 17:23:05 +0300 Subject: [PATCH 16/16] Add vector definition to divert_cap.cpp --- .../stargazer/plugins/capture/divert_freebsd/divert_cap.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 5d49f692..ca308593 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -41,6 +41,7 @@ $Date: 2010/09/10 06:43:03 $ #include #include +#include #include "common.h" #include "divert_cap.h" @@ -277,7 +278,7 @@ int DIVERT_CAP::ParseSettings() { int p; PARAM_VALUE pv; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pv.param = "Port"; pvi = std::find(settings.moduleParams.begin(), settings.moduleParams.end(), pv); -- 2.44.2