12be9e038Ssthen /* 22be9e038Ssthen * ipsecmod/ipsecmod.h - facilitate opportunistic IPsec module 32be9e038Ssthen * 42be9e038Ssthen * Copyright (c) 2017, NLnet Labs. All rights reserved. 52be9e038Ssthen * 62be9e038Ssthen * This software is open source. 72be9e038Ssthen * 82be9e038Ssthen * Redistribution and use in source and binary forms, with or without 92be9e038Ssthen * modification, are permitted provided that the following conditions 102be9e038Ssthen * are met: 112be9e038Ssthen * 122be9e038Ssthen * Redistributions of source code must retain the above copyright notice, 132be9e038Ssthen * this list of conditions and the following disclaimer. 142be9e038Ssthen * 152be9e038Ssthen * Redistributions in binary form must reproduce the above copyright notice, 162be9e038Ssthen * this list of conditions and the following disclaimer in the documentation 172be9e038Ssthen * and/or other materials provided with the distribution. 182be9e038Ssthen * 192be9e038Ssthen * Neither the name of the NLNET LABS nor the names of its contributors may 202be9e038Ssthen * be used to endorse or promote products derived from this software without 212be9e038Ssthen * specific prior written permission. 222be9e038Ssthen * 232be9e038Ssthen * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 242be9e038Ssthen * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 252be9e038Ssthen * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 262be9e038Ssthen * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 272be9e038Ssthen * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 282be9e038Ssthen * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 292be9e038Ssthen * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 302be9e038Ssthen * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 312be9e038Ssthen * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 322be9e038Ssthen * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 332be9e038Ssthen * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 342be9e038Ssthen */ 352be9e038Ssthen 362be9e038Ssthen /** 372be9e038Ssthen * \file 382be9e038Ssthen * 392be9e038Ssthen * This file contains a module that facilitates opportunistic IPsec. It does so 40*83152a15Ssthen * by also querying for the IPSECKEY for A/AAAA queries and calling a 412be9e038Ssthen * configurable hook (eg. signaling an IKE daemon) before replying. 422be9e038Ssthen */ 432be9e038Ssthen 442be9e038Ssthen #ifndef IPSECMOD_H 452be9e038Ssthen #define IPSECMOD_H 462be9e038Ssthen #include "util/module.h" 472be9e038Ssthen #include "util/rbtree.h" 482be9e038Ssthen 492be9e038Ssthen /** 502be9e038Ssthen * The global variable environment contents for the ipsecmod 512be9e038Ssthen * Shared between threads, this represents long term information. 522be9e038Ssthen */ 532be9e038Ssthen struct ipsecmod_env { 542be9e038Ssthen /** White listed domains for ipsecmod. */ 552be9e038Ssthen rbtree_type* whitelist; 562be9e038Ssthen }; 572be9e038Ssthen 582be9e038Ssthen /** 592be9e038Ssthen * Per query state for the ipsecmod module. 602be9e038Ssthen */ 612be9e038Ssthen struct ipsecmod_qstate { 622be9e038Ssthen /** State of the IPsec module. */ 632be9e038Ssthen /** NOTE: This value is copied here from the configuration so that a change 642be9e038Ssthen * with unbound-control would not complicate an already running mesh. */ 652be9e038Ssthen int enabled; 662be9e038Ssthen /** If the qname is whitelisted or not. */ 672be9e038Ssthen /** NOTE: No whitelist means all qnames are whitelisted. */ 682be9e038Ssthen int is_whitelisted; 692be9e038Ssthen /** Pointer to IPSECKEY rrset allocated in the qstate region. NULL if there 702be9e038Ssthen * was no IPSECKEY reply from the subquery. */ 712be9e038Ssthen struct ub_packed_rrset_key* ipseckey_rrset; 722be9e038Ssthen /** If the IPSECKEY subquery has finished. */ 732be9e038Ssthen int ipseckey_done; 742be9e038Ssthen }; 752be9e038Ssthen 762be9e038Ssthen /** Init the ipsecmod module */ 772be9e038Ssthen int ipsecmod_init(struct module_env* env, int id); 782be9e038Ssthen /** Deinit the ipsecmod module */ 792be9e038Ssthen void ipsecmod_deinit(struct module_env* env, int id); 802be9e038Ssthen /** Operate on an event on a query (in qstate). */ 812be9e038Ssthen void ipsecmod_operate(struct module_qstate* qstate, enum module_ev event, 822be9e038Ssthen int id, struct outbound_entry* outbound); 832be9e038Ssthen /** Subordinate query done, inform this super request of its conclusion */ 842be9e038Ssthen void ipsecmod_inform_super(struct module_qstate* qstate, int id, 852be9e038Ssthen struct module_qstate* super); 862be9e038Ssthen /** clear the ipsecmod query-specific contents out of qstate */ 872be9e038Ssthen void ipsecmod_clear(struct module_qstate* qstate, int id); 882be9e038Ssthen /** return memory estimate for the ipsecmod module */ 892be9e038Ssthen size_t ipsecmod_get_mem(struct module_env* env, int id); 902be9e038Ssthen 912be9e038Ssthen /** 922be9e038Ssthen * Get the function block with pointers to the ipsecmod functions 932be9e038Ssthen * @return the function block for "ipsecmod". 942be9e038Ssthen */ 952be9e038Ssthen struct module_func_block* ipsecmod_get_funcblock(void); 962be9e038Ssthen 972be9e038Ssthen #endif /* IPSECMOD_H */ 98