2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
8 * Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "config-win32.h"
39 #include "forward-inline.h"
41 #define P2P_CHECK_SIG() EVENT_LOOP_CHECK_SIGNAL (c, process_signal_p2p, c);
44 process_signal_p2p (struct context
*c
)
47 return process_signal (c
);
51 tunnel_point_to_point (struct context
*c
)
55 /* set point-to-point mode */
58 /* initialize tunnel instance */
59 init_instance_handle_signals (c
, c
->es
, CC_HARD_USR1_TO_HUP
);
63 init_management_callback_p2p (c
);
68 perf_push (PERF_EVENT_LOOP
);
70 /* process timers, TLS, etc. */
74 /* set up and do the I/O wait */
75 io_wait (c
, p2p_iow_flags (c
));
79 if (c
->c2
.event_set_status
== ES_TIMEOUT
)
85 /* process the I/O which triggered select */
92 uninit_management_callback ();
94 /* tear down tunnel instance (unless --persist-tun) */
98 #undef PROCESS_SIGNAL_P2P
101 main (int argc
, char *argv
[])
106 fprintf (stderr
, "Sorry, I was built with --enable-pedantic and I am incapable of doing any real work!\n");
112 /* signify first time for components which can
113 only be initialized once per program instantiation. */
116 /* initialize program-wide statics */
120 * This loop is initially executed on startup and then
125 /* zero context struct but leave first_time member alone */
126 context_clear_all_except_first_time (&c
);
128 /* static signal info object */
129 CLEAR (siginfo_static
);
130 c
.sig
= &siginfo_static
;
132 /* initialize garbage collector scoped to context object */
135 /* initialize environmental variable store */
136 c
.es
= env_set_create (&c
.gc
);
138 #ifdef ENABLE_MANAGEMENT
139 /* initialize management subsystem */
140 init_management (&c
);
143 /* initialize options to default state */
144 init_options (&c
.options
);
146 /* parse command line options, and read configuration file */
147 parse_argv (&c
.options
, argc
, argv
, M_USAGE
, OPT_P_DEFAULT
, NULL
, c
.es
);
149 /* init verbosity and mute levels */
150 init_verb_mute (&c
, IVM_LEVEL_1
);
152 /* set dev options */
153 init_options_dev (&c
.options
);
155 /* openssl print info? */
156 if (print_openssl_info (&c
.options
))
160 if (do_genkey (&c
.options
))
163 /* tun/tap persist command? */
164 if (do_persist_tuntap (&c
.options
))
167 /* sanity check on options */
168 options_postprocess (&c
.options
, c
.first_time
);
170 /* show all option settings */
171 show_settings (&c
.options
);
173 /* print version number */
174 msg (M_INFO
, "%s", title_string
);
177 pre_setup (&c
.options
);
180 if (do_test_crypto (&c
.options
))
183 #ifdef ENABLE_MANAGEMENT
184 /* open management subsystem */
185 if (!open_management (&c
))
189 /* set certain options as environmental variables */
190 setenv_settings (c
.es
, &c
.options
);
192 /* finish context init */
197 /* run tunnel depending on mode */
198 switch (c
.options
.mode
)
200 case MODE_POINT_TO_POINT
:
201 tunnel_point_to_point (&c
);
212 /* indicates first iteration -- has program-wide scope */
213 c
.first_time
= false;
215 /* any signals received? */
217 print_signal (c
.sig
, NULL
, M_INFO
);
219 /* pass restart status to management subsystem */
220 signal_restart_status (c
.sig
);
222 while (c
.sig
->signal_received
== SIGUSR1
);
224 uninit_options (&c
.options
);
227 while (c
.sig
->signal_received
== SIGHUP
);
230 context_gc_free (&c
);
232 #ifdef ENABLE_MANAGEMENT
233 /* close management interface */
237 /* uninitialize program-wide statics */
240 openvpn_exit (OPENVPN_EXIT_STATUS_GOOD
); /* exit point */
241 return 0; /* NOTREACHED */