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-2005 Marc Lehmann <gvpe@schmorp.de> |
6 | |
6 | |
7 | This file is part of GVPE. |
7 | This file is part of GVPE. |
… | |
… | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | GNU General Public License for more details. |
17 | GNU General 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 |
20 | along with gvpe; if not, write to the Free Software |
20 | along with gvpe; if not, write to the Free Software |
21 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include "config.h" |
24 | #include "config.h" |
25 | |
25 | |
26 | #include <cstdio> |
26 | #include <cstdio> |
… | |
… | |
48 | |
48 | |
49 | #include "conf.h" |
49 | #include "conf.h" |
50 | #include "slog.h" |
50 | #include "slog.h" |
51 | #include "util.h" |
51 | #include "util.h" |
52 | #include "vpn.h" |
52 | #include "vpn.h" |
53 | #include "iom.h" |
53 | #include "ev_cpp.h" |
54 | |
54 | |
55 | static loglevel llevel = L_NONE; |
55 | static loglevel llevel = L_NONE; |
56 | |
56 | |
57 | /* If nonzero, display usage information and exit. */ |
57 | /* If nonzero, display usage information and exit. */ |
58 | static int show_help; |
58 | static int show_help; |
… | |
… | |
90 | " -D, --no-detach Don't fork and detach.\n" |
90 | " -D, --no-detach Don't fork and detach.\n" |
91 | " -l, --log-level=LEVEL Set logging level (info, notice, warn are common).\n" |
91 | " -l, --log-level=LEVEL Set logging level (info, notice, warn are common).\n" |
92 | " -L, --mlock Lock tinc into main memory.\n" |
92 | " -L, --mlock Lock tinc into main memory.\n" |
93 | " --help Display this help and exit.\n" |
93 | " --help Display this help and exit.\n" |
94 | " --version Output version information and exit.\n\n")); |
94 | " --version Output version information and exit.\n\n")); |
95 | printf (_("Report bugs to <vpe@plan9.de>.\n")); |
95 | printf (_("Report bugs to <gvpe@schmorp.de>.\n")); |
96 | } |
96 | } |
97 | |
97 | |
98 | exit (status); |
98 | exit (status); |
99 | } |
99 | } |
100 | |
100 | |
… | |
… | |
102 | parse_options (int argc, char **argv, char **envp) |
102 | parse_options (int argc, char **argv, char **envp) |
103 | { |
103 | { |
104 | int r; |
104 | int r; |
105 | int option_index = 0; |
105 | int option_index = 0; |
106 | |
106 | |
107 | while ((r = getopt_long (argc, argv, "-c:DLl:", long_options, &option_index)) != EOF) |
107 | while ((r = getopt_long (argc, argv, "c:DLl:", long_options, &option_index)) != EOF) |
108 | { |
108 | { |
109 | switch (r) |
109 | switch (r) |
110 | { |
110 | { |
111 | case 0: /* long option */ |
111 | case 0: /* long option */ |
112 | break; |
|
|
113 | |
|
|
114 | case 1: /* this node name */ |
|
|
115 | thisnode = strdup (optarg); |
|
|
116 | break; |
112 | break; |
117 | |
113 | |
118 | case 'c': /* config file */ |
114 | case 'c': /* config file */ |
119 | confbase = strdup (optarg); |
115 | confbase = strdup (optarg); |
120 | break; |
116 | break; |
… | |
… | |
165 | */ |
161 | */ |
166 | RETSIGTYPE |
162 | RETSIGTYPE |
167 | sigterm_handler (int a) |
163 | sigterm_handler (int a) |
168 | { |
164 | { |
169 | network.events |= vpn::EVENT_SHUTDOWN; |
165 | network.events |= vpn::EVENT_SHUTDOWN; |
170 | network.event.start (0); |
166 | network.event.start (); |
171 | } |
167 | } |
172 | |
168 | |
173 | RETSIGTYPE |
169 | RETSIGTYPE |
174 | sighup_handler (int a) |
170 | sighup_handler (int a) |
175 | { |
171 | { |
176 | network.events |= vpn::EVENT_RECONNECT; |
172 | network.events |= vpn::EVENT_RECONNECT; |
177 | network.event.start (0); |
173 | network.event.start (); |
178 | } |
174 | } |
179 | |
175 | |
180 | RETSIGTYPE |
176 | RETSIGTYPE |
181 | sigusr1_handler (int a) |
177 | sigusr1_handler (int a) |
182 | { |
178 | { |
… | |
… | |
219 | bindtextdomain (PACKAGE, LOCALEDIR); |
215 | bindtextdomain (PACKAGE, LOCALEDIR); |
220 | textdomain (PACKAGE); |
216 | textdomain (PACKAGE); |
221 | |
217 | |
222 | parse_options (argc, argv, envp); |
218 | parse_options (argc, argv, envp); |
223 | |
219 | |
|
|
220 | argc -= optind; |
|
|
221 | argv += optind; |
|
|
222 | |
224 | if (show_version) |
223 | if (show_version) |
225 | { |
224 | { |
226 | printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), |
225 | printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (), |
227 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
226 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
228 | printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); |
227 | printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); |
229 | printf (_ |
228 | printf (_ |
230 | ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" |
229 | ("Copyright (C) 2003 Marc Lehmann <gvpe@schmorp.de> and others.\n" |
231 | "See the AUTHORS file for a complete list.\n\n" |
230 | "See the AUTHORS file for a complete list.\n\n" |
232 | "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
231 | "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
233 | "and you are welcome to redistribute it under certain conditions;\n" |
232 | "and you are welcome to redistribute it under certain conditions;\n" |
234 | "see the file COPYING for details.\n")); |
233 | "see the file COPYING for details.\n")); |
235 | |
234 | |
… | |
… | |
247 | if (do_mlock) |
246 | if (do_mlock) |
248 | if (mlockall (MCL_CURRENT | MCL_FUTURE)) |
247 | if (mlockall (MCL_CURRENT | MCL_FUTURE)) |
249 | slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); |
248 | slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); |
250 | #endif |
249 | #endif |
251 | |
250 | |
252 | conf.read_config (true); |
251 | if (argc >= 1) |
|
|
252 | { |
|
|
253 | thisnode = *argv++; |
|
|
254 | argc--; |
|
|
255 | } |
|
|
256 | |
|
|
257 | if (!ev::ev_default_loop (0)) |
|
|
258 | { |
|
|
259 | slog (L_ERR, _("unable to initialise the event loop (bad $LIBEV_METHODS?)")); |
|
|
260 | exit (EXIT_FAILURE); |
|
|
261 | } |
|
|
262 | |
|
|
263 | { |
|
|
264 | configuration_parser (conf, true, argc, argv); |
|
|
265 | } |
253 | |
266 | |
254 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
267 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
255 | |
268 | |
256 | RAND_load_file ("/dev/urandom", 1024); |
269 | RAND_load_file ("/dev/urandom", 1024); |
257 | |
270 | |
… | |
… | |
267 | |
280 | |
268 | setup_signals (); |
281 | setup_signals (); |
269 | |
282 | |
270 | if (!network.setup ()) |
283 | if (!network.setup ()) |
271 | { |
284 | { |
272 | io_manager::loop (); |
285 | ev::ev_loop (0); |
273 | cleanup_and_exit (EXIT_FAILURE); |
286 | cleanup_and_exit (EXIT_FAILURE); |
274 | } |
287 | } |
275 | |
288 | |
276 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
289 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
277 | cleanup_and_exit (EXIT_FAILURE); |
290 | cleanup_and_exit (EXIT_FAILURE); |