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. |
… | |
… | |
21 | |
21 | |
22 | #include "config.h" |
22 | #include "config.h" |
23 | |
23 | |
24 | #include <cstdio> |
24 | #include <cstdio> |
25 | #include <cstring> |
25 | #include <cstring> |
|
|
26 | #include <cstdlib> |
|
|
27 | #include <clocale> |
26 | |
28 | |
27 | #include <errno.h> |
29 | #include <errno.h> |
28 | #include <fcntl.h> |
30 | #include <fcntl.h> |
29 | #include <getopt.h> |
31 | #include <getopt.h> |
30 | #include <signal.h> |
32 | #include <signal.h> |
… | |
… | |
46 | #include "conf.h" |
48 | #include "conf.h" |
47 | #include "slog.h" |
49 | #include "slog.h" |
48 | #include "util.h" |
50 | #include "util.h" |
49 | #include "vpn.h" |
51 | #include "vpn.h" |
50 | #include "iom.h" |
52 | #include "iom.h" |
51 | |
|
|
52 | vpn network; |
|
|
53 | |
53 | |
54 | static loglevel llevel = L_NONE; |
54 | static loglevel llevel = L_NONE; |
55 | |
55 | |
56 | /* If nonzero, display usage information and exit. */ |
56 | /* If nonzero, display usage information and exit. */ |
57 | static int show_help; |
57 | static int show_help; |
… | |
… | |
149 | */ |
149 | */ |
150 | void cleanup_and_exit(int c) |
150 | void cleanup_and_exit(int c) |
151 | { |
151 | { |
152 | network.shutdown_all (); |
152 | network.shutdown_all (); |
153 | |
153 | |
154 | if (pidfilename) |
154 | if (conf.pidfilename) |
155 | remove_pid (pidfilename); |
155 | remove_pid (conf.pidfilename); |
156 | |
156 | |
157 | slog (L_INFO, _("terminating with exit code %d"), c); |
157 | slog (L_INFO, _("terminating with exit code %d"), c); |
158 | |
158 | |
159 | exit (c); |
159 | exit (c); |
160 | } |
160 | } |
… | |
… | |
222 | |
222 | |
223 | if (show_version) |
223 | if (show_version) |
224 | { |
224 | { |
225 | printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), |
225 | printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), |
226 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
226 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
|
|
227 | printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); |
227 | printf (_ |
228 | printf (_ |
228 | ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" |
229 | ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" |
229 | "See the AUTHORS file for a complete list.\n\n" |
230 | "See the AUTHORS file for a complete list.\n\n" |
230 | "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
231 | "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
231 | "and you are welcome to redistribute it under certain conditions;\n" |
232 | "and you are welcome to redistribute it under certain conditions;\n" |
… | |
… | |
239 | |
240 | |
240 | log_to (LOGTO_SYSLOG | LOGTO_STDERR); |
241 | log_to (LOGTO_SYSLOG | LOGTO_STDERR); |
241 | |
242 | |
242 | /* Lock all pages into memory if requested */ |
243 | /* Lock all pages into memory if requested */ |
243 | |
244 | |
244 | #if HAVE_MLOCKALL && HAVE_SYS_MMAN_H |
245 | #if HAVE_MLOCKALL && HAVE_SYS_MMAN_H && _POSIX_MEMLOCK |
245 | if (do_mlock) |
246 | if (do_mlock) |
246 | if (mlockall (MCL_CURRENT | MCL_FUTURE)) |
247 | if (mlockall (MCL_CURRENT | MCL_FUTURE)) |
247 | slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); |
248 | slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); |
248 | #endif |
249 | #endif |
249 | |
250 | |
|
|
251 | conf.read_config (true); |
250 | make_names (); |
252 | make_names (); |
251 | conf.read_config (true); |
|
|
252 | |
253 | |
253 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
254 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
254 | |
255 | |
255 | RAND_load_file ("/dev/urandom", 1024); |
256 | RAND_load_file ("/dev/urandom", 1024); |
256 | |
257 | |
257 | if (!THISNODE) |
258 | if (!THISNODE) |
258 | { |
259 | { |
259 | slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."), |
260 | slog (L_ERR, _("current node not set, or node '%s' not found in configfile, specify the nodename when starting vped."), |
260 | thisnode ? thisnode : "<unset>"); |
261 | thisnode ? thisnode : "<unset>"); |
261 | exit (1); |
262 | exit (EXIT_FAILURE); |
262 | } |
263 | } |
263 | |
264 | |
264 | if (detach (do_detach)) |
265 | if (detach (do_detach)) |
265 | exit (0); |
266 | exit (EXIT_SUCCESS); |
266 | |
267 | |
267 | setup_signals (); |
268 | setup_signals (); |
268 | |
269 | |
269 | if (!network.setup ()) |
270 | if (!network.setup ()) |
270 | { |
271 | { |
271 | iom.loop (); |
272 | iom.loop (); |
272 | cleanup_and_exit (1); |
273 | cleanup_and_exit (EXIT_FAILURE); |
273 | } |
274 | } |
274 | |
275 | |
275 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
276 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
276 | cleanup_and_exit (1); |
277 | cleanup_and_exit (EXIT_FAILURE); |
277 | } |
278 | } |
278 | |
279 | |