ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/util.h
Revision: 1.10
Committed: Thu Oct 16 14:12:00 2003 UTC (20 years, 7 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: VPE_1_2
Changes since 1.9: +5 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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 pcg 1.9 2003 Marc Lehmann <pcg@goof.com>
6 pcg 1.1
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.10 #include "gettext.h"
26    
27     #include "slog.h"
28 pcg 1.3 #include "iom.h"
29 pcg 1.1
30     /*
31     * check for an existing vped for this net, and write pid to pidfile
32     */
33     extern int write_pidfile (void);
34    
35     /*
36     * kill older vped
37     */
38     extern int kill_other (int signal);
39    
40     /*
41     * Detach from current terminal, write pidfile, kill parent
42     */
43     extern int detach (int do_detach);
44    
45     /*
46     * Set all files and paths according to netname
47     */
48     extern void make_names (void);
49    
50     /*
51     * check wether the given path is an absolute pathname
52     */
53     #define ABSOLUTE_PATH(c) ((c)[0] == '/')
54 pcg 1.10
55     typedef u8 mac[6];
56 pcg 1.1
57 pcg 1.8 extern void id2mac (unsigned int id, void *m);
58 pcg 1.1
59 pcg 1.8 #define mac2id(p) ((p)[0] & 0x01 ? 0 : ((p)[4] << 8) | (p)[5])
60 pcg 1.1
61 pcg 1.2 struct sliding_window {
62     u32 v[(WINDOWSIZE + 31) / 32];
63     u32 seq;
64    
65     void reset (u32 seqno)
66     {
67     memset (v, -1, sizeof v);
68     seq = seqno;
69     }
70    
71     bool recv_ok (u32 seqno)
72     {
73     if (seqno <= seq - WINDOWSIZE)
74     slog (L_ERR, _("received duplicate or outdated packet (received %08lx, expected %08lx)\n"
75     "possible replay attack, or just massive packet reordering"), seqno, seq + 1);//D
76     else if (seqno > seq + WINDOWSIZE)
77     slog (L_ERR, _("received duplicate or out-of-sync packet (received %08lx, expected %08lx)\n"
78     "possible replay attack, or just massive packet loss"), seqno, seq + 1);//D
79     else
80     {
81     while (seqno > seq)
82     {
83     seq++;
84    
85     u32 s = seq % WINDOWSIZE;
86     u32 *cell = v + (s >> 5);
87     u32 mask = 1 << (s & 31);
88    
89     *cell &= ~mask;
90     }
91    
92     u32 s = seqno % WINDOWSIZE;
93     u32 *cell = v + (s >> 5);
94     u32 mask = 1 << (s & 31);
95    
96     if (*cell & mask)
97     {
98     slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n"
99     "possible replay attack, or just packet duplication"), seqno, seq + 1);//D
100     return false;
101     }
102     else
103     {
104     *cell |= mask;
105     return true;
106     }
107     }
108     }
109     };
110    
111 pcg 1.6 typedef callback0<const char *> run_script_cb;
112 pcg 1.5
113     // run a shell script (or actually an external program).
114     void run_script (const run_script_cb &cb, bool wait);
115    
116 pcg 1.7 #if ENABLE_HTTP_PROXY
117     u8 *base64_encode (const u8 *data, unsigned int len);
118     #endif
119    
120 pcg 1.1 #endif
121