| 1 |
pcg |
1.1 |
/* |
| 2 |
|
|
util.h -- process management and other utility functions |
| 3 |
|
|
Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl> |
| 4 |
|
|
2000-2002 Guus Sliepen <guus@sliepen.eu.org> |
| 5 |
|
|
2003 Marc Lehmannn <pcg@goof.com> |
| 6 |
|
|
|
| 7 |
|
|
This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
it under the terms of the GNU General Public License as published by |
| 9 |
|
|
the Free Software Foundation; either version 2 of the License, or |
| 10 |
|
|
(at your option) any later version. |
| 11 |
|
|
|
| 12 |
|
|
This program is distributed in the hope that it will be useful, |
| 13 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
|
|
GNU General Public License for more details. |
| 16 |
|
|
|
| 17 |
|
|
You should have received a copy of the GNU General Public License |
| 18 |
|
|
along with this program; if not, write to the Free Software |
| 19 |
|
|
Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
|
|
#ifndef UTIL_H__ |
| 23 |
|
|
#define UTIL_H__ |
| 24 |
|
|
|
| 25 |
pcg |
1.3 |
#include "iom.h" |
| 26 |
pcg |
1.1 |
#include "device.h" |
| 27 |
|
|
|
| 28 |
|
|
/* |
| 29 |
|
|
* check for an existing vped for this net, and write pid to pidfile |
| 30 |
|
|
*/ |
| 31 |
|
|
extern int write_pidfile (void); |
| 32 |
|
|
|
| 33 |
|
|
/* |
| 34 |
|
|
* kill older vped |
| 35 |
|
|
*/ |
| 36 |
|
|
extern int kill_other (int signal); |
| 37 |
|
|
|
| 38 |
|
|
/* |
| 39 |
|
|
* Detach from current terminal, write pidfile, kill parent |
| 40 |
|
|
*/ |
| 41 |
|
|
extern int detach (int do_detach); |
| 42 |
|
|
|
| 43 |
|
|
/* |
| 44 |
|
|
* Set all files and paths according to netname |
| 45 |
|
|
*/ |
| 46 |
|
|
extern void make_names (void); |
| 47 |
|
|
|
| 48 |
|
|
/* |
| 49 |
|
|
* check wether the given path is an absolute pathname |
| 50 |
|
|
*/ |
| 51 |
|
|
#define ABSOLUTE_PATH(c) ((c)[0] == '/') |
| 52 |
|
|
|
| 53 |
pcg |
1.8 |
extern void id2mac (unsigned int id, void *m); |
| 54 |
pcg |
1.1 |
|
| 55 |
pcg |
1.8 |
#define mac2id(p) ((p)[0] & 0x01 ? 0 : ((p)[4] << 8) | (p)[5]) |
| 56 |
pcg |
1.1 |
|
| 57 |
pcg |
1.2 |
struct sliding_window { |
| 58 |
|
|
u32 v[(WINDOWSIZE + 31) / 32]; |
| 59 |
|
|
u32 seq; |
| 60 |
|
|
|
| 61 |
|
|
void reset (u32 seqno) |
| 62 |
|
|
{ |
| 63 |
|
|
memset (v, -1, sizeof v); |
| 64 |
|
|
seq = seqno; |
| 65 |
|
|
} |
| 66 |
|
|
|
| 67 |
|
|
bool recv_ok (u32 seqno) |
| 68 |
|
|
{ |
| 69 |
|
|
if (seqno <= seq - WINDOWSIZE) |
| 70 |
|
|
slog (L_ERR, _("received duplicate or outdated packet (received %08lx, expected %08lx)\n" |
| 71 |
|
|
"possible replay attack, or just massive packet reordering"), seqno, seq + 1);//D |
| 72 |
|
|
else if (seqno > seq + WINDOWSIZE) |
| 73 |
|
|
slog (L_ERR, _("received duplicate or out-of-sync packet (received %08lx, expected %08lx)\n" |
| 74 |
|
|
"possible replay attack, or just massive packet loss"), seqno, seq + 1);//D |
| 75 |
|
|
else |
| 76 |
|
|
{ |
| 77 |
|
|
while (seqno > seq) |
| 78 |
|
|
{ |
| 79 |
|
|
seq++; |
| 80 |
|
|
|
| 81 |
|
|
u32 s = seq % WINDOWSIZE; |
| 82 |
|
|
u32 *cell = v + (s >> 5); |
| 83 |
|
|
u32 mask = 1 << (s & 31); |
| 84 |
|
|
|
| 85 |
|
|
*cell &= ~mask; |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
|
u32 s = seqno % WINDOWSIZE; |
| 89 |
|
|
u32 *cell = v + (s >> 5); |
| 90 |
|
|
u32 mask = 1 << (s & 31); |
| 91 |
|
|
|
| 92 |
|
|
if (*cell & mask) |
| 93 |
|
|
{ |
| 94 |
|
|
slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n" |
| 95 |
|
|
"possible replay attack, or just packet duplication"), seqno, seq + 1);//D |
| 96 |
|
|
return false; |
| 97 |
|
|
} |
| 98 |
|
|
else |
| 99 |
|
|
{ |
| 100 |
|
|
*cell |= mask; |
| 101 |
|
|
return true; |
| 102 |
|
|
} |
| 103 |
|
|
} |
| 104 |
|
|
} |
| 105 |
|
|
}; |
| 106 |
|
|
|
| 107 |
pcg |
1.6 |
typedef callback0<const char *> run_script_cb; |
| 108 |
pcg |
1.5 |
|
| 109 |
|
|
// run a shell script (or actually an external program). |
| 110 |
|
|
void run_script (const run_script_cb &cb, bool wait); |
| 111 |
|
|
|
| 112 |
pcg |
1.7 |
#if ENABLE_HTTP_PROXY |
| 113 |
|
|
u8 *base64_encode (const u8 *data, unsigned int len); |
| 114 |
|
|
#endif |
| 115 |
|
|
|
| 116 |
pcg |
1.1 |
#endif |
| 117 |
|
|
|