ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/util.h
Revision: 1.7
Committed: Mon Apr 7 01:12:56 2003 UTC (21 years, 1 month ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: VPE_0_9, VPE_1_0
Changes since 1.6: +4 -0 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     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     static inline void
54     id2mac (unsigned int id, void *m)
55     {
56     mac &p = *(mac *)m;
57    
58     p[0] = 0xfe;
59     p[1] = 0xfd;
60     p[2] = 0x80;
61     p[3] = 0x00;
62     p[4] = id >> 8;
63     p[5] = id;
64     }
65    
66     #define mac2id(p) (p[0] & 0x01 ? 0 : (p[4] << 8) | p[5])
67    
68 pcg 1.2 struct sliding_window {
69     u32 v[(WINDOWSIZE + 31) / 32];
70     u32 seq;
71    
72     void reset (u32 seqno)
73     {
74     memset (v, -1, sizeof v);
75     seq = seqno;
76     }
77    
78     bool recv_ok (u32 seqno)
79     {
80     if (seqno <= seq - WINDOWSIZE)
81     slog (L_ERR, _("received duplicate or outdated packet (received %08lx, expected %08lx)\n"
82     "possible replay attack, or just massive packet reordering"), seqno, seq + 1);//D
83     else if (seqno > seq + WINDOWSIZE)
84     slog (L_ERR, _("received duplicate or out-of-sync packet (received %08lx, expected %08lx)\n"
85     "possible replay attack, or just massive packet loss"), seqno, seq + 1);//D
86     else
87     {
88     while (seqno > seq)
89     {
90     seq++;
91    
92     u32 s = seq % WINDOWSIZE;
93     u32 *cell = v + (s >> 5);
94     u32 mask = 1 << (s & 31);
95    
96     *cell &= ~mask;
97     }
98    
99     u32 s = seqno % WINDOWSIZE;
100     u32 *cell = v + (s >> 5);
101     u32 mask = 1 << (s & 31);
102    
103     if (*cell & mask)
104     {
105     slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n"
106     "possible replay attack, or just packet duplication"), seqno, seq + 1);//D
107     return false;
108     }
109     else
110     {
111     *cell |= mask;
112     return true;
113     }
114     }
115     }
116     };
117    
118 pcg 1.6 typedef callback0<const char *> run_script_cb;
119 pcg 1.5
120     // run a shell script (or actually an external program).
121     void run_script (const run_script_cb &cb, bool wait);
122    
123 pcg 1.7 #if ENABLE_HTTP_PROXY
124     u8 *base64_encode (const u8 *data, unsigned int len);
125     #endif
126    
127 pcg 1.1 #endif
128