… | |
… | |
42 | |
42 | |
43 | #include "conf.h" |
43 | #include "conf.h" |
44 | #include "slog.h" |
44 | #include "slog.h" |
45 | #include "util.h" |
45 | #include "util.h" |
46 | #include "protocol.h" |
46 | #include "protocol.h" |
|
|
47 | #include "iom.h" |
47 | |
48 | |
48 | vpn network; |
49 | vpn network; |
|
|
50 | |
|
|
51 | static loglevel llevel = L_NONE; |
49 | |
52 | |
50 | /* If nonzero, display usage information and exit. */ |
53 | /* If nonzero, display usage information and exit. */ |
51 | static int show_help; |
54 | static int show_help; |
52 | |
55 | |
53 | /* If nonzero, print the version on standard output and exit. */ |
56 | /* If nonzero, print the version on standard output and exit. */ |
… | |
… | |
126 | break; |
129 | break; |
127 | #endif |
130 | #endif |
128 | |
131 | |
129 | case 'l': /* inc debug level */ |
132 | case 'l': /* inc debug level */ |
130 | { |
133 | { |
131 | loglevel l = string_to_loglevel (optarg); |
134 | llevel = string_to_loglevel (optarg); |
132 | |
135 | |
133 | if (l != L_NONE) |
136 | if (llevel == L_NONE) |
134 | set_loglevel (l); |
|
|
135 | else |
|
|
136 | slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL); |
137 | slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL); |
137 | } |
138 | } |
138 | break; |
139 | break; |
139 | |
140 | |
140 | case '?': |
141 | case '?': |
… | |
… | |
166 | */ |
167 | */ |
167 | RETSIGTYPE |
168 | RETSIGTYPE |
168 | sigterm_handler (int a) |
169 | sigterm_handler (int a) |
169 | { |
170 | { |
170 | network.events |= vpn::EVENT_SHUTDOWN; |
171 | network.events |= vpn::EVENT_SHUTDOWN; |
|
|
172 | network.event.start (0); |
171 | } |
173 | } |
172 | |
174 | |
173 | RETSIGTYPE |
175 | RETSIGTYPE |
174 | sighup_handler (int a) |
176 | sighup_handler (int a) |
175 | { |
177 | { |
176 | network.events |= vpn::EVENT_RECONNECT; |
178 | network.events |= vpn::EVENT_RECONNECT; |
|
|
179 | network.event.start (0); |
177 | } |
180 | } |
178 | |
181 | |
179 | RETSIGTYPE |
182 | RETSIGTYPE |
180 | sigusr1_handler (int a) |
183 | sigusr1_handler (int a) |
181 | { |
184 | { |
|
|
185 | network.dump_status (); |
182 | } |
186 | } |
183 | |
187 | |
184 | RETSIGTYPE |
188 | RETSIGTYPE |
185 | sigusr2_handler (int a) |
189 | sigusr2_handler (int a) |
186 | { |
190 | { |
… | |
… | |
244 | #endif |
248 | #endif |
245 | |
249 | |
246 | make_names (); |
250 | make_names (); |
247 | conf.read_config (true); |
251 | conf.read_config (true); |
248 | |
252 | |
|
|
253 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
|
|
254 | |
249 | RAND_load_file ("/dev/urandom", 1024); |
255 | RAND_load_file ("/dev/urandom", 1024); |
250 | |
|
|
251 | //OpenSSL_add_all_algorithms (); |
|
|
252 | |
256 | |
253 | if (!THISNODE) |
257 | if (!THISNODE) |
254 | { |
258 | { |
255 | slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."), |
259 | slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."), |
256 | thisnode ? thisnode : "<unset>"); |
260 | thisnode ? thisnode : "<unset>"); |
… | |
… | |
262 | |
266 | |
263 | setup_signals (); |
267 | setup_signals (); |
264 | |
268 | |
265 | if (!network.setup ()) |
269 | if (!network.setup ()) |
266 | { |
270 | { |
267 | network.main_loop (); |
271 | iom.loop (); |
268 | cleanup_and_exit (1); |
272 | cleanup_and_exit (1); |
269 | } |
273 | } |
270 | |
274 | |
271 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
275 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
272 | cleanup_and_exit (1); |
276 | cleanup_and_exit (1); |