ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/vped.C
(Generate patch)

Comparing gvpe/src/vped.C (file contents):
Revision 1.1 by pcg, Sat Mar 1 15:53:03 2003 UTC vs.
Revision 1.13 by pcg, Thu Oct 16 21:57:54 2003 UTC

1/* 1/*
2 vped.C -- the main file for vped 2 vped.C -- the main file for vped
3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl> 3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl>
4 2000-2002 Guus Sliepen <guus@sliepen.eu.org> 4 2000-2002 Guus Sliepen <guus@sliepen.eu.org>
5 2003 Marc Lehmannn <pcg@goof.com> 5 2003 Marc Lehmann <pcg@goof.com>
6 6
7 This program is free software; you can redistribute it and/or modify 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 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 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
31#include <sys/types.h> 31#include <sys/types.h>
32#include <unistd.h> 32#include <unistd.h>
33#include <signal.h> 33#include <signal.h>
34#include <termios.h> 34#include <termios.h>
35 35
36#if HAVE_SYS_MMAN_H
36#include <sys/mman.h> 37# include <sys/mman.h>
38#endif
37 39
40#include <openssl/err.h>
38#include <openssl/rand.h> 41#include <openssl/rand.h>
39 42
40#include "gettext.h" 43#include "gettext.h"
41#include "pidfile.h" 44#include "pidfile.h"
42 45
43#include "conf.h" 46#include "conf.h"
44#include "slog.h" 47#include "slog.h"
45#include "util.h" 48#include "util.h"
46#include "protocol.h" 49#include "vpn.h"
50#include "iom.h"
47 51
48vpn network; 52static loglevel llevel = L_NONE;
49 53
50/* If nonzero, display usage information and exit. */ 54/* If nonzero, display usage information and exit. */
51static int show_help; 55static int show_help;
52 56
53/* If nonzero, print the version on standard output and exit. */ 57/* If nonzero, print the version on standard output and exit. */
54static int show_version; 58static int show_version;
55 59
56#if HAVE_MLOCKALL
57/* If nonzero, disable swapping for this process. */ 60/* If nonzero, disable swapping for this process. */
58static int do_mlock = 0; 61static int do_mlock = 0;
59#endif
60 62
61/* If zero, don't detach from the terminal. */ 63/* If zero, don't detach from the terminal. */
62static int do_detach = 1; 64static int do_detach = 1;
63 65
64static struct option const long_options[] = 66static struct option const long_options[] =
66 {"config", required_argument, NULL, 'c'}, 68 {"config", required_argument, NULL, 'c'},
67 {"help", no_argument, &show_help, 1}, 69 {"help", no_argument, &show_help, 1},
68 {"version", no_argument, &show_version, 1}, 70 {"version", no_argument, &show_version, 1},
69 {"no-detach", no_argument, &do_detach, 0}, 71 {"no-detach", no_argument, &do_detach, 0},
70 {"log-level", required_argument, NULL, 'l'}, 72 {"log-level", required_argument, NULL, 'l'},
71#if HAVE_MLOCKALL
72 {"mlock", no_argument, &do_mlock, 1}, 73 {"mlock", no_argument, &do_mlock, 1},
73#endif
74 {NULL, 0, NULL, 0} 74 {NULL, 0, NULL, 0}
75 }; 75 };
76 76
77static void 77static void
78usage (int status) 78usage (int status)
118 118
119 case 'D': /* no detach */ 119 case 'D': /* no detach */
120 do_detach = 0; 120 do_detach = 0;
121 break; 121 break;
122 122
123#if HAVE_MLOCKALL
124 case 'L': /* lock into memory */ 123 case 'L': /* lock into memory */
125 do_mlock = 1; 124 do_mlock = 1;
126 break; 125 break;
127#endif
128 126
129 case 'l': /* inc debug level */ 127 case 'l': /* inc debug level */
130 { 128 {
131 loglevel l = string_to_loglevel (optarg); 129 llevel = string_to_loglevel (optarg);
132 130
133 if (l != L_NONE) 131 if (llevel == L_NONE)
134 set_loglevel (l);
135 else
136 slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL); 132 slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL);
137 } 133 }
138 break; 134 break;
139 135
140 case '?': 136 case '?':
166*/ 162*/
167RETSIGTYPE 163RETSIGTYPE
168sigterm_handler (int a) 164sigterm_handler (int a)
169{ 165{
170 network.events |= vpn::EVENT_SHUTDOWN; 166 network.events |= vpn::EVENT_SHUTDOWN;
167 network.event.start (0);
171} 168}
172 169
173RETSIGTYPE 170RETSIGTYPE
174sighup_handler (int a) 171sighup_handler (int a)
175{ 172{
176 network.events |= vpn::EVENT_RECONNECT; 173 network.events |= vpn::EVENT_RECONNECT;
174 network.event.start (0);
177} 175}
178 176
179RETSIGTYPE 177RETSIGTYPE
180sigusr1_handler (int a) 178sigusr1_handler (int a)
181{ 179{
180 network.dump_status ();
182} 181}
183 182
184RETSIGTYPE 183RETSIGTYPE
185sigusr2_handler (int a) 184sigusr2_handler (int a)
186{ 185{
196 195
197 act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL); 196 act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL);
198 act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); 197 act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL);
199 act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); 198 act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL);
200 act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL); 199 act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL);
200 act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL);
201 act.sa_flags = SA_RESETHAND; 201 act.sa_flags = SA_RESETHAND;
202 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); 202 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL);
203 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); 203 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL);
204} 204}
205 205
206int 206int
207main (int argc, char **argv, char **envp) 207main (int argc, char **argv, char **envp)
208{ 208{
209 ERR_load_crypto_strings (); // we have the RAM
210
209 set_loglevel (L_INFO); 211 set_loglevel (L_INFO);
210 set_identity (argv[0]); 212 set_identity (argv[0]);
211 log_to (LOGTO_SYSLOG | LOGTO_STDERR); 213 log_to (LOGTO_SYSLOG | LOGTO_STDERR);
212 214
213 setlocale (LC_ALL, ""); 215 setlocale (LC_ALL, "");
216 218
217 parse_options (argc, argv, envp); 219 parse_options (argc, argv, envp);
218 220
219 if (show_version) 221 if (show_version)
220 { 222 {
221 printf (_("%s version %s (built %s %s, protocol %d:%d)\n"), get_identity (), 223 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (),
222 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 224 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
225 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE);
223 printf (_ 226 printf (_
224 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" 227 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n"
225 "See the AUTHORS file for a complete list.\n\n" 228 "See the AUTHORS file for a complete list.\n\n"
226 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 229 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
227 "and you are welcome to redistribute it under certain conditions;\n" 230 "and you are welcome to redistribute it under certain conditions;\n"
235 238
236 log_to (LOGTO_SYSLOG | LOGTO_STDERR); 239 log_to (LOGTO_SYSLOG | LOGTO_STDERR);
237 240
238 /* Lock all pages into memory if requested */ 241 /* Lock all pages into memory if requested */
239 242
240#if HAVE_MLOCKALL 243#if HAVE_MLOCKALL && HAVE_SYS_MMAN_H && _POSIX_MEMLOCK
241 if (do_mlock) 244 if (do_mlock)
242 if (mlockall (MCL_CURRENT | MCL_FUTURE)) 245 if (mlockall (MCL_CURRENT | MCL_FUTURE))
243 slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); 246 slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno));
244#endif 247#endif
245 248
246 make_names (); 249 make_names ();
247 conf.read_config (true); 250 conf.read_config (true);
248 251
252 set_loglevel (llevel != L_NONE ? llevel : conf.llevel);
253
249 RAND_load_file ("/dev/urandom", 1024); 254 RAND_load_file ("/dev/urandom", 1024);
250
251 //OpenSSL_add_all_algorithms ();
252 255
253 if (!THISNODE) 256 if (!THISNODE)
254 { 257 {
255 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."), 258 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."),
256 thisnode ? thisnode : "<unset>"); 259 thisnode ? thisnode : "<unset>");
262 265
263 setup_signals (); 266 setup_signals ();
264 267
265 if (!network.setup ()) 268 if (!network.setup ())
266 { 269 {
267 network.main_loop (); 270 iom.loop ();
268 cleanup_and_exit (1); 271 cleanup_and_exit (1);
269 } 272 }
270 273
271 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); 274 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting."));
272 cleanup_and_exit (1); 275 cleanup_and_exit (1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines