--- gvpe/src/util.h 2005/06/21 08:34:47 1.19 +++ gvpe/src/util.h 2008/08/10 15:04:55 1.28 @@ -2,34 +2,50 @@ util.h -- process management and other utility functions Copyright (C) 1998-2002 Ivo Timmermans 2000-2002 Guus Sliepen - 2003 Marc Lehmann + 2003-2008 Marc Lehmann This file is part of GVPE. - GVPE is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with gvpe; if not, write to the Free Software - Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + GVPE is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . + + Additional permission under GNU GPL version 3 section 7 + + If you modify this Program, or any covered work, by linking or + combining it with the OpenSSL project's OpenSSL library (or a modified + version of that library), containing parts covered by the terms of the + OpenSSL or SSLeay licenses, the licensors of this Program grant you + additional permission to convey the resulting work. Corresponding + Source for a non-source form of such a combination shall include the + source code for the parts of OpenSSL used as well as that of the + covered work. */ #ifndef UTIL_H__ #define UTIL_H__ +#include +#include + #include #include "gettext.h" #include "slog.h" -#include "iom.h" +#include "ev_cpp.h" +#include "callback.h" + +typedef ev_tstamp tstamp; /* * check for an existing gvpe for this net, and write pid to pidfile @@ -59,7 +75,8 @@ #define mac2id(p) ((p)[0] & 0x01 ? 0 : ((p)[4] << 8) | (p)[5]) -struct sliding_window { +struct sliding_window +{ u32 v[(WINDOWSIZE + 31) / 32]; u32 seq; @@ -69,14 +86,13 @@ seq = seqno; } - bool recv_ok (u32 seqno) + // 0 == ok, 1 == far history, 2 == duplicate in-window, 3 == far future + int seqno_classify (u32 seqno) { if (seqno <= seq - WINDOWSIZE) - slog (L_ERR, _("received duplicate or outdated packet (received %08lx, expected %08lx)\n" - "possible replay attack, or just massive packet reordering"), seqno, seq + 1); - else if (seqno > seq + WINDOWSIZE * 4) - slog (L_ERR, _("received duplicate or out-of-sync packet (received %08lx, expected %08lx)\n" - "possible replay attack, or just massive packet loss"), seqno, seq + 1); + return 1; + else if (seqno > seq + WINDOWSIZE * 16) + return 3; else { while (seqno > seq) @@ -95,23 +111,20 @@ u32 mask = 1 << (s & 31); if (*cell & mask) - slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n" - "possible replay attack, or just packet duplication"), seqno, seq + 1); + return 2; else { *cell |= mask; - return true; + return 0; } } - - return false; } }; -typedef callback0 run_script_cb; +typedef callback run_script_cb; // run a shell script (or actually an external program). -bool run_script (const run_script_cb &cb, bool wait); +pid_t run_script (const run_script_cb &cb, bool wait); #if ENABLE_HTTP_PROXY u8 *base64_encode (const u8 *data, unsigned int len);