]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h
Rename BASE_AUTH and BASE_STORE to AUTH and STORE
[stg.git] / projects / stargazer / plugins / capture / ether_freebsd / ether_cap.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17  /*
18  $Revision: 1.11 $
19  $Date: 2009/06/23 11:32:27 $
20  $Author: faust $
21  */
22
23 /*
24 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
25 */
26
27 #ifndef ETHER_CAP_H
28 #define ETHER_CAP_H
29
30 #include <pthread.h>
31
32 #include <string>
33 #include <vector>
34
35 #ifdef FREE_BSD5
36 #include <inttypes.h>
37 #endif
38
39 #ifdef FREE_BSD
40 #include <sys/inttypes.h>
41 #endif
42
43 #include "plugin.h"
44 #include "module_settings.h"
45 #include "../../../traffcounter.h"
46
47 extern "C" PLUGIN * GetPlugin();
48
49 #define BUFF_LEN (128)
50
51 //-----------------------------------------------------------------------------
52 struct BPF_DATA {
53     BPF_DATA()
54         {
55         fd = 0;
56         p = NULL;
57         r = 0;
58         sum = 0;
59         memset(buffer, 0, BUFF_LEN);
60         bh = NULL;
61         canRead = 1;
62         iface = "";
63         };
64
65     BPF_DATA(const BPF_DATA & bd)
66         {
67         fd = bd.fd;
68         p = bd.p;
69         r = bd.r;
70         sum = bd.sum;
71         memcpy(buffer, bd.buffer, BUFF_LEN);
72         bh = bd.bh;
73         canRead = bd.canRead;
74         iface = bd.iface;
75         };
76
77 int             fd;
78 uint8_t *       p;
79 int             r;
80 int             sum;
81 uint8_t         buffer[BUFF_LEN];
82 struct bpf_hdr * bh;
83 int             canRead;
84 std::string     iface;
85 };
86 //-----------------------------------------------------------------------------
87 class BPF_CAP_SETTINGS {
88 public:
89     virtual         ~BPF_CAP_SETTINGS() {}
90     const std::string & GetStrError() const { return errorStr; }
91     int             ParseSettings(const MODULE_SETTINGS & s);
92     std::string     GetIface(unsigned int num);
93
94 private:
95     std::vector<std::string> iface;
96     mutable std::string errorStr;
97 };
98 //-----------------------------------------------------------------------------
99 class BPF_CAP : public PLUGIN {
100 public:
101                         BPF_CAP();
102     virtual             ~BPF_CAP() {}
103
104     void                SetUsers(USERS *) {}
105     void                SetTariffs(TARIFFS *) {}
106     void                SetAdmins(ADMINS *) {}
107     void                SetTraffcounter(TRAFFCOUNTER * tc);
108     void                SetStore(STORE *) {}
109     void                SetStgSettings(const SETTINGS *) {}
110
111     int                 Start();
112     int                 Stop();
113     int                 Reload() { return 0; }
114     bool                IsRunning();
115
116     void                SetSettings(const MODULE_SETTINGS & s);
117     int                 ParseSettings();
118
119     const std::string & GetStrError() const;
120     const std::string   GetVersion() const;
121     uint16_t            GetStartPosition() const;
122     uint16_t            GetStopPosition() const;
123
124 private:
125     static void *       Run(void *);
126     int                 BPFCapOpen();
127     int                 BPFCapOpen(BPF_DATA * bd);
128     int                 BPFCapClose();
129     int                 BPFCapRead(char * buffer, int blen, char ** iface);
130     int                 BPFCapRead(char * buffer, int blen, char ** iface, BPF_DATA * bd);
131
132     BPF_CAP_SETTINGS      capSettings;
133
134     mutable std::string   errorStr;
135
136     std::vector<BPF_DATA> bpfData;
137     std::vector<pollfd>   polld;
138
139     pthread_t             thread;
140     bool                  nonstop;
141     bool                  isRunning;
142     int                   capSock;
143     MODULE_SETTINGS       settings;
144
145     TRAFFCOUNTER *        traffCnt;
146 };
147 //-----------------------------------------------------------------------------
148
149 #endif