1 /* $OpenBSD: init.c,v 1.37 2005/05/26 05:14:17 hshoexer Exp $	 */
2 /* $EOM: init.c,v 1.25 2000/03/30 14:27:24 ho Exp $	 */
3 
4 /*
5  * Copyright (c) 1998, 1999, 2000 Niklas Hallqvist.  All rights reserved.
6  * Copyright (c) 2000 Angelos D. Keromytis.  All rights reserved.
7  * Copyright (c) 2003, 2004 H�kan Olsson.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * This code was written under funding by Ericsson Radio Systems.
32  */
33 
34 /* XXX This file could easily be built dynamically instead.  */
35 
36 #include <stdlib.h>
37 
38 #include "app.h"
39 #include "cert.h"
40 #include "conf.h"
41 #include "connection.h"
42 #include "doi.h"
43 #include "exchange.h"
44 #include "init.h"
45 #include "ipsec.h"
46 #include "isakmp_doi.h"
47 #include "libcrypto.h"
48 #include "log.h"
49 #include "math_group.h"
50 #include "monitor.h"
51 #include "sa.h"
52 #include "timer.h"
53 #include "transport.h"
54 #include "virtual.h"
55 #include "udp.h"
56 #include "ui.h"
57 #include "util.h"
58 
59 #include "policy.h"
60 
61 #include "nat_traversal.h"
62 #include "udp_encap.h"
63 
64 void
init(void)65 init(void)
66 {
67 	app_init();
68 	doi_init();
69 	exchange_init();
70 	group_init();
71 	ipsec_init();
72 	isakmp_doi_init();
73 	libcrypto_init();
74 
75 	timer_init();
76 
77 	/* The following group are depending on timer_init having run.  */
78 	conf_init();
79 	connection_init();
80 
81 	/* This depends on conf_init, thus check as soon as possible. */
82 	log_reinit();
83 
84 	/* policy_init depends on conf_init having run.  */
85 	policy_init();
86 
87 	/* Depends on conf_init and policy_init having run */
88 	cert_init();
89 	crl_init();
90 
91 	sa_init();
92 	transport_init();
93 	virtual_init();
94 	udp_init();
95 	nat_t_init();
96 	udp_encap_init();
97 	monitor_ui_init();
98 }
99 
100 /* Reinitialize, either after a SIGHUP reception or by FIFO UI cmd.  */
101 void
reinit(void)102 reinit(void)
103 {
104 	log_print("isakmpd: reinitializing daemon");
105 
106 	/*
107 	 * XXX Remove all(/some?) pending exchange timers? - they may not be
108 	 *     possible to complete after we've re-read the config file.
109 	 *     User-initiated SIGHUP's maybe "authorizes" a wait until
110 	 *     next connection-check.
111 	 * XXX This means we discard exchange->last_msg, is this really ok?
112          */
113 
114 #if defined(INSECURE_RAND)
115 	/* Reinitialize PRNG if we are in deterministic mode.  */
116 	if (regrand)
117 		srandom(seed);
118 #endif
119 
120 	/* Reread config file.  */
121 	conf_reinit();
122 
123 	log_reinit();
124 
125 	/* Reread the policies.  */
126 	policy_init();
127 
128 	/* Reinitialize certificates */
129 	cert_init();
130 	crl_init();
131 
132 	/* Reinitialize our connection list.  */
133 	connection_reinit();
134 
135 	/*
136 	 * Rescan interfaces (call reinit() in all transports).
137          */
138 	transport_reinit();
139 
140 	/*
141 	 * XXX "These" (non-existent) reinitializations should not be done.
142 	 * cookie_reinit ();
143 	 * ui_reinit ();
144          */
145 
146 	sa_reinit();
147 }
148