xref: /freebsd/contrib/unbound/ipsecmod/ipsecmod.h (revision 24e365220007c415f495cf8dcb228ece6002b8b7)
1c7f4d7adSDag-Erling Smørgrav /*
2c7f4d7adSDag-Erling Smørgrav  * ipsecmod/ipsecmod.h - facilitate opportunistic IPsec module
3c7f4d7adSDag-Erling Smørgrav  *
4c7f4d7adSDag-Erling Smørgrav  * Copyright (c) 2017, NLnet Labs. All rights reserved.
5c7f4d7adSDag-Erling Smørgrav  *
6c7f4d7adSDag-Erling Smørgrav  * This software is open source.
7c7f4d7adSDag-Erling Smørgrav  *
8c7f4d7adSDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
9c7f4d7adSDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
10c7f4d7adSDag-Erling Smørgrav  * are met:
11c7f4d7adSDag-Erling Smørgrav  *
12c7f4d7adSDag-Erling Smørgrav  * Redistributions of source code must retain the above copyright notice,
13c7f4d7adSDag-Erling Smørgrav  * this list of conditions and the following disclaimer.
14c7f4d7adSDag-Erling Smørgrav  *
15c7f4d7adSDag-Erling Smørgrav  * Redistributions in binary form must reproduce the above copyright notice,
16c7f4d7adSDag-Erling Smørgrav  * this list of conditions and the following disclaimer in the documentation
17c7f4d7adSDag-Erling Smørgrav  * and/or other materials provided with the distribution.
18c7f4d7adSDag-Erling Smørgrav  *
19c7f4d7adSDag-Erling Smørgrav  * Neither the name of the NLNET LABS nor the names of its contributors may
20c7f4d7adSDag-Erling Smørgrav  * be used to endorse or promote products derived from this software without
21c7f4d7adSDag-Erling Smørgrav  * specific prior written permission.
22c7f4d7adSDag-Erling Smørgrav  *
23c7f4d7adSDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24c7f4d7adSDag-Erling Smørgrav  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25c7f4d7adSDag-Erling Smørgrav  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26c7f4d7adSDag-Erling Smørgrav  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27c7f4d7adSDag-Erling Smørgrav  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28c7f4d7adSDag-Erling Smørgrav  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29c7f4d7adSDag-Erling Smørgrav  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30c7f4d7adSDag-Erling Smørgrav  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31c7f4d7adSDag-Erling Smørgrav  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32c7f4d7adSDag-Erling Smørgrav  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33c7f4d7adSDag-Erling Smørgrav  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34c7f4d7adSDag-Erling Smørgrav  */
35c7f4d7adSDag-Erling Smørgrav 
36c7f4d7adSDag-Erling Smørgrav /**
37c7f4d7adSDag-Erling Smørgrav  * \file
38c7f4d7adSDag-Erling Smørgrav  *
39c7f4d7adSDag-Erling Smørgrav  * This file contains a module that facilitates opportunistic IPsec. It does so
40*24e36522SCy Schubert  * by also querying for the IPSECKEY for A/AAAA queries and calling a
41c7f4d7adSDag-Erling Smørgrav  * configurable hook (eg. signaling an IKE daemon) before replying.
42c7f4d7adSDag-Erling Smørgrav  */
43c7f4d7adSDag-Erling Smørgrav 
44c7f4d7adSDag-Erling Smørgrav #ifndef IPSECMOD_H
45c7f4d7adSDag-Erling Smørgrav #define IPSECMOD_H
46c7f4d7adSDag-Erling Smørgrav #include "util/module.h"
47c7f4d7adSDag-Erling Smørgrav #include "util/rbtree.h"
48c7f4d7adSDag-Erling Smørgrav 
49c7f4d7adSDag-Erling Smørgrav /**
50c7f4d7adSDag-Erling Smørgrav  * The global variable environment contents for the ipsecmod
51c7f4d7adSDag-Erling Smørgrav  * Shared between threads, this represents long term information.
52c7f4d7adSDag-Erling Smørgrav  */
53c7f4d7adSDag-Erling Smørgrav struct ipsecmod_env {
54c7f4d7adSDag-Erling Smørgrav 	/** White listed domains for ipsecmod. */
55c7f4d7adSDag-Erling Smørgrav 	rbtree_type* whitelist;
56c7f4d7adSDag-Erling Smørgrav };
57c7f4d7adSDag-Erling Smørgrav 
58c7f4d7adSDag-Erling Smørgrav /**
59c7f4d7adSDag-Erling Smørgrav  * Per query state for the ipsecmod module.
60c7f4d7adSDag-Erling Smørgrav  */
61c7f4d7adSDag-Erling Smørgrav struct ipsecmod_qstate {
62c7f4d7adSDag-Erling Smørgrav 	/** State of the IPsec module. */
63c7f4d7adSDag-Erling Smørgrav 	/** NOTE: This value is copied here from the configuration so that a change
64c7f4d7adSDag-Erling Smørgrav 	 *  with unbound-control would not complicate an already running mesh. */
65c7f4d7adSDag-Erling Smørgrav 	int enabled;
66c7f4d7adSDag-Erling Smørgrav 	/** If the qname is whitelisted or not. */
67c7f4d7adSDag-Erling Smørgrav 	/** NOTE: No whitelist means all qnames are whitelisted. */
68c7f4d7adSDag-Erling Smørgrav 	int is_whitelisted;
69c7f4d7adSDag-Erling Smørgrav 	/** Pointer to IPSECKEY rrset allocated in the qstate region. NULL if there
70c7f4d7adSDag-Erling Smørgrav 	 *  was no IPSECKEY reply from the subquery. */
71c7f4d7adSDag-Erling Smørgrav 	struct ub_packed_rrset_key* ipseckey_rrset;
72c7f4d7adSDag-Erling Smørgrav 	/** If the IPSECKEY subquery has finished. */
73c7f4d7adSDag-Erling Smørgrav 	int ipseckey_done;
74c7f4d7adSDag-Erling Smørgrav };
75c7f4d7adSDag-Erling Smørgrav 
76c7f4d7adSDag-Erling Smørgrav /** Init the ipsecmod module */
77c7f4d7adSDag-Erling Smørgrav int ipsecmod_init(struct module_env* env, int id);
78c7f4d7adSDag-Erling Smørgrav /** Deinit the ipsecmod module */
79c7f4d7adSDag-Erling Smørgrav void ipsecmod_deinit(struct module_env* env, int id);
80c7f4d7adSDag-Erling Smørgrav /** Operate on an event on a query (in qstate). */
81c7f4d7adSDag-Erling Smørgrav void ipsecmod_operate(struct module_qstate* qstate, enum module_ev event,
82c7f4d7adSDag-Erling Smørgrav 	int id, struct outbound_entry* outbound);
83c7f4d7adSDag-Erling Smørgrav /** Subordinate query done, inform this super request of its conclusion */
84c7f4d7adSDag-Erling Smørgrav void ipsecmod_inform_super(struct module_qstate* qstate, int id,
85c7f4d7adSDag-Erling Smørgrav 	struct module_qstate* super);
86c7f4d7adSDag-Erling Smørgrav /** clear the ipsecmod query-specific contents out of qstate */
87c7f4d7adSDag-Erling Smørgrav void ipsecmod_clear(struct module_qstate* qstate, int id);
88c7f4d7adSDag-Erling Smørgrav /** return memory estimate for the ipsecmod module */
89c7f4d7adSDag-Erling Smørgrav size_t ipsecmod_get_mem(struct module_env* env, int id);
90c7f4d7adSDag-Erling Smørgrav 
91c7f4d7adSDag-Erling Smørgrav /**
92c7f4d7adSDag-Erling Smørgrav  * Get the function block with pointers to the ipsecmod functions
93c7f4d7adSDag-Erling Smørgrav  * @return the function block for "ipsecmod".
94c7f4d7adSDag-Erling Smørgrav  */
95c7f4d7adSDag-Erling Smørgrav struct module_func_block* ipsecmod_get_funcblock(void);
96c7f4d7adSDag-Erling Smørgrav 
97c7f4d7adSDag-Erling Smørgrav #endif /* IPSECMOD_H */
98