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.
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.
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
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 $Date: 2009/04/10 14:14:49 $
28 #ifndef __TC_PACKETS_H__
29 #define __TC_PACKETS_H__
31 #include <netinet/ip.h>
39 #error "You need either stdint.h or inttypes.h to compile this!"
46 //-----------------------------------------------------------------------------
49 * A session is an amount of bytes transfered in one direction between two
50 * fixed addresses by one protocol.
51 * In case of UDP/TCP session is also identified by ports.
64 SESSION_ID(const iphdr & ipHdr, uint16_t sp, uint16_t dp)
79 bool operator ==(const SESSION_ID & rval)
81 return saddr == rval.saddr &&
82 sport == rval.sport &&
83 daddr == rval.daddr &&
84 dport == rval.dport &&
88 //-----------------------------------------------------------------------------
90 * Ordering functor to use SESSION_ID as key-type in maps
93 : public std::binary_function<SESSION_ID, SESSION_ID, bool> {
94 bool operator()(const SESSION_ID & lval, const SESSION_ID & rval) const
96 if (lval.saddr > rval.saddr)
98 if (lval.saddr < rval.saddr)
100 if (lval.daddr > rval.daddr)
102 if (lval.daddr < rval.daddr)
104 if (lval.sport > rval.sport)
106 if (lval.sport < rval.sport)
108 if (lval.dport > rval.dport)
110 if (lval.dport < rval.dport)
112 if (lval.proto > rval.proto)
114 if (lval.proto < rval.proto)
119 //-----------------------------------------------------------------------------
121 * A packet in the incoming queue
122 * Can create a new session or be attached to an existing one
124 struct PENDING_PACKET : public SESSION_ID
129 PENDING_PACKET(const iphdr & ipHdr, uint16_t sp, uint16_t dp)
130 : SESSION_ID(ipHdr, sp, dp),
131 length(ipHdr.tot_len),
139 INCOMING = 0, // From outer world to user
140 OUTGOING, // From user to outer world
141 LOCAL, // From user to user
142 FOREIGN // From outer world to outer world
145 //-----------------------------------------------------------------------------
147 * Session length and meta-information
148 * Used to identify data cost
154 dir = -1; // NULL direction
158 SESSION_DATA(const SESSION_DATA & sp)
167 //-----------------------------------------------------------------------------
171 typedef std::pair<SESSION_ID, SESSION_DATA> TRAFF_ITEM;
172 typedef std::list<TRAFF_ITEM> TRAFF_DATA;