ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/util.h
(Generate patch)

Comparing gvpe/src/util.h (file contents):
Revision 1.2 by pcg, Mon Mar 17 15:20:18 2003 UTC vs.
Revision 1.3 by pcg, Fri Mar 21 23:17:01 2003 UTC

25#include <sys/socket.h> 25#include <sys/socket.h>
26#include <netinet/in.h> 26#include <netinet/in.h>
27 27
28#include <map> 28#include <map>
29 29
30#include "iom.h"
30#include "device.h" 31#include "device.h"
31 32
32#define SOCKADDR sockaddr_in // this is lame, I know 33#define SOCKADDR sockaddr_in // this is lame, I know
33 34
34/* 35/*
68 p[4] = id >> 8; 69 p[4] = id >> 8;
69 p[5] = id; 70 p[5] = id;
70} 71}
71 72
72#define mac2id(p) (p[0] & 0x01 ? 0 : (p[4] << 8) | p[5]) 73#define mac2id(p) (p[0] & 0x01 ? 0 : (p[4] << 8) | p[5])
73
74// a very simple fifo pkt-queue
75class pkt_queue
76 {
77 tap_packet *queue[QUEUEDEPTH];
78 int i, j;
79
80 public:
81
82 void put (tap_packet *p);
83 tap_packet *get ();
84
85 pkt_queue ();
86 ~pkt_queue ();
87 };
88 74
89struct sockinfo 75struct sockinfo
90 { 76 {
91 u32 host; 77 u32 host;
92 u16 port; 78 u16 port;
137{ 123{
138 return a.host < b.host 124 return a.host < b.host
139 || (a.host == b.host && a.port < b.port); 125 || (a.host == b.host && a.port < b.port);
140} 126}
141 127
142// only do action once every x seconds per host.
143// currently this is quite a slow implementation,
144// but suffices for normal operation.
145struct u32_rate_limiter : private map<u32, time_t>
146 {
147 int every;
148
149 bool can (u32 host);
150
151 u32_rate_limiter (time_t every = 1)
152 {
153 this->every = every;
154 }
155 };
156
157struct net_rate_limiter : u32_rate_limiter
158 {
159 bool can (SOCKADDR *sa) { return u32_rate_limiter::can((u32)sa->sin_addr.s_addr); }
160 bool can (sockinfo &si) { return u32_rate_limiter::can((u32)si.host); }
161
162 net_rate_limiter (time_t every) : u32_rate_limiter (every) {}
163 };
164
165struct sliding_window { 128struct sliding_window {
166 u32 v[(WINDOWSIZE + 31) / 32]; 129 u32 v[(WINDOWSIZE + 31) / 32];
167 u32 seq; 130 u32 seq;
168 131
169 void reset (u32 seqno) 132 void reset (u32 seqno)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines