From 9faa3c51da5965b95d165ade36120a74a69521f4 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 4 Apr 2011 15:58:36 +0300 Subject: [PATCH 1/1] 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