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.13 by pcg, Thu Mar 3 16:54:34 2005 UTC vs.
Revision 1.22 by pcg, Sun Dec 2 00:09:36 2007 UTC

16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18 18
19 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
20 along with gvpe; if not, write to the Free Software 20 along with gvpe; if not, write to the Free Software
21 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22*/ 22*/
23 23
24#ifndef UTIL_H__ 24#ifndef UTIL_H__
25#define UTIL_H__ 25#define UTIL_H__
26 26
27#include <openssl/rsa.h> 27#include <openssl/rsa.h>
28 28
29#include "gettext.h" 29#include "gettext.h"
30 30
31#include "slog.h" 31#include "slog.h"
32#include "iom.h" 32#include "ev_cpp.h"
33#include "callback.h"
34
35typedef ev_tstamp tstamp;
33 36
34/* 37/*
35 * check for an existing vped for this net, and write pid to pidfile 38 * check for an existing gvpe for this net, and write pid to pidfile
36 */ 39 */
37extern int write_pidfile (void); 40extern int write_pidfile (void);
38 41
39/* 42/*
40 * kill older vped 43 * kill older gvpe
41 */ 44 */
42extern int kill_other (int signal); 45extern int kill_other (int signal);
43 46
44/* 47/*
45 * Detach from current terminal, write pidfile, kill parent 48 * Detach from current terminal, write pidfile, kill parent
57 60
58extern void id2mac (unsigned int id, void *m); 61extern void id2mac (unsigned int id, void *m);
59 62
60#define mac2id(p) ((p)[0] & 0x01 ? 0 : ((p)[4] << 8) | (p)[5]) 63#define mac2id(p) ((p)[0] & 0x01 ? 0 : ((p)[4] << 8) | (p)[5])
61 64
62struct sliding_window { 65struct sliding_window
66{
63 u32 v[(WINDOWSIZE + 31) / 32]; 67 u32 v[(WINDOWSIZE + 31) / 32];
64 u32 seq; 68 u32 seq;
65 69
66 void reset (u32 seqno) 70 void reset (u32 seqno)
67 { 71 {
71 75
72 bool recv_ok (u32 seqno) 76 bool recv_ok (u32 seqno)
73 { 77 {
74 if (seqno <= seq - WINDOWSIZE) 78 if (seqno <= seq - WINDOWSIZE)
75 slog (L_ERR, _("received duplicate or outdated packet (received %08lx, expected %08lx)\n" 79 slog (L_ERR, _("received duplicate or outdated packet (received %08lx, expected %08lx)\n"
76 "possible replay attack, or just massive packet reordering"), seqno, seq + 1);//D 80 "possible replay attack, or just massive packet reordering"), seqno, seq + 1);
77 else if (seqno > seq + WINDOWSIZE) 81 else if (seqno > seq + WINDOWSIZE * 4)
78 slog (L_ERR, _("received duplicate or out-of-sync packet (received %08lx, expected %08lx)\n" 82 slog (L_ERR, _("received duplicate or out-of-sync packet (received %08lx, expected %08lx)\n"
79 "possible replay attack, or just massive packet loss"), seqno, seq + 1);//D 83 "possible replay attack, or just massive packet loss"), seqno, seq + 1);
80 else 84 else
81 { 85 {
82 while (seqno > seq) 86 while (seqno > seq)
83 { 87 {
84 seq++; 88 seq++;
93 u32 s = seqno % WINDOWSIZE; 97 u32 s = seqno % WINDOWSIZE;
94 u32 *cell = v + (s >> 5); 98 u32 *cell = v + (s >> 5);
95 u32 mask = 1 << (s & 31); 99 u32 mask = 1 << (s & 31);
96 100
97 if (*cell & mask) 101 if (*cell & mask)
98 {
99 slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n" 102 slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n"
100 "possible replay attack, or just packet duplication"), seqno, seq + 1);//D 103 "possible replay attack, or just packet duplication"), seqno, seq + 1);
101 return false;
102 }
103 else 104 else
104 { 105 {
105 *cell |= mask; 106 *cell |= mask;
106 return true; 107 return true;
107 } 108 }
108 } 109 }
110
111 return false;
109 } 112 }
110}; 113};
111 114
112typedef callback0<const char *> run_script_cb; 115typedef callback0<const char *> run_script_cb;
113 116
114// run a shell script (or actually an external program). 117// run a shell script (or actually an external program).
115void run_script (const run_script_cb &cb, bool wait); 118bool run_script (const run_script_cb &cb, bool wait);
116 119
117#if ENABLE_HTTP_PROXY 120#if ENABLE_HTTP_PROXY
118u8 *base64_encode (const u8 *data, unsigned int len); 121u8 *base64_encode (const u8 *data, unsigned int len);
119#endif 122#endif
120 123

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines