1 | /* |
1 | /* |
2 | vped.C -- the main file for gvpe |
2 | gvpe.C -- the main file for gvpe |
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-2005 Marc Lehmann <gvpe@schmorp.de> |
5 | 2003-2008 Marc Lehmann <gvpe@schmorp.de> |
6 | |
6 | |
7 | This file is part of GVPE. |
7 | This file is part of GVPE. |
8 | |
8 | |
9 | GVPE is free software; you can redistribute it and/or modify |
9 | GVPE is free software; you can redistribute it and/or modify it |
10 | it under the terms of the GNU General Public License as published by |
10 | under the terms of the GNU General Public License as published by the |
11 | the Free Software Foundation; either version 2 of the License, or |
11 | Free Software Foundation; either version 3 of the License, or (at your |
12 | (at your option) any later version. |
12 | option) any later version. |
13 | |
13 | |
14 | This program is distributed in the hope that it will be useful, |
14 | This program is distributed in the hope that it will be useful, but |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
17 | GNU General Public License for more details. |
17 | Public License for more details. |
18 | |
18 | |
19 | You should have received a copy of the GNU General Public License |
19 | You should have received a copy of the GNU General Public License along |
20 | along with gvpe; if not, write to the Free Software |
20 | with this program; if not, see <http://www.gnu.org/licenses/>. |
21 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | |
|
|
22 | Additional permission under GNU GPL version 3 section 7 |
|
|
23 | |
|
|
24 | If you modify this Program, or any covered work, by linking or |
|
|
25 | combining it with the OpenSSL project's OpenSSL library (or a modified |
|
|
26 | version of that library), containing parts covered by the terms of the |
|
|
27 | OpenSSL or SSLeay licenses, the licensors of this Program grant you |
|
|
28 | additional permission to convey the resulting work. Corresponding |
|
|
29 | Source for a non-source form of such a combination shall include the |
|
|
30 | source code for the parts of OpenSSL used as well as that of the |
|
|
31 | covered work. |
22 | */ |
32 | */ |
23 | |
33 | |
24 | #include "config.h" |
34 | #include "config.h" |
25 | |
35 | |
26 | #include <cstdio> |
36 | #include <cstdio> |
… | |
… | |
48 | |
58 | |
49 | #include "conf.h" |
59 | #include "conf.h" |
50 | #include "slog.h" |
60 | #include "slog.h" |
51 | #include "util.h" |
61 | #include "util.h" |
52 | #include "vpn.h" |
62 | #include "vpn.h" |
53 | #include "iom.h" |
63 | #include "ev_cpp.h" |
54 | |
64 | |
55 | static loglevel llevel = L_NONE; |
65 | static loglevel llevel = L_NONE; |
56 | |
66 | |
57 | /* If nonzero, display usage information and exit. */ |
67 | /* If nonzero, display usage information and exit. */ |
58 | static int show_help; |
68 | static int show_help; |
… | |
… | |
90 | " -D, --no-detach Don't fork and detach.\n" |
100 | " -D, --no-detach Don't fork and detach.\n" |
91 | " -l, --log-level=LEVEL Set logging level (info, notice, warn are common).\n" |
101 | " -l, --log-level=LEVEL Set logging level (info, notice, warn are common).\n" |
92 | " -L, --mlock Lock tinc into main memory.\n" |
102 | " -L, --mlock Lock tinc into main memory.\n" |
93 | " --help Display this help and exit.\n" |
103 | " --help Display this help and exit.\n" |
94 | " --version Output version information and exit.\n\n")); |
104 | " --version Output version information and exit.\n\n")); |
95 | printf (_("Report bugs to <vpe@plan9.de>.\n")); |
105 | printf (_("Report bugs to <gvpe@schmorp.de>.\n")); |
96 | } |
106 | } |
97 | |
107 | |
98 | exit (status); |
108 | exit (status); |
99 | } |
109 | } |
100 | |
110 | |
… | |
… | |
102 | parse_options (int argc, char **argv, char **envp) |
112 | parse_options (int argc, char **argv, char **envp) |
103 | { |
113 | { |
104 | int r; |
114 | int r; |
105 | int option_index = 0; |
115 | int option_index = 0; |
106 | |
116 | |
107 | while ((r = getopt_long (argc, argv, "-c:DLl:", long_options, &option_index)) != EOF) |
117 | while ((r = getopt_long (argc, argv, "c:DLl:", long_options, &option_index)) != EOF) |
108 | { |
118 | { |
109 | switch (r) |
119 | switch (r) |
110 | { |
120 | { |
111 | case 0: /* long option */ |
121 | case 0: /* long option */ |
112 | break; |
|
|
113 | |
|
|
114 | case 1: /* this node name */ |
|
|
115 | thisnode = strdup (optarg); |
|
|
116 | break; |
122 | break; |
117 | |
123 | |
118 | case 'c': /* config file */ |
124 | case 'c': /* config file */ |
119 | confbase = strdup (optarg); |
125 | confbase = strdup (optarg); |
120 | break; |
126 | break; |
… | |
… | |
165 | */ |
171 | */ |
166 | RETSIGTYPE |
172 | RETSIGTYPE |
167 | sigterm_handler (int a) |
173 | sigterm_handler (int a) |
168 | { |
174 | { |
169 | network.events |= vpn::EVENT_SHUTDOWN; |
175 | network.events |= vpn::EVENT_SHUTDOWN; |
170 | network.event.start (0); |
176 | network.event.start (); |
171 | } |
177 | } |
172 | |
178 | |
173 | RETSIGTYPE |
179 | RETSIGTYPE |
174 | sighup_handler (int a) |
180 | sighup_handler (int a) |
175 | { |
181 | { |
176 | network.events |= vpn::EVENT_RECONNECT; |
182 | network.events |= vpn::EVENT_RECONNECT; |
177 | network.event.start (0); |
183 | network.event.start (); |
178 | } |
184 | } |
179 | |
185 | |
180 | RETSIGTYPE |
186 | RETSIGTYPE |
181 | sigusr1_handler (int a) |
187 | sigusr1_handler (int a) |
182 | { |
188 | { |
… | |
… | |
219 | bindtextdomain (PACKAGE, LOCALEDIR); |
225 | bindtextdomain (PACKAGE, LOCALEDIR); |
220 | textdomain (PACKAGE); |
226 | textdomain (PACKAGE); |
221 | |
227 | |
222 | parse_options (argc, argv, envp); |
228 | parse_options (argc, argv, envp); |
223 | |
229 | |
|
|
230 | argc -= optind; |
|
|
231 | argv += optind; |
|
|
232 | |
224 | if (show_version) |
233 | if (show_version) |
225 | { |
234 | { |
226 | printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), |
235 | printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (), |
227 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
236 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
228 | printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); |
237 | printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); |
229 | printf (_ |
238 | printf (_ |
230 | ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" |
239 | ("Copyright (C) 2003 Marc Lehmann <gvpe@schmorp.de> and others.\n" |
231 | "See the AUTHORS file for a complete list.\n\n" |
240 | "See the AUTHORS file for a complete list.\n\n" |
232 | "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
241 | "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
233 | "and you are welcome to redistribute it under certain conditions;\n" |
242 | "and you are welcome to redistribute it under certain conditions;\n" |
234 | "see the file COPYING for details.\n")); |
243 | "see the file COPYING for details.\n")); |
235 | |
244 | |
… | |
… | |
247 | if (do_mlock) |
256 | if (do_mlock) |
248 | if (mlockall (MCL_CURRENT | MCL_FUTURE)) |
257 | if (mlockall (MCL_CURRENT | MCL_FUTURE)) |
249 | slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); |
258 | slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); |
250 | #endif |
259 | #endif |
251 | |
260 | |
252 | conf.read_config (true); |
261 | if (argc >= 1) |
|
|
262 | { |
|
|
263 | thisnode = *argv++; |
|
|
264 | argc--; |
|
|
265 | } |
|
|
266 | |
|
|
267 | if (!ev_default_loop (0)) |
|
|
268 | { |
|
|
269 | slog (L_ERR, _("unable to initialise the event loop (bad $LIBEV_METHODS?)")); |
|
|
270 | exit (EXIT_FAILURE); |
|
|
271 | } |
|
|
272 | |
|
|
273 | { |
|
|
274 | configuration_parser (conf, true, argc, argv); |
|
|
275 | } |
253 | |
276 | |
254 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
277 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
255 | |
278 | |
256 | RAND_load_file ("/dev/urandom", 1024); |
279 | RAND_load_file ("/dev/urandom", 1024); |
257 | |
280 | |
… | |
… | |
267 | |
290 | |
268 | setup_signals (); |
291 | setup_signals (); |
269 | |
292 | |
270 | if (!network.setup ()) |
293 | if (!network.setup ()) |
271 | { |
294 | { |
272 | io_manager::loop (); |
295 | ev_loop (EV_DEFAULT_ 0); |
273 | cleanup_and_exit (EXIT_FAILURE); |
296 | cleanup_and_exit (EXIT_FAILURE); |
274 | } |
297 | } |
275 | |
298 | |
276 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
299 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
277 | cleanup_and_exit (EXIT_FAILURE); |
300 | cleanup_and_exit (EXIT_FAILURE); |