]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/capture/cap_nf/cap_nf.h
Добавление исходников
[stg.git] / projects / stargazer / plugins / capture / cap_nf / cap_nf.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 Date: 16.05.2008
19 */
20
21 /*
22 * Author : Maxim Mamontov <faust@stg.dp.ua>
23 */
24
25 /*
26 $Revision: 1.5 $
27 $Date: 2009/12/13 12:56:07 $
28 $Author: faust $
29 */
30 #ifndef __CAP_NF_H__
31 #define __CAP_NF_H__
32
33 #include <string>
34 #include <pthread.h>
35
36 #include "os_int.h"
37 #include "base_plugin.h"
38
39 #define VERSION "CAP_NF v. 0.4"
40 #define START_POS 0
41 #define STOP_POS 0
42
43 struct NF_HEADER
44 {
45     uint16_t version;   // Protocol version
46     uint16_t count;     // Flows count
47     uint32_t uptime;    // System uptime
48     uint32_t timestamp; // UNIX timestamp
49     uint32_t nsecs;     // Residual nanoseconds
50     uint32_t flowSeq;   // Sequence counter
51     uint8_t  eType;     // Engine type
52     uint8_t  eID;       // Engine ID
53     uint16_t sInterval; // Sampling mode and interval
54 } __attribute__ ((packed));
55
56 struct NF_DATA
57 {
58     uint32_t srcAddr;   // Flow source address
59     uint32_t dstAddr;   // Flow destination address
60     uint32_t nextHop;   // IP addres on next hop router
61     uint16_t inSNMP;    // SNMP index of input iface
62     uint16_t outSNMP;   // SNMP index of output iface
63     uint32_t packets;   // Packets in flow
64     uint32_t octets;    // Total number of bytes in flow
65     uint32_t timeStart; // Uptime on first packet in flow
66     uint32_t timeFinish;// Uptime on last packet in flow
67     uint16_t srcPort;   // Flow source port
68     uint16_t dstPort;   // Flow destination port
69     uint8_t  pad1;      // 1-byte padding
70     uint8_t  TCPFlags;  // Cumulative OR of TCP flags
71     uint8_t  proto;     // IP protocol type (tcp, udp, etc.)
72     uint8_t  tos;       // IP Type of Service (ToS)
73     uint16_t srcAS;     // Source BGP autonomous system number
74     uint16_t dstAS;     // Destination BGP autonomus system number
75     uint8_t  srcMask;   // Source address mask in "slash" notation
76     uint8_t  dstMask;   // Destination address mask in "slash" notation
77     uint16_t pad2;      // 2-byte padding
78 } __attribute__ ((packed));
79
80 #define BUF_SIZE (sizeof(NF_HEADER) + 30 * sizeof(NF_DATA))
81
82 class NF_CAP : public BASE_PLUGIN 
83 {
84 public:
85     NF_CAP();
86     ~NF_CAP();
87
88     void            SetUsers(USERS *) {};
89     void            SetTariffs(TARIFFS *) {};
90     void            SetAdmins(ADMINS *) {};
91     void            SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; };
92     void            SetStore(BASE_STORE *) {};
93     void            SetStgSettings(const SETTINGS *) {};
94     void            SetSettings(const MODULE_SETTINGS & s) { settings = s; };
95     int             ParseSettings();
96
97     int             Start();
98     int             Stop();
99     int             Reload() { return 0; };
100     bool            IsRunning() { return runningTCP || runningUDP; };
101     const string  & GetStrError() const { return errorStr; };
102     const string    GetVersion() const { return VERSION; };
103     uint16_t        GetStartPosition() const { return START_POS; };
104     uint16_t        GetStopPosition() const { return STOP_POS; };
105
106 private:
107     TRAFFCOUNTER * traffCnt;
108     MODULE_SETTINGS settings;
109     pthread_t tidTCP;
110     pthread_t tidUDP;
111     bool runningTCP;
112     bool runningUDP;
113     bool stoppedTCP;
114     bool stoppedUDP;
115     uint16_t portT;
116     uint16_t portU;
117     int sockTCP;
118     int sockUDP;
119     mutable std::string errorStr;
120
121     static void * RunUDP(void *);
122     static void * RunTCP(void *);
123     void ParseBuffer(uint8_t *, int);
124
125     bool OpenTCP();
126     bool OpenUDP();
127     void CloseTCP() { close(sockTCP); };
128     void CloseUDP() { close(sockUDP); };
129
130     bool WaitPackets(int sd) const;
131 };
132
133 extern "C" BASE_PLUGIN * GetPlugin();
134
135 #endif