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