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 | |
… | |
… | |
44 | #include "slog.h" |
47 | #include "slog.h" |
45 | #include "util.h" |
48 | #include "util.h" |
46 | #include "vpn.h" |
49 | #include "vpn.h" |
47 | #include "iom.h" |
50 | #include "iom.h" |
48 | |
51 | |
49 | vpn network; |
|
|
50 | |
|
|
51 | static loglevel llevel = L_NONE; |
52 | static loglevel llevel = L_NONE; |
52 | |
53 | |
53 | /* If nonzero, display usage information and exit. */ |
54 | /* If nonzero, display usage information and exit. */ |
54 | static int show_help; |
55 | static int show_help; |
55 | |
56 | |
56 | /* If nonzero, print the version on standard output and exit. */ |
57 | /* If nonzero, print the version on standard output and exit. */ |
57 | static int show_version; |
58 | static int show_version; |
58 | |
59 | |
59 | #if HAVE_MLOCKALL |
|
|
60 | /* If nonzero, disable swapping for this process. */ |
60 | /* If nonzero, disable swapping for this process. */ |
61 | static int do_mlock = 0; |
61 | static int do_mlock = 0; |
62 | #endif |
|
|
63 | |
62 | |
64 | /* If zero, don't detach from the terminal. */ |
63 | /* If zero, don't detach from the terminal. */ |
65 | static int do_detach = 1; |
64 | static int do_detach = 1; |
66 | |
65 | |
67 | static struct option const long_options[] = |
66 | static struct option const long_options[] = |
… | |
… | |
69 | {"config", required_argument, NULL, 'c'}, |
68 | {"config", required_argument, NULL, 'c'}, |
70 | {"help", no_argument, &show_help, 1}, |
69 | {"help", no_argument, &show_help, 1}, |
71 | {"version", no_argument, &show_version, 1}, |
70 | {"version", no_argument, &show_version, 1}, |
72 | {"no-detach", no_argument, &do_detach, 0}, |
71 | {"no-detach", no_argument, &do_detach, 0}, |
73 | {"log-level", required_argument, NULL, 'l'}, |
72 | {"log-level", required_argument, NULL, 'l'}, |
74 | #if HAVE_MLOCKALL |
|
|
75 | {"mlock", no_argument, &do_mlock, 1}, |
73 | {"mlock", no_argument, &do_mlock, 1}, |
76 | #endif |
|
|
77 | {NULL, 0, NULL, 0} |
74 | {NULL, 0, NULL, 0} |
78 | }; |
75 | }; |
79 | |
76 | |
80 | static void |
77 | static void |
81 | usage (int status) |
78 | usage (int status) |
… | |
… | |
121 | |
118 | |
122 | case 'D': /* no detach */ |
119 | case 'D': /* no detach */ |
123 | do_detach = 0; |
120 | do_detach = 0; |
124 | break; |
121 | break; |
125 | |
122 | |
126 | #if HAVE_MLOCKALL |
|
|
127 | case 'L': /* lock into memory */ |
123 | case 'L': /* lock into memory */ |
128 | do_mlock = 1; |
124 | do_mlock = 1; |
129 | break; |
125 | break; |
130 | #endif |
|
|
131 | |
126 | |
132 | case 'l': /* inc debug level */ |
127 | case 'l': /* inc debug level */ |
133 | { |
128 | { |
134 | llevel = string_to_loglevel (optarg); |
129 | llevel = string_to_loglevel (optarg); |
135 | |
130 | |
… | |
… | |
209 | } |
204 | } |
210 | |
205 | |
211 | int |
206 | int |
212 | main (int argc, char **argv, char **envp) |
207 | main (int argc, char **argv, char **envp) |
213 | { |
208 | { |
|
|
209 | ERR_load_crypto_strings (); // we have the RAM |
|
|
210 | |
214 | set_loglevel (L_INFO); |
211 | set_loglevel (L_INFO); |
215 | set_identity (argv[0]); |
212 | set_identity (argv[0]); |
216 | log_to (LOGTO_SYSLOG | LOGTO_STDERR); |
213 | log_to (LOGTO_SYSLOG | LOGTO_STDERR); |
217 | |
214 | |
218 | setlocale (LC_ALL, ""); |
215 | setlocale (LC_ALL, ""); |
… | |
… | |
221 | |
218 | |
222 | parse_options (argc, argv, envp); |
219 | parse_options (argc, argv, envp); |
223 | |
220 | |
224 | if (show_version) |
221 | if (show_version) |
225 | { |
222 | { |
226 | 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 (), |
227 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
224 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
228 | printf (_ |
225 | printf (_ |
229 | ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" |
226 | ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" |
230 | "See the AUTHORS file for a complete list.\n\n" |
227 | "See the AUTHORS file for a complete list.\n\n" |
231 | "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
228 | "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
… | |
… | |
240 | |
237 | |
241 | log_to (LOGTO_SYSLOG | LOGTO_STDERR); |
238 | log_to (LOGTO_SYSLOG | LOGTO_STDERR); |
242 | |
239 | |
243 | /* Lock all pages into memory if requested */ |
240 | /* Lock all pages into memory if requested */ |
244 | |
241 | |
245 | #if HAVE_MLOCKALL |
242 | #if HAVE_MLOCKALL && HAVE_SYS_MMAN_H && _POSIX_MEMLOCK |
246 | if (do_mlock) |
243 | if (do_mlock) |
247 | if (mlockall (MCL_CURRENT | MCL_FUTURE)) |
244 | if (mlockall (MCL_CURRENT | MCL_FUTURE)) |
248 | slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); |
245 | slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); |
249 | #endif |
246 | #endif |
250 | |
247 | |