From: Wouter Wijngaards Date: Mon, 14 May 2007 15:03:55 +0000 (+0000) Subject: Host cache setup. X-Git-Tag: release-0.4~148 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62461e23bec559f441c8cb40ec37ebbdcc1f23e5;p=thirdparty%2Funbound.git Host cache setup. git-svn-id: file:///svn/unbound/trunk@318 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/Makefile.in b/Makefile.in index 5bff4f0bd..528ba63c8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -50,21 +50,28 @@ LINTFLAGS+="-DBN_ULONG=unsigned long" -Dkrb5_int32=int "-Dkrb5_ui_4=unsigned int INSTALL=$(srcdir)/install-sh -COMMON_SRC=$(wildcard services/*.c util/*.c util/data/*.c util/storage/*.c iterator/*.c) util/configparser.c util/configlexer.c testcode/checklocks.c +COMMON_SRC=$(wildcard services/*.c services/cache/*.c util/*.c \ + util/data/*.c util/storage/*.c iterator/*.c) util/configparser.c \ + util/configlexer.c testcode/checklocks.c COMMON_OBJ=$(addprefix $(BUILD),$(COMMON_SRC:.c=.o)) COMPAT_OBJ=$(addprefix $(BUILD)compat/,$(LIBOBJS)) UNITTEST_SRC=$(wildcard testcode/unit*.c) testcode/readhex.c $(COMMON_SRC) UNITTEST_OBJ=$(addprefix $(BUILD),$(UNITTEST_SRC:.c=.o)) $(COMPAT_OBJ) DAEMON_SRC=$(wildcard daemon/*.c) $(COMMON_SRC) DAEMON_OBJ=$(addprefix $(BUILD),$(DAEMON_SRC:.c=.o)) $(COMPAT_OBJ) -TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c daemon/worker.c daemon/daemon.c daemon/stats.c testcode/replay.c testcode/fake_event.c $(filter-out util/netevent.c services/listen_dnsport.c services/outside_network.c, $(COMMON_SRC)) +TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c \ + daemon/worker.c daemon/daemon.c daemon/stats.c testcode/replay.c \ + testcode/fake_event.c $(filter-out util/netevent.c \ + services/listen_dnsport.c services/outside_network.c, $(COMMON_SRC)) TESTBOUND_OBJ=$(addprefix $(BUILD),$(TESTBOUND_SRC:.c=.o)) $(COMPAT_OBJ) LOCKVERIFY_SRC=testcode/lock_verify.c $(COMMON_SRC) LOCKVERIFY_OBJ=$(addprefix $(BUILD),$(LOCKVERIFY_SRC:.c=.o)) $(COMPAT_OBJ) PKTVIEW_SRC=testcode/pktview.c testcode/readhex.c $(COMMON_SRC) PKTVIEW_OBJ=$(addprefix $(BUILD),$(PKTVIEW_SRC:.c=.o)) $(COMPAT_OBJ) -ALL_SRC=$(COMMON_SRC) $(UNITTEST_SRC) $(DAEMON_SRC) $(TESTBOUND_SRC) $(LOCKVERIFY_SRC) -ALL_OBJ=$(addprefix $(BUILD),$(ALL_SRC:.c=.o) $(addprefix compat/,$(LIBOBJS))) $(COMPAT_OBJ) +ALL_SRC=$(COMMON_SRC) $(UNITTEST_SRC) $(DAEMON_SRC) \ + $(TESTBOUND_SRC) $(LOCKVERIFY_SRC) +ALL_OBJ=$(addprefix $(BUILD),$(ALL_SRC:.c=.o) \ + $(addprefix compat/,$(LIBOBJS))) $(COMPAT_OBJ) COMPILE=$(LIBTOOL) --tag=CC --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) LINK=$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) diff --git a/doc/Changelog b/doc/Changelog index 347ad94d8..74d58f281 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,7 @@ - Port to OS/X and Dec Alpha. Printf format and alignment fixes. - extensive lock debug report on join timeout. - proper RTT calculation, in utility code. + - setup of services/cache/infra, host cache. 11 May 2007: Wouter - iterator/iterator.c module. diff --git a/services/cache/infra.c b/services/cache/infra.c new file mode 100644 index 000000000..356dc690d --- /dev/null +++ b/services/cache/infra.c @@ -0,0 +1,43 @@ +/* + * services/cache/infra.c - infrastructure cache, server rtt and capabilities + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * This software is open source. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the NLNET LABS nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * + * This file contains the infrastructure cache. + */ +#include "config.h" +#include "services/cache/infra.h" + diff --git a/services/cache/infra.h b/services/cache/infra.h new file mode 100644 index 000000000..486a041e3 --- /dev/null +++ b/services/cache/infra.h @@ -0,0 +1,199 @@ +/* + * services/cache/infra.h - infrastructure cache, server rtt and capabilities + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * This software is open source. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the NLNET LABS nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * + * This file contains the infrastructure cache. + */ + +#ifndef SERVICES_CACHE_INFRA_H +#define SERVICES_CACHE_INFRA_H +#include "util/storage/lruhash.h" +#include "util/rtt.h" +struct slabhash; +struct config_file; + +/** + * Host information kept for every server. + */ +struct infra_host_key { + /** the host address. */ + struct sockaddr_storage addr; + /** length of addr. */ + socklen_t addrlen; + /** hash table entry, data of type infra_host_data. */ + struct lruhash_entry entry; +}; + +/** + * Host information encompasses host capabilities and retransmission timeouts. + */ +struct infra_host_data { + /** TTL value for this entry. absolute time. */ + time_t ttl; + /** round trip times for timeout calculation */ + struct rtt_info rtt; + /** Names of the zones that are lame. NULL=no lame zones. */ + struct lruhash* lameness; + /** edns version that the host supports, -1 means no EDNS */ + int edns_version; + /** edns message size that the host advertizes, 512 by default. */ + uint16_t edns_size; +}; + +/** + * Lameness information, per host, per zone. + */ +struct infra_lame_key { + /** key is zone name in wireformat */ + uint8_t* zonename; + /** length of zonename */ + size_t namelen; + /** lruhash entry */ + struct lruhash_entry entry; +}; + +/** + * Lameness information. Expires. + * This host is lame because it is in the cache. + */ +struct infra_lame_data { + /** TTL of this entry. absolute time. */ + time_t ttl; +}; + +/** default TTL value for host information, in seconds */ +#define HOST_TTL 900 +/** default TTL for Lameness information, in seconds */ +#define HOST_LAME_TTL 900 +/** default size of the host cache, number of entries */ +#define HOST_DEFAULT_SIZE 1000 + +/** + * Create infra cache. + * @param cfg: config parameters. + * @return: new infra cache, or NULL. + */ +struct slabhash* infra_create(struct config_file* cfg); + +/** + * Delete infra cache. + * @param infra: infrastructure cache to delete. + */ +void infra_delete(struct slabhash* infra); + +/** + * Lookup host data + * @param infra: infrastructure cache. + * @param addr: host address. + * @param addrlen: length of addr. + * @param wr: set to true to get a writelock on the entry. + * @param timenow: what time it is now. + * @return: host data or NULL if not found or expired. + */ +struct infra_data* infra_lookup_host(struct slabhash* infra, + struct sockaddr_storage* addr, socklen_t addrlen, int wr, + time_t timenow); + +/** + * Find host information to send a packet. Creates new entry if not found. + * Lameness is empty. EDNS is 0, size is 512, and rtt is returned for + * the first message to it. + * @param infra: infrastructure cache. + * @param addr: host address. + * @param addrlen: length of addr. + * @param timenow: what time it is now. + * @param edns_vs: edns version it supports, is returned. + * @param to: timeout to use, is returned. + * @return: 0 on error. + */ +int infra_host(struct slabhash* infra, struct sockaddr_storage* addr, + socklen_t addrlen, time_t timenow, int* edns_vs, int* to); + +/** + * Check for lameness of this server for a particular zone. + * You must have a lock on the host structure. + * @param host: infrastructure cache data for the host. Caller holds lock. + * @param name: domain name of zone apex. + * @param namelen: length of domain name. + * @param timenow: what time it is now. + * @return: 0 if not lame or unknown or timed out, true if lame. + */ +int infra_lookup_lame(struct infra_data* host, + uint8_t* name, size_t namelen, time_t timenow); + +/** + * Set a host to be lame for the given zone. + * @param infra: infrastructure cache. + * @param addr: host address. + * @param addrlen: length of addr. + * @param name: domain name of zone apex. + * @param namelen: length of domain name. + * @param timenow: what time it is now. + * @return: 0 on error. + */ +int infra_set_lame(struct slabhash* infra, + struct sockaddr_storage* addr, socklen_t addrlen, + uint8_t* name, size_t namelen, time_t timenow); + +/** + * Update rtt information for the host. + * @param infra: infrastructure cache. + * @param addr: host address. + * @param addrlen: length of addr. + * @param roundtrip: estimate of roundtrip time or -1 for timeout. + * @param timenow: what time it is now. + * @return: 0 on error. + */ +int infra_rtt_update(struct slabhash* infra, + struct sockaddr_storage* addr, socklen_t addrlen, + int roundtrip, time_t timenow); + +/** + * Update edns information for the host. + * @param infra: infrastructure cache. + * @param addr: host address. + * @param addrlen: length of addr. + * @param edns_version: the version that it publishes. + * @param udp_size: what udp size it can handle. + * @param timenow: what time it is now. + * @return: 0 on error. + */ +int infra_edns_update(struct slabhash* infra, + struct sockaddr_storage* addr, socklen_t addrlen, + int edns_version, uint16_t udp_size, time_t timenow); + +#endif /* SERVICES_CACHE_INFRA_H */