#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;
continue;
}
-
- // Wrong logic!
- // Need to check actual data length and wait all data to receive
if (res < 24)
{
if (errno != EINTR)
{
NF_DATA * data = reinterpret_cast<NF_DATA *>(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;
#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;
#include "common.h"
#include "divert_cap.h"
+#include "traffcounter.h"
#define BUFF_LEN (16384) /* max mtu -> lo=16436 TODO why?*/
DIVERT_CAP_CREATOR()
: divc(new DIVERT_CAP())
{
- };
+ }
~DIVERT_CAP_CREATOR()
{
delete divc;
- };
+ }
DIVERT_CAP * GetCapturer()
{
return divc;
- };
+ }
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
{
}
//-----------------------------------------------------------------------------
-void DIVERT_CAP::SetTraffcounter(TRAFFCOUNTER * tc)
-{
-traffCnt = tc;
-}
-//-----------------------------------------------------------------------------
-const std::string & DIVERT_CAP::GetStrError() const
-{
-return errorStr;
-}
-//-----------------------------------------------------------------------------
int DIVERT_CAP::Start()
{
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);
}
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));
return 0;
}
//-----------------------------------------------------------------------------
-void DIVERT_CAP::SetSettings(const MODULE_SETTINGS & s)
-{
-settings = s;
-}
-//-----------------------------------------------------------------------------
-
#include "plugin.h"
#include "module_settings.h"
-#include "../../../traffcounter.h"
class USERS;
class TARIFFS;
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 *);
#include "ether_cap.h"
#include "common.h"
#include "raw_ip_packet.h"
+#include "traffcounter.h"
//#define CAP_DEBUG 1
//-----------------------------------------------------------------------------
BPF_CAP_CREATOR()
: bpfc(new BPF_CAP())
{
- };
+ }
~BPF_CAP_CREATOR()
{
delete bpfc;
- };
+ }
BPF_CAP * GetCapturer()
{
return bpfc;
- };
+ }
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
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<PARAM_VALUE>::const_iterator pvi;
-
if (s.moduleParams.empty())
{
errorStr = "Parameter \'iface\' not found.";
}
}
-/*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;
}
//-----------------------------------------------------------------------------
{
}
//-----------------------------------------------------------------------------
-void BPF_CAP::SetSettings(const MODULE_SETTINGS & s)
-{
-settings = s;
-}
-//-----------------------------------------------------------------------------
int BPF_CAP::ParseSettings()
{
int ret = capSettings.ParseSettings(settings);
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)
return 0;
}
//-----------------------------------------------------------------------------
-bool BPF_CAP::IsRunning()
-{
-return isRunning;
-}
-//-----------------------------------------------------------------------------
void * BPF_CAP::Run(void * d)
{
BPF_CAP * dc = (BPF_CAP *)d;
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;
{
bpfData.push_back(bd);
if (BPFCapOpen(&bpfData[i]) < 0)
- {
- return -1;
- }
+ {
+ return -1;
+ }
pd.events = POLLIN;
pd.fd = bpfData[i].fd;
return 0;
}
//-----------------------------------------------------------------------------
-//int BPF_CAP::BPFCapOpen(string ifaceToOpen)
int BPF_CAP::BPFCapOpen(BPF_DATA * bd)
{
char devbpf[20];
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.";
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));
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));
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));
}
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;
}
//-----------------------------------------------------------------------------
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);
return 0;
}
//-----------------------------------------------------------------------------
-
#include <string>
#include <vector>
-#ifdef FREE_BSD5
-#include <inttypes.h>
-#endif
-
-#ifdef FREE_BSD
-#include <sys/inttypes.h>
-#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()
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 {
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 *);
#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;
ETHER_CAP_CREATOR()
: ec(new ETHER_CAP())
{
- };
+ }
~ETHER_CAP_CREATOR()
{
delete ec;
- };
+ }
ETHER_CAP * GetCapturer()
{
return ec;
- };
+ }
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
{
}
//-----------------------------------------------------------------------------
-void ETHER_CAP::SetTraffcounter(TRAFFCOUNTER * tc)
-{
-traffCnt = tc;
-}
-//-----------------------------------------------------------------------------
-const std::string & ETHER_CAP::GetStrError() const
-{
-return errorStr;
-}
-//-----------------------------------------------------------------------------
int ETHER_CAP::Start()
{
if (isRunning)
return 0;
}
//-----------------------------------------------------------------------------
-bool ETHER_CAP::IsRunning()
-{
-return isRunning;
-}
-//-----------------------------------------------------------------------------
void * ETHER_CAP::Run(void * d)
{
ETHER_CAP * dc = (ETHER_CAP *)d;
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));
#include "plugin.h"
#include "module_settings.h"
-#include "../../../traffcounter.h"
class USERS;
class TARIFFS;
extern "C" PLUGIN * GetPlugin();
+class TRAFFCOUNTER;
+
//-----------------------------------------------------------------------------
-class ETHER_CAP :public PLUGIN {
+class ETHER_CAP : public PLUGIN {
public:
ETHER_CAP();
virtual ~ETHER_CAP() {}
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 *);
#include "ipq_cap.h"
#include "raw_ip_packet.h"
+#include "../../../traffcounter.h"
extern "C"
{
IPQ_CAP_CREATOR()
: ic(new IPQ_CAP())
{
- };
+ }
~IPQ_CAP_CREATOR()
{
delete ic;
- };
+ }
IPQ_CAP * GetCapturer()
{
return ic;
- };
+ }
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
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)
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;
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 ||
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)
{
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);
//-----------------------------------------------------------------------------
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)
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;
#include "plugin.h"
#include "module_settings.h"
-#include "../../../traffcounter.h"
+#include "os_int.h"
#define BUFSIZE (256)
#define PAYLOAD_LEN (96)
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 *);