1*c442abe9Stb /* $OpenBSD: init.c,v 1.44 2021/10/13 16:56:30 tb Exp $ */
27918ad0aSniklas /* $EOM: init.c,v 1.25 2000/03/30 14:27:24 ho Exp $ */
32040585eSniklas
42040585eSniklas /*
502005a80Sniklas * Copyright (c) 1998, 1999, 2000 Niklas Hallqvist. All rights reserved.
6bdbf6df3Sniklas * Copyright (c) 2000 Angelos D. Keromytis. All rights reserved.
7cd6bf844Sho * Copyright (c) 2003, 2004 H�kan Olsson. All rights reserved.
82040585eSniklas *
92040585eSniklas * Redistribution and use in source and binary forms, with or without
102040585eSniklas * modification, are permitted provided that the following conditions
112040585eSniklas * are met:
122040585eSniklas * 1. Redistributions of source code must retain the above copyright
132040585eSniklas * notice, this list of conditions and the following disclaimer.
142040585eSniklas * 2. Redistributions in binary form must reproduce the above copyright
152040585eSniklas * notice, this list of conditions and the following disclaimer in the
162040585eSniklas * documentation and/or other materials provided with the distribution.
172040585eSniklas *
182040585eSniklas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
192040585eSniklas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
202040585eSniklas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
212040585eSniklas * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
222040585eSniklas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
232040585eSniklas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242040585eSniklas * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252040585eSniklas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262040585eSniklas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
272040585eSniklas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282040585eSniklas */
292040585eSniklas
302040585eSniklas /*
312040585eSniklas * This code was written under funding by Ericsson Radio Systems.
322040585eSniklas */
332040585eSniklas
342040585eSniklas /* XXX This file could easily be built dynamically instead. */
352040585eSniklas
36a60f36f9Sho #include <stdlib.h>
37a60f36f9Sho
382040585eSniklas #include "app.h"
39fb1921ccSniklas #include "cert.h"
402040585eSniklas #include "conf.h"
41b393bef8Sniklas #include "connection.h"
422040585eSniklas #include "doi.h"
432040585eSniklas #include "exchange.h"
442040585eSniklas #include "init.h"
452040585eSniklas #include "ipsec.h"
462040585eSniklas #include "isakmp_doi.h"
474f94bf8bSniklas #include "libcrypto.h"
487918ad0aSniklas #include "log.h"
49fefcb31aSreyk #include "dh.h"
50b09056b7Shshoexer #include "monitor.h"
512040585eSniklas #include "sa.h"
522040585eSniklas #include "timer.h"
532040585eSniklas #include "transport.h"
54cd6bf844Sho #include "virtual.h"
552040585eSniklas #include "udp.h"
562040585eSniklas #include "ui.h"
57b7f5c844Sho #include "util.h"
5817f91f1cShshoexer #include "vendor.h"
592040585eSniklas
60ee0e5087Sniklas #include "policy.h"
61ee0e5087Sniklas
62cd6bf844Sho #include "nat_traversal.h"
63cd6bf844Sho #include "udp_encap.h"
64cd6bf844Sho
652040585eSniklas void
init(void)6630c1e3c7Sho init(void)
672040585eSniklas {
682040585eSniklas app_init();
692040585eSniklas doi_init();
702040585eSniklas exchange_init();
712040585eSniklas group_init();
722040585eSniklas ipsec_init();
732040585eSniklas isakmp_doi_init();
7493dee98cSniklas
752040585eSniklas timer_init();
768b10b501Sniklas
778b10b501Sniklas /* The following group are depending on timer_init having run. */
788b10b501Sniklas conf_init();
79b393bef8Sniklas connection_init();
808b10b501Sniklas
814e2ad344Shshoexer /* This depends on conf_init, thus check as soon as possible. */
824e2ad344Shshoexer log_reinit();
834e2ad344Shshoexer
846d74ce46Sniklas /* policy_init depends on conf_init having run. */
856d74ce46Sniklas policy_init();
866d74ce46Sniklas
876d74ce46Sniklas /* Depends on conf_init and policy_init having run */
88fb1921ccSniklas cert_init();
899dbe9fb4Sho crl_init();
90fb1921ccSniklas
912040585eSniklas sa_init();
922040585eSniklas transport_init();
93cd6bf844Sho virtual_init();
942040585eSniklas udp_init();
95cd6bf844Sho nat_t_init();
96cd6bf844Sho udp_encap_init();
9717f91f1cShshoexer vendor_init();
982040585eSniklas }
99b7f5c844Sho
100b7f5c844Sho /* Reinitialize, either after a SIGHUP reception or by FIFO UI cmd. */
101b7f5c844Sho void
reinit(void)102b7f5c844Sho reinit(void)
103b7f5c844Sho {
104bfe429baSho log_print("isakmpd: reinitializing daemon");
105b7f5c844Sho
106b7f5c844Sho /*
107b7f5c844Sho * XXX Remove all(/some?) pending exchange timers? - they may not be
108b7f5c844Sho * possible to complete after we've re-read the config file.
109b7f5c844Sho * User-initiated SIGHUP's maybe "authorizes" a wait until
110b7f5c844Sho * next connection-check.
111b7f5c844Sho * XXX This means we discard exchange->last_msg, is this really ok?
112b7f5c844Sho */
113b7f5c844Sho
114b7f5c844Sho /* Reread config file. */
115b7f5c844Sho conf_reinit();
116b7f5c844Sho
1174e2ad344Shshoexer log_reinit();
1184e2ad344Shshoexer
119b7f5c844Sho /* Reread the policies. */
120b7f5c844Sho policy_init();
121b7f5c844Sho
122b7f5c844Sho /* Reinitialize certificates */
123b7f5c844Sho cert_init();
1249dbe9fb4Sho crl_init();
125b7f5c844Sho
126b7f5c844Sho /* Reinitialize our connection list. */
127b7f5c844Sho connection_reinit();
128b7f5c844Sho
129b7f5c844Sho /*
130cd6bf844Sho * Rescan interfaces (call reinit() in all transports).
131b7f5c844Sho */
132b7f5c844Sho transport_reinit();
133b7f5c844Sho
134b7f5c844Sho /*
1356957a4a4Sjmc * XXX "These" (non-existent) reinitializations should not be done.
136b7f5c844Sho * cookie_reinit ();
137b7f5c844Sho * ui_reinit ();
138b7f5c844Sho */
1394d27bb0fSho
1404d27bb0fSho sa_reinit();
141b7f5c844Sho }
142